ethdev: introduce indirect flow action
[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_NET_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_NET_IXGBE
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_NET_I40E
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_NET_BNXT
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) rxq (queue_id) desc used count\n"
250                         "    Show current number of filled receive"
251                         " packet descriptors.\n\n"
252
253                         "show port (port_id) macs|mcast_macs"
254                         "       Display list of mac addresses added to port.\n\n"
255
256                         "show port (port_id) fec capabilities"
257                         "       Show fec capabilities of a port.\n\n"
258
259                         "show port (port_id) fec_mode"
260                         "       Show fec mode of a port.\n\n"
261                 );
262         }
263
264         if (show_all || !strcmp(res->section, "config")) {
265                 cmdline_printf(
266                         cl,
267                         "\n"
268                         "Configuration:\n"
269                         "--------------\n"
270                         "Configuration changes only become active when"
271                         " forwarding is started/restarted.\n\n"
272
273                         "set default\n"
274                         "    Reset forwarding to the default configuration.\n\n"
275
276                         "set verbose (level)\n"
277                         "    Set the debug verbosity level X.\n\n"
278
279                         "set log global|(type) (level)\n"
280                         "    Set the log level.\n\n"
281
282                         "set nbport (num)\n"
283                         "    Set number of ports.\n\n"
284
285                         "set nbcore (num)\n"
286                         "    Set number of cores.\n\n"
287
288                         "set coremask (mask)\n"
289                         "    Set the forwarding cores hexadecimal mask.\n\n"
290
291                         "set portmask (mask)\n"
292                         "    Set the forwarding ports hexadecimal mask.\n\n"
293
294                         "set burst (num)\n"
295                         "    Set number of packets per burst.\n\n"
296
297                         "set burst tx delay (microseconds) retry (num)\n"
298                         "    Set the transmit delay time and number of retries,"
299                         " effective when retry is enabled.\n\n"
300
301                         "set rxoffs (x[,y]*)\n"
302                         "    Set the offset of each packet segment on"
303                         " receiving if split feature is engaged."
304                         " Affects only the queues configured with split"
305                         " offloads.\n\n"
306
307                         "set rxpkts (x[,y]*)\n"
308                         "    Set the length of each segment to scatter"
309                         " packets on receiving if split feature is engaged."
310                         " Affects only the queues configured with split"
311                         " offloads.\n\n"
312
313                         "set txpkts (x[,y]*)\n"
314                         "    Set the length of each segment of TXONLY"
315                         " and optionally CSUM packets.\n\n"
316
317                         "set txsplit (off|on|rand)\n"
318                         "    Set the split policy for the TX packets."
319                         " Right now only applicable for CSUM and TXONLY"
320                         " modes\n\n"
321
322                         "set txtimes (x, y)\n"
323                         "    Set the scheduling on timestamps"
324                         " timings for the TXONLY mode\n\n"
325
326                         "set corelist (x[,y]*)\n"
327                         "    Set the list of forwarding cores.\n\n"
328
329                         "set portlist (x[,y]*)\n"
330                         "    Set the list of forwarding ports.\n\n"
331
332                         "set port setup on (iterator|event)\n"
333                         "    Select how attached port is retrieved for setup.\n\n"
334
335                         "set tx loopback (port_id) (on|off)\n"
336                         "    Enable or disable tx loopback.\n\n"
337
338                         "set all queues drop (port_id) (on|off)\n"
339                         "    Set drop enable bit for all queues.\n\n"
340
341                         "set vf split drop (port_id) (vf_id) (on|off)\n"
342                         "    Set split drop enable bit for a VF from the PF.\n\n"
343
344                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
345                         "    Set MAC antispoof for a VF from the PF.\n\n"
346
347                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
348                         "    Enable MACsec offload.\n\n"
349
350                         "set macsec offload (port_id) off\n"
351                         "    Disable MACsec offload.\n\n"
352
353                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
354                         "    Configure MACsec secure connection (SC).\n\n"
355
356                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
357                         "    Configure MACsec secure association (SA).\n\n"
358
359                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
360                         "    Set VF broadcast for a VF from the PF.\n\n"
361
362                         "vlan set stripq (on|off) (port_id,queue_id)\n"
363                         "    Set the VLAN strip for a queue on a port.\n\n"
364
365                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
366                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
367
368                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
369                         "    Set VLAN insert for a VF from the PF.\n\n"
370
371                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
372                         "    Set VLAN antispoof for a VF from the PF.\n\n"
373
374                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
375                         "    Set VLAN tag for a VF from the PF.\n\n"
376
377                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
378                         "    Set a VF's max bandwidth(Mbps).\n\n"
379
380                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
381                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
382
383                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
384                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
385
386                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
387                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
388
389                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
390                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
391
392                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
393                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
394
395                         "vlan set (inner|outer) tpid (value) (port_id)\n"
396                         "    Set the VLAN TPID for Packet Filtering on"
397                         " a port\n\n"
398
399                         "rx_vlan add (vlan_id|all) (port_id)\n"
400                         "    Add a vlan_id, or all identifiers, to the set"
401                         " of VLAN identifiers filtered by port_id.\n\n"
402
403                         "rx_vlan rm (vlan_id|all) (port_id)\n"
404                         "    Remove a vlan_id, or all identifiers, from the set"
405                         " of VLAN identifiers filtered by port_id.\n\n"
406
407                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
408                         "    Add a vlan_id, to the set of VLAN identifiers"
409                         "filtered for VF(s) from port_id.\n\n"
410
411                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
412                         "    Remove a vlan_id, to the set of VLAN identifiers"
413                         "filtered for VF(s) from port_id.\n\n"
414
415                         "rx_vxlan_port add (udp_port) (port_id)\n"
416                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
417
418                         "rx_vxlan_port rm (udp_port) (port_id)\n"
419                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
420
421                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
422                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
423                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
424
425                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
426                         "    Set port based TX VLAN insertion.\n\n"
427
428                         "tx_vlan reset (port_id)\n"
429                         "    Disable hardware insertion of a VLAN header in"
430                         " packets sent on a port.\n\n"
431
432                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
433                         "    Select hardware or software calculation of the"
434                         " checksum when transmitting a packet using the"
435                         " csum forward engine.\n"
436                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
437                         "    outer-ip concerns the outer IP layer in"
438                         "    outer-udp concerns the outer UDP layer in"
439                         " case the packet is recognized as a tunnel packet by"
440                         " the forward engine (vxlan, gre and ipip are supported)\n"
441                         "    Please check the NIC datasheet for HW limits.\n\n"
442
443                         "csum parse-tunnel (on|off) (tx_port_id)\n"
444                         "    If disabled, treat tunnel packets as non-tunneled"
445                         " packets (treat inner headers as payload). The port\n"
446                         "    argument is the port used for TX in csum forward"
447                         " engine.\n\n"
448
449                         "csum show (port_id)\n"
450                         "    Display tx checksum offload configuration\n\n"
451
452                         "tso set (segsize) (portid)\n"
453                         "    Enable TCP Segmentation Offload in csum forward"
454                         " engine.\n"
455                         "    Please check the NIC datasheet for HW limits.\n\n"
456
457                         "tso show (portid)"
458                         "    Display the status of TCP Segmentation Offload.\n\n"
459
460                         "set port (port_id) gro on|off\n"
461                         "    Enable or disable Generic Receive Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "show port (port_id) gro\n"
465                         "    Display GRO configuration.\n\n"
466
467                         "set gro flush (cycles)\n"
468                         "    Set the cycle to flush GROed packets from"
469                         " reassembly tables.\n\n"
470
471                         "set port (port_id) gso (on|off)"
472                         "    Enable or disable Generic Segmentation Offload in"
473                         " csum forwarding engine.\n\n"
474
475                         "set gso segsz (length)\n"
476                         "    Set max packet length for output GSO segments,"
477                         " including packet header and payload.\n\n"
478
479                         "show port (port_id) gso\n"
480                         "    Show GSO configuration.\n\n"
481
482                         "set fwd (%s)\n"
483                         "    Set packet forwarding mode.\n\n"
484
485                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
486                         "    Add a MAC address on port_id.\n\n"
487
488                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
489                         "    Remove a MAC address from port_id.\n\n"
490
491                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
492                         "    Set the default MAC address for port_id.\n\n"
493
494                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
495                         "    Add a MAC address for a VF on the port.\n\n"
496
497                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
498                         "    Set the MAC address for a VF from the PF.\n\n"
499
500                         "set eth-peer (port_id) (peer_addr)\n"
501                         "    set the peer address for certain port.\n\n"
502
503                         "set port (port_id) uta (mac_address|all) (on|off)\n"
504                         "    Add/Remove a or all unicast hash filter(s)"
505                         "from port X.\n\n"
506
507                         "set promisc (port_id|all) (on|off)\n"
508                         "    Set the promiscuous mode on port_id, or all.\n\n"
509
510                         "set allmulti (port_id|all) (on|off)\n"
511                         "    Set the allmulti mode on port_id, or all.\n\n"
512
513                         "set vf promisc (port_id) (vf_id) (on|off)\n"
514                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
515
516                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
517                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
518
519                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
520                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
521                         " (on|off) autoneg (on|off) (port_id)\n"
522                         "set flow_ctrl rx (on|off) (portid)\n"
523                         "set flow_ctrl tx (on|off) (portid)\n"
524                         "set flow_ctrl high_water (high_water) (portid)\n"
525                         "set flow_ctrl low_water (low_water) (portid)\n"
526                         "set flow_ctrl pause_time (pause_time) (portid)\n"
527                         "set flow_ctrl send_xon (send_xon) (portid)\n"
528                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
529                         "set flow_ctrl autoneg (on|off) (port_id)\n"
530                         "    Set the link flow control parameter on a port.\n\n"
531
532                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
533                         " (low_water) (pause_time) (priority) (port_id)\n"
534                         "    Set the priority flow control parameter on a"
535                         " port.\n\n"
536
537                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
538                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
539                         " queue on port.\n"
540                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
541                         " on port 0 to mapping 5.\n\n"
542
543                         "set xstats-hide-zero on|off\n"
544                         "    Set the option to hide the zero values"
545                         " for xstats display.\n"
546
547                         "set record-core-cycles on|off\n"
548                         "    Set the option to enable measurement of CPU cycles.\n"
549
550                         "set record-burst-stats on|off\n"
551                         "    Set the option to enable display of RX and TX bursts.\n"
552
553                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
554                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
555
556                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
557                         "|MPE) (on|off)\n"
558                         "    AUPE:accepts untagged VLAN;"
559                         "ROPE:accept unicast hash\n\n"
560                         "    BAM:accepts broadcast packets;"
561                         "MPE:accepts all multicast packets\n\n"
562                         "    Enable/Disable a VF receive mode of a port\n\n"
563
564                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
565                         "    Set rate limit for a queue of a port\n\n"
566
567                         "set port (port_id) vf (vf_id) rate (rate_num) "
568                         "queue_mask (queue_mask_value)\n"
569                         "    Set rate limit for queues in VF of a port\n\n"
570
571                         "set port (port_id) mirror-rule (rule_id)"
572                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
573                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
574                         "   Set pool or vlan type mirror rule on a port.\n"
575                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
576                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
577                         " to pool 0.\n\n"
578
579                         "set port (port_id) mirror-rule (rule_id)"
580                         " (uplink-mirror|downlink-mirror) dst-pool"
581                         " (pool_id) (on|off)\n"
582                         "   Set uplink or downlink type mirror rule on a port.\n"
583                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
584                         " 0 on' enable mirror income traffic to pool 0.\n\n"
585
586                         "reset port (port_id) mirror-rule (rule_id)\n"
587                         "   Reset a mirror rule.\n\n"
588
589                         "set flush_rx (on|off)\n"
590                         "   Flush (default) or don't flush RX streams before"
591                         " forwarding. Mainly used with PCAP drivers.\n\n"
592
593                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
594                         "   Set the bypass mode for the lowest port on bypass enabled"
595                         " NIC.\n\n"
596
597                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
598                         "mode (normal|bypass|isolate) (port_id)\n"
599                         "   Set the event required to initiate specified bypass mode for"
600                         " the lowest port on a bypass enabled NIC where:\n"
601                         "       timeout   = enable bypass after watchdog timeout.\n"
602                         "       os_on     = enable bypass when OS/board is powered on.\n"
603                         "       os_off    = enable bypass when OS/board is powered off.\n"
604                         "       power_on  = enable bypass when power supply is turned on.\n"
605                         "       power_off = enable bypass when power supply is turned off."
606                         "\n\n"
607
608                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
609                         "   Set the bypass watchdog timeout to 'n' seconds"
610                         " where 0 = instant.\n\n"
611
612                         "show bypass config (port_id)\n"
613                         "   Show the bypass configuration for a bypass enabled NIC"
614                         " using the lowest port on the NIC.\n\n"
615
616 #ifdef RTE_NET_BOND
617                         "create bonded device (mode) (socket)\n"
618                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
619
620                         "add bonding slave (slave_id) (port_id)\n"
621                         "       Add a slave device to a bonded device.\n\n"
622
623                         "remove bonding slave (slave_id) (port_id)\n"
624                         "       Remove a slave device from a bonded device.\n\n"
625
626                         "set bonding mode (value) (port_id)\n"
627                         "       Set the bonding mode on a bonded device.\n\n"
628
629                         "set bonding primary (slave_id) (port_id)\n"
630                         "       Set the primary slave for a bonded device.\n\n"
631
632                         "show bonding config (port_id)\n"
633                         "       Show the bonding config for port_id.\n\n"
634
635                         "set bonding mac_addr (port_id) (address)\n"
636                         "       Set the MAC address of a bonded device.\n\n"
637
638                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
639                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
640
641                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
642                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
643
644                         "set bonding mon_period (port_id) (value)\n"
645                         "       Set the bonding link status monitoring polling period in ms.\n\n"
646
647                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
648                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
649
650 #endif
651                         "set link-up port (port_id)\n"
652                         "       Set link up for a port.\n\n"
653
654                         "set link-down port (port_id)\n"
655                         "       Set link down for a port.\n\n"
656
657                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
658                         "    Load a profile package on a port\n\n"
659
660                         "ddp del (port_id) (backup_profile_path)\n"
661                         "    Delete a profile package from a port\n\n"
662
663                         "ptype mapping get (port_id) (valid_only)\n"
664                         "    Get ptype mapping on a port\n\n"
665
666                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
667                         "    Replace target with the pkt_type in ptype mapping\n\n"
668
669                         "ptype mapping reset (port_id)\n"
670                         "    Reset ptype mapping on a port\n\n"
671
672                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
673                         "    Update a ptype mapping item on a port\n\n"
674
675                         "set port (port_id) ptype_mask (ptype_mask)\n"
676                         "    set packet types classification for a specific port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "queue_start_index (value) queue_num (value)\n"
680                         "    Set a queue region on a port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "flowtype (value)\n"
684                         "    Set a flowtype region index on a port\n\n"
685
686                         "set port (port_id) queue-region UP (value) region_id (value)\n"
687                         "    Set the mapping of User Priority to "
688                         "queue region on a port\n\n"
689
690                         "set port (port_id) queue-region flush (on|off)\n"
691                         "    flush all queue region related configuration\n\n"
692
693                         "show port meter cap (port_id)\n"
694                         "    Show port meter capability information\n\n"
695
696                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
697                         "    meter profile add - srtcm rfc 2697\n\n"
698
699                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
700                         "    meter profile add - trtcm rfc 2698\n\n"
701
702                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
703                         "    meter profile add - trtcm rfc 4115\n\n"
704
705                         "del port meter profile (port_id) (profile_id)\n"
706                         "    meter profile delete\n\n"
707
708                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
709                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
710                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
711                         "(dscp_tbl_entry63)]\n"
712                         "    meter create\n\n"
713
714                         "enable port meter (port_id) (mtr_id)\n"
715                         "    meter enable\n\n"
716
717                         "disable port meter (port_id) (mtr_id)\n"
718                         "    meter disable\n\n"
719
720                         "del port meter (port_id) (mtr_id)\n"
721                         "    meter delete\n\n"
722
723                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
724                         "    meter update meter profile\n\n"
725
726                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
727                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
728                         "    update meter dscp table entries\n\n"
729
730                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
731                         "(action0) [(action1) (action2)]\n"
732                         "    meter update policer action\n\n"
733
734                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
735                         "    meter update stats\n\n"
736
737                         "show port (port_id) queue-region\n"
738                         "    show all queue region related configuration info\n\n"
739
740                         "set port (port_id) fec_mode auto|off|rs|baser\n"
741                         "    set fec mode for a specific port\n\n"
742
743                         , list_pkt_forwarding_modes()
744                 );
745         }
746
747         if (show_all || !strcmp(res->section, "ports")) {
748
749                 cmdline_printf(
750                         cl,
751                         "\n"
752                         "Port Operations:\n"
753                         "----------------\n\n"
754
755                         "port start (port_id|all)\n"
756                         "    Start all ports or port_id.\n\n"
757
758                         "port stop (port_id|all)\n"
759                         "    Stop all ports or port_id.\n\n"
760
761                         "port close (port_id|all)\n"
762                         "    Close all ports or port_id.\n\n"
763
764                         "port reset (port_id|all)\n"
765                         "    Reset all ports or port_id.\n\n"
766
767                         "port attach (ident)\n"
768                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
769
770                         "port detach (port_id)\n"
771                         "    Detach physical or virtual dev by port_id\n\n"
772
773                         "port config (port_id|all)"
774                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
775                         " duplex (half|full|auto)\n"
776                         "    Set speed and duplex for all ports or port_id\n\n"
777
778                         "port config (port_id|all) loopback (mode)\n"
779                         "    Set loopback mode for all ports or port_id\n\n"
780
781                         "port config all (rxq|txq|rxd|txd) (value)\n"
782                         "    Set number for rxq/txq/rxd/txd.\n\n"
783
784                         "port config all max-pkt-len (value)\n"
785                         "    Set the max packet length.\n\n"
786
787                         "port config all max-lro-pkt-size (value)\n"
788                         "    Set the max LRO aggregated packet size.\n\n"
789
790                         "port config all drop-en (on|off)\n"
791                         "    Enable or disable packet drop on all RX queues of all ports when no "
792                         "receive buffers available.\n\n"
793
794                         "port config all rss (all|default|ip|tcp|udp|sctp|"
795                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|none|level-default|"
796                         "level-outer|level-inner|<flowtype_id>)\n"
797                         "    Set the RSS mode.\n\n"
798
799                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
800                         "    Set the RSS redirection table.\n\n"
801
802                         "port config (port_id) dcb vt (on|off) (traffic_class)"
803                         " pfc (on|off)\n"
804                         "    Set the DCB mode.\n\n"
805
806                         "port config all burst (value)\n"
807                         "    Set the number of packets per burst.\n\n"
808
809                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
810                         " (value)\n"
811                         "    Set the ring prefetch/host/writeback threshold"
812                         " for tx/rx queue.\n\n"
813
814                         "port config all (txfreet|txrst|rxfreet) (value)\n"
815                         "    Set free threshold for rx/tx, or set"
816                         " tx rs bit threshold.\n\n"
817                         "port config mtu X value\n"
818                         "    Set the MTU of port X to a given value\n\n"
819
820                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
821                         "    Set a rx/tx queue's ring size configuration, the new"
822                         " value will take effect after command that (re-)start the port"
823                         " or command that setup the specific queue\n\n"
824
825                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
826                         "    Start/stop a rx/tx queue of port X. Only take effect"
827                         " when port X is started\n\n"
828
829                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
830                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
831                         " take effect when port X is stopped.\n\n"
832
833                         "port (port_id) (rxq|txq) (queue_id) setup\n"
834                         "    Setup a rx/tx queue of port X.\n\n"
835
836                         "port config (port_id) pctype mapping reset\n"
837                         "    Reset flow type to pctype mapping on a port\n\n"
838
839                         "port config (port_id) pctype mapping update"
840                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
841                         "    Update a flow type to pctype mapping item on a port\n\n"
842
843                         "port config (port_id) pctype (pctype_id) hash_inset|"
844                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
845                         " (field_idx)\n"
846                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
847
848                         "port config (port_id) pctype (pctype_id) hash_inset|"
849                         "fdir_inset|fdir_flx_inset clear all"
850                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
851
852                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
853                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
854
855                         "port config <port_id> rx_offload vlan_strip|"
856                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
857                         "outer_ipv4_cksum|macsec_strip|header_split|"
858                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
859                         "buffer_split|timestamp|security|keep_crc on|off\n"
860                         "     Enable or disable a per port Rx offloading"
861                         " on all Rx queues of a port\n\n"
862
863                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
864                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
865                         "outer_ipv4_cksum|macsec_strip|header_split|"
866                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
867                         "buffer_split|timestamp|security|keep_crc on|off\n"
868                         "    Enable or disable a per queue Rx offloading"
869                         " only on a specific Rx queue\n\n"
870
871                         "port config (port_id) tx_offload vlan_insert|"
872                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
873                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
874                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
875                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
876                         "security on|off\n"
877                         "    Enable or disable a per port Tx offloading"
878                         " on all Tx queues of a port\n\n"
879
880                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
881                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
882                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
883                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
884                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
885                         " on|off\n"
886                         "    Enable or disable a per queue Tx offloading"
887                         " only on a specific Tx queue\n\n"
888
889                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
890                         "    Load an eBPF program as a callback"
891                         " for particular RX/TX queue\n\n"
892
893                         "bpf-unload rx|tx (port) (queue)\n"
894                         "    Unload previously loaded eBPF program"
895                         " for particular RX/TX queue\n\n"
896
897                         "port config (port_id) tx_metadata (value)\n"
898                         "    Set Tx metadata value per port. Testpmd will add this value"
899                         " to any Tx packet sent from this port\n\n"
900
901                         "port config (port_id) dynf (name) set|clear\n"
902                         "    Register a dynf and Set/clear this flag on Tx. "
903                         "Testpmd will set this value to any Tx packet "
904                         "sent from this port\n\n"
905                 );
906         }
907
908         if (show_all || !strcmp(res->section, "registers")) {
909
910                 cmdline_printf(
911                         cl,
912                         "\n"
913                         "Registers:\n"
914                         "----------\n\n"
915
916                         "read reg (port_id) (address)\n"
917                         "    Display value of a port register.\n\n"
918
919                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
920                         "    Display a port register bit field.\n\n"
921
922                         "read regbit (port_id) (address) (bit_x)\n"
923                         "    Display a single port register bit.\n\n"
924
925                         "write reg (port_id) (address) (value)\n"
926                         "    Set value of a port register.\n\n"
927
928                         "write regfield (port_id) (address) (bit_x) (bit_y)"
929                         " (value)\n"
930                         "    Set bit field of a port register.\n\n"
931
932                         "write regbit (port_id) (address) (bit_x) (value)\n"
933                         "    Set single bit value of a port register.\n\n"
934                 );
935         }
936         if (show_all || !strcmp(res->section, "filters")) {
937
938                 cmdline_printf(
939                         cl,
940                         "\n"
941                         "filters:\n"
942                         "--------\n\n"
943
944 #ifdef RTE_NET_I40E
945                         "flow_director_filter (port_id) mode raw (add|del|update)"
946                         " flow (flow_id) (drop|fwd) queue (queue_id)"
947                         " fd_id (fd_id_value) packet (packet file name)\n"
948                         "    Add/Del a raw type flow director filter.\n\n"
949 #endif
950
951                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
952                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
953                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
954                         "    Set flow director IP mask.\n\n"
955
956                         "flow_director_mask (port_id) mode MAC-VLAN"
957                         " vlan (vlan_value)\n"
958                         "    Set flow director MAC-VLAN mask.\n\n"
959
960                         "flow_director_mask (port_id) mode Tunnel"
961                         " vlan (vlan_value) mac (mac_value)"
962                         " tunnel-type (tunnel_type_value)"
963                         " tunnel-id (tunnel_id_value)\n"
964                         "    Set flow director Tunnel mask.\n\n"
965
966                         "flow_director_flex_payload (port_id)"
967                         " (raw|l2|l3|l4) (config)\n"
968                         "    Configure flex payload selection.\n\n"
969
970                         "flow validate {port_id}"
971                         " [group {group_id}] [priority {level}]"
972                         " [ingress] [egress]"
973                         " pattern {item} [/ {item} [...]] / end"
974                         " actions {action} [/ {action} [...]] / end\n"
975                         "    Check whether a flow rule can be created.\n\n"
976
977                         "flow create {port_id}"
978                         " [group {group_id}] [priority {level}]"
979                         " [ingress] [egress]"
980                         " pattern {item} [/ {item} [...]] / end"
981                         " actions {action} [/ {action} [...]] / end\n"
982                         "    Create a flow rule.\n\n"
983
984                         "flow destroy {port_id} rule {rule_id} [...]\n"
985                         "    Destroy specific flow rules.\n\n"
986
987                         "flow flush {port_id}\n"
988                         "    Destroy all flow rules.\n\n"
989
990                         "flow query {port_id} {rule_id} {action}\n"
991                         "    Query an existing flow rule.\n\n"
992
993                         "flow list {port_id} [group {group_id}] [...]\n"
994                         "    List existing flow rules sorted by priority,"
995                         " filtered by group identifiers.\n\n"
996
997                         "flow isolate {port_id} {boolean}\n"
998                         "    Restrict ingress traffic to the defined"
999                         " flow rules\n\n"
1000
1001                         "flow aged {port_id} [destroy]\n"
1002                         "    List and destroy aged flows"
1003                         " flow rules\n\n"
1004
1005                         "flow indirect_action {port_id} create"
1006                         " [action_id {indirect_action_id}]"
1007                         " [ingress] [egress]"
1008                         " action {action} / end\n"
1009                         "    Create indirect action.\n\n"
1010
1011                         "flow indirect_action {port_id} update"
1012                         " {indirect_action_id} action {action} / end\n"
1013                         "    Update indirect action.\n\n"
1014
1015                         "flow indirect_action {port_id} destroy"
1016                         " action_id {indirect_action_id} [...]\n"
1017                         "    Destroy specific indirect actions.\n\n"
1018
1019                         "flow indirect_action {port_id} query"
1020                         " {indirect_action_id}\n"
1021                         "    Query an existing indirect action.\n\n"
1022
1023                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1024                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1025                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1026                         "       Configure the VXLAN encapsulation for flows.\n\n"
1027
1028                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1029                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1030                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1031                         " eth-dst (eth-dst)\n"
1032                         "       Configure the VXLAN encapsulation for flows.\n\n"
1033
1034                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1035                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1036                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1037                         " eth-dst (eth-dst)\n"
1038                         "       Configure the VXLAN encapsulation for flows.\n\n"
1039
1040                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1041                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1042                         " (eth-dst)\n"
1043                         "       Configure the NVGRE encapsulation for flows.\n\n"
1044
1045                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1046                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1047                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1048                         "       Configure the NVGRE encapsulation for flows.\n\n"
1049
1050                         "set raw_encap {flow items}\n"
1051                         "       Configure the encapsulation with raw data.\n\n"
1052
1053                         "set raw_decap {flow items}\n"
1054                         "       Configure the decapsulation with raw data.\n\n"
1055
1056                 );
1057         }
1058
1059         if (show_all || !strcmp(res->section, "traffic_management")) {
1060                 cmdline_printf(
1061                         cl,
1062                         "\n"
1063                         "Traffic Management:\n"
1064                         "--------------\n"
1065                         "show port tm cap (port_id)\n"
1066                         "       Display the port TM capability.\n\n"
1067
1068                         "show port tm level cap (port_id) (level_id)\n"
1069                         "       Display the port TM hierarchical level capability.\n\n"
1070
1071                         "show port tm node cap (port_id) (node_id)\n"
1072                         "       Display the port TM node capability.\n\n"
1073
1074                         "show port tm node type (port_id) (node_id)\n"
1075                         "       Display the port TM node type.\n\n"
1076
1077                         "show port tm node stats (port_id) (node_id) (clear)\n"
1078                         "       Display the port TM node stats.\n\n"
1079
1080                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1081                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1082                         " (packet_length_adjust) (packet_mode)\n"
1083                         "       Add port tm node private shaper profile.\n\n"
1084
1085                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1086                         "       Delete port tm node private shaper profile.\n\n"
1087
1088                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1089                         " (shaper_profile_id)\n"
1090                         "       Add/update port tm node shared shaper.\n\n"
1091
1092                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1093                         "       Delete port tm node shared shaper.\n\n"
1094
1095                         "set port tm node shaper profile (port_id) (node_id)"
1096                         " (shaper_profile_id)\n"
1097                         "       Set port tm node shaper profile.\n\n"
1098
1099                         "add port tm node wred profile (port_id) (wred_profile_id)"
1100                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1101                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1102                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1103                         "       Add port tm node wred profile.\n\n"
1104
1105                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1106                         "       Delete port tm node wred profile.\n\n"
1107
1108                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1109                         " (priority) (weight) (level_id) (shaper_profile_id)"
1110                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1111                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1112                         "       Add port tm nonleaf node.\n\n"
1113
1114                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1115                         " (priority) (weight) (level_id) (shaper_profile_id)"
1116                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1117                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1118                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1119
1120                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1121                         " (priority) (weight) (level_id) (shaper_profile_id)"
1122                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1123                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1124                         "       Add port tm leaf node.\n\n"
1125
1126                         "del port tm node (port_id) (node_id)\n"
1127                         "       Delete port tm node.\n\n"
1128
1129                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1130                         " (priority) (weight)\n"
1131                         "       Set port tm node parent.\n\n"
1132
1133                         "suspend port tm node (port_id) (node_id)"
1134                         "       Suspend tm node.\n\n"
1135
1136                         "resume port tm node (port_id) (node_id)"
1137                         "       Resume tm node.\n\n"
1138
1139                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1140                         "       Commit tm hierarchy.\n\n"
1141
1142                         "set port tm mark ip_ecn (port) (green) (yellow)"
1143                         " (red)\n"
1144                         "    Enables/Disables the traffic management marking"
1145                         " for IP ECN (Explicit Congestion Notification)"
1146                         " packets on a given port\n\n"
1147
1148                         "set port tm mark ip_dscp (port) (green) (yellow)"
1149                         " (red)\n"
1150                         "    Enables/Disables the traffic management marking"
1151                         " on the port for IP dscp packets\n\n"
1152
1153                         "set port tm mark vlan_dei (port) (green) (yellow)"
1154                         " (red)\n"
1155                         "    Enables/Disables the traffic management marking"
1156                         " on the port for VLAN packets with DEI enabled\n\n"
1157                 );
1158         }
1159
1160         if (show_all || !strcmp(res->section, "devices")) {
1161                 cmdline_printf(
1162                         cl,
1163                         "\n"
1164                         "Device Operations:\n"
1165                         "--------------\n"
1166                         "device detach (identifier)\n"
1167                         "       Detach device by identifier.\n\n"
1168                 );
1169         }
1170
1171 }
1172
1173 cmdline_parse_token_string_t cmd_help_long_help =
1174         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1175
1176 cmdline_parse_token_string_t cmd_help_long_section =
1177         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1178                         "all#control#display#config#"
1179                         "ports#registers#filters#traffic_management#devices");
1180
1181 cmdline_parse_inst_t cmd_help_long = {
1182         .f = cmd_help_long_parsed,
1183         .data = NULL,
1184         .help_str = "help all|control|display|config|ports|register|"
1185                 "filters|traffic_management|devices: "
1186                 "Show help",
1187         .tokens = {
1188                 (void *)&cmd_help_long_help,
1189                 (void *)&cmd_help_long_section,
1190                 NULL,
1191         },
1192 };
1193
1194
1195 /* *** start/stop/close all ports *** */
1196 struct cmd_operate_port_result {
1197         cmdline_fixed_string_t keyword;
1198         cmdline_fixed_string_t name;
1199         cmdline_fixed_string_t value;
1200 };
1201
1202 static void cmd_operate_port_parsed(void *parsed_result,
1203                                 __rte_unused struct cmdline *cl,
1204                                 __rte_unused void *data)
1205 {
1206         struct cmd_operate_port_result *res = parsed_result;
1207
1208         if (!strcmp(res->name, "start"))
1209                 start_port(RTE_PORT_ALL);
1210         else if (!strcmp(res->name, "stop"))
1211                 stop_port(RTE_PORT_ALL);
1212         else if (!strcmp(res->name, "close"))
1213                 close_port(RTE_PORT_ALL);
1214         else if (!strcmp(res->name, "reset"))
1215                 reset_port(RTE_PORT_ALL);
1216         else
1217                 printf("Unknown parameter\n");
1218 }
1219
1220 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1221         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1222                                                                 "port");
1223 cmdline_parse_token_string_t cmd_operate_port_all_port =
1224         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1225                                                 "start#stop#close#reset");
1226 cmdline_parse_token_string_t cmd_operate_port_all_all =
1227         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1228
1229 cmdline_parse_inst_t cmd_operate_port = {
1230         .f = cmd_operate_port_parsed,
1231         .data = NULL,
1232         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1233         .tokens = {
1234                 (void *)&cmd_operate_port_all_cmd,
1235                 (void *)&cmd_operate_port_all_port,
1236                 (void *)&cmd_operate_port_all_all,
1237                 NULL,
1238         },
1239 };
1240
1241 /* *** start/stop/close specific port *** */
1242 struct cmd_operate_specific_port_result {
1243         cmdline_fixed_string_t keyword;
1244         cmdline_fixed_string_t name;
1245         uint8_t value;
1246 };
1247
1248 static void cmd_operate_specific_port_parsed(void *parsed_result,
1249                         __rte_unused struct cmdline *cl,
1250                                 __rte_unused void *data)
1251 {
1252         struct cmd_operate_specific_port_result *res = parsed_result;
1253
1254         if (!strcmp(res->name, "start"))
1255                 start_port(res->value);
1256         else if (!strcmp(res->name, "stop"))
1257                 stop_port(res->value);
1258         else if (!strcmp(res->name, "close"))
1259                 close_port(res->value);
1260         else if (!strcmp(res->name, "reset"))
1261                 reset_port(res->value);
1262         else
1263                 printf("Unknown parameter\n");
1264 }
1265
1266 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1267         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1268                                                         keyword, "port");
1269 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1270         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1271                                                 name, "start#stop#close#reset");
1272 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1273         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1274                                                         value, RTE_UINT8);
1275
1276 cmdline_parse_inst_t cmd_operate_specific_port = {
1277         .f = cmd_operate_specific_port_parsed,
1278         .data = NULL,
1279         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1280         .tokens = {
1281                 (void *)&cmd_operate_specific_port_cmd,
1282                 (void *)&cmd_operate_specific_port_port,
1283                 (void *)&cmd_operate_specific_port_id,
1284                 NULL,
1285         },
1286 };
1287
1288 /* *** enable port setup (after attach) via iterator or event *** */
1289 struct cmd_set_port_setup_on_result {
1290         cmdline_fixed_string_t set;
1291         cmdline_fixed_string_t port;
1292         cmdline_fixed_string_t setup;
1293         cmdline_fixed_string_t on;
1294         cmdline_fixed_string_t mode;
1295 };
1296
1297 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1298                                 __rte_unused struct cmdline *cl,
1299                                 __rte_unused void *data)
1300 {
1301         struct cmd_set_port_setup_on_result *res = parsed_result;
1302
1303         if (strcmp(res->mode, "event") == 0)
1304                 setup_on_probe_event = true;
1305         else if (strcmp(res->mode, "iterator") == 0)
1306                 setup_on_probe_event = false;
1307         else
1308                 printf("Unknown mode\n");
1309 }
1310
1311 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1312         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1313                         set, "set");
1314 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1315         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1316                         port, "port");
1317 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1318         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1319                         setup, "setup");
1320 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1321         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1322                         on, "on");
1323 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1324         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1325                         mode, "iterator#event");
1326
1327 cmdline_parse_inst_t cmd_set_port_setup_on = {
1328         .f = cmd_set_port_setup_on_parsed,
1329         .data = NULL,
1330         .help_str = "set port setup on iterator|event",
1331         .tokens = {
1332                 (void *)&cmd_set_port_setup_on_set,
1333                 (void *)&cmd_set_port_setup_on_port,
1334                 (void *)&cmd_set_port_setup_on_setup,
1335                 (void *)&cmd_set_port_setup_on_on,
1336                 (void *)&cmd_set_port_setup_on_mode,
1337                 NULL,
1338         },
1339 };
1340
1341 /* *** attach a specified port *** */
1342 struct cmd_operate_attach_port_result {
1343         cmdline_fixed_string_t port;
1344         cmdline_fixed_string_t keyword;
1345         cmdline_multi_string_t identifier;
1346 };
1347
1348 static void cmd_operate_attach_port_parsed(void *parsed_result,
1349                                 __rte_unused struct cmdline *cl,
1350                                 __rte_unused void *data)
1351 {
1352         struct cmd_operate_attach_port_result *res = parsed_result;
1353
1354         if (!strcmp(res->keyword, "attach"))
1355                 attach_port(res->identifier);
1356         else
1357                 printf("Unknown parameter\n");
1358 }
1359
1360 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1361         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1362                         port, "port");
1363 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1364         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1365                         keyword, "attach");
1366 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1367         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1368                         identifier, TOKEN_STRING_MULTI);
1369
1370 cmdline_parse_inst_t cmd_operate_attach_port = {
1371         .f = cmd_operate_attach_port_parsed,
1372         .data = NULL,
1373         .help_str = "port attach <identifier>: "
1374                 "(identifier: pci address or virtual dev name)",
1375         .tokens = {
1376                 (void *)&cmd_operate_attach_port_port,
1377                 (void *)&cmd_operate_attach_port_keyword,
1378                 (void *)&cmd_operate_attach_port_identifier,
1379                 NULL,
1380         },
1381 };
1382
1383 /* *** detach a specified port *** */
1384 struct cmd_operate_detach_port_result {
1385         cmdline_fixed_string_t port;
1386         cmdline_fixed_string_t keyword;
1387         portid_t port_id;
1388 };
1389
1390 static void cmd_operate_detach_port_parsed(void *parsed_result,
1391                                 __rte_unused struct cmdline *cl,
1392                                 __rte_unused void *data)
1393 {
1394         struct cmd_operate_detach_port_result *res = parsed_result;
1395
1396         if (!strcmp(res->keyword, "detach")) {
1397                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1398                 detach_port_device(res->port_id);
1399         } else {
1400                 printf("Unknown parameter\n");
1401         }
1402 }
1403
1404 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1405         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1406                         port, "port");
1407 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1408         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1409                         keyword, "detach");
1410 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1411         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1412                         port_id, RTE_UINT16);
1413
1414 cmdline_parse_inst_t cmd_operate_detach_port = {
1415         .f = cmd_operate_detach_port_parsed,
1416         .data = NULL,
1417         .help_str = "port detach <port_id>",
1418         .tokens = {
1419                 (void *)&cmd_operate_detach_port_port,
1420                 (void *)&cmd_operate_detach_port_keyword,
1421                 (void *)&cmd_operate_detach_port_port_id,
1422                 NULL,
1423         },
1424 };
1425
1426 /* *** detach device by identifier *** */
1427 struct cmd_operate_detach_device_result {
1428         cmdline_fixed_string_t device;
1429         cmdline_fixed_string_t keyword;
1430         cmdline_fixed_string_t identifier;
1431 };
1432
1433 static void cmd_operate_detach_device_parsed(void *parsed_result,
1434                                 __rte_unused struct cmdline *cl,
1435                                 __rte_unused void *data)
1436 {
1437         struct cmd_operate_detach_device_result *res = parsed_result;
1438
1439         if (!strcmp(res->keyword, "detach"))
1440                 detach_devargs(res->identifier);
1441         else
1442                 printf("Unknown parameter\n");
1443 }
1444
1445 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1446         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1447                         device, "device");
1448 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1449         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1450                         keyword, "detach");
1451 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1452         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1453                         identifier, NULL);
1454
1455 cmdline_parse_inst_t cmd_operate_detach_device = {
1456         .f = cmd_operate_detach_device_parsed,
1457         .data = NULL,
1458         .help_str = "device detach <identifier>:"
1459                 "(identifier: pci address or virtual dev name)",
1460         .tokens = {
1461                 (void *)&cmd_operate_detach_device_device,
1462                 (void *)&cmd_operate_detach_device_keyword,
1463                 (void *)&cmd_operate_detach_device_identifier,
1464                 NULL,
1465         },
1466 };
1467 /* *** configure speed for all ports *** */
1468 struct cmd_config_speed_all {
1469         cmdline_fixed_string_t port;
1470         cmdline_fixed_string_t keyword;
1471         cmdline_fixed_string_t all;
1472         cmdline_fixed_string_t item1;
1473         cmdline_fixed_string_t item2;
1474         cmdline_fixed_string_t value1;
1475         cmdline_fixed_string_t value2;
1476 };
1477
1478 static int
1479 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1480 {
1481
1482         int duplex;
1483
1484         if (!strcmp(duplexstr, "half")) {
1485                 duplex = ETH_LINK_HALF_DUPLEX;
1486         } else if (!strcmp(duplexstr, "full")) {
1487                 duplex = ETH_LINK_FULL_DUPLEX;
1488         } else if (!strcmp(duplexstr, "auto")) {
1489                 duplex = ETH_LINK_FULL_DUPLEX;
1490         } else {
1491                 printf("Unknown duplex parameter\n");
1492                 return -1;
1493         }
1494
1495         if (!strcmp(speedstr, "10")) {
1496                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1497                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1498         } else if (!strcmp(speedstr, "100")) {
1499                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1500                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1501         } else {
1502                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1503                         printf("Invalid speed/duplex parameters\n");
1504                         return -1;
1505                 }
1506                 if (!strcmp(speedstr, "1000")) {
1507                         *speed = ETH_LINK_SPEED_1G;
1508                 } else if (!strcmp(speedstr, "10000")) {
1509                         *speed = ETH_LINK_SPEED_10G;
1510                 } else if (!strcmp(speedstr, "25000")) {
1511                         *speed = ETH_LINK_SPEED_25G;
1512                 } else if (!strcmp(speedstr, "40000")) {
1513                         *speed = ETH_LINK_SPEED_40G;
1514                 } else if (!strcmp(speedstr, "50000")) {
1515                         *speed = ETH_LINK_SPEED_50G;
1516                 } else if (!strcmp(speedstr, "100000")) {
1517                         *speed = ETH_LINK_SPEED_100G;
1518                 } else if (!strcmp(speedstr, "200000")) {
1519                         *speed = ETH_LINK_SPEED_200G;
1520                 } else if (!strcmp(speedstr, "auto")) {
1521                         *speed = ETH_LINK_SPEED_AUTONEG;
1522                 } else {
1523                         printf("Unknown speed parameter\n");
1524                         return -1;
1525                 }
1526         }
1527
1528         if (*speed != ETH_LINK_SPEED_AUTONEG)
1529                 *speed |= ETH_LINK_SPEED_FIXED;
1530
1531         return 0;
1532 }
1533
1534 static void
1535 cmd_config_speed_all_parsed(void *parsed_result,
1536                         __rte_unused struct cmdline *cl,
1537                         __rte_unused void *data)
1538 {
1539         struct cmd_config_speed_all *res = parsed_result;
1540         uint32_t link_speed;
1541         portid_t pid;
1542
1543         if (!all_ports_stopped()) {
1544                 printf("Please stop all ports first\n");
1545                 return;
1546         }
1547
1548         if (parse_and_check_speed_duplex(res->value1, res->value2,
1549                         &link_speed) < 0)
1550                 return;
1551
1552         RTE_ETH_FOREACH_DEV(pid) {
1553                 ports[pid].dev_conf.link_speeds = link_speed;
1554         }
1555
1556         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1557 }
1558
1559 cmdline_parse_token_string_t cmd_config_speed_all_port =
1560         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1561 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1562         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1563                                                         "config");
1564 cmdline_parse_token_string_t cmd_config_speed_all_all =
1565         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1566 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1568 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1569         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1570                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1571 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1572         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1573 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1574         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1575                                                 "half#full#auto");
1576
1577 cmdline_parse_inst_t cmd_config_speed_all = {
1578         .f = cmd_config_speed_all_parsed,
1579         .data = NULL,
1580         .help_str = "port config all speed "
1581                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1582                                                         "half|full|auto",
1583         .tokens = {
1584                 (void *)&cmd_config_speed_all_port,
1585                 (void *)&cmd_config_speed_all_keyword,
1586                 (void *)&cmd_config_speed_all_all,
1587                 (void *)&cmd_config_speed_all_item1,
1588                 (void *)&cmd_config_speed_all_value1,
1589                 (void *)&cmd_config_speed_all_item2,
1590                 (void *)&cmd_config_speed_all_value2,
1591                 NULL,
1592         },
1593 };
1594
1595 /* *** configure speed for specific port *** */
1596 struct cmd_config_speed_specific {
1597         cmdline_fixed_string_t port;
1598         cmdline_fixed_string_t keyword;
1599         portid_t id;
1600         cmdline_fixed_string_t item1;
1601         cmdline_fixed_string_t item2;
1602         cmdline_fixed_string_t value1;
1603         cmdline_fixed_string_t value2;
1604 };
1605
1606 static void
1607 cmd_config_speed_specific_parsed(void *parsed_result,
1608                                 __rte_unused struct cmdline *cl,
1609                                 __rte_unused void *data)
1610 {
1611         struct cmd_config_speed_specific *res = parsed_result;
1612         uint32_t link_speed;
1613
1614         if (!all_ports_stopped()) {
1615                 printf("Please stop all ports first\n");
1616                 return;
1617         }
1618
1619         if (port_id_is_invalid(res->id, ENABLED_WARN))
1620                 return;
1621
1622         if (parse_and_check_speed_duplex(res->value1, res->value2,
1623                         &link_speed) < 0)
1624                 return;
1625
1626         ports[res->id].dev_conf.link_speeds = link_speed;
1627
1628         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1629 }
1630
1631
1632 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1633         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1634                                                                 "port");
1635 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1636         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1637                                                                 "config");
1638 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1639         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1640 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1641         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1642                                                                 "speed");
1643 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1644         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1645                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1646 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1648                                                                 "duplex");
1649 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1650         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1651                                                         "half#full#auto");
1652
1653 cmdline_parse_inst_t cmd_config_speed_specific = {
1654         .f = cmd_config_speed_specific_parsed,
1655         .data = NULL,
1656         .help_str = "port config <port_id> speed "
1657                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1658                                                         "half|full|auto",
1659         .tokens = {
1660                 (void *)&cmd_config_speed_specific_port,
1661                 (void *)&cmd_config_speed_specific_keyword,
1662                 (void *)&cmd_config_speed_specific_id,
1663                 (void *)&cmd_config_speed_specific_item1,
1664                 (void *)&cmd_config_speed_specific_value1,
1665                 (void *)&cmd_config_speed_specific_item2,
1666                 (void *)&cmd_config_speed_specific_value2,
1667                 NULL,
1668         },
1669 };
1670
1671 /* *** configure loopback for all ports *** */
1672 struct cmd_config_loopback_all {
1673         cmdline_fixed_string_t port;
1674         cmdline_fixed_string_t keyword;
1675         cmdline_fixed_string_t all;
1676         cmdline_fixed_string_t item;
1677         uint32_t mode;
1678 };
1679
1680 static void
1681 cmd_config_loopback_all_parsed(void *parsed_result,
1682                         __rte_unused struct cmdline *cl,
1683                         __rte_unused void *data)
1684 {
1685         struct cmd_config_loopback_all *res = parsed_result;
1686         portid_t pid;
1687
1688         if (!all_ports_stopped()) {
1689                 printf("Please stop all ports first\n");
1690                 return;
1691         }
1692
1693         RTE_ETH_FOREACH_DEV(pid) {
1694                 ports[pid].dev_conf.lpbk_mode = res->mode;
1695         }
1696
1697         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1698 }
1699
1700 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1701         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1702 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1703         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1704                                                         "config");
1705 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1706         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1707 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1708         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1709                                                         "loopback");
1710 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1711         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1712
1713 cmdline_parse_inst_t cmd_config_loopback_all = {
1714         .f = cmd_config_loopback_all_parsed,
1715         .data = NULL,
1716         .help_str = "port config all loopback <mode>",
1717         .tokens = {
1718                 (void *)&cmd_config_loopback_all_port,
1719                 (void *)&cmd_config_loopback_all_keyword,
1720                 (void *)&cmd_config_loopback_all_all,
1721                 (void *)&cmd_config_loopback_all_item,
1722                 (void *)&cmd_config_loopback_all_mode,
1723                 NULL,
1724         },
1725 };
1726
1727 /* *** configure loopback for specific port *** */
1728 struct cmd_config_loopback_specific {
1729         cmdline_fixed_string_t port;
1730         cmdline_fixed_string_t keyword;
1731         uint16_t port_id;
1732         cmdline_fixed_string_t item;
1733         uint32_t mode;
1734 };
1735
1736 static void
1737 cmd_config_loopback_specific_parsed(void *parsed_result,
1738                                 __rte_unused struct cmdline *cl,
1739                                 __rte_unused void *data)
1740 {
1741         struct cmd_config_loopback_specific *res = parsed_result;
1742
1743         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1744                 return;
1745
1746         if (!port_is_stopped(res->port_id)) {
1747                 printf("Please stop port %u first\n", res->port_id);
1748                 return;
1749         }
1750
1751         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1752
1753         cmd_reconfig_device_queue(res->port_id, 1, 1);
1754 }
1755
1756
1757 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1758         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1759                                                                 "port");
1760 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1761         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1762                                                                 "config");
1763 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1764         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1765                                                                 RTE_UINT16);
1766 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1767         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1768                                                                 "loopback");
1769 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1770         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1771                               RTE_UINT32);
1772
1773 cmdline_parse_inst_t cmd_config_loopback_specific = {
1774         .f = cmd_config_loopback_specific_parsed,
1775         .data = NULL,
1776         .help_str = "port config <port_id> loopback <mode>",
1777         .tokens = {
1778                 (void *)&cmd_config_loopback_specific_port,
1779                 (void *)&cmd_config_loopback_specific_keyword,
1780                 (void *)&cmd_config_loopback_specific_id,
1781                 (void *)&cmd_config_loopback_specific_item,
1782                 (void *)&cmd_config_loopback_specific_mode,
1783                 NULL,
1784         },
1785 };
1786
1787 /* *** configure txq/rxq, txd/rxd *** */
1788 struct cmd_config_rx_tx {
1789         cmdline_fixed_string_t port;
1790         cmdline_fixed_string_t keyword;
1791         cmdline_fixed_string_t all;
1792         cmdline_fixed_string_t name;
1793         uint16_t value;
1794 };
1795
1796 static void
1797 cmd_config_rx_tx_parsed(void *parsed_result,
1798                         __rte_unused struct cmdline *cl,
1799                         __rte_unused void *data)
1800 {
1801         struct cmd_config_rx_tx *res = parsed_result;
1802
1803         if (!all_ports_stopped()) {
1804                 printf("Please stop all ports first\n");
1805                 return;
1806         }
1807         if (!strcmp(res->name, "rxq")) {
1808                 if (!res->value && !nb_txq) {
1809                         printf("Warning: Either rx or tx queues should be non zero\n");
1810                         return;
1811                 }
1812                 if (check_nb_rxq(res->value) != 0)
1813                         return;
1814                 nb_rxq = res->value;
1815         }
1816         else if (!strcmp(res->name, "txq")) {
1817                 if (!res->value && !nb_rxq) {
1818                         printf("Warning: Either rx or tx queues should be non zero\n");
1819                         return;
1820                 }
1821                 if (check_nb_txq(res->value) != 0)
1822                         return;
1823                 nb_txq = res->value;
1824         }
1825         else if (!strcmp(res->name, "rxd")) {
1826                 if (check_nb_rxd(res->value) != 0)
1827                         return;
1828                 nb_rxd = res->value;
1829         } else if (!strcmp(res->name, "txd")) {
1830                 if (check_nb_txd(res->value) != 0)
1831                         return;
1832
1833                 nb_txd = res->value;
1834         } else {
1835                 printf("Unknown parameter\n");
1836                 return;
1837         }
1838
1839         fwd_config_setup();
1840
1841         init_port_config();
1842
1843         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1844 }
1845
1846 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1848 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1850 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1851         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1852 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1853         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1854                                                 "rxq#txq#rxd#txd");
1855 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1856         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1857
1858 cmdline_parse_inst_t cmd_config_rx_tx = {
1859         .f = cmd_config_rx_tx_parsed,
1860         .data = NULL,
1861         .help_str = "port config all rxq|txq|rxd|txd <value>",
1862         .tokens = {
1863                 (void *)&cmd_config_rx_tx_port,
1864                 (void *)&cmd_config_rx_tx_keyword,
1865                 (void *)&cmd_config_rx_tx_all,
1866                 (void *)&cmd_config_rx_tx_name,
1867                 (void *)&cmd_config_rx_tx_value,
1868                 NULL,
1869         },
1870 };
1871
1872 /* *** config max packet length *** */
1873 struct cmd_config_max_pkt_len_result {
1874         cmdline_fixed_string_t port;
1875         cmdline_fixed_string_t keyword;
1876         cmdline_fixed_string_t all;
1877         cmdline_fixed_string_t name;
1878         uint32_t value;
1879 };
1880
1881 static void
1882 cmd_config_max_pkt_len_parsed(void *parsed_result,
1883                                 __rte_unused struct cmdline *cl,
1884                                 __rte_unused void *data)
1885 {
1886         struct cmd_config_max_pkt_len_result *res = parsed_result;
1887         uint32_t max_rx_pkt_len_backup = 0;
1888         portid_t pid;
1889         int ret;
1890
1891         if (!all_ports_stopped()) {
1892                 printf("Please stop all ports first\n");
1893                 return;
1894         }
1895
1896         RTE_ETH_FOREACH_DEV(pid) {
1897                 struct rte_port *port = &ports[pid];
1898
1899                 if (!strcmp(res->name, "max-pkt-len")) {
1900                         if (res->value < RTE_ETHER_MIN_LEN) {
1901                                 printf("max-pkt-len can not be less than %d\n",
1902                                                 RTE_ETHER_MIN_LEN);
1903                                 return;
1904                         }
1905                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1906                                 return;
1907
1908                         ret = eth_dev_info_get_print_err(pid, &port->dev_info);
1909                         if (ret != 0) {
1910                                 printf("rte_eth_dev_info_get() failed for port %u\n",
1911                                         pid);
1912                                 return;
1913                         }
1914
1915                         max_rx_pkt_len_backup = port->dev_conf.rxmode.max_rx_pkt_len;
1916
1917                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1918                         if (update_jumbo_frame_offload(pid) != 0)
1919                                 port->dev_conf.rxmode.max_rx_pkt_len = max_rx_pkt_len_backup;
1920                 } else {
1921                         printf("Unknown parameter\n");
1922                         return;
1923                 }
1924         }
1925
1926         init_port_config();
1927
1928         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1929 }
1930
1931 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1932         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1933                                                                 "port");
1934 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1935         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1936                                                                 "config");
1937 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1938         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1939                                                                 "all");
1940 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1941         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1942                                                                 "max-pkt-len");
1943 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1944         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1945                                                                 RTE_UINT32);
1946
1947 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1948         .f = cmd_config_max_pkt_len_parsed,
1949         .data = NULL,
1950         .help_str = "port config all max-pkt-len <value>",
1951         .tokens = {
1952                 (void *)&cmd_config_max_pkt_len_port,
1953                 (void *)&cmd_config_max_pkt_len_keyword,
1954                 (void *)&cmd_config_max_pkt_len_all,
1955                 (void *)&cmd_config_max_pkt_len_name,
1956                 (void *)&cmd_config_max_pkt_len_value,
1957                 NULL,
1958         },
1959 };
1960
1961 /* *** config max LRO aggregated packet size *** */
1962 struct cmd_config_max_lro_pkt_size_result {
1963         cmdline_fixed_string_t port;
1964         cmdline_fixed_string_t keyword;
1965         cmdline_fixed_string_t all;
1966         cmdline_fixed_string_t name;
1967         uint32_t value;
1968 };
1969
1970 static void
1971 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1972                                 __rte_unused struct cmdline *cl,
1973                                 __rte_unused void *data)
1974 {
1975         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1976         portid_t pid;
1977
1978         if (!all_ports_stopped()) {
1979                 printf("Please stop all ports first\n");
1980                 return;
1981         }
1982
1983         RTE_ETH_FOREACH_DEV(pid) {
1984                 struct rte_port *port = &ports[pid];
1985
1986                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1987                         if (res->value ==
1988                                         port->dev_conf.rxmode.max_lro_pkt_size)
1989                                 return;
1990
1991                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1992                 } else {
1993                         printf("Unknown parameter\n");
1994                         return;
1995                 }
1996         }
1997
1998         init_port_config();
1999
2000         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2001 }
2002
2003 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2004         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2005                                  port, "port");
2006 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2007         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2008                                  keyword, "config");
2009 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2010         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2011                                  all, "all");
2012 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2013         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2014                                  name, "max-lro-pkt-size");
2015 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2016         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2017                               value, RTE_UINT32);
2018
2019 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2020         .f = cmd_config_max_lro_pkt_size_parsed,
2021         .data = NULL,
2022         .help_str = "port config all max-lro-pkt-size <value>",
2023         .tokens = {
2024                 (void *)&cmd_config_max_lro_pkt_size_port,
2025                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2026                 (void *)&cmd_config_max_lro_pkt_size_all,
2027                 (void *)&cmd_config_max_lro_pkt_size_name,
2028                 (void *)&cmd_config_max_lro_pkt_size_value,
2029                 NULL,
2030         },
2031 };
2032
2033 /* *** configure port MTU *** */
2034 struct cmd_config_mtu_result {
2035         cmdline_fixed_string_t port;
2036         cmdline_fixed_string_t keyword;
2037         cmdline_fixed_string_t mtu;
2038         portid_t port_id;
2039         uint16_t value;
2040 };
2041
2042 static void
2043 cmd_config_mtu_parsed(void *parsed_result,
2044                       __rte_unused struct cmdline *cl,
2045                       __rte_unused void *data)
2046 {
2047         struct cmd_config_mtu_result *res = parsed_result;
2048
2049         if (res->value < RTE_ETHER_MIN_LEN) {
2050                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2051                 return;
2052         }
2053         port_mtu_set(res->port_id, res->value);
2054 }
2055
2056 cmdline_parse_token_string_t cmd_config_mtu_port =
2057         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2058                                  "port");
2059 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2060         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2061                                  "config");
2062 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2063         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2064                                  "mtu");
2065 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2066         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2067                                  RTE_UINT16);
2068 cmdline_parse_token_num_t cmd_config_mtu_value =
2069         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2070                                  RTE_UINT16);
2071
2072 cmdline_parse_inst_t cmd_config_mtu = {
2073         .f = cmd_config_mtu_parsed,
2074         .data = NULL,
2075         .help_str = "port config mtu <port_id> <value>",
2076         .tokens = {
2077                 (void *)&cmd_config_mtu_port,
2078                 (void *)&cmd_config_mtu_keyword,
2079                 (void *)&cmd_config_mtu_mtu,
2080                 (void *)&cmd_config_mtu_port_id,
2081                 (void *)&cmd_config_mtu_value,
2082                 NULL,
2083         },
2084 };
2085
2086 /* *** configure rx mode *** */
2087 struct cmd_config_rx_mode_flag {
2088         cmdline_fixed_string_t port;
2089         cmdline_fixed_string_t keyword;
2090         cmdline_fixed_string_t all;
2091         cmdline_fixed_string_t name;
2092         cmdline_fixed_string_t value;
2093 };
2094
2095 static void
2096 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2097                                 __rte_unused struct cmdline *cl,
2098                                 __rte_unused void *data)
2099 {
2100         struct cmd_config_rx_mode_flag *res = parsed_result;
2101
2102         if (!all_ports_stopped()) {
2103                 printf("Please stop all ports first\n");
2104                 return;
2105         }
2106
2107         if (!strcmp(res->name, "drop-en")) {
2108                 if (!strcmp(res->value, "on"))
2109                         rx_drop_en = 1;
2110                 else if (!strcmp(res->value, "off"))
2111                         rx_drop_en = 0;
2112                 else {
2113                         printf("Unknown parameter\n");
2114                         return;
2115                 }
2116         } else {
2117                 printf("Unknown parameter\n");
2118                 return;
2119         }
2120
2121         init_port_config();
2122
2123         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2124 }
2125
2126 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2127         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2128 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2129         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2130                                                                 "config");
2131 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2132         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2133 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2134         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2135                                         "drop-en");
2136 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2137         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2138                                                         "on#off");
2139
2140 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2141         .f = cmd_config_rx_mode_flag_parsed,
2142         .data = NULL,
2143         .help_str = "port config all drop-en on|off",
2144         .tokens = {
2145                 (void *)&cmd_config_rx_mode_flag_port,
2146                 (void *)&cmd_config_rx_mode_flag_keyword,
2147                 (void *)&cmd_config_rx_mode_flag_all,
2148                 (void *)&cmd_config_rx_mode_flag_name,
2149                 (void *)&cmd_config_rx_mode_flag_value,
2150                 NULL,
2151         },
2152 };
2153
2154 /* *** configure rss *** */
2155 struct cmd_config_rss {
2156         cmdline_fixed_string_t port;
2157         cmdline_fixed_string_t keyword;
2158         cmdline_fixed_string_t all;
2159         cmdline_fixed_string_t name;
2160         cmdline_fixed_string_t value;
2161 };
2162
2163 static void
2164 cmd_config_rss_parsed(void *parsed_result,
2165                         __rte_unused struct cmdline *cl,
2166                         __rte_unused void *data)
2167 {
2168         struct cmd_config_rss *res = parsed_result;
2169         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2170         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2171         int use_default = 0;
2172         int all_updated = 1;
2173         int diag;
2174         uint16_t i;
2175         int ret;
2176
2177         if (!strcmp(res->value, "all"))
2178                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2179                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2180                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2181                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU |
2182                         ETH_RSS_ECPRI;
2183         else if (!strcmp(res->value, "eth"))
2184                 rss_conf.rss_hf = ETH_RSS_ETH;
2185         else if (!strcmp(res->value, "vlan"))
2186                 rss_conf.rss_hf = ETH_RSS_VLAN;
2187         else if (!strcmp(res->value, "ip"))
2188                 rss_conf.rss_hf = ETH_RSS_IP;
2189         else if (!strcmp(res->value, "udp"))
2190                 rss_conf.rss_hf = ETH_RSS_UDP;
2191         else if (!strcmp(res->value, "tcp"))
2192                 rss_conf.rss_hf = ETH_RSS_TCP;
2193         else if (!strcmp(res->value, "sctp"))
2194                 rss_conf.rss_hf = ETH_RSS_SCTP;
2195         else if (!strcmp(res->value, "ether"))
2196                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2197         else if (!strcmp(res->value, "port"))
2198                 rss_conf.rss_hf = ETH_RSS_PORT;
2199         else if (!strcmp(res->value, "vxlan"))
2200                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2201         else if (!strcmp(res->value, "geneve"))
2202                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2203         else if (!strcmp(res->value, "nvgre"))
2204                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2205         else if (!strcmp(res->value, "l3-pre32"))
2206                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2207         else if (!strcmp(res->value, "l3-pre40"))
2208                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2209         else if (!strcmp(res->value, "l3-pre48"))
2210                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2211         else if (!strcmp(res->value, "l3-pre56"))
2212                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2213         else if (!strcmp(res->value, "l3-pre64"))
2214                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2215         else if (!strcmp(res->value, "l3-pre96"))
2216                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2217         else if (!strcmp(res->value, "l3-src-only"))
2218                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2219         else if (!strcmp(res->value, "l3-dst-only"))
2220                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2221         else if (!strcmp(res->value, "l4-src-only"))
2222                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2223         else if (!strcmp(res->value, "l4-dst-only"))
2224                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2225         else if (!strcmp(res->value, "l2-src-only"))
2226                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2227         else if (!strcmp(res->value, "l2-dst-only"))
2228                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2229         else if (!strcmp(res->value, "l2tpv3"))
2230                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2231         else if (!strcmp(res->value, "esp"))
2232                 rss_conf.rss_hf = ETH_RSS_ESP;
2233         else if (!strcmp(res->value, "ah"))
2234                 rss_conf.rss_hf = ETH_RSS_AH;
2235         else if (!strcmp(res->value, "pfcp"))
2236                 rss_conf.rss_hf = ETH_RSS_PFCP;
2237         else if (!strcmp(res->value, "pppoe"))
2238                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2239         else if (!strcmp(res->value, "gtpu"))
2240                 rss_conf.rss_hf = ETH_RSS_GTPU;
2241         else if (!strcmp(res->value, "ecpri"))
2242                 rss_conf.rss_hf = ETH_RSS_ECPRI;
2243         else if (!strcmp(res->value, "mpls"))
2244                 rss_conf.rss_hf = ETH_RSS_MPLS;
2245         else if (!strcmp(res->value, "none"))
2246                 rss_conf.rss_hf = 0;
2247         else if (!strcmp(res->value, "level-default")) {
2248                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2249                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2250         } else if (!strcmp(res->value, "level-outer")) {
2251                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2252                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2253         } else if (!strcmp(res->value, "level-inner")) {
2254                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2255                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2256         } else if (!strcmp(res->value, "default"))
2257                 use_default = 1;
2258         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2259                                                 atoi(res->value) < 64)
2260                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2261         else {
2262                 printf("Unknown parameter\n");
2263                 return;
2264         }
2265         rss_conf.rss_key = NULL;
2266         /* Update global configuration for RSS types. */
2267         RTE_ETH_FOREACH_DEV(i) {
2268                 struct rte_eth_rss_conf local_rss_conf;
2269
2270                 ret = eth_dev_info_get_print_err(i, &dev_info);
2271                 if (ret != 0)
2272                         return;
2273
2274                 if (use_default)
2275                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2276
2277                 local_rss_conf = rss_conf;
2278                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2279                         dev_info.flow_type_rss_offloads;
2280                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2281                         printf("Port %u modified RSS hash function based on hardware support,"
2282                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2283                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2284                 }
2285                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2286                 if (diag < 0) {
2287                         all_updated = 0;
2288                         printf("Configuration of RSS hash at ethernet port %d "
2289                                 "failed with error (%d): %s.\n",
2290                                 i, -diag, strerror(-diag));
2291                 }
2292         }
2293         if (all_updated && !use_default) {
2294                 rss_hf = rss_conf.rss_hf;
2295                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2296         }
2297 }
2298
2299 cmdline_parse_token_string_t cmd_config_rss_port =
2300         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2301 cmdline_parse_token_string_t cmd_config_rss_keyword =
2302         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2303 cmdline_parse_token_string_t cmd_config_rss_all =
2304         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2305 cmdline_parse_token_string_t cmd_config_rss_name =
2306         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2307 cmdline_parse_token_string_t cmd_config_rss_value =
2308         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2309
2310 cmdline_parse_inst_t cmd_config_rss = {
2311         .f = cmd_config_rss_parsed,
2312         .data = NULL,
2313         .help_str = "port config all rss "
2314                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2315                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2316                 "level-outer|level-inner|<flowtype_id>",
2317         .tokens = {
2318                 (void *)&cmd_config_rss_port,
2319                 (void *)&cmd_config_rss_keyword,
2320                 (void *)&cmd_config_rss_all,
2321                 (void *)&cmd_config_rss_name,
2322                 (void *)&cmd_config_rss_value,
2323                 NULL,
2324         },
2325 };
2326
2327 /* *** configure rss hash key *** */
2328 struct cmd_config_rss_hash_key {
2329         cmdline_fixed_string_t port;
2330         cmdline_fixed_string_t config;
2331         portid_t port_id;
2332         cmdline_fixed_string_t rss_hash_key;
2333         cmdline_fixed_string_t rss_type;
2334         cmdline_fixed_string_t key;
2335 };
2336
2337 static uint8_t
2338 hexa_digit_to_value(char hexa_digit)
2339 {
2340         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2341                 return (uint8_t) (hexa_digit - '0');
2342         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2343                 return (uint8_t) ((hexa_digit - 'a') + 10);
2344         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2345                 return (uint8_t) ((hexa_digit - 'A') + 10);
2346         /* Invalid hexa digit */
2347         return 0xFF;
2348 }
2349
2350 static uint8_t
2351 parse_and_check_key_hexa_digit(char *key, int idx)
2352 {
2353         uint8_t hexa_v;
2354
2355         hexa_v = hexa_digit_to_value(key[idx]);
2356         if (hexa_v == 0xFF)
2357                 printf("invalid key: character %c at position %d is not a "
2358                        "valid hexa digit\n", key[idx], idx);
2359         return hexa_v;
2360 }
2361
2362 static void
2363 cmd_config_rss_hash_key_parsed(void *parsed_result,
2364                                __rte_unused struct cmdline *cl,
2365                                __rte_unused void *data)
2366 {
2367         struct cmd_config_rss_hash_key *res = parsed_result;
2368         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2369         uint8_t xdgt0;
2370         uint8_t xdgt1;
2371         int i;
2372         struct rte_eth_dev_info dev_info;
2373         uint8_t hash_key_size;
2374         uint32_t key_len;
2375         int ret;
2376
2377         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2378         if (ret != 0)
2379                 return;
2380
2381         if (dev_info.hash_key_size > 0 &&
2382                         dev_info.hash_key_size <= sizeof(hash_key))
2383                 hash_key_size = dev_info.hash_key_size;
2384         else {
2385                 printf("dev_info did not provide a valid hash key size\n");
2386                 return;
2387         }
2388         /* Check the length of the RSS hash key */
2389         key_len = strlen(res->key);
2390         if (key_len != (hash_key_size * 2)) {
2391                 printf("key length: %d invalid - key must be a string of %d"
2392                            " hexa-decimal numbers\n",
2393                            (int) key_len, hash_key_size * 2);
2394                 return;
2395         }
2396         /* Translate RSS hash key into binary representation */
2397         for (i = 0; i < hash_key_size; i++) {
2398                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2399                 if (xdgt0 == 0xFF)
2400                         return;
2401                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2402                 if (xdgt1 == 0xFF)
2403                         return;
2404                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2405         }
2406         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2407                         hash_key_size);
2408 }
2409
2410 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2411         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2412 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2413         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2414                                  "config");
2415 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2416         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2417                                  RTE_UINT16);
2418 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2419         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2420                                  rss_hash_key, "rss-hash-key");
2421 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2422         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2423                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2424                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2425                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2426                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2427                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2428                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2429                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls");
2430 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2431         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2432
2433 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2434         .f = cmd_config_rss_hash_key_parsed,
2435         .data = NULL,
2436         .help_str = "port config <port_id> rss-hash-key "
2437                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2438                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2439                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2440                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2441                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2442                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls "
2443                 "<string of hex digits (variable length, NIC dependent)>",
2444         .tokens = {
2445                 (void *)&cmd_config_rss_hash_key_port,
2446                 (void *)&cmd_config_rss_hash_key_config,
2447                 (void *)&cmd_config_rss_hash_key_port_id,
2448                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2449                 (void *)&cmd_config_rss_hash_key_rss_type,
2450                 (void *)&cmd_config_rss_hash_key_value,
2451                 NULL,
2452         },
2453 };
2454
2455 /* *** configure port rxq/txq ring size *** */
2456 struct cmd_config_rxtx_ring_size {
2457         cmdline_fixed_string_t port;
2458         cmdline_fixed_string_t config;
2459         portid_t portid;
2460         cmdline_fixed_string_t rxtxq;
2461         uint16_t qid;
2462         cmdline_fixed_string_t rsize;
2463         uint16_t size;
2464 };
2465
2466 static void
2467 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2468                                  __rte_unused struct cmdline *cl,
2469                                  __rte_unused void *data)
2470 {
2471         struct cmd_config_rxtx_ring_size *res = parsed_result;
2472         struct rte_port *port;
2473         uint8_t isrx;
2474
2475         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2476                 return;
2477
2478         if (res->portid == (portid_t)RTE_PORT_ALL) {
2479                 printf("Invalid port id\n");
2480                 return;
2481         }
2482
2483         port = &ports[res->portid];
2484
2485         if (!strcmp(res->rxtxq, "rxq"))
2486                 isrx = 1;
2487         else if (!strcmp(res->rxtxq, "txq"))
2488                 isrx = 0;
2489         else {
2490                 printf("Unknown parameter\n");
2491                 return;
2492         }
2493
2494         if (isrx && rx_queue_id_is_invalid(res->qid))
2495                 return;
2496         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2497                 return;
2498
2499         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2500                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2501                        rx_free_thresh);
2502                 return;
2503         }
2504
2505         if (isrx)
2506                 port->nb_rx_desc[res->qid] = res->size;
2507         else
2508                 port->nb_tx_desc[res->qid] = res->size;
2509
2510         cmd_reconfig_device_queue(res->portid, 0, 1);
2511 }
2512
2513 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2514         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2515                                  port, "port");
2516 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2517         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2518                                  config, "config");
2519 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2520         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2521                                  portid, RTE_UINT16);
2522 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2523         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2524                                  rxtxq, "rxq#txq");
2525 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2526         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2527                               qid, RTE_UINT16);
2528 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2529         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2530                                  rsize, "ring_size");
2531 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2532         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2533                               size, RTE_UINT16);
2534
2535 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2536         .f = cmd_config_rxtx_ring_size_parsed,
2537         .data = NULL,
2538         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2539         .tokens = {
2540                 (void *)&cmd_config_rxtx_ring_size_port,
2541                 (void *)&cmd_config_rxtx_ring_size_config,
2542                 (void *)&cmd_config_rxtx_ring_size_portid,
2543                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2544                 (void *)&cmd_config_rxtx_ring_size_qid,
2545                 (void *)&cmd_config_rxtx_ring_size_rsize,
2546                 (void *)&cmd_config_rxtx_ring_size_size,
2547                 NULL,
2548         },
2549 };
2550
2551 /* *** configure port rxq/txq start/stop *** */
2552 struct cmd_config_rxtx_queue {
2553         cmdline_fixed_string_t port;
2554         portid_t portid;
2555         cmdline_fixed_string_t rxtxq;
2556         uint16_t qid;
2557         cmdline_fixed_string_t opname;
2558 };
2559
2560 static void
2561 cmd_config_rxtx_queue_parsed(void *parsed_result,
2562                         __rte_unused struct cmdline *cl,
2563                         __rte_unused void *data)
2564 {
2565         struct cmd_config_rxtx_queue *res = parsed_result;
2566         uint8_t isrx;
2567         uint8_t isstart;
2568         int ret = 0;
2569
2570         if (test_done == 0) {
2571                 printf("Please stop forwarding first\n");
2572                 return;
2573         }
2574
2575         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2576                 return;
2577
2578         if (port_is_started(res->portid) != 1) {
2579                 printf("Please start port %u first\n", res->portid);
2580                 return;
2581         }
2582
2583         if (!strcmp(res->rxtxq, "rxq"))
2584                 isrx = 1;
2585         else if (!strcmp(res->rxtxq, "txq"))
2586                 isrx = 0;
2587         else {
2588                 printf("Unknown parameter\n");
2589                 return;
2590         }
2591
2592         if (isrx && rx_queue_id_is_invalid(res->qid))
2593                 return;
2594         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2595                 return;
2596
2597         if (!strcmp(res->opname, "start"))
2598                 isstart = 1;
2599         else if (!strcmp(res->opname, "stop"))
2600                 isstart = 0;
2601         else {
2602                 printf("Unknown parameter\n");
2603                 return;
2604         }
2605
2606         if (isstart && isrx)
2607                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2608         else if (!isstart && isrx)
2609                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2610         else if (isstart && !isrx)
2611                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2612         else
2613                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2614
2615         if (ret == -ENOTSUP)
2616                 printf("Function not supported in PMD driver\n");
2617 }
2618
2619 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2620         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2621 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2622         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2623 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2624         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2625 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2626         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2627 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2628         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2629                                                 "start#stop");
2630
2631 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2632         .f = cmd_config_rxtx_queue_parsed,
2633         .data = NULL,
2634         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2635         .tokens = {
2636                 (void *)&cmd_config_rxtx_queue_port,
2637                 (void *)&cmd_config_rxtx_queue_portid,
2638                 (void *)&cmd_config_rxtx_queue_rxtxq,
2639                 (void *)&cmd_config_rxtx_queue_qid,
2640                 (void *)&cmd_config_rxtx_queue_opname,
2641                 NULL,
2642         },
2643 };
2644
2645 /* *** configure port rxq/txq deferred start on/off *** */
2646 struct cmd_config_deferred_start_rxtx_queue {
2647         cmdline_fixed_string_t port;
2648         portid_t port_id;
2649         cmdline_fixed_string_t rxtxq;
2650         uint16_t qid;
2651         cmdline_fixed_string_t opname;
2652         cmdline_fixed_string_t state;
2653 };
2654
2655 static void
2656 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2657                         __rte_unused struct cmdline *cl,
2658                         __rte_unused void *data)
2659 {
2660         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2661         struct rte_port *port;
2662         uint8_t isrx;
2663         uint8_t ison;
2664         uint8_t needreconfig = 0;
2665
2666         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2667                 return;
2668
2669         if (port_is_started(res->port_id) != 0) {
2670                 printf("Please stop port %u first\n", res->port_id);
2671                 return;
2672         }
2673
2674         port = &ports[res->port_id];
2675
2676         isrx = !strcmp(res->rxtxq, "rxq");
2677
2678         if (isrx && rx_queue_id_is_invalid(res->qid))
2679                 return;
2680         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2681                 return;
2682
2683         ison = !strcmp(res->state, "on");
2684
2685         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2686                 port->rx_conf[res->qid].rx_deferred_start = ison;
2687                 needreconfig = 1;
2688         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2689                 port->tx_conf[res->qid].tx_deferred_start = ison;
2690                 needreconfig = 1;
2691         }
2692
2693         if (needreconfig)
2694                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2695 }
2696
2697 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2698         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2699                                                 port, "port");
2700 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2701         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2702                                                 port_id, RTE_UINT16);
2703 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2704         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2705                                                 rxtxq, "rxq#txq");
2706 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2707         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2708                                                 qid, RTE_UINT16);
2709 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2710         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2711                                                 opname, "deferred_start");
2712 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2713         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2714                                                 state, "on#off");
2715
2716 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2717         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2718         .data = NULL,
2719         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2720         .tokens = {
2721                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2722                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2723                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2724                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2725                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2726                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2727                 NULL,
2728         },
2729 };
2730
2731 /* *** configure port rxq/txq setup *** */
2732 struct cmd_setup_rxtx_queue {
2733         cmdline_fixed_string_t port;
2734         portid_t portid;
2735         cmdline_fixed_string_t rxtxq;
2736         uint16_t qid;
2737         cmdline_fixed_string_t setup;
2738 };
2739
2740 /* Common CLI fields for queue setup */
2741 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2742         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2743 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2744         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2745 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2746         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2747 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2748         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2749 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2750         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2751
2752 static void
2753 cmd_setup_rxtx_queue_parsed(
2754         void *parsed_result,
2755         __rte_unused struct cmdline *cl,
2756         __rte_unused void *data)
2757 {
2758         struct cmd_setup_rxtx_queue *res = parsed_result;
2759         struct rte_port *port;
2760         struct rte_mempool *mp;
2761         unsigned int socket_id;
2762         uint8_t isrx = 0;
2763         int ret;
2764
2765         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2766                 return;
2767
2768         if (res->portid == (portid_t)RTE_PORT_ALL) {
2769                 printf("Invalid port id\n");
2770                 return;
2771         }
2772
2773         if (!strcmp(res->rxtxq, "rxq"))
2774                 isrx = 1;
2775         else if (!strcmp(res->rxtxq, "txq"))
2776                 isrx = 0;
2777         else {
2778                 printf("Unknown parameter\n");
2779                 return;
2780         }
2781
2782         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2783                 printf("Invalid rx queue\n");
2784                 return;
2785         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2786                 printf("Invalid tx queue\n");
2787                 return;
2788         }
2789
2790         port = &ports[res->portid];
2791         if (isrx) {
2792                 socket_id = rxring_numa[res->portid];
2793                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2794                         socket_id = port->socket_id;
2795
2796                 mp = mbuf_pool_find(socket_id, 0);
2797                 if (mp == NULL) {
2798                         printf("Failed to setup RX queue: "
2799                                 "No mempool allocation"
2800                                 " on the socket %d\n",
2801                                 rxring_numa[res->portid]);
2802                         return;
2803                 }
2804                 ret = rx_queue_setup(res->portid,
2805                                      res->qid,
2806                                      port->nb_rx_desc[res->qid],
2807                                      socket_id,
2808                                      &port->rx_conf[res->qid],
2809                                      mp);
2810                 if (ret)
2811                         printf("Failed to setup RX queue\n");
2812         } else {
2813                 socket_id = txring_numa[res->portid];
2814                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2815                         socket_id = port->socket_id;
2816
2817                 ret = rte_eth_tx_queue_setup(res->portid,
2818                                              res->qid,
2819                                              port->nb_tx_desc[res->qid],
2820                                              socket_id,
2821                                              &port->tx_conf[res->qid]);
2822                 if (ret)
2823                         printf("Failed to setup TX queue\n");
2824         }
2825 }
2826
2827 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2828         .f = cmd_setup_rxtx_queue_parsed,
2829         .data = NULL,
2830         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2831         .tokens = {
2832                 (void *)&cmd_setup_rxtx_queue_port,
2833                 (void *)&cmd_setup_rxtx_queue_portid,
2834                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2835                 (void *)&cmd_setup_rxtx_queue_qid,
2836                 (void *)&cmd_setup_rxtx_queue_setup,
2837                 NULL,
2838         },
2839 };
2840
2841
2842 /* *** Configure RSS RETA *** */
2843 struct cmd_config_rss_reta {
2844         cmdline_fixed_string_t port;
2845         cmdline_fixed_string_t keyword;
2846         portid_t port_id;
2847         cmdline_fixed_string_t name;
2848         cmdline_fixed_string_t list_name;
2849         cmdline_fixed_string_t list_of_items;
2850 };
2851
2852 static int
2853 parse_reta_config(const char *str,
2854                   struct rte_eth_rss_reta_entry64 *reta_conf,
2855                   uint16_t nb_entries)
2856 {
2857         int i;
2858         unsigned size;
2859         uint16_t hash_index, idx, shift;
2860         uint16_t nb_queue;
2861         char s[256];
2862         const char *p, *p0 = str;
2863         char *end;
2864         enum fieldnames {
2865                 FLD_HASH_INDEX = 0,
2866                 FLD_QUEUE,
2867                 _NUM_FLD
2868         };
2869         unsigned long int_fld[_NUM_FLD];
2870         char *str_fld[_NUM_FLD];
2871
2872         while ((p = strchr(p0,'(')) != NULL) {
2873                 ++p;
2874                 if((p0 = strchr(p,')')) == NULL)
2875                         return -1;
2876
2877                 size = p0 - p;
2878                 if(size >= sizeof(s))
2879                         return -1;
2880
2881                 snprintf(s, sizeof(s), "%.*s", size, p);
2882                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2883                         return -1;
2884                 for (i = 0; i < _NUM_FLD; i++) {
2885                         errno = 0;
2886                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2887                         if (errno != 0 || end == str_fld[i] ||
2888                                         int_fld[i] > 65535)
2889                                 return -1;
2890                 }
2891
2892                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2893                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2894
2895                 if (hash_index >= nb_entries) {
2896                         printf("Invalid RETA hash index=%d\n", hash_index);
2897                         return -1;
2898                 }
2899
2900                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2901                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2902                 reta_conf[idx].mask |= (1ULL << shift);
2903                 reta_conf[idx].reta[shift] = nb_queue;
2904         }
2905
2906         return 0;
2907 }
2908
2909 static void
2910 cmd_set_rss_reta_parsed(void *parsed_result,
2911                         __rte_unused struct cmdline *cl,
2912                         __rte_unused void *data)
2913 {
2914         int ret;
2915         struct rte_eth_dev_info dev_info;
2916         struct rte_eth_rss_reta_entry64 reta_conf[8];
2917         struct cmd_config_rss_reta *res = parsed_result;
2918
2919         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2920         if (ret != 0)
2921                 return;
2922
2923         if (dev_info.reta_size == 0) {
2924                 printf("Redirection table size is 0 which is "
2925                                         "invalid for RSS\n");
2926                 return;
2927         } else
2928                 printf("The reta size of port %d is %u\n",
2929                         res->port_id, dev_info.reta_size);
2930         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2931                 printf("Currently do not support more than %u entries of "
2932                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2933                 return;
2934         }
2935
2936         memset(reta_conf, 0, sizeof(reta_conf));
2937         if (!strcmp(res->list_name, "reta")) {
2938                 if (parse_reta_config(res->list_of_items, reta_conf,
2939                                                 dev_info.reta_size)) {
2940                         printf("Invalid RSS Redirection Table "
2941                                         "config entered\n");
2942                         return;
2943                 }
2944                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2945                                 reta_conf, dev_info.reta_size);
2946                 if (ret != 0)
2947                         printf("Bad redirection table parameter, "
2948                                         "return code = %d \n", ret);
2949         }
2950 }
2951
2952 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2953         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2954 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2955         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2956 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2957         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
2958 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2959         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2960 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2961         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2962 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2963         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2964                                  NULL);
2965 cmdline_parse_inst_t cmd_config_rss_reta = {
2966         .f = cmd_set_rss_reta_parsed,
2967         .data = NULL,
2968         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2969         .tokens = {
2970                 (void *)&cmd_config_rss_reta_port,
2971                 (void *)&cmd_config_rss_reta_keyword,
2972                 (void *)&cmd_config_rss_reta_port_id,
2973                 (void *)&cmd_config_rss_reta_name,
2974                 (void *)&cmd_config_rss_reta_list_name,
2975                 (void *)&cmd_config_rss_reta_list_of_items,
2976                 NULL,
2977         },
2978 };
2979
2980 /* *** SHOW PORT RETA INFO *** */
2981 struct cmd_showport_reta {
2982         cmdline_fixed_string_t show;
2983         cmdline_fixed_string_t port;
2984         portid_t port_id;
2985         cmdline_fixed_string_t rss;
2986         cmdline_fixed_string_t reta;
2987         uint16_t size;
2988         cmdline_fixed_string_t list_of_items;
2989 };
2990
2991 static int
2992 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2993                            uint16_t nb_entries,
2994                            char *str)
2995 {
2996         uint32_t size;
2997         const char *p, *p0 = str;
2998         char s[256];
2999         char *end;
3000         char *str_fld[8];
3001         uint16_t i;
3002         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3003                         RTE_RETA_GROUP_SIZE;
3004         int ret;
3005
3006         p = strchr(p0, '(');
3007         if (p == NULL)
3008                 return -1;
3009         p++;
3010         p0 = strchr(p, ')');
3011         if (p0 == NULL)
3012                 return -1;
3013         size = p0 - p;
3014         if (size >= sizeof(s)) {
3015                 printf("The string size exceeds the internal buffer size\n");
3016                 return -1;
3017         }
3018         snprintf(s, sizeof(s), "%.*s", size, p);
3019         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3020         if (ret <= 0 || ret != num) {
3021                 printf("The bits of masks do not match the number of "
3022                                         "reta entries: %u\n", num);
3023                 return -1;
3024         }
3025         for (i = 0; i < ret; i++)
3026                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3027
3028         return 0;
3029 }
3030
3031 static void
3032 cmd_showport_reta_parsed(void *parsed_result,
3033                          __rte_unused struct cmdline *cl,
3034                          __rte_unused void *data)
3035 {
3036         struct cmd_showport_reta *res = parsed_result;
3037         struct rte_eth_rss_reta_entry64 reta_conf[8];
3038         struct rte_eth_dev_info dev_info;
3039         uint16_t max_reta_size;
3040         int ret;
3041
3042         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3043         if (ret != 0)
3044                 return;
3045
3046         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3047         if (res->size == 0 || res->size > max_reta_size) {
3048                 printf("Invalid redirection table size: %u (1-%u)\n",
3049                         res->size, max_reta_size);
3050                 return;
3051         }
3052
3053         memset(reta_conf, 0, sizeof(reta_conf));
3054         if (showport_parse_reta_config(reta_conf, res->size,
3055                                 res->list_of_items) < 0) {
3056                 printf("Invalid string: %s for reta masks\n",
3057                                         res->list_of_items);
3058                 return;
3059         }
3060         port_rss_reta_info(res->port_id, reta_conf, res->size);
3061 }
3062
3063 cmdline_parse_token_string_t cmd_showport_reta_show =
3064         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3065 cmdline_parse_token_string_t cmd_showport_reta_port =
3066         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3067 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3068         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3069 cmdline_parse_token_string_t cmd_showport_reta_rss =
3070         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3071 cmdline_parse_token_string_t cmd_showport_reta_reta =
3072         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3073 cmdline_parse_token_num_t cmd_showport_reta_size =
3074         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3075 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3076         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3077                                         list_of_items, NULL);
3078
3079 cmdline_parse_inst_t cmd_showport_reta = {
3080         .f = cmd_showport_reta_parsed,
3081         .data = NULL,
3082         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3083         .tokens = {
3084                 (void *)&cmd_showport_reta_show,
3085                 (void *)&cmd_showport_reta_port,
3086                 (void *)&cmd_showport_reta_port_id,
3087                 (void *)&cmd_showport_reta_rss,
3088                 (void *)&cmd_showport_reta_reta,
3089                 (void *)&cmd_showport_reta_size,
3090                 (void *)&cmd_showport_reta_list_of_items,
3091                 NULL,
3092         },
3093 };
3094
3095 /* *** Show RSS hash configuration *** */
3096 struct cmd_showport_rss_hash {
3097         cmdline_fixed_string_t show;
3098         cmdline_fixed_string_t port;
3099         portid_t port_id;
3100         cmdline_fixed_string_t rss_hash;
3101         cmdline_fixed_string_t rss_type;
3102         cmdline_fixed_string_t key; /* optional argument */
3103 };
3104
3105 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3106                                 __rte_unused struct cmdline *cl,
3107                                 void *show_rss_key)
3108 {
3109         struct cmd_showport_rss_hash *res = parsed_result;
3110
3111         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3112 }
3113
3114 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3115         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3116 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3117         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3118 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3119         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3120                                  RTE_UINT16);
3121 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3122         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3123                                  "rss-hash");
3124 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3125         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3126
3127 cmdline_parse_inst_t cmd_showport_rss_hash = {
3128         .f = cmd_showport_rss_hash_parsed,
3129         .data = NULL,
3130         .help_str = "show port <port_id> rss-hash",
3131         .tokens = {
3132                 (void *)&cmd_showport_rss_hash_show,
3133                 (void *)&cmd_showport_rss_hash_port,
3134                 (void *)&cmd_showport_rss_hash_port_id,
3135                 (void *)&cmd_showport_rss_hash_rss_hash,
3136                 NULL,
3137         },
3138 };
3139
3140 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3141         .f = cmd_showport_rss_hash_parsed,
3142         .data = (void *)1,
3143         .help_str = "show port <port_id> rss-hash key",
3144         .tokens = {
3145                 (void *)&cmd_showport_rss_hash_show,
3146                 (void *)&cmd_showport_rss_hash_port,
3147                 (void *)&cmd_showport_rss_hash_port_id,
3148                 (void *)&cmd_showport_rss_hash_rss_hash,
3149                 (void *)&cmd_showport_rss_hash_rss_key,
3150                 NULL,
3151         },
3152 };
3153
3154 /* *** Configure DCB *** */
3155 struct cmd_config_dcb {
3156         cmdline_fixed_string_t port;
3157         cmdline_fixed_string_t config;
3158         portid_t port_id;
3159         cmdline_fixed_string_t dcb;
3160         cmdline_fixed_string_t vt;
3161         cmdline_fixed_string_t vt_en;
3162         uint8_t num_tcs;
3163         cmdline_fixed_string_t pfc;
3164         cmdline_fixed_string_t pfc_en;
3165 };
3166
3167 static void
3168 cmd_config_dcb_parsed(void *parsed_result,
3169                         __rte_unused struct cmdline *cl,
3170                         __rte_unused void *data)
3171 {
3172         struct cmd_config_dcb *res = parsed_result;
3173         portid_t port_id = res->port_id;
3174         struct rte_port *port;
3175         uint8_t pfc_en;
3176         int ret;
3177
3178         port = &ports[port_id];
3179         /** Check if the port is not started **/
3180         if (port->port_status != RTE_PORT_STOPPED) {
3181                 printf("Please stop port %d first\n", port_id);
3182                 return;
3183         }
3184
3185         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3186                 printf("The invalid number of traffic class,"
3187                         " only 4 or 8 allowed.\n");
3188                 return;
3189         }
3190
3191         if (nb_fwd_lcores < res->num_tcs) {
3192                 printf("nb_cores shouldn't be less than number of TCs.\n");
3193                 return;
3194         }
3195         if (!strncmp(res->pfc_en, "on", 2))
3196                 pfc_en = 1;
3197         else
3198                 pfc_en = 0;
3199
3200         /* DCB in VT mode */
3201         if (!strncmp(res->vt_en, "on", 2))
3202                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3203                                 (enum rte_eth_nb_tcs)res->num_tcs,
3204                                 pfc_en);
3205         else
3206                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3207                                 (enum rte_eth_nb_tcs)res->num_tcs,
3208                                 pfc_en);
3209
3210
3211         if (ret != 0) {
3212                 printf("Cannot initialize network ports.\n");
3213                 return;
3214         }
3215
3216         cmd_reconfig_device_queue(port_id, 1, 1);
3217 }
3218
3219 cmdline_parse_token_string_t cmd_config_dcb_port =
3220         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3221 cmdline_parse_token_string_t cmd_config_dcb_config =
3222         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3223 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3224         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3225 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3226         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3227 cmdline_parse_token_string_t cmd_config_dcb_vt =
3228         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3229 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3230         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3231 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3232         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3233 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3234         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3235 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3236         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3237
3238 cmdline_parse_inst_t cmd_config_dcb = {
3239         .f = cmd_config_dcb_parsed,
3240         .data = NULL,
3241         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3242         .tokens = {
3243                 (void *)&cmd_config_dcb_port,
3244                 (void *)&cmd_config_dcb_config,
3245                 (void *)&cmd_config_dcb_port_id,
3246                 (void *)&cmd_config_dcb_dcb,
3247                 (void *)&cmd_config_dcb_vt,
3248                 (void *)&cmd_config_dcb_vt_en,
3249                 (void *)&cmd_config_dcb_num_tcs,
3250                 (void *)&cmd_config_dcb_pfc,
3251                 (void *)&cmd_config_dcb_pfc_en,
3252                 NULL,
3253         },
3254 };
3255
3256 /* *** configure number of packets per burst *** */
3257 struct cmd_config_burst {
3258         cmdline_fixed_string_t port;
3259         cmdline_fixed_string_t keyword;
3260         cmdline_fixed_string_t all;
3261         cmdline_fixed_string_t name;
3262         uint16_t value;
3263 };
3264
3265 static void
3266 cmd_config_burst_parsed(void *parsed_result,
3267                         __rte_unused struct cmdline *cl,
3268                         __rte_unused void *data)
3269 {
3270         struct cmd_config_burst *res = parsed_result;
3271         struct rte_eth_dev_info dev_info;
3272         uint16_t rec_nb_pkts;
3273         int ret;
3274
3275         if (!all_ports_stopped()) {
3276                 printf("Please stop all ports first\n");
3277                 return;
3278         }
3279
3280         if (!strcmp(res->name, "burst")) {
3281                 if (res->value == 0) {
3282                         /* If user gives a value of zero, query the PMD for
3283                          * its recommended Rx burst size. Testpmd uses a single
3284                          * size for all ports, so assume all ports are the same
3285                          * NIC model and use the values from Port 0.
3286                          */
3287                         ret = eth_dev_info_get_print_err(0, &dev_info);
3288                         if (ret != 0)
3289                                 return;
3290
3291                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3292
3293                         if (rec_nb_pkts == 0) {
3294                                 printf("PMD does not recommend a burst size.\n"
3295                                         "User provided value must be between"
3296                                         " 1 and %d\n", MAX_PKT_BURST);
3297                                 return;
3298                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3299                                 printf("PMD recommended burst size of %d"
3300                                         " exceeds maximum value of %d\n",
3301                                         rec_nb_pkts, MAX_PKT_BURST);
3302                                 return;
3303                         }
3304                         printf("Using PMD-provided burst value of %d\n",
3305                                 rec_nb_pkts);
3306                         nb_pkt_per_burst = rec_nb_pkts;
3307                 } else if (res->value > MAX_PKT_BURST) {
3308                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3309                         return;
3310                 } else
3311                         nb_pkt_per_burst = res->value;
3312         } else {
3313                 printf("Unknown parameter\n");
3314                 return;
3315         }
3316
3317         init_port_config();
3318
3319         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3320 }
3321
3322 cmdline_parse_token_string_t cmd_config_burst_port =
3323         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3324 cmdline_parse_token_string_t cmd_config_burst_keyword =
3325         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3326 cmdline_parse_token_string_t cmd_config_burst_all =
3327         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3328 cmdline_parse_token_string_t cmd_config_burst_name =
3329         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3330 cmdline_parse_token_num_t cmd_config_burst_value =
3331         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3332
3333 cmdline_parse_inst_t cmd_config_burst = {
3334         .f = cmd_config_burst_parsed,
3335         .data = NULL,
3336         .help_str = "port config all burst <value>",
3337         .tokens = {
3338                 (void *)&cmd_config_burst_port,
3339                 (void *)&cmd_config_burst_keyword,
3340                 (void *)&cmd_config_burst_all,
3341                 (void *)&cmd_config_burst_name,
3342                 (void *)&cmd_config_burst_value,
3343                 NULL,
3344         },
3345 };
3346
3347 /* *** configure rx/tx queues *** */
3348 struct cmd_config_thresh {
3349         cmdline_fixed_string_t port;
3350         cmdline_fixed_string_t keyword;
3351         cmdline_fixed_string_t all;
3352         cmdline_fixed_string_t name;
3353         uint8_t value;
3354 };
3355
3356 static void
3357 cmd_config_thresh_parsed(void *parsed_result,
3358                         __rte_unused struct cmdline *cl,
3359                         __rte_unused void *data)
3360 {
3361         struct cmd_config_thresh *res = parsed_result;
3362
3363         if (!all_ports_stopped()) {
3364                 printf("Please stop all ports first\n");
3365                 return;
3366         }
3367
3368         if (!strcmp(res->name, "txpt"))
3369                 tx_pthresh = res->value;
3370         else if(!strcmp(res->name, "txht"))
3371                 tx_hthresh = res->value;
3372         else if(!strcmp(res->name, "txwt"))
3373                 tx_wthresh = res->value;
3374         else if(!strcmp(res->name, "rxpt"))
3375                 rx_pthresh = res->value;
3376         else if(!strcmp(res->name, "rxht"))
3377                 rx_hthresh = res->value;
3378         else if(!strcmp(res->name, "rxwt"))
3379                 rx_wthresh = res->value;
3380         else {
3381                 printf("Unknown parameter\n");
3382                 return;
3383         }
3384
3385         init_port_config();
3386
3387         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3388 }
3389
3390 cmdline_parse_token_string_t cmd_config_thresh_port =
3391         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3392 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3393         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3394 cmdline_parse_token_string_t cmd_config_thresh_all =
3395         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3396 cmdline_parse_token_string_t cmd_config_thresh_name =
3397         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3398                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3399 cmdline_parse_token_num_t cmd_config_thresh_value =
3400         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3401
3402 cmdline_parse_inst_t cmd_config_thresh = {
3403         .f = cmd_config_thresh_parsed,
3404         .data = NULL,
3405         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3406         .tokens = {
3407                 (void *)&cmd_config_thresh_port,
3408                 (void *)&cmd_config_thresh_keyword,
3409                 (void *)&cmd_config_thresh_all,
3410                 (void *)&cmd_config_thresh_name,
3411                 (void *)&cmd_config_thresh_value,
3412                 NULL,
3413         },
3414 };
3415
3416 /* *** configure free/rs threshold *** */
3417 struct cmd_config_threshold {
3418         cmdline_fixed_string_t port;
3419         cmdline_fixed_string_t keyword;
3420         cmdline_fixed_string_t all;
3421         cmdline_fixed_string_t name;
3422         uint16_t value;
3423 };
3424
3425 static void
3426 cmd_config_threshold_parsed(void *parsed_result,
3427                         __rte_unused struct cmdline *cl,
3428                         __rte_unused void *data)
3429 {
3430         struct cmd_config_threshold *res = parsed_result;
3431
3432         if (!all_ports_stopped()) {
3433                 printf("Please stop all ports first\n");
3434                 return;
3435         }
3436
3437         if (!strcmp(res->name, "txfreet"))
3438                 tx_free_thresh = res->value;
3439         else if (!strcmp(res->name, "txrst"))
3440                 tx_rs_thresh = res->value;
3441         else if (!strcmp(res->name, "rxfreet"))
3442                 rx_free_thresh = res->value;
3443         else {
3444                 printf("Unknown parameter\n");
3445                 return;
3446         }
3447
3448         init_port_config();
3449
3450         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3451 }
3452
3453 cmdline_parse_token_string_t cmd_config_threshold_port =
3454         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3455 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3456         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3457                                                                 "config");
3458 cmdline_parse_token_string_t cmd_config_threshold_all =
3459         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3460 cmdline_parse_token_string_t cmd_config_threshold_name =
3461         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3462                                                 "txfreet#txrst#rxfreet");
3463 cmdline_parse_token_num_t cmd_config_threshold_value =
3464         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3465
3466 cmdline_parse_inst_t cmd_config_threshold = {
3467         .f = cmd_config_threshold_parsed,
3468         .data = NULL,
3469         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3470         .tokens = {
3471                 (void *)&cmd_config_threshold_port,
3472                 (void *)&cmd_config_threshold_keyword,
3473                 (void *)&cmd_config_threshold_all,
3474                 (void *)&cmd_config_threshold_name,
3475                 (void *)&cmd_config_threshold_value,
3476                 NULL,
3477         },
3478 };
3479
3480 /* *** stop *** */
3481 struct cmd_stop_result {
3482         cmdline_fixed_string_t stop;
3483 };
3484
3485 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3486                             __rte_unused struct cmdline *cl,
3487                             __rte_unused void *data)
3488 {
3489         stop_packet_forwarding();
3490 }
3491
3492 cmdline_parse_token_string_t cmd_stop_stop =
3493         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3494
3495 cmdline_parse_inst_t cmd_stop = {
3496         .f = cmd_stop_parsed,
3497         .data = NULL,
3498         .help_str = "stop: Stop packet forwarding",
3499         .tokens = {
3500                 (void *)&cmd_stop_stop,
3501                 NULL,
3502         },
3503 };
3504
3505 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3506
3507 unsigned int
3508 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3509                 unsigned int *parsed_items, int check_unique_values)
3510 {
3511         unsigned int nb_item;
3512         unsigned int value;
3513         unsigned int i;
3514         unsigned int j;
3515         int value_ok;
3516         char c;
3517
3518         /*
3519          * First parse all items in the list and store their value.
3520          */
3521         value = 0;
3522         nb_item = 0;
3523         value_ok = 0;
3524         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3525                 c = str[i];
3526                 if ((c >= '0') && (c <= '9')) {
3527                         value = (unsigned int) (value * 10 + (c - '0'));
3528                         value_ok = 1;
3529                         continue;
3530                 }
3531                 if (c != ',') {
3532                         printf("character %c is not a decimal digit\n", c);
3533                         return 0;
3534                 }
3535                 if (! value_ok) {
3536                         printf("No valid value before comma\n");
3537                         return 0;
3538                 }
3539                 if (nb_item < max_items) {
3540                         parsed_items[nb_item] = value;
3541                         value_ok = 0;
3542                         value = 0;
3543                 }
3544                 nb_item++;
3545         }
3546         if (nb_item >= max_items) {
3547                 printf("Number of %s = %u > %u (maximum items)\n",
3548                        item_name, nb_item + 1, max_items);
3549                 return 0;
3550         }
3551         parsed_items[nb_item++] = value;
3552         if (! check_unique_values)
3553                 return nb_item;
3554
3555         /*
3556          * Then, check that all values in the list are differents.
3557          * No optimization here...
3558          */
3559         for (i = 0; i < nb_item; i++) {
3560                 for (j = i + 1; j < nb_item; j++) {
3561                         if (parsed_items[j] == parsed_items[i]) {
3562                                 printf("duplicated %s %u at index %u and %u\n",
3563                                        item_name, parsed_items[i], i, j);
3564                                 return 0;
3565                         }
3566                 }
3567         }
3568         return nb_item;
3569 }
3570
3571 struct cmd_set_list_result {
3572         cmdline_fixed_string_t cmd_keyword;
3573         cmdline_fixed_string_t list_name;
3574         cmdline_fixed_string_t list_of_items;
3575 };
3576
3577 static void cmd_set_list_parsed(void *parsed_result,
3578                                 __rte_unused struct cmdline *cl,
3579                                 __rte_unused void *data)
3580 {
3581         struct cmd_set_list_result *res;
3582         union {
3583                 unsigned int lcorelist[RTE_MAX_LCORE];
3584                 unsigned int portlist[RTE_MAX_ETHPORTS];
3585         } parsed_items;
3586         unsigned int nb_item;
3587
3588         if (test_done == 0) {
3589                 printf("Please stop forwarding first\n");
3590                 return;
3591         }
3592
3593         res = parsed_result;
3594         if (!strcmp(res->list_name, "corelist")) {
3595                 nb_item = parse_item_list(res->list_of_items, "core",
3596                                           RTE_MAX_LCORE,
3597                                           parsed_items.lcorelist, 1);
3598                 if (nb_item > 0) {
3599                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3600                         fwd_config_setup();
3601                 }
3602                 return;
3603         }
3604         if (!strcmp(res->list_name, "portlist")) {
3605                 nb_item = parse_item_list(res->list_of_items, "port",
3606                                           RTE_MAX_ETHPORTS,
3607                                           parsed_items.portlist, 1);
3608                 if (nb_item > 0) {
3609                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3610                         fwd_config_setup();
3611                 }
3612         }
3613 }
3614
3615 cmdline_parse_token_string_t cmd_set_list_keyword =
3616         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3617                                  "set");
3618 cmdline_parse_token_string_t cmd_set_list_name =
3619         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3620                                  "corelist#portlist");
3621 cmdline_parse_token_string_t cmd_set_list_of_items =
3622         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3623                                  NULL);
3624
3625 cmdline_parse_inst_t cmd_set_fwd_list = {
3626         .f = cmd_set_list_parsed,
3627         .data = NULL,
3628         .help_str = "set corelist|portlist <list0[,list1]*>",
3629         .tokens = {
3630                 (void *)&cmd_set_list_keyword,
3631                 (void *)&cmd_set_list_name,
3632                 (void *)&cmd_set_list_of_items,
3633                 NULL,
3634         },
3635 };
3636
3637 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3638
3639 struct cmd_setmask_result {
3640         cmdline_fixed_string_t set;
3641         cmdline_fixed_string_t mask;
3642         uint64_t hexavalue;
3643 };
3644
3645 static void cmd_set_mask_parsed(void *parsed_result,
3646                                 __rte_unused struct cmdline *cl,
3647                                 __rte_unused void *data)
3648 {
3649         struct cmd_setmask_result *res = parsed_result;
3650
3651         if (test_done == 0) {
3652                 printf("Please stop forwarding first\n");
3653                 return;
3654         }
3655         if (!strcmp(res->mask, "coremask")) {
3656                 set_fwd_lcores_mask(res->hexavalue);
3657                 fwd_config_setup();
3658         } else if (!strcmp(res->mask, "portmask")) {
3659                 set_fwd_ports_mask(res->hexavalue);
3660                 fwd_config_setup();
3661         }
3662 }
3663
3664 cmdline_parse_token_string_t cmd_setmask_set =
3665         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3666 cmdline_parse_token_string_t cmd_setmask_mask =
3667         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3668                                  "coremask#portmask");
3669 cmdline_parse_token_num_t cmd_setmask_value =
3670         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3671
3672 cmdline_parse_inst_t cmd_set_fwd_mask = {
3673         .f = cmd_set_mask_parsed,
3674         .data = NULL,
3675         .help_str = "set coremask|portmask <hexadecimal value>",
3676         .tokens = {
3677                 (void *)&cmd_setmask_set,
3678                 (void *)&cmd_setmask_mask,
3679                 (void *)&cmd_setmask_value,
3680                 NULL,
3681         },
3682 };
3683
3684 /*
3685  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3686  */
3687 struct cmd_set_result {
3688         cmdline_fixed_string_t set;
3689         cmdline_fixed_string_t what;
3690         uint16_t value;
3691 };
3692
3693 static void cmd_set_parsed(void *parsed_result,
3694                            __rte_unused struct cmdline *cl,
3695                            __rte_unused void *data)
3696 {
3697         struct cmd_set_result *res = parsed_result;
3698         if (!strcmp(res->what, "nbport")) {
3699                 set_fwd_ports_number(res->value);
3700                 fwd_config_setup();
3701         } else if (!strcmp(res->what, "nbcore")) {
3702                 set_fwd_lcores_number(res->value);
3703                 fwd_config_setup();
3704         } else if (!strcmp(res->what, "burst"))
3705                 set_nb_pkt_per_burst(res->value);
3706         else if (!strcmp(res->what, "verbose"))
3707                 set_verbose_level(res->value);
3708 }
3709
3710 cmdline_parse_token_string_t cmd_set_set =
3711         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3712 cmdline_parse_token_string_t cmd_set_what =
3713         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3714                                  "nbport#nbcore#burst#verbose");
3715 cmdline_parse_token_num_t cmd_set_value =
3716         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3717
3718 cmdline_parse_inst_t cmd_set_numbers = {
3719         .f = cmd_set_parsed,
3720         .data = NULL,
3721         .help_str = "set nbport|nbcore|burst|verbose <value>",
3722         .tokens = {
3723                 (void *)&cmd_set_set,
3724                 (void *)&cmd_set_what,
3725                 (void *)&cmd_set_value,
3726                 NULL,
3727         },
3728 };
3729
3730 /* *** SET LOG LEVEL CONFIGURATION *** */
3731
3732 struct cmd_set_log_result {
3733         cmdline_fixed_string_t set;
3734         cmdline_fixed_string_t log;
3735         cmdline_fixed_string_t type;
3736         uint32_t level;
3737 };
3738
3739 static void
3740 cmd_set_log_parsed(void *parsed_result,
3741                    __rte_unused struct cmdline *cl,
3742                    __rte_unused void *data)
3743 {
3744         struct cmd_set_log_result *res;
3745         int ret;
3746
3747         res = parsed_result;
3748         if (!strcmp(res->type, "global"))
3749                 rte_log_set_global_level(res->level);
3750         else {
3751                 ret = rte_log_set_level_regexp(res->type, res->level);
3752                 if (ret < 0)
3753                         printf("Unable to set log level\n");
3754         }
3755 }
3756
3757 cmdline_parse_token_string_t cmd_set_log_set =
3758         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3759 cmdline_parse_token_string_t cmd_set_log_log =
3760         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3761 cmdline_parse_token_string_t cmd_set_log_type =
3762         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3763 cmdline_parse_token_num_t cmd_set_log_level =
3764         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3765
3766 cmdline_parse_inst_t cmd_set_log = {
3767         .f = cmd_set_log_parsed,
3768         .data = NULL,
3769         .help_str = "set log global|<type> <level>",
3770         .tokens = {
3771                 (void *)&cmd_set_log_set,
3772                 (void *)&cmd_set_log_log,
3773                 (void *)&cmd_set_log_type,
3774                 (void *)&cmd_set_log_level,
3775                 NULL,
3776         },
3777 };
3778
3779 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3780
3781 struct cmd_set_rxoffs_result {
3782         cmdline_fixed_string_t cmd_keyword;
3783         cmdline_fixed_string_t rxoffs;
3784         cmdline_fixed_string_t seg_offsets;
3785 };
3786
3787 static void
3788 cmd_set_rxoffs_parsed(void *parsed_result,
3789                       __rte_unused struct cmdline *cl,
3790                       __rte_unused void *data)
3791 {
3792         struct cmd_set_rxoffs_result *res;
3793         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3794         unsigned int nb_segs;
3795
3796         res = parsed_result;
3797         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3798                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3799         if (nb_segs > 0)
3800                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3801         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3802 }
3803
3804 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3805         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3806                                  cmd_keyword, "set");
3807 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3808         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3809                                  rxoffs, "rxoffs");
3810 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3811         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3812                                  seg_offsets, NULL);
3813
3814 cmdline_parse_inst_t cmd_set_rxoffs = {
3815         .f = cmd_set_rxoffs_parsed,
3816         .data = NULL,
3817         .help_str = "set rxoffs <len0[,len1]*>",
3818         .tokens = {
3819                 (void *)&cmd_set_rxoffs_keyword,
3820                 (void *)&cmd_set_rxoffs_name,
3821                 (void *)&cmd_set_rxoffs_offsets,
3822                 NULL,
3823         },
3824 };
3825
3826 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3827
3828 struct cmd_set_rxpkts_result {
3829         cmdline_fixed_string_t cmd_keyword;
3830         cmdline_fixed_string_t rxpkts;
3831         cmdline_fixed_string_t seg_lengths;
3832 };
3833
3834 static void
3835 cmd_set_rxpkts_parsed(void *parsed_result,
3836                       __rte_unused struct cmdline *cl,
3837                       __rte_unused void *data)
3838 {
3839         struct cmd_set_rxpkts_result *res;
3840         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3841         unsigned int nb_segs;
3842
3843         res = parsed_result;
3844         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3845                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3846         if (nb_segs > 0)
3847                 set_rx_pkt_segments(seg_lengths, nb_segs);
3848         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3849 }
3850
3851 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3852         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3853                                  cmd_keyword, "set");
3854 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3855         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3856                                  rxpkts, "rxpkts");
3857 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3858         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3859                                  seg_lengths, NULL);
3860
3861 cmdline_parse_inst_t cmd_set_rxpkts = {
3862         .f = cmd_set_rxpkts_parsed,
3863         .data = NULL,
3864         .help_str = "set rxpkts <len0[,len1]*>",
3865         .tokens = {
3866                 (void *)&cmd_set_rxpkts_keyword,
3867                 (void *)&cmd_set_rxpkts_name,
3868                 (void *)&cmd_set_rxpkts_lengths,
3869                 NULL,
3870         },
3871 };
3872
3873 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3874
3875 struct cmd_set_txpkts_result {
3876         cmdline_fixed_string_t cmd_keyword;
3877         cmdline_fixed_string_t txpkts;
3878         cmdline_fixed_string_t seg_lengths;
3879 };
3880
3881 static void
3882 cmd_set_txpkts_parsed(void *parsed_result,
3883                       __rte_unused struct cmdline *cl,
3884                       __rte_unused void *data)
3885 {
3886         struct cmd_set_txpkts_result *res;
3887         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3888         unsigned int nb_segs;
3889
3890         res = parsed_result;
3891         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3892                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3893         if (nb_segs > 0)
3894                 set_tx_pkt_segments(seg_lengths, nb_segs);
3895 }
3896
3897 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3898         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3899                                  cmd_keyword, "set");
3900 cmdline_parse_token_string_t cmd_set_txpkts_name =
3901         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3902                                  txpkts, "txpkts");
3903 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3904         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3905                                  seg_lengths, NULL);
3906
3907 cmdline_parse_inst_t cmd_set_txpkts = {
3908         .f = cmd_set_txpkts_parsed,
3909         .data = NULL,
3910         .help_str = "set txpkts <len0[,len1]*>",
3911         .tokens = {
3912                 (void *)&cmd_set_txpkts_keyword,
3913                 (void *)&cmd_set_txpkts_name,
3914                 (void *)&cmd_set_txpkts_lengths,
3915                 NULL,
3916         },
3917 };
3918
3919 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3920
3921 struct cmd_set_txsplit_result {
3922         cmdline_fixed_string_t cmd_keyword;
3923         cmdline_fixed_string_t txsplit;
3924         cmdline_fixed_string_t mode;
3925 };
3926
3927 static void
3928 cmd_set_txsplit_parsed(void *parsed_result,
3929                       __rte_unused struct cmdline *cl,
3930                       __rte_unused void *data)
3931 {
3932         struct cmd_set_txsplit_result *res;
3933
3934         res = parsed_result;
3935         set_tx_pkt_split(res->mode);
3936 }
3937
3938 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3939         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3940                                  cmd_keyword, "set");
3941 cmdline_parse_token_string_t cmd_set_txsplit_name =
3942         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3943                                  txsplit, "txsplit");
3944 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3945         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3946                                  mode, NULL);
3947
3948 cmdline_parse_inst_t cmd_set_txsplit = {
3949         .f = cmd_set_txsplit_parsed,
3950         .data = NULL,
3951         .help_str = "set txsplit on|off|rand",
3952         .tokens = {
3953                 (void *)&cmd_set_txsplit_keyword,
3954                 (void *)&cmd_set_txsplit_name,
3955                 (void *)&cmd_set_txsplit_mode,
3956                 NULL,
3957         },
3958 };
3959
3960 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3961
3962 struct cmd_set_txtimes_result {
3963         cmdline_fixed_string_t cmd_keyword;
3964         cmdline_fixed_string_t txtimes;
3965         cmdline_fixed_string_t tx_times;
3966 };
3967
3968 static void
3969 cmd_set_txtimes_parsed(void *parsed_result,
3970                        __rte_unused struct cmdline *cl,
3971                        __rte_unused void *data)
3972 {
3973         struct cmd_set_txtimes_result *res;
3974         unsigned int tx_times[2] = {0, 0};
3975         unsigned int n_times;
3976
3977         res = parsed_result;
3978         n_times = parse_item_list(res->tx_times, "tx times",
3979                                   2, tx_times, 0);
3980         if (n_times == 2)
3981                 set_tx_pkt_times(tx_times);
3982 }
3983
3984 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3985         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3986                                  cmd_keyword, "set");
3987 cmdline_parse_token_string_t cmd_set_txtimes_name =
3988         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3989                                  txtimes, "txtimes");
3990 cmdline_parse_token_string_t cmd_set_txtimes_value =
3991         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3992                                  tx_times, NULL);
3993
3994 cmdline_parse_inst_t cmd_set_txtimes = {
3995         .f = cmd_set_txtimes_parsed,
3996         .data = NULL,
3997         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3998         .tokens = {
3999                 (void *)&cmd_set_txtimes_keyword,
4000                 (void *)&cmd_set_txtimes_name,
4001                 (void *)&cmd_set_txtimes_value,
4002                 NULL,
4003         },
4004 };
4005
4006 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4007 struct cmd_rx_vlan_filter_all_result {
4008         cmdline_fixed_string_t rx_vlan;
4009         cmdline_fixed_string_t what;
4010         cmdline_fixed_string_t all;
4011         portid_t port_id;
4012 };
4013
4014 static void
4015 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4016                               __rte_unused struct cmdline *cl,
4017                               __rte_unused void *data)
4018 {
4019         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4020
4021         if (!strcmp(res->what, "add"))
4022                 rx_vlan_all_filter_set(res->port_id, 1);
4023         else
4024                 rx_vlan_all_filter_set(res->port_id, 0);
4025 }
4026
4027 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4028         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4029                                  rx_vlan, "rx_vlan");
4030 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4031         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4032                                  what, "add#rm");
4033 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4034         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4035                                  all, "all");
4036 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4037         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4038                               port_id, RTE_UINT16);
4039
4040 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4041         .f = cmd_rx_vlan_filter_all_parsed,
4042         .data = NULL,
4043         .help_str = "rx_vlan add|rm all <port_id>: "
4044                 "Add/Remove all identifiers to/from the set of VLAN "
4045                 "identifiers filtered by a port",
4046         .tokens = {
4047                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4048                 (void *)&cmd_rx_vlan_filter_all_what,
4049                 (void *)&cmd_rx_vlan_filter_all_all,
4050                 (void *)&cmd_rx_vlan_filter_all_portid,
4051                 NULL,
4052         },
4053 };
4054
4055 /* *** VLAN OFFLOAD SET ON A PORT *** */
4056 struct cmd_vlan_offload_result {
4057         cmdline_fixed_string_t vlan;
4058         cmdline_fixed_string_t set;
4059         cmdline_fixed_string_t vlan_type;
4060         cmdline_fixed_string_t what;
4061         cmdline_fixed_string_t on;
4062         cmdline_fixed_string_t port_id;
4063 };
4064
4065 static void
4066 cmd_vlan_offload_parsed(void *parsed_result,
4067                           __rte_unused struct cmdline *cl,
4068                           __rte_unused void *data)
4069 {
4070         int on;
4071         struct cmd_vlan_offload_result *res = parsed_result;
4072         char *str;
4073         int i, len = 0;
4074         portid_t port_id = 0;
4075         unsigned int tmp;
4076
4077         str = res->port_id;
4078         len = strnlen(str, STR_TOKEN_SIZE);
4079         i = 0;
4080         /* Get port_id first */
4081         while(i < len){
4082                 if(str[i] == ',')
4083                         break;
4084
4085                 i++;
4086         }
4087         str[i]='\0';
4088         tmp = strtoul(str, NULL, 0);
4089         /* If port_id greater that what portid_t can represent, return */
4090         if(tmp >= RTE_MAX_ETHPORTS)
4091                 return;
4092         port_id = (portid_t)tmp;
4093
4094         if (!strcmp(res->on, "on"))
4095                 on = 1;
4096         else
4097                 on = 0;
4098
4099         if (!strcmp(res->what, "strip"))
4100                 rx_vlan_strip_set(port_id,  on);
4101         else if(!strcmp(res->what, "stripq")){
4102                 uint16_t queue_id = 0;
4103
4104                 /* No queue_id, return */
4105                 if(i + 1 >= len) {
4106                         printf("must specify (port,queue_id)\n");
4107                         return;
4108                 }
4109                 tmp = strtoul(str + i + 1, NULL, 0);
4110                 /* If queue_id greater that what 16-bits can represent, return */
4111                 if(tmp > 0xffff)
4112                         return;
4113
4114                 queue_id = (uint16_t)tmp;
4115                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4116         }
4117         else if (!strcmp(res->what, "filter"))
4118                 rx_vlan_filter_set(port_id, on);
4119         else if (!strcmp(res->what, "qinq_strip"))
4120                 rx_vlan_qinq_strip_set(port_id, on);
4121         else
4122                 vlan_extend_set(port_id, on);
4123
4124         return;
4125 }
4126
4127 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4128         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4129                                  vlan, "vlan");
4130 cmdline_parse_token_string_t cmd_vlan_offload_set =
4131         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4132                                  set, "set");
4133 cmdline_parse_token_string_t cmd_vlan_offload_what =
4134         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4135                                 what, "strip#filter#qinq_strip#extend#stripq");
4136 cmdline_parse_token_string_t cmd_vlan_offload_on =
4137         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4138                               on, "on#off");
4139 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4140         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4141                               port_id, NULL);
4142
4143 cmdline_parse_inst_t cmd_vlan_offload = {
4144         .f = cmd_vlan_offload_parsed,
4145         .data = NULL,
4146         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4147                 "<port_id[,queue_id]>: "
4148                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4149         .tokens = {
4150                 (void *)&cmd_vlan_offload_vlan,
4151                 (void *)&cmd_vlan_offload_set,
4152                 (void *)&cmd_vlan_offload_what,
4153                 (void *)&cmd_vlan_offload_on,
4154                 (void *)&cmd_vlan_offload_portid,
4155                 NULL,
4156         },
4157 };
4158
4159 /* *** VLAN TPID SET ON A PORT *** */
4160 struct cmd_vlan_tpid_result {
4161         cmdline_fixed_string_t vlan;
4162         cmdline_fixed_string_t set;
4163         cmdline_fixed_string_t vlan_type;
4164         cmdline_fixed_string_t what;
4165         uint16_t tp_id;
4166         portid_t port_id;
4167 };
4168
4169 static void
4170 cmd_vlan_tpid_parsed(void *parsed_result,
4171                           __rte_unused struct cmdline *cl,
4172                           __rte_unused void *data)
4173 {
4174         struct cmd_vlan_tpid_result *res = parsed_result;
4175         enum rte_vlan_type vlan_type;
4176
4177         if (!strcmp(res->vlan_type, "inner"))
4178                 vlan_type = ETH_VLAN_TYPE_INNER;
4179         else if (!strcmp(res->vlan_type, "outer"))
4180                 vlan_type = ETH_VLAN_TYPE_OUTER;
4181         else {
4182                 printf("Unknown vlan type\n");
4183                 return;
4184         }
4185         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4186 }
4187
4188 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4189         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4190                                  vlan, "vlan");
4191 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4192         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4193                                  set, "set");
4194 cmdline_parse_token_string_t cmd_vlan_type =
4195         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4196                                  vlan_type, "inner#outer");
4197 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4198         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4199                                  what, "tpid");
4200 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4201         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4202                               tp_id, RTE_UINT16);
4203 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4204         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4205                               port_id, RTE_UINT16);
4206
4207 cmdline_parse_inst_t cmd_vlan_tpid = {
4208         .f = cmd_vlan_tpid_parsed,
4209         .data = NULL,
4210         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4211                 "Set the VLAN Ether type",
4212         .tokens = {
4213                 (void *)&cmd_vlan_tpid_vlan,
4214                 (void *)&cmd_vlan_tpid_set,
4215                 (void *)&cmd_vlan_type,
4216                 (void *)&cmd_vlan_tpid_what,
4217                 (void *)&cmd_vlan_tpid_tpid,
4218                 (void *)&cmd_vlan_tpid_portid,
4219                 NULL,
4220         },
4221 };
4222
4223 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4224 struct cmd_rx_vlan_filter_result {
4225         cmdline_fixed_string_t rx_vlan;
4226         cmdline_fixed_string_t what;
4227         uint16_t vlan_id;
4228         portid_t port_id;
4229 };
4230
4231 static void
4232 cmd_rx_vlan_filter_parsed(void *parsed_result,
4233                           __rte_unused struct cmdline *cl,
4234                           __rte_unused void *data)
4235 {
4236         struct cmd_rx_vlan_filter_result *res = parsed_result;
4237
4238         if (!strcmp(res->what, "add"))
4239                 rx_vft_set(res->port_id, res->vlan_id, 1);
4240         else
4241                 rx_vft_set(res->port_id, res->vlan_id, 0);
4242 }
4243
4244 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4245         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4246                                  rx_vlan, "rx_vlan");
4247 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4248         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4249                                  what, "add#rm");
4250 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4251         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4252                               vlan_id, RTE_UINT16);
4253 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4254         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4255                               port_id, RTE_UINT16);
4256
4257 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4258         .f = cmd_rx_vlan_filter_parsed,
4259         .data = NULL,
4260         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4261                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4262                 "identifiers filtered by a port",
4263         .tokens = {
4264                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4265                 (void *)&cmd_rx_vlan_filter_what,
4266                 (void *)&cmd_rx_vlan_filter_vlanid,
4267                 (void *)&cmd_rx_vlan_filter_portid,
4268                 NULL,
4269         },
4270 };
4271
4272 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4273 struct cmd_tx_vlan_set_result {
4274         cmdline_fixed_string_t tx_vlan;
4275         cmdline_fixed_string_t set;
4276         portid_t port_id;
4277         uint16_t vlan_id;
4278 };
4279
4280 static void
4281 cmd_tx_vlan_set_parsed(void *parsed_result,
4282                        __rte_unused struct cmdline *cl,
4283                        __rte_unused void *data)
4284 {
4285         struct cmd_tx_vlan_set_result *res = parsed_result;
4286
4287         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4288                 return;
4289
4290         if (!port_is_stopped(res->port_id)) {
4291                 printf("Please stop port %d first\n", res->port_id);
4292                 return;
4293         }
4294
4295         tx_vlan_set(res->port_id, res->vlan_id);
4296
4297         cmd_reconfig_device_queue(res->port_id, 1, 1);
4298 }
4299
4300 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4301         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4302                                  tx_vlan, "tx_vlan");
4303 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4304         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4305                                  set, "set");
4306 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4307         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4308                               port_id, RTE_UINT16);
4309 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4310         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4311                               vlan_id, RTE_UINT16);
4312
4313 cmdline_parse_inst_t cmd_tx_vlan_set = {
4314         .f = cmd_tx_vlan_set_parsed,
4315         .data = NULL,
4316         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4317                 "Enable hardware insertion of a single VLAN header "
4318                 "with a given TAG Identifier in packets sent on a port",
4319         .tokens = {
4320                 (void *)&cmd_tx_vlan_set_tx_vlan,
4321                 (void *)&cmd_tx_vlan_set_set,
4322                 (void *)&cmd_tx_vlan_set_portid,
4323                 (void *)&cmd_tx_vlan_set_vlanid,
4324                 NULL,
4325         },
4326 };
4327
4328 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4329 struct cmd_tx_vlan_set_qinq_result {
4330         cmdline_fixed_string_t tx_vlan;
4331         cmdline_fixed_string_t set;
4332         portid_t port_id;
4333         uint16_t vlan_id;
4334         uint16_t vlan_id_outer;
4335 };
4336
4337 static void
4338 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4339                             __rte_unused struct cmdline *cl,
4340                             __rte_unused void *data)
4341 {
4342         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4343
4344         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4345                 return;
4346
4347         if (!port_is_stopped(res->port_id)) {
4348                 printf("Please stop port %d first\n", res->port_id);
4349                 return;
4350         }
4351
4352         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4353
4354         cmd_reconfig_device_queue(res->port_id, 1, 1);
4355 }
4356
4357 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4358         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4359                 tx_vlan, "tx_vlan");
4360 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4361         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4362                 set, "set");
4363 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4364         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4365                 port_id, RTE_UINT16);
4366 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4367         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4368                 vlan_id, RTE_UINT16);
4369 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4370         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4371                 vlan_id_outer, RTE_UINT16);
4372
4373 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4374         .f = cmd_tx_vlan_set_qinq_parsed,
4375         .data = NULL,
4376         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4377                 "Enable hardware insertion of double VLAN header "
4378                 "with given TAG Identifiers in packets sent on a port",
4379         .tokens = {
4380                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4381                 (void *)&cmd_tx_vlan_set_qinq_set,
4382                 (void *)&cmd_tx_vlan_set_qinq_portid,
4383                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4384                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4385                 NULL,
4386         },
4387 };
4388
4389 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4390 struct cmd_tx_vlan_set_pvid_result {
4391         cmdline_fixed_string_t tx_vlan;
4392         cmdline_fixed_string_t set;
4393         cmdline_fixed_string_t pvid;
4394         portid_t port_id;
4395         uint16_t vlan_id;
4396         cmdline_fixed_string_t mode;
4397 };
4398
4399 static void
4400 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4401                             __rte_unused struct cmdline *cl,
4402                             __rte_unused void *data)
4403 {
4404         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4405
4406         if (strcmp(res->mode, "on") == 0)
4407                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4408         else
4409                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4410 }
4411
4412 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4413         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4414                                  tx_vlan, "tx_vlan");
4415 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4416         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4417                                  set, "set");
4418 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4419         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4420                                  pvid, "pvid");
4421 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4422         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4423                              port_id, RTE_UINT16);
4424 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4425         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4426                               vlan_id, RTE_UINT16);
4427 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4428         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4429                                  mode, "on#off");
4430
4431 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4432         .f = cmd_tx_vlan_set_pvid_parsed,
4433         .data = NULL,
4434         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4435         .tokens = {
4436                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4437                 (void *)&cmd_tx_vlan_set_pvid_set,
4438                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4439                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4440                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4441                 (void *)&cmd_tx_vlan_set_pvid_mode,
4442                 NULL,
4443         },
4444 };
4445
4446 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4447 struct cmd_tx_vlan_reset_result {
4448         cmdline_fixed_string_t tx_vlan;
4449         cmdline_fixed_string_t reset;
4450         portid_t port_id;
4451 };
4452
4453 static void
4454 cmd_tx_vlan_reset_parsed(void *parsed_result,
4455                          __rte_unused struct cmdline *cl,
4456                          __rte_unused void *data)
4457 {
4458         struct cmd_tx_vlan_reset_result *res = parsed_result;
4459
4460         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4461                 return;
4462
4463         if (!port_is_stopped(res->port_id)) {
4464                 printf("Please stop port %d first\n", res->port_id);
4465                 return;
4466         }
4467
4468         tx_vlan_reset(res->port_id);
4469
4470         cmd_reconfig_device_queue(res->port_id, 1, 1);
4471 }
4472
4473 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4474         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4475                                  tx_vlan, "tx_vlan");
4476 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4477         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4478                                  reset, "reset");
4479 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4480         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4481                               port_id, RTE_UINT16);
4482
4483 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4484         .f = cmd_tx_vlan_reset_parsed,
4485         .data = NULL,
4486         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4487                 "VLAN header in packets sent on a port",
4488         .tokens = {
4489                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4490                 (void *)&cmd_tx_vlan_reset_reset,
4491                 (void *)&cmd_tx_vlan_reset_portid,
4492                 NULL,
4493         },
4494 };
4495
4496
4497 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4498 struct cmd_csum_result {
4499         cmdline_fixed_string_t csum;
4500         cmdline_fixed_string_t mode;
4501         cmdline_fixed_string_t proto;
4502         cmdline_fixed_string_t hwsw;
4503         portid_t port_id;
4504 };
4505
4506 static void
4507 csum_show(int port_id)
4508 {
4509         struct rte_eth_dev_info dev_info;
4510         uint64_t tx_offloads;
4511         int ret;
4512
4513         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4514         printf("Parse tunnel is %s\n",
4515                 (ports[port_id].parse_tunnel) ? "on" : "off");
4516         printf("IP checksum offload is %s\n",
4517                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4518         printf("UDP checksum offload is %s\n",
4519                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4520         printf("TCP checksum offload is %s\n",
4521                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4522         printf("SCTP checksum offload is %s\n",
4523                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4524         printf("Outer-Ip checksum offload is %s\n",
4525                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4526         printf("Outer-Udp checksum offload is %s\n",
4527                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4528
4529         /* display warnings if configuration is not supported by the NIC */
4530         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4531         if (ret != 0)
4532                 return;
4533
4534         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4535                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4536                 printf("Warning: hardware IP checksum enabled but not "
4537                         "supported by port %d\n", port_id);
4538         }
4539         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4540                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4541                 printf("Warning: hardware UDP checksum enabled but not "
4542                         "supported by port %d\n", port_id);
4543         }
4544         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4545                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4546                 printf("Warning: hardware TCP checksum enabled but not "
4547                         "supported by port %d\n", port_id);
4548         }
4549         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4550                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4551                 printf("Warning: hardware SCTP checksum enabled but not "
4552                         "supported by port %d\n", port_id);
4553         }
4554         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4555                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4556                 printf("Warning: hardware outer IP checksum enabled but not "
4557                         "supported by port %d\n", port_id);
4558         }
4559         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4560                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4561                         == 0) {
4562                 printf("Warning: hardware outer UDP checksum enabled but not "
4563                         "supported by port %d\n", port_id);
4564         }
4565 }
4566
4567 static void
4568 cmd_config_queue_tx_offloads(struct rte_port *port)
4569 {
4570         int k;
4571
4572         /* Apply queue tx offloads configuration */
4573         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4574                 port->tx_conf[k].offloads =
4575                         port->dev_conf.txmode.offloads;
4576 }
4577
4578 static void
4579 cmd_csum_parsed(void *parsed_result,
4580                        __rte_unused struct cmdline *cl,
4581                        __rte_unused void *data)
4582 {
4583         struct cmd_csum_result *res = parsed_result;
4584         int hw = 0;
4585         uint64_t csum_offloads = 0;
4586         struct rte_eth_dev_info dev_info;
4587         int ret;
4588
4589         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4590                 printf("invalid port %d\n", res->port_id);
4591                 return;
4592         }
4593         if (!port_is_stopped(res->port_id)) {
4594                 printf("Please stop port %d first\n", res->port_id);
4595                 return;
4596         }
4597
4598         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4599         if (ret != 0)
4600                 return;
4601
4602         if (!strcmp(res->mode, "set")) {
4603
4604                 if (!strcmp(res->hwsw, "hw"))
4605                         hw = 1;
4606
4607                 if (!strcmp(res->proto, "ip")) {
4608                         if (hw == 0 || (dev_info.tx_offload_capa &
4609                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4610                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4611                         } else {
4612                                 printf("IP checksum offload is not supported "
4613                                        "by port %u\n", res->port_id);
4614                         }
4615                 } else if (!strcmp(res->proto, "udp")) {
4616                         if (hw == 0 || (dev_info.tx_offload_capa &
4617                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4618                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4619                         } else {
4620                                 printf("UDP checksum offload is not supported "
4621                                        "by port %u\n", res->port_id);
4622                         }
4623                 } else if (!strcmp(res->proto, "tcp")) {
4624                         if (hw == 0 || (dev_info.tx_offload_capa &
4625                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4626                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4627                         } else {
4628                                 printf("TCP checksum offload is not supported "
4629                                        "by port %u\n", res->port_id);
4630                         }
4631                 } else if (!strcmp(res->proto, "sctp")) {
4632                         if (hw == 0 || (dev_info.tx_offload_capa &
4633                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4634                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4635                         } else {
4636                                 printf("SCTP checksum offload is not supported "
4637                                        "by port %u\n", res->port_id);
4638                         }
4639                 } else if (!strcmp(res->proto, "outer-ip")) {
4640                         if (hw == 0 || (dev_info.tx_offload_capa &
4641                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4642                                 csum_offloads |=
4643                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4644                         } else {
4645                                 printf("Outer IP checksum offload is not "
4646                                        "supported by port %u\n", res->port_id);
4647                         }
4648                 } else if (!strcmp(res->proto, "outer-udp")) {
4649                         if (hw == 0 || (dev_info.tx_offload_capa &
4650                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4651                                 csum_offloads |=
4652                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4653                         } else {
4654                                 printf("Outer UDP checksum offload is not "
4655                                        "supported by port %u\n", res->port_id);
4656                         }
4657                 }
4658
4659                 if (hw) {
4660                         ports[res->port_id].dev_conf.txmode.offloads |=
4661                                                         csum_offloads;
4662                 } else {
4663                         ports[res->port_id].dev_conf.txmode.offloads &=
4664                                                         (~csum_offloads);
4665                 }
4666                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4667         }
4668         csum_show(res->port_id);
4669
4670         cmd_reconfig_device_queue(res->port_id, 1, 1);
4671 }
4672
4673 cmdline_parse_token_string_t cmd_csum_csum =
4674         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4675                                 csum, "csum");
4676 cmdline_parse_token_string_t cmd_csum_mode =
4677         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4678                                 mode, "set");
4679 cmdline_parse_token_string_t cmd_csum_proto =
4680         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4681                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4682 cmdline_parse_token_string_t cmd_csum_hwsw =
4683         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4684                                 hwsw, "hw#sw");
4685 cmdline_parse_token_num_t cmd_csum_portid =
4686         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4687                                 port_id, RTE_UINT16);
4688
4689 cmdline_parse_inst_t cmd_csum_set = {
4690         .f = cmd_csum_parsed,
4691         .data = NULL,
4692         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4693                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4694                 "using csum forward engine",
4695         .tokens = {
4696                 (void *)&cmd_csum_csum,
4697                 (void *)&cmd_csum_mode,
4698                 (void *)&cmd_csum_proto,
4699                 (void *)&cmd_csum_hwsw,
4700                 (void *)&cmd_csum_portid,
4701                 NULL,
4702         },
4703 };
4704
4705 cmdline_parse_token_string_t cmd_csum_mode_show =
4706         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4707                                 mode, "show");
4708
4709 cmdline_parse_inst_t cmd_csum_show = {
4710         .f = cmd_csum_parsed,
4711         .data = NULL,
4712         .help_str = "csum show <port_id>: Show checksum offload configuration",
4713         .tokens = {
4714                 (void *)&cmd_csum_csum,
4715                 (void *)&cmd_csum_mode_show,
4716                 (void *)&cmd_csum_portid,
4717                 NULL,
4718         },
4719 };
4720
4721 /* Enable/disable tunnel parsing */
4722 struct cmd_csum_tunnel_result {
4723         cmdline_fixed_string_t csum;
4724         cmdline_fixed_string_t parse;
4725         cmdline_fixed_string_t onoff;
4726         portid_t port_id;
4727 };
4728
4729 static void
4730 cmd_csum_tunnel_parsed(void *parsed_result,
4731                        __rte_unused struct cmdline *cl,
4732                        __rte_unused void *data)
4733 {
4734         struct cmd_csum_tunnel_result *res = parsed_result;
4735
4736         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4737                 return;
4738
4739         if (!strcmp(res->onoff, "on"))
4740                 ports[res->port_id].parse_tunnel = 1;
4741         else
4742                 ports[res->port_id].parse_tunnel = 0;
4743
4744         csum_show(res->port_id);
4745 }
4746
4747 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4748         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4749                                 csum, "csum");
4750 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4751         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4752                                 parse, "parse-tunnel");
4753 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4754         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4755                                 onoff, "on#off");
4756 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4757         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4758                                 port_id, RTE_UINT16);
4759
4760 cmdline_parse_inst_t cmd_csum_tunnel = {
4761         .f = cmd_csum_tunnel_parsed,
4762         .data = NULL,
4763         .help_str = "csum parse-tunnel on|off <port_id>: "
4764                 "Enable/Disable parsing of tunnels for csum engine",
4765         .tokens = {
4766                 (void *)&cmd_csum_tunnel_csum,
4767                 (void *)&cmd_csum_tunnel_parse,
4768                 (void *)&cmd_csum_tunnel_onoff,
4769                 (void *)&cmd_csum_tunnel_portid,
4770                 NULL,
4771         },
4772 };
4773
4774 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4775 struct cmd_tso_set_result {
4776         cmdline_fixed_string_t tso;
4777         cmdline_fixed_string_t mode;
4778         uint16_t tso_segsz;
4779         portid_t port_id;
4780 };
4781
4782 static void
4783 cmd_tso_set_parsed(void *parsed_result,
4784                        __rte_unused struct cmdline *cl,
4785                        __rte_unused void *data)
4786 {
4787         struct cmd_tso_set_result *res = parsed_result;
4788         struct rte_eth_dev_info dev_info;
4789         int ret;
4790
4791         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4792                 return;
4793         if (!port_is_stopped(res->port_id)) {
4794                 printf("Please stop port %d first\n", res->port_id);
4795                 return;
4796         }
4797
4798         if (!strcmp(res->mode, "set"))
4799                 ports[res->port_id].tso_segsz = res->tso_segsz;
4800
4801         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4802         if (ret != 0)
4803                 return;
4804
4805         if ((ports[res->port_id].tso_segsz != 0) &&
4806                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4807                 printf("Error: TSO is not supported by port %d\n",
4808                        res->port_id);
4809                 return;
4810         }
4811
4812         if (ports[res->port_id].tso_segsz == 0) {
4813                 ports[res->port_id].dev_conf.txmode.offloads &=
4814                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4815                 printf("TSO for non-tunneled packets is disabled\n");
4816         } else {
4817                 ports[res->port_id].dev_conf.txmode.offloads |=
4818                                                 DEV_TX_OFFLOAD_TCP_TSO;
4819                 printf("TSO segment size for non-tunneled packets is %d\n",
4820                         ports[res->port_id].tso_segsz);
4821         }
4822         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4823
4824         /* display warnings if configuration is not supported by the NIC */
4825         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4826         if (ret != 0)
4827                 return;
4828
4829         if ((ports[res->port_id].tso_segsz != 0) &&
4830                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4831                 printf("Warning: TSO enabled but not "
4832                         "supported by port %d\n", res->port_id);
4833         }
4834
4835         cmd_reconfig_device_queue(res->port_id, 1, 1);
4836 }
4837
4838 cmdline_parse_token_string_t cmd_tso_set_tso =
4839         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4840                                 tso, "tso");
4841 cmdline_parse_token_string_t cmd_tso_set_mode =
4842         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4843                                 mode, "set");
4844 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4845         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4846                                 tso_segsz, RTE_UINT16);
4847 cmdline_parse_token_num_t cmd_tso_set_portid =
4848         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4849                                 port_id, RTE_UINT16);
4850
4851 cmdline_parse_inst_t cmd_tso_set = {
4852         .f = cmd_tso_set_parsed,
4853         .data = NULL,
4854         .help_str = "tso set <tso_segsz> <port_id>: "
4855                 "Set TSO segment size of non-tunneled packets for csum engine "
4856                 "(0 to disable)",
4857         .tokens = {
4858                 (void *)&cmd_tso_set_tso,
4859                 (void *)&cmd_tso_set_mode,
4860                 (void *)&cmd_tso_set_tso_segsz,
4861                 (void *)&cmd_tso_set_portid,
4862                 NULL,
4863         },
4864 };
4865
4866 cmdline_parse_token_string_t cmd_tso_show_mode =
4867         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4868                                 mode, "show");
4869
4870
4871 cmdline_parse_inst_t cmd_tso_show = {
4872         .f = cmd_tso_set_parsed,
4873         .data = NULL,
4874         .help_str = "tso show <port_id>: "
4875                 "Show TSO segment size of non-tunneled packets for csum engine",
4876         .tokens = {
4877                 (void *)&cmd_tso_set_tso,
4878                 (void *)&cmd_tso_show_mode,
4879                 (void *)&cmd_tso_set_portid,
4880                 NULL,
4881         },
4882 };
4883
4884 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4885 struct cmd_tunnel_tso_set_result {
4886         cmdline_fixed_string_t tso;
4887         cmdline_fixed_string_t mode;
4888         uint16_t tso_segsz;
4889         portid_t port_id;
4890 };
4891
4892 static struct rte_eth_dev_info
4893 check_tunnel_tso_nic_support(portid_t port_id)
4894 {
4895         struct rte_eth_dev_info dev_info;
4896
4897         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4898                 return dev_info;
4899
4900         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4901                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4902                        "not enabled for port %d\n", port_id);
4903         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4904                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4905                        "not enabled for port %d\n", port_id);
4906         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4907                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4908                        "not enabled for port %d\n", port_id);
4909         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4910                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4911                        "not enabled for port %d\n", port_id);
4912         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4913                 printf("Warning: IP TUNNEL TSO not supported therefore "
4914                        "not enabled for port %d\n", port_id);
4915         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4916                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4917                        "not enabled for port %d\n", port_id);
4918         return dev_info;
4919 }
4920
4921 static void
4922 cmd_tunnel_tso_set_parsed(void *parsed_result,
4923                           __rte_unused struct cmdline *cl,
4924                           __rte_unused void *data)
4925 {
4926         struct cmd_tunnel_tso_set_result *res = parsed_result;
4927         struct rte_eth_dev_info dev_info;
4928
4929         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4930                 return;
4931         if (!port_is_stopped(res->port_id)) {
4932                 printf("Please stop port %d first\n", res->port_id);
4933                 return;
4934         }
4935
4936         if (!strcmp(res->mode, "set"))
4937                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4938
4939         dev_info = check_tunnel_tso_nic_support(res->port_id);
4940         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4941                 ports[res->port_id].dev_conf.txmode.offloads &=
4942                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4943                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4944                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4945                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4946                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4947                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4948                 printf("TSO for tunneled packets is disabled\n");
4949         } else {
4950                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4951                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4952                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4953                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4954                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4955                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4956
4957                 ports[res->port_id].dev_conf.txmode.offloads |=
4958                         (tso_offloads & dev_info.tx_offload_capa);
4959                 printf("TSO segment size for tunneled packets is %d\n",
4960                         ports[res->port_id].tunnel_tso_segsz);
4961
4962                 /* Below conditions are needed to make it work:
4963                  * (1) tunnel TSO is supported by the NIC;
4964                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4965                  * are recognized;
4966                  * (3) for tunneled pkts with outer L3 of IPv4,
4967                  * "csum set outer-ip" must be set to hw, because after tso,
4968                  * total_len of outer IP header is changed, and the checksum
4969                  * of outer IP header calculated by sw should be wrong; that
4970                  * is not necessary for IPv6 tunneled pkts because there's no
4971                  * checksum in IP header anymore.
4972                  */
4973
4974                 if (!ports[res->port_id].parse_tunnel)
4975                         printf("Warning: csum parse_tunnel must be set "
4976                                 "so that tunneled packets are recognized\n");
4977                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4978                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4979                         printf("Warning: csum set outer-ip must be set to hw "
4980                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4981         }
4982
4983         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4984         cmd_reconfig_device_queue(res->port_id, 1, 1);
4985 }
4986
4987 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4988         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4989                                 tso, "tunnel_tso");
4990 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4991         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4992                                 mode, "set");
4993 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4994         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4995                                 tso_segsz, RTE_UINT16);
4996 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4997         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4998                                 port_id, RTE_UINT16);
4999
5000 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5001         .f = cmd_tunnel_tso_set_parsed,
5002         .data = NULL,
5003         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5004                 "Set TSO segment size of tunneled packets for csum engine "
5005                 "(0 to disable)",
5006         .tokens = {
5007                 (void *)&cmd_tunnel_tso_set_tso,
5008                 (void *)&cmd_tunnel_tso_set_mode,
5009                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5010                 (void *)&cmd_tunnel_tso_set_portid,
5011                 NULL,
5012         },
5013 };
5014
5015 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5016         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5017                                 mode, "show");
5018
5019
5020 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5021         .f = cmd_tunnel_tso_set_parsed,
5022         .data = NULL,
5023         .help_str = "tunnel_tso show <port_id> "
5024                 "Show TSO segment size of tunneled packets for csum engine",
5025         .tokens = {
5026                 (void *)&cmd_tunnel_tso_set_tso,
5027                 (void *)&cmd_tunnel_tso_show_mode,
5028                 (void *)&cmd_tunnel_tso_set_portid,
5029                 NULL,
5030         },
5031 };
5032
5033 /* *** SET GRO FOR A PORT *** */
5034 struct cmd_gro_enable_result {
5035         cmdline_fixed_string_t cmd_set;
5036         cmdline_fixed_string_t cmd_port;
5037         cmdline_fixed_string_t cmd_keyword;
5038         cmdline_fixed_string_t cmd_onoff;
5039         portid_t cmd_pid;
5040 };
5041
5042 static void
5043 cmd_gro_enable_parsed(void *parsed_result,
5044                 __rte_unused struct cmdline *cl,
5045                 __rte_unused void *data)
5046 {
5047         struct cmd_gro_enable_result *res;
5048
5049         res = parsed_result;
5050         if (!strcmp(res->cmd_keyword, "gro"))
5051                 setup_gro(res->cmd_onoff, res->cmd_pid);
5052 }
5053
5054 cmdline_parse_token_string_t cmd_gro_enable_set =
5055         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5056                         cmd_set, "set");
5057 cmdline_parse_token_string_t cmd_gro_enable_port =
5058         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5059                         cmd_keyword, "port");
5060 cmdline_parse_token_num_t cmd_gro_enable_pid =
5061         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5062                         cmd_pid, RTE_UINT16);
5063 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5064         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5065                         cmd_keyword, "gro");
5066 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5067         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5068                         cmd_onoff, "on#off");
5069
5070 cmdline_parse_inst_t cmd_gro_enable = {
5071         .f = cmd_gro_enable_parsed,
5072         .data = NULL,
5073         .help_str = "set port <port_id> gro on|off",
5074         .tokens = {
5075                 (void *)&cmd_gro_enable_set,
5076                 (void *)&cmd_gro_enable_port,
5077                 (void *)&cmd_gro_enable_pid,
5078                 (void *)&cmd_gro_enable_keyword,
5079                 (void *)&cmd_gro_enable_onoff,
5080                 NULL,
5081         },
5082 };
5083
5084 /* *** DISPLAY GRO CONFIGURATION *** */
5085 struct cmd_gro_show_result {
5086         cmdline_fixed_string_t cmd_show;
5087         cmdline_fixed_string_t cmd_port;
5088         cmdline_fixed_string_t cmd_keyword;
5089         portid_t cmd_pid;
5090 };
5091
5092 static void
5093 cmd_gro_show_parsed(void *parsed_result,
5094                 __rte_unused struct cmdline *cl,
5095                 __rte_unused void *data)
5096 {
5097         struct cmd_gro_show_result *res;
5098
5099         res = parsed_result;
5100         if (!strcmp(res->cmd_keyword, "gro"))
5101                 show_gro(res->cmd_pid);
5102 }
5103
5104 cmdline_parse_token_string_t cmd_gro_show_show =
5105         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5106                         cmd_show, "show");
5107 cmdline_parse_token_string_t cmd_gro_show_port =
5108         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5109                         cmd_port, "port");
5110 cmdline_parse_token_num_t cmd_gro_show_pid =
5111         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5112                         cmd_pid, RTE_UINT16);
5113 cmdline_parse_token_string_t cmd_gro_show_keyword =
5114         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5115                         cmd_keyword, "gro");
5116
5117 cmdline_parse_inst_t cmd_gro_show = {
5118         .f = cmd_gro_show_parsed,
5119         .data = NULL,
5120         .help_str = "show port <port_id> gro",
5121         .tokens = {
5122                 (void *)&cmd_gro_show_show,
5123                 (void *)&cmd_gro_show_port,
5124                 (void *)&cmd_gro_show_pid,
5125                 (void *)&cmd_gro_show_keyword,
5126                 NULL,
5127         },
5128 };
5129
5130 /* *** SET FLUSH CYCLES FOR GRO *** */
5131 struct cmd_gro_flush_result {
5132         cmdline_fixed_string_t cmd_set;
5133         cmdline_fixed_string_t cmd_keyword;
5134         cmdline_fixed_string_t cmd_flush;
5135         uint8_t cmd_cycles;
5136 };
5137
5138 static void
5139 cmd_gro_flush_parsed(void *parsed_result,
5140                 __rte_unused struct cmdline *cl,
5141                 __rte_unused void *data)
5142 {
5143         struct cmd_gro_flush_result *res;
5144
5145         res = parsed_result;
5146         if ((!strcmp(res->cmd_keyword, "gro")) &&
5147                         (!strcmp(res->cmd_flush, "flush")))
5148                 setup_gro_flush_cycles(res->cmd_cycles);
5149 }
5150
5151 cmdline_parse_token_string_t cmd_gro_flush_set =
5152         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5153                         cmd_set, "set");
5154 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5155         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5156                         cmd_keyword, "gro");
5157 cmdline_parse_token_string_t cmd_gro_flush_flush =
5158         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5159                         cmd_flush, "flush");
5160 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5161         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5162                         cmd_cycles, RTE_UINT8);
5163
5164 cmdline_parse_inst_t cmd_gro_flush = {
5165         .f = cmd_gro_flush_parsed,
5166         .data = NULL,
5167         .help_str = "set gro flush <cycles>",
5168         .tokens = {
5169                 (void *)&cmd_gro_flush_set,
5170                 (void *)&cmd_gro_flush_keyword,
5171                 (void *)&cmd_gro_flush_flush,
5172                 (void *)&cmd_gro_flush_cycles,
5173                 NULL,
5174         },
5175 };
5176
5177 /* *** ENABLE/DISABLE GSO *** */
5178 struct cmd_gso_enable_result {
5179         cmdline_fixed_string_t cmd_set;
5180         cmdline_fixed_string_t cmd_port;
5181         cmdline_fixed_string_t cmd_keyword;
5182         cmdline_fixed_string_t cmd_mode;
5183         portid_t cmd_pid;
5184 };
5185
5186 static void
5187 cmd_gso_enable_parsed(void *parsed_result,
5188                 __rte_unused struct cmdline *cl,
5189                 __rte_unused void *data)
5190 {
5191         struct cmd_gso_enable_result *res;
5192
5193         res = parsed_result;
5194         if (!strcmp(res->cmd_keyword, "gso"))
5195                 setup_gso(res->cmd_mode, res->cmd_pid);
5196 }
5197
5198 cmdline_parse_token_string_t cmd_gso_enable_set =
5199         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5200                         cmd_set, "set");
5201 cmdline_parse_token_string_t cmd_gso_enable_port =
5202         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5203                         cmd_port, "port");
5204 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5205         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5206                         cmd_keyword, "gso");
5207 cmdline_parse_token_string_t cmd_gso_enable_mode =
5208         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5209                         cmd_mode, "on#off");
5210 cmdline_parse_token_num_t cmd_gso_enable_pid =
5211         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5212                         cmd_pid, RTE_UINT16);
5213
5214 cmdline_parse_inst_t cmd_gso_enable = {
5215         .f = cmd_gso_enable_parsed,
5216         .data = NULL,
5217         .help_str = "set port <port_id> gso on|off",
5218         .tokens = {
5219                 (void *)&cmd_gso_enable_set,
5220                 (void *)&cmd_gso_enable_port,
5221                 (void *)&cmd_gso_enable_pid,
5222                 (void *)&cmd_gso_enable_keyword,
5223                 (void *)&cmd_gso_enable_mode,
5224                 NULL,
5225         },
5226 };
5227
5228 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5229 struct cmd_gso_size_result {
5230         cmdline_fixed_string_t cmd_set;
5231         cmdline_fixed_string_t cmd_keyword;
5232         cmdline_fixed_string_t cmd_segsz;
5233         uint16_t cmd_size;
5234 };
5235
5236 static void
5237 cmd_gso_size_parsed(void *parsed_result,
5238                        __rte_unused struct cmdline *cl,
5239                        __rte_unused void *data)
5240 {
5241         struct cmd_gso_size_result *res = parsed_result;
5242
5243         if (test_done == 0) {
5244                 printf("Before setting GSO segsz, please first"
5245                                 " stop forwarding\n");
5246                 return;
5247         }
5248
5249         if (!strcmp(res->cmd_keyword, "gso") &&
5250                         !strcmp(res->cmd_segsz, "segsz")) {
5251                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5252                         printf("gso_size should be larger than %zu."
5253                                         " Please input a legal value\n",
5254                                         RTE_GSO_SEG_SIZE_MIN);
5255                 else
5256                         gso_max_segment_size = res->cmd_size;
5257         }
5258 }
5259
5260 cmdline_parse_token_string_t cmd_gso_size_set =
5261         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5262                                 cmd_set, "set");
5263 cmdline_parse_token_string_t cmd_gso_size_keyword =
5264         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5265                                 cmd_keyword, "gso");
5266 cmdline_parse_token_string_t cmd_gso_size_segsz =
5267         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5268                                 cmd_segsz, "segsz");
5269 cmdline_parse_token_num_t cmd_gso_size_size =
5270         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5271                                 cmd_size, RTE_UINT16);
5272
5273 cmdline_parse_inst_t cmd_gso_size = {
5274         .f = cmd_gso_size_parsed,
5275         .data = NULL,
5276         .help_str = "set gso segsz <length>",
5277         .tokens = {
5278                 (void *)&cmd_gso_size_set,
5279                 (void *)&cmd_gso_size_keyword,
5280                 (void *)&cmd_gso_size_segsz,
5281                 (void *)&cmd_gso_size_size,
5282                 NULL,
5283         },
5284 };
5285
5286 /* *** SHOW GSO CONFIGURATION *** */
5287 struct cmd_gso_show_result {
5288         cmdline_fixed_string_t cmd_show;
5289         cmdline_fixed_string_t cmd_port;
5290         cmdline_fixed_string_t cmd_keyword;
5291         portid_t cmd_pid;
5292 };
5293
5294 static void
5295 cmd_gso_show_parsed(void *parsed_result,
5296                        __rte_unused struct cmdline *cl,
5297                        __rte_unused void *data)
5298 {
5299         struct cmd_gso_show_result *res = parsed_result;
5300
5301         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5302                 printf("invalid port id %u\n", res->cmd_pid);
5303                 return;
5304         }
5305         if (!strcmp(res->cmd_keyword, "gso")) {
5306                 if (gso_ports[res->cmd_pid].enable) {
5307                         printf("Max GSO'd packet size: %uB\n"
5308                                         "Supported GSO types: TCP/IPv4, "
5309                                         "UDP/IPv4, VxLAN with inner "
5310                                         "TCP/IPv4 packet, GRE with inner "
5311                                         "TCP/IPv4 packet\n",
5312                                         gso_max_segment_size);
5313                 } else
5314                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5315         }
5316 }
5317
5318 cmdline_parse_token_string_t cmd_gso_show_show =
5319 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5320                 cmd_show, "show");
5321 cmdline_parse_token_string_t cmd_gso_show_port =
5322 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5323                 cmd_port, "port");
5324 cmdline_parse_token_string_t cmd_gso_show_keyword =
5325         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5326                                 cmd_keyword, "gso");
5327 cmdline_parse_token_num_t cmd_gso_show_pid =
5328         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5329                                 cmd_pid, RTE_UINT16);
5330
5331 cmdline_parse_inst_t cmd_gso_show = {
5332         .f = cmd_gso_show_parsed,
5333         .data = NULL,
5334         .help_str = "show port <port_id> gso",
5335         .tokens = {
5336                 (void *)&cmd_gso_show_show,
5337                 (void *)&cmd_gso_show_port,
5338                 (void *)&cmd_gso_show_pid,
5339                 (void *)&cmd_gso_show_keyword,
5340                 NULL,
5341         },
5342 };
5343
5344 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5345 struct cmd_set_flush_rx {
5346         cmdline_fixed_string_t set;
5347         cmdline_fixed_string_t flush_rx;
5348         cmdline_fixed_string_t mode;
5349 };
5350
5351 static void
5352 cmd_set_flush_rx_parsed(void *parsed_result,
5353                 __rte_unused struct cmdline *cl,
5354                 __rte_unused void *data)
5355 {
5356         struct cmd_set_flush_rx *res = parsed_result;
5357         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5358 }
5359
5360 cmdline_parse_token_string_t cmd_setflushrx_set =
5361         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5362                         set, "set");
5363 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5364         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5365                         flush_rx, "flush_rx");
5366 cmdline_parse_token_string_t cmd_setflushrx_mode =
5367         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5368                         mode, "on#off");
5369
5370
5371 cmdline_parse_inst_t cmd_set_flush_rx = {
5372         .f = cmd_set_flush_rx_parsed,
5373         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5374         .data = NULL,
5375         .tokens = {
5376                 (void *)&cmd_setflushrx_set,
5377                 (void *)&cmd_setflushrx_flush_rx,
5378                 (void *)&cmd_setflushrx_mode,
5379                 NULL,
5380         },
5381 };
5382
5383 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5384 struct cmd_set_link_check {
5385         cmdline_fixed_string_t set;
5386         cmdline_fixed_string_t link_check;
5387         cmdline_fixed_string_t mode;
5388 };
5389
5390 static void
5391 cmd_set_link_check_parsed(void *parsed_result,
5392                 __rte_unused struct cmdline *cl,
5393                 __rte_unused void *data)
5394 {
5395         struct cmd_set_link_check *res = parsed_result;
5396         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5397 }
5398
5399 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5400         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5401                         set, "set");
5402 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5403         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5404                         link_check, "link_check");
5405 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5406         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5407                         mode, "on#off");
5408
5409
5410 cmdline_parse_inst_t cmd_set_link_check = {
5411         .f = cmd_set_link_check_parsed,
5412         .help_str = "set link_check on|off: Enable/Disable link status check "
5413                     "when starting/stopping a port",
5414         .data = NULL,
5415         .tokens = {
5416                 (void *)&cmd_setlinkcheck_set,
5417                 (void *)&cmd_setlinkcheck_link_check,
5418                 (void *)&cmd_setlinkcheck_mode,
5419                 NULL,
5420         },
5421 };
5422
5423 /* *** SET NIC BYPASS MODE *** */
5424 struct cmd_set_bypass_mode_result {
5425         cmdline_fixed_string_t set;
5426         cmdline_fixed_string_t bypass;
5427         cmdline_fixed_string_t mode;
5428         cmdline_fixed_string_t value;
5429         portid_t port_id;
5430 };
5431
5432 static void
5433 cmd_set_bypass_mode_parsed(void *parsed_result,
5434                 __rte_unused struct cmdline *cl,
5435                 __rte_unused void *data)
5436 {
5437         struct cmd_set_bypass_mode_result *res = parsed_result;
5438         portid_t port_id = res->port_id;
5439         int32_t rc = -EINVAL;
5440
5441 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5442         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5443
5444         if (!strcmp(res->value, "bypass"))
5445                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5446         else if (!strcmp(res->value, "isolate"))
5447                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5448         else
5449                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5450
5451         /* Set the bypass mode for the relevant port. */
5452         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5453 #endif
5454         if (rc != 0)
5455                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5456 }
5457
5458 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5459         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5460                         set, "set");
5461 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5462         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5463                         bypass, "bypass");
5464 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5465         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5466                         mode, "mode");
5467 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5468         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5469                         value, "normal#bypass#isolate");
5470 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5471         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5472                                 port_id, RTE_UINT16);
5473
5474 cmdline_parse_inst_t cmd_set_bypass_mode = {
5475         .f = cmd_set_bypass_mode_parsed,
5476         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5477                     "Set the NIC bypass mode for port_id",
5478         .data = NULL,
5479         .tokens = {
5480                 (void *)&cmd_setbypass_mode_set,
5481                 (void *)&cmd_setbypass_mode_bypass,
5482                 (void *)&cmd_setbypass_mode_mode,
5483                 (void *)&cmd_setbypass_mode_value,
5484                 (void *)&cmd_setbypass_mode_port,
5485                 NULL,
5486         },
5487 };
5488
5489 /* *** SET NIC BYPASS EVENT *** */
5490 struct cmd_set_bypass_event_result {
5491         cmdline_fixed_string_t set;
5492         cmdline_fixed_string_t bypass;
5493         cmdline_fixed_string_t event;
5494         cmdline_fixed_string_t event_value;
5495         cmdline_fixed_string_t mode;
5496         cmdline_fixed_string_t mode_value;
5497         portid_t port_id;
5498 };
5499
5500 static void
5501 cmd_set_bypass_event_parsed(void *parsed_result,
5502                 __rte_unused struct cmdline *cl,
5503                 __rte_unused void *data)
5504 {
5505         int32_t rc = -EINVAL;
5506         struct cmd_set_bypass_event_result *res = parsed_result;
5507         portid_t port_id = res->port_id;
5508
5509 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5510         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5511         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5512
5513         if (!strcmp(res->event_value, "timeout"))
5514                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5515         else if (!strcmp(res->event_value, "os_on"))
5516                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5517         else if (!strcmp(res->event_value, "os_off"))
5518                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5519         else if (!strcmp(res->event_value, "power_on"))
5520                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5521         else if (!strcmp(res->event_value, "power_off"))
5522                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5523         else
5524                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5525
5526         if (!strcmp(res->mode_value, "bypass"))
5527                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5528         else if (!strcmp(res->mode_value, "isolate"))
5529                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5530         else
5531                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5532
5533         /* Set the watchdog timeout. */
5534         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5535
5536                 rc = -EINVAL;
5537                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5538                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5539                                                            bypass_timeout);
5540                 }
5541                 if (rc != 0) {
5542                         printf("Failed to set timeout value %u "
5543                         "for port %d, errto code: %d.\n",
5544                         bypass_timeout, port_id, rc);
5545                 }
5546         }
5547
5548         /* Set the bypass event to transition to bypass mode. */
5549         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5550                                               bypass_mode);
5551 #endif
5552
5553         if (rc != 0)
5554                 printf("\t Failed to set bypass event for port = %d.\n",
5555                        port_id);
5556 }
5557
5558 cmdline_parse_token_string_t cmd_setbypass_event_set =
5559         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5560                         set, "set");
5561 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5562         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5563                         bypass, "bypass");
5564 cmdline_parse_token_string_t cmd_setbypass_event_event =
5565         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5566                         event, "event");
5567 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5568         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5569                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5570 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5571         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5572                         mode, "mode");
5573 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5574         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5575                         mode_value, "normal#bypass#isolate");
5576 cmdline_parse_token_num_t cmd_setbypass_event_port =
5577         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5578                                 port_id, RTE_UINT16);
5579
5580 cmdline_parse_inst_t cmd_set_bypass_event = {
5581         .f = cmd_set_bypass_event_parsed,
5582         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5583                 "power_off mode normal|bypass|isolate <port_id>: "
5584                 "Set the NIC bypass event mode for port_id",
5585         .data = NULL,
5586         .tokens = {
5587                 (void *)&cmd_setbypass_event_set,
5588                 (void *)&cmd_setbypass_event_bypass,
5589                 (void *)&cmd_setbypass_event_event,
5590                 (void *)&cmd_setbypass_event_event_value,
5591                 (void *)&cmd_setbypass_event_mode,
5592                 (void *)&cmd_setbypass_event_mode_value,
5593                 (void *)&cmd_setbypass_event_port,
5594                 NULL,
5595         },
5596 };
5597
5598
5599 /* *** SET NIC BYPASS TIMEOUT *** */
5600 struct cmd_set_bypass_timeout_result {
5601         cmdline_fixed_string_t set;
5602         cmdline_fixed_string_t bypass;
5603         cmdline_fixed_string_t timeout;
5604         cmdline_fixed_string_t value;
5605 };
5606
5607 static void
5608 cmd_set_bypass_timeout_parsed(void *parsed_result,
5609                 __rte_unused struct cmdline *cl,
5610                 __rte_unused void *data)
5611 {
5612         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5613
5614 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5615         if (!strcmp(res->value, "1.5"))
5616                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5617         else if (!strcmp(res->value, "2"))
5618                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5619         else if (!strcmp(res->value, "3"))
5620                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5621         else if (!strcmp(res->value, "4"))
5622                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5623         else if (!strcmp(res->value, "8"))
5624                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5625         else if (!strcmp(res->value, "16"))
5626                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5627         else if (!strcmp(res->value, "32"))
5628                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5629         else
5630                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5631 #endif
5632 }
5633
5634 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5636                         set, "set");
5637 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5639                         bypass, "bypass");
5640 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5642                         timeout, "timeout");
5643 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5644         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5645                         value, "0#1.5#2#3#4#8#16#32");
5646
5647 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5648         .f = cmd_set_bypass_timeout_parsed,
5649         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5650                 "Set the NIC bypass watchdog timeout in seconds",
5651         .data = NULL,
5652         .tokens = {
5653                 (void *)&cmd_setbypass_timeout_set,
5654                 (void *)&cmd_setbypass_timeout_bypass,
5655                 (void *)&cmd_setbypass_timeout_timeout,
5656                 (void *)&cmd_setbypass_timeout_value,
5657                 NULL,
5658         },
5659 };
5660
5661 /* *** SHOW NIC BYPASS MODE *** */
5662 struct cmd_show_bypass_config_result {
5663         cmdline_fixed_string_t show;
5664         cmdline_fixed_string_t bypass;
5665         cmdline_fixed_string_t config;
5666         portid_t port_id;
5667 };
5668
5669 static void
5670 cmd_show_bypass_config_parsed(void *parsed_result,
5671                 __rte_unused struct cmdline *cl,
5672                 __rte_unused void *data)
5673 {
5674         struct cmd_show_bypass_config_result *res = parsed_result;
5675         portid_t port_id = res->port_id;
5676         int rc = -EINVAL;
5677 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5678         uint32_t event_mode;
5679         uint32_t bypass_mode;
5680         uint32_t timeout = bypass_timeout;
5681         unsigned int i;
5682
5683         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5684                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5685         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5686                 {"UNKNOWN", "normal", "bypass", "isolate"};
5687         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5688                 "NONE",
5689                 "OS/board on",
5690                 "power supply on",
5691                 "OS/board off",
5692                 "power supply off",
5693                 "timeout"};
5694
5695         /* Display the bypass mode.*/
5696         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5697                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5698                 return;
5699         }
5700         else {
5701                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5702                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5703
5704                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5705         }
5706
5707         /* Display the bypass timeout.*/
5708         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5709                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5710
5711         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5712
5713         /* Display the bypass events and associated modes. */
5714         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5715
5716                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5717                         printf("\tFailed to get bypass mode for event = %s\n",
5718                                 events[i]);
5719                 } else {
5720                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5721                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5722
5723                         printf("\tbypass event: %-16s = %s\n", events[i],
5724                                 modes[event_mode]);
5725                 }
5726         }
5727 #endif
5728         if (rc != 0)
5729                 printf("\tFailed to get bypass configuration for port = %d\n",
5730                        port_id);
5731 }
5732
5733 cmdline_parse_token_string_t cmd_showbypass_config_show =
5734         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5735                         show, "show");
5736 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5737         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5738                         bypass, "bypass");
5739 cmdline_parse_token_string_t cmd_showbypass_config_config =
5740         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5741                         config, "config");
5742 cmdline_parse_token_num_t cmd_showbypass_config_port =
5743         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5744                                 port_id, RTE_UINT16);
5745
5746 cmdline_parse_inst_t cmd_show_bypass_config = {
5747         .f = cmd_show_bypass_config_parsed,
5748         .help_str = "show bypass config <port_id>: "
5749                     "Show the NIC bypass config for port_id",
5750         .data = NULL,
5751         .tokens = {
5752                 (void *)&cmd_showbypass_config_show,
5753                 (void *)&cmd_showbypass_config_bypass,
5754                 (void *)&cmd_showbypass_config_config,
5755                 (void *)&cmd_showbypass_config_port,
5756                 NULL,
5757         },
5758 };
5759
5760 #ifdef RTE_NET_BOND
5761 /* *** SET BONDING MODE *** */
5762 struct cmd_set_bonding_mode_result {
5763         cmdline_fixed_string_t set;
5764         cmdline_fixed_string_t bonding;
5765         cmdline_fixed_string_t mode;
5766         uint8_t value;
5767         portid_t port_id;
5768 };
5769
5770 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5771                 __rte_unused  struct cmdline *cl,
5772                 __rte_unused void *data)
5773 {
5774         struct cmd_set_bonding_mode_result *res = parsed_result;
5775         portid_t port_id = res->port_id;
5776
5777         /* Set the bonding mode for the relevant port. */
5778         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5779                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5780 }
5781
5782 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5783 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5784                 set, "set");
5785 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5786 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5787                 bonding, "bonding");
5788 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5789 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5790                 mode, "mode");
5791 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5792 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5793                 value, RTE_UINT8);
5794 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5795 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5796                 port_id, RTE_UINT16);
5797
5798 cmdline_parse_inst_t cmd_set_bonding_mode = {
5799                 .f = cmd_set_bonding_mode_parsed,
5800                 .help_str = "set bonding mode <mode_value> <port_id>: "
5801                         "Set the bonding mode for port_id",
5802                 .data = NULL,
5803                 .tokens = {
5804                                 (void *) &cmd_setbonding_mode_set,
5805                                 (void *) &cmd_setbonding_mode_bonding,
5806                                 (void *) &cmd_setbonding_mode_mode,
5807                                 (void *) &cmd_setbonding_mode_value,
5808                                 (void *) &cmd_setbonding_mode_port,
5809                                 NULL
5810                 }
5811 };
5812
5813 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5814 struct cmd_set_bonding_lacp_dedicated_queues_result {
5815         cmdline_fixed_string_t set;
5816         cmdline_fixed_string_t bonding;
5817         cmdline_fixed_string_t lacp;
5818         cmdline_fixed_string_t dedicated_queues;
5819         portid_t port_id;
5820         cmdline_fixed_string_t mode;
5821 };
5822
5823 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5824                 __rte_unused  struct cmdline *cl,
5825                 __rte_unused void *data)
5826 {
5827         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5828         portid_t port_id = res->port_id;
5829         struct rte_port *port;
5830
5831         port = &ports[port_id];
5832
5833         /** Check if the port is not started **/
5834         if (port->port_status != RTE_PORT_STOPPED) {
5835                 printf("Please stop port %d first\n", port_id);
5836                 return;
5837         }
5838
5839         if (!strcmp(res->mode, "enable")) {
5840                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5841                         printf("Dedicate queues for LACP control packets"
5842                                         " enabled\n");
5843                 else
5844                         printf("Enabling dedicate queues for LACP control "
5845                                         "packets on port %d failed\n", port_id);
5846         } else if (!strcmp(res->mode, "disable")) {
5847                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5848                         printf("Dedicated queues for LACP control packets "
5849                                         "disabled\n");
5850                 else
5851                         printf("Disabling dedicated queues for LACP control "
5852                                         "traffic on port %d failed\n", port_id);
5853         }
5854 }
5855
5856 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5857 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5858                 set, "set");
5859 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5860 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5861                 bonding, "bonding");
5862 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5863 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5864                 lacp, "lacp");
5865 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5866 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5867                 dedicated_queues, "dedicated_queues");
5868 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5869 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5870                 port_id, RTE_UINT16);
5871 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5872 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5873                 mode, "enable#disable");
5874
5875 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5876                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5877                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5878                         "enable|disable: "
5879                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5880                 .data = NULL,
5881                 .tokens = {
5882                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5883                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5884                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5885                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5886                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5887                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5888                         NULL
5889                 }
5890 };
5891
5892 /* *** SET BALANCE XMIT POLICY *** */
5893 struct cmd_set_bonding_balance_xmit_policy_result {
5894         cmdline_fixed_string_t set;
5895         cmdline_fixed_string_t bonding;
5896         cmdline_fixed_string_t balance_xmit_policy;
5897         portid_t port_id;
5898         cmdline_fixed_string_t policy;
5899 };
5900
5901 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5902                 __rte_unused  struct cmdline *cl,
5903                 __rte_unused void *data)
5904 {
5905         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5906         portid_t port_id = res->port_id;
5907         uint8_t policy;
5908
5909         if (!strcmp(res->policy, "l2")) {
5910                 policy = BALANCE_XMIT_POLICY_LAYER2;
5911         } else if (!strcmp(res->policy, "l23")) {
5912                 policy = BALANCE_XMIT_POLICY_LAYER23;
5913         } else if (!strcmp(res->policy, "l34")) {
5914                 policy = BALANCE_XMIT_POLICY_LAYER34;
5915         } else {
5916                 printf("\t Invalid xmit policy selection");
5917                 return;
5918         }
5919
5920         /* Set the bonding mode for the relevant port. */
5921         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5922                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5923                                 port_id);
5924         }
5925 }
5926
5927 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5928 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5929                 set, "set");
5930 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5931 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5932                 bonding, "bonding");
5933 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5934 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5935                 balance_xmit_policy, "balance_xmit_policy");
5936 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5937 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5938                 port_id, RTE_UINT16);
5939 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5940 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5941                 policy, "l2#l23#l34");
5942
5943 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5944                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5945                 .help_str = "set bonding balance_xmit_policy <port_id> "
5946                         "l2|l23|l34: "
5947                         "Set the bonding balance_xmit_policy for port_id",
5948                 .data = NULL,
5949                 .tokens = {
5950                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5951                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5952                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5953                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5954                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5955                                 NULL
5956                 }
5957 };
5958
5959 /* *** SHOW NIC BONDING CONFIGURATION *** */
5960 struct cmd_show_bonding_config_result {
5961         cmdline_fixed_string_t show;
5962         cmdline_fixed_string_t bonding;
5963         cmdline_fixed_string_t config;
5964         portid_t port_id;
5965 };
5966
5967 static void cmd_show_bonding_config_parsed(void *parsed_result,
5968                 __rte_unused  struct cmdline *cl,
5969                 __rte_unused void *data)
5970 {
5971         struct cmd_show_bonding_config_result *res = parsed_result;
5972         int bonding_mode, agg_mode;
5973         portid_t slaves[RTE_MAX_ETHPORTS];
5974         int num_slaves, num_active_slaves;
5975         int primary_id;
5976         int i;
5977         portid_t port_id = res->port_id;
5978
5979         /* Display the bonding mode.*/
5980         bonding_mode = rte_eth_bond_mode_get(port_id);
5981         if (bonding_mode < 0) {
5982                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5983                 return;
5984         } else
5985                 printf("\tBonding mode: %d\n", bonding_mode);
5986
5987         if (bonding_mode == BONDING_MODE_BALANCE) {
5988                 int balance_xmit_policy;
5989
5990                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5991                 if (balance_xmit_policy < 0) {
5992                         printf("\tFailed to get balance xmit policy for port = %d\n",
5993                                         port_id);
5994                         return;
5995                 } else {
5996                         printf("\tBalance Xmit Policy: ");
5997
5998                         switch (balance_xmit_policy) {
5999                         case BALANCE_XMIT_POLICY_LAYER2:
6000                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6001                                 break;
6002                         case BALANCE_XMIT_POLICY_LAYER23:
6003                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6004                                 break;
6005                         case BALANCE_XMIT_POLICY_LAYER34:
6006                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6007                                 break;
6008                         }
6009                         printf("\n");
6010                 }
6011         }
6012
6013         if (bonding_mode == BONDING_MODE_8023AD) {
6014                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6015                 printf("\tIEEE802.3AD Aggregator Mode: ");
6016                 switch (agg_mode) {
6017                 case AGG_BANDWIDTH:
6018                         printf("bandwidth");
6019                         break;
6020                 case AGG_STABLE:
6021                         printf("stable");
6022                         break;
6023                 case AGG_COUNT:
6024                         printf("count");
6025                         break;
6026                 }
6027                 printf("\n");
6028         }
6029
6030         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6031
6032         if (num_slaves < 0) {
6033                 printf("\tFailed to get slave list for port = %d\n", port_id);
6034                 return;
6035         }
6036         if (num_slaves > 0) {
6037                 printf("\tSlaves (%d): [", num_slaves);
6038                 for (i = 0; i < num_slaves - 1; i++)
6039                         printf("%d ", slaves[i]);
6040
6041                 printf("%d]\n", slaves[num_slaves - 1]);
6042         } else {
6043                 printf("\tSlaves: []\n");
6044
6045         }
6046
6047         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6048                         RTE_MAX_ETHPORTS);
6049
6050         if (num_active_slaves < 0) {
6051                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6052                 return;
6053         }
6054         if (num_active_slaves > 0) {
6055                 printf("\tActive Slaves (%d): [", num_active_slaves);
6056                 for (i = 0; i < num_active_slaves - 1; i++)
6057                         printf("%d ", slaves[i]);
6058
6059                 printf("%d]\n", slaves[num_active_slaves - 1]);
6060
6061         } else {
6062                 printf("\tActive Slaves: []\n");
6063
6064         }
6065
6066         primary_id = rte_eth_bond_primary_get(port_id);
6067         if (primary_id < 0) {
6068                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6069                 return;
6070         } else
6071                 printf("\tPrimary: [%d]\n", primary_id);
6072
6073 }
6074
6075 cmdline_parse_token_string_t cmd_showbonding_config_show =
6076 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6077                 show, "show");
6078 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6079 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6080                 bonding, "bonding");
6081 cmdline_parse_token_string_t cmd_showbonding_config_config =
6082 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6083                 config, "config");
6084 cmdline_parse_token_num_t cmd_showbonding_config_port =
6085 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6086                 port_id, RTE_UINT16);
6087
6088 cmdline_parse_inst_t cmd_show_bonding_config = {
6089                 .f = cmd_show_bonding_config_parsed,
6090                 .help_str = "show bonding config <port_id>: "
6091                         "Show the bonding config for port_id",
6092                 .data = NULL,
6093                 .tokens = {
6094                                 (void *)&cmd_showbonding_config_show,
6095                                 (void *)&cmd_showbonding_config_bonding,
6096                                 (void *)&cmd_showbonding_config_config,
6097                                 (void *)&cmd_showbonding_config_port,
6098                                 NULL
6099                 }
6100 };
6101
6102 /* *** SET BONDING PRIMARY *** */
6103 struct cmd_set_bonding_primary_result {
6104         cmdline_fixed_string_t set;
6105         cmdline_fixed_string_t bonding;
6106         cmdline_fixed_string_t primary;
6107         portid_t slave_id;
6108         portid_t port_id;
6109 };
6110
6111 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6112                 __rte_unused  struct cmdline *cl,
6113                 __rte_unused void *data)
6114 {
6115         struct cmd_set_bonding_primary_result *res = parsed_result;
6116         portid_t master_port_id = res->port_id;
6117         portid_t slave_port_id = res->slave_id;
6118
6119         /* Set the primary slave for a bonded device. */
6120         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6121                 printf("\t Failed to set primary slave for port = %d.\n",
6122                                 master_port_id);
6123                 return;
6124         }
6125         init_port_config();
6126 }
6127
6128 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6129 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6130                 set, "set");
6131 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6132 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6133                 bonding, "bonding");
6134 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6135 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6136                 primary, "primary");
6137 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6138 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6139                 slave_id, RTE_UINT16);
6140 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6141 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6142                 port_id, RTE_UINT16);
6143
6144 cmdline_parse_inst_t cmd_set_bonding_primary = {
6145                 .f = cmd_set_bonding_primary_parsed,
6146                 .help_str = "set bonding primary <slave_id> <port_id>: "
6147                         "Set the primary slave for port_id",
6148                 .data = NULL,
6149                 .tokens = {
6150                                 (void *)&cmd_setbonding_primary_set,
6151                                 (void *)&cmd_setbonding_primary_bonding,
6152                                 (void *)&cmd_setbonding_primary_primary,
6153                                 (void *)&cmd_setbonding_primary_slave,
6154                                 (void *)&cmd_setbonding_primary_port,
6155                                 NULL
6156                 }
6157 };
6158
6159 /* *** ADD SLAVE *** */
6160 struct cmd_add_bonding_slave_result {
6161         cmdline_fixed_string_t add;
6162         cmdline_fixed_string_t bonding;
6163         cmdline_fixed_string_t slave;
6164         portid_t slave_id;
6165         portid_t port_id;
6166 };
6167
6168 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6169                 __rte_unused  struct cmdline *cl,
6170                 __rte_unused void *data)
6171 {
6172         struct cmd_add_bonding_slave_result *res = parsed_result;
6173         portid_t master_port_id = res->port_id;
6174         portid_t slave_port_id = res->slave_id;
6175
6176         /* add the slave for a bonded device. */
6177         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6178                 printf("\t Failed to add slave %d to master port = %d.\n",
6179                                 slave_port_id, master_port_id);
6180                 return;
6181         }
6182         init_port_config();
6183         set_port_slave_flag(slave_port_id);
6184 }
6185
6186 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6187 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6188                 add, "add");
6189 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6190 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6191                 bonding, "bonding");
6192 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6193 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6194                 slave, "slave");
6195 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6196 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6197                 slave_id, RTE_UINT16);
6198 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6199 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6200                 port_id, RTE_UINT16);
6201
6202 cmdline_parse_inst_t cmd_add_bonding_slave = {
6203                 .f = cmd_add_bonding_slave_parsed,
6204                 .help_str = "add bonding slave <slave_id> <port_id>: "
6205                         "Add a slave device to a bonded device",
6206                 .data = NULL,
6207                 .tokens = {
6208                                 (void *)&cmd_addbonding_slave_add,
6209                                 (void *)&cmd_addbonding_slave_bonding,
6210                                 (void *)&cmd_addbonding_slave_slave,
6211                                 (void *)&cmd_addbonding_slave_slaveid,
6212                                 (void *)&cmd_addbonding_slave_port,
6213                                 NULL
6214                 }
6215 };
6216
6217 /* *** REMOVE SLAVE *** */
6218 struct cmd_remove_bonding_slave_result {
6219         cmdline_fixed_string_t remove;
6220         cmdline_fixed_string_t bonding;
6221         cmdline_fixed_string_t slave;
6222         portid_t slave_id;
6223         portid_t port_id;
6224 };
6225
6226 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6227                 __rte_unused  struct cmdline *cl,
6228                 __rte_unused void *data)
6229 {
6230         struct cmd_remove_bonding_slave_result *res = parsed_result;
6231         portid_t master_port_id = res->port_id;
6232         portid_t slave_port_id = res->slave_id;
6233
6234         /* remove the slave from a bonded device. */
6235         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6236                 printf("\t Failed to remove slave %d from master port = %d.\n",
6237                                 slave_port_id, master_port_id);
6238                 return;
6239         }
6240         init_port_config();
6241         clear_port_slave_flag(slave_port_id);
6242 }
6243
6244 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6245                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6246                                 remove, "remove");
6247 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6248                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6249                                 bonding, "bonding");
6250 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6251                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6252                                 slave, "slave");
6253 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6254                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6255                                 slave_id, RTE_UINT16);
6256 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6257                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6258                                 port_id, RTE_UINT16);
6259
6260 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6261                 .f = cmd_remove_bonding_slave_parsed,
6262                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6263                         "Remove a slave device from a bonded device",
6264                 .data = NULL,
6265                 .tokens = {
6266                                 (void *)&cmd_removebonding_slave_remove,
6267                                 (void *)&cmd_removebonding_slave_bonding,
6268                                 (void *)&cmd_removebonding_slave_slave,
6269                                 (void *)&cmd_removebonding_slave_slaveid,
6270                                 (void *)&cmd_removebonding_slave_port,
6271                                 NULL
6272                 }
6273 };
6274
6275 /* *** CREATE BONDED DEVICE *** */
6276 struct cmd_create_bonded_device_result {
6277         cmdline_fixed_string_t create;
6278         cmdline_fixed_string_t bonded;
6279         cmdline_fixed_string_t device;
6280         uint8_t mode;
6281         uint8_t socket;
6282 };
6283
6284 static int bond_dev_num = 0;
6285
6286 static void cmd_create_bonded_device_parsed(void *parsed_result,
6287                 __rte_unused  struct cmdline *cl,
6288                 __rte_unused void *data)
6289 {
6290         struct cmd_create_bonded_device_result *res = parsed_result;
6291         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6292         int port_id;
6293         int ret;
6294
6295         if (test_done == 0) {
6296                 printf("Please stop forwarding first\n");
6297                 return;
6298         }
6299
6300         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6301                         bond_dev_num++);
6302
6303         /* Create a new bonded device. */
6304         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6305         if (port_id < 0) {
6306                 printf("\t Failed to create bonded device.\n");
6307                 return;
6308         } else {
6309                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6310                                 port_id);
6311
6312                 /* Update number of ports */
6313                 nb_ports = rte_eth_dev_count_avail();
6314                 reconfig(port_id, res->socket);
6315                 ret = rte_eth_promiscuous_enable(port_id);
6316                 if (ret != 0)
6317                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6318                                 port_id, rte_strerror(-ret));
6319
6320                 ports[port_id].need_setup = 0;
6321                 ports[port_id].port_status = RTE_PORT_STOPPED;
6322         }
6323
6324 }
6325
6326 cmdline_parse_token_string_t cmd_createbonded_device_create =
6327                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6328                                 create, "create");
6329 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6330                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6331                                 bonded, "bonded");
6332 cmdline_parse_token_string_t cmd_createbonded_device_device =
6333                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6334                                 device, "device");
6335 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6336                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6337                                 mode, RTE_UINT8);
6338 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6339                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6340                                 socket, RTE_UINT8);
6341
6342 cmdline_parse_inst_t cmd_create_bonded_device = {
6343                 .f = cmd_create_bonded_device_parsed,
6344                 .help_str = "create bonded device <mode> <socket>: "
6345                         "Create a new bonded device with specific bonding mode and socket",
6346                 .data = NULL,
6347                 .tokens = {
6348                                 (void *)&cmd_createbonded_device_create,
6349                                 (void *)&cmd_createbonded_device_bonded,
6350                                 (void *)&cmd_createbonded_device_device,
6351                                 (void *)&cmd_createbonded_device_mode,
6352                                 (void *)&cmd_createbonded_device_socket,
6353                                 NULL
6354                 }
6355 };
6356
6357 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6358 struct cmd_set_bond_mac_addr_result {
6359         cmdline_fixed_string_t set;
6360         cmdline_fixed_string_t bonding;
6361         cmdline_fixed_string_t mac_addr;
6362         uint16_t port_num;
6363         struct rte_ether_addr address;
6364 };
6365
6366 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6367                 __rte_unused  struct cmdline *cl,
6368                 __rte_unused void *data)
6369 {
6370         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6371         int ret;
6372
6373         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6374                 return;
6375
6376         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6377
6378         /* check the return value and print it if is < 0 */
6379         if (ret < 0)
6380                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6381 }
6382
6383 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6384                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6385 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6386                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6387                                 "bonding");
6388 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6389                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6390                                 "mac_addr");
6391 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6392                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6393                                 port_num, RTE_UINT16);
6394 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6395                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6396
6397 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6398                 .f = cmd_set_bond_mac_addr_parsed,
6399                 .data = (void *) 0,
6400                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6401                 .tokens = {
6402                                 (void *)&cmd_set_bond_mac_addr_set,
6403                                 (void *)&cmd_set_bond_mac_addr_bonding,
6404                                 (void *)&cmd_set_bond_mac_addr_mac,
6405                                 (void *)&cmd_set_bond_mac_addr_portnum,
6406                                 (void *)&cmd_set_bond_mac_addr_addr,
6407                                 NULL
6408                 }
6409 };
6410
6411
6412 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6413 struct cmd_set_bond_mon_period_result {
6414         cmdline_fixed_string_t set;
6415         cmdline_fixed_string_t bonding;
6416         cmdline_fixed_string_t mon_period;
6417         uint16_t port_num;
6418         uint32_t period_ms;
6419 };
6420
6421 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6422                 __rte_unused  struct cmdline *cl,
6423                 __rte_unused void *data)
6424 {
6425         struct cmd_set_bond_mon_period_result *res = parsed_result;
6426         int ret;
6427
6428         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6429
6430         /* check the return value and print it if is < 0 */
6431         if (ret < 0)
6432                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6433 }
6434
6435 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6436                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6437                                 set, "set");
6438 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6439                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6440                                 bonding, "bonding");
6441 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6442                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6443                                 mon_period,     "mon_period");
6444 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6445                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6446                                 port_num, RTE_UINT16);
6447 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6448                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6449                                 period_ms, RTE_UINT32);
6450
6451 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6452                 .f = cmd_set_bond_mon_period_parsed,
6453                 .data = (void *) 0,
6454                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6455                 .tokens = {
6456                                 (void *)&cmd_set_bond_mon_period_set,
6457                                 (void *)&cmd_set_bond_mon_period_bonding,
6458                                 (void *)&cmd_set_bond_mon_period_mon_period,
6459                                 (void *)&cmd_set_bond_mon_period_portnum,
6460                                 (void *)&cmd_set_bond_mon_period_period_ms,
6461                                 NULL
6462                 }
6463 };
6464
6465
6466
6467 struct cmd_set_bonding_agg_mode_policy_result {
6468         cmdline_fixed_string_t set;
6469         cmdline_fixed_string_t bonding;
6470         cmdline_fixed_string_t agg_mode;
6471         uint16_t port_num;
6472         cmdline_fixed_string_t policy;
6473 };
6474
6475
6476 static void
6477 cmd_set_bonding_agg_mode(void *parsed_result,
6478                 __rte_unused struct cmdline *cl,
6479                 __rte_unused void *data)
6480 {
6481         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6482         uint8_t policy = AGG_BANDWIDTH;
6483
6484         if (!strcmp(res->policy, "bandwidth"))
6485                 policy = AGG_BANDWIDTH;
6486         else if (!strcmp(res->policy, "stable"))
6487                 policy = AGG_STABLE;
6488         else if (!strcmp(res->policy, "count"))
6489                 policy = AGG_COUNT;
6490
6491         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6492 }
6493
6494
6495 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6496         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6497                                 set, "set");
6498 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6499         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6500                                 bonding, "bonding");
6501
6502 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6503         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6504                                 agg_mode, "agg_mode");
6505
6506 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6507         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6508                                 port_num, RTE_UINT16);
6509
6510 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6511         TOKEN_STRING_INITIALIZER(
6512                         struct cmd_set_bonding_balance_xmit_policy_result,
6513                 policy, "stable#bandwidth#count");
6514
6515 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6516         .f = cmd_set_bonding_agg_mode,
6517         .data = (void *) 0,
6518         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6519         .tokens = {
6520                         (void *)&cmd_set_bonding_agg_mode_set,
6521                         (void *)&cmd_set_bonding_agg_mode_bonding,
6522                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6523                         (void *)&cmd_set_bonding_agg_mode_portnum,
6524                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6525                         NULL
6526                 }
6527 };
6528
6529
6530 #endif /* RTE_NET_BOND */
6531
6532 /* *** SET FORWARDING MODE *** */
6533 struct cmd_set_fwd_mode_result {
6534         cmdline_fixed_string_t set;
6535         cmdline_fixed_string_t fwd;
6536         cmdline_fixed_string_t mode;
6537 };
6538
6539 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6540                                     __rte_unused struct cmdline *cl,
6541                                     __rte_unused void *data)
6542 {
6543         struct cmd_set_fwd_mode_result *res = parsed_result;
6544
6545         retry_enabled = 0;
6546         set_pkt_forwarding_mode(res->mode);
6547 }
6548
6549 cmdline_parse_token_string_t cmd_setfwd_set =
6550         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6551 cmdline_parse_token_string_t cmd_setfwd_fwd =
6552         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6553 cmdline_parse_token_string_t cmd_setfwd_mode =
6554         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6555                 "" /* defined at init */);
6556
6557 cmdline_parse_inst_t cmd_set_fwd_mode = {
6558         .f = cmd_set_fwd_mode_parsed,
6559         .data = NULL,
6560         .help_str = NULL, /* defined at init */
6561         .tokens = {
6562                 (void *)&cmd_setfwd_set,
6563                 (void *)&cmd_setfwd_fwd,
6564                 (void *)&cmd_setfwd_mode,
6565                 NULL,
6566         },
6567 };
6568
6569 static void cmd_set_fwd_mode_init(void)
6570 {
6571         char *modes, *c;
6572         static char token[128];
6573         static char help[256];
6574         cmdline_parse_token_string_t *token_struct;
6575
6576         modes = list_pkt_forwarding_modes();
6577         snprintf(help, sizeof(help), "set fwd %s: "
6578                 "Set packet forwarding mode", modes);
6579         cmd_set_fwd_mode.help_str = help;
6580
6581         /* string token separator is # */
6582         for (c = token; *modes != '\0'; modes++)
6583                 if (*modes == '|')
6584                         *c++ = '#';
6585                 else
6586                         *c++ = *modes;
6587         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6588         token_struct->string_data.str = token;
6589 }
6590
6591 /* *** SET RETRY FORWARDING MODE *** */
6592 struct cmd_set_fwd_retry_mode_result {
6593         cmdline_fixed_string_t set;
6594         cmdline_fixed_string_t fwd;
6595         cmdline_fixed_string_t mode;
6596         cmdline_fixed_string_t retry;
6597 };
6598
6599 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6600                             __rte_unused struct cmdline *cl,
6601                             __rte_unused void *data)
6602 {
6603         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6604
6605         retry_enabled = 1;
6606         set_pkt_forwarding_mode(res->mode);
6607 }
6608
6609 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6610         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6611                         set, "set");
6612 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6613         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6614                         fwd, "fwd");
6615 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6616         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6617                         mode,
6618                 "" /* defined at init */);
6619 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6620         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6621                         retry, "retry");
6622
6623 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6624         .f = cmd_set_fwd_retry_mode_parsed,
6625         .data = NULL,
6626         .help_str = NULL, /* defined at init */
6627         .tokens = {
6628                 (void *)&cmd_setfwd_retry_set,
6629                 (void *)&cmd_setfwd_retry_fwd,
6630                 (void *)&cmd_setfwd_retry_mode,
6631                 (void *)&cmd_setfwd_retry_retry,
6632                 NULL,
6633         },
6634 };
6635
6636 static void cmd_set_fwd_retry_mode_init(void)
6637 {
6638         char *modes, *c;
6639         static char token[128];
6640         static char help[256];
6641         cmdline_parse_token_string_t *token_struct;
6642
6643         modes = list_pkt_forwarding_retry_modes();
6644         snprintf(help, sizeof(help), "set fwd %s retry: "
6645                 "Set packet forwarding mode with retry", modes);
6646         cmd_set_fwd_retry_mode.help_str = help;
6647
6648         /* string token separator is # */
6649         for (c = token; *modes != '\0'; modes++)
6650                 if (*modes == '|')
6651                         *c++ = '#';
6652                 else
6653                         *c++ = *modes;
6654         token_struct = (cmdline_parse_token_string_t *)
6655                 cmd_set_fwd_retry_mode.tokens[2];
6656         token_struct->string_data.str = token;
6657 }
6658
6659 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6660 struct cmd_set_burst_tx_retry_result {
6661         cmdline_fixed_string_t set;
6662         cmdline_fixed_string_t burst;
6663         cmdline_fixed_string_t tx;
6664         cmdline_fixed_string_t delay;
6665         uint32_t time;
6666         cmdline_fixed_string_t retry;
6667         uint32_t retry_num;
6668 };
6669
6670 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6671                                         __rte_unused struct cmdline *cl,
6672                                         __rte_unused void *data)
6673 {
6674         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6675
6676         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6677                 && !strcmp(res->tx, "tx")) {
6678                 if (!strcmp(res->delay, "delay"))
6679                         burst_tx_delay_time = res->time;
6680                 if (!strcmp(res->retry, "retry"))
6681                         burst_tx_retry_num = res->retry_num;
6682         }
6683
6684 }
6685
6686 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6687         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6688 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6689         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6690                                  "burst");
6691 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6692         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6693 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6694         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6695 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6696         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
6697                                  RTE_UINT32);
6698 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6699         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6700 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6701         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
6702                                  RTE_UINT32);
6703
6704 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6705         .f = cmd_set_burst_tx_retry_parsed,
6706         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6707         .tokens = {
6708                 (void *)&cmd_set_burst_tx_retry_set,
6709                 (void *)&cmd_set_burst_tx_retry_burst,
6710                 (void *)&cmd_set_burst_tx_retry_tx,
6711                 (void *)&cmd_set_burst_tx_retry_delay,
6712                 (void *)&cmd_set_burst_tx_retry_time,
6713                 (void *)&cmd_set_burst_tx_retry_retry,
6714                 (void *)&cmd_set_burst_tx_retry_retry_num,
6715                 NULL,
6716         },
6717 };
6718
6719 /* *** SET PROMISC MODE *** */
6720 struct cmd_set_promisc_mode_result {
6721         cmdline_fixed_string_t set;
6722         cmdline_fixed_string_t promisc;
6723         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6724         uint16_t port_num;               /* valid if "allports" argument == 0 */
6725         cmdline_fixed_string_t mode;
6726 };
6727
6728 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6729                                         __rte_unused struct cmdline *cl,
6730                                         void *allports)
6731 {
6732         struct cmd_set_promisc_mode_result *res = parsed_result;
6733         int enable;
6734         portid_t i;
6735
6736         if (!strcmp(res->mode, "on"))
6737                 enable = 1;
6738         else
6739                 enable = 0;
6740
6741         /* all ports */
6742         if (allports) {
6743                 RTE_ETH_FOREACH_DEV(i)
6744                         eth_set_promisc_mode(i, enable);
6745         } else {
6746                 eth_set_promisc_mode(res->port_num, enable);
6747         }
6748 }
6749
6750 cmdline_parse_token_string_t cmd_setpromisc_set =
6751         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6752 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6753         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6754                                  "promisc");
6755 cmdline_parse_token_string_t cmd_setpromisc_portall =
6756         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6757                                  "all");
6758 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6759         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6760                               RTE_UINT16);
6761 cmdline_parse_token_string_t cmd_setpromisc_mode =
6762         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6763                                  "on#off");
6764
6765 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6766         .f = cmd_set_promisc_mode_parsed,
6767         .data = (void *)1,
6768         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6769         .tokens = {
6770                 (void *)&cmd_setpromisc_set,
6771                 (void *)&cmd_setpromisc_promisc,
6772                 (void *)&cmd_setpromisc_portall,
6773                 (void *)&cmd_setpromisc_mode,
6774                 NULL,
6775         },
6776 };
6777
6778 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6779         .f = cmd_set_promisc_mode_parsed,
6780         .data = (void *)0,
6781         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6782         .tokens = {
6783                 (void *)&cmd_setpromisc_set,
6784                 (void *)&cmd_setpromisc_promisc,
6785                 (void *)&cmd_setpromisc_portnum,
6786                 (void *)&cmd_setpromisc_mode,
6787                 NULL,
6788         },
6789 };
6790
6791 /* *** SET ALLMULTI MODE *** */
6792 struct cmd_set_allmulti_mode_result {
6793         cmdline_fixed_string_t set;
6794         cmdline_fixed_string_t allmulti;
6795         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6796         uint16_t port_num;               /* valid if "allports" argument == 0 */
6797         cmdline_fixed_string_t mode;
6798 };
6799
6800 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6801                                         __rte_unused struct cmdline *cl,
6802                                         void *allports)
6803 {
6804         struct cmd_set_allmulti_mode_result *res = parsed_result;
6805         int enable;
6806         portid_t i;
6807
6808         if (!strcmp(res->mode, "on"))
6809                 enable = 1;
6810         else
6811                 enable = 0;
6812
6813         /* all ports */
6814         if (allports) {
6815                 RTE_ETH_FOREACH_DEV(i) {
6816                         eth_set_allmulticast_mode(i, enable);
6817                 }
6818         }
6819         else {
6820                 eth_set_allmulticast_mode(res->port_num, enable);
6821         }
6822 }
6823
6824 cmdline_parse_token_string_t cmd_setallmulti_set =
6825         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6826 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6827         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6828                                  "allmulti");
6829 cmdline_parse_token_string_t cmd_setallmulti_portall =
6830         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6831                                  "all");
6832 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6833         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6834                               RTE_UINT16);
6835 cmdline_parse_token_string_t cmd_setallmulti_mode =
6836         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6837                                  "on#off");
6838
6839 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6840         .f = cmd_set_allmulti_mode_parsed,
6841         .data = (void *)1,
6842         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6843         .tokens = {
6844                 (void *)&cmd_setallmulti_set,
6845                 (void *)&cmd_setallmulti_allmulti,
6846                 (void *)&cmd_setallmulti_portall,
6847                 (void *)&cmd_setallmulti_mode,
6848                 NULL,
6849         },
6850 };
6851
6852 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6853         .f = cmd_set_allmulti_mode_parsed,
6854         .data = (void *)0,
6855         .help_str = "set allmulti <port_id> on|off: "
6856                 "Set allmulti mode on port_id",
6857         .tokens = {
6858                 (void *)&cmd_setallmulti_set,
6859                 (void *)&cmd_setallmulti_allmulti,
6860                 (void *)&cmd_setallmulti_portnum,
6861                 (void *)&cmd_setallmulti_mode,
6862                 NULL,
6863         },
6864 };
6865
6866 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6867 struct cmd_link_flow_ctrl_set_result {
6868         cmdline_fixed_string_t set;
6869         cmdline_fixed_string_t flow_ctrl;
6870         cmdline_fixed_string_t rx;
6871         cmdline_fixed_string_t rx_lfc_mode;
6872         cmdline_fixed_string_t tx;
6873         cmdline_fixed_string_t tx_lfc_mode;
6874         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6875         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6876         cmdline_fixed_string_t autoneg_str;
6877         cmdline_fixed_string_t autoneg;
6878         cmdline_fixed_string_t hw_str;
6879         uint32_t high_water;
6880         cmdline_fixed_string_t lw_str;
6881         uint32_t low_water;
6882         cmdline_fixed_string_t pt_str;
6883         uint16_t pause_time;
6884         cmdline_fixed_string_t xon_str;
6885         uint16_t send_xon;
6886         portid_t port_id;
6887 };
6888
6889 cmdline_parse_token_string_t cmd_lfc_set_set =
6890         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891                                 set, "set");
6892 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6893         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894                                 flow_ctrl, "flow_ctrl");
6895 cmdline_parse_token_string_t cmd_lfc_set_rx =
6896         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 rx, "rx");
6898 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6899         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 rx_lfc_mode, "on#off");
6901 cmdline_parse_token_string_t cmd_lfc_set_tx =
6902         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 tx, "tx");
6904 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6905         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 tx_lfc_mode, "on#off");
6907 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6908         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 hw_str, "high_water");
6910 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6911         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 high_water, RTE_UINT32);
6913 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6914         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 lw_str, "low_water");
6916 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6917         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 low_water, RTE_UINT32);
6919 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6920         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6921                                 pt_str, "pause_time");
6922 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6923         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6924                                 pause_time, RTE_UINT16);
6925 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6926         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6927                                 xon_str, "send_xon");
6928 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6929         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6930                                 send_xon, RTE_UINT16);
6931 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6932         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6933                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6934 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6935         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6936                                 mac_ctrl_frame_fwd_mode, "on#off");
6937 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6938         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6939                                 autoneg_str, "autoneg");
6940 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6941         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6942                                 autoneg, "on#off");
6943 cmdline_parse_token_num_t cmd_lfc_set_portid =
6944         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6945                                 port_id, RTE_UINT16);
6946
6947 /* forward declaration */
6948 static void
6949 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6950                               void *data);
6951
6952 cmdline_parse_inst_t cmd_link_flow_control_set = {
6953         .f = cmd_link_flow_ctrl_set_parsed,
6954         .data = NULL,
6955         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6956                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6957                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6958         .tokens = {
6959                 (void *)&cmd_lfc_set_set,
6960                 (void *)&cmd_lfc_set_flow_ctrl,
6961                 (void *)&cmd_lfc_set_rx,
6962                 (void *)&cmd_lfc_set_rx_mode,
6963                 (void *)&cmd_lfc_set_tx,
6964                 (void *)&cmd_lfc_set_tx_mode,
6965                 (void *)&cmd_lfc_set_high_water,
6966                 (void *)&cmd_lfc_set_low_water,
6967                 (void *)&cmd_lfc_set_pause_time,
6968                 (void *)&cmd_lfc_set_send_xon,
6969                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6970                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6971                 (void *)&cmd_lfc_set_autoneg_str,
6972                 (void *)&cmd_lfc_set_autoneg,
6973                 (void *)&cmd_lfc_set_portid,
6974                 NULL,
6975         },
6976 };
6977
6978 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6979         .f = cmd_link_flow_ctrl_set_parsed,
6980         .data = (void *)&cmd_link_flow_control_set_rx,
6981         .help_str = "set flow_ctrl rx on|off <port_id>: "
6982                 "Change rx flow control parameter",
6983         .tokens = {
6984                 (void *)&cmd_lfc_set_set,
6985                 (void *)&cmd_lfc_set_flow_ctrl,
6986                 (void *)&cmd_lfc_set_rx,
6987                 (void *)&cmd_lfc_set_rx_mode,
6988                 (void *)&cmd_lfc_set_portid,
6989                 NULL,
6990         },
6991 };
6992
6993 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6994         .f = cmd_link_flow_ctrl_set_parsed,
6995         .data = (void *)&cmd_link_flow_control_set_tx,
6996         .help_str = "set flow_ctrl tx on|off <port_id>: "
6997                 "Change tx flow control parameter",
6998         .tokens = {
6999                 (void *)&cmd_lfc_set_set,
7000                 (void *)&cmd_lfc_set_flow_ctrl,
7001                 (void *)&cmd_lfc_set_tx,
7002                 (void *)&cmd_lfc_set_tx_mode,
7003                 (void *)&cmd_lfc_set_portid,
7004                 NULL,
7005         },
7006 };
7007
7008 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7009         .f = cmd_link_flow_ctrl_set_parsed,
7010         .data = (void *)&cmd_link_flow_control_set_hw,
7011         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7012                 "Change high water flow control parameter",
7013         .tokens = {
7014                 (void *)&cmd_lfc_set_set,
7015                 (void *)&cmd_lfc_set_flow_ctrl,
7016                 (void *)&cmd_lfc_set_high_water_str,
7017                 (void *)&cmd_lfc_set_high_water,
7018                 (void *)&cmd_lfc_set_portid,
7019                 NULL,
7020         },
7021 };
7022
7023 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7024         .f = cmd_link_flow_ctrl_set_parsed,
7025         .data = (void *)&cmd_link_flow_control_set_lw,
7026         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7027                 "Change low water flow control parameter",
7028         .tokens = {
7029                 (void *)&cmd_lfc_set_set,
7030                 (void *)&cmd_lfc_set_flow_ctrl,
7031                 (void *)&cmd_lfc_set_low_water_str,
7032                 (void *)&cmd_lfc_set_low_water,
7033                 (void *)&cmd_lfc_set_portid,
7034                 NULL,
7035         },
7036 };
7037
7038 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7039         .f = cmd_link_flow_ctrl_set_parsed,
7040         .data = (void *)&cmd_link_flow_control_set_pt,
7041         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7042                 "Change pause time flow control parameter",
7043         .tokens = {
7044                 (void *)&cmd_lfc_set_set,
7045                 (void *)&cmd_lfc_set_flow_ctrl,
7046                 (void *)&cmd_lfc_set_pause_time_str,
7047                 (void *)&cmd_lfc_set_pause_time,
7048                 (void *)&cmd_lfc_set_portid,
7049                 NULL,
7050         },
7051 };
7052
7053 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7054         .f = cmd_link_flow_ctrl_set_parsed,
7055         .data = (void *)&cmd_link_flow_control_set_xon,
7056         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7057                 "Change send_xon flow control parameter",
7058         .tokens = {
7059                 (void *)&cmd_lfc_set_set,
7060                 (void *)&cmd_lfc_set_flow_ctrl,
7061                 (void *)&cmd_lfc_set_send_xon_str,
7062                 (void *)&cmd_lfc_set_send_xon,
7063                 (void *)&cmd_lfc_set_portid,
7064                 NULL,
7065         },
7066 };
7067
7068 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7069         .f = cmd_link_flow_ctrl_set_parsed,
7070         .data = (void *)&cmd_link_flow_control_set_macfwd,
7071         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7072                 "Change mac ctrl fwd flow control parameter",
7073         .tokens = {
7074                 (void *)&cmd_lfc_set_set,
7075                 (void *)&cmd_lfc_set_flow_ctrl,
7076                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7077                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7078                 (void *)&cmd_lfc_set_portid,
7079                 NULL,
7080         },
7081 };
7082
7083 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7084         .f = cmd_link_flow_ctrl_set_parsed,
7085         .data = (void *)&cmd_link_flow_control_set_autoneg,
7086         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7087                 "Change autoneg flow control parameter",
7088         .tokens = {
7089                 (void *)&cmd_lfc_set_set,
7090                 (void *)&cmd_lfc_set_flow_ctrl,
7091                 (void *)&cmd_lfc_set_autoneg_str,
7092                 (void *)&cmd_lfc_set_autoneg,
7093                 (void *)&cmd_lfc_set_portid,
7094                 NULL,
7095         },
7096 };
7097
7098 static void
7099 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7100                               __rte_unused struct cmdline *cl,
7101                               void *data)
7102 {
7103         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7104         cmdline_parse_inst_t *cmd = data;
7105         struct rte_eth_fc_conf fc_conf;
7106         int rx_fc_en = 0;
7107         int tx_fc_en = 0;
7108         int ret;
7109
7110         /*
7111          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7112          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7113          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7114          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7115          */
7116         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7117                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7118         };
7119
7120         /* Partial command line, retrieve current configuration */
7121         if (cmd) {
7122                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7123                 if (ret != 0) {
7124                         printf("cannot get current flow ctrl parameters, return"
7125                                "code = %d\n", ret);
7126                         return;
7127                 }
7128
7129                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7130                     (fc_conf.mode == RTE_FC_FULL))
7131                         rx_fc_en = 1;
7132                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7133                     (fc_conf.mode == RTE_FC_FULL))
7134                         tx_fc_en = 1;
7135         }
7136
7137         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7138                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7139
7140         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7141                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7142
7143         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7144
7145         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7146                 fc_conf.high_water = res->high_water;
7147
7148         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7149                 fc_conf.low_water = res->low_water;
7150
7151         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7152                 fc_conf.pause_time = res->pause_time;
7153
7154         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7155                 fc_conf.send_xon = res->send_xon;
7156
7157         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7158                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7159                         fc_conf.mac_ctrl_frame_fwd = 1;
7160                 else
7161                         fc_conf.mac_ctrl_frame_fwd = 0;
7162         }
7163
7164         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7165                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7166
7167         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7168         if (ret != 0)
7169                 printf("bad flow contrl parameter, return code = %d \n", ret);
7170 }
7171
7172 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7173 struct cmd_priority_flow_ctrl_set_result {
7174         cmdline_fixed_string_t set;
7175         cmdline_fixed_string_t pfc_ctrl;
7176         cmdline_fixed_string_t rx;
7177         cmdline_fixed_string_t rx_pfc_mode;
7178         cmdline_fixed_string_t tx;
7179         cmdline_fixed_string_t tx_pfc_mode;
7180         uint32_t high_water;
7181         uint32_t low_water;
7182         uint16_t pause_time;
7183         uint8_t  priority;
7184         portid_t port_id;
7185 };
7186
7187 static void
7188 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7189                        __rte_unused struct cmdline *cl,
7190                        __rte_unused void *data)
7191 {
7192         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7193         struct rte_eth_pfc_conf pfc_conf;
7194         int rx_fc_enable, tx_fc_enable;
7195         int ret;
7196
7197         /*
7198          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7199          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7200          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7201          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7202          */
7203         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7204                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7205         };
7206
7207         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7208         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7209         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7210         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7211         pfc_conf.fc.high_water = res->high_water;
7212         pfc_conf.fc.low_water  = res->low_water;
7213         pfc_conf.fc.pause_time = res->pause_time;
7214         pfc_conf.priority      = res->priority;
7215
7216         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7217         if (ret != 0)
7218                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7219 }
7220
7221 cmdline_parse_token_string_t cmd_pfc_set_set =
7222         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223                                 set, "set");
7224 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7225         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226                                 pfc_ctrl, "pfc_ctrl");
7227 cmdline_parse_token_string_t cmd_pfc_set_rx =
7228         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7229                                 rx, "rx");
7230 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7231         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7232                                 rx_pfc_mode, "on#off");
7233 cmdline_parse_token_string_t cmd_pfc_set_tx =
7234         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7235                                 tx, "tx");
7236 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7237         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7238                                 tx_pfc_mode, "on#off");
7239 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7240         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7241                                 high_water, RTE_UINT32);
7242 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7243         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7244                                 low_water, RTE_UINT32);
7245 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7246         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7247                                 pause_time, RTE_UINT16);
7248 cmdline_parse_token_num_t cmd_pfc_set_priority =
7249         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7250                                 priority, RTE_UINT8);
7251 cmdline_parse_token_num_t cmd_pfc_set_portid =
7252         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7253                                 port_id, RTE_UINT16);
7254
7255 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7256         .f = cmd_priority_flow_ctrl_set_parsed,
7257         .data = NULL,
7258         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7259                 "<pause_time> <priority> <port_id>: "
7260                 "Configure the Ethernet priority flow control",
7261         .tokens = {
7262                 (void *)&cmd_pfc_set_set,
7263                 (void *)&cmd_pfc_set_flow_ctrl,
7264                 (void *)&cmd_pfc_set_rx,
7265                 (void *)&cmd_pfc_set_rx_mode,
7266                 (void *)&cmd_pfc_set_tx,
7267                 (void *)&cmd_pfc_set_tx_mode,
7268                 (void *)&cmd_pfc_set_high_water,
7269                 (void *)&cmd_pfc_set_low_water,
7270                 (void *)&cmd_pfc_set_pause_time,
7271                 (void *)&cmd_pfc_set_priority,
7272                 (void *)&cmd_pfc_set_portid,
7273                 NULL,
7274         },
7275 };
7276
7277 /* *** RESET CONFIGURATION *** */
7278 struct cmd_reset_result {
7279         cmdline_fixed_string_t reset;
7280         cmdline_fixed_string_t def;
7281 };
7282
7283 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7284                              struct cmdline *cl,
7285                              __rte_unused void *data)
7286 {
7287         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7288         set_def_fwd_config();
7289 }
7290
7291 cmdline_parse_token_string_t cmd_reset_set =
7292         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7293 cmdline_parse_token_string_t cmd_reset_def =
7294         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7295                                  "default");
7296
7297 cmdline_parse_inst_t cmd_reset = {
7298         .f = cmd_reset_parsed,
7299         .data = NULL,
7300         .help_str = "set default: Reset default forwarding configuration",
7301         .tokens = {
7302                 (void *)&cmd_reset_set,
7303                 (void *)&cmd_reset_def,
7304                 NULL,
7305         },
7306 };
7307
7308 /* *** START FORWARDING *** */
7309 struct cmd_start_result {
7310         cmdline_fixed_string_t start;
7311 };
7312
7313 cmdline_parse_token_string_t cmd_start_start =
7314         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7315
7316 static void cmd_start_parsed(__rte_unused void *parsed_result,
7317                              __rte_unused struct cmdline *cl,
7318                              __rte_unused void *data)
7319 {
7320         start_packet_forwarding(0);
7321 }
7322
7323 cmdline_parse_inst_t cmd_start = {
7324         .f = cmd_start_parsed,
7325         .data = NULL,
7326         .help_str = "start: Start packet forwarding",
7327         .tokens = {
7328                 (void *)&cmd_start_start,
7329                 NULL,
7330         },
7331 };
7332
7333 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7334 struct cmd_start_tx_first_result {
7335         cmdline_fixed_string_t start;
7336         cmdline_fixed_string_t tx_first;
7337 };
7338
7339 static void
7340 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7341                           __rte_unused struct cmdline *cl,
7342                           __rte_unused void *data)
7343 {
7344         start_packet_forwarding(1);
7345 }
7346
7347 cmdline_parse_token_string_t cmd_start_tx_first_start =
7348         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7349                                  "start");
7350 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7351         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7352                                  tx_first, "tx_first");
7353
7354 cmdline_parse_inst_t cmd_start_tx_first = {
7355         .f = cmd_start_tx_first_parsed,
7356         .data = NULL,
7357         .help_str = "start tx_first: Start packet forwarding, "
7358                 "after sending 1 burst of packets",
7359         .tokens = {
7360                 (void *)&cmd_start_tx_first_start,
7361                 (void *)&cmd_start_tx_first_tx_first,
7362                 NULL,
7363         },
7364 };
7365
7366 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7367 struct cmd_start_tx_first_n_result {
7368         cmdline_fixed_string_t start;
7369         cmdline_fixed_string_t tx_first;
7370         uint32_t tx_num;
7371 };
7372
7373 static void
7374 cmd_start_tx_first_n_parsed(void *parsed_result,
7375                           __rte_unused struct cmdline *cl,
7376                           __rte_unused void *data)
7377 {
7378         struct cmd_start_tx_first_n_result *res = parsed_result;
7379
7380         start_packet_forwarding(res->tx_num);
7381 }
7382
7383 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7384         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7385                         start, "start");
7386 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7387         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7388                         tx_first, "tx_first");
7389 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7390         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7391                         tx_num, RTE_UINT32);
7392
7393 cmdline_parse_inst_t cmd_start_tx_first_n = {
7394         .f = cmd_start_tx_first_n_parsed,
7395         .data = NULL,
7396         .help_str = "start tx_first <num>: "
7397                 "packet forwarding, after sending <num> bursts of packets",
7398         .tokens = {
7399                 (void *)&cmd_start_tx_first_n_start,
7400                 (void *)&cmd_start_tx_first_n_tx_first,
7401                 (void *)&cmd_start_tx_first_n_tx_num,
7402                 NULL,
7403         },
7404 };
7405
7406 /* *** SET LINK UP *** */
7407 struct cmd_set_link_up_result {
7408         cmdline_fixed_string_t set;
7409         cmdline_fixed_string_t link_up;
7410         cmdline_fixed_string_t port;
7411         portid_t port_id;
7412 };
7413
7414 cmdline_parse_token_string_t cmd_set_link_up_set =
7415         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7416 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7417         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7418                                 "link-up");
7419 cmdline_parse_token_string_t cmd_set_link_up_port =
7420         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7421 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7422         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7423                                 RTE_UINT16);
7424
7425 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7426                              __rte_unused struct cmdline *cl,
7427                              __rte_unused void *data)
7428 {
7429         struct cmd_set_link_up_result *res = parsed_result;
7430         dev_set_link_up(res->port_id);
7431 }
7432
7433 cmdline_parse_inst_t cmd_set_link_up = {
7434         .f = cmd_set_link_up_parsed,
7435         .data = NULL,
7436         .help_str = "set link-up port <port id>",
7437         .tokens = {
7438                 (void *)&cmd_set_link_up_set,
7439                 (void *)&cmd_set_link_up_link_up,
7440                 (void *)&cmd_set_link_up_port,
7441                 (void *)&cmd_set_link_up_port_id,
7442                 NULL,
7443         },
7444 };
7445
7446 /* *** SET LINK DOWN *** */
7447 struct cmd_set_link_down_result {
7448         cmdline_fixed_string_t set;
7449         cmdline_fixed_string_t link_down;
7450         cmdline_fixed_string_t port;
7451         portid_t port_id;
7452 };
7453
7454 cmdline_parse_token_string_t cmd_set_link_down_set =
7455         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7456 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7457         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7458                                 "link-down");
7459 cmdline_parse_token_string_t cmd_set_link_down_port =
7460         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7461 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7462         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7463                                 RTE_UINT16);
7464
7465 static void cmd_set_link_down_parsed(
7466                                 __rte_unused void *parsed_result,
7467                                 __rte_unused struct cmdline *cl,
7468                                 __rte_unused void *data)
7469 {
7470         struct cmd_set_link_down_result *res = parsed_result;
7471         dev_set_link_down(res->port_id);
7472 }
7473
7474 cmdline_parse_inst_t cmd_set_link_down = {
7475         .f = cmd_set_link_down_parsed,
7476         .data = NULL,
7477         .help_str = "set link-down port <port id>",
7478         .tokens = {
7479                 (void *)&cmd_set_link_down_set,
7480                 (void *)&cmd_set_link_down_link_down,
7481                 (void *)&cmd_set_link_down_port,
7482                 (void *)&cmd_set_link_down_port_id,
7483                 NULL,
7484         },
7485 };
7486
7487 /* *** SHOW CFG *** */
7488 struct cmd_showcfg_result {
7489         cmdline_fixed_string_t show;
7490         cmdline_fixed_string_t cfg;
7491         cmdline_fixed_string_t what;
7492 };
7493
7494 static void cmd_showcfg_parsed(void *parsed_result,
7495                                __rte_unused struct cmdline *cl,
7496                                __rte_unused void *data)
7497 {
7498         struct cmd_showcfg_result *res = parsed_result;
7499         if (!strcmp(res->what, "rxtx"))
7500                 rxtx_config_display();
7501         else if (!strcmp(res->what, "cores"))
7502                 fwd_lcores_config_display();
7503         else if (!strcmp(res->what, "fwd"))
7504                 pkt_fwd_config_display(&cur_fwd_config);
7505         else if (!strcmp(res->what, "rxoffs"))
7506                 show_rx_pkt_offsets();
7507         else if (!strcmp(res->what, "rxpkts"))
7508                 show_rx_pkt_segments();
7509         else if (!strcmp(res->what, "txpkts"))
7510                 show_tx_pkt_segments();
7511         else if (!strcmp(res->what, "txtimes"))
7512                 show_tx_pkt_times();
7513 }
7514
7515 cmdline_parse_token_string_t cmd_showcfg_show =
7516         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7517 cmdline_parse_token_string_t cmd_showcfg_port =
7518         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7519 cmdline_parse_token_string_t cmd_showcfg_what =
7520         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7521                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7522
7523 cmdline_parse_inst_t cmd_showcfg = {
7524         .f = cmd_showcfg_parsed,
7525         .data = NULL,
7526         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7527         .tokens = {
7528                 (void *)&cmd_showcfg_show,
7529                 (void *)&cmd_showcfg_port,
7530                 (void *)&cmd_showcfg_what,
7531                 NULL,
7532         },
7533 };
7534
7535 /* *** SHOW ALL PORT INFO *** */
7536 struct cmd_showportall_result {
7537         cmdline_fixed_string_t show;
7538         cmdline_fixed_string_t port;
7539         cmdline_fixed_string_t what;
7540         cmdline_fixed_string_t all;
7541 };
7542
7543 static void cmd_showportall_parsed(void *parsed_result,
7544                                 __rte_unused struct cmdline *cl,
7545                                 __rte_unused void *data)
7546 {
7547         portid_t i;
7548
7549         struct cmd_showportall_result *res = parsed_result;
7550         if (!strcmp(res->show, "clear")) {
7551                 if (!strcmp(res->what, "stats"))
7552                         RTE_ETH_FOREACH_DEV(i)
7553                                 nic_stats_clear(i);
7554                 else if (!strcmp(res->what, "xstats"))
7555                         RTE_ETH_FOREACH_DEV(i)
7556                                 nic_xstats_clear(i);
7557         } else if (!strcmp(res->what, "info"))
7558                 RTE_ETH_FOREACH_DEV(i)
7559                         port_infos_display(i);
7560         else if (!strcmp(res->what, "summary")) {
7561                 port_summary_header_display();
7562                 RTE_ETH_FOREACH_DEV(i)
7563                         port_summary_display(i);
7564         }
7565         else if (!strcmp(res->what, "stats"))
7566                 RTE_ETH_FOREACH_DEV(i)
7567                         nic_stats_display(i);
7568         else if (!strcmp(res->what, "xstats"))
7569                 RTE_ETH_FOREACH_DEV(i)
7570                         nic_xstats_display(i);
7571 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7572         else if (!strcmp(res->what, "fdir"))
7573                 RTE_ETH_FOREACH_DEV(i)
7574                         fdir_get_infos(i);
7575 #endif
7576         else if (!strcmp(res->what, "dcb_tc"))
7577                 RTE_ETH_FOREACH_DEV(i)
7578                         port_dcb_info_display(i);
7579 }
7580
7581 cmdline_parse_token_string_t cmd_showportall_show =
7582         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7583                                  "show#clear");
7584 cmdline_parse_token_string_t cmd_showportall_port =
7585         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7586 cmdline_parse_token_string_t cmd_showportall_what =
7587         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7588                                  "info#summary#stats#xstats#fdir#dcb_tc");
7589 cmdline_parse_token_string_t cmd_showportall_all =
7590         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7591 cmdline_parse_inst_t cmd_showportall = {
7592         .f = cmd_showportall_parsed,
7593         .data = NULL,
7594         .help_str = "show|clear port "
7595                 "info|summary|stats|xstats|fdir|dcb_tc all",
7596         .tokens = {
7597                 (void *)&cmd_showportall_show,
7598                 (void *)&cmd_showportall_port,
7599                 (void *)&cmd_showportall_what,
7600                 (void *)&cmd_showportall_all,
7601                 NULL,
7602         },
7603 };
7604
7605 /* *** SHOW PORT INFO *** */
7606 struct cmd_showport_result {
7607         cmdline_fixed_string_t show;
7608         cmdline_fixed_string_t port;
7609         cmdline_fixed_string_t what;
7610         uint16_t portnum;
7611 };
7612
7613 static void cmd_showport_parsed(void *parsed_result,
7614                                 __rte_unused struct cmdline *cl,
7615                                 __rte_unused void *data)
7616 {
7617         struct cmd_showport_result *res = parsed_result;
7618         if (!strcmp(res->show, "clear")) {
7619                 if (!strcmp(res->what, "stats"))
7620                         nic_stats_clear(res->portnum);
7621                 else if (!strcmp(res->what, "xstats"))
7622                         nic_xstats_clear(res->portnum);
7623         } else if (!strcmp(res->what, "info"))
7624                 port_infos_display(res->portnum);
7625         else if (!strcmp(res->what, "summary")) {
7626                 port_summary_header_display();
7627                 port_summary_display(res->portnum);
7628         }
7629         else if (!strcmp(res->what, "stats"))
7630                 nic_stats_display(res->portnum);
7631         else if (!strcmp(res->what, "xstats"))
7632                 nic_xstats_display(res->portnum);
7633 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7634         else if (!strcmp(res->what, "fdir"))
7635                  fdir_get_infos(res->portnum);
7636 #endif
7637         else if (!strcmp(res->what, "dcb_tc"))
7638                 port_dcb_info_display(res->portnum);
7639 }
7640
7641 cmdline_parse_token_string_t cmd_showport_show =
7642         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7643                                  "show#clear");
7644 cmdline_parse_token_string_t cmd_showport_port =
7645         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7646 cmdline_parse_token_string_t cmd_showport_what =
7647         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7648                                  "info#summary#stats#xstats#fdir#dcb_tc");
7649 cmdline_parse_token_num_t cmd_showport_portnum =
7650         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
7651
7652 cmdline_parse_inst_t cmd_showport = {
7653         .f = cmd_showport_parsed,
7654         .data = NULL,
7655         .help_str = "show|clear port "
7656                 "info|summary|stats|xstats|fdir|dcb_tc "
7657                 "<port_id>",
7658         .tokens = {
7659                 (void *)&cmd_showport_show,
7660                 (void *)&cmd_showport_port,
7661                 (void *)&cmd_showport_what,
7662                 (void *)&cmd_showport_portnum,
7663                 NULL,
7664         },
7665 };
7666
7667 /* *** SHOW DEVICE INFO *** */
7668 struct cmd_showdevice_result {
7669         cmdline_fixed_string_t show;
7670         cmdline_fixed_string_t device;
7671         cmdline_fixed_string_t what;
7672         cmdline_fixed_string_t identifier;
7673 };
7674
7675 static void cmd_showdevice_parsed(void *parsed_result,
7676                                 __rte_unused struct cmdline *cl,
7677                                 __rte_unused void *data)
7678 {
7679         struct cmd_showdevice_result *res = parsed_result;
7680         if (!strcmp(res->what, "info")) {
7681                 if (!strcmp(res->identifier, "all"))
7682                         device_infos_display(NULL);
7683                 else
7684                         device_infos_display(res->identifier);
7685         }
7686 }
7687
7688 cmdline_parse_token_string_t cmd_showdevice_show =
7689         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7690                                  "show");
7691 cmdline_parse_token_string_t cmd_showdevice_device =
7692         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7693 cmdline_parse_token_string_t cmd_showdevice_what =
7694         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7695                                  "info");
7696 cmdline_parse_token_string_t cmd_showdevice_identifier =
7697         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7698                         identifier, NULL);
7699
7700 cmdline_parse_inst_t cmd_showdevice = {
7701         .f = cmd_showdevice_parsed,
7702         .data = NULL,
7703         .help_str = "show device info <identifier>|all",
7704         .tokens = {
7705                 (void *)&cmd_showdevice_show,
7706                 (void *)&cmd_showdevice_device,
7707                 (void *)&cmd_showdevice_what,
7708                 (void *)&cmd_showdevice_identifier,
7709                 NULL,
7710         },
7711 };
7712
7713 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7714 struct cmd_showeeprom_result {
7715         cmdline_fixed_string_t show;
7716         cmdline_fixed_string_t port;
7717         uint16_t portnum;
7718         cmdline_fixed_string_t type;
7719 };
7720
7721 static void cmd_showeeprom_parsed(void *parsed_result,
7722                 __rte_unused struct cmdline *cl,
7723                 __rte_unused void *data)
7724 {
7725         struct cmd_showeeprom_result *res = parsed_result;
7726
7727         if (!strcmp(res->type, "eeprom"))
7728                 port_eeprom_display(res->portnum);
7729         else if (!strcmp(res->type, "module_eeprom"))
7730                 port_module_eeprom_display(res->portnum);
7731         else
7732                 printf("Unknown argument\n");
7733 }
7734
7735 cmdline_parse_token_string_t cmd_showeeprom_show =
7736         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7737 cmdline_parse_token_string_t cmd_showeeprom_port =
7738         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7739 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7740         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
7741                         RTE_UINT16);
7742 cmdline_parse_token_string_t cmd_showeeprom_type =
7743         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7744
7745 cmdline_parse_inst_t cmd_showeeprom = {
7746         .f = cmd_showeeprom_parsed,
7747         .data = NULL,
7748         .help_str = "show port <port_id> module_eeprom|eeprom",
7749         .tokens = {
7750                 (void *)&cmd_showeeprom_show,
7751                 (void *)&cmd_showeeprom_port,
7752                 (void *)&cmd_showeeprom_portnum,
7753                 (void *)&cmd_showeeprom_type,
7754                 NULL,
7755         },
7756 };
7757
7758 /* *** SHOW QUEUE INFO *** */
7759 struct cmd_showqueue_result {
7760         cmdline_fixed_string_t show;
7761         cmdline_fixed_string_t type;
7762         cmdline_fixed_string_t what;
7763         uint16_t portnum;
7764         uint16_t queuenum;
7765 };
7766
7767 static void
7768 cmd_showqueue_parsed(void *parsed_result,
7769         __rte_unused struct cmdline *cl,
7770         __rte_unused void *data)
7771 {
7772         struct cmd_showqueue_result *res = parsed_result;
7773
7774         if (!strcmp(res->type, "rxq"))
7775                 rx_queue_infos_display(res->portnum, res->queuenum);
7776         else if (!strcmp(res->type, "txq"))
7777                 tx_queue_infos_display(res->portnum, res->queuenum);
7778 }
7779
7780 cmdline_parse_token_string_t cmd_showqueue_show =
7781         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7782 cmdline_parse_token_string_t cmd_showqueue_type =
7783         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7784 cmdline_parse_token_string_t cmd_showqueue_what =
7785         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7786 cmdline_parse_token_num_t cmd_showqueue_portnum =
7787         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
7788                 RTE_UINT16);
7789 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7790         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
7791                 RTE_UINT16);
7792
7793 cmdline_parse_inst_t cmd_showqueue = {
7794         .f = cmd_showqueue_parsed,
7795         .data = NULL,
7796         .help_str = "show rxq|txq info <port_id> <queue_id>",
7797         .tokens = {
7798                 (void *)&cmd_showqueue_show,
7799                 (void *)&cmd_showqueue_type,
7800                 (void *)&cmd_showqueue_what,
7801                 (void *)&cmd_showqueue_portnum,
7802                 (void *)&cmd_showqueue_queuenum,
7803                 NULL,
7804         },
7805 };
7806
7807 /* show/clear fwd engine statistics */
7808 struct fwd_result {
7809         cmdline_fixed_string_t action;
7810         cmdline_fixed_string_t fwd;
7811         cmdline_fixed_string_t stats;
7812         cmdline_fixed_string_t all;
7813 };
7814
7815 cmdline_parse_token_string_t cmd_fwd_action =
7816         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7817 cmdline_parse_token_string_t cmd_fwd_fwd =
7818         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7819 cmdline_parse_token_string_t cmd_fwd_stats =
7820         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7821 cmdline_parse_token_string_t cmd_fwd_all =
7822         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7823
7824 static void
7825 cmd_showfwdall_parsed(void *parsed_result,
7826                       __rte_unused struct cmdline *cl,
7827                       __rte_unused void *data)
7828 {
7829         struct fwd_result *res = parsed_result;
7830
7831         if (!strcmp(res->action, "show"))
7832                 fwd_stats_display();
7833         else
7834                 fwd_stats_reset();
7835 }
7836
7837 static cmdline_parse_inst_t cmd_showfwdall = {
7838         .f = cmd_showfwdall_parsed,
7839         .data = NULL,
7840         .help_str = "show|clear fwd stats all",
7841         .tokens = {
7842                 (void *)&cmd_fwd_action,
7843                 (void *)&cmd_fwd_fwd,
7844                 (void *)&cmd_fwd_stats,
7845                 (void *)&cmd_fwd_all,
7846                 NULL,
7847         },
7848 };
7849
7850 /* *** READ PORT REGISTER *** */
7851 struct cmd_read_reg_result {
7852         cmdline_fixed_string_t read;
7853         cmdline_fixed_string_t reg;
7854         portid_t port_id;
7855         uint32_t reg_off;
7856 };
7857
7858 static void
7859 cmd_read_reg_parsed(void *parsed_result,
7860                     __rte_unused struct cmdline *cl,
7861                     __rte_unused void *data)
7862 {
7863         struct cmd_read_reg_result *res = parsed_result;
7864         port_reg_display(res->port_id, res->reg_off);
7865 }
7866
7867 cmdline_parse_token_string_t cmd_read_reg_read =
7868         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7869 cmdline_parse_token_string_t cmd_read_reg_reg =
7870         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7871 cmdline_parse_token_num_t cmd_read_reg_port_id =
7872         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
7873 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7874         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
7875
7876 cmdline_parse_inst_t cmd_read_reg = {
7877         .f = cmd_read_reg_parsed,
7878         .data = NULL,
7879         .help_str = "read reg <port_id> <reg_off>",
7880         .tokens = {
7881                 (void *)&cmd_read_reg_read,
7882                 (void *)&cmd_read_reg_reg,
7883                 (void *)&cmd_read_reg_port_id,
7884                 (void *)&cmd_read_reg_reg_off,
7885                 NULL,
7886         },
7887 };
7888
7889 /* *** READ PORT REGISTER BIT FIELD *** */
7890 struct cmd_read_reg_bit_field_result {
7891         cmdline_fixed_string_t read;
7892         cmdline_fixed_string_t regfield;
7893         portid_t port_id;
7894         uint32_t reg_off;
7895         uint8_t bit1_pos;
7896         uint8_t bit2_pos;
7897 };
7898
7899 static void
7900 cmd_read_reg_bit_field_parsed(void *parsed_result,
7901                               __rte_unused struct cmdline *cl,
7902                               __rte_unused void *data)
7903 {
7904         struct cmd_read_reg_bit_field_result *res = parsed_result;
7905         port_reg_bit_field_display(res->port_id, res->reg_off,
7906                                    res->bit1_pos, res->bit2_pos);
7907 }
7908
7909 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7910         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7911                                  "read");
7912 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7913         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7914                                  regfield, "regfield");
7915 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7916         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7917                               RTE_UINT16);
7918 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7919         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7920                               RTE_UINT32);
7921 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7922         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7923                               RTE_UINT8);
7924 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7925         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7926                               RTE_UINT8);
7927
7928 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7929         .f = cmd_read_reg_bit_field_parsed,
7930         .data = NULL,
7931         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7932         "Read register bit field between bit_x and bit_y included",
7933         .tokens = {
7934                 (void *)&cmd_read_reg_bit_field_read,
7935                 (void *)&cmd_read_reg_bit_field_regfield,
7936                 (void *)&cmd_read_reg_bit_field_port_id,
7937                 (void *)&cmd_read_reg_bit_field_reg_off,
7938                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7939                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7940                 NULL,
7941         },
7942 };
7943
7944 /* *** READ PORT REGISTER BIT *** */
7945 struct cmd_read_reg_bit_result {
7946         cmdline_fixed_string_t read;
7947         cmdline_fixed_string_t regbit;
7948         portid_t port_id;
7949         uint32_t reg_off;
7950         uint8_t bit_pos;
7951 };
7952
7953 static void
7954 cmd_read_reg_bit_parsed(void *parsed_result,
7955                         __rte_unused struct cmdline *cl,
7956                         __rte_unused void *data)
7957 {
7958         struct cmd_read_reg_bit_result *res = parsed_result;
7959         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7960 }
7961
7962 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7963         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7964 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7965         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7966                                  regbit, "regbit");
7967 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7968         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
7969                                  RTE_UINT16);
7970 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7971         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
7972                                  RTE_UINT32);
7973 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7974         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
7975                                  RTE_UINT8);
7976
7977 cmdline_parse_inst_t cmd_read_reg_bit = {
7978         .f = cmd_read_reg_bit_parsed,
7979         .data = NULL,
7980         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7981         .tokens = {
7982                 (void *)&cmd_read_reg_bit_read,
7983                 (void *)&cmd_read_reg_bit_regbit,
7984                 (void *)&cmd_read_reg_bit_port_id,
7985                 (void *)&cmd_read_reg_bit_reg_off,
7986                 (void *)&cmd_read_reg_bit_bit_pos,
7987                 NULL,
7988         },
7989 };
7990
7991 /* *** WRITE PORT REGISTER *** */
7992 struct cmd_write_reg_result {
7993         cmdline_fixed_string_t write;
7994         cmdline_fixed_string_t reg;
7995         portid_t port_id;
7996         uint32_t reg_off;
7997         uint32_t value;
7998 };
7999
8000 static void
8001 cmd_write_reg_parsed(void *parsed_result,
8002                      __rte_unused struct cmdline *cl,
8003                      __rte_unused void *data)
8004 {
8005         struct cmd_write_reg_result *res = parsed_result;
8006         port_reg_set(res->port_id, res->reg_off, res->value);
8007 }
8008
8009 cmdline_parse_token_string_t cmd_write_reg_write =
8010         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8011 cmdline_parse_token_string_t cmd_write_reg_reg =
8012         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8013 cmdline_parse_token_num_t cmd_write_reg_port_id =
8014         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8015 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8016         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8017 cmdline_parse_token_num_t cmd_write_reg_value =
8018         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8019
8020 cmdline_parse_inst_t cmd_write_reg = {
8021         .f = cmd_write_reg_parsed,
8022         .data = NULL,
8023         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8024         .tokens = {
8025                 (void *)&cmd_write_reg_write,
8026                 (void *)&cmd_write_reg_reg,
8027                 (void *)&cmd_write_reg_port_id,
8028                 (void *)&cmd_write_reg_reg_off,
8029                 (void *)&cmd_write_reg_value,
8030                 NULL,
8031         },
8032 };
8033
8034 /* *** WRITE PORT REGISTER BIT FIELD *** */
8035 struct cmd_write_reg_bit_field_result {
8036         cmdline_fixed_string_t write;
8037         cmdline_fixed_string_t regfield;
8038         portid_t port_id;
8039         uint32_t reg_off;
8040         uint8_t bit1_pos;
8041         uint8_t bit2_pos;
8042         uint32_t value;
8043 };
8044
8045 static void
8046 cmd_write_reg_bit_field_parsed(void *parsed_result,
8047                                __rte_unused struct cmdline *cl,
8048                                __rte_unused void *data)
8049 {
8050         struct cmd_write_reg_bit_field_result *res = parsed_result;
8051         port_reg_bit_field_set(res->port_id, res->reg_off,
8052                           res->bit1_pos, res->bit2_pos, res->value);
8053 }
8054
8055 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8056         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8057                                  "write");
8058 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8059         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8060                                  regfield, "regfield");
8061 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8062         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8063                               RTE_UINT16);
8064 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8065         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8066                               RTE_UINT32);
8067 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8068         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8069                               RTE_UINT8);
8070 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8071         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8072                               RTE_UINT8);
8073 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8074         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8075                               RTE_UINT32);
8076
8077 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8078         .f = cmd_write_reg_bit_field_parsed,
8079         .data = NULL,
8080         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8081                 "<reg_value>: "
8082                 "Set register bit field between bit_x and bit_y included",
8083         .tokens = {
8084                 (void *)&cmd_write_reg_bit_field_write,
8085                 (void *)&cmd_write_reg_bit_field_regfield,
8086                 (void *)&cmd_write_reg_bit_field_port_id,
8087                 (void *)&cmd_write_reg_bit_field_reg_off,
8088                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8089                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8090                 (void *)&cmd_write_reg_bit_field_value,
8091                 NULL,
8092         },
8093 };
8094
8095 /* *** WRITE PORT REGISTER BIT *** */
8096 struct cmd_write_reg_bit_result {
8097         cmdline_fixed_string_t write;
8098         cmdline_fixed_string_t regbit;
8099         portid_t port_id;
8100         uint32_t reg_off;
8101         uint8_t bit_pos;
8102         uint8_t value;
8103 };
8104
8105 static void
8106 cmd_write_reg_bit_parsed(void *parsed_result,
8107                          __rte_unused struct cmdline *cl,
8108                          __rte_unused void *data)
8109 {
8110         struct cmd_write_reg_bit_result *res = parsed_result;
8111         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8112 }
8113
8114 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8115         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8116                                  "write");
8117 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8118         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8119                                  regbit, "regbit");
8120 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8121         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8122                                  RTE_UINT16);
8123 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8124         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8125                                  RTE_UINT32);
8126 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8127         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8128                                  RTE_UINT8);
8129 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8130         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8131                                  RTE_UINT8);
8132
8133 cmdline_parse_inst_t cmd_write_reg_bit = {
8134         .f = cmd_write_reg_bit_parsed,
8135         .data = NULL,
8136         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8137                 "0 <= bit_x <= 31",
8138         .tokens = {
8139                 (void *)&cmd_write_reg_bit_write,
8140                 (void *)&cmd_write_reg_bit_regbit,
8141                 (void *)&cmd_write_reg_bit_port_id,
8142                 (void *)&cmd_write_reg_bit_reg_off,
8143                 (void *)&cmd_write_reg_bit_bit_pos,
8144                 (void *)&cmd_write_reg_bit_value,
8145                 NULL,
8146         },
8147 };
8148
8149 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8150 struct cmd_read_rxd_txd_result {
8151         cmdline_fixed_string_t read;
8152         cmdline_fixed_string_t rxd_txd;
8153         portid_t port_id;
8154         uint16_t queue_id;
8155         uint16_t desc_id;
8156 };
8157
8158 static void
8159 cmd_read_rxd_txd_parsed(void *parsed_result,
8160                         __rte_unused struct cmdline *cl,
8161                         __rte_unused void *data)
8162 {
8163         struct cmd_read_rxd_txd_result *res = parsed_result;
8164
8165         if (!strcmp(res->rxd_txd, "rxd"))
8166                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8167         else if (!strcmp(res->rxd_txd, "txd"))
8168                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8169 }
8170
8171 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8172         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8173 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8174         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8175                                  "rxd#txd");
8176 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8177         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8178                                  RTE_UINT16);
8179 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8180         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8181                                  RTE_UINT16);
8182 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8183         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8184                                  RTE_UINT16);
8185
8186 cmdline_parse_inst_t cmd_read_rxd_txd = {
8187         .f = cmd_read_rxd_txd_parsed,
8188         .data = NULL,
8189         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8190         .tokens = {
8191                 (void *)&cmd_read_rxd_txd_read,
8192                 (void *)&cmd_read_rxd_txd_rxd_txd,
8193                 (void *)&cmd_read_rxd_txd_port_id,
8194                 (void *)&cmd_read_rxd_txd_queue_id,
8195                 (void *)&cmd_read_rxd_txd_desc_id,
8196                 NULL,
8197         },
8198 };
8199
8200 /* *** QUIT *** */
8201 struct cmd_quit_result {
8202         cmdline_fixed_string_t quit;
8203 };
8204
8205 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8206                             struct cmdline *cl,
8207                             __rte_unused void *data)
8208 {
8209         cmdline_quit(cl);
8210 }
8211
8212 cmdline_parse_token_string_t cmd_quit_quit =
8213         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8214
8215 cmdline_parse_inst_t cmd_quit = {
8216         .f = cmd_quit_parsed,
8217         .data = NULL,
8218         .help_str = "quit: Exit application",
8219         .tokens = {
8220                 (void *)&cmd_quit_quit,
8221                 NULL,
8222         },
8223 };
8224
8225 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8226 struct cmd_mac_addr_result {
8227         cmdline_fixed_string_t mac_addr_cmd;
8228         cmdline_fixed_string_t what;
8229         uint16_t port_num;
8230         struct rte_ether_addr address;
8231 };
8232
8233 static void cmd_mac_addr_parsed(void *parsed_result,
8234                 __rte_unused struct cmdline *cl,
8235                 __rte_unused void *data)
8236 {
8237         struct cmd_mac_addr_result *res = parsed_result;
8238         int ret;
8239
8240         if (strcmp(res->what, "add") == 0)
8241                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8242         else if (strcmp(res->what, "set") == 0)
8243                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8244                                                        &res->address);
8245         else
8246                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8247
8248         /* check the return value and print it if is < 0 */
8249         if(ret < 0)
8250                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8251
8252 }
8253
8254 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8255         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8256                                 "mac_addr");
8257 cmdline_parse_token_string_t cmd_mac_addr_what =
8258         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8259                                 "add#remove#set");
8260 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8261                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8262                                         RTE_UINT16);
8263 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8264                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8265
8266 cmdline_parse_inst_t cmd_mac_addr = {
8267         .f = cmd_mac_addr_parsed,
8268         .data = (void *)0,
8269         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8270                         "Add/Remove/Set MAC address on port_id",
8271         .tokens = {
8272                 (void *)&cmd_mac_addr_cmd,
8273                 (void *)&cmd_mac_addr_what,
8274                 (void *)&cmd_mac_addr_portnum,
8275                 (void *)&cmd_mac_addr_addr,
8276                 NULL,
8277         },
8278 };
8279
8280 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8281 struct cmd_eth_peer_result {
8282         cmdline_fixed_string_t set;
8283         cmdline_fixed_string_t eth_peer;
8284         portid_t port_id;
8285         cmdline_fixed_string_t peer_addr;
8286 };
8287
8288 static void cmd_set_eth_peer_parsed(void *parsed_result,
8289                         __rte_unused struct cmdline *cl,
8290                         __rte_unused void *data)
8291 {
8292                 struct cmd_eth_peer_result *res = parsed_result;
8293
8294                 if (test_done == 0) {
8295                         printf("Please stop forwarding first\n");
8296                         return;
8297                 }
8298                 if (!strcmp(res->eth_peer, "eth-peer")) {
8299                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8300                         fwd_config_setup();
8301                 }
8302 }
8303 cmdline_parse_token_string_t cmd_eth_peer_set =
8304         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8305 cmdline_parse_token_string_t cmd_eth_peer =
8306         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8307 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8308         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8309                 RTE_UINT16);
8310 cmdline_parse_token_string_t cmd_eth_peer_addr =
8311         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8312
8313 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8314         .f = cmd_set_eth_peer_parsed,
8315         .data = NULL,
8316         .help_str = "set eth-peer <port_id> <peer_mac>",
8317         .tokens = {
8318                 (void *)&cmd_eth_peer_set,
8319                 (void *)&cmd_eth_peer,
8320                 (void *)&cmd_eth_peer_port_id,
8321                 (void *)&cmd_eth_peer_addr,
8322                 NULL,
8323         },
8324 };
8325
8326 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8327 struct cmd_set_qmap_result {
8328         cmdline_fixed_string_t set;
8329         cmdline_fixed_string_t qmap;
8330         cmdline_fixed_string_t what;
8331         portid_t port_id;
8332         uint16_t queue_id;
8333         uint8_t map_value;
8334 };
8335
8336 static void
8337 cmd_set_qmap_parsed(void *parsed_result,
8338                        __rte_unused struct cmdline *cl,
8339                        __rte_unused void *data)
8340 {
8341         struct cmd_set_qmap_result *res = parsed_result;
8342         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8343
8344         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8345 }
8346
8347 cmdline_parse_token_string_t cmd_setqmap_set =
8348         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8349                                  set, "set");
8350 cmdline_parse_token_string_t cmd_setqmap_qmap =
8351         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8352                                  qmap, "stat_qmap");
8353 cmdline_parse_token_string_t cmd_setqmap_what =
8354         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8355                                  what, "tx#rx");
8356 cmdline_parse_token_num_t cmd_setqmap_portid =
8357         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8358                               port_id, RTE_UINT16);
8359 cmdline_parse_token_num_t cmd_setqmap_queueid =
8360         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8361                               queue_id, RTE_UINT16);
8362 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8363         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8364                               map_value, RTE_UINT8);
8365
8366 cmdline_parse_inst_t cmd_set_qmap = {
8367         .f = cmd_set_qmap_parsed,
8368         .data = NULL,
8369         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8370                 "Set statistics mapping value on tx|rx queue_id of port_id",
8371         .tokens = {
8372                 (void *)&cmd_setqmap_set,
8373                 (void *)&cmd_setqmap_qmap,
8374                 (void *)&cmd_setqmap_what,
8375                 (void *)&cmd_setqmap_portid,
8376                 (void *)&cmd_setqmap_queueid,
8377                 (void *)&cmd_setqmap_mapvalue,
8378                 NULL,
8379         },
8380 };
8381
8382 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8383 struct cmd_set_xstats_hide_zero_result {
8384         cmdline_fixed_string_t keyword;
8385         cmdline_fixed_string_t name;
8386         cmdline_fixed_string_t on_off;
8387 };
8388
8389 static void
8390 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8391                         __rte_unused struct cmdline *cl,
8392                         __rte_unused void *data)
8393 {
8394         struct cmd_set_xstats_hide_zero_result *res;
8395         uint16_t on_off = 0;
8396
8397         res = parsed_result;
8398         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8399         set_xstats_hide_zero(on_off);
8400 }
8401
8402 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8403         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8404                                  keyword, "set");
8405 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8406         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8407                                  name, "xstats-hide-zero");
8408 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8409         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8410                                  on_off, "on#off");
8411
8412 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8413         .f = cmd_set_xstats_hide_zero_parsed,
8414         .data = NULL,
8415         .help_str = "set xstats-hide-zero on|off",
8416         .tokens = {
8417                 (void *)&cmd_set_xstats_hide_zero_keyword,
8418                 (void *)&cmd_set_xstats_hide_zero_name,
8419                 (void *)&cmd_set_xstats_hide_zero_on_off,
8420                 NULL,
8421         },
8422 };
8423
8424 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8425 struct cmd_set_record_core_cycles_result {
8426         cmdline_fixed_string_t keyword;
8427         cmdline_fixed_string_t name;
8428         cmdline_fixed_string_t on_off;
8429 };
8430
8431 static void
8432 cmd_set_record_core_cycles_parsed(void *parsed_result,
8433                         __rte_unused struct cmdline *cl,
8434                         __rte_unused void *data)
8435 {
8436         struct cmd_set_record_core_cycles_result *res;
8437         uint16_t on_off = 0;
8438
8439         res = parsed_result;
8440         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8441         set_record_core_cycles(on_off);
8442 }
8443
8444 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8445         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8446                                  keyword, "set");
8447 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8448         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8449                                  name, "record-core-cycles");
8450 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8451         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8452                                  on_off, "on#off");
8453
8454 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8455         .f = cmd_set_record_core_cycles_parsed,
8456         .data = NULL,
8457         .help_str = "set record-core-cycles on|off",
8458         .tokens = {
8459                 (void *)&cmd_set_record_core_cycles_keyword,
8460                 (void *)&cmd_set_record_core_cycles_name,
8461                 (void *)&cmd_set_record_core_cycles_on_off,
8462                 NULL,
8463         },
8464 };
8465
8466 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8467 struct cmd_set_record_burst_stats_result {
8468         cmdline_fixed_string_t keyword;
8469         cmdline_fixed_string_t name;
8470         cmdline_fixed_string_t on_off;
8471 };
8472
8473 static void
8474 cmd_set_record_burst_stats_parsed(void *parsed_result,
8475                         __rte_unused struct cmdline *cl,
8476                         __rte_unused void *data)
8477 {
8478         struct cmd_set_record_burst_stats_result *res;
8479         uint16_t on_off = 0;
8480
8481         res = parsed_result;
8482         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8483         set_record_burst_stats(on_off);
8484 }
8485
8486 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8487         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8488                                  keyword, "set");
8489 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8490         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8491                                  name, "record-burst-stats");
8492 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8493         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8494                                  on_off, "on#off");
8495
8496 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8497         .f = cmd_set_record_burst_stats_parsed,
8498         .data = NULL,
8499         .help_str = "set record-burst-stats on|off",
8500         .tokens = {
8501                 (void *)&cmd_set_record_burst_stats_keyword,
8502                 (void *)&cmd_set_record_burst_stats_name,
8503                 (void *)&cmd_set_record_burst_stats_on_off,
8504                 NULL,
8505         },
8506 };
8507
8508 /* *** CONFIGURE UNICAST HASH TABLE *** */
8509 struct cmd_set_uc_hash_table {
8510         cmdline_fixed_string_t set;
8511         cmdline_fixed_string_t port;
8512         portid_t port_id;
8513         cmdline_fixed_string_t what;
8514         struct rte_ether_addr address;
8515         cmdline_fixed_string_t mode;
8516 };
8517
8518 static void
8519 cmd_set_uc_hash_parsed(void *parsed_result,
8520                        __rte_unused struct cmdline *cl,
8521                        __rte_unused void *data)
8522 {
8523         int ret=0;
8524         struct cmd_set_uc_hash_table *res = parsed_result;
8525
8526         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8527
8528         if (strcmp(res->what, "uta") == 0)
8529                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8530                                                 &res->address,(uint8_t)is_on);
8531         if (ret < 0)
8532                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8533
8534 }
8535
8536 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8537         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8538                                  set, "set");
8539 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8540         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8541                                  port, "port");
8542 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8543         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8544                               port_id, RTE_UINT16);
8545 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8546         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8547                                  what, "uta");
8548 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8549         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8550                                 address);
8551 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8552         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8553                                  mode, "on#off");
8554
8555 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8556         .f = cmd_set_uc_hash_parsed,
8557         .data = NULL,
8558         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8559         .tokens = {
8560                 (void *)&cmd_set_uc_hash_set,
8561                 (void *)&cmd_set_uc_hash_port,
8562                 (void *)&cmd_set_uc_hash_portid,
8563                 (void *)&cmd_set_uc_hash_what,
8564                 (void *)&cmd_set_uc_hash_mac,
8565                 (void *)&cmd_set_uc_hash_mode,
8566                 NULL,
8567         },
8568 };
8569
8570 struct cmd_set_uc_all_hash_table {
8571         cmdline_fixed_string_t set;
8572         cmdline_fixed_string_t port;
8573         portid_t port_id;
8574         cmdline_fixed_string_t what;
8575         cmdline_fixed_string_t value;
8576         cmdline_fixed_string_t mode;
8577 };
8578
8579 static void
8580 cmd_set_uc_all_hash_parsed(void *parsed_result,
8581                        __rte_unused struct cmdline *cl,
8582                        __rte_unused void *data)
8583 {
8584         int ret=0;
8585         struct cmd_set_uc_all_hash_table *res = parsed_result;
8586
8587         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8588
8589         if ((strcmp(res->what, "uta") == 0) &&
8590                 (strcmp(res->value, "all") == 0))
8591                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8592         if (ret < 0)
8593                 printf("bad unicast hash table parameter,"
8594                         "return code = %d \n", ret);
8595 }
8596
8597 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8598         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8599                                  set, "set");
8600 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8601         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8602                                  port, "port");
8603 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8604         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8605                               port_id, RTE_UINT16);
8606 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8607         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8608                                  what, "uta");
8609 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8610         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8611                                 value,"all");
8612 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8613         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8614                                  mode, "on#off");
8615
8616 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8617         .f = cmd_set_uc_all_hash_parsed,
8618         .data = NULL,
8619         .help_str = "set port <port_id> uta all on|off",
8620         .tokens = {
8621                 (void *)&cmd_set_uc_all_hash_set,
8622                 (void *)&cmd_set_uc_all_hash_port,
8623                 (void *)&cmd_set_uc_all_hash_portid,
8624                 (void *)&cmd_set_uc_all_hash_what,
8625                 (void *)&cmd_set_uc_all_hash_value,
8626                 (void *)&cmd_set_uc_all_hash_mode,
8627                 NULL,
8628         },
8629 };
8630
8631 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8632 struct cmd_set_vf_traffic {
8633         cmdline_fixed_string_t set;
8634         cmdline_fixed_string_t port;
8635         portid_t port_id;
8636         cmdline_fixed_string_t vf;
8637         uint8_t vf_id;
8638         cmdline_fixed_string_t what;
8639         cmdline_fixed_string_t mode;
8640 };
8641
8642 static void
8643 cmd_set_vf_traffic_parsed(void *parsed_result,
8644                        __rte_unused struct cmdline *cl,
8645                        __rte_unused void *data)
8646 {
8647         struct cmd_set_vf_traffic *res = parsed_result;
8648         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8649         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8650
8651         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8652 }
8653
8654 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8655         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8656                                  set, "set");
8657 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8658         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8659                                  port, "port");
8660 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8661         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8662                               port_id, RTE_UINT16);
8663 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8664         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8665                                  vf, "vf");
8666 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8667         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8668                               vf_id, RTE_UINT8);
8669 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8670         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8671                                  what, "tx#rx");
8672 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8673         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8674                                  mode, "on#off");
8675
8676 cmdline_parse_inst_t cmd_set_vf_traffic = {
8677         .f = cmd_set_vf_traffic_parsed,
8678         .data = NULL,
8679         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8680         .tokens = {
8681                 (void *)&cmd_setvf_traffic_set,
8682                 (void *)&cmd_setvf_traffic_port,
8683                 (void *)&cmd_setvf_traffic_portid,
8684                 (void *)&cmd_setvf_traffic_vf,
8685                 (void *)&cmd_setvf_traffic_vfid,
8686                 (void *)&cmd_setvf_traffic_what,
8687                 (void *)&cmd_setvf_traffic_mode,
8688                 NULL,
8689         },
8690 };
8691
8692 /* *** CONFIGURE VF RECEIVE MODE *** */
8693 struct cmd_set_vf_rxmode {
8694         cmdline_fixed_string_t set;
8695         cmdline_fixed_string_t port;
8696         portid_t port_id;
8697         cmdline_fixed_string_t vf;
8698         uint8_t vf_id;
8699         cmdline_fixed_string_t what;
8700         cmdline_fixed_string_t mode;
8701         cmdline_fixed_string_t on;
8702 };
8703
8704 static void
8705 cmd_set_vf_rxmode_parsed(void *parsed_result,
8706                        __rte_unused struct cmdline *cl,
8707                        __rte_unused void *data)
8708 {
8709         int ret = -ENOTSUP;
8710         uint16_t vf_rxmode = 0;
8711         struct cmd_set_vf_rxmode *res = parsed_result;
8712
8713         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8714         if (!strcmp(res->what,"rxmode")) {
8715                 if (!strcmp(res->mode, "AUPE"))
8716                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8717                 else if (!strcmp(res->mode, "ROPE"))
8718                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8719                 else if (!strcmp(res->mode, "BAM"))
8720                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8721                 else if (!strncmp(res->mode, "MPE",3))
8722                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8723         }
8724
8725         RTE_SET_USED(is_on);
8726
8727 #ifdef RTE_NET_IXGBE
8728         if (ret == -ENOTSUP)
8729                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8730                                                   vf_rxmode, (uint8_t)is_on);
8731 #endif
8732 #ifdef RTE_NET_BNXT
8733         if (ret == -ENOTSUP)
8734                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8735                                                  vf_rxmode, (uint8_t)is_on);
8736 #endif
8737         if (ret < 0)
8738                 printf("bad VF receive mode parameter, return code = %d \n",
8739                 ret);
8740 }
8741
8742 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8743         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8744                                  set, "set");
8745 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8746         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8747                                  port, "port");
8748 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8749         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8750                               port_id, RTE_UINT16);
8751 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8752         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8753                                  vf, "vf");
8754 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8755         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8756                               vf_id, RTE_UINT8);
8757 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8758         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8759                                  what, "rxmode");
8760 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8761         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8762                                  mode, "AUPE#ROPE#BAM#MPE");
8763 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8764         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8765                                  on, "on#off");
8766
8767 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8768         .f = cmd_set_vf_rxmode_parsed,
8769         .data = NULL,
8770         .help_str = "set port <port_id> vf <vf_id> rxmode "
8771                 "AUPE|ROPE|BAM|MPE on|off",
8772         .tokens = {
8773                 (void *)&cmd_set_vf_rxmode_set,
8774                 (void *)&cmd_set_vf_rxmode_port,
8775                 (void *)&cmd_set_vf_rxmode_portid,
8776                 (void *)&cmd_set_vf_rxmode_vf,
8777                 (void *)&cmd_set_vf_rxmode_vfid,
8778                 (void *)&cmd_set_vf_rxmode_what,
8779                 (void *)&cmd_set_vf_rxmode_mode,
8780                 (void *)&cmd_set_vf_rxmode_on,
8781                 NULL,
8782         },
8783 };
8784
8785 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8786 struct cmd_vf_mac_addr_result {
8787         cmdline_fixed_string_t mac_addr_cmd;
8788         cmdline_fixed_string_t what;
8789         cmdline_fixed_string_t port;
8790         uint16_t port_num;
8791         cmdline_fixed_string_t vf;
8792         uint8_t vf_num;
8793         struct rte_ether_addr address;
8794 };
8795
8796 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8797                 __rte_unused struct cmdline *cl,
8798                 __rte_unused void *data)
8799 {
8800         struct cmd_vf_mac_addr_result *res = parsed_result;
8801         int ret = -ENOTSUP;
8802
8803         if (strcmp(res->what, "add") != 0)
8804                 return;
8805
8806 #ifdef RTE_NET_I40E
8807         if (ret == -ENOTSUP)
8808                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8809                                                    &res->address);
8810 #endif
8811 #ifdef RTE_NET_BNXT
8812         if (ret == -ENOTSUP)
8813                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8814                                                 res->vf_num);
8815 #endif
8816
8817         if(ret < 0)
8818                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8819
8820 }
8821
8822 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8823         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8824                                 mac_addr_cmd,"mac_addr");
8825 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8826         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8827                                 what,"add");
8828 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8829         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8830                                 port,"port");
8831 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8832         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8833                                 port_num, RTE_UINT16);
8834 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8835         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8836                                 vf,"vf");
8837 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8838         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8839                                 vf_num, RTE_UINT8);
8840 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8841         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8842                                 address);
8843
8844 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8845         .f = cmd_vf_mac_addr_parsed,
8846         .data = (void *)0,
8847         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8848                 "Add MAC address filtering for a VF on port_id",
8849         .tokens = {
8850                 (void *)&cmd_vf_mac_addr_cmd,
8851                 (void *)&cmd_vf_mac_addr_what,
8852                 (void *)&cmd_vf_mac_addr_port,
8853                 (void *)&cmd_vf_mac_addr_portnum,
8854                 (void *)&cmd_vf_mac_addr_vf,
8855                 (void *)&cmd_vf_mac_addr_vfnum,
8856                 (void *)&cmd_vf_mac_addr_addr,
8857                 NULL,
8858         },
8859 };
8860
8861 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8862 struct cmd_vf_rx_vlan_filter {
8863         cmdline_fixed_string_t rx_vlan;
8864         cmdline_fixed_string_t what;
8865         uint16_t vlan_id;
8866         cmdline_fixed_string_t port;
8867         portid_t port_id;
8868         cmdline_fixed_string_t vf;
8869         uint64_t vf_mask;
8870 };
8871
8872 static void
8873 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8874                           __rte_unused struct cmdline *cl,
8875                           __rte_unused void *data)
8876 {
8877         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8878         int ret = -ENOTSUP;
8879
8880         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8881
8882 #ifdef RTE_NET_IXGBE
8883         if (ret == -ENOTSUP)
8884                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8885                                 res->vlan_id, res->vf_mask, is_add);
8886 #endif
8887 #ifdef RTE_NET_I40E
8888         if (ret == -ENOTSUP)
8889                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8890                                 res->vlan_id, res->vf_mask, is_add);
8891 #endif
8892 #ifdef RTE_NET_BNXT
8893         if (ret == -ENOTSUP)
8894                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8895                                 res->vlan_id, res->vf_mask, is_add);
8896 #endif
8897
8898         switch (ret) {
8899         case 0:
8900                 break;
8901         case -EINVAL:
8902                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8903                                 res->vlan_id, res->vf_mask);
8904                 break;
8905         case -ENODEV:
8906                 printf("invalid port_id %d\n", res->port_id);
8907                 break;
8908         case -ENOTSUP:
8909                 printf("function not implemented or supported\n");
8910                 break;
8911         default:
8912                 printf("programming error: (%s)\n", strerror(-ret));
8913         }
8914 }
8915
8916 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8917         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8918                                  rx_vlan, "rx_vlan");
8919 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8920         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8921                                  what, "add#rm");
8922 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8923         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8924                               vlan_id, RTE_UINT16);
8925 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8926         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8927                                  port, "port");
8928 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8929         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8930                               port_id, RTE_UINT16);
8931 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8932         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8933                                  vf, "vf");
8934 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8935         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8936                               vf_mask, RTE_UINT64);
8937
8938 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8939         .f = cmd_vf_rx_vlan_filter_parsed,
8940         .data = NULL,
8941         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8942                 "(vf_mask = hexadecimal VF mask)",
8943         .tokens = {
8944                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8945                 (void *)&cmd_vf_rx_vlan_filter_what,
8946                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8947                 (void *)&cmd_vf_rx_vlan_filter_port,
8948                 (void *)&cmd_vf_rx_vlan_filter_portid,
8949                 (void *)&cmd_vf_rx_vlan_filter_vf,
8950                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8951                 NULL,
8952         },
8953 };
8954
8955 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8956 struct cmd_queue_rate_limit_result {
8957         cmdline_fixed_string_t set;
8958         cmdline_fixed_string_t port;
8959         uint16_t port_num;
8960         cmdline_fixed_string_t queue;
8961         uint8_t queue_num;
8962         cmdline_fixed_string_t rate;
8963         uint16_t rate_num;
8964 };
8965
8966 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8967                 __rte_unused struct cmdline *cl,
8968                 __rte_unused void *data)
8969 {
8970         struct cmd_queue_rate_limit_result *res = parsed_result;
8971         int ret = 0;
8972
8973         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8974                 && (strcmp(res->queue, "queue") == 0)
8975                 && (strcmp(res->rate, "rate") == 0))
8976                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8977                                         res->rate_num);
8978         if (ret < 0)
8979                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8980
8981 }
8982
8983 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8984         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8985                                 set, "set");
8986 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8987         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8988                                 port, "port");
8989 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8990         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8991                                 port_num, RTE_UINT16);
8992 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8993         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8994                                 queue, "queue");
8995 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8996         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8997                                 queue_num, RTE_UINT8);
8998 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8999         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9000                                 rate, "rate");
9001 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9002         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9003                                 rate_num, RTE_UINT16);
9004
9005 cmdline_parse_inst_t cmd_queue_rate_limit = {
9006         .f = cmd_queue_rate_limit_parsed,
9007         .data = (void *)0,
9008         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9009                 "Set rate limit for a queue on port_id",
9010         .tokens = {
9011                 (void *)&cmd_queue_rate_limit_set,
9012                 (void *)&cmd_queue_rate_limit_port,
9013                 (void *)&cmd_queue_rate_limit_portnum,
9014                 (void *)&cmd_queue_rate_limit_queue,
9015                 (void *)&cmd_queue_rate_limit_queuenum,
9016                 (void *)&cmd_queue_rate_limit_rate,
9017                 (void *)&cmd_queue_rate_limit_ratenum,
9018                 NULL,
9019         },
9020 };
9021
9022 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9023 struct cmd_vf_rate_limit_result {
9024         cmdline_fixed_string_t set;
9025         cmdline_fixed_string_t port;
9026         uint16_t port_num;
9027         cmdline_fixed_string_t vf;
9028         uint8_t vf_num;
9029         cmdline_fixed_string_t rate;
9030         uint16_t rate_num;
9031         cmdline_fixed_string_t q_msk;
9032         uint64_t q_msk_val;
9033 };
9034
9035 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9036                 __rte_unused struct cmdline *cl,
9037                 __rte_unused void *data)
9038 {
9039         struct cmd_vf_rate_limit_result *res = parsed_result;
9040         int ret = 0;
9041
9042         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9043                 && (strcmp(res->vf, "vf") == 0)
9044                 && (strcmp(res->rate, "rate") == 0)
9045                 && (strcmp(res->q_msk, "queue_mask") == 0))
9046                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9047                                         res->rate_num, res->q_msk_val);
9048         if (ret < 0)
9049                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9050
9051 }
9052
9053 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9054         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9055                                 set, "set");
9056 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9057         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9058                                 port, "port");
9059 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9060         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9061                                 port_num, RTE_UINT16);
9062 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9063         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9064                                 vf, "vf");
9065 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9066         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9067                                 vf_num, RTE_UINT8);
9068 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9069         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9070                                 rate, "rate");
9071 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9072         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9073                                 rate_num, RTE_UINT16);
9074 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9075         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9076                                 q_msk, "queue_mask");
9077 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9078         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9079                                 q_msk_val, RTE_UINT64);
9080
9081 cmdline_parse_inst_t cmd_vf_rate_limit = {
9082         .f = cmd_vf_rate_limit_parsed,
9083         .data = (void *)0,
9084         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9085                 "queue_mask <queue_mask_value>: "
9086                 "Set rate limit for queues of VF on port_id",
9087         .tokens = {
9088                 (void *)&cmd_vf_rate_limit_set,
9089                 (void *)&cmd_vf_rate_limit_port,
9090                 (void *)&cmd_vf_rate_limit_portnum,
9091                 (void *)&cmd_vf_rate_limit_vf,
9092                 (void *)&cmd_vf_rate_limit_vfnum,
9093                 (void *)&cmd_vf_rate_limit_rate,
9094                 (void *)&cmd_vf_rate_limit_ratenum,
9095                 (void *)&cmd_vf_rate_limit_q_msk,
9096                 (void *)&cmd_vf_rate_limit_q_msk_val,
9097                 NULL,
9098         },
9099 };
9100
9101 /* *** CONFIGURE TUNNEL UDP PORT *** */
9102 struct cmd_tunnel_udp_config {
9103         cmdline_fixed_string_t rx_vxlan_port;
9104         cmdline_fixed_string_t what;
9105         uint16_t udp_port;
9106         portid_t port_id;
9107 };
9108
9109 static void
9110 cmd_tunnel_udp_config_parsed(void *parsed_result,
9111                           __rte_unused struct cmdline *cl,
9112                           __rte_unused void *data)
9113 {
9114         struct cmd_tunnel_udp_config *res = parsed_result;
9115         struct rte_eth_udp_tunnel tunnel_udp;
9116         int ret;
9117
9118         tunnel_udp.udp_port = res->udp_port;
9119         tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9120
9121         if (!strcmp(res->what, "add"))
9122                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9123                                                       &tunnel_udp);
9124         else
9125                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9126                                                          &tunnel_udp);
9127
9128         if (ret < 0)
9129                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9130 }
9131
9132 cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9133         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9134                                 rx_vxlan_port, "rx_vxlan_port");
9135 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9136         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9137                                 what, "add#rm");
9138 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9139         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9140                                 udp_port, RTE_UINT16);
9141 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9142         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9143                                 port_id, RTE_UINT16);
9144
9145 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9146         .f = cmd_tunnel_udp_config_parsed,
9147         .data = (void *)0,
9148         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9149                 "Add/Remove a tunneling UDP port filter",
9150         .tokens = {
9151                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9152                 (void *)&cmd_tunnel_udp_config_what,
9153                 (void *)&cmd_tunnel_udp_config_udp_port,
9154                 (void *)&cmd_tunnel_udp_config_port_id,
9155                 NULL,
9156         },
9157 };
9158
9159 struct cmd_config_tunnel_udp_port {
9160         cmdline_fixed_string_t port;
9161         cmdline_fixed_string_t config;
9162         portid_t port_id;
9163         cmdline_fixed_string_t udp_tunnel_port;
9164         cmdline_fixed_string_t action;
9165         cmdline_fixed_string_t tunnel_type;
9166         uint16_t udp_port;
9167 };
9168
9169 static void
9170 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9171                                __rte_unused struct cmdline *cl,
9172                                __rte_unused void *data)
9173 {
9174         struct cmd_config_tunnel_udp_port *res = parsed_result;
9175         struct rte_eth_udp_tunnel tunnel_udp;
9176         int ret = 0;
9177
9178         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9179                 return;
9180
9181         tunnel_udp.udp_port = res->udp_port;
9182
9183         if (!strcmp(res->tunnel_type, "vxlan")) {
9184                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9185         } else if (!strcmp(res->tunnel_type, "geneve")) {
9186                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9187         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9188                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9189         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9190                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_ECPRI;
9191         } else {
9192                 printf("Invalid tunnel type\n");
9193                 return;
9194         }
9195
9196         if (!strcmp(res->action, "add"))
9197                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9198                                                       &tunnel_udp);
9199         else
9200                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9201                                                          &tunnel_udp);
9202
9203         if (ret < 0)
9204                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9205 }
9206
9207 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9208         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9209                                  "port");
9210 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9211         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9212                                  "config");
9213 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9214         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9215                               RTE_UINT16);
9216 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9217         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9218                                  udp_tunnel_port,
9219                                  "udp_tunnel_port");
9220 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9221         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9222                                  "add#rm");
9223 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9224         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9225                                  "vxlan#geneve#vxlan-gpe#ecpri");
9226 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9227         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9228                               RTE_UINT16);
9229
9230 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9231         .f = cmd_cfg_tunnel_udp_port_parsed,
9232         .data = NULL,
9233         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9234                 "geneve|vxlan-gpe|ecpri <udp_port>",
9235         .tokens = {
9236                 (void *)&cmd_config_tunnel_udp_port_port,
9237                 (void *)&cmd_config_tunnel_udp_port_config,
9238                 (void *)&cmd_config_tunnel_udp_port_port_id,
9239                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9240                 (void *)&cmd_config_tunnel_udp_port_action,
9241                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9242                 (void *)&cmd_config_tunnel_udp_port_value,
9243                 NULL,
9244         },
9245 };
9246
9247 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9248 struct cmd_set_mirror_mask_result {
9249         cmdline_fixed_string_t set;
9250         cmdline_fixed_string_t port;
9251         portid_t port_id;
9252         cmdline_fixed_string_t mirror;
9253         uint8_t rule_id;
9254         cmdline_fixed_string_t what;
9255         cmdline_fixed_string_t value;
9256         cmdline_fixed_string_t dstpool;
9257         uint8_t dstpool_id;
9258         cmdline_fixed_string_t on;
9259 };
9260
9261 cmdline_parse_token_string_t cmd_mirror_mask_set =
9262         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9263                                 set, "set");
9264 cmdline_parse_token_string_t cmd_mirror_mask_port =
9265         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9266                                 port, "port");
9267 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9268         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9269                                 port_id, RTE_UINT16);
9270 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9271         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9272                                 mirror, "mirror-rule");
9273 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9274         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9275                                 rule_id, RTE_UINT8);
9276 cmdline_parse_token_string_t cmd_mirror_mask_what =
9277         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9278                                 what, "pool-mirror-up#pool-mirror-down"
9279                                       "#vlan-mirror");
9280 cmdline_parse_token_string_t cmd_mirror_mask_value =
9281         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9282                                 value, NULL);
9283 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9284         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9285                                 dstpool, "dst-pool");
9286 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9287         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9288                                 dstpool_id, RTE_UINT8);
9289 cmdline_parse_token_string_t cmd_mirror_mask_on =
9290         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9291                                 on, "on#off");
9292
9293 static void
9294 cmd_set_mirror_mask_parsed(void *parsed_result,
9295                        __rte_unused struct cmdline *cl,
9296                        __rte_unused void *data)
9297 {
9298         int ret,nb_item,i;
9299         struct cmd_set_mirror_mask_result *res = parsed_result;
9300         struct rte_eth_mirror_conf mr_conf;
9301
9302         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9303
9304         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9305
9306         mr_conf.dst_pool = res->dstpool_id;
9307
9308         if (!strcmp(res->what, "pool-mirror-up")) {
9309                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9310                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9311         } else if (!strcmp(res->what, "pool-mirror-down")) {
9312                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9313                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9314         } else if (!strcmp(res->what, "vlan-mirror")) {
9315                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9316                 nb_item = parse_item_list(res->value, "vlan",
9317                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9318                 if (nb_item <= 0)
9319                         return;
9320
9321                 for (i = 0; i < nb_item; i++) {
9322                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9323                                 printf("Invalid vlan_id: must be < 4096\n");
9324                                 return;
9325                         }
9326
9327                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9328                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9329                 }
9330         }
9331
9332         if (!strcmp(res->on, "on"))
9333                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9334                                                 res->rule_id, 1);
9335         else
9336                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9337                                                 res->rule_id, 0);
9338         if (ret < 0)
9339                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9340 }
9341
9342 cmdline_parse_inst_t cmd_set_mirror_mask = {
9343                 .f = cmd_set_mirror_mask_parsed,
9344                 .data = NULL,
9345                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9346                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9347                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9348                 .tokens = {
9349                         (void *)&cmd_mirror_mask_set,
9350                         (void *)&cmd_mirror_mask_port,
9351                         (void *)&cmd_mirror_mask_portid,
9352                         (void *)&cmd_mirror_mask_mirror,
9353                         (void *)&cmd_mirror_mask_ruleid,
9354                         (void *)&cmd_mirror_mask_what,
9355                         (void *)&cmd_mirror_mask_value,
9356                         (void *)&cmd_mirror_mask_dstpool,
9357                         (void *)&cmd_mirror_mask_poolid,
9358                         (void *)&cmd_mirror_mask_on,
9359                         NULL,
9360                 },
9361 };
9362
9363 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9364 struct cmd_set_mirror_link_result {
9365         cmdline_fixed_string_t set;
9366         cmdline_fixed_string_t port;
9367         portid_t port_id;
9368         cmdline_fixed_string_t mirror;
9369         uint8_t rule_id;
9370         cmdline_fixed_string_t what;
9371         cmdline_fixed_string_t dstpool;
9372         uint8_t dstpool_id;
9373         cmdline_fixed_string_t on;
9374 };
9375
9376 cmdline_parse_token_string_t cmd_mirror_link_set =
9377         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9378                                  set, "set");
9379 cmdline_parse_token_string_t cmd_mirror_link_port =
9380         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9381                                 port, "port");
9382 cmdline_parse_token_num_t cmd_mirror_link_portid =
9383         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9384                                 port_id, RTE_UINT16);
9385 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9386         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9387                                 mirror, "mirror-rule");
9388 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9389         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9390                             rule_id, RTE_UINT8);
9391 cmdline_parse_token_string_t cmd_mirror_link_what =
9392         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9393                                 what, "uplink-mirror#downlink-mirror");
9394 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9395         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9396                                 dstpool, "dst-pool");
9397 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9398         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9399                                 dstpool_id, RTE_UINT8);
9400 cmdline_parse_token_string_t cmd_mirror_link_on =
9401         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9402                                 on, "on#off");
9403
9404 static void
9405 cmd_set_mirror_link_parsed(void *parsed_result,
9406                        __rte_unused struct cmdline *cl,
9407                        __rte_unused void *data)
9408 {
9409         int ret;
9410         struct cmd_set_mirror_link_result *res = parsed_result;
9411         struct rte_eth_mirror_conf mr_conf;
9412
9413         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9414         if (!strcmp(res->what, "uplink-mirror"))
9415                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9416         else
9417                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9418
9419         mr_conf.dst_pool = res->dstpool_id;
9420
9421         if (!strcmp(res->on, "on"))
9422                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9423                                                 res->rule_id, 1);
9424         else
9425                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9426                                                 res->rule_id, 0);
9427
9428         /* check the return value and print it if is < 0 */
9429         if (ret < 0)
9430                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9431
9432 }
9433
9434 cmdline_parse_inst_t cmd_set_mirror_link = {
9435                 .f = cmd_set_mirror_link_parsed,
9436                 .data = NULL,
9437                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9438                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9439                 .tokens = {
9440                         (void *)&cmd_mirror_link_set,
9441                         (void *)&cmd_mirror_link_port,
9442                         (void *)&cmd_mirror_link_portid,
9443                         (void *)&cmd_mirror_link_mirror,
9444                         (void *)&cmd_mirror_link_ruleid,
9445                         (void *)&cmd_mirror_link_what,
9446                         (void *)&cmd_mirror_link_dstpool,
9447                         (void *)&cmd_mirror_link_poolid,
9448                         (void *)&cmd_mirror_link_on,
9449                         NULL,
9450                 },
9451 };
9452
9453 /* *** RESET VM MIRROR RULE *** */
9454 struct cmd_rm_mirror_rule_result {
9455         cmdline_fixed_string_t reset;
9456         cmdline_fixed_string_t port;
9457         portid_t port_id;
9458         cmdline_fixed_string_t mirror;
9459         uint8_t rule_id;
9460 };
9461
9462 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9463         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9464                                  reset, "reset");
9465 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9466         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9467                                 port, "port");
9468 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9469         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9470                                 port_id, RTE_UINT16);
9471 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9472         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9473                                 mirror, "mirror-rule");
9474 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9475         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9476                                 rule_id, RTE_UINT8);
9477
9478 static void
9479 cmd_reset_mirror_rule_parsed(void *parsed_result,
9480                        __rte_unused struct cmdline *cl,
9481                        __rte_unused void *data)
9482 {
9483         int ret;
9484         struct cmd_set_mirror_link_result *res = parsed_result;
9485         /* check rule_id */
9486         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9487         if(ret < 0)
9488                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9489 }
9490
9491 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9492                 .f = cmd_reset_mirror_rule_parsed,
9493                 .data = NULL,
9494                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9495                 .tokens = {
9496                         (void *)&cmd_rm_mirror_rule_reset,
9497                         (void *)&cmd_rm_mirror_rule_port,
9498                         (void *)&cmd_rm_mirror_rule_portid,
9499                         (void *)&cmd_rm_mirror_rule_mirror,
9500                         (void *)&cmd_rm_mirror_rule_ruleid,
9501                         NULL,
9502                 },
9503 };
9504
9505 /* ******************************************************************************** */
9506
9507 struct cmd_dump_result {
9508         cmdline_fixed_string_t dump;
9509 };
9510
9511 static void
9512 dump_struct_sizes(void)
9513 {
9514 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9515         DUMP_SIZE(struct rte_mbuf);
9516         DUMP_SIZE(struct rte_mempool);
9517         DUMP_SIZE(struct rte_ring);
9518 #undef DUMP_SIZE
9519 }
9520
9521
9522 /* Dump the socket memory statistics on console */
9523 static void
9524 dump_socket_mem(FILE *f)
9525 {
9526         struct rte_malloc_socket_stats socket_stats;
9527         unsigned int i;
9528         size_t total = 0;
9529         size_t alloc = 0;
9530         size_t free = 0;
9531         unsigned int n_alloc = 0;
9532         unsigned int n_free = 0;
9533         static size_t last_allocs;
9534         static size_t last_total;
9535
9536
9537         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9538                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9539                     !socket_stats.heap_totalsz_bytes)
9540                         continue;
9541                 total += socket_stats.heap_totalsz_bytes;
9542                 alloc += socket_stats.heap_allocsz_bytes;
9543                 free += socket_stats.heap_freesz_bytes;
9544                 n_alloc += socket_stats.alloc_count;
9545                 n_free += socket_stats.free_count;
9546                 fprintf(f,
9547                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9548                         i,
9549                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9550                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9551                         (double)socket_stats.heap_allocsz_bytes * 100 /
9552                         (double)socket_stats.heap_totalsz_bytes,
9553                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9554                         socket_stats.alloc_count,
9555                         socket_stats.free_count);
9556         }
9557         fprintf(f,
9558                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9559                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9560                 (double)alloc * 100 / (double)total,
9561                 (double)free / (1024 * 1024),
9562                 n_alloc, n_free);
9563         if (last_allocs)
9564                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9565                         ((double)total - (double)last_total) / (1024 * 1024),
9566                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9567         last_allocs = alloc;
9568         last_total = total;
9569 }
9570
9571 static void cmd_dump_parsed(void *parsed_result,
9572                             __rte_unused struct cmdline *cl,
9573                             __rte_unused void *data)
9574 {
9575         struct cmd_dump_result *res = parsed_result;
9576
9577         if (!strcmp(res->dump, "dump_physmem"))
9578                 rte_dump_physmem_layout(stdout);
9579         else if (!strcmp(res->dump, "dump_socket_mem"))
9580                 dump_socket_mem(stdout);
9581         else if (!strcmp(res->dump, "dump_memzone"))
9582                 rte_memzone_dump(stdout);
9583         else if (!strcmp(res->dump, "dump_struct_sizes"))
9584                 dump_struct_sizes();
9585         else if (!strcmp(res->dump, "dump_ring"))
9586                 rte_ring_list_dump(stdout);
9587         else if (!strcmp(res->dump, "dump_mempool"))
9588                 rte_mempool_list_dump(stdout);
9589         else if (!strcmp(res->dump, "dump_devargs"))
9590                 rte_devargs_dump(stdout);
9591         else if (!strcmp(res->dump, "dump_log_types"))
9592                 rte_log_dump(stdout);
9593 }
9594
9595 cmdline_parse_token_string_t cmd_dump_dump =
9596         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9597                 "dump_physmem#"
9598                 "dump_memzone#"
9599                 "dump_socket_mem#"
9600                 "dump_struct_sizes#"
9601                 "dump_ring#"
9602                 "dump_mempool#"
9603                 "dump_devargs#"
9604                 "dump_log_types");
9605
9606 cmdline_parse_inst_t cmd_dump = {
9607         .f = cmd_dump_parsed,  /* function to call */
9608         .data = NULL,      /* 2nd arg of func */
9609         .help_str = "Dump status",
9610         .tokens = {        /* token list, NULL terminated */
9611                 (void *)&cmd_dump_dump,
9612                 NULL,
9613         },
9614 };
9615
9616 /* ******************************************************************************** */
9617
9618 struct cmd_dump_one_result {
9619         cmdline_fixed_string_t dump;
9620         cmdline_fixed_string_t name;
9621 };
9622
9623 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9624                                 __rte_unused void *data)
9625 {
9626         struct cmd_dump_one_result *res = parsed_result;
9627
9628         if (!strcmp(res->dump, "dump_ring")) {
9629                 struct rte_ring *r;
9630                 r = rte_ring_lookup(res->name);
9631                 if (r == NULL) {
9632                         cmdline_printf(cl, "Cannot find ring\n");
9633                         return;
9634                 }
9635                 rte_ring_dump(stdout, r);
9636         } else if (!strcmp(res->dump, "dump_mempool")) {
9637                 struct rte_mempool *mp;
9638                 mp = rte_mempool_lookup(res->name);
9639                 if (mp == NULL) {
9640                         cmdline_printf(cl, "Cannot find mempool\n");
9641                         return;
9642                 }
9643                 rte_mempool_dump(stdout, mp);
9644         }
9645 }
9646
9647 cmdline_parse_token_string_t cmd_dump_one_dump =
9648         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9649                                  "dump_ring#dump_mempool");
9650
9651 cmdline_parse_token_string_t cmd_dump_one_name =
9652         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9653
9654 cmdline_parse_inst_t cmd_dump_one = {
9655         .f = cmd_dump_one_parsed,  /* function to call */
9656         .data = NULL,      /* 2nd arg of func */
9657         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9658         .tokens = {        /* token list, NULL terminated */
9659                 (void *)&cmd_dump_one_dump,
9660                 (void *)&cmd_dump_one_name,
9661                 NULL,
9662         },
9663 };
9664
9665 /* *** queue region set *** */
9666 struct cmd_queue_region_result {
9667         cmdline_fixed_string_t set;
9668         cmdline_fixed_string_t port;
9669         portid_t port_id;
9670         cmdline_fixed_string_t cmd;
9671         cmdline_fixed_string_t region;
9672         uint8_t  region_id;
9673         cmdline_fixed_string_t queue_start_index;
9674         uint8_t  queue_id;
9675         cmdline_fixed_string_t queue_num;
9676         uint8_t  queue_num_value;
9677 };
9678
9679 static void
9680 cmd_queue_region_parsed(void *parsed_result,
9681                         __rte_unused struct cmdline *cl,
9682                         __rte_unused void *data)
9683 {
9684         struct cmd_queue_region_result *res = parsed_result;
9685         int ret = -ENOTSUP;
9686 #ifdef RTE_NET_I40E
9687         struct rte_pmd_i40e_queue_region_conf region_conf;
9688         enum rte_pmd_i40e_queue_region_op op_type;
9689 #endif
9690
9691         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9692                 return;
9693
9694 #ifdef RTE_NET_I40E
9695         memset(&region_conf, 0, sizeof(region_conf));
9696         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9697         region_conf.region_id = res->region_id;
9698         region_conf.queue_num = res->queue_num_value;
9699         region_conf.queue_start_index = res->queue_id;
9700
9701         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9702                                 op_type, &region_conf);
9703 #endif
9704
9705         switch (ret) {
9706         case 0:
9707                 break;
9708         case -ENOTSUP:
9709                 printf("function not implemented or supported\n");
9710                 break;
9711         default:
9712                 printf("queue region config error: (%s)\n", strerror(-ret));
9713         }
9714 }
9715
9716 cmdline_parse_token_string_t cmd_queue_region_set =
9717 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9718                 set, "set");
9719 cmdline_parse_token_string_t cmd_queue_region_port =
9720         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9721 cmdline_parse_token_num_t cmd_queue_region_port_id =
9722         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9723                                 port_id, RTE_UINT16);
9724 cmdline_parse_token_string_t cmd_queue_region_cmd =
9725         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9726                                  cmd, "queue-region");
9727 cmdline_parse_token_string_t cmd_queue_region_id =
9728         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9729                                 region, "region_id");
9730 cmdline_parse_token_num_t cmd_queue_region_index =
9731         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9732                                 region_id, RTE_UINT8);
9733 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9734         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9735                                 queue_start_index, "queue_start_index");
9736 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9737         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9738                                 queue_id, RTE_UINT8);
9739 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9740         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9741                                 queue_num, "queue_num");
9742 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9743         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9744                                 queue_num_value, RTE_UINT8);
9745
9746 cmdline_parse_inst_t cmd_queue_region = {
9747         .f = cmd_queue_region_parsed,
9748         .data = NULL,
9749         .help_str = "set port <port_id> queue-region region_id <value> "
9750                 "queue_start_index <value> queue_num <value>: Set a queue region",
9751         .tokens = {
9752                 (void *)&cmd_queue_region_set,
9753                 (void *)&cmd_queue_region_port,
9754                 (void *)&cmd_queue_region_port_id,
9755                 (void *)&cmd_queue_region_cmd,
9756                 (void *)&cmd_queue_region_id,
9757                 (void *)&cmd_queue_region_index,
9758                 (void *)&cmd_queue_region_queue_start_index,
9759                 (void *)&cmd_queue_region_queue_id,
9760                 (void *)&cmd_queue_region_queue_num,
9761                 (void *)&cmd_queue_region_queue_num_value,
9762                 NULL,
9763         },
9764 };
9765
9766 /* *** queue region and flowtype set *** */
9767 struct cmd_region_flowtype_result {
9768         cmdline_fixed_string_t set;
9769         cmdline_fixed_string_t port;
9770         portid_t port_id;
9771         cmdline_fixed_string_t cmd;
9772         cmdline_fixed_string_t region;
9773         uint8_t  region_id;
9774         cmdline_fixed_string_t flowtype;
9775         uint8_t  flowtype_id;
9776 };
9777
9778 static void
9779 cmd_region_flowtype_parsed(void *parsed_result,
9780                         __rte_unused struct cmdline *cl,
9781                         __rte_unused void *data)
9782 {
9783         struct cmd_region_flowtype_result *res = parsed_result;
9784         int ret = -ENOTSUP;
9785 #ifdef RTE_NET_I40E
9786         struct rte_pmd_i40e_queue_region_conf region_conf;
9787         enum rte_pmd_i40e_queue_region_op op_type;
9788 #endif
9789
9790         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9791                 return;
9792
9793 #ifdef RTE_NET_I40E
9794         memset(&region_conf, 0, sizeof(region_conf));
9795
9796         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9797         region_conf.region_id = res->region_id;
9798         region_conf.hw_flowtype = res->flowtype_id;
9799
9800         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9801                         op_type, &region_conf);
9802 #endif
9803
9804         switch (ret) {
9805         case 0:
9806                 break;
9807         case -ENOTSUP:
9808                 printf("function not implemented or supported\n");
9809                 break;
9810         default:
9811                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9812         }
9813 }
9814
9815 cmdline_parse_token_string_t cmd_region_flowtype_set =
9816 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9817                                 set, "set");
9818 cmdline_parse_token_string_t cmd_region_flowtype_port =
9819         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9820                                 port, "port");
9821 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9822         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9823                                 port_id, RTE_UINT16);
9824 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9825         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9826                                 cmd, "queue-region");
9827 cmdline_parse_token_string_t cmd_region_flowtype_index =
9828         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9829                                 region, "region_id");
9830 cmdline_parse_token_num_t cmd_region_flowtype_id =
9831         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9832                                 region_id, RTE_UINT8);
9833 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9834         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9835                                 flowtype, "flowtype");
9836 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9837         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9838                                 flowtype_id, RTE_UINT8);
9839 cmdline_parse_inst_t cmd_region_flowtype = {
9840         .f = cmd_region_flowtype_parsed,
9841         .data = NULL,
9842         .help_str = "set port <port_id> queue-region region_id <value> "
9843                 "flowtype <value>: Set a flowtype region index",
9844         .tokens = {
9845                 (void *)&cmd_region_flowtype_set,
9846                 (void *)&cmd_region_flowtype_port,
9847                 (void *)&cmd_region_flowtype_port_index,
9848                 (void *)&cmd_region_flowtype_cmd,
9849                 (void *)&cmd_region_flowtype_index,
9850                 (void *)&cmd_region_flowtype_id,
9851                 (void *)&cmd_region_flowtype_flow_index,
9852                 (void *)&cmd_region_flowtype_flow_id,
9853                 NULL,
9854         },
9855 };
9856
9857 /* *** User Priority (UP) to queue region (region_id) set *** */
9858 struct cmd_user_priority_region_result {
9859         cmdline_fixed_string_t set;
9860         cmdline_fixed_string_t port;
9861         portid_t port_id;
9862         cmdline_fixed_string_t cmd;
9863         cmdline_fixed_string_t user_priority;
9864         uint8_t  user_priority_id;
9865         cmdline_fixed_string_t region;
9866         uint8_t  region_id;
9867 };
9868
9869 static void
9870 cmd_user_priority_region_parsed(void *parsed_result,
9871                         __rte_unused struct cmdline *cl,
9872                         __rte_unused void *data)
9873 {
9874         struct cmd_user_priority_region_result *res = parsed_result;
9875         int ret = -ENOTSUP;
9876 #ifdef RTE_NET_I40E
9877         struct rte_pmd_i40e_queue_region_conf region_conf;
9878         enum rte_pmd_i40e_queue_region_op op_type;
9879 #endif
9880
9881         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9882                 return;
9883
9884 #ifdef RTE_NET_I40E
9885         memset(&region_conf, 0, sizeof(region_conf));
9886         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9887         region_conf.user_priority = res->user_priority_id;
9888         region_conf.region_id = res->region_id;
9889
9890         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9891                                 op_type, &region_conf);
9892 #endif
9893
9894         switch (ret) {
9895         case 0:
9896                 break;
9897         case -ENOTSUP:
9898                 printf("function not implemented or supported\n");
9899                 break;
9900         default:
9901                 printf("user_priority region config error: (%s)\n",
9902                                 strerror(-ret));
9903         }
9904 }
9905
9906 cmdline_parse_token_string_t cmd_user_priority_region_set =
9907         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9908                                 set, "set");
9909 cmdline_parse_token_string_t cmd_user_priority_region_port =
9910         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9911                                 port, "port");
9912 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9913         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9914                                 port_id, RTE_UINT16);
9915 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9916         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9917                                 cmd, "queue-region");
9918 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9919         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9920                                 user_priority, "UP");
9921 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9922         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9923                                 user_priority_id, RTE_UINT8);
9924 cmdline_parse_token_string_t cmd_user_priority_region_region =
9925         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9926                                 region, "region_id");
9927 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9928         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9929                                 region_id, RTE_UINT8);
9930
9931 cmdline_parse_inst_t cmd_user_priority_region = {
9932         .f = cmd_user_priority_region_parsed,
9933         .data = NULL,
9934         .help_str = "set port <port_id> queue-region UP <value> "
9935                 "region_id <value>: Set the mapping of User Priority (UP) "
9936                 "to queue region (region_id) ",
9937         .tokens = {
9938                 (void *)&cmd_user_priority_region_set,
9939                 (void *)&cmd_user_priority_region_port,
9940                 (void *)&cmd_user_priority_region_port_index,
9941                 (void *)&cmd_user_priority_region_cmd,
9942                 (void *)&cmd_user_priority_region_UP,
9943                 (void *)&cmd_user_priority_region_UP_id,
9944                 (void *)&cmd_user_priority_region_region,
9945                 (void *)&cmd_user_priority_region_region_id,
9946                 NULL,
9947         },
9948 };
9949
9950 /* *** flush all queue region related configuration *** */
9951 struct cmd_flush_queue_region_result {
9952         cmdline_fixed_string_t set;
9953         cmdline_fixed_string_t port;
9954         portid_t port_id;
9955         cmdline_fixed_string_t cmd;
9956         cmdline_fixed_string_t flush;
9957         cmdline_fixed_string_t what;
9958 };
9959
9960 static void
9961 cmd_flush_queue_region_parsed(void *parsed_result,
9962                         __rte_unused struct cmdline *cl,
9963                         __rte_unused void *data)
9964 {
9965         struct cmd_flush_queue_region_result *res = parsed_result;
9966         int ret = -ENOTSUP;
9967 #ifdef RTE_NET_I40E
9968         struct rte_pmd_i40e_queue_region_conf region_conf;
9969         enum rte_pmd_i40e_queue_region_op op_type;
9970 #endif
9971
9972         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9973                 return;
9974
9975 #ifdef RTE_NET_I40E
9976         memset(&region_conf, 0, sizeof(region_conf));
9977
9978         if (strcmp(res->what, "on") == 0)
9979                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9980         else
9981                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9982
9983         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9984                                 op_type, &region_conf);
9985 #endif
9986
9987         switch (ret) {
9988         case 0:
9989                 break;
9990         case -ENOTSUP:
9991                 printf("function not implemented or supported\n");
9992                 break;
9993         default:
9994                 printf("queue region config flush error: (%s)\n",
9995                                 strerror(-ret));
9996         }
9997 }
9998
9999 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10000         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10001                                 set, "set");
10002 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10003         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10004                                 port, "port");
10005 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10006         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10007                                 port_id, RTE_UINT16);
10008 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10009         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10010                                 cmd, "queue-region");
10011 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10012         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10013                                 flush, "flush");
10014 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10015         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10016                                 what, "on#off");
10017
10018 cmdline_parse_inst_t cmd_flush_queue_region = {
10019         .f = cmd_flush_queue_region_parsed,
10020         .data = NULL,
10021         .help_str = "set port <port_id> queue-region flush on|off"
10022                 ": flush all queue region related configuration",
10023         .tokens = {
10024                 (void *)&cmd_flush_queue_region_set,
10025                 (void *)&cmd_flush_queue_region_port,
10026                 (void *)&cmd_flush_queue_region_port_index,
10027                 (void *)&cmd_flush_queue_region_cmd,
10028                 (void *)&cmd_flush_queue_region_flush,
10029                 (void *)&cmd_flush_queue_region_what,
10030                 NULL,
10031         },
10032 };
10033
10034 /* *** get all queue region related configuration info *** */
10035 struct cmd_show_queue_region_info {
10036         cmdline_fixed_string_t show;
10037         cmdline_fixed_string_t port;
10038         portid_t port_id;
10039         cmdline_fixed_string_t cmd;
10040 };
10041
10042 static void
10043 cmd_show_queue_region_info_parsed(void *parsed_result,
10044                         __rte_unused struct cmdline *cl,
10045                         __rte_unused void *data)
10046 {
10047         struct cmd_show_queue_region_info *res = parsed_result;
10048         int ret = -ENOTSUP;
10049 #ifdef RTE_NET_I40E
10050         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10051         enum rte_pmd_i40e_queue_region_op op_type;
10052 #endif
10053
10054         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10055                 return;
10056
10057 #ifdef RTE_NET_I40E
10058         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10059
10060         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10061
10062         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10063                                         op_type, &rte_pmd_regions);
10064
10065         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10066 #endif
10067
10068         switch (ret) {
10069         case 0:
10070                 break;
10071         case -ENOTSUP:
10072                 printf("function not implemented or supported\n");
10073                 break;
10074         default:
10075                 printf("queue region config info show error: (%s)\n",
10076                                 strerror(-ret));
10077         }
10078 }
10079
10080 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10081 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10082                                 show, "show");
10083 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10084         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10085                                 port, "port");
10086 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10087         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10088                                 port_id, RTE_UINT16);
10089 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10090         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10091                                 cmd, "queue-region");
10092
10093 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10094         .f = cmd_show_queue_region_info_parsed,
10095         .data = NULL,
10096         .help_str = "show port <port_id> queue-region"
10097                 ": show all queue region related configuration info",
10098         .tokens = {
10099                 (void *)&cmd_show_queue_region_info_get,
10100                 (void *)&cmd_show_queue_region_info_port,
10101                 (void *)&cmd_show_queue_region_info_port_index,
10102                 (void *)&cmd_show_queue_region_info_cmd,
10103                 NULL,
10104         },
10105 };
10106
10107 /* *** Filters Control *** */
10108
10109 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10110 do { \
10111         if ((ip_addr).family == AF_INET) \
10112                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10113         else { \
10114                 printf("invalid parameter.\n"); \
10115                 return; \
10116         } \
10117 } while (0)
10118
10119 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10120 do { \
10121         if ((ip_addr).family == AF_INET6) \
10122                 rte_memcpy(&(ip), \
10123                                  &((ip_addr).addr.ipv6), \
10124                                  sizeof(struct in6_addr)); \
10125         else { \
10126                 printf("invalid parameter.\n"); \
10127                 return; \
10128         } \
10129 } while (0)
10130
10131 #ifdef RTE_NET_I40E
10132
10133 static uint16_t
10134 str2flowtype(char *string)
10135 {
10136         uint8_t i = 0;
10137         static const struct {
10138                 char str[32];
10139                 uint16_t type;
10140         } flowtype_str[] = {
10141                 {"raw", RTE_ETH_FLOW_RAW},
10142                 {"ipv4", RTE_ETH_FLOW_IPV4},
10143                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10144                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10145                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10146                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10147                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10148                 {"ipv6", RTE_ETH_FLOW_IPV6},
10149                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10150                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10151                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10152                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10153                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10154                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10155         };
10156
10157         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10158                 if (!strcmp(flowtype_str[i].str, string))
10159                         return flowtype_str[i].type;
10160         }
10161
10162         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10163                 return (uint16_t)atoi(string);
10164
10165         return RTE_ETH_FLOW_UNKNOWN;
10166 }
10167
10168 /* *** deal with flow director filter *** */
10169 struct cmd_flow_director_result {
10170         cmdline_fixed_string_t flow_director_filter;
10171         portid_t port_id;
10172         cmdline_fixed_string_t mode;
10173         cmdline_fixed_string_t mode_value;
10174         cmdline_fixed_string_t ops;
10175         cmdline_fixed_string_t flow;
10176         cmdline_fixed_string_t flow_type;
10177         cmdline_fixed_string_t drop;
10178         cmdline_fixed_string_t queue;
10179         uint16_t  queue_id;
10180         cmdline_fixed_string_t fd_id;
10181         uint32_t  fd_id_value;
10182         cmdline_fixed_string_t packet;
10183         char filepath[];
10184 };
10185
10186 static void
10187 cmd_flow_director_filter_parsed(void *parsed_result,
10188                           __rte_unused struct cmdline *cl,
10189                           __rte_unused void *data)
10190 {
10191         struct cmd_flow_director_result *res = parsed_result;
10192         int ret = 0;
10193         struct rte_pmd_i40e_flow_type_mapping
10194                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10195         struct rte_pmd_i40e_pkt_template_conf conf;
10196         uint16_t flow_type = str2flowtype(res->flow_type);
10197         uint16_t i, port = res->port_id;
10198         uint8_t add;
10199
10200         memset(&conf, 0, sizeof(conf));
10201
10202         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10203                 printf("Invalid flow type specified.\n");
10204                 return;
10205         }
10206         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10207                                                  mapping);
10208         if (ret)
10209                 return;
10210         if (mapping[flow_type].pctype == 0ULL) {
10211                 printf("Invalid flow type specified.\n");
10212                 return;
10213         }
10214         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10215                 if (mapping[flow_type].pctype & (1ULL << i)) {
10216                         conf.input.pctype = i;
10217                         break;
10218                 }
10219         }
10220
10221         conf.input.packet = open_file(res->filepath,
10222                                 &conf.input.length);
10223         if (!conf.input.packet)
10224                 return;
10225         if (!strcmp(res->drop, "drop"))
10226                 conf.action.behavior =
10227                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10228         else
10229                 conf.action.behavior =
10230                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10231         conf.action.report_status =
10232                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10233         conf.action.rx_queue = res->queue_id;
10234         conf.soft_id = res->fd_id_value;
10235         add  = strcmp(res->ops, "del") ? 1 : 0;
10236         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10237                                                         &conf,
10238                                                         add);
10239         if (ret < 0)
10240                 printf("flow director config error: (%s)\n",
10241                        strerror(-ret));
10242         close_file(conf.input.packet);
10243 }
10244
10245 cmdline_parse_token_string_t cmd_flow_director_filter =
10246         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10247                                  flow_director_filter, "flow_director_filter");
10248 cmdline_parse_token_num_t cmd_flow_director_port_id =
10249         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10250                               port_id, RTE_UINT16);
10251 cmdline_parse_token_string_t cmd_flow_director_ops =
10252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10253                                  ops, "add#del#update");
10254 cmdline_parse_token_string_t cmd_flow_director_flow =
10255         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10256                                  flow, "flow");
10257 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10258         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10259                 flow_type, NULL);
10260 cmdline_parse_token_string_t cmd_flow_director_drop =
10261         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10262                                  drop, "drop#fwd");
10263 cmdline_parse_token_string_t cmd_flow_director_queue =
10264         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10265                                  queue, "queue");
10266 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10267         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10268                               queue_id, RTE_UINT16);
10269 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10270         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10271                                  fd_id, "fd_id");
10272 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10273         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10274                               fd_id_value, RTE_UINT32);
10275
10276 cmdline_parse_token_string_t cmd_flow_director_mode =
10277         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10278                                  mode, "mode");
10279 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10280         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10281                                  mode_value, "raw");
10282 cmdline_parse_token_string_t cmd_flow_director_packet =
10283         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10284                                  packet, "packet");
10285 cmdline_parse_token_string_t cmd_flow_director_filepath =
10286         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10287                                  filepath, NULL);
10288
10289 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10290         .f = cmd_flow_director_filter_parsed,
10291         .data = NULL,
10292         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10293                 "director entry on NIC",
10294         .tokens = {
10295                 (void *)&cmd_flow_director_filter,
10296                 (void *)&cmd_flow_director_port_id,
10297                 (void *)&cmd_flow_director_mode,
10298                 (void *)&cmd_flow_director_mode_raw,
10299                 (void *)&cmd_flow_director_ops,
10300                 (void *)&cmd_flow_director_flow,
10301                 (void *)&cmd_flow_director_flow_type,
10302                 (void *)&cmd_flow_director_drop,
10303                 (void *)&cmd_flow_director_queue,
10304                 (void *)&cmd_flow_director_queue_id,
10305                 (void *)&cmd_flow_director_fd_id,
10306                 (void *)&cmd_flow_director_fd_id_value,
10307                 (void *)&cmd_flow_director_packet,
10308                 (void *)&cmd_flow_director_filepath,
10309                 NULL,
10310         },
10311 };
10312
10313 #endif /* RTE_NET_I40E */
10314
10315 /* *** deal with flow director mask *** */
10316 struct cmd_flow_director_mask_result {
10317         cmdline_fixed_string_t flow_director_mask;
10318         portid_t port_id;
10319         cmdline_fixed_string_t mode;
10320         cmdline_fixed_string_t mode_value;
10321         cmdline_fixed_string_t vlan;
10322         uint16_t vlan_mask;
10323         cmdline_fixed_string_t src_mask;
10324         cmdline_ipaddr_t ipv4_src;
10325         cmdline_ipaddr_t ipv6_src;
10326         uint16_t port_src;
10327         cmdline_fixed_string_t dst_mask;
10328         cmdline_ipaddr_t ipv4_dst;
10329         cmdline_ipaddr_t ipv6_dst;
10330         uint16_t port_dst;
10331         cmdline_fixed_string_t mac;
10332         uint8_t mac_addr_byte_mask;
10333         cmdline_fixed_string_t tunnel_id;
10334         uint32_t tunnel_id_mask;
10335         cmdline_fixed_string_t tunnel_type;
10336         uint8_t tunnel_type_mask;
10337 };
10338
10339 static void
10340 cmd_flow_director_mask_parsed(void *parsed_result,
10341                           __rte_unused struct cmdline *cl,
10342                           __rte_unused void *data)
10343 {
10344         struct cmd_flow_director_mask_result *res = parsed_result;
10345         struct rte_eth_fdir_masks *mask;
10346         struct rte_port *port;
10347
10348         port = &ports[res->port_id];
10349         /** Check if the port is not started **/
10350         if (port->port_status != RTE_PORT_STOPPED) {
10351                 printf("Please stop port %d first\n", res->port_id);
10352                 return;
10353         }
10354
10355         mask = &port->dev_conf.fdir_conf.mask;
10356
10357         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10358                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10359                         printf("Please set mode to MAC-VLAN.\n");
10360                         return;
10361                 }
10362
10363                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10364         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10365                 if (strcmp(res->mode_value, "Tunnel")) {
10366                         printf("Please set mode to Tunnel.\n");
10367                         return;
10368                 }
10369
10370                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10371                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10372                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10373                 mask->tunnel_type_mask = res->tunnel_type_mask;
10374         } else {
10375                 if (strcmp(res->mode_value, "IP")) {
10376                         printf("Please set mode to IP.\n");
10377                         return;
10378                 }
10379
10380                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10381                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10382                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10383                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10384                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10385                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10386                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10387         }
10388
10389         cmd_reconfig_device_queue(res->port_id, 1, 1);
10390 }
10391
10392 cmdline_parse_token_string_t cmd_flow_director_mask =
10393         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10394                                  flow_director_mask, "flow_director_mask");
10395 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10396         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10397                               port_id, RTE_UINT16);
10398 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10399         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10400                                  vlan, "vlan");
10401 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10402         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10403                               vlan_mask, RTE_UINT16);
10404 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10406                                  src_mask, "src_mask");
10407 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10408         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10409                                  ipv4_src);
10410 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10411         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10412                                  ipv6_src);
10413 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10414         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10415                               port_src, RTE_UINT16);
10416 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10417         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10418                                  dst_mask, "dst_mask");
10419 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10420         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10421                                  ipv4_dst);
10422 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10423         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10424                                  ipv6_dst);
10425 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10426         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10427                               port_dst, RTE_UINT16);
10428
10429 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10431                                  mode, "mode");
10432 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10433         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10434                                  mode_value, "IP");
10435 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10436         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10437                                  mode_value, "MAC-VLAN");
10438 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10439         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10440                                  mode_value, "Tunnel");
10441 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10442         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10443                                  mac, "mac");
10444 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10445         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10446                               mac_addr_byte_mask, RTE_UINT8);
10447 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10448         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10449                                  tunnel_type, "tunnel-type");
10450 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10451         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10452                               tunnel_type_mask, RTE_UINT8);
10453 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10454         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10455                                  tunnel_id, "tunnel-id");
10456 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10457         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10458                               tunnel_id_mask, RTE_UINT32);
10459
10460 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10461         .f = cmd_flow_director_mask_parsed,
10462         .data = NULL,
10463         .help_str = "flow_director_mask ... : "
10464                 "Set IP mode flow director's mask on NIC",
10465         .tokens = {
10466                 (void *)&cmd_flow_director_mask,
10467                 (void *)&cmd_flow_director_mask_port_id,
10468                 (void *)&cmd_flow_director_mask_mode,
10469                 (void *)&cmd_flow_director_mask_mode_ip,
10470                 (void *)&cmd_flow_director_mask_vlan,
10471                 (void *)&cmd_flow_director_mask_vlan_value,
10472                 (void *)&cmd_flow_director_mask_src,
10473                 (void *)&cmd_flow_director_mask_ipv4_src,
10474                 (void *)&cmd_flow_director_mask_ipv6_src,
10475                 (void *)&cmd_flow_director_mask_port_src,
10476                 (void *)&cmd_flow_director_mask_dst,
10477                 (void *)&cmd_flow_director_mask_ipv4_dst,
10478                 (void *)&cmd_flow_director_mask_ipv6_dst,
10479                 (void *)&cmd_flow_director_mask_port_dst,
10480                 NULL,
10481         },
10482 };
10483
10484 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10485         .f = cmd_flow_director_mask_parsed,
10486         .data = NULL,
10487         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10488                 "flow director's mask on NIC",
10489         .tokens = {
10490                 (void *)&cmd_flow_director_mask,
10491                 (void *)&cmd_flow_director_mask_port_id,
10492                 (void *)&cmd_flow_director_mask_mode,
10493                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10494                 (void *)&cmd_flow_director_mask_vlan,
10495                 (void *)&cmd_flow_director_mask_vlan_value,
10496                 NULL,
10497         },
10498 };
10499
10500 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10501         .f = cmd_flow_director_mask_parsed,
10502         .data = NULL,
10503         .help_str = "flow_director_mask ... : Set tunnel mode "
10504                 "flow director's mask on NIC",
10505         .tokens = {
10506                 (void *)&cmd_flow_director_mask,
10507                 (void *)&cmd_flow_director_mask_port_id,
10508                 (void *)&cmd_flow_director_mask_mode,
10509                 (void *)&cmd_flow_director_mask_mode_tunnel,
10510                 (void *)&cmd_flow_director_mask_vlan,
10511                 (void *)&cmd_flow_director_mask_vlan_value,
10512                 (void *)&cmd_flow_director_mask_mac,
10513                 (void *)&cmd_flow_director_mask_mac_value,
10514                 (void *)&cmd_flow_director_mask_tunnel_type,
10515                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10516                 (void *)&cmd_flow_director_mask_tunnel_id,
10517                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10518                 NULL,
10519         },
10520 };
10521
10522 /* *** deal with flow director flexible payload configuration *** */
10523 struct cmd_flow_director_flexpayload_result {
10524         cmdline_fixed_string_t flow_director_flexpayload;
10525         portid_t port_id;
10526         cmdline_fixed_string_t payload_layer;
10527         cmdline_fixed_string_t payload_cfg;
10528 };
10529
10530 static inline int
10531 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10532 {
10533         char s[256];
10534         const char *p, *p0 = q_arg;
10535         char *end;
10536         unsigned long int_fld;
10537         char *str_fld[max_num];
10538         int i;
10539         unsigned size;
10540         int ret = -1;
10541
10542         p = strchr(p0, '(');
10543         if (p == NULL)
10544                 return -1;
10545         ++p;
10546         p0 = strchr(p, ')');
10547         if (p0 == NULL)
10548                 return -1;
10549
10550         size = p0 - p;
10551         if (size >= sizeof(s))
10552                 return -1;
10553
10554         snprintf(s, sizeof(s), "%.*s", size, p);
10555         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10556         if (ret < 0 || ret > max_num)
10557                 return -1;
10558         for (i = 0; i < ret; i++) {
10559                 errno = 0;
10560                 int_fld = strtoul(str_fld[i], &end, 0);
10561                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10562                         return -1;
10563                 offsets[i] = (uint16_t)int_fld;
10564         }
10565         return ret;
10566 }
10567
10568 static void
10569 cmd_flow_director_flxpld_parsed(void *parsed_result,
10570                           __rte_unused struct cmdline *cl,
10571                           __rte_unused void *data)
10572 {
10573         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10574         struct rte_eth_flex_payload_cfg flex_cfg;
10575         struct rte_port *port;
10576         int ret = 0;
10577
10578         port = &ports[res->port_id];
10579         /** Check if the port is not started **/
10580         if (port->port_status != RTE_PORT_STOPPED) {
10581                 printf("Please stop port %d first\n", res->port_id);
10582                 return;
10583         }
10584
10585         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10586
10587         if (!strcmp(res->payload_layer, "raw"))
10588                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10589         else if (!strcmp(res->payload_layer, "l2"))
10590                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10591         else if (!strcmp(res->payload_layer, "l3"))
10592                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10593         else if (!strcmp(res->payload_layer, "l4"))
10594                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10595
10596         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10597                             RTE_ETH_FDIR_MAX_FLEXLEN);
10598         if (ret < 0) {
10599                 printf("error: Cannot parse flex payload input.\n");
10600                 return;
10601         }
10602
10603         fdir_set_flex_payload(res->port_id, &flex_cfg);
10604         cmd_reconfig_device_queue(res->port_id, 1, 1);
10605 }
10606
10607 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10608         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10609                                  flow_director_flexpayload,
10610                                  "flow_director_flex_payload");
10611 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10612         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10613                               port_id, RTE_UINT16);
10614 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10615         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10616                                  payload_layer, "raw#l2#l3#l4");
10617 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10618         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10619                                  payload_cfg, NULL);
10620
10621 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10622         .f = cmd_flow_director_flxpld_parsed,
10623         .data = NULL,
10624         .help_str = "flow_director_flexpayload ... : "
10625                 "Set flow director's flex payload on NIC",
10626         .tokens = {
10627                 (void *)&cmd_flow_director_flexpayload,
10628                 (void *)&cmd_flow_director_flexpayload_port_id,
10629                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10630                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10631                 NULL,
10632         },
10633 };
10634
10635 /* Generic flow interface command. */
10636 extern cmdline_parse_inst_t cmd_flow;
10637
10638 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10639 struct cmd_mcast_addr_result {
10640         cmdline_fixed_string_t mcast_addr_cmd;
10641         cmdline_fixed_string_t what;
10642         uint16_t port_num;
10643         struct rte_ether_addr mc_addr;
10644 };
10645
10646 static void cmd_mcast_addr_parsed(void *parsed_result,
10647                 __rte_unused struct cmdline *cl,
10648                 __rte_unused void *data)
10649 {
10650         struct cmd_mcast_addr_result *res = parsed_result;
10651
10652         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10653                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10654                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10655                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10656                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10657                 return;
10658         }
10659         if (strcmp(res->what, "add") == 0)
10660                 mcast_addr_add(res->port_num, &res->mc_addr);
10661         else
10662                 mcast_addr_remove(res->port_num, &res->mc_addr);
10663 }
10664
10665 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10666         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10667                                  mcast_addr_cmd, "mcast_addr");
10668 cmdline_parse_token_string_t cmd_mcast_addr_what =
10669         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10670                                  "add#remove");
10671 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10672         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10673                                  RTE_UINT16);
10674 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10675         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10676
10677 cmdline_parse_inst_t cmd_mcast_addr = {
10678         .f = cmd_mcast_addr_parsed,
10679         .data = (void *)0,
10680         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10681                 "Add/Remove multicast MAC address on port_id",
10682         .tokens = {
10683                 (void *)&cmd_mcast_addr_cmd,
10684                 (void *)&cmd_mcast_addr_what,
10685                 (void *)&cmd_mcast_addr_portnum,
10686                 (void *)&cmd_mcast_addr_addr,
10687                 NULL,
10688         },
10689 };
10690
10691 /* vf vlan anti spoof configuration */
10692
10693 /* Common result structure for vf vlan anti spoof */
10694 struct cmd_vf_vlan_anti_spoof_result {
10695         cmdline_fixed_string_t set;
10696         cmdline_fixed_string_t vf;
10697         cmdline_fixed_string_t vlan;
10698         cmdline_fixed_string_t antispoof;
10699         portid_t port_id;
10700         uint32_t vf_id;
10701         cmdline_fixed_string_t on_off;
10702 };
10703
10704 /* Common CLI fields for vf vlan anti spoof enable disable */
10705 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10706         TOKEN_STRING_INITIALIZER
10707                 (struct cmd_vf_vlan_anti_spoof_result,
10708                  set, "set");
10709 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10710         TOKEN_STRING_INITIALIZER
10711                 (struct cmd_vf_vlan_anti_spoof_result,
10712                  vf, "vf");
10713 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10714         TOKEN_STRING_INITIALIZER
10715                 (struct cmd_vf_vlan_anti_spoof_result,
10716                  vlan, "vlan");
10717 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10718         TOKEN_STRING_INITIALIZER
10719                 (struct cmd_vf_vlan_anti_spoof_result,
10720                  antispoof, "antispoof");
10721 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10722         TOKEN_NUM_INITIALIZER
10723                 (struct cmd_vf_vlan_anti_spoof_result,
10724                  port_id, RTE_UINT16);
10725 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10726         TOKEN_NUM_INITIALIZER
10727                 (struct cmd_vf_vlan_anti_spoof_result,
10728                  vf_id, RTE_UINT32);
10729 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10730         TOKEN_STRING_INITIALIZER
10731                 (struct cmd_vf_vlan_anti_spoof_result,
10732                  on_off, "on#off");
10733
10734 static void
10735 cmd_set_vf_vlan_anti_spoof_parsed(
10736         void *parsed_result,
10737         __rte_unused struct cmdline *cl,
10738         __rte_unused void *data)
10739 {
10740         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10741         int ret = -ENOTSUP;
10742
10743         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10744
10745         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10746                 return;
10747
10748 #ifdef RTE_NET_IXGBE
10749         if (ret == -ENOTSUP)
10750                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10751                                 res->vf_id, is_on);
10752 #endif
10753 #ifdef RTE_NET_I40E
10754         if (ret == -ENOTSUP)
10755                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10756                                 res->vf_id, is_on);
10757 #endif
10758 #ifdef RTE_NET_BNXT
10759         if (ret == -ENOTSUP)
10760                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
10761                                 res->vf_id, is_on);
10762 #endif
10763
10764         switch (ret) {
10765         case 0:
10766                 break;
10767         case -EINVAL:
10768                 printf("invalid vf_id %d\n", res->vf_id);
10769                 break;
10770         case -ENODEV:
10771                 printf("invalid port_id %d\n", res->port_id);
10772                 break;
10773         case -ENOTSUP:
10774                 printf("function not implemented\n");
10775                 break;
10776         default:
10777                 printf("programming error: (%s)\n", strerror(-ret));
10778         }
10779 }
10780
10781 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10782         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10783         .data = NULL,
10784         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10785         .tokens = {
10786                 (void *)&cmd_vf_vlan_anti_spoof_set,
10787                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10788                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10789                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10790                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10791                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10792                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10793                 NULL,
10794         },
10795 };
10796
10797 /* vf mac anti spoof configuration */
10798
10799 /* Common result structure for vf mac anti spoof */
10800 struct cmd_vf_mac_anti_spoof_result {
10801         cmdline_fixed_string_t set;
10802         cmdline_fixed_string_t vf;
10803         cmdline_fixed_string_t mac;
10804         cmdline_fixed_string_t antispoof;
10805         portid_t port_id;
10806         uint32_t vf_id;
10807         cmdline_fixed_string_t on_off;
10808 };
10809
10810 /* Common CLI fields for vf mac anti spoof enable disable */
10811 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10812         TOKEN_STRING_INITIALIZER
10813                 (struct cmd_vf_mac_anti_spoof_result,
10814                  set, "set");
10815 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10816         TOKEN_STRING_INITIALIZER
10817                 (struct cmd_vf_mac_anti_spoof_result,
10818                  vf, "vf");
10819 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10820         TOKEN_STRING_INITIALIZER
10821                 (struct cmd_vf_mac_anti_spoof_result,
10822                  mac, "mac");
10823 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10824         TOKEN_STRING_INITIALIZER
10825                 (struct cmd_vf_mac_anti_spoof_result,
10826                  antispoof, "antispoof");
10827 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10828         TOKEN_NUM_INITIALIZER
10829                 (struct cmd_vf_mac_anti_spoof_result,
10830                  port_id, RTE_UINT16);
10831 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
10832         TOKEN_NUM_INITIALIZER
10833                 (struct cmd_vf_mac_anti_spoof_result,
10834                  vf_id, RTE_UINT32);
10835 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
10836         TOKEN_STRING_INITIALIZER
10837                 (struct cmd_vf_mac_anti_spoof_result,
10838                  on_off, "on#off");
10839
10840 static void
10841 cmd_set_vf_mac_anti_spoof_parsed(
10842         void *parsed_result,
10843         __rte_unused struct cmdline *cl,
10844         __rte_unused void *data)
10845 {
10846         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
10847         int ret = -ENOTSUP;
10848
10849         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10850
10851         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10852                 return;
10853
10854 #ifdef RTE_NET_IXGBE
10855         if (ret == -ENOTSUP)
10856                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
10857                         res->vf_id, is_on);
10858 #endif
10859 #ifdef RTE_NET_I40E
10860         if (ret == -ENOTSUP)
10861                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
10862                         res->vf_id, is_on);
10863 #endif
10864 #ifdef RTE_NET_BNXT
10865         if (ret == -ENOTSUP)
10866                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
10867                         res->vf_id, is_on);
10868 #endif
10869
10870         switch (ret) {
10871         case 0:
10872                 break;
10873         case -EINVAL:
10874                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10875                 break;
10876         case -ENODEV:
10877                 printf("invalid port_id %d\n", res->port_id);
10878                 break;
10879         case -ENOTSUP:
10880                 printf("function not implemented\n");
10881                 break;
10882         default:
10883                 printf("programming error: (%s)\n", strerror(-ret));
10884         }
10885 }
10886
10887 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
10888         .f = cmd_set_vf_mac_anti_spoof_parsed,
10889         .data = NULL,
10890         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
10891         .tokens = {
10892                 (void *)&cmd_vf_mac_anti_spoof_set,
10893                 (void *)&cmd_vf_mac_anti_spoof_vf,
10894                 (void *)&cmd_vf_mac_anti_spoof_mac,
10895                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
10896                 (void *)&cmd_vf_mac_anti_spoof_port_id,
10897                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
10898                 (void *)&cmd_vf_mac_anti_spoof_on_off,
10899                 NULL,
10900         },
10901 };
10902
10903 /* vf vlan strip queue configuration */
10904
10905 /* Common result structure for vf mac anti spoof */
10906 struct cmd_vf_vlan_stripq_result {
10907         cmdline_fixed_string_t set;
10908         cmdline_fixed_string_t vf;
10909         cmdline_fixed_string_t vlan;
10910         cmdline_fixed_string_t stripq;
10911         portid_t port_id;
10912         uint16_t vf_id;
10913         cmdline_fixed_string_t on_off;
10914 };
10915
10916 /* Common CLI fields for vf vlan strip enable disable */
10917 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
10918         TOKEN_STRING_INITIALIZER
10919                 (struct cmd_vf_vlan_stripq_result,
10920                  set, "set");
10921 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
10922         TOKEN_STRING_INITIALIZER
10923                 (struct cmd_vf_vlan_stripq_result,
10924                  vf, "vf");
10925 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
10926         TOKEN_STRING_INITIALIZER
10927                 (struct cmd_vf_vlan_stripq_result,
10928                  vlan, "vlan");
10929 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
10930         TOKEN_STRING_INITIALIZER
10931                 (struct cmd_vf_vlan_stripq_result,
10932                  stripq, "stripq");
10933 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
10934         TOKEN_NUM_INITIALIZER
10935                 (struct cmd_vf_vlan_stripq_result,
10936                  port_id, RTE_UINT16);
10937 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
10938         TOKEN_NUM_INITIALIZER
10939                 (struct cmd_vf_vlan_stripq_result,
10940                  vf_id, RTE_UINT16);
10941 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
10942         TOKEN_STRING_INITIALIZER
10943                 (struct cmd_vf_vlan_stripq_result,
10944                  on_off, "on#off");
10945
10946 static void
10947 cmd_set_vf_vlan_stripq_parsed(
10948         void *parsed_result,
10949         __rte_unused struct cmdline *cl,
10950         __rte_unused void *data)
10951 {
10952         struct cmd_vf_vlan_stripq_result *res = parsed_result;
10953         int ret = -ENOTSUP;
10954
10955         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10956
10957         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10958                 return;
10959
10960 #ifdef RTE_NET_IXGBE
10961         if (ret == -ENOTSUP)
10962                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
10963                         res->vf_id, is_on);
10964 #endif
10965 #ifdef RTE_NET_I40E
10966         if (ret == -ENOTSUP)
10967                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
10968                         res->vf_id, is_on);
10969 #endif
10970 #ifdef RTE_NET_BNXT
10971         if (ret == -ENOTSUP)
10972                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
10973                         res->vf_id, is_on);
10974 #endif
10975
10976         switch (ret) {
10977         case 0:
10978                 break;
10979         case -EINVAL:
10980                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10981                 break;
10982         case -ENODEV:
10983                 printf("invalid port_id %d\n", res->port_id);
10984                 break;
10985         case -ENOTSUP:
10986                 printf("function not implemented\n");
10987                 break;
10988         default:
10989                 printf("programming error: (%s)\n", strerror(-ret));
10990         }
10991 }
10992
10993 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
10994         .f = cmd_set_vf_vlan_stripq_parsed,
10995         .data = NULL,
10996         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
10997         .tokens = {
10998                 (void *)&cmd_vf_vlan_stripq_set,
10999                 (void *)&cmd_vf_vlan_stripq_vf,
11000                 (void *)&cmd_vf_vlan_stripq_vlan,
11001                 (void *)&cmd_vf_vlan_stripq_stripq,
11002                 (void *)&cmd_vf_vlan_stripq_port_id,
11003                 (void *)&cmd_vf_vlan_stripq_vf_id,
11004                 (void *)&cmd_vf_vlan_stripq_on_off,
11005                 NULL,
11006         },
11007 };
11008
11009 /* vf vlan insert configuration */
11010
11011 /* Common result structure for vf vlan insert */
11012 struct cmd_vf_vlan_insert_result {
11013         cmdline_fixed_string_t set;
11014         cmdline_fixed_string_t vf;
11015         cmdline_fixed_string_t vlan;
11016         cmdline_fixed_string_t insert;
11017         portid_t port_id;
11018         uint16_t vf_id;
11019         uint16_t vlan_id;
11020 };
11021
11022 /* Common CLI fields for vf vlan insert enable disable */
11023 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11024         TOKEN_STRING_INITIALIZER
11025                 (struct cmd_vf_vlan_insert_result,
11026                  set, "set");
11027 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11028         TOKEN_STRING_INITIALIZER
11029                 (struct cmd_vf_vlan_insert_result,
11030                  vf, "vf");
11031 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11032         TOKEN_STRING_INITIALIZER
11033                 (struct cmd_vf_vlan_insert_result,
11034                  vlan, "vlan");
11035 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11036         TOKEN_STRING_INITIALIZER
11037                 (struct cmd_vf_vlan_insert_result,
11038                  insert, "insert");
11039 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11040         TOKEN_NUM_INITIALIZER
11041                 (struct cmd_vf_vlan_insert_result,
11042                  port_id, RTE_UINT16);
11043 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11044         TOKEN_NUM_INITIALIZER
11045                 (struct cmd_vf_vlan_insert_result,
11046                  vf_id, RTE_UINT16);
11047 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11048         TOKEN_NUM_INITIALIZER
11049                 (struct cmd_vf_vlan_insert_result,
11050                  vlan_id, RTE_UINT16);
11051
11052 static void
11053 cmd_set_vf_vlan_insert_parsed(
11054         void *parsed_result,
11055         __rte_unused struct cmdline *cl,
11056         __rte_unused void *data)
11057 {
11058         struct cmd_vf_vlan_insert_result *res = parsed_result;
11059         int ret = -ENOTSUP;
11060
11061         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11062                 return;
11063
11064 #ifdef RTE_NET_IXGBE
11065         if (ret == -ENOTSUP)
11066                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11067                         res->vlan_id);
11068 #endif
11069 #ifdef RTE_NET_I40E
11070         if (ret == -ENOTSUP)
11071                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11072                         res->vlan_id);
11073 #endif
11074 #ifdef RTE_NET_BNXT
11075         if (ret == -ENOTSUP)
11076                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11077                         res->vlan_id);
11078 #endif
11079
11080         switch (ret) {
11081         case 0:
11082                 break;
11083         case -EINVAL:
11084                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11085                 break;
11086         case -ENODEV:
11087                 printf("invalid port_id %d\n", res->port_id);
11088                 break;
11089         case -ENOTSUP:
11090                 printf("function not implemented\n");
11091                 break;
11092         default:
11093                 printf("programming error: (%s)\n", strerror(-ret));
11094         }
11095 }
11096
11097 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11098         .f = cmd_set_vf_vlan_insert_parsed,
11099         .data = NULL,
11100         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11101         .tokens = {
11102                 (void *)&cmd_vf_vlan_insert_set,
11103                 (void *)&cmd_vf_vlan_insert_vf,
11104                 (void *)&cmd_vf_vlan_insert_vlan,
11105                 (void *)&cmd_vf_vlan_insert_insert,
11106                 (void *)&cmd_vf_vlan_insert_port_id,
11107                 (void *)&cmd_vf_vlan_insert_vf_id,
11108                 (void *)&cmd_vf_vlan_insert_vlan_id,
11109                 NULL,
11110         },
11111 };
11112
11113 /* tx loopback configuration */
11114
11115 /* Common result structure for tx loopback */
11116 struct cmd_tx_loopback_result {
11117         cmdline_fixed_string_t set;
11118         cmdline_fixed_string_t tx;
11119         cmdline_fixed_string_t loopback;
11120         portid_t port_id;
11121         cmdline_fixed_string_t on_off;
11122 };
11123
11124 /* Common CLI fields for tx loopback enable disable */
11125 cmdline_parse_token_string_t cmd_tx_loopback_set =
11126         TOKEN_STRING_INITIALIZER
11127                 (struct cmd_tx_loopback_result,
11128                  set, "set");
11129 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11130         TOKEN_STRING_INITIALIZER
11131                 (struct cmd_tx_loopback_result,
11132                  tx, "tx");
11133 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11134         TOKEN_STRING_INITIALIZER
11135                 (struct cmd_tx_loopback_result,
11136                  loopback, "loopback");
11137 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11138         TOKEN_NUM_INITIALIZER
11139                 (struct cmd_tx_loopback_result,
11140                  port_id, RTE_UINT16);
11141 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11142         TOKEN_STRING_INITIALIZER
11143                 (struct cmd_tx_loopback_result,
11144                  on_off, "on#off");
11145
11146 static void
11147 cmd_set_tx_loopback_parsed(
11148         void *parsed_result,
11149         __rte_unused struct cmdline *cl,
11150         __rte_unused void *data)
11151 {
11152         struct cmd_tx_loopback_result *res = parsed_result;
11153         int ret = -ENOTSUP;
11154
11155         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11156
11157         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11158                 return;
11159
11160 #ifdef RTE_NET_IXGBE
11161         if (ret == -ENOTSUP)
11162                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11163 #endif
11164 #ifdef RTE_NET_I40E
11165         if (ret == -ENOTSUP)
11166                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11167 #endif
11168 #ifdef RTE_NET_BNXT
11169         if (ret == -ENOTSUP)
11170                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11171 #endif
11172 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11173         if (ret == -ENOTSUP)
11174                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11175 #endif
11176
11177         switch (ret) {
11178         case 0:
11179                 break;
11180         case -EINVAL:
11181                 printf("invalid is_on %d\n", is_on);
11182                 break;
11183         case -ENODEV:
11184                 printf("invalid port_id %d\n", res->port_id);
11185                 break;
11186         case -ENOTSUP:
11187                 printf("function not implemented\n");
11188                 break;
11189         default:
11190                 printf("programming error: (%s)\n", strerror(-ret));
11191         }
11192 }
11193
11194 cmdline_parse_inst_t cmd_set_tx_loopback = {
11195         .f = cmd_set_tx_loopback_parsed,
11196         .data = NULL,
11197         .help_str = "set tx loopback <port_id> on|off",
11198         .tokens = {
11199                 (void *)&cmd_tx_loopback_set,
11200                 (void *)&cmd_tx_loopback_tx,
11201                 (void *)&cmd_tx_loopback_loopback,
11202                 (void *)&cmd_tx_loopback_port_id,
11203                 (void *)&cmd_tx_loopback_on_off,
11204                 NULL,
11205         },
11206 };
11207
11208 /* all queues drop enable configuration */
11209
11210 /* Common result structure for all queues drop enable */
11211 struct cmd_all_queues_drop_en_result {
11212         cmdline_fixed_string_t set;
11213         cmdline_fixed_string_t all;
11214         cmdline_fixed_string_t queues;
11215         cmdline_fixed_string_t drop;
11216         portid_t port_id;
11217         cmdline_fixed_string_t on_off;
11218 };
11219
11220 /* Common CLI fields for tx loopback enable disable */
11221 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11222         TOKEN_STRING_INITIALIZER
11223                 (struct cmd_all_queues_drop_en_result,
11224                  set, "set");
11225 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11226         TOKEN_STRING_INITIALIZER
11227                 (struct cmd_all_queues_drop_en_result,
11228                  all, "all");
11229 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11230         TOKEN_STRING_INITIALIZER
11231                 (struct cmd_all_queues_drop_en_result,
11232                  queues, "queues");
11233 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11234         TOKEN_STRING_INITIALIZER
11235                 (struct cmd_all_queues_drop_en_result,
11236                  drop, "drop");
11237 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11238         TOKEN_NUM_INITIALIZER
11239                 (struct cmd_all_queues_drop_en_result,
11240                  port_id, RTE_UINT16);
11241 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11242         TOKEN_STRING_INITIALIZER
11243                 (struct cmd_all_queues_drop_en_result,
11244                  on_off, "on#off");
11245
11246 static void
11247 cmd_set_all_queues_drop_en_parsed(
11248         void *parsed_result,
11249         __rte_unused struct cmdline *cl,
11250         __rte_unused void *data)
11251 {
11252         struct cmd_all_queues_drop_en_result *res = parsed_result;
11253         int ret = -ENOTSUP;
11254         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11255
11256         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11257                 return;
11258
11259 #ifdef RTE_NET_IXGBE
11260         if (ret == -ENOTSUP)
11261                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11262 #endif
11263 #ifdef RTE_NET_BNXT
11264         if (ret == -ENOTSUP)
11265                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11266 #endif
11267         switch (ret) {
11268         case 0:
11269                 break;
11270         case -EINVAL:
11271                 printf("invalid is_on %d\n", is_on);
11272                 break;
11273         case -ENODEV:
11274                 printf("invalid port_id %d\n", res->port_id);
11275                 break;
11276         case -ENOTSUP:
11277                 printf("function not implemented\n");
11278                 break;
11279         default:
11280                 printf("programming error: (%s)\n", strerror(-ret));
11281         }
11282 }
11283
11284 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11285         .f = cmd_set_all_queues_drop_en_parsed,
11286         .data = NULL,
11287         .help_str = "set all queues drop <port_id> on|off",
11288         .tokens = {
11289                 (void *)&cmd_all_queues_drop_en_set,
11290                 (void *)&cmd_all_queues_drop_en_all,
11291                 (void *)&cmd_all_queues_drop_en_queues,
11292                 (void *)&cmd_all_queues_drop_en_drop,
11293                 (void *)&cmd_all_queues_drop_en_port_id,
11294                 (void *)&cmd_all_queues_drop_en_on_off,
11295                 NULL,
11296         },
11297 };
11298
11299 /* vf split drop enable configuration */
11300
11301 /* Common result structure for vf split drop enable */
11302 struct cmd_vf_split_drop_en_result {
11303         cmdline_fixed_string_t set;
11304         cmdline_fixed_string_t vf;
11305         cmdline_fixed_string_t split;
11306         cmdline_fixed_string_t drop;
11307         portid_t port_id;
11308         uint16_t vf_id;
11309         cmdline_fixed_string_t on_off;
11310 };
11311
11312 /* Common CLI fields for vf split drop enable disable */
11313 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11314         TOKEN_STRING_INITIALIZER
11315                 (struct cmd_vf_split_drop_en_result,
11316                  set, "set");
11317 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11318         TOKEN_STRING_INITIALIZER
11319                 (struct cmd_vf_split_drop_en_result,
11320                  vf, "vf");
11321 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11322         TOKEN_STRING_INITIALIZER
11323                 (struct cmd_vf_split_drop_en_result,
11324                  split, "split");
11325 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11326         TOKEN_STRING_INITIALIZER
11327                 (struct cmd_vf_split_drop_en_result,
11328                  drop, "drop");
11329 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11330         TOKEN_NUM_INITIALIZER
11331                 (struct cmd_vf_split_drop_en_result,
11332                  port_id, RTE_UINT16);
11333 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11334         TOKEN_NUM_INITIALIZER
11335                 (struct cmd_vf_split_drop_en_result,
11336                  vf_id, RTE_UINT16);
11337 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11338         TOKEN_STRING_INITIALIZER
11339                 (struct cmd_vf_split_drop_en_result,
11340                  on_off, "on#off");
11341
11342 static void
11343 cmd_set_vf_split_drop_en_parsed(
11344         void *parsed_result,
11345         __rte_unused struct cmdline *cl,
11346         __rte_unused void *data)
11347 {
11348         struct cmd_vf_split_drop_en_result *res = parsed_result;
11349         int ret = -ENOTSUP;
11350         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11351
11352         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11353                 return;
11354
11355 #ifdef RTE_NET_IXGBE
11356         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11357                         is_on);
11358 #endif
11359         switch (ret) {
11360         case 0:
11361                 break;
11362         case -EINVAL:
11363                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11364                 break;
11365         case -ENODEV:
11366                 printf("invalid port_id %d\n", res->port_id);
11367                 break;
11368         case -ENOTSUP:
11369                 printf("not supported on port %d\n", res->port_id);
11370                 break;
11371         default:
11372                 printf("programming error: (%s)\n", strerror(-ret));
11373         }
11374 }
11375
11376 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11377         .f = cmd_set_vf_split_drop_en_parsed,
11378         .data = NULL,
11379         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11380         .tokens = {
11381                 (void *)&cmd_vf_split_drop_en_set,
11382                 (void *)&cmd_vf_split_drop_en_vf,
11383                 (void *)&cmd_vf_split_drop_en_split,
11384                 (void *)&cmd_vf_split_drop_en_drop,
11385                 (void *)&cmd_vf_split_drop_en_port_id,
11386                 (void *)&cmd_vf_split_drop_en_vf_id,
11387                 (void *)&cmd_vf_split_drop_en_on_off,
11388                 NULL,
11389         },
11390 };
11391
11392 /* vf mac address configuration */
11393
11394 /* Common result structure for vf mac address */
11395 struct cmd_set_vf_mac_addr_result {
11396         cmdline_fixed_string_t set;
11397         cmdline_fixed_string_t vf;
11398         cmdline_fixed_string_t mac;
11399         cmdline_fixed_string_t addr;
11400         portid_t port_id;
11401         uint16_t vf_id;
11402         struct rte_ether_addr mac_addr;
11403
11404 };
11405
11406 /* Common CLI fields for vf split drop enable disable */
11407 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11408         TOKEN_STRING_INITIALIZER
11409                 (struct cmd_set_vf_mac_addr_result,
11410                  set, "set");
11411 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11412         TOKEN_STRING_INITIALIZER
11413                 (struct cmd_set_vf_mac_addr_result,
11414                  vf, "vf");
11415 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11416         TOKEN_STRING_INITIALIZER
11417                 (struct cmd_set_vf_mac_addr_result,
11418                  mac, "mac");
11419 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11420         TOKEN_STRING_INITIALIZER
11421                 (struct cmd_set_vf_mac_addr_result,
11422                  addr, "addr");
11423 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11424         TOKEN_NUM_INITIALIZER
11425                 (struct cmd_set_vf_mac_addr_result,
11426                  port_id, RTE_UINT16);
11427 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11428         TOKEN_NUM_INITIALIZER
11429                 (struct cmd_set_vf_mac_addr_result,
11430                  vf_id, RTE_UINT16);
11431 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11432         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11433                  mac_addr);
11434
11435 static void
11436 cmd_set_vf_mac_addr_parsed(
11437         void *parsed_result,
11438         __rte_unused struct cmdline *cl,
11439         __rte_unused void *data)
11440 {
11441         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11442         int ret = -ENOTSUP;
11443
11444         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11445                 return;
11446
11447 #ifdef RTE_NET_IXGBE
11448         if (ret == -ENOTSUP)
11449                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11450                                 &res->mac_addr);
11451 #endif
11452 #ifdef RTE_NET_I40E
11453         if (ret == -ENOTSUP)
11454                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11455                                 &res->mac_addr);
11456 #endif
11457 #ifdef RTE_NET_BNXT
11458         if (ret == -ENOTSUP)
11459                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11460                                 &res->mac_addr);
11461 #endif
11462
11463         switch (ret) {
11464         case 0:
11465                 break;
11466         case -EINVAL:
11467                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11468                 break;
11469         case -ENODEV:
11470                 printf("invalid port_id %d\n", res->port_id);
11471                 break;
11472         case -ENOTSUP:
11473                 printf("function not implemented\n");
11474                 break;
11475         default:
11476                 printf("programming error: (%s)\n", strerror(-ret));
11477         }
11478 }
11479
11480 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11481         .f = cmd_set_vf_mac_addr_parsed,
11482         .data = NULL,
11483         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11484         .tokens = {
11485                 (void *)&cmd_set_vf_mac_addr_set,
11486                 (void *)&cmd_set_vf_mac_addr_vf,
11487                 (void *)&cmd_set_vf_mac_addr_mac,
11488                 (void *)&cmd_set_vf_mac_addr_addr,
11489                 (void *)&cmd_set_vf_mac_addr_port_id,
11490                 (void *)&cmd_set_vf_mac_addr_vf_id,
11491                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11492                 NULL,
11493         },
11494 };
11495
11496 /* MACsec configuration */
11497
11498 /* Common result structure for MACsec offload enable */
11499 struct cmd_macsec_offload_on_result {
11500         cmdline_fixed_string_t set;
11501         cmdline_fixed_string_t macsec;
11502         cmdline_fixed_string_t offload;
11503         portid_t port_id;
11504         cmdline_fixed_string_t on;
11505         cmdline_fixed_string_t encrypt;
11506         cmdline_fixed_string_t en_on_off;
11507         cmdline_fixed_string_t replay_protect;
11508         cmdline_fixed_string_t rp_on_off;
11509 };
11510
11511 /* Common CLI fields for MACsec offload disable */
11512 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11513         TOKEN_STRING_INITIALIZER
11514                 (struct cmd_macsec_offload_on_result,
11515                  set, "set");
11516 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11517         TOKEN_STRING_INITIALIZER
11518                 (struct cmd_macsec_offload_on_result,
11519                  macsec, "macsec");
11520 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11521         TOKEN_STRING_INITIALIZER
11522                 (struct cmd_macsec_offload_on_result,
11523                  offload, "offload");
11524 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11525         TOKEN_NUM_INITIALIZER
11526                 (struct cmd_macsec_offload_on_result,
11527                  port_id, RTE_UINT16);
11528 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11529         TOKEN_STRING_INITIALIZER
11530                 (struct cmd_macsec_offload_on_result,
11531                  on, "on");
11532 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11533         TOKEN_STRING_INITIALIZER
11534                 (struct cmd_macsec_offload_on_result,
11535                  encrypt, "encrypt");
11536 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11537         TOKEN_STRING_INITIALIZER
11538                 (struct cmd_macsec_offload_on_result,
11539                  en_on_off, "on#off");
11540 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11541         TOKEN_STRING_INITIALIZER
11542                 (struct cmd_macsec_offload_on_result,
11543                  replay_protect, "replay-protect");
11544 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11545         TOKEN_STRING_INITIALIZER
11546                 (struct cmd_macsec_offload_on_result,
11547                  rp_on_off, "on#off");
11548
11549 static void
11550 cmd_set_macsec_offload_on_parsed(
11551         void *parsed_result,
11552         __rte_unused struct cmdline *cl,
11553         __rte_unused void *data)
11554 {
11555         struct cmd_macsec_offload_on_result *res = parsed_result;
11556         int ret = -ENOTSUP;
11557         portid_t port_id = res->port_id;
11558         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11559         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11560         struct rte_eth_dev_info dev_info;
11561
11562         if (port_id_is_invalid(port_id, ENABLED_WARN))
11563                 return;
11564         if (!port_is_stopped(port_id)) {
11565                 printf("Please stop port %d first\n", port_id);
11566                 return;
11567         }
11568
11569         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11570         if (ret != 0)
11571                 return;
11572
11573         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11574 #ifdef RTE_NET_IXGBE
11575                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11576 #endif
11577         }
11578         RTE_SET_USED(en);
11579         RTE_SET_USED(rp);
11580
11581         switch (ret) {
11582         case 0:
11583                 ports[port_id].dev_conf.txmode.offloads |=
11584                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11585                 cmd_reconfig_device_queue(port_id, 1, 1);
11586                 break;
11587         case -ENODEV:
11588                 printf("invalid port_id %d\n", port_id);
11589                 break;
11590         case -ENOTSUP:
11591                 printf("not supported on port %d\n", port_id);
11592                 break;
11593         default:
11594                 printf("programming error: (%s)\n", strerror(-ret));
11595         }
11596 }
11597
11598 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11599         .f = cmd_set_macsec_offload_on_parsed,
11600         .data = NULL,
11601         .help_str = "set macsec offload <port_id> on "
11602                 "encrypt on|off replay-protect on|off",
11603         .tokens = {
11604                 (void *)&cmd_macsec_offload_on_set,
11605                 (void *)&cmd_macsec_offload_on_macsec,
11606                 (void *)&cmd_macsec_offload_on_offload,
11607                 (void *)&cmd_macsec_offload_on_port_id,
11608                 (void *)&cmd_macsec_offload_on_on,
11609                 (void *)&cmd_macsec_offload_on_encrypt,
11610                 (void *)&cmd_macsec_offload_on_en_on_off,
11611                 (void *)&cmd_macsec_offload_on_replay_protect,
11612                 (void *)&cmd_macsec_offload_on_rp_on_off,
11613                 NULL,
11614         },
11615 };
11616
11617 /* Common result structure for MACsec offload disable */
11618 struct cmd_macsec_offload_off_result {
11619         cmdline_fixed_string_t set;
11620         cmdline_fixed_string_t macsec;
11621         cmdline_fixed_string_t offload;
11622         portid_t port_id;
11623         cmdline_fixed_string_t off;
11624 };
11625
11626 /* Common CLI fields for MACsec offload disable */
11627 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11628         TOKEN_STRING_INITIALIZER
11629                 (struct cmd_macsec_offload_off_result,
11630                  set, "set");
11631 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11632         TOKEN_STRING_INITIALIZER
11633                 (struct cmd_macsec_offload_off_result,
11634                  macsec, "macsec");
11635 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11636         TOKEN_STRING_INITIALIZER
11637                 (struct cmd_macsec_offload_off_result,
11638                  offload, "offload");
11639 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11640         TOKEN_NUM_INITIALIZER
11641                 (struct cmd_macsec_offload_off_result,
11642                  port_id, RTE_UINT16);
11643 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11644         TOKEN_STRING_INITIALIZER
11645                 (struct cmd_macsec_offload_off_result,
11646                  off, "off");
11647
11648 static void
11649 cmd_set_macsec_offload_off_parsed(
11650         void *parsed_result,
11651         __rte_unused struct cmdline *cl,
11652         __rte_unused void *data)
11653 {
11654         struct cmd_macsec_offload_off_result *res = parsed_result;
11655         int ret = -ENOTSUP;
11656         struct rte_eth_dev_info dev_info;
11657         portid_t port_id = res->port_id;
11658
11659         if (port_id_is_invalid(port_id, ENABLED_WARN))
11660                 return;
11661         if (!port_is_stopped(port_id)) {
11662                 printf("Please stop port %d first\n", port_id);
11663                 return;
11664         }
11665
11666         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11667         if (ret != 0)
11668                 return;
11669
11670         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11671 #ifdef RTE_NET_IXGBE
11672                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11673 #endif
11674         }
11675         switch (ret) {
11676         case 0:
11677                 ports[port_id].dev_conf.txmode.offloads &=
11678                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11679                 cmd_reconfig_device_queue(port_id, 1, 1);
11680                 break;
11681         case -ENODEV:
11682                 printf("invalid port_id %d\n", port_id);
11683                 break;
11684         case -ENOTSUP:
11685                 printf("not supported on port %d\n", port_id);
11686                 break;
11687         default:
11688                 printf("programming error: (%s)\n", strerror(-ret));
11689         }
11690 }
11691
11692 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11693         .f = cmd_set_macsec_offload_off_parsed,
11694         .data = NULL,
11695         .help_str = "set macsec offload <port_id> off",
11696         .tokens = {
11697                 (void *)&cmd_macsec_offload_off_set,
11698                 (void *)&cmd_macsec_offload_off_macsec,
11699                 (void *)&cmd_macsec_offload_off_offload,
11700                 (void *)&cmd_macsec_offload_off_port_id,
11701                 (void *)&cmd_macsec_offload_off_off,
11702                 NULL,
11703         },
11704 };
11705
11706 /* Common result structure for MACsec secure connection configure */
11707 struct cmd_macsec_sc_result {
11708         cmdline_fixed_string_t set;
11709         cmdline_fixed_string_t macsec;
11710         cmdline_fixed_string_t sc;
11711         cmdline_fixed_string_t tx_rx;
11712         portid_t port_id;
11713         struct rte_ether_addr mac;
11714         uint16_t pi;
11715 };
11716
11717 /* Common CLI fields for MACsec secure connection configure */
11718 cmdline_parse_token_string_t cmd_macsec_sc_set =
11719         TOKEN_STRING_INITIALIZER
11720                 (struct cmd_macsec_sc_result,
11721                  set, "set");
11722 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11723         TOKEN_STRING_INITIALIZER
11724                 (struct cmd_macsec_sc_result,
11725                  macsec, "macsec");
11726 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11727         TOKEN_STRING_INITIALIZER
11728                 (struct cmd_macsec_sc_result,
11729                  sc, "sc");
11730 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11731         TOKEN_STRING_INITIALIZER
11732                 (struct cmd_macsec_sc_result,
11733                  tx_rx, "tx#rx");
11734 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11735         TOKEN_NUM_INITIALIZER
11736                 (struct cmd_macsec_sc_result,
11737                  port_id, RTE_UINT16);
11738 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11739         TOKEN_ETHERADDR_INITIALIZER
11740                 (struct cmd_macsec_sc_result,
11741                  mac);
11742 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11743         TOKEN_NUM_INITIALIZER
11744                 (struct cmd_macsec_sc_result,
11745                  pi, RTE_UINT16);
11746
11747 static void
11748 cmd_set_macsec_sc_parsed(
11749         void *parsed_result,
11750         __rte_unused struct cmdline *cl,
11751         __rte_unused void *data)
11752 {
11753         struct cmd_macsec_sc_result *res = parsed_result;
11754         int ret = -ENOTSUP;
11755         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11756
11757 #ifdef RTE_NET_IXGBE
11758         ret = is_tx ?
11759                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11760                                 res->mac.addr_bytes) :
11761                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11762                                 res->mac.addr_bytes, res->pi);
11763 #endif
11764         RTE_SET_USED(is_tx);
11765
11766         switch (ret) {
11767         case 0:
11768                 break;
11769         case -ENODEV:
11770                 printf("invalid port_id %d\n", res->port_id);
11771                 break;
11772         case -ENOTSUP:
11773                 printf("not supported on port %d\n", res->port_id);
11774                 break;
11775         default:
11776                 printf("programming error: (%s)\n", strerror(-ret));
11777         }
11778 }
11779
11780 cmdline_parse_inst_t cmd_set_macsec_sc = {
11781         .f = cmd_set_macsec_sc_parsed,
11782         .data = NULL,
11783         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11784         .tokens = {
11785                 (void *)&cmd_macsec_sc_set,
11786                 (void *)&cmd_macsec_sc_macsec,
11787                 (void *)&cmd_macsec_sc_sc,
11788                 (void *)&cmd_macsec_sc_tx_rx,
11789                 (void *)&cmd_macsec_sc_port_id,
11790                 (void *)&cmd_macsec_sc_mac,
11791                 (void *)&cmd_macsec_sc_pi,
11792                 NULL,
11793         },
11794 };
11795
11796 /* Common result structure for MACsec secure connection configure */
11797 struct cmd_macsec_sa_result {
11798         cmdline_fixed_string_t set;
11799         cmdline_fixed_string_t macsec;
11800         cmdline_fixed_string_t sa;
11801         cmdline_fixed_string_t tx_rx;
11802         portid_t port_id;
11803         uint8_t idx;
11804         uint8_t an;
11805         uint32_t pn;
11806         cmdline_fixed_string_t key;
11807 };
11808
11809 /* Common CLI fields for MACsec secure connection configure */
11810 cmdline_parse_token_string_t cmd_macsec_sa_set =
11811         TOKEN_STRING_INITIALIZER
11812                 (struct cmd_macsec_sa_result,
11813                  set, "set");
11814 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11815         TOKEN_STRING_INITIALIZER
11816                 (struct cmd_macsec_sa_result,
11817                  macsec, "macsec");
11818 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11819         TOKEN_STRING_INITIALIZER
11820                 (struct cmd_macsec_sa_result,
11821                  sa, "sa");
11822 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11823         TOKEN_STRING_INITIALIZER
11824                 (struct cmd_macsec_sa_result,
11825                  tx_rx, "tx#rx");
11826 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11827         TOKEN_NUM_INITIALIZER
11828                 (struct cmd_macsec_sa_result,
11829                  port_id, RTE_UINT16);
11830 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11831         TOKEN_NUM_INITIALIZER
11832                 (struct cmd_macsec_sa_result,
11833                  idx, RTE_UINT8);
11834 cmdline_parse_token_num_t cmd_macsec_sa_an =
11835         TOKEN_NUM_INITIALIZER
11836                 (struct cmd_macsec_sa_result,
11837                  an, RTE_UINT8);
11838 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11839         TOKEN_NUM_INITIALIZER
11840                 (struct cmd_macsec_sa_result,
11841                  pn, RTE_UINT32);
11842 cmdline_parse_token_string_t cmd_macsec_sa_key =
11843         TOKEN_STRING_INITIALIZER
11844                 (struct cmd_macsec_sa_result,
11845                  key, NULL);
11846
11847 static void
11848 cmd_set_macsec_sa_parsed(
11849         void *parsed_result,
11850         __rte_unused struct cmdline *cl,
11851         __rte_unused void *data)
11852 {
11853         struct cmd_macsec_sa_result *res = parsed_result;
11854         int ret = -ENOTSUP;
11855         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11856         uint8_t key[16] = { 0 };
11857         uint8_t xdgt0;
11858         uint8_t xdgt1;
11859         int key_len;
11860         int i;
11861
11862         key_len = strlen(res->key) / 2;
11863         if (key_len > 16)
11864                 key_len = 16;
11865
11866         for (i = 0; i < key_len; i++) {
11867                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
11868                 if (xdgt0 == 0xFF)
11869                         return;
11870                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
11871                 if (xdgt1 == 0xFF)
11872                         return;
11873                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
11874         }
11875
11876 #ifdef RTE_NET_IXGBE
11877         ret = is_tx ?
11878                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
11879                         res->idx, res->an, res->pn, key) :
11880                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
11881                         res->idx, res->an, res->pn, key);
11882 #endif
11883         RTE_SET_USED(is_tx);
11884         RTE_SET_USED(key);
11885
11886         switch (ret) {
11887         case 0:
11888                 break;
11889         case -EINVAL:
11890                 printf("invalid idx %d or an %d\n", res->idx, res->an);
11891                 break;
11892         case -ENODEV:
11893                 printf("invalid port_id %d\n", res->port_id);
11894                 break;
11895         case -ENOTSUP:
11896                 printf("not supported on port %d\n", res->port_id);
11897                 break;
11898         default:
11899                 printf("programming error: (%s)\n", strerror(-ret));
11900         }
11901 }
11902
11903 cmdline_parse_inst_t cmd_set_macsec_sa = {
11904         .f = cmd_set_macsec_sa_parsed,
11905         .data = NULL,
11906         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
11907         .tokens = {
11908                 (void *)&cmd_macsec_sa_set,
11909                 (void *)&cmd_macsec_sa_macsec,
11910                 (void *)&cmd_macsec_sa_sa,
11911                 (void *)&cmd_macsec_sa_tx_rx,
11912                 (void *)&cmd_macsec_sa_port_id,
11913                 (void *)&cmd_macsec_sa_idx,
11914                 (void *)&cmd_macsec_sa_an,
11915                 (void *)&cmd_macsec_sa_pn,
11916                 (void *)&cmd_macsec_sa_key,
11917                 NULL,
11918         },
11919 };
11920
11921 /* VF unicast promiscuous mode configuration */
11922
11923 /* Common result structure for VF unicast promiscuous mode */
11924 struct cmd_vf_promisc_result {
11925         cmdline_fixed_string_t set;
11926         cmdline_fixed_string_t vf;
11927         cmdline_fixed_string_t promisc;
11928         portid_t port_id;
11929         uint32_t vf_id;
11930         cmdline_fixed_string_t on_off;
11931 };
11932
11933 /* Common CLI fields for VF unicast promiscuous mode enable disable */
11934 cmdline_parse_token_string_t cmd_vf_promisc_set =
11935         TOKEN_STRING_INITIALIZER
11936                 (struct cmd_vf_promisc_result,
11937                  set, "set");
11938 cmdline_parse_token_string_t cmd_vf_promisc_vf =
11939         TOKEN_STRING_INITIALIZER
11940                 (struct cmd_vf_promisc_result,
11941                  vf, "vf");
11942 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
11943         TOKEN_STRING_INITIALIZER
11944                 (struct cmd_vf_promisc_result,
11945                  promisc, "promisc");
11946 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
11947         TOKEN_NUM_INITIALIZER
11948                 (struct cmd_vf_promisc_result,
11949                  port_id, RTE_UINT16);
11950 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
11951         TOKEN_NUM_INITIALIZER
11952                 (struct cmd_vf_promisc_result,
11953                  vf_id, RTE_UINT32);
11954 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
11955         TOKEN_STRING_INITIALIZER
11956                 (struct cmd_vf_promisc_result,
11957                  on_off, "on#off");
11958
11959 static void
11960 cmd_set_vf_promisc_parsed(
11961         void *parsed_result,
11962         __rte_unused struct cmdline *cl,
11963         __rte_unused void *data)
11964 {
11965         struct cmd_vf_promisc_result *res = parsed_result;
11966         int ret = -ENOTSUP;
11967
11968         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11969
11970         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11971                 return;
11972
11973 #ifdef RTE_NET_I40E
11974         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
11975                                                   res->vf_id, is_on);
11976 #endif
11977
11978         switch (ret) {
11979         case 0:
11980                 break;
11981         case -EINVAL:
11982                 printf("invalid vf_id %d\n", res->vf_id);
11983                 break;
11984         case -ENODEV:
11985                 printf("invalid port_id %d\n", res->port_id);
11986                 break;
11987         case -ENOTSUP:
11988                 printf("function not implemented\n");
11989                 break;
11990         default:
11991                 printf("programming error: (%s)\n", strerror(-ret));
11992         }
11993 }
11994
11995 cmdline_parse_inst_t cmd_set_vf_promisc = {
11996         .f = cmd_set_vf_promisc_parsed,
11997         .data = NULL,
11998         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
11999                 "Set unicast promiscuous mode for a VF from the PF",
12000         .tokens = {
12001                 (void *)&cmd_vf_promisc_set,
12002                 (void *)&cmd_vf_promisc_vf,
12003                 (void *)&cmd_vf_promisc_promisc,
12004                 (void *)&cmd_vf_promisc_port_id,
12005                 (void *)&cmd_vf_promisc_vf_id,
12006                 (void *)&cmd_vf_promisc_on_off,
12007                 NULL,
12008         },
12009 };
12010
12011 /* VF multicast promiscuous mode configuration */
12012
12013 /* Common result structure for VF multicast promiscuous mode */
12014 struct cmd_vf_allmulti_result {
12015         cmdline_fixed_string_t set;
12016         cmdline_fixed_string_t vf;
12017         cmdline_fixed_string_t allmulti;
12018         portid_t port_id;
12019         uint32_t vf_id;
12020         cmdline_fixed_string_t on_off;
12021 };
12022
12023 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12024 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12025         TOKEN_STRING_INITIALIZER
12026                 (struct cmd_vf_allmulti_result,
12027                  set, "set");
12028 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12029         TOKEN_STRING_INITIALIZER
12030                 (struct cmd_vf_allmulti_result,
12031                  vf, "vf");
12032 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12033         TOKEN_STRING_INITIALIZER
12034                 (struct cmd_vf_allmulti_result,
12035                  allmulti, "allmulti");
12036 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12037         TOKEN_NUM_INITIALIZER
12038                 (struct cmd_vf_allmulti_result,
12039                  port_id, RTE_UINT16);
12040 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12041         TOKEN_NUM_INITIALIZER
12042                 (struct cmd_vf_allmulti_result,
12043                  vf_id, RTE_UINT32);
12044 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12045         TOKEN_STRING_INITIALIZER
12046                 (struct cmd_vf_allmulti_result,
12047                  on_off, "on#off");
12048
12049 static void
12050 cmd_set_vf_allmulti_parsed(
12051         void *parsed_result,
12052         __rte_unused struct cmdline *cl,
12053         __rte_unused void *data)
12054 {
12055         struct cmd_vf_allmulti_result *res = parsed_result;
12056         int ret = -ENOTSUP;
12057
12058         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12059
12060         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12061                 return;
12062
12063 #ifdef RTE_NET_I40E
12064         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12065                                                     res->vf_id, is_on);
12066 #endif
12067
12068         switch (ret) {
12069         case 0:
12070                 break;
12071         case -EINVAL:
12072                 printf("invalid vf_id %d\n", res->vf_id);
12073                 break;
12074         case -ENODEV:
12075                 printf("invalid port_id %d\n", res->port_id);
12076                 break;
12077         case -ENOTSUP:
12078                 printf("function not implemented\n");
12079                 break;
12080         default:
12081                 printf("programming error: (%s)\n", strerror(-ret));
12082         }
12083 }
12084
12085 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12086         .f = cmd_set_vf_allmulti_parsed,
12087         .data = NULL,
12088         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12089                 "Set multicast promiscuous mode for a VF from the PF",
12090         .tokens = {
12091                 (void *)&cmd_vf_allmulti_set,
12092                 (void *)&cmd_vf_allmulti_vf,
12093                 (void *)&cmd_vf_allmulti_allmulti,
12094                 (void *)&cmd_vf_allmulti_port_id,
12095                 (void *)&cmd_vf_allmulti_vf_id,
12096                 (void *)&cmd_vf_allmulti_on_off,
12097                 NULL,
12098         },
12099 };
12100
12101 /* vf broadcast mode configuration */
12102
12103 /* Common result structure for vf broadcast */
12104 struct cmd_set_vf_broadcast_result {
12105         cmdline_fixed_string_t set;
12106         cmdline_fixed_string_t vf;
12107         cmdline_fixed_string_t broadcast;
12108         portid_t port_id;
12109         uint16_t vf_id;
12110         cmdline_fixed_string_t on_off;
12111 };
12112
12113 /* Common CLI fields for vf broadcast enable disable */
12114 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12115         TOKEN_STRING_INITIALIZER
12116                 (struct cmd_set_vf_broadcast_result,
12117                  set, "set");
12118 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12119         TOKEN_STRING_INITIALIZER
12120                 (struct cmd_set_vf_broadcast_result,
12121                  vf, "vf");
12122 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12123         TOKEN_STRING_INITIALIZER
12124                 (struct cmd_set_vf_broadcast_result,
12125                  broadcast, "broadcast");
12126 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12127         TOKEN_NUM_INITIALIZER
12128                 (struct cmd_set_vf_broadcast_result,
12129                  port_id, RTE_UINT16);
12130 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12131         TOKEN_NUM_INITIALIZER
12132                 (struct cmd_set_vf_broadcast_result,
12133                  vf_id, RTE_UINT16);
12134 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12135         TOKEN_STRING_INITIALIZER
12136                 (struct cmd_set_vf_broadcast_result,
12137                  on_off, "on#off");
12138
12139 static void
12140 cmd_set_vf_broadcast_parsed(
12141         void *parsed_result,
12142         __rte_unused struct cmdline *cl,
12143         __rte_unused void *data)
12144 {
12145         struct cmd_set_vf_broadcast_result *res = parsed_result;
12146         int ret = -ENOTSUP;
12147
12148         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12149
12150         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12151                 return;
12152
12153 #ifdef RTE_NET_I40E
12154         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12155                                             res->vf_id, is_on);
12156 #endif
12157
12158         switch (ret) {
12159         case 0:
12160                 break;
12161         case -EINVAL:
12162                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12163                 break;
12164         case -ENODEV:
12165                 printf("invalid port_id %d\n", res->port_id);
12166                 break;
12167         case -ENOTSUP:
12168                 printf("function not implemented\n");
12169                 break;
12170         default:
12171                 printf("programming error: (%s)\n", strerror(-ret));
12172         }
12173 }
12174
12175 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12176         .f = cmd_set_vf_broadcast_parsed,
12177         .data = NULL,
12178         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12179         .tokens = {
12180                 (void *)&cmd_set_vf_broadcast_set,
12181                 (void *)&cmd_set_vf_broadcast_vf,
12182                 (void *)&cmd_set_vf_broadcast_broadcast,
12183                 (void *)&cmd_set_vf_broadcast_port_id,
12184                 (void *)&cmd_set_vf_broadcast_vf_id,
12185                 (void *)&cmd_set_vf_broadcast_on_off,
12186                 NULL,
12187         },
12188 };
12189
12190 /* vf vlan tag configuration */
12191
12192 /* Common result structure for vf vlan tag */
12193 struct cmd_set_vf_vlan_tag_result {
12194         cmdline_fixed_string_t set;
12195         cmdline_fixed_string_t vf;
12196         cmdline_fixed_string_t vlan;
12197         cmdline_fixed_string_t tag;
12198         portid_t port_id;
12199         uint16_t vf_id;
12200         cmdline_fixed_string_t on_off;
12201 };
12202
12203 /* Common CLI fields for vf vlan tag enable disable */
12204 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12205         TOKEN_STRING_INITIALIZER
12206                 (struct cmd_set_vf_vlan_tag_result,
12207                  set, "set");
12208 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12209         TOKEN_STRING_INITIALIZER
12210                 (struct cmd_set_vf_vlan_tag_result,
12211                  vf, "vf");
12212 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12213         TOKEN_STRING_INITIALIZER
12214                 (struct cmd_set_vf_vlan_tag_result,
12215                  vlan, "vlan");
12216 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12217         TOKEN_STRING_INITIALIZER
12218                 (struct cmd_set_vf_vlan_tag_result,
12219                  tag, "tag");
12220 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12221         TOKEN_NUM_INITIALIZER
12222                 (struct cmd_set_vf_vlan_tag_result,
12223                  port_id, RTE_UINT16);
12224 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12225         TOKEN_NUM_INITIALIZER
12226                 (struct cmd_set_vf_vlan_tag_result,
12227                  vf_id, RTE_UINT16);
12228 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12229         TOKEN_STRING_INITIALIZER
12230                 (struct cmd_set_vf_vlan_tag_result,
12231                  on_off, "on#off");
12232
12233 static void
12234 cmd_set_vf_vlan_tag_parsed(
12235         void *parsed_result,
12236         __rte_unused struct cmdline *cl,
12237         __rte_unused void *data)
12238 {
12239         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12240         int ret = -ENOTSUP;
12241
12242         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12243
12244         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12245                 return;
12246
12247 #ifdef RTE_NET_I40E
12248         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12249                                            res->vf_id, is_on);
12250 #endif
12251
12252         switch (ret) {
12253         case 0:
12254                 break;
12255         case -EINVAL:
12256                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12257                 break;
12258         case -ENODEV:
12259                 printf("invalid port_id %d\n", res->port_id);
12260                 break;
12261         case -ENOTSUP:
12262                 printf("function not implemented\n");
12263                 break;
12264         default:
12265                 printf("programming error: (%s)\n", strerror(-ret));
12266         }
12267 }
12268
12269 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12270         .f = cmd_set_vf_vlan_tag_parsed,
12271         .data = NULL,
12272         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12273         .tokens = {
12274                 (void *)&cmd_set_vf_vlan_tag_set,
12275                 (void *)&cmd_set_vf_vlan_tag_vf,
12276                 (void *)&cmd_set_vf_vlan_tag_vlan,
12277                 (void *)&cmd_set_vf_vlan_tag_tag,
12278                 (void *)&cmd_set_vf_vlan_tag_port_id,
12279                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12280                 (void *)&cmd_set_vf_vlan_tag_on_off,
12281                 NULL,
12282         },
12283 };
12284
12285 /* Common definition of VF and TC TX bandwidth configuration */
12286 struct cmd_vf_tc_bw_result {
12287         cmdline_fixed_string_t set;
12288         cmdline_fixed_string_t vf;
12289         cmdline_fixed_string_t tc;
12290         cmdline_fixed_string_t tx;
12291         cmdline_fixed_string_t min_bw;
12292         cmdline_fixed_string_t max_bw;
12293         cmdline_fixed_string_t strict_link_prio;
12294         portid_t port_id;
12295         uint16_t vf_id;
12296         uint8_t tc_no;
12297         uint32_t bw;
12298         cmdline_fixed_string_t bw_list;
12299         uint8_t tc_map;
12300 };
12301
12302 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12303         TOKEN_STRING_INITIALIZER
12304                 (struct cmd_vf_tc_bw_result,
12305                  set, "set");
12306 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12307         TOKEN_STRING_INITIALIZER
12308                 (struct cmd_vf_tc_bw_result,
12309                  vf, "vf");
12310 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12311         TOKEN_STRING_INITIALIZER
12312                 (struct cmd_vf_tc_bw_result,
12313                  tc, "tc");
12314 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12315         TOKEN_STRING_INITIALIZER
12316                 (struct cmd_vf_tc_bw_result,
12317                  tx, "tx");
12318 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12319         TOKEN_STRING_INITIALIZER
12320                 (struct cmd_vf_tc_bw_result,
12321                  strict_link_prio, "strict-link-priority");
12322 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12323         TOKEN_STRING_INITIALIZER
12324                 (struct cmd_vf_tc_bw_result,
12325                  min_bw, "min-bandwidth");
12326 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12327         TOKEN_STRING_INITIALIZER
12328                 (struct cmd_vf_tc_bw_result,
12329                  max_bw, "max-bandwidth");
12330 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12331         TOKEN_NUM_INITIALIZER
12332                 (struct cmd_vf_tc_bw_result,
12333                  port_id, RTE_UINT16);
12334 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12335         TOKEN_NUM_INITIALIZER
12336                 (struct cmd_vf_tc_bw_result,
12337                  vf_id, RTE_UINT16);
12338 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12339         TOKEN_NUM_INITIALIZER
12340                 (struct cmd_vf_tc_bw_result,
12341                  tc_no, RTE_UINT8);
12342 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12343         TOKEN_NUM_INITIALIZER
12344                 (struct cmd_vf_tc_bw_result,
12345                  bw, RTE_UINT32);
12346 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12347         TOKEN_STRING_INITIALIZER
12348                 (struct cmd_vf_tc_bw_result,
12349                  bw_list, NULL);
12350 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12351         TOKEN_NUM_INITIALIZER
12352                 (struct cmd_vf_tc_bw_result,
12353                  tc_map, RTE_UINT8);
12354
12355 /* VF max bandwidth setting */
12356 static void
12357 cmd_vf_max_bw_parsed(
12358         void *parsed_result,
12359         __rte_unused struct cmdline *cl,
12360         __rte_unused void *data)
12361 {
12362         struct cmd_vf_tc_bw_result *res = parsed_result;
12363         int ret = -ENOTSUP;
12364
12365         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12366                 return;
12367
12368 #ifdef RTE_NET_I40E
12369         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12370                                          res->vf_id, res->bw);
12371 #endif
12372
12373         switch (ret) {
12374         case 0:
12375                 break;
12376         case -EINVAL:
12377                 printf("invalid vf_id %d or bandwidth %d\n",
12378                        res->vf_id, res->bw);
12379                 break;
12380         case -ENODEV:
12381                 printf("invalid port_id %d\n", res->port_id);
12382                 break;
12383         case -ENOTSUP:
12384                 printf("function not implemented\n");
12385                 break;
12386         default:
12387                 printf("programming error: (%s)\n", strerror(-ret));
12388         }
12389 }
12390
12391 cmdline_parse_inst_t cmd_vf_max_bw = {
12392         .f = cmd_vf_max_bw_parsed,
12393         .data = NULL,
12394         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12395         .tokens = {
12396                 (void *)&cmd_vf_tc_bw_set,
12397                 (void *)&cmd_vf_tc_bw_vf,
12398                 (void *)&cmd_vf_tc_bw_tx,
12399                 (void *)&cmd_vf_tc_bw_max_bw,
12400                 (void *)&cmd_vf_tc_bw_port_id,
12401                 (void *)&cmd_vf_tc_bw_vf_id,
12402                 (void *)&cmd_vf_tc_bw_bw,
12403                 NULL,
12404         },
12405 };
12406
12407 static int
12408 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12409                            uint8_t *tc_num,
12410                            char *str)
12411 {
12412         uint32_t size;
12413         const char *p, *p0 = str;
12414         char s[256];
12415         char *end;
12416         char *str_fld[16];
12417         uint16_t i;
12418         int ret;
12419
12420         p = strchr(p0, '(');
12421         if (p == NULL) {
12422                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12423                 return -1;
12424         }
12425         p++;
12426         p0 = strchr(p, ')');
12427         if (p0 == NULL) {
12428                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12429                 return -1;
12430         }
12431         size = p0 - p;
12432         if (size >= sizeof(s)) {
12433                 printf("The string size exceeds the internal buffer size\n");
12434                 return -1;
12435         }
12436         snprintf(s, sizeof(s), "%.*s", size, p);
12437         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12438         if (ret <= 0) {
12439                 printf("Failed to get the bandwidth list. ");
12440                 return -1;
12441         }
12442         *tc_num = ret;
12443         for (i = 0; i < ret; i++)
12444                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12445
12446         return 0;
12447 }
12448
12449 /* TC min bandwidth setting */
12450 static void
12451 cmd_vf_tc_min_bw_parsed(
12452         void *parsed_result,
12453         __rte_unused struct cmdline *cl,
12454         __rte_unused void *data)
12455 {
12456         struct cmd_vf_tc_bw_result *res = parsed_result;
12457         uint8_t tc_num;
12458         uint8_t bw[16];
12459         int ret = -ENOTSUP;
12460
12461         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12462                 return;
12463
12464         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12465         if (ret)
12466                 return;
12467
12468 #ifdef RTE_NET_I40E
12469         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12470                                               tc_num, bw);
12471 #endif
12472
12473         switch (ret) {
12474         case 0:
12475                 break;
12476         case -EINVAL:
12477                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12478                 break;
12479         case -ENODEV:
12480                 printf("invalid port_id %d\n", res->port_id);
12481                 break;
12482         case -ENOTSUP:
12483                 printf("function not implemented\n");
12484                 break;
12485         default:
12486                 printf("programming error: (%s)\n", strerror(-ret));
12487         }
12488 }
12489
12490 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12491         .f = cmd_vf_tc_min_bw_parsed,
12492         .data = NULL,
12493         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12494                     " <bw1, bw2, ...>",
12495         .tokens = {
12496                 (void *)&cmd_vf_tc_bw_set,
12497                 (void *)&cmd_vf_tc_bw_vf,
12498                 (void *)&cmd_vf_tc_bw_tc,
12499                 (void *)&cmd_vf_tc_bw_tx,
12500                 (void *)&cmd_vf_tc_bw_min_bw,
12501                 (void *)&cmd_vf_tc_bw_port_id,
12502                 (void *)&cmd_vf_tc_bw_vf_id,
12503                 (void *)&cmd_vf_tc_bw_bw_list,
12504                 NULL,
12505         },
12506 };
12507
12508 static void
12509 cmd_tc_min_bw_parsed(
12510         void *parsed_result,
12511         __rte_unused struct cmdline *cl,
12512         __rte_unused void *data)
12513 {
12514         struct cmd_vf_tc_bw_result *res = parsed_result;
12515         struct rte_port *port;
12516         uint8_t tc_num;
12517         uint8_t bw[16];
12518         int ret = -ENOTSUP;
12519
12520         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12521                 return;
12522
12523         port = &ports[res->port_id];
12524         /** Check if the port is not started **/
12525         if (port->port_status != RTE_PORT_STOPPED) {
12526                 printf("Please stop port %d first\n", res->port_id);
12527                 return;
12528         }
12529
12530         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12531         if (ret)
12532                 return;
12533
12534 #ifdef RTE_NET_IXGBE
12535         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12536 #endif
12537
12538         switch (ret) {
12539         case 0:
12540                 break;
12541         case -EINVAL:
12542                 printf("invalid bandwidth\n");
12543                 break;
12544         case -ENODEV:
12545                 printf("invalid port_id %d\n", res->port_id);
12546                 break;
12547         case -ENOTSUP:
12548                 printf("function not implemented\n");
12549                 break;
12550         default:
12551                 printf("programming error: (%s)\n", strerror(-ret));
12552         }
12553 }
12554
12555 cmdline_parse_inst_t cmd_tc_min_bw = {
12556         .f = cmd_tc_min_bw_parsed,
12557         .data = NULL,
12558         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12559         .tokens = {
12560                 (void *)&cmd_vf_tc_bw_set,
12561                 (void *)&cmd_vf_tc_bw_tc,
12562                 (void *)&cmd_vf_tc_bw_tx,
12563                 (void *)&cmd_vf_tc_bw_min_bw,
12564                 (void *)&cmd_vf_tc_bw_port_id,
12565                 (void *)&cmd_vf_tc_bw_bw_list,
12566                 NULL,
12567         },
12568 };
12569
12570 /* TC max bandwidth setting */
12571 static void
12572 cmd_vf_tc_max_bw_parsed(
12573         void *parsed_result,
12574         __rte_unused struct cmdline *cl,
12575         __rte_unused void *data)
12576 {
12577         struct cmd_vf_tc_bw_result *res = parsed_result;
12578         int ret = -ENOTSUP;
12579
12580         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12581                 return;
12582
12583 #ifdef RTE_NET_I40E
12584         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12585                                             res->tc_no, res->bw);
12586 #endif
12587
12588         switch (ret) {
12589         case 0:
12590                 break;
12591         case -EINVAL:
12592                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12593                        res->vf_id, res->tc_no, res->bw);
12594                 break;
12595         case -ENODEV:
12596                 printf("invalid port_id %d\n", res->port_id);
12597                 break;
12598         case -ENOTSUP:
12599                 printf("function not implemented\n");
12600                 break;
12601         default:
12602                 printf("programming error: (%s)\n", strerror(-ret));
12603         }
12604 }
12605
12606 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12607         .f = cmd_vf_tc_max_bw_parsed,
12608         .data = NULL,
12609         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12610                     " <bandwidth>",
12611         .tokens = {
12612                 (void *)&cmd_vf_tc_bw_set,
12613                 (void *)&cmd_vf_tc_bw_vf,
12614                 (void *)&cmd_vf_tc_bw_tc,
12615                 (void *)&cmd_vf_tc_bw_tx,
12616                 (void *)&cmd_vf_tc_bw_max_bw,
12617                 (void *)&cmd_vf_tc_bw_port_id,
12618                 (void *)&cmd_vf_tc_bw_vf_id,
12619                 (void *)&cmd_vf_tc_bw_tc_no,
12620                 (void *)&cmd_vf_tc_bw_bw,
12621                 NULL,
12622         },
12623 };
12624
12625 /** Set VXLAN encapsulation details */
12626 struct cmd_set_vxlan_result {
12627         cmdline_fixed_string_t set;
12628         cmdline_fixed_string_t vxlan;
12629         cmdline_fixed_string_t pos_token;
12630         cmdline_fixed_string_t ip_version;
12631         uint32_t vlan_present:1;
12632         uint32_t vni;
12633         uint16_t udp_src;
12634         uint16_t udp_dst;
12635         cmdline_ipaddr_t ip_src;
12636         cmdline_ipaddr_t ip_dst;
12637         uint16_t tci;
12638         uint8_t tos;
12639         uint8_t ttl;
12640         struct rte_ether_addr eth_src;
12641         struct rte_ether_addr eth_dst;
12642 };
12643
12644 cmdline_parse_token_string_t cmd_set_vxlan_set =
12645         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12646 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12647         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12648 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12649         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12650                                  "vxlan-tos-ttl");
12651 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12652         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12653                                  "vxlan-with-vlan");
12654 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12655         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12656                                  "ip-version");
12657 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12658         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12659                                  "ipv4#ipv6");
12660 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12661         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12662                                  "vni");
12663 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12664         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12665 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12666         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12667                                  "udp-src");
12668 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12669         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12670 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12671         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12672                                  "udp-dst");
12673 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12674         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12675 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12676         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12677                                  "ip-tos");
12678 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12679         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12680 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12681         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12682                                  "ip-ttl");
12683 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12684         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12685 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12686         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12687                                  "ip-src");
12688 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12689         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12690 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12691         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12692                                  "ip-dst");
12693 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12694         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12695 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12696         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12697                                  "vlan-tci");
12698 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12699         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12700 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12701         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12702                                  "eth-src");
12703 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12704         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12705 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12706         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12707                                  "eth-dst");
12708 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12709         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12710
12711 static void cmd_set_vxlan_parsed(void *parsed_result,
12712         __rte_unused struct cmdline *cl,
12713         __rte_unused void *data)
12714 {
12715         struct cmd_set_vxlan_result *res = parsed_result;
12716         union {
12717                 uint32_t vxlan_id;
12718                 uint8_t vni[4];
12719         } id = {
12720                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12721         };
12722
12723         vxlan_encap_conf.select_tos_ttl = 0;
12724         if (strcmp(res->vxlan, "vxlan") == 0)
12725                 vxlan_encap_conf.select_vlan = 0;
12726         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12727                 vxlan_encap_conf.select_vlan = 1;
12728         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12729                 vxlan_encap_conf.select_vlan = 0;
12730                 vxlan_encap_conf.select_tos_ttl = 1;
12731         }
12732         if (strcmp(res->ip_version, "ipv4") == 0)
12733                 vxlan_encap_conf.select_ipv4 = 1;
12734         else if (strcmp(res->ip_version, "ipv6") == 0)
12735                 vxlan_encap_conf.select_ipv4 = 0;
12736         else
12737                 return;
12738         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12739         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12740         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
12741         vxlan_encap_conf.ip_tos = res->tos;
12742         vxlan_encap_conf.ip_ttl = res->ttl;
12743         if (vxlan_encap_conf.select_ipv4) {
12744                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
12745                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
12746         } else {
12747                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
12748                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
12749         }
12750         if (vxlan_encap_conf.select_vlan)
12751                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12752         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
12753                    RTE_ETHER_ADDR_LEN);
12754         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12755                    RTE_ETHER_ADDR_LEN);
12756 }
12757
12758 cmdline_parse_inst_t cmd_set_vxlan = {
12759         .f = cmd_set_vxlan_parsed,
12760         .data = NULL,
12761         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
12762                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
12763                 " eth-src <eth-src> eth-dst <eth-dst>",
12764         .tokens = {
12765                 (void *)&cmd_set_vxlan_set,
12766                 (void *)&cmd_set_vxlan_vxlan,
12767                 (void *)&cmd_set_vxlan_ip_version,
12768                 (void *)&cmd_set_vxlan_ip_version_value,
12769                 (void *)&cmd_set_vxlan_vni,
12770                 (void *)&cmd_set_vxlan_vni_value,
12771                 (void *)&cmd_set_vxlan_udp_src,
12772                 (void *)&cmd_set_vxlan_udp_src_value,
12773                 (void *)&cmd_set_vxlan_udp_dst,
12774                 (void *)&cmd_set_vxlan_udp_dst_value,
12775                 (void *)&cmd_set_vxlan_ip_src,
12776                 (void *)&cmd_set_vxlan_ip_src_value,
12777                 (void *)&cmd_set_vxlan_ip_dst,
12778                 (void *)&cmd_set_vxlan_ip_dst_value,
12779                 (void *)&cmd_set_vxlan_eth_src,
12780                 (void *)&cmd_set_vxlan_eth_src_value,
12781                 (void *)&cmd_set_vxlan_eth_dst,
12782                 (void *)&cmd_set_vxlan_eth_dst_value,
12783                 NULL,
12784         },
12785 };
12786
12787 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
12788         .f = cmd_set_vxlan_parsed,
12789         .data = NULL,
12790         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
12791                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
12792                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12793                 " eth-dst <eth-dst>",
12794         .tokens = {
12795                 (void *)&cmd_set_vxlan_set,
12796                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
12797                 (void *)&cmd_set_vxlan_ip_version,
12798                 (void *)&cmd_set_vxlan_ip_version_value,
12799                 (void *)&cmd_set_vxlan_vni,
12800                 (void *)&cmd_set_vxlan_vni_value,
12801                 (void *)&cmd_set_vxlan_udp_src,
12802                 (void *)&cmd_set_vxlan_udp_src_value,
12803                 (void *)&cmd_set_vxlan_udp_dst,
12804                 (void *)&cmd_set_vxlan_udp_dst_value,
12805                 (void *)&cmd_set_vxlan_ip_tos,
12806                 (void *)&cmd_set_vxlan_ip_tos_value,
12807                 (void *)&cmd_set_vxlan_ip_ttl,
12808                 (void *)&cmd_set_vxlan_ip_ttl_value,
12809                 (void *)&cmd_set_vxlan_ip_src,
12810                 (void *)&cmd_set_vxlan_ip_src_value,
12811                 (void *)&cmd_set_vxlan_ip_dst,
12812                 (void *)&cmd_set_vxlan_ip_dst_value,
12813                 (void *)&cmd_set_vxlan_eth_src,
12814                 (void *)&cmd_set_vxlan_eth_src_value,
12815                 (void *)&cmd_set_vxlan_eth_dst,
12816                 (void *)&cmd_set_vxlan_eth_dst_value,
12817                 NULL,
12818         },
12819 };
12820
12821 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
12822         .f = cmd_set_vxlan_parsed,
12823         .data = NULL,
12824         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
12825                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
12826                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
12827                 " <eth-dst>",
12828         .tokens = {
12829                 (void *)&cmd_set_vxlan_set,
12830                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
12831                 (void *)&cmd_set_vxlan_ip_version,
12832                 (void *)&cmd_set_vxlan_ip_version_value,
12833                 (void *)&cmd_set_vxlan_vni,
12834                 (void *)&cmd_set_vxlan_vni_value,
12835                 (void *)&cmd_set_vxlan_udp_src,
12836                 (void *)&cmd_set_vxlan_udp_src_value,
12837                 (void *)&cmd_set_vxlan_udp_dst,
12838                 (void *)&cmd_set_vxlan_udp_dst_value,
12839                 (void *)&cmd_set_vxlan_ip_src,
12840                 (void *)&cmd_set_vxlan_ip_src_value,
12841                 (void *)&cmd_set_vxlan_ip_dst,
12842                 (void *)&cmd_set_vxlan_ip_dst_value,
12843                 (void *)&cmd_set_vxlan_vlan,
12844                 (void *)&cmd_set_vxlan_vlan_value,
12845                 (void *)&cmd_set_vxlan_eth_src,
12846                 (void *)&cmd_set_vxlan_eth_src_value,
12847                 (void *)&cmd_set_vxlan_eth_dst,
12848                 (void *)&cmd_set_vxlan_eth_dst_value,
12849                 NULL,
12850         },
12851 };
12852
12853 /** Set NVGRE encapsulation details */
12854 struct cmd_set_nvgre_result {
12855         cmdline_fixed_string_t set;
12856         cmdline_fixed_string_t nvgre;
12857         cmdline_fixed_string_t pos_token;
12858         cmdline_fixed_string_t ip_version;
12859         uint32_t tni;
12860         cmdline_ipaddr_t ip_src;
12861         cmdline_ipaddr_t ip_dst;
12862         uint16_t tci;
12863         struct rte_ether_addr eth_src;
12864         struct rte_ether_addr eth_dst;
12865 };
12866
12867 cmdline_parse_token_string_t cmd_set_nvgre_set =
12868         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
12869 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
12870         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
12871 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
12872         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
12873                                  "nvgre-with-vlan");
12874 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
12875         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12876                                  "ip-version");
12877 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
12878         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
12879                                  "ipv4#ipv6");
12880 cmdline_parse_token_string_t cmd_set_nvgre_tni =
12881         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12882                                  "tni");
12883 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
12884         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
12885 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
12886         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12887                                  "ip-src");
12888 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
12889         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
12890 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
12891         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12892                                  "ip-dst");
12893 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
12894         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
12895 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
12896         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12897                                  "vlan-tci");
12898 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
12899         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
12900 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
12901         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12902                                  "eth-src");
12903 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
12904         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
12905 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
12906         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12907                                  "eth-dst");
12908 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
12909         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
12910
12911 static void cmd_set_nvgre_parsed(void *parsed_result,
12912         __rte_unused struct cmdline *cl,
12913         __rte_unused void *data)
12914 {
12915         struct cmd_set_nvgre_result *res = parsed_result;
12916         union {
12917                 uint32_t nvgre_tni;
12918                 uint8_t tni[4];
12919         } id = {
12920                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
12921         };
12922
12923         if (strcmp(res->nvgre, "nvgre") == 0)
12924                 nvgre_encap_conf.select_vlan = 0;
12925         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
12926                 nvgre_encap_conf.select_vlan = 1;
12927         if (strcmp(res->ip_version, "ipv4") == 0)
12928                 nvgre_encap_conf.select_ipv4 = 1;
12929         else if (strcmp(res->ip_version, "ipv6") == 0)
12930                 nvgre_encap_conf.select_ipv4 = 0;
12931         else
12932                 return;
12933         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
12934         if (nvgre_encap_conf.select_ipv4) {
12935                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
12936                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
12937         } else {
12938                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
12939                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
12940         }
12941         if (nvgre_encap_conf.select_vlan)
12942                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12943         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
12944                    RTE_ETHER_ADDR_LEN);
12945         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12946                    RTE_ETHER_ADDR_LEN);
12947 }
12948
12949 cmdline_parse_inst_t cmd_set_nvgre = {
12950         .f = cmd_set_nvgre_parsed,
12951         .data = NULL,
12952         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
12953                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12954                 " eth-dst <eth-dst>",
12955         .tokens = {
12956                 (void *)&cmd_set_nvgre_set,
12957                 (void *)&cmd_set_nvgre_nvgre,
12958                 (void *)&cmd_set_nvgre_ip_version,
12959                 (void *)&cmd_set_nvgre_ip_version_value,
12960                 (void *)&cmd_set_nvgre_tni,
12961                 (void *)&cmd_set_nvgre_tni_value,
12962                 (void *)&cmd_set_nvgre_ip_src,
12963                 (void *)&cmd_set_nvgre_ip_src_value,
12964                 (void *)&cmd_set_nvgre_ip_dst,
12965                 (void *)&cmd_set_nvgre_ip_dst_value,
12966                 (void *)&cmd_set_nvgre_eth_src,
12967                 (void *)&cmd_set_nvgre_eth_src_value,
12968                 (void *)&cmd_set_nvgre_eth_dst,
12969                 (void *)&cmd_set_nvgre_eth_dst_value,
12970                 NULL,
12971         },
12972 };
12973
12974 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
12975         .f = cmd_set_nvgre_parsed,
12976         .data = NULL,
12977         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
12978                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
12979                 " eth-src <eth-src> eth-dst <eth-dst>",
12980         .tokens = {
12981                 (void *)&cmd_set_nvgre_set,
12982                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
12983                 (void *)&cmd_set_nvgre_ip_version,
12984                 (void *)&cmd_set_nvgre_ip_version_value,
12985                 (void *)&cmd_set_nvgre_tni,
12986                 (void *)&cmd_set_nvgre_tni_value,
12987                 (void *)&cmd_set_nvgre_ip_src,
12988                 (void *)&cmd_set_nvgre_ip_src_value,
12989                 (void *)&cmd_set_nvgre_ip_dst,
12990                 (void *)&cmd_set_nvgre_ip_dst_value,
12991                 (void *)&cmd_set_nvgre_vlan,
12992                 (void *)&cmd_set_nvgre_vlan_value,
12993                 (void *)&cmd_set_nvgre_eth_src,
12994                 (void *)&cmd_set_nvgre_eth_src_value,
12995                 (void *)&cmd_set_nvgre_eth_dst,
12996                 (void *)&cmd_set_nvgre_eth_dst_value,
12997                 NULL,
12998         },
12999 };
13000
13001 /** Set L2 encapsulation details */
13002 struct cmd_set_l2_encap_result {
13003         cmdline_fixed_string_t set;
13004         cmdline_fixed_string_t l2_encap;
13005         cmdline_fixed_string_t pos_token;
13006         cmdline_fixed_string_t ip_version;
13007         uint32_t vlan_present:1;
13008         uint16_t tci;
13009         struct rte_ether_addr eth_src;
13010         struct rte_ether_addr eth_dst;
13011 };
13012
13013 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13014         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13015 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13016         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13017 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13018         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13019                                  "l2_encap-with-vlan");
13020 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13021         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13022                                  "ip-version");
13023 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13024         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13025                                  "ipv4#ipv6");
13026 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13027         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13028                                  "vlan-tci");
13029 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13030         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13031 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13032         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13033                                  "eth-src");
13034 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13035         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13036 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13037         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13038                                  "eth-dst");
13039 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13040         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13041
13042 static void cmd_set_l2_encap_parsed(void *parsed_result,
13043         __rte_unused struct cmdline *cl,
13044         __rte_unused void *data)
13045 {
13046         struct cmd_set_l2_encap_result *res = parsed_result;
13047
13048         if (strcmp(res->l2_encap, "l2_encap") == 0)
13049                 l2_encap_conf.select_vlan = 0;
13050         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13051                 l2_encap_conf.select_vlan = 1;
13052         if (strcmp(res->ip_version, "ipv4") == 0)
13053                 l2_encap_conf.select_ipv4 = 1;
13054         else if (strcmp(res->ip_version, "ipv6") == 0)
13055                 l2_encap_conf.select_ipv4 = 0;
13056         else
13057                 return;
13058         if (l2_encap_conf.select_vlan)
13059                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13060         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13061                    RTE_ETHER_ADDR_LEN);
13062         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13063                    RTE_ETHER_ADDR_LEN);
13064 }
13065
13066 cmdline_parse_inst_t cmd_set_l2_encap = {
13067         .f = cmd_set_l2_encap_parsed,
13068         .data = NULL,
13069         .help_str = "set l2_encap ip-version ipv4|ipv6"
13070                 " eth-src <eth-src> eth-dst <eth-dst>",
13071         .tokens = {
13072                 (void *)&cmd_set_l2_encap_set,
13073                 (void *)&cmd_set_l2_encap_l2_encap,
13074                 (void *)&cmd_set_l2_encap_ip_version,
13075                 (void *)&cmd_set_l2_encap_ip_version_value,
13076                 (void *)&cmd_set_l2_encap_eth_src,
13077                 (void *)&cmd_set_l2_encap_eth_src_value,
13078                 (void *)&cmd_set_l2_encap_eth_dst,
13079                 (void *)&cmd_set_l2_encap_eth_dst_value,
13080                 NULL,
13081         },
13082 };
13083
13084 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13085         .f = cmd_set_l2_encap_parsed,
13086         .data = NULL,
13087         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13088                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13089         .tokens = {
13090                 (void *)&cmd_set_l2_encap_set,
13091                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13092                 (void *)&cmd_set_l2_encap_ip_version,
13093                 (void *)&cmd_set_l2_encap_ip_version_value,
13094                 (void *)&cmd_set_l2_encap_vlan,
13095                 (void *)&cmd_set_l2_encap_vlan_value,
13096                 (void *)&cmd_set_l2_encap_eth_src,
13097                 (void *)&cmd_set_l2_encap_eth_src_value,
13098                 (void *)&cmd_set_l2_encap_eth_dst,
13099                 (void *)&cmd_set_l2_encap_eth_dst_value,
13100                 NULL,
13101         },
13102 };
13103
13104 /** Set L2 decapsulation details */
13105 struct cmd_set_l2_decap_result {
13106         cmdline_fixed_string_t set;
13107         cmdline_fixed_string_t l2_decap;
13108         cmdline_fixed_string_t pos_token;
13109         uint32_t vlan_present:1;
13110 };
13111
13112 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13113         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13114 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13115         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13116                                  "l2_decap");
13117 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13118         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13119                                  "l2_decap-with-vlan");
13120
13121 static void cmd_set_l2_decap_parsed(void *parsed_result,
13122         __rte_unused struct cmdline *cl,
13123         __rte_unused void *data)
13124 {
13125         struct cmd_set_l2_decap_result *res = parsed_result;
13126
13127         if (strcmp(res->l2_decap, "l2_decap") == 0)
13128                 l2_decap_conf.select_vlan = 0;
13129         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13130                 l2_decap_conf.select_vlan = 1;
13131 }
13132
13133 cmdline_parse_inst_t cmd_set_l2_decap = {
13134         .f = cmd_set_l2_decap_parsed,
13135         .data = NULL,
13136         .help_str = "set l2_decap",
13137         .tokens = {
13138                 (void *)&cmd_set_l2_decap_set,
13139                 (void *)&cmd_set_l2_decap_l2_decap,
13140                 NULL,
13141         },
13142 };
13143
13144 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13145         .f = cmd_set_l2_decap_parsed,
13146         .data = NULL,
13147         .help_str = "set l2_decap-with-vlan",
13148         .tokens = {
13149                 (void *)&cmd_set_l2_decap_set,
13150                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13151                 NULL,
13152         },
13153 };
13154
13155 /** Set MPLSoGRE encapsulation details */
13156 struct cmd_set_mplsogre_encap_result {
13157         cmdline_fixed_string_t set;
13158         cmdline_fixed_string_t mplsogre;
13159         cmdline_fixed_string_t pos_token;
13160         cmdline_fixed_string_t ip_version;
13161         uint32_t vlan_present:1;
13162         uint32_t label;
13163         cmdline_ipaddr_t ip_src;
13164         cmdline_ipaddr_t ip_dst;
13165         uint16_t tci;
13166         struct rte_ether_addr eth_src;
13167         struct rte_ether_addr eth_dst;
13168 };
13169
13170 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13171         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13172                                  "set");
13173 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13174         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13175                                  "mplsogre_encap");
13176 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13177         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13178                                  mplsogre, "mplsogre_encap-with-vlan");
13179 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13180         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13181                                  pos_token, "ip-version");
13182 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13183         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13184                                  ip_version, "ipv4#ipv6");
13185 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13186         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13187                                  pos_token, "label");
13188 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13189         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13190                               RTE_UINT32);
13191 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13192         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13193                                  pos_token, "ip-src");
13194 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13195         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13196 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13197         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13198                                  pos_token, "ip-dst");
13199 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13200         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13201 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13202         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13203                                  pos_token, "vlan-tci");
13204 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13205         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13206                               RTE_UINT16);
13207 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13208         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13209                                  pos_token, "eth-src");
13210 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13211         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13212                                     eth_src);
13213 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13214         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13215                                  pos_token, "eth-dst");
13216 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13217         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13218                                     eth_dst);
13219
13220 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13221         __rte_unused struct cmdline *cl,
13222         __rte_unused void *data)
13223 {
13224         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13225         union {
13226                 uint32_t mplsogre_label;
13227                 uint8_t label[4];
13228         } id = {
13229                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13230         };
13231
13232         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13233                 mplsogre_encap_conf.select_vlan = 0;
13234         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13235                 mplsogre_encap_conf.select_vlan = 1;
13236         if (strcmp(res->ip_version, "ipv4") == 0)
13237                 mplsogre_encap_conf.select_ipv4 = 1;
13238         else if (strcmp(res->ip_version, "ipv6") == 0)
13239                 mplsogre_encap_conf.select_ipv4 = 0;
13240         else
13241                 return;
13242         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13243         if (mplsogre_encap_conf.select_ipv4) {
13244                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13245                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13246         } else {
13247                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13248                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13249         }
13250         if (mplsogre_encap_conf.select_vlan)
13251                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13252         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13253                    RTE_ETHER_ADDR_LEN);
13254         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13255                    RTE_ETHER_ADDR_LEN);
13256 }
13257
13258 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13259         .f = cmd_set_mplsogre_encap_parsed,
13260         .data = NULL,
13261         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13262                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13263                 " eth-dst <eth-dst>",
13264         .tokens = {
13265                 (void *)&cmd_set_mplsogre_encap_set,
13266                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13267                 (void *)&cmd_set_mplsogre_encap_ip_version,
13268                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13269                 (void *)&cmd_set_mplsogre_encap_label,
13270                 (void *)&cmd_set_mplsogre_encap_label_value,
13271                 (void *)&cmd_set_mplsogre_encap_ip_src,
13272                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13273                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13274                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13275                 (void *)&cmd_set_mplsogre_encap_eth_src,
13276                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13277                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13278                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13279                 NULL,
13280         },
13281 };
13282
13283 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13284         .f = cmd_set_mplsogre_encap_parsed,
13285         .data = NULL,
13286         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13287                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13288                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13289         .tokens = {
13290                 (void *)&cmd_set_mplsogre_encap_set,
13291                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13292                 (void *)&cmd_set_mplsogre_encap_ip_version,
13293                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13294                 (void *)&cmd_set_mplsogre_encap_label,
13295                 (void *)&cmd_set_mplsogre_encap_label_value,
13296                 (void *)&cmd_set_mplsogre_encap_ip_src,
13297                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13298                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13299                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13300                 (void *)&cmd_set_mplsogre_encap_vlan,
13301                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13302                 (void *)&cmd_set_mplsogre_encap_eth_src,
13303                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13304                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13305                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13306                 NULL,
13307         },
13308 };
13309
13310 /** Set MPLSoGRE decapsulation details */
13311 struct cmd_set_mplsogre_decap_result {
13312         cmdline_fixed_string_t set;
13313         cmdline_fixed_string_t mplsogre;
13314         cmdline_fixed_string_t pos_token;
13315         cmdline_fixed_string_t ip_version;
13316         uint32_t vlan_present:1;
13317 };
13318
13319 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13320         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13321                                  "set");
13322 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13323         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13324                                  "mplsogre_decap");
13325 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13326         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13327                                  mplsogre, "mplsogre_decap-with-vlan");
13328 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13329         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13330                                  pos_token, "ip-version");
13331 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13332         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13333                                  ip_version, "ipv4#ipv6");
13334
13335 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13336         __rte_unused struct cmdline *cl,
13337         __rte_unused void *data)
13338 {
13339         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13340
13341         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13342                 mplsogre_decap_conf.select_vlan = 0;
13343         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13344                 mplsogre_decap_conf.select_vlan = 1;
13345         if (strcmp(res->ip_version, "ipv4") == 0)
13346                 mplsogre_decap_conf.select_ipv4 = 1;
13347         else if (strcmp(res->ip_version, "ipv6") == 0)
13348                 mplsogre_decap_conf.select_ipv4 = 0;
13349 }
13350
13351 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13352         .f = cmd_set_mplsogre_decap_parsed,
13353         .data = NULL,
13354         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13355         .tokens = {
13356                 (void *)&cmd_set_mplsogre_decap_set,
13357                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13358                 (void *)&cmd_set_mplsogre_decap_ip_version,
13359                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13360                 NULL,
13361         },
13362 };
13363
13364 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13365         .f = cmd_set_mplsogre_decap_parsed,
13366         .data = NULL,
13367         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13368         .tokens = {
13369                 (void *)&cmd_set_mplsogre_decap_set,
13370                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13371                 (void *)&cmd_set_mplsogre_decap_ip_version,
13372                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13373                 NULL,
13374         },
13375 };
13376
13377 /** Set MPLSoUDP encapsulation details */
13378 struct cmd_set_mplsoudp_encap_result {
13379         cmdline_fixed_string_t set;
13380         cmdline_fixed_string_t mplsoudp;
13381         cmdline_fixed_string_t pos_token;
13382         cmdline_fixed_string_t ip_version;
13383         uint32_t vlan_present:1;
13384         uint32_t label;
13385         uint16_t udp_src;
13386         uint16_t udp_dst;
13387         cmdline_ipaddr_t ip_src;
13388         cmdline_ipaddr_t ip_dst;
13389         uint16_t tci;
13390         struct rte_ether_addr eth_src;
13391         struct rte_ether_addr eth_dst;
13392 };
13393
13394 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13395         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13396                                  "set");
13397 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13398         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13399                                  "mplsoudp_encap");
13400 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13401         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13402                                  mplsoudp, "mplsoudp_encap-with-vlan");
13403 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13404         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13405                                  pos_token, "ip-version");
13406 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13407         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13408                                  ip_version, "ipv4#ipv6");
13409 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13410         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13411                                  pos_token, "label");
13412 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13413         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13414                               RTE_UINT32);
13415 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13416         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13417                                  pos_token, "udp-src");
13418 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13419         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13420                               RTE_UINT16);
13421 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13422         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13423                                  pos_token, "udp-dst");
13424 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13425         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13426                               RTE_UINT16);
13427 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13428         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13429                                  pos_token, "ip-src");
13430 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13431         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13432 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13433         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13434                                  pos_token, "ip-dst");
13435 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13436         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13437 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13438         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13439                                  pos_token, "vlan-tci");
13440 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13441         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13442                               RTE_UINT16);
13443 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13444         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13445                                  pos_token, "eth-src");
13446 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13447         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13448                                     eth_src);
13449 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13450         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13451                                  pos_token, "eth-dst");
13452 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13453         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13454                                     eth_dst);
13455
13456 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13457         __rte_unused struct cmdline *cl,
13458         __rte_unused void *data)
13459 {
13460         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13461         union {
13462                 uint32_t mplsoudp_label;
13463                 uint8_t label[4];
13464         } id = {
13465                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13466         };
13467
13468         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13469                 mplsoudp_encap_conf.select_vlan = 0;
13470         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13471                 mplsoudp_encap_conf.select_vlan = 1;
13472         if (strcmp(res->ip_version, "ipv4") == 0)
13473                 mplsoudp_encap_conf.select_ipv4 = 1;
13474         else if (strcmp(res->ip_version, "ipv6") == 0)
13475                 mplsoudp_encap_conf.select_ipv4 = 0;
13476         else
13477                 return;
13478         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13479         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13480         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13481         if (mplsoudp_encap_conf.select_ipv4) {
13482                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13483                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13484         } else {
13485                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13486                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13487         }
13488         if (mplsoudp_encap_conf.select_vlan)
13489                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13490         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13491                    RTE_ETHER_ADDR_LEN);
13492         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13493                    RTE_ETHER_ADDR_LEN);
13494 }
13495
13496 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13497         .f = cmd_set_mplsoudp_encap_parsed,
13498         .data = NULL,
13499         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13500                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13501                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13502         .tokens = {
13503                 (void *)&cmd_set_mplsoudp_encap_set,
13504                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13505                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13506                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13507                 (void *)&cmd_set_mplsoudp_encap_label,
13508                 (void *)&cmd_set_mplsoudp_encap_label_value,
13509                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13510                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13511                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13512                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13513                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13514                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13515                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13516                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13517                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13518                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13519                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13520                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13521                 NULL,
13522         },
13523 };
13524
13525 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13526         .f = cmd_set_mplsoudp_encap_parsed,
13527         .data = NULL,
13528         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13529                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13530                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13531                 " eth-src <eth-src> eth-dst <eth-dst>",
13532         .tokens = {
13533                 (void *)&cmd_set_mplsoudp_encap_set,
13534                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13535                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13536                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13537                 (void *)&cmd_set_mplsoudp_encap_label,
13538                 (void *)&cmd_set_mplsoudp_encap_label_value,
13539                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13540                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13541                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13542                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13543                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13544                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13545                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13546                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13547                 (void *)&cmd_set_mplsoudp_encap_vlan,
13548                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13549                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13550                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13551                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13552                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13553                 NULL,
13554         },
13555 };
13556
13557 /** Set MPLSoUDP decapsulation details */
13558 struct cmd_set_mplsoudp_decap_result {
13559         cmdline_fixed_string_t set;
13560         cmdline_fixed_string_t mplsoudp;
13561         cmdline_fixed_string_t pos_token;
13562         cmdline_fixed_string_t ip_version;
13563         uint32_t vlan_present:1;
13564 };
13565
13566 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13567         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13568                                  "set");
13569 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13570         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13571                                  "mplsoudp_decap");
13572 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13573         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13574                                  mplsoudp, "mplsoudp_decap-with-vlan");
13575 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13576         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13577                                  pos_token, "ip-version");
13578 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13579         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13580                                  ip_version, "ipv4#ipv6");
13581
13582 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13583         __rte_unused struct cmdline *cl,
13584         __rte_unused void *data)
13585 {
13586         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13587
13588         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13589                 mplsoudp_decap_conf.select_vlan = 0;
13590         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13591                 mplsoudp_decap_conf.select_vlan = 1;
13592         if (strcmp(res->ip_version, "ipv4") == 0)
13593                 mplsoudp_decap_conf.select_ipv4 = 1;
13594         else if (strcmp(res->ip_version, "ipv6") == 0)
13595                 mplsoudp_decap_conf.select_ipv4 = 0;
13596 }
13597
13598 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13599         .f = cmd_set_mplsoudp_decap_parsed,
13600         .data = NULL,
13601         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13602         .tokens = {
13603                 (void *)&cmd_set_mplsoudp_decap_set,
13604                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13605                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13606                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13607                 NULL,
13608         },
13609 };
13610
13611 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13612         .f = cmd_set_mplsoudp_decap_parsed,
13613         .data = NULL,
13614         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13615         .tokens = {
13616                 (void *)&cmd_set_mplsoudp_decap_set,
13617                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13618                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13619                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13620                 NULL,
13621         },
13622 };
13623
13624 /* Strict link priority scheduling mode setting */
13625 static void
13626 cmd_strict_link_prio_parsed(
13627         void *parsed_result,
13628         __rte_unused struct cmdline *cl,
13629         __rte_unused void *data)
13630 {
13631         struct cmd_vf_tc_bw_result *res = parsed_result;
13632         int ret = -ENOTSUP;
13633
13634         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13635                 return;
13636
13637 #ifdef RTE_NET_I40E
13638         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13639 #endif
13640
13641         switch (ret) {
13642         case 0:
13643                 break;
13644         case -EINVAL:
13645                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13646                 break;
13647         case -ENODEV:
13648                 printf("invalid port_id %d\n", res->port_id);
13649                 break;
13650         case -ENOTSUP:
13651                 printf("function not implemented\n");
13652                 break;
13653         default:
13654                 printf("programming error: (%s)\n", strerror(-ret));
13655         }
13656 }
13657
13658 cmdline_parse_inst_t cmd_strict_link_prio = {
13659         .f = cmd_strict_link_prio_parsed,
13660         .data = NULL,
13661         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13662         .tokens = {
13663                 (void *)&cmd_vf_tc_bw_set,
13664                 (void *)&cmd_vf_tc_bw_tx,
13665                 (void *)&cmd_vf_tc_bw_strict_link_prio,
13666                 (void *)&cmd_vf_tc_bw_port_id,
13667                 (void *)&cmd_vf_tc_bw_tc_map,
13668                 NULL,
13669         },
13670 };
13671
13672 /* Load dynamic device personalization*/
13673 struct cmd_ddp_add_result {
13674         cmdline_fixed_string_t ddp;
13675         cmdline_fixed_string_t add;
13676         portid_t port_id;
13677         char filepath[];
13678 };
13679
13680 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13681         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13682 cmdline_parse_token_string_t cmd_ddp_add_add =
13683         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13684 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13685         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
13686                 RTE_UINT16);
13687 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13688         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13689
13690 static void
13691 cmd_ddp_add_parsed(
13692         void *parsed_result,
13693         __rte_unused struct cmdline *cl,
13694         __rte_unused void *data)
13695 {
13696         struct cmd_ddp_add_result *res = parsed_result;
13697         uint8_t *buff;
13698         uint32_t size;
13699         char *filepath;
13700         char *file_fld[2];
13701         int file_num;
13702         int ret = -ENOTSUP;
13703
13704         if (!all_ports_stopped()) {
13705                 printf("Please stop all ports first\n");
13706                 return;
13707         }
13708
13709         filepath = strdup(res->filepath);
13710         if (filepath == NULL) {
13711                 printf("Failed to allocate memory\n");
13712                 return;
13713         }
13714         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13715
13716         buff = open_file(file_fld[0], &size);
13717         if (!buff) {
13718                 free((void *)filepath);
13719                 return;
13720         }
13721
13722 #ifdef RTE_NET_I40E
13723         if (ret == -ENOTSUP)
13724                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13725                                                buff, size,
13726                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
13727 #endif
13728
13729         if (ret == -EEXIST)
13730                 printf("Profile has already existed.\n");
13731         else if (ret < 0)
13732                 printf("Failed to load profile.\n");
13733         else if (file_num == 2)
13734                 save_file(file_fld[1], buff, size);
13735
13736         close_file(buff);
13737         free((void *)filepath);
13738 }
13739
13740 cmdline_parse_inst_t cmd_ddp_add = {
13741         .f = cmd_ddp_add_parsed,
13742         .data = NULL,
13743         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
13744         .tokens = {
13745                 (void *)&cmd_ddp_add_ddp,
13746                 (void *)&cmd_ddp_add_add,
13747                 (void *)&cmd_ddp_add_port_id,
13748                 (void *)&cmd_ddp_add_filepath,
13749                 NULL,
13750         },
13751 };
13752
13753 /* Delete dynamic device personalization*/
13754 struct cmd_ddp_del_result {
13755         cmdline_fixed_string_t ddp;
13756         cmdline_fixed_string_t del;
13757         portid_t port_id;
13758         char filepath[];
13759 };
13760
13761 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13762         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13763 cmdline_parse_token_string_t cmd_ddp_del_del =
13764         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13765 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13766         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
13767 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13768         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13769
13770 static void
13771 cmd_ddp_del_parsed(
13772         void *parsed_result,
13773         __rte_unused struct cmdline *cl,
13774         __rte_unused void *data)
13775 {
13776         struct cmd_ddp_del_result *res = parsed_result;
13777         uint8_t *buff;
13778         uint32_t size;
13779         int ret = -ENOTSUP;
13780
13781         if (!all_ports_stopped()) {
13782                 printf("Please stop all ports first\n");
13783                 return;
13784         }
13785
13786         buff = open_file(res->filepath, &size);
13787         if (!buff)
13788                 return;
13789
13790 #ifdef RTE_NET_I40E
13791         if (ret == -ENOTSUP)
13792                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13793                                                buff, size,
13794                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
13795 #endif
13796
13797         if (ret == -EACCES)
13798                 printf("Profile does not exist.\n");
13799         else if (ret < 0)
13800                 printf("Failed to delete profile.\n");
13801
13802         close_file(buff);
13803 }
13804
13805 cmdline_parse_inst_t cmd_ddp_del = {
13806         .f = cmd_ddp_del_parsed,
13807         .data = NULL,
13808         .help_str = "ddp del <port_id> <backup_profile_path>",
13809         .tokens = {
13810                 (void *)&cmd_ddp_del_ddp,
13811                 (void *)&cmd_ddp_del_del,
13812                 (void *)&cmd_ddp_del_port_id,
13813                 (void *)&cmd_ddp_del_filepath,
13814                 NULL,
13815         },
13816 };
13817
13818 /* Get dynamic device personalization profile info */
13819 struct cmd_ddp_info_result {
13820         cmdline_fixed_string_t ddp;
13821         cmdline_fixed_string_t get;
13822         cmdline_fixed_string_t info;
13823         char filepath[];
13824 };
13825
13826 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13827         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13828 cmdline_parse_token_string_t cmd_ddp_info_get =
13829         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13830 cmdline_parse_token_string_t cmd_ddp_info_info =
13831         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13832 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13833         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13834
13835 static void
13836 cmd_ddp_info_parsed(
13837         void *parsed_result,
13838         __rte_unused struct cmdline *cl,
13839         __rte_unused void *data)
13840 {
13841         struct cmd_ddp_info_result *res = parsed_result;
13842         uint8_t *pkg;
13843         uint32_t pkg_size;
13844         int ret = -ENOTSUP;
13845 #ifdef RTE_NET_I40E
13846         uint32_t i, j, n;
13847         uint8_t *buff;
13848         uint32_t buff_size = 0;
13849         struct rte_pmd_i40e_profile_info info;
13850         uint32_t dev_num = 0;
13851         struct rte_pmd_i40e_ddp_device_id *devs;
13852         uint32_t proto_num = 0;
13853         struct rte_pmd_i40e_proto_info *proto = NULL;
13854         uint32_t pctype_num = 0;
13855         struct rte_pmd_i40e_ptype_info *pctype;
13856         uint32_t ptype_num = 0;
13857         struct rte_pmd_i40e_ptype_info *ptype;
13858         uint8_t proto_id;
13859
13860 #endif
13861
13862         pkg = open_file(res->filepath, &pkg_size);
13863         if (!pkg)
13864                 return;
13865
13866 #ifdef RTE_NET_I40E
13867         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13868                                 (uint8_t *)&info, sizeof(info),
13869                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13870         if (!ret) {
13871                 printf("Global Track id:       0x%x\n", info.track_id);
13872                 printf("Global Version:        %d.%d.%d.%d\n",
13873                         info.version.major,
13874                         info.version.minor,
13875                         info.version.update,
13876                         info.version.draft);
13877                 printf("Global Package name:   %s\n\n", info.name);
13878         }
13879
13880         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13881                                 (uint8_t *)&info, sizeof(info),
13882                                 RTE_PMD_I40E_PKG_INFO_HEADER);
13883         if (!ret) {
13884                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
13885                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
13886                         info.version.major,
13887                         info.version.minor,
13888                         info.version.update,
13889                         info.version.draft);
13890                 printf("i40e Profile name:     %s\n\n", info.name);
13891         }
13892
13893         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13894                                 (uint8_t *)&buff_size, sizeof(buff_size),
13895                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13896         if (!ret && buff_size) {
13897                 buff = (uint8_t *)malloc(buff_size);
13898                 if (buff) {
13899                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13900                                                 buff, buff_size,
13901                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13902                         if (!ret)
13903                                 printf("Package Notes:\n%s\n\n", buff);
13904                         free(buff);
13905                 }
13906         }
13907
13908         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13909                                 (uint8_t *)&dev_num, sizeof(dev_num),
13910                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13911         if (!ret && dev_num) {
13912                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13913                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13914                 if (devs) {
13915                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13916                                                 (uint8_t *)devs, buff_size,
13917                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13918                         if (!ret) {
13919                                 printf("List of supported devices:\n");
13920                                 for (i = 0; i < dev_num; i++) {
13921                                         printf("  %04X:%04X %04X:%04X\n",
13922                                                 devs[i].vendor_dev_id >> 16,
13923                                                 devs[i].vendor_dev_id & 0xFFFF,
13924                                                 devs[i].sub_vendor_dev_id >> 16,
13925                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
13926                                 }
13927                                 printf("\n");
13928                         }
13929                         free(devs);
13930                 }
13931         }
13932
13933         /* get information about protocols and packet types */
13934         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13935                 (uint8_t *)&proto_num, sizeof(proto_num),
13936                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13937         if (ret || !proto_num)
13938                 goto no_print_return;
13939
13940         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13941         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13942         if (!proto)
13943                 goto no_print_return;
13944
13945         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13946                                         buff_size,
13947                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13948         if (!ret) {
13949                 printf("List of used protocols:\n");
13950                 for (i = 0; i < proto_num; i++)
13951                         printf("  %2u: %s\n", proto[i].proto_id,
13952                                proto[i].name);
13953                 printf("\n");
13954         }
13955         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13956                 (uint8_t *)&pctype_num, sizeof(pctype_num),
13957                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13958         if (ret || !pctype_num)
13959                 goto no_print_pctypes;
13960
13961         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13962         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13963         if (!pctype)
13964                 goto no_print_pctypes;
13965
13966         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13967                                         buff_size,
13968                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13969         if (ret) {
13970                 free(pctype);
13971                 goto no_print_pctypes;
13972         }
13973
13974         printf("List of defined packet classification types:\n");
13975         for (i = 0; i < pctype_num; i++) {
13976                 printf("  %2u:", pctype[i].ptype_id);
13977                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13978                         proto_id = pctype[i].protocols[j];
13979                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13980                                 for (n = 0; n < proto_num; n++) {
13981                                         if (proto[n].proto_id == proto_id) {
13982                                                 printf(" %s", proto[n].name);
13983                                                 break;
13984                                         }
13985                                 }
13986                         }
13987                 }
13988                 printf("\n");
13989         }
13990         printf("\n");
13991         free(pctype);
13992
13993 no_print_pctypes:
13994
13995         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13996                                         sizeof(ptype_num),
13997                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13998         if (ret || !ptype_num)
13999                 goto no_print_return;
14000
14001         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14002         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14003         if (!ptype)
14004                 goto no_print_return;
14005
14006         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14007                                         buff_size,
14008                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14009         if (ret) {
14010                 free(ptype);
14011                 goto no_print_return;
14012         }
14013         printf("List of defined packet types:\n");
14014         for (i = 0; i < ptype_num; i++) {
14015                 printf("  %2u:", ptype[i].ptype_id);
14016                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14017                         proto_id = ptype[i].protocols[j];
14018                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14019                                 for (n = 0; n < proto_num; n++) {
14020                                         if (proto[n].proto_id == proto_id) {
14021                                                 printf(" %s", proto[n].name);
14022                                                 break;
14023                                         }
14024                                 }
14025                         }
14026                 }
14027                 printf("\n");
14028         }
14029         free(ptype);
14030         printf("\n");
14031
14032         ret = 0;
14033 no_print_return:
14034         if (proto)
14035                 free(proto);
14036 #endif
14037         if (ret == -ENOTSUP)
14038                 printf("Function not supported in PMD driver\n");
14039         close_file(pkg);
14040 }
14041
14042 cmdline_parse_inst_t cmd_ddp_get_info = {
14043         .f = cmd_ddp_info_parsed,
14044         .data = NULL,
14045         .help_str = "ddp get info <profile_path>",
14046         .tokens = {
14047                 (void *)&cmd_ddp_info_ddp,
14048                 (void *)&cmd_ddp_info_get,
14049                 (void *)&cmd_ddp_info_info,
14050                 (void *)&cmd_ddp_info_filepath,
14051                 NULL,
14052         },
14053 };
14054
14055 /* Get dynamic device personalization profile info list*/
14056 #define PROFILE_INFO_SIZE 48
14057 #define MAX_PROFILE_NUM 16
14058
14059 struct cmd_ddp_get_list_result {
14060         cmdline_fixed_string_t ddp;
14061         cmdline_fixed_string_t get;
14062         cmdline_fixed_string_t list;
14063         portid_t port_id;
14064 };
14065
14066 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14067         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14068 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14069         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14070 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14071         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14072 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14073         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14074                 RTE_UINT16);
14075
14076 static void
14077 cmd_ddp_get_list_parsed(
14078         __rte_unused void *parsed_result,
14079         __rte_unused struct cmdline *cl,
14080         __rte_unused void *data)
14081 {
14082 #ifdef RTE_NET_I40E
14083         struct cmd_ddp_get_list_result *res = parsed_result;
14084         struct rte_pmd_i40e_profile_list *p_list;
14085         struct rte_pmd_i40e_profile_info *p_info;
14086         uint32_t p_num;
14087         uint32_t size;
14088         uint32_t i;
14089 #endif
14090         int ret = -ENOTSUP;
14091
14092 #ifdef RTE_NET_I40E
14093         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14094         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14095         if (!p_list) {
14096                 printf("%s: Failed to malloc buffer\n", __func__);
14097                 return;
14098         }
14099
14100         if (ret == -ENOTSUP)
14101                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14102                                                 (uint8_t *)p_list, size);
14103
14104         if (!ret) {
14105                 p_num = p_list->p_count;
14106                 printf("Profile number is: %d\n\n", p_num);
14107
14108                 for (i = 0; i < p_num; i++) {
14109                         p_info = &p_list->p_info[i];
14110                         printf("Profile %d:\n", i);
14111                         printf("Track id:     0x%x\n", p_info->track_id);
14112                         printf("Version:      %d.%d.%d.%d\n",
14113                                p_info->version.major,
14114                                p_info->version.minor,
14115                                p_info->version.update,
14116                                p_info->version.draft);
14117                         printf("Profile name: %s\n\n", p_info->name);
14118                 }
14119         }
14120
14121         free(p_list);
14122 #endif
14123
14124         if (ret < 0)
14125                 printf("Failed to get ddp list\n");
14126 }
14127
14128 cmdline_parse_inst_t cmd_ddp_get_list = {
14129         .f = cmd_ddp_get_list_parsed,
14130         .data = NULL,
14131         .help_str = "ddp get list <port_id>",
14132         .tokens = {
14133                 (void *)&cmd_ddp_get_list_ddp,
14134                 (void *)&cmd_ddp_get_list_get,
14135                 (void *)&cmd_ddp_get_list_list,
14136                 (void *)&cmd_ddp_get_list_port_id,
14137                 NULL,
14138         },
14139 };
14140
14141 /* Configure input set */
14142 struct cmd_cfg_input_set_result {
14143         cmdline_fixed_string_t port;
14144         cmdline_fixed_string_t cfg;
14145         portid_t port_id;
14146         cmdline_fixed_string_t pctype;
14147         uint8_t pctype_id;
14148         cmdline_fixed_string_t inset_type;
14149         cmdline_fixed_string_t opt;
14150         cmdline_fixed_string_t field;
14151         uint8_t field_idx;
14152 };
14153
14154 static void
14155 cmd_cfg_input_set_parsed(
14156         __rte_unused void *parsed_result,
14157         __rte_unused struct cmdline *cl,
14158         __rte_unused void *data)
14159 {
14160 #ifdef RTE_NET_I40E
14161         struct cmd_cfg_input_set_result *res = parsed_result;
14162         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14163         struct rte_pmd_i40e_inset inset;
14164 #endif
14165         int ret = -ENOTSUP;
14166
14167         if (!all_ports_stopped()) {
14168                 printf("Please stop all ports first\n");
14169                 return;
14170         }
14171
14172 #ifdef RTE_NET_I40E
14173         if (!strcmp(res->inset_type, "hash_inset"))
14174                 inset_type = INSET_HASH;
14175         else if (!strcmp(res->inset_type, "fdir_inset"))
14176                 inset_type = INSET_FDIR;
14177         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14178                 inset_type = INSET_FDIR_FLX;
14179         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14180                                      &inset, inset_type);
14181         if (ret) {
14182                 printf("Failed to get input set.\n");
14183                 return;
14184         }
14185
14186         if (!strcmp(res->opt, "get")) {
14187                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14188                                                    res->field_idx);
14189                 if (ret)
14190                         printf("Field index %d is enabled.\n", res->field_idx);
14191                 else
14192                         printf("Field index %d is disabled.\n", res->field_idx);
14193                 return;
14194         } else if (!strcmp(res->opt, "set"))
14195                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14196                                                    res->field_idx);
14197         else if (!strcmp(res->opt, "clear"))
14198                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14199                                                      res->field_idx);
14200         if (ret) {
14201                 printf("Failed to configure input set field.\n");
14202                 return;
14203         }
14204
14205         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14206                                      &inset, inset_type);
14207         if (ret) {
14208                 printf("Failed to set input set.\n");
14209                 return;
14210         }
14211 #endif
14212
14213         if (ret == -ENOTSUP)
14214                 printf("Function not supported\n");
14215 }
14216
14217 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14218         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14219                                  port, "port");
14220 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14221         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14222                                  cfg, "config");
14223 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14224         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14225                               port_id, RTE_UINT16);
14226 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14227         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14228                                  pctype, "pctype");
14229 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14230         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14231                               pctype_id, RTE_UINT8);
14232 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14233         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14234                                  inset_type,
14235                                  "hash_inset#fdir_inset#fdir_flx_inset");
14236 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14237         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14238                                  opt, "get#set#clear");
14239 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14240         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14241                                  field, "field");
14242 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14243         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14244                               field_idx, RTE_UINT8);
14245
14246 cmdline_parse_inst_t cmd_cfg_input_set = {
14247         .f = cmd_cfg_input_set_parsed,
14248         .data = NULL,
14249         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14250                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14251         .tokens = {
14252                 (void *)&cmd_cfg_input_set_port,
14253                 (void *)&cmd_cfg_input_set_cfg,
14254                 (void *)&cmd_cfg_input_set_port_id,
14255                 (void *)&cmd_cfg_input_set_pctype,
14256                 (void *)&cmd_cfg_input_set_pctype_id,
14257                 (void *)&cmd_cfg_input_set_inset_type,
14258                 (void *)&cmd_cfg_input_set_opt,
14259                 (void *)&cmd_cfg_input_set_field,
14260                 (void *)&cmd_cfg_input_set_field_idx,
14261                 NULL,
14262         },
14263 };
14264
14265 /* Clear input set */
14266 struct cmd_clear_input_set_result {
14267         cmdline_fixed_string_t port;
14268         cmdline_fixed_string_t cfg;
14269         portid_t port_id;
14270         cmdline_fixed_string_t pctype;
14271         uint8_t pctype_id;
14272         cmdline_fixed_string_t inset_type;
14273         cmdline_fixed_string_t clear;
14274         cmdline_fixed_string_t all;
14275 };
14276
14277 static void
14278 cmd_clear_input_set_parsed(
14279         __rte_unused void *parsed_result,
14280         __rte_unused struct cmdline *cl,
14281         __rte_unused void *data)
14282 {
14283 #ifdef RTE_NET_I40E
14284         struct cmd_clear_input_set_result *res = parsed_result;
14285         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14286         struct rte_pmd_i40e_inset inset;
14287 #endif
14288         int ret = -ENOTSUP;
14289
14290         if (!all_ports_stopped()) {
14291                 printf("Please stop all ports first\n");
14292                 return;
14293         }
14294
14295 #ifdef RTE_NET_I40E
14296         if (!strcmp(res->inset_type, "hash_inset"))
14297                 inset_type = INSET_HASH;
14298         else if (!strcmp(res->inset_type, "fdir_inset"))
14299                 inset_type = INSET_FDIR;
14300         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14301                 inset_type = INSET_FDIR_FLX;
14302
14303         memset(&inset, 0, sizeof(inset));
14304
14305         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14306                                      &inset, inset_type);
14307         if (ret) {
14308                 printf("Failed to clear input set.\n");
14309                 return;
14310         }
14311
14312 #endif
14313
14314         if (ret == -ENOTSUP)
14315                 printf("Function not supported\n");
14316 }
14317
14318 cmdline_parse_token_string_t cmd_clear_input_set_port =
14319         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14320                                  port, "port");
14321 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14322         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14323                                  cfg, "config");
14324 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14325         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14326                               port_id, RTE_UINT16);
14327 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14328         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14329                                  pctype, "pctype");
14330 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14331         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14332                               pctype_id, RTE_UINT8);
14333 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14334         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14335                                  inset_type,
14336                                  "hash_inset#fdir_inset#fdir_flx_inset");
14337 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14338         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14339                                  clear, "clear");
14340 cmdline_parse_token_string_t cmd_clear_input_set_all =
14341         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14342                                  all, "all");
14343
14344 cmdline_parse_inst_t cmd_clear_input_set = {
14345         .f = cmd_clear_input_set_parsed,
14346         .data = NULL,
14347         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14348                     "fdir_inset|fdir_flx_inset clear all",
14349         .tokens = {
14350                 (void *)&cmd_clear_input_set_port,
14351                 (void *)&cmd_clear_input_set_cfg,
14352                 (void *)&cmd_clear_input_set_port_id,
14353                 (void *)&cmd_clear_input_set_pctype,
14354                 (void *)&cmd_clear_input_set_pctype_id,
14355                 (void *)&cmd_clear_input_set_inset_type,
14356                 (void *)&cmd_clear_input_set_clear,
14357                 (void *)&cmd_clear_input_set_all,
14358                 NULL,
14359         },
14360 };
14361
14362 /* show vf stats */
14363
14364 /* Common result structure for show vf stats */
14365 struct cmd_show_vf_stats_result {
14366         cmdline_fixed_string_t show;
14367         cmdline_fixed_string_t vf;
14368         cmdline_fixed_string_t stats;
14369         portid_t port_id;
14370         uint16_t vf_id;
14371 };
14372
14373 /* Common CLI fields show vf stats*/
14374 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14375         TOKEN_STRING_INITIALIZER
14376                 (struct cmd_show_vf_stats_result,
14377                  show, "show");
14378 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14379         TOKEN_STRING_INITIALIZER
14380                 (struct cmd_show_vf_stats_result,
14381                  vf, "vf");
14382 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14383         TOKEN_STRING_INITIALIZER
14384                 (struct cmd_show_vf_stats_result,
14385                  stats, "stats");
14386 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14387         TOKEN_NUM_INITIALIZER
14388                 (struct cmd_show_vf_stats_result,
14389                  port_id, RTE_UINT16);
14390 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14391         TOKEN_NUM_INITIALIZER
14392                 (struct cmd_show_vf_stats_result,
14393                  vf_id, RTE_UINT16);
14394
14395 static void
14396 cmd_show_vf_stats_parsed(
14397         void *parsed_result,
14398         __rte_unused struct cmdline *cl,
14399         __rte_unused void *data)
14400 {
14401         struct cmd_show_vf_stats_result *res = parsed_result;
14402         struct rte_eth_stats stats;
14403         int ret = -ENOTSUP;
14404         static const char *nic_stats_border = "########################";
14405
14406         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14407                 return;
14408
14409         memset(&stats, 0, sizeof(stats));
14410
14411 #ifdef RTE_NET_I40E
14412         if (ret == -ENOTSUP)
14413                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14414                                                 res->vf_id,
14415                                                 &stats);
14416 #endif
14417 #ifdef RTE_NET_BNXT
14418         if (ret == -ENOTSUP)
14419                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14420                                                 res->vf_id,
14421                                                 &stats);
14422 #endif
14423
14424         switch (ret) {
14425         case 0:
14426                 break;
14427         case -EINVAL:
14428                 printf("invalid vf_id %d\n", res->vf_id);
14429                 break;
14430         case -ENODEV:
14431                 printf("invalid port_id %d\n", res->port_id);
14432                 break;
14433         case -ENOTSUP:
14434                 printf("function not implemented\n");
14435                 break;
14436         default:
14437                 printf("programming error: (%s)\n", strerror(-ret));
14438         }
14439
14440         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14441                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14442
14443         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14444                "%-"PRIu64"\n",
14445                stats.ipackets, stats.imissed, stats.ibytes);
14446         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14447         printf("  RX-nombuf:  %-10"PRIu64"\n",
14448                stats.rx_nombuf);
14449         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14450                "%-"PRIu64"\n",
14451                stats.opackets, stats.oerrors, stats.obytes);
14452
14453         printf("  %s############################%s\n",
14454                                nic_stats_border, nic_stats_border);
14455 }
14456
14457 cmdline_parse_inst_t cmd_show_vf_stats = {
14458         .f = cmd_show_vf_stats_parsed,
14459         .data = NULL,
14460         .help_str = "show vf stats <port_id> <vf_id>",
14461         .tokens = {
14462                 (void *)&cmd_show_vf_stats_show,
14463                 (void *)&cmd_show_vf_stats_vf,
14464                 (void *)&cmd_show_vf_stats_stats,
14465                 (void *)&cmd_show_vf_stats_port_id,
14466                 (void *)&cmd_show_vf_stats_vf_id,
14467                 NULL,
14468         },
14469 };
14470
14471 /* clear vf stats */
14472
14473 /* Common result structure for clear vf stats */
14474 struct cmd_clear_vf_stats_result {
14475         cmdline_fixed_string_t clear;
14476         cmdline_fixed_string_t vf;
14477         cmdline_fixed_string_t stats;
14478         portid_t port_id;
14479         uint16_t vf_id;
14480 };
14481
14482 /* Common CLI fields clear vf stats*/
14483 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14484         TOKEN_STRING_INITIALIZER
14485                 (struct cmd_clear_vf_stats_result,
14486                  clear, "clear");
14487 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14488         TOKEN_STRING_INITIALIZER
14489                 (struct cmd_clear_vf_stats_result,
14490                  vf, "vf");
14491 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14492         TOKEN_STRING_INITIALIZER
14493                 (struct cmd_clear_vf_stats_result,
14494                  stats, "stats");
14495 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14496         TOKEN_NUM_INITIALIZER
14497                 (struct cmd_clear_vf_stats_result,
14498                  port_id, RTE_UINT16);
14499 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14500         TOKEN_NUM_INITIALIZER
14501                 (struct cmd_clear_vf_stats_result,
14502                  vf_id, RTE_UINT16);
14503
14504 static void
14505 cmd_clear_vf_stats_parsed(
14506         void *parsed_result,
14507         __rte_unused struct cmdline *cl,
14508         __rte_unused void *data)
14509 {
14510         struct cmd_clear_vf_stats_result *res = parsed_result;
14511         int ret = -ENOTSUP;
14512
14513         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14514                 return;
14515
14516 #ifdef RTE_NET_I40E
14517         if (ret == -ENOTSUP)
14518                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14519                                                   res->vf_id);
14520 #endif
14521 #ifdef RTE_NET_BNXT
14522         if (ret == -ENOTSUP)
14523                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14524                                                   res->vf_id);
14525 #endif
14526
14527         switch (ret) {
14528         case 0:
14529                 break;
14530         case -EINVAL:
14531                 printf("invalid vf_id %d\n", res->vf_id);
14532                 break;
14533         case -ENODEV:
14534                 printf("invalid port_id %d\n", res->port_id);
14535                 break;
14536         case -ENOTSUP:
14537                 printf("function not implemented\n");
14538                 break;
14539         default:
14540                 printf("programming error: (%s)\n", strerror(-ret));
14541         }
14542 }
14543
14544 cmdline_parse_inst_t cmd_clear_vf_stats = {
14545         .f = cmd_clear_vf_stats_parsed,
14546         .data = NULL,
14547         .help_str = "clear vf stats <port_id> <vf_id>",
14548         .tokens = {
14549                 (void *)&cmd_clear_vf_stats_clear,
14550                 (void *)&cmd_clear_vf_stats_vf,
14551                 (void *)&cmd_clear_vf_stats_stats,
14552                 (void *)&cmd_clear_vf_stats_port_id,
14553                 (void *)&cmd_clear_vf_stats_vf_id,
14554                 NULL,
14555         },
14556 };
14557
14558 /* port config pctype mapping reset */
14559
14560 /* Common result structure for port config pctype mapping reset */
14561 struct cmd_pctype_mapping_reset_result {
14562         cmdline_fixed_string_t port;
14563         cmdline_fixed_string_t config;
14564         portid_t port_id;
14565         cmdline_fixed_string_t pctype;
14566         cmdline_fixed_string_t mapping;
14567         cmdline_fixed_string_t reset;
14568 };
14569
14570 /* Common CLI fields for port config pctype mapping reset*/
14571 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14572         TOKEN_STRING_INITIALIZER
14573                 (struct cmd_pctype_mapping_reset_result,
14574                  port, "port");
14575 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14576         TOKEN_STRING_INITIALIZER
14577                 (struct cmd_pctype_mapping_reset_result,
14578                  config, "config");
14579 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14580         TOKEN_NUM_INITIALIZER
14581                 (struct cmd_pctype_mapping_reset_result,
14582                  port_id, RTE_UINT16);
14583 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14584         TOKEN_STRING_INITIALIZER
14585                 (struct cmd_pctype_mapping_reset_result,
14586                  pctype, "pctype");
14587 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14588         TOKEN_STRING_INITIALIZER
14589                 (struct cmd_pctype_mapping_reset_result,
14590                  mapping, "mapping");
14591 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14592         TOKEN_STRING_INITIALIZER
14593                 (struct cmd_pctype_mapping_reset_result,
14594                  reset, "reset");
14595
14596 static void
14597 cmd_pctype_mapping_reset_parsed(
14598         void *parsed_result,
14599         __rte_unused struct cmdline *cl,
14600         __rte_unused void *data)
14601 {
14602         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14603         int ret = -ENOTSUP;
14604
14605         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14606                 return;
14607
14608 #ifdef RTE_NET_I40E
14609         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14610 #endif
14611
14612         switch (ret) {
14613         case 0:
14614                 break;
14615         case -ENODEV:
14616                 printf("invalid port_id %d\n", res->port_id);
14617                 break;
14618         case -ENOTSUP:
14619                 printf("function not implemented\n");
14620                 break;
14621         default:
14622                 printf("programming error: (%s)\n", strerror(-ret));
14623         }
14624 }
14625
14626 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14627         .f = cmd_pctype_mapping_reset_parsed,
14628         .data = NULL,
14629         .help_str = "port config <port_id> pctype mapping reset",
14630         .tokens = {
14631                 (void *)&cmd_pctype_mapping_reset_port,
14632                 (void *)&cmd_pctype_mapping_reset_config,
14633                 (void *)&cmd_pctype_mapping_reset_port_id,
14634                 (void *)&cmd_pctype_mapping_reset_pctype,
14635                 (void *)&cmd_pctype_mapping_reset_mapping,
14636                 (void *)&cmd_pctype_mapping_reset_reset,
14637                 NULL,
14638         },
14639 };
14640
14641 /* show port pctype mapping */
14642
14643 /* Common result structure for show port pctype mapping */
14644 struct cmd_pctype_mapping_get_result {
14645         cmdline_fixed_string_t show;
14646         cmdline_fixed_string_t port;
14647         portid_t port_id;
14648         cmdline_fixed_string_t pctype;
14649         cmdline_fixed_string_t mapping;
14650 };
14651
14652 /* Common CLI fields for pctype mapping get */
14653 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14654         TOKEN_STRING_INITIALIZER
14655                 (struct cmd_pctype_mapping_get_result,
14656                  show, "show");
14657 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14658         TOKEN_STRING_INITIALIZER
14659                 (struct cmd_pctype_mapping_get_result,
14660                  port, "port");
14661 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14662         TOKEN_NUM_INITIALIZER
14663                 (struct cmd_pctype_mapping_get_result,
14664                  port_id, RTE_UINT16);
14665 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14666         TOKEN_STRING_INITIALIZER
14667                 (struct cmd_pctype_mapping_get_result,
14668                  pctype, "pctype");
14669 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14670         TOKEN_STRING_INITIALIZER
14671                 (struct cmd_pctype_mapping_get_result,
14672                  mapping, "mapping");
14673
14674 static void
14675 cmd_pctype_mapping_get_parsed(
14676         void *parsed_result,
14677         __rte_unused struct cmdline *cl,
14678         __rte_unused void *data)
14679 {
14680         struct cmd_pctype_mapping_get_result *res = parsed_result;
14681         int ret = -ENOTSUP;
14682 #ifdef RTE_NET_I40E
14683         struct rte_pmd_i40e_flow_type_mapping
14684                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14685         int i, j, first_pctype;
14686 #endif
14687
14688         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14689                 return;
14690
14691 #ifdef RTE_NET_I40E
14692         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14693 #endif
14694
14695         switch (ret) {
14696         case 0:
14697                 break;
14698         case -ENODEV:
14699                 printf("invalid port_id %d\n", res->port_id);
14700                 return;
14701         case -ENOTSUP:
14702                 printf("function not implemented\n");
14703                 return;
14704         default:
14705                 printf("programming error: (%s)\n", strerror(-ret));
14706                 return;
14707         }
14708
14709 #ifdef RTE_NET_I40E
14710         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14711                 if (mapping[i].pctype != 0ULL) {
14712                         first_pctype = 1;
14713
14714                         printf("pctype: ");
14715                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14716                                 if (mapping[i].pctype & (1ULL << j)) {
14717                                         printf(first_pctype ?
14718                                                "%02d" : ",%02d", j);
14719                                         first_pctype = 0;
14720                                 }
14721                         }
14722                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14723                 }
14724         }
14725 #endif
14726 }
14727
14728 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14729         .f = cmd_pctype_mapping_get_parsed,
14730         .data = NULL,
14731         .help_str = "show port <port_id> pctype mapping",
14732         .tokens = {
14733                 (void *)&cmd_pctype_mapping_get_show,
14734                 (void *)&cmd_pctype_mapping_get_port,
14735                 (void *)&cmd_pctype_mapping_get_port_id,
14736                 (void *)&cmd_pctype_mapping_get_pctype,
14737                 (void *)&cmd_pctype_mapping_get_mapping,
14738                 NULL,
14739         },
14740 };
14741
14742 /* port config pctype mapping update */
14743
14744 /* Common result structure for port config pctype mapping update */
14745 struct cmd_pctype_mapping_update_result {
14746         cmdline_fixed_string_t port;
14747         cmdline_fixed_string_t config;
14748         portid_t port_id;
14749         cmdline_fixed_string_t pctype;
14750         cmdline_fixed_string_t mapping;
14751         cmdline_fixed_string_t update;
14752         cmdline_fixed_string_t pctype_list;
14753         uint16_t flow_type;
14754 };
14755
14756 /* Common CLI fields for pctype mapping update*/
14757 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14758         TOKEN_STRING_INITIALIZER
14759                 (struct cmd_pctype_mapping_update_result,
14760                  port, "port");
14761 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14762         TOKEN_STRING_INITIALIZER
14763                 (struct cmd_pctype_mapping_update_result,
14764                  config, "config");
14765 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14766         TOKEN_NUM_INITIALIZER
14767                 (struct cmd_pctype_mapping_update_result,
14768                  port_id, RTE_UINT16);
14769 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14770         TOKEN_STRING_INITIALIZER
14771                 (struct cmd_pctype_mapping_update_result,
14772                  pctype, "pctype");
14773 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14774         TOKEN_STRING_INITIALIZER
14775                 (struct cmd_pctype_mapping_update_result,
14776                  mapping, "mapping");
14777 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14778         TOKEN_STRING_INITIALIZER
14779                 (struct cmd_pctype_mapping_update_result,
14780                  update, "update");
14781 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14782         TOKEN_STRING_INITIALIZER
14783                 (struct cmd_pctype_mapping_update_result,
14784                  pctype_list, NULL);
14785 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14786         TOKEN_NUM_INITIALIZER
14787                 (struct cmd_pctype_mapping_update_result,
14788                  flow_type, RTE_UINT16);
14789
14790 static void
14791 cmd_pctype_mapping_update_parsed(
14792         void *parsed_result,
14793         __rte_unused struct cmdline *cl,
14794         __rte_unused void *data)
14795 {
14796         struct cmd_pctype_mapping_update_result *res = parsed_result;
14797         int ret = -ENOTSUP;
14798 #ifdef RTE_NET_I40E
14799         struct rte_pmd_i40e_flow_type_mapping mapping;
14800         unsigned int i;
14801         unsigned int nb_item;
14802         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14803 #endif
14804
14805         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14806                 return;
14807
14808 #ifdef RTE_NET_I40E
14809         nb_item = parse_item_list(res->pctype_list, "pctypes",
14810                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14811         mapping.flow_type = res->flow_type;
14812         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14813                 mapping.pctype |= (1ULL << pctype_list[i]);
14814         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14815                                                 &mapping,
14816                                                 1,
14817                                                 0);
14818 #endif
14819
14820         switch (ret) {
14821         case 0:
14822                 break;
14823         case -EINVAL:
14824                 printf("invalid pctype or flow type\n");
14825                 break;
14826         case -ENODEV:
14827                 printf("invalid port_id %d\n", res->port_id);
14828                 break;
14829         case -ENOTSUP:
14830                 printf("function not implemented\n");
14831                 break;
14832         default:
14833                 printf("programming error: (%s)\n", strerror(-ret));
14834         }
14835 }
14836
14837 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14838         .f = cmd_pctype_mapping_update_parsed,
14839         .data = NULL,
14840         .help_str = "port config <port_id> pctype mapping update"
14841         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14842         .tokens = {
14843                 (void *)&cmd_pctype_mapping_update_port,
14844                 (void *)&cmd_pctype_mapping_update_config,
14845                 (void *)&cmd_pctype_mapping_update_port_id,
14846                 (void *)&cmd_pctype_mapping_update_pctype,
14847                 (void *)&cmd_pctype_mapping_update_mapping,
14848                 (void *)&cmd_pctype_mapping_update_update,
14849                 (void *)&cmd_pctype_mapping_update_pc_type,
14850                 (void *)&cmd_pctype_mapping_update_flow_type,
14851                 NULL,
14852         },
14853 };
14854
14855 /* ptype mapping get */
14856
14857 /* Common result structure for ptype mapping get */
14858 struct cmd_ptype_mapping_get_result {
14859         cmdline_fixed_string_t ptype;
14860         cmdline_fixed_string_t mapping;
14861         cmdline_fixed_string_t get;
14862         portid_t port_id;
14863         uint8_t valid_only;
14864 };
14865
14866 /* Common CLI fields for ptype mapping get */
14867 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14868         TOKEN_STRING_INITIALIZER
14869                 (struct cmd_ptype_mapping_get_result,
14870                  ptype, "ptype");
14871 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14872         TOKEN_STRING_INITIALIZER
14873                 (struct cmd_ptype_mapping_get_result,
14874                  mapping, "mapping");
14875 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14876         TOKEN_STRING_INITIALIZER
14877                 (struct cmd_ptype_mapping_get_result,
14878                  get, "get");
14879 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14880         TOKEN_NUM_INITIALIZER
14881                 (struct cmd_ptype_mapping_get_result,
14882                  port_id, RTE_UINT16);
14883 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14884         TOKEN_NUM_INITIALIZER
14885                 (struct cmd_ptype_mapping_get_result,
14886                  valid_only, RTE_UINT8);
14887
14888 static void
14889 cmd_ptype_mapping_get_parsed(
14890         void *parsed_result,
14891         __rte_unused struct cmdline *cl,
14892         __rte_unused void *data)
14893 {
14894         struct cmd_ptype_mapping_get_result *res = parsed_result;
14895         int ret = -ENOTSUP;
14896 #ifdef RTE_NET_I40E
14897         int max_ptype_num = 256;
14898         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14899         uint16_t count;
14900         int i;
14901 #endif
14902
14903         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14904                 return;
14905
14906 #ifdef RTE_NET_I40E
14907         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14908                                         mapping,
14909                                         max_ptype_num,
14910                                         &count,
14911                                         res->valid_only);
14912 #endif
14913
14914         switch (ret) {
14915         case 0:
14916                 break;
14917         case -ENODEV:
14918                 printf("invalid port_id %d\n", res->port_id);
14919                 break;
14920         case -ENOTSUP:
14921                 printf("function not implemented\n");
14922                 break;
14923         default:
14924                 printf("programming error: (%s)\n", strerror(-ret));
14925         }
14926
14927 #ifdef RTE_NET_I40E
14928         if (!ret) {
14929                 for (i = 0; i < count; i++)
14930                         printf("%3d\t0x%08x\n",
14931                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
14932         }
14933 #endif
14934 }
14935
14936 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14937         .f = cmd_ptype_mapping_get_parsed,
14938         .data = NULL,
14939         .help_str = "ptype mapping get <port_id> <valid_only>",
14940         .tokens = {
14941                 (void *)&cmd_ptype_mapping_get_ptype,
14942                 (void *)&cmd_ptype_mapping_get_mapping,
14943                 (void *)&cmd_ptype_mapping_get_get,
14944                 (void *)&cmd_ptype_mapping_get_port_id,
14945                 (void *)&cmd_ptype_mapping_get_valid_only,
14946                 NULL,
14947         },
14948 };
14949
14950 /* ptype mapping replace */
14951
14952 /* Common result structure for ptype mapping replace */
14953 struct cmd_ptype_mapping_replace_result {
14954         cmdline_fixed_string_t ptype;
14955         cmdline_fixed_string_t mapping;
14956         cmdline_fixed_string_t replace;
14957         portid_t port_id;
14958         uint32_t target;
14959         uint8_t mask;
14960         uint32_t pkt_type;
14961 };
14962
14963 /* Common CLI fields for ptype mapping replace */
14964 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14965         TOKEN_STRING_INITIALIZER
14966                 (struct cmd_ptype_mapping_replace_result,
14967                  ptype, "ptype");
14968 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14969         TOKEN_STRING_INITIALIZER
14970                 (struct cmd_ptype_mapping_replace_result,
14971                  mapping, "mapping");
14972 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14973         TOKEN_STRING_INITIALIZER
14974                 (struct cmd_ptype_mapping_replace_result,
14975                  replace, "replace");
14976 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14977         TOKEN_NUM_INITIALIZER
14978                 (struct cmd_ptype_mapping_replace_result,
14979                  port_id, RTE_UINT16);
14980 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14981         TOKEN_NUM_INITIALIZER
14982                 (struct cmd_ptype_mapping_replace_result,
14983                  target, RTE_UINT32);
14984 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14985         TOKEN_NUM_INITIALIZER
14986                 (struct cmd_ptype_mapping_replace_result,
14987                  mask, RTE_UINT8);
14988 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14989         TOKEN_NUM_INITIALIZER
14990                 (struct cmd_ptype_mapping_replace_result,
14991                  pkt_type, RTE_UINT32);
14992
14993 static void
14994 cmd_ptype_mapping_replace_parsed(
14995         void *parsed_result,
14996         __rte_unused struct cmdline *cl,
14997         __rte_unused void *data)
14998 {
14999         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15000         int ret = -ENOTSUP;
15001
15002         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15003                 return;
15004
15005 #ifdef RTE_NET_I40E
15006         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15007                                         res->target,
15008                                         res->mask,
15009                                         res->pkt_type);
15010 #endif
15011
15012         switch (ret) {
15013         case 0:
15014                 break;
15015         case -EINVAL:
15016                 printf("invalid ptype 0x%8x or 0x%8x\n",
15017                                 res->target, res->pkt_type);
15018                 break;
15019         case -ENODEV:
15020                 printf("invalid port_id %d\n", res->port_id);
15021                 break;
15022         case -ENOTSUP:
15023                 printf("function not implemented\n");
15024                 break;
15025         default:
15026                 printf("programming error: (%s)\n", strerror(-ret));
15027         }
15028 }
15029
15030 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15031         .f = cmd_ptype_mapping_replace_parsed,
15032         .data = NULL,
15033         .help_str =
15034                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15035         .tokens = {
15036                 (void *)&cmd_ptype_mapping_replace_ptype,
15037                 (void *)&cmd_ptype_mapping_replace_mapping,
15038                 (void *)&cmd_ptype_mapping_replace_replace,
15039                 (void *)&cmd_ptype_mapping_replace_port_id,
15040                 (void *)&cmd_ptype_mapping_replace_target,
15041                 (void *)&cmd_ptype_mapping_replace_mask,
15042                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15043                 NULL,
15044         },
15045 };
15046
15047 /* ptype mapping reset */
15048
15049 /* Common result structure for ptype mapping reset */
15050 struct cmd_ptype_mapping_reset_result {
15051         cmdline_fixed_string_t ptype;
15052         cmdline_fixed_string_t mapping;
15053         cmdline_fixed_string_t reset;
15054         portid_t port_id;
15055 };
15056
15057 /* Common CLI fields for ptype mapping reset*/
15058 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15059         TOKEN_STRING_INITIALIZER
15060                 (struct cmd_ptype_mapping_reset_result,
15061                  ptype, "ptype");
15062 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15063         TOKEN_STRING_INITIALIZER
15064                 (struct cmd_ptype_mapping_reset_result,
15065                  mapping, "mapping");
15066 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15067         TOKEN_STRING_INITIALIZER
15068                 (struct cmd_ptype_mapping_reset_result,
15069                  reset, "reset");
15070 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15071         TOKEN_NUM_INITIALIZER
15072                 (struct cmd_ptype_mapping_reset_result,
15073                  port_id, RTE_UINT16);
15074
15075 static void
15076 cmd_ptype_mapping_reset_parsed(
15077         void *parsed_result,
15078         __rte_unused struct cmdline *cl,
15079         __rte_unused void *data)
15080 {
15081         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15082         int ret = -ENOTSUP;
15083
15084         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15085                 return;
15086
15087 #ifdef RTE_NET_I40E
15088         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15089 #endif
15090
15091         switch (ret) {
15092         case 0:
15093                 break;
15094         case -ENODEV:
15095                 printf("invalid port_id %d\n", res->port_id);
15096                 break;
15097         case -ENOTSUP:
15098                 printf("function not implemented\n");
15099                 break;
15100         default:
15101                 printf("programming error: (%s)\n", strerror(-ret));
15102         }
15103 }
15104
15105 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15106         .f = cmd_ptype_mapping_reset_parsed,
15107         .data = NULL,
15108         .help_str = "ptype mapping reset <port_id>",
15109         .tokens = {
15110                 (void *)&cmd_ptype_mapping_reset_ptype,
15111                 (void *)&cmd_ptype_mapping_reset_mapping,
15112                 (void *)&cmd_ptype_mapping_reset_reset,
15113                 (void *)&cmd_ptype_mapping_reset_port_id,
15114                 NULL,
15115         },
15116 };
15117
15118 /* ptype mapping update */
15119
15120 /* Common result structure for ptype mapping update */
15121 struct cmd_ptype_mapping_update_result {
15122         cmdline_fixed_string_t ptype;
15123         cmdline_fixed_string_t mapping;
15124         cmdline_fixed_string_t reset;
15125         portid_t port_id;
15126         uint8_t hw_ptype;
15127         uint32_t sw_ptype;
15128 };
15129
15130 /* Common CLI fields for ptype mapping update*/
15131 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15132         TOKEN_STRING_INITIALIZER
15133                 (struct cmd_ptype_mapping_update_result,
15134                  ptype, "ptype");
15135 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15136         TOKEN_STRING_INITIALIZER
15137                 (struct cmd_ptype_mapping_update_result,
15138                  mapping, "mapping");
15139 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15140         TOKEN_STRING_INITIALIZER
15141                 (struct cmd_ptype_mapping_update_result,
15142                  reset, "update");
15143 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15144         TOKEN_NUM_INITIALIZER
15145                 (struct cmd_ptype_mapping_update_result,
15146                  port_id, RTE_UINT16);
15147 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15148         TOKEN_NUM_INITIALIZER
15149                 (struct cmd_ptype_mapping_update_result,
15150                  hw_ptype, RTE_UINT8);
15151 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15152         TOKEN_NUM_INITIALIZER
15153                 (struct cmd_ptype_mapping_update_result,
15154                  sw_ptype, RTE_UINT32);
15155
15156 static void
15157 cmd_ptype_mapping_update_parsed(
15158         void *parsed_result,
15159         __rte_unused struct cmdline *cl,
15160         __rte_unused void *data)
15161 {
15162         struct cmd_ptype_mapping_update_result *res = parsed_result;
15163         int ret = -ENOTSUP;
15164 #ifdef RTE_NET_I40E
15165         struct rte_pmd_i40e_ptype_mapping mapping;
15166 #endif
15167         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15168                 return;
15169
15170 #ifdef RTE_NET_I40E
15171         mapping.hw_ptype = res->hw_ptype;
15172         mapping.sw_ptype = res->sw_ptype;
15173         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15174                                                 &mapping,
15175                                                 1,
15176                                                 0);
15177 #endif
15178
15179         switch (ret) {
15180         case 0:
15181                 break;
15182         case -EINVAL:
15183                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15184                 break;
15185         case -ENODEV:
15186                 printf("invalid port_id %d\n", res->port_id);
15187                 break;
15188         case -ENOTSUP:
15189                 printf("function not implemented\n");
15190                 break;
15191         default:
15192                 printf("programming error: (%s)\n", strerror(-ret));
15193         }
15194 }
15195
15196 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15197         .f = cmd_ptype_mapping_update_parsed,
15198         .data = NULL,
15199         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15200         .tokens = {
15201                 (void *)&cmd_ptype_mapping_update_ptype,
15202                 (void *)&cmd_ptype_mapping_update_mapping,
15203                 (void *)&cmd_ptype_mapping_update_update,
15204                 (void *)&cmd_ptype_mapping_update_port_id,
15205                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15206                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15207                 NULL,
15208         },
15209 };
15210
15211 /* Common result structure for file commands */
15212 struct cmd_cmdfile_result {
15213         cmdline_fixed_string_t load;
15214         cmdline_fixed_string_t filename;
15215 };
15216
15217 /* Common CLI fields for file commands */
15218 cmdline_parse_token_string_t cmd_load_cmdfile =
15219         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15220 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15221         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15222
15223 static void
15224 cmd_load_from_file_parsed(
15225         void *parsed_result,
15226         __rte_unused struct cmdline *cl,
15227         __rte_unused void *data)
15228 {
15229         struct cmd_cmdfile_result *res = parsed_result;
15230
15231         cmdline_read_from_file(res->filename);
15232 }
15233
15234 cmdline_parse_inst_t cmd_load_from_file = {
15235         .f = cmd_load_from_file_parsed,
15236         .data = NULL,
15237         .help_str = "load <filename>",
15238         .tokens = {
15239                 (void *)&cmd_load_cmdfile,
15240                 (void *)&cmd_load_cmdfile_filename,
15241                 NULL,
15242         },
15243 };
15244
15245 /* Get Rx offloads capabilities */
15246 struct cmd_rx_offload_get_capa_result {
15247         cmdline_fixed_string_t show;
15248         cmdline_fixed_string_t port;
15249         portid_t port_id;
15250         cmdline_fixed_string_t rx_offload;
15251         cmdline_fixed_string_t capabilities;
15252 };
15253
15254 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15255         TOKEN_STRING_INITIALIZER
15256                 (struct cmd_rx_offload_get_capa_result,
15257                  show, "show");
15258 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15259         TOKEN_STRING_INITIALIZER
15260                 (struct cmd_rx_offload_get_capa_result,
15261                  port, "port");
15262 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15263         TOKEN_NUM_INITIALIZER
15264                 (struct cmd_rx_offload_get_capa_result,
15265                  port_id, RTE_UINT16);
15266 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15267         TOKEN_STRING_INITIALIZER
15268                 (struct cmd_rx_offload_get_capa_result,
15269                  rx_offload, "rx_offload");
15270 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15271         TOKEN_STRING_INITIALIZER
15272                 (struct cmd_rx_offload_get_capa_result,
15273                  capabilities, "capabilities");
15274
15275 static void
15276 print_rx_offloads(uint64_t offloads)
15277 {
15278         uint64_t single_offload;
15279         int begin;
15280         int end;
15281         int bit;
15282
15283         if (offloads == 0)
15284                 return;
15285
15286         begin = __builtin_ctzll(offloads);
15287         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15288
15289         single_offload = 1ULL << begin;
15290         for (bit = begin; bit < end; bit++) {
15291                 if (offloads & single_offload)
15292                         printf(" %s",
15293                                rte_eth_dev_rx_offload_name(single_offload));
15294                 single_offload <<= 1;
15295         }
15296 }
15297
15298 static void
15299 cmd_rx_offload_get_capa_parsed(
15300         void *parsed_result,
15301         __rte_unused struct cmdline *cl,
15302         __rte_unused void *data)
15303 {
15304         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15305         struct rte_eth_dev_info dev_info;
15306         portid_t port_id = res->port_id;
15307         uint64_t queue_offloads;
15308         uint64_t port_offloads;
15309         int ret;
15310
15311         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15312         if (ret != 0)
15313                 return;
15314
15315         queue_offloads = dev_info.rx_queue_offload_capa;
15316         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15317
15318         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15319         printf("  Per Queue :");
15320         print_rx_offloads(queue_offloads);
15321
15322         printf("\n");
15323         printf("  Per Port  :");
15324         print_rx_offloads(port_offloads);
15325         printf("\n\n");
15326 }
15327
15328 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15329         .f = cmd_rx_offload_get_capa_parsed,
15330         .data = NULL,
15331         .help_str = "show port <port_id> rx_offload capabilities",
15332         .tokens = {
15333                 (void *)&cmd_rx_offload_get_capa_show,
15334                 (void *)&cmd_rx_offload_get_capa_port,
15335                 (void *)&cmd_rx_offload_get_capa_port_id,
15336                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15337                 (void *)&cmd_rx_offload_get_capa_capabilities,
15338                 NULL,
15339         }
15340 };
15341
15342 /* Get Rx offloads configuration */
15343 struct cmd_rx_offload_get_configuration_result {
15344         cmdline_fixed_string_t show;
15345         cmdline_fixed_string_t port;
15346         portid_t port_id;
15347         cmdline_fixed_string_t rx_offload;
15348         cmdline_fixed_string_t configuration;
15349 };
15350
15351 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15352         TOKEN_STRING_INITIALIZER
15353                 (struct cmd_rx_offload_get_configuration_result,
15354                  show, "show");
15355 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15356         TOKEN_STRING_INITIALIZER
15357                 (struct cmd_rx_offload_get_configuration_result,
15358                  port, "port");
15359 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15360         TOKEN_NUM_INITIALIZER
15361                 (struct cmd_rx_offload_get_configuration_result,
15362                  port_id, RTE_UINT16);
15363 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15364         TOKEN_STRING_INITIALIZER
15365                 (struct cmd_rx_offload_get_configuration_result,
15366                  rx_offload, "rx_offload");
15367 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15368         TOKEN_STRING_INITIALIZER
15369                 (struct cmd_rx_offload_get_configuration_result,
15370                  configuration, "configuration");
15371
15372 static void
15373 cmd_rx_offload_get_configuration_parsed(
15374         void *parsed_result,
15375         __rte_unused struct cmdline *cl,
15376         __rte_unused void *data)
15377 {
15378         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15379         struct rte_eth_dev_info dev_info;
15380         portid_t port_id = res->port_id;
15381         struct rte_port *port = &ports[port_id];
15382         uint64_t port_offloads;
15383         uint64_t queue_offloads;
15384         uint16_t nb_rx_queues;
15385         int q;
15386         int ret;
15387
15388         printf("Rx Offloading Configuration of port %d :\n", port_id);
15389
15390         port_offloads = port->dev_conf.rxmode.offloads;
15391         printf("  Port :");
15392         print_rx_offloads(port_offloads);
15393         printf("\n");
15394
15395         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15396         if (ret != 0)
15397                 return;
15398
15399         nb_rx_queues = dev_info.nb_rx_queues;
15400         for (q = 0; q < nb_rx_queues; q++) {
15401                 queue_offloads = port->rx_conf[q].offloads;
15402                 printf("  Queue[%2d] :", q);
15403                 print_rx_offloads(queue_offloads);
15404                 printf("\n");
15405         }
15406         printf("\n");
15407 }
15408
15409 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15410         .f = cmd_rx_offload_get_configuration_parsed,
15411         .data = NULL,
15412         .help_str = "show port <port_id> rx_offload configuration",
15413         .tokens = {
15414                 (void *)&cmd_rx_offload_get_configuration_show,
15415                 (void *)&cmd_rx_offload_get_configuration_port,
15416                 (void *)&cmd_rx_offload_get_configuration_port_id,
15417                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15418                 (void *)&cmd_rx_offload_get_configuration_configuration,
15419                 NULL,
15420         }
15421 };
15422
15423 /* Enable/Disable a per port offloading */
15424 struct cmd_config_per_port_rx_offload_result {
15425         cmdline_fixed_string_t port;
15426         cmdline_fixed_string_t config;
15427         portid_t port_id;
15428         cmdline_fixed_string_t rx_offload;
15429         cmdline_fixed_string_t offload;
15430         cmdline_fixed_string_t on_off;
15431 };
15432
15433 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15434         TOKEN_STRING_INITIALIZER
15435                 (struct cmd_config_per_port_rx_offload_result,
15436                  port, "port");
15437 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15438         TOKEN_STRING_INITIALIZER
15439                 (struct cmd_config_per_port_rx_offload_result,
15440                  config, "config");
15441 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15442         TOKEN_NUM_INITIALIZER
15443                 (struct cmd_config_per_port_rx_offload_result,
15444                  port_id, RTE_UINT16);
15445 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15446         TOKEN_STRING_INITIALIZER
15447                 (struct cmd_config_per_port_rx_offload_result,
15448                  rx_offload, "rx_offload");
15449 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15450         TOKEN_STRING_INITIALIZER
15451                 (struct cmd_config_per_port_rx_offload_result,
15452                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15453                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15454                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15455                            "scatter#buffer_split#timestamp#security#"
15456                            "keep_crc#rss_hash");
15457 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15458         TOKEN_STRING_INITIALIZER
15459                 (struct cmd_config_per_port_rx_offload_result,
15460                  on_off, "on#off");
15461
15462 static uint64_t
15463 search_rx_offload(const char *name)
15464 {
15465         uint64_t single_offload;
15466         const char *single_name;
15467         int found = 0;
15468         unsigned int bit;
15469
15470         single_offload = 1;
15471         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15472                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15473                 if (!strcasecmp(single_name, name)) {
15474                         found = 1;
15475                         break;
15476                 }
15477                 single_offload <<= 1;
15478         }
15479
15480         if (found)
15481                 return single_offload;
15482
15483         return 0;
15484 }
15485
15486 static void
15487 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
15488                                 __rte_unused struct cmdline *cl,
15489                                 __rte_unused void *data)
15490 {
15491         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
15492         portid_t port_id = res->port_id;
15493         struct rte_eth_dev_info dev_info;
15494         struct rte_port *port = &ports[port_id];
15495         uint64_t single_offload;
15496         uint16_t nb_rx_queues;
15497         int q;
15498         int ret;
15499
15500         if (port->port_status != RTE_PORT_STOPPED) {
15501                 printf("Error: Can't config offload when Port %d "
15502                        "is not stopped\n", port_id);
15503                 return;
15504         }
15505
15506         single_offload = search_rx_offload(res->offload);
15507         if (single_offload == 0) {
15508                 printf("Unknown offload name: %s\n", res->offload);
15509                 return;
15510         }
15511
15512         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15513         if (ret != 0)
15514                 return;
15515
15516         nb_rx_queues = dev_info.nb_rx_queues;
15517         if (!strcmp(res->on_off, "on")) {
15518                 port->dev_conf.rxmode.offloads |= single_offload;
15519                 for (q = 0; q < nb_rx_queues; q++)
15520                         port->rx_conf[q].offloads |= single_offload;
15521         } else {
15522                 port->dev_conf.rxmode.offloads &= ~single_offload;
15523                 for (q = 0; q < nb_rx_queues; q++)
15524                         port->rx_conf[q].offloads &= ~single_offload;
15525         }
15526
15527         cmd_reconfig_device_queue(port_id, 1, 1);
15528 }
15529
15530 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
15531         .f = cmd_config_per_port_rx_offload_parsed,
15532         .data = NULL,
15533         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
15534                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15535                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15536                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15537                     "keep_crc|rss_hash on|off",
15538         .tokens = {
15539                 (void *)&cmd_config_per_port_rx_offload_result_port,
15540                 (void *)&cmd_config_per_port_rx_offload_result_config,
15541                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
15542                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
15543                 (void *)&cmd_config_per_port_rx_offload_result_offload,
15544                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
15545                 NULL,
15546         }
15547 };
15548
15549 /* Enable/Disable a per queue offloading */
15550 struct cmd_config_per_queue_rx_offload_result {
15551         cmdline_fixed_string_t port;
15552         portid_t port_id;
15553         cmdline_fixed_string_t rxq;
15554         uint16_t queue_id;
15555         cmdline_fixed_string_t rx_offload;
15556         cmdline_fixed_string_t offload;
15557         cmdline_fixed_string_t on_off;
15558 };
15559
15560 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
15561         TOKEN_STRING_INITIALIZER
15562                 (struct cmd_config_per_queue_rx_offload_result,
15563                  port, "port");
15564 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
15565         TOKEN_NUM_INITIALIZER
15566                 (struct cmd_config_per_queue_rx_offload_result,
15567                  port_id, RTE_UINT16);
15568 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
15569         TOKEN_STRING_INITIALIZER
15570                 (struct cmd_config_per_queue_rx_offload_result,
15571                  rxq, "rxq");
15572 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
15573         TOKEN_NUM_INITIALIZER
15574                 (struct cmd_config_per_queue_rx_offload_result,
15575                  queue_id, RTE_UINT16);
15576 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
15577         TOKEN_STRING_INITIALIZER
15578                 (struct cmd_config_per_queue_rx_offload_result,
15579                  rx_offload, "rx_offload");
15580 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
15581         TOKEN_STRING_INITIALIZER
15582                 (struct cmd_config_per_queue_rx_offload_result,
15583                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15584                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15585                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15586                            "scatter#buffer_split#timestamp#security#keep_crc");
15587 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
15588         TOKEN_STRING_INITIALIZER
15589                 (struct cmd_config_per_queue_rx_offload_result,
15590                  on_off, "on#off");
15591
15592 static void
15593 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
15594                                 __rte_unused struct cmdline *cl,
15595                                 __rte_unused void *data)
15596 {
15597         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
15598         struct rte_eth_dev_info dev_info;
15599         portid_t port_id = res->port_id;
15600         uint16_t queue_id = res->queue_id;
15601         struct rte_port *port = &ports[port_id];
15602         uint64_t single_offload;
15603         int ret;
15604
15605         if (port->port_status != RTE_PORT_STOPPED) {
15606                 printf("Error: Can't config offload when Port %d "
15607                        "is not stopped\n", port_id);
15608                 return;
15609         }
15610
15611         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15612         if (ret != 0)
15613                 return;
15614
15615         if (queue_id >= dev_info.nb_rx_queues) {
15616                 printf("Error: input queue_id should be 0 ... "
15617                        "%d\n", dev_info.nb_rx_queues - 1);
15618                 return;
15619         }
15620
15621         single_offload = search_rx_offload(res->offload);
15622         if (single_offload == 0) {
15623                 printf("Unknown offload name: %s\n", res->offload);
15624                 return;
15625         }
15626
15627         if (!strcmp(res->on_off, "on"))
15628                 port->rx_conf[queue_id].offloads |= single_offload;
15629         else
15630                 port->rx_conf[queue_id].offloads &= ~single_offload;
15631
15632         cmd_reconfig_device_queue(port_id, 1, 1);
15633 }
15634
15635 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
15636         .f = cmd_config_per_queue_rx_offload_parsed,
15637         .data = NULL,
15638         .help_str = "port <port_id> rxq <queue_id> rx_offload "
15639                     "vlan_strip|ipv4_cksum|"
15640                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15641                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15642                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15643                     "keep_crc on|off",
15644         .tokens = {
15645                 (void *)&cmd_config_per_queue_rx_offload_result_port,
15646                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
15647                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
15648                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
15649                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
15650                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
15651                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
15652                 NULL,
15653         }
15654 };
15655
15656 /* Get Tx offloads capabilities */
15657 struct cmd_tx_offload_get_capa_result {
15658         cmdline_fixed_string_t show;
15659         cmdline_fixed_string_t port;
15660         portid_t port_id;
15661         cmdline_fixed_string_t tx_offload;
15662         cmdline_fixed_string_t capabilities;
15663 };
15664
15665 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
15666         TOKEN_STRING_INITIALIZER
15667                 (struct cmd_tx_offload_get_capa_result,
15668                  show, "show");
15669 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
15670         TOKEN_STRING_INITIALIZER
15671                 (struct cmd_tx_offload_get_capa_result,
15672                  port, "port");
15673 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
15674         TOKEN_NUM_INITIALIZER
15675                 (struct cmd_tx_offload_get_capa_result,
15676                  port_id, RTE_UINT16);
15677 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
15678         TOKEN_STRING_INITIALIZER
15679                 (struct cmd_tx_offload_get_capa_result,
15680                  tx_offload, "tx_offload");
15681 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
15682         TOKEN_STRING_INITIALIZER
15683                 (struct cmd_tx_offload_get_capa_result,
15684                  capabilities, "capabilities");
15685
15686 static void
15687 print_tx_offloads(uint64_t offloads)
15688 {
15689         uint64_t single_offload;
15690         int begin;
15691         int end;
15692         int bit;
15693
15694         if (offloads == 0)
15695                 return;
15696
15697         begin = __builtin_ctzll(offloads);
15698         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15699
15700         single_offload = 1ULL << begin;
15701         for (bit = begin; bit < end; bit++) {
15702                 if (offloads & single_offload)
15703                         printf(" %s",
15704                                rte_eth_dev_tx_offload_name(single_offload));
15705                 single_offload <<= 1;
15706         }
15707 }
15708
15709 static void
15710 cmd_tx_offload_get_capa_parsed(
15711         void *parsed_result,
15712         __rte_unused struct cmdline *cl,
15713         __rte_unused void *data)
15714 {
15715         struct cmd_tx_offload_get_capa_result *res = parsed_result;
15716         struct rte_eth_dev_info dev_info;
15717         portid_t port_id = res->port_id;
15718         uint64_t queue_offloads;
15719         uint64_t port_offloads;
15720         int ret;
15721
15722         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15723         if (ret != 0)
15724                 return;
15725
15726         queue_offloads = dev_info.tx_queue_offload_capa;
15727         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
15728
15729         printf("Tx Offloading Capabilities of port %d :\n", port_id);
15730         printf("  Per Queue :");
15731         print_tx_offloads(queue_offloads);
15732
15733         printf("\n");
15734         printf("  Per Port  :");
15735         print_tx_offloads(port_offloads);
15736         printf("\n\n");
15737 }
15738
15739 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
15740         .f = cmd_tx_offload_get_capa_parsed,
15741         .data = NULL,
15742         .help_str = "show port <port_id> tx_offload capabilities",
15743         .tokens = {
15744                 (void *)&cmd_tx_offload_get_capa_show,
15745                 (void *)&cmd_tx_offload_get_capa_port,
15746                 (void *)&cmd_tx_offload_get_capa_port_id,
15747                 (void *)&cmd_tx_offload_get_capa_tx_offload,
15748                 (void *)&cmd_tx_offload_get_capa_capabilities,
15749                 NULL,
15750         }
15751 };
15752
15753 /* Get Tx offloads configuration */
15754 struct cmd_tx_offload_get_configuration_result {
15755         cmdline_fixed_string_t show;
15756         cmdline_fixed_string_t port;
15757         portid_t port_id;
15758         cmdline_fixed_string_t tx_offload;
15759         cmdline_fixed_string_t configuration;
15760 };
15761
15762 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
15763         TOKEN_STRING_INITIALIZER
15764                 (struct cmd_tx_offload_get_configuration_result,
15765                  show, "show");
15766 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
15767         TOKEN_STRING_INITIALIZER
15768                 (struct cmd_tx_offload_get_configuration_result,
15769                  port, "port");
15770 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
15771         TOKEN_NUM_INITIALIZER
15772                 (struct cmd_tx_offload_get_configuration_result,
15773                  port_id, RTE_UINT16);
15774 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
15775         TOKEN_STRING_INITIALIZER
15776                 (struct cmd_tx_offload_get_configuration_result,
15777                  tx_offload, "tx_offload");
15778 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
15779         TOKEN_STRING_INITIALIZER
15780                 (struct cmd_tx_offload_get_configuration_result,
15781                  configuration, "configuration");
15782
15783 static void
15784 cmd_tx_offload_get_configuration_parsed(
15785         void *parsed_result,
15786         __rte_unused struct cmdline *cl,
15787         __rte_unused void *data)
15788 {
15789         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
15790         struct rte_eth_dev_info dev_info;
15791         portid_t port_id = res->port_id;
15792         struct rte_port *port = &ports[port_id];
15793         uint64_t port_offloads;
15794         uint64_t queue_offloads;
15795         uint16_t nb_tx_queues;
15796         int q;
15797         int ret;
15798
15799         printf("Tx Offloading Configuration of port %d :\n", port_id);
15800
15801         port_offloads = port->dev_conf.txmode.offloads;
15802         printf("  Port :");
15803         print_tx_offloads(port_offloads);
15804         printf("\n");
15805
15806         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15807         if (ret != 0)
15808                 return;
15809
15810         nb_tx_queues = dev_info.nb_tx_queues;
15811         for (q = 0; q < nb_tx_queues; q++) {
15812                 queue_offloads = port->tx_conf[q].offloads;
15813                 printf("  Queue[%2d] :", q);
15814                 print_tx_offloads(queue_offloads);
15815                 printf("\n");
15816         }
15817         printf("\n");
15818 }
15819
15820 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
15821         .f = cmd_tx_offload_get_configuration_parsed,
15822         .data = NULL,
15823         .help_str = "show port <port_id> tx_offload configuration",
15824         .tokens = {
15825                 (void *)&cmd_tx_offload_get_configuration_show,
15826                 (void *)&cmd_tx_offload_get_configuration_port,
15827                 (void *)&cmd_tx_offload_get_configuration_port_id,
15828                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
15829                 (void *)&cmd_tx_offload_get_configuration_configuration,
15830                 NULL,
15831         }
15832 };
15833
15834 /* Enable/Disable a per port offloading */
15835 struct cmd_config_per_port_tx_offload_result {
15836         cmdline_fixed_string_t port;
15837         cmdline_fixed_string_t config;
15838         portid_t port_id;
15839         cmdline_fixed_string_t tx_offload;
15840         cmdline_fixed_string_t offload;
15841         cmdline_fixed_string_t on_off;
15842 };
15843
15844 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
15845         TOKEN_STRING_INITIALIZER
15846                 (struct cmd_config_per_port_tx_offload_result,
15847                  port, "port");
15848 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
15849         TOKEN_STRING_INITIALIZER
15850                 (struct cmd_config_per_port_tx_offload_result,
15851                  config, "config");
15852 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
15853         TOKEN_NUM_INITIALIZER
15854                 (struct cmd_config_per_port_tx_offload_result,
15855                  port_id, RTE_UINT16);
15856 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
15857         TOKEN_STRING_INITIALIZER
15858                 (struct cmd_config_per_port_tx_offload_result,
15859                  tx_offload, "tx_offload");
15860 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
15861         TOKEN_STRING_INITIALIZER
15862                 (struct cmd_config_per_port_tx_offload_result,
15863                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
15864                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
15865                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
15866                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
15867                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
15868                           "send_on_timestamp");
15869 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
15870         TOKEN_STRING_INITIALIZER
15871                 (struct cmd_config_per_port_tx_offload_result,
15872                  on_off, "on#off");
15873
15874 static uint64_t
15875 search_tx_offload(const char *name)
15876 {
15877         uint64_t single_offload;
15878         const char *single_name;
15879         int found = 0;
15880         unsigned int bit;
15881
15882         single_offload = 1;
15883         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15884                 single_name = rte_eth_dev_tx_offload_name(single_offload);
15885                 if (single_name == NULL)
15886                         break;
15887                 if (!strcasecmp(single_name, name)) {
15888                         found = 1;
15889                         break;
15890                 } else if (!strcasecmp(single_name, "UNKNOWN"))
15891                         break;
15892                 single_offload <<= 1;
15893         }
15894
15895         if (found)
15896                 return single_offload;
15897
15898         return 0;
15899 }
15900
15901 static void
15902 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
15903                                 __rte_unused struct cmdline *cl,
15904                                 __rte_unused void *data)
15905 {
15906         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
15907         portid_t port_id = res->port_id;
15908         struct rte_eth_dev_info dev_info;
15909         struct rte_port *port = &ports[port_id];
15910         uint64_t single_offload;
15911         uint16_t nb_tx_queues;
15912         int q;
15913         int ret;
15914
15915         if (port->port_status != RTE_PORT_STOPPED) {
15916                 printf("Error: Can't config offload when Port %d "
15917                        "is not stopped\n", port_id);
15918                 return;
15919         }
15920
15921         single_offload = search_tx_offload(res->offload);
15922         if (single_offload == 0) {
15923                 printf("Unknown offload name: %s\n", res->offload);
15924                 return;
15925         }
15926
15927         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15928         if (ret != 0)
15929                 return;
15930
15931         nb_tx_queues = dev_info.nb_tx_queues;
15932         if (!strcmp(res->on_off, "on")) {
15933                 port->dev_conf.txmode.offloads |= single_offload;
15934                 for (q = 0; q < nb_tx_queues; q++)
15935                         port->tx_conf[q].offloads |= single_offload;
15936         } else {
15937                 port->dev_conf.txmode.offloads &= ~single_offload;
15938                 for (q = 0; q < nb_tx_queues; q++)
15939                         port->tx_conf[q].offloads &= ~single_offload;
15940         }
15941
15942         cmd_reconfig_device_queue(port_id, 1, 1);
15943 }
15944
15945 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
15946         .f = cmd_config_per_port_tx_offload_parsed,
15947         .data = NULL,
15948         .help_str = "port config <port_id> tx_offload "
15949                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
15950                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
15951                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
15952                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
15953                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
15954                     "send_on_timestamp on|off",
15955         .tokens = {
15956                 (void *)&cmd_config_per_port_tx_offload_result_port,
15957                 (void *)&cmd_config_per_port_tx_offload_result_config,
15958                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
15959                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
15960                 (void *)&cmd_config_per_port_tx_offload_result_offload,
15961                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
15962                 NULL,
15963         }
15964 };
15965
15966 /* Enable/Disable a per queue offloading */
15967 struct cmd_config_per_queue_tx_offload_result {
15968         cmdline_fixed_string_t port;
15969         portid_t port_id;
15970         cmdline_fixed_string_t txq;
15971         uint16_t queue_id;
15972         cmdline_fixed_string_t tx_offload;
15973         cmdline_fixed_string_t offload;
15974         cmdline_fixed_string_t on_off;
15975 };
15976
15977 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
15978         TOKEN_STRING_INITIALIZER
15979                 (struct cmd_config_per_queue_tx_offload_result,
15980                  port, "port");
15981 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
15982         TOKEN_NUM_INITIALIZER
15983                 (struct cmd_config_per_queue_tx_offload_result,
15984                  port_id, RTE_UINT16);
15985 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
15986         TOKEN_STRING_INITIALIZER
15987                 (struct cmd_config_per_queue_tx_offload_result,
15988                  txq, "txq");
15989 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
15990         TOKEN_NUM_INITIALIZER
15991                 (struct cmd_config_per_queue_tx_offload_result,
15992                  queue_id, RTE_UINT16);
15993 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
15994         TOKEN_STRING_INITIALIZER
15995                 (struct cmd_config_per_queue_tx_offload_result,
15996                  tx_offload, "tx_offload");
15997 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
15998         TOKEN_STRING_INITIALIZER
15999                 (struct cmd_config_per_queue_tx_offload_result,
16000                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16001                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16002                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16003                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16004                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16005 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16006         TOKEN_STRING_INITIALIZER
16007                 (struct cmd_config_per_queue_tx_offload_result,
16008                  on_off, "on#off");
16009
16010 static void
16011 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16012                                 __rte_unused struct cmdline *cl,
16013                                 __rte_unused void *data)
16014 {
16015         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16016         struct rte_eth_dev_info dev_info;
16017         portid_t port_id = res->port_id;
16018         uint16_t queue_id = res->queue_id;
16019         struct rte_port *port = &ports[port_id];
16020         uint64_t single_offload;
16021         int ret;
16022
16023         if (port->port_status != RTE_PORT_STOPPED) {
16024                 printf("Error: Can't config offload when Port %d "
16025                        "is not stopped\n", port_id);
16026                 return;
16027         }
16028
16029         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16030         if (ret != 0)
16031                 return;
16032
16033         if (queue_id >= dev_info.nb_tx_queues) {
16034                 printf("Error: input queue_id should be 0 ... "
16035                        "%d\n", dev_info.nb_tx_queues - 1);
16036                 return;
16037         }
16038
16039         single_offload = search_tx_offload(res->offload);
16040         if (single_offload == 0) {
16041                 printf("Unknown offload name: %s\n", res->offload);
16042                 return;
16043         }
16044
16045         if (!strcmp(res->on_off, "on"))
16046                 port->tx_conf[queue_id].offloads |= single_offload;
16047         else
16048                 port->tx_conf[queue_id].offloads &= ~single_offload;
16049
16050         cmd_reconfig_device_queue(port_id, 1, 1);
16051 }
16052
16053 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16054         .f = cmd_config_per_queue_tx_offload_parsed,
16055         .data = NULL,
16056         .help_str = "port <port_id> txq <queue_id> tx_offload "
16057                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16058                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16059                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16060                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16061                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16062                     "on|off",
16063         .tokens = {
16064                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16065                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16066                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16067                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16068                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16069                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16070                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16071                 NULL,
16072         }
16073 };
16074
16075 /* *** configure tx_metadata for specific port *** */
16076 struct cmd_config_tx_metadata_specific_result {
16077         cmdline_fixed_string_t port;
16078         cmdline_fixed_string_t keyword;
16079         uint16_t port_id;
16080         cmdline_fixed_string_t item;
16081         uint32_t value;
16082 };
16083
16084 static void
16085 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16086                                 __rte_unused struct cmdline *cl,
16087                                 __rte_unused void *data)
16088 {
16089         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16090
16091         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16092                 return;
16093         ports[res->port_id].tx_metadata = res->value;
16094         /* Add/remove callback to insert valid metadata in every Tx packet. */
16095         if (ports[res->port_id].tx_metadata)
16096                 add_tx_md_callback(res->port_id);
16097         else
16098                 remove_tx_md_callback(res->port_id);
16099         rte_flow_dynf_metadata_register();
16100 }
16101
16102 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16103         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16104                         port, "port");
16105 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16106         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16107                         keyword, "config");
16108 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16109         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16110                         port_id, RTE_UINT16);
16111 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16112         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16113                         item, "tx_metadata");
16114 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16115         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16116                         value, RTE_UINT32);
16117
16118 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16119         .f = cmd_config_tx_metadata_specific_parsed,
16120         .data = NULL,
16121         .help_str = "port config <port_id> tx_metadata <value>",
16122         .tokens = {
16123                 (void *)&cmd_config_tx_metadata_specific_port,
16124                 (void *)&cmd_config_tx_metadata_specific_keyword,
16125                 (void *)&cmd_config_tx_metadata_specific_id,
16126                 (void *)&cmd_config_tx_metadata_specific_item,
16127                 (void *)&cmd_config_tx_metadata_specific_value,
16128                 NULL,
16129         },
16130 };
16131
16132 /* *** set dynf *** */
16133 struct cmd_config_tx_dynf_specific_result {
16134         cmdline_fixed_string_t port;
16135         cmdline_fixed_string_t keyword;
16136         uint16_t port_id;
16137         cmdline_fixed_string_t item;
16138         cmdline_fixed_string_t name;
16139         cmdline_fixed_string_t value;
16140 };
16141
16142 static void
16143 cmd_config_dynf_specific_parsed(void *parsed_result,
16144                                 __rte_unused struct cmdline *cl,
16145                                 __rte_unused void *data)
16146 {
16147         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16148         struct rte_mbuf_dynflag desc_flag;
16149         int flag;
16150         uint64_t old_port_flags;
16151
16152         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16153                 return;
16154         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16155         if (flag <= 0) {
16156                 if (strlcpy(desc_flag.name, res->name,
16157                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16158                         printf("Flag name too long\n");
16159                         return;
16160                 }
16161                 desc_flag.flags = 0;
16162                 flag = rte_mbuf_dynflag_register(&desc_flag);
16163                 if (flag < 0) {
16164                         printf("Can't register flag\n");
16165                         return;
16166                 }
16167                 strcpy(dynf_names[flag], desc_flag.name);
16168         }
16169         old_port_flags = ports[res->port_id].mbuf_dynf;
16170         if (!strcmp(res->value, "set")) {
16171                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16172                 if (old_port_flags == 0)
16173                         add_tx_dynf_callback(res->port_id);
16174         } else {
16175                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16176                 if (ports[res->port_id].mbuf_dynf == 0)
16177                         remove_tx_dynf_callback(res->port_id);
16178         }
16179 }
16180
16181 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16182         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16183                         keyword, "port");
16184 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16185         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16186                         keyword, "config");
16187 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16188         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16189                         port_id, RTE_UINT16);
16190 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16191         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16192                         item, "dynf");
16193 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16194         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16195                         name, NULL);
16196 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16197         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16198                         value, "set#clear");
16199
16200 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16201         .f = cmd_config_dynf_specific_parsed,
16202         .data = NULL,
16203         .help_str = "port config <port id> dynf <name> set|clear",
16204         .tokens = {
16205                 (void *)&cmd_config_tx_dynf_specific_port,
16206                 (void *)&cmd_config_tx_dynf_specific_keyword,
16207                 (void *)&cmd_config_tx_dynf_specific_port_id,
16208                 (void *)&cmd_config_tx_dynf_specific_item,
16209                 (void *)&cmd_config_tx_dynf_specific_name,
16210                 (void *)&cmd_config_tx_dynf_specific_value,
16211                 NULL,
16212         },
16213 };
16214
16215 /* *** display tx_metadata per port configuration *** */
16216 struct cmd_show_tx_metadata_result {
16217         cmdline_fixed_string_t cmd_show;
16218         cmdline_fixed_string_t cmd_port;
16219         cmdline_fixed_string_t cmd_keyword;
16220         portid_t cmd_pid;
16221 };
16222
16223 static void
16224 cmd_show_tx_metadata_parsed(void *parsed_result,
16225                 __rte_unused struct cmdline *cl,
16226                 __rte_unused void *data)
16227 {
16228         struct cmd_show_tx_metadata_result *res = parsed_result;
16229
16230         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16231                 printf("invalid port id %u\n", res->cmd_pid);
16232                 return;
16233         }
16234         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16235                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16236                        ports[res->cmd_pid].tx_metadata);
16237         }
16238 }
16239
16240 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16241         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16242                         cmd_show, "show");
16243 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16244         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16245                         cmd_port, "port");
16246 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16247         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16248                         cmd_pid, RTE_UINT16);
16249 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16250         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16251                         cmd_keyword, "tx_metadata");
16252
16253 cmdline_parse_inst_t cmd_show_tx_metadata = {
16254         .f = cmd_show_tx_metadata_parsed,
16255         .data = NULL,
16256         .help_str = "show port <port_id> tx_metadata",
16257         .tokens = {
16258                 (void *)&cmd_show_tx_metadata_show,
16259                 (void *)&cmd_show_tx_metadata_port,
16260                 (void *)&cmd_show_tx_metadata_pid,
16261                 (void *)&cmd_show_tx_metadata_keyword,
16262                 NULL,
16263         },
16264 };
16265
16266 /* *** show fec capability per port configuration *** */
16267 struct cmd_show_fec_capability_result {
16268         cmdline_fixed_string_t cmd_show;
16269         cmdline_fixed_string_t cmd_port;
16270         cmdline_fixed_string_t cmd_fec;
16271         cmdline_fixed_string_t cmd_keyword;
16272         portid_t cmd_pid;
16273 };
16274
16275 static void
16276 cmd_show_fec_capability_parsed(void *parsed_result,
16277                 __rte_unused struct cmdline *cl,
16278                 __rte_unused void *data)
16279 {
16280         struct cmd_show_fec_capability_result *res = parsed_result;
16281         struct rte_eth_fec_capa *speed_fec_capa;
16282         unsigned int num;
16283         int ret;
16284
16285         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16286                 printf("Invalid port id %u\n", res->cmd_pid);
16287                 return;
16288         }
16289
16290         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
16291         if (ret == -ENOTSUP) {
16292                 printf("Function not implemented\n");
16293                 return;
16294         } else if (ret < 0) {
16295                 printf("Get FEC capability failed: %d\n", ret);
16296                 return;
16297         }
16298
16299         num = (unsigned int)ret;
16300         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
16301         if (speed_fec_capa == NULL) {
16302                 printf("Failed to alloc FEC capability buffer\n");
16303                 return;
16304         }
16305
16306         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16307         if (ret < 0) {
16308                 printf("Error getting FEC capability: %d\n", ret);
16309                 goto out;
16310         }
16311
16312         show_fec_capability(num, speed_fec_capa);
16313 out:
16314         free(speed_fec_capa);
16315 }
16316
16317 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16318         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16319                         cmd_show, "show");
16320 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16321         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16322                         cmd_port, "port");
16323 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16324         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16325                         cmd_pid, RTE_UINT16);
16326 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16327         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16328                         cmd_fec, "fec");
16329 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16330         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16331                         cmd_keyword, "capabilities");
16332
16333 cmdline_parse_inst_t cmd_show_capability = {
16334         .f = cmd_show_fec_capability_parsed,
16335         .data = NULL,
16336         .help_str = "show port <port_id> fec capabilities",
16337         .tokens = {
16338                 (void *)&cmd_show_fec_capability_show,
16339                 (void *)&cmd_show_fec_capability_port,
16340                 (void *)&cmd_show_fec_capability_pid,
16341                 (void *)&cmd_show_fec_capability_fec,
16342                 (void *)&cmd_show_fec_capability_keyword,
16343                 NULL,
16344         },
16345 };
16346
16347 /* *** show fec mode per port configuration *** */
16348 struct cmd_show_fec_metadata_result {
16349         cmdline_fixed_string_t cmd_show;
16350         cmdline_fixed_string_t cmd_port;
16351         cmdline_fixed_string_t cmd_keyword;
16352         portid_t cmd_pid;
16353 };
16354
16355 static void
16356 cmd_show_fec_mode_parsed(void *parsed_result,
16357                 __rte_unused struct cmdline *cl,
16358                 __rte_unused void *data)
16359 {
16360 #define FEC_NAME_SIZE 16
16361         struct cmd_show_fec_metadata_result *res = parsed_result;
16362         uint32_t mode;
16363         char buf[FEC_NAME_SIZE];
16364         int ret;
16365
16366         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16367                 printf("Invalid port id %u\n", res->cmd_pid);
16368                 return;
16369         }
16370         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16371         if (ret == -ENOTSUP) {
16372                 printf("Function not implemented\n");
16373                 return;
16374         } else if (ret < 0) {
16375                 printf("Get FEC mode failed\n");
16376                 return;
16377         }
16378
16379         switch (mode) {
16380         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16381                 strlcpy(buf, "off", sizeof(buf));
16382                 break;
16383         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16384                 strlcpy(buf, "auto", sizeof(buf));
16385                 break;
16386         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16387                 strlcpy(buf, "baser", sizeof(buf));
16388                 break;
16389         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16390                 strlcpy(buf, "rs", sizeof(buf));
16391                 break;
16392         default:
16393                 return;
16394         }
16395
16396         printf("%s\n", buf);
16397 }
16398
16399 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16400         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16401                         cmd_show, "show");
16402 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16403         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16404                         cmd_port, "port");
16405 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16406         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16407                         cmd_pid, RTE_UINT16);
16408 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16409         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16410                         cmd_keyword, "fec_mode");
16411
16412 cmdline_parse_inst_t cmd_show_fec_mode = {
16413         .f = cmd_show_fec_mode_parsed,
16414         .data = NULL,
16415         .help_str = "show port <port_id> fec_mode",
16416         .tokens = {
16417                 (void *)&cmd_show_fec_mode_show,
16418                 (void *)&cmd_show_fec_mode_port,
16419                 (void *)&cmd_show_fec_mode_pid,
16420                 (void *)&cmd_show_fec_mode_keyword,
16421                 NULL,
16422         },
16423 };
16424
16425 /* *** set fec mode per port configuration *** */
16426 struct cmd_set_port_fec_mode {
16427         cmdline_fixed_string_t set;
16428         cmdline_fixed_string_t port;
16429         portid_t port_id;
16430         cmdline_fixed_string_t fec_mode;
16431         cmdline_fixed_string_t fec_value;
16432 };
16433
16434 /* Common CLI fields for set fec mode */
16435 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16436         TOKEN_STRING_INITIALIZER
16437                 (struct cmd_set_port_fec_mode,
16438                  set, "set");
16439 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16440         TOKEN_STRING_INITIALIZER
16441                 (struct cmd_set_port_fec_mode,
16442                  port, "port");
16443 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16444         TOKEN_NUM_INITIALIZER
16445                 (struct cmd_set_port_fec_mode,
16446                  port_id, RTE_UINT16);
16447 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16448         TOKEN_STRING_INITIALIZER
16449                 (struct cmd_set_port_fec_mode,
16450                  fec_mode, "fec_mode");
16451 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16452         TOKEN_STRING_INITIALIZER
16453                 (struct cmd_set_port_fec_mode,
16454                  fec_value, NULL);
16455
16456 static void
16457 cmd_set_port_fec_mode_parsed(
16458         void *parsed_result,
16459         __rte_unused struct cmdline *cl,
16460         __rte_unused void *data)
16461 {
16462         struct cmd_set_port_fec_mode *res = parsed_result;
16463         uint16_t port_id = res->port_id;
16464         uint32_t mode;
16465         int ret;
16466
16467         ret = parse_fec_mode(res->fec_value, &mode);
16468         if (ret < 0) {
16469                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16470                         port_id);
16471                 return;
16472         }
16473
16474         ret = rte_eth_fec_set(port_id, mode);
16475         if (ret == -ENOTSUP) {
16476                 printf("Function not implemented\n");
16477                 return;
16478         } else if (ret < 0) {
16479                 printf("Set FEC mode failed\n");
16480                 return;
16481         }
16482 }
16483
16484 cmdline_parse_inst_t cmd_set_fec_mode = {
16485         .f = cmd_set_port_fec_mode_parsed,
16486         .data = NULL,
16487         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
16488         .tokens = {
16489                 (void *)&cmd_set_port_fec_mode_set,
16490                 (void *)&cmd_set_port_fec_mode_port,
16491                 (void *)&cmd_set_port_fec_mode_port_id,
16492                 (void *)&cmd_set_port_fec_mode_str,
16493                 (void *)&cmd_set_port_fec_mode_value,
16494                 NULL,
16495         },
16496 };
16497
16498 /* show port supported ptypes */
16499
16500 /* Common result structure for show port ptypes */
16501 struct cmd_show_port_supported_ptypes_result {
16502         cmdline_fixed_string_t show;
16503         cmdline_fixed_string_t port;
16504         portid_t port_id;
16505         cmdline_fixed_string_t ptypes;
16506 };
16507
16508 /* Common CLI fields for show port ptypes */
16509 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
16510         TOKEN_STRING_INITIALIZER
16511                 (struct cmd_show_port_supported_ptypes_result,
16512                  show, "show");
16513 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
16514         TOKEN_STRING_INITIALIZER
16515                 (struct cmd_show_port_supported_ptypes_result,
16516                  port, "port");
16517 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
16518         TOKEN_NUM_INITIALIZER
16519                 (struct cmd_show_port_supported_ptypes_result,
16520                  port_id, RTE_UINT16);
16521 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
16522         TOKEN_STRING_INITIALIZER
16523                 (struct cmd_show_port_supported_ptypes_result,
16524                  ptypes, "ptypes");
16525
16526 static void
16527 cmd_show_port_supported_ptypes_parsed(
16528         void *parsed_result,
16529         __rte_unused struct cmdline *cl,
16530         __rte_unused void *data)
16531 {
16532 #define RSVD_PTYPE_MASK       0xf0000000
16533 #define MAX_PTYPES_PER_LAYER  16
16534 #define LTYPE_NAMESIZE        32
16535 #define PTYPE_NAMESIZE        256
16536         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
16537         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
16538         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
16539         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
16540         uint16_t port_id = res->port_id;
16541         int ret, i;
16542
16543         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
16544         if (ret < 0)
16545                 return;
16546
16547         while (ptype_mask != RSVD_PTYPE_MASK) {
16548
16549                 switch (ptype_mask) {
16550                 case RTE_PTYPE_L2_MASK:
16551                         strlcpy(ltype, "L2", sizeof(ltype));
16552                         break;
16553                 case RTE_PTYPE_L3_MASK:
16554                         strlcpy(ltype, "L3", sizeof(ltype));
16555                         break;
16556                 case RTE_PTYPE_L4_MASK:
16557                         strlcpy(ltype, "L4", sizeof(ltype));
16558                         break;
16559                 case RTE_PTYPE_TUNNEL_MASK:
16560                         strlcpy(ltype, "Tunnel", sizeof(ltype));
16561                         break;
16562                 case RTE_PTYPE_INNER_L2_MASK:
16563                         strlcpy(ltype, "Inner L2", sizeof(ltype));
16564                         break;
16565                 case RTE_PTYPE_INNER_L3_MASK:
16566                         strlcpy(ltype, "Inner L3", sizeof(ltype));
16567                         break;
16568                 case RTE_PTYPE_INNER_L4_MASK:
16569                         strlcpy(ltype, "Inner L4", sizeof(ltype));
16570                         break;
16571                 default:
16572                         return;
16573                 }
16574
16575                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
16576                                                        ptype_mask, ptypes,
16577                                                        MAX_PTYPES_PER_LAYER);
16578
16579                 if (ret > 0)
16580                         printf("Supported %s ptypes:\n", ltype);
16581                 else
16582                         printf("%s ptypes unsupported\n", ltype);
16583
16584                 for (i = 0; i < ret; ++i) {
16585                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
16586                         printf("%s\n", buf);
16587                 }
16588
16589                 ptype_mask <<= 4;
16590         }
16591 }
16592
16593 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
16594         .f = cmd_show_port_supported_ptypes_parsed,
16595         .data = NULL,
16596         .help_str = "show port <port_id> ptypes",
16597         .tokens = {
16598                 (void *)&cmd_show_port_supported_ptypes_show,
16599                 (void *)&cmd_show_port_supported_ptypes_port,
16600                 (void *)&cmd_show_port_supported_ptypes_port_id,
16601                 (void *)&cmd_show_port_supported_ptypes_ptypes,
16602                 NULL,
16603         },
16604 };
16605
16606 /* *** display rx/tx descriptor status *** */
16607 struct cmd_show_rx_tx_desc_status_result {
16608         cmdline_fixed_string_t cmd_show;
16609         cmdline_fixed_string_t cmd_port;
16610         cmdline_fixed_string_t cmd_keyword;
16611         cmdline_fixed_string_t cmd_desc;
16612         cmdline_fixed_string_t cmd_status;
16613         portid_t cmd_pid;
16614         portid_t cmd_qid;
16615         portid_t cmd_did;
16616 };
16617
16618 static void
16619 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
16620                 __rte_unused struct cmdline *cl,
16621                 __rte_unused void *data)
16622 {
16623         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
16624         int rc;
16625
16626         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16627                 printf("invalid port id %u\n", res->cmd_pid);
16628                 return;
16629         }
16630
16631         if (!strcmp(res->cmd_keyword, "rxq")) {
16632                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
16633                                              res->cmd_did);
16634                 if (rc < 0) {
16635                         printf("Invalid input: queue id = %d, desc id = %d\n",
16636                                res->cmd_qid, res->cmd_did);
16637                         return;
16638                 }
16639                 if (rc == RTE_ETH_RX_DESC_AVAIL)
16640                         printf("Desc status = AVAILABLE\n");
16641                 else if (rc == RTE_ETH_RX_DESC_DONE)
16642                         printf("Desc status = DONE\n");
16643                 else
16644                         printf("Desc status = UNAVAILABLE\n");
16645         } else if (!strcmp(res->cmd_keyword, "txq")) {
16646                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
16647                                              res->cmd_did);
16648                 if (rc < 0) {
16649                         printf("Invalid input: queue id = %d, desc id = %d\n",
16650                                res->cmd_qid, res->cmd_did);
16651                         return;
16652                 }
16653                 if (rc == RTE_ETH_TX_DESC_FULL)
16654                         printf("Desc status = FULL\n");
16655                 else if (rc == RTE_ETH_TX_DESC_DONE)
16656                         printf("Desc status = DONE\n");
16657                 else
16658                         printf("Desc status = UNAVAILABLE\n");
16659         }
16660 }
16661
16662 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
16663         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16664                         cmd_show, "show");
16665 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
16666         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16667                         cmd_port, "port");
16668 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
16669         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16670                         cmd_pid, RTE_UINT16);
16671 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
16672         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16673                         cmd_keyword, "rxq#txq");
16674 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
16675         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16676                         cmd_qid, RTE_UINT16);
16677 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
16678         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16679                         cmd_desc, "desc");
16680 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
16681         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16682                         cmd_did, RTE_UINT16);
16683 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
16684         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
16685                         cmd_status, "status");
16686 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
16687         .f = cmd_show_rx_tx_desc_status_parsed,
16688         .data = NULL,
16689         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
16690                 "status",
16691         .tokens = {
16692                 (void *)&cmd_show_rx_tx_desc_status_show,
16693                 (void *)&cmd_show_rx_tx_desc_status_port,
16694                 (void *)&cmd_show_rx_tx_desc_status_pid,
16695                 (void *)&cmd_show_rx_tx_desc_status_keyword,
16696                 (void *)&cmd_show_rx_tx_desc_status_qid,
16697                 (void *)&cmd_show_rx_tx_desc_status_desc,
16698                 (void *)&cmd_show_rx_tx_desc_status_did,
16699                 (void *)&cmd_show_rx_tx_desc_status_status,
16700                 NULL,
16701         },
16702 };
16703
16704 /* *** display rx queue desc used count *** */
16705 struct cmd_show_rx_queue_desc_used_count_result {
16706         cmdline_fixed_string_t cmd_show;
16707         cmdline_fixed_string_t cmd_port;
16708         cmdline_fixed_string_t cmd_rxq;
16709         cmdline_fixed_string_t cmd_desc;
16710         cmdline_fixed_string_t cmd_used;
16711         cmdline_fixed_string_t cmd_count;
16712         portid_t cmd_pid;
16713         portid_t cmd_qid;
16714 };
16715
16716 static void
16717 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
16718                 __rte_unused struct cmdline *cl,
16719                 __rte_unused void *data)
16720 {
16721         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
16722         int rc;
16723
16724         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16725                 printf("invalid port id %u\n", res->cmd_pid);
16726                 return;
16727         }
16728
16729         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
16730         if (rc < 0) {
16731                 printf("Invalid queueid = %d\n", res->cmd_qid);
16732                 return;
16733         }
16734         printf("Used desc count = %d\n", rc);
16735 }
16736
16737 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
16738         TOKEN_STRING_INITIALIZER
16739                 (struct cmd_show_rx_queue_desc_used_count_result,
16740                  cmd_show, "show");
16741 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
16742         TOKEN_STRING_INITIALIZER
16743                 (struct cmd_show_rx_queue_desc_used_count_result,
16744                  cmd_port, "port");
16745 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
16746         TOKEN_NUM_INITIALIZER
16747                 (struct cmd_show_rx_queue_desc_used_count_result,
16748                  cmd_pid, RTE_UINT16);
16749 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
16750         TOKEN_STRING_INITIALIZER
16751                 (struct cmd_show_rx_queue_desc_used_count_result,
16752                  cmd_rxq, "rxq");
16753 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
16754         TOKEN_NUM_INITIALIZER
16755                 (struct cmd_show_rx_queue_desc_used_count_result,
16756                  cmd_qid, RTE_UINT16);
16757 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
16758         TOKEN_STRING_INITIALIZER
16759                 (struct cmd_show_rx_queue_desc_used_count_result,
16760                  cmd_count, "desc");
16761 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
16762         TOKEN_STRING_INITIALIZER
16763                 (struct cmd_show_rx_queue_desc_used_count_result,
16764                  cmd_count, "used");
16765 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
16766         TOKEN_STRING_INITIALIZER
16767                 (struct cmd_show_rx_queue_desc_used_count_result,
16768                  cmd_count, "count");
16769 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
16770         .f = cmd_show_rx_queue_desc_used_count_parsed,
16771         .data = NULL,
16772         .help_str = "show port <port_id> rxq <queue_id> desc used count",
16773         .tokens = {
16774                 (void *)&cmd_show_rx_queue_desc_used_count_show,
16775                 (void *)&cmd_show_rx_queue_desc_used_count_port,
16776                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
16777                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
16778                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
16779                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
16780                 (void *)&cmd_show_rx_queue_desc_used_count_used,
16781                 (void *)&cmd_show_rx_queue_desc_used_count_count,
16782                 NULL,
16783         },
16784 };
16785
16786 /* Common result structure for set port ptypes */
16787 struct cmd_set_port_ptypes_result {
16788         cmdline_fixed_string_t set;
16789         cmdline_fixed_string_t port;
16790         portid_t port_id;
16791         cmdline_fixed_string_t ptype_mask;
16792         uint32_t mask;
16793 };
16794
16795 /* Common CLI fields for set port ptypes */
16796 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
16797         TOKEN_STRING_INITIALIZER
16798                 (struct cmd_set_port_ptypes_result,
16799                  set, "set");
16800 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
16801         TOKEN_STRING_INITIALIZER
16802                 (struct cmd_set_port_ptypes_result,
16803                  port, "port");
16804 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
16805         TOKEN_NUM_INITIALIZER
16806                 (struct cmd_set_port_ptypes_result,
16807                  port_id, RTE_UINT16);
16808 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
16809         TOKEN_STRING_INITIALIZER
16810                 (struct cmd_set_port_ptypes_result,
16811                  ptype_mask, "ptype_mask");
16812 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
16813         TOKEN_NUM_INITIALIZER
16814                 (struct cmd_set_port_ptypes_result,
16815                  mask, RTE_UINT32);
16816
16817 static void
16818 cmd_set_port_ptypes_parsed(
16819         void *parsed_result,
16820         __rte_unused struct cmdline *cl,
16821         __rte_unused void *data)
16822 {
16823         struct cmd_set_port_ptypes_result *res = parsed_result;
16824 #define PTYPE_NAMESIZE        256
16825         char ptype_name[PTYPE_NAMESIZE];
16826         uint16_t port_id = res->port_id;
16827         uint32_t ptype_mask = res->mask;
16828         int ret, i;
16829
16830         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
16831                                                NULL, 0);
16832         if (ret <= 0) {
16833                 printf("Port %d doesn't support any ptypes.\n", port_id);
16834                 return;
16835         }
16836
16837         uint32_t ptypes[ret];
16838
16839         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
16840         if (ret < 0) {
16841                 printf("Unable to set requested ptypes for Port %d\n", port_id);
16842                 return;
16843         }
16844
16845         printf("Successfully set following ptypes for Port %d\n", port_id);
16846         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
16847                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
16848                 printf("%s\n", ptype_name);
16849         }
16850
16851         clear_ptypes = false;
16852 }
16853
16854 cmdline_parse_inst_t cmd_set_port_ptypes = {
16855         .f = cmd_set_port_ptypes_parsed,
16856         .data = NULL,
16857         .help_str = "set port <port_id> ptype_mask <mask>",
16858         .tokens = {
16859                 (void *)&cmd_set_port_ptypes_set,
16860                 (void *)&cmd_set_port_ptypes_port,
16861                 (void *)&cmd_set_port_ptypes_port_id,
16862                 (void *)&cmd_set_port_ptypes_mask_str,
16863                 (void *)&cmd_set_port_ptypes_mask_u32,
16864                 NULL,
16865         },
16866 };
16867
16868 /* *** display mac addresses added to a port *** */
16869 struct cmd_showport_macs_result {
16870         cmdline_fixed_string_t cmd_show;
16871         cmdline_fixed_string_t cmd_port;
16872         cmdline_fixed_string_t cmd_keyword;
16873         portid_t cmd_pid;
16874 };
16875
16876 static void
16877 cmd_showport_macs_parsed(void *parsed_result,
16878                 __rte_unused struct cmdline *cl,
16879                 __rte_unused void *data)
16880 {
16881         struct cmd_showport_macs_result *res = parsed_result;
16882
16883         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
16884                 return;
16885
16886         if (!strcmp(res->cmd_keyword, "macs"))
16887                 show_macs(res->cmd_pid);
16888         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
16889                 show_mcast_macs(res->cmd_pid);
16890 }
16891
16892 cmdline_parse_token_string_t cmd_showport_macs_show =
16893         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16894                         cmd_show, "show");
16895 cmdline_parse_token_string_t cmd_showport_macs_port =
16896         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16897                         cmd_port, "port");
16898 cmdline_parse_token_num_t cmd_showport_macs_pid =
16899         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
16900                         cmd_pid, RTE_UINT16);
16901 cmdline_parse_token_string_t cmd_showport_macs_keyword =
16902         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
16903                         cmd_keyword, "macs#mcast_macs");
16904
16905 cmdline_parse_inst_t cmd_showport_macs = {
16906         .f = cmd_showport_macs_parsed,
16907         .data = NULL,
16908         .help_str = "show port <port_id> macs|mcast_macs",
16909         .tokens = {
16910                 (void *)&cmd_showport_macs_show,
16911                 (void *)&cmd_showport_macs_port,
16912                 (void *)&cmd_showport_macs_pid,
16913                 (void *)&cmd_showport_macs_keyword,
16914                 NULL,
16915         },
16916 };
16917
16918 /* ******************************************************************************** */
16919
16920 /* list of instructions */
16921 cmdline_parse_ctx_t main_ctx[] = {
16922         (cmdline_parse_inst_t *)&cmd_help_brief,
16923         (cmdline_parse_inst_t *)&cmd_help_long,
16924         (cmdline_parse_inst_t *)&cmd_quit,
16925         (cmdline_parse_inst_t *)&cmd_load_from_file,
16926         (cmdline_parse_inst_t *)&cmd_showport,
16927         (cmdline_parse_inst_t *)&cmd_showqueue,
16928         (cmdline_parse_inst_t *)&cmd_showeeprom,
16929         (cmdline_parse_inst_t *)&cmd_showportall,
16930         (cmdline_parse_inst_t *)&cmd_showdevice,
16931         (cmdline_parse_inst_t *)&cmd_showcfg,
16932         (cmdline_parse_inst_t *)&cmd_showfwdall,
16933         (cmdline_parse_inst_t *)&cmd_start,
16934         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16935         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16936         (cmdline_parse_inst_t *)&cmd_set_link_up,
16937         (cmdline_parse_inst_t *)&cmd_set_link_down,
16938         (cmdline_parse_inst_t *)&cmd_reset,
16939         (cmdline_parse_inst_t *)&cmd_set_numbers,
16940         (cmdline_parse_inst_t *)&cmd_set_log,
16941         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
16942         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
16943         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16944         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16945         (cmdline_parse_inst_t *)&cmd_set_txtimes,
16946         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16947         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16948         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16949         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16950         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16951         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16952         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16953         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16954         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16955         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16956         (cmdline_parse_inst_t *)&cmd_set_link_check,
16957         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16958         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16959         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16960         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16961 #ifdef RTE_NET_BOND
16962         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16963         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16964         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16965         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16966         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16967         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16968         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16969         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16970         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16971         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16972         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16973 #endif
16974         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16975         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16976         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16977         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16978         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16979         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16980         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16981         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16982         (cmdline_parse_inst_t *)&cmd_csum_set,
16983         (cmdline_parse_inst_t *)&cmd_csum_show,
16984         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16985         (cmdline_parse_inst_t *)&cmd_tso_set,
16986         (cmdline_parse_inst_t *)&cmd_tso_show,
16987         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16988         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16989         (cmdline_parse_inst_t *)&cmd_gro_enable,
16990         (cmdline_parse_inst_t *)&cmd_gro_flush,
16991         (cmdline_parse_inst_t *)&cmd_gro_show,
16992         (cmdline_parse_inst_t *)&cmd_gso_enable,
16993         (cmdline_parse_inst_t *)&cmd_gso_size,
16994         (cmdline_parse_inst_t *)&cmd_gso_show,
16995         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16996         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16997         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16998         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16999         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17000         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17001         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17002         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17003         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17004         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17005         (cmdline_parse_inst_t *)&cmd_config_dcb,
17006         (cmdline_parse_inst_t *)&cmd_read_reg,
17007         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17008         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17009         (cmdline_parse_inst_t *)&cmd_write_reg,
17010         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17011         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17012         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17013         (cmdline_parse_inst_t *)&cmd_stop,
17014         (cmdline_parse_inst_t *)&cmd_mac_addr,
17015         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17016         (cmdline_parse_inst_t *)&cmd_set_qmap,
17017         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17018         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17019         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17020         (cmdline_parse_inst_t *)&cmd_operate_port,
17021         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17022         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17023         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17024         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17025         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17026         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17027         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17028         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17029         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17030         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17031         (cmdline_parse_inst_t *)&cmd_config_mtu,
17032         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17033         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17034         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17035         (cmdline_parse_inst_t *)&cmd_config_rss,
17036         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17037         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17038         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17039         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17040         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17041         (cmdline_parse_inst_t *)&cmd_showport_reta,
17042         (cmdline_parse_inst_t *)&cmd_showport_macs,
17043         (cmdline_parse_inst_t *)&cmd_config_burst,
17044         (cmdline_parse_inst_t *)&cmd_config_thresh,
17045         (cmdline_parse_inst_t *)&cmd_config_threshold,
17046         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17047         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17048         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17049         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17050         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17051         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17052         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17053         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17054         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17055         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17056         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17057         (cmdline_parse_inst_t *)&cmd_dump,
17058         (cmdline_parse_inst_t *)&cmd_dump_one,
17059 #ifdef RTE_NET_I40E
17060         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17061 #endif
17062         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17063         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17064         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17065         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17066         (cmdline_parse_inst_t *)&cmd_flow,
17067         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17068         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17069         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17070         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17071         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17072         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17073         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17074         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17075         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17076         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17077         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17078         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17079         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17080         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17081         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17082         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17083         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17084         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17085         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17086         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17087         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17088         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17089         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17090         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17091         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17092         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17093         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17094         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17095         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17096         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17097         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17098         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17099         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17100         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17101         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17102         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17103         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17104         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17105         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17106         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17107         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17108         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17109         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17110         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17111         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17112         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17113         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17114         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17115         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17116         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17117         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17118         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17119         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17120         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17121         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17122         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17123         (cmdline_parse_inst_t *)&cmd_ddp_add,
17124         (cmdline_parse_inst_t *)&cmd_ddp_del,
17125         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17126         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17127         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17128         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17129         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17130         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17131         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17132         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17133         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17134         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17135         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17136         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17137
17138         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17139         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17140         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17141         (cmdline_parse_inst_t *)&cmd_queue_region,
17142         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17143         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17144         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17145         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17146         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17147         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17148         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17149         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17150         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17151         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17152         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17153         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17154         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17155         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17156         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17157         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17158         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17159         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17160         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17161         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17162         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17163         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17164         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17165         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17166         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17167         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17168         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17169         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17170         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17171         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17172         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17173         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17174         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17175         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17176         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17177         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17178 #ifdef RTE_LIB_BPF
17179         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17180         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17181 #endif
17182         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17183         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17184         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17185         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
17186         (cmdline_parse_inst_t *)&cmd_set_raw,
17187         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17188         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17189         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17190         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17191         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17192         (cmdline_parse_inst_t *)&cmd_show_capability,
17193         NULL,
17194 };
17195
17196 /* read cmdline commands from file */
17197 void
17198 cmdline_read_from_file(const char *filename)
17199 {
17200         struct cmdline *cl;
17201
17202         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17203         if (cl == NULL) {
17204                 printf("Failed to create file based cmdline context: %s\n",
17205                        filename);
17206                 return;
17207         }
17208
17209         cmdline_interact(cl);
17210         cmdline_quit(cl);
17211
17212         cmdline_free(cl);
17213
17214         printf("Read CLI commands from %s\n", filename);
17215 }
17216
17217 /* prompt function, called from main on MAIN lcore */
17218 void
17219 prompt(void)
17220 {
17221         int ret;
17222         /* initialize non-constant commands */
17223         cmd_set_fwd_mode_init();
17224         cmd_set_fwd_retry_mode_init();
17225
17226         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17227         if (testpmd_cl == NULL)
17228                 return;
17229
17230         ret = atexit(prompt_exit);
17231         if (ret != 0)
17232                 printf("Cannot set exit function for cmdline\n");
17233
17234         cmdline_interact(testpmd_cl);
17235         if (ret != 0)
17236                 cmdline_stdin_exit(testpmd_cl);
17237 }
17238
17239 void
17240 prompt_exit(void)
17241 {
17242         if (testpmd_cl != NULL) {
17243                 cmdline_quit(testpmd_cl);
17244                 cmdline_stdin_exit(testpmd_cl);
17245         }
17246 }
17247
17248 static void
17249 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17250 {
17251         if (id == (portid_t)RTE_PORT_ALL) {
17252                 portid_t pid;
17253
17254                 RTE_ETH_FOREACH_DEV(pid) {
17255                         /* check if need_reconfig has been set to 1 */
17256                         if (ports[pid].need_reconfig == 0)
17257                                 ports[pid].need_reconfig = dev;
17258                         /* check if need_reconfig_queues has been set to 1 */
17259                         if (ports[pid].need_reconfig_queues == 0)
17260                                 ports[pid].need_reconfig_queues = queue;
17261                 }
17262         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17263                 /* check if need_reconfig has been set to 1 */
17264                 if (ports[id].need_reconfig == 0)
17265                         ports[id].need_reconfig = dev;
17266                 /* check if need_reconfig_queues has been set to 1 */
17267                 if (ports[id].need_reconfig_queues == 0)
17268                         ports[id].need_reconfig_queues = queue;
17269         }
17270 }