app/testpmd: support policy actions per color
[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) (policy_id) (meter_enable)\n"
709                         "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
710                         "(dscp_tbl_entry63)]\n"
711                         "    meter create\n\n"
712
713                         "enable port meter (port_id) (mtr_id)\n"
714                         "    meter enable\n\n"
715
716                         "disable port meter (port_id) (mtr_id)\n"
717                         "    meter disable\n\n"
718
719                         "del port meter (port_id) (mtr_id)\n"
720                         "    meter delete\n\n"
721
722                         "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
723                         "y_actions (actions) r_actions (actions)\n"
724                         "    meter policy add\n\n"
725
726                         "del port meter policy (port_id) (policy_id)\n"
727                         "    meter policy delete\n\n"
728
729                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
730                         "    meter update meter profile\n\n"
731
732                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
733                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
734                         "    update meter dscp table entries\n\n"
735
736                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
737                         "(action0) [(action1) (action2)]\n"
738                         "    meter update policer action\n\n"
739
740                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
741                         "    meter update stats\n\n"
742
743                         "show port (port_id) queue-region\n"
744                         "    show all queue region related configuration info\n\n"
745
746                         "set port (port_id) fec_mode auto|off|rs|baser\n"
747                         "    set fec mode for a specific port\n\n"
748
749                         , list_pkt_forwarding_modes()
750                 );
751         }
752
753         if (show_all || !strcmp(res->section, "ports")) {
754
755                 cmdline_printf(
756                         cl,
757                         "\n"
758                         "Port Operations:\n"
759                         "----------------\n\n"
760
761                         "port start (port_id|all)\n"
762                         "    Start all ports or port_id.\n\n"
763
764                         "port stop (port_id|all)\n"
765                         "    Stop all ports or port_id.\n\n"
766
767                         "port close (port_id|all)\n"
768                         "    Close all ports or port_id.\n\n"
769
770                         "port reset (port_id|all)\n"
771                         "    Reset all ports or port_id.\n\n"
772
773                         "port attach (ident)\n"
774                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
775
776                         "port detach (port_id)\n"
777                         "    Detach physical or virtual dev by port_id\n\n"
778
779                         "port config (port_id|all)"
780                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
781                         " duplex (half|full|auto)\n"
782                         "    Set speed and duplex for all ports or port_id\n\n"
783
784                         "port config (port_id|all) loopback (mode)\n"
785                         "    Set loopback mode for all ports or port_id\n\n"
786
787                         "port config all (rxq|txq|rxd|txd) (value)\n"
788                         "    Set number for rxq/txq/rxd/txd.\n\n"
789
790                         "port config all max-pkt-len (value)\n"
791                         "    Set the max packet length.\n\n"
792
793                         "port config all max-lro-pkt-size (value)\n"
794                         "    Set the max LRO aggregated packet size.\n\n"
795
796                         "port config all drop-en (on|off)\n"
797                         "    Enable or disable packet drop on all RX queues of all ports when no "
798                         "receive buffers available.\n\n"
799
800                         "port config all rss (all|default|ip|tcp|udp|sctp|"
801                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|none|level-default|"
802                         "level-outer|level-inner|<flowtype_id>)\n"
803                         "    Set the RSS mode.\n\n"
804
805                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
806                         "    Set the RSS redirection table.\n\n"
807
808                         "port config (port_id) dcb vt (on|off) (traffic_class)"
809                         " pfc (on|off)\n"
810                         "    Set the DCB mode.\n\n"
811
812                         "port config all burst (value)\n"
813                         "    Set the number of packets per burst.\n\n"
814
815                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
816                         " (value)\n"
817                         "    Set the ring prefetch/host/writeback threshold"
818                         " for tx/rx queue.\n\n"
819
820                         "port config all (txfreet|txrst|rxfreet) (value)\n"
821                         "    Set free threshold for rx/tx, or set"
822                         " tx rs bit threshold.\n\n"
823                         "port config mtu X value\n"
824                         "    Set the MTU of port X to a given value\n\n"
825
826                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
827                         "    Set a rx/tx queue's ring size configuration, the new"
828                         " value will take effect after command that (re-)start the port"
829                         " or command that setup the specific queue\n\n"
830
831                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
832                         "    Start/stop a rx/tx queue of port X. Only take effect"
833                         " when port X is started\n\n"
834
835                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
836                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
837                         " take effect when port X is stopped.\n\n"
838
839                         "port (port_id) (rxq|txq) (queue_id) setup\n"
840                         "    Setup a rx/tx queue of port X.\n\n"
841
842                         "port config (port_id) pctype mapping reset\n"
843                         "    Reset flow type to pctype mapping on a port\n\n"
844
845                         "port config (port_id) pctype mapping update"
846                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
847                         "    Update a flow type to pctype mapping item on a port\n\n"
848
849                         "port config (port_id) pctype (pctype_id) hash_inset|"
850                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
851                         " (field_idx)\n"
852                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
853
854                         "port config (port_id) pctype (pctype_id) hash_inset|"
855                         "fdir_inset|fdir_flx_inset clear all"
856                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
857
858                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
859                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
860
861                         "port config <port_id> rx_offload vlan_strip|"
862                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
863                         "outer_ipv4_cksum|macsec_strip|header_split|"
864                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
865                         "buffer_split|timestamp|security|keep_crc on|off\n"
866                         "     Enable or disable a per port Rx offloading"
867                         " on all Rx queues of a port\n\n"
868
869                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
870                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
871                         "outer_ipv4_cksum|macsec_strip|header_split|"
872                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
873                         "buffer_split|timestamp|security|keep_crc on|off\n"
874                         "    Enable or disable a per queue Rx offloading"
875                         " only on a specific Rx queue\n\n"
876
877                         "port config (port_id) tx_offload vlan_insert|"
878                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
879                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
880                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
881                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
882                         "security on|off\n"
883                         "    Enable or disable a per port Tx offloading"
884                         " on all Tx queues of a port\n\n"
885
886                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
887                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
888                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
889                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
890                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
891                         " on|off\n"
892                         "    Enable or disable a per queue Tx offloading"
893                         " only on a specific Tx queue\n\n"
894
895                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
896                         "    Load an eBPF program as a callback"
897                         " for particular RX/TX queue\n\n"
898
899                         "bpf-unload rx|tx (port) (queue)\n"
900                         "    Unload previously loaded eBPF program"
901                         " for particular RX/TX queue\n\n"
902
903                         "port config (port_id) tx_metadata (value)\n"
904                         "    Set Tx metadata value per port. Testpmd will add this value"
905                         " to any Tx packet sent from this port\n\n"
906
907                         "port config (port_id) dynf (name) set|clear\n"
908                         "    Register a dynf and Set/clear this flag on Tx. "
909                         "Testpmd will set this value to any Tx packet "
910                         "sent from this port\n\n"
911                 );
912         }
913
914         if (show_all || !strcmp(res->section, "registers")) {
915
916                 cmdline_printf(
917                         cl,
918                         "\n"
919                         "Registers:\n"
920                         "----------\n\n"
921
922                         "read reg (port_id) (address)\n"
923                         "    Display value of a port register.\n\n"
924
925                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
926                         "    Display a port register bit field.\n\n"
927
928                         "read regbit (port_id) (address) (bit_x)\n"
929                         "    Display a single port register bit.\n\n"
930
931                         "write reg (port_id) (address) (value)\n"
932                         "    Set value of a port register.\n\n"
933
934                         "write regfield (port_id) (address) (bit_x) (bit_y)"
935                         " (value)\n"
936                         "    Set bit field of a port register.\n\n"
937
938                         "write regbit (port_id) (address) (bit_x) (value)\n"
939                         "    Set single bit value of a port register.\n\n"
940                 );
941         }
942         if (show_all || !strcmp(res->section, "filters")) {
943
944                 cmdline_printf(
945                         cl,
946                         "\n"
947                         "filters:\n"
948                         "--------\n\n"
949
950 #ifdef RTE_NET_I40E
951                         "flow_director_filter (port_id) mode raw (add|del|update)"
952                         " flow (flow_id) (drop|fwd) queue (queue_id)"
953                         " fd_id (fd_id_value) packet (packet file name)\n"
954                         "    Add/Del a raw type flow director filter.\n\n"
955 #endif
956
957                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
958                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
959                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
960                         "    Set flow director IP mask.\n\n"
961
962                         "flow_director_mask (port_id) mode MAC-VLAN"
963                         " vlan (vlan_value)\n"
964                         "    Set flow director MAC-VLAN mask.\n\n"
965
966                         "flow_director_mask (port_id) mode Tunnel"
967                         " vlan (vlan_value) mac (mac_value)"
968                         " tunnel-type (tunnel_type_value)"
969                         " tunnel-id (tunnel_id_value)\n"
970                         "    Set flow director Tunnel mask.\n\n"
971
972                         "flow_director_flex_payload (port_id)"
973                         " (raw|l2|l3|l4) (config)\n"
974                         "    Configure flex payload selection.\n\n"
975
976                         "flow validate {port_id}"
977                         " [group {group_id}] [priority {level}]"
978                         " [ingress] [egress]"
979                         " pattern {item} [/ {item} [...]] / end"
980                         " actions {action} [/ {action} [...]] / end\n"
981                         "    Check whether a flow rule can be created.\n\n"
982
983                         "flow create {port_id}"
984                         " [group {group_id}] [priority {level}]"
985                         " [ingress] [egress]"
986                         " pattern {item} [/ {item} [...]] / end"
987                         " actions {action} [/ {action} [...]] / end\n"
988                         "    Create a flow rule.\n\n"
989
990                         "flow destroy {port_id} rule {rule_id} [...]\n"
991                         "    Destroy specific flow rules.\n\n"
992
993                         "flow flush {port_id}\n"
994                         "    Destroy all flow rules.\n\n"
995
996                         "flow query {port_id} {rule_id} {action}\n"
997                         "    Query an existing flow rule.\n\n"
998
999                         "flow list {port_id} [group {group_id}] [...]\n"
1000                         "    List existing flow rules sorted by priority,"
1001                         " filtered by group identifiers.\n\n"
1002
1003                         "flow isolate {port_id} {boolean}\n"
1004                         "    Restrict ingress traffic to the defined"
1005                         " flow rules\n\n"
1006
1007                         "flow aged {port_id} [destroy]\n"
1008                         "    List and destroy aged flows"
1009                         " flow rules\n\n"
1010
1011                         "flow indirect_action {port_id} create"
1012                         " [action_id {indirect_action_id}]"
1013                         " [ingress] [egress]"
1014                         " action {action} / end\n"
1015                         "    Create indirect action.\n\n"
1016
1017                         "flow indirect_action {port_id} update"
1018                         " {indirect_action_id} action {action} / end\n"
1019                         "    Update indirect action.\n\n"
1020
1021                         "flow indirect_action {port_id} destroy"
1022                         " action_id {indirect_action_id} [...]\n"
1023                         "    Destroy specific indirect actions.\n\n"
1024
1025                         "flow indirect_action {port_id} query"
1026                         " {indirect_action_id}\n"
1027                         "    Query an existing indirect action.\n\n"
1028
1029                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1030                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1031                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1032                         "       Configure the VXLAN encapsulation for flows.\n\n"
1033
1034                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1035                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1036                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1037                         " eth-dst (eth-dst)\n"
1038                         "       Configure the VXLAN encapsulation for flows.\n\n"
1039
1040                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1041                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1042                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1043                         " eth-dst (eth-dst)\n"
1044                         "       Configure the VXLAN encapsulation for flows.\n\n"
1045
1046                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1047                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1048                         " (eth-dst)\n"
1049                         "       Configure the NVGRE encapsulation for flows.\n\n"
1050
1051                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1052                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1053                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1054                         "       Configure the NVGRE encapsulation for flows.\n\n"
1055
1056                         "set raw_encap {flow items}\n"
1057                         "       Configure the encapsulation with raw data.\n\n"
1058
1059                         "set raw_decap {flow items}\n"
1060                         "       Configure the decapsulation with raw data.\n\n"
1061
1062                 );
1063         }
1064
1065         if (show_all || !strcmp(res->section, "traffic_management")) {
1066                 cmdline_printf(
1067                         cl,
1068                         "\n"
1069                         "Traffic Management:\n"
1070                         "--------------\n"
1071                         "show port tm cap (port_id)\n"
1072                         "       Display the port TM capability.\n\n"
1073
1074                         "show port tm level cap (port_id) (level_id)\n"
1075                         "       Display the port TM hierarchical level capability.\n\n"
1076
1077                         "show port tm node cap (port_id) (node_id)\n"
1078                         "       Display the port TM node capability.\n\n"
1079
1080                         "show port tm node type (port_id) (node_id)\n"
1081                         "       Display the port TM node type.\n\n"
1082
1083                         "show port tm node stats (port_id) (node_id) (clear)\n"
1084                         "       Display the port TM node stats.\n\n"
1085
1086                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1087                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1088                         " (packet_length_adjust) (packet_mode)\n"
1089                         "       Add port tm node private shaper profile.\n\n"
1090
1091                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1092                         "       Delete port tm node private shaper profile.\n\n"
1093
1094                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1095                         " (shaper_profile_id)\n"
1096                         "       Add/update port tm node shared shaper.\n\n"
1097
1098                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1099                         "       Delete port tm node shared shaper.\n\n"
1100
1101                         "set port tm node shaper profile (port_id) (node_id)"
1102                         " (shaper_profile_id)\n"
1103                         "       Set port tm node shaper profile.\n\n"
1104
1105                         "add port tm node wred profile (port_id) (wred_profile_id)"
1106                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1107                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1108                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1109                         "       Add port tm node wred profile.\n\n"
1110
1111                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1112                         "       Delete port tm node wred profile.\n\n"
1113
1114                         "add port tm nonleaf node (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.\n\n"
1119
1120                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1121                         " (priority) (weight) (level_id) (shaper_profile_id)"
1122                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1123                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1124                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1125
1126                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1127                         " (priority) (weight) (level_id) (shaper_profile_id)"
1128                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1129                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1130                         "       Add port tm leaf node.\n\n"
1131
1132                         "del port tm node (port_id) (node_id)\n"
1133                         "       Delete port tm node.\n\n"
1134
1135                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1136                         " (priority) (weight)\n"
1137                         "       Set port tm node parent.\n\n"
1138
1139                         "suspend port tm node (port_id) (node_id)"
1140                         "       Suspend tm node.\n\n"
1141
1142                         "resume port tm node (port_id) (node_id)"
1143                         "       Resume tm node.\n\n"
1144
1145                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1146                         "       Commit tm hierarchy.\n\n"
1147
1148                         "set port tm mark ip_ecn (port) (green) (yellow)"
1149                         " (red)\n"
1150                         "    Enables/Disables the traffic management marking"
1151                         " for IP ECN (Explicit Congestion Notification)"
1152                         " packets on a given port\n\n"
1153
1154                         "set port tm mark ip_dscp (port) (green) (yellow)"
1155                         " (red)\n"
1156                         "    Enables/Disables the traffic management marking"
1157                         " on the port for IP dscp packets\n\n"
1158
1159                         "set port tm mark vlan_dei (port) (green) (yellow)"
1160                         " (red)\n"
1161                         "    Enables/Disables the traffic management marking"
1162                         " on the port for VLAN packets with DEI enabled\n\n"
1163                 );
1164         }
1165
1166         if (show_all || !strcmp(res->section, "devices")) {
1167                 cmdline_printf(
1168                         cl,
1169                         "\n"
1170                         "Device Operations:\n"
1171                         "--------------\n"
1172                         "device detach (identifier)\n"
1173                         "       Detach device by identifier.\n\n"
1174                 );
1175         }
1176
1177 }
1178
1179 cmdline_parse_token_string_t cmd_help_long_help =
1180         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1181
1182 cmdline_parse_token_string_t cmd_help_long_section =
1183         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1184                         "all#control#display#config#"
1185                         "ports#registers#filters#traffic_management#devices");
1186
1187 cmdline_parse_inst_t cmd_help_long = {
1188         .f = cmd_help_long_parsed,
1189         .data = NULL,
1190         .help_str = "help all|control|display|config|ports|register|"
1191                 "filters|traffic_management|devices: "
1192                 "Show help",
1193         .tokens = {
1194                 (void *)&cmd_help_long_help,
1195                 (void *)&cmd_help_long_section,
1196                 NULL,
1197         },
1198 };
1199
1200
1201 /* *** start/stop/close all ports *** */
1202 struct cmd_operate_port_result {
1203         cmdline_fixed_string_t keyword;
1204         cmdline_fixed_string_t name;
1205         cmdline_fixed_string_t value;
1206 };
1207
1208 static void cmd_operate_port_parsed(void *parsed_result,
1209                                 __rte_unused struct cmdline *cl,
1210                                 __rte_unused void *data)
1211 {
1212         struct cmd_operate_port_result *res = parsed_result;
1213
1214         if (!strcmp(res->name, "start"))
1215                 start_port(RTE_PORT_ALL);
1216         else if (!strcmp(res->name, "stop"))
1217                 stop_port(RTE_PORT_ALL);
1218         else if (!strcmp(res->name, "close"))
1219                 close_port(RTE_PORT_ALL);
1220         else if (!strcmp(res->name, "reset"))
1221                 reset_port(RTE_PORT_ALL);
1222         else
1223                 printf("Unknown parameter\n");
1224 }
1225
1226 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1227         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1228                                                                 "port");
1229 cmdline_parse_token_string_t cmd_operate_port_all_port =
1230         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1231                                                 "start#stop#close#reset");
1232 cmdline_parse_token_string_t cmd_operate_port_all_all =
1233         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1234
1235 cmdline_parse_inst_t cmd_operate_port = {
1236         .f = cmd_operate_port_parsed,
1237         .data = NULL,
1238         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1239         .tokens = {
1240                 (void *)&cmd_operate_port_all_cmd,
1241                 (void *)&cmd_operate_port_all_port,
1242                 (void *)&cmd_operate_port_all_all,
1243                 NULL,
1244         },
1245 };
1246
1247 /* *** start/stop/close specific port *** */
1248 struct cmd_operate_specific_port_result {
1249         cmdline_fixed_string_t keyword;
1250         cmdline_fixed_string_t name;
1251         uint8_t value;
1252 };
1253
1254 static void cmd_operate_specific_port_parsed(void *parsed_result,
1255                         __rte_unused struct cmdline *cl,
1256                                 __rte_unused void *data)
1257 {
1258         struct cmd_operate_specific_port_result *res = parsed_result;
1259
1260         if (!strcmp(res->name, "start"))
1261                 start_port(res->value);
1262         else if (!strcmp(res->name, "stop"))
1263                 stop_port(res->value);
1264         else if (!strcmp(res->name, "close"))
1265                 close_port(res->value);
1266         else if (!strcmp(res->name, "reset"))
1267                 reset_port(res->value);
1268         else
1269                 printf("Unknown parameter\n");
1270 }
1271
1272 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1273         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1274                                                         keyword, "port");
1275 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1277                                                 name, "start#stop#close#reset");
1278 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1279         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1280                                                         value, RTE_UINT8);
1281
1282 cmdline_parse_inst_t cmd_operate_specific_port = {
1283         .f = cmd_operate_specific_port_parsed,
1284         .data = NULL,
1285         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1286         .tokens = {
1287                 (void *)&cmd_operate_specific_port_cmd,
1288                 (void *)&cmd_operate_specific_port_port,
1289                 (void *)&cmd_operate_specific_port_id,
1290                 NULL,
1291         },
1292 };
1293
1294 /* *** enable port setup (after attach) via iterator or event *** */
1295 struct cmd_set_port_setup_on_result {
1296         cmdline_fixed_string_t set;
1297         cmdline_fixed_string_t port;
1298         cmdline_fixed_string_t setup;
1299         cmdline_fixed_string_t on;
1300         cmdline_fixed_string_t mode;
1301 };
1302
1303 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1304                                 __rte_unused struct cmdline *cl,
1305                                 __rte_unused void *data)
1306 {
1307         struct cmd_set_port_setup_on_result *res = parsed_result;
1308
1309         if (strcmp(res->mode, "event") == 0)
1310                 setup_on_probe_event = true;
1311         else if (strcmp(res->mode, "iterator") == 0)
1312                 setup_on_probe_event = false;
1313         else
1314                 printf("Unknown mode\n");
1315 }
1316
1317 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1318         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1319                         set, "set");
1320 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1321         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1322                         port, "port");
1323 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1324         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1325                         setup, "setup");
1326 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1327         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1328                         on, "on");
1329 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1330         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1331                         mode, "iterator#event");
1332
1333 cmdline_parse_inst_t cmd_set_port_setup_on = {
1334         .f = cmd_set_port_setup_on_parsed,
1335         .data = NULL,
1336         .help_str = "set port setup on iterator|event",
1337         .tokens = {
1338                 (void *)&cmd_set_port_setup_on_set,
1339                 (void *)&cmd_set_port_setup_on_port,
1340                 (void *)&cmd_set_port_setup_on_setup,
1341                 (void *)&cmd_set_port_setup_on_on,
1342                 (void *)&cmd_set_port_setup_on_mode,
1343                 NULL,
1344         },
1345 };
1346
1347 /* *** attach a specified port *** */
1348 struct cmd_operate_attach_port_result {
1349         cmdline_fixed_string_t port;
1350         cmdline_fixed_string_t keyword;
1351         cmdline_multi_string_t identifier;
1352 };
1353
1354 static void cmd_operate_attach_port_parsed(void *parsed_result,
1355                                 __rte_unused struct cmdline *cl,
1356                                 __rte_unused void *data)
1357 {
1358         struct cmd_operate_attach_port_result *res = parsed_result;
1359
1360         if (!strcmp(res->keyword, "attach"))
1361                 attach_port(res->identifier);
1362         else
1363                 printf("Unknown parameter\n");
1364 }
1365
1366 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1367         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1368                         port, "port");
1369 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1370         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1371                         keyword, "attach");
1372 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1373         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1374                         identifier, TOKEN_STRING_MULTI);
1375
1376 cmdline_parse_inst_t cmd_operate_attach_port = {
1377         .f = cmd_operate_attach_port_parsed,
1378         .data = NULL,
1379         .help_str = "port attach <identifier>: "
1380                 "(identifier: pci address or virtual dev name)",
1381         .tokens = {
1382                 (void *)&cmd_operate_attach_port_port,
1383                 (void *)&cmd_operate_attach_port_keyword,
1384                 (void *)&cmd_operate_attach_port_identifier,
1385                 NULL,
1386         },
1387 };
1388
1389 /* *** detach a specified port *** */
1390 struct cmd_operate_detach_port_result {
1391         cmdline_fixed_string_t port;
1392         cmdline_fixed_string_t keyword;
1393         portid_t port_id;
1394 };
1395
1396 static void cmd_operate_detach_port_parsed(void *parsed_result,
1397                                 __rte_unused struct cmdline *cl,
1398                                 __rte_unused void *data)
1399 {
1400         struct cmd_operate_detach_port_result *res = parsed_result;
1401
1402         if (!strcmp(res->keyword, "detach")) {
1403                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1404                 detach_port_device(res->port_id);
1405         } else {
1406                 printf("Unknown parameter\n");
1407         }
1408 }
1409
1410 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1411         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1412                         port, "port");
1413 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1414         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1415                         keyword, "detach");
1416 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1417         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1418                         port_id, RTE_UINT16);
1419
1420 cmdline_parse_inst_t cmd_operate_detach_port = {
1421         .f = cmd_operate_detach_port_parsed,
1422         .data = NULL,
1423         .help_str = "port detach <port_id>",
1424         .tokens = {
1425                 (void *)&cmd_operate_detach_port_port,
1426                 (void *)&cmd_operate_detach_port_keyword,
1427                 (void *)&cmd_operate_detach_port_port_id,
1428                 NULL,
1429         },
1430 };
1431
1432 /* *** detach device by identifier *** */
1433 struct cmd_operate_detach_device_result {
1434         cmdline_fixed_string_t device;
1435         cmdline_fixed_string_t keyword;
1436         cmdline_fixed_string_t identifier;
1437 };
1438
1439 static void cmd_operate_detach_device_parsed(void *parsed_result,
1440                                 __rte_unused struct cmdline *cl,
1441                                 __rte_unused void *data)
1442 {
1443         struct cmd_operate_detach_device_result *res = parsed_result;
1444
1445         if (!strcmp(res->keyword, "detach"))
1446                 detach_devargs(res->identifier);
1447         else
1448                 printf("Unknown parameter\n");
1449 }
1450
1451 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1452         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1453                         device, "device");
1454 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1455         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1456                         keyword, "detach");
1457 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1458         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1459                         identifier, NULL);
1460
1461 cmdline_parse_inst_t cmd_operate_detach_device = {
1462         .f = cmd_operate_detach_device_parsed,
1463         .data = NULL,
1464         .help_str = "device detach <identifier>:"
1465                 "(identifier: pci address or virtual dev name)",
1466         .tokens = {
1467                 (void *)&cmd_operate_detach_device_device,
1468                 (void *)&cmd_operate_detach_device_keyword,
1469                 (void *)&cmd_operate_detach_device_identifier,
1470                 NULL,
1471         },
1472 };
1473 /* *** configure speed for all ports *** */
1474 struct cmd_config_speed_all {
1475         cmdline_fixed_string_t port;
1476         cmdline_fixed_string_t keyword;
1477         cmdline_fixed_string_t all;
1478         cmdline_fixed_string_t item1;
1479         cmdline_fixed_string_t item2;
1480         cmdline_fixed_string_t value1;
1481         cmdline_fixed_string_t value2;
1482 };
1483
1484 static int
1485 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1486 {
1487
1488         int duplex;
1489
1490         if (!strcmp(duplexstr, "half")) {
1491                 duplex = ETH_LINK_HALF_DUPLEX;
1492         } else if (!strcmp(duplexstr, "full")) {
1493                 duplex = ETH_LINK_FULL_DUPLEX;
1494         } else if (!strcmp(duplexstr, "auto")) {
1495                 duplex = ETH_LINK_FULL_DUPLEX;
1496         } else {
1497                 printf("Unknown duplex parameter\n");
1498                 return -1;
1499         }
1500
1501         if (!strcmp(speedstr, "10")) {
1502                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1503                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1504         } else if (!strcmp(speedstr, "100")) {
1505                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1506                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1507         } else {
1508                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1509                         printf("Invalid speed/duplex parameters\n");
1510                         return -1;
1511                 }
1512                 if (!strcmp(speedstr, "1000")) {
1513                         *speed = ETH_LINK_SPEED_1G;
1514                 } else if (!strcmp(speedstr, "10000")) {
1515                         *speed = ETH_LINK_SPEED_10G;
1516                 } else if (!strcmp(speedstr, "25000")) {
1517                         *speed = ETH_LINK_SPEED_25G;
1518                 } else if (!strcmp(speedstr, "40000")) {
1519                         *speed = ETH_LINK_SPEED_40G;
1520                 } else if (!strcmp(speedstr, "50000")) {
1521                         *speed = ETH_LINK_SPEED_50G;
1522                 } else if (!strcmp(speedstr, "100000")) {
1523                         *speed = ETH_LINK_SPEED_100G;
1524                 } else if (!strcmp(speedstr, "200000")) {
1525                         *speed = ETH_LINK_SPEED_200G;
1526                 } else if (!strcmp(speedstr, "auto")) {
1527                         *speed = ETH_LINK_SPEED_AUTONEG;
1528                 } else {
1529                         printf("Unknown speed parameter\n");
1530                         return -1;
1531                 }
1532         }
1533
1534         if (*speed != ETH_LINK_SPEED_AUTONEG)
1535                 *speed |= ETH_LINK_SPEED_FIXED;
1536
1537         return 0;
1538 }
1539
1540 static void
1541 cmd_config_speed_all_parsed(void *parsed_result,
1542                         __rte_unused struct cmdline *cl,
1543                         __rte_unused void *data)
1544 {
1545         struct cmd_config_speed_all *res = parsed_result;
1546         uint32_t link_speed;
1547         portid_t pid;
1548
1549         if (!all_ports_stopped()) {
1550                 printf("Please stop all ports first\n");
1551                 return;
1552         }
1553
1554         if (parse_and_check_speed_duplex(res->value1, res->value2,
1555                         &link_speed) < 0)
1556                 return;
1557
1558         RTE_ETH_FOREACH_DEV(pid) {
1559                 ports[pid].dev_conf.link_speeds = link_speed;
1560         }
1561
1562         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1563 }
1564
1565 cmdline_parse_token_string_t cmd_config_speed_all_port =
1566         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1567 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1568         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1569                                                         "config");
1570 cmdline_parse_token_string_t cmd_config_speed_all_all =
1571         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1572 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1573         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1574 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1575         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1576                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1577 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1578         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1579 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1580         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1581                                                 "half#full#auto");
1582
1583 cmdline_parse_inst_t cmd_config_speed_all = {
1584         .f = cmd_config_speed_all_parsed,
1585         .data = NULL,
1586         .help_str = "port config all speed "
1587                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1588                                                         "half|full|auto",
1589         .tokens = {
1590                 (void *)&cmd_config_speed_all_port,
1591                 (void *)&cmd_config_speed_all_keyword,
1592                 (void *)&cmd_config_speed_all_all,
1593                 (void *)&cmd_config_speed_all_item1,
1594                 (void *)&cmd_config_speed_all_value1,
1595                 (void *)&cmd_config_speed_all_item2,
1596                 (void *)&cmd_config_speed_all_value2,
1597                 NULL,
1598         },
1599 };
1600
1601 /* *** configure speed for specific port *** */
1602 struct cmd_config_speed_specific {
1603         cmdline_fixed_string_t port;
1604         cmdline_fixed_string_t keyword;
1605         portid_t id;
1606         cmdline_fixed_string_t item1;
1607         cmdline_fixed_string_t item2;
1608         cmdline_fixed_string_t value1;
1609         cmdline_fixed_string_t value2;
1610 };
1611
1612 static void
1613 cmd_config_speed_specific_parsed(void *parsed_result,
1614                                 __rte_unused struct cmdline *cl,
1615                                 __rte_unused void *data)
1616 {
1617         struct cmd_config_speed_specific *res = parsed_result;
1618         uint32_t link_speed;
1619
1620         if (!all_ports_stopped()) {
1621                 printf("Please stop all ports first\n");
1622                 return;
1623         }
1624
1625         if (port_id_is_invalid(res->id, ENABLED_WARN))
1626                 return;
1627
1628         if (parse_and_check_speed_duplex(res->value1, res->value2,
1629                         &link_speed) < 0)
1630                 return;
1631
1632         ports[res->id].dev_conf.link_speeds = link_speed;
1633
1634         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1635 }
1636
1637
1638 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1639         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1640                                                                 "port");
1641 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1642         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1643                                                                 "config");
1644 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1645         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1646 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1648                                                                 "speed");
1649 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1650         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1651                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1652 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1653         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1654                                                                 "duplex");
1655 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1657                                                         "half#full#auto");
1658
1659 cmdline_parse_inst_t cmd_config_speed_specific = {
1660         .f = cmd_config_speed_specific_parsed,
1661         .data = NULL,
1662         .help_str = "port config <port_id> speed "
1663                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1664                                                         "half|full|auto",
1665         .tokens = {
1666                 (void *)&cmd_config_speed_specific_port,
1667                 (void *)&cmd_config_speed_specific_keyword,
1668                 (void *)&cmd_config_speed_specific_id,
1669                 (void *)&cmd_config_speed_specific_item1,
1670                 (void *)&cmd_config_speed_specific_value1,
1671                 (void *)&cmd_config_speed_specific_item2,
1672                 (void *)&cmd_config_speed_specific_value2,
1673                 NULL,
1674         },
1675 };
1676
1677 /* *** configure loopback for all ports *** */
1678 struct cmd_config_loopback_all {
1679         cmdline_fixed_string_t port;
1680         cmdline_fixed_string_t keyword;
1681         cmdline_fixed_string_t all;
1682         cmdline_fixed_string_t item;
1683         uint32_t mode;
1684 };
1685
1686 static void
1687 cmd_config_loopback_all_parsed(void *parsed_result,
1688                         __rte_unused struct cmdline *cl,
1689                         __rte_unused void *data)
1690 {
1691         struct cmd_config_loopback_all *res = parsed_result;
1692         portid_t pid;
1693
1694         if (!all_ports_stopped()) {
1695                 printf("Please stop all ports first\n");
1696                 return;
1697         }
1698
1699         RTE_ETH_FOREACH_DEV(pid) {
1700                 ports[pid].dev_conf.lpbk_mode = res->mode;
1701         }
1702
1703         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1704 }
1705
1706 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1707         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1708 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1709         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1710                                                         "config");
1711 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1712         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1713 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1714         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1715                                                         "loopback");
1716 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1717         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1718
1719 cmdline_parse_inst_t cmd_config_loopback_all = {
1720         .f = cmd_config_loopback_all_parsed,
1721         .data = NULL,
1722         .help_str = "port config all loopback <mode>",
1723         .tokens = {
1724                 (void *)&cmd_config_loopback_all_port,
1725                 (void *)&cmd_config_loopback_all_keyword,
1726                 (void *)&cmd_config_loopback_all_all,
1727                 (void *)&cmd_config_loopback_all_item,
1728                 (void *)&cmd_config_loopback_all_mode,
1729                 NULL,
1730         },
1731 };
1732
1733 /* *** configure loopback for specific port *** */
1734 struct cmd_config_loopback_specific {
1735         cmdline_fixed_string_t port;
1736         cmdline_fixed_string_t keyword;
1737         uint16_t port_id;
1738         cmdline_fixed_string_t item;
1739         uint32_t mode;
1740 };
1741
1742 static void
1743 cmd_config_loopback_specific_parsed(void *parsed_result,
1744                                 __rte_unused struct cmdline *cl,
1745                                 __rte_unused void *data)
1746 {
1747         struct cmd_config_loopback_specific *res = parsed_result;
1748
1749         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1750                 return;
1751
1752         if (!port_is_stopped(res->port_id)) {
1753                 printf("Please stop port %u first\n", res->port_id);
1754                 return;
1755         }
1756
1757         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1758
1759         cmd_reconfig_device_queue(res->port_id, 1, 1);
1760 }
1761
1762
1763 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1764         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1765                                                                 "port");
1766 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1767         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1768                                                                 "config");
1769 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1770         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1771                                                                 RTE_UINT16);
1772 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1773         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1774                                                                 "loopback");
1775 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1776         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1777                               RTE_UINT32);
1778
1779 cmdline_parse_inst_t cmd_config_loopback_specific = {
1780         .f = cmd_config_loopback_specific_parsed,
1781         .data = NULL,
1782         .help_str = "port config <port_id> loopback <mode>",
1783         .tokens = {
1784                 (void *)&cmd_config_loopback_specific_port,
1785                 (void *)&cmd_config_loopback_specific_keyword,
1786                 (void *)&cmd_config_loopback_specific_id,
1787                 (void *)&cmd_config_loopback_specific_item,
1788                 (void *)&cmd_config_loopback_specific_mode,
1789                 NULL,
1790         },
1791 };
1792
1793 /* *** configure txq/rxq, txd/rxd *** */
1794 struct cmd_config_rx_tx {
1795         cmdline_fixed_string_t port;
1796         cmdline_fixed_string_t keyword;
1797         cmdline_fixed_string_t all;
1798         cmdline_fixed_string_t name;
1799         uint16_t value;
1800 };
1801
1802 static void
1803 cmd_config_rx_tx_parsed(void *parsed_result,
1804                         __rte_unused struct cmdline *cl,
1805                         __rte_unused void *data)
1806 {
1807         struct cmd_config_rx_tx *res = parsed_result;
1808
1809         if (!all_ports_stopped()) {
1810                 printf("Please stop all ports first\n");
1811                 return;
1812         }
1813         if (!strcmp(res->name, "rxq")) {
1814                 if (!res->value && !nb_txq) {
1815                         printf("Warning: Either rx or tx queues should be non zero\n");
1816                         return;
1817                 }
1818                 if (check_nb_rxq(res->value) != 0)
1819                         return;
1820                 nb_rxq = res->value;
1821         }
1822         else if (!strcmp(res->name, "txq")) {
1823                 if (!res->value && !nb_rxq) {
1824                         printf("Warning: Either rx or tx queues should be non zero\n");
1825                         return;
1826                 }
1827                 if (check_nb_txq(res->value) != 0)
1828                         return;
1829                 nb_txq = res->value;
1830         }
1831         else if (!strcmp(res->name, "rxd")) {
1832                 if (check_nb_rxd(res->value) != 0)
1833                         return;
1834                 nb_rxd = res->value;
1835         } else if (!strcmp(res->name, "txd")) {
1836                 if (check_nb_txd(res->value) != 0)
1837                         return;
1838
1839                 nb_txd = res->value;
1840         } else {
1841                 printf("Unknown parameter\n");
1842                 return;
1843         }
1844
1845         fwd_config_setup();
1846
1847         init_port_config();
1848
1849         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1850 }
1851
1852 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1853         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1854 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1855         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1856 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1857         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1858 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1859         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1860                                                 "rxq#txq#rxd#txd");
1861 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1862         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1863
1864 cmdline_parse_inst_t cmd_config_rx_tx = {
1865         .f = cmd_config_rx_tx_parsed,
1866         .data = NULL,
1867         .help_str = "port config all rxq|txq|rxd|txd <value>",
1868         .tokens = {
1869                 (void *)&cmd_config_rx_tx_port,
1870                 (void *)&cmd_config_rx_tx_keyword,
1871                 (void *)&cmd_config_rx_tx_all,
1872                 (void *)&cmd_config_rx_tx_name,
1873                 (void *)&cmd_config_rx_tx_value,
1874                 NULL,
1875         },
1876 };
1877
1878 /* *** config max packet length *** */
1879 struct cmd_config_max_pkt_len_result {
1880         cmdline_fixed_string_t port;
1881         cmdline_fixed_string_t keyword;
1882         cmdline_fixed_string_t all;
1883         cmdline_fixed_string_t name;
1884         uint32_t value;
1885 };
1886
1887 static void
1888 cmd_config_max_pkt_len_parsed(void *parsed_result,
1889                                 __rte_unused struct cmdline *cl,
1890                                 __rte_unused void *data)
1891 {
1892         struct cmd_config_max_pkt_len_result *res = parsed_result;
1893         uint32_t max_rx_pkt_len_backup = 0;
1894         portid_t pid;
1895         int ret;
1896
1897         if (!all_ports_stopped()) {
1898                 printf("Please stop all ports first\n");
1899                 return;
1900         }
1901
1902         RTE_ETH_FOREACH_DEV(pid) {
1903                 struct rte_port *port = &ports[pid];
1904
1905                 if (!strcmp(res->name, "max-pkt-len")) {
1906                         if (res->value < RTE_ETHER_MIN_LEN) {
1907                                 printf("max-pkt-len can not be less than %d\n",
1908                                                 RTE_ETHER_MIN_LEN);
1909                                 return;
1910                         }
1911                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1912                                 return;
1913
1914                         ret = eth_dev_info_get_print_err(pid, &port->dev_info);
1915                         if (ret != 0) {
1916                                 printf("rte_eth_dev_info_get() failed for port %u\n",
1917                                         pid);
1918                                 return;
1919                         }
1920
1921                         max_rx_pkt_len_backup = port->dev_conf.rxmode.max_rx_pkt_len;
1922
1923                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1924                         if (update_jumbo_frame_offload(pid) != 0)
1925                                 port->dev_conf.rxmode.max_rx_pkt_len = max_rx_pkt_len_backup;
1926                 } else {
1927                         printf("Unknown parameter\n");
1928                         return;
1929                 }
1930         }
1931
1932         init_port_config();
1933
1934         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1935 }
1936
1937 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1938         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1939                                                                 "port");
1940 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1941         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1942                                                                 "config");
1943 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1944         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1945                                                                 "all");
1946 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1947         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1948                                                                 "max-pkt-len");
1949 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1950         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1951                                                                 RTE_UINT32);
1952
1953 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1954         .f = cmd_config_max_pkt_len_parsed,
1955         .data = NULL,
1956         .help_str = "port config all max-pkt-len <value>",
1957         .tokens = {
1958                 (void *)&cmd_config_max_pkt_len_port,
1959                 (void *)&cmd_config_max_pkt_len_keyword,
1960                 (void *)&cmd_config_max_pkt_len_all,
1961                 (void *)&cmd_config_max_pkt_len_name,
1962                 (void *)&cmd_config_max_pkt_len_value,
1963                 NULL,
1964         },
1965 };
1966
1967 /* *** config max LRO aggregated packet size *** */
1968 struct cmd_config_max_lro_pkt_size_result {
1969         cmdline_fixed_string_t port;
1970         cmdline_fixed_string_t keyword;
1971         cmdline_fixed_string_t all;
1972         cmdline_fixed_string_t name;
1973         uint32_t value;
1974 };
1975
1976 static void
1977 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1978                                 __rte_unused struct cmdline *cl,
1979                                 __rte_unused void *data)
1980 {
1981         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1982         portid_t pid;
1983
1984         if (!all_ports_stopped()) {
1985                 printf("Please stop all ports first\n");
1986                 return;
1987         }
1988
1989         RTE_ETH_FOREACH_DEV(pid) {
1990                 struct rte_port *port = &ports[pid];
1991
1992                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1993                         if (res->value ==
1994                                         port->dev_conf.rxmode.max_lro_pkt_size)
1995                                 return;
1996
1997                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1998                 } else {
1999                         printf("Unknown parameter\n");
2000                         return;
2001                 }
2002         }
2003
2004         init_port_config();
2005
2006         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2007 }
2008
2009 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2010         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2011                                  port, "port");
2012 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2013         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2014                                  keyword, "config");
2015 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2016         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2017                                  all, "all");
2018 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2019         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2020                                  name, "max-lro-pkt-size");
2021 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2022         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2023                               value, RTE_UINT32);
2024
2025 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2026         .f = cmd_config_max_lro_pkt_size_parsed,
2027         .data = NULL,
2028         .help_str = "port config all max-lro-pkt-size <value>",
2029         .tokens = {
2030                 (void *)&cmd_config_max_lro_pkt_size_port,
2031                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2032                 (void *)&cmd_config_max_lro_pkt_size_all,
2033                 (void *)&cmd_config_max_lro_pkt_size_name,
2034                 (void *)&cmd_config_max_lro_pkt_size_value,
2035                 NULL,
2036         },
2037 };
2038
2039 /* *** configure port MTU *** */
2040 struct cmd_config_mtu_result {
2041         cmdline_fixed_string_t port;
2042         cmdline_fixed_string_t keyword;
2043         cmdline_fixed_string_t mtu;
2044         portid_t port_id;
2045         uint16_t value;
2046 };
2047
2048 static void
2049 cmd_config_mtu_parsed(void *parsed_result,
2050                       __rte_unused struct cmdline *cl,
2051                       __rte_unused void *data)
2052 {
2053         struct cmd_config_mtu_result *res = parsed_result;
2054
2055         if (res->value < RTE_ETHER_MIN_LEN) {
2056                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2057                 return;
2058         }
2059         port_mtu_set(res->port_id, res->value);
2060 }
2061
2062 cmdline_parse_token_string_t cmd_config_mtu_port =
2063         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2064                                  "port");
2065 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2066         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2067                                  "config");
2068 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2069         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2070                                  "mtu");
2071 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2072         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2073                                  RTE_UINT16);
2074 cmdline_parse_token_num_t cmd_config_mtu_value =
2075         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2076                                  RTE_UINT16);
2077
2078 cmdline_parse_inst_t cmd_config_mtu = {
2079         .f = cmd_config_mtu_parsed,
2080         .data = NULL,
2081         .help_str = "port config mtu <port_id> <value>",
2082         .tokens = {
2083                 (void *)&cmd_config_mtu_port,
2084                 (void *)&cmd_config_mtu_keyword,
2085                 (void *)&cmd_config_mtu_mtu,
2086                 (void *)&cmd_config_mtu_port_id,
2087                 (void *)&cmd_config_mtu_value,
2088                 NULL,
2089         },
2090 };
2091
2092 /* *** configure rx mode *** */
2093 struct cmd_config_rx_mode_flag {
2094         cmdline_fixed_string_t port;
2095         cmdline_fixed_string_t keyword;
2096         cmdline_fixed_string_t all;
2097         cmdline_fixed_string_t name;
2098         cmdline_fixed_string_t value;
2099 };
2100
2101 static void
2102 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2103                                 __rte_unused struct cmdline *cl,
2104                                 __rte_unused void *data)
2105 {
2106         struct cmd_config_rx_mode_flag *res = parsed_result;
2107
2108         if (!all_ports_stopped()) {
2109                 printf("Please stop all ports first\n");
2110                 return;
2111         }
2112
2113         if (!strcmp(res->name, "drop-en")) {
2114                 if (!strcmp(res->value, "on"))
2115                         rx_drop_en = 1;
2116                 else if (!strcmp(res->value, "off"))
2117                         rx_drop_en = 0;
2118                 else {
2119                         printf("Unknown parameter\n");
2120                         return;
2121                 }
2122         } else {
2123                 printf("Unknown parameter\n");
2124                 return;
2125         }
2126
2127         init_port_config();
2128
2129         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2130 }
2131
2132 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2133         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2134 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2135         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2136                                                                 "config");
2137 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2138         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2139 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2140         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2141                                         "drop-en");
2142 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2143         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2144                                                         "on#off");
2145
2146 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2147         .f = cmd_config_rx_mode_flag_parsed,
2148         .data = NULL,
2149         .help_str = "port config all drop-en on|off",
2150         .tokens = {
2151                 (void *)&cmd_config_rx_mode_flag_port,
2152                 (void *)&cmd_config_rx_mode_flag_keyword,
2153                 (void *)&cmd_config_rx_mode_flag_all,
2154                 (void *)&cmd_config_rx_mode_flag_name,
2155                 (void *)&cmd_config_rx_mode_flag_value,
2156                 NULL,
2157         },
2158 };
2159
2160 /* *** configure rss *** */
2161 struct cmd_config_rss {
2162         cmdline_fixed_string_t port;
2163         cmdline_fixed_string_t keyword;
2164         cmdline_fixed_string_t all;
2165         cmdline_fixed_string_t name;
2166         cmdline_fixed_string_t value;
2167 };
2168
2169 static void
2170 cmd_config_rss_parsed(void *parsed_result,
2171                         __rte_unused struct cmdline *cl,
2172                         __rte_unused void *data)
2173 {
2174         struct cmd_config_rss *res = parsed_result;
2175         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2176         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2177         int use_default = 0;
2178         int all_updated = 1;
2179         int diag;
2180         uint16_t i;
2181         int ret;
2182
2183         if (!strcmp(res->value, "all"))
2184                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2185                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2186                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2187                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU |
2188                         ETH_RSS_ECPRI;
2189         else if (!strcmp(res->value, "eth"))
2190                 rss_conf.rss_hf = ETH_RSS_ETH;
2191         else if (!strcmp(res->value, "vlan"))
2192                 rss_conf.rss_hf = ETH_RSS_VLAN;
2193         else if (!strcmp(res->value, "ip"))
2194                 rss_conf.rss_hf = ETH_RSS_IP;
2195         else if (!strcmp(res->value, "udp"))
2196                 rss_conf.rss_hf = ETH_RSS_UDP;
2197         else if (!strcmp(res->value, "tcp"))
2198                 rss_conf.rss_hf = ETH_RSS_TCP;
2199         else if (!strcmp(res->value, "sctp"))
2200                 rss_conf.rss_hf = ETH_RSS_SCTP;
2201         else if (!strcmp(res->value, "ether"))
2202                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2203         else if (!strcmp(res->value, "port"))
2204                 rss_conf.rss_hf = ETH_RSS_PORT;
2205         else if (!strcmp(res->value, "vxlan"))
2206                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2207         else if (!strcmp(res->value, "geneve"))
2208                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2209         else if (!strcmp(res->value, "nvgre"))
2210                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2211         else if (!strcmp(res->value, "l3-pre32"))
2212                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2213         else if (!strcmp(res->value, "l3-pre40"))
2214                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2215         else if (!strcmp(res->value, "l3-pre48"))
2216                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2217         else if (!strcmp(res->value, "l3-pre56"))
2218                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2219         else if (!strcmp(res->value, "l3-pre64"))
2220                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2221         else if (!strcmp(res->value, "l3-pre96"))
2222                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2223         else if (!strcmp(res->value, "l3-src-only"))
2224                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2225         else if (!strcmp(res->value, "l3-dst-only"))
2226                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2227         else if (!strcmp(res->value, "l4-src-only"))
2228                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2229         else if (!strcmp(res->value, "l4-dst-only"))
2230                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2231         else if (!strcmp(res->value, "l2-src-only"))
2232                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2233         else if (!strcmp(res->value, "l2-dst-only"))
2234                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2235         else if (!strcmp(res->value, "l2tpv3"))
2236                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2237         else if (!strcmp(res->value, "esp"))
2238                 rss_conf.rss_hf = ETH_RSS_ESP;
2239         else if (!strcmp(res->value, "ah"))
2240                 rss_conf.rss_hf = ETH_RSS_AH;
2241         else if (!strcmp(res->value, "pfcp"))
2242                 rss_conf.rss_hf = ETH_RSS_PFCP;
2243         else if (!strcmp(res->value, "pppoe"))
2244                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2245         else if (!strcmp(res->value, "gtpu"))
2246                 rss_conf.rss_hf = ETH_RSS_GTPU;
2247         else if (!strcmp(res->value, "ecpri"))
2248                 rss_conf.rss_hf = ETH_RSS_ECPRI;
2249         else if (!strcmp(res->value, "mpls"))
2250                 rss_conf.rss_hf = ETH_RSS_MPLS;
2251         else if (!strcmp(res->value, "none"))
2252                 rss_conf.rss_hf = 0;
2253         else if (!strcmp(res->value, "level-default")) {
2254                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2255                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2256         } else if (!strcmp(res->value, "level-outer")) {
2257                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2258                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2259         } else if (!strcmp(res->value, "level-inner")) {
2260                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2261                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2262         } else if (!strcmp(res->value, "default"))
2263                 use_default = 1;
2264         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2265                                                 atoi(res->value) < 64)
2266                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2267         else {
2268                 printf("Unknown parameter\n");
2269                 return;
2270         }
2271         rss_conf.rss_key = NULL;
2272         /* Update global configuration for RSS types. */
2273         RTE_ETH_FOREACH_DEV(i) {
2274                 struct rte_eth_rss_conf local_rss_conf;
2275
2276                 ret = eth_dev_info_get_print_err(i, &dev_info);
2277                 if (ret != 0)
2278                         return;
2279
2280                 if (use_default)
2281                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2282
2283                 local_rss_conf = rss_conf;
2284                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2285                         dev_info.flow_type_rss_offloads;
2286                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2287                         printf("Port %u modified RSS hash function based on hardware support,"
2288                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2289                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2290                 }
2291                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2292                 if (diag < 0) {
2293                         all_updated = 0;
2294                         printf("Configuration of RSS hash at ethernet port %d "
2295                                 "failed with error (%d): %s.\n",
2296                                 i, -diag, strerror(-diag));
2297                 }
2298         }
2299         if (all_updated && !use_default) {
2300                 rss_hf = rss_conf.rss_hf;
2301                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2302         }
2303 }
2304
2305 cmdline_parse_token_string_t cmd_config_rss_port =
2306         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2307 cmdline_parse_token_string_t cmd_config_rss_keyword =
2308         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2309 cmdline_parse_token_string_t cmd_config_rss_all =
2310         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2311 cmdline_parse_token_string_t cmd_config_rss_name =
2312         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2313 cmdline_parse_token_string_t cmd_config_rss_value =
2314         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2315
2316 cmdline_parse_inst_t cmd_config_rss = {
2317         .f = cmd_config_rss_parsed,
2318         .data = NULL,
2319         .help_str = "port config all rss "
2320                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2321                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2322                 "level-outer|level-inner|<flowtype_id>",
2323         .tokens = {
2324                 (void *)&cmd_config_rss_port,
2325                 (void *)&cmd_config_rss_keyword,
2326                 (void *)&cmd_config_rss_all,
2327                 (void *)&cmd_config_rss_name,
2328                 (void *)&cmd_config_rss_value,
2329                 NULL,
2330         },
2331 };
2332
2333 /* *** configure rss hash key *** */
2334 struct cmd_config_rss_hash_key {
2335         cmdline_fixed_string_t port;
2336         cmdline_fixed_string_t config;
2337         portid_t port_id;
2338         cmdline_fixed_string_t rss_hash_key;
2339         cmdline_fixed_string_t rss_type;
2340         cmdline_fixed_string_t key;
2341 };
2342
2343 static uint8_t
2344 hexa_digit_to_value(char hexa_digit)
2345 {
2346         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2347                 return (uint8_t) (hexa_digit - '0');
2348         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2349                 return (uint8_t) ((hexa_digit - 'a') + 10);
2350         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2351                 return (uint8_t) ((hexa_digit - 'A') + 10);
2352         /* Invalid hexa digit */
2353         return 0xFF;
2354 }
2355
2356 static uint8_t
2357 parse_and_check_key_hexa_digit(char *key, int idx)
2358 {
2359         uint8_t hexa_v;
2360
2361         hexa_v = hexa_digit_to_value(key[idx]);
2362         if (hexa_v == 0xFF)
2363                 printf("invalid key: character %c at position %d is not a "
2364                        "valid hexa digit\n", key[idx], idx);
2365         return hexa_v;
2366 }
2367
2368 static void
2369 cmd_config_rss_hash_key_parsed(void *parsed_result,
2370                                __rte_unused struct cmdline *cl,
2371                                __rte_unused void *data)
2372 {
2373         struct cmd_config_rss_hash_key *res = parsed_result;
2374         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2375         uint8_t xdgt0;
2376         uint8_t xdgt1;
2377         int i;
2378         struct rte_eth_dev_info dev_info;
2379         uint8_t hash_key_size;
2380         uint32_t key_len;
2381         int ret;
2382
2383         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2384         if (ret != 0)
2385                 return;
2386
2387         if (dev_info.hash_key_size > 0 &&
2388                         dev_info.hash_key_size <= sizeof(hash_key))
2389                 hash_key_size = dev_info.hash_key_size;
2390         else {
2391                 printf("dev_info did not provide a valid hash key size\n");
2392                 return;
2393         }
2394         /* Check the length of the RSS hash key */
2395         key_len = strlen(res->key);
2396         if (key_len != (hash_key_size * 2)) {
2397                 printf("key length: %d invalid - key must be a string of %d"
2398                            " hexa-decimal numbers\n",
2399                            (int) key_len, hash_key_size * 2);
2400                 return;
2401         }
2402         /* Translate RSS hash key into binary representation */
2403         for (i = 0; i < hash_key_size; i++) {
2404                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2405                 if (xdgt0 == 0xFF)
2406                         return;
2407                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2408                 if (xdgt1 == 0xFF)
2409                         return;
2410                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2411         }
2412         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2413                         hash_key_size);
2414 }
2415
2416 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2417         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2418 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2419         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2420                                  "config");
2421 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2422         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2423                                  RTE_UINT16);
2424 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2425         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2426                                  rss_hash_key, "rss-hash-key");
2427 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2428         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2429                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2430                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2431                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2432                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2433                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2434                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2435                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls");
2436 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2437         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2438
2439 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2440         .f = cmd_config_rss_hash_key_parsed,
2441         .data = NULL,
2442         .help_str = "port config <port_id> rss-hash-key "
2443                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2444                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2445                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2446                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2447                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2448                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls "
2449                 "<string of hex digits (variable length, NIC dependent)>",
2450         .tokens = {
2451                 (void *)&cmd_config_rss_hash_key_port,
2452                 (void *)&cmd_config_rss_hash_key_config,
2453                 (void *)&cmd_config_rss_hash_key_port_id,
2454                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2455                 (void *)&cmd_config_rss_hash_key_rss_type,
2456                 (void *)&cmd_config_rss_hash_key_value,
2457                 NULL,
2458         },
2459 };
2460
2461 /* *** configure port rxq/txq ring size *** */
2462 struct cmd_config_rxtx_ring_size {
2463         cmdline_fixed_string_t port;
2464         cmdline_fixed_string_t config;
2465         portid_t portid;
2466         cmdline_fixed_string_t rxtxq;
2467         uint16_t qid;
2468         cmdline_fixed_string_t rsize;
2469         uint16_t size;
2470 };
2471
2472 static void
2473 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2474                                  __rte_unused struct cmdline *cl,
2475                                  __rte_unused void *data)
2476 {
2477         struct cmd_config_rxtx_ring_size *res = parsed_result;
2478         struct rte_port *port;
2479         uint8_t isrx;
2480
2481         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2482                 return;
2483
2484         if (res->portid == (portid_t)RTE_PORT_ALL) {
2485                 printf("Invalid port id\n");
2486                 return;
2487         }
2488
2489         port = &ports[res->portid];
2490
2491         if (!strcmp(res->rxtxq, "rxq"))
2492                 isrx = 1;
2493         else if (!strcmp(res->rxtxq, "txq"))
2494                 isrx = 0;
2495         else {
2496                 printf("Unknown parameter\n");
2497                 return;
2498         }
2499
2500         if (isrx && rx_queue_id_is_invalid(res->qid))
2501                 return;
2502         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2503                 return;
2504
2505         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2506                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2507                        rx_free_thresh);
2508                 return;
2509         }
2510
2511         if (isrx)
2512                 port->nb_rx_desc[res->qid] = res->size;
2513         else
2514                 port->nb_tx_desc[res->qid] = res->size;
2515
2516         cmd_reconfig_device_queue(res->portid, 0, 1);
2517 }
2518
2519 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2520         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2521                                  port, "port");
2522 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2523         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2524                                  config, "config");
2525 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2526         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2527                                  portid, RTE_UINT16);
2528 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2529         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2530                                  rxtxq, "rxq#txq");
2531 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2532         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2533                               qid, RTE_UINT16);
2534 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2535         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2536                                  rsize, "ring_size");
2537 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2538         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2539                               size, RTE_UINT16);
2540
2541 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2542         .f = cmd_config_rxtx_ring_size_parsed,
2543         .data = NULL,
2544         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2545         .tokens = {
2546                 (void *)&cmd_config_rxtx_ring_size_port,
2547                 (void *)&cmd_config_rxtx_ring_size_config,
2548                 (void *)&cmd_config_rxtx_ring_size_portid,
2549                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2550                 (void *)&cmd_config_rxtx_ring_size_qid,
2551                 (void *)&cmd_config_rxtx_ring_size_rsize,
2552                 (void *)&cmd_config_rxtx_ring_size_size,
2553                 NULL,
2554         },
2555 };
2556
2557 /* *** configure port rxq/txq start/stop *** */
2558 struct cmd_config_rxtx_queue {
2559         cmdline_fixed_string_t port;
2560         portid_t portid;
2561         cmdline_fixed_string_t rxtxq;
2562         uint16_t qid;
2563         cmdline_fixed_string_t opname;
2564 };
2565
2566 static void
2567 cmd_config_rxtx_queue_parsed(void *parsed_result,
2568                         __rte_unused struct cmdline *cl,
2569                         __rte_unused void *data)
2570 {
2571         struct cmd_config_rxtx_queue *res = parsed_result;
2572         uint8_t isrx;
2573         uint8_t isstart;
2574         int ret = 0;
2575
2576         if (test_done == 0) {
2577                 printf("Please stop forwarding first\n");
2578                 return;
2579         }
2580
2581         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2582                 return;
2583
2584         if (port_is_started(res->portid) != 1) {
2585                 printf("Please start port %u first\n", res->portid);
2586                 return;
2587         }
2588
2589         if (!strcmp(res->rxtxq, "rxq"))
2590                 isrx = 1;
2591         else if (!strcmp(res->rxtxq, "txq"))
2592                 isrx = 0;
2593         else {
2594                 printf("Unknown parameter\n");
2595                 return;
2596         }
2597
2598         if (isrx && rx_queue_id_is_invalid(res->qid))
2599                 return;
2600         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2601                 return;
2602
2603         if (!strcmp(res->opname, "start"))
2604                 isstart = 1;
2605         else if (!strcmp(res->opname, "stop"))
2606                 isstart = 0;
2607         else {
2608                 printf("Unknown parameter\n");
2609                 return;
2610         }
2611
2612         if (isstart && isrx)
2613                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2614         else if (!isstart && isrx)
2615                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2616         else if (isstart && !isrx)
2617                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2618         else
2619                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2620
2621         if (ret == -ENOTSUP)
2622                 printf("Function not supported in PMD driver\n");
2623 }
2624
2625 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2626         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2627 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2628         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2629 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2630         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2631 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2632         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2633 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2634         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2635                                                 "start#stop");
2636
2637 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2638         .f = cmd_config_rxtx_queue_parsed,
2639         .data = NULL,
2640         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2641         .tokens = {
2642                 (void *)&cmd_config_rxtx_queue_port,
2643                 (void *)&cmd_config_rxtx_queue_portid,
2644                 (void *)&cmd_config_rxtx_queue_rxtxq,
2645                 (void *)&cmd_config_rxtx_queue_qid,
2646                 (void *)&cmd_config_rxtx_queue_opname,
2647                 NULL,
2648         },
2649 };
2650
2651 /* *** configure port rxq/txq deferred start on/off *** */
2652 struct cmd_config_deferred_start_rxtx_queue {
2653         cmdline_fixed_string_t port;
2654         portid_t port_id;
2655         cmdline_fixed_string_t rxtxq;
2656         uint16_t qid;
2657         cmdline_fixed_string_t opname;
2658         cmdline_fixed_string_t state;
2659 };
2660
2661 static void
2662 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2663                         __rte_unused struct cmdline *cl,
2664                         __rte_unused void *data)
2665 {
2666         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2667         struct rte_port *port;
2668         uint8_t isrx;
2669         uint8_t ison;
2670         uint8_t needreconfig = 0;
2671
2672         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2673                 return;
2674
2675         if (port_is_started(res->port_id) != 0) {
2676                 printf("Please stop port %u first\n", res->port_id);
2677                 return;
2678         }
2679
2680         port = &ports[res->port_id];
2681
2682         isrx = !strcmp(res->rxtxq, "rxq");
2683
2684         if (isrx && rx_queue_id_is_invalid(res->qid))
2685                 return;
2686         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2687                 return;
2688
2689         ison = !strcmp(res->state, "on");
2690
2691         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2692                 port->rx_conf[res->qid].rx_deferred_start = ison;
2693                 needreconfig = 1;
2694         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2695                 port->tx_conf[res->qid].tx_deferred_start = ison;
2696                 needreconfig = 1;
2697         }
2698
2699         if (needreconfig)
2700                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2701 }
2702
2703 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2704         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2705                                                 port, "port");
2706 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2707         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2708                                                 port_id, RTE_UINT16);
2709 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2710         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2711                                                 rxtxq, "rxq#txq");
2712 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2713         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2714                                                 qid, RTE_UINT16);
2715 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2716         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2717                                                 opname, "deferred_start");
2718 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2719         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2720                                                 state, "on#off");
2721
2722 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2723         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2724         .data = NULL,
2725         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2726         .tokens = {
2727                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2728                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2729                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2730                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2731                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2732                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2733                 NULL,
2734         },
2735 };
2736
2737 /* *** configure port rxq/txq setup *** */
2738 struct cmd_setup_rxtx_queue {
2739         cmdline_fixed_string_t port;
2740         portid_t portid;
2741         cmdline_fixed_string_t rxtxq;
2742         uint16_t qid;
2743         cmdline_fixed_string_t setup;
2744 };
2745
2746 /* Common CLI fields for queue setup */
2747 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2748         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2749 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2750         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2751 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2752         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2753 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2754         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2755 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2756         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2757
2758 static void
2759 cmd_setup_rxtx_queue_parsed(
2760         void *parsed_result,
2761         __rte_unused struct cmdline *cl,
2762         __rte_unused void *data)
2763 {
2764         struct cmd_setup_rxtx_queue *res = parsed_result;
2765         struct rte_port *port;
2766         struct rte_mempool *mp;
2767         unsigned int socket_id;
2768         uint8_t isrx = 0;
2769         int ret;
2770
2771         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2772                 return;
2773
2774         if (res->portid == (portid_t)RTE_PORT_ALL) {
2775                 printf("Invalid port id\n");
2776                 return;
2777         }
2778
2779         if (!strcmp(res->rxtxq, "rxq"))
2780                 isrx = 1;
2781         else if (!strcmp(res->rxtxq, "txq"))
2782                 isrx = 0;
2783         else {
2784                 printf("Unknown parameter\n");
2785                 return;
2786         }
2787
2788         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2789                 printf("Invalid rx queue\n");
2790                 return;
2791         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2792                 printf("Invalid tx queue\n");
2793                 return;
2794         }
2795
2796         port = &ports[res->portid];
2797         if (isrx) {
2798                 socket_id = rxring_numa[res->portid];
2799                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2800                         socket_id = port->socket_id;
2801
2802                 mp = mbuf_pool_find(socket_id, 0);
2803                 if (mp == NULL) {
2804                         printf("Failed to setup RX queue: "
2805                                 "No mempool allocation"
2806                                 " on the socket %d\n",
2807                                 rxring_numa[res->portid]);
2808                         return;
2809                 }
2810                 ret = rx_queue_setup(res->portid,
2811                                      res->qid,
2812                                      port->nb_rx_desc[res->qid],
2813                                      socket_id,
2814                                      &port->rx_conf[res->qid],
2815                                      mp);
2816                 if (ret)
2817                         printf("Failed to setup RX queue\n");
2818         } else {
2819                 socket_id = txring_numa[res->portid];
2820                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2821                         socket_id = port->socket_id;
2822
2823                 ret = rte_eth_tx_queue_setup(res->portid,
2824                                              res->qid,
2825                                              port->nb_tx_desc[res->qid],
2826                                              socket_id,
2827                                              &port->tx_conf[res->qid]);
2828                 if (ret)
2829                         printf("Failed to setup TX queue\n");
2830         }
2831 }
2832
2833 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2834         .f = cmd_setup_rxtx_queue_parsed,
2835         .data = NULL,
2836         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2837         .tokens = {
2838                 (void *)&cmd_setup_rxtx_queue_port,
2839                 (void *)&cmd_setup_rxtx_queue_portid,
2840                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2841                 (void *)&cmd_setup_rxtx_queue_qid,
2842                 (void *)&cmd_setup_rxtx_queue_setup,
2843                 NULL,
2844         },
2845 };
2846
2847
2848 /* *** Configure RSS RETA *** */
2849 struct cmd_config_rss_reta {
2850         cmdline_fixed_string_t port;
2851         cmdline_fixed_string_t keyword;
2852         portid_t port_id;
2853         cmdline_fixed_string_t name;
2854         cmdline_fixed_string_t list_name;
2855         cmdline_fixed_string_t list_of_items;
2856 };
2857
2858 static int
2859 parse_reta_config(const char *str,
2860                   struct rte_eth_rss_reta_entry64 *reta_conf,
2861                   uint16_t nb_entries)
2862 {
2863         int i;
2864         unsigned size;
2865         uint16_t hash_index, idx, shift;
2866         uint16_t nb_queue;
2867         char s[256];
2868         const char *p, *p0 = str;
2869         char *end;
2870         enum fieldnames {
2871                 FLD_HASH_INDEX = 0,
2872                 FLD_QUEUE,
2873                 _NUM_FLD
2874         };
2875         unsigned long int_fld[_NUM_FLD];
2876         char *str_fld[_NUM_FLD];
2877
2878         while ((p = strchr(p0,'(')) != NULL) {
2879                 ++p;
2880                 if((p0 = strchr(p,')')) == NULL)
2881                         return -1;
2882
2883                 size = p0 - p;
2884                 if(size >= sizeof(s))
2885                         return -1;
2886
2887                 snprintf(s, sizeof(s), "%.*s", size, p);
2888                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2889                         return -1;
2890                 for (i = 0; i < _NUM_FLD; i++) {
2891                         errno = 0;
2892                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2893                         if (errno != 0 || end == str_fld[i] ||
2894                                         int_fld[i] > 65535)
2895                                 return -1;
2896                 }
2897
2898                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2899                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2900
2901                 if (hash_index >= nb_entries) {
2902                         printf("Invalid RETA hash index=%d\n", hash_index);
2903                         return -1;
2904                 }
2905
2906                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2907                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2908                 reta_conf[idx].mask |= (1ULL << shift);
2909                 reta_conf[idx].reta[shift] = nb_queue;
2910         }
2911
2912         return 0;
2913 }
2914
2915 static void
2916 cmd_set_rss_reta_parsed(void *parsed_result,
2917                         __rte_unused struct cmdline *cl,
2918                         __rte_unused void *data)
2919 {
2920         int ret;
2921         struct rte_eth_dev_info dev_info;
2922         struct rte_eth_rss_reta_entry64 reta_conf[8];
2923         struct cmd_config_rss_reta *res = parsed_result;
2924
2925         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2926         if (ret != 0)
2927                 return;
2928
2929         if (dev_info.reta_size == 0) {
2930                 printf("Redirection table size is 0 which is "
2931                                         "invalid for RSS\n");
2932                 return;
2933         } else
2934                 printf("The reta size of port %d is %u\n",
2935                         res->port_id, dev_info.reta_size);
2936         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2937                 printf("Currently do not support more than %u entries of "
2938                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2939                 return;
2940         }
2941
2942         memset(reta_conf, 0, sizeof(reta_conf));
2943         if (!strcmp(res->list_name, "reta")) {
2944                 if (parse_reta_config(res->list_of_items, reta_conf,
2945                                                 dev_info.reta_size)) {
2946                         printf("Invalid RSS Redirection Table "
2947                                         "config entered\n");
2948                         return;
2949                 }
2950                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2951                                 reta_conf, dev_info.reta_size);
2952                 if (ret != 0)
2953                         printf("Bad redirection table parameter, "
2954                                         "return code = %d \n", ret);
2955         }
2956 }
2957
2958 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2959         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2960 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2961         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2962 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2963         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
2964 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2965         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2966 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2967         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2968 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2969         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2970                                  NULL);
2971 cmdline_parse_inst_t cmd_config_rss_reta = {
2972         .f = cmd_set_rss_reta_parsed,
2973         .data = NULL,
2974         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2975         .tokens = {
2976                 (void *)&cmd_config_rss_reta_port,
2977                 (void *)&cmd_config_rss_reta_keyword,
2978                 (void *)&cmd_config_rss_reta_port_id,
2979                 (void *)&cmd_config_rss_reta_name,
2980                 (void *)&cmd_config_rss_reta_list_name,
2981                 (void *)&cmd_config_rss_reta_list_of_items,
2982                 NULL,
2983         },
2984 };
2985
2986 /* *** SHOW PORT RETA INFO *** */
2987 struct cmd_showport_reta {
2988         cmdline_fixed_string_t show;
2989         cmdline_fixed_string_t port;
2990         portid_t port_id;
2991         cmdline_fixed_string_t rss;
2992         cmdline_fixed_string_t reta;
2993         uint16_t size;
2994         cmdline_fixed_string_t list_of_items;
2995 };
2996
2997 static int
2998 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2999                            uint16_t nb_entries,
3000                            char *str)
3001 {
3002         uint32_t size;
3003         const char *p, *p0 = str;
3004         char s[256];
3005         char *end;
3006         char *str_fld[8];
3007         uint16_t i;
3008         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3009                         RTE_RETA_GROUP_SIZE;
3010         int ret;
3011
3012         p = strchr(p0, '(');
3013         if (p == NULL)
3014                 return -1;
3015         p++;
3016         p0 = strchr(p, ')');
3017         if (p0 == NULL)
3018                 return -1;
3019         size = p0 - p;
3020         if (size >= sizeof(s)) {
3021                 printf("The string size exceeds the internal buffer size\n");
3022                 return -1;
3023         }
3024         snprintf(s, sizeof(s), "%.*s", size, p);
3025         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3026         if (ret <= 0 || ret != num) {
3027                 printf("The bits of masks do not match the number of "
3028                                         "reta entries: %u\n", num);
3029                 return -1;
3030         }
3031         for (i = 0; i < ret; i++)
3032                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3033
3034         return 0;
3035 }
3036
3037 static void
3038 cmd_showport_reta_parsed(void *parsed_result,
3039                          __rte_unused struct cmdline *cl,
3040                          __rte_unused void *data)
3041 {
3042         struct cmd_showport_reta *res = parsed_result;
3043         struct rte_eth_rss_reta_entry64 reta_conf[8];
3044         struct rte_eth_dev_info dev_info;
3045         uint16_t max_reta_size;
3046         int ret;
3047
3048         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3049         if (ret != 0)
3050                 return;
3051
3052         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3053         if (res->size == 0 || res->size > max_reta_size) {
3054                 printf("Invalid redirection table size: %u (1-%u)\n",
3055                         res->size, max_reta_size);
3056                 return;
3057         }
3058
3059         memset(reta_conf, 0, sizeof(reta_conf));
3060         if (showport_parse_reta_config(reta_conf, res->size,
3061                                 res->list_of_items) < 0) {
3062                 printf("Invalid string: %s for reta masks\n",
3063                                         res->list_of_items);
3064                 return;
3065         }
3066         port_rss_reta_info(res->port_id, reta_conf, res->size);
3067 }
3068
3069 cmdline_parse_token_string_t cmd_showport_reta_show =
3070         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3071 cmdline_parse_token_string_t cmd_showport_reta_port =
3072         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3073 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3074         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3075 cmdline_parse_token_string_t cmd_showport_reta_rss =
3076         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3077 cmdline_parse_token_string_t cmd_showport_reta_reta =
3078         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3079 cmdline_parse_token_num_t cmd_showport_reta_size =
3080         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3081 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3082         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3083                                         list_of_items, NULL);
3084
3085 cmdline_parse_inst_t cmd_showport_reta = {
3086         .f = cmd_showport_reta_parsed,
3087         .data = NULL,
3088         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3089         .tokens = {
3090                 (void *)&cmd_showport_reta_show,
3091                 (void *)&cmd_showport_reta_port,
3092                 (void *)&cmd_showport_reta_port_id,
3093                 (void *)&cmd_showport_reta_rss,
3094                 (void *)&cmd_showport_reta_reta,
3095                 (void *)&cmd_showport_reta_size,
3096                 (void *)&cmd_showport_reta_list_of_items,
3097                 NULL,
3098         },
3099 };
3100
3101 /* *** Show RSS hash configuration *** */
3102 struct cmd_showport_rss_hash {
3103         cmdline_fixed_string_t show;
3104         cmdline_fixed_string_t port;
3105         portid_t port_id;
3106         cmdline_fixed_string_t rss_hash;
3107         cmdline_fixed_string_t rss_type;
3108         cmdline_fixed_string_t key; /* optional argument */
3109 };
3110
3111 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3112                                 __rte_unused struct cmdline *cl,
3113                                 void *show_rss_key)
3114 {
3115         struct cmd_showport_rss_hash *res = parsed_result;
3116
3117         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3118 }
3119
3120 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3121         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3122 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3123         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3124 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3125         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3126                                  RTE_UINT16);
3127 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3128         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3129                                  "rss-hash");
3130 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3131         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3132
3133 cmdline_parse_inst_t cmd_showport_rss_hash = {
3134         .f = cmd_showport_rss_hash_parsed,
3135         .data = NULL,
3136         .help_str = "show port <port_id> rss-hash",
3137         .tokens = {
3138                 (void *)&cmd_showport_rss_hash_show,
3139                 (void *)&cmd_showport_rss_hash_port,
3140                 (void *)&cmd_showport_rss_hash_port_id,
3141                 (void *)&cmd_showport_rss_hash_rss_hash,
3142                 NULL,
3143         },
3144 };
3145
3146 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3147         .f = cmd_showport_rss_hash_parsed,
3148         .data = (void *)1,
3149         .help_str = "show port <port_id> rss-hash key",
3150         .tokens = {
3151                 (void *)&cmd_showport_rss_hash_show,
3152                 (void *)&cmd_showport_rss_hash_port,
3153                 (void *)&cmd_showport_rss_hash_port_id,
3154                 (void *)&cmd_showport_rss_hash_rss_hash,
3155                 (void *)&cmd_showport_rss_hash_rss_key,
3156                 NULL,
3157         },
3158 };
3159
3160 /* *** Configure DCB *** */
3161 struct cmd_config_dcb {
3162         cmdline_fixed_string_t port;
3163         cmdline_fixed_string_t config;
3164         portid_t port_id;
3165         cmdline_fixed_string_t dcb;
3166         cmdline_fixed_string_t vt;
3167         cmdline_fixed_string_t vt_en;
3168         uint8_t num_tcs;
3169         cmdline_fixed_string_t pfc;
3170         cmdline_fixed_string_t pfc_en;
3171 };
3172
3173 static void
3174 cmd_config_dcb_parsed(void *parsed_result,
3175                         __rte_unused struct cmdline *cl,
3176                         __rte_unused void *data)
3177 {
3178         struct cmd_config_dcb *res = parsed_result;
3179         portid_t port_id = res->port_id;
3180         struct rte_port *port;
3181         uint8_t pfc_en;
3182         int ret;
3183
3184         port = &ports[port_id];
3185         /** Check if the port is not started **/
3186         if (port->port_status != RTE_PORT_STOPPED) {
3187                 printf("Please stop port %d first\n", port_id);
3188                 return;
3189         }
3190
3191         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3192                 printf("The invalid number of traffic class,"
3193                         " only 4 or 8 allowed.\n");
3194                 return;
3195         }
3196
3197         if (nb_fwd_lcores < res->num_tcs) {
3198                 printf("nb_cores shouldn't be less than number of TCs.\n");
3199                 return;
3200         }
3201         if (!strncmp(res->pfc_en, "on", 2))
3202                 pfc_en = 1;
3203         else
3204                 pfc_en = 0;
3205
3206         /* DCB in VT mode */
3207         if (!strncmp(res->vt_en, "on", 2))
3208                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3209                                 (enum rte_eth_nb_tcs)res->num_tcs,
3210                                 pfc_en);
3211         else
3212                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3213                                 (enum rte_eth_nb_tcs)res->num_tcs,
3214                                 pfc_en);
3215
3216
3217         if (ret != 0) {
3218                 printf("Cannot initialize network ports.\n");
3219                 return;
3220         }
3221
3222         cmd_reconfig_device_queue(port_id, 1, 1);
3223 }
3224
3225 cmdline_parse_token_string_t cmd_config_dcb_port =
3226         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3227 cmdline_parse_token_string_t cmd_config_dcb_config =
3228         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3229 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3230         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3231 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3232         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3233 cmdline_parse_token_string_t cmd_config_dcb_vt =
3234         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3235 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3236         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3237 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3238         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3239 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3240         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3241 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3242         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3243
3244 cmdline_parse_inst_t cmd_config_dcb = {
3245         .f = cmd_config_dcb_parsed,
3246         .data = NULL,
3247         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3248         .tokens = {
3249                 (void *)&cmd_config_dcb_port,
3250                 (void *)&cmd_config_dcb_config,
3251                 (void *)&cmd_config_dcb_port_id,
3252                 (void *)&cmd_config_dcb_dcb,
3253                 (void *)&cmd_config_dcb_vt,
3254                 (void *)&cmd_config_dcb_vt_en,
3255                 (void *)&cmd_config_dcb_num_tcs,
3256                 (void *)&cmd_config_dcb_pfc,
3257                 (void *)&cmd_config_dcb_pfc_en,
3258                 NULL,
3259         },
3260 };
3261
3262 /* *** configure number of packets per burst *** */
3263 struct cmd_config_burst {
3264         cmdline_fixed_string_t port;
3265         cmdline_fixed_string_t keyword;
3266         cmdline_fixed_string_t all;
3267         cmdline_fixed_string_t name;
3268         uint16_t value;
3269 };
3270
3271 static void
3272 cmd_config_burst_parsed(void *parsed_result,
3273                         __rte_unused struct cmdline *cl,
3274                         __rte_unused void *data)
3275 {
3276         struct cmd_config_burst *res = parsed_result;
3277         struct rte_eth_dev_info dev_info;
3278         uint16_t rec_nb_pkts;
3279         int ret;
3280
3281         if (!all_ports_stopped()) {
3282                 printf("Please stop all ports first\n");
3283                 return;
3284         }
3285
3286         if (!strcmp(res->name, "burst")) {
3287                 if (res->value == 0) {
3288                         /* If user gives a value of zero, query the PMD for
3289                          * its recommended Rx burst size. Testpmd uses a single
3290                          * size for all ports, so assume all ports are the same
3291                          * NIC model and use the values from Port 0.
3292                          */
3293                         ret = eth_dev_info_get_print_err(0, &dev_info);
3294                         if (ret != 0)
3295                                 return;
3296
3297                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3298
3299                         if (rec_nb_pkts == 0) {
3300                                 printf("PMD does not recommend a burst size.\n"
3301                                         "User provided value must be between"
3302                                         " 1 and %d\n", MAX_PKT_BURST);
3303                                 return;
3304                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3305                                 printf("PMD recommended burst size of %d"
3306                                         " exceeds maximum value of %d\n",
3307                                         rec_nb_pkts, MAX_PKT_BURST);
3308                                 return;
3309                         }
3310                         printf("Using PMD-provided burst value of %d\n",
3311                                 rec_nb_pkts);
3312                         nb_pkt_per_burst = rec_nb_pkts;
3313                 } else if (res->value > MAX_PKT_BURST) {
3314                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3315                         return;
3316                 } else
3317                         nb_pkt_per_burst = res->value;
3318         } else {
3319                 printf("Unknown parameter\n");
3320                 return;
3321         }
3322
3323         init_port_config();
3324
3325         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3326 }
3327
3328 cmdline_parse_token_string_t cmd_config_burst_port =
3329         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3330 cmdline_parse_token_string_t cmd_config_burst_keyword =
3331         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3332 cmdline_parse_token_string_t cmd_config_burst_all =
3333         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3334 cmdline_parse_token_string_t cmd_config_burst_name =
3335         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3336 cmdline_parse_token_num_t cmd_config_burst_value =
3337         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3338
3339 cmdline_parse_inst_t cmd_config_burst = {
3340         .f = cmd_config_burst_parsed,
3341         .data = NULL,
3342         .help_str = "port config all burst <value>",
3343         .tokens = {
3344                 (void *)&cmd_config_burst_port,
3345                 (void *)&cmd_config_burst_keyword,
3346                 (void *)&cmd_config_burst_all,
3347                 (void *)&cmd_config_burst_name,
3348                 (void *)&cmd_config_burst_value,
3349                 NULL,
3350         },
3351 };
3352
3353 /* *** configure rx/tx queues *** */
3354 struct cmd_config_thresh {
3355         cmdline_fixed_string_t port;
3356         cmdline_fixed_string_t keyword;
3357         cmdline_fixed_string_t all;
3358         cmdline_fixed_string_t name;
3359         uint8_t value;
3360 };
3361
3362 static void
3363 cmd_config_thresh_parsed(void *parsed_result,
3364                         __rte_unused struct cmdline *cl,
3365                         __rte_unused void *data)
3366 {
3367         struct cmd_config_thresh *res = parsed_result;
3368
3369         if (!all_ports_stopped()) {
3370                 printf("Please stop all ports first\n");
3371                 return;
3372         }
3373
3374         if (!strcmp(res->name, "txpt"))
3375                 tx_pthresh = res->value;
3376         else if(!strcmp(res->name, "txht"))
3377                 tx_hthresh = res->value;
3378         else if(!strcmp(res->name, "txwt"))
3379                 tx_wthresh = res->value;
3380         else if(!strcmp(res->name, "rxpt"))
3381                 rx_pthresh = res->value;
3382         else if(!strcmp(res->name, "rxht"))
3383                 rx_hthresh = res->value;
3384         else if(!strcmp(res->name, "rxwt"))
3385                 rx_wthresh = res->value;
3386         else {
3387                 printf("Unknown parameter\n");
3388                 return;
3389         }
3390
3391         init_port_config();
3392
3393         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3394 }
3395
3396 cmdline_parse_token_string_t cmd_config_thresh_port =
3397         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3398 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3399         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3400 cmdline_parse_token_string_t cmd_config_thresh_all =
3401         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3402 cmdline_parse_token_string_t cmd_config_thresh_name =
3403         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3404                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3405 cmdline_parse_token_num_t cmd_config_thresh_value =
3406         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3407
3408 cmdline_parse_inst_t cmd_config_thresh = {
3409         .f = cmd_config_thresh_parsed,
3410         .data = NULL,
3411         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3412         .tokens = {
3413                 (void *)&cmd_config_thresh_port,
3414                 (void *)&cmd_config_thresh_keyword,
3415                 (void *)&cmd_config_thresh_all,
3416                 (void *)&cmd_config_thresh_name,
3417                 (void *)&cmd_config_thresh_value,
3418                 NULL,
3419         },
3420 };
3421
3422 /* *** configure free/rs threshold *** */
3423 struct cmd_config_threshold {
3424         cmdline_fixed_string_t port;
3425         cmdline_fixed_string_t keyword;
3426         cmdline_fixed_string_t all;
3427         cmdline_fixed_string_t name;
3428         uint16_t value;
3429 };
3430
3431 static void
3432 cmd_config_threshold_parsed(void *parsed_result,
3433                         __rte_unused struct cmdline *cl,
3434                         __rte_unused void *data)
3435 {
3436         struct cmd_config_threshold *res = parsed_result;
3437
3438         if (!all_ports_stopped()) {
3439                 printf("Please stop all ports first\n");
3440                 return;
3441         }
3442
3443         if (!strcmp(res->name, "txfreet"))
3444                 tx_free_thresh = res->value;
3445         else if (!strcmp(res->name, "txrst"))
3446                 tx_rs_thresh = res->value;
3447         else if (!strcmp(res->name, "rxfreet"))
3448                 rx_free_thresh = res->value;
3449         else {
3450                 printf("Unknown parameter\n");
3451                 return;
3452         }
3453
3454         init_port_config();
3455
3456         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3457 }
3458
3459 cmdline_parse_token_string_t cmd_config_threshold_port =
3460         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3461 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3462         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3463                                                                 "config");
3464 cmdline_parse_token_string_t cmd_config_threshold_all =
3465         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3466 cmdline_parse_token_string_t cmd_config_threshold_name =
3467         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3468                                                 "txfreet#txrst#rxfreet");
3469 cmdline_parse_token_num_t cmd_config_threshold_value =
3470         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3471
3472 cmdline_parse_inst_t cmd_config_threshold = {
3473         .f = cmd_config_threshold_parsed,
3474         .data = NULL,
3475         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3476         .tokens = {
3477                 (void *)&cmd_config_threshold_port,
3478                 (void *)&cmd_config_threshold_keyword,
3479                 (void *)&cmd_config_threshold_all,
3480                 (void *)&cmd_config_threshold_name,
3481                 (void *)&cmd_config_threshold_value,
3482                 NULL,
3483         },
3484 };
3485
3486 /* *** stop *** */
3487 struct cmd_stop_result {
3488         cmdline_fixed_string_t stop;
3489 };
3490
3491 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3492                             __rte_unused struct cmdline *cl,
3493                             __rte_unused void *data)
3494 {
3495         stop_packet_forwarding();
3496 }
3497
3498 cmdline_parse_token_string_t cmd_stop_stop =
3499         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3500
3501 cmdline_parse_inst_t cmd_stop = {
3502         .f = cmd_stop_parsed,
3503         .data = NULL,
3504         .help_str = "stop: Stop packet forwarding",
3505         .tokens = {
3506                 (void *)&cmd_stop_stop,
3507                 NULL,
3508         },
3509 };
3510
3511 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3512
3513 unsigned int
3514 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3515                 unsigned int *parsed_items, int check_unique_values)
3516 {
3517         unsigned int nb_item;
3518         unsigned int value;
3519         unsigned int i;
3520         unsigned int j;
3521         int value_ok;
3522         char c;
3523
3524         /*
3525          * First parse all items in the list and store their value.
3526          */
3527         value = 0;
3528         nb_item = 0;
3529         value_ok = 0;
3530         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3531                 c = str[i];
3532                 if ((c >= '0') && (c <= '9')) {
3533                         value = (unsigned int) (value * 10 + (c - '0'));
3534                         value_ok = 1;
3535                         continue;
3536                 }
3537                 if (c != ',') {
3538                         printf("character %c is not a decimal digit\n", c);
3539                         return 0;
3540                 }
3541                 if (! value_ok) {
3542                         printf("No valid value before comma\n");
3543                         return 0;
3544                 }
3545                 if (nb_item < max_items) {
3546                         parsed_items[nb_item] = value;
3547                         value_ok = 0;
3548                         value = 0;
3549                 }
3550                 nb_item++;
3551         }
3552         if (nb_item >= max_items) {
3553                 printf("Number of %s = %u > %u (maximum items)\n",
3554                        item_name, nb_item + 1, max_items);
3555                 return 0;
3556         }
3557         parsed_items[nb_item++] = value;
3558         if (! check_unique_values)
3559                 return nb_item;
3560
3561         /*
3562          * Then, check that all values in the list are differents.
3563          * No optimization here...
3564          */
3565         for (i = 0; i < nb_item; i++) {
3566                 for (j = i + 1; j < nb_item; j++) {
3567                         if (parsed_items[j] == parsed_items[i]) {
3568                                 printf("duplicated %s %u at index %u and %u\n",
3569                                        item_name, parsed_items[i], i, j);
3570                                 return 0;
3571                         }
3572                 }
3573         }
3574         return nb_item;
3575 }
3576
3577 struct cmd_set_list_result {
3578         cmdline_fixed_string_t cmd_keyword;
3579         cmdline_fixed_string_t list_name;
3580         cmdline_fixed_string_t list_of_items;
3581 };
3582
3583 static void cmd_set_list_parsed(void *parsed_result,
3584                                 __rte_unused struct cmdline *cl,
3585                                 __rte_unused void *data)
3586 {
3587         struct cmd_set_list_result *res;
3588         union {
3589                 unsigned int lcorelist[RTE_MAX_LCORE];
3590                 unsigned int portlist[RTE_MAX_ETHPORTS];
3591         } parsed_items;
3592         unsigned int nb_item;
3593
3594         if (test_done == 0) {
3595                 printf("Please stop forwarding first\n");
3596                 return;
3597         }
3598
3599         res = parsed_result;
3600         if (!strcmp(res->list_name, "corelist")) {
3601                 nb_item = parse_item_list(res->list_of_items, "core",
3602                                           RTE_MAX_LCORE,
3603                                           parsed_items.lcorelist, 1);
3604                 if (nb_item > 0) {
3605                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3606                         fwd_config_setup();
3607                 }
3608                 return;
3609         }
3610         if (!strcmp(res->list_name, "portlist")) {
3611                 nb_item = parse_item_list(res->list_of_items, "port",
3612                                           RTE_MAX_ETHPORTS,
3613                                           parsed_items.portlist, 1);
3614                 if (nb_item > 0) {
3615                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3616                         fwd_config_setup();
3617                 }
3618         }
3619 }
3620
3621 cmdline_parse_token_string_t cmd_set_list_keyword =
3622         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3623                                  "set");
3624 cmdline_parse_token_string_t cmd_set_list_name =
3625         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3626                                  "corelist#portlist");
3627 cmdline_parse_token_string_t cmd_set_list_of_items =
3628         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3629                                  NULL);
3630
3631 cmdline_parse_inst_t cmd_set_fwd_list = {
3632         .f = cmd_set_list_parsed,
3633         .data = NULL,
3634         .help_str = "set corelist|portlist <list0[,list1]*>",
3635         .tokens = {
3636                 (void *)&cmd_set_list_keyword,
3637                 (void *)&cmd_set_list_name,
3638                 (void *)&cmd_set_list_of_items,
3639                 NULL,
3640         },
3641 };
3642
3643 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3644
3645 struct cmd_setmask_result {
3646         cmdline_fixed_string_t set;
3647         cmdline_fixed_string_t mask;
3648         uint64_t hexavalue;
3649 };
3650
3651 static void cmd_set_mask_parsed(void *parsed_result,
3652                                 __rte_unused struct cmdline *cl,
3653                                 __rte_unused void *data)
3654 {
3655         struct cmd_setmask_result *res = parsed_result;
3656
3657         if (test_done == 0) {
3658                 printf("Please stop forwarding first\n");
3659                 return;
3660         }
3661         if (!strcmp(res->mask, "coremask")) {
3662                 set_fwd_lcores_mask(res->hexavalue);
3663                 fwd_config_setup();
3664         } else if (!strcmp(res->mask, "portmask")) {
3665                 set_fwd_ports_mask(res->hexavalue);
3666                 fwd_config_setup();
3667         }
3668 }
3669
3670 cmdline_parse_token_string_t cmd_setmask_set =
3671         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3672 cmdline_parse_token_string_t cmd_setmask_mask =
3673         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3674                                  "coremask#portmask");
3675 cmdline_parse_token_num_t cmd_setmask_value =
3676         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3677
3678 cmdline_parse_inst_t cmd_set_fwd_mask = {
3679         .f = cmd_set_mask_parsed,
3680         .data = NULL,
3681         .help_str = "set coremask|portmask <hexadecimal value>",
3682         .tokens = {
3683                 (void *)&cmd_setmask_set,
3684                 (void *)&cmd_setmask_mask,
3685                 (void *)&cmd_setmask_value,
3686                 NULL,
3687         },
3688 };
3689
3690 /*
3691  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3692  */
3693 struct cmd_set_result {
3694         cmdline_fixed_string_t set;
3695         cmdline_fixed_string_t what;
3696         uint16_t value;
3697 };
3698
3699 static void cmd_set_parsed(void *parsed_result,
3700                            __rte_unused struct cmdline *cl,
3701                            __rte_unused void *data)
3702 {
3703         struct cmd_set_result *res = parsed_result;
3704         if (!strcmp(res->what, "nbport")) {
3705                 set_fwd_ports_number(res->value);
3706                 fwd_config_setup();
3707         } else if (!strcmp(res->what, "nbcore")) {
3708                 set_fwd_lcores_number(res->value);
3709                 fwd_config_setup();
3710         } else if (!strcmp(res->what, "burst"))
3711                 set_nb_pkt_per_burst(res->value);
3712         else if (!strcmp(res->what, "verbose"))
3713                 set_verbose_level(res->value);
3714 }
3715
3716 cmdline_parse_token_string_t cmd_set_set =
3717         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3718 cmdline_parse_token_string_t cmd_set_what =
3719         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3720                                  "nbport#nbcore#burst#verbose");
3721 cmdline_parse_token_num_t cmd_set_value =
3722         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3723
3724 cmdline_parse_inst_t cmd_set_numbers = {
3725         .f = cmd_set_parsed,
3726         .data = NULL,
3727         .help_str = "set nbport|nbcore|burst|verbose <value>",
3728         .tokens = {
3729                 (void *)&cmd_set_set,
3730                 (void *)&cmd_set_what,
3731                 (void *)&cmd_set_value,
3732                 NULL,
3733         },
3734 };
3735
3736 /* *** SET LOG LEVEL CONFIGURATION *** */
3737
3738 struct cmd_set_log_result {
3739         cmdline_fixed_string_t set;
3740         cmdline_fixed_string_t log;
3741         cmdline_fixed_string_t type;
3742         uint32_t level;
3743 };
3744
3745 static void
3746 cmd_set_log_parsed(void *parsed_result,
3747                    __rte_unused struct cmdline *cl,
3748                    __rte_unused void *data)
3749 {
3750         struct cmd_set_log_result *res;
3751         int ret;
3752
3753         res = parsed_result;
3754         if (!strcmp(res->type, "global"))
3755                 rte_log_set_global_level(res->level);
3756         else {
3757                 ret = rte_log_set_level_regexp(res->type, res->level);
3758                 if (ret < 0)
3759                         printf("Unable to set log level\n");
3760         }
3761 }
3762
3763 cmdline_parse_token_string_t cmd_set_log_set =
3764         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3765 cmdline_parse_token_string_t cmd_set_log_log =
3766         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3767 cmdline_parse_token_string_t cmd_set_log_type =
3768         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3769 cmdline_parse_token_num_t cmd_set_log_level =
3770         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3771
3772 cmdline_parse_inst_t cmd_set_log = {
3773         .f = cmd_set_log_parsed,
3774         .data = NULL,
3775         .help_str = "set log global|<type> <level>",
3776         .tokens = {
3777                 (void *)&cmd_set_log_set,
3778                 (void *)&cmd_set_log_log,
3779                 (void *)&cmd_set_log_type,
3780                 (void *)&cmd_set_log_level,
3781                 NULL,
3782         },
3783 };
3784
3785 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3786
3787 struct cmd_set_rxoffs_result {
3788         cmdline_fixed_string_t cmd_keyword;
3789         cmdline_fixed_string_t rxoffs;
3790         cmdline_fixed_string_t seg_offsets;
3791 };
3792
3793 static void
3794 cmd_set_rxoffs_parsed(void *parsed_result,
3795                       __rte_unused struct cmdline *cl,
3796                       __rte_unused void *data)
3797 {
3798         struct cmd_set_rxoffs_result *res;
3799         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3800         unsigned int nb_segs;
3801
3802         res = parsed_result;
3803         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3804                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3805         if (nb_segs > 0)
3806                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3807         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3808 }
3809
3810 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3811         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3812                                  cmd_keyword, "set");
3813 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3814         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3815                                  rxoffs, "rxoffs");
3816 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3817         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3818                                  seg_offsets, NULL);
3819
3820 cmdline_parse_inst_t cmd_set_rxoffs = {
3821         .f = cmd_set_rxoffs_parsed,
3822         .data = NULL,
3823         .help_str = "set rxoffs <len0[,len1]*>",
3824         .tokens = {
3825                 (void *)&cmd_set_rxoffs_keyword,
3826                 (void *)&cmd_set_rxoffs_name,
3827                 (void *)&cmd_set_rxoffs_offsets,
3828                 NULL,
3829         },
3830 };
3831
3832 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3833
3834 struct cmd_set_rxpkts_result {
3835         cmdline_fixed_string_t cmd_keyword;
3836         cmdline_fixed_string_t rxpkts;
3837         cmdline_fixed_string_t seg_lengths;
3838 };
3839
3840 static void
3841 cmd_set_rxpkts_parsed(void *parsed_result,
3842                       __rte_unused struct cmdline *cl,
3843                       __rte_unused void *data)
3844 {
3845         struct cmd_set_rxpkts_result *res;
3846         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3847         unsigned int nb_segs;
3848
3849         res = parsed_result;
3850         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3851                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3852         if (nb_segs > 0)
3853                 set_rx_pkt_segments(seg_lengths, nb_segs);
3854         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3855 }
3856
3857 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3858         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3859                                  cmd_keyword, "set");
3860 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3861         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3862                                  rxpkts, "rxpkts");
3863 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3864         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3865                                  seg_lengths, NULL);
3866
3867 cmdline_parse_inst_t cmd_set_rxpkts = {
3868         .f = cmd_set_rxpkts_parsed,
3869         .data = NULL,
3870         .help_str = "set rxpkts <len0[,len1]*>",
3871         .tokens = {
3872                 (void *)&cmd_set_rxpkts_keyword,
3873                 (void *)&cmd_set_rxpkts_name,
3874                 (void *)&cmd_set_rxpkts_lengths,
3875                 NULL,
3876         },
3877 };
3878
3879 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3880
3881 struct cmd_set_txpkts_result {
3882         cmdline_fixed_string_t cmd_keyword;
3883         cmdline_fixed_string_t txpkts;
3884         cmdline_fixed_string_t seg_lengths;
3885 };
3886
3887 static void
3888 cmd_set_txpkts_parsed(void *parsed_result,
3889                       __rte_unused struct cmdline *cl,
3890                       __rte_unused void *data)
3891 {
3892         struct cmd_set_txpkts_result *res;
3893         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3894         unsigned int nb_segs;
3895
3896         res = parsed_result;
3897         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3898                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3899         if (nb_segs > 0)
3900                 set_tx_pkt_segments(seg_lengths, nb_segs);
3901 }
3902
3903 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3904         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3905                                  cmd_keyword, "set");
3906 cmdline_parse_token_string_t cmd_set_txpkts_name =
3907         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3908                                  txpkts, "txpkts");
3909 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3910         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3911                                  seg_lengths, NULL);
3912
3913 cmdline_parse_inst_t cmd_set_txpkts = {
3914         .f = cmd_set_txpkts_parsed,
3915         .data = NULL,
3916         .help_str = "set txpkts <len0[,len1]*>",
3917         .tokens = {
3918                 (void *)&cmd_set_txpkts_keyword,
3919                 (void *)&cmd_set_txpkts_name,
3920                 (void *)&cmd_set_txpkts_lengths,
3921                 NULL,
3922         },
3923 };
3924
3925 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3926
3927 struct cmd_set_txsplit_result {
3928         cmdline_fixed_string_t cmd_keyword;
3929         cmdline_fixed_string_t txsplit;
3930         cmdline_fixed_string_t mode;
3931 };
3932
3933 static void
3934 cmd_set_txsplit_parsed(void *parsed_result,
3935                       __rte_unused struct cmdline *cl,
3936                       __rte_unused void *data)
3937 {
3938         struct cmd_set_txsplit_result *res;
3939
3940         res = parsed_result;
3941         set_tx_pkt_split(res->mode);
3942 }
3943
3944 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3945         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3946                                  cmd_keyword, "set");
3947 cmdline_parse_token_string_t cmd_set_txsplit_name =
3948         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3949                                  txsplit, "txsplit");
3950 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3951         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3952                                  mode, NULL);
3953
3954 cmdline_parse_inst_t cmd_set_txsplit = {
3955         .f = cmd_set_txsplit_parsed,
3956         .data = NULL,
3957         .help_str = "set txsplit on|off|rand",
3958         .tokens = {
3959                 (void *)&cmd_set_txsplit_keyword,
3960                 (void *)&cmd_set_txsplit_name,
3961                 (void *)&cmd_set_txsplit_mode,
3962                 NULL,
3963         },
3964 };
3965
3966 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3967
3968 struct cmd_set_txtimes_result {
3969         cmdline_fixed_string_t cmd_keyword;
3970         cmdline_fixed_string_t txtimes;
3971         cmdline_fixed_string_t tx_times;
3972 };
3973
3974 static void
3975 cmd_set_txtimes_parsed(void *parsed_result,
3976                        __rte_unused struct cmdline *cl,
3977                        __rte_unused void *data)
3978 {
3979         struct cmd_set_txtimes_result *res;
3980         unsigned int tx_times[2] = {0, 0};
3981         unsigned int n_times;
3982
3983         res = parsed_result;
3984         n_times = parse_item_list(res->tx_times, "tx times",
3985                                   2, tx_times, 0);
3986         if (n_times == 2)
3987                 set_tx_pkt_times(tx_times);
3988 }
3989
3990 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3991         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3992                                  cmd_keyword, "set");
3993 cmdline_parse_token_string_t cmd_set_txtimes_name =
3994         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3995                                  txtimes, "txtimes");
3996 cmdline_parse_token_string_t cmd_set_txtimes_value =
3997         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3998                                  tx_times, NULL);
3999
4000 cmdline_parse_inst_t cmd_set_txtimes = {
4001         .f = cmd_set_txtimes_parsed,
4002         .data = NULL,
4003         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4004         .tokens = {
4005                 (void *)&cmd_set_txtimes_keyword,
4006                 (void *)&cmd_set_txtimes_name,
4007                 (void *)&cmd_set_txtimes_value,
4008                 NULL,
4009         },
4010 };
4011
4012 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4013 struct cmd_rx_vlan_filter_all_result {
4014         cmdline_fixed_string_t rx_vlan;
4015         cmdline_fixed_string_t what;
4016         cmdline_fixed_string_t all;
4017         portid_t port_id;
4018 };
4019
4020 static void
4021 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4022                               __rte_unused struct cmdline *cl,
4023                               __rte_unused void *data)
4024 {
4025         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4026
4027         if (!strcmp(res->what, "add"))
4028                 rx_vlan_all_filter_set(res->port_id, 1);
4029         else
4030                 rx_vlan_all_filter_set(res->port_id, 0);
4031 }
4032
4033 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4034         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4035                                  rx_vlan, "rx_vlan");
4036 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4037         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4038                                  what, "add#rm");
4039 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4040         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4041                                  all, "all");
4042 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4043         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4044                               port_id, RTE_UINT16);
4045
4046 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4047         .f = cmd_rx_vlan_filter_all_parsed,
4048         .data = NULL,
4049         .help_str = "rx_vlan add|rm all <port_id>: "
4050                 "Add/Remove all identifiers to/from the set of VLAN "
4051                 "identifiers filtered by a port",
4052         .tokens = {
4053                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4054                 (void *)&cmd_rx_vlan_filter_all_what,
4055                 (void *)&cmd_rx_vlan_filter_all_all,
4056                 (void *)&cmd_rx_vlan_filter_all_portid,
4057                 NULL,
4058         },
4059 };
4060
4061 /* *** VLAN OFFLOAD SET ON A PORT *** */
4062 struct cmd_vlan_offload_result {
4063         cmdline_fixed_string_t vlan;
4064         cmdline_fixed_string_t set;
4065         cmdline_fixed_string_t vlan_type;
4066         cmdline_fixed_string_t what;
4067         cmdline_fixed_string_t on;
4068         cmdline_fixed_string_t port_id;
4069 };
4070
4071 static void
4072 cmd_vlan_offload_parsed(void *parsed_result,
4073                           __rte_unused struct cmdline *cl,
4074                           __rte_unused void *data)
4075 {
4076         int on;
4077         struct cmd_vlan_offload_result *res = parsed_result;
4078         char *str;
4079         int i, len = 0;
4080         portid_t port_id = 0;
4081         unsigned int tmp;
4082
4083         str = res->port_id;
4084         len = strnlen(str, STR_TOKEN_SIZE);
4085         i = 0;
4086         /* Get port_id first */
4087         while(i < len){
4088                 if(str[i] == ',')
4089                         break;
4090
4091                 i++;
4092         }
4093         str[i]='\0';
4094         tmp = strtoul(str, NULL, 0);
4095         /* If port_id greater that what portid_t can represent, return */
4096         if(tmp >= RTE_MAX_ETHPORTS)
4097                 return;
4098         port_id = (portid_t)tmp;
4099
4100         if (!strcmp(res->on, "on"))
4101                 on = 1;
4102         else
4103                 on = 0;
4104
4105         if (!strcmp(res->what, "strip"))
4106                 rx_vlan_strip_set(port_id,  on);
4107         else if(!strcmp(res->what, "stripq")){
4108                 uint16_t queue_id = 0;
4109
4110                 /* No queue_id, return */
4111                 if(i + 1 >= len) {
4112                         printf("must specify (port,queue_id)\n");
4113                         return;
4114                 }
4115                 tmp = strtoul(str + i + 1, NULL, 0);
4116                 /* If queue_id greater that what 16-bits can represent, return */
4117                 if(tmp > 0xffff)
4118                         return;
4119
4120                 queue_id = (uint16_t)tmp;
4121                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4122         }
4123         else if (!strcmp(res->what, "filter"))
4124                 rx_vlan_filter_set(port_id, on);
4125         else if (!strcmp(res->what, "qinq_strip"))
4126                 rx_vlan_qinq_strip_set(port_id, on);
4127         else
4128                 vlan_extend_set(port_id, on);
4129
4130         return;
4131 }
4132
4133 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4134         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4135                                  vlan, "vlan");
4136 cmdline_parse_token_string_t cmd_vlan_offload_set =
4137         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4138                                  set, "set");
4139 cmdline_parse_token_string_t cmd_vlan_offload_what =
4140         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4141                                 what, "strip#filter#qinq_strip#extend#stripq");
4142 cmdline_parse_token_string_t cmd_vlan_offload_on =
4143         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4144                               on, "on#off");
4145 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4146         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4147                               port_id, NULL);
4148
4149 cmdline_parse_inst_t cmd_vlan_offload = {
4150         .f = cmd_vlan_offload_parsed,
4151         .data = NULL,
4152         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4153                 "<port_id[,queue_id]>: "
4154                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4155         .tokens = {
4156                 (void *)&cmd_vlan_offload_vlan,
4157                 (void *)&cmd_vlan_offload_set,
4158                 (void *)&cmd_vlan_offload_what,
4159                 (void *)&cmd_vlan_offload_on,
4160                 (void *)&cmd_vlan_offload_portid,
4161                 NULL,
4162         },
4163 };
4164
4165 /* *** VLAN TPID SET ON A PORT *** */
4166 struct cmd_vlan_tpid_result {
4167         cmdline_fixed_string_t vlan;
4168         cmdline_fixed_string_t set;
4169         cmdline_fixed_string_t vlan_type;
4170         cmdline_fixed_string_t what;
4171         uint16_t tp_id;
4172         portid_t port_id;
4173 };
4174
4175 static void
4176 cmd_vlan_tpid_parsed(void *parsed_result,
4177                           __rte_unused struct cmdline *cl,
4178                           __rte_unused void *data)
4179 {
4180         struct cmd_vlan_tpid_result *res = parsed_result;
4181         enum rte_vlan_type vlan_type;
4182
4183         if (!strcmp(res->vlan_type, "inner"))
4184                 vlan_type = ETH_VLAN_TYPE_INNER;
4185         else if (!strcmp(res->vlan_type, "outer"))
4186                 vlan_type = ETH_VLAN_TYPE_OUTER;
4187         else {
4188                 printf("Unknown vlan type\n");
4189                 return;
4190         }
4191         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4192 }
4193
4194 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4195         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4196                                  vlan, "vlan");
4197 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4198         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4199                                  set, "set");
4200 cmdline_parse_token_string_t cmd_vlan_type =
4201         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4202                                  vlan_type, "inner#outer");
4203 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4204         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4205                                  what, "tpid");
4206 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4207         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4208                               tp_id, RTE_UINT16);
4209 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4210         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4211                               port_id, RTE_UINT16);
4212
4213 cmdline_parse_inst_t cmd_vlan_tpid = {
4214         .f = cmd_vlan_tpid_parsed,
4215         .data = NULL,
4216         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4217                 "Set the VLAN Ether type",
4218         .tokens = {
4219                 (void *)&cmd_vlan_tpid_vlan,
4220                 (void *)&cmd_vlan_tpid_set,
4221                 (void *)&cmd_vlan_type,
4222                 (void *)&cmd_vlan_tpid_what,
4223                 (void *)&cmd_vlan_tpid_tpid,
4224                 (void *)&cmd_vlan_tpid_portid,
4225                 NULL,
4226         },
4227 };
4228
4229 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4230 struct cmd_rx_vlan_filter_result {
4231         cmdline_fixed_string_t rx_vlan;
4232         cmdline_fixed_string_t what;
4233         uint16_t vlan_id;
4234         portid_t port_id;
4235 };
4236
4237 static void
4238 cmd_rx_vlan_filter_parsed(void *parsed_result,
4239                           __rte_unused struct cmdline *cl,
4240                           __rte_unused void *data)
4241 {
4242         struct cmd_rx_vlan_filter_result *res = parsed_result;
4243
4244         if (!strcmp(res->what, "add"))
4245                 rx_vft_set(res->port_id, res->vlan_id, 1);
4246         else
4247                 rx_vft_set(res->port_id, res->vlan_id, 0);
4248 }
4249
4250 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4251         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4252                                  rx_vlan, "rx_vlan");
4253 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4254         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4255                                  what, "add#rm");
4256 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4257         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4258                               vlan_id, RTE_UINT16);
4259 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4260         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4261                               port_id, RTE_UINT16);
4262
4263 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4264         .f = cmd_rx_vlan_filter_parsed,
4265         .data = NULL,
4266         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4267                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4268                 "identifiers filtered by a port",
4269         .tokens = {
4270                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4271                 (void *)&cmd_rx_vlan_filter_what,
4272                 (void *)&cmd_rx_vlan_filter_vlanid,
4273                 (void *)&cmd_rx_vlan_filter_portid,
4274                 NULL,
4275         },
4276 };
4277
4278 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4279 struct cmd_tx_vlan_set_result {
4280         cmdline_fixed_string_t tx_vlan;
4281         cmdline_fixed_string_t set;
4282         portid_t port_id;
4283         uint16_t vlan_id;
4284 };
4285
4286 static void
4287 cmd_tx_vlan_set_parsed(void *parsed_result,
4288                        __rte_unused struct cmdline *cl,
4289                        __rte_unused void *data)
4290 {
4291         struct cmd_tx_vlan_set_result *res = parsed_result;
4292
4293         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4294                 return;
4295
4296         if (!port_is_stopped(res->port_id)) {
4297                 printf("Please stop port %d first\n", res->port_id);
4298                 return;
4299         }
4300
4301         tx_vlan_set(res->port_id, res->vlan_id);
4302
4303         cmd_reconfig_device_queue(res->port_id, 1, 1);
4304 }
4305
4306 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4307         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4308                                  tx_vlan, "tx_vlan");
4309 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4310         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4311                                  set, "set");
4312 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4313         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4314                               port_id, RTE_UINT16);
4315 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4316         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4317                               vlan_id, RTE_UINT16);
4318
4319 cmdline_parse_inst_t cmd_tx_vlan_set = {
4320         .f = cmd_tx_vlan_set_parsed,
4321         .data = NULL,
4322         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4323                 "Enable hardware insertion of a single VLAN header "
4324                 "with a given TAG Identifier in packets sent on a port",
4325         .tokens = {
4326                 (void *)&cmd_tx_vlan_set_tx_vlan,
4327                 (void *)&cmd_tx_vlan_set_set,
4328                 (void *)&cmd_tx_vlan_set_portid,
4329                 (void *)&cmd_tx_vlan_set_vlanid,
4330                 NULL,
4331         },
4332 };
4333
4334 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4335 struct cmd_tx_vlan_set_qinq_result {
4336         cmdline_fixed_string_t tx_vlan;
4337         cmdline_fixed_string_t set;
4338         portid_t port_id;
4339         uint16_t vlan_id;
4340         uint16_t vlan_id_outer;
4341 };
4342
4343 static void
4344 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4345                             __rte_unused struct cmdline *cl,
4346                             __rte_unused void *data)
4347 {
4348         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4349
4350         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4351                 return;
4352
4353         if (!port_is_stopped(res->port_id)) {
4354                 printf("Please stop port %d first\n", res->port_id);
4355                 return;
4356         }
4357
4358         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4359
4360         cmd_reconfig_device_queue(res->port_id, 1, 1);
4361 }
4362
4363 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4364         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4365                 tx_vlan, "tx_vlan");
4366 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4367         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4368                 set, "set");
4369 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4370         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4371                 port_id, RTE_UINT16);
4372 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4373         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4374                 vlan_id, RTE_UINT16);
4375 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4376         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4377                 vlan_id_outer, RTE_UINT16);
4378
4379 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4380         .f = cmd_tx_vlan_set_qinq_parsed,
4381         .data = NULL,
4382         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4383                 "Enable hardware insertion of double VLAN header "
4384                 "with given TAG Identifiers in packets sent on a port",
4385         .tokens = {
4386                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4387                 (void *)&cmd_tx_vlan_set_qinq_set,
4388                 (void *)&cmd_tx_vlan_set_qinq_portid,
4389                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4390                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4391                 NULL,
4392         },
4393 };
4394
4395 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4396 struct cmd_tx_vlan_set_pvid_result {
4397         cmdline_fixed_string_t tx_vlan;
4398         cmdline_fixed_string_t set;
4399         cmdline_fixed_string_t pvid;
4400         portid_t port_id;
4401         uint16_t vlan_id;
4402         cmdline_fixed_string_t mode;
4403 };
4404
4405 static void
4406 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4407                             __rte_unused struct cmdline *cl,
4408                             __rte_unused void *data)
4409 {
4410         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4411
4412         if (strcmp(res->mode, "on") == 0)
4413                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4414         else
4415                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4416 }
4417
4418 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4419         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4420                                  tx_vlan, "tx_vlan");
4421 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4422         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4423                                  set, "set");
4424 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4425         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4426                                  pvid, "pvid");
4427 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4428         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4429                              port_id, RTE_UINT16);
4430 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4431         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4432                               vlan_id, RTE_UINT16);
4433 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4434         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4435                                  mode, "on#off");
4436
4437 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4438         .f = cmd_tx_vlan_set_pvid_parsed,
4439         .data = NULL,
4440         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4441         .tokens = {
4442                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4443                 (void *)&cmd_tx_vlan_set_pvid_set,
4444                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4445                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4446                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4447                 (void *)&cmd_tx_vlan_set_pvid_mode,
4448                 NULL,
4449         },
4450 };
4451
4452 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4453 struct cmd_tx_vlan_reset_result {
4454         cmdline_fixed_string_t tx_vlan;
4455         cmdline_fixed_string_t reset;
4456         portid_t port_id;
4457 };
4458
4459 static void
4460 cmd_tx_vlan_reset_parsed(void *parsed_result,
4461                          __rte_unused struct cmdline *cl,
4462                          __rte_unused void *data)
4463 {
4464         struct cmd_tx_vlan_reset_result *res = parsed_result;
4465
4466         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4467                 return;
4468
4469         if (!port_is_stopped(res->port_id)) {
4470                 printf("Please stop port %d first\n", res->port_id);
4471                 return;
4472         }
4473
4474         tx_vlan_reset(res->port_id);
4475
4476         cmd_reconfig_device_queue(res->port_id, 1, 1);
4477 }
4478
4479 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4480         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4481                                  tx_vlan, "tx_vlan");
4482 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4483         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4484                                  reset, "reset");
4485 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4486         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4487                               port_id, RTE_UINT16);
4488
4489 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4490         .f = cmd_tx_vlan_reset_parsed,
4491         .data = NULL,
4492         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4493                 "VLAN header in packets sent on a port",
4494         .tokens = {
4495                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4496                 (void *)&cmd_tx_vlan_reset_reset,
4497                 (void *)&cmd_tx_vlan_reset_portid,
4498                 NULL,
4499         },
4500 };
4501
4502
4503 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4504 struct cmd_csum_result {
4505         cmdline_fixed_string_t csum;
4506         cmdline_fixed_string_t mode;
4507         cmdline_fixed_string_t proto;
4508         cmdline_fixed_string_t hwsw;
4509         portid_t port_id;
4510 };
4511
4512 static void
4513 csum_show(int port_id)
4514 {
4515         struct rte_eth_dev_info dev_info;
4516         uint64_t tx_offloads;
4517         int ret;
4518
4519         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4520         printf("Parse tunnel is %s\n",
4521                 (ports[port_id].parse_tunnel) ? "on" : "off");
4522         printf("IP checksum offload is %s\n",
4523                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4524         printf("UDP checksum offload is %s\n",
4525                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4526         printf("TCP checksum offload is %s\n",
4527                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4528         printf("SCTP checksum offload is %s\n",
4529                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4530         printf("Outer-Ip checksum offload is %s\n",
4531                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4532         printf("Outer-Udp checksum offload is %s\n",
4533                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4534
4535         /* display warnings if configuration is not supported by the NIC */
4536         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4537         if (ret != 0)
4538                 return;
4539
4540         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4541                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4542                 printf("Warning: hardware IP checksum enabled but not "
4543                         "supported by port %d\n", port_id);
4544         }
4545         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4546                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4547                 printf("Warning: hardware UDP checksum enabled but not "
4548                         "supported by port %d\n", port_id);
4549         }
4550         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4551                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4552                 printf("Warning: hardware TCP checksum enabled but not "
4553                         "supported by port %d\n", port_id);
4554         }
4555         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4556                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4557                 printf("Warning: hardware SCTP checksum enabled but not "
4558                         "supported by port %d\n", port_id);
4559         }
4560         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4561                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4562                 printf("Warning: hardware outer IP checksum enabled but not "
4563                         "supported by port %d\n", port_id);
4564         }
4565         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4566                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4567                         == 0) {
4568                 printf("Warning: hardware outer UDP checksum enabled but not "
4569                         "supported by port %d\n", port_id);
4570         }
4571 }
4572
4573 static void
4574 cmd_config_queue_tx_offloads(struct rte_port *port)
4575 {
4576         int k;
4577
4578         /* Apply queue tx offloads configuration */
4579         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4580                 port->tx_conf[k].offloads =
4581                         port->dev_conf.txmode.offloads;
4582 }
4583
4584 static void
4585 cmd_csum_parsed(void *parsed_result,
4586                        __rte_unused struct cmdline *cl,
4587                        __rte_unused void *data)
4588 {
4589         struct cmd_csum_result *res = parsed_result;
4590         int hw = 0;
4591         uint64_t csum_offloads = 0;
4592         struct rte_eth_dev_info dev_info;
4593         int ret;
4594
4595         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4596                 printf("invalid port %d\n", res->port_id);
4597                 return;
4598         }
4599         if (!port_is_stopped(res->port_id)) {
4600                 printf("Please stop port %d first\n", res->port_id);
4601                 return;
4602         }
4603
4604         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4605         if (ret != 0)
4606                 return;
4607
4608         if (!strcmp(res->mode, "set")) {
4609
4610                 if (!strcmp(res->hwsw, "hw"))
4611                         hw = 1;
4612
4613                 if (!strcmp(res->proto, "ip")) {
4614                         if (hw == 0 || (dev_info.tx_offload_capa &
4615                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4616                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4617                         } else {
4618                                 printf("IP checksum offload is not supported "
4619                                        "by port %u\n", res->port_id);
4620                         }
4621                 } else if (!strcmp(res->proto, "udp")) {
4622                         if (hw == 0 || (dev_info.tx_offload_capa &
4623                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4624                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4625                         } else {
4626                                 printf("UDP checksum offload is not supported "
4627                                        "by port %u\n", res->port_id);
4628                         }
4629                 } else if (!strcmp(res->proto, "tcp")) {
4630                         if (hw == 0 || (dev_info.tx_offload_capa &
4631                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4632                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4633                         } else {
4634                                 printf("TCP checksum offload is not supported "
4635                                        "by port %u\n", res->port_id);
4636                         }
4637                 } else if (!strcmp(res->proto, "sctp")) {
4638                         if (hw == 0 || (dev_info.tx_offload_capa &
4639                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4640                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4641                         } else {
4642                                 printf("SCTP checksum offload is not supported "
4643                                        "by port %u\n", res->port_id);
4644                         }
4645                 } else if (!strcmp(res->proto, "outer-ip")) {
4646                         if (hw == 0 || (dev_info.tx_offload_capa &
4647                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4648                                 csum_offloads |=
4649                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4650                         } else {
4651                                 printf("Outer IP checksum offload is not "
4652                                        "supported by port %u\n", res->port_id);
4653                         }
4654                 } else if (!strcmp(res->proto, "outer-udp")) {
4655                         if (hw == 0 || (dev_info.tx_offload_capa &
4656                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4657                                 csum_offloads |=
4658                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4659                         } else {
4660                                 printf("Outer UDP checksum offload is not "
4661                                        "supported by port %u\n", res->port_id);
4662                         }
4663                 }
4664
4665                 if (hw) {
4666                         ports[res->port_id].dev_conf.txmode.offloads |=
4667                                                         csum_offloads;
4668                 } else {
4669                         ports[res->port_id].dev_conf.txmode.offloads &=
4670                                                         (~csum_offloads);
4671                 }
4672                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4673         }
4674         csum_show(res->port_id);
4675
4676         cmd_reconfig_device_queue(res->port_id, 1, 1);
4677 }
4678
4679 cmdline_parse_token_string_t cmd_csum_csum =
4680         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4681                                 csum, "csum");
4682 cmdline_parse_token_string_t cmd_csum_mode =
4683         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4684                                 mode, "set");
4685 cmdline_parse_token_string_t cmd_csum_proto =
4686         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4687                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4688 cmdline_parse_token_string_t cmd_csum_hwsw =
4689         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4690                                 hwsw, "hw#sw");
4691 cmdline_parse_token_num_t cmd_csum_portid =
4692         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4693                                 port_id, RTE_UINT16);
4694
4695 cmdline_parse_inst_t cmd_csum_set = {
4696         .f = cmd_csum_parsed,
4697         .data = NULL,
4698         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4699                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4700                 "using csum forward engine",
4701         .tokens = {
4702                 (void *)&cmd_csum_csum,
4703                 (void *)&cmd_csum_mode,
4704                 (void *)&cmd_csum_proto,
4705                 (void *)&cmd_csum_hwsw,
4706                 (void *)&cmd_csum_portid,
4707                 NULL,
4708         },
4709 };
4710
4711 cmdline_parse_token_string_t cmd_csum_mode_show =
4712         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4713                                 mode, "show");
4714
4715 cmdline_parse_inst_t cmd_csum_show = {
4716         .f = cmd_csum_parsed,
4717         .data = NULL,
4718         .help_str = "csum show <port_id>: Show checksum offload configuration",
4719         .tokens = {
4720                 (void *)&cmd_csum_csum,
4721                 (void *)&cmd_csum_mode_show,
4722                 (void *)&cmd_csum_portid,
4723                 NULL,
4724         },
4725 };
4726
4727 /* Enable/disable tunnel parsing */
4728 struct cmd_csum_tunnel_result {
4729         cmdline_fixed_string_t csum;
4730         cmdline_fixed_string_t parse;
4731         cmdline_fixed_string_t onoff;
4732         portid_t port_id;
4733 };
4734
4735 static void
4736 cmd_csum_tunnel_parsed(void *parsed_result,
4737                        __rte_unused struct cmdline *cl,
4738                        __rte_unused void *data)
4739 {
4740         struct cmd_csum_tunnel_result *res = parsed_result;
4741
4742         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4743                 return;
4744
4745         if (!strcmp(res->onoff, "on"))
4746                 ports[res->port_id].parse_tunnel = 1;
4747         else
4748                 ports[res->port_id].parse_tunnel = 0;
4749
4750         csum_show(res->port_id);
4751 }
4752
4753 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4754         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4755                                 csum, "csum");
4756 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4757         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4758                                 parse, "parse-tunnel");
4759 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4760         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4761                                 onoff, "on#off");
4762 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4763         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4764                                 port_id, RTE_UINT16);
4765
4766 cmdline_parse_inst_t cmd_csum_tunnel = {
4767         .f = cmd_csum_tunnel_parsed,
4768         .data = NULL,
4769         .help_str = "csum parse-tunnel on|off <port_id>: "
4770                 "Enable/Disable parsing of tunnels for csum engine",
4771         .tokens = {
4772                 (void *)&cmd_csum_tunnel_csum,
4773                 (void *)&cmd_csum_tunnel_parse,
4774                 (void *)&cmd_csum_tunnel_onoff,
4775                 (void *)&cmd_csum_tunnel_portid,
4776                 NULL,
4777         },
4778 };
4779
4780 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4781 struct cmd_tso_set_result {
4782         cmdline_fixed_string_t tso;
4783         cmdline_fixed_string_t mode;
4784         uint16_t tso_segsz;
4785         portid_t port_id;
4786 };
4787
4788 static void
4789 cmd_tso_set_parsed(void *parsed_result,
4790                        __rte_unused struct cmdline *cl,
4791                        __rte_unused void *data)
4792 {
4793         struct cmd_tso_set_result *res = parsed_result;
4794         struct rte_eth_dev_info dev_info;
4795         int ret;
4796
4797         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4798                 return;
4799         if (!port_is_stopped(res->port_id)) {
4800                 printf("Please stop port %d first\n", res->port_id);
4801                 return;
4802         }
4803
4804         if (!strcmp(res->mode, "set"))
4805                 ports[res->port_id].tso_segsz = res->tso_segsz;
4806
4807         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4808         if (ret != 0)
4809                 return;
4810
4811         if ((ports[res->port_id].tso_segsz != 0) &&
4812                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4813                 printf("Error: TSO is not supported by port %d\n",
4814                        res->port_id);
4815                 return;
4816         }
4817
4818         if (ports[res->port_id].tso_segsz == 0) {
4819                 ports[res->port_id].dev_conf.txmode.offloads &=
4820                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4821                 printf("TSO for non-tunneled packets is disabled\n");
4822         } else {
4823                 ports[res->port_id].dev_conf.txmode.offloads |=
4824                                                 DEV_TX_OFFLOAD_TCP_TSO;
4825                 printf("TSO segment size for non-tunneled packets is %d\n",
4826                         ports[res->port_id].tso_segsz);
4827         }
4828         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4829
4830         /* display warnings if configuration is not supported by the NIC */
4831         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4832         if (ret != 0)
4833                 return;
4834
4835         if ((ports[res->port_id].tso_segsz != 0) &&
4836                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4837                 printf("Warning: TSO enabled but not "
4838                         "supported by port %d\n", res->port_id);
4839         }
4840
4841         cmd_reconfig_device_queue(res->port_id, 1, 1);
4842 }
4843
4844 cmdline_parse_token_string_t cmd_tso_set_tso =
4845         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4846                                 tso, "tso");
4847 cmdline_parse_token_string_t cmd_tso_set_mode =
4848         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4849                                 mode, "set");
4850 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4851         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4852                                 tso_segsz, RTE_UINT16);
4853 cmdline_parse_token_num_t cmd_tso_set_portid =
4854         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4855                                 port_id, RTE_UINT16);
4856
4857 cmdline_parse_inst_t cmd_tso_set = {
4858         .f = cmd_tso_set_parsed,
4859         .data = NULL,
4860         .help_str = "tso set <tso_segsz> <port_id>: "
4861                 "Set TSO segment size of non-tunneled packets for csum engine "
4862                 "(0 to disable)",
4863         .tokens = {
4864                 (void *)&cmd_tso_set_tso,
4865                 (void *)&cmd_tso_set_mode,
4866                 (void *)&cmd_tso_set_tso_segsz,
4867                 (void *)&cmd_tso_set_portid,
4868                 NULL,
4869         },
4870 };
4871
4872 cmdline_parse_token_string_t cmd_tso_show_mode =
4873         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4874                                 mode, "show");
4875
4876
4877 cmdline_parse_inst_t cmd_tso_show = {
4878         .f = cmd_tso_set_parsed,
4879         .data = NULL,
4880         .help_str = "tso show <port_id>: "
4881                 "Show TSO segment size of non-tunneled packets for csum engine",
4882         .tokens = {
4883                 (void *)&cmd_tso_set_tso,
4884                 (void *)&cmd_tso_show_mode,
4885                 (void *)&cmd_tso_set_portid,
4886                 NULL,
4887         },
4888 };
4889
4890 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4891 struct cmd_tunnel_tso_set_result {
4892         cmdline_fixed_string_t tso;
4893         cmdline_fixed_string_t mode;
4894         uint16_t tso_segsz;
4895         portid_t port_id;
4896 };
4897
4898 static struct rte_eth_dev_info
4899 check_tunnel_tso_nic_support(portid_t port_id)
4900 {
4901         struct rte_eth_dev_info dev_info;
4902
4903         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4904                 return dev_info;
4905
4906         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4907                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4908                        "not enabled for port %d\n", port_id);
4909         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4910                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4911                        "not enabled for port %d\n", port_id);
4912         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4913                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4914                        "not enabled for port %d\n", port_id);
4915         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4916                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4917                        "not enabled for port %d\n", port_id);
4918         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4919                 printf("Warning: IP TUNNEL TSO not supported therefore "
4920                        "not enabled for port %d\n", port_id);
4921         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4922                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4923                        "not enabled for port %d\n", port_id);
4924         return dev_info;
4925 }
4926
4927 static void
4928 cmd_tunnel_tso_set_parsed(void *parsed_result,
4929                           __rte_unused struct cmdline *cl,
4930                           __rte_unused void *data)
4931 {
4932         struct cmd_tunnel_tso_set_result *res = parsed_result;
4933         struct rte_eth_dev_info dev_info;
4934
4935         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4936                 return;
4937         if (!port_is_stopped(res->port_id)) {
4938                 printf("Please stop port %d first\n", res->port_id);
4939                 return;
4940         }
4941
4942         if (!strcmp(res->mode, "set"))
4943                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4944
4945         dev_info = check_tunnel_tso_nic_support(res->port_id);
4946         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4947                 ports[res->port_id].dev_conf.txmode.offloads &=
4948                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4949                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4950                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4951                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4952                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4953                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4954                 printf("TSO for tunneled packets is disabled\n");
4955         } else {
4956                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4957                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4958                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4959                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4960                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4961                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4962
4963                 ports[res->port_id].dev_conf.txmode.offloads |=
4964                         (tso_offloads & dev_info.tx_offload_capa);
4965                 printf("TSO segment size for tunneled packets is %d\n",
4966                         ports[res->port_id].tunnel_tso_segsz);
4967
4968                 /* Below conditions are needed to make it work:
4969                  * (1) tunnel TSO is supported by the NIC;
4970                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4971                  * are recognized;
4972                  * (3) for tunneled pkts with outer L3 of IPv4,
4973                  * "csum set outer-ip" must be set to hw, because after tso,
4974                  * total_len of outer IP header is changed, and the checksum
4975                  * of outer IP header calculated by sw should be wrong; that
4976                  * is not necessary for IPv6 tunneled pkts because there's no
4977                  * checksum in IP header anymore.
4978                  */
4979
4980                 if (!ports[res->port_id].parse_tunnel)
4981                         printf("Warning: csum parse_tunnel must be set "
4982                                 "so that tunneled packets are recognized\n");
4983                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4984                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4985                         printf("Warning: csum set outer-ip must be set to hw "
4986                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4987         }
4988
4989         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4990         cmd_reconfig_device_queue(res->port_id, 1, 1);
4991 }
4992
4993 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4994         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4995                                 tso, "tunnel_tso");
4996 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4997         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4998                                 mode, "set");
4999 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5000         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5001                                 tso_segsz, RTE_UINT16);
5002 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5003         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5004                                 port_id, RTE_UINT16);
5005
5006 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5007         .f = cmd_tunnel_tso_set_parsed,
5008         .data = NULL,
5009         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5010                 "Set TSO segment size of tunneled packets for csum engine "
5011                 "(0 to disable)",
5012         .tokens = {
5013                 (void *)&cmd_tunnel_tso_set_tso,
5014                 (void *)&cmd_tunnel_tso_set_mode,
5015                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5016                 (void *)&cmd_tunnel_tso_set_portid,
5017                 NULL,
5018         },
5019 };
5020
5021 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5022         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5023                                 mode, "show");
5024
5025
5026 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5027         .f = cmd_tunnel_tso_set_parsed,
5028         .data = NULL,
5029         .help_str = "tunnel_tso show <port_id> "
5030                 "Show TSO segment size of tunneled packets for csum engine",
5031         .tokens = {
5032                 (void *)&cmd_tunnel_tso_set_tso,
5033                 (void *)&cmd_tunnel_tso_show_mode,
5034                 (void *)&cmd_tunnel_tso_set_portid,
5035                 NULL,
5036         },
5037 };
5038
5039 /* *** SET GRO FOR A PORT *** */
5040 struct cmd_gro_enable_result {
5041         cmdline_fixed_string_t cmd_set;
5042         cmdline_fixed_string_t cmd_port;
5043         cmdline_fixed_string_t cmd_keyword;
5044         cmdline_fixed_string_t cmd_onoff;
5045         portid_t cmd_pid;
5046 };
5047
5048 static void
5049 cmd_gro_enable_parsed(void *parsed_result,
5050                 __rte_unused struct cmdline *cl,
5051                 __rte_unused void *data)
5052 {
5053         struct cmd_gro_enable_result *res;
5054
5055         res = parsed_result;
5056         if (!strcmp(res->cmd_keyword, "gro"))
5057                 setup_gro(res->cmd_onoff, res->cmd_pid);
5058 }
5059
5060 cmdline_parse_token_string_t cmd_gro_enable_set =
5061         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5062                         cmd_set, "set");
5063 cmdline_parse_token_string_t cmd_gro_enable_port =
5064         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5065                         cmd_keyword, "port");
5066 cmdline_parse_token_num_t cmd_gro_enable_pid =
5067         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5068                         cmd_pid, RTE_UINT16);
5069 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5070         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5071                         cmd_keyword, "gro");
5072 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5073         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5074                         cmd_onoff, "on#off");
5075
5076 cmdline_parse_inst_t cmd_gro_enable = {
5077         .f = cmd_gro_enable_parsed,
5078         .data = NULL,
5079         .help_str = "set port <port_id> gro on|off",
5080         .tokens = {
5081                 (void *)&cmd_gro_enable_set,
5082                 (void *)&cmd_gro_enable_port,
5083                 (void *)&cmd_gro_enable_pid,
5084                 (void *)&cmd_gro_enable_keyword,
5085                 (void *)&cmd_gro_enable_onoff,
5086                 NULL,
5087         },
5088 };
5089
5090 /* *** DISPLAY GRO CONFIGURATION *** */
5091 struct cmd_gro_show_result {
5092         cmdline_fixed_string_t cmd_show;
5093         cmdline_fixed_string_t cmd_port;
5094         cmdline_fixed_string_t cmd_keyword;
5095         portid_t cmd_pid;
5096 };
5097
5098 static void
5099 cmd_gro_show_parsed(void *parsed_result,
5100                 __rte_unused struct cmdline *cl,
5101                 __rte_unused void *data)
5102 {
5103         struct cmd_gro_show_result *res;
5104
5105         res = parsed_result;
5106         if (!strcmp(res->cmd_keyword, "gro"))
5107                 show_gro(res->cmd_pid);
5108 }
5109
5110 cmdline_parse_token_string_t cmd_gro_show_show =
5111         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5112                         cmd_show, "show");
5113 cmdline_parse_token_string_t cmd_gro_show_port =
5114         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5115                         cmd_port, "port");
5116 cmdline_parse_token_num_t cmd_gro_show_pid =
5117         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5118                         cmd_pid, RTE_UINT16);
5119 cmdline_parse_token_string_t cmd_gro_show_keyword =
5120         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5121                         cmd_keyword, "gro");
5122
5123 cmdline_parse_inst_t cmd_gro_show = {
5124         .f = cmd_gro_show_parsed,
5125         .data = NULL,
5126         .help_str = "show port <port_id> gro",
5127         .tokens = {
5128                 (void *)&cmd_gro_show_show,
5129                 (void *)&cmd_gro_show_port,
5130                 (void *)&cmd_gro_show_pid,
5131                 (void *)&cmd_gro_show_keyword,
5132                 NULL,
5133         },
5134 };
5135
5136 /* *** SET FLUSH CYCLES FOR GRO *** */
5137 struct cmd_gro_flush_result {
5138         cmdline_fixed_string_t cmd_set;
5139         cmdline_fixed_string_t cmd_keyword;
5140         cmdline_fixed_string_t cmd_flush;
5141         uint8_t cmd_cycles;
5142 };
5143
5144 static void
5145 cmd_gro_flush_parsed(void *parsed_result,
5146                 __rte_unused struct cmdline *cl,
5147                 __rte_unused void *data)
5148 {
5149         struct cmd_gro_flush_result *res;
5150
5151         res = parsed_result;
5152         if ((!strcmp(res->cmd_keyword, "gro")) &&
5153                         (!strcmp(res->cmd_flush, "flush")))
5154                 setup_gro_flush_cycles(res->cmd_cycles);
5155 }
5156
5157 cmdline_parse_token_string_t cmd_gro_flush_set =
5158         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5159                         cmd_set, "set");
5160 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5161         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5162                         cmd_keyword, "gro");
5163 cmdline_parse_token_string_t cmd_gro_flush_flush =
5164         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5165                         cmd_flush, "flush");
5166 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5167         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5168                         cmd_cycles, RTE_UINT8);
5169
5170 cmdline_parse_inst_t cmd_gro_flush = {
5171         .f = cmd_gro_flush_parsed,
5172         .data = NULL,
5173         .help_str = "set gro flush <cycles>",
5174         .tokens = {
5175                 (void *)&cmd_gro_flush_set,
5176                 (void *)&cmd_gro_flush_keyword,
5177                 (void *)&cmd_gro_flush_flush,
5178                 (void *)&cmd_gro_flush_cycles,
5179                 NULL,
5180         },
5181 };
5182
5183 /* *** ENABLE/DISABLE GSO *** */
5184 struct cmd_gso_enable_result {
5185         cmdline_fixed_string_t cmd_set;
5186         cmdline_fixed_string_t cmd_port;
5187         cmdline_fixed_string_t cmd_keyword;
5188         cmdline_fixed_string_t cmd_mode;
5189         portid_t cmd_pid;
5190 };
5191
5192 static void
5193 cmd_gso_enable_parsed(void *parsed_result,
5194                 __rte_unused struct cmdline *cl,
5195                 __rte_unused void *data)
5196 {
5197         struct cmd_gso_enable_result *res;
5198
5199         res = parsed_result;
5200         if (!strcmp(res->cmd_keyword, "gso"))
5201                 setup_gso(res->cmd_mode, res->cmd_pid);
5202 }
5203
5204 cmdline_parse_token_string_t cmd_gso_enable_set =
5205         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5206                         cmd_set, "set");
5207 cmdline_parse_token_string_t cmd_gso_enable_port =
5208         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5209                         cmd_port, "port");
5210 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5211         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5212                         cmd_keyword, "gso");
5213 cmdline_parse_token_string_t cmd_gso_enable_mode =
5214         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5215                         cmd_mode, "on#off");
5216 cmdline_parse_token_num_t cmd_gso_enable_pid =
5217         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5218                         cmd_pid, RTE_UINT16);
5219
5220 cmdline_parse_inst_t cmd_gso_enable = {
5221         .f = cmd_gso_enable_parsed,
5222         .data = NULL,
5223         .help_str = "set port <port_id> gso on|off",
5224         .tokens = {
5225                 (void *)&cmd_gso_enable_set,
5226                 (void *)&cmd_gso_enable_port,
5227                 (void *)&cmd_gso_enable_pid,
5228                 (void *)&cmd_gso_enable_keyword,
5229                 (void *)&cmd_gso_enable_mode,
5230                 NULL,
5231         },
5232 };
5233
5234 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5235 struct cmd_gso_size_result {
5236         cmdline_fixed_string_t cmd_set;
5237         cmdline_fixed_string_t cmd_keyword;
5238         cmdline_fixed_string_t cmd_segsz;
5239         uint16_t cmd_size;
5240 };
5241
5242 static void
5243 cmd_gso_size_parsed(void *parsed_result,
5244                        __rte_unused struct cmdline *cl,
5245                        __rte_unused void *data)
5246 {
5247         struct cmd_gso_size_result *res = parsed_result;
5248
5249         if (test_done == 0) {
5250                 printf("Before setting GSO segsz, please first"
5251                                 " stop forwarding\n");
5252                 return;
5253         }
5254
5255         if (!strcmp(res->cmd_keyword, "gso") &&
5256                         !strcmp(res->cmd_segsz, "segsz")) {
5257                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5258                         printf("gso_size should be larger than %zu."
5259                                         " Please input a legal value\n",
5260                                         RTE_GSO_SEG_SIZE_MIN);
5261                 else
5262                         gso_max_segment_size = res->cmd_size;
5263         }
5264 }
5265
5266 cmdline_parse_token_string_t cmd_gso_size_set =
5267         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5268                                 cmd_set, "set");
5269 cmdline_parse_token_string_t cmd_gso_size_keyword =
5270         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5271                                 cmd_keyword, "gso");
5272 cmdline_parse_token_string_t cmd_gso_size_segsz =
5273         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5274                                 cmd_segsz, "segsz");
5275 cmdline_parse_token_num_t cmd_gso_size_size =
5276         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5277                                 cmd_size, RTE_UINT16);
5278
5279 cmdline_parse_inst_t cmd_gso_size = {
5280         .f = cmd_gso_size_parsed,
5281         .data = NULL,
5282         .help_str = "set gso segsz <length>",
5283         .tokens = {
5284                 (void *)&cmd_gso_size_set,
5285                 (void *)&cmd_gso_size_keyword,
5286                 (void *)&cmd_gso_size_segsz,
5287                 (void *)&cmd_gso_size_size,
5288                 NULL,
5289         },
5290 };
5291
5292 /* *** SHOW GSO CONFIGURATION *** */
5293 struct cmd_gso_show_result {
5294         cmdline_fixed_string_t cmd_show;
5295         cmdline_fixed_string_t cmd_port;
5296         cmdline_fixed_string_t cmd_keyword;
5297         portid_t cmd_pid;
5298 };
5299
5300 static void
5301 cmd_gso_show_parsed(void *parsed_result,
5302                        __rte_unused struct cmdline *cl,
5303                        __rte_unused void *data)
5304 {
5305         struct cmd_gso_show_result *res = parsed_result;
5306
5307         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5308                 printf("invalid port id %u\n", res->cmd_pid);
5309                 return;
5310         }
5311         if (!strcmp(res->cmd_keyword, "gso")) {
5312                 if (gso_ports[res->cmd_pid].enable) {
5313                         printf("Max GSO'd packet size: %uB\n"
5314                                         "Supported GSO types: TCP/IPv4, "
5315                                         "UDP/IPv4, VxLAN with inner "
5316                                         "TCP/IPv4 packet, GRE with inner "
5317                                         "TCP/IPv4 packet\n",
5318                                         gso_max_segment_size);
5319                 } else
5320                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5321         }
5322 }
5323
5324 cmdline_parse_token_string_t cmd_gso_show_show =
5325 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5326                 cmd_show, "show");
5327 cmdline_parse_token_string_t cmd_gso_show_port =
5328 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5329                 cmd_port, "port");
5330 cmdline_parse_token_string_t cmd_gso_show_keyword =
5331         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5332                                 cmd_keyword, "gso");
5333 cmdline_parse_token_num_t cmd_gso_show_pid =
5334         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5335                                 cmd_pid, RTE_UINT16);
5336
5337 cmdline_parse_inst_t cmd_gso_show = {
5338         .f = cmd_gso_show_parsed,
5339         .data = NULL,
5340         .help_str = "show port <port_id> gso",
5341         .tokens = {
5342                 (void *)&cmd_gso_show_show,
5343                 (void *)&cmd_gso_show_port,
5344                 (void *)&cmd_gso_show_pid,
5345                 (void *)&cmd_gso_show_keyword,
5346                 NULL,
5347         },
5348 };
5349
5350 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5351 struct cmd_set_flush_rx {
5352         cmdline_fixed_string_t set;
5353         cmdline_fixed_string_t flush_rx;
5354         cmdline_fixed_string_t mode;
5355 };
5356
5357 static void
5358 cmd_set_flush_rx_parsed(void *parsed_result,
5359                 __rte_unused struct cmdline *cl,
5360                 __rte_unused void *data)
5361 {
5362         struct cmd_set_flush_rx *res = parsed_result;
5363         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5364 }
5365
5366 cmdline_parse_token_string_t cmd_setflushrx_set =
5367         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5368                         set, "set");
5369 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5370         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5371                         flush_rx, "flush_rx");
5372 cmdline_parse_token_string_t cmd_setflushrx_mode =
5373         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5374                         mode, "on#off");
5375
5376
5377 cmdline_parse_inst_t cmd_set_flush_rx = {
5378         .f = cmd_set_flush_rx_parsed,
5379         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5380         .data = NULL,
5381         .tokens = {
5382                 (void *)&cmd_setflushrx_set,
5383                 (void *)&cmd_setflushrx_flush_rx,
5384                 (void *)&cmd_setflushrx_mode,
5385                 NULL,
5386         },
5387 };
5388
5389 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5390 struct cmd_set_link_check {
5391         cmdline_fixed_string_t set;
5392         cmdline_fixed_string_t link_check;
5393         cmdline_fixed_string_t mode;
5394 };
5395
5396 static void
5397 cmd_set_link_check_parsed(void *parsed_result,
5398                 __rte_unused struct cmdline *cl,
5399                 __rte_unused void *data)
5400 {
5401         struct cmd_set_link_check *res = parsed_result;
5402         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5403 }
5404
5405 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5406         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5407                         set, "set");
5408 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5409         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5410                         link_check, "link_check");
5411 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5412         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5413                         mode, "on#off");
5414
5415
5416 cmdline_parse_inst_t cmd_set_link_check = {
5417         .f = cmd_set_link_check_parsed,
5418         .help_str = "set link_check on|off: Enable/Disable link status check "
5419                     "when starting/stopping a port",
5420         .data = NULL,
5421         .tokens = {
5422                 (void *)&cmd_setlinkcheck_set,
5423                 (void *)&cmd_setlinkcheck_link_check,
5424                 (void *)&cmd_setlinkcheck_mode,
5425                 NULL,
5426         },
5427 };
5428
5429 /* *** SET NIC BYPASS MODE *** */
5430 struct cmd_set_bypass_mode_result {
5431         cmdline_fixed_string_t set;
5432         cmdline_fixed_string_t bypass;
5433         cmdline_fixed_string_t mode;
5434         cmdline_fixed_string_t value;
5435         portid_t port_id;
5436 };
5437
5438 static void
5439 cmd_set_bypass_mode_parsed(void *parsed_result,
5440                 __rte_unused struct cmdline *cl,
5441                 __rte_unused void *data)
5442 {
5443         struct cmd_set_bypass_mode_result *res = parsed_result;
5444         portid_t port_id = res->port_id;
5445         int32_t rc = -EINVAL;
5446
5447 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5448         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5449
5450         if (!strcmp(res->value, "bypass"))
5451                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5452         else if (!strcmp(res->value, "isolate"))
5453                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5454         else
5455                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5456
5457         /* Set the bypass mode for the relevant port. */
5458         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5459 #endif
5460         if (rc != 0)
5461                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5462 }
5463
5464 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5465         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5466                         set, "set");
5467 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5468         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5469                         bypass, "bypass");
5470 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5471         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5472                         mode, "mode");
5473 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5474         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5475                         value, "normal#bypass#isolate");
5476 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5477         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5478                                 port_id, RTE_UINT16);
5479
5480 cmdline_parse_inst_t cmd_set_bypass_mode = {
5481         .f = cmd_set_bypass_mode_parsed,
5482         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5483                     "Set the NIC bypass mode for port_id",
5484         .data = NULL,
5485         .tokens = {
5486                 (void *)&cmd_setbypass_mode_set,
5487                 (void *)&cmd_setbypass_mode_bypass,
5488                 (void *)&cmd_setbypass_mode_mode,
5489                 (void *)&cmd_setbypass_mode_value,
5490                 (void *)&cmd_setbypass_mode_port,
5491                 NULL,
5492         },
5493 };
5494
5495 /* *** SET NIC BYPASS EVENT *** */
5496 struct cmd_set_bypass_event_result {
5497         cmdline_fixed_string_t set;
5498         cmdline_fixed_string_t bypass;
5499         cmdline_fixed_string_t event;
5500         cmdline_fixed_string_t event_value;
5501         cmdline_fixed_string_t mode;
5502         cmdline_fixed_string_t mode_value;
5503         portid_t port_id;
5504 };
5505
5506 static void
5507 cmd_set_bypass_event_parsed(void *parsed_result,
5508                 __rte_unused struct cmdline *cl,
5509                 __rte_unused void *data)
5510 {
5511         int32_t rc = -EINVAL;
5512         struct cmd_set_bypass_event_result *res = parsed_result;
5513         portid_t port_id = res->port_id;
5514
5515 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5516         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5517         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5518
5519         if (!strcmp(res->event_value, "timeout"))
5520                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5521         else if (!strcmp(res->event_value, "os_on"))
5522                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5523         else if (!strcmp(res->event_value, "os_off"))
5524                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5525         else if (!strcmp(res->event_value, "power_on"))
5526                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5527         else if (!strcmp(res->event_value, "power_off"))
5528                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5529         else
5530                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5531
5532         if (!strcmp(res->mode_value, "bypass"))
5533                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5534         else if (!strcmp(res->mode_value, "isolate"))
5535                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5536         else
5537                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5538
5539         /* Set the watchdog timeout. */
5540         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5541
5542                 rc = -EINVAL;
5543                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5544                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5545                                                            bypass_timeout);
5546                 }
5547                 if (rc != 0) {
5548                         printf("Failed to set timeout value %u "
5549                         "for port %d, errto code: %d.\n",
5550                         bypass_timeout, port_id, rc);
5551                 }
5552         }
5553
5554         /* Set the bypass event to transition to bypass mode. */
5555         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5556                                               bypass_mode);
5557 #endif
5558
5559         if (rc != 0)
5560                 printf("\t Failed to set bypass event for port = %d.\n",
5561                        port_id);
5562 }
5563
5564 cmdline_parse_token_string_t cmd_setbypass_event_set =
5565         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5566                         set, "set");
5567 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5568         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5569                         bypass, "bypass");
5570 cmdline_parse_token_string_t cmd_setbypass_event_event =
5571         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5572                         event, "event");
5573 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5574         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5575                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5576 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5577         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5578                         mode, "mode");
5579 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5580         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5581                         mode_value, "normal#bypass#isolate");
5582 cmdline_parse_token_num_t cmd_setbypass_event_port =
5583         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5584                                 port_id, RTE_UINT16);
5585
5586 cmdline_parse_inst_t cmd_set_bypass_event = {
5587         .f = cmd_set_bypass_event_parsed,
5588         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5589                 "power_off mode normal|bypass|isolate <port_id>: "
5590                 "Set the NIC bypass event mode for port_id",
5591         .data = NULL,
5592         .tokens = {
5593                 (void *)&cmd_setbypass_event_set,
5594                 (void *)&cmd_setbypass_event_bypass,
5595                 (void *)&cmd_setbypass_event_event,
5596                 (void *)&cmd_setbypass_event_event_value,
5597                 (void *)&cmd_setbypass_event_mode,
5598                 (void *)&cmd_setbypass_event_mode_value,
5599                 (void *)&cmd_setbypass_event_port,
5600                 NULL,
5601         },
5602 };
5603
5604
5605 /* *** SET NIC BYPASS TIMEOUT *** */
5606 struct cmd_set_bypass_timeout_result {
5607         cmdline_fixed_string_t set;
5608         cmdline_fixed_string_t bypass;
5609         cmdline_fixed_string_t timeout;
5610         cmdline_fixed_string_t value;
5611 };
5612
5613 static void
5614 cmd_set_bypass_timeout_parsed(void *parsed_result,
5615                 __rte_unused struct cmdline *cl,
5616                 __rte_unused void *data)
5617 {
5618         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5619
5620 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5621         if (!strcmp(res->value, "1.5"))
5622                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5623         else if (!strcmp(res->value, "2"))
5624                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5625         else if (!strcmp(res->value, "3"))
5626                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5627         else if (!strcmp(res->value, "4"))
5628                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5629         else if (!strcmp(res->value, "8"))
5630                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5631         else if (!strcmp(res->value, "16"))
5632                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5633         else if (!strcmp(res->value, "32"))
5634                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5635         else
5636                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5637 #endif
5638 }
5639
5640 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5642                         set, "set");
5643 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5644         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5645                         bypass, "bypass");
5646 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5647         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5648                         timeout, "timeout");
5649 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5650         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5651                         value, "0#1.5#2#3#4#8#16#32");
5652
5653 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5654         .f = cmd_set_bypass_timeout_parsed,
5655         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5656                 "Set the NIC bypass watchdog timeout in seconds",
5657         .data = NULL,
5658         .tokens = {
5659                 (void *)&cmd_setbypass_timeout_set,
5660                 (void *)&cmd_setbypass_timeout_bypass,
5661                 (void *)&cmd_setbypass_timeout_timeout,
5662                 (void *)&cmd_setbypass_timeout_value,
5663                 NULL,
5664         },
5665 };
5666
5667 /* *** SHOW NIC BYPASS MODE *** */
5668 struct cmd_show_bypass_config_result {
5669         cmdline_fixed_string_t show;
5670         cmdline_fixed_string_t bypass;
5671         cmdline_fixed_string_t config;
5672         portid_t port_id;
5673 };
5674
5675 static void
5676 cmd_show_bypass_config_parsed(void *parsed_result,
5677                 __rte_unused struct cmdline *cl,
5678                 __rte_unused void *data)
5679 {
5680         struct cmd_show_bypass_config_result *res = parsed_result;
5681         portid_t port_id = res->port_id;
5682         int rc = -EINVAL;
5683 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5684         uint32_t event_mode;
5685         uint32_t bypass_mode;
5686         uint32_t timeout = bypass_timeout;
5687         unsigned int i;
5688
5689         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5690                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5691         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5692                 {"UNKNOWN", "normal", "bypass", "isolate"};
5693         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5694                 "NONE",
5695                 "OS/board on",
5696                 "power supply on",
5697                 "OS/board off",
5698                 "power supply off",
5699                 "timeout"};
5700
5701         /* Display the bypass mode.*/
5702         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5703                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5704                 return;
5705         }
5706         else {
5707                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5708                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5709
5710                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5711         }
5712
5713         /* Display the bypass timeout.*/
5714         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5715                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5716
5717         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5718
5719         /* Display the bypass events and associated modes. */
5720         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5721
5722                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5723                         printf("\tFailed to get bypass mode for event = %s\n",
5724                                 events[i]);
5725                 } else {
5726                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5727                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5728
5729                         printf("\tbypass event: %-16s = %s\n", events[i],
5730                                 modes[event_mode]);
5731                 }
5732         }
5733 #endif
5734         if (rc != 0)
5735                 printf("\tFailed to get bypass configuration for port = %d\n",
5736                        port_id);
5737 }
5738
5739 cmdline_parse_token_string_t cmd_showbypass_config_show =
5740         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5741                         show, "show");
5742 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5743         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5744                         bypass, "bypass");
5745 cmdline_parse_token_string_t cmd_showbypass_config_config =
5746         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5747                         config, "config");
5748 cmdline_parse_token_num_t cmd_showbypass_config_port =
5749         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5750                                 port_id, RTE_UINT16);
5751
5752 cmdline_parse_inst_t cmd_show_bypass_config = {
5753         .f = cmd_show_bypass_config_parsed,
5754         .help_str = "show bypass config <port_id>: "
5755                     "Show the NIC bypass config for port_id",
5756         .data = NULL,
5757         .tokens = {
5758                 (void *)&cmd_showbypass_config_show,
5759                 (void *)&cmd_showbypass_config_bypass,
5760                 (void *)&cmd_showbypass_config_config,
5761                 (void *)&cmd_showbypass_config_port,
5762                 NULL,
5763         },
5764 };
5765
5766 #ifdef RTE_NET_BOND
5767 /* *** SET BONDING MODE *** */
5768 struct cmd_set_bonding_mode_result {
5769         cmdline_fixed_string_t set;
5770         cmdline_fixed_string_t bonding;
5771         cmdline_fixed_string_t mode;
5772         uint8_t value;
5773         portid_t port_id;
5774 };
5775
5776 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5777                 __rte_unused  struct cmdline *cl,
5778                 __rte_unused void *data)
5779 {
5780         struct cmd_set_bonding_mode_result *res = parsed_result;
5781         portid_t port_id = res->port_id;
5782
5783         /* Set the bonding mode for the relevant port. */
5784         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5785                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5786 }
5787
5788 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5789 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5790                 set, "set");
5791 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5792 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5793                 bonding, "bonding");
5794 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5795 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5796                 mode, "mode");
5797 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5798 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5799                 value, RTE_UINT8);
5800 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5801 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5802                 port_id, RTE_UINT16);
5803
5804 cmdline_parse_inst_t cmd_set_bonding_mode = {
5805                 .f = cmd_set_bonding_mode_parsed,
5806                 .help_str = "set bonding mode <mode_value> <port_id>: "
5807                         "Set the bonding mode for port_id",
5808                 .data = NULL,
5809                 .tokens = {
5810                                 (void *) &cmd_setbonding_mode_set,
5811                                 (void *) &cmd_setbonding_mode_bonding,
5812                                 (void *) &cmd_setbonding_mode_mode,
5813                                 (void *) &cmd_setbonding_mode_value,
5814                                 (void *) &cmd_setbonding_mode_port,
5815                                 NULL
5816                 }
5817 };
5818
5819 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5820 struct cmd_set_bonding_lacp_dedicated_queues_result {
5821         cmdline_fixed_string_t set;
5822         cmdline_fixed_string_t bonding;
5823         cmdline_fixed_string_t lacp;
5824         cmdline_fixed_string_t dedicated_queues;
5825         portid_t port_id;
5826         cmdline_fixed_string_t mode;
5827 };
5828
5829 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5830                 __rte_unused  struct cmdline *cl,
5831                 __rte_unused void *data)
5832 {
5833         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5834         portid_t port_id = res->port_id;
5835         struct rte_port *port;
5836
5837         port = &ports[port_id];
5838
5839         /** Check if the port is not started **/
5840         if (port->port_status != RTE_PORT_STOPPED) {
5841                 printf("Please stop port %d first\n", port_id);
5842                 return;
5843         }
5844
5845         if (!strcmp(res->mode, "enable")) {
5846                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5847                         printf("Dedicate queues for LACP control packets"
5848                                         " enabled\n");
5849                 else
5850                         printf("Enabling dedicate queues for LACP control "
5851                                         "packets on port %d failed\n", port_id);
5852         } else if (!strcmp(res->mode, "disable")) {
5853                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5854                         printf("Dedicated queues for LACP control packets "
5855                                         "disabled\n");
5856                 else
5857                         printf("Disabling dedicated queues for LACP control "
5858                                         "traffic on port %d failed\n", port_id);
5859         }
5860 }
5861
5862 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5863 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5864                 set, "set");
5865 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5866 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5867                 bonding, "bonding");
5868 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5869 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5870                 lacp, "lacp");
5871 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5872 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5873                 dedicated_queues, "dedicated_queues");
5874 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5875 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5876                 port_id, RTE_UINT16);
5877 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5878 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5879                 mode, "enable#disable");
5880
5881 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5882                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5883                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5884                         "enable|disable: "
5885                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5886                 .data = NULL,
5887                 .tokens = {
5888                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5889                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5890                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5891                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5892                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5893                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5894                         NULL
5895                 }
5896 };
5897
5898 /* *** SET BALANCE XMIT POLICY *** */
5899 struct cmd_set_bonding_balance_xmit_policy_result {
5900         cmdline_fixed_string_t set;
5901         cmdline_fixed_string_t bonding;
5902         cmdline_fixed_string_t balance_xmit_policy;
5903         portid_t port_id;
5904         cmdline_fixed_string_t policy;
5905 };
5906
5907 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5908                 __rte_unused  struct cmdline *cl,
5909                 __rte_unused void *data)
5910 {
5911         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5912         portid_t port_id = res->port_id;
5913         uint8_t policy;
5914
5915         if (!strcmp(res->policy, "l2")) {
5916                 policy = BALANCE_XMIT_POLICY_LAYER2;
5917         } else if (!strcmp(res->policy, "l23")) {
5918                 policy = BALANCE_XMIT_POLICY_LAYER23;
5919         } else if (!strcmp(res->policy, "l34")) {
5920                 policy = BALANCE_XMIT_POLICY_LAYER34;
5921         } else {
5922                 printf("\t Invalid xmit policy selection");
5923                 return;
5924         }
5925
5926         /* Set the bonding mode for the relevant port. */
5927         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5928                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5929                                 port_id);
5930         }
5931 }
5932
5933 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5934 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5935                 set, "set");
5936 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5937 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5938                 bonding, "bonding");
5939 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5940 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5941                 balance_xmit_policy, "balance_xmit_policy");
5942 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5943 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5944                 port_id, RTE_UINT16);
5945 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5946 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5947                 policy, "l2#l23#l34");
5948
5949 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5950                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5951                 .help_str = "set bonding balance_xmit_policy <port_id> "
5952                         "l2|l23|l34: "
5953                         "Set the bonding balance_xmit_policy for port_id",
5954                 .data = NULL,
5955                 .tokens = {
5956                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5957                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5958                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5959                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5960                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5961                                 NULL
5962                 }
5963 };
5964
5965 /* *** SHOW NIC BONDING CONFIGURATION *** */
5966 struct cmd_show_bonding_config_result {
5967         cmdline_fixed_string_t show;
5968         cmdline_fixed_string_t bonding;
5969         cmdline_fixed_string_t config;
5970         portid_t port_id;
5971 };
5972
5973 static void cmd_show_bonding_config_parsed(void *parsed_result,
5974                 __rte_unused  struct cmdline *cl,
5975                 __rte_unused void *data)
5976 {
5977         struct cmd_show_bonding_config_result *res = parsed_result;
5978         int bonding_mode, agg_mode;
5979         portid_t slaves[RTE_MAX_ETHPORTS];
5980         int num_slaves, num_active_slaves;
5981         int primary_id;
5982         int i;
5983         portid_t port_id = res->port_id;
5984
5985         /* Display the bonding mode.*/
5986         bonding_mode = rte_eth_bond_mode_get(port_id);
5987         if (bonding_mode < 0) {
5988                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5989                 return;
5990         } else
5991                 printf("\tBonding mode: %d\n", bonding_mode);
5992
5993         if (bonding_mode == BONDING_MODE_BALANCE) {
5994                 int balance_xmit_policy;
5995
5996                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5997                 if (balance_xmit_policy < 0) {
5998                         printf("\tFailed to get balance xmit policy for port = %d\n",
5999                                         port_id);
6000                         return;
6001                 } else {
6002                         printf("\tBalance Xmit Policy: ");
6003
6004                         switch (balance_xmit_policy) {
6005                         case BALANCE_XMIT_POLICY_LAYER2:
6006                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6007                                 break;
6008                         case BALANCE_XMIT_POLICY_LAYER23:
6009                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6010                                 break;
6011                         case BALANCE_XMIT_POLICY_LAYER34:
6012                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6013                                 break;
6014                         }
6015                         printf("\n");
6016                 }
6017         }
6018
6019         if (bonding_mode == BONDING_MODE_8023AD) {
6020                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6021                 printf("\tIEEE802.3AD Aggregator Mode: ");
6022                 switch (agg_mode) {
6023                 case AGG_BANDWIDTH:
6024                         printf("bandwidth");
6025                         break;
6026                 case AGG_STABLE:
6027                         printf("stable");
6028                         break;
6029                 case AGG_COUNT:
6030                         printf("count");
6031                         break;
6032                 }
6033                 printf("\n");
6034         }
6035
6036         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6037
6038         if (num_slaves < 0) {
6039                 printf("\tFailed to get slave list for port = %d\n", port_id);
6040                 return;
6041         }
6042         if (num_slaves > 0) {
6043                 printf("\tSlaves (%d): [", num_slaves);
6044                 for (i = 0; i < num_slaves - 1; i++)
6045                         printf("%d ", slaves[i]);
6046
6047                 printf("%d]\n", slaves[num_slaves - 1]);
6048         } else {
6049                 printf("\tSlaves: []\n");
6050
6051         }
6052
6053         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6054                         RTE_MAX_ETHPORTS);
6055
6056         if (num_active_slaves < 0) {
6057                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6058                 return;
6059         }
6060         if (num_active_slaves > 0) {
6061                 printf("\tActive Slaves (%d): [", num_active_slaves);
6062                 for (i = 0; i < num_active_slaves - 1; i++)
6063                         printf("%d ", slaves[i]);
6064
6065                 printf("%d]\n", slaves[num_active_slaves - 1]);
6066
6067         } else {
6068                 printf("\tActive Slaves: []\n");
6069
6070         }
6071
6072         primary_id = rte_eth_bond_primary_get(port_id);
6073         if (primary_id < 0) {
6074                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6075                 return;
6076         } else
6077                 printf("\tPrimary: [%d]\n", primary_id);
6078
6079 }
6080
6081 cmdline_parse_token_string_t cmd_showbonding_config_show =
6082 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6083                 show, "show");
6084 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6085 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6086                 bonding, "bonding");
6087 cmdline_parse_token_string_t cmd_showbonding_config_config =
6088 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6089                 config, "config");
6090 cmdline_parse_token_num_t cmd_showbonding_config_port =
6091 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6092                 port_id, RTE_UINT16);
6093
6094 cmdline_parse_inst_t cmd_show_bonding_config = {
6095                 .f = cmd_show_bonding_config_parsed,
6096                 .help_str = "show bonding config <port_id>: "
6097                         "Show the bonding config for port_id",
6098                 .data = NULL,
6099                 .tokens = {
6100                                 (void *)&cmd_showbonding_config_show,
6101                                 (void *)&cmd_showbonding_config_bonding,
6102                                 (void *)&cmd_showbonding_config_config,
6103                                 (void *)&cmd_showbonding_config_port,
6104                                 NULL
6105                 }
6106 };
6107
6108 /* *** SET BONDING PRIMARY *** */
6109 struct cmd_set_bonding_primary_result {
6110         cmdline_fixed_string_t set;
6111         cmdline_fixed_string_t bonding;
6112         cmdline_fixed_string_t primary;
6113         portid_t slave_id;
6114         portid_t port_id;
6115 };
6116
6117 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6118                 __rte_unused  struct cmdline *cl,
6119                 __rte_unused void *data)
6120 {
6121         struct cmd_set_bonding_primary_result *res = parsed_result;
6122         portid_t master_port_id = res->port_id;
6123         portid_t slave_port_id = res->slave_id;
6124
6125         /* Set the primary slave for a bonded device. */
6126         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6127                 printf("\t Failed to set primary slave for port = %d.\n",
6128                                 master_port_id);
6129                 return;
6130         }
6131         init_port_config();
6132 }
6133
6134 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6135 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6136                 set, "set");
6137 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6138 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6139                 bonding, "bonding");
6140 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6141 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6142                 primary, "primary");
6143 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6144 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6145                 slave_id, RTE_UINT16);
6146 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6147 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6148                 port_id, RTE_UINT16);
6149
6150 cmdline_parse_inst_t cmd_set_bonding_primary = {
6151                 .f = cmd_set_bonding_primary_parsed,
6152                 .help_str = "set bonding primary <slave_id> <port_id>: "
6153                         "Set the primary slave for port_id",
6154                 .data = NULL,
6155                 .tokens = {
6156                                 (void *)&cmd_setbonding_primary_set,
6157                                 (void *)&cmd_setbonding_primary_bonding,
6158                                 (void *)&cmd_setbonding_primary_primary,
6159                                 (void *)&cmd_setbonding_primary_slave,
6160                                 (void *)&cmd_setbonding_primary_port,
6161                                 NULL
6162                 }
6163 };
6164
6165 /* *** ADD SLAVE *** */
6166 struct cmd_add_bonding_slave_result {
6167         cmdline_fixed_string_t add;
6168         cmdline_fixed_string_t bonding;
6169         cmdline_fixed_string_t slave;
6170         portid_t slave_id;
6171         portid_t port_id;
6172 };
6173
6174 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6175                 __rte_unused  struct cmdline *cl,
6176                 __rte_unused void *data)
6177 {
6178         struct cmd_add_bonding_slave_result *res = parsed_result;
6179         portid_t master_port_id = res->port_id;
6180         portid_t slave_port_id = res->slave_id;
6181
6182         /* add the slave for a bonded device. */
6183         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6184                 printf("\t Failed to add slave %d to master port = %d.\n",
6185                                 slave_port_id, master_port_id);
6186                 return;
6187         }
6188         init_port_config();
6189         set_port_slave_flag(slave_port_id);
6190 }
6191
6192 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6193 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6194                 add, "add");
6195 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6196 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6197                 bonding, "bonding");
6198 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6199 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6200                 slave, "slave");
6201 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6202 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6203                 slave_id, RTE_UINT16);
6204 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6205 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6206                 port_id, RTE_UINT16);
6207
6208 cmdline_parse_inst_t cmd_add_bonding_slave = {
6209                 .f = cmd_add_bonding_slave_parsed,
6210                 .help_str = "add bonding slave <slave_id> <port_id>: "
6211                         "Add a slave device to a bonded device",
6212                 .data = NULL,
6213                 .tokens = {
6214                                 (void *)&cmd_addbonding_slave_add,
6215                                 (void *)&cmd_addbonding_slave_bonding,
6216                                 (void *)&cmd_addbonding_slave_slave,
6217                                 (void *)&cmd_addbonding_slave_slaveid,
6218                                 (void *)&cmd_addbonding_slave_port,
6219                                 NULL
6220                 }
6221 };
6222
6223 /* *** REMOVE SLAVE *** */
6224 struct cmd_remove_bonding_slave_result {
6225         cmdline_fixed_string_t remove;
6226         cmdline_fixed_string_t bonding;
6227         cmdline_fixed_string_t slave;
6228         portid_t slave_id;
6229         portid_t port_id;
6230 };
6231
6232 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6233                 __rte_unused  struct cmdline *cl,
6234                 __rte_unused void *data)
6235 {
6236         struct cmd_remove_bonding_slave_result *res = parsed_result;
6237         portid_t master_port_id = res->port_id;
6238         portid_t slave_port_id = res->slave_id;
6239
6240         /* remove the slave from a bonded device. */
6241         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6242                 printf("\t Failed to remove slave %d from master port = %d.\n",
6243                                 slave_port_id, master_port_id);
6244                 return;
6245         }
6246         init_port_config();
6247         clear_port_slave_flag(slave_port_id);
6248 }
6249
6250 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6251                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6252                                 remove, "remove");
6253 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6254                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6255                                 bonding, "bonding");
6256 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6257                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6258                                 slave, "slave");
6259 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6260                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6261                                 slave_id, RTE_UINT16);
6262 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6263                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6264                                 port_id, RTE_UINT16);
6265
6266 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6267                 .f = cmd_remove_bonding_slave_parsed,
6268                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6269                         "Remove a slave device from a bonded device",
6270                 .data = NULL,
6271                 .tokens = {
6272                                 (void *)&cmd_removebonding_slave_remove,
6273                                 (void *)&cmd_removebonding_slave_bonding,
6274                                 (void *)&cmd_removebonding_slave_slave,
6275                                 (void *)&cmd_removebonding_slave_slaveid,
6276                                 (void *)&cmd_removebonding_slave_port,
6277                                 NULL
6278                 }
6279 };
6280
6281 /* *** CREATE BONDED DEVICE *** */
6282 struct cmd_create_bonded_device_result {
6283         cmdline_fixed_string_t create;
6284         cmdline_fixed_string_t bonded;
6285         cmdline_fixed_string_t device;
6286         uint8_t mode;
6287         uint8_t socket;
6288 };
6289
6290 static int bond_dev_num = 0;
6291
6292 static void cmd_create_bonded_device_parsed(void *parsed_result,
6293                 __rte_unused  struct cmdline *cl,
6294                 __rte_unused void *data)
6295 {
6296         struct cmd_create_bonded_device_result *res = parsed_result;
6297         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6298         int port_id;
6299         int ret;
6300
6301         if (test_done == 0) {
6302                 printf("Please stop forwarding first\n");
6303                 return;
6304         }
6305
6306         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6307                         bond_dev_num++);
6308
6309         /* Create a new bonded device. */
6310         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6311         if (port_id < 0) {
6312                 printf("\t Failed to create bonded device.\n");
6313                 return;
6314         } else {
6315                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6316                                 port_id);
6317
6318                 /* Update number of ports */
6319                 nb_ports = rte_eth_dev_count_avail();
6320                 reconfig(port_id, res->socket);
6321                 ret = rte_eth_promiscuous_enable(port_id);
6322                 if (ret != 0)
6323                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6324                                 port_id, rte_strerror(-ret));
6325
6326                 ports[port_id].need_setup = 0;
6327                 ports[port_id].port_status = RTE_PORT_STOPPED;
6328         }
6329
6330 }
6331
6332 cmdline_parse_token_string_t cmd_createbonded_device_create =
6333                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6334                                 create, "create");
6335 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6336                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6337                                 bonded, "bonded");
6338 cmdline_parse_token_string_t cmd_createbonded_device_device =
6339                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6340                                 device, "device");
6341 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6342                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6343                                 mode, RTE_UINT8);
6344 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6345                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6346                                 socket, RTE_UINT8);
6347
6348 cmdline_parse_inst_t cmd_create_bonded_device = {
6349                 .f = cmd_create_bonded_device_parsed,
6350                 .help_str = "create bonded device <mode> <socket>: "
6351                         "Create a new bonded device with specific bonding mode and socket",
6352                 .data = NULL,
6353                 .tokens = {
6354                                 (void *)&cmd_createbonded_device_create,
6355                                 (void *)&cmd_createbonded_device_bonded,
6356                                 (void *)&cmd_createbonded_device_device,
6357                                 (void *)&cmd_createbonded_device_mode,
6358                                 (void *)&cmd_createbonded_device_socket,
6359                                 NULL
6360                 }
6361 };
6362
6363 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6364 struct cmd_set_bond_mac_addr_result {
6365         cmdline_fixed_string_t set;
6366         cmdline_fixed_string_t bonding;
6367         cmdline_fixed_string_t mac_addr;
6368         uint16_t port_num;
6369         struct rte_ether_addr address;
6370 };
6371
6372 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6373                 __rte_unused  struct cmdline *cl,
6374                 __rte_unused void *data)
6375 {
6376         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6377         int ret;
6378
6379         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6380                 return;
6381
6382         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6383
6384         /* check the return value and print it if is < 0 */
6385         if (ret < 0)
6386                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6387 }
6388
6389 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6390                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6391 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6392                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6393                                 "bonding");
6394 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6395                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6396                                 "mac_addr");
6397 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6398                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6399                                 port_num, RTE_UINT16);
6400 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6401                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6402
6403 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6404                 .f = cmd_set_bond_mac_addr_parsed,
6405                 .data = (void *) 0,
6406                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6407                 .tokens = {
6408                                 (void *)&cmd_set_bond_mac_addr_set,
6409                                 (void *)&cmd_set_bond_mac_addr_bonding,
6410                                 (void *)&cmd_set_bond_mac_addr_mac,
6411                                 (void *)&cmd_set_bond_mac_addr_portnum,
6412                                 (void *)&cmd_set_bond_mac_addr_addr,
6413                                 NULL
6414                 }
6415 };
6416
6417
6418 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6419 struct cmd_set_bond_mon_period_result {
6420         cmdline_fixed_string_t set;
6421         cmdline_fixed_string_t bonding;
6422         cmdline_fixed_string_t mon_period;
6423         uint16_t port_num;
6424         uint32_t period_ms;
6425 };
6426
6427 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6428                 __rte_unused  struct cmdline *cl,
6429                 __rte_unused void *data)
6430 {
6431         struct cmd_set_bond_mon_period_result *res = parsed_result;
6432         int ret;
6433
6434         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6435
6436         /* check the return value and print it if is < 0 */
6437         if (ret < 0)
6438                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6439 }
6440
6441 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6442                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6443                                 set, "set");
6444 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6445                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6446                                 bonding, "bonding");
6447 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6448                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6449                                 mon_period,     "mon_period");
6450 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6451                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6452                                 port_num, RTE_UINT16);
6453 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6454                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6455                                 period_ms, RTE_UINT32);
6456
6457 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6458                 .f = cmd_set_bond_mon_period_parsed,
6459                 .data = (void *) 0,
6460                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6461                 .tokens = {
6462                                 (void *)&cmd_set_bond_mon_period_set,
6463                                 (void *)&cmd_set_bond_mon_period_bonding,
6464                                 (void *)&cmd_set_bond_mon_period_mon_period,
6465                                 (void *)&cmd_set_bond_mon_period_portnum,
6466                                 (void *)&cmd_set_bond_mon_period_period_ms,
6467                                 NULL
6468                 }
6469 };
6470
6471
6472
6473 struct cmd_set_bonding_agg_mode_policy_result {
6474         cmdline_fixed_string_t set;
6475         cmdline_fixed_string_t bonding;
6476         cmdline_fixed_string_t agg_mode;
6477         uint16_t port_num;
6478         cmdline_fixed_string_t policy;
6479 };
6480
6481
6482 static void
6483 cmd_set_bonding_agg_mode(void *parsed_result,
6484                 __rte_unused struct cmdline *cl,
6485                 __rte_unused void *data)
6486 {
6487         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6488         uint8_t policy = AGG_BANDWIDTH;
6489
6490         if (!strcmp(res->policy, "bandwidth"))
6491                 policy = AGG_BANDWIDTH;
6492         else if (!strcmp(res->policy, "stable"))
6493                 policy = AGG_STABLE;
6494         else if (!strcmp(res->policy, "count"))
6495                 policy = AGG_COUNT;
6496
6497         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6498 }
6499
6500
6501 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6502         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6503                                 set, "set");
6504 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6505         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6506                                 bonding, "bonding");
6507
6508 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6509         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6510                                 agg_mode, "agg_mode");
6511
6512 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6513         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6514                                 port_num, RTE_UINT16);
6515
6516 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6517         TOKEN_STRING_INITIALIZER(
6518                         struct cmd_set_bonding_balance_xmit_policy_result,
6519                 policy, "stable#bandwidth#count");
6520
6521 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6522         .f = cmd_set_bonding_agg_mode,
6523         .data = (void *) 0,
6524         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6525         .tokens = {
6526                         (void *)&cmd_set_bonding_agg_mode_set,
6527                         (void *)&cmd_set_bonding_agg_mode_bonding,
6528                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6529                         (void *)&cmd_set_bonding_agg_mode_portnum,
6530                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6531                         NULL
6532                 }
6533 };
6534
6535
6536 #endif /* RTE_NET_BOND */
6537
6538 /* *** SET FORWARDING MODE *** */
6539 struct cmd_set_fwd_mode_result {
6540         cmdline_fixed_string_t set;
6541         cmdline_fixed_string_t fwd;
6542         cmdline_fixed_string_t mode;
6543 };
6544
6545 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6546                                     __rte_unused struct cmdline *cl,
6547                                     __rte_unused void *data)
6548 {
6549         struct cmd_set_fwd_mode_result *res = parsed_result;
6550
6551         retry_enabled = 0;
6552         set_pkt_forwarding_mode(res->mode);
6553 }
6554
6555 cmdline_parse_token_string_t cmd_setfwd_set =
6556         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6557 cmdline_parse_token_string_t cmd_setfwd_fwd =
6558         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6559 cmdline_parse_token_string_t cmd_setfwd_mode =
6560         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6561                 "" /* defined at init */);
6562
6563 cmdline_parse_inst_t cmd_set_fwd_mode = {
6564         .f = cmd_set_fwd_mode_parsed,
6565         .data = NULL,
6566         .help_str = NULL, /* defined at init */
6567         .tokens = {
6568                 (void *)&cmd_setfwd_set,
6569                 (void *)&cmd_setfwd_fwd,
6570                 (void *)&cmd_setfwd_mode,
6571                 NULL,
6572         },
6573 };
6574
6575 static void cmd_set_fwd_mode_init(void)
6576 {
6577         char *modes, *c;
6578         static char token[128];
6579         static char help[256];
6580         cmdline_parse_token_string_t *token_struct;
6581
6582         modes = list_pkt_forwarding_modes();
6583         snprintf(help, sizeof(help), "set fwd %s: "
6584                 "Set packet forwarding mode", modes);
6585         cmd_set_fwd_mode.help_str = help;
6586
6587         /* string token separator is # */
6588         for (c = token; *modes != '\0'; modes++)
6589                 if (*modes == '|')
6590                         *c++ = '#';
6591                 else
6592                         *c++ = *modes;
6593         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6594         token_struct->string_data.str = token;
6595 }
6596
6597 /* *** SET RETRY FORWARDING MODE *** */
6598 struct cmd_set_fwd_retry_mode_result {
6599         cmdline_fixed_string_t set;
6600         cmdline_fixed_string_t fwd;
6601         cmdline_fixed_string_t mode;
6602         cmdline_fixed_string_t retry;
6603 };
6604
6605 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6606                             __rte_unused struct cmdline *cl,
6607                             __rte_unused void *data)
6608 {
6609         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6610
6611         retry_enabled = 1;
6612         set_pkt_forwarding_mode(res->mode);
6613 }
6614
6615 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6616         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6617                         set, "set");
6618 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6619         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6620                         fwd, "fwd");
6621 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6622         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6623                         mode,
6624                 "" /* defined at init */);
6625 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6626         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6627                         retry, "retry");
6628
6629 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6630         .f = cmd_set_fwd_retry_mode_parsed,
6631         .data = NULL,
6632         .help_str = NULL, /* defined at init */
6633         .tokens = {
6634                 (void *)&cmd_setfwd_retry_set,
6635                 (void *)&cmd_setfwd_retry_fwd,
6636                 (void *)&cmd_setfwd_retry_mode,
6637                 (void *)&cmd_setfwd_retry_retry,
6638                 NULL,
6639         },
6640 };
6641
6642 static void cmd_set_fwd_retry_mode_init(void)
6643 {
6644         char *modes, *c;
6645         static char token[128];
6646         static char help[256];
6647         cmdline_parse_token_string_t *token_struct;
6648
6649         modes = list_pkt_forwarding_retry_modes();
6650         snprintf(help, sizeof(help), "set fwd %s retry: "
6651                 "Set packet forwarding mode with retry", modes);
6652         cmd_set_fwd_retry_mode.help_str = help;
6653
6654         /* string token separator is # */
6655         for (c = token; *modes != '\0'; modes++)
6656                 if (*modes == '|')
6657                         *c++ = '#';
6658                 else
6659                         *c++ = *modes;
6660         token_struct = (cmdline_parse_token_string_t *)
6661                 cmd_set_fwd_retry_mode.tokens[2];
6662         token_struct->string_data.str = token;
6663 }
6664
6665 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6666 struct cmd_set_burst_tx_retry_result {
6667         cmdline_fixed_string_t set;
6668         cmdline_fixed_string_t burst;
6669         cmdline_fixed_string_t tx;
6670         cmdline_fixed_string_t delay;
6671         uint32_t time;
6672         cmdline_fixed_string_t retry;
6673         uint32_t retry_num;
6674 };
6675
6676 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6677                                         __rte_unused struct cmdline *cl,
6678                                         __rte_unused void *data)
6679 {
6680         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6681
6682         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6683                 && !strcmp(res->tx, "tx")) {
6684                 if (!strcmp(res->delay, "delay"))
6685                         burst_tx_delay_time = res->time;
6686                 if (!strcmp(res->retry, "retry"))
6687                         burst_tx_retry_num = res->retry_num;
6688         }
6689
6690 }
6691
6692 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6693         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6694 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6695         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6696                                  "burst");
6697 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6698         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6699 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6700         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6701 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6702         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
6703                                  RTE_UINT32);
6704 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6705         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6706 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6707         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
6708                                  RTE_UINT32);
6709
6710 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6711         .f = cmd_set_burst_tx_retry_parsed,
6712         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6713         .tokens = {
6714                 (void *)&cmd_set_burst_tx_retry_set,
6715                 (void *)&cmd_set_burst_tx_retry_burst,
6716                 (void *)&cmd_set_burst_tx_retry_tx,
6717                 (void *)&cmd_set_burst_tx_retry_delay,
6718                 (void *)&cmd_set_burst_tx_retry_time,
6719                 (void *)&cmd_set_burst_tx_retry_retry,
6720                 (void *)&cmd_set_burst_tx_retry_retry_num,
6721                 NULL,
6722         },
6723 };
6724
6725 /* *** SET PROMISC MODE *** */
6726 struct cmd_set_promisc_mode_result {
6727         cmdline_fixed_string_t set;
6728         cmdline_fixed_string_t promisc;
6729         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6730         uint16_t port_num;               /* valid if "allports" argument == 0 */
6731         cmdline_fixed_string_t mode;
6732 };
6733
6734 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6735                                         __rte_unused struct cmdline *cl,
6736                                         void *allports)
6737 {
6738         struct cmd_set_promisc_mode_result *res = parsed_result;
6739         int enable;
6740         portid_t i;
6741
6742         if (!strcmp(res->mode, "on"))
6743                 enable = 1;
6744         else
6745                 enable = 0;
6746
6747         /* all ports */
6748         if (allports) {
6749                 RTE_ETH_FOREACH_DEV(i)
6750                         eth_set_promisc_mode(i, enable);
6751         } else {
6752                 eth_set_promisc_mode(res->port_num, enable);
6753         }
6754 }
6755
6756 cmdline_parse_token_string_t cmd_setpromisc_set =
6757         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6758 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6759         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6760                                  "promisc");
6761 cmdline_parse_token_string_t cmd_setpromisc_portall =
6762         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6763                                  "all");
6764 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6765         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6766                               RTE_UINT16);
6767 cmdline_parse_token_string_t cmd_setpromisc_mode =
6768         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6769                                  "on#off");
6770
6771 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6772         .f = cmd_set_promisc_mode_parsed,
6773         .data = (void *)1,
6774         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6775         .tokens = {
6776                 (void *)&cmd_setpromisc_set,
6777                 (void *)&cmd_setpromisc_promisc,
6778                 (void *)&cmd_setpromisc_portall,
6779                 (void *)&cmd_setpromisc_mode,
6780                 NULL,
6781         },
6782 };
6783
6784 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6785         .f = cmd_set_promisc_mode_parsed,
6786         .data = (void *)0,
6787         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6788         .tokens = {
6789                 (void *)&cmd_setpromisc_set,
6790                 (void *)&cmd_setpromisc_promisc,
6791                 (void *)&cmd_setpromisc_portnum,
6792                 (void *)&cmd_setpromisc_mode,
6793                 NULL,
6794         },
6795 };
6796
6797 /* *** SET ALLMULTI MODE *** */
6798 struct cmd_set_allmulti_mode_result {
6799         cmdline_fixed_string_t set;
6800         cmdline_fixed_string_t allmulti;
6801         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6802         uint16_t port_num;               /* valid if "allports" argument == 0 */
6803         cmdline_fixed_string_t mode;
6804 };
6805
6806 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6807                                         __rte_unused struct cmdline *cl,
6808                                         void *allports)
6809 {
6810         struct cmd_set_allmulti_mode_result *res = parsed_result;
6811         int enable;
6812         portid_t i;
6813
6814         if (!strcmp(res->mode, "on"))
6815                 enable = 1;
6816         else
6817                 enable = 0;
6818
6819         /* all ports */
6820         if (allports) {
6821                 RTE_ETH_FOREACH_DEV(i) {
6822                         eth_set_allmulticast_mode(i, enable);
6823                 }
6824         }
6825         else {
6826                 eth_set_allmulticast_mode(res->port_num, enable);
6827         }
6828 }
6829
6830 cmdline_parse_token_string_t cmd_setallmulti_set =
6831         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6832 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6833         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6834                                  "allmulti");
6835 cmdline_parse_token_string_t cmd_setallmulti_portall =
6836         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6837                                  "all");
6838 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6839         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6840                               RTE_UINT16);
6841 cmdline_parse_token_string_t cmd_setallmulti_mode =
6842         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6843                                  "on#off");
6844
6845 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6846         .f = cmd_set_allmulti_mode_parsed,
6847         .data = (void *)1,
6848         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6849         .tokens = {
6850                 (void *)&cmd_setallmulti_set,
6851                 (void *)&cmd_setallmulti_allmulti,
6852                 (void *)&cmd_setallmulti_portall,
6853                 (void *)&cmd_setallmulti_mode,
6854                 NULL,
6855         },
6856 };
6857
6858 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6859         .f = cmd_set_allmulti_mode_parsed,
6860         .data = (void *)0,
6861         .help_str = "set allmulti <port_id> on|off: "
6862                 "Set allmulti mode on port_id",
6863         .tokens = {
6864                 (void *)&cmd_setallmulti_set,
6865                 (void *)&cmd_setallmulti_allmulti,
6866                 (void *)&cmd_setallmulti_portnum,
6867                 (void *)&cmd_setallmulti_mode,
6868                 NULL,
6869         },
6870 };
6871
6872 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6873 struct cmd_link_flow_ctrl_set_result {
6874         cmdline_fixed_string_t set;
6875         cmdline_fixed_string_t flow_ctrl;
6876         cmdline_fixed_string_t rx;
6877         cmdline_fixed_string_t rx_lfc_mode;
6878         cmdline_fixed_string_t tx;
6879         cmdline_fixed_string_t tx_lfc_mode;
6880         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6881         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6882         cmdline_fixed_string_t autoneg_str;
6883         cmdline_fixed_string_t autoneg;
6884         cmdline_fixed_string_t hw_str;
6885         uint32_t high_water;
6886         cmdline_fixed_string_t lw_str;
6887         uint32_t low_water;
6888         cmdline_fixed_string_t pt_str;
6889         uint16_t pause_time;
6890         cmdline_fixed_string_t xon_str;
6891         uint16_t send_xon;
6892         portid_t port_id;
6893 };
6894
6895 cmdline_parse_token_string_t cmd_lfc_set_set =
6896         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 set, "set");
6898 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6899         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 flow_ctrl, "flow_ctrl");
6901 cmdline_parse_token_string_t cmd_lfc_set_rx =
6902         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 rx, "rx");
6904 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6905         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 rx_lfc_mode, "on#off");
6907 cmdline_parse_token_string_t cmd_lfc_set_tx =
6908         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 tx, "tx");
6910 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6911         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 tx_lfc_mode, "on#off");
6913 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6914         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 hw_str, "high_water");
6916 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6917         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 high_water, RTE_UINT32);
6919 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6920         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6921                                 lw_str, "low_water");
6922 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6923         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6924                                 low_water, RTE_UINT32);
6925 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6926         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6927                                 pt_str, "pause_time");
6928 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6929         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6930                                 pause_time, RTE_UINT16);
6931 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6932         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6933                                 xon_str, "send_xon");
6934 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6935         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6936                                 send_xon, RTE_UINT16);
6937 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6938         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6939                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6940 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6941         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6942                                 mac_ctrl_frame_fwd_mode, "on#off");
6943 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6944         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6945                                 autoneg_str, "autoneg");
6946 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6947         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6948                                 autoneg, "on#off");
6949 cmdline_parse_token_num_t cmd_lfc_set_portid =
6950         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6951                                 port_id, RTE_UINT16);
6952
6953 /* forward declaration */
6954 static void
6955 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6956                               void *data);
6957
6958 cmdline_parse_inst_t cmd_link_flow_control_set = {
6959         .f = cmd_link_flow_ctrl_set_parsed,
6960         .data = NULL,
6961         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6962                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6963                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6964         .tokens = {
6965                 (void *)&cmd_lfc_set_set,
6966                 (void *)&cmd_lfc_set_flow_ctrl,
6967                 (void *)&cmd_lfc_set_rx,
6968                 (void *)&cmd_lfc_set_rx_mode,
6969                 (void *)&cmd_lfc_set_tx,
6970                 (void *)&cmd_lfc_set_tx_mode,
6971                 (void *)&cmd_lfc_set_high_water,
6972                 (void *)&cmd_lfc_set_low_water,
6973                 (void *)&cmd_lfc_set_pause_time,
6974                 (void *)&cmd_lfc_set_send_xon,
6975                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6976                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6977                 (void *)&cmd_lfc_set_autoneg_str,
6978                 (void *)&cmd_lfc_set_autoneg,
6979                 (void *)&cmd_lfc_set_portid,
6980                 NULL,
6981         },
6982 };
6983
6984 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6985         .f = cmd_link_flow_ctrl_set_parsed,
6986         .data = (void *)&cmd_link_flow_control_set_rx,
6987         .help_str = "set flow_ctrl rx on|off <port_id>: "
6988                 "Change rx flow control parameter",
6989         .tokens = {
6990                 (void *)&cmd_lfc_set_set,
6991                 (void *)&cmd_lfc_set_flow_ctrl,
6992                 (void *)&cmd_lfc_set_rx,
6993                 (void *)&cmd_lfc_set_rx_mode,
6994                 (void *)&cmd_lfc_set_portid,
6995                 NULL,
6996         },
6997 };
6998
6999 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7000         .f = cmd_link_flow_ctrl_set_parsed,
7001         .data = (void *)&cmd_link_flow_control_set_tx,
7002         .help_str = "set flow_ctrl tx on|off <port_id>: "
7003                 "Change tx flow control parameter",
7004         .tokens = {
7005                 (void *)&cmd_lfc_set_set,
7006                 (void *)&cmd_lfc_set_flow_ctrl,
7007                 (void *)&cmd_lfc_set_tx,
7008                 (void *)&cmd_lfc_set_tx_mode,
7009                 (void *)&cmd_lfc_set_portid,
7010                 NULL,
7011         },
7012 };
7013
7014 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7015         .f = cmd_link_flow_ctrl_set_parsed,
7016         .data = (void *)&cmd_link_flow_control_set_hw,
7017         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7018                 "Change high water flow control parameter",
7019         .tokens = {
7020                 (void *)&cmd_lfc_set_set,
7021                 (void *)&cmd_lfc_set_flow_ctrl,
7022                 (void *)&cmd_lfc_set_high_water_str,
7023                 (void *)&cmd_lfc_set_high_water,
7024                 (void *)&cmd_lfc_set_portid,
7025                 NULL,
7026         },
7027 };
7028
7029 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7030         .f = cmd_link_flow_ctrl_set_parsed,
7031         .data = (void *)&cmd_link_flow_control_set_lw,
7032         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7033                 "Change low water flow control parameter",
7034         .tokens = {
7035                 (void *)&cmd_lfc_set_set,
7036                 (void *)&cmd_lfc_set_flow_ctrl,
7037                 (void *)&cmd_lfc_set_low_water_str,
7038                 (void *)&cmd_lfc_set_low_water,
7039                 (void *)&cmd_lfc_set_portid,
7040                 NULL,
7041         },
7042 };
7043
7044 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7045         .f = cmd_link_flow_ctrl_set_parsed,
7046         .data = (void *)&cmd_link_flow_control_set_pt,
7047         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7048                 "Change pause time flow control parameter",
7049         .tokens = {
7050                 (void *)&cmd_lfc_set_set,
7051                 (void *)&cmd_lfc_set_flow_ctrl,
7052                 (void *)&cmd_lfc_set_pause_time_str,
7053                 (void *)&cmd_lfc_set_pause_time,
7054                 (void *)&cmd_lfc_set_portid,
7055                 NULL,
7056         },
7057 };
7058
7059 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7060         .f = cmd_link_flow_ctrl_set_parsed,
7061         .data = (void *)&cmd_link_flow_control_set_xon,
7062         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7063                 "Change send_xon flow control parameter",
7064         .tokens = {
7065                 (void *)&cmd_lfc_set_set,
7066                 (void *)&cmd_lfc_set_flow_ctrl,
7067                 (void *)&cmd_lfc_set_send_xon_str,
7068                 (void *)&cmd_lfc_set_send_xon,
7069                 (void *)&cmd_lfc_set_portid,
7070                 NULL,
7071         },
7072 };
7073
7074 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7075         .f = cmd_link_flow_ctrl_set_parsed,
7076         .data = (void *)&cmd_link_flow_control_set_macfwd,
7077         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7078                 "Change mac ctrl fwd flow control parameter",
7079         .tokens = {
7080                 (void *)&cmd_lfc_set_set,
7081                 (void *)&cmd_lfc_set_flow_ctrl,
7082                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7083                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7084                 (void *)&cmd_lfc_set_portid,
7085                 NULL,
7086         },
7087 };
7088
7089 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7090         .f = cmd_link_flow_ctrl_set_parsed,
7091         .data = (void *)&cmd_link_flow_control_set_autoneg,
7092         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7093                 "Change autoneg flow control parameter",
7094         .tokens = {
7095                 (void *)&cmd_lfc_set_set,
7096                 (void *)&cmd_lfc_set_flow_ctrl,
7097                 (void *)&cmd_lfc_set_autoneg_str,
7098                 (void *)&cmd_lfc_set_autoneg,
7099                 (void *)&cmd_lfc_set_portid,
7100                 NULL,
7101         },
7102 };
7103
7104 static void
7105 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7106                               __rte_unused struct cmdline *cl,
7107                               void *data)
7108 {
7109         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7110         cmdline_parse_inst_t *cmd = data;
7111         struct rte_eth_fc_conf fc_conf;
7112         int rx_fc_en = 0;
7113         int tx_fc_en = 0;
7114         int ret;
7115
7116         /*
7117          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7118          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7119          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7120          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7121          */
7122         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7123                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7124         };
7125
7126         /* Partial command line, retrieve current configuration */
7127         if (cmd) {
7128                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7129                 if (ret != 0) {
7130                         printf("cannot get current flow ctrl parameters, return"
7131                                "code = %d\n", ret);
7132                         return;
7133                 }
7134
7135                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7136                     (fc_conf.mode == RTE_FC_FULL))
7137                         rx_fc_en = 1;
7138                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7139                     (fc_conf.mode == RTE_FC_FULL))
7140                         tx_fc_en = 1;
7141         }
7142
7143         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7144                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7145
7146         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7147                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7148
7149         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7150
7151         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7152                 fc_conf.high_water = res->high_water;
7153
7154         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7155                 fc_conf.low_water = res->low_water;
7156
7157         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7158                 fc_conf.pause_time = res->pause_time;
7159
7160         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7161                 fc_conf.send_xon = res->send_xon;
7162
7163         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7164                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7165                         fc_conf.mac_ctrl_frame_fwd = 1;
7166                 else
7167                         fc_conf.mac_ctrl_frame_fwd = 0;
7168         }
7169
7170         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7171                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7172
7173         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7174         if (ret != 0)
7175                 printf("bad flow contrl parameter, return code = %d \n", ret);
7176 }
7177
7178 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7179 struct cmd_priority_flow_ctrl_set_result {
7180         cmdline_fixed_string_t set;
7181         cmdline_fixed_string_t pfc_ctrl;
7182         cmdline_fixed_string_t rx;
7183         cmdline_fixed_string_t rx_pfc_mode;
7184         cmdline_fixed_string_t tx;
7185         cmdline_fixed_string_t tx_pfc_mode;
7186         uint32_t high_water;
7187         uint32_t low_water;
7188         uint16_t pause_time;
7189         uint8_t  priority;
7190         portid_t port_id;
7191 };
7192
7193 static void
7194 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7195                        __rte_unused struct cmdline *cl,
7196                        __rte_unused void *data)
7197 {
7198         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7199         struct rte_eth_pfc_conf pfc_conf;
7200         int rx_fc_enable, tx_fc_enable;
7201         int ret;
7202
7203         /*
7204          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7205          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7206          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7207          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7208          */
7209         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7210                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7211         };
7212
7213         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7214         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7215         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7216         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7217         pfc_conf.fc.high_water = res->high_water;
7218         pfc_conf.fc.low_water  = res->low_water;
7219         pfc_conf.fc.pause_time = res->pause_time;
7220         pfc_conf.priority      = res->priority;
7221
7222         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7223         if (ret != 0)
7224                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7225 }
7226
7227 cmdline_parse_token_string_t cmd_pfc_set_set =
7228         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7229                                 set, "set");
7230 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7231         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7232                                 pfc_ctrl, "pfc_ctrl");
7233 cmdline_parse_token_string_t cmd_pfc_set_rx =
7234         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7235                                 rx, "rx");
7236 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7237         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7238                                 rx_pfc_mode, "on#off");
7239 cmdline_parse_token_string_t cmd_pfc_set_tx =
7240         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7241                                 tx, "tx");
7242 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7243         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7244                                 tx_pfc_mode, "on#off");
7245 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7246         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7247                                 high_water, RTE_UINT32);
7248 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7249         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7250                                 low_water, RTE_UINT32);
7251 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7252         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7253                                 pause_time, RTE_UINT16);
7254 cmdline_parse_token_num_t cmd_pfc_set_priority =
7255         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7256                                 priority, RTE_UINT8);
7257 cmdline_parse_token_num_t cmd_pfc_set_portid =
7258         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7259                                 port_id, RTE_UINT16);
7260
7261 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7262         .f = cmd_priority_flow_ctrl_set_parsed,
7263         .data = NULL,
7264         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7265                 "<pause_time> <priority> <port_id>: "
7266                 "Configure the Ethernet priority flow control",
7267         .tokens = {
7268                 (void *)&cmd_pfc_set_set,
7269                 (void *)&cmd_pfc_set_flow_ctrl,
7270                 (void *)&cmd_pfc_set_rx,
7271                 (void *)&cmd_pfc_set_rx_mode,
7272                 (void *)&cmd_pfc_set_tx,
7273                 (void *)&cmd_pfc_set_tx_mode,
7274                 (void *)&cmd_pfc_set_high_water,
7275                 (void *)&cmd_pfc_set_low_water,
7276                 (void *)&cmd_pfc_set_pause_time,
7277                 (void *)&cmd_pfc_set_priority,
7278                 (void *)&cmd_pfc_set_portid,
7279                 NULL,
7280         },
7281 };
7282
7283 /* *** RESET CONFIGURATION *** */
7284 struct cmd_reset_result {
7285         cmdline_fixed_string_t reset;
7286         cmdline_fixed_string_t def;
7287 };
7288
7289 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7290                              struct cmdline *cl,
7291                              __rte_unused void *data)
7292 {
7293         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7294         set_def_fwd_config();
7295 }
7296
7297 cmdline_parse_token_string_t cmd_reset_set =
7298         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7299 cmdline_parse_token_string_t cmd_reset_def =
7300         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7301                                  "default");
7302
7303 cmdline_parse_inst_t cmd_reset = {
7304         .f = cmd_reset_parsed,
7305         .data = NULL,
7306         .help_str = "set default: Reset default forwarding configuration",
7307         .tokens = {
7308                 (void *)&cmd_reset_set,
7309                 (void *)&cmd_reset_def,
7310                 NULL,
7311         },
7312 };
7313
7314 /* *** START FORWARDING *** */
7315 struct cmd_start_result {
7316         cmdline_fixed_string_t start;
7317 };
7318
7319 cmdline_parse_token_string_t cmd_start_start =
7320         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7321
7322 static void cmd_start_parsed(__rte_unused void *parsed_result,
7323                              __rte_unused struct cmdline *cl,
7324                              __rte_unused void *data)
7325 {
7326         start_packet_forwarding(0);
7327 }
7328
7329 cmdline_parse_inst_t cmd_start = {
7330         .f = cmd_start_parsed,
7331         .data = NULL,
7332         .help_str = "start: Start packet forwarding",
7333         .tokens = {
7334                 (void *)&cmd_start_start,
7335                 NULL,
7336         },
7337 };
7338
7339 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7340 struct cmd_start_tx_first_result {
7341         cmdline_fixed_string_t start;
7342         cmdline_fixed_string_t tx_first;
7343 };
7344
7345 static void
7346 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7347                           __rte_unused struct cmdline *cl,
7348                           __rte_unused void *data)
7349 {
7350         start_packet_forwarding(1);
7351 }
7352
7353 cmdline_parse_token_string_t cmd_start_tx_first_start =
7354         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7355                                  "start");
7356 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7357         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7358                                  tx_first, "tx_first");
7359
7360 cmdline_parse_inst_t cmd_start_tx_first = {
7361         .f = cmd_start_tx_first_parsed,
7362         .data = NULL,
7363         .help_str = "start tx_first: Start packet forwarding, "
7364                 "after sending 1 burst of packets",
7365         .tokens = {
7366                 (void *)&cmd_start_tx_first_start,
7367                 (void *)&cmd_start_tx_first_tx_first,
7368                 NULL,
7369         },
7370 };
7371
7372 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7373 struct cmd_start_tx_first_n_result {
7374         cmdline_fixed_string_t start;
7375         cmdline_fixed_string_t tx_first;
7376         uint32_t tx_num;
7377 };
7378
7379 static void
7380 cmd_start_tx_first_n_parsed(void *parsed_result,
7381                           __rte_unused struct cmdline *cl,
7382                           __rte_unused void *data)
7383 {
7384         struct cmd_start_tx_first_n_result *res = parsed_result;
7385
7386         start_packet_forwarding(res->tx_num);
7387 }
7388
7389 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7390         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7391                         start, "start");
7392 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7393         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7394                         tx_first, "tx_first");
7395 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7396         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7397                         tx_num, RTE_UINT32);
7398
7399 cmdline_parse_inst_t cmd_start_tx_first_n = {
7400         .f = cmd_start_tx_first_n_parsed,
7401         .data = NULL,
7402         .help_str = "start tx_first <num>: "
7403                 "packet forwarding, after sending <num> bursts of packets",
7404         .tokens = {
7405                 (void *)&cmd_start_tx_first_n_start,
7406                 (void *)&cmd_start_tx_first_n_tx_first,
7407                 (void *)&cmd_start_tx_first_n_tx_num,
7408                 NULL,
7409         },
7410 };
7411
7412 /* *** SET LINK UP *** */
7413 struct cmd_set_link_up_result {
7414         cmdline_fixed_string_t set;
7415         cmdline_fixed_string_t link_up;
7416         cmdline_fixed_string_t port;
7417         portid_t port_id;
7418 };
7419
7420 cmdline_parse_token_string_t cmd_set_link_up_set =
7421         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7422 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7423         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7424                                 "link-up");
7425 cmdline_parse_token_string_t cmd_set_link_up_port =
7426         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7427 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7428         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7429                                 RTE_UINT16);
7430
7431 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7432                              __rte_unused struct cmdline *cl,
7433                              __rte_unused void *data)
7434 {
7435         struct cmd_set_link_up_result *res = parsed_result;
7436         dev_set_link_up(res->port_id);
7437 }
7438
7439 cmdline_parse_inst_t cmd_set_link_up = {
7440         .f = cmd_set_link_up_parsed,
7441         .data = NULL,
7442         .help_str = "set link-up port <port id>",
7443         .tokens = {
7444                 (void *)&cmd_set_link_up_set,
7445                 (void *)&cmd_set_link_up_link_up,
7446                 (void *)&cmd_set_link_up_port,
7447                 (void *)&cmd_set_link_up_port_id,
7448                 NULL,
7449         },
7450 };
7451
7452 /* *** SET LINK DOWN *** */
7453 struct cmd_set_link_down_result {
7454         cmdline_fixed_string_t set;
7455         cmdline_fixed_string_t link_down;
7456         cmdline_fixed_string_t port;
7457         portid_t port_id;
7458 };
7459
7460 cmdline_parse_token_string_t cmd_set_link_down_set =
7461         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7462 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7463         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7464                                 "link-down");
7465 cmdline_parse_token_string_t cmd_set_link_down_port =
7466         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7467 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7468         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7469                                 RTE_UINT16);
7470
7471 static void cmd_set_link_down_parsed(
7472                                 __rte_unused void *parsed_result,
7473                                 __rte_unused struct cmdline *cl,
7474                                 __rte_unused void *data)
7475 {
7476         struct cmd_set_link_down_result *res = parsed_result;
7477         dev_set_link_down(res->port_id);
7478 }
7479
7480 cmdline_parse_inst_t cmd_set_link_down = {
7481         .f = cmd_set_link_down_parsed,
7482         .data = NULL,
7483         .help_str = "set link-down port <port id>",
7484         .tokens = {
7485                 (void *)&cmd_set_link_down_set,
7486                 (void *)&cmd_set_link_down_link_down,
7487                 (void *)&cmd_set_link_down_port,
7488                 (void *)&cmd_set_link_down_port_id,
7489                 NULL,
7490         },
7491 };
7492
7493 /* *** SHOW CFG *** */
7494 struct cmd_showcfg_result {
7495         cmdline_fixed_string_t show;
7496         cmdline_fixed_string_t cfg;
7497         cmdline_fixed_string_t what;
7498 };
7499
7500 static void cmd_showcfg_parsed(void *parsed_result,
7501                                __rte_unused struct cmdline *cl,
7502                                __rte_unused void *data)
7503 {
7504         struct cmd_showcfg_result *res = parsed_result;
7505         if (!strcmp(res->what, "rxtx"))
7506                 rxtx_config_display();
7507         else if (!strcmp(res->what, "cores"))
7508                 fwd_lcores_config_display();
7509         else if (!strcmp(res->what, "fwd"))
7510                 pkt_fwd_config_display(&cur_fwd_config);
7511         else if (!strcmp(res->what, "rxoffs"))
7512                 show_rx_pkt_offsets();
7513         else if (!strcmp(res->what, "rxpkts"))
7514                 show_rx_pkt_segments();
7515         else if (!strcmp(res->what, "txpkts"))
7516                 show_tx_pkt_segments();
7517         else if (!strcmp(res->what, "txtimes"))
7518                 show_tx_pkt_times();
7519 }
7520
7521 cmdline_parse_token_string_t cmd_showcfg_show =
7522         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7523 cmdline_parse_token_string_t cmd_showcfg_port =
7524         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7525 cmdline_parse_token_string_t cmd_showcfg_what =
7526         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7527                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7528
7529 cmdline_parse_inst_t cmd_showcfg = {
7530         .f = cmd_showcfg_parsed,
7531         .data = NULL,
7532         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7533         .tokens = {
7534                 (void *)&cmd_showcfg_show,
7535                 (void *)&cmd_showcfg_port,
7536                 (void *)&cmd_showcfg_what,
7537                 NULL,
7538         },
7539 };
7540
7541 /* *** SHOW ALL PORT INFO *** */
7542 struct cmd_showportall_result {
7543         cmdline_fixed_string_t show;
7544         cmdline_fixed_string_t port;
7545         cmdline_fixed_string_t what;
7546         cmdline_fixed_string_t all;
7547 };
7548
7549 static void cmd_showportall_parsed(void *parsed_result,
7550                                 __rte_unused struct cmdline *cl,
7551                                 __rte_unused void *data)
7552 {
7553         portid_t i;
7554
7555         struct cmd_showportall_result *res = parsed_result;
7556         if (!strcmp(res->show, "clear")) {
7557                 if (!strcmp(res->what, "stats"))
7558                         RTE_ETH_FOREACH_DEV(i)
7559                                 nic_stats_clear(i);
7560                 else if (!strcmp(res->what, "xstats"))
7561                         RTE_ETH_FOREACH_DEV(i)
7562                                 nic_xstats_clear(i);
7563         } else if (!strcmp(res->what, "info"))
7564                 RTE_ETH_FOREACH_DEV(i)
7565                         port_infos_display(i);
7566         else if (!strcmp(res->what, "summary")) {
7567                 port_summary_header_display();
7568                 RTE_ETH_FOREACH_DEV(i)
7569                         port_summary_display(i);
7570         }
7571         else if (!strcmp(res->what, "stats"))
7572                 RTE_ETH_FOREACH_DEV(i)
7573                         nic_stats_display(i);
7574         else if (!strcmp(res->what, "xstats"))
7575                 RTE_ETH_FOREACH_DEV(i)
7576                         nic_xstats_display(i);
7577 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7578         else if (!strcmp(res->what, "fdir"))
7579                 RTE_ETH_FOREACH_DEV(i)
7580                         fdir_get_infos(i);
7581 #endif
7582         else if (!strcmp(res->what, "dcb_tc"))
7583                 RTE_ETH_FOREACH_DEV(i)
7584                         port_dcb_info_display(i);
7585 }
7586
7587 cmdline_parse_token_string_t cmd_showportall_show =
7588         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7589                                  "show#clear");
7590 cmdline_parse_token_string_t cmd_showportall_port =
7591         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7592 cmdline_parse_token_string_t cmd_showportall_what =
7593         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7594                                  "info#summary#stats#xstats#fdir#dcb_tc");
7595 cmdline_parse_token_string_t cmd_showportall_all =
7596         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7597 cmdline_parse_inst_t cmd_showportall = {
7598         .f = cmd_showportall_parsed,
7599         .data = NULL,
7600         .help_str = "show|clear port "
7601                 "info|summary|stats|xstats|fdir|dcb_tc all",
7602         .tokens = {
7603                 (void *)&cmd_showportall_show,
7604                 (void *)&cmd_showportall_port,
7605                 (void *)&cmd_showportall_what,
7606                 (void *)&cmd_showportall_all,
7607                 NULL,
7608         },
7609 };
7610
7611 /* *** SHOW PORT INFO *** */
7612 struct cmd_showport_result {
7613         cmdline_fixed_string_t show;
7614         cmdline_fixed_string_t port;
7615         cmdline_fixed_string_t what;
7616         uint16_t portnum;
7617 };
7618
7619 static void cmd_showport_parsed(void *parsed_result,
7620                                 __rte_unused struct cmdline *cl,
7621                                 __rte_unused void *data)
7622 {
7623         struct cmd_showport_result *res = parsed_result;
7624         if (!strcmp(res->show, "clear")) {
7625                 if (!strcmp(res->what, "stats"))
7626                         nic_stats_clear(res->portnum);
7627                 else if (!strcmp(res->what, "xstats"))
7628                         nic_xstats_clear(res->portnum);
7629         } else if (!strcmp(res->what, "info"))
7630                 port_infos_display(res->portnum);
7631         else if (!strcmp(res->what, "summary")) {
7632                 port_summary_header_display();
7633                 port_summary_display(res->portnum);
7634         }
7635         else if (!strcmp(res->what, "stats"))
7636                 nic_stats_display(res->portnum);
7637         else if (!strcmp(res->what, "xstats"))
7638                 nic_xstats_display(res->portnum);
7639 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7640         else if (!strcmp(res->what, "fdir"))
7641                  fdir_get_infos(res->portnum);
7642 #endif
7643         else if (!strcmp(res->what, "dcb_tc"))
7644                 port_dcb_info_display(res->portnum);
7645 }
7646
7647 cmdline_parse_token_string_t cmd_showport_show =
7648         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7649                                  "show#clear");
7650 cmdline_parse_token_string_t cmd_showport_port =
7651         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7652 cmdline_parse_token_string_t cmd_showport_what =
7653         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7654                                  "info#summary#stats#xstats#fdir#dcb_tc");
7655 cmdline_parse_token_num_t cmd_showport_portnum =
7656         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
7657
7658 cmdline_parse_inst_t cmd_showport = {
7659         .f = cmd_showport_parsed,
7660         .data = NULL,
7661         .help_str = "show|clear port "
7662                 "info|summary|stats|xstats|fdir|dcb_tc "
7663                 "<port_id>",
7664         .tokens = {
7665                 (void *)&cmd_showport_show,
7666                 (void *)&cmd_showport_port,
7667                 (void *)&cmd_showport_what,
7668                 (void *)&cmd_showport_portnum,
7669                 NULL,
7670         },
7671 };
7672
7673 /* *** SHOW DEVICE INFO *** */
7674 struct cmd_showdevice_result {
7675         cmdline_fixed_string_t show;
7676         cmdline_fixed_string_t device;
7677         cmdline_fixed_string_t what;
7678         cmdline_fixed_string_t identifier;
7679 };
7680
7681 static void cmd_showdevice_parsed(void *parsed_result,
7682                                 __rte_unused struct cmdline *cl,
7683                                 __rte_unused void *data)
7684 {
7685         struct cmd_showdevice_result *res = parsed_result;
7686         if (!strcmp(res->what, "info")) {
7687                 if (!strcmp(res->identifier, "all"))
7688                         device_infos_display(NULL);
7689                 else
7690                         device_infos_display(res->identifier);
7691         }
7692 }
7693
7694 cmdline_parse_token_string_t cmd_showdevice_show =
7695         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7696                                  "show");
7697 cmdline_parse_token_string_t cmd_showdevice_device =
7698         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7699 cmdline_parse_token_string_t cmd_showdevice_what =
7700         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7701                                  "info");
7702 cmdline_parse_token_string_t cmd_showdevice_identifier =
7703         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7704                         identifier, NULL);
7705
7706 cmdline_parse_inst_t cmd_showdevice = {
7707         .f = cmd_showdevice_parsed,
7708         .data = NULL,
7709         .help_str = "show device info <identifier>|all",
7710         .tokens = {
7711                 (void *)&cmd_showdevice_show,
7712                 (void *)&cmd_showdevice_device,
7713                 (void *)&cmd_showdevice_what,
7714                 (void *)&cmd_showdevice_identifier,
7715                 NULL,
7716         },
7717 };
7718
7719 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7720 struct cmd_showeeprom_result {
7721         cmdline_fixed_string_t show;
7722         cmdline_fixed_string_t port;
7723         uint16_t portnum;
7724         cmdline_fixed_string_t type;
7725 };
7726
7727 static void cmd_showeeprom_parsed(void *parsed_result,
7728                 __rte_unused struct cmdline *cl,
7729                 __rte_unused void *data)
7730 {
7731         struct cmd_showeeprom_result *res = parsed_result;
7732
7733         if (!strcmp(res->type, "eeprom"))
7734                 port_eeprom_display(res->portnum);
7735         else if (!strcmp(res->type, "module_eeprom"))
7736                 port_module_eeprom_display(res->portnum);
7737         else
7738                 printf("Unknown argument\n");
7739 }
7740
7741 cmdline_parse_token_string_t cmd_showeeprom_show =
7742         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7743 cmdline_parse_token_string_t cmd_showeeprom_port =
7744         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7745 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7746         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
7747                         RTE_UINT16);
7748 cmdline_parse_token_string_t cmd_showeeprom_type =
7749         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7750
7751 cmdline_parse_inst_t cmd_showeeprom = {
7752         .f = cmd_showeeprom_parsed,
7753         .data = NULL,
7754         .help_str = "show port <port_id> module_eeprom|eeprom",
7755         .tokens = {
7756                 (void *)&cmd_showeeprom_show,
7757                 (void *)&cmd_showeeprom_port,
7758                 (void *)&cmd_showeeprom_portnum,
7759                 (void *)&cmd_showeeprom_type,
7760                 NULL,
7761         },
7762 };
7763
7764 /* *** SHOW QUEUE INFO *** */
7765 struct cmd_showqueue_result {
7766         cmdline_fixed_string_t show;
7767         cmdline_fixed_string_t type;
7768         cmdline_fixed_string_t what;
7769         uint16_t portnum;
7770         uint16_t queuenum;
7771 };
7772
7773 static void
7774 cmd_showqueue_parsed(void *parsed_result,
7775         __rte_unused struct cmdline *cl,
7776         __rte_unused void *data)
7777 {
7778         struct cmd_showqueue_result *res = parsed_result;
7779
7780         if (!strcmp(res->type, "rxq"))
7781                 rx_queue_infos_display(res->portnum, res->queuenum);
7782         else if (!strcmp(res->type, "txq"))
7783                 tx_queue_infos_display(res->portnum, res->queuenum);
7784 }
7785
7786 cmdline_parse_token_string_t cmd_showqueue_show =
7787         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7788 cmdline_parse_token_string_t cmd_showqueue_type =
7789         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7790 cmdline_parse_token_string_t cmd_showqueue_what =
7791         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7792 cmdline_parse_token_num_t cmd_showqueue_portnum =
7793         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
7794                 RTE_UINT16);
7795 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7796         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
7797                 RTE_UINT16);
7798
7799 cmdline_parse_inst_t cmd_showqueue = {
7800         .f = cmd_showqueue_parsed,
7801         .data = NULL,
7802         .help_str = "show rxq|txq info <port_id> <queue_id>",
7803         .tokens = {
7804                 (void *)&cmd_showqueue_show,
7805                 (void *)&cmd_showqueue_type,
7806                 (void *)&cmd_showqueue_what,
7807                 (void *)&cmd_showqueue_portnum,
7808                 (void *)&cmd_showqueue_queuenum,
7809                 NULL,
7810         },
7811 };
7812
7813 /* show/clear fwd engine statistics */
7814 struct fwd_result {
7815         cmdline_fixed_string_t action;
7816         cmdline_fixed_string_t fwd;
7817         cmdline_fixed_string_t stats;
7818         cmdline_fixed_string_t all;
7819 };
7820
7821 cmdline_parse_token_string_t cmd_fwd_action =
7822         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7823 cmdline_parse_token_string_t cmd_fwd_fwd =
7824         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7825 cmdline_parse_token_string_t cmd_fwd_stats =
7826         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7827 cmdline_parse_token_string_t cmd_fwd_all =
7828         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7829
7830 static void
7831 cmd_showfwdall_parsed(void *parsed_result,
7832                       __rte_unused struct cmdline *cl,
7833                       __rte_unused void *data)
7834 {
7835         struct fwd_result *res = parsed_result;
7836
7837         if (!strcmp(res->action, "show"))
7838                 fwd_stats_display();
7839         else
7840                 fwd_stats_reset();
7841 }
7842
7843 static cmdline_parse_inst_t cmd_showfwdall = {
7844         .f = cmd_showfwdall_parsed,
7845         .data = NULL,
7846         .help_str = "show|clear fwd stats all",
7847         .tokens = {
7848                 (void *)&cmd_fwd_action,
7849                 (void *)&cmd_fwd_fwd,
7850                 (void *)&cmd_fwd_stats,
7851                 (void *)&cmd_fwd_all,
7852                 NULL,
7853         },
7854 };
7855
7856 /* *** READ PORT REGISTER *** */
7857 struct cmd_read_reg_result {
7858         cmdline_fixed_string_t read;
7859         cmdline_fixed_string_t reg;
7860         portid_t port_id;
7861         uint32_t reg_off;
7862 };
7863
7864 static void
7865 cmd_read_reg_parsed(void *parsed_result,
7866                     __rte_unused struct cmdline *cl,
7867                     __rte_unused void *data)
7868 {
7869         struct cmd_read_reg_result *res = parsed_result;
7870         port_reg_display(res->port_id, res->reg_off);
7871 }
7872
7873 cmdline_parse_token_string_t cmd_read_reg_read =
7874         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7875 cmdline_parse_token_string_t cmd_read_reg_reg =
7876         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7877 cmdline_parse_token_num_t cmd_read_reg_port_id =
7878         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
7879 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7880         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
7881
7882 cmdline_parse_inst_t cmd_read_reg = {
7883         .f = cmd_read_reg_parsed,
7884         .data = NULL,
7885         .help_str = "read reg <port_id> <reg_off>",
7886         .tokens = {
7887                 (void *)&cmd_read_reg_read,
7888                 (void *)&cmd_read_reg_reg,
7889                 (void *)&cmd_read_reg_port_id,
7890                 (void *)&cmd_read_reg_reg_off,
7891                 NULL,
7892         },
7893 };
7894
7895 /* *** READ PORT REGISTER BIT FIELD *** */
7896 struct cmd_read_reg_bit_field_result {
7897         cmdline_fixed_string_t read;
7898         cmdline_fixed_string_t regfield;
7899         portid_t port_id;
7900         uint32_t reg_off;
7901         uint8_t bit1_pos;
7902         uint8_t bit2_pos;
7903 };
7904
7905 static void
7906 cmd_read_reg_bit_field_parsed(void *parsed_result,
7907                               __rte_unused struct cmdline *cl,
7908                               __rte_unused void *data)
7909 {
7910         struct cmd_read_reg_bit_field_result *res = parsed_result;
7911         port_reg_bit_field_display(res->port_id, res->reg_off,
7912                                    res->bit1_pos, res->bit2_pos);
7913 }
7914
7915 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7916         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7917                                  "read");
7918 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7919         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7920                                  regfield, "regfield");
7921 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7922         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7923                               RTE_UINT16);
7924 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7925         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7926                               RTE_UINT32);
7927 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7928         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7929                               RTE_UINT8);
7930 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7931         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7932                               RTE_UINT8);
7933
7934 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7935         .f = cmd_read_reg_bit_field_parsed,
7936         .data = NULL,
7937         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7938         "Read register bit field between bit_x and bit_y included",
7939         .tokens = {
7940                 (void *)&cmd_read_reg_bit_field_read,
7941                 (void *)&cmd_read_reg_bit_field_regfield,
7942                 (void *)&cmd_read_reg_bit_field_port_id,
7943                 (void *)&cmd_read_reg_bit_field_reg_off,
7944                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7945                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7946                 NULL,
7947         },
7948 };
7949
7950 /* *** READ PORT REGISTER BIT *** */
7951 struct cmd_read_reg_bit_result {
7952         cmdline_fixed_string_t read;
7953         cmdline_fixed_string_t regbit;
7954         portid_t port_id;
7955         uint32_t reg_off;
7956         uint8_t bit_pos;
7957 };
7958
7959 static void
7960 cmd_read_reg_bit_parsed(void *parsed_result,
7961                         __rte_unused struct cmdline *cl,
7962                         __rte_unused void *data)
7963 {
7964         struct cmd_read_reg_bit_result *res = parsed_result;
7965         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7966 }
7967
7968 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7969         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7970 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7971         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7972                                  regbit, "regbit");
7973 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7974         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
7975                                  RTE_UINT16);
7976 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7977         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
7978                                  RTE_UINT32);
7979 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7980         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
7981                                  RTE_UINT8);
7982
7983 cmdline_parse_inst_t cmd_read_reg_bit = {
7984         .f = cmd_read_reg_bit_parsed,
7985         .data = NULL,
7986         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7987         .tokens = {
7988                 (void *)&cmd_read_reg_bit_read,
7989                 (void *)&cmd_read_reg_bit_regbit,
7990                 (void *)&cmd_read_reg_bit_port_id,
7991                 (void *)&cmd_read_reg_bit_reg_off,
7992                 (void *)&cmd_read_reg_bit_bit_pos,
7993                 NULL,
7994         },
7995 };
7996
7997 /* *** WRITE PORT REGISTER *** */
7998 struct cmd_write_reg_result {
7999         cmdline_fixed_string_t write;
8000         cmdline_fixed_string_t reg;
8001         portid_t port_id;
8002         uint32_t reg_off;
8003         uint32_t value;
8004 };
8005
8006 static void
8007 cmd_write_reg_parsed(void *parsed_result,
8008                      __rte_unused struct cmdline *cl,
8009                      __rte_unused void *data)
8010 {
8011         struct cmd_write_reg_result *res = parsed_result;
8012         port_reg_set(res->port_id, res->reg_off, res->value);
8013 }
8014
8015 cmdline_parse_token_string_t cmd_write_reg_write =
8016         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8017 cmdline_parse_token_string_t cmd_write_reg_reg =
8018         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8019 cmdline_parse_token_num_t cmd_write_reg_port_id =
8020         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8021 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8022         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8023 cmdline_parse_token_num_t cmd_write_reg_value =
8024         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8025
8026 cmdline_parse_inst_t cmd_write_reg = {
8027         .f = cmd_write_reg_parsed,
8028         .data = NULL,
8029         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8030         .tokens = {
8031                 (void *)&cmd_write_reg_write,
8032                 (void *)&cmd_write_reg_reg,
8033                 (void *)&cmd_write_reg_port_id,
8034                 (void *)&cmd_write_reg_reg_off,
8035                 (void *)&cmd_write_reg_value,
8036                 NULL,
8037         },
8038 };
8039
8040 /* *** WRITE PORT REGISTER BIT FIELD *** */
8041 struct cmd_write_reg_bit_field_result {
8042         cmdline_fixed_string_t write;
8043         cmdline_fixed_string_t regfield;
8044         portid_t port_id;
8045         uint32_t reg_off;
8046         uint8_t bit1_pos;
8047         uint8_t bit2_pos;
8048         uint32_t value;
8049 };
8050
8051 static void
8052 cmd_write_reg_bit_field_parsed(void *parsed_result,
8053                                __rte_unused struct cmdline *cl,
8054                                __rte_unused void *data)
8055 {
8056         struct cmd_write_reg_bit_field_result *res = parsed_result;
8057         port_reg_bit_field_set(res->port_id, res->reg_off,
8058                           res->bit1_pos, res->bit2_pos, res->value);
8059 }
8060
8061 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8062         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8063                                  "write");
8064 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8065         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8066                                  regfield, "regfield");
8067 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8068         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8069                               RTE_UINT16);
8070 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8071         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8072                               RTE_UINT32);
8073 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8074         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8075                               RTE_UINT8);
8076 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8077         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8078                               RTE_UINT8);
8079 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8080         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8081                               RTE_UINT32);
8082
8083 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8084         .f = cmd_write_reg_bit_field_parsed,
8085         .data = NULL,
8086         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8087                 "<reg_value>: "
8088                 "Set register bit field between bit_x and bit_y included",
8089         .tokens = {
8090                 (void *)&cmd_write_reg_bit_field_write,
8091                 (void *)&cmd_write_reg_bit_field_regfield,
8092                 (void *)&cmd_write_reg_bit_field_port_id,
8093                 (void *)&cmd_write_reg_bit_field_reg_off,
8094                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8095                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8096                 (void *)&cmd_write_reg_bit_field_value,
8097                 NULL,
8098         },
8099 };
8100
8101 /* *** WRITE PORT REGISTER BIT *** */
8102 struct cmd_write_reg_bit_result {
8103         cmdline_fixed_string_t write;
8104         cmdline_fixed_string_t regbit;
8105         portid_t port_id;
8106         uint32_t reg_off;
8107         uint8_t bit_pos;
8108         uint8_t value;
8109 };
8110
8111 static void
8112 cmd_write_reg_bit_parsed(void *parsed_result,
8113                          __rte_unused struct cmdline *cl,
8114                          __rte_unused void *data)
8115 {
8116         struct cmd_write_reg_bit_result *res = parsed_result;
8117         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8118 }
8119
8120 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8121         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8122                                  "write");
8123 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8124         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8125                                  regbit, "regbit");
8126 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8127         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8128                                  RTE_UINT16);
8129 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8130         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8131                                  RTE_UINT32);
8132 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8133         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8134                                  RTE_UINT8);
8135 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8136         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8137                                  RTE_UINT8);
8138
8139 cmdline_parse_inst_t cmd_write_reg_bit = {
8140         .f = cmd_write_reg_bit_parsed,
8141         .data = NULL,
8142         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8143                 "0 <= bit_x <= 31",
8144         .tokens = {
8145                 (void *)&cmd_write_reg_bit_write,
8146                 (void *)&cmd_write_reg_bit_regbit,
8147                 (void *)&cmd_write_reg_bit_port_id,
8148                 (void *)&cmd_write_reg_bit_reg_off,
8149                 (void *)&cmd_write_reg_bit_bit_pos,
8150                 (void *)&cmd_write_reg_bit_value,
8151                 NULL,
8152         },
8153 };
8154
8155 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8156 struct cmd_read_rxd_txd_result {
8157         cmdline_fixed_string_t read;
8158         cmdline_fixed_string_t rxd_txd;
8159         portid_t port_id;
8160         uint16_t queue_id;
8161         uint16_t desc_id;
8162 };
8163
8164 static void
8165 cmd_read_rxd_txd_parsed(void *parsed_result,
8166                         __rte_unused struct cmdline *cl,
8167                         __rte_unused void *data)
8168 {
8169         struct cmd_read_rxd_txd_result *res = parsed_result;
8170
8171         if (!strcmp(res->rxd_txd, "rxd"))
8172                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8173         else if (!strcmp(res->rxd_txd, "txd"))
8174                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8175 }
8176
8177 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8178         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8179 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8180         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8181                                  "rxd#txd");
8182 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8183         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8184                                  RTE_UINT16);
8185 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8186         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8187                                  RTE_UINT16);
8188 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8189         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8190                                  RTE_UINT16);
8191
8192 cmdline_parse_inst_t cmd_read_rxd_txd = {
8193         .f = cmd_read_rxd_txd_parsed,
8194         .data = NULL,
8195         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8196         .tokens = {
8197                 (void *)&cmd_read_rxd_txd_read,
8198                 (void *)&cmd_read_rxd_txd_rxd_txd,
8199                 (void *)&cmd_read_rxd_txd_port_id,
8200                 (void *)&cmd_read_rxd_txd_queue_id,
8201                 (void *)&cmd_read_rxd_txd_desc_id,
8202                 NULL,
8203         },
8204 };
8205
8206 /* *** QUIT *** */
8207 struct cmd_quit_result {
8208         cmdline_fixed_string_t quit;
8209 };
8210
8211 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8212                             struct cmdline *cl,
8213                             __rte_unused void *data)
8214 {
8215         cmdline_quit(cl);
8216 }
8217
8218 cmdline_parse_token_string_t cmd_quit_quit =
8219         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8220
8221 cmdline_parse_inst_t cmd_quit = {
8222         .f = cmd_quit_parsed,
8223         .data = NULL,
8224         .help_str = "quit: Exit application",
8225         .tokens = {
8226                 (void *)&cmd_quit_quit,
8227                 NULL,
8228         },
8229 };
8230
8231 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8232 struct cmd_mac_addr_result {
8233         cmdline_fixed_string_t mac_addr_cmd;
8234         cmdline_fixed_string_t what;
8235         uint16_t port_num;
8236         struct rte_ether_addr address;
8237 };
8238
8239 static void cmd_mac_addr_parsed(void *parsed_result,
8240                 __rte_unused struct cmdline *cl,
8241                 __rte_unused void *data)
8242 {
8243         struct cmd_mac_addr_result *res = parsed_result;
8244         int ret;
8245
8246         if (strcmp(res->what, "add") == 0)
8247                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8248         else if (strcmp(res->what, "set") == 0)
8249                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8250                                                        &res->address);
8251         else
8252                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8253
8254         /* check the return value and print it if is < 0 */
8255         if(ret < 0)
8256                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8257
8258 }
8259
8260 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8261         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8262                                 "mac_addr");
8263 cmdline_parse_token_string_t cmd_mac_addr_what =
8264         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8265                                 "add#remove#set");
8266 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8267                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8268                                         RTE_UINT16);
8269 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8270                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8271
8272 cmdline_parse_inst_t cmd_mac_addr = {
8273         .f = cmd_mac_addr_parsed,
8274         .data = (void *)0,
8275         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8276                         "Add/Remove/Set MAC address on port_id",
8277         .tokens = {
8278                 (void *)&cmd_mac_addr_cmd,
8279                 (void *)&cmd_mac_addr_what,
8280                 (void *)&cmd_mac_addr_portnum,
8281                 (void *)&cmd_mac_addr_addr,
8282                 NULL,
8283         },
8284 };
8285
8286 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8287 struct cmd_eth_peer_result {
8288         cmdline_fixed_string_t set;
8289         cmdline_fixed_string_t eth_peer;
8290         portid_t port_id;
8291         cmdline_fixed_string_t peer_addr;
8292 };
8293
8294 static void cmd_set_eth_peer_parsed(void *parsed_result,
8295                         __rte_unused struct cmdline *cl,
8296                         __rte_unused void *data)
8297 {
8298                 struct cmd_eth_peer_result *res = parsed_result;
8299
8300                 if (test_done == 0) {
8301                         printf("Please stop forwarding first\n");
8302                         return;
8303                 }
8304                 if (!strcmp(res->eth_peer, "eth-peer")) {
8305                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8306                         fwd_config_setup();
8307                 }
8308 }
8309 cmdline_parse_token_string_t cmd_eth_peer_set =
8310         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8311 cmdline_parse_token_string_t cmd_eth_peer =
8312         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8313 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8314         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8315                 RTE_UINT16);
8316 cmdline_parse_token_string_t cmd_eth_peer_addr =
8317         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8318
8319 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8320         .f = cmd_set_eth_peer_parsed,
8321         .data = NULL,
8322         .help_str = "set eth-peer <port_id> <peer_mac>",
8323         .tokens = {
8324                 (void *)&cmd_eth_peer_set,
8325                 (void *)&cmd_eth_peer,
8326                 (void *)&cmd_eth_peer_port_id,
8327                 (void *)&cmd_eth_peer_addr,
8328                 NULL,
8329         },
8330 };
8331
8332 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8333 struct cmd_set_qmap_result {
8334         cmdline_fixed_string_t set;
8335         cmdline_fixed_string_t qmap;
8336         cmdline_fixed_string_t what;
8337         portid_t port_id;
8338         uint16_t queue_id;
8339         uint8_t map_value;
8340 };
8341
8342 static void
8343 cmd_set_qmap_parsed(void *parsed_result,
8344                        __rte_unused struct cmdline *cl,
8345                        __rte_unused void *data)
8346 {
8347         struct cmd_set_qmap_result *res = parsed_result;
8348         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8349
8350         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8351 }
8352
8353 cmdline_parse_token_string_t cmd_setqmap_set =
8354         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8355                                  set, "set");
8356 cmdline_parse_token_string_t cmd_setqmap_qmap =
8357         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8358                                  qmap, "stat_qmap");
8359 cmdline_parse_token_string_t cmd_setqmap_what =
8360         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8361                                  what, "tx#rx");
8362 cmdline_parse_token_num_t cmd_setqmap_portid =
8363         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8364                               port_id, RTE_UINT16);
8365 cmdline_parse_token_num_t cmd_setqmap_queueid =
8366         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8367                               queue_id, RTE_UINT16);
8368 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8369         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8370                               map_value, RTE_UINT8);
8371
8372 cmdline_parse_inst_t cmd_set_qmap = {
8373         .f = cmd_set_qmap_parsed,
8374         .data = NULL,
8375         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8376                 "Set statistics mapping value on tx|rx queue_id of port_id",
8377         .tokens = {
8378                 (void *)&cmd_setqmap_set,
8379                 (void *)&cmd_setqmap_qmap,
8380                 (void *)&cmd_setqmap_what,
8381                 (void *)&cmd_setqmap_portid,
8382                 (void *)&cmd_setqmap_queueid,
8383                 (void *)&cmd_setqmap_mapvalue,
8384                 NULL,
8385         },
8386 };
8387
8388 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8389 struct cmd_set_xstats_hide_zero_result {
8390         cmdline_fixed_string_t keyword;
8391         cmdline_fixed_string_t name;
8392         cmdline_fixed_string_t on_off;
8393 };
8394
8395 static void
8396 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8397                         __rte_unused struct cmdline *cl,
8398                         __rte_unused void *data)
8399 {
8400         struct cmd_set_xstats_hide_zero_result *res;
8401         uint16_t on_off = 0;
8402
8403         res = parsed_result;
8404         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8405         set_xstats_hide_zero(on_off);
8406 }
8407
8408 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8409         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8410                                  keyword, "set");
8411 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8412         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8413                                  name, "xstats-hide-zero");
8414 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8415         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8416                                  on_off, "on#off");
8417
8418 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8419         .f = cmd_set_xstats_hide_zero_parsed,
8420         .data = NULL,
8421         .help_str = "set xstats-hide-zero on|off",
8422         .tokens = {
8423                 (void *)&cmd_set_xstats_hide_zero_keyword,
8424                 (void *)&cmd_set_xstats_hide_zero_name,
8425                 (void *)&cmd_set_xstats_hide_zero_on_off,
8426                 NULL,
8427         },
8428 };
8429
8430 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8431 struct cmd_set_record_core_cycles_result {
8432         cmdline_fixed_string_t keyword;
8433         cmdline_fixed_string_t name;
8434         cmdline_fixed_string_t on_off;
8435 };
8436
8437 static void
8438 cmd_set_record_core_cycles_parsed(void *parsed_result,
8439                         __rte_unused struct cmdline *cl,
8440                         __rte_unused void *data)
8441 {
8442         struct cmd_set_record_core_cycles_result *res;
8443         uint16_t on_off = 0;
8444
8445         res = parsed_result;
8446         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8447         set_record_core_cycles(on_off);
8448 }
8449
8450 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8451         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8452                                  keyword, "set");
8453 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8454         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8455                                  name, "record-core-cycles");
8456 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8457         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8458                                  on_off, "on#off");
8459
8460 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8461         .f = cmd_set_record_core_cycles_parsed,
8462         .data = NULL,
8463         .help_str = "set record-core-cycles on|off",
8464         .tokens = {
8465                 (void *)&cmd_set_record_core_cycles_keyword,
8466                 (void *)&cmd_set_record_core_cycles_name,
8467                 (void *)&cmd_set_record_core_cycles_on_off,
8468                 NULL,
8469         },
8470 };
8471
8472 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8473 struct cmd_set_record_burst_stats_result {
8474         cmdline_fixed_string_t keyword;
8475         cmdline_fixed_string_t name;
8476         cmdline_fixed_string_t on_off;
8477 };
8478
8479 static void
8480 cmd_set_record_burst_stats_parsed(void *parsed_result,
8481                         __rte_unused struct cmdline *cl,
8482                         __rte_unused void *data)
8483 {
8484         struct cmd_set_record_burst_stats_result *res;
8485         uint16_t on_off = 0;
8486
8487         res = parsed_result;
8488         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8489         set_record_burst_stats(on_off);
8490 }
8491
8492 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8493         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8494                                  keyword, "set");
8495 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8496         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8497                                  name, "record-burst-stats");
8498 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8499         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8500                                  on_off, "on#off");
8501
8502 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8503         .f = cmd_set_record_burst_stats_parsed,
8504         .data = NULL,
8505         .help_str = "set record-burst-stats on|off",
8506         .tokens = {
8507                 (void *)&cmd_set_record_burst_stats_keyword,
8508                 (void *)&cmd_set_record_burst_stats_name,
8509                 (void *)&cmd_set_record_burst_stats_on_off,
8510                 NULL,
8511         },
8512 };
8513
8514 /* *** CONFIGURE UNICAST HASH TABLE *** */
8515 struct cmd_set_uc_hash_table {
8516         cmdline_fixed_string_t set;
8517         cmdline_fixed_string_t port;
8518         portid_t port_id;
8519         cmdline_fixed_string_t what;
8520         struct rte_ether_addr address;
8521         cmdline_fixed_string_t mode;
8522 };
8523
8524 static void
8525 cmd_set_uc_hash_parsed(void *parsed_result,
8526                        __rte_unused struct cmdline *cl,
8527                        __rte_unused void *data)
8528 {
8529         int ret=0;
8530         struct cmd_set_uc_hash_table *res = parsed_result;
8531
8532         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8533
8534         if (strcmp(res->what, "uta") == 0)
8535                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8536                                                 &res->address,(uint8_t)is_on);
8537         if (ret < 0)
8538                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8539
8540 }
8541
8542 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8543         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8544                                  set, "set");
8545 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8546         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8547                                  port, "port");
8548 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8549         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8550                               port_id, RTE_UINT16);
8551 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8552         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8553                                  what, "uta");
8554 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8555         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8556                                 address);
8557 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8558         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8559                                  mode, "on#off");
8560
8561 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8562         .f = cmd_set_uc_hash_parsed,
8563         .data = NULL,
8564         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8565         .tokens = {
8566                 (void *)&cmd_set_uc_hash_set,
8567                 (void *)&cmd_set_uc_hash_port,
8568                 (void *)&cmd_set_uc_hash_portid,
8569                 (void *)&cmd_set_uc_hash_what,
8570                 (void *)&cmd_set_uc_hash_mac,
8571                 (void *)&cmd_set_uc_hash_mode,
8572                 NULL,
8573         },
8574 };
8575
8576 struct cmd_set_uc_all_hash_table {
8577         cmdline_fixed_string_t set;
8578         cmdline_fixed_string_t port;
8579         portid_t port_id;
8580         cmdline_fixed_string_t what;
8581         cmdline_fixed_string_t value;
8582         cmdline_fixed_string_t mode;
8583 };
8584
8585 static void
8586 cmd_set_uc_all_hash_parsed(void *parsed_result,
8587                        __rte_unused struct cmdline *cl,
8588                        __rte_unused void *data)
8589 {
8590         int ret=0;
8591         struct cmd_set_uc_all_hash_table *res = parsed_result;
8592
8593         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8594
8595         if ((strcmp(res->what, "uta") == 0) &&
8596                 (strcmp(res->value, "all") == 0))
8597                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8598         if (ret < 0)
8599                 printf("bad unicast hash table parameter,"
8600                         "return code = %d \n", ret);
8601 }
8602
8603 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8604         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8605                                  set, "set");
8606 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8607         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8608                                  port, "port");
8609 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8610         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8611                               port_id, RTE_UINT16);
8612 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8613         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8614                                  what, "uta");
8615 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8616         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8617                                 value,"all");
8618 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8619         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8620                                  mode, "on#off");
8621
8622 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8623         .f = cmd_set_uc_all_hash_parsed,
8624         .data = NULL,
8625         .help_str = "set port <port_id> uta all on|off",
8626         .tokens = {
8627                 (void *)&cmd_set_uc_all_hash_set,
8628                 (void *)&cmd_set_uc_all_hash_port,
8629                 (void *)&cmd_set_uc_all_hash_portid,
8630                 (void *)&cmd_set_uc_all_hash_what,
8631                 (void *)&cmd_set_uc_all_hash_value,
8632                 (void *)&cmd_set_uc_all_hash_mode,
8633                 NULL,
8634         },
8635 };
8636
8637 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8638 struct cmd_set_vf_traffic {
8639         cmdline_fixed_string_t set;
8640         cmdline_fixed_string_t port;
8641         portid_t port_id;
8642         cmdline_fixed_string_t vf;
8643         uint8_t vf_id;
8644         cmdline_fixed_string_t what;
8645         cmdline_fixed_string_t mode;
8646 };
8647
8648 static void
8649 cmd_set_vf_traffic_parsed(void *parsed_result,
8650                        __rte_unused struct cmdline *cl,
8651                        __rte_unused void *data)
8652 {
8653         struct cmd_set_vf_traffic *res = parsed_result;
8654         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8655         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8656
8657         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8658 }
8659
8660 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8661         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8662                                  set, "set");
8663 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8664         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8665                                  port, "port");
8666 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8667         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8668                               port_id, RTE_UINT16);
8669 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8670         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8671                                  vf, "vf");
8672 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8673         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8674                               vf_id, RTE_UINT8);
8675 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8676         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8677                                  what, "tx#rx");
8678 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8679         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8680                                  mode, "on#off");
8681
8682 cmdline_parse_inst_t cmd_set_vf_traffic = {
8683         .f = cmd_set_vf_traffic_parsed,
8684         .data = NULL,
8685         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8686         .tokens = {
8687                 (void *)&cmd_setvf_traffic_set,
8688                 (void *)&cmd_setvf_traffic_port,
8689                 (void *)&cmd_setvf_traffic_portid,
8690                 (void *)&cmd_setvf_traffic_vf,
8691                 (void *)&cmd_setvf_traffic_vfid,
8692                 (void *)&cmd_setvf_traffic_what,
8693                 (void *)&cmd_setvf_traffic_mode,
8694                 NULL,
8695         },
8696 };
8697
8698 /* *** CONFIGURE VF RECEIVE MODE *** */
8699 struct cmd_set_vf_rxmode {
8700         cmdline_fixed_string_t set;
8701         cmdline_fixed_string_t port;
8702         portid_t port_id;
8703         cmdline_fixed_string_t vf;
8704         uint8_t vf_id;
8705         cmdline_fixed_string_t what;
8706         cmdline_fixed_string_t mode;
8707         cmdline_fixed_string_t on;
8708 };
8709
8710 static void
8711 cmd_set_vf_rxmode_parsed(void *parsed_result,
8712                        __rte_unused struct cmdline *cl,
8713                        __rte_unused void *data)
8714 {
8715         int ret = -ENOTSUP;
8716         uint16_t vf_rxmode = 0;
8717         struct cmd_set_vf_rxmode *res = parsed_result;
8718
8719         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8720         if (!strcmp(res->what,"rxmode")) {
8721                 if (!strcmp(res->mode, "AUPE"))
8722                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8723                 else if (!strcmp(res->mode, "ROPE"))
8724                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8725                 else if (!strcmp(res->mode, "BAM"))
8726                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8727                 else if (!strncmp(res->mode, "MPE",3))
8728                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8729         }
8730
8731         RTE_SET_USED(is_on);
8732
8733 #ifdef RTE_NET_IXGBE
8734         if (ret == -ENOTSUP)
8735                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8736                                                   vf_rxmode, (uint8_t)is_on);
8737 #endif
8738 #ifdef RTE_NET_BNXT
8739         if (ret == -ENOTSUP)
8740                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8741                                                  vf_rxmode, (uint8_t)is_on);
8742 #endif
8743         if (ret < 0)
8744                 printf("bad VF receive mode parameter, return code = %d \n",
8745                 ret);
8746 }
8747
8748 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8749         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8750                                  set, "set");
8751 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8752         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8753                                  port, "port");
8754 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8755         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8756                               port_id, RTE_UINT16);
8757 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8758         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8759                                  vf, "vf");
8760 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8761         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8762                               vf_id, RTE_UINT8);
8763 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8764         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8765                                  what, "rxmode");
8766 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8767         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8768                                  mode, "AUPE#ROPE#BAM#MPE");
8769 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8770         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8771                                  on, "on#off");
8772
8773 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8774         .f = cmd_set_vf_rxmode_parsed,
8775         .data = NULL,
8776         .help_str = "set port <port_id> vf <vf_id> rxmode "
8777                 "AUPE|ROPE|BAM|MPE on|off",
8778         .tokens = {
8779                 (void *)&cmd_set_vf_rxmode_set,
8780                 (void *)&cmd_set_vf_rxmode_port,
8781                 (void *)&cmd_set_vf_rxmode_portid,
8782                 (void *)&cmd_set_vf_rxmode_vf,
8783                 (void *)&cmd_set_vf_rxmode_vfid,
8784                 (void *)&cmd_set_vf_rxmode_what,
8785                 (void *)&cmd_set_vf_rxmode_mode,
8786                 (void *)&cmd_set_vf_rxmode_on,
8787                 NULL,
8788         },
8789 };
8790
8791 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8792 struct cmd_vf_mac_addr_result {
8793         cmdline_fixed_string_t mac_addr_cmd;
8794         cmdline_fixed_string_t what;
8795         cmdline_fixed_string_t port;
8796         uint16_t port_num;
8797         cmdline_fixed_string_t vf;
8798         uint8_t vf_num;
8799         struct rte_ether_addr address;
8800 };
8801
8802 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8803                 __rte_unused struct cmdline *cl,
8804                 __rte_unused void *data)
8805 {
8806         struct cmd_vf_mac_addr_result *res = parsed_result;
8807         int ret = -ENOTSUP;
8808
8809         if (strcmp(res->what, "add") != 0)
8810                 return;
8811
8812 #ifdef RTE_NET_I40E
8813         if (ret == -ENOTSUP)
8814                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8815                                                    &res->address);
8816 #endif
8817 #ifdef RTE_NET_BNXT
8818         if (ret == -ENOTSUP)
8819                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8820                                                 res->vf_num);
8821 #endif
8822
8823         if(ret < 0)
8824                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8825
8826 }
8827
8828 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8829         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8830                                 mac_addr_cmd,"mac_addr");
8831 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8832         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8833                                 what,"add");
8834 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8835         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8836                                 port,"port");
8837 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8838         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8839                                 port_num, RTE_UINT16);
8840 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8841         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8842                                 vf,"vf");
8843 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8844         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8845                                 vf_num, RTE_UINT8);
8846 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8847         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8848                                 address);
8849
8850 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8851         .f = cmd_vf_mac_addr_parsed,
8852         .data = (void *)0,
8853         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8854                 "Add MAC address filtering for a VF on port_id",
8855         .tokens = {
8856                 (void *)&cmd_vf_mac_addr_cmd,
8857                 (void *)&cmd_vf_mac_addr_what,
8858                 (void *)&cmd_vf_mac_addr_port,
8859                 (void *)&cmd_vf_mac_addr_portnum,
8860                 (void *)&cmd_vf_mac_addr_vf,
8861                 (void *)&cmd_vf_mac_addr_vfnum,
8862                 (void *)&cmd_vf_mac_addr_addr,
8863                 NULL,
8864         },
8865 };
8866
8867 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8868 struct cmd_vf_rx_vlan_filter {
8869         cmdline_fixed_string_t rx_vlan;
8870         cmdline_fixed_string_t what;
8871         uint16_t vlan_id;
8872         cmdline_fixed_string_t port;
8873         portid_t port_id;
8874         cmdline_fixed_string_t vf;
8875         uint64_t vf_mask;
8876 };
8877
8878 static void
8879 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8880                           __rte_unused struct cmdline *cl,
8881                           __rte_unused void *data)
8882 {
8883         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8884         int ret = -ENOTSUP;
8885
8886         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8887
8888 #ifdef RTE_NET_IXGBE
8889         if (ret == -ENOTSUP)
8890                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8891                                 res->vlan_id, res->vf_mask, is_add);
8892 #endif
8893 #ifdef RTE_NET_I40E
8894         if (ret == -ENOTSUP)
8895                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8896                                 res->vlan_id, res->vf_mask, is_add);
8897 #endif
8898 #ifdef RTE_NET_BNXT
8899         if (ret == -ENOTSUP)
8900                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8901                                 res->vlan_id, res->vf_mask, is_add);
8902 #endif
8903
8904         switch (ret) {
8905         case 0:
8906                 break;
8907         case -EINVAL:
8908                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8909                                 res->vlan_id, res->vf_mask);
8910                 break;
8911         case -ENODEV:
8912                 printf("invalid port_id %d\n", res->port_id);
8913                 break;
8914         case -ENOTSUP:
8915                 printf("function not implemented or supported\n");
8916                 break;
8917         default:
8918                 printf("programming error: (%s)\n", strerror(-ret));
8919         }
8920 }
8921
8922 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8923         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8924                                  rx_vlan, "rx_vlan");
8925 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8926         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8927                                  what, "add#rm");
8928 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8929         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8930                               vlan_id, RTE_UINT16);
8931 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8932         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8933                                  port, "port");
8934 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8935         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8936                               port_id, RTE_UINT16);
8937 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8938         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8939                                  vf, "vf");
8940 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8941         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8942                               vf_mask, RTE_UINT64);
8943
8944 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8945         .f = cmd_vf_rx_vlan_filter_parsed,
8946         .data = NULL,
8947         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8948                 "(vf_mask = hexadecimal VF mask)",
8949         .tokens = {
8950                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8951                 (void *)&cmd_vf_rx_vlan_filter_what,
8952                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8953                 (void *)&cmd_vf_rx_vlan_filter_port,
8954                 (void *)&cmd_vf_rx_vlan_filter_portid,
8955                 (void *)&cmd_vf_rx_vlan_filter_vf,
8956                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8957                 NULL,
8958         },
8959 };
8960
8961 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8962 struct cmd_queue_rate_limit_result {
8963         cmdline_fixed_string_t set;
8964         cmdline_fixed_string_t port;
8965         uint16_t port_num;
8966         cmdline_fixed_string_t queue;
8967         uint8_t queue_num;
8968         cmdline_fixed_string_t rate;
8969         uint16_t rate_num;
8970 };
8971
8972 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8973                 __rte_unused struct cmdline *cl,
8974                 __rte_unused void *data)
8975 {
8976         struct cmd_queue_rate_limit_result *res = parsed_result;
8977         int ret = 0;
8978
8979         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8980                 && (strcmp(res->queue, "queue") == 0)
8981                 && (strcmp(res->rate, "rate") == 0))
8982                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8983                                         res->rate_num);
8984         if (ret < 0)
8985                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8986
8987 }
8988
8989 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8990         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8991                                 set, "set");
8992 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8993         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8994                                 port, "port");
8995 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8996         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8997                                 port_num, RTE_UINT16);
8998 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8999         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9000                                 queue, "queue");
9001 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9002         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9003                                 queue_num, RTE_UINT8);
9004 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9005         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9006                                 rate, "rate");
9007 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9008         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9009                                 rate_num, RTE_UINT16);
9010
9011 cmdline_parse_inst_t cmd_queue_rate_limit = {
9012         .f = cmd_queue_rate_limit_parsed,
9013         .data = (void *)0,
9014         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9015                 "Set rate limit for a queue on port_id",
9016         .tokens = {
9017                 (void *)&cmd_queue_rate_limit_set,
9018                 (void *)&cmd_queue_rate_limit_port,
9019                 (void *)&cmd_queue_rate_limit_portnum,
9020                 (void *)&cmd_queue_rate_limit_queue,
9021                 (void *)&cmd_queue_rate_limit_queuenum,
9022                 (void *)&cmd_queue_rate_limit_rate,
9023                 (void *)&cmd_queue_rate_limit_ratenum,
9024                 NULL,
9025         },
9026 };
9027
9028 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9029 struct cmd_vf_rate_limit_result {
9030         cmdline_fixed_string_t set;
9031         cmdline_fixed_string_t port;
9032         uint16_t port_num;
9033         cmdline_fixed_string_t vf;
9034         uint8_t vf_num;
9035         cmdline_fixed_string_t rate;
9036         uint16_t rate_num;
9037         cmdline_fixed_string_t q_msk;
9038         uint64_t q_msk_val;
9039 };
9040
9041 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9042                 __rte_unused struct cmdline *cl,
9043                 __rte_unused void *data)
9044 {
9045         struct cmd_vf_rate_limit_result *res = parsed_result;
9046         int ret = 0;
9047
9048         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9049                 && (strcmp(res->vf, "vf") == 0)
9050                 && (strcmp(res->rate, "rate") == 0)
9051                 && (strcmp(res->q_msk, "queue_mask") == 0))
9052                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9053                                         res->rate_num, res->q_msk_val);
9054         if (ret < 0)
9055                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9056
9057 }
9058
9059 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9060         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9061                                 set, "set");
9062 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9063         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9064                                 port, "port");
9065 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9066         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9067                                 port_num, RTE_UINT16);
9068 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9069         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9070                                 vf, "vf");
9071 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9072         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9073                                 vf_num, RTE_UINT8);
9074 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9075         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9076                                 rate, "rate");
9077 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9078         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9079                                 rate_num, RTE_UINT16);
9080 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9081         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9082                                 q_msk, "queue_mask");
9083 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9084         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9085                                 q_msk_val, RTE_UINT64);
9086
9087 cmdline_parse_inst_t cmd_vf_rate_limit = {
9088         .f = cmd_vf_rate_limit_parsed,
9089         .data = (void *)0,
9090         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9091                 "queue_mask <queue_mask_value>: "
9092                 "Set rate limit for queues of VF on port_id",
9093         .tokens = {
9094                 (void *)&cmd_vf_rate_limit_set,
9095                 (void *)&cmd_vf_rate_limit_port,
9096                 (void *)&cmd_vf_rate_limit_portnum,
9097                 (void *)&cmd_vf_rate_limit_vf,
9098                 (void *)&cmd_vf_rate_limit_vfnum,
9099                 (void *)&cmd_vf_rate_limit_rate,
9100                 (void *)&cmd_vf_rate_limit_ratenum,
9101                 (void *)&cmd_vf_rate_limit_q_msk,
9102                 (void *)&cmd_vf_rate_limit_q_msk_val,
9103                 NULL,
9104         },
9105 };
9106
9107 /* *** CONFIGURE TUNNEL UDP PORT *** */
9108 struct cmd_tunnel_udp_config {
9109         cmdline_fixed_string_t rx_vxlan_port;
9110         cmdline_fixed_string_t what;
9111         uint16_t udp_port;
9112         portid_t port_id;
9113 };
9114
9115 static void
9116 cmd_tunnel_udp_config_parsed(void *parsed_result,
9117                           __rte_unused struct cmdline *cl,
9118                           __rte_unused void *data)
9119 {
9120         struct cmd_tunnel_udp_config *res = parsed_result;
9121         struct rte_eth_udp_tunnel tunnel_udp;
9122         int ret;
9123
9124         tunnel_udp.udp_port = res->udp_port;
9125         tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9126
9127         if (!strcmp(res->what, "add"))
9128                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9129                                                       &tunnel_udp);
9130         else
9131                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9132                                                          &tunnel_udp);
9133
9134         if (ret < 0)
9135                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9136 }
9137
9138 cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9139         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9140                                 rx_vxlan_port, "rx_vxlan_port");
9141 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9142         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9143                                 what, "add#rm");
9144 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9145         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9146                                 udp_port, RTE_UINT16);
9147 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9148         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9149                                 port_id, RTE_UINT16);
9150
9151 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9152         .f = cmd_tunnel_udp_config_parsed,
9153         .data = (void *)0,
9154         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9155                 "Add/Remove a tunneling UDP port filter",
9156         .tokens = {
9157                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9158                 (void *)&cmd_tunnel_udp_config_what,
9159                 (void *)&cmd_tunnel_udp_config_udp_port,
9160                 (void *)&cmd_tunnel_udp_config_port_id,
9161                 NULL,
9162         },
9163 };
9164
9165 struct cmd_config_tunnel_udp_port {
9166         cmdline_fixed_string_t port;
9167         cmdline_fixed_string_t config;
9168         portid_t port_id;
9169         cmdline_fixed_string_t udp_tunnel_port;
9170         cmdline_fixed_string_t action;
9171         cmdline_fixed_string_t tunnel_type;
9172         uint16_t udp_port;
9173 };
9174
9175 static void
9176 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9177                                __rte_unused struct cmdline *cl,
9178                                __rte_unused void *data)
9179 {
9180         struct cmd_config_tunnel_udp_port *res = parsed_result;
9181         struct rte_eth_udp_tunnel tunnel_udp;
9182         int ret = 0;
9183
9184         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9185                 return;
9186
9187         tunnel_udp.udp_port = res->udp_port;
9188
9189         if (!strcmp(res->tunnel_type, "vxlan")) {
9190                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9191         } else if (!strcmp(res->tunnel_type, "geneve")) {
9192                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9193         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9194                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9195         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9196                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_ECPRI;
9197         } else {
9198                 printf("Invalid tunnel type\n");
9199                 return;
9200         }
9201
9202         if (!strcmp(res->action, "add"))
9203                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9204                                                       &tunnel_udp);
9205         else
9206                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9207                                                          &tunnel_udp);
9208
9209         if (ret < 0)
9210                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9211 }
9212
9213 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9214         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9215                                  "port");
9216 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9217         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9218                                  "config");
9219 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9220         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9221                               RTE_UINT16);
9222 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9223         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9224                                  udp_tunnel_port,
9225                                  "udp_tunnel_port");
9226 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9227         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9228                                  "add#rm");
9229 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9230         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9231                                  "vxlan#geneve#vxlan-gpe#ecpri");
9232 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9233         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9234                               RTE_UINT16);
9235
9236 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9237         .f = cmd_cfg_tunnel_udp_port_parsed,
9238         .data = NULL,
9239         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9240                 "geneve|vxlan-gpe|ecpri <udp_port>",
9241         .tokens = {
9242                 (void *)&cmd_config_tunnel_udp_port_port,
9243                 (void *)&cmd_config_tunnel_udp_port_config,
9244                 (void *)&cmd_config_tunnel_udp_port_port_id,
9245                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9246                 (void *)&cmd_config_tunnel_udp_port_action,
9247                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9248                 (void *)&cmd_config_tunnel_udp_port_value,
9249                 NULL,
9250         },
9251 };
9252
9253 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9254 struct cmd_set_mirror_mask_result {
9255         cmdline_fixed_string_t set;
9256         cmdline_fixed_string_t port;
9257         portid_t port_id;
9258         cmdline_fixed_string_t mirror;
9259         uint8_t rule_id;
9260         cmdline_fixed_string_t what;
9261         cmdline_fixed_string_t value;
9262         cmdline_fixed_string_t dstpool;
9263         uint8_t dstpool_id;
9264         cmdline_fixed_string_t on;
9265 };
9266
9267 cmdline_parse_token_string_t cmd_mirror_mask_set =
9268         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9269                                 set, "set");
9270 cmdline_parse_token_string_t cmd_mirror_mask_port =
9271         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9272                                 port, "port");
9273 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9274         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9275                                 port_id, RTE_UINT16);
9276 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9277         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9278                                 mirror, "mirror-rule");
9279 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9280         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9281                                 rule_id, RTE_UINT8);
9282 cmdline_parse_token_string_t cmd_mirror_mask_what =
9283         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9284                                 what, "pool-mirror-up#pool-mirror-down"
9285                                       "#vlan-mirror");
9286 cmdline_parse_token_string_t cmd_mirror_mask_value =
9287         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9288                                 value, NULL);
9289 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9290         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9291                                 dstpool, "dst-pool");
9292 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9293         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9294                                 dstpool_id, RTE_UINT8);
9295 cmdline_parse_token_string_t cmd_mirror_mask_on =
9296         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9297                                 on, "on#off");
9298
9299 static void
9300 cmd_set_mirror_mask_parsed(void *parsed_result,
9301                        __rte_unused struct cmdline *cl,
9302                        __rte_unused void *data)
9303 {
9304         int ret,nb_item,i;
9305         struct cmd_set_mirror_mask_result *res = parsed_result;
9306         struct rte_eth_mirror_conf mr_conf;
9307
9308         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9309
9310         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9311
9312         mr_conf.dst_pool = res->dstpool_id;
9313
9314         if (!strcmp(res->what, "pool-mirror-up")) {
9315                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9316                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9317         } else if (!strcmp(res->what, "pool-mirror-down")) {
9318                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9319                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9320         } else if (!strcmp(res->what, "vlan-mirror")) {
9321                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9322                 nb_item = parse_item_list(res->value, "vlan",
9323                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9324                 if (nb_item <= 0)
9325                         return;
9326
9327                 for (i = 0; i < nb_item; i++) {
9328                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9329                                 printf("Invalid vlan_id: must be < 4096\n");
9330                                 return;
9331                         }
9332
9333                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9334                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9335                 }
9336         }
9337
9338         if (!strcmp(res->on, "on"))
9339                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9340                                                 res->rule_id, 1);
9341         else
9342                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9343                                                 res->rule_id, 0);
9344         if (ret < 0)
9345                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9346 }
9347
9348 cmdline_parse_inst_t cmd_set_mirror_mask = {
9349                 .f = cmd_set_mirror_mask_parsed,
9350                 .data = NULL,
9351                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9352                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9353                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9354                 .tokens = {
9355                         (void *)&cmd_mirror_mask_set,
9356                         (void *)&cmd_mirror_mask_port,
9357                         (void *)&cmd_mirror_mask_portid,
9358                         (void *)&cmd_mirror_mask_mirror,
9359                         (void *)&cmd_mirror_mask_ruleid,
9360                         (void *)&cmd_mirror_mask_what,
9361                         (void *)&cmd_mirror_mask_value,
9362                         (void *)&cmd_mirror_mask_dstpool,
9363                         (void *)&cmd_mirror_mask_poolid,
9364                         (void *)&cmd_mirror_mask_on,
9365                         NULL,
9366                 },
9367 };
9368
9369 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9370 struct cmd_set_mirror_link_result {
9371         cmdline_fixed_string_t set;
9372         cmdline_fixed_string_t port;
9373         portid_t port_id;
9374         cmdline_fixed_string_t mirror;
9375         uint8_t rule_id;
9376         cmdline_fixed_string_t what;
9377         cmdline_fixed_string_t dstpool;
9378         uint8_t dstpool_id;
9379         cmdline_fixed_string_t on;
9380 };
9381
9382 cmdline_parse_token_string_t cmd_mirror_link_set =
9383         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9384                                  set, "set");
9385 cmdline_parse_token_string_t cmd_mirror_link_port =
9386         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9387                                 port, "port");
9388 cmdline_parse_token_num_t cmd_mirror_link_portid =
9389         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9390                                 port_id, RTE_UINT16);
9391 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9392         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9393                                 mirror, "mirror-rule");
9394 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9395         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9396                             rule_id, RTE_UINT8);
9397 cmdline_parse_token_string_t cmd_mirror_link_what =
9398         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9399                                 what, "uplink-mirror#downlink-mirror");
9400 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9401         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9402                                 dstpool, "dst-pool");
9403 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9404         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9405                                 dstpool_id, RTE_UINT8);
9406 cmdline_parse_token_string_t cmd_mirror_link_on =
9407         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9408                                 on, "on#off");
9409
9410 static void
9411 cmd_set_mirror_link_parsed(void *parsed_result,
9412                        __rte_unused struct cmdline *cl,
9413                        __rte_unused void *data)
9414 {
9415         int ret;
9416         struct cmd_set_mirror_link_result *res = parsed_result;
9417         struct rte_eth_mirror_conf mr_conf;
9418
9419         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9420         if (!strcmp(res->what, "uplink-mirror"))
9421                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9422         else
9423                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9424
9425         mr_conf.dst_pool = res->dstpool_id;
9426
9427         if (!strcmp(res->on, "on"))
9428                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9429                                                 res->rule_id, 1);
9430         else
9431                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9432                                                 res->rule_id, 0);
9433
9434         /* check the return value and print it if is < 0 */
9435         if (ret < 0)
9436                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9437
9438 }
9439
9440 cmdline_parse_inst_t cmd_set_mirror_link = {
9441                 .f = cmd_set_mirror_link_parsed,
9442                 .data = NULL,
9443                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9444                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9445                 .tokens = {
9446                         (void *)&cmd_mirror_link_set,
9447                         (void *)&cmd_mirror_link_port,
9448                         (void *)&cmd_mirror_link_portid,
9449                         (void *)&cmd_mirror_link_mirror,
9450                         (void *)&cmd_mirror_link_ruleid,
9451                         (void *)&cmd_mirror_link_what,
9452                         (void *)&cmd_mirror_link_dstpool,
9453                         (void *)&cmd_mirror_link_poolid,
9454                         (void *)&cmd_mirror_link_on,
9455                         NULL,
9456                 },
9457 };
9458
9459 /* *** RESET VM MIRROR RULE *** */
9460 struct cmd_rm_mirror_rule_result {
9461         cmdline_fixed_string_t reset;
9462         cmdline_fixed_string_t port;
9463         portid_t port_id;
9464         cmdline_fixed_string_t mirror;
9465         uint8_t rule_id;
9466 };
9467
9468 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9469         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9470                                  reset, "reset");
9471 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9472         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9473                                 port, "port");
9474 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9475         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9476                                 port_id, RTE_UINT16);
9477 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9478         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9479                                 mirror, "mirror-rule");
9480 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9481         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9482                                 rule_id, RTE_UINT8);
9483
9484 static void
9485 cmd_reset_mirror_rule_parsed(void *parsed_result,
9486                        __rte_unused struct cmdline *cl,
9487                        __rte_unused void *data)
9488 {
9489         int ret;
9490         struct cmd_set_mirror_link_result *res = parsed_result;
9491         /* check rule_id */
9492         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9493         if(ret < 0)
9494                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9495 }
9496
9497 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9498                 .f = cmd_reset_mirror_rule_parsed,
9499                 .data = NULL,
9500                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9501                 .tokens = {
9502                         (void *)&cmd_rm_mirror_rule_reset,
9503                         (void *)&cmd_rm_mirror_rule_port,
9504                         (void *)&cmd_rm_mirror_rule_portid,
9505                         (void *)&cmd_rm_mirror_rule_mirror,
9506                         (void *)&cmd_rm_mirror_rule_ruleid,
9507                         NULL,
9508                 },
9509 };
9510
9511 /* ******************************************************************************** */
9512
9513 struct cmd_dump_result {
9514         cmdline_fixed_string_t dump;
9515 };
9516
9517 static void
9518 dump_struct_sizes(void)
9519 {
9520 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9521         DUMP_SIZE(struct rte_mbuf);
9522         DUMP_SIZE(struct rte_mempool);
9523         DUMP_SIZE(struct rte_ring);
9524 #undef DUMP_SIZE
9525 }
9526
9527
9528 /* Dump the socket memory statistics on console */
9529 static void
9530 dump_socket_mem(FILE *f)
9531 {
9532         struct rte_malloc_socket_stats socket_stats;
9533         unsigned int i;
9534         size_t total = 0;
9535         size_t alloc = 0;
9536         size_t free = 0;
9537         unsigned int n_alloc = 0;
9538         unsigned int n_free = 0;
9539         static size_t last_allocs;
9540         static size_t last_total;
9541
9542
9543         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9544                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9545                     !socket_stats.heap_totalsz_bytes)
9546                         continue;
9547                 total += socket_stats.heap_totalsz_bytes;
9548                 alloc += socket_stats.heap_allocsz_bytes;
9549                 free += socket_stats.heap_freesz_bytes;
9550                 n_alloc += socket_stats.alloc_count;
9551                 n_free += socket_stats.free_count;
9552                 fprintf(f,
9553                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9554                         i,
9555                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9556                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9557                         (double)socket_stats.heap_allocsz_bytes * 100 /
9558                         (double)socket_stats.heap_totalsz_bytes,
9559                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9560                         socket_stats.alloc_count,
9561                         socket_stats.free_count);
9562         }
9563         fprintf(f,
9564                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9565                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9566                 (double)alloc * 100 / (double)total,
9567                 (double)free / (1024 * 1024),
9568                 n_alloc, n_free);
9569         if (last_allocs)
9570                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9571                         ((double)total - (double)last_total) / (1024 * 1024),
9572                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9573         last_allocs = alloc;
9574         last_total = total;
9575 }
9576
9577 static void cmd_dump_parsed(void *parsed_result,
9578                             __rte_unused struct cmdline *cl,
9579                             __rte_unused void *data)
9580 {
9581         struct cmd_dump_result *res = parsed_result;
9582
9583         if (!strcmp(res->dump, "dump_physmem"))
9584                 rte_dump_physmem_layout(stdout);
9585         else if (!strcmp(res->dump, "dump_socket_mem"))
9586                 dump_socket_mem(stdout);
9587         else if (!strcmp(res->dump, "dump_memzone"))
9588                 rte_memzone_dump(stdout);
9589         else if (!strcmp(res->dump, "dump_struct_sizes"))
9590                 dump_struct_sizes();
9591         else if (!strcmp(res->dump, "dump_ring"))
9592                 rte_ring_list_dump(stdout);
9593         else if (!strcmp(res->dump, "dump_mempool"))
9594                 rte_mempool_list_dump(stdout);
9595         else if (!strcmp(res->dump, "dump_devargs"))
9596                 rte_devargs_dump(stdout);
9597         else if (!strcmp(res->dump, "dump_log_types"))
9598                 rte_log_dump(stdout);
9599 }
9600
9601 cmdline_parse_token_string_t cmd_dump_dump =
9602         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9603                 "dump_physmem#"
9604                 "dump_memzone#"
9605                 "dump_socket_mem#"
9606                 "dump_struct_sizes#"
9607                 "dump_ring#"
9608                 "dump_mempool#"
9609                 "dump_devargs#"
9610                 "dump_log_types");
9611
9612 cmdline_parse_inst_t cmd_dump = {
9613         .f = cmd_dump_parsed,  /* function to call */
9614         .data = NULL,      /* 2nd arg of func */
9615         .help_str = "Dump status",
9616         .tokens = {        /* token list, NULL terminated */
9617                 (void *)&cmd_dump_dump,
9618                 NULL,
9619         },
9620 };
9621
9622 /* ******************************************************************************** */
9623
9624 struct cmd_dump_one_result {
9625         cmdline_fixed_string_t dump;
9626         cmdline_fixed_string_t name;
9627 };
9628
9629 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9630                                 __rte_unused void *data)
9631 {
9632         struct cmd_dump_one_result *res = parsed_result;
9633
9634         if (!strcmp(res->dump, "dump_ring")) {
9635                 struct rte_ring *r;
9636                 r = rte_ring_lookup(res->name);
9637                 if (r == NULL) {
9638                         cmdline_printf(cl, "Cannot find ring\n");
9639                         return;
9640                 }
9641                 rte_ring_dump(stdout, r);
9642         } else if (!strcmp(res->dump, "dump_mempool")) {
9643                 struct rte_mempool *mp;
9644                 mp = rte_mempool_lookup(res->name);
9645                 if (mp == NULL) {
9646                         cmdline_printf(cl, "Cannot find mempool\n");
9647                         return;
9648                 }
9649                 rte_mempool_dump(stdout, mp);
9650         }
9651 }
9652
9653 cmdline_parse_token_string_t cmd_dump_one_dump =
9654         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9655                                  "dump_ring#dump_mempool");
9656
9657 cmdline_parse_token_string_t cmd_dump_one_name =
9658         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9659
9660 cmdline_parse_inst_t cmd_dump_one = {
9661         .f = cmd_dump_one_parsed,  /* function to call */
9662         .data = NULL,      /* 2nd arg of func */
9663         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9664         .tokens = {        /* token list, NULL terminated */
9665                 (void *)&cmd_dump_one_dump,
9666                 (void *)&cmd_dump_one_name,
9667                 NULL,
9668         },
9669 };
9670
9671 /* *** queue region set *** */
9672 struct cmd_queue_region_result {
9673         cmdline_fixed_string_t set;
9674         cmdline_fixed_string_t port;
9675         portid_t port_id;
9676         cmdline_fixed_string_t cmd;
9677         cmdline_fixed_string_t region;
9678         uint8_t  region_id;
9679         cmdline_fixed_string_t queue_start_index;
9680         uint8_t  queue_id;
9681         cmdline_fixed_string_t queue_num;
9682         uint8_t  queue_num_value;
9683 };
9684
9685 static void
9686 cmd_queue_region_parsed(void *parsed_result,
9687                         __rte_unused struct cmdline *cl,
9688                         __rte_unused void *data)
9689 {
9690         struct cmd_queue_region_result *res = parsed_result;
9691         int ret = -ENOTSUP;
9692 #ifdef RTE_NET_I40E
9693         struct rte_pmd_i40e_queue_region_conf region_conf;
9694         enum rte_pmd_i40e_queue_region_op op_type;
9695 #endif
9696
9697         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9698                 return;
9699
9700 #ifdef RTE_NET_I40E
9701         memset(&region_conf, 0, sizeof(region_conf));
9702         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9703         region_conf.region_id = res->region_id;
9704         region_conf.queue_num = res->queue_num_value;
9705         region_conf.queue_start_index = res->queue_id;
9706
9707         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9708                                 op_type, &region_conf);
9709 #endif
9710
9711         switch (ret) {
9712         case 0:
9713                 break;
9714         case -ENOTSUP:
9715                 printf("function not implemented or supported\n");
9716                 break;
9717         default:
9718                 printf("queue region config error: (%s)\n", strerror(-ret));
9719         }
9720 }
9721
9722 cmdline_parse_token_string_t cmd_queue_region_set =
9723 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9724                 set, "set");
9725 cmdline_parse_token_string_t cmd_queue_region_port =
9726         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9727 cmdline_parse_token_num_t cmd_queue_region_port_id =
9728         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9729                                 port_id, RTE_UINT16);
9730 cmdline_parse_token_string_t cmd_queue_region_cmd =
9731         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9732                                  cmd, "queue-region");
9733 cmdline_parse_token_string_t cmd_queue_region_id =
9734         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9735                                 region, "region_id");
9736 cmdline_parse_token_num_t cmd_queue_region_index =
9737         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9738                                 region_id, RTE_UINT8);
9739 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9740         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9741                                 queue_start_index, "queue_start_index");
9742 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9743         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9744                                 queue_id, RTE_UINT8);
9745 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9746         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9747                                 queue_num, "queue_num");
9748 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9749         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9750                                 queue_num_value, RTE_UINT8);
9751
9752 cmdline_parse_inst_t cmd_queue_region = {
9753         .f = cmd_queue_region_parsed,
9754         .data = NULL,
9755         .help_str = "set port <port_id> queue-region region_id <value> "
9756                 "queue_start_index <value> queue_num <value>: Set a queue region",
9757         .tokens = {
9758                 (void *)&cmd_queue_region_set,
9759                 (void *)&cmd_queue_region_port,
9760                 (void *)&cmd_queue_region_port_id,
9761                 (void *)&cmd_queue_region_cmd,
9762                 (void *)&cmd_queue_region_id,
9763                 (void *)&cmd_queue_region_index,
9764                 (void *)&cmd_queue_region_queue_start_index,
9765                 (void *)&cmd_queue_region_queue_id,
9766                 (void *)&cmd_queue_region_queue_num,
9767                 (void *)&cmd_queue_region_queue_num_value,
9768                 NULL,
9769         },
9770 };
9771
9772 /* *** queue region and flowtype set *** */
9773 struct cmd_region_flowtype_result {
9774         cmdline_fixed_string_t set;
9775         cmdline_fixed_string_t port;
9776         portid_t port_id;
9777         cmdline_fixed_string_t cmd;
9778         cmdline_fixed_string_t region;
9779         uint8_t  region_id;
9780         cmdline_fixed_string_t flowtype;
9781         uint8_t  flowtype_id;
9782 };
9783
9784 static void
9785 cmd_region_flowtype_parsed(void *parsed_result,
9786                         __rte_unused struct cmdline *cl,
9787                         __rte_unused void *data)
9788 {
9789         struct cmd_region_flowtype_result *res = parsed_result;
9790         int ret = -ENOTSUP;
9791 #ifdef RTE_NET_I40E
9792         struct rte_pmd_i40e_queue_region_conf region_conf;
9793         enum rte_pmd_i40e_queue_region_op op_type;
9794 #endif
9795
9796         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9797                 return;
9798
9799 #ifdef RTE_NET_I40E
9800         memset(&region_conf, 0, sizeof(region_conf));
9801
9802         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9803         region_conf.region_id = res->region_id;
9804         region_conf.hw_flowtype = res->flowtype_id;
9805
9806         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9807                         op_type, &region_conf);
9808 #endif
9809
9810         switch (ret) {
9811         case 0:
9812                 break;
9813         case -ENOTSUP:
9814                 printf("function not implemented or supported\n");
9815                 break;
9816         default:
9817                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9818         }
9819 }
9820
9821 cmdline_parse_token_string_t cmd_region_flowtype_set =
9822 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9823                                 set, "set");
9824 cmdline_parse_token_string_t cmd_region_flowtype_port =
9825         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9826                                 port, "port");
9827 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9828         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9829                                 port_id, RTE_UINT16);
9830 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9831         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9832                                 cmd, "queue-region");
9833 cmdline_parse_token_string_t cmd_region_flowtype_index =
9834         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9835                                 region, "region_id");
9836 cmdline_parse_token_num_t cmd_region_flowtype_id =
9837         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9838                                 region_id, RTE_UINT8);
9839 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9840         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9841                                 flowtype, "flowtype");
9842 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9843         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9844                                 flowtype_id, RTE_UINT8);
9845 cmdline_parse_inst_t cmd_region_flowtype = {
9846         .f = cmd_region_flowtype_parsed,
9847         .data = NULL,
9848         .help_str = "set port <port_id> queue-region region_id <value> "
9849                 "flowtype <value>: Set a flowtype region index",
9850         .tokens = {
9851                 (void *)&cmd_region_flowtype_set,
9852                 (void *)&cmd_region_flowtype_port,
9853                 (void *)&cmd_region_flowtype_port_index,
9854                 (void *)&cmd_region_flowtype_cmd,
9855                 (void *)&cmd_region_flowtype_index,
9856                 (void *)&cmd_region_flowtype_id,
9857                 (void *)&cmd_region_flowtype_flow_index,
9858                 (void *)&cmd_region_flowtype_flow_id,
9859                 NULL,
9860         },
9861 };
9862
9863 /* *** User Priority (UP) to queue region (region_id) set *** */
9864 struct cmd_user_priority_region_result {
9865         cmdline_fixed_string_t set;
9866         cmdline_fixed_string_t port;
9867         portid_t port_id;
9868         cmdline_fixed_string_t cmd;
9869         cmdline_fixed_string_t user_priority;
9870         uint8_t  user_priority_id;
9871         cmdline_fixed_string_t region;
9872         uint8_t  region_id;
9873 };
9874
9875 static void
9876 cmd_user_priority_region_parsed(void *parsed_result,
9877                         __rte_unused struct cmdline *cl,
9878                         __rte_unused void *data)
9879 {
9880         struct cmd_user_priority_region_result *res = parsed_result;
9881         int ret = -ENOTSUP;
9882 #ifdef RTE_NET_I40E
9883         struct rte_pmd_i40e_queue_region_conf region_conf;
9884         enum rte_pmd_i40e_queue_region_op op_type;
9885 #endif
9886
9887         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9888                 return;
9889
9890 #ifdef RTE_NET_I40E
9891         memset(&region_conf, 0, sizeof(region_conf));
9892         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9893         region_conf.user_priority = res->user_priority_id;
9894         region_conf.region_id = res->region_id;
9895
9896         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9897                                 op_type, &region_conf);
9898 #endif
9899
9900         switch (ret) {
9901         case 0:
9902                 break;
9903         case -ENOTSUP:
9904                 printf("function not implemented or supported\n");
9905                 break;
9906         default:
9907                 printf("user_priority region config error: (%s)\n",
9908                                 strerror(-ret));
9909         }
9910 }
9911
9912 cmdline_parse_token_string_t cmd_user_priority_region_set =
9913         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9914                                 set, "set");
9915 cmdline_parse_token_string_t cmd_user_priority_region_port =
9916         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9917                                 port, "port");
9918 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9919         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9920                                 port_id, RTE_UINT16);
9921 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9922         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9923                                 cmd, "queue-region");
9924 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9925         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9926                                 user_priority, "UP");
9927 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9928         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9929                                 user_priority_id, RTE_UINT8);
9930 cmdline_parse_token_string_t cmd_user_priority_region_region =
9931         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9932                                 region, "region_id");
9933 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9934         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9935                                 region_id, RTE_UINT8);
9936
9937 cmdline_parse_inst_t cmd_user_priority_region = {
9938         .f = cmd_user_priority_region_parsed,
9939         .data = NULL,
9940         .help_str = "set port <port_id> queue-region UP <value> "
9941                 "region_id <value>: Set the mapping of User Priority (UP) "
9942                 "to queue region (region_id) ",
9943         .tokens = {
9944                 (void *)&cmd_user_priority_region_set,
9945                 (void *)&cmd_user_priority_region_port,
9946                 (void *)&cmd_user_priority_region_port_index,
9947                 (void *)&cmd_user_priority_region_cmd,
9948                 (void *)&cmd_user_priority_region_UP,
9949                 (void *)&cmd_user_priority_region_UP_id,
9950                 (void *)&cmd_user_priority_region_region,
9951                 (void *)&cmd_user_priority_region_region_id,
9952                 NULL,
9953         },
9954 };
9955
9956 /* *** flush all queue region related configuration *** */
9957 struct cmd_flush_queue_region_result {
9958         cmdline_fixed_string_t set;
9959         cmdline_fixed_string_t port;
9960         portid_t port_id;
9961         cmdline_fixed_string_t cmd;
9962         cmdline_fixed_string_t flush;
9963         cmdline_fixed_string_t what;
9964 };
9965
9966 static void
9967 cmd_flush_queue_region_parsed(void *parsed_result,
9968                         __rte_unused struct cmdline *cl,
9969                         __rte_unused void *data)
9970 {
9971         struct cmd_flush_queue_region_result *res = parsed_result;
9972         int ret = -ENOTSUP;
9973 #ifdef RTE_NET_I40E
9974         struct rte_pmd_i40e_queue_region_conf region_conf;
9975         enum rte_pmd_i40e_queue_region_op op_type;
9976 #endif
9977
9978         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9979                 return;
9980
9981 #ifdef RTE_NET_I40E
9982         memset(&region_conf, 0, sizeof(region_conf));
9983
9984         if (strcmp(res->what, "on") == 0)
9985                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9986         else
9987                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9988
9989         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9990                                 op_type, &region_conf);
9991 #endif
9992
9993         switch (ret) {
9994         case 0:
9995                 break;
9996         case -ENOTSUP:
9997                 printf("function not implemented or supported\n");
9998                 break;
9999         default:
10000                 printf("queue region config flush error: (%s)\n",
10001                                 strerror(-ret));
10002         }
10003 }
10004
10005 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10006         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10007                                 set, "set");
10008 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10009         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10010                                 port, "port");
10011 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10012         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10013                                 port_id, RTE_UINT16);
10014 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10015         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10016                                 cmd, "queue-region");
10017 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10018         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10019                                 flush, "flush");
10020 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10021         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10022                                 what, "on#off");
10023
10024 cmdline_parse_inst_t cmd_flush_queue_region = {
10025         .f = cmd_flush_queue_region_parsed,
10026         .data = NULL,
10027         .help_str = "set port <port_id> queue-region flush on|off"
10028                 ": flush all queue region related configuration",
10029         .tokens = {
10030                 (void *)&cmd_flush_queue_region_set,
10031                 (void *)&cmd_flush_queue_region_port,
10032                 (void *)&cmd_flush_queue_region_port_index,
10033                 (void *)&cmd_flush_queue_region_cmd,
10034                 (void *)&cmd_flush_queue_region_flush,
10035                 (void *)&cmd_flush_queue_region_what,
10036                 NULL,
10037         },
10038 };
10039
10040 /* *** get all queue region related configuration info *** */
10041 struct cmd_show_queue_region_info {
10042         cmdline_fixed_string_t show;
10043         cmdline_fixed_string_t port;
10044         portid_t port_id;
10045         cmdline_fixed_string_t cmd;
10046 };
10047
10048 static void
10049 cmd_show_queue_region_info_parsed(void *parsed_result,
10050                         __rte_unused struct cmdline *cl,
10051                         __rte_unused void *data)
10052 {
10053         struct cmd_show_queue_region_info *res = parsed_result;
10054         int ret = -ENOTSUP;
10055 #ifdef RTE_NET_I40E
10056         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10057         enum rte_pmd_i40e_queue_region_op op_type;
10058 #endif
10059
10060         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10061                 return;
10062
10063 #ifdef RTE_NET_I40E
10064         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10065
10066         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10067
10068         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10069                                         op_type, &rte_pmd_regions);
10070
10071         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10072 #endif
10073
10074         switch (ret) {
10075         case 0:
10076                 break;
10077         case -ENOTSUP:
10078                 printf("function not implemented or supported\n");
10079                 break;
10080         default:
10081                 printf("queue region config info show error: (%s)\n",
10082                                 strerror(-ret));
10083         }
10084 }
10085
10086 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10087 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10088                                 show, "show");
10089 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10090         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10091                                 port, "port");
10092 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10093         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10094                                 port_id, RTE_UINT16);
10095 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10096         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10097                                 cmd, "queue-region");
10098
10099 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10100         .f = cmd_show_queue_region_info_parsed,
10101         .data = NULL,
10102         .help_str = "show port <port_id> queue-region"
10103                 ": show all queue region related configuration info",
10104         .tokens = {
10105                 (void *)&cmd_show_queue_region_info_get,
10106                 (void *)&cmd_show_queue_region_info_port,
10107                 (void *)&cmd_show_queue_region_info_port_index,
10108                 (void *)&cmd_show_queue_region_info_cmd,
10109                 NULL,
10110         },
10111 };
10112
10113 /* *** Filters Control *** */
10114
10115 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10116 do { \
10117         if ((ip_addr).family == AF_INET) \
10118                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10119         else { \
10120                 printf("invalid parameter.\n"); \
10121                 return; \
10122         } \
10123 } while (0)
10124
10125 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10126 do { \
10127         if ((ip_addr).family == AF_INET6) \
10128                 rte_memcpy(&(ip), \
10129                                  &((ip_addr).addr.ipv6), \
10130                                  sizeof(struct in6_addr)); \
10131         else { \
10132                 printf("invalid parameter.\n"); \
10133                 return; \
10134         } \
10135 } while (0)
10136
10137 #ifdef RTE_NET_I40E
10138
10139 static uint16_t
10140 str2flowtype(char *string)
10141 {
10142         uint8_t i = 0;
10143         static const struct {
10144                 char str[32];
10145                 uint16_t type;
10146         } flowtype_str[] = {
10147                 {"raw", RTE_ETH_FLOW_RAW},
10148                 {"ipv4", RTE_ETH_FLOW_IPV4},
10149                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10150                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10151                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10152                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10153                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10154                 {"ipv6", RTE_ETH_FLOW_IPV6},
10155                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10156                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10157                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10158                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10159                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10160                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10161         };
10162
10163         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10164                 if (!strcmp(flowtype_str[i].str, string))
10165                         return flowtype_str[i].type;
10166         }
10167
10168         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10169                 return (uint16_t)atoi(string);
10170
10171         return RTE_ETH_FLOW_UNKNOWN;
10172 }
10173
10174 /* *** deal with flow director filter *** */
10175 struct cmd_flow_director_result {
10176         cmdline_fixed_string_t flow_director_filter;
10177         portid_t port_id;
10178         cmdline_fixed_string_t mode;
10179         cmdline_fixed_string_t mode_value;
10180         cmdline_fixed_string_t ops;
10181         cmdline_fixed_string_t flow;
10182         cmdline_fixed_string_t flow_type;
10183         cmdline_fixed_string_t drop;
10184         cmdline_fixed_string_t queue;
10185         uint16_t  queue_id;
10186         cmdline_fixed_string_t fd_id;
10187         uint32_t  fd_id_value;
10188         cmdline_fixed_string_t packet;
10189         char filepath[];
10190 };
10191
10192 static void
10193 cmd_flow_director_filter_parsed(void *parsed_result,
10194                           __rte_unused struct cmdline *cl,
10195                           __rte_unused void *data)
10196 {
10197         struct cmd_flow_director_result *res = parsed_result;
10198         int ret = 0;
10199         struct rte_pmd_i40e_flow_type_mapping
10200                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10201         struct rte_pmd_i40e_pkt_template_conf conf;
10202         uint16_t flow_type = str2flowtype(res->flow_type);
10203         uint16_t i, port = res->port_id;
10204         uint8_t add;
10205
10206         memset(&conf, 0, sizeof(conf));
10207
10208         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10209                 printf("Invalid flow type specified.\n");
10210                 return;
10211         }
10212         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10213                                                  mapping);
10214         if (ret)
10215                 return;
10216         if (mapping[flow_type].pctype == 0ULL) {
10217                 printf("Invalid flow type specified.\n");
10218                 return;
10219         }
10220         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10221                 if (mapping[flow_type].pctype & (1ULL << i)) {
10222                         conf.input.pctype = i;
10223                         break;
10224                 }
10225         }
10226
10227         conf.input.packet = open_file(res->filepath,
10228                                 &conf.input.length);
10229         if (!conf.input.packet)
10230                 return;
10231         if (!strcmp(res->drop, "drop"))
10232                 conf.action.behavior =
10233                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10234         else
10235                 conf.action.behavior =
10236                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10237         conf.action.report_status =
10238                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10239         conf.action.rx_queue = res->queue_id;
10240         conf.soft_id = res->fd_id_value;
10241         add  = strcmp(res->ops, "del") ? 1 : 0;
10242         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10243                                                         &conf,
10244                                                         add);
10245         if (ret < 0)
10246                 printf("flow director config error: (%s)\n",
10247                        strerror(-ret));
10248         close_file(conf.input.packet);
10249 }
10250
10251 cmdline_parse_token_string_t cmd_flow_director_filter =
10252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10253                                  flow_director_filter, "flow_director_filter");
10254 cmdline_parse_token_num_t cmd_flow_director_port_id =
10255         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10256                               port_id, RTE_UINT16);
10257 cmdline_parse_token_string_t cmd_flow_director_ops =
10258         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10259                                  ops, "add#del#update");
10260 cmdline_parse_token_string_t cmd_flow_director_flow =
10261         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10262                                  flow, "flow");
10263 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10264         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10265                 flow_type, NULL);
10266 cmdline_parse_token_string_t cmd_flow_director_drop =
10267         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10268                                  drop, "drop#fwd");
10269 cmdline_parse_token_string_t cmd_flow_director_queue =
10270         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10271                                  queue, "queue");
10272 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10273         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10274                               queue_id, RTE_UINT16);
10275 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10276         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10277                                  fd_id, "fd_id");
10278 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10279         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10280                               fd_id_value, RTE_UINT32);
10281
10282 cmdline_parse_token_string_t cmd_flow_director_mode =
10283         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10284                                  mode, "mode");
10285 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10286         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10287                                  mode_value, "raw");
10288 cmdline_parse_token_string_t cmd_flow_director_packet =
10289         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10290                                  packet, "packet");
10291 cmdline_parse_token_string_t cmd_flow_director_filepath =
10292         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10293                                  filepath, NULL);
10294
10295 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10296         .f = cmd_flow_director_filter_parsed,
10297         .data = NULL,
10298         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10299                 "director entry on NIC",
10300         .tokens = {
10301                 (void *)&cmd_flow_director_filter,
10302                 (void *)&cmd_flow_director_port_id,
10303                 (void *)&cmd_flow_director_mode,
10304                 (void *)&cmd_flow_director_mode_raw,
10305                 (void *)&cmd_flow_director_ops,
10306                 (void *)&cmd_flow_director_flow,
10307                 (void *)&cmd_flow_director_flow_type,
10308                 (void *)&cmd_flow_director_drop,
10309                 (void *)&cmd_flow_director_queue,
10310                 (void *)&cmd_flow_director_queue_id,
10311                 (void *)&cmd_flow_director_fd_id,
10312                 (void *)&cmd_flow_director_fd_id_value,
10313                 (void *)&cmd_flow_director_packet,
10314                 (void *)&cmd_flow_director_filepath,
10315                 NULL,
10316         },
10317 };
10318
10319 #endif /* RTE_NET_I40E */
10320
10321 /* *** deal with flow director mask *** */
10322 struct cmd_flow_director_mask_result {
10323         cmdline_fixed_string_t flow_director_mask;
10324         portid_t port_id;
10325         cmdline_fixed_string_t mode;
10326         cmdline_fixed_string_t mode_value;
10327         cmdline_fixed_string_t vlan;
10328         uint16_t vlan_mask;
10329         cmdline_fixed_string_t src_mask;
10330         cmdline_ipaddr_t ipv4_src;
10331         cmdline_ipaddr_t ipv6_src;
10332         uint16_t port_src;
10333         cmdline_fixed_string_t dst_mask;
10334         cmdline_ipaddr_t ipv4_dst;
10335         cmdline_ipaddr_t ipv6_dst;
10336         uint16_t port_dst;
10337         cmdline_fixed_string_t mac;
10338         uint8_t mac_addr_byte_mask;
10339         cmdline_fixed_string_t tunnel_id;
10340         uint32_t tunnel_id_mask;
10341         cmdline_fixed_string_t tunnel_type;
10342         uint8_t tunnel_type_mask;
10343 };
10344
10345 static void
10346 cmd_flow_director_mask_parsed(void *parsed_result,
10347                           __rte_unused struct cmdline *cl,
10348                           __rte_unused void *data)
10349 {
10350         struct cmd_flow_director_mask_result *res = parsed_result;
10351         struct rte_eth_fdir_masks *mask;
10352         struct rte_port *port;
10353
10354         port = &ports[res->port_id];
10355         /** Check if the port is not started **/
10356         if (port->port_status != RTE_PORT_STOPPED) {
10357                 printf("Please stop port %d first\n", res->port_id);
10358                 return;
10359         }
10360
10361         mask = &port->dev_conf.fdir_conf.mask;
10362
10363         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10364                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10365                         printf("Please set mode to MAC-VLAN.\n");
10366                         return;
10367                 }
10368
10369                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10370         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10371                 if (strcmp(res->mode_value, "Tunnel")) {
10372                         printf("Please set mode to Tunnel.\n");
10373                         return;
10374                 }
10375
10376                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10377                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10378                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10379                 mask->tunnel_type_mask = res->tunnel_type_mask;
10380         } else {
10381                 if (strcmp(res->mode_value, "IP")) {
10382                         printf("Please set mode to IP.\n");
10383                         return;
10384                 }
10385
10386                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10387                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10388                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10389                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10390                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10391                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10392                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10393         }
10394
10395         cmd_reconfig_device_queue(res->port_id, 1, 1);
10396 }
10397
10398 cmdline_parse_token_string_t cmd_flow_director_mask =
10399         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10400                                  flow_director_mask, "flow_director_mask");
10401 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10402         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10403                               port_id, RTE_UINT16);
10404 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10406                                  vlan, "vlan");
10407 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10408         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10409                               vlan_mask, RTE_UINT16);
10410 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10411         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10412                                  src_mask, "src_mask");
10413 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10414         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10415                                  ipv4_src);
10416 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10417         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10418                                  ipv6_src);
10419 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10420         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10421                               port_src, RTE_UINT16);
10422 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10423         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10424                                  dst_mask, "dst_mask");
10425 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10426         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10427                                  ipv4_dst);
10428 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10429         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10430                                  ipv6_dst);
10431 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10432         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10433                               port_dst, RTE_UINT16);
10434
10435 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10436         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10437                                  mode, "mode");
10438 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10439         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10440                                  mode_value, "IP");
10441 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10442         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10443                                  mode_value, "MAC-VLAN");
10444 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10445         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10446                                  mode_value, "Tunnel");
10447 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10448         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10449                                  mac, "mac");
10450 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10451         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10452                               mac_addr_byte_mask, RTE_UINT8);
10453 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10454         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10455                                  tunnel_type, "tunnel-type");
10456 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10457         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10458                               tunnel_type_mask, RTE_UINT8);
10459 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10460         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10461                                  tunnel_id, "tunnel-id");
10462 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10463         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10464                               tunnel_id_mask, RTE_UINT32);
10465
10466 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10467         .f = cmd_flow_director_mask_parsed,
10468         .data = NULL,
10469         .help_str = "flow_director_mask ... : "
10470                 "Set IP mode flow director's mask on NIC",
10471         .tokens = {
10472                 (void *)&cmd_flow_director_mask,
10473                 (void *)&cmd_flow_director_mask_port_id,
10474                 (void *)&cmd_flow_director_mask_mode,
10475                 (void *)&cmd_flow_director_mask_mode_ip,
10476                 (void *)&cmd_flow_director_mask_vlan,
10477                 (void *)&cmd_flow_director_mask_vlan_value,
10478                 (void *)&cmd_flow_director_mask_src,
10479                 (void *)&cmd_flow_director_mask_ipv4_src,
10480                 (void *)&cmd_flow_director_mask_ipv6_src,
10481                 (void *)&cmd_flow_director_mask_port_src,
10482                 (void *)&cmd_flow_director_mask_dst,
10483                 (void *)&cmd_flow_director_mask_ipv4_dst,
10484                 (void *)&cmd_flow_director_mask_ipv6_dst,
10485                 (void *)&cmd_flow_director_mask_port_dst,
10486                 NULL,
10487         },
10488 };
10489
10490 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10491         .f = cmd_flow_director_mask_parsed,
10492         .data = NULL,
10493         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10494                 "flow director's mask on NIC",
10495         .tokens = {
10496                 (void *)&cmd_flow_director_mask,
10497                 (void *)&cmd_flow_director_mask_port_id,
10498                 (void *)&cmd_flow_director_mask_mode,
10499                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10500                 (void *)&cmd_flow_director_mask_vlan,
10501                 (void *)&cmd_flow_director_mask_vlan_value,
10502                 NULL,
10503         },
10504 };
10505
10506 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10507         .f = cmd_flow_director_mask_parsed,
10508         .data = NULL,
10509         .help_str = "flow_director_mask ... : Set tunnel mode "
10510                 "flow director's mask on NIC",
10511         .tokens = {
10512                 (void *)&cmd_flow_director_mask,
10513                 (void *)&cmd_flow_director_mask_port_id,
10514                 (void *)&cmd_flow_director_mask_mode,
10515                 (void *)&cmd_flow_director_mask_mode_tunnel,
10516                 (void *)&cmd_flow_director_mask_vlan,
10517                 (void *)&cmd_flow_director_mask_vlan_value,
10518                 (void *)&cmd_flow_director_mask_mac,
10519                 (void *)&cmd_flow_director_mask_mac_value,
10520                 (void *)&cmd_flow_director_mask_tunnel_type,
10521                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10522                 (void *)&cmd_flow_director_mask_tunnel_id,
10523                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10524                 NULL,
10525         },
10526 };
10527
10528 /* *** deal with flow director flexible payload configuration *** */
10529 struct cmd_flow_director_flexpayload_result {
10530         cmdline_fixed_string_t flow_director_flexpayload;
10531         portid_t port_id;
10532         cmdline_fixed_string_t payload_layer;
10533         cmdline_fixed_string_t payload_cfg;
10534 };
10535
10536 static inline int
10537 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10538 {
10539         char s[256];
10540         const char *p, *p0 = q_arg;
10541         char *end;
10542         unsigned long int_fld;
10543         char *str_fld[max_num];
10544         int i;
10545         unsigned size;
10546         int ret = -1;
10547
10548         p = strchr(p0, '(');
10549         if (p == NULL)
10550                 return -1;
10551         ++p;
10552         p0 = strchr(p, ')');
10553         if (p0 == NULL)
10554                 return -1;
10555
10556         size = p0 - p;
10557         if (size >= sizeof(s))
10558                 return -1;
10559
10560         snprintf(s, sizeof(s), "%.*s", size, p);
10561         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10562         if (ret < 0 || ret > max_num)
10563                 return -1;
10564         for (i = 0; i < ret; i++) {
10565                 errno = 0;
10566                 int_fld = strtoul(str_fld[i], &end, 0);
10567                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10568                         return -1;
10569                 offsets[i] = (uint16_t)int_fld;
10570         }
10571         return ret;
10572 }
10573
10574 static void
10575 cmd_flow_director_flxpld_parsed(void *parsed_result,
10576                           __rte_unused struct cmdline *cl,
10577                           __rte_unused void *data)
10578 {
10579         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10580         struct rte_eth_flex_payload_cfg flex_cfg;
10581         struct rte_port *port;
10582         int ret = 0;
10583
10584         port = &ports[res->port_id];
10585         /** Check if the port is not started **/
10586         if (port->port_status != RTE_PORT_STOPPED) {
10587                 printf("Please stop port %d first\n", res->port_id);
10588                 return;
10589         }
10590
10591         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10592
10593         if (!strcmp(res->payload_layer, "raw"))
10594                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10595         else if (!strcmp(res->payload_layer, "l2"))
10596                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10597         else if (!strcmp(res->payload_layer, "l3"))
10598                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10599         else if (!strcmp(res->payload_layer, "l4"))
10600                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10601
10602         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10603                             RTE_ETH_FDIR_MAX_FLEXLEN);
10604         if (ret < 0) {
10605                 printf("error: Cannot parse flex payload input.\n");
10606                 return;
10607         }
10608
10609         fdir_set_flex_payload(res->port_id, &flex_cfg);
10610         cmd_reconfig_device_queue(res->port_id, 1, 1);
10611 }
10612
10613 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10614         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10615                                  flow_director_flexpayload,
10616                                  "flow_director_flex_payload");
10617 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10618         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10619                               port_id, RTE_UINT16);
10620 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10621         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10622                                  payload_layer, "raw#l2#l3#l4");
10623 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10624         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10625                                  payload_cfg, NULL);
10626
10627 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10628         .f = cmd_flow_director_flxpld_parsed,
10629         .data = NULL,
10630         .help_str = "flow_director_flexpayload ... : "
10631                 "Set flow director's flex payload on NIC",
10632         .tokens = {
10633                 (void *)&cmd_flow_director_flexpayload,
10634                 (void *)&cmd_flow_director_flexpayload_port_id,
10635                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10636                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10637                 NULL,
10638         },
10639 };
10640
10641 /* Generic flow interface command. */
10642 extern cmdline_parse_inst_t cmd_flow;
10643
10644 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10645 struct cmd_mcast_addr_result {
10646         cmdline_fixed_string_t mcast_addr_cmd;
10647         cmdline_fixed_string_t what;
10648         uint16_t port_num;
10649         struct rte_ether_addr mc_addr;
10650 };
10651
10652 static void cmd_mcast_addr_parsed(void *parsed_result,
10653                 __rte_unused struct cmdline *cl,
10654                 __rte_unused void *data)
10655 {
10656         struct cmd_mcast_addr_result *res = parsed_result;
10657
10658         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10659                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10660                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10661                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10662                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10663                 return;
10664         }
10665         if (strcmp(res->what, "add") == 0)
10666                 mcast_addr_add(res->port_num, &res->mc_addr);
10667         else
10668                 mcast_addr_remove(res->port_num, &res->mc_addr);
10669 }
10670
10671 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10672         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10673                                  mcast_addr_cmd, "mcast_addr");
10674 cmdline_parse_token_string_t cmd_mcast_addr_what =
10675         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10676                                  "add#remove");
10677 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10678         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10679                                  RTE_UINT16);
10680 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10681         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10682
10683 cmdline_parse_inst_t cmd_mcast_addr = {
10684         .f = cmd_mcast_addr_parsed,
10685         .data = (void *)0,
10686         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10687                 "Add/Remove multicast MAC address on port_id",
10688         .tokens = {
10689                 (void *)&cmd_mcast_addr_cmd,
10690                 (void *)&cmd_mcast_addr_what,
10691                 (void *)&cmd_mcast_addr_portnum,
10692                 (void *)&cmd_mcast_addr_addr,
10693                 NULL,
10694         },
10695 };
10696
10697 /* vf vlan anti spoof configuration */
10698
10699 /* Common result structure for vf vlan anti spoof */
10700 struct cmd_vf_vlan_anti_spoof_result {
10701         cmdline_fixed_string_t set;
10702         cmdline_fixed_string_t vf;
10703         cmdline_fixed_string_t vlan;
10704         cmdline_fixed_string_t antispoof;
10705         portid_t port_id;
10706         uint32_t vf_id;
10707         cmdline_fixed_string_t on_off;
10708 };
10709
10710 /* Common CLI fields for vf vlan anti spoof enable disable */
10711 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10712         TOKEN_STRING_INITIALIZER
10713                 (struct cmd_vf_vlan_anti_spoof_result,
10714                  set, "set");
10715 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10716         TOKEN_STRING_INITIALIZER
10717                 (struct cmd_vf_vlan_anti_spoof_result,
10718                  vf, "vf");
10719 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10720         TOKEN_STRING_INITIALIZER
10721                 (struct cmd_vf_vlan_anti_spoof_result,
10722                  vlan, "vlan");
10723 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10724         TOKEN_STRING_INITIALIZER
10725                 (struct cmd_vf_vlan_anti_spoof_result,
10726                  antispoof, "antispoof");
10727 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10728         TOKEN_NUM_INITIALIZER
10729                 (struct cmd_vf_vlan_anti_spoof_result,
10730                  port_id, RTE_UINT16);
10731 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10732         TOKEN_NUM_INITIALIZER
10733                 (struct cmd_vf_vlan_anti_spoof_result,
10734                  vf_id, RTE_UINT32);
10735 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10736         TOKEN_STRING_INITIALIZER
10737                 (struct cmd_vf_vlan_anti_spoof_result,
10738                  on_off, "on#off");
10739
10740 static void
10741 cmd_set_vf_vlan_anti_spoof_parsed(
10742         void *parsed_result,
10743         __rte_unused struct cmdline *cl,
10744         __rte_unused void *data)
10745 {
10746         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10747         int ret = -ENOTSUP;
10748
10749         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10750
10751         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10752                 return;
10753
10754 #ifdef RTE_NET_IXGBE
10755         if (ret == -ENOTSUP)
10756                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10757                                 res->vf_id, is_on);
10758 #endif
10759 #ifdef RTE_NET_I40E
10760         if (ret == -ENOTSUP)
10761                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10762                                 res->vf_id, is_on);
10763 #endif
10764 #ifdef RTE_NET_BNXT
10765         if (ret == -ENOTSUP)
10766                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
10767                                 res->vf_id, is_on);
10768 #endif
10769
10770         switch (ret) {
10771         case 0:
10772                 break;
10773         case -EINVAL:
10774                 printf("invalid vf_id %d\n", res->vf_id);
10775                 break;
10776         case -ENODEV:
10777                 printf("invalid port_id %d\n", res->port_id);
10778                 break;
10779         case -ENOTSUP:
10780                 printf("function not implemented\n");
10781                 break;
10782         default:
10783                 printf("programming error: (%s)\n", strerror(-ret));
10784         }
10785 }
10786
10787 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10788         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10789         .data = NULL,
10790         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10791         .tokens = {
10792                 (void *)&cmd_vf_vlan_anti_spoof_set,
10793                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10794                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10795                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10796                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10797                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10798                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10799                 NULL,
10800         },
10801 };
10802
10803 /* vf mac anti spoof configuration */
10804
10805 /* Common result structure for vf mac anti spoof */
10806 struct cmd_vf_mac_anti_spoof_result {
10807         cmdline_fixed_string_t set;
10808         cmdline_fixed_string_t vf;
10809         cmdline_fixed_string_t mac;
10810         cmdline_fixed_string_t antispoof;
10811         portid_t port_id;
10812         uint32_t vf_id;
10813         cmdline_fixed_string_t on_off;
10814 };
10815
10816 /* Common CLI fields for vf mac anti spoof enable disable */
10817 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10818         TOKEN_STRING_INITIALIZER
10819                 (struct cmd_vf_mac_anti_spoof_result,
10820                  set, "set");
10821 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10822         TOKEN_STRING_INITIALIZER
10823                 (struct cmd_vf_mac_anti_spoof_result,
10824                  vf, "vf");
10825 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10826         TOKEN_STRING_INITIALIZER
10827                 (struct cmd_vf_mac_anti_spoof_result,
10828                  mac, "mac");
10829 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10830         TOKEN_STRING_INITIALIZER
10831                 (struct cmd_vf_mac_anti_spoof_result,
10832                  antispoof, "antispoof");
10833 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10834         TOKEN_NUM_INITIALIZER
10835                 (struct cmd_vf_mac_anti_spoof_result,
10836                  port_id, RTE_UINT16);
10837 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
10838         TOKEN_NUM_INITIALIZER
10839                 (struct cmd_vf_mac_anti_spoof_result,
10840                  vf_id, RTE_UINT32);
10841 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
10842         TOKEN_STRING_INITIALIZER
10843                 (struct cmd_vf_mac_anti_spoof_result,
10844                  on_off, "on#off");
10845
10846 static void
10847 cmd_set_vf_mac_anti_spoof_parsed(
10848         void *parsed_result,
10849         __rte_unused struct cmdline *cl,
10850         __rte_unused void *data)
10851 {
10852         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
10853         int ret = -ENOTSUP;
10854
10855         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10856
10857         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10858                 return;
10859
10860 #ifdef RTE_NET_IXGBE
10861         if (ret == -ENOTSUP)
10862                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
10863                         res->vf_id, is_on);
10864 #endif
10865 #ifdef RTE_NET_I40E
10866         if (ret == -ENOTSUP)
10867                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
10868                         res->vf_id, is_on);
10869 #endif
10870 #ifdef RTE_NET_BNXT
10871         if (ret == -ENOTSUP)
10872                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
10873                         res->vf_id, is_on);
10874 #endif
10875
10876         switch (ret) {
10877         case 0:
10878                 break;
10879         case -EINVAL:
10880                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10881                 break;
10882         case -ENODEV:
10883                 printf("invalid port_id %d\n", res->port_id);
10884                 break;
10885         case -ENOTSUP:
10886                 printf("function not implemented\n");
10887                 break;
10888         default:
10889                 printf("programming error: (%s)\n", strerror(-ret));
10890         }
10891 }
10892
10893 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
10894         .f = cmd_set_vf_mac_anti_spoof_parsed,
10895         .data = NULL,
10896         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
10897         .tokens = {
10898                 (void *)&cmd_vf_mac_anti_spoof_set,
10899                 (void *)&cmd_vf_mac_anti_spoof_vf,
10900                 (void *)&cmd_vf_mac_anti_spoof_mac,
10901                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
10902                 (void *)&cmd_vf_mac_anti_spoof_port_id,
10903                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
10904                 (void *)&cmd_vf_mac_anti_spoof_on_off,
10905                 NULL,
10906         },
10907 };
10908
10909 /* vf vlan strip queue configuration */
10910
10911 /* Common result structure for vf mac anti spoof */
10912 struct cmd_vf_vlan_stripq_result {
10913         cmdline_fixed_string_t set;
10914         cmdline_fixed_string_t vf;
10915         cmdline_fixed_string_t vlan;
10916         cmdline_fixed_string_t stripq;
10917         portid_t port_id;
10918         uint16_t vf_id;
10919         cmdline_fixed_string_t on_off;
10920 };
10921
10922 /* Common CLI fields for vf vlan strip enable disable */
10923 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
10924         TOKEN_STRING_INITIALIZER
10925                 (struct cmd_vf_vlan_stripq_result,
10926                  set, "set");
10927 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
10928         TOKEN_STRING_INITIALIZER
10929                 (struct cmd_vf_vlan_stripq_result,
10930                  vf, "vf");
10931 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
10932         TOKEN_STRING_INITIALIZER
10933                 (struct cmd_vf_vlan_stripq_result,
10934                  vlan, "vlan");
10935 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
10936         TOKEN_STRING_INITIALIZER
10937                 (struct cmd_vf_vlan_stripq_result,
10938                  stripq, "stripq");
10939 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
10940         TOKEN_NUM_INITIALIZER
10941                 (struct cmd_vf_vlan_stripq_result,
10942                  port_id, RTE_UINT16);
10943 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
10944         TOKEN_NUM_INITIALIZER
10945                 (struct cmd_vf_vlan_stripq_result,
10946                  vf_id, RTE_UINT16);
10947 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
10948         TOKEN_STRING_INITIALIZER
10949                 (struct cmd_vf_vlan_stripq_result,
10950                  on_off, "on#off");
10951
10952 static void
10953 cmd_set_vf_vlan_stripq_parsed(
10954         void *parsed_result,
10955         __rte_unused struct cmdline *cl,
10956         __rte_unused void *data)
10957 {
10958         struct cmd_vf_vlan_stripq_result *res = parsed_result;
10959         int ret = -ENOTSUP;
10960
10961         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10962
10963         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10964                 return;
10965
10966 #ifdef RTE_NET_IXGBE
10967         if (ret == -ENOTSUP)
10968                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
10969                         res->vf_id, is_on);
10970 #endif
10971 #ifdef RTE_NET_I40E
10972         if (ret == -ENOTSUP)
10973                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
10974                         res->vf_id, is_on);
10975 #endif
10976 #ifdef RTE_NET_BNXT
10977         if (ret == -ENOTSUP)
10978                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
10979                         res->vf_id, is_on);
10980 #endif
10981
10982         switch (ret) {
10983         case 0:
10984                 break;
10985         case -EINVAL:
10986                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
10987                 break;
10988         case -ENODEV:
10989                 printf("invalid port_id %d\n", res->port_id);
10990                 break;
10991         case -ENOTSUP:
10992                 printf("function not implemented\n");
10993                 break;
10994         default:
10995                 printf("programming error: (%s)\n", strerror(-ret));
10996         }
10997 }
10998
10999 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11000         .f = cmd_set_vf_vlan_stripq_parsed,
11001         .data = NULL,
11002         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11003         .tokens = {
11004                 (void *)&cmd_vf_vlan_stripq_set,
11005                 (void *)&cmd_vf_vlan_stripq_vf,
11006                 (void *)&cmd_vf_vlan_stripq_vlan,
11007                 (void *)&cmd_vf_vlan_stripq_stripq,
11008                 (void *)&cmd_vf_vlan_stripq_port_id,
11009                 (void *)&cmd_vf_vlan_stripq_vf_id,
11010                 (void *)&cmd_vf_vlan_stripq_on_off,
11011                 NULL,
11012         },
11013 };
11014
11015 /* vf vlan insert configuration */
11016
11017 /* Common result structure for vf vlan insert */
11018 struct cmd_vf_vlan_insert_result {
11019         cmdline_fixed_string_t set;
11020         cmdline_fixed_string_t vf;
11021         cmdline_fixed_string_t vlan;
11022         cmdline_fixed_string_t insert;
11023         portid_t port_id;
11024         uint16_t vf_id;
11025         uint16_t vlan_id;
11026 };
11027
11028 /* Common CLI fields for vf vlan insert enable disable */
11029 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11030         TOKEN_STRING_INITIALIZER
11031                 (struct cmd_vf_vlan_insert_result,
11032                  set, "set");
11033 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11034         TOKEN_STRING_INITIALIZER
11035                 (struct cmd_vf_vlan_insert_result,
11036                  vf, "vf");
11037 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11038         TOKEN_STRING_INITIALIZER
11039                 (struct cmd_vf_vlan_insert_result,
11040                  vlan, "vlan");
11041 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11042         TOKEN_STRING_INITIALIZER
11043                 (struct cmd_vf_vlan_insert_result,
11044                  insert, "insert");
11045 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11046         TOKEN_NUM_INITIALIZER
11047                 (struct cmd_vf_vlan_insert_result,
11048                  port_id, RTE_UINT16);
11049 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11050         TOKEN_NUM_INITIALIZER
11051                 (struct cmd_vf_vlan_insert_result,
11052                  vf_id, RTE_UINT16);
11053 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11054         TOKEN_NUM_INITIALIZER
11055                 (struct cmd_vf_vlan_insert_result,
11056                  vlan_id, RTE_UINT16);
11057
11058 static void
11059 cmd_set_vf_vlan_insert_parsed(
11060         void *parsed_result,
11061         __rte_unused struct cmdline *cl,
11062         __rte_unused void *data)
11063 {
11064         struct cmd_vf_vlan_insert_result *res = parsed_result;
11065         int ret = -ENOTSUP;
11066
11067         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11068                 return;
11069
11070 #ifdef RTE_NET_IXGBE
11071         if (ret == -ENOTSUP)
11072                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11073                         res->vlan_id);
11074 #endif
11075 #ifdef RTE_NET_I40E
11076         if (ret == -ENOTSUP)
11077                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11078                         res->vlan_id);
11079 #endif
11080 #ifdef RTE_NET_BNXT
11081         if (ret == -ENOTSUP)
11082                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11083                         res->vlan_id);
11084 #endif
11085
11086         switch (ret) {
11087         case 0:
11088                 break;
11089         case -EINVAL:
11090                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11091                 break;
11092         case -ENODEV:
11093                 printf("invalid port_id %d\n", res->port_id);
11094                 break;
11095         case -ENOTSUP:
11096                 printf("function not implemented\n");
11097                 break;
11098         default:
11099                 printf("programming error: (%s)\n", strerror(-ret));
11100         }
11101 }
11102
11103 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11104         .f = cmd_set_vf_vlan_insert_parsed,
11105         .data = NULL,
11106         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11107         .tokens = {
11108                 (void *)&cmd_vf_vlan_insert_set,
11109                 (void *)&cmd_vf_vlan_insert_vf,
11110                 (void *)&cmd_vf_vlan_insert_vlan,
11111                 (void *)&cmd_vf_vlan_insert_insert,
11112                 (void *)&cmd_vf_vlan_insert_port_id,
11113                 (void *)&cmd_vf_vlan_insert_vf_id,
11114                 (void *)&cmd_vf_vlan_insert_vlan_id,
11115                 NULL,
11116         },
11117 };
11118
11119 /* tx loopback configuration */
11120
11121 /* Common result structure for tx loopback */
11122 struct cmd_tx_loopback_result {
11123         cmdline_fixed_string_t set;
11124         cmdline_fixed_string_t tx;
11125         cmdline_fixed_string_t loopback;
11126         portid_t port_id;
11127         cmdline_fixed_string_t on_off;
11128 };
11129
11130 /* Common CLI fields for tx loopback enable disable */
11131 cmdline_parse_token_string_t cmd_tx_loopback_set =
11132         TOKEN_STRING_INITIALIZER
11133                 (struct cmd_tx_loopback_result,
11134                  set, "set");
11135 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11136         TOKEN_STRING_INITIALIZER
11137                 (struct cmd_tx_loopback_result,
11138                  tx, "tx");
11139 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11140         TOKEN_STRING_INITIALIZER
11141                 (struct cmd_tx_loopback_result,
11142                  loopback, "loopback");
11143 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11144         TOKEN_NUM_INITIALIZER
11145                 (struct cmd_tx_loopback_result,
11146                  port_id, RTE_UINT16);
11147 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11148         TOKEN_STRING_INITIALIZER
11149                 (struct cmd_tx_loopback_result,
11150                  on_off, "on#off");
11151
11152 static void
11153 cmd_set_tx_loopback_parsed(
11154         void *parsed_result,
11155         __rte_unused struct cmdline *cl,
11156         __rte_unused void *data)
11157 {
11158         struct cmd_tx_loopback_result *res = parsed_result;
11159         int ret = -ENOTSUP;
11160
11161         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11162
11163         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11164                 return;
11165
11166 #ifdef RTE_NET_IXGBE
11167         if (ret == -ENOTSUP)
11168                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11169 #endif
11170 #ifdef RTE_NET_I40E
11171         if (ret == -ENOTSUP)
11172                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11173 #endif
11174 #ifdef RTE_NET_BNXT
11175         if (ret == -ENOTSUP)
11176                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11177 #endif
11178 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11179         if (ret == -ENOTSUP)
11180                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11181 #endif
11182
11183         switch (ret) {
11184         case 0:
11185                 break;
11186         case -EINVAL:
11187                 printf("invalid is_on %d\n", is_on);
11188                 break;
11189         case -ENODEV:
11190                 printf("invalid port_id %d\n", res->port_id);
11191                 break;
11192         case -ENOTSUP:
11193                 printf("function not implemented\n");
11194                 break;
11195         default:
11196                 printf("programming error: (%s)\n", strerror(-ret));
11197         }
11198 }
11199
11200 cmdline_parse_inst_t cmd_set_tx_loopback = {
11201         .f = cmd_set_tx_loopback_parsed,
11202         .data = NULL,
11203         .help_str = "set tx loopback <port_id> on|off",
11204         .tokens = {
11205                 (void *)&cmd_tx_loopback_set,
11206                 (void *)&cmd_tx_loopback_tx,
11207                 (void *)&cmd_tx_loopback_loopback,
11208                 (void *)&cmd_tx_loopback_port_id,
11209                 (void *)&cmd_tx_loopback_on_off,
11210                 NULL,
11211         },
11212 };
11213
11214 /* all queues drop enable configuration */
11215
11216 /* Common result structure for all queues drop enable */
11217 struct cmd_all_queues_drop_en_result {
11218         cmdline_fixed_string_t set;
11219         cmdline_fixed_string_t all;
11220         cmdline_fixed_string_t queues;
11221         cmdline_fixed_string_t drop;
11222         portid_t port_id;
11223         cmdline_fixed_string_t on_off;
11224 };
11225
11226 /* Common CLI fields for tx loopback enable disable */
11227 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11228         TOKEN_STRING_INITIALIZER
11229                 (struct cmd_all_queues_drop_en_result,
11230                  set, "set");
11231 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11232         TOKEN_STRING_INITIALIZER
11233                 (struct cmd_all_queues_drop_en_result,
11234                  all, "all");
11235 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11236         TOKEN_STRING_INITIALIZER
11237                 (struct cmd_all_queues_drop_en_result,
11238                  queues, "queues");
11239 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11240         TOKEN_STRING_INITIALIZER
11241                 (struct cmd_all_queues_drop_en_result,
11242                  drop, "drop");
11243 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11244         TOKEN_NUM_INITIALIZER
11245                 (struct cmd_all_queues_drop_en_result,
11246                  port_id, RTE_UINT16);
11247 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11248         TOKEN_STRING_INITIALIZER
11249                 (struct cmd_all_queues_drop_en_result,
11250                  on_off, "on#off");
11251
11252 static void
11253 cmd_set_all_queues_drop_en_parsed(
11254         void *parsed_result,
11255         __rte_unused struct cmdline *cl,
11256         __rte_unused void *data)
11257 {
11258         struct cmd_all_queues_drop_en_result *res = parsed_result;
11259         int ret = -ENOTSUP;
11260         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11261
11262         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11263                 return;
11264
11265 #ifdef RTE_NET_IXGBE
11266         if (ret == -ENOTSUP)
11267                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11268 #endif
11269 #ifdef RTE_NET_BNXT
11270         if (ret == -ENOTSUP)
11271                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11272 #endif
11273         switch (ret) {
11274         case 0:
11275                 break;
11276         case -EINVAL:
11277                 printf("invalid is_on %d\n", is_on);
11278                 break;
11279         case -ENODEV:
11280                 printf("invalid port_id %d\n", res->port_id);
11281                 break;
11282         case -ENOTSUP:
11283                 printf("function not implemented\n");
11284                 break;
11285         default:
11286                 printf("programming error: (%s)\n", strerror(-ret));
11287         }
11288 }
11289
11290 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11291         .f = cmd_set_all_queues_drop_en_parsed,
11292         .data = NULL,
11293         .help_str = "set all queues drop <port_id> on|off",
11294         .tokens = {
11295                 (void *)&cmd_all_queues_drop_en_set,
11296                 (void *)&cmd_all_queues_drop_en_all,
11297                 (void *)&cmd_all_queues_drop_en_queues,
11298                 (void *)&cmd_all_queues_drop_en_drop,
11299                 (void *)&cmd_all_queues_drop_en_port_id,
11300                 (void *)&cmd_all_queues_drop_en_on_off,
11301                 NULL,
11302         },
11303 };
11304
11305 /* vf split drop enable configuration */
11306
11307 /* Common result structure for vf split drop enable */
11308 struct cmd_vf_split_drop_en_result {
11309         cmdline_fixed_string_t set;
11310         cmdline_fixed_string_t vf;
11311         cmdline_fixed_string_t split;
11312         cmdline_fixed_string_t drop;
11313         portid_t port_id;
11314         uint16_t vf_id;
11315         cmdline_fixed_string_t on_off;
11316 };
11317
11318 /* Common CLI fields for vf split drop enable disable */
11319 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11320         TOKEN_STRING_INITIALIZER
11321                 (struct cmd_vf_split_drop_en_result,
11322                  set, "set");
11323 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11324         TOKEN_STRING_INITIALIZER
11325                 (struct cmd_vf_split_drop_en_result,
11326                  vf, "vf");
11327 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11328         TOKEN_STRING_INITIALIZER
11329                 (struct cmd_vf_split_drop_en_result,
11330                  split, "split");
11331 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11332         TOKEN_STRING_INITIALIZER
11333                 (struct cmd_vf_split_drop_en_result,
11334                  drop, "drop");
11335 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11336         TOKEN_NUM_INITIALIZER
11337                 (struct cmd_vf_split_drop_en_result,
11338                  port_id, RTE_UINT16);
11339 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11340         TOKEN_NUM_INITIALIZER
11341                 (struct cmd_vf_split_drop_en_result,
11342                  vf_id, RTE_UINT16);
11343 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11344         TOKEN_STRING_INITIALIZER
11345                 (struct cmd_vf_split_drop_en_result,
11346                  on_off, "on#off");
11347
11348 static void
11349 cmd_set_vf_split_drop_en_parsed(
11350         void *parsed_result,
11351         __rte_unused struct cmdline *cl,
11352         __rte_unused void *data)
11353 {
11354         struct cmd_vf_split_drop_en_result *res = parsed_result;
11355         int ret = -ENOTSUP;
11356         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11357
11358         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11359                 return;
11360
11361 #ifdef RTE_NET_IXGBE
11362         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11363                         is_on);
11364 #endif
11365         switch (ret) {
11366         case 0:
11367                 break;
11368         case -EINVAL:
11369                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11370                 break;
11371         case -ENODEV:
11372                 printf("invalid port_id %d\n", res->port_id);
11373                 break;
11374         case -ENOTSUP:
11375                 printf("not supported on port %d\n", res->port_id);
11376                 break;
11377         default:
11378                 printf("programming error: (%s)\n", strerror(-ret));
11379         }
11380 }
11381
11382 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11383         .f = cmd_set_vf_split_drop_en_parsed,
11384         .data = NULL,
11385         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11386         .tokens = {
11387                 (void *)&cmd_vf_split_drop_en_set,
11388                 (void *)&cmd_vf_split_drop_en_vf,
11389                 (void *)&cmd_vf_split_drop_en_split,
11390                 (void *)&cmd_vf_split_drop_en_drop,
11391                 (void *)&cmd_vf_split_drop_en_port_id,
11392                 (void *)&cmd_vf_split_drop_en_vf_id,
11393                 (void *)&cmd_vf_split_drop_en_on_off,
11394                 NULL,
11395         },
11396 };
11397
11398 /* vf mac address configuration */
11399
11400 /* Common result structure for vf mac address */
11401 struct cmd_set_vf_mac_addr_result {
11402         cmdline_fixed_string_t set;
11403         cmdline_fixed_string_t vf;
11404         cmdline_fixed_string_t mac;
11405         cmdline_fixed_string_t addr;
11406         portid_t port_id;
11407         uint16_t vf_id;
11408         struct rte_ether_addr mac_addr;
11409
11410 };
11411
11412 /* Common CLI fields for vf split drop enable disable */
11413 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11414         TOKEN_STRING_INITIALIZER
11415                 (struct cmd_set_vf_mac_addr_result,
11416                  set, "set");
11417 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11418         TOKEN_STRING_INITIALIZER
11419                 (struct cmd_set_vf_mac_addr_result,
11420                  vf, "vf");
11421 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11422         TOKEN_STRING_INITIALIZER
11423                 (struct cmd_set_vf_mac_addr_result,
11424                  mac, "mac");
11425 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11426         TOKEN_STRING_INITIALIZER
11427                 (struct cmd_set_vf_mac_addr_result,
11428                  addr, "addr");
11429 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11430         TOKEN_NUM_INITIALIZER
11431                 (struct cmd_set_vf_mac_addr_result,
11432                  port_id, RTE_UINT16);
11433 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11434         TOKEN_NUM_INITIALIZER
11435                 (struct cmd_set_vf_mac_addr_result,
11436                  vf_id, RTE_UINT16);
11437 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11438         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11439                  mac_addr);
11440
11441 static void
11442 cmd_set_vf_mac_addr_parsed(
11443         void *parsed_result,
11444         __rte_unused struct cmdline *cl,
11445         __rte_unused void *data)
11446 {
11447         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11448         int ret = -ENOTSUP;
11449
11450         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11451                 return;
11452
11453 #ifdef RTE_NET_IXGBE
11454         if (ret == -ENOTSUP)
11455                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11456                                 &res->mac_addr);
11457 #endif
11458 #ifdef RTE_NET_I40E
11459         if (ret == -ENOTSUP)
11460                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11461                                 &res->mac_addr);
11462 #endif
11463 #ifdef RTE_NET_BNXT
11464         if (ret == -ENOTSUP)
11465                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11466                                 &res->mac_addr);
11467 #endif
11468
11469         switch (ret) {
11470         case 0:
11471                 break;
11472         case -EINVAL:
11473                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11474                 break;
11475         case -ENODEV:
11476                 printf("invalid port_id %d\n", res->port_id);
11477                 break;
11478         case -ENOTSUP:
11479                 printf("function not implemented\n");
11480                 break;
11481         default:
11482                 printf("programming error: (%s)\n", strerror(-ret));
11483         }
11484 }
11485
11486 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11487         .f = cmd_set_vf_mac_addr_parsed,
11488         .data = NULL,
11489         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11490         .tokens = {
11491                 (void *)&cmd_set_vf_mac_addr_set,
11492                 (void *)&cmd_set_vf_mac_addr_vf,
11493                 (void *)&cmd_set_vf_mac_addr_mac,
11494                 (void *)&cmd_set_vf_mac_addr_addr,
11495                 (void *)&cmd_set_vf_mac_addr_port_id,
11496                 (void *)&cmd_set_vf_mac_addr_vf_id,
11497                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11498                 NULL,
11499         },
11500 };
11501
11502 /* MACsec configuration */
11503
11504 /* Common result structure for MACsec offload enable */
11505 struct cmd_macsec_offload_on_result {
11506         cmdline_fixed_string_t set;
11507         cmdline_fixed_string_t macsec;
11508         cmdline_fixed_string_t offload;
11509         portid_t port_id;
11510         cmdline_fixed_string_t on;
11511         cmdline_fixed_string_t encrypt;
11512         cmdline_fixed_string_t en_on_off;
11513         cmdline_fixed_string_t replay_protect;
11514         cmdline_fixed_string_t rp_on_off;
11515 };
11516
11517 /* Common CLI fields for MACsec offload disable */
11518 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11519         TOKEN_STRING_INITIALIZER
11520                 (struct cmd_macsec_offload_on_result,
11521                  set, "set");
11522 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11523         TOKEN_STRING_INITIALIZER
11524                 (struct cmd_macsec_offload_on_result,
11525                  macsec, "macsec");
11526 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11527         TOKEN_STRING_INITIALIZER
11528                 (struct cmd_macsec_offload_on_result,
11529                  offload, "offload");
11530 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11531         TOKEN_NUM_INITIALIZER
11532                 (struct cmd_macsec_offload_on_result,
11533                  port_id, RTE_UINT16);
11534 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11535         TOKEN_STRING_INITIALIZER
11536                 (struct cmd_macsec_offload_on_result,
11537                  on, "on");
11538 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11539         TOKEN_STRING_INITIALIZER
11540                 (struct cmd_macsec_offload_on_result,
11541                  encrypt, "encrypt");
11542 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11543         TOKEN_STRING_INITIALIZER
11544                 (struct cmd_macsec_offload_on_result,
11545                  en_on_off, "on#off");
11546 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11547         TOKEN_STRING_INITIALIZER
11548                 (struct cmd_macsec_offload_on_result,
11549                  replay_protect, "replay-protect");
11550 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11551         TOKEN_STRING_INITIALIZER
11552                 (struct cmd_macsec_offload_on_result,
11553                  rp_on_off, "on#off");
11554
11555 static void
11556 cmd_set_macsec_offload_on_parsed(
11557         void *parsed_result,
11558         __rte_unused struct cmdline *cl,
11559         __rte_unused void *data)
11560 {
11561         struct cmd_macsec_offload_on_result *res = parsed_result;
11562         int ret = -ENOTSUP;
11563         portid_t port_id = res->port_id;
11564         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11565         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11566         struct rte_eth_dev_info dev_info;
11567
11568         if (port_id_is_invalid(port_id, ENABLED_WARN))
11569                 return;
11570         if (!port_is_stopped(port_id)) {
11571                 printf("Please stop port %d first\n", port_id);
11572                 return;
11573         }
11574
11575         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11576         if (ret != 0)
11577                 return;
11578
11579         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11580 #ifdef RTE_NET_IXGBE
11581                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11582 #endif
11583         }
11584         RTE_SET_USED(en);
11585         RTE_SET_USED(rp);
11586
11587         switch (ret) {
11588         case 0:
11589                 ports[port_id].dev_conf.txmode.offloads |=
11590                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11591                 cmd_reconfig_device_queue(port_id, 1, 1);
11592                 break;
11593         case -ENODEV:
11594                 printf("invalid port_id %d\n", port_id);
11595                 break;
11596         case -ENOTSUP:
11597                 printf("not supported on port %d\n", port_id);
11598                 break;
11599         default:
11600                 printf("programming error: (%s)\n", strerror(-ret));
11601         }
11602 }
11603
11604 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11605         .f = cmd_set_macsec_offload_on_parsed,
11606         .data = NULL,
11607         .help_str = "set macsec offload <port_id> on "
11608                 "encrypt on|off replay-protect on|off",
11609         .tokens = {
11610                 (void *)&cmd_macsec_offload_on_set,
11611                 (void *)&cmd_macsec_offload_on_macsec,
11612                 (void *)&cmd_macsec_offload_on_offload,
11613                 (void *)&cmd_macsec_offload_on_port_id,
11614                 (void *)&cmd_macsec_offload_on_on,
11615                 (void *)&cmd_macsec_offload_on_encrypt,
11616                 (void *)&cmd_macsec_offload_on_en_on_off,
11617                 (void *)&cmd_macsec_offload_on_replay_protect,
11618                 (void *)&cmd_macsec_offload_on_rp_on_off,
11619                 NULL,
11620         },
11621 };
11622
11623 /* Common result structure for MACsec offload disable */
11624 struct cmd_macsec_offload_off_result {
11625         cmdline_fixed_string_t set;
11626         cmdline_fixed_string_t macsec;
11627         cmdline_fixed_string_t offload;
11628         portid_t port_id;
11629         cmdline_fixed_string_t off;
11630 };
11631
11632 /* Common CLI fields for MACsec offload disable */
11633 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11634         TOKEN_STRING_INITIALIZER
11635                 (struct cmd_macsec_offload_off_result,
11636                  set, "set");
11637 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11638         TOKEN_STRING_INITIALIZER
11639                 (struct cmd_macsec_offload_off_result,
11640                  macsec, "macsec");
11641 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11642         TOKEN_STRING_INITIALIZER
11643                 (struct cmd_macsec_offload_off_result,
11644                  offload, "offload");
11645 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11646         TOKEN_NUM_INITIALIZER
11647                 (struct cmd_macsec_offload_off_result,
11648                  port_id, RTE_UINT16);
11649 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11650         TOKEN_STRING_INITIALIZER
11651                 (struct cmd_macsec_offload_off_result,
11652                  off, "off");
11653
11654 static void
11655 cmd_set_macsec_offload_off_parsed(
11656         void *parsed_result,
11657         __rte_unused struct cmdline *cl,
11658         __rte_unused void *data)
11659 {
11660         struct cmd_macsec_offload_off_result *res = parsed_result;
11661         int ret = -ENOTSUP;
11662         struct rte_eth_dev_info dev_info;
11663         portid_t port_id = res->port_id;
11664
11665         if (port_id_is_invalid(port_id, ENABLED_WARN))
11666                 return;
11667         if (!port_is_stopped(port_id)) {
11668                 printf("Please stop port %d first\n", port_id);
11669                 return;
11670         }
11671
11672         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11673         if (ret != 0)
11674                 return;
11675
11676         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11677 #ifdef RTE_NET_IXGBE
11678                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11679 #endif
11680         }
11681         switch (ret) {
11682         case 0:
11683                 ports[port_id].dev_conf.txmode.offloads &=
11684                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11685                 cmd_reconfig_device_queue(port_id, 1, 1);
11686                 break;
11687         case -ENODEV:
11688                 printf("invalid port_id %d\n", port_id);
11689                 break;
11690         case -ENOTSUP:
11691                 printf("not supported on port %d\n", port_id);
11692                 break;
11693         default:
11694                 printf("programming error: (%s)\n", strerror(-ret));
11695         }
11696 }
11697
11698 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11699         .f = cmd_set_macsec_offload_off_parsed,
11700         .data = NULL,
11701         .help_str = "set macsec offload <port_id> off",
11702         .tokens = {
11703                 (void *)&cmd_macsec_offload_off_set,
11704                 (void *)&cmd_macsec_offload_off_macsec,
11705                 (void *)&cmd_macsec_offload_off_offload,
11706                 (void *)&cmd_macsec_offload_off_port_id,
11707                 (void *)&cmd_macsec_offload_off_off,
11708                 NULL,
11709         },
11710 };
11711
11712 /* Common result structure for MACsec secure connection configure */
11713 struct cmd_macsec_sc_result {
11714         cmdline_fixed_string_t set;
11715         cmdline_fixed_string_t macsec;
11716         cmdline_fixed_string_t sc;
11717         cmdline_fixed_string_t tx_rx;
11718         portid_t port_id;
11719         struct rte_ether_addr mac;
11720         uint16_t pi;
11721 };
11722
11723 /* Common CLI fields for MACsec secure connection configure */
11724 cmdline_parse_token_string_t cmd_macsec_sc_set =
11725         TOKEN_STRING_INITIALIZER
11726                 (struct cmd_macsec_sc_result,
11727                  set, "set");
11728 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11729         TOKEN_STRING_INITIALIZER
11730                 (struct cmd_macsec_sc_result,
11731                  macsec, "macsec");
11732 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11733         TOKEN_STRING_INITIALIZER
11734                 (struct cmd_macsec_sc_result,
11735                  sc, "sc");
11736 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11737         TOKEN_STRING_INITIALIZER
11738                 (struct cmd_macsec_sc_result,
11739                  tx_rx, "tx#rx");
11740 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11741         TOKEN_NUM_INITIALIZER
11742                 (struct cmd_macsec_sc_result,
11743                  port_id, RTE_UINT16);
11744 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11745         TOKEN_ETHERADDR_INITIALIZER
11746                 (struct cmd_macsec_sc_result,
11747                  mac);
11748 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11749         TOKEN_NUM_INITIALIZER
11750                 (struct cmd_macsec_sc_result,
11751                  pi, RTE_UINT16);
11752
11753 static void
11754 cmd_set_macsec_sc_parsed(
11755         void *parsed_result,
11756         __rte_unused struct cmdline *cl,
11757         __rte_unused void *data)
11758 {
11759         struct cmd_macsec_sc_result *res = parsed_result;
11760         int ret = -ENOTSUP;
11761         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11762
11763 #ifdef RTE_NET_IXGBE
11764         ret = is_tx ?
11765                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11766                                 res->mac.addr_bytes) :
11767                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11768                                 res->mac.addr_bytes, res->pi);
11769 #endif
11770         RTE_SET_USED(is_tx);
11771
11772         switch (ret) {
11773         case 0:
11774                 break;
11775         case -ENODEV:
11776                 printf("invalid port_id %d\n", res->port_id);
11777                 break;
11778         case -ENOTSUP:
11779                 printf("not supported on port %d\n", res->port_id);
11780                 break;
11781         default:
11782                 printf("programming error: (%s)\n", strerror(-ret));
11783         }
11784 }
11785
11786 cmdline_parse_inst_t cmd_set_macsec_sc = {
11787         .f = cmd_set_macsec_sc_parsed,
11788         .data = NULL,
11789         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11790         .tokens = {
11791                 (void *)&cmd_macsec_sc_set,
11792                 (void *)&cmd_macsec_sc_macsec,
11793                 (void *)&cmd_macsec_sc_sc,
11794                 (void *)&cmd_macsec_sc_tx_rx,
11795                 (void *)&cmd_macsec_sc_port_id,
11796                 (void *)&cmd_macsec_sc_mac,
11797                 (void *)&cmd_macsec_sc_pi,
11798                 NULL,
11799         },
11800 };
11801
11802 /* Common result structure for MACsec secure connection configure */
11803 struct cmd_macsec_sa_result {
11804         cmdline_fixed_string_t set;
11805         cmdline_fixed_string_t macsec;
11806         cmdline_fixed_string_t sa;
11807         cmdline_fixed_string_t tx_rx;
11808         portid_t port_id;
11809         uint8_t idx;
11810         uint8_t an;
11811         uint32_t pn;
11812         cmdline_fixed_string_t key;
11813 };
11814
11815 /* Common CLI fields for MACsec secure connection configure */
11816 cmdline_parse_token_string_t cmd_macsec_sa_set =
11817         TOKEN_STRING_INITIALIZER
11818                 (struct cmd_macsec_sa_result,
11819                  set, "set");
11820 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11821         TOKEN_STRING_INITIALIZER
11822                 (struct cmd_macsec_sa_result,
11823                  macsec, "macsec");
11824 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11825         TOKEN_STRING_INITIALIZER
11826                 (struct cmd_macsec_sa_result,
11827                  sa, "sa");
11828 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11829         TOKEN_STRING_INITIALIZER
11830                 (struct cmd_macsec_sa_result,
11831                  tx_rx, "tx#rx");
11832 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11833         TOKEN_NUM_INITIALIZER
11834                 (struct cmd_macsec_sa_result,
11835                  port_id, RTE_UINT16);
11836 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11837         TOKEN_NUM_INITIALIZER
11838                 (struct cmd_macsec_sa_result,
11839                  idx, RTE_UINT8);
11840 cmdline_parse_token_num_t cmd_macsec_sa_an =
11841         TOKEN_NUM_INITIALIZER
11842                 (struct cmd_macsec_sa_result,
11843                  an, RTE_UINT8);
11844 cmdline_parse_token_num_t cmd_macsec_sa_pn =
11845         TOKEN_NUM_INITIALIZER
11846                 (struct cmd_macsec_sa_result,
11847                  pn, RTE_UINT32);
11848 cmdline_parse_token_string_t cmd_macsec_sa_key =
11849         TOKEN_STRING_INITIALIZER
11850                 (struct cmd_macsec_sa_result,
11851                  key, NULL);
11852
11853 static void
11854 cmd_set_macsec_sa_parsed(
11855         void *parsed_result,
11856         __rte_unused struct cmdline *cl,
11857         __rte_unused void *data)
11858 {
11859         struct cmd_macsec_sa_result *res = parsed_result;
11860         int ret = -ENOTSUP;
11861         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11862         uint8_t key[16] = { 0 };
11863         uint8_t xdgt0;
11864         uint8_t xdgt1;
11865         int key_len;
11866         int i;
11867
11868         key_len = strlen(res->key) / 2;
11869         if (key_len > 16)
11870                 key_len = 16;
11871
11872         for (i = 0; i < key_len; i++) {
11873                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
11874                 if (xdgt0 == 0xFF)
11875                         return;
11876                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
11877                 if (xdgt1 == 0xFF)
11878                         return;
11879                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
11880         }
11881
11882 #ifdef RTE_NET_IXGBE
11883         ret = is_tx ?
11884                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
11885                         res->idx, res->an, res->pn, key) :
11886                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
11887                         res->idx, res->an, res->pn, key);
11888 #endif
11889         RTE_SET_USED(is_tx);
11890         RTE_SET_USED(key);
11891
11892         switch (ret) {
11893         case 0:
11894                 break;
11895         case -EINVAL:
11896                 printf("invalid idx %d or an %d\n", res->idx, res->an);
11897                 break;
11898         case -ENODEV:
11899                 printf("invalid port_id %d\n", res->port_id);
11900                 break;
11901         case -ENOTSUP:
11902                 printf("not supported on port %d\n", res->port_id);
11903                 break;
11904         default:
11905                 printf("programming error: (%s)\n", strerror(-ret));
11906         }
11907 }
11908
11909 cmdline_parse_inst_t cmd_set_macsec_sa = {
11910         .f = cmd_set_macsec_sa_parsed,
11911         .data = NULL,
11912         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
11913         .tokens = {
11914                 (void *)&cmd_macsec_sa_set,
11915                 (void *)&cmd_macsec_sa_macsec,
11916                 (void *)&cmd_macsec_sa_sa,
11917                 (void *)&cmd_macsec_sa_tx_rx,
11918                 (void *)&cmd_macsec_sa_port_id,
11919                 (void *)&cmd_macsec_sa_idx,
11920                 (void *)&cmd_macsec_sa_an,
11921                 (void *)&cmd_macsec_sa_pn,
11922                 (void *)&cmd_macsec_sa_key,
11923                 NULL,
11924         },
11925 };
11926
11927 /* VF unicast promiscuous mode configuration */
11928
11929 /* Common result structure for VF unicast promiscuous mode */
11930 struct cmd_vf_promisc_result {
11931         cmdline_fixed_string_t set;
11932         cmdline_fixed_string_t vf;
11933         cmdline_fixed_string_t promisc;
11934         portid_t port_id;
11935         uint32_t vf_id;
11936         cmdline_fixed_string_t on_off;
11937 };
11938
11939 /* Common CLI fields for VF unicast promiscuous mode enable disable */
11940 cmdline_parse_token_string_t cmd_vf_promisc_set =
11941         TOKEN_STRING_INITIALIZER
11942                 (struct cmd_vf_promisc_result,
11943                  set, "set");
11944 cmdline_parse_token_string_t cmd_vf_promisc_vf =
11945         TOKEN_STRING_INITIALIZER
11946                 (struct cmd_vf_promisc_result,
11947                  vf, "vf");
11948 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
11949         TOKEN_STRING_INITIALIZER
11950                 (struct cmd_vf_promisc_result,
11951                  promisc, "promisc");
11952 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
11953         TOKEN_NUM_INITIALIZER
11954                 (struct cmd_vf_promisc_result,
11955                  port_id, RTE_UINT16);
11956 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
11957         TOKEN_NUM_INITIALIZER
11958                 (struct cmd_vf_promisc_result,
11959                  vf_id, RTE_UINT32);
11960 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
11961         TOKEN_STRING_INITIALIZER
11962                 (struct cmd_vf_promisc_result,
11963                  on_off, "on#off");
11964
11965 static void
11966 cmd_set_vf_promisc_parsed(
11967         void *parsed_result,
11968         __rte_unused struct cmdline *cl,
11969         __rte_unused void *data)
11970 {
11971         struct cmd_vf_promisc_result *res = parsed_result;
11972         int ret = -ENOTSUP;
11973
11974         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11975
11976         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11977                 return;
11978
11979 #ifdef RTE_NET_I40E
11980         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
11981                                                   res->vf_id, is_on);
11982 #endif
11983
11984         switch (ret) {
11985         case 0:
11986                 break;
11987         case -EINVAL:
11988                 printf("invalid vf_id %d\n", res->vf_id);
11989                 break;
11990         case -ENODEV:
11991                 printf("invalid port_id %d\n", res->port_id);
11992                 break;
11993         case -ENOTSUP:
11994                 printf("function not implemented\n");
11995                 break;
11996         default:
11997                 printf("programming error: (%s)\n", strerror(-ret));
11998         }
11999 }
12000
12001 cmdline_parse_inst_t cmd_set_vf_promisc = {
12002         .f = cmd_set_vf_promisc_parsed,
12003         .data = NULL,
12004         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12005                 "Set unicast promiscuous mode for a VF from the PF",
12006         .tokens = {
12007                 (void *)&cmd_vf_promisc_set,
12008                 (void *)&cmd_vf_promisc_vf,
12009                 (void *)&cmd_vf_promisc_promisc,
12010                 (void *)&cmd_vf_promisc_port_id,
12011                 (void *)&cmd_vf_promisc_vf_id,
12012                 (void *)&cmd_vf_promisc_on_off,
12013                 NULL,
12014         },
12015 };
12016
12017 /* VF multicast promiscuous mode configuration */
12018
12019 /* Common result structure for VF multicast promiscuous mode */
12020 struct cmd_vf_allmulti_result {
12021         cmdline_fixed_string_t set;
12022         cmdline_fixed_string_t vf;
12023         cmdline_fixed_string_t allmulti;
12024         portid_t port_id;
12025         uint32_t vf_id;
12026         cmdline_fixed_string_t on_off;
12027 };
12028
12029 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12030 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12031         TOKEN_STRING_INITIALIZER
12032                 (struct cmd_vf_allmulti_result,
12033                  set, "set");
12034 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12035         TOKEN_STRING_INITIALIZER
12036                 (struct cmd_vf_allmulti_result,
12037                  vf, "vf");
12038 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12039         TOKEN_STRING_INITIALIZER
12040                 (struct cmd_vf_allmulti_result,
12041                  allmulti, "allmulti");
12042 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12043         TOKEN_NUM_INITIALIZER
12044                 (struct cmd_vf_allmulti_result,
12045                  port_id, RTE_UINT16);
12046 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12047         TOKEN_NUM_INITIALIZER
12048                 (struct cmd_vf_allmulti_result,
12049                  vf_id, RTE_UINT32);
12050 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12051         TOKEN_STRING_INITIALIZER
12052                 (struct cmd_vf_allmulti_result,
12053                  on_off, "on#off");
12054
12055 static void
12056 cmd_set_vf_allmulti_parsed(
12057         void *parsed_result,
12058         __rte_unused struct cmdline *cl,
12059         __rte_unused void *data)
12060 {
12061         struct cmd_vf_allmulti_result *res = parsed_result;
12062         int ret = -ENOTSUP;
12063
12064         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12065
12066         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12067                 return;
12068
12069 #ifdef RTE_NET_I40E
12070         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12071                                                     res->vf_id, is_on);
12072 #endif
12073
12074         switch (ret) {
12075         case 0:
12076                 break;
12077         case -EINVAL:
12078                 printf("invalid vf_id %d\n", res->vf_id);
12079                 break;
12080         case -ENODEV:
12081                 printf("invalid port_id %d\n", res->port_id);
12082                 break;
12083         case -ENOTSUP:
12084                 printf("function not implemented\n");
12085                 break;
12086         default:
12087                 printf("programming error: (%s)\n", strerror(-ret));
12088         }
12089 }
12090
12091 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12092         .f = cmd_set_vf_allmulti_parsed,
12093         .data = NULL,
12094         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12095                 "Set multicast promiscuous mode for a VF from the PF",
12096         .tokens = {
12097                 (void *)&cmd_vf_allmulti_set,
12098                 (void *)&cmd_vf_allmulti_vf,
12099                 (void *)&cmd_vf_allmulti_allmulti,
12100                 (void *)&cmd_vf_allmulti_port_id,
12101                 (void *)&cmd_vf_allmulti_vf_id,
12102                 (void *)&cmd_vf_allmulti_on_off,
12103                 NULL,
12104         },
12105 };
12106
12107 /* vf broadcast mode configuration */
12108
12109 /* Common result structure for vf broadcast */
12110 struct cmd_set_vf_broadcast_result {
12111         cmdline_fixed_string_t set;
12112         cmdline_fixed_string_t vf;
12113         cmdline_fixed_string_t broadcast;
12114         portid_t port_id;
12115         uint16_t vf_id;
12116         cmdline_fixed_string_t on_off;
12117 };
12118
12119 /* Common CLI fields for vf broadcast enable disable */
12120 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12121         TOKEN_STRING_INITIALIZER
12122                 (struct cmd_set_vf_broadcast_result,
12123                  set, "set");
12124 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12125         TOKEN_STRING_INITIALIZER
12126                 (struct cmd_set_vf_broadcast_result,
12127                  vf, "vf");
12128 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12129         TOKEN_STRING_INITIALIZER
12130                 (struct cmd_set_vf_broadcast_result,
12131                  broadcast, "broadcast");
12132 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12133         TOKEN_NUM_INITIALIZER
12134                 (struct cmd_set_vf_broadcast_result,
12135                  port_id, RTE_UINT16);
12136 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12137         TOKEN_NUM_INITIALIZER
12138                 (struct cmd_set_vf_broadcast_result,
12139                  vf_id, RTE_UINT16);
12140 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12141         TOKEN_STRING_INITIALIZER
12142                 (struct cmd_set_vf_broadcast_result,
12143                  on_off, "on#off");
12144
12145 static void
12146 cmd_set_vf_broadcast_parsed(
12147         void *parsed_result,
12148         __rte_unused struct cmdline *cl,
12149         __rte_unused void *data)
12150 {
12151         struct cmd_set_vf_broadcast_result *res = parsed_result;
12152         int ret = -ENOTSUP;
12153
12154         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12155
12156         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12157                 return;
12158
12159 #ifdef RTE_NET_I40E
12160         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12161                                             res->vf_id, is_on);
12162 #endif
12163
12164         switch (ret) {
12165         case 0:
12166                 break;
12167         case -EINVAL:
12168                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12169                 break;
12170         case -ENODEV:
12171                 printf("invalid port_id %d\n", res->port_id);
12172                 break;
12173         case -ENOTSUP:
12174                 printf("function not implemented\n");
12175                 break;
12176         default:
12177                 printf("programming error: (%s)\n", strerror(-ret));
12178         }
12179 }
12180
12181 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12182         .f = cmd_set_vf_broadcast_parsed,
12183         .data = NULL,
12184         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12185         .tokens = {
12186                 (void *)&cmd_set_vf_broadcast_set,
12187                 (void *)&cmd_set_vf_broadcast_vf,
12188                 (void *)&cmd_set_vf_broadcast_broadcast,
12189                 (void *)&cmd_set_vf_broadcast_port_id,
12190                 (void *)&cmd_set_vf_broadcast_vf_id,
12191                 (void *)&cmd_set_vf_broadcast_on_off,
12192                 NULL,
12193         },
12194 };
12195
12196 /* vf vlan tag configuration */
12197
12198 /* Common result structure for vf vlan tag */
12199 struct cmd_set_vf_vlan_tag_result {
12200         cmdline_fixed_string_t set;
12201         cmdline_fixed_string_t vf;
12202         cmdline_fixed_string_t vlan;
12203         cmdline_fixed_string_t tag;
12204         portid_t port_id;
12205         uint16_t vf_id;
12206         cmdline_fixed_string_t on_off;
12207 };
12208
12209 /* Common CLI fields for vf vlan tag enable disable */
12210 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12211         TOKEN_STRING_INITIALIZER
12212                 (struct cmd_set_vf_vlan_tag_result,
12213                  set, "set");
12214 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12215         TOKEN_STRING_INITIALIZER
12216                 (struct cmd_set_vf_vlan_tag_result,
12217                  vf, "vf");
12218 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12219         TOKEN_STRING_INITIALIZER
12220                 (struct cmd_set_vf_vlan_tag_result,
12221                  vlan, "vlan");
12222 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12223         TOKEN_STRING_INITIALIZER
12224                 (struct cmd_set_vf_vlan_tag_result,
12225                  tag, "tag");
12226 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12227         TOKEN_NUM_INITIALIZER
12228                 (struct cmd_set_vf_vlan_tag_result,
12229                  port_id, RTE_UINT16);
12230 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12231         TOKEN_NUM_INITIALIZER
12232                 (struct cmd_set_vf_vlan_tag_result,
12233                  vf_id, RTE_UINT16);
12234 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12235         TOKEN_STRING_INITIALIZER
12236                 (struct cmd_set_vf_vlan_tag_result,
12237                  on_off, "on#off");
12238
12239 static void
12240 cmd_set_vf_vlan_tag_parsed(
12241         void *parsed_result,
12242         __rte_unused struct cmdline *cl,
12243         __rte_unused void *data)
12244 {
12245         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12246         int ret = -ENOTSUP;
12247
12248         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12249
12250         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12251                 return;
12252
12253 #ifdef RTE_NET_I40E
12254         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12255                                            res->vf_id, is_on);
12256 #endif
12257
12258         switch (ret) {
12259         case 0:
12260                 break;
12261         case -EINVAL:
12262                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12263                 break;
12264         case -ENODEV:
12265                 printf("invalid port_id %d\n", res->port_id);
12266                 break;
12267         case -ENOTSUP:
12268                 printf("function not implemented\n");
12269                 break;
12270         default:
12271                 printf("programming error: (%s)\n", strerror(-ret));
12272         }
12273 }
12274
12275 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12276         .f = cmd_set_vf_vlan_tag_parsed,
12277         .data = NULL,
12278         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12279         .tokens = {
12280                 (void *)&cmd_set_vf_vlan_tag_set,
12281                 (void *)&cmd_set_vf_vlan_tag_vf,
12282                 (void *)&cmd_set_vf_vlan_tag_vlan,
12283                 (void *)&cmd_set_vf_vlan_tag_tag,
12284                 (void *)&cmd_set_vf_vlan_tag_port_id,
12285                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12286                 (void *)&cmd_set_vf_vlan_tag_on_off,
12287                 NULL,
12288         },
12289 };
12290
12291 /* Common definition of VF and TC TX bandwidth configuration */
12292 struct cmd_vf_tc_bw_result {
12293         cmdline_fixed_string_t set;
12294         cmdline_fixed_string_t vf;
12295         cmdline_fixed_string_t tc;
12296         cmdline_fixed_string_t tx;
12297         cmdline_fixed_string_t min_bw;
12298         cmdline_fixed_string_t max_bw;
12299         cmdline_fixed_string_t strict_link_prio;
12300         portid_t port_id;
12301         uint16_t vf_id;
12302         uint8_t tc_no;
12303         uint32_t bw;
12304         cmdline_fixed_string_t bw_list;
12305         uint8_t tc_map;
12306 };
12307
12308 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12309         TOKEN_STRING_INITIALIZER
12310                 (struct cmd_vf_tc_bw_result,
12311                  set, "set");
12312 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12313         TOKEN_STRING_INITIALIZER
12314                 (struct cmd_vf_tc_bw_result,
12315                  vf, "vf");
12316 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12317         TOKEN_STRING_INITIALIZER
12318                 (struct cmd_vf_tc_bw_result,
12319                  tc, "tc");
12320 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12321         TOKEN_STRING_INITIALIZER
12322                 (struct cmd_vf_tc_bw_result,
12323                  tx, "tx");
12324 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12325         TOKEN_STRING_INITIALIZER
12326                 (struct cmd_vf_tc_bw_result,
12327                  strict_link_prio, "strict-link-priority");
12328 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12329         TOKEN_STRING_INITIALIZER
12330                 (struct cmd_vf_tc_bw_result,
12331                  min_bw, "min-bandwidth");
12332 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12333         TOKEN_STRING_INITIALIZER
12334                 (struct cmd_vf_tc_bw_result,
12335                  max_bw, "max-bandwidth");
12336 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12337         TOKEN_NUM_INITIALIZER
12338                 (struct cmd_vf_tc_bw_result,
12339                  port_id, RTE_UINT16);
12340 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12341         TOKEN_NUM_INITIALIZER
12342                 (struct cmd_vf_tc_bw_result,
12343                  vf_id, RTE_UINT16);
12344 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12345         TOKEN_NUM_INITIALIZER
12346                 (struct cmd_vf_tc_bw_result,
12347                  tc_no, RTE_UINT8);
12348 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12349         TOKEN_NUM_INITIALIZER
12350                 (struct cmd_vf_tc_bw_result,
12351                  bw, RTE_UINT32);
12352 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12353         TOKEN_STRING_INITIALIZER
12354                 (struct cmd_vf_tc_bw_result,
12355                  bw_list, NULL);
12356 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12357         TOKEN_NUM_INITIALIZER
12358                 (struct cmd_vf_tc_bw_result,
12359                  tc_map, RTE_UINT8);
12360
12361 /* VF max bandwidth setting */
12362 static void
12363 cmd_vf_max_bw_parsed(
12364         void *parsed_result,
12365         __rte_unused struct cmdline *cl,
12366         __rte_unused void *data)
12367 {
12368         struct cmd_vf_tc_bw_result *res = parsed_result;
12369         int ret = -ENOTSUP;
12370
12371         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12372                 return;
12373
12374 #ifdef RTE_NET_I40E
12375         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12376                                          res->vf_id, res->bw);
12377 #endif
12378
12379         switch (ret) {
12380         case 0:
12381                 break;
12382         case -EINVAL:
12383                 printf("invalid vf_id %d or bandwidth %d\n",
12384                        res->vf_id, res->bw);
12385                 break;
12386         case -ENODEV:
12387                 printf("invalid port_id %d\n", res->port_id);
12388                 break;
12389         case -ENOTSUP:
12390                 printf("function not implemented\n");
12391                 break;
12392         default:
12393                 printf("programming error: (%s)\n", strerror(-ret));
12394         }
12395 }
12396
12397 cmdline_parse_inst_t cmd_vf_max_bw = {
12398         .f = cmd_vf_max_bw_parsed,
12399         .data = NULL,
12400         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12401         .tokens = {
12402                 (void *)&cmd_vf_tc_bw_set,
12403                 (void *)&cmd_vf_tc_bw_vf,
12404                 (void *)&cmd_vf_tc_bw_tx,
12405                 (void *)&cmd_vf_tc_bw_max_bw,
12406                 (void *)&cmd_vf_tc_bw_port_id,
12407                 (void *)&cmd_vf_tc_bw_vf_id,
12408                 (void *)&cmd_vf_tc_bw_bw,
12409                 NULL,
12410         },
12411 };
12412
12413 static int
12414 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12415                            uint8_t *tc_num,
12416                            char *str)
12417 {
12418         uint32_t size;
12419         const char *p, *p0 = str;
12420         char s[256];
12421         char *end;
12422         char *str_fld[16];
12423         uint16_t i;
12424         int ret;
12425
12426         p = strchr(p0, '(');
12427         if (p == NULL) {
12428                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12429                 return -1;
12430         }
12431         p++;
12432         p0 = strchr(p, ')');
12433         if (p0 == NULL) {
12434                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12435                 return -1;
12436         }
12437         size = p0 - p;
12438         if (size >= sizeof(s)) {
12439                 printf("The string size exceeds the internal buffer size\n");
12440                 return -1;
12441         }
12442         snprintf(s, sizeof(s), "%.*s", size, p);
12443         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12444         if (ret <= 0) {
12445                 printf("Failed to get the bandwidth list. ");
12446                 return -1;
12447         }
12448         *tc_num = ret;
12449         for (i = 0; i < ret; i++)
12450                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12451
12452         return 0;
12453 }
12454
12455 /* TC min bandwidth setting */
12456 static void
12457 cmd_vf_tc_min_bw_parsed(
12458         void *parsed_result,
12459         __rte_unused struct cmdline *cl,
12460         __rte_unused void *data)
12461 {
12462         struct cmd_vf_tc_bw_result *res = parsed_result;
12463         uint8_t tc_num;
12464         uint8_t bw[16];
12465         int ret = -ENOTSUP;
12466
12467         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12468                 return;
12469
12470         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12471         if (ret)
12472                 return;
12473
12474 #ifdef RTE_NET_I40E
12475         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12476                                               tc_num, bw);
12477 #endif
12478
12479         switch (ret) {
12480         case 0:
12481                 break;
12482         case -EINVAL:
12483                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12484                 break;
12485         case -ENODEV:
12486                 printf("invalid port_id %d\n", res->port_id);
12487                 break;
12488         case -ENOTSUP:
12489                 printf("function not implemented\n");
12490                 break;
12491         default:
12492                 printf("programming error: (%s)\n", strerror(-ret));
12493         }
12494 }
12495
12496 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12497         .f = cmd_vf_tc_min_bw_parsed,
12498         .data = NULL,
12499         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12500                     " <bw1, bw2, ...>",
12501         .tokens = {
12502                 (void *)&cmd_vf_tc_bw_set,
12503                 (void *)&cmd_vf_tc_bw_vf,
12504                 (void *)&cmd_vf_tc_bw_tc,
12505                 (void *)&cmd_vf_tc_bw_tx,
12506                 (void *)&cmd_vf_tc_bw_min_bw,
12507                 (void *)&cmd_vf_tc_bw_port_id,
12508                 (void *)&cmd_vf_tc_bw_vf_id,
12509                 (void *)&cmd_vf_tc_bw_bw_list,
12510                 NULL,
12511         },
12512 };
12513
12514 static void
12515 cmd_tc_min_bw_parsed(
12516         void *parsed_result,
12517         __rte_unused struct cmdline *cl,
12518         __rte_unused void *data)
12519 {
12520         struct cmd_vf_tc_bw_result *res = parsed_result;
12521         struct rte_port *port;
12522         uint8_t tc_num;
12523         uint8_t bw[16];
12524         int ret = -ENOTSUP;
12525
12526         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12527                 return;
12528
12529         port = &ports[res->port_id];
12530         /** Check if the port is not started **/
12531         if (port->port_status != RTE_PORT_STOPPED) {
12532                 printf("Please stop port %d first\n", res->port_id);
12533                 return;
12534         }
12535
12536         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12537         if (ret)
12538                 return;
12539
12540 #ifdef RTE_NET_IXGBE
12541         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12542 #endif
12543
12544         switch (ret) {
12545         case 0:
12546                 break;
12547         case -EINVAL:
12548                 printf("invalid bandwidth\n");
12549                 break;
12550         case -ENODEV:
12551                 printf("invalid port_id %d\n", res->port_id);
12552                 break;
12553         case -ENOTSUP:
12554                 printf("function not implemented\n");
12555                 break;
12556         default:
12557                 printf("programming error: (%s)\n", strerror(-ret));
12558         }
12559 }
12560
12561 cmdline_parse_inst_t cmd_tc_min_bw = {
12562         .f = cmd_tc_min_bw_parsed,
12563         .data = NULL,
12564         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12565         .tokens = {
12566                 (void *)&cmd_vf_tc_bw_set,
12567                 (void *)&cmd_vf_tc_bw_tc,
12568                 (void *)&cmd_vf_tc_bw_tx,
12569                 (void *)&cmd_vf_tc_bw_min_bw,
12570                 (void *)&cmd_vf_tc_bw_port_id,
12571                 (void *)&cmd_vf_tc_bw_bw_list,
12572                 NULL,
12573         },
12574 };
12575
12576 /* TC max bandwidth setting */
12577 static void
12578 cmd_vf_tc_max_bw_parsed(
12579         void *parsed_result,
12580         __rte_unused struct cmdline *cl,
12581         __rte_unused void *data)
12582 {
12583         struct cmd_vf_tc_bw_result *res = parsed_result;
12584         int ret = -ENOTSUP;
12585
12586         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12587                 return;
12588
12589 #ifdef RTE_NET_I40E
12590         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12591                                             res->tc_no, res->bw);
12592 #endif
12593
12594         switch (ret) {
12595         case 0:
12596                 break;
12597         case -EINVAL:
12598                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12599                        res->vf_id, res->tc_no, res->bw);
12600                 break;
12601         case -ENODEV:
12602                 printf("invalid port_id %d\n", res->port_id);
12603                 break;
12604         case -ENOTSUP:
12605                 printf("function not implemented\n");
12606                 break;
12607         default:
12608                 printf("programming error: (%s)\n", strerror(-ret));
12609         }
12610 }
12611
12612 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12613         .f = cmd_vf_tc_max_bw_parsed,
12614         .data = NULL,
12615         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12616                     " <bandwidth>",
12617         .tokens = {
12618                 (void *)&cmd_vf_tc_bw_set,
12619                 (void *)&cmd_vf_tc_bw_vf,
12620                 (void *)&cmd_vf_tc_bw_tc,
12621                 (void *)&cmd_vf_tc_bw_tx,
12622                 (void *)&cmd_vf_tc_bw_max_bw,
12623                 (void *)&cmd_vf_tc_bw_port_id,
12624                 (void *)&cmd_vf_tc_bw_vf_id,
12625                 (void *)&cmd_vf_tc_bw_tc_no,
12626                 (void *)&cmd_vf_tc_bw_bw,
12627                 NULL,
12628         },
12629 };
12630
12631 /** Set VXLAN encapsulation details */
12632 struct cmd_set_vxlan_result {
12633         cmdline_fixed_string_t set;
12634         cmdline_fixed_string_t vxlan;
12635         cmdline_fixed_string_t pos_token;
12636         cmdline_fixed_string_t ip_version;
12637         uint32_t vlan_present:1;
12638         uint32_t vni;
12639         uint16_t udp_src;
12640         uint16_t udp_dst;
12641         cmdline_ipaddr_t ip_src;
12642         cmdline_ipaddr_t ip_dst;
12643         uint16_t tci;
12644         uint8_t tos;
12645         uint8_t ttl;
12646         struct rte_ether_addr eth_src;
12647         struct rte_ether_addr eth_dst;
12648 };
12649
12650 cmdline_parse_token_string_t cmd_set_vxlan_set =
12651         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12652 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12653         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12654 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12655         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12656                                  "vxlan-tos-ttl");
12657 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12658         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12659                                  "vxlan-with-vlan");
12660 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12661         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12662                                  "ip-version");
12663 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12664         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12665                                  "ipv4#ipv6");
12666 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12667         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12668                                  "vni");
12669 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12670         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12671 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12672         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12673                                  "udp-src");
12674 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12675         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12676 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12677         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12678                                  "udp-dst");
12679 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12680         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12681 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12682         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12683                                  "ip-tos");
12684 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12685         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12686 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12687         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12688                                  "ip-ttl");
12689 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12690         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12691 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12692         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12693                                  "ip-src");
12694 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12695         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12696 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12697         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12698                                  "ip-dst");
12699 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12700         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12701 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12702         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12703                                  "vlan-tci");
12704 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12705         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12706 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12707         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12708                                  "eth-src");
12709 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12710         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12711 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12712         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12713                                  "eth-dst");
12714 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12715         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12716
12717 static void cmd_set_vxlan_parsed(void *parsed_result,
12718         __rte_unused struct cmdline *cl,
12719         __rte_unused void *data)
12720 {
12721         struct cmd_set_vxlan_result *res = parsed_result;
12722         union {
12723                 uint32_t vxlan_id;
12724                 uint8_t vni[4];
12725         } id = {
12726                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12727         };
12728
12729         vxlan_encap_conf.select_tos_ttl = 0;
12730         if (strcmp(res->vxlan, "vxlan") == 0)
12731                 vxlan_encap_conf.select_vlan = 0;
12732         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12733                 vxlan_encap_conf.select_vlan = 1;
12734         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12735                 vxlan_encap_conf.select_vlan = 0;
12736                 vxlan_encap_conf.select_tos_ttl = 1;
12737         }
12738         if (strcmp(res->ip_version, "ipv4") == 0)
12739                 vxlan_encap_conf.select_ipv4 = 1;
12740         else if (strcmp(res->ip_version, "ipv6") == 0)
12741                 vxlan_encap_conf.select_ipv4 = 0;
12742         else
12743                 return;
12744         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12745         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12746         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
12747         vxlan_encap_conf.ip_tos = res->tos;
12748         vxlan_encap_conf.ip_ttl = res->ttl;
12749         if (vxlan_encap_conf.select_ipv4) {
12750                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
12751                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
12752         } else {
12753                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
12754                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
12755         }
12756         if (vxlan_encap_conf.select_vlan)
12757                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12758         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
12759                    RTE_ETHER_ADDR_LEN);
12760         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12761                    RTE_ETHER_ADDR_LEN);
12762 }
12763
12764 cmdline_parse_inst_t cmd_set_vxlan = {
12765         .f = cmd_set_vxlan_parsed,
12766         .data = NULL,
12767         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
12768                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
12769                 " eth-src <eth-src> eth-dst <eth-dst>",
12770         .tokens = {
12771                 (void *)&cmd_set_vxlan_set,
12772                 (void *)&cmd_set_vxlan_vxlan,
12773                 (void *)&cmd_set_vxlan_ip_version,
12774                 (void *)&cmd_set_vxlan_ip_version_value,
12775                 (void *)&cmd_set_vxlan_vni,
12776                 (void *)&cmd_set_vxlan_vni_value,
12777                 (void *)&cmd_set_vxlan_udp_src,
12778                 (void *)&cmd_set_vxlan_udp_src_value,
12779                 (void *)&cmd_set_vxlan_udp_dst,
12780                 (void *)&cmd_set_vxlan_udp_dst_value,
12781                 (void *)&cmd_set_vxlan_ip_src,
12782                 (void *)&cmd_set_vxlan_ip_src_value,
12783                 (void *)&cmd_set_vxlan_ip_dst,
12784                 (void *)&cmd_set_vxlan_ip_dst_value,
12785                 (void *)&cmd_set_vxlan_eth_src,
12786                 (void *)&cmd_set_vxlan_eth_src_value,
12787                 (void *)&cmd_set_vxlan_eth_dst,
12788                 (void *)&cmd_set_vxlan_eth_dst_value,
12789                 NULL,
12790         },
12791 };
12792
12793 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
12794         .f = cmd_set_vxlan_parsed,
12795         .data = NULL,
12796         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
12797                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
12798                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12799                 " eth-dst <eth-dst>",
12800         .tokens = {
12801                 (void *)&cmd_set_vxlan_set,
12802                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
12803                 (void *)&cmd_set_vxlan_ip_version,
12804                 (void *)&cmd_set_vxlan_ip_version_value,
12805                 (void *)&cmd_set_vxlan_vni,
12806                 (void *)&cmd_set_vxlan_vni_value,
12807                 (void *)&cmd_set_vxlan_udp_src,
12808                 (void *)&cmd_set_vxlan_udp_src_value,
12809                 (void *)&cmd_set_vxlan_udp_dst,
12810                 (void *)&cmd_set_vxlan_udp_dst_value,
12811                 (void *)&cmd_set_vxlan_ip_tos,
12812                 (void *)&cmd_set_vxlan_ip_tos_value,
12813                 (void *)&cmd_set_vxlan_ip_ttl,
12814                 (void *)&cmd_set_vxlan_ip_ttl_value,
12815                 (void *)&cmd_set_vxlan_ip_src,
12816                 (void *)&cmd_set_vxlan_ip_src_value,
12817                 (void *)&cmd_set_vxlan_ip_dst,
12818                 (void *)&cmd_set_vxlan_ip_dst_value,
12819                 (void *)&cmd_set_vxlan_eth_src,
12820                 (void *)&cmd_set_vxlan_eth_src_value,
12821                 (void *)&cmd_set_vxlan_eth_dst,
12822                 (void *)&cmd_set_vxlan_eth_dst_value,
12823                 NULL,
12824         },
12825 };
12826
12827 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
12828         .f = cmd_set_vxlan_parsed,
12829         .data = NULL,
12830         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
12831                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
12832                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
12833                 " <eth-dst>",
12834         .tokens = {
12835                 (void *)&cmd_set_vxlan_set,
12836                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
12837                 (void *)&cmd_set_vxlan_ip_version,
12838                 (void *)&cmd_set_vxlan_ip_version_value,
12839                 (void *)&cmd_set_vxlan_vni,
12840                 (void *)&cmd_set_vxlan_vni_value,
12841                 (void *)&cmd_set_vxlan_udp_src,
12842                 (void *)&cmd_set_vxlan_udp_src_value,
12843                 (void *)&cmd_set_vxlan_udp_dst,
12844                 (void *)&cmd_set_vxlan_udp_dst_value,
12845                 (void *)&cmd_set_vxlan_ip_src,
12846                 (void *)&cmd_set_vxlan_ip_src_value,
12847                 (void *)&cmd_set_vxlan_ip_dst,
12848                 (void *)&cmd_set_vxlan_ip_dst_value,
12849                 (void *)&cmd_set_vxlan_vlan,
12850                 (void *)&cmd_set_vxlan_vlan_value,
12851                 (void *)&cmd_set_vxlan_eth_src,
12852                 (void *)&cmd_set_vxlan_eth_src_value,
12853                 (void *)&cmd_set_vxlan_eth_dst,
12854                 (void *)&cmd_set_vxlan_eth_dst_value,
12855                 NULL,
12856         },
12857 };
12858
12859 /** Set NVGRE encapsulation details */
12860 struct cmd_set_nvgre_result {
12861         cmdline_fixed_string_t set;
12862         cmdline_fixed_string_t nvgre;
12863         cmdline_fixed_string_t pos_token;
12864         cmdline_fixed_string_t ip_version;
12865         uint32_t tni;
12866         cmdline_ipaddr_t ip_src;
12867         cmdline_ipaddr_t ip_dst;
12868         uint16_t tci;
12869         struct rte_ether_addr eth_src;
12870         struct rte_ether_addr eth_dst;
12871 };
12872
12873 cmdline_parse_token_string_t cmd_set_nvgre_set =
12874         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
12875 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
12876         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
12877 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
12878         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
12879                                  "nvgre-with-vlan");
12880 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
12881         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12882                                  "ip-version");
12883 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
12884         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
12885                                  "ipv4#ipv6");
12886 cmdline_parse_token_string_t cmd_set_nvgre_tni =
12887         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12888                                  "tni");
12889 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
12890         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
12891 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
12892         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12893                                  "ip-src");
12894 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
12895         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
12896 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
12897         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12898                                  "ip-dst");
12899 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
12900         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
12901 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
12902         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12903                                  "vlan-tci");
12904 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
12905         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
12906 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
12907         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12908                                  "eth-src");
12909 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
12910         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
12911 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
12912         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
12913                                  "eth-dst");
12914 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
12915         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
12916
12917 static void cmd_set_nvgre_parsed(void *parsed_result,
12918         __rte_unused struct cmdline *cl,
12919         __rte_unused void *data)
12920 {
12921         struct cmd_set_nvgre_result *res = parsed_result;
12922         union {
12923                 uint32_t nvgre_tni;
12924                 uint8_t tni[4];
12925         } id = {
12926                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
12927         };
12928
12929         if (strcmp(res->nvgre, "nvgre") == 0)
12930                 nvgre_encap_conf.select_vlan = 0;
12931         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
12932                 nvgre_encap_conf.select_vlan = 1;
12933         if (strcmp(res->ip_version, "ipv4") == 0)
12934                 nvgre_encap_conf.select_ipv4 = 1;
12935         else if (strcmp(res->ip_version, "ipv6") == 0)
12936                 nvgre_encap_conf.select_ipv4 = 0;
12937         else
12938                 return;
12939         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
12940         if (nvgre_encap_conf.select_ipv4) {
12941                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
12942                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
12943         } else {
12944                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
12945                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
12946         }
12947         if (nvgre_encap_conf.select_vlan)
12948                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12949         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
12950                    RTE_ETHER_ADDR_LEN);
12951         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12952                    RTE_ETHER_ADDR_LEN);
12953 }
12954
12955 cmdline_parse_inst_t cmd_set_nvgre = {
12956         .f = cmd_set_nvgre_parsed,
12957         .data = NULL,
12958         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
12959                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12960                 " eth-dst <eth-dst>",
12961         .tokens = {
12962                 (void *)&cmd_set_nvgre_set,
12963                 (void *)&cmd_set_nvgre_nvgre,
12964                 (void *)&cmd_set_nvgre_ip_version,
12965                 (void *)&cmd_set_nvgre_ip_version_value,
12966                 (void *)&cmd_set_nvgre_tni,
12967                 (void *)&cmd_set_nvgre_tni_value,
12968                 (void *)&cmd_set_nvgre_ip_src,
12969                 (void *)&cmd_set_nvgre_ip_src_value,
12970                 (void *)&cmd_set_nvgre_ip_dst,
12971                 (void *)&cmd_set_nvgre_ip_dst_value,
12972                 (void *)&cmd_set_nvgre_eth_src,
12973                 (void *)&cmd_set_nvgre_eth_src_value,
12974                 (void *)&cmd_set_nvgre_eth_dst,
12975                 (void *)&cmd_set_nvgre_eth_dst_value,
12976                 NULL,
12977         },
12978 };
12979
12980 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
12981         .f = cmd_set_nvgre_parsed,
12982         .data = NULL,
12983         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
12984                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
12985                 " eth-src <eth-src> eth-dst <eth-dst>",
12986         .tokens = {
12987                 (void *)&cmd_set_nvgre_set,
12988                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
12989                 (void *)&cmd_set_nvgre_ip_version,
12990                 (void *)&cmd_set_nvgre_ip_version_value,
12991                 (void *)&cmd_set_nvgre_tni,
12992                 (void *)&cmd_set_nvgre_tni_value,
12993                 (void *)&cmd_set_nvgre_ip_src,
12994                 (void *)&cmd_set_nvgre_ip_src_value,
12995                 (void *)&cmd_set_nvgre_ip_dst,
12996                 (void *)&cmd_set_nvgre_ip_dst_value,
12997                 (void *)&cmd_set_nvgre_vlan,
12998                 (void *)&cmd_set_nvgre_vlan_value,
12999                 (void *)&cmd_set_nvgre_eth_src,
13000                 (void *)&cmd_set_nvgre_eth_src_value,
13001                 (void *)&cmd_set_nvgre_eth_dst,
13002                 (void *)&cmd_set_nvgre_eth_dst_value,
13003                 NULL,
13004         },
13005 };
13006
13007 /** Set L2 encapsulation details */
13008 struct cmd_set_l2_encap_result {
13009         cmdline_fixed_string_t set;
13010         cmdline_fixed_string_t l2_encap;
13011         cmdline_fixed_string_t pos_token;
13012         cmdline_fixed_string_t ip_version;
13013         uint32_t vlan_present:1;
13014         uint16_t tci;
13015         struct rte_ether_addr eth_src;
13016         struct rte_ether_addr eth_dst;
13017 };
13018
13019 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13020         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13021 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13022         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13023 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13024         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13025                                  "l2_encap-with-vlan");
13026 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13027         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13028                                  "ip-version");
13029 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13030         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13031                                  "ipv4#ipv6");
13032 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13033         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13034                                  "vlan-tci");
13035 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13036         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13037 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13038         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13039                                  "eth-src");
13040 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13041         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13042 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13043         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13044                                  "eth-dst");
13045 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13046         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13047
13048 static void cmd_set_l2_encap_parsed(void *parsed_result,
13049         __rte_unused struct cmdline *cl,
13050         __rte_unused void *data)
13051 {
13052         struct cmd_set_l2_encap_result *res = parsed_result;
13053
13054         if (strcmp(res->l2_encap, "l2_encap") == 0)
13055                 l2_encap_conf.select_vlan = 0;
13056         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13057                 l2_encap_conf.select_vlan = 1;
13058         if (strcmp(res->ip_version, "ipv4") == 0)
13059                 l2_encap_conf.select_ipv4 = 1;
13060         else if (strcmp(res->ip_version, "ipv6") == 0)
13061                 l2_encap_conf.select_ipv4 = 0;
13062         else
13063                 return;
13064         if (l2_encap_conf.select_vlan)
13065                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13066         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13067                    RTE_ETHER_ADDR_LEN);
13068         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13069                    RTE_ETHER_ADDR_LEN);
13070 }
13071
13072 cmdline_parse_inst_t cmd_set_l2_encap = {
13073         .f = cmd_set_l2_encap_parsed,
13074         .data = NULL,
13075         .help_str = "set l2_encap ip-version ipv4|ipv6"
13076                 " eth-src <eth-src> eth-dst <eth-dst>",
13077         .tokens = {
13078                 (void *)&cmd_set_l2_encap_set,
13079                 (void *)&cmd_set_l2_encap_l2_encap,
13080                 (void *)&cmd_set_l2_encap_ip_version,
13081                 (void *)&cmd_set_l2_encap_ip_version_value,
13082                 (void *)&cmd_set_l2_encap_eth_src,
13083                 (void *)&cmd_set_l2_encap_eth_src_value,
13084                 (void *)&cmd_set_l2_encap_eth_dst,
13085                 (void *)&cmd_set_l2_encap_eth_dst_value,
13086                 NULL,
13087         },
13088 };
13089
13090 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13091         .f = cmd_set_l2_encap_parsed,
13092         .data = NULL,
13093         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13094                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13095         .tokens = {
13096                 (void *)&cmd_set_l2_encap_set,
13097                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13098                 (void *)&cmd_set_l2_encap_ip_version,
13099                 (void *)&cmd_set_l2_encap_ip_version_value,
13100                 (void *)&cmd_set_l2_encap_vlan,
13101                 (void *)&cmd_set_l2_encap_vlan_value,
13102                 (void *)&cmd_set_l2_encap_eth_src,
13103                 (void *)&cmd_set_l2_encap_eth_src_value,
13104                 (void *)&cmd_set_l2_encap_eth_dst,
13105                 (void *)&cmd_set_l2_encap_eth_dst_value,
13106                 NULL,
13107         },
13108 };
13109
13110 /** Set L2 decapsulation details */
13111 struct cmd_set_l2_decap_result {
13112         cmdline_fixed_string_t set;
13113         cmdline_fixed_string_t l2_decap;
13114         cmdline_fixed_string_t pos_token;
13115         uint32_t vlan_present:1;
13116 };
13117
13118 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13119         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13120 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13121         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13122                                  "l2_decap");
13123 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13124         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13125                                  "l2_decap-with-vlan");
13126
13127 static void cmd_set_l2_decap_parsed(void *parsed_result,
13128         __rte_unused struct cmdline *cl,
13129         __rte_unused void *data)
13130 {
13131         struct cmd_set_l2_decap_result *res = parsed_result;
13132
13133         if (strcmp(res->l2_decap, "l2_decap") == 0)
13134                 l2_decap_conf.select_vlan = 0;
13135         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13136                 l2_decap_conf.select_vlan = 1;
13137 }
13138
13139 cmdline_parse_inst_t cmd_set_l2_decap = {
13140         .f = cmd_set_l2_decap_parsed,
13141         .data = NULL,
13142         .help_str = "set l2_decap",
13143         .tokens = {
13144                 (void *)&cmd_set_l2_decap_set,
13145                 (void *)&cmd_set_l2_decap_l2_decap,
13146                 NULL,
13147         },
13148 };
13149
13150 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13151         .f = cmd_set_l2_decap_parsed,
13152         .data = NULL,
13153         .help_str = "set l2_decap-with-vlan",
13154         .tokens = {
13155                 (void *)&cmd_set_l2_decap_set,
13156                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13157                 NULL,
13158         },
13159 };
13160
13161 /** Set MPLSoGRE encapsulation details */
13162 struct cmd_set_mplsogre_encap_result {
13163         cmdline_fixed_string_t set;
13164         cmdline_fixed_string_t mplsogre;
13165         cmdline_fixed_string_t pos_token;
13166         cmdline_fixed_string_t ip_version;
13167         uint32_t vlan_present:1;
13168         uint32_t label;
13169         cmdline_ipaddr_t ip_src;
13170         cmdline_ipaddr_t ip_dst;
13171         uint16_t tci;
13172         struct rte_ether_addr eth_src;
13173         struct rte_ether_addr eth_dst;
13174 };
13175
13176 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13177         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13178                                  "set");
13179 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13180         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13181                                  "mplsogre_encap");
13182 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13183         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13184                                  mplsogre, "mplsogre_encap-with-vlan");
13185 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13186         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13187                                  pos_token, "ip-version");
13188 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13189         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13190                                  ip_version, "ipv4#ipv6");
13191 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13192         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13193                                  pos_token, "label");
13194 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13195         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13196                               RTE_UINT32);
13197 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13198         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13199                                  pos_token, "ip-src");
13200 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13201         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13202 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13203         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13204                                  pos_token, "ip-dst");
13205 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13206         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13207 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13208         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13209                                  pos_token, "vlan-tci");
13210 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13211         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13212                               RTE_UINT16);
13213 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13214         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13215                                  pos_token, "eth-src");
13216 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13217         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13218                                     eth_src);
13219 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13220         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13221                                  pos_token, "eth-dst");
13222 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13223         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13224                                     eth_dst);
13225
13226 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13227         __rte_unused struct cmdline *cl,
13228         __rte_unused void *data)
13229 {
13230         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13231         union {
13232                 uint32_t mplsogre_label;
13233                 uint8_t label[4];
13234         } id = {
13235                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13236         };
13237
13238         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13239                 mplsogre_encap_conf.select_vlan = 0;
13240         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13241                 mplsogre_encap_conf.select_vlan = 1;
13242         if (strcmp(res->ip_version, "ipv4") == 0)
13243                 mplsogre_encap_conf.select_ipv4 = 1;
13244         else if (strcmp(res->ip_version, "ipv6") == 0)
13245                 mplsogre_encap_conf.select_ipv4 = 0;
13246         else
13247                 return;
13248         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13249         if (mplsogre_encap_conf.select_ipv4) {
13250                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13251                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13252         } else {
13253                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13254                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13255         }
13256         if (mplsogre_encap_conf.select_vlan)
13257                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13258         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13259                    RTE_ETHER_ADDR_LEN);
13260         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13261                    RTE_ETHER_ADDR_LEN);
13262 }
13263
13264 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13265         .f = cmd_set_mplsogre_encap_parsed,
13266         .data = NULL,
13267         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13268                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13269                 " eth-dst <eth-dst>",
13270         .tokens = {
13271                 (void *)&cmd_set_mplsogre_encap_set,
13272                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13273                 (void *)&cmd_set_mplsogre_encap_ip_version,
13274                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13275                 (void *)&cmd_set_mplsogre_encap_label,
13276                 (void *)&cmd_set_mplsogre_encap_label_value,
13277                 (void *)&cmd_set_mplsogre_encap_ip_src,
13278                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13279                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13280                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13281                 (void *)&cmd_set_mplsogre_encap_eth_src,
13282                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13283                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13284                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13285                 NULL,
13286         },
13287 };
13288
13289 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13290         .f = cmd_set_mplsogre_encap_parsed,
13291         .data = NULL,
13292         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13293                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13294                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13295         .tokens = {
13296                 (void *)&cmd_set_mplsogre_encap_set,
13297                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13298                 (void *)&cmd_set_mplsogre_encap_ip_version,
13299                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13300                 (void *)&cmd_set_mplsogre_encap_label,
13301                 (void *)&cmd_set_mplsogre_encap_label_value,
13302                 (void *)&cmd_set_mplsogre_encap_ip_src,
13303                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13304                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13305                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13306                 (void *)&cmd_set_mplsogre_encap_vlan,
13307                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13308                 (void *)&cmd_set_mplsogre_encap_eth_src,
13309                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13310                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13311                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13312                 NULL,
13313         },
13314 };
13315
13316 /** Set MPLSoGRE decapsulation details */
13317 struct cmd_set_mplsogre_decap_result {
13318         cmdline_fixed_string_t set;
13319         cmdline_fixed_string_t mplsogre;
13320         cmdline_fixed_string_t pos_token;
13321         cmdline_fixed_string_t ip_version;
13322         uint32_t vlan_present:1;
13323 };
13324
13325 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13326         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13327                                  "set");
13328 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13329         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13330                                  "mplsogre_decap");
13331 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13332         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13333                                  mplsogre, "mplsogre_decap-with-vlan");
13334 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13335         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13336                                  pos_token, "ip-version");
13337 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13338         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13339                                  ip_version, "ipv4#ipv6");
13340
13341 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13342         __rte_unused struct cmdline *cl,
13343         __rte_unused void *data)
13344 {
13345         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13346
13347         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13348                 mplsogre_decap_conf.select_vlan = 0;
13349         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13350                 mplsogre_decap_conf.select_vlan = 1;
13351         if (strcmp(res->ip_version, "ipv4") == 0)
13352                 mplsogre_decap_conf.select_ipv4 = 1;
13353         else if (strcmp(res->ip_version, "ipv6") == 0)
13354                 mplsogre_decap_conf.select_ipv4 = 0;
13355 }
13356
13357 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13358         .f = cmd_set_mplsogre_decap_parsed,
13359         .data = NULL,
13360         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13361         .tokens = {
13362                 (void *)&cmd_set_mplsogre_decap_set,
13363                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13364                 (void *)&cmd_set_mplsogre_decap_ip_version,
13365                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13366                 NULL,
13367         },
13368 };
13369
13370 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13371         .f = cmd_set_mplsogre_decap_parsed,
13372         .data = NULL,
13373         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13374         .tokens = {
13375                 (void *)&cmd_set_mplsogre_decap_set,
13376                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13377                 (void *)&cmd_set_mplsogre_decap_ip_version,
13378                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13379                 NULL,
13380         },
13381 };
13382
13383 /** Set MPLSoUDP encapsulation details */
13384 struct cmd_set_mplsoudp_encap_result {
13385         cmdline_fixed_string_t set;
13386         cmdline_fixed_string_t mplsoudp;
13387         cmdline_fixed_string_t pos_token;
13388         cmdline_fixed_string_t ip_version;
13389         uint32_t vlan_present:1;
13390         uint32_t label;
13391         uint16_t udp_src;
13392         uint16_t udp_dst;
13393         cmdline_ipaddr_t ip_src;
13394         cmdline_ipaddr_t ip_dst;
13395         uint16_t tci;
13396         struct rte_ether_addr eth_src;
13397         struct rte_ether_addr eth_dst;
13398 };
13399
13400 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13401         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13402                                  "set");
13403 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13404         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13405                                  "mplsoudp_encap");
13406 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13407         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13408                                  mplsoudp, "mplsoudp_encap-with-vlan");
13409 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13410         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13411                                  pos_token, "ip-version");
13412 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13413         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13414                                  ip_version, "ipv4#ipv6");
13415 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13416         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13417                                  pos_token, "label");
13418 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13419         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13420                               RTE_UINT32);
13421 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13422         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13423                                  pos_token, "udp-src");
13424 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13425         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13426                               RTE_UINT16);
13427 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13428         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13429                                  pos_token, "udp-dst");
13430 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13431         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13432                               RTE_UINT16);
13433 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13434         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13435                                  pos_token, "ip-src");
13436 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13437         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13438 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13439         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13440                                  pos_token, "ip-dst");
13441 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13442         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13443 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13444         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13445                                  pos_token, "vlan-tci");
13446 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13447         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13448                               RTE_UINT16);
13449 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13450         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13451                                  pos_token, "eth-src");
13452 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13453         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13454                                     eth_src);
13455 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13456         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13457                                  pos_token, "eth-dst");
13458 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13459         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13460                                     eth_dst);
13461
13462 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13463         __rte_unused struct cmdline *cl,
13464         __rte_unused void *data)
13465 {
13466         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13467         union {
13468                 uint32_t mplsoudp_label;
13469                 uint8_t label[4];
13470         } id = {
13471                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13472         };
13473
13474         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13475                 mplsoudp_encap_conf.select_vlan = 0;
13476         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13477                 mplsoudp_encap_conf.select_vlan = 1;
13478         if (strcmp(res->ip_version, "ipv4") == 0)
13479                 mplsoudp_encap_conf.select_ipv4 = 1;
13480         else if (strcmp(res->ip_version, "ipv6") == 0)
13481                 mplsoudp_encap_conf.select_ipv4 = 0;
13482         else
13483                 return;
13484         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13485         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13486         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13487         if (mplsoudp_encap_conf.select_ipv4) {
13488                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13489                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13490         } else {
13491                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13492                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13493         }
13494         if (mplsoudp_encap_conf.select_vlan)
13495                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13496         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13497                    RTE_ETHER_ADDR_LEN);
13498         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13499                    RTE_ETHER_ADDR_LEN);
13500 }
13501
13502 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13503         .f = cmd_set_mplsoudp_encap_parsed,
13504         .data = NULL,
13505         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13506                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13507                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13508         .tokens = {
13509                 (void *)&cmd_set_mplsoudp_encap_set,
13510                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13511                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13512                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13513                 (void *)&cmd_set_mplsoudp_encap_label,
13514                 (void *)&cmd_set_mplsoudp_encap_label_value,
13515                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13516                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13517                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13518                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13519                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13520                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13521                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13522                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13523                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13524                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13525                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13526                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13527                 NULL,
13528         },
13529 };
13530
13531 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13532         .f = cmd_set_mplsoudp_encap_parsed,
13533         .data = NULL,
13534         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13535                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13536                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13537                 " eth-src <eth-src> eth-dst <eth-dst>",
13538         .tokens = {
13539                 (void *)&cmd_set_mplsoudp_encap_set,
13540                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13541                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13542                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13543                 (void *)&cmd_set_mplsoudp_encap_label,
13544                 (void *)&cmd_set_mplsoudp_encap_label_value,
13545                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13546                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13547                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13548                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13549                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13550                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13551                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13552                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13553                 (void *)&cmd_set_mplsoudp_encap_vlan,
13554                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13555                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13556                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13557                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13558                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13559                 NULL,
13560         },
13561 };
13562
13563 /** Set MPLSoUDP decapsulation details */
13564 struct cmd_set_mplsoudp_decap_result {
13565         cmdline_fixed_string_t set;
13566         cmdline_fixed_string_t mplsoudp;
13567         cmdline_fixed_string_t pos_token;
13568         cmdline_fixed_string_t ip_version;
13569         uint32_t vlan_present:1;
13570 };
13571
13572 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13573         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13574                                  "set");
13575 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13576         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13577                                  "mplsoudp_decap");
13578 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13579         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13580                                  mplsoudp, "mplsoudp_decap-with-vlan");
13581 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13582         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13583                                  pos_token, "ip-version");
13584 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13585         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13586                                  ip_version, "ipv4#ipv6");
13587
13588 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13589         __rte_unused struct cmdline *cl,
13590         __rte_unused void *data)
13591 {
13592         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13593
13594         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13595                 mplsoudp_decap_conf.select_vlan = 0;
13596         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13597                 mplsoudp_decap_conf.select_vlan = 1;
13598         if (strcmp(res->ip_version, "ipv4") == 0)
13599                 mplsoudp_decap_conf.select_ipv4 = 1;
13600         else if (strcmp(res->ip_version, "ipv6") == 0)
13601                 mplsoudp_decap_conf.select_ipv4 = 0;
13602 }
13603
13604 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13605         .f = cmd_set_mplsoudp_decap_parsed,
13606         .data = NULL,
13607         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13608         .tokens = {
13609                 (void *)&cmd_set_mplsoudp_decap_set,
13610                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13611                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13612                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13613                 NULL,
13614         },
13615 };
13616
13617 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13618         .f = cmd_set_mplsoudp_decap_parsed,
13619         .data = NULL,
13620         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13621         .tokens = {
13622                 (void *)&cmd_set_mplsoudp_decap_set,
13623                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13624                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13625                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13626                 NULL,
13627         },
13628 };
13629
13630 /** Set connection tracking object common details */
13631 struct cmd_set_conntrack_common_result {
13632         cmdline_fixed_string_t set;
13633         cmdline_fixed_string_t conntrack;
13634         cmdline_fixed_string_t common;
13635         cmdline_fixed_string_t peer;
13636         cmdline_fixed_string_t is_orig;
13637         cmdline_fixed_string_t enable;
13638         cmdline_fixed_string_t live;
13639         cmdline_fixed_string_t sack;
13640         cmdline_fixed_string_t cack;
13641         cmdline_fixed_string_t last_dir;
13642         cmdline_fixed_string_t liberal;
13643         cmdline_fixed_string_t state;
13644         cmdline_fixed_string_t max_ack_win;
13645         cmdline_fixed_string_t retrans;
13646         cmdline_fixed_string_t last_win;
13647         cmdline_fixed_string_t last_seq;
13648         cmdline_fixed_string_t last_ack;
13649         cmdline_fixed_string_t last_end;
13650         cmdline_fixed_string_t last_index;
13651         uint8_t stat;
13652         uint8_t factor;
13653         uint16_t peer_port;
13654         uint32_t is_original;
13655         uint32_t en;
13656         uint32_t is_live;
13657         uint32_t s_ack;
13658         uint32_t c_ack;
13659         uint32_t ld;
13660         uint32_t lb;
13661         uint8_t re_num;
13662         uint8_t li;
13663         uint16_t lw;
13664         uint32_t ls;
13665         uint32_t la;
13666         uint32_t le;
13667 };
13668
13669 cmdline_parse_token_string_t cmd_set_conntrack_set =
13670         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13671                                  set, "set");
13672 cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
13673         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13674                                  conntrack, "conntrack");
13675 cmdline_parse_token_string_t cmd_set_conntrack_common_com =
13676         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13677                                  common, "com");
13678 cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
13679         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13680                                  peer, "peer");
13681 cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
13682         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13683                               peer_port, RTE_UINT16);
13684 cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
13685         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13686                                  is_orig, "is_orig");
13687 cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
13688         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13689                               is_original, RTE_UINT32);
13690 cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
13691         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13692                                  enable, "enable");
13693 cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
13694         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13695                               en, RTE_UINT32);
13696 cmdline_parse_token_string_t cmd_set_conntrack_common_live =
13697         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13698                                  live, "live");
13699 cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
13700         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13701                               is_live, RTE_UINT32);
13702 cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
13703         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13704                                  sack, "sack");
13705 cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
13706         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13707                               s_ack, RTE_UINT32);
13708 cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
13709         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13710                                  cack, "cack");
13711 cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
13712         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13713                               c_ack, RTE_UINT32);
13714 cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
13715         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13716                                  last_dir, "last_dir");
13717 cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
13718         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13719                               ld, RTE_UINT32);
13720 cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
13721         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13722                                  liberal, "liberal");
13723 cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
13724         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13725                               lb, RTE_UINT32);
13726 cmdline_parse_token_string_t cmd_set_conntrack_common_state =
13727         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13728                                  state, "state");
13729 cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
13730         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13731                               stat, RTE_UINT8);
13732 cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
13733         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13734                                  max_ack_win, "max_ack_win");
13735 cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
13736         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13737                               factor, RTE_UINT8);
13738 cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
13739         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13740                                  retrans, "r_lim");
13741 cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
13742         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13743                               re_num, RTE_UINT8);
13744 cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
13745         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13746                                  last_win, "last_win");
13747 cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
13748         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13749                               lw, RTE_UINT16);
13750 cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
13751         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13752                                  last_seq, "last_seq");
13753 cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
13754         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13755                               ls, RTE_UINT32);
13756 cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
13757         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13758                                  last_ack, "last_ack");
13759 cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
13760         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13761                               la, RTE_UINT32);
13762 cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
13763         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13764                                  last_end, "last_end");
13765 cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
13766         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13767                               le, RTE_UINT32);
13768 cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
13769         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13770                                  last_index, "last_index");
13771 cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
13772         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13773                               li, RTE_UINT8);
13774
13775 static void cmd_set_conntrack_common_parsed(void *parsed_result,
13776         __rte_unused struct cmdline *cl,
13777         __rte_unused void *data)
13778 {
13779         struct cmd_set_conntrack_common_result *res = parsed_result;
13780
13781         /* No need to swap to big endian. */
13782         conntrack_context.peer_port = res->peer_port;
13783         conntrack_context.is_original_dir = res->is_original;
13784         conntrack_context.enable = res->en;
13785         conntrack_context.live_connection = res->is_live;
13786         conntrack_context.selective_ack = res->s_ack;
13787         conntrack_context.challenge_ack_passed = res->c_ack;
13788         conntrack_context.last_direction = res->ld;
13789         conntrack_context.liberal_mode = res->lb;
13790         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
13791         conntrack_context.max_ack_window = res->factor;
13792         conntrack_context.retransmission_limit = res->re_num;
13793         conntrack_context.last_window = res->lw;
13794         conntrack_context.last_index =
13795                 (enum rte_flow_conntrack_tcp_last_index)res->li;
13796         conntrack_context.last_seq = res->ls;
13797         conntrack_context.last_ack = res->la;
13798         conntrack_context.last_end = res->le;
13799 }
13800
13801 cmdline_parse_inst_t cmd_set_conntrack_common = {
13802         .f = cmd_set_conntrack_common_parsed,
13803         .data = NULL,
13804         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
13805                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
13806                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
13807                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
13808                 " last_index <flag>",
13809         .tokens = {
13810                 (void *)&cmd_set_conntrack_set,
13811                 (void *)&cmd_set_conntrack_conntrack,
13812                 (void *)&cmd_set_conntrack_common_com,
13813                 (void *)&cmd_set_conntrack_common_peer,
13814                 (void *)&cmd_set_conntrack_common_peer_value,
13815                 (void *)&cmd_set_conntrack_common_is_orig,
13816                 (void *)&cmd_set_conntrack_common_is_orig_value,
13817                 (void *)&cmd_set_conntrack_common_enable,
13818                 (void *)&cmd_set_conntrack_common_enable_value,
13819                 (void *)&cmd_set_conntrack_common_live,
13820                 (void *)&cmd_set_conntrack_common_live_value,
13821                 (void *)&cmd_set_conntrack_common_sack,
13822                 (void *)&cmd_set_conntrack_common_sack_value,
13823                 (void *)&cmd_set_conntrack_common_cack,
13824                 (void *)&cmd_set_conntrack_common_cack_value,
13825                 (void *)&cmd_set_conntrack_common_last_dir,
13826                 (void *)&cmd_set_conntrack_common_last_dir_value,
13827                 (void *)&cmd_set_conntrack_common_liberal,
13828                 (void *)&cmd_set_conntrack_common_liberal_value,
13829                 (void *)&cmd_set_conntrack_common_state,
13830                 (void *)&cmd_set_conntrack_common_state_value,
13831                 (void *)&cmd_set_conntrack_common_max_ackwin,
13832                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
13833                 (void *)&cmd_set_conntrack_common_retrans,
13834                 (void *)&cmd_set_conntrack_common_retrans_value,
13835                 (void *)&cmd_set_conntrack_common_last_win,
13836                 (void *)&cmd_set_conntrack_common_last_win_value,
13837                 (void *)&cmd_set_conntrack_common_last_seq,
13838                 (void *)&cmd_set_conntrack_common_last_seq_value,
13839                 (void *)&cmd_set_conntrack_common_last_ack,
13840                 (void *)&cmd_set_conntrack_common_last_ack_value,
13841                 (void *)&cmd_set_conntrack_common_last_end,
13842                 (void *)&cmd_set_conntrack_common_last_end_value,
13843                 (void *)&cmd_set_conntrack_common_last_index,
13844                 (void *)&cmd_set_conntrack_common_last_index_value,
13845                 NULL,
13846         },
13847 };
13848
13849 /** Set connection tracking object both directions' details */
13850 struct cmd_set_conntrack_dir_result {
13851         cmdline_fixed_string_t set;
13852         cmdline_fixed_string_t conntrack;
13853         cmdline_fixed_string_t dir;
13854         cmdline_fixed_string_t scale;
13855         cmdline_fixed_string_t fin;
13856         cmdline_fixed_string_t ack_seen;
13857         cmdline_fixed_string_t unack;
13858         cmdline_fixed_string_t sent_end;
13859         cmdline_fixed_string_t reply_end;
13860         cmdline_fixed_string_t max_win;
13861         cmdline_fixed_string_t max_ack;
13862         uint32_t factor;
13863         uint32_t f;
13864         uint32_t as;
13865         uint32_t un;
13866         uint32_t se;
13867         uint32_t re;
13868         uint32_t mw;
13869         uint32_t ma;
13870 };
13871
13872 cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
13873         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13874                                  set, "set");
13875 cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
13876         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13877                                  conntrack, "conntrack");
13878 cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
13879         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13880                                  dir, "orig#rply");
13881 cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
13882         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13883                                  scale, "scale");
13884 cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
13885         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
13886                               factor, RTE_UINT32);
13887 cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
13888         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13889                                  fin, "fin");
13890 cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
13891         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
13892                               f, RTE_UINT32);
13893 cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
13894         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13895                                  ack_seen, "acked");
13896 cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
13897         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
13898                               as, RTE_UINT32);
13899 cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
13900         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13901                                  unack, "unack_data");
13902 cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
13903         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
13904                               un, RTE_UINT32);
13905 cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
13906         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13907                                  sent_end, "sent_end");
13908 cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
13909         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
13910                               se, RTE_UINT32);
13911 cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
13912         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13913                                  reply_end, "reply_end");
13914 cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
13915         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
13916                               re, RTE_UINT32);
13917 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
13918         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13919                                  max_win, "max_win");
13920 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
13921         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
13922                               mw, RTE_UINT32);
13923 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
13924         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
13925                                  max_ack, "max_ack");
13926 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
13927         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
13928                               ma, RTE_UINT32);
13929
13930 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
13931         __rte_unused struct cmdline *cl,
13932         __rte_unused void *data)
13933 {
13934         struct cmd_set_conntrack_dir_result *res = parsed_result;
13935         struct rte_flow_tcp_dir_param *dir = NULL;
13936
13937         if (strcmp(res->dir, "orig") == 0)
13938                 dir = &conntrack_context.original_dir;
13939         else if (strcmp(res->dir, "rply") == 0)
13940                 dir = &conntrack_context.reply_dir;
13941         else
13942                 return;
13943         dir->scale = res->factor;
13944         dir->close_initiated = res->f;
13945         dir->last_ack_seen = res->as;
13946         dir->data_unacked = res->un;
13947         dir->sent_end = res->se;
13948         dir->reply_end = res->re;
13949         dir->max_ack = res->ma;
13950         dir->max_win = res->mw;
13951 }
13952
13953 cmdline_parse_inst_t cmd_set_conntrack_dir = {
13954         .f = cmd_set_conntrack_dir_parsed,
13955         .data = NULL,
13956         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
13957                     " acked <seen> unack_data <unack> sent_end <sent>"
13958                     " reply_end <reply> max_win <win> max_ack <ack>",
13959         .tokens = {
13960                 (void *)&cmd_set_conntrack_set,
13961                 (void *)&cmd_set_conntrack_conntrack,
13962                 (void *)&cmd_set_conntrack_dir_dir,
13963                 (void *)&cmd_set_conntrack_dir_scale,
13964                 (void *)&cmd_set_conntrack_dir_scale_value,
13965                 (void *)&cmd_set_conntrack_dir_fin,
13966                 (void *)&cmd_set_conntrack_dir_fin_value,
13967                 (void *)&cmd_set_conntrack_dir_ack,
13968                 (void *)&cmd_set_conntrack_dir_ack_value,
13969                 (void *)&cmd_set_conntrack_dir_unack_data,
13970                 (void *)&cmd_set_conntrack_dir_unack_data_value,
13971                 (void *)&cmd_set_conntrack_dir_sent_end,
13972                 (void *)&cmd_set_conntrack_dir_sent_end_value,
13973                 (void *)&cmd_set_conntrack_dir_reply_end,
13974                 (void *)&cmd_set_conntrack_dir_reply_end_value,
13975                 (void *)&cmd_set_conntrack_dir_max_win,
13976                 (void *)&cmd_set_conntrack_dir_max_win_value,
13977                 (void *)&cmd_set_conntrack_dir_max_ack,
13978                 (void *)&cmd_set_conntrack_dir_max_ack_value,
13979                 NULL,
13980         },
13981 };
13982
13983 /* Strict link priority scheduling mode setting */
13984 static void
13985 cmd_strict_link_prio_parsed(
13986         void *parsed_result,
13987         __rte_unused struct cmdline *cl,
13988         __rte_unused void *data)
13989 {
13990         struct cmd_vf_tc_bw_result *res = parsed_result;
13991         int ret = -ENOTSUP;
13992
13993         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13994                 return;
13995
13996 #ifdef RTE_NET_I40E
13997         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13998 #endif
13999
14000         switch (ret) {
14001         case 0:
14002                 break;
14003         case -EINVAL:
14004                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14005                 break;
14006         case -ENODEV:
14007                 printf("invalid port_id %d\n", res->port_id);
14008                 break;
14009         case -ENOTSUP:
14010                 printf("function not implemented\n");
14011                 break;
14012         default:
14013                 printf("programming error: (%s)\n", strerror(-ret));
14014         }
14015 }
14016
14017 cmdline_parse_inst_t cmd_strict_link_prio = {
14018         .f = cmd_strict_link_prio_parsed,
14019         .data = NULL,
14020         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14021         .tokens = {
14022                 (void *)&cmd_vf_tc_bw_set,
14023                 (void *)&cmd_vf_tc_bw_tx,
14024                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14025                 (void *)&cmd_vf_tc_bw_port_id,
14026                 (void *)&cmd_vf_tc_bw_tc_map,
14027                 NULL,
14028         },
14029 };
14030
14031 /* Load dynamic device personalization*/
14032 struct cmd_ddp_add_result {
14033         cmdline_fixed_string_t ddp;
14034         cmdline_fixed_string_t add;
14035         portid_t port_id;
14036         char filepath[];
14037 };
14038
14039 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14040         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14041 cmdline_parse_token_string_t cmd_ddp_add_add =
14042         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14043 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14044         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14045                 RTE_UINT16);
14046 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14047         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14048
14049 static void
14050 cmd_ddp_add_parsed(
14051         void *parsed_result,
14052         __rte_unused struct cmdline *cl,
14053         __rte_unused void *data)
14054 {
14055         struct cmd_ddp_add_result *res = parsed_result;
14056         uint8_t *buff;
14057         uint32_t size;
14058         char *filepath;
14059         char *file_fld[2];
14060         int file_num;
14061         int ret = -ENOTSUP;
14062
14063         if (!all_ports_stopped()) {
14064                 printf("Please stop all ports first\n");
14065                 return;
14066         }
14067
14068         filepath = strdup(res->filepath);
14069         if (filepath == NULL) {
14070                 printf("Failed to allocate memory\n");
14071                 return;
14072         }
14073         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14074
14075         buff = open_file(file_fld[0], &size);
14076         if (!buff) {
14077                 free((void *)filepath);
14078                 return;
14079         }
14080
14081 #ifdef RTE_NET_I40E
14082         if (ret == -ENOTSUP)
14083                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14084                                                buff, size,
14085                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14086 #endif
14087
14088         if (ret == -EEXIST)
14089                 printf("Profile has already existed.\n");
14090         else if (ret < 0)
14091                 printf("Failed to load profile.\n");
14092         else if (file_num == 2)
14093                 save_file(file_fld[1], buff, size);
14094
14095         close_file(buff);
14096         free((void *)filepath);
14097 }
14098
14099 cmdline_parse_inst_t cmd_ddp_add = {
14100         .f = cmd_ddp_add_parsed,
14101         .data = NULL,
14102         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14103         .tokens = {
14104                 (void *)&cmd_ddp_add_ddp,
14105                 (void *)&cmd_ddp_add_add,
14106                 (void *)&cmd_ddp_add_port_id,
14107                 (void *)&cmd_ddp_add_filepath,
14108                 NULL,
14109         },
14110 };
14111
14112 /* Delete dynamic device personalization*/
14113 struct cmd_ddp_del_result {
14114         cmdline_fixed_string_t ddp;
14115         cmdline_fixed_string_t del;
14116         portid_t port_id;
14117         char filepath[];
14118 };
14119
14120 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14121         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14122 cmdline_parse_token_string_t cmd_ddp_del_del =
14123         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14124 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14125         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14126 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14127         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14128
14129 static void
14130 cmd_ddp_del_parsed(
14131         void *parsed_result,
14132         __rte_unused struct cmdline *cl,
14133         __rte_unused void *data)
14134 {
14135         struct cmd_ddp_del_result *res = parsed_result;
14136         uint8_t *buff;
14137         uint32_t size;
14138         int ret = -ENOTSUP;
14139
14140         if (!all_ports_stopped()) {
14141                 printf("Please stop all ports first\n");
14142                 return;
14143         }
14144
14145         buff = open_file(res->filepath, &size);
14146         if (!buff)
14147                 return;
14148
14149 #ifdef RTE_NET_I40E
14150         if (ret == -ENOTSUP)
14151                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14152                                                buff, size,
14153                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14154 #endif
14155
14156         if (ret == -EACCES)
14157                 printf("Profile does not exist.\n");
14158         else if (ret < 0)
14159                 printf("Failed to delete profile.\n");
14160
14161         close_file(buff);
14162 }
14163
14164 cmdline_parse_inst_t cmd_ddp_del = {
14165         .f = cmd_ddp_del_parsed,
14166         .data = NULL,
14167         .help_str = "ddp del <port_id> <backup_profile_path>",
14168         .tokens = {
14169                 (void *)&cmd_ddp_del_ddp,
14170                 (void *)&cmd_ddp_del_del,
14171                 (void *)&cmd_ddp_del_port_id,
14172                 (void *)&cmd_ddp_del_filepath,
14173                 NULL,
14174         },
14175 };
14176
14177 /* Get dynamic device personalization profile info */
14178 struct cmd_ddp_info_result {
14179         cmdline_fixed_string_t ddp;
14180         cmdline_fixed_string_t get;
14181         cmdline_fixed_string_t info;
14182         char filepath[];
14183 };
14184
14185 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14186         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14187 cmdline_parse_token_string_t cmd_ddp_info_get =
14188         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14189 cmdline_parse_token_string_t cmd_ddp_info_info =
14190         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14191 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14192         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14193
14194 static void
14195 cmd_ddp_info_parsed(
14196         void *parsed_result,
14197         __rte_unused struct cmdline *cl,
14198         __rte_unused void *data)
14199 {
14200         struct cmd_ddp_info_result *res = parsed_result;
14201         uint8_t *pkg;
14202         uint32_t pkg_size;
14203         int ret = -ENOTSUP;
14204 #ifdef RTE_NET_I40E
14205         uint32_t i, j, n;
14206         uint8_t *buff;
14207         uint32_t buff_size = 0;
14208         struct rte_pmd_i40e_profile_info info;
14209         uint32_t dev_num = 0;
14210         struct rte_pmd_i40e_ddp_device_id *devs;
14211         uint32_t proto_num = 0;
14212         struct rte_pmd_i40e_proto_info *proto = NULL;
14213         uint32_t pctype_num = 0;
14214         struct rte_pmd_i40e_ptype_info *pctype;
14215         uint32_t ptype_num = 0;
14216         struct rte_pmd_i40e_ptype_info *ptype;
14217         uint8_t proto_id;
14218
14219 #endif
14220
14221         pkg = open_file(res->filepath, &pkg_size);
14222         if (!pkg)
14223                 return;
14224
14225 #ifdef RTE_NET_I40E
14226         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14227                                 (uint8_t *)&info, sizeof(info),
14228                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14229         if (!ret) {
14230                 printf("Global Track id:       0x%x\n", info.track_id);
14231                 printf("Global Version:        %d.%d.%d.%d\n",
14232                         info.version.major,
14233                         info.version.minor,
14234                         info.version.update,
14235                         info.version.draft);
14236                 printf("Global Package name:   %s\n\n", info.name);
14237         }
14238
14239         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14240                                 (uint8_t *)&info, sizeof(info),
14241                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14242         if (!ret) {
14243                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14244                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14245                         info.version.major,
14246                         info.version.minor,
14247                         info.version.update,
14248                         info.version.draft);
14249                 printf("i40e Profile name:     %s\n\n", info.name);
14250         }
14251
14252         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14253                                 (uint8_t *)&buff_size, sizeof(buff_size),
14254                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14255         if (!ret && buff_size) {
14256                 buff = (uint8_t *)malloc(buff_size);
14257                 if (buff) {
14258                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14259                                                 buff, buff_size,
14260                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14261                         if (!ret)
14262                                 printf("Package Notes:\n%s\n\n", buff);
14263                         free(buff);
14264                 }
14265         }
14266
14267         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14268                                 (uint8_t *)&dev_num, sizeof(dev_num),
14269                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14270         if (!ret && dev_num) {
14271                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14272                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14273                 if (devs) {
14274                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14275                                                 (uint8_t *)devs, buff_size,
14276                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14277                         if (!ret) {
14278                                 printf("List of supported devices:\n");
14279                                 for (i = 0; i < dev_num; i++) {
14280                                         printf("  %04X:%04X %04X:%04X\n",
14281                                                 devs[i].vendor_dev_id >> 16,
14282                                                 devs[i].vendor_dev_id & 0xFFFF,
14283                                                 devs[i].sub_vendor_dev_id >> 16,
14284                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14285                                 }
14286                                 printf("\n");
14287                         }
14288                         free(devs);
14289                 }
14290         }
14291
14292         /* get information about protocols and packet types */
14293         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14294                 (uint8_t *)&proto_num, sizeof(proto_num),
14295                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14296         if (ret || !proto_num)
14297                 goto no_print_return;
14298
14299         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14300         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14301         if (!proto)
14302                 goto no_print_return;
14303
14304         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14305                                         buff_size,
14306                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14307         if (!ret) {
14308                 printf("List of used protocols:\n");
14309                 for (i = 0; i < proto_num; i++)
14310                         printf("  %2u: %s\n", proto[i].proto_id,
14311                                proto[i].name);
14312                 printf("\n");
14313         }
14314         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14315                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14316                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14317         if (ret || !pctype_num)
14318                 goto no_print_pctypes;
14319
14320         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14321         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14322         if (!pctype)
14323                 goto no_print_pctypes;
14324
14325         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14326                                         buff_size,
14327                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14328         if (ret) {
14329                 free(pctype);
14330                 goto no_print_pctypes;
14331         }
14332
14333         printf("List of defined packet classification types:\n");
14334         for (i = 0; i < pctype_num; i++) {
14335                 printf("  %2u:", pctype[i].ptype_id);
14336                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14337                         proto_id = pctype[i].protocols[j];
14338                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14339                                 for (n = 0; n < proto_num; n++) {
14340                                         if (proto[n].proto_id == proto_id) {
14341                                                 printf(" %s", proto[n].name);
14342                                                 break;
14343                                         }
14344                                 }
14345                         }
14346                 }
14347                 printf("\n");
14348         }
14349         printf("\n");
14350         free(pctype);
14351
14352 no_print_pctypes:
14353
14354         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14355                                         sizeof(ptype_num),
14356                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14357         if (ret || !ptype_num)
14358                 goto no_print_return;
14359
14360         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14361         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14362         if (!ptype)
14363                 goto no_print_return;
14364
14365         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14366                                         buff_size,
14367                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14368         if (ret) {
14369                 free(ptype);
14370                 goto no_print_return;
14371         }
14372         printf("List of defined packet types:\n");
14373         for (i = 0; i < ptype_num; i++) {
14374                 printf("  %2u:", ptype[i].ptype_id);
14375                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14376                         proto_id = ptype[i].protocols[j];
14377                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14378                                 for (n = 0; n < proto_num; n++) {
14379                                         if (proto[n].proto_id == proto_id) {
14380                                                 printf(" %s", proto[n].name);
14381                                                 break;
14382                                         }
14383                                 }
14384                         }
14385                 }
14386                 printf("\n");
14387         }
14388         free(ptype);
14389         printf("\n");
14390
14391         ret = 0;
14392 no_print_return:
14393         if (proto)
14394                 free(proto);
14395 #endif
14396         if (ret == -ENOTSUP)
14397                 printf("Function not supported in PMD driver\n");
14398         close_file(pkg);
14399 }
14400
14401 cmdline_parse_inst_t cmd_ddp_get_info = {
14402         .f = cmd_ddp_info_parsed,
14403         .data = NULL,
14404         .help_str = "ddp get info <profile_path>",
14405         .tokens = {
14406                 (void *)&cmd_ddp_info_ddp,
14407                 (void *)&cmd_ddp_info_get,
14408                 (void *)&cmd_ddp_info_info,
14409                 (void *)&cmd_ddp_info_filepath,
14410                 NULL,
14411         },
14412 };
14413
14414 /* Get dynamic device personalization profile info list*/
14415 #define PROFILE_INFO_SIZE 48
14416 #define MAX_PROFILE_NUM 16
14417
14418 struct cmd_ddp_get_list_result {
14419         cmdline_fixed_string_t ddp;
14420         cmdline_fixed_string_t get;
14421         cmdline_fixed_string_t list;
14422         portid_t port_id;
14423 };
14424
14425 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14426         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14427 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14428         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14429 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14430         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14431 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14432         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14433                 RTE_UINT16);
14434
14435 static void
14436 cmd_ddp_get_list_parsed(
14437         __rte_unused void *parsed_result,
14438         __rte_unused struct cmdline *cl,
14439         __rte_unused void *data)
14440 {
14441 #ifdef RTE_NET_I40E
14442         struct cmd_ddp_get_list_result *res = parsed_result;
14443         struct rte_pmd_i40e_profile_list *p_list;
14444         struct rte_pmd_i40e_profile_info *p_info;
14445         uint32_t p_num;
14446         uint32_t size;
14447         uint32_t i;
14448 #endif
14449         int ret = -ENOTSUP;
14450
14451 #ifdef RTE_NET_I40E
14452         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14453         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14454         if (!p_list) {
14455                 printf("%s: Failed to malloc buffer\n", __func__);
14456                 return;
14457         }
14458
14459         if (ret == -ENOTSUP)
14460                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14461                                                 (uint8_t *)p_list, size);
14462
14463         if (!ret) {
14464                 p_num = p_list->p_count;
14465                 printf("Profile number is: %d\n\n", p_num);
14466
14467                 for (i = 0; i < p_num; i++) {
14468                         p_info = &p_list->p_info[i];
14469                         printf("Profile %d:\n", i);
14470                         printf("Track id:     0x%x\n", p_info->track_id);
14471                         printf("Version:      %d.%d.%d.%d\n",
14472                                p_info->version.major,
14473                                p_info->version.minor,
14474                                p_info->version.update,
14475                                p_info->version.draft);
14476                         printf("Profile name: %s\n\n", p_info->name);
14477                 }
14478         }
14479
14480         free(p_list);
14481 #endif
14482
14483         if (ret < 0)
14484                 printf("Failed to get ddp list\n");
14485 }
14486
14487 cmdline_parse_inst_t cmd_ddp_get_list = {
14488         .f = cmd_ddp_get_list_parsed,
14489         .data = NULL,
14490         .help_str = "ddp get list <port_id>",
14491         .tokens = {
14492                 (void *)&cmd_ddp_get_list_ddp,
14493                 (void *)&cmd_ddp_get_list_get,
14494                 (void *)&cmd_ddp_get_list_list,
14495                 (void *)&cmd_ddp_get_list_port_id,
14496                 NULL,
14497         },
14498 };
14499
14500 /* Configure input set */
14501 struct cmd_cfg_input_set_result {
14502         cmdline_fixed_string_t port;
14503         cmdline_fixed_string_t cfg;
14504         portid_t port_id;
14505         cmdline_fixed_string_t pctype;
14506         uint8_t pctype_id;
14507         cmdline_fixed_string_t inset_type;
14508         cmdline_fixed_string_t opt;
14509         cmdline_fixed_string_t field;
14510         uint8_t field_idx;
14511 };
14512
14513 static void
14514 cmd_cfg_input_set_parsed(
14515         __rte_unused void *parsed_result,
14516         __rte_unused struct cmdline *cl,
14517         __rte_unused void *data)
14518 {
14519 #ifdef RTE_NET_I40E
14520         struct cmd_cfg_input_set_result *res = parsed_result;
14521         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14522         struct rte_pmd_i40e_inset inset;
14523 #endif
14524         int ret = -ENOTSUP;
14525
14526         if (!all_ports_stopped()) {
14527                 printf("Please stop all ports first\n");
14528                 return;
14529         }
14530
14531 #ifdef RTE_NET_I40E
14532         if (!strcmp(res->inset_type, "hash_inset"))
14533                 inset_type = INSET_HASH;
14534         else if (!strcmp(res->inset_type, "fdir_inset"))
14535                 inset_type = INSET_FDIR;
14536         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14537                 inset_type = INSET_FDIR_FLX;
14538         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14539                                      &inset, inset_type);
14540         if (ret) {
14541                 printf("Failed to get input set.\n");
14542                 return;
14543         }
14544
14545         if (!strcmp(res->opt, "get")) {
14546                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14547                                                    res->field_idx);
14548                 if (ret)
14549                         printf("Field index %d is enabled.\n", res->field_idx);
14550                 else
14551                         printf("Field index %d is disabled.\n", res->field_idx);
14552                 return;
14553         } else if (!strcmp(res->opt, "set"))
14554                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14555                                                    res->field_idx);
14556         else if (!strcmp(res->opt, "clear"))
14557                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14558                                                      res->field_idx);
14559         if (ret) {
14560                 printf("Failed to configure input set field.\n");
14561                 return;
14562         }
14563
14564         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14565                                      &inset, inset_type);
14566         if (ret) {
14567                 printf("Failed to set input set.\n");
14568                 return;
14569         }
14570 #endif
14571
14572         if (ret == -ENOTSUP)
14573                 printf("Function not supported\n");
14574 }
14575
14576 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14577         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14578                                  port, "port");
14579 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14580         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14581                                  cfg, "config");
14582 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14583         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14584                               port_id, RTE_UINT16);
14585 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14586         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14587                                  pctype, "pctype");
14588 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14589         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14590                               pctype_id, RTE_UINT8);
14591 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14592         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14593                                  inset_type,
14594                                  "hash_inset#fdir_inset#fdir_flx_inset");
14595 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14596         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14597                                  opt, "get#set#clear");
14598 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14599         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14600                                  field, "field");
14601 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14602         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14603                               field_idx, RTE_UINT8);
14604
14605 cmdline_parse_inst_t cmd_cfg_input_set = {
14606         .f = cmd_cfg_input_set_parsed,
14607         .data = NULL,
14608         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14609                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14610         .tokens = {
14611                 (void *)&cmd_cfg_input_set_port,
14612                 (void *)&cmd_cfg_input_set_cfg,
14613                 (void *)&cmd_cfg_input_set_port_id,
14614                 (void *)&cmd_cfg_input_set_pctype,
14615                 (void *)&cmd_cfg_input_set_pctype_id,
14616                 (void *)&cmd_cfg_input_set_inset_type,
14617                 (void *)&cmd_cfg_input_set_opt,
14618                 (void *)&cmd_cfg_input_set_field,
14619                 (void *)&cmd_cfg_input_set_field_idx,
14620                 NULL,
14621         },
14622 };
14623
14624 /* Clear input set */
14625 struct cmd_clear_input_set_result {
14626         cmdline_fixed_string_t port;
14627         cmdline_fixed_string_t cfg;
14628         portid_t port_id;
14629         cmdline_fixed_string_t pctype;
14630         uint8_t pctype_id;
14631         cmdline_fixed_string_t inset_type;
14632         cmdline_fixed_string_t clear;
14633         cmdline_fixed_string_t all;
14634 };
14635
14636 static void
14637 cmd_clear_input_set_parsed(
14638         __rte_unused void *parsed_result,
14639         __rte_unused struct cmdline *cl,
14640         __rte_unused void *data)
14641 {
14642 #ifdef RTE_NET_I40E
14643         struct cmd_clear_input_set_result *res = parsed_result;
14644         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14645         struct rte_pmd_i40e_inset inset;
14646 #endif
14647         int ret = -ENOTSUP;
14648
14649         if (!all_ports_stopped()) {
14650                 printf("Please stop all ports first\n");
14651                 return;
14652         }
14653
14654 #ifdef RTE_NET_I40E
14655         if (!strcmp(res->inset_type, "hash_inset"))
14656                 inset_type = INSET_HASH;
14657         else if (!strcmp(res->inset_type, "fdir_inset"))
14658                 inset_type = INSET_FDIR;
14659         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14660                 inset_type = INSET_FDIR_FLX;
14661
14662         memset(&inset, 0, sizeof(inset));
14663
14664         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14665                                      &inset, inset_type);
14666         if (ret) {
14667                 printf("Failed to clear input set.\n");
14668                 return;
14669         }
14670
14671 #endif
14672
14673         if (ret == -ENOTSUP)
14674                 printf("Function not supported\n");
14675 }
14676
14677 cmdline_parse_token_string_t cmd_clear_input_set_port =
14678         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14679                                  port, "port");
14680 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14681         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14682                                  cfg, "config");
14683 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14684         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14685                               port_id, RTE_UINT16);
14686 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14687         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14688                                  pctype, "pctype");
14689 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14690         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14691                               pctype_id, RTE_UINT8);
14692 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14693         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14694                                  inset_type,
14695                                  "hash_inset#fdir_inset#fdir_flx_inset");
14696 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14697         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14698                                  clear, "clear");
14699 cmdline_parse_token_string_t cmd_clear_input_set_all =
14700         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14701                                  all, "all");
14702
14703 cmdline_parse_inst_t cmd_clear_input_set = {
14704         .f = cmd_clear_input_set_parsed,
14705         .data = NULL,
14706         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14707                     "fdir_inset|fdir_flx_inset clear all",
14708         .tokens = {
14709                 (void *)&cmd_clear_input_set_port,
14710                 (void *)&cmd_clear_input_set_cfg,
14711                 (void *)&cmd_clear_input_set_port_id,
14712                 (void *)&cmd_clear_input_set_pctype,
14713                 (void *)&cmd_clear_input_set_pctype_id,
14714                 (void *)&cmd_clear_input_set_inset_type,
14715                 (void *)&cmd_clear_input_set_clear,
14716                 (void *)&cmd_clear_input_set_all,
14717                 NULL,
14718         },
14719 };
14720
14721 /* show vf stats */
14722
14723 /* Common result structure for show vf stats */
14724 struct cmd_show_vf_stats_result {
14725         cmdline_fixed_string_t show;
14726         cmdline_fixed_string_t vf;
14727         cmdline_fixed_string_t stats;
14728         portid_t port_id;
14729         uint16_t vf_id;
14730 };
14731
14732 /* Common CLI fields show vf stats*/
14733 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14734         TOKEN_STRING_INITIALIZER
14735                 (struct cmd_show_vf_stats_result,
14736                  show, "show");
14737 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14738         TOKEN_STRING_INITIALIZER
14739                 (struct cmd_show_vf_stats_result,
14740                  vf, "vf");
14741 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14742         TOKEN_STRING_INITIALIZER
14743                 (struct cmd_show_vf_stats_result,
14744                  stats, "stats");
14745 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14746         TOKEN_NUM_INITIALIZER
14747                 (struct cmd_show_vf_stats_result,
14748                  port_id, RTE_UINT16);
14749 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14750         TOKEN_NUM_INITIALIZER
14751                 (struct cmd_show_vf_stats_result,
14752                  vf_id, RTE_UINT16);
14753
14754 static void
14755 cmd_show_vf_stats_parsed(
14756         void *parsed_result,
14757         __rte_unused struct cmdline *cl,
14758         __rte_unused void *data)
14759 {
14760         struct cmd_show_vf_stats_result *res = parsed_result;
14761         struct rte_eth_stats stats;
14762         int ret = -ENOTSUP;
14763         static const char *nic_stats_border = "########################";
14764
14765         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14766                 return;
14767
14768         memset(&stats, 0, sizeof(stats));
14769
14770 #ifdef RTE_NET_I40E
14771         if (ret == -ENOTSUP)
14772                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14773                                                 res->vf_id,
14774                                                 &stats);
14775 #endif
14776 #ifdef RTE_NET_BNXT
14777         if (ret == -ENOTSUP)
14778                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14779                                                 res->vf_id,
14780                                                 &stats);
14781 #endif
14782
14783         switch (ret) {
14784         case 0:
14785                 break;
14786         case -EINVAL:
14787                 printf("invalid vf_id %d\n", res->vf_id);
14788                 break;
14789         case -ENODEV:
14790                 printf("invalid port_id %d\n", res->port_id);
14791                 break;
14792         case -ENOTSUP:
14793                 printf("function not implemented\n");
14794                 break;
14795         default:
14796                 printf("programming error: (%s)\n", strerror(-ret));
14797         }
14798
14799         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14800                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14801
14802         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14803                "%-"PRIu64"\n",
14804                stats.ipackets, stats.imissed, stats.ibytes);
14805         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14806         printf("  RX-nombuf:  %-10"PRIu64"\n",
14807                stats.rx_nombuf);
14808         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14809                "%-"PRIu64"\n",
14810                stats.opackets, stats.oerrors, stats.obytes);
14811
14812         printf("  %s############################%s\n",
14813                                nic_stats_border, nic_stats_border);
14814 }
14815
14816 cmdline_parse_inst_t cmd_show_vf_stats = {
14817         .f = cmd_show_vf_stats_parsed,
14818         .data = NULL,
14819         .help_str = "show vf stats <port_id> <vf_id>",
14820         .tokens = {
14821                 (void *)&cmd_show_vf_stats_show,
14822                 (void *)&cmd_show_vf_stats_vf,
14823                 (void *)&cmd_show_vf_stats_stats,
14824                 (void *)&cmd_show_vf_stats_port_id,
14825                 (void *)&cmd_show_vf_stats_vf_id,
14826                 NULL,
14827         },
14828 };
14829
14830 /* clear vf stats */
14831
14832 /* Common result structure for clear vf stats */
14833 struct cmd_clear_vf_stats_result {
14834         cmdline_fixed_string_t clear;
14835         cmdline_fixed_string_t vf;
14836         cmdline_fixed_string_t stats;
14837         portid_t port_id;
14838         uint16_t vf_id;
14839 };
14840
14841 /* Common CLI fields clear vf stats*/
14842 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14843         TOKEN_STRING_INITIALIZER
14844                 (struct cmd_clear_vf_stats_result,
14845                  clear, "clear");
14846 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14847         TOKEN_STRING_INITIALIZER
14848                 (struct cmd_clear_vf_stats_result,
14849                  vf, "vf");
14850 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14851         TOKEN_STRING_INITIALIZER
14852                 (struct cmd_clear_vf_stats_result,
14853                  stats, "stats");
14854 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14855         TOKEN_NUM_INITIALIZER
14856                 (struct cmd_clear_vf_stats_result,
14857                  port_id, RTE_UINT16);
14858 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14859         TOKEN_NUM_INITIALIZER
14860                 (struct cmd_clear_vf_stats_result,
14861                  vf_id, RTE_UINT16);
14862
14863 static void
14864 cmd_clear_vf_stats_parsed(
14865         void *parsed_result,
14866         __rte_unused struct cmdline *cl,
14867         __rte_unused void *data)
14868 {
14869         struct cmd_clear_vf_stats_result *res = parsed_result;
14870         int ret = -ENOTSUP;
14871
14872         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14873                 return;
14874
14875 #ifdef RTE_NET_I40E
14876         if (ret == -ENOTSUP)
14877                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14878                                                   res->vf_id);
14879 #endif
14880 #ifdef RTE_NET_BNXT
14881         if (ret == -ENOTSUP)
14882                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14883                                                   res->vf_id);
14884 #endif
14885
14886         switch (ret) {
14887         case 0:
14888                 break;
14889         case -EINVAL:
14890                 printf("invalid vf_id %d\n", res->vf_id);
14891                 break;
14892         case -ENODEV:
14893                 printf("invalid port_id %d\n", res->port_id);
14894                 break;
14895         case -ENOTSUP:
14896                 printf("function not implemented\n");
14897                 break;
14898         default:
14899                 printf("programming error: (%s)\n", strerror(-ret));
14900         }
14901 }
14902
14903 cmdline_parse_inst_t cmd_clear_vf_stats = {
14904         .f = cmd_clear_vf_stats_parsed,
14905         .data = NULL,
14906         .help_str = "clear vf stats <port_id> <vf_id>",
14907         .tokens = {
14908                 (void *)&cmd_clear_vf_stats_clear,
14909                 (void *)&cmd_clear_vf_stats_vf,
14910                 (void *)&cmd_clear_vf_stats_stats,
14911                 (void *)&cmd_clear_vf_stats_port_id,
14912                 (void *)&cmd_clear_vf_stats_vf_id,
14913                 NULL,
14914         },
14915 };
14916
14917 /* port config pctype mapping reset */
14918
14919 /* Common result structure for port config pctype mapping reset */
14920 struct cmd_pctype_mapping_reset_result {
14921         cmdline_fixed_string_t port;
14922         cmdline_fixed_string_t config;
14923         portid_t port_id;
14924         cmdline_fixed_string_t pctype;
14925         cmdline_fixed_string_t mapping;
14926         cmdline_fixed_string_t reset;
14927 };
14928
14929 /* Common CLI fields for port config pctype mapping reset*/
14930 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14931         TOKEN_STRING_INITIALIZER
14932                 (struct cmd_pctype_mapping_reset_result,
14933                  port, "port");
14934 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14935         TOKEN_STRING_INITIALIZER
14936                 (struct cmd_pctype_mapping_reset_result,
14937                  config, "config");
14938 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14939         TOKEN_NUM_INITIALIZER
14940                 (struct cmd_pctype_mapping_reset_result,
14941                  port_id, RTE_UINT16);
14942 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14943         TOKEN_STRING_INITIALIZER
14944                 (struct cmd_pctype_mapping_reset_result,
14945                  pctype, "pctype");
14946 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14947         TOKEN_STRING_INITIALIZER
14948                 (struct cmd_pctype_mapping_reset_result,
14949                  mapping, "mapping");
14950 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14951         TOKEN_STRING_INITIALIZER
14952                 (struct cmd_pctype_mapping_reset_result,
14953                  reset, "reset");
14954
14955 static void
14956 cmd_pctype_mapping_reset_parsed(
14957         void *parsed_result,
14958         __rte_unused struct cmdline *cl,
14959         __rte_unused void *data)
14960 {
14961         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14962         int ret = -ENOTSUP;
14963
14964         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14965                 return;
14966
14967 #ifdef RTE_NET_I40E
14968         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14969 #endif
14970
14971         switch (ret) {
14972         case 0:
14973                 break;
14974         case -ENODEV:
14975                 printf("invalid port_id %d\n", res->port_id);
14976                 break;
14977         case -ENOTSUP:
14978                 printf("function not implemented\n");
14979                 break;
14980         default:
14981                 printf("programming error: (%s)\n", strerror(-ret));
14982         }
14983 }
14984
14985 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14986         .f = cmd_pctype_mapping_reset_parsed,
14987         .data = NULL,
14988         .help_str = "port config <port_id> pctype mapping reset",
14989         .tokens = {
14990                 (void *)&cmd_pctype_mapping_reset_port,
14991                 (void *)&cmd_pctype_mapping_reset_config,
14992                 (void *)&cmd_pctype_mapping_reset_port_id,
14993                 (void *)&cmd_pctype_mapping_reset_pctype,
14994                 (void *)&cmd_pctype_mapping_reset_mapping,
14995                 (void *)&cmd_pctype_mapping_reset_reset,
14996                 NULL,
14997         },
14998 };
14999
15000 /* show port pctype mapping */
15001
15002 /* Common result structure for show port pctype mapping */
15003 struct cmd_pctype_mapping_get_result {
15004         cmdline_fixed_string_t show;
15005         cmdline_fixed_string_t port;
15006         portid_t port_id;
15007         cmdline_fixed_string_t pctype;
15008         cmdline_fixed_string_t mapping;
15009 };
15010
15011 /* Common CLI fields for pctype mapping get */
15012 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15013         TOKEN_STRING_INITIALIZER
15014                 (struct cmd_pctype_mapping_get_result,
15015                  show, "show");
15016 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15017         TOKEN_STRING_INITIALIZER
15018                 (struct cmd_pctype_mapping_get_result,
15019                  port, "port");
15020 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15021         TOKEN_NUM_INITIALIZER
15022                 (struct cmd_pctype_mapping_get_result,
15023                  port_id, RTE_UINT16);
15024 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15025         TOKEN_STRING_INITIALIZER
15026                 (struct cmd_pctype_mapping_get_result,
15027                  pctype, "pctype");
15028 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15029         TOKEN_STRING_INITIALIZER
15030                 (struct cmd_pctype_mapping_get_result,
15031                  mapping, "mapping");
15032
15033 static void
15034 cmd_pctype_mapping_get_parsed(
15035         void *parsed_result,
15036         __rte_unused struct cmdline *cl,
15037         __rte_unused void *data)
15038 {
15039         struct cmd_pctype_mapping_get_result *res = parsed_result;
15040         int ret = -ENOTSUP;
15041 #ifdef RTE_NET_I40E
15042         struct rte_pmd_i40e_flow_type_mapping
15043                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15044         int i, j, first_pctype;
15045 #endif
15046
15047         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15048                 return;
15049
15050 #ifdef RTE_NET_I40E
15051         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15052 #endif
15053
15054         switch (ret) {
15055         case 0:
15056                 break;
15057         case -ENODEV:
15058                 printf("invalid port_id %d\n", res->port_id);
15059                 return;
15060         case -ENOTSUP:
15061                 printf("function not implemented\n");
15062                 return;
15063         default:
15064                 printf("programming error: (%s)\n", strerror(-ret));
15065                 return;
15066         }
15067
15068 #ifdef RTE_NET_I40E
15069         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15070                 if (mapping[i].pctype != 0ULL) {
15071                         first_pctype = 1;
15072
15073                         printf("pctype: ");
15074                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15075                                 if (mapping[i].pctype & (1ULL << j)) {
15076                                         printf(first_pctype ?
15077                                                "%02d" : ",%02d", j);
15078                                         first_pctype = 0;
15079                                 }
15080                         }
15081                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15082                 }
15083         }
15084 #endif
15085 }
15086
15087 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15088         .f = cmd_pctype_mapping_get_parsed,
15089         .data = NULL,
15090         .help_str = "show port <port_id> pctype mapping",
15091         .tokens = {
15092                 (void *)&cmd_pctype_mapping_get_show,
15093                 (void *)&cmd_pctype_mapping_get_port,
15094                 (void *)&cmd_pctype_mapping_get_port_id,
15095                 (void *)&cmd_pctype_mapping_get_pctype,
15096                 (void *)&cmd_pctype_mapping_get_mapping,
15097                 NULL,
15098         },
15099 };
15100
15101 /* port config pctype mapping update */
15102
15103 /* Common result structure for port config pctype mapping update */
15104 struct cmd_pctype_mapping_update_result {
15105         cmdline_fixed_string_t port;
15106         cmdline_fixed_string_t config;
15107         portid_t port_id;
15108         cmdline_fixed_string_t pctype;
15109         cmdline_fixed_string_t mapping;
15110         cmdline_fixed_string_t update;
15111         cmdline_fixed_string_t pctype_list;
15112         uint16_t flow_type;
15113 };
15114
15115 /* Common CLI fields for pctype mapping update*/
15116 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15117         TOKEN_STRING_INITIALIZER
15118                 (struct cmd_pctype_mapping_update_result,
15119                  port, "port");
15120 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15121         TOKEN_STRING_INITIALIZER
15122                 (struct cmd_pctype_mapping_update_result,
15123                  config, "config");
15124 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15125         TOKEN_NUM_INITIALIZER
15126                 (struct cmd_pctype_mapping_update_result,
15127                  port_id, RTE_UINT16);
15128 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15129         TOKEN_STRING_INITIALIZER
15130                 (struct cmd_pctype_mapping_update_result,
15131                  pctype, "pctype");
15132 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15133         TOKEN_STRING_INITIALIZER
15134                 (struct cmd_pctype_mapping_update_result,
15135                  mapping, "mapping");
15136 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15137         TOKEN_STRING_INITIALIZER
15138                 (struct cmd_pctype_mapping_update_result,
15139                  update, "update");
15140 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15141         TOKEN_STRING_INITIALIZER
15142                 (struct cmd_pctype_mapping_update_result,
15143                  pctype_list, NULL);
15144 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15145         TOKEN_NUM_INITIALIZER
15146                 (struct cmd_pctype_mapping_update_result,
15147                  flow_type, RTE_UINT16);
15148
15149 static void
15150 cmd_pctype_mapping_update_parsed(
15151         void *parsed_result,
15152         __rte_unused struct cmdline *cl,
15153         __rte_unused void *data)
15154 {
15155         struct cmd_pctype_mapping_update_result *res = parsed_result;
15156         int ret = -ENOTSUP;
15157 #ifdef RTE_NET_I40E
15158         struct rte_pmd_i40e_flow_type_mapping mapping;
15159         unsigned int i;
15160         unsigned int nb_item;
15161         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15162 #endif
15163
15164         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15165                 return;
15166
15167 #ifdef RTE_NET_I40E
15168         nb_item = parse_item_list(res->pctype_list, "pctypes",
15169                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15170         mapping.flow_type = res->flow_type;
15171         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15172                 mapping.pctype |= (1ULL << pctype_list[i]);
15173         ret = rte_pmd_i40e_flow_type_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 pctype or flow type\n");
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_pctype_mapping_update = {
15197         .f = cmd_pctype_mapping_update_parsed,
15198         .data = NULL,
15199         .help_str = "port config <port_id> pctype mapping update"
15200         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15201         .tokens = {
15202                 (void *)&cmd_pctype_mapping_update_port,
15203                 (void *)&cmd_pctype_mapping_update_config,
15204                 (void *)&cmd_pctype_mapping_update_port_id,
15205                 (void *)&cmd_pctype_mapping_update_pctype,
15206                 (void *)&cmd_pctype_mapping_update_mapping,
15207                 (void *)&cmd_pctype_mapping_update_update,
15208                 (void *)&cmd_pctype_mapping_update_pc_type,
15209                 (void *)&cmd_pctype_mapping_update_flow_type,
15210                 NULL,
15211         },
15212 };
15213
15214 /* ptype mapping get */
15215
15216 /* Common result structure for ptype mapping get */
15217 struct cmd_ptype_mapping_get_result {
15218         cmdline_fixed_string_t ptype;
15219         cmdline_fixed_string_t mapping;
15220         cmdline_fixed_string_t get;
15221         portid_t port_id;
15222         uint8_t valid_only;
15223 };
15224
15225 /* Common CLI fields for ptype mapping get */
15226 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15227         TOKEN_STRING_INITIALIZER
15228                 (struct cmd_ptype_mapping_get_result,
15229                  ptype, "ptype");
15230 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15231         TOKEN_STRING_INITIALIZER
15232                 (struct cmd_ptype_mapping_get_result,
15233                  mapping, "mapping");
15234 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15235         TOKEN_STRING_INITIALIZER
15236                 (struct cmd_ptype_mapping_get_result,
15237                  get, "get");
15238 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15239         TOKEN_NUM_INITIALIZER
15240                 (struct cmd_ptype_mapping_get_result,
15241                  port_id, RTE_UINT16);
15242 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15243         TOKEN_NUM_INITIALIZER
15244                 (struct cmd_ptype_mapping_get_result,
15245                  valid_only, RTE_UINT8);
15246
15247 static void
15248 cmd_ptype_mapping_get_parsed(
15249         void *parsed_result,
15250         __rte_unused struct cmdline *cl,
15251         __rte_unused void *data)
15252 {
15253         struct cmd_ptype_mapping_get_result *res = parsed_result;
15254         int ret = -ENOTSUP;
15255 #ifdef RTE_NET_I40E
15256         int max_ptype_num = 256;
15257         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15258         uint16_t count;
15259         int i;
15260 #endif
15261
15262         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15263                 return;
15264
15265 #ifdef RTE_NET_I40E
15266         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15267                                         mapping,
15268                                         max_ptype_num,
15269                                         &count,
15270                                         res->valid_only);
15271 #endif
15272
15273         switch (ret) {
15274         case 0:
15275                 break;
15276         case -ENODEV:
15277                 printf("invalid port_id %d\n", res->port_id);
15278                 break;
15279         case -ENOTSUP:
15280                 printf("function not implemented\n");
15281                 break;
15282         default:
15283                 printf("programming error: (%s)\n", strerror(-ret));
15284         }
15285
15286 #ifdef RTE_NET_I40E
15287         if (!ret) {
15288                 for (i = 0; i < count; i++)
15289                         printf("%3d\t0x%08x\n",
15290                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15291         }
15292 #endif
15293 }
15294
15295 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15296         .f = cmd_ptype_mapping_get_parsed,
15297         .data = NULL,
15298         .help_str = "ptype mapping get <port_id> <valid_only>",
15299         .tokens = {
15300                 (void *)&cmd_ptype_mapping_get_ptype,
15301                 (void *)&cmd_ptype_mapping_get_mapping,
15302                 (void *)&cmd_ptype_mapping_get_get,
15303                 (void *)&cmd_ptype_mapping_get_port_id,
15304                 (void *)&cmd_ptype_mapping_get_valid_only,
15305                 NULL,
15306         },
15307 };
15308
15309 /* ptype mapping replace */
15310
15311 /* Common result structure for ptype mapping replace */
15312 struct cmd_ptype_mapping_replace_result {
15313         cmdline_fixed_string_t ptype;
15314         cmdline_fixed_string_t mapping;
15315         cmdline_fixed_string_t replace;
15316         portid_t port_id;
15317         uint32_t target;
15318         uint8_t mask;
15319         uint32_t pkt_type;
15320 };
15321
15322 /* Common CLI fields for ptype mapping replace */
15323 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15324         TOKEN_STRING_INITIALIZER
15325                 (struct cmd_ptype_mapping_replace_result,
15326                  ptype, "ptype");
15327 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15328         TOKEN_STRING_INITIALIZER
15329                 (struct cmd_ptype_mapping_replace_result,
15330                  mapping, "mapping");
15331 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15332         TOKEN_STRING_INITIALIZER
15333                 (struct cmd_ptype_mapping_replace_result,
15334                  replace, "replace");
15335 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15336         TOKEN_NUM_INITIALIZER
15337                 (struct cmd_ptype_mapping_replace_result,
15338                  port_id, RTE_UINT16);
15339 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15340         TOKEN_NUM_INITIALIZER
15341                 (struct cmd_ptype_mapping_replace_result,
15342                  target, RTE_UINT32);
15343 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15344         TOKEN_NUM_INITIALIZER
15345                 (struct cmd_ptype_mapping_replace_result,
15346                  mask, RTE_UINT8);
15347 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15348         TOKEN_NUM_INITIALIZER
15349                 (struct cmd_ptype_mapping_replace_result,
15350                  pkt_type, RTE_UINT32);
15351
15352 static void
15353 cmd_ptype_mapping_replace_parsed(
15354         void *parsed_result,
15355         __rte_unused struct cmdline *cl,
15356         __rte_unused void *data)
15357 {
15358         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15359         int ret = -ENOTSUP;
15360
15361         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15362                 return;
15363
15364 #ifdef RTE_NET_I40E
15365         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15366                                         res->target,
15367                                         res->mask,
15368                                         res->pkt_type);
15369 #endif
15370
15371         switch (ret) {
15372         case 0:
15373                 break;
15374         case -EINVAL:
15375                 printf("invalid ptype 0x%8x or 0x%8x\n",
15376                                 res->target, res->pkt_type);
15377                 break;
15378         case -ENODEV:
15379                 printf("invalid port_id %d\n", res->port_id);
15380                 break;
15381         case -ENOTSUP:
15382                 printf("function not implemented\n");
15383                 break;
15384         default:
15385                 printf("programming error: (%s)\n", strerror(-ret));
15386         }
15387 }
15388
15389 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15390         .f = cmd_ptype_mapping_replace_parsed,
15391         .data = NULL,
15392         .help_str =
15393                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15394         .tokens = {
15395                 (void *)&cmd_ptype_mapping_replace_ptype,
15396                 (void *)&cmd_ptype_mapping_replace_mapping,
15397                 (void *)&cmd_ptype_mapping_replace_replace,
15398                 (void *)&cmd_ptype_mapping_replace_port_id,
15399                 (void *)&cmd_ptype_mapping_replace_target,
15400                 (void *)&cmd_ptype_mapping_replace_mask,
15401                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15402                 NULL,
15403         },
15404 };
15405
15406 /* ptype mapping reset */
15407
15408 /* Common result structure for ptype mapping reset */
15409 struct cmd_ptype_mapping_reset_result {
15410         cmdline_fixed_string_t ptype;
15411         cmdline_fixed_string_t mapping;
15412         cmdline_fixed_string_t reset;
15413         portid_t port_id;
15414 };
15415
15416 /* Common CLI fields for ptype mapping reset*/
15417 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15418         TOKEN_STRING_INITIALIZER
15419                 (struct cmd_ptype_mapping_reset_result,
15420                  ptype, "ptype");
15421 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15422         TOKEN_STRING_INITIALIZER
15423                 (struct cmd_ptype_mapping_reset_result,
15424                  mapping, "mapping");
15425 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15426         TOKEN_STRING_INITIALIZER
15427                 (struct cmd_ptype_mapping_reset_result,
15428                  reset, "reset");
15429 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15430         TOKEN_NUM_INITIALIZER
15431                 (struct cmd_ptype_mapping_reset_result,
15432                  port_id, RTE_UINT16);
15433
15434 static void
15435 cmd_ptype_mapping_reset_parsed(
15436         void *parsed_result,
15437         __rte_unused struct cmdline *cl,
15438         __rte_unused void *data)
15439 {
15440         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15441         int ret = -ENOTSUP;
15442
15443         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15444                 return;
15445
15446 #ifdef RTE_NET_I40E
15447         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15448 #endif
15449
15450         switch (ret) {
15451         case 0:
15452                 break;
15453         case -ENODEV:
15454                 printf("invalid port_id %d\n", res->port_id);
15455                 break;
15456         case -ENOTSUP:
15457                 printf("function not implemented\n");
15458                 break;
15459         default:
15460                 printf("programming error: (%s)\n", strerror(-ret));
15461         }
15462 }
15463
15464 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15465         .f = cmd_ptype_mapping_reset_parsed,
15466         .data = NULL,
15467         .help_str = "ptype mapping reset <port_id>",
15468         .tokens = {
15469                 (void *)&cmd_ptype_mapping_reset_ptype,
15470                 (void *)&cmd_ptype_mapping_reset_mapping,
15471                 (void *)&cmd_ptype_mapping_reset_reset,
15472                 (void *)&cmd_ptype_mapping_reset_port_id,
15473                 NULL,
15474         },
15475 };
15476
15477 /* ptype mapping update */
15478
15479 /* Common result structure for ptype mapping update */
15480 struct cmd_ptype_mapping_update_result {
15481         cmdline_fixed_string_t ptype;
15482         cmdline_fixed_string_t mapping;
15483         cmdline_fixed_string_t reset;
15484         portid_t port_id;
15485         uint8_t hw_ptype;
15486         uint32_t sw_ptype;
15487 };
15488
15489 /* Common CLI fields for ptype mapping update*/
15490 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15491         TOKEN_STRING_INITIALIZER
15492                 (struct cmd_ptype_mapping_update_result,
15493                  ptype, "ptype");
15494 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15495         TOKEN_STRING_INITIALIZER
15496                 (struct cmd_ptype_mapping_update_result,
15497                  mapping, "mapping");
15498 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15499         TOKEN_STRING_INITIALIZER
15500                 (struct cmd_ptype_mapping_update_result,
15501                  reset, "update");
15502 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15503         TOKEN_NUM_INITIALIZER
15504                 (struct cmd_ptype_mapping_update_result,
15505                  port_id, RTE_UINT16);
15506 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15507         TOKEN_NUM_INITIALIZER
15508                 (struct cmd_ptype_mapping_update_result,
15509                  hw_ptype, RTE_UINT8);
15510 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15511         TOKEN_NUM_INITIALIZER
15512                 (struct cmd_ptype_mapping_update_result,
15513                  sw_ptype, RTE_UINT32);
15514
15515 static void
15516 cmd_ptype_mapping_update_parsed(
15517         void *parsed_result,
15518         __rte_unused struct cmdline *cl,
15519         __rte_unused void *data)
15520 {
15521         struct cmd_ptype_mapping_update_result *res = parsed_result;
15522         int ret = -ENOTSUP;
15523 #ifdef RTE_NET_I40E
15524         struct rte_pmd_i40e_ptype_mapping mapping;
15525 #endif
15526         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15527                 return;
15528
15529 #ifdef RTE_NET_I40E
15530         mapping.hw_ptype = res->hw_ptype;
15531         mapping.sw_ptype = res->sw_ptype;
15532         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15533                                                 &mapping,
15534                                                 1,
15535                                                 0);
15536 #endif
15537
15538         switch (ret) {
15539         case 0:
15540                 break;
15541         case -EINVAL:
15542                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15543                 break;
15544         case -ENODEV:
15545                 printf("invalid port_id %d\n", res->port_id);
15546                 break;
15547         case -ENOTSUP:
15548                 printf("function not implemented\n");
15549                 break;
15550         default:
15551                 printf("programming error: (%s)\n", strerror(-ret));
15552         }
15553 }
15554
15555 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15556         .f = cmd_ptype_mapping_update_parsed,
15557         .data = NULL,
15558         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15559         .tokens = {
15560                 (void *)&cmd_ptype_mapping_update_ptype,
15561                 (void *)&cmd_ptype_mapping_update_mapping,
15562                 (void *)&cmd_ptype_mapping_update_update,
15563                 (void *)&cmd_ptype_mapping_update_port_id,
15564                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15565                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15566                 NULL,
15567         },
15568 };
15569
15570 /* Common result structure for file commands */
15571 struct cmd_cmdfile_result {
15572         cmdline_fixed_string_t load;
15573         cmdline_fixed_string_t filename;
15574 };
15575
15576 /* Common CLI fields for file commands */
15577 cmdline_parse_token_string_t cmd_load_cmdfile =
15578         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15579 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15580         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15581
15582 static void
15583 cmd_load_from_file_parsed(
15584         void *parsed_result,
15585         __rte_unused struct cmdline *cl,
15586         __rte_unused void *data)
15587 {
15588         struct cmd_cmdfile_result *res = parsed_result;
15589
15590         cmdline_read_from_file(res->filename);
15591 }
15592
15593 cmdline_parse_inst_t cmd_load_from_file = {
15594         .f = cmd_load_from_file_parsed,
15595         .data = NULL,
15596         .help_str = "load <filename>",
15597         .tokens = {
15598                 (void *)&cmd_load_cmdfile,
15599                 (void *)&cmd_load_cmdfile_filename,
15600                 NULL,
15601         },
15602 };
15603
15604 /* Get Rx offloads capabilities */
15605 struct cmd_rx_offload_get_capa_result {
15606         cmdline_fixed_string_t show;
15607         cmdline_fixed_string_t port;
15608         portid_t port_id;
15609         cmdline_fixed_string_t rx_offload;
15610         cmdline_fixed_string_t capabilities;
15611 };
15612
15613 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15614         TOKEN_STRING_INITIALIZER
15615                 (struct cmd_rx_offload_get_capa_result,
15616                  show, "show");
15617 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15618         TOKEN_STRING_INITIALIZER
15619                 (struct cmd_rx_offload_get_capa_result,
15620                  port, "port");
15621 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15622         TOKEN_NUM_INITIALIZER
15623                 (struct cmd_rx_offload_get_capa_result,
15624                  port_id, RTE_UINT16);
15625 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15626         TOKEN_STRING_INITIALIZER
15627                 (struct cmd_rx_offload_get_capa_result,
15628                  rx_offload, "rx_offload");
15629 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15630         TOKEN_STRING_INITIALIZER
15631                 (struct cmd_rx_offload_get_capa_result,
15632                  capabilities, "capabilities");
15633
15634 static void
15635 print_rx_offloads(uint64_t offloads)
15636 {
15637         uint64_t single_offload;
15638         int begin;
15639         int end;
15640         int bit;
15641
15642         if (offloads == 0)
15643                 return;
15644
15645         begin = __builtin_ctzll(offloads);
15646         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15647
15648         single_offload = 1ULL << begin;
15649         for (bit = begin; bit < end; bit++) {
15650                 if (offloads & single_offload)
15651                         printf(" %s",
15652                                rte_eth_dev_rx_offload_name(single_offload));
15653                 single_offload <<= 1;
15654         }
15655 }
15656
15657 static void
15658 cmd_rx_offload_get_capa_parsed(
15659         void *parsed_result,
15660         __rte_unused struct cmdline *cl,
15661         __rte_unused void *data)
15662 {
15663         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15664         struct rte_eth_dev_info dev_info;
15665         portid_t port_id = res->port_id;
15666         uint64_t queue_offloads;
15667         uint64_t port_offloads;
15668         int ret;
15669
15670         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15671         if (ret != 0)
15672                 return;
15673
15674         queue_offloads = dev_info.rx_queue_offload_capa;
15675         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15676
15677         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15678         printf("  Per Queue :");
15679         print_rx_offloads(queue_offloads);
15680
15681         printf("\n");
15682         printf("  Per Port  :");
15683         print_rx_offloads(port_offloads);
15684         printf("\n\n");
15685 }
15686
15687 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15688         .f = cmd_rx_offload_get_capa_parsed,
15689         .data = NULL,
15690         .help_str = "show port <port_id> rx_offload capabilities",
15691         .tokens = {
15692                 (void *)&cmd_rx_offload_get_capa_show,
15693                 (void *)&cmd_rx_offload_get_capa_port,
15694                 (void *)&cmd_rx_offload_get_capa_port_id,
15695                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15696                 (void *)&cmd_rx_offload_get_capa_capabilities,
15697                 NULL,
15698         }
15699 };
15700
15701 /* Get Rx offloads configuration */
15702 struct cmd_rx_offload_get_configuration_result {
15703         cmdline_fixed_string_t show;
15704         cmdline_fixed_string_t port;
15705         portid_t port_id;
15706         cmdline_fixed_string_t rx_offload;
15707         cmdline_fixed_string_t configuration;
15708 };
15709
15710 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15711         TOKEN_STRING_INITIALIZER
15712                 (struct cmd_rx_offload_get_configuration_result,
15713                  show, "show");
15714 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15715         TOKEN_STRING_INITIALIZER
15716                 (struct cmd_rx_offload_get_configuration_result,
15717                  port, "port");
15718 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15719         TOKEN_NUM_INITIALIZER
15720                 (struct cmd_rx_offload_get_configuration_result,
15721                  port_id, RTE_UINT16);
15722 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15723         TOKEN_STRING_INITIALIZER
15724                 (struct cmd_rx_offload_get_configuration_result,
15725                  rx_offload, "rx_offload");
15726 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15727         TOKEN_STRING_INITIALIZER
15728                 (struct cmd_rx_offload_get_configuration_result,
15729                  configuration, "configuration");
15730
15731 static void
15732 cmd_rx_offload_get_configuration_parsed(
15733         void *parsed_result,
15734         __rte_unused struct cmdline *cl,
15735         __rte_unused void *data)
15736 {
15737         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15738         struct rte_eth_dev_info dev_info;
15739         portid_t port_id = res->port_id;
15740         struct rte_port *port = &ports[port_id];
15741         uint64_t port_offloads;
15742         uint64_t queue_offloads;
15743         uint16_t nb_rx_queues;
15744         int q;
15745         int ret;
15746
15747         printf("Rx Offloading Configuration of port %d :\n", port_id);
15748
15749         port_offloads = port->dev_conf.rxmode.offloads;
15750         printf("  Port :");
15751         print_rx_offloads(port_offloads);
15752         printf("\n");
15753
15754         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15755         if (ret != 0)
15756                 return;
15757
15758         nb_rx_queues = dev_info.nb_rx_queues;
15759         for (q = 0; q < nb_rx_queues; q++) {
15760                 queue_offloads = port->rx_conf[q].offloads;
15761                 printf("  Queue[%2d] :", q);
15762                 print_rx_offloads(queue_offloads);
15763                 printf("\n");
15764         }
15765         printf("\n");
15766 }
15767
15768 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15769         .f = cmd_rx_offload_get_configuration_parsed,
15770         .data = NULL,
15771         .help_str = "show port <port_id> rx_offload configuration",
15772         .tokens = {
15773                 (void *)&cmd_rx_offload_get_configuration_show,
15774                 (void *)&cmd_rx_offload_get_configuration_port,
15775                 (void *)&cmd_rx_offload_get_configuration_port_id,
15776                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15777                 (void *)&cmd_rx_offload_get_configuration_configuration,
15778                 NULL,
15779         }
15780 };
15781
15782 /* Enable/Disable a per port offloading */
15783 struct cmd_config_per_port_rx_offload_result {
15784         cmdline_fixed_string_t port;
15785         cmdline_fixed_string_t config;
15786         portid_t port_id;
15787         cmdline_fixed_string_t rx_offload;
15788         cmdline_fixed_string_t offload;
15789         cmdline_fixed_string_t on_off;
15790 };
15791
15792 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15793         TOKEN_STRING_INITIALIZER
15794                 (struct cmd_config_per_port_rx_offload_result,
15795                  port, "port");
15796 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15797         TOKEN_STRING_INITIALIZER
15798                 (struct cmd_config_per_port_rx_offload_result,
15799                  config, "config");
15800 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15801         TOKEN_NUM_INITIALIZER
15802                 (struct cmd_config_per_port_rx_offload_result,
15803                  port_id, RTE_UINT16);
15804 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15805         TOKEN_STRING_INITIALIZER
15806                 (struct cmd_config_per_port_rx_offload_result,
15807                  rx_offload, "rx_offload");
15808 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15809         TOKEN_STRING_INITIALIZER
15810                 (struct cmd_config_per_port_rx_offload_result,
15811                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15812                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15813                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15814                            "scatter#buffer_split#timestamp#security#"
15815                            "keep_crc#rss_hash");
15816 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15817         TOKEN_STRING_INITIALIZER
15818                 (struct cmd_config_per_port_rx_offload_result,
15819                  on_off, "on#off");
15820
15821 static uint64_t
15822 search_rx_offload(const char *name)
15823 {
15824         uint64_t single_offload;
15825         const char *single_name;
15826         int found = 0;
15827         unsigned int bit;
15828
15829         single_offload = 1;
15830         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15831                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15832                 if (!strcasecmp(single_name, name)) {
15833                         found = 1;
15834                         break;
15835                 }
15836                 single_offload <<= 1;
15837         }
15838
15839         if (found)
15840                 return single_offload;
15841
15842         return 0;
15843 }
15844
15845 static void
15846 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
15847                                 __rte_unused struct cmdline *cl,
15848                                 __rte_unused void *data)
15849 {
15850         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
15851         portid_t port_id = res->port_id;
15852         struct rte_eth_dev_info dev_info;
15853         struct rte_port *port = &ports[port_id];
15854         uint64_t single_offload;
15855         uint16_t nb_rx_queues;
15856         int q;
15857         int ret;
15858
15859         if (port->port_status != RTE_PORT_STOPPED) {
15860                 printf("Error: Can't config offload when Port %d "
15861                        "is not stopped\n", port_id);
15862                 return;
15863         }
15864
15865         single_offload = search_rx_offload(res->offload);
15866         if (single_offload == 0) {
15867                 printf("Unknown offload name: %s\n", res->offload);
15868                 return;
15869         }
15870
15871         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15872         if (ret != 0)
15873                 return;
15874
15875         nb_rx_queues = dev_info.nb_rx_queues;
15876         if (!strcmp(res->on_off, "on")) {
15877                 port->dev_conf.rxmode.offloads |= single_offload;
15878                 for (q = 0; q < nb_rx_queues; q++)
15879                         port->rx_conf[q].offloads |= single_offload;
15880         } else {
15881                 port->dev_conf.rxmode.offloads &= ~single_offload;
15882                 for (q = 0; q < nb_rx_queues; q++)
15883                         port->rx_conf[q].offloads &= ~single_offload;
15884         }
15885
15886         cmd_reconfig_device_queue(port_id, 1, 1);
15887 }
15888
15889 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
15890         .f = cmd_config_per_port_rx_offload_parsed,
15891         .data = NULL,
15892         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
15893                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
15894                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
15895                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
15896                     "keep_crc|rss_hash on|off",
15897         .tokens = {
15898                 (void *)&cmd_config_per_port_rx_offload_result_port,
15899                 (void *)&cmd_config_per_port_rx_offload_result_config,
15900                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
15901                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
15902                 (void *)&cmd_config_per_port_rx_offload_result_offload,
15903                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
15904                 NULL,
15905         }
15906 };
15907
15908 /* Enable/Disable a per queue offloading */
15909 struct cmd_config_per_queue_rx_offload_result {
15910         cmdline_fixed_string_t port;
15911         portid_t port_id;
15912         cmdline_fixed_string_t rxq;
15913         uint16_t queue_id;
15914         cmdline_fixed_string_t rx_offload;
15915         cmdline_fixed_string_t offload;
15916         cmdline_fixed_string_t on_off;
15917 };
15918
15919 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
15920         TOKEN_STRING_INITIALIZER
15921                 (struct cmd_config_per_queue_rx_offload_result,
15922                  port, "port");
15923 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
15924         TOKEN_NUM_INITIALIZER
15925                 (struct cmd_config_per_queue_rx_offload_result,
15926                  port_id, RTE_UINT16);
15927 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
15928         TOKEN_STRING_INITIALIZER
15929                 (struct cmd_config_per_queue_rx_offload_result,
15930                  rxq, "rxq");
15931 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
15932         TOKEN_NUM_INITIALIZER
15933                 (struct cmd_config_per_queue_rx_offload_result,
15934                  queue_id, RTE_UINT16);
15935 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
15936         TOKEN_STRING_INITIALIZER
15937                 (struct cmd_config_per_queue_rx_offload_result,
15938                  rx_offload, "rx_offload");
15939 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
15940         TOKEN_STRING_INITIALIZER
15941                 (struct cmd_config_per_queue_rx_offload_result,
15942                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15943                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15944                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15945                            "scatter#buffer_split#timestamp#security#keep_crc");
15946 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
15947         TOKEN_STRING_INITIALIZER
15948                 (struct cmd_config_per_queue_rx_offload_result,
15949                  on_off, "on#off");
15950
15951 static void
15952 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
15953                                 __rte_unused struct cmdline *cl,
15954                                 __rte_unused void *data)
15955 {
15956         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
15957         struct rte_eth_dev_info dev_info;
15958         portid_t port_id = res->port_id;
15959         uint16_t queue_id = res->queue_id;
15960         struct rte_port *port = &ports[port_id];
15961         uint64_t single_offload;
15962         int ret;
15963
15964         if (port->port_status != RTE_PORT_STOPPED) {
15965                 printf("Error: Can't config offload when Port %d "
15966                        "is not stopped\n", port_id);
15967                 return;
15968         }
15969
15970         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15971         if (ret != 0)
15972                 return;
15973
15974         if (queue_id >= dev_info.nb_rx_queues) {
15975                 printf("Error: input queue_id should be 0 ... "
15976                        "%d\n", dev_info.nb_rx_queues - 1);
15977                 return;
15978         }
15979
15980         single_offload = search_rx_offload(res->offload);
15981         if (single_offload == 0) {
15982                 printf("Unknown offload name: %s\n", res->offload);
15983                 return;
15984         }
15985
15986         if (!strcmp(res->on_off, "on"))
15987                 port->rx_conf[queue_id].offloads |= single_offload;
15988         else
15989                 port->rx_conf[queue_id].offloads &= ~single_offload;
15990
15991         cmd_reconfig_device_queue(port_id, 1, 1);
15992 }
15993
15994 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
15995         .f = cmd_config_per_queue_rx_offload_parsed,
15996         .data = NULL,
15997         .help_str = "port <port_id> rxq <queue_id> rx_offload "
15998                     "vlan_strip|ipv4_cksum|"
15999                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16000                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16001                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16002                     "keep_crc on|off",
16003         .tokens = {
16004                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16005                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16006                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16007                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16008                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16009                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16010                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16011                 NULL,
16012         }
16013 };
16014
16015 /* Get Tx offloads capabilities */
16016 struct cmd_tx_offload_get_capa_result {
16017         cmdline_fixed_string_t show;
16018         cmdline_fixed_string_t port;
16019         portid_t port_id;
16020         cmdline_fixed_string_t tx_offload;
16021         cmdline_fixed_string_t capabilities;
16022 };
16023
16024 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16025         TOKEN_STRING_INITIALIZER
16026                 (struct cmd_tx_offload_get_capa_result,
16027                  show, "show");
16028 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16029         TOKEN_STRING_INITIALIZER
16030                 (struct cmd_tx_offload_get_capa_result,
16031                  port, "port");
16032 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16033         TOKEN_NUM_INITIALIZER
16034                 (struct cmd_tx_offload_get_capa_result,
16035                  port_id, RTE_UINT16);
16036 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16037         TOKEN_STRING_INITIALIZER
16038                 (struct cmd_tx_offload_get_capa_result,
16039                  tx_offload, "tx_offload");
16040 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16041         TOKEN_STRING_INITIALIZER
16042                 (struct cmd_tx_offload_get_capa_result,
16043                  capabilities, "capabilities");
16044
16045 static void
16046 print_tx_offloads(uint64_t offloads)
16047 {
16048         uint64_t single_offload;
16049         int begin;
16050         int end;
16051         int bit;
16052
16053         if (offloads == 0)
16054                 return;
16055
16056         begin = __builtin_ctzll(offloads);
16057         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16058
16059         single_offload = 1ULL << begin;
16060         for (bit = begin; bit < end; bit++) {
16061                 if (offloads & single_offload)
16062                         printf(" %s",
16063                                rte_eth_dev_tx_offload_name(single_offload));
16064                 single_offload <<= 1;
16065         }
16066 }
16067
16068 static void
16069 cmd_tx_offload_get_capa_parsed(
16070         void *parsed_result,
16071         __rte_unused struct cmdline *cl,
16072         __rte_unused void *data)
16073 {
16074         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16075         struct rte_eth_dev_info dev_info;
16076         portid_t port_id = res->port_id;
16077         uint64_t queue_offloads;
16078         uint64_t port_offloads;
16079         int ret;
16080
16081         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16082         if (ret != 0)
16083                 return;
16084
16085         queue_offloads = dev_info.tx_queue_offload_capa;
16086         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16087
16088         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16089         printf("  Per Queue :");
16090         print_tx_offloads(queue_offloads);
16091
16092         printf("\n");
16093         printf("  Per Port  :");
16094         print_tx_offloads(port_offloads);
16095         printf("\n\n");
16096 }
16097
16098 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16099         .f = cmd_tx_offload_get_capa_parsed,
16100         .data = NULL,
16101         .help_str = "show port <port_id> tx_offload capabilities",
16102         .tokens = {
16103                 (void *)&cmd_tx_offload_get_capa_show,
16104                 (void *)&cmd_tx_offload_get_capa_port,
16105                 (void *)&cmd_tx_offload_get_capa_port_id,
16106                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16107                 (void *)&cmd_tx_offload_get_capa_capabilities,
16108                 NULL,
16109         }
16110 };
16111
16112 /* Get Tx offloads configuration */
16113 struct cmd_tx_offload_get_configuration_result {
16114         cmdline_fixed_string_t show;
16115         cmdline_fixed_string_t port;
16116         portid_t port_id;
16117         cmdline_fixed_string_t tx_offload;
16118         cmdline_fixed_string_t configuration;
16119 };
16120
16121 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16122         TOKEN_STRING_INITIALIZER
16123                 (struct cmd_tx_offload_get_configuration_result,
16124                  show, "show");
16125 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16126         TOKEN_STRING_INITIALIZER
16127                 (struct cmd_tx_offload_get_configuration_result,
16128                  port, "port");
16129 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16130         TOKEN_NUM_INITIALIZER
16131                 (struct cmd_tx_offload_get_configuration_result,
16132                  port_id, RTE_UINT16);
16133 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16134         TOKEN_STRING_INITIALIZER
16135                 (struct cmd_tx_offload_get_configuration_result,
16136                  tx_offload, "tx_offload");
16137 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16138         TOKEN_STRING_INITIALIZER
16139                 (struct cmd_tx_offload_get_configuration_result,
16140                  configuration, "configuration");
16141
16142 static void
16143 cmd_tx_offload_get_configuration_parsed(
16144         void *parsed_result,
16145         __rte_unused struct cmdline *cl,
16146         __rte_unused void *data)
16147 {
16148         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16149         struct rte_eth_dev_info dev_info;
16150         portid_t port_id = res->port_id;
16151         struct rte_port *port = &ports[port_id];
16152         uint64_t port_offloads;
16153         uint64_t queue_offloads;
16154         uint16_t nb_tx_queues;
16155         int q;
16156         int ret;
16157
16158         printf("Tx Offloading Configuration of port %d :\n", port_id);
16159
16160         port_offloads = port->dev_conf.txmode.offloads;
16161         printf("  Port :");
16162         print_tx_offloads(port_offloads);
16163         printf("\n");
16164
16165         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16166         if (ret != 0)
16167                 return;
16168
16169         nb_tx_queues = dev_info.nb_tx_queues;
16170         for (q = 0; q < nb_tx_queues; q++) {
16171                 queue_offloads = port->tx_conf[q].offloads;
16172                 printf("  Queue[%2d] :", q);
16173                 print_tx_offloads(queue_offloads);
16174                 printf("\n");
16175         }
16176         printf("\n");
16177 }
16178
16179 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16180         .f = cmd_tx_offload_get_configuration_parsed,
16181         .data = NULL,
16182         .help_str = "show port <port_id> tx_offload configuration",
16183         .tokens = {
16184                 (void *)&cmd_tx_offload_get_configuration_show,
16185                 (void *)&cmd_tx_offload_get_configuration_port,
16186                 (void *)&cmd_tx_offload_get_configuration_port_id,
16187                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16188                 (void *)&cmd_tx_offload_get_configuration_configuration,
16189                 NULL,
16190         }
16191 };
16192
16193 /* Enable/Disable a per port offloading */
16194 struct cmd_config_per_port_tx_offload_result {
16195         cmdline_fixed_string_t port;
16196         cmdline_fixed_string_t config;
16197         portid_t port_id;
16198         cmdline_fixed_string_t tx_offload;
16199         cmdline_fixed_string_t offload;
16200         cmdline_fixed_string_t on_off;
16201 };
16202
16203 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16204         TOKEN_STRING_INITIALIZER
16205                 (struct cmd_config_per_port_tx_offload_result,
16206                  port, "port");
16207 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16208         TOKEN_STRING_INITIALIZER
16209                 (struct cmd_config_per_port_tx_offload_result,
16210                  config, "config");
16211 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16212         TOKEN_NUM_INITIALIZER
16213                 (struct cmd_config_per_port_tx_offload_result,
16214                  port_id, RTE_UINT16);
16215 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16216         TOKEN_STRING_INITIALIZER
16217                 (struct cmd_config_per_port_tx_offload_result,
16218                  tx_offload, "tx_offload");
16219 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16220         TOKEN_STRING_INITIALIZER
16221                 (struct cmd_config_per_port_tx_offload_result,
16222                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16223                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16224                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16225                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16226                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16227                           "send_on_timestamp");
16228 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16229         TOKEN_STRING_INITIALIZER
16230                 (struct cmd_config_per_port_tx_offload_result,
16231                  on_off, "on#off");
16232
16233 static uint64_t
16234 search_tx_offload(const char *name)
16235 {
16236         uint64_t single_offload;
16237         const char *single_name;
16238         int found = 0;
16239         unsigned int bit;
16240
16241         single_offload = 1;
16242         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16243                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16244                 if (single_name == NULL)
16245                         break;
16246                 if (!strcasecmp(single_name, name)) {
16247                         found = 1;
16248                         break;
16249                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16250                         break;
16251                 single_offload <<= 1;
16252         }
16253
16254         if (found)
16255                 return single_offload;
16256
16257         return 0;
16258 }
16259
16260 static void
16261 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16262                                 __rte_unused struct cmdline *cl,
16263                                 __rte_unused void *data)
16264 {
16265         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16266         portid_t port_id = res->port_id;
16267         struct rte_eth_dev_info dev_info;
16268         struct rte_port *port = &ports[port_id];
16269         uint64_t single_offload;
16270         uint16_t nb_tx_queues;
16271         int q;
16272         int ret;
16273
16274         if (port->port_status != RTE_PORT_STOPPED) {
16275                 printf("Error: Can't config offload when Port %d "
16276                        "is not stopped\n", port_id);
16277                 return;
16278         }
16279
16280         single_offload = search_tx_offload(res->offload);
16281         if (single_offload == 0) {
16282                 printf("Unknown offload name: %s\n", res->offload);
16283                 return;
16284         }
16285
16286         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16287         if (ret != 0)
16288                 return;
16289
16290         nb_tx_queues = dev_info.nb_tx_queues;
16291         if (!strcmp(res->on_off, "on")) {
16292                 port->dev_conf.txmode.offloads |= single_offload;
16293                 for (q = 0; q < nb_tx_queues; q++)
16294                         port->tx_conf[q].offloads |= single_offload;
16295         } else {
16296                 port->dev_conf.txmode.offloads &= ~single_offload;
16297                 for (q = 0; q < nb_tx_queues; q++)
16298                         port->tx_conf[q].offloads &= ~single_offload;
16299         }
16300
16301         cmd_reconfig_device_queue(port_id, 1, 1);
16302 }
16303
16304 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16305         .f = cmd_config_per_port_tx_offload_parsed,
16306         .data = NULL,
16307         .help_str = "port config <port_id> tx_offload "
16308                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16309                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16310                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16311                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16312                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16313                     "send_on_timestamp on|off",
16314         .tokens = {
16315                 (void *)&cmd_config_per_port_tx_offload_result_port,
16316                 (void *)&cmd_config_per_port_tx_offload_result_config,
16317                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16318                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16319                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16320                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16321                 NULL,
16322         }
16323 };
16324
16325 /* Enable/Disable a per queue offloading */
16326 struct cmd_config_per_queue_tx_offload_result {
16327         cmdline_fixed_string_t port;
16328         portid_t port_id;
16329         cmdline_fixed_string_t txq;
16330         uint16_t queue_id;
16331         cmdline_fixed_string_t tx_offload;
16332         cmdline_fixed_string_t offload;
16333         cmdline_fixed_string_t on_off;
16334 };
16335
16336 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16337         TOKEN_STRING_INITIALIZER
16338                 (struct cmd_config_per_queue_tx_offload_result,
16339                  port, "port");
16340 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16341         TOKEN_NUM_INITIALIZER
16342                 (struct cmd_config_per_queue_tx_offload_result,
16343                  port_id, RTE_UINT16);
16344 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16345         TOKEN_STRING_INITIALIZER
16346                 (struct cmd_config_per_queue_tx_offload_result,
16347                  txq, "txq");
16348 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16349         TOKEN_NUM_INITIALIZER
16350                 (struct cmd_config_per_queue_tx_offload_result,
16351                  queue_id, RTE_UINT16);
16352 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16353         TOKEN_STRING_INITIALIZER
16354                 (struct cmd_config_per_queue_tx_offload_result,
16355                  tx_offload, "tx_offload");
16356 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16357         TOKEN_STRING_INITIALIZER
16358                 (struct cmd_config_per_queue_tx_offload_result,
16359                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16360                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16361                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16362                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16363                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16364 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16365         TOKEN_STRING_INITIALIZER
16366                 (struct cmd_config_per_queue_tx_offload_result,
16367                  on_off, "on#off");
16368
16369 static void
16370 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16371                                 __rte_unused struct cmdline *cl,
16372                                 __rte_unused void *data)
16373 {
16374         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16375         struct rte_eth_dev_info dev_info;
16376         portid_t port_id = res->port_id;
16377         uint16_t queue_id = res->queue_id;
16378         struct rte_port *port = &ports[port_id];
16379         uint64_t single_offload;
16380         int ret;
16381
16382         if (port->port_status != RTE_PORT_STOPPED) {
16383                 printf("Error: Can't config offload when Port %d "
16384                        "is not stopped\n", port_id);
16385                 return;
16386         }
16387
16388         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16389         if (ret != 0)
16390                 return;
16391
16392         if (queue_id >= dev_info.nb_tx_queues) {
16393                 printf("Error: input queue_id should be 0 ... "
16394                        "%d\n", dev_info.nb_tx_queues - 1);
16395                 return;
16396         }
16397
16398         single_offload = search_tx_offload(res->offload);
16399         if (single_offload == 0) {
16400                 printf("Unknown offload name: %s\n", res->offload);
16401                 return;
16402         }
16403
16404         if (!strcmp(res->on_off, "on"))
16405                 port->tx_conf[queue_id].offloads |= single_offload;
16406         else
16407                 port->tx_conf[queue_id].offloads &= ~single_offload;
16408
16409         cmd_reconfig_device_queue(port_id, 1, 1);
16410 }
16411
16412 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16413         .f = cmd_config_per_queue_tx_offload_parsed,
16414         .data = NULL,
16415         .help_str = "port <port_id> txq <queue_id> tx_offload "
16416                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16417                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16418                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16419                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16420                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16421                     "on|off",
16422         .tokens = {
16423                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16424                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16425                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16426                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16427                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16428                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16429                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16430                 NULL,
16431         }
16432 };
16433
16434 /* *** configure tx_metadata for specific port *** */
16435 struct cmd_config_tx_metadata_specific_result {
16436         cmdline_fixed_string_t port;
16437         cmdline_fixed_string_t keyword;
16438         uint16_t port_id;
16439         cmdline_fixed_string_t item;
16440         uint32_t value;
16441 };
16442
16443 static void
16444 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16445                                 __rte_unused struct cmdline *cl,
16446                                 __rte_unused void *data)
16447 {
16448         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16449
16450         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16451                 return;
16452         ports[res->port_id].tx_metadata = res->value;
16453         /* Add/remove callback to insert valid metadata in every Tx packet. */
16454         if (ports[res->port_id].tx_metadata)
16455                 add_tx_md_callback(res->port_id);
16456         else
16457                 remove_tx_md_callback(res->port_id);
16458         rte_flow_dynf_metadata_register();
16459 }
16460
16461 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16462         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16463                         port, "port");
16464 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16465         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16466                         keyword, "config");
16467 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16468         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16469                         port_id, RTE_UINT16);
16470 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16471         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16472                         item, "tx_metadata");
16473 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16474         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16475                         value, RTE_UINT32);
16476
16477 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16478         .f = cmd_config_tx_metadata_specific_parsed,
16479         .data = NULL,
16480         .help_str = "port config <port_id> tx_metadata <value>",
16481         .tokens = {
16482                 (void *)&cmd_config_tx_metadata_specific_port,
16483                 (void *)&cmd_config_tx_metadata_specific_keyword,
16484                 (void *)&cmd_config_tx_metadata_specific_id,
16485                 (void *)&cmd_config_tx_metadata_specific_item,
16486                 (void *)&cmd_config_tx_metadata_specific_value,
16487                 NULL,
16488         },
16489 };
16490
16491 /* *** set dynf *** */
16492 struct cmd_config_tx_dynf_specific_result {
16493         cmdline_fixed_string_t port;
16494         cmdline_fixed_string_t keyword;
16495         uint16_t port_id;
16496         cmdline_fixed_string_t item;
16497         cmdline_fixed_string_t name;
16498         cmdline_fixed_string_t value;
16499 };
16500
16501 static void
16502 cmd_config_dynf_specific_parsed(void *parsed_result,
16503                                 __rte_unused struct cmdline *cl,
16504                                 __rte_unused void *data)
16505 {
16506         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16507         struct rte_mbuf_dynflag desc_flag;
16508         int flag;
16509         uint64_t old_port_flags;
16510
16511         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16512                 return;
16513         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16514         if (flag <= 0) {
16515                 if (strlcpy(desc_flag.name, res->name,
16516                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16517                         printf("Flag name too long\n");
16518                         return;
16519                 }
16520                 desc_flag.flags = 0;
16521                 flag = rte_mbuf_dynflag_register(&desc_flag);
16522                 if (flag < 0) {
16523                         printf("Can't register flag\n");
16524                         return;
16525                 }
16526                 strcpy(dynf_names[flag], desc_flag.name);
16527         }
16528         old_port_flags = ports[res->port_id].mbuf_dynf;
16529         if (!strcmp(res->value, "set")) {
16530                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16531                 if (old_port_flags == 0)
16532                         add_tx_dynf_callback(res->port_id);
16533         } else {
16534                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16535                 if (ports[res->port_id].mbuf_dynf == 0)
16536                         remove_tx_dynf_callback(res->port_id);
16537         }
16538 }
16539
16540 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16541         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16542                         keyword, "port");
16543 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16544         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16545                         keyword, "config");
16546 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16547         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16548                         port_id, RTE_UINT16);
16549 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16550         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16551                         item, "dynf");
16552 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16553         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16554                         name, NULL);
16555 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16556         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16557                         value, "set#clear");
16558
16559 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16560         .f = cmd_config_dynf_specific_parsed,
16561         .data = NULL,
16562         .help_str = "port config <port id> dynf <name> set|clear",
16563         .tokens = {
16564                 (void *)&cmd_config_tx_dynf_specific_port,
16565                 (void *)&cmd_config_tx_dynf_specific_keyword,
16566                 (void *)&cmd_config_tx_dynf_specific_port_id,
16567                 (void *)&cmd_config_tx_dynf_specific_item,
16568                 (void *)&cmd_config_tx_dynf_specific_name,
16569                 (void *)&cmd_config_tx_dynf_specific_value,
16570                 NULL,
16571         },
16572 };
16573
16574 /* *** display tx_metadata per port configuration *** */
16575 struct cmd_show_tx_metadata_result {
16576         cmdline_fixed_string_t cmd_show;
16577         cmdline_fixed_string_t cmd_port;
16578         cmdline_fixed_string_t cmd_keyword;
16579         portid_t cmd_pid;
16580 };
16581
16582 static void
16583 cmd_show_tx_metadata_parsed(void *parsed_result,
16584                 __rte_unused struct cmdline *cl,
16585                 __rte_unused void *data)
16586 {
16587         struct cmd_show_tx_metadata_result *res = parsed_result;
16588
16589         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16590                 printf("invalid port id %u\n", res->cmd_pid);
16591                 return;
16592         }
16593         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16594                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16595                        ports[res->cmd_pid].tx_metadata);
16596         }
16597 }
16598
16599 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16600         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16601                         cmd_show, "show");
16602 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16603         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16604                         cmd_port, "port");
16605 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16606         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16607                         cmd_pid, RTE_UINT16);
16608 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16609         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16610                         cmd_keyword, "tx_metadata");
16611
16612 cmdline_parse_inst_t cmd_show_tx_metadata = {
16613         .f = cmd_show_tx_metadata_parsed,
16614         .data = NULL,
16615         .help_str = "show port <port_id> tx_metadata",
16616         .tokens = {
16617                 (void *)&cmd_show_tx_metadata_show,
16618                 (void *)&cmd_show_tx_metadata_port,
16619                 (void *)&cmd_show_tx_metadata_pid,
16620                 (void *)&cmd_show_tx_metadata_keyword,
16621                 NULL,
16622         },
16623 };
16624
16625 /* *** show fec capability per port configuration *** */
16626 struct cmd_show_fec_capability_result {
16627         cmdline_fixed_string_t cmd_show;
16628         cmdline_fixed_string_t cmd_port;
16629         cmdline_fixed_string_t cmd_fec;
16630         cmdline_fixed_string_t cmd_keyword;
16631         portid_t cmd_pid;
16632 };
16633
16634 static void
16635 cmd_show_fec_capability_parsed(void *parsed_result,
16636                 __rte_unused struct cmdline *cl,
16637                 __rte_unused void *data)
16638 {
16639         struct cmd_show_fec_capability_result *res = parsed_result;
16640         struct rte_eth_fec_capa *speed_fec_capa;
16641         unsigned int num;
16642         int ret;
16643
16644         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16645                 printf("Invalid port id %u\n", res->cmd_pid);
16646                 return;
16647         }
16648
16649         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
16650         if (ret == -ENOTSUP) {
16651                 printf("Function not implemented\n");
16652                 return;
16653         } else if (ret < 0) {
16654                 printf("Get FEC capability failed: %d\n", ret);
16655                 return;
16656         }
16657
16658         num = (unsigned int)ret;
16659         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
16660         if (speed_fec_capa == NULL) {
16661                 printf("Failed to alloc FEC capability buffer\n");
16662                 return;
16663         }
16664
16665         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16666         if (ret < 0) {
16667                 printf("Error getting FEC capability: %d\n", ret);
16668                 goto out;
16669         }
16670
16671         show_fec_capability(num, speed_fec_capa);
16672 out:
16673         free(speed_fec_capa);
16674 }
16675
16676 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16677         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16678                         cmd_show, "show");
16679 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16680         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16681                         cmd_port, "port");
16682 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16683         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16684                         cmd_pid, RTE_UINT16);
16685 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16686         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16687                         cmd_fec, "fec");
16688 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16689         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16690                         cmd_keyword, "capabilities");
16691
16692 cmdline_parse_inst_t cmd_show_capability = {
16693         .f = cmd_show_fec_capability_parsed,
16694         .data = NULL,
16695         .help_str = "show port <port_id> fec capabilities",
16696         .tokens = {
16697                 (void *)&cmd_show_fec_capability_show,
16698                 (void *)&cmd_show_fec_capability_port,
16699                 (void *)&cmd_show_fec_capability_pid,
16700                 (void *)&cmd_show_fec_capability_fec,
16701                 (void *)&cmd_show_fec_capability_keyword,
16702                 NULL,
16703         },
16704 };
16705
16706 /* *** show fec mode per port configuration *** */
16707 struct cmd_show_fec_metadata_result {
16708         cmdline_fixed_string_t cmd_show;
16709         cmdline_fixed_string_t cmd_port;
16710         cmdline_fixed_string_t cmd_keyword;
16711         portid_t cmd_pid;
16712 };
16713
16714 static void
16715 cmd_show_fec_mode_parsed(void *parsed_result,
16716                 __rte_unused struct cmdline *cl,
16717                 __rte_unused void *data)
16718 {
16719 #define FEC_NAME_SIZE 16
16720         struct cmd_show_fec_metadata_result *res = parsed_result;
16721         uint32_t mode;
16722         char buf[FEC_NAME_SIZE];
16723         int ret;
16724
16725         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16726                 printf("Invalid port id %u\n", res->cmd_pid);
16727                 return;
16728         }
16729         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16730         if (ret == -ENOTSUP) {
16731                 printf("Function not implemented\n");
16732                 return;
16733         } else if (ret < 0) {
16734                 printf("Get FEC mode failed\n");
16735                 return;
16736         }
16737
16738         switch (mode) {
16739         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16740                 strlcpy(buf, "off", sizeof(buf));
16741                 break;
16742         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16743                 strlcpy(buf, "auto", sizeof(buf));
16744                 break;
16745         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16746                 strlcpy(buf, "baser", sizeof(buf));
16747                 break;
16748         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16749                 strlcpy(buf, "rs", sizeof(buf));
16750                 break;
16751         default:
16752                 return;
16753         }
16754
16755         printf("%s\n", buf);
16756 }
16757
16758 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16759         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16760                         cmd_show, "show");
16761 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16762         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16763                         cmd_port, "port");
16764 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16765         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16766                         cmd_pid, RTE_UINT16);
16767 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16768         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16769                         cmd_keyword, "fec_mode");
16770
16771 cmdline_parse_inst_t cmd_show_fec_mode = {
16772         .f = cmd_show_fec_mode_parsed,
16773         .data = NULL,
16774         .help_str = "show port <port_id> fec_mode",
16775         .tokens = {
16776                 (void *)&cmd_show_fec_mode_show,
16777                 (void *)&cmd_show_fec_mode_port,
16778                 (void *)&cmd_show_fec_mode_pid,
16779                 (void *)&cmd_show_fec_mode_keyword,
16780                 NULL,
16781         },
16782 };
16783
16784 /* *** set fec mode per port configuration *** */
16785 struct cmd_set_port_fec_mode {
16786         cmdline_fixed_string_t set;
16787         cmdline_fixed_string_t port;
16788         portid_t port_id;
16789         cmdline_fixed_string_t fec_mode;
16790         cmdline_fixed_string_t fec_value;
16791 };
16792
16793 /* Common CLI fields for set fec mode */
16794 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16795         TOKEN_STRING_INITIALIZER
16796                 (struct cmd_set_port_fec_mode,
16797                  set, "set");
16798 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16799         TOKEN_STRING_INITIALIZER
16800                 (struct cmd_set_port_fec_mode,
16801                  port, "port");
16802 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16803         TOKEN_NUM_INITIALIZER
16804                 (struct cmd_set_port_fec_mode,
16805                  port_id, RTE_UINT16);
16806 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16807         TOKEN_STRING_INITIALIZER
16808                 (struct cmd_set_port_fec_mode,
16809                  fec_mode, "fec_mode");
16810 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16811         TOKEN_STRING_INITIALIZER
16812                 (struct cmd_set_port_fec_mode,
16813                  fec_value, NULL);
16814
16815 static void
16816 cmd_set_port_fec_mode_parsed(
16817         void *parsed_result,
16818         __rte_unused struct cmdline *cl,
16819         __rte_unused void *data)
16820 {
16821         struct cmd_set_port_fec_mode *res = parsed_result;
16822         uint16_t port_id = res->port_id;
16823         uint32_t mode;
16824         int ret;
16825
16826         ret = parse_fec_mode(res->fec_value, &mode);
16827         if (ret < 0) {
16828                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16829                         port_id);
16830                 return;
16831         }
16832
16833         ret = rte_eth_fec_set(port_id, mode);
16834         if (ret == -ENOTSUP) {
16835                 printf("Function not implemented\n");
16836                 return;
16837         } else if (ret < 0) {
16838                 printf("Set FEC mode failed\n");
16839                 return;
16840         }
16841 }
16842
16843 cmdline_parse_inst_t cmd_set_fec_mode = {
16844         .f = cmd_set_port_fec_mode_parsed,
16845         .data = NULL,
16846         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
16847         .tokens = {
16848                 (void *)&cmd_set_port_fec_mode_set,
16849                 (void *)&cmd_set_port_fec_mode_port,
16850                 (void *)&cmd_set_port_fec_mode_port_id,
16851                 (void *)&cmd_set_port_fec_mode_str,
16852                 (void *)&cmd_set_port_fec_mode_value,
16853                 NULL,
16854         },
16855 };
16856
16857 /* show port supported ptypes */
16858
16859 /* Common result structure for show port ptypes */
16860 struct cmd_show_port_supported_ptypes_result {
16861         cmdline_fixed_string_t show;
16862         cmdline_fixed_string_t port;
16863         portid_t port_id;
16864         cmdline_fixed_string_t ptypes;
16865 };
16866
16867 /* Common CLI fields for show port ptypes */
16868 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
16869         TOKEN_STRING_INITIALIZER
16870                 (struct cmd_show_port_supported_ptypes_result,
16871                  show, "show");
16872 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
16873         TOKEN_STRING_INITIALIZER
16874                 (struct cmd_show_port_supported_ptypes_result,
16875                  port, "port");
16876 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
16877         TOKEN_NUM_INITIALIZER
16878                 (struct cmd_show_port_supported_ptypes_result,
16879                  port_id, RTE_UINT16);
16880 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
16881         TOKEN_STRING_INITIALIZER
16882                 (struct cmd_show_port_supported_ptypes_result,
16883                  ptypes, "ptypes");
16884
16885 static void
16886 cmd_show_port_supported_ptypes_parsed(
16887         void *parsed_result,
16888         __rte_unused struct cmdline *cl,
16889         __rte_unused void *data)
16890 {
16891 #define RSVD_PTYPE_MASK       0xf0000000
16892 #define MAX_PTYPES_PER_LAYER  16
16893 #define LTYPE_NAMESIZE        32
16894 #define PTYPE_NAMESIZE        256
16895         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
16896         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
16897         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
16898         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
16899         uint16_t port_id = res->port_id;
16900         int ret, i;
16901
16902         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
16903         if (ret < 0)
16904                 return;
16905
16906         while (ptype_mask != RSVD_PTYPE_MASK) {
16907
16908                 switch (ptype_mask) {
16909                 case RTE_PTYPE_L2_MASK:
16910                         strlcpy(ltype, "L2", sizeof(ltype));
16911                         break;
16912                 case RTE_PTYPE_L3_MASK:
16913                         strlcpy(ltype, "L3", sizeof(ltype));
16914                         break;
16915                 case RTE_PTYPE_L4_MASK:
16916                         strlcpy(ltype, "L4", sizeof(ltype));
16917                         break;
16918                 case RTE_PTYPE_TUNNEL_MASK:
16919                         strlcpy(ltype, "Tunnel", sizeof(ltype));
16920                         break;
16921                 case RTE_PTYPE_INNER_L2_MASK:
16922                         strlcpy(ltype, "Inner L2", sizeof(ltype));
16923                         break;
16924                 case RTE_PTYPE_INNER_L3_MASK:
16925                         strlcpy(ltype, "Inner L3", sizeof(ltype));
16926                         break;
16927                 case RTE_PTYPE_INNER_L4_MASK:
16928                         strlcpy(ltype, "Inner L4", sizeof(ltype));
16929                         break;
16930                 default:
16931                         return;
16932                 }
16933
16934                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
16935                                                        ptype_mask, ptypes,
16936                                                        MAX_PTYPES_PER_LAYER);
16937
16938                 if (ret > 0)
16939                         printf("Supported %s ptypes:\n", ltype);
16940                 else
16941                         printf("%s ptypes unsupported\n", ltype);
16942
16943                 for (i = 0; i < ret; ++i) {
16944                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
16945                         printf("%s\n", buf);
16946                 }
16947
16948                 ptype_mask <<= 4;
16949         }
16950 }
16951
16952 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
16953         .f = cmd_show_port_supported_ptypes_parsed,
16954         .data = NULL,
16955         .help_str = "show port <port_id> ptypes",
16956         .tokens = {
16957                 (void *)&cmd_show_port_supported_ptypes_show,
16958                 (void *)&cmd_show_port_supported_ptypes_port,
16959                 (void *)&cmd_show_port_supported_ptypes_port_id,
16960                 (void *)&cmd_show_port_supported_ptypes_ptypes,
16961                 NULL,
16962         },
16963 };
16964
16965 /* *** display rx/tx descriptor status *** */
16966 struct cmd_show_rx_tx_desc_status_result {
16967         cmdline_fixed_string_t cmd_show;
16968         cmdline_fixed_string_t cmd_port;
16969         cmdline_fixed_string_t cmd_keyword;
16970         cmdline_fixed_string_t cmd_desc;
16971         cmdline_fixed_string_t cmd_status;
16972         portid_t cmd_pid;
16973         portid_t cmd_qid;
16974         portid_t cmd_did;
16975 };
16976
16977 static void
16978 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
16979                 __rte_unused struct cmdline *cl,
16980                 __rte_unused void *data)
16981 {
16982         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
16983         int rc;
16984
16985         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16986                 printf("invalid port id %u\n", res->cmd_pid);
16987                 return;
16988         }
16989
16990         if (!strcmp(res->cmd_keyword, "rxq")) {
16991                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
16992                                              res->cmd_did);
16993                 if (rc < 0) {
16994                         printf("Invalid input: queue id = %d, desc id = %d\n",
16995                                res->cmd_qid, res->cmd_did);
16996                         return;
16997                 }
16998                 if (rc == RTE_ETH_RX_DESC_AVAIL)
16999                         printf("Desc status = AVAILABLE\n");
17000                 else if (rc == RTE_ETH_RX_DESC_DONE)
17001                         printf("Desc status = DONE\n");
17002                 else
17003                         printf("Desc status = UNAVAILABLE\n");
17004         } else if (!strcmp(res->cmd_keyword, "txq")) {
17005                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17006                                              res->cmd_did);
17007                 if (rc < 0) {
17008                         printf("Invalid input: queue id = %d, desc id = %d\n",
17009                                res->cmd_qid, res->cmd_did);
17010                         return;
17011                 }
17012                 if (rc == RTE_ETH_TX_DESC_FULL)
17013                         printf("Desc status = FULL\n");
17014                 else if (rc == RTE_ETH_TX_DESC_DONE)
17015                         printf("Desc status = DONE\n");
17016                 else
17017                         printf("Desc status = UNAVAILABLE\n");
17018         }
17019 }
17020
17021 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17022         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17023                         cmd_show, "show");
17024 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17025         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17026                         cmd_port, "port");
17027 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17028         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17029                         cmd_pid, RTE_UINT16);
17030 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17031         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17032                         cmd_keyword, "rxq#txq");
17033 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17034         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17035                         cmd_qid, RTE_UINT16);
17036 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17037         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17038                         cmd_desc, "desc");
17039 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17040         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17041                         cmd_did, RTE_UINT16);
17042 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17043         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17044                         cmd_status, "status");
17045 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17046         .f = cmd_show_rx_tx_desc_status_parsed,
17047         .data = NULL,
17048         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17049                 "status",
17050         .tokens = {
17051                 (void *)&cmd_show_rx_tx_desc_status_show,
17052                 (void *)&cmd_show_rx_tx_desc_status_port,
17053                 (void *)&cmd_show_rx_tx_desc_status_pid,
17054                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17055                 (void *)&cmd_show_rx_tx_desc_status_qid,
17056                 (void *)&cmd_show_rx_tx_desc_status_desc,
17057                 (void *)&cmd_show_rx_tx_desc_status_did,
17058                 (void *)&cmd_show_rx_tx_desc_status_status,
17059                 NULL,
17060         },
17061 };
17062
17063 /* *** display rx queue desc used count *** */
17064 struct cmd_show_rx_queue_desc_used_count_result {
17065         cmdline_fixed_string_t cmd_show;
17066         cmdline_fixed_string_t cmd_port;
17067         cmdline_fixed_string_t cmd_rxq;
17068         cmdline_fixed_string_t cmd_desc;
17069         cmdline_fixed_string_t cmd_used;
17070         cmdline_fixed_string_t cmd_count;
17071         portid_t cmd_pid;
17072         portid_t cmd_qid;
17073 };
17074
17075 static void
17076 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17077                 __rte_unused struct cmdline *cl,
17078                 __rte_unused void *data)
17079 {
17080         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17081         int rc;
17082
17083         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17084                 printf("invalid port id %u\n", res->cmd_pid);
17085                 return;
17086         }
17087
17088         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17089         if (rc < 0) {
17090                 printf("Invalid queueid = %d\n", res->cmd_qid);
17091                 return;
17092         }
17093         printf("Used desc count = %d\n", rc);
17094 }
17095
17096 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17097         TOKEN_STRING_INITIALIZER
17098                 (struct cmd_show_rx_queue_desc_used_count_result,
17099                  cmd_show, "show");
17100 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17101         TOKEN_STRING_INITIALIZER
17102                 (struct cmd_show_rx_queue_desc_used_count_result,
17103                  cmd_port, "port");
17104 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17105         TOKEN_NUM_INITIALIZER
17106                 (struct cmd_show_rx_queue_desc_used_count_result,
17107                  cmd_pid, RTE_UINT16);
17108 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17109         TOKEN_STRING_INITIALIZER
17110                 (struct cmd_show_rx_queue_desc_used_count_result,
17111                  cmd_rxq, "rxq");
17112 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17113         TOKEN_NUM_INITIALIZER
17114                 (struct cmd_show_rx_queue_desc_used_count_result,
17115                  cmd_qid, RTE_UINT16);
17116 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17117         TOKEN_STRING_INITIALIZER
17118                 (struct cmd_show_rx_queue_desc_used_count_result,
17119                  cmd_count, "desc");
17120 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17121         TOKEN_STRING_INITIALIZER
17122                 (struct cmd_show_rx_queue_desc_used_count_result,
17123                  cmd_count, "used");
17124 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17125         TOKEN_STRING_INITIALIZER
17126                 (struct cmd_show_rx_queue_desc_used_count_result,
17127                  cmd_count, "count");
17128 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17129         .f = cmd_show_rx_queue_desc_used_count_parsed,
17130         .data = NULL,
17131         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17132         .tokens = {
17133                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17134                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17135                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17136                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17137                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17138                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17139                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17140                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17141                 NULL,
17142         },
17143 };
17144
17145 /* Common result structure for set port ptypes */
17146 struct cmd_set_port_ptypes_result {
17147         cmdline_fixed_string_t set;
17148         cmdline_fixed_string_t port;
17149         portid_t port_id;
17150         cmdline_fixed_string_t ptype_mask;
17151         uint32_t mask;
17152 };
17153
17154 /* Common CLI fields for set port ptypes */
17155 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17156         TOKEN_STRING_INITIALIZER
17157                 (struct cmd_set_port_ptypes_result,
17158                  set, "set");
17159 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17160         TOKEN_STRING_INITIALIZER
17161                 (struct cmd_set_port_ptypes_result,
17162                  port, "port");
17163 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17164         TOKEN_NUM_INITIALIZER
17165                 (struct cmd_set_port_ptypes_result,
17166                  port_id, RTE_UINT16);
17167 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17168         TOKEN_STRING_INITIALIZER
17169                 (struct cmd_set_port_ptypes_result,
17170                  ptype_mask, "ptype_mask");
17171 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17172         TOKEN_NUM_INITIALIZER
17173                 (struct cmd_set_port_ptypes_result,
17174                  mask, RTE_UINT32);
17175
17176 static void
17177 cmd_set_port_ptypes_parsed(
17178         void *parsed_result,
17179         __rte_unused struct cmdline *cl,
17180         __rte_unused void *data)
17181 {
17182         struct cmd_set_port_ptypes_result *res = parsed_result;
17183 #define PTYPE_NAMESIZE        256
17184         char ptype_name[PTYPE_NAMESIZE];
17185         uint16_t port_id = res->port_id;
17186         uint32_t ptype_mask = res->mask;
17187         int ret, i;
17188
17189         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17190                                                NULL, 0);
17191         if (ret <= 0) {
17192                 printf("Port %d doesn't support any ptypes.\n", port_id);
17193                 return;
17194         }
17195
17196         uint32_t ptypes[ret];
17197
17198         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17199         if (ret < 0) {
17200                 printf("Unable to set requested ptypes for Port %d\n", port_id);
17201                 return;
17202         }
17203
17204         printf("Successfully set following ptypes for Port %d\n", port_id);
17205         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17206                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17207                 printf("%s\n", ptype_name);
17208         }
17209
17210         clear_ptypes = false;
17211 }
17212
17213 cmdline_parse_inst_t cmd_set_port_ptypes = {
17214         .f = cmd_set_port_ptypes_parsed,
17215         .data = NULL,
17216         .help_str = "set port <port_id> ptype_mask <mask>",
17217         .tokens = {
17218                 (void *)&cmd_set_port_ptypes_set,
17219                 (void *)&cmd_set_port_ptypes_port,
17220                 (void *)&cmd_set_port_ptypes_port_id,
17221                 (void *)&cmd_set_port_ptypes_mask_str,
17222                 (void *)&cmd_set_port_ptypes_mask_u32,
17223                 NULL,
17224         },
17225 };
17226
17227 /* *** display mac addresses added to a port *** */
17228 struct cmd_showport_macs_result {
17229         cmdline_fixed_string_t cmd_show;
17230         cmdline_fixed_string_t cmd_port;
17231         cmdline_fixed_string_t cmd_keyword;
17232         portid_t cmd_pid;
17233 };
17234
17235 static void
17236 cmd_showport_macs_parsed(void *parsed_result,
17237                 __rte_unused struct cmdline *cl,
17238                 __rte_unused void *data)
17239 {
17240         struct cmd_showport_macs_result *res = parsed_result;
17241
17242         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17243                 return;
17244
17245         if (!strcmp(res->cmd_keyword, "macs"))
17246                 show_macs(res->cmd_pid);
17247         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17248                 show_mcast_macs(res->cmd_pid);
17249 }
17250
17251 cmdline_parse_token_string_t cmd_showport_macs_show =
17252         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17253                         cmd_show, "show");
17254 cmdline_parse_token_string_t cmd_showport_macs_port =
17255         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17256                         cmd_port, "port");
17257 cmdline_parse_token_num_t cmd_showport_macs_pid =
17258         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17259                         cmd_pid, RTE_UINT16);
17260 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17261         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17262                         cmd_keyword, "macs#mcast_macs");
17263
17264 cmdline_parse_inst_t cmd_showport_macs = {
17265         .f = cmd_showport_macs_parsed,
17266         .data = NULL,
17267         .help_str = "show port <port_id> macs|mcast_macs",
17268         .tokens = {
17269                 (void *)&cmd_showport_macs_show,
17270                 (void *)&cmd_showport_macs_port,
17271                 (void *)&cmd_showport_macs_pid,
17272                 (void *)&cmd_showport_macs_keyword,
17273                 NULL,
17274         },
17275 };
17276
17277 /* ******************************************************************************** */
17278
17279 /* list of instructions */
17280 cmdline_parse_ctx_t main_ctx[] = {
17281         (cmdline_parse_inst_t *)&cmd_help_brief,
17282         (cmdline_parse_inst_t *)&cmd_help_long,
17283         (cmdline_parse_inst_t *)&cmd_quit,
17284         (cmdline_parse_inst_t *)&cmd_load_from_file,
17285         (cmdline_parse_inst_t *)&cmd_showport,
17286         (cmdline_parse_inst_t *)&cmd_showqueue,
17287         (cmdline_parse_inst_t *)&cmd_showeeprom,
17288         (cmdline_parse_inst_t *)&cmd_showportall,
17289         (cmdline_parse_inst_t *)&cmd_showdevice,
17290         (cmdline_parse_inst_t *)&cmd_showcfg,
17291         (cmdline_parse_inst_t *)&cmd_showfwdall,
17292         (cmdline_parse_inst_t *)&cmd_start,
17293         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17294         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17295         (cmdline_parse_inst_t *)&cmd_set_link_up,
17296         (cmdline_parse_inst_t *)&cmd_set_link_down,
17297         (cmdline_parse_inst_t *)&cmd_reset,
17298         (cmdline_parse_inst_t *)&cmd_set_numbers,
17299         (cmdline_parse_inst_t *)&cmd_set_log,
17300         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17301         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17302         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17303         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17304         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17305         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17306         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17307         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17308         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17309         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17310         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17311         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17312         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17313         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17314         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17315         (cmdline_parse_inst_t *)&cmd_set_link_check,
17316         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17317         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17318         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17319         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17320 #ifdef RTE_NET_BOND
17321         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17322         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17323         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17324         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17325         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17326         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17327         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17328         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17329         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17330         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17331         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17332 #endif
17333         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17334         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17335         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17336         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17337         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17338         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17339         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17340         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17341         (cmdline_parse_inst_t *)&cmd_csum_set,
17342         (cmdline_parse_inst_t *)&cmd_csum_show,
17343         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17344         (cmdline_parse_inst_t *)&cmd_tso_set,
17345         (cmdline_parse_inst_t *)&cmd_tso_show,
17346         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17347         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17348         (cmdline_parse_inst_t *)&cmd_gro_enable,
17349         (cmdline_parse_inst_t *)&cmd_gro_flush,
17350         (cmdline_parse_inst_t *)&cmd_gro_show,
17351         (cmdline_parse_inst_t *)&cmd_gso_enable,
17352         (cmdline_parse_inst_t *)&cmd_gso_size,
17353         (cmdline_parse_inst_t *)&cmd_gso_show,
17354         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17355         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17356         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17357         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17358         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17359         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17360         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17361         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17362         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17363         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17364         (cmdline_parse_inst_t *)&cmd_config_dcb,
17365         (cmdline_parse_inst_t *)&cmd_read_reg,
17366         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17367         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17368         (cmdline_parse_inst_t *)&cmd_write_reg,
17369         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17370         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17371         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17372         (cmdline_parse_inst_t *)&cmd_stop,
17373         (cmdline_parse_inst_t *)&cmd_mac_addr,
17374         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17375         (cmdline_parse_inst_t *)&cmd_set_qmap,
17376         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17377         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17378         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17379         (cmdline_parse_inst_t *)&cmd_operate_port,
17380         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17381         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17382         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17383         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17384         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17385         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17386         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17387         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17388         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17389         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17390         (cmdline_parse_inst_t *)&cmd_config_mtu,
17391         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17392         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17393         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17394         (cmdline_parse_inst_t *)&cmd_config_rss,
17395         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17396         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17397         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17398         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17399         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17400         (cmdline_parse_inst_t *)&cmd_showport_reta,
17401         (cmdline_parse_inst_t *)&cmd_showport_macs,
17402         (cmdline_parse_inst_t *)&cmd_config_burst,
17403         (cmdline_parse_inst_t *)&cmd_config_thresh,
17404         (cmdline_parse_inst_t *)&cmd_config_threshold,
17405         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17406         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17407         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17408         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17409         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17410         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17411         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17412         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17413         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17414         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17415         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17416         (cmdline_parse_inst_t *)&cmd_dump,
17417         (cmdline_parse_inst_t *)&cmd_dump_one,
17418 #ifdef RTE_NET_I40E
17419         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17420 #endif
17421         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17422         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17423         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17424         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17425         (cmdline_parse_inst_t *)&cmd_flow,
17426         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17427         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17428         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17429         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17430         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17431         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17432         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17433         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17434         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17435         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17436         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17437         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17438         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17439         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17440         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17441         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17442         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17443         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17444         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17445         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17446         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17447         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17448         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17449         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17450         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17451         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17452         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17453         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17454         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17455         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17456         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17457         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17458         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17459         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17460         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17461         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17462         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17463         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17464         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17465         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17466         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17467         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17468         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17469         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17470         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17471         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17472         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17473         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17474         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17475         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17476         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17477         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17478         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17479         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17480         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17481         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17482         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
17483         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
17484         (cmdline_parse_inst_t *)&cmd_ddp_add,
17485         (cmdline_parse_inst_t *)&cmd_ddp_del,
17486         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17487         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17488         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17489         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17490         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17491         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17492         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17493         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17494         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17495         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17496         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17497         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17498
17499         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17500         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17501         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17502         (cmdline_parse_inst_t *)&cmd_queue_region,
17503         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17504         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17505         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17506         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17507         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17508         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17509         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17510         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17511         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17512         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17513         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17514         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17515         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17516         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17517         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17518         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17519         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17520         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17521         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17522         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17523         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17524         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17525         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17526         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17527         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17528         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17529         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17530         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17531         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17532         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17533         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17534         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17535         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17536         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17537         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17538         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17539 #ifdef RTE_LIB_BPF
17540         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17541         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17542 #endif
17543         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17544         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17545         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17546         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
17547         (cmdline_parse_inst_t *)&cmd_set_raw,
17548         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17549         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17550         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17551         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17552         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17553         (cmdline_parse_inst_t *)&cmd_show_capability,
17554         NULL,
17555 };
17556
17557 /* read cmdline commands from file */
17558 void
17559 cmdline_read_from_file(const char *filename)
17560 {
17561         struct cmdline *cl;
17562
17563         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17564         if (cl == NULL) {
17565                 printf("Failed to create file based cmdline context: %s\n",
17566                        filename);
17567                 return;
17568         }
17569
17570         cmdline_interact(cl);
17571         cmdline_quit(cl);
17572
17573         cmdline_free(cl);
17574
17575         printf("Read CLI commands from %s\n", filename);
17576 }
17577
17578 /* prompt function, called from main on MAIN lcore */
17579 void
17580 prompt(void)
17581 {
17582         int ret;
17583         /* initialize non-constant commands */
17584         cmd_set_fwd_mode_init();
17585         cmd_set_fwd_retry_mode_init();
17586
17587         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17588         if (testpmd_cl == NULL)
17589                 return;
17590
17591         ret = atexit(prompt_exit);
17592         if (ret != 0)
17593                 printf("Cannot set exit function for cmdline\n");
17594
17595         cmdline_interact(testpmd_cl);
17596         if (ret != 0)
17597                 cmdline_stdin_exit(testpmd_cl);
17598 }
17599
17600 void
17601 prompt_exit(void)
17602 {
17603         if (testpmd_cl != NULL) {
17604                 cmdline_quit(testpmd_cl);
17605                 cmdline_stdin_exit(testpmd_cl);
17606         }
17607 }
17608
17609 static void
17610 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17611 {
17612         if (id == (portid_t)RTE_PORT_ALL) {
17613                 portid_t pid;
17614
17615                 RTE_ETH_FOREACH_DEV(pid) {
17616                         /* check if need_reconfig has been set to 1 */
17617                         if (ports[pid].need_reconfig == 0)
17618                                 ports[pid].need_reconfig = dev;
17619                         /* check if need_reconfig_queues has been set to 1 */
17620                         if (ports[pid].need_reconfig_queues == 0)
17621                                 ports[pid].need_reconfig_queues = queue;
17622                 }
17623         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17624                 /* check if need_reconfig has been set to 1 */
17625                 if (ports[id].need_reconfig == 0)
17626                         ports[id].need_reconfig = dev;
17627                 /* check if need_reconfig_queues has been set to 1 */
17628                 if (ports[id].need_reconfig_queues == 0)
17629                         ports[id].need_reconfig_queues = queue;
17630         }
17631 }