ethdev: remove legacy global filter configuration support
[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|stat_qmap|dcb_tc|cap) (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|stat_qmap) (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) macs|mcast_macs"
250                         "       Display list of mac addresses added to port.\n\n"
251
252                         "show port (port_id) fec capabilities"
253                         "       Show fec capabilities of a port.\n\n"
254
255                         "show port (port_id) fec_mode"
256                         "       Show fec mode of a port.\n\n"
257                 );
258         }
259
260         if (show_all || !strcmp(res->section, "config")) {
261                 cmdline_printf(
262                         cl,
263                         "\n"
264                         "Configuration:\n"
265                         "--------------\n"
266                         "Configuration changes only become active when"
267                         " forwarding is started/restarted.\n\n"
268
269                         "set default\n"
270                         "    Reset forwarding to the default configuration.\n\n"
271
272                         "set verbose (level)\n"
273                         "    Set the debug verbosity level X.\n\n"
274
275                         "set log global|(type) (level)\n"
276                         "    Set the log level.\n\n"
277
278                         "set nbport (num)\n"
279                         "    Set number of ports.\n\n"
280
281                         "set nbcore (num)\n"
282                         "    Set number of cores.\n\n"
283
284                         "set coremask (mask)\n"
285                         "    Set the forwarding cores hexadecimal mask.\n\n"
286
287                         "set portmask (mask)\n"
288                         "    Set the forwarding ports hexadecimal mask.\n\n"
289
290                         "set burst (num)\n"
291                         "    Set number of packets per burst.\n\n"
292
293                         "set burst tx delay (microseconds) retry (num)\n"
294                         "    Set the transmit delay time and number of retries,"
295                         " effective when retry is enabled.\n\n"
296
297                         "set rxoffs (x[,y]*)\n"
298                         "    Set the offset of each packet segment on"
299                         " receiving if split feature is engaged."
300                         " Affects only the queues configured with split"
301                         " offloads.\n\n"
302
303                         "set rxpkts (x[,y]*)\n"
304                         "    Set the length of each segment to scatter"
305                         " packets on receiving if split feature is engaged."
306                         " Affects only the queues configured with split"
307                         " offloads.\n\n"
308
309                         "set txpkts (x[,y]*)\n"
310                         "    Set the length of each segment of TXONLY"
311                         " and optionally CSUM packets.\n\n"
312
313                         "set txsplit (off|on|rand)\n"
314                         "    Set the split policy for the TX packets."
315                         " Right now only applicable for CSUM and TXONLY"
316                         " modes\n\n"
317
318                         "set txtimes (x, y)\n"
319                         "    Set the scheduling on timestamps"
320                         " timings for the TXONLY mode\n\n"
321
322                         "set corelist (x[,y]*)\n"
323                         "    Set the list of forwarding cores.\n\n"
324
325                         "set portlist (x[,y]*)\n"
326                         "    Set the list of forwarding ports.\n\n"
327
328                         "set port setup on (iterator|event)\n"
329                         "    Select how attached port is retrieved for setup.\n\n"
330
331                         "set tx loopback (port_id) (on|off)\n"
332                         "    Enable or disable tx loopback.\n\n"
333
334                         "set all queues drop (port_id) (on|off)\n"
335                         "    Set drop enable bit for all queues.\n\n"
336
337                         "set vf split drop (port_id) (vf_id) (on|off)\n"
338                         "    Set split drop enable bit for a VF from the PF.\n\n"
339
340                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
341                         "    Set MAC antispoof for a VF from the PF.\n\n"
342
343                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
344                         "    Enable MACsec offload.\n\n"
345
346                         "set macsec offload (port_id) off\n"
347                         "    Disable MACsec offload.\n\n"
348
349                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
350                         "    Configure MACsec secure connection (SC).\n\n"
351
352                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
353                         "    Configure MACsec secure association (SA).\n\n"
354
355                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
356                         "    Set VF broadcast for a VF from the PF.\n\n"
357
358                         "vlan set stripq (on|off) (port_id,queue_id)\n"
359                         "    Set the VLAN strip for a queue on a port.\n\n"
360
361                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
362                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
363
364                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
365                         "    Set VLAN insert for a VF from the PF.\n\n"
366
367                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
368                         "    Set VLAN antispoof for a VF from the PF.\n\n"
369
370                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
371                         "    Set VLAN tag for a VF from the PF.\n\n"
372
373                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
374                         "    Set a VF's max bandwidth(Mbps).\n\n"
375
376                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
377                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
378
379                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
380                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
381
382                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
383                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
384
385                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
386                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
387
388                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
389                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
390
391                         "vlan set (inner|outer) tpid (value) (port_id)\n"
392                         "    Set the VLAN TPID for Packet Filtering on"
393                         " a port\n\n"
394
395                         "rx_vlan add (vlan_id|all) (port_id)\n"
396                         "    Add a vlan_id, or all identifiers, to the set"
397                         " of VLAN identifiers filtered by port_id.\n\n"
398
399                         "rx_vlan rm (vlan_id|all) (port_id)\n"
400                         "    Remove a vlan_id, or all identifiers, from the set"
401                         " of VLAN identifiers filtered by port_id.\n\n"
402
403                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
404                         "    Add a vlan_id, to the set of VLAN identifiers"
405                         "filtered for VF(s) from port_id.\n\n"
406
407                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
408                         "    Remove a vlan_id, to the set of VLAN identifiers"
409                         "filtered for VF(s) from port_id.\n\n"
410
411                         "rx_vxlan_port add (udp_port) (port_id)\n"
412                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
413
414                         "rx_vxlan_port rm (udp_port) (port_id)\n"
415                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
416
417                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
418                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
419                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
420
421                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
422                         "    Set port based TX VLAN insertion.\n\n"
423
424                         "tx_vlan reset (port_id)\n"
425                         "    Disable hardware insertion of a VLAN header in"
426                         " packets sent on a port.\n\n"
427
428                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
429                         "    Select hardware or software calculation of the"
430                         " checksum when transmitting a packet using the"
431                         " csum forward engine.\n"
432                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
433                         "    outer-ip concerns the outer IP layer in"
434                         "    outer-udp concerns the outer UDP layer in"
435                         " case the packet is recognized as a tunnel packet by"
436                         " the forward engine (vxlan, gre and ipip are supported)\n"
437                         "    Please check the NIC datasheet for HW limits.\n\n"
438
439                         "csum parse-tunnel (on|off) (tx_port_id)\n"
440                         "    If disabled, treat tunnel packets as non-tunneled"
441                         " packets (treat inner headers as payload). The port\n"
442                         "    argument is the port used for TX in csum forward"
443                         " engine.\n\n"
444
445                         "csum show (port_id)\n"
446                         "    Display tx checksum offload configuration\n\n"
447
448                         "tso set (segsize) (portid)\n"
449                         "    Enable TCP Segmentation Offload in csum forward"
450                         " engine.\n"
451                         "    Please check the NIC datasheet for HW limits.\n\n"
452
453                         "tso show (portid)"
454                         "    Display the status of TCP Segmentation Offload.\n\n"
455
456                         "set port (port_id) gro on|off\n"
457                         "    Enable or disable Generic Receive Offload in"
458                         " csum forwarding engine.\n\n"
459
460                         "show port (port_id) gro\n"
461                         "    Display GRO configuration.\n\n"
462
463                         "set gro flush (cycles)\n"
464                         "    Set the cycle to flush GROed packets from"
465                         " reassembly tables.\n\n"
466
467                         "set port (port_id) gso (on|off)"
468                         "    Enable or disable Generic Segmentation Offload in"
469                         " csum forwarding engine.\n\n"
470
471                         "set gso segsz (length)\n"
472                         "    Set max packet length for output GSO segments,"
473                         " including packet header and payload.\n\n"
474
475                         "show port (port_id) gso\n"
476                         "    Show GSO configuration.\n\n"
477
478                         "set fwd (%s)\n"
479                         "    Set packet forwarding mode.\n\n"
480
481                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
482                         "    Add a MAC address on port_id.\n\n"
483
484                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
485                         "    Remove a MAC address from port_id.\n\n"
486
487                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
488                         "    Set the default MAC address for port_id.\n\n"
489
490                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
491                         "    Add a MAC address for a VF on the port.\n\n"
492
493                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
494                         "    Set the MAC address for a VF from the PF.\n\n"
495
496                         "set eth-peer (port_id) (peer_addr)\n"
497                         "    set the peer address for certain port.\n\n"
498
499                         "set port (port_id) uta (mac_address|all) (on|off)\n"
500                         "    Add/Remove a or all unicast hash filter(s)"
501                         "from port X.\n\n"
502
503                         "set promisc (port_id|all) (on|off)\n"
504                         "    Set the promiscuous mode on port_id, or all.\n\n"
505
506                         "set allmulti (port_id|all) (on|off)\n"
507                         "    Set the allmulti mode on port_id, or all.\n\n"
508
509                         "set vf promisc (port_id) (vf_id) (on|off)\n"
510                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
511
512                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
513                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
514
515                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
516                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
517                         " (on|off) autoneg (on|off) (port_id)\n"
518                         "set flow_ctrl rx (on|off) (portid)\n"
519                         "set flow_ctrl tx (on|off) (portid)\n"
520                         "set flow_ctrl high_water (high_water) (portid)\n"
521                         "set flow_ctrl low_water (low_water) (portid)\n"
522                         "set flow_ctrl pause_time (pause_time) (portid)\n"
523                         "set flow_ctrl send_xon (send_xon) (portid)\n"
524                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
525                         "set flow_ctrl autoneg (on|off) (port_id)\n"
526                         "    Set the link flow control parameter on a port.\n\n"
527
528                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
529                         " (low_water) (pause_time) (priority) (port_id)\n"
530                         "    Set the priority flow control parameter on a"
531                         " port.\n\n"
532
533                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
534                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
535                         " queue on port.\n"
536                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
537                         " on port 0 to mapping 5.\n\n"
538
539                         "set xstats-hide-zero on|off\n"
540                         "    Set the option to hide the zero values"
541                         " for xstats display.\n"
542
543                         "set record-core-cycles on|off\n"
544                         "    Set the option to enable measurement of CPU cycles.\n"
545
546                         "set record-burst-stats on|off\n"
547                         "    Set the option to enable display of RX and TX bursts.\n"
548
549                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
550                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
553                         "|MPE) (on|off)\n"
554                         "    AUPE:accepts untagged VLAN;"
555                         "ROPE:accept unicast hash\n\n"
556                         "    BAM:accepts broadcast packets;"
557                         "MPE:accepts all multicast packets\n\n"
558                         "    Enable/Disable a VF receive mode of a port\n\n"
559
560                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
561                         "    Set rate limit for a queue of a port\n\n"
562
563                         "set port (port_id) vf (vf_id) rate (rate_num) "
564                         "queue_mask (queue_mask_value)\n"
565                         "    Set rate limit for queues in VF of a port\n\n"
566
567                         "set port (port_id) mirror-rule (rule_id)"
568                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
569                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
570                         "   Set pool or vlan type mirror rule on a port.\n"
571                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
572                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
573                         " to pool 0.\n\n"
574
575                         "set port (port_id) mirror-rule (rule_id)"
576                         " (uplink-mirror|downlink-mirror) dst-pool"
577                         " (pool_id) (on|off)\n"
578                         "   Set uplink or downlink type mirror rule on a port.\n"
579                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
580                         " 0 on' enable mirror income traffic to pool 0.\n\n"
581
582                         "reset port (port_id) mirror-rule (rule_id)\n"
583                         "   Reset a mirror rule.\n\n"
584
585                         "set flush_rx (on|off)\n"
586                         "   Flush (default) or don't flush RX streams before"
587                         " forwarding. Mainly used with PCAP drivers.\n\n"
588
589                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
590                         "   Set the bypass mode for the lowest port on bypass enabled"
591                         " NIC.\n\n"
592
593                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
594                         "mode (normal|bypass|isolate) (port_id)\n"
595                         "   Set the event required to initiate specified bypass mode for"
596                         " the lowest port on a bypass enabled NIC where:\n"
597                         "       timeout   = enable bypass after watchdog timeout.\n"
598                         "       os_on     = enable bypass when OS/board is powered on.\n"
599                         "       os_off    = enable bypass when OS/board is powered off.\n"
600                         "       power_on  = enable bypass when power supply is turned on.\n"
601                         "       power_off = enable bypass when power supply is turned off."
602                         "\n\n"
603
604                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
605                         "   Set the bypass watchdog timeout to 'n' seconds"
606                         " where 0 = instant.\n\n"
607
608                         "show bypass config (port_id)\n"
609                         "   Show the bypass configuration for a bypass enabled NIC"
610                         " using the lowest port on the NIC.\n\n"
611
612 #ifdef RTE_NET_BOND
613                         "create bonded device (mode) (socket)\n"
614                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
615
616                         "add bonding slave (slave_id) (port_id)\n"
617                         "       Add a slave device to a bonded device.\n\n"
618
619                         "remove bonding slave (slave_id) (port_id)\n"
620                         "       Remove a slave device from a bonded device.\n\n"
621
622                         "set bonding mode (value) (port_id)\n"
623                         "       Set the bonding mode on a bonded device.\n\n"
624
625                         "set bonding primary (slave_id) (port_id)\n"
626                         "       Set the primary slave for a bonded device.\n\n"
627
628                         "show bonding config (port_id)\n"
629                         "       Show the bonding config for port_id.\n\n"
630
631                         "set bonding mac_addr (port_id) (address)\n"
632                         "       Set the MAC address of a bonded device.\n\n"
633
634                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
635                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
636
637                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
638                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
639
640                         "set bonding mon_period (port_id) (value)\n"
641                         "       Set the bonding link status monitoring polling period in ms.\n\n"
642
643                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
644                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
645
646 #endif
647                         "set link-up port (port_id)\n"
648                         "       Set link up for a port.\n\n"
649
650                         "set link-down port (port_id)\n"
651                         "       Set link down for a port.\n\n"
652
653                         "E-tag set insertion on port-tag-id (value)"
654                         " port (port_id) vf (vf_id)\n"
655                         "    Enable E-tag insertion for a VF on a port\n\n"
656
657                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
658                         "    Disable E-tag insertion for a VF on a port\n\n"
659
660                         "E-tag set stripping (on|off) port (port_id)\n"
661                         "    Enable/disable E-tag stripping on a port\n\n"
662
663                         "E-tag set forwarding (on|off) port (port_id)\n"
664                         "    Enable/disable E-tag based forwarding"
665                         " on a port\n\n"
666
667                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
668                         "    Load a profile package on a port\n\n"
669
670                         "ddp del (port_id) (backup_profile_path)\n"
671                         "    Delete a profile package from a port\n\n"
672
673                         "ptype mapping get (port_id) (valid_only)\n"
674                         "    Get ptype mapping on a port\n\n"
675
676                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
677                         "    Replace target with the pkt_type in ptype mapping\n\n"
678
679                         "ptype mapping reset (port_id)\n"
680                         "    Reset ptype mapping on a port\n\n"
681
682                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
683                         "    Update a ptype mapping item on a port\n\n"
684
685                         "set port (port_id) ptype_mask (ptype_mask)\n"
686                         "    set packet types classification for a specific port\n\n"
687
688                         "set port (port_id) queue-region region_id (value) "
689                         "queue_start_index (value) queue_num (value)\n"
690                         "    Set a queue region on a port\n\n"
691
692                         "set port (port_id) queue-region region_id (value) "
693                         "flowtype (value)\n"
694                         "    Set a flowtype region index on a port\n\n"
695
696                         "set port (port_id) queue-region UP (value) region_id (value)\n"
697                         "    Set the mapping of User Priority to "
698                         "queue region on a port\n\n"
699
700                         "set port (port_id) queue-region flush (on|off)\n"
701                         "    flush all queue region related configuration\n\n"
702
703                         "show port meter cap (port_id)\n"
704                         "    Show port meter capability information\n\n"
705
706                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
707                         "    meter profile add - srtcm rfc 2697\n\n"
708
709                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
710                         "    meter profile add - trtcm rfc 2698\n\n"
711
712                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
713                         "    meter profile add - trtcm rfc 4115\n\n"
714
715                         "del port meter profile (port_id) (profile_id)\n"
716                         "    meter profile delete\n\n"
717
718                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
719                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
720                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
721                         "(dscp_tbl_entry63)]\n"
722                         "    meter create\n\n"
723
724                         "enable port meter (port_id) (mtr_id)\n"
725                         "    meter enable\n\n"
726
727                         "disable port meter (port_id) (mtr_id)\n"
728                         "    meter disable\n\n"
729
730                         "del port meter (port_id) (mtr_id)\n"
731                         "    meter delete\n\n"
732
733                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
734                         "    meter update meter profile\n\n"
735
736                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
737                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
738                         "    update meter dscp table entries\n\n"
739
740                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
741                         "(action0) [(action1) (action2)]\n"
742                         "    meter update policer action\n\n"
743
744                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
745                         "    meter update stats\n\n"
746
747                         "show port (port_id) queue-region\n"
748                         "    show all queue region related configuration info\n\n"
749
750                         "set port (port_id) fec_mode auto|off|rs|baser\n"
751                         "    set fec mode for a specific port\n\n"
752
753                         , list_pkt_forwarding_modes()
754                 );
755         }
756
757         if (show_all || !strcmp(res->section, "ports")) {
758
759                 cmdline_printf(
760                         cl,
761                         "\n"
762                         "Port Operations:\n"
763                         "----------------\n\n"
764
765                         "port start (port_id|all)\n"
766                         "    Start all ports or port_id.\n\n"
767
768                         "port stop (port_id|all)\n"
769                         "    Stop all ports or port_id.\n\n"
770
771                         "port close (port_id|all)\n"
772                         "    Close all ports or port_id.\n\n"
773
774                         "port reset (port_id|all)\n"
775                         "    Reset all ports or port_id.\n\n"
776
777                         "port attach (ident)\n"
778                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
779
780                         "port detach (port_id)\n"
781                         "    Detach physical or virtual dev by port_id\n\n"
782
783                         "port config (port_id|all)"
784                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
785                         " duplex (half|full|auto)\n"
786                         "    Set speed and duplex for all ports or port_id\n\n"
787
788                         "port config (port_id|all) loopback (mode)\n"
789                         "    Set loopback mode for all ports or port_id\n\n"
790
791                         "port config all (rxq|txq|rxd|txd) (value)\n"
792                         "    Set number for rxq/txq/rxd/txd.\n\n"
793
794                         "port config all max-pkt-len (value)\n"
795                         "    Set the max packet length.\n\n"
796
797                         "port config all max-lro-pkt-size (value)\n"
798                         "    Set the max LRO aggregated packet size.\n\n"
799
800                         "port config all drop-en (on|off)\n"
801                         "    Enable or disable packet drop on all RX queues of all ports when no "
802                         "receive buffers available.\n\n"
803
804                         "port config all rss (all|default|ip|tcp|udp|sctp|"
805                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
806                         "level-outer|level-inner|<flowtype_id>)\n"
807                         "    Set the RSS mode.\n\n"
808
809                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
810                         "    Set the RSS redirection table.\n\n"
811
812                         "port config (port_id) dcb vt (on|off) (traffic_class)"
813                         " pfc (on|off)\n"
814                         "    Set the DCB mode.\n\n"
815
816                         "port config all burst (value)\n"
817                         "    Set the number of packets per burst.\n\n"
818
819                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
820                         " (value)\n"
821                         "    Set the ring prefetch/host/writeback threshold"
822                         " for tx/rx queue.\n\n"
823
824                         "port config all (txfreet|txrst|rxfreet) (value)\n"
825                         "    Set free threshold for rx/tx, or set"
826                         " tx rs bit threshold.\n\n"
827                         "port config mtu X value\n"
828                         "    Set the MTU of port X to a given value\n\n"
829
830                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
831                         "    Set a rx/tx queue's ring size configuration, the new"
832                         " value will take effect after command that (re-)start the port"
833                         " or command that setup the specific queue\n\n"
834
835                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
836                         "    Start/stop a rx/tx queue of port X. Only take effect"
837                         " when port X is started\n\n"
838
839                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
840                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
841                         " take effect when port X is stopped.\n\n"
842
843                         "port (port_id) (rxq|txq) (queue_id) setup\n"
844                         "    Setup a rx/tx queue of port X.\n\n"
845
846                         "port config (port_id|all) l2-tunnel E-tag ether-type"
847                         " (value)\n"
848                         "    Set the value of E-tag ether-type.\n\n"
849
850                         "port config (port_id|all) l2-tunnel E-tag"
851                         " (enable|disable)\n"
852                         "    Enable/disable the E-tag support.\n\n"
853
854                         "port config (port_id) pctype mapping reset\n"
855                         "    Reset flow type to pctype mapping on a port\n\n"
856
857                         "port config (port_id) pctype mapping update"
858                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
859                         "    Update a flow type to pctype mapping item on a port\n\n"
860
861                         "port config (port_id) pctype (pctype_id) hash_inset|"
862                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
863                         " (field_idx)\n"
864                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
865
866                         "port config (port_id) pctype (pctype_id) hash_inset|"
867                         "fdir_inset|fdir_flx_inset clear all"
868                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
869
870                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
871                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
872
873                         "port config <port_id> rx_offload vlan_strip|"
874                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
875                         "outer_ipv4_cksum|macsec_strip|header_split|"
876                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
877                         "buffer_split|timestamp|security|keep_crc on|off\n"
878                         "     Enable or disable a per port Rx offloading"
879                         " on all Rx queues of a port\n\n"
880
881                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
882                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
883                         "outer_ipv4_cksum|macsec_strip|header_split|"
884                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
885                         "buffer_split|timestamp|security|keep_crc on|off\n"
886                         "    Enable or disable a per queue Rx offloading"
887                         " only on a specific Rx queue\n\n"
888
889                         "port config (port_id) tx_offload vlan_insert|"
890                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
891                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
892                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
893                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
894                         "security on|off\n"
895                         "    Enable or disable a per port Tx offloading"
896                         " on all Tx queues of a port\n\n"
897
898                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
899                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
900                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
901                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
902                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
903                         " on|off\n"
904                         "    Enable or disable a per queue Tx offloading"
905                         " only on a specific Tx queue\n\n"
906
907                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
908                         "    Load an eBPF program as a callback"
909                         " for particular RX/TX queue\n\n"
910
911                         "bpf-unload rx|tx (port) (queue)\n"
912                         "    Unload previously loaded eBPF program"
913                         " for particular RX/TX queue\n\n"
914
915                         "port config (port_id) tx_metadata (value)\n"
916                         "    Set Tx metadata value per port. Testpmd will add this value"
917                         " to any Tx packet sent from this port\n\n"
918
919                         "port config (port_id) dynf (name) set|clear\n"
920                         "    Register a dynf and Set/clear this flag on Tx. "
921                         "Testpmd will set this value to any Tx packet "
922                         "sent from this port\n\n"
923                 );
924         }
925
926         if (show_all || !strcmp(res->section, "registers")) {
927
928                 cmdline_printf(
929                         cl,
930                         "\n"
931                         "Registers:\n"
932                         "----------\n\n"
933
934                         "read reg (port_id) (address)\n"
935                         "    Display value of a port register.\n\n"
936
937                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
938                         "    Display a port register bit field.\n\n"
939
940                         "read regbit (port_id) (address) (bit_x)\n"
941                         "    Display a single port register bit.\n\n"
942
943                         "write reg (port_id) (address) (value)\n"
944                         "    Set value of a port register.\n\n"
945
946                         "write regfield (port_id) (address) (bit_x) (bit_y)"
947                         " (value)\n"
948                         "    Set bit field of a port register.\n\n"
949
950                         "write regbit (port_id) (address) (bit_x) (value)\n"
951                         "    Set single bit value of a port register.\n\n"
952                 );
953         }
954         if (show_all || !strcmp(res->section, "filters")) {
955
956                 cmdline_printf(
957                         cl,
958                         "\n"
959                         "filters:\n"
960                         "--------\n\n"
961
962                         "flow_director_filter (port_id) mode IP (add|del|update)"
963                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
964                         " src (src_ip_address) dst (dst_ip_address)"
965                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
966                         " vlan (vlan_value) flexbytes (flexbytes_value)"
967                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
968                         " fd_id (fd_id_value)\n"
969                         "    Add/Del an IP type flow director filter.\n\n"
970
971                         "flow_director_filter (port_id) mode IP (add|del|update)"
972                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
973                         " src (src_ip_address) (src_port)"
974                         " dst (dst_ip_address) (dst_port)"
975                         " tos (tos_value) ttl (ttl_value)"
976                         " vlan (vlan_value) flexbytes (flexbytes_value)"
977                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
978                         " fd_id (fd_id_value)\n"
979                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
980
981                         "flow_director_filter (port_id) mode IP (add|del|update)"
982                         " flow (ipv4-sctp|ipv6-sctp)"
983                         " src (src_ip_address) (src_port)"
984                         " dst (dst_ip_address) (dst_port)"
985                         " tag (verification_tag) "
986                         " tos (tos_value) ttl (ttl_value)"
987                         " vlan (vlan_value)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a SCTP type flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode IP (add|del|update)"
993                         " flow l2_payload ether (ethertype)"
994                         " flexbytes (flexbytes_value) (drop|fwd)"
995                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
996                         "    Add/Del a l2 payload type flow director filter.\n\n"
997
998                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
999                         " mac (mac_address) vlan (vlan_value)"
1000                         " flexbytes (flexbytes_value) (drop|fwd)"
1001                         " queue (queue_id) fd_id (fd_id_value)\n"
1002                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1003
1004                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1005                         " mac (mac_address) vlan (vlan_value)"
1006                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1007                         " flexbytes (flexbytes_value) (drop|fwd)"
1008                         " queue (queue_id) fd_id (fd_id_value)\n"
1009                         "    Add/Del a Tunnel flow director filter.\n\n"
1010
1011                         "flow_director_filter (port_id) mode raw (add|del|update)"
1012                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1013                         " fd_id (fd_id_value) packet (packet file name)\n"
1014                         "    Add/Del a raw type flow director filter.\n\n"
1015
1016                         "flush_flow_director (port_id)\n"
1017                         "    Flush all flow director entries of a device.\n\n"
1018
1019                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1020                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1021                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1022                         "    Set flow director IP mask.\n\n"
1023
1024                         "flow_director_mask (port_id) mode MAC-VLAN"
1025                         " vlan (vlan_value)\n"
1026                         "    Set flow director MAC-VLAN mask.\n\n"
1027
1028                         "flow_director_mask (port_id) mode Tunnel"
1029                         " vlan (vlan_value) mac (mac_value)"
1030                         " tunnel-type (tunnel_type_value)"
1031                         " tunnel-id (tunnel_id_value)\n"
1032                         "    Set flow director Tunnel mask.\n\n"
1033
1034                         "flow_director_flex_mask (port_id)"
1035                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1036                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1037                         " (mask)\n"
1038                         "    Configure mask of flex payload.\n\n"
1039
1040                         "flow_director_flex_payload (port_id)"
1041                         " (raw|l2|l3|l4) (config)\n"
1042                         "    Configure flex payload selection.\n\n"
1043
1044                         "set_fdir_input_set (port_id) "
1045                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1046                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1047                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1048                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1049                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1050                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1051                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1052                         " (select|add)\n"
1053                         "    Set the input set for FDir.\n\n"
1054
1055                         "flow validate {port_id}"
1056                         " [group {group_id}] [priority {level}]"
1057                         " [ingress] [egress]"
1058                         " pattern {item} [/ {item} [...]] / end"
1059                         " actions {action} [/ {action} [...]] / end\n"
1060                         "    Check whether a flow rule can be created.\n\n"
1061
1062                         "flow create {port_id}"
1063                         " [group {group_id}] [priority {level}]"
1064                         " [ingress] [egress]"
1065                         " pattern {item} [/ {item} [...]] / end"
1066                         " actions {action} [/ {action} [...]] / end\n"
1067                         "    Create a flow rule.\n\n"
1068
1069                         "flow destroy {port_id} rule {rule_id} [...]\n"
1070                         "    Destroy specific flow rules.\n\n"
1071
1072                         "flow flush {port_id}\n"
1073                         "    Destroy all flow rules.\n\n"
1074
1075                         "flow query {port_id} {rule_id} {action}\n"
1076                         "    Query an existing flow rule.\n\n"
1077
1078                         "flow list {port_id} [group {group_id}] [...]\n"
1079                         "    List existing flow rules sorted by priority,"
1080                         " filtered by group identifiers.\n\n"
1081
1082                         "flow isolate {port_id} {boolean}\n"
1083                         "    Restrict ingress traffic to the defined"
1084                         " flow rules\n\n"
1085
1086                         "flow aged {port_id} [destroy]\n"
1087                         "    List and destroy aged flows"
1088                         " flow rules\n\n"
1089
1090                         "flow shared_action {port_id} create"
1091                         " [action_id {shared_action_id}]"
1092                         " [ingress] [egress]"
1093                         " action {action} / end\n"
1094                         "    Create shared action.\n\n"
1095
1096                         "flow shared_action {port_id} update"
1097                         " {shared_action_id} action {action} / end\n"
1098                         "    Update shared action.\n\n"
1099
1100                         "flow shared_action {port_id} destroy"
1101                         " action_id {shared_action_id} [...]\n"
1102                         "    Destroy specific shared actions.\n\n"
1103
1104                         "flow shared_action {port_id} query"
1105                         " {shared_action_id}\n"
1106                         "    Query an existing shared action.\n\n"
1107
1108                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1109                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1110                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1111                         "       Configure the VXLAN encapsulation for flows.\n\n"
1112
1113                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1114                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1115                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1116                         " eth-dst (eth-dst)\n"
1117                         "       Configure the VXLAN encapsulation for flows.\n\n"
1118
1119                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1120                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1121                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1122                         " eth-dst (eth-dst)\n"
1123                         "       Configure the VXLAN encapsulation for flows.\n\n"
1124
1125                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1126                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1127                         " (eth-dst)\n"
1128                         "       Configure the NVGRE encapsulation for flows.\n\n"
1129
1130                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1131                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1132                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1133                         "       Configure the NVGRE encapsulation for flows.\n\n"
1134
1135                         "set raw_encap {flow items}\n"
1136                         "       Configure the encapsulation with raw data.\n\n"
1137
1138                         "set raw_decap {flow items}\n"
1139                         "       Configure the decapsulation with raw data.\n\n"
1140
1141                 );
1142         }
1143
1144         if (show_all || !strcmp(res->section, "traffic_management")) {
1145                 cmdline_printf(
1146                         cl,
1147                         "\n"
1148                         "Traffic Management:\n"
1149                         "--------------\n"
1150                         "show port tm cap (port_id)\n"
1151                         "       Display the port TM capability.\n\n"
1152
1153                         "show port tm level cap (port_id) (level_id)\n"
1154                         "       Display the port TM hierarchical level capability.\n\n"
1155
1156                         "show port tm node cap (port_id) (node_id)\n"
1157                         "       Display the port TM node capability.\n\n"
1158
1159                         "show port tm node type (port_id) (node_id)\n"
1160                         "       Display the port TM node type.\n\n"
1161
1162                         "show port tm node stats (port_id) (node_id) (clear)\n"
1163                         "       Display the port TM node stats.\n\n"
1164
1165                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1166                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1167                         " (packet_length_adjust) (packet_mode)\n"
1168                         "       Add port tm node private shaper profile.\n\n"
1169
1170                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1171                         "       Delete port tm node private shaper profile.\n\n"
1172
1173                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1174                         " (shaper_profile_id)\n"
1175                         "       Add/update port tm node shared shaper.\n\n"
1176
1177                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1178                         "       Delete port tm node shared shaper.\n\n"
1179
1180                         "set port tm node shaper profile (port_id) (node_id)"
1181                         " (shaper_profile_id)\n"
1182                         "       Set port tm node shaper profile.\n\n"
1183
1184                         "add port tm node wred profile (port_id) (wred_profile_id)"
1185                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1186                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1187                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1188                         "       Add port tm node wred profile.\n\n"
1189
1190                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1191                         "       Delete port tm node wred profile.\n\n"
1192
1193                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1194                         " (priority) (weight) (level_id) (shaper_profile_id)"
1195                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1196                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1197                         "       Add port tm nonleaf node.\n\n"
1198
1199                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1200                         " (priority) (weight) (level_id) (shaper_profile_id)"
1201                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1202                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1203                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1204
1205                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1206                         " (priority) (weight) (level_id) (shaper_profile_id)"
1207                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1208                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1209                         "       Add port tm leaf node.\n\n"
1210
1211                         "del port tm node (port_id) (node_id)\n"
1212                         "       Delete port tm node.\n\n"
1213
1214                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1215                         " (priority) (weight)\n"
1216                         "       Set port tm node parent.\n\n"
1217
1218                         "suspend port tm node (port_id) (node_id)"
1219                         "       Suspend tm node.\n\n"
1220
1221                         "resume port tm node (port_id) (node_id)"
1222                         "       Resume tm node.\n\n"
1223
1224                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1225                         "       Commit tm hierarchy.\n\n"
1226
1227                         "set port tm mark ip_ecn (port) (green) (yellow)"
1228                         " (red)\n"
1229                         "    Enables/Disables the traffic management marking"
1230                         " for IP ECN (Explicit Congestion Notification)"
1231                         " packets on a given port\n\n"
1232
1233                         "set port tm mark ip_dscp (port) (green) (yellow)"
1234                         " (red)\n"
1235                         "    Enables/Disables the traffic management marking"
1236                         " on the port for IP dscp packets\n\n"
1237
1238                         "set port tm mark vlan_dei (port) (green) (yellow)"
1239                         " (red)\n"
1240                         "    Enables/Disables the traffic management marking"
1241                         " on the port for VLAN packets with DEI enabled\n\n"
1242                 );
1243         }
1244
1245         if (show_all || !strcmp(res->section, "devices")) {
1246                 cmdline_printf(
1247                         cl,
1248                         "\n"
1249                         "Device Operations:\n"
1250                         "--------------\n"
1251                         "device detach (identifier)\n"
1252                         "       Detach device by identifier.\n\n"
1253                 );
1254         }
1255
1256 }
1257
1258 cmdline_parse_token_string_t cmd_help_long_help =
1259         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1260
1261 cmdline_parse_token_string_t cmd_help_long_section =
1262         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1263                         "all#control#display#config#"
1264                         "ports#registers#filters#traffic_management#devices");
1265
1266 cmdline_parse_inst_t cmd_help_long = {
1267         .f = cmd_help_long_parsed,
1268         .data = NULL,
1269         .help_str = "help all|control|display|config|ports|register|"
1270                 "filters|traffic_management|devices: "
1271                 "Show help",
1272         .tokens = {
1273                 (void *)&cmd_help_long_help,
1274                 (void *)&cmd_help_long_section,
1275                 NULL,
1276         },
1277 };
1278
1279
1280 /* *** start/stop/close all ports *** */
1281 struct cmd_operate_port_result {
1282         cmdline_fixed_string_t keyword;
1283         cmdline_fixed_string_t name;
1284         cmdline_fixed_string_t value;
1285 };
1286
1287 static void cmd_operate_port_parsed(void *parsed_result,
1288                                 __rte_unused struct cmdline *cl,
1289                                 __rte_unused void *data)
1290 {
1291         struct cmd_operate_port_result *res = parsed_result;
1292
1293         if (!strcmp(res->name, "start"))
1294                 start_port(RTE_PORT_ALL);
1295         else if (!strcmp(res->name, "stop"))
1296                 stop_port(RTE_PORT_ALL);
1297         else if (!strcmp(res->name, "close"))
1298                 close_port(RTE_PORT_ALL);
1299         else if (!strcmp(res->name, "reset"))
1300                 reset_port(RTE_PORT_ALL);
1301         else
1302                 printf("Unknown parameter\n");
1303 }
1304
1305 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1306         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1307                                                                 "port");
1308 cmdline_parse_token_string_t cmd_operate_port_all_port =
1309         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1310                                                 "start#stop#close#reset");
1311 cmdline_parse_token_string_t cmd_operate_port_all_all =
1312         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1313
1314 cmdline_parse_inst_t cmd_operate_port = {
1315         .f = cmd_operate_port_parsed,
1316         .data = NULL,
1317         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1318         .tokens = {
1319                 (void *)&cmd_operate_port_all_cmd,
1320                 (void *)&cmd_operate_port_all_port,
1321                 (void *)&cmd_operate_port_all_all,
1322                 NULL,
1323         },
1324 };
1325
1326 /* *** start/stop/close specific port *** */
1327 struct cmd_operate_specific_port_result {
1328         cmdline_fixed_string_t keyword;
1329         cmdline_fixed_string_t name;
1330         uint8_t value;
1331 };
1332
1333 static void cmd_operate_specific_port_parsed(void *parsed_result,
1334                         __rte_unused struct cmdline *cl,
1335                                 __rte_unused void *data)
1336 {
1337         struct cmd_operate_specific_port_result *res = parsed_result;
1338
1339         if (!strcmp(res->name, "start"))
1340                 start_port(res->value);
1341         else if (!strcmp(res->name, "stop"))
1342                 stop_port(res->value);
1343         else if (!strcmp(res->name, "close"))
1344                 close_port(res->value);
1345         else if (!strcmp(res->name, "reset"))
1346                 reset_port(res->value);
1347         else
1348                 printf("Unknown parameter\n");
1349 }
1350
1351 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1352         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1353                                                         keyword, "port");
1354 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1355         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1356                                                 name, "start#stop#close#reset");
1357 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1358         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1359                                                         value, UINT8);
1360
1361 cmdline_parse_inst_t cmd_operate_specific_port = {
1362         .f = cmd_operate_specific_port_parsed,
1363         .data = NULL,
1364         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1365         .tokens = {
1366                 (void *)&cmd_operate_specific_port_cmd,
1367                 (void *)&cmd_operate_specific_port_port,
1368                 (void *)&cmd_operate_specific_port_id,
1369                 NULL,
1370         },
1371 };
1372
1373 /* *** enable port setup (after attach) via iterator or event *** */
1374 struct cmd_set_port_setup_on_result {
1375         cmdline_fixed_string_t set;
1376         cmdline_fixed_string_t port;
1377         cmdline_fixed_string_t setup;
1378         cmdline_fixed_string_t on;
1379         cmdline_fixed_string_t mode;
1380 };
1381
1382 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1383                                 __rte_unused struct cmdline *cl,
1384                                 __rte_unused void *data)
1385 {
1386         struct cmd_set_port_setup_on_result *res = parsed_result;
1387
1388         if (strcmp(res->mode, "event") == 0)
1389                 setup_on_probe_event = true;
1390         else if (strcmp(res->mode, "iterator") == 0)
1391                 setup_on_probe_event = false;
1392         else
1393                 printf("Unknown mode\n");
1394 }
1395
1396 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1397         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1398                         set, "set");
1399 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1400         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1401                         port, "port");
1402 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1403         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1404                         setup, "setup");
1405 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1406         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1407                         on, "on");
1408 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1409         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1410                         mode, "iterator#event");
1411
1412 cmdline_parse_inst_t cmd_set_port_setup_on = {
1413         .f = cmd_set_port_setup_on_parsed,
1414         .data = NULL,
1415         .help_str = "set port setup on iterator|event",
1416         .tokens = {
1417                 (void *)&cmd_set_port_setup_on_set,
1418                 (void *)&cmd_set_port_setup_on_port,
1419                 (void *)&cmd_set_port_setup_on_setup,
1420                 (void *)&cmd_set_port_setup_on_on,
1421                 (void *)&cmd_set_port_setup_on_mode,
1422                 NULL,
1423         },
1424 };
1425
1426 /* *** attach a specified port *** */
1427 struct cmd_operate_attach_port_result {
1428         cmdline_fixed_string_t port;
1429         cmdline_fixed_string_t keyword;
1430         cmdline_multi_string_t identifier;
1431 };
1432
1433 static void cmd_operate_attach_port_parsed(void *parsed_result,
1434                                 __rte_unused struct cmdline *cl,
1435                                 __rte_unused void *data)
1436 {
1437         struct cmd_operate_attach_port_result *res = parsed_result;
1438
1439         if (!strcmp(res->keyword, "attach"))
1440                 attach_port(res->identifier);
1441         else
1442                 printf("Unknown parameter\n");
1443 }
1444
1445 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1446         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1447                         port, "port");
1448 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1449         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1450                         keyword, "attach");
1451 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1452         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1453                         identifier, TOKEN_STRING_MULTI);
1454
1455 cmdline_parse_inst_t cmd_operate_attach_port = {
1456         .f = cmd_operate_attach_port_parsed,
1457         .data = NULL,
1458         .help_str = "port attach <identifier>: "
1459                 "(identifier: pci address or virtual dev name)",
1460         .tokens = {
1461                 (void *)&cmd_operate_attach_port_port,
1462                 (void *)&cmd_operate_attach_port_keyword,
1463                 (void *)&cmd_operate_attach_port_identifier,
1464                 NULL,
1465         },
1466 };
1467
1468 /* *** detach a specified port *** */
1469 struct cmd_operate_detach_port_result {
1470         cmdline_fixed_string_t port;
1471         cmdline_fixed_string_t keyword;
1472         portid_t port_id;
1473 };
1474
1475 static void cmd_operate_detach_port_parsed(void *parsed_result,
1476                                 __rte_unused struct cmdline *cl,
1477                                 __rte_unused void *data)
1478 {
1479         struct cmd_operate_detach_port_result *res = parsed_result;
1480
1481         if (!strcmp(res->keyword, "detach")) {
1482                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1483                 detach_port_device(res->port_id);
1484         } else {
1485                 printf("Unknown parameter\n");
1486         }
1487 }
1488
1489 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1490         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1491                         port, "port");
1492 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1493         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1494                         keyword, "detach");
1495 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1496         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1497                         port_id, UINT16);
1498
1499 cmdline_parse_inst_t cmd_operate_detach_port = {
1500         .f = cmd_operate_detach_port_parsed,
1501         .data = NULL,
1502         .help_str = "port detach <port_id>",
1503         .tokens = {
1504                 (void *)&cmd_operate_detach_port_port,
1505                 (void *)&cmd_operate_detach_port_keyword,
1506                 (void *)&cmd_operate_detach_port_port_id,
1507                 NULL,
1508         },
1509 };
1510
1511 /* *** detach device by identifier *** */
1512 struct cmd_operate_detach_device_result {
1513         cmdline_fixed_string_t device;
1514         cmdline_fixed_string_t keyword;
1515         cmdline_fixed_string_t identifier;
1516 };
1517
1518 static void cmd_operate_detach_device_parsed(void *parsed_result,
1519                                 __rte_unused struct cmdline *cl,
1520                                 __rte_unused void *data)
1521 {
1522         struct cmd_operate_detach_device_result *res = parsed_result;
1523
1524         if (!strcmp(res->keyword, "detach"))
1525                 detach_devargs(res->identifier);
1526         else
1527                 printf("Unknown parameter\n");
1528 }
1529
1530 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1531         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1532                         device, "device");
1533 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1534         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1535                         keyword, "detach");
1536 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1537         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1538                         identifier, NULL);
1539
1540 cmdline_parse_inst_t cmd_operate_detach_device = {
1541         .f = cmd_operate_detach_device_parsed,
1542         .data = NULL,
1543         .help_str = "device detach <identifier>:"
1544                 "(identifier: pci address or virtual dev name)",
1545         .tokens = {
1546                 (void *)&cmd_operate_detach_device_device,
1547                 (void *)&cmd_operate_detach_device_keyword,
1548                 (void *)&cmd_operate_detach_device_identifier,
1549                 NULL,
1550         },
1551 };
1552 /* *** configure speed for all ports *** */
1553 struct cmd_config_speed_all {
1554         cmdline_fixed_string_t port;
1555         cmdline_fixed_string_t keyword;
1556         cmdline_fixed_string_t all;
1557         cmdline_fixed_string_t item1;
1558         cmdline_fixed_string_t item2;
1559         cmdline_fixed_string_t value1;
1560         cmdline_fixed_string_t value2;
1561 };
1562
1563 static int
1564 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1565 {
1566
1567         int duplex;
1568
1569         if (!strcmp(duplexstr, "half")) {
1570                 duplex = ETH_LINK_HALF_DUPLEX;
1571         } else if (!strcmp(duplexstr, "full")) {
1572                 duplex = ETH_LINK_FULL_DUPLEX;
1573         } else if (!strcmp(duplexstr, "auto")) {
1574                 duplex = ETH_LINK_FULL_DUPLEX;
1575         } else {
1576                 printf("Unknown duplex parameter\n");
1577                 return -1;
1578         }
1579
1580         if (!strcmp(speedstr, "10")) {
1581                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1582                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1583         } else if (!strcmp(speedstr, "100")) {
1584                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1585                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1586         } else {
1587                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1588                         printf("Invalid speed/duplex parameters\n");
1589                         return -1;
1590                 }
1591                 if (!strcmp(speedstr, "1000")) {
1592                         *speed = ETH_LINK_SPEED_1G;
1593                 } else if (!strcmp(speedstr, "10000")) {
1594                         *speed = ETH_LINK_SPEED_10G;
1595                 } else if (!strcmp(speedstr, "25000")) {
1596                         *speed = ETH_LINK_SPEED_25G;
1597                 } else if (!strcmp(speedstr, "40000")) {
1598                         *speed = ETH_LINK_SPEED_40G;
1599                 } else if (!strcmp(speedstr, "50000")) {
1600                         *speed = ETH_LINK_SPEED_50G;
1601                 } else if (!strcmp(speedstr, "100000")) {
1602                         *speed = ETH_LINK_SPEED_100G;
1603                 } else if (!strcmp(speedstr, "200000")) {
1604                         *speed = ETH_LINK_SPEED_200G;
1605                 } else if (!strcmp(speedstr, "auto")) {
1606                         *speed = ETH_LINK_SPEED_AUTONEG;
1607                 } else {
1608                         printf("Unknown speed parameter\n");
1609                         return -1;
1610                 }
1611         }
1612
1613         return 0;
1614 }
1615
1616 static void
1617 cmd_config_speed_all_parsed(void *parsed_result,
1618                         __rte_unused struct cmdline *cl,
1619                         __rte_unused void *data)
1620 {
1621         struct cmd_config_speed_all *res = parsed_result;
1622         uint32_t link_speed;
1623         portid_t pid;
1624
1625         if (!all_ports_stopped()) {
1626                 printf("Please stop all ports first\n");
1627                 return;
1628         }
1629
1630         if (parse_and_check_speed_duplex(res->value1, res->value2,
1631                         &link_speed) < 0)
1632                 return;
1633
1634         RTE_ETH_FOREACH_DEV(pid) {
1635                 ports[pid].dev_conf.link_speeds = link_speed;
1636         }
1637
1638         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1639 }
1640
1641 cmdline_parse_token_string_t cmd_config_speed_all_port =
1642         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1643 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1644         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1645                                                         "config");
1646 cmdline_parse_token_string_t cmd_config_speed_all_all =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1648 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1649         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1650 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1651         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1652                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1653 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1654         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1655 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1657                                                 "half#full#auto");
1658
1659 cmdline_parse_inst_t cmd_config_speed_all = {
1660         .f = cmd_config_speed_all_parsed,
1661         .data = NULL,
1662         .help_str = "port config all speed "
1663                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1664                                                         "half|full|auto",
1665         .tokens = {
1666                 (void *)&cmd_config_speed_all_port,
1667                 (void *)&cmd_config_speed_all_keyword,
1668                 (void *)&cmd_config_speed_all_all,
1669                 (void *)&cmd_config_speed_all_item1,
1670                 (void *)&cmd_config_speed_all_value1,
1671                 (void *)&cmd_config_speed_all_item2,
1672                 (void *)&cmd_config_speed_all_value2,
1673                 NULL,
1674         },
1675 };
1676
1677 /* *** configure speed for specific port *** */
1678 struct cmd_config_speed_specific {
1679         cmdline_fixed_string_t port;
1680         cmdline_fixed_string_t keyword;
1681         portid_t id;
1682         cmdline_fixed_string_t item1;
1683         cmdline_fixed_string_t item2;
1684         cmdline_fixed_string_t value1;
1685         cmdline_fixed_string_t value2;
1686 };
1687
1688 static void
1689 cmd_config_speed_specific_parsed(void *parsed_result,
1690                                 __rte_unused struct cmdline *cl,
1691                                 __rte_unused void *data)
1692 {
1693         struct cmd_config_speed_specific *res = parsed_result;
1694         uint32_t link_speed;
1695
1696         if (!all_ports_stopped()) {
1697                 printf("Please stop all ports first\n");
1698                 return;
1699         }
1700
1701         if (port_id_is_invalid(res->id, ENABLED_WARN))
1702                 return;
1703
1704         if (parse_and_check_speed_duplex(res->value1, res->value2,
1705                         &link_speed) < 0)
1706                 return;
1707
1708         ports[res->id].dev_conf.link_speeds = link_speed;
1709
1710         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1711 }
1712
1713
1714 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1715         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1716                                                                 "port");
1717 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1719                                                                 "config");
1720 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1721         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1722 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1723         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1724                                                                 "speed");
1725 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1726         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1727                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1728 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1729         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1730                                                                 "duplex");
1731 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1733                                                         "half#full#auto");
1734
1735 cmdline_parse_inst_t cmd_config_speed_specific = {
1736         .f = cmd_config_speed_specific_parsed,
1737         .data = NULL,
1738         .help_str = "port config <port_id> speed "
1739                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1740                                                         "half|full|auto",
1741         .tokens = {
1742                 (void *)&cmd_config_speed_specific_port,
1743                 (void *)&cmd_config_speed_specific_keyword,
1744                 (void *)&cmd_config_speed_specific_id,
1745                 (void *)&cmd_config_speed_specific_item1,
1746                 (void *)&cmd_config_speed_specific_value1,
1747                 (void *)&cmd_config_speed_specific_item2,
1748                 (void *)&cmd_config_speed_specific_value2,
1749                 NULL,
1750         },
1751 };
1752
1753 /* *** configure loopback for all ports *** */
1754 struct cmd_config_loopback_all {
1755         cmdline_fixed_string_t port;
1756         cmdline_fixed_string_t keyword;
1757         cmdline_fixed_string_t all;
1758         cmdline_fixed_string_t item;
1759         uint32_t mode;
1760 };
1761
1762 static void
1763 cmd_config_loopback_all_parsed(void *parsed_result,
1764                         __rte_unused struct cmdline *cl,
1765                         __rte_unused void *data)
1766 {
1767         struct cmd_config_loopback_all *res = parsed_result;
1768         portid_t pid;
1769
1770         if (!all_ports_stopped()) {
1771                 printf("Please stop all ports first\n");
1772                 return;
1773         }
1774
1775         RTE_ETH_FOREACH_DEV(pid) {
1776                 ports[pid].dev_conf.lpbk_mode = res->mode;
1777         }
1778
1779         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1780 }
1781
1782 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1783         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1784 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1785         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1786                                                         "config");
1787 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1788         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1789 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1790         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1791                                                         "loopback");
1792 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1793         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1794
1795 cmdline_parse_inst_t cmd_config_loopback_all = {
1796         .f = cmd_config_loopback_all_parsed,
1797         .data = NULL,
1798         .help_str = "port config all loopback <mode>",
1799         .tokens = {
1800                 (void *)&cmd_config_loopback_all_port,
1801                 (void *)&cmd_config_loopback_all_keyword,
1802                 (void *)&cmd_config_loopback_all_all,
1803                 (void *)&cmd_config_loopback_all_item,
1804                 (void *)&cmd_config_loopback_all_mode,
1805                 NULL,
1806         },
1807 };
1808
1809 /* *** configure loopback for specific port *** */
1810 struct cmd_config_loopback_specific {
1811         cmdline_fixed_string_t port;
1812         cmdline_fixed_string_t keyword;
1813         uint16_t port_id;
1814         cmdline_fixed_string_t item;
1815         uint32_t mode;
1816 };
1817
1818 static void
1819 cmd_config_loopback_specific_parsed(void *parsed_result,
1820                                 __rte_unused struct cmdline *cl,
1821                                 __rte_unused void *data)
1822 {
1823         struct cmd_config_loopback_specific *res = parsed_result;
1824
1825         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1826                 return;
1827
1828         if (!port_is_stopped(res->port_id)) {
1829                 printf("Please stop port %u first\n", res->port_id);
1830                 return;
1831         }
1832
1833         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1834
1835         cmd_reconfig_device_queue(res->port_id, 1, 1);
1836 }
1837
1838
1839 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1840         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1841                                                                 "port");
1842 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1843         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1844                                                                 "config");
1845 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1846         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1847                                                                 UINT16);
1848 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1850                                                                 "loopback");
1851 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1852         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1853                               UINT32);
1854
1855 cmdline_parse_inst_t cmd_config_loopback_specific = {
1856         .f = cmd_config_loopback_specific_parsed,
1857         .data = NULL,
1858         .help_str = "port config <port_id> loopback <mode>",
1859         .tokens = {
1860                 (void *)&cmd_config_loopback_specific_port,
1861                 (void *)&cmd_config_loopback_specific_keyword,
1862                 (void *)&cmd_config_loopback_specific_id,
1863                 (void *)&cmd_config_loopback_specific_item,
1864                 (void *)&cmd_config_loopback_specific_mode,
1865                 NULL,
1866         },
1867 };
1868
1869 /* *** configure txq/rxq, txd/rxd *** */
1870 struct cmd_config_rx_tx {
1871         cmdline_fixed_string_t port;
1872         cmdline_fixed_string_t keyword;
1873         cmdline_fixed_string_t all;
1874         cmdline_fixed_string_t name;
1875         uint16_t value;
1876 };
1877
1878 static void
1879 cmd_config_rx_tx_parsed(void *parsed_result,
1880                         __rte_unused struct cmdline *cl,
1881                         __rte_unused void *data)
1882 {
1883         struct cmd_config_rx_tx *res = parsed_result;
1884
1885         if (!all_ports_stopped()) {
1886                 printf("Please stop all ports first\n");
1887                 return;
1888         }
1889         if (!strcmp(res->name, "rxq")) {
1890                 if (!res->value && !nb_txq) {
1891                         printf("Warning: Either rx or tx queues should be non zero\n");
1892                         return;
1893                 }
1894                 if (check_nb_rxq(res->value) != 0)
1895                         return;
1896                 nb_rxq = res->value;
1897         }
1898         else if (!strcmp(res->name, "txq")) {
1899                 if (!res->value && !nb_rxq) {
1900                         printf("Warning: Either rx or tx queues should be non zero\n");
1901                         return;
1902                 }
1903                 if (check_nb_txq(res->value) != 0)
1904                         return;
1905                 nb_txq = res->value;
1906         }
1907         else if (!strcmp(res->name, "rxd")) {
1908                 if (check_nb_rxd(res->value) != 0)
1909                         return;
1910                 nb_rxd = res->value;
1911         } else if (!strcmp(res->name, "txd")) {
1912                 if (check_nb_txd(res->value) != 0)
1913                         return;
1914
1915                 nb_txd = res->value;
1916         } else {
1917                 printf("Unknown parameter\n");
1918                 return;
1919         }
1920
1921         fwd_config_setup();
1922
1923         init_port_config();
1924
1925         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1926 }
1927
1928 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1929         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1930 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1931         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1932 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1933         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1934 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1935         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1936                                                 "rxq#txq#rxd#txd");
1937 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1938         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1939
1940 cmdline_parse_inst_t cmd_config_rx_tx = {
1941         .f = cmd_config_rx_tx_parsed,
1942         .data = NULL,
1943         .help_str = "port config all rxq|txq|rxd|txd <value>",
1944         .tokens = {
1945                 (void *)&cmd_config_rx_tx_port,
1946                 (void *)&cmd_config_rx_tx_keyword,
1947                 (void *)&cmd_config_rx_tx_all,
1948                 (void *)&cmd_config_rx_tx_name,
1949                 (void *)&cmd_config_rx_tx_value,
1950                 NULL,
1951         },
1952 };
1953
1954 /* *** config max packet length *** */
1955 struct cmd_config_max_pkt_len_result {
1956         cmdline_fixed_string_t port;
1957         cmdline_fixed_string_t keyword;
1958         cmdline_fixed_string_t all;
1959         cmdline_fixed_string_t name;
1960         uint32_t value;
1961 };
1962
1963 static void
1964 cmd_config_max_pkt_len_parsed(void *parsed_result,
1965                                 __rte_unused struct cmdline *cl,
1966                                 __rte_unused void *data)
1967 {
1968         struct cmd_config_max_pkt_len_result *res = parsed_result;
1969         portid_t pid;
1970
1971         if (!all_ports_stopped()) {
1972                 printf("Please stop all ports first\n");
1973                 return;
1974         }
1975
1976         RTE_ETH_FOREACH_DEV(pid) {
1977                 struct rte_port *port = &ports[pid];
1978                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1979
1980                 if (!strcmp(res->name, "max-pkt-len")) {
1981                         if (res->value < RTE_ETHER_MIN_LEN) {
1982                                 printf("max-pkt-len can not be less than %d\n",
1983                                                 RTE_ETHER_MIN_LEN);
1984                                 return;
1985                         }
1986                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1987                                 return;
1988
1989                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1990                         if (res->value > RTE_ETHER_MAX_LEN)
1991                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1992                         else
1993                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1994                         port->dev_conf.rxmode.offloads = rx_offloads;
1995                 } else {
1996                         printf("Unknown parameter\n");
1997                         return;
1998                 }
1999         }
2000
2001         init_port_config();
2002
2003         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2004 }
2005
2006 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2007         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2008                                                                 "port");
2009 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2010         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2011                                                                 "config");
2012 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2013         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2014                                                                 "all");
2015 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2016         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2017                                                                 "max-pkt-len");
2018 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2019         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2020                                                                 UINT32);
2021
2022 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2023         .f = cmd_config_max_pkt_len_parsed,
2024         .data = NULL,
2025         .help_str = "port config all max-pkt-len <value>",
2026         .tokens = {
2027                 (void *)&cmd_config_max_pkt_len_port,
2028                 (void *)&cmd_config_max_pkt_len_keyword,
2029                 (void *)&cmd_config_max_pkt_len_all,
2030                 (void *)&cmd_config_max_pkt_len_name,
2031                 (void *)&cmd_config_max_pkt_len_value,
2032                 NULL,
2033         },
2034 };
2035
2036 /* *** config max LRO aggregated packet size *** */
2037 struct cmd_config_max_lro_pkt_size_result {
2038         cmdline_fixed_string_t port;
2039         cmdline_fixed_string_t keyword;
2040         cmdline_fixed_string_t all;
2041         cmdline_fixed_string_t name;
2042         uint32_t value;
2043 };
2044
2045 static void
2046 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2047                                 __rte_unused struct cmdline *cl,
2048                                 __rte_unused void *data)
2049 {
2050         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2051         portid_t pid;
2052
2053         if (!all_ports_stopped()) {
2054                 printf("Please stop all ports first\n");
2055                 return;
2056         }
2057
2058         RTE_ETH_FOREACH_DEV(pid) {
2059                 struct rte_port *port = &ports[pid];
2060
2061                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2062                         if (res->value ==
2063                                         port->dev_conf.rxmode.max_lro_pkt_size)
2064                                 return;
2065
2066                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2067                 } else {
2068                         printf("Unknown parameter\n");
2069                         return;
2070                 }
2071         }
2072
2073         init_port_config();
2074
2075         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2076 }
2077
2078 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2079         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2080                                  port, "port");
2081 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2082         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2083                                  keyword, "config");
2084 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2085         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2086                                  all, "all");
2087 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2088         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2089                                  name, "max-lro-pkt-size");
2090 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2091         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2092                               value, UINT32);
2093
2094 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2095         .f = cmd_config_max_lro_pkt_size_parsed,
2096         .data = NULL,
2097         .help_str = "port config all max-lro-pkt-size <value>",
2098         .tokens = {
2099                 (void *)&cmd_config_max_lro_pkt_size_port,
2100                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2101                 (void *)&cmd_config_max_lro_pkt_size_all,
2102                 (void *)&cmd_config_max_lro_pkt_size_name,
2103                 (void *)&cmd_config_max_lro_pkt_size_value,
2104                 NULL,
2105         },
2106 };
2107
2108 /* *** configure port MTU *** */
2109 struct cmd_config_mtu_result {
2110         cmdline_fixed_string_t port;
2111         cmdline_fixed_string_t keyword;
2112         cmdline_fixed_string_t mtu;
2113         portid_t port_id;
2114         uint16_t value;
2115 };
2116
2117 static void
2118 cmd_config_mtu_parsed(void *parsed_result,
2119                       __rte_unused struct cmdline *cl,
2120                       __rte_unused void *data)
2121 {
2122         struct cmd_config_mtu_result *res = parsed_result;
2123
2124         if (res->value < RTE_ETHER_MIN_LEN) {
2125                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2126                 return;
2127         }
2128         port_mtu_set(res->port_id, res->value);
2129 }
2130
2131 cmdline_parse_token_string_t cmd_config_mtu_port =
2132         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2133                                  "port");
2134 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2135         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2136                                  "config");
2137 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2138         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2139                                  "mtu");
2140 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2141         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2142 cmdline_parse_token_num_t cmd_config_mtu_value =
2143         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2144
2145 cmdline_parse_inst_t cmd_config_mtu = {
2146         .f = cmd_config_mtu_parsed,
2147         .data = NULL,
2148         .help_str = "port config mtu <port_id> <value>",
2149         .tokens = {
2150                 (void *)&cmd_config_mtu_port,
2151                 (void *)&cmd_config_mtu_keyword,
2152                 (void *)&cmd_config_mtu_mtu,
2153                 (void *)&cmd_config_mtu_port_id,
2154                 (void *)&cmd_config_mtu_value,
2155                 NULL,
2156         },
2157 };
2158
2159 /* *** configure rx mode *** */
2160 struct cmd_config_rx_mode_flag {
2161         cmdline_fixed_string_t port;
2162         cmdline_fixed_string_t keyword;
2163         cmdline_fixed_string_t all;
2164         cmdline_fixed_string_t name;
2165         cmdline_fixed_string_t value;
2166 };
2167
2168 static void
2169 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2170                                 __rte_unused struct cmdline *cl,
2171                                 __rte_unused void *data)
2172 {
2173         struct cmd_config_rx_mode_flag *res = parsed_result;
2174
2175         if (!all_ports_stopped()) {
2176                 printf("Please stop all ports first\n");
2177                 return;
2178         }
2179
2180         if (!strcmp(res->name, "drop-en")) {
2181                 if (!strcmp(res->value, "on"))
2182                         rx_drop_en = 1;
2183                 else if (!strcmp(res->value, "off"))
2184                         rx_drop_en = 0;
2185                 else {
2186                         printf("Unknown parameter\n");
2187                         return;
2188                 }
2189         } else {
2190                 printf("Unknown parameter\n");
2191                 return;
2192         }
2193
2194         init_port_config();
2195
2196         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2197 }
2198
2199 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2200         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2201 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2202         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2203                                                                 "config");
2204 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2205         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2206 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2207         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2208                                         "drop-en");
2209 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2210         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2211                                                         "on#off");
2212
2213 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2214         .f = cmd_config_rx_mode_flag_parsed,
2215         .data = NULL,
2216         .help_str = "port config all drop-en on|off",
2217         .tokens = {
2218                 (void *)&cmd_config_rx_mode_flag_port,
2219                 (void *)&cmd_config_rx_mode_flag_keyword,
2220                 (void *)&cmd_config_rx_mode_flag_all,
2221                 (void *)&cmd_config_rx_mode_flag_name,
2222                 (void *)&cmd_config_rx_mode_flag_value,
2223                 NULL,
2224         },
2225 };
2226
2227 /* *** configure rss *** */
2228 struct cmd_config_rss {
2229         cmdline_fixed_string_t port;
2230         cmdline_fixed_string_t keyword;
2231         cmdline_fixed_string_t all;
2232         cmdline_fixed_string_t name;
2233         cmdline_fixed_string_t value;
2234 };
2235
2236 static void
2237 cmd_config_rss_parsed(void *parsed_result,
2238                         __rte_unused struct cmdline *cl,
2239                         __rte_unused void *data)
2240 {
2241         struct cmd_config_rss *res = parsed_result;
2242         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2243         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2244         int use_default = 0;
2245         int all_updated = 1;
2246         int diag;
2247         uint16_t i;
2248         int ret;
2249
2250         if (!strcmp(res->value, "all"))
2251                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2252                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2253                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2254                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2255         else if (!strcmp(res->value, "eth"))
2256                 rss_conf.rss_hf = ETH_RSS_ETH;
2257         else if (!strcmp(res->value, "vlan"))
2258                 rss_conf.rss_hf = ETH_RSS_VLAN;
2259         else if (!strcmp(res->value, "ip"))
2260                 rss_conf.rss_hf = ETH_RSS_IP;
2261         else if (!strcmp(res->value, "udp"))
2262                 rss_conf.rss_hf = ETH_RSS_UDP;
2263         else if (!strcmp(res->value, "tcp"))
2264                 rss_conf.rss_hf = ETH_RSS_TCP;
2265         else if (!strcmp(res->value, "sctp"))
2266                 rss_conf.rss_hf = ETH_RSS_SCTP;
2267         else if (!strcmp(res->value, "ether"))
2268                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2269         else if (!strcmp(res->value, "port"))
2270                 rss_conf.rss_hf = ETH_RSS_PORT;
2271         else if (!strcmp(res->value, "vxlan"))
2272                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2273         else if (!strcmp(res->value, "geneve"))
2274                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2275         else if (!strcmp(res->value, "nvgre"))
2276                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2277         else if (!strcmp(res->value, "l3-pre32"))
2278                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2279         else if (!strcmp(res->value, "l3-pre40"))
2280                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2281         else if (!strcmp(res->value, "l3-pre48"))
2282                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2283         else if (!strcmp(res->value, "l3-pre56"))
2284                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2285         else if (!strcmp(res->value, "l3-pre64"))
2286                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2287         else if (!strcmp(res->value, "l3-pre96"))
2288                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2289         else if (!strcmp(res->value, "l3-src-only"))
2290                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2291         else if (!strcmp(res->value, "l3-dst-only"))
2292                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2293         else if (!strcmp(res->value, "l4-src-only"))
2294                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2295         else if (!strcmp(res->value, "l4-dst-only"))
2296                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2297         else if (!strcmp(res->value, "l2-src-only"))
2298                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2299         else if (!strcmp(res->value, "l2-dst-only"))
2300                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2301         else if (!strcmp(res->value, "l2tpv3"))
2302                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2303         else if (!strcmp(res->value, "esp"))
2304                 rss_conf.rss_hf = ETH_RSS_ESP;
2305         else if (!strcmp(res->value, "ah"))
2306                 rss_conf.rss_hf = ETH_RSS_AH;
2307         else if (!strcmp(res->value, "pfcp"))
2308                 rss_conf.rss_hf = ETH_RSS_PFCP;
2309         else if (!strcmp(res->value, "pppoe"))
2310                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2311         else if (!strcmp(res->value, "gtpu"))
2312                 rss_conf.rss_hf = ETH_RSS_GTPU;
2313         else if (!strcmp(res->value, "none"))
2314                 rss_conf.rss_hf = 0;
2315         else if (!strcmp(res->value, "level-default")) {
2316                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2317                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2318         } else if (!strcmp(res->value, "level-outer")) {
2319                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2320                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2321         } else if (!strcmp(res->value, "level-inner")) {
2322                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2323                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2324         } else if (!strcmp(res->value, "default"))
2325                 use_default = 1;
2326         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2327                                                 atoi(res->value) < 64)
2328                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2329         else {
2330                 printf("Unknown parameter\n");
2331                 return;
2332         }
2333         rss_conf.rss_key = NULL;
2334         /* Update global configuration for RSS types. */
2335         RTE_ETH_FOREACH_DEV(i) {
2336                 struct rte_eth_rss_conf local_rss_conf;
2337
2338                 ret = eth_dev_info_get_print_err(i, &dev_info);
2339                 if (ret != 0)
2340                         return;
2341
2342                 if (use_default)
2343                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2344
2345                 local_rss_conf = rss_conf;
2346                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2347                         dev_info.flow_type_rss_offloads;
2348                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2349                         printf("Port %u modified RSS hash function based on hardware support,"
2350                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2351                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2352                 }
2353                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2354                 if (diag < 0) {
2355                         all_updated = 0;
2356                         printf("Configuration of RSS hash at ethernet port %d "
2357                                 "failed with error (%d): %s.\n",
2358                                 i, -diag, strerror(-diag));
2359                 }
2360         }
2361         if (all_updated && !use_default) {
2362                 rss_hf = rss_conf.rss_hf;
2363                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2364         }
2365 }
2366
2367 cmdline_parse_token_string_t cmd_config_rss_port =
2368         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2369 cmdline_parse_token_string_t cmd_config_rss_keyword =
2370         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2371 cmdline_parse_token_string_t cmd_config_rss_all =
2372         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2373 cmdline_parse_token_string_t cmd_config_rss_name =
2374         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2375 cmdline_parse_token_string_t cmd_config_rss_value =
2376         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2377
2378 cmdline_parse_inst_t cmd_config_rss = {
2379         .f = cmd_config_rss_parsed,
2380         .data = NULL,
2381         .help_str = "port config all rss "
2382                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2383                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2384                 "level-outer|level-inner|<flowtype_id>",
2385         .tokens = {
2386                 (void *)&cmd_config_rss_port,
2387                 (void *)&cmd_config_rss_keyword,
2388                 (void *)&cmd_config_rss_all,
2389                 (void *)&cmd_config_rss_name,
2390                 (void *)&cmd_config_rss_value,
2391                 NULL,
2392         },
2393 };
2394
2395 /* *** configure rss hash key *** */
2396 struct cmd_config_rss_hash_key {
2397         cmdline_fixed_string_t port;
2398         cmdline_fixed_string_t config;
2399         portid_t port_id;
2400         cmdline_fixed_string_t rss_hash_key;
2401         cmdline_fixed_string_t rss_type;
2402         cmdline_fixed_string_t key;
2403 };
2404
2405 static uint8_t
2406 hexa_digit_to_value(char hexa_digit)
2407 {
2408         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2409                 return (uint8_t) (hexa_digit - '0');
2410         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2411                 return (uint8_t) ((hexa_digit - 'a') + 10);
2412         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2413                 return (uint8_t) ((hexa_digit - 'A') + 10);
2414         /* Invalid hexa digit */
2415         return 0xFF;
2416 }
2417
2418 static uint8_t
2419 parse_and_check_key_hexa_digit(char *key, int idx)
2420 {
2421         uint8_t hexa_v;
2422
2423         hexa_v = hexa_digit_to_value(key[idx]);
2424         if (hexa_v == 0xFF)
2425                 printf("invalid key: character %c at position %d is not a "
2426                        "valid hexa digit\n", key[idx], idx);
2427         return hexa_v;
2428 }
2429
2430 static void
2431 cmd_config_rss_hash_key_parsed(void *parsed_result,
2432                                __rte_unused struct cmdline *cl,
2433                                __rte_unused void *data)
2434 {
2435         struct cmd_config_rss_hash_key *res = parsed_result;
2436         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2437         uint8_t xdgt0;
2438         uint8_t xdgt1;
2439         int i;
2440         struct rte_eth_dev_info dev_info;
2441         uint8_t hash_key_size;
2442         uint32_t key_len;
2443         int ret;
2444
2445         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2446         if (ret != 0)
2447                 return;
2448
2449         if (dev_info.hash_key_size > 0 &&
2450                         dev_info.hash_key_size <= sizeof(hash_key))
2451                 hash_key_size = dev_info.hash_key_size;
2452         else {
2453                 printf("dev_info did not provide a valid hash key size\n");
2454                 return;
2455         }
2456         /* Check the length of the RSS hash key */
2457         key_len = strlen(res->key);
2458         if (key_len != (hash_key_size * 2)) {
2459                 printf("key length: %d invalid - key must be a string of %d"
2460                            " hexa-decimal numbers\n",
2461                            (int) key_len, hash_key_size * 2);
2462                 return;
2463         }
2464         /* Translate RSS hash key into binary representation */
2465         for (i = 0; i < hash_key_size; i++) {
2466                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2467                 if (xdgt0 == 0xFF)
2468                         return;
2469                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2470                 if (xdgt1 == 0xFF)
2471                         return;
2472                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2473         }
2474         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2475                         hash_key_size);
2476 }
2477
2478 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2479         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2480 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2481         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2482                                  "config");
2483 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2484         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2485 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2486         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2487                                  rss_hash_key, "rss-hash-key");
2488 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2489         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2490                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2491                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2492                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2493                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2494                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2495                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2496                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2497 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2498         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2499
2500 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2501         .f = cmd_config_rss_hash_key_parsed,
2502         .data = NULL,
2503         .help_str = "port config <port_id> rss-hash-key "
2504                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2505                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2506                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2507                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2508                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2509                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2510                 "<string of hex digits (variable length, NIC dependent)>",
2511         .tokens = {
2512                 (void *)&cmd_config_rss_hash_key_port,
2513                 (void *)&cmd_config_rss_hash_key_config,
2514                 (void *)&cmd_config_rss_hash_key_port_id,
2515                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2516                 (void *)&cmd_config_rss_hash_key_rss_type,
2517                 (void *)&cmd_config_rss_hash_key_value,
2518                 NULL,
2519         },
2520 };
2521
2522 /* *** configure port rxq/txq ring size *** */
2523 struct cmd_config_rxtx_ring_size {
2524         cmdline_fixed_string_t port;
2525         cmdline_fixed_string_t config;
2526         portid_t portid;
2527         cmdline_fixed_string_t rxtxq;
2528         uint16_t qid;
2529         cmdline_fixed_string_t rsize;
2530         uint16_t size;
2531 };
2532
2533 static void
2534 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2535                                  __rte_unused struct cmdline *cl,
2536                                  __rte_unused void *data)
2537 {
2538         struct cmd_config_rxtx_ring_size *res = parsed_result;
2539         struct rte_port *port;
2540         uint8_t isrx;
2541
2542         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2543                 return;
2544
2545         if (res->portid == (portid_t)RTE_PORT_ALL) {
2546                 printf("Invalid port id\n");
2547                 return;
2548         }
2549
2550         port = &ports[res->portid];
2551
2552         if (!strcmp(res->rxtxq, "rxq"))
2553                 isrx = 1;
2554         else if (!strcmp(res->rxtxq, "txq"))
2555                 isrx = 0;
2556         else {
2557                 printf("Unknown parameter\n");
2558                 return;
2559         }
2560
2561         if (isrx && rx_queue_id_is_invalid(res->qid))
2562                 return;
2563         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2564                 return;
2565
2566         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2567                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2568                        rx_free_thresh);
2569                 return;
2570         }
2571
2572         if (isrx)
2573                 port->nb_rx_desc[res->qid] = res->size;
2574         else
2575                 port->nb_tx_desc[res->qid] = res->size;
2576
2577         cmd_reconfig_device_queue(res->portid, 0, 1);
2578 }
2579
2580 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2581         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2582                                  port, "port");
2583 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2584         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2585                                  config, "config");
2586 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2587         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2588                                  portid, UINT16);
2589 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2590         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2591                                  rxtxq, "rxq#txq");
2592 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2593         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2594                               qid, UINT16);
2595 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2596         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2597                                  rsize, "ring_size");
2598 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2599         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2600                               size, UINT16);
2601
2602 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2603         .f = cmd_config_rxtx_ring_size_parsed,
2604         .data = NULL,
2605         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2606         .tokens = {
2607                 (void *)&cmd_config_rxtx_ring_size_port,
2608                 (void *)&cmd_config_rxtx_ring_size_config,
2609                 (void *)&cmd_config_rxtx_ring_size_portid,
2610                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2611                 (void *)&cmd_config_rxtx_ring_size_qid,
2612                 (void *)&cmd_config_rxtx_ring_size_rsize,
2613                 (void *)&cmd_config_rxtx_ring_size_size,
2614                 NULL,
2615         },
2616 };
2617
2618 /* *** configure port rxq/txq start/stop *** */
2619 struct cmd_config_rxtx_queue {
2620         cmdline_fixed_string_t port;
2621         portid_t portid;
2622         cmdline_fixed_string_t rxtxq;
2623         uint16_t qid;
2624         cmdline_fixed_string_t opname;
2625 };
2626
2627 static void
2628 cmd_config_rxtx_queue_parsed(void *parsed_result,
2629                         __rte_unused struct cmdline *cl,
2630                         __rte_unused void *data)
2631 {
2632         struct cmd_config_rxtx_queue *res = parsed_result;
2633         uint8_t isrx;
2634         uint8_t isstart;
2635         int ret = 0;
2636
2637         if (test_done == 0) {
2638                 printf("Please stop forwarding first\n");
2639                 return;
2640         }
2641
2642         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2643                 return;
2644
2645         if (port_is_started(res->portid) != 1) {
2646                 printf("Please start port %u first\n", res->portid);
2647                 return;
2648         }
2649
2650         if (!strcmp(res->rxtxq, "rxq"))
2651                 isrx = 1;
2652         else if (!strcmp(res->rxtxq, "txq"))
2653                 isrx = 0;
2654         else {
2655                 printf("Unknown parameter\n");
2656                 return;
2657         }
2658
2659         if (isrx && rx_queue_id_is_invalid(res->qid))
2660                 return;
2661         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2662                 return;
2663
2664         if (!strcmp(res->opname, "start"))
2665                 isstart = 1;
2666         else if (!strcmp(res->opname, "stop"))
2667                 isstart = 0;
2668         else {
2669                 printf("Unknown parameter\n");
2670                 return;
2671         }
2672
2673         if (isstart && isrx)
2674                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2675         else if (!isstart && isrx)
2676                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2677         else if (isstart && !isrx)
2678                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2679         else
2680                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2681
2682         if (ret == -ENOTSUP)
2683                 printf("Function not supported in PMD driver\n");
2684 }
2685
2686 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2687         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2688 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2689         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2690 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2691         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2692 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2693         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2694 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2695         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2696                                                 "start#stop");
2697
2698 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2699         .f = cmd_config_rxtx_queue_parsed,
2700         .data = NULL,
2701         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2702         .tokens = {
2703                 (void *)&cmd_config_rxtx_queue_port,
2704                 (void *)&cmd_config_rxtx_queue_portid,
2705                 (void *)&cmd_config_rxtx_queue_rxtxq,
2706                 (void *)&cmd_config_rxtx_queue_qid,
2707                 (void *)&cmd_config_rxtx_queue_opname,
2708                 NULL,
2709         },
2710 };
2711
2712 /* *** configure port rxq/txq deferred start on/off *** */
2713 struct cmd_config_deferred_start_rxtx_queue {
2714         cmdline_fixed_string_t port;
2715         portid_t port_id;
2716         cmdline_fixed_string_t rxtxq;
2717         uint16_t qid;
2718         cmdline_fixed_string_t opname;
2719         cmdline_fixed_string_t state;
2720 };
2721
2722 static void
2723 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2724                         __rte_unused struct cmdline *cl,
2725                         __rte_unused void *data)
2726 {
2727         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2728         struct rte_port *port;
2729         uint8_t isrx;
2730         uint8_t ison;
2731         uint8_t needreconfig = 0;
2732
2733         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2734                 return;
2735
2736         if (port_is_started(res->port_id) != 0) {
2737                 printf("Please stop port %u first\n", res->port_id);
2738                 return;
2739         }
2740
2741         port = &ports[res->port_id];
2742
2743         isrx = !strcmp(res->rxtxq, "rxq");
2744
2745         if (isrx && rx_queue_id_is_invalid(res->qid))
2746                 return;
2747         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2748                 return;
2749
2750         ison = !strcmp(res->state, "on");
2751
2752         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2753                 port->rx_conf[res->qid].rx_deferred_start = ison;
2754                 needreconfig = 1;
2755         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2756                 port->tx_conf[res->qid].tx_deferred_start = ison;
2757                 needreconfig = 1;
2758         }
2759
2760         if (needreconfig)
2761                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2762 }
2763
2764 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2765         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2766                                                 port, "port");
2767 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2768         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2769                                                 port_id, UINT16);
2770 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2771         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2772                                                 rxtxq, "rxq#txq");
2773 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2774         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2775                                                 qid, UINT16);
2776 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2777         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2778                                                 opname, "deferred_start");
2779 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2780         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2781                                                 state, "on#off");
2782
2783 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2784         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2785         .data = NULL,
2786         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2787         .tokens = {
2788                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2789                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2790                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2791                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2792                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2793                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2794                 NULL,
2795         },
2796 };
2797
2798 /* *** configure port rxq/txq setup *** */
2799 struct cmd_setup_rxtx_queue {
2800         cmdline_fixed_string_t port;
2801         portid_t portid;
2802         cmdline_fixed_string_t rxtxq;
2803         uint16_t qid;
2804         cmdline_fixed_string_t setup;
2805 };
2806
2807 /* Common CLI fields for queue setup */
2808 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2809         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2810 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2811         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2812 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2813         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2814 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2815         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2816 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2817         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2818
2819 static void
2820 cmd_setup_rxtx_queue_parsed(
2821         void *parsed_result,
2822         __rte_unused struct cmdline *cl,
2823         __rte_unused void *data)
2824 {
2825         struct cmd_setup_rxtx_queue *res = parsed_result;
2826         struct rte_port *port;
2827         struct rte_mempool *mp;
2828         unsigned int socket_id;
2829         uint8_t isrx = 0;
2830         int ret;
2831
2832         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2833                 return;
2834
2835         if (res->portid == (portid_t)RTE_PORT_ALL) {
2836                 printf("Invalid port id\n");
2837                 return;
2838         }
2839
2840         if (!strcmp(res->rxtxq, "rxq"))
2841                 isrx = 1;
2842         else if (!strcmp(res->rxtxq, "txq"))
2843                 isrx = 0;
2844         else {
2845                 printf("Unknown parameter\n");
2846                 return;
2847         }
2848
2849         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2850                 printf("Invalid rx queue\n");
2851                 return;
2852         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2853                 printf("Invalid tx queue\n");
2854                 return;
2855         }
2856
2857         port = &ports[res->portid];
2858         if (isrx) {
2859                 socket_id = rxring_numa[res->portid];
2860                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2861                         socket_id = port->socket_id;
2862
2863                 mp = mbuf_pool_find(socket_id, 0);
2864                 if (mp == NULL) {
2865                         printf("Failed to setup RX queue: "
2866                                 "No mempool allocation"
2867                                 " on the socket %d\n",
2868                                 rxring_numa[res->portid]);
2869                         return;
2870                 }
2871                 ret = rx_queue_setup(res->portid,
2872                                      res->qid,
2873                                      port->nb_rx_desc[res->qid],
2874                                      socket_id,
2875                                      &port->rx_conf[res->qid],
2876                                      mp);
2877                 if (ret)
2878                         printf("Failed to setup RX queue\n");
2879         } else {
2880                 socket_id = txring_numa[res->portid];
2881                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2882                         socket_id = port->socket_id;
2883
2884                 ret = rte_eth_tx_queue_setup(res->portid,
2885                                              res->qid,
2886                                              port->nb_tx_desc[res->qid],
2887                                              socket_id,
2888                                              &port->tx_conf[res->qid]);
2889                 if (ret)
2890                         printf("Failed to setup TX queue\n");
2891         }
2892 }
2893
2894 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2895         .f = cmd_setup_rxtx_queue_parsed,
2896         .data = NULL,
2897         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2898         .tokens = {
2899                 (void *)&cmd_setup_rxtx_queue_port,
2900                 (void *)&cmd_setup_rxtx_queue_portid,
2901                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2902                 (void *)&cmd_setup_rxtx_queue_qid,
2903                 (void *)&cmd_setup_rxtx_queue_setup,
2904                 NULL,
2905         },
2906 };
2907
2908
2909 /* *** Configure RSS RETA *** */
2910 struct cmd_config_rss_reta {
2911         cmdline_fixed_string_t port;
2912         cmdline_fixed_string_t keyword;
2913         portid_t port_id;
2914         cmdline_fixed_string_t name;
2915         cmdline_fixed_string_t list_name;
2916         cmdline_fixed_string_t list_of_items;
2917 };
2918
2919 static int
2920 parse_reta_config(const char *str,
2921                   struct rte_eth_rss_reta_entry64 *reta_conf,
2922                   uint16_t nb_entries)
2923 {
2924         int i;
2925         unsigned size;
2926         uint16_t hash_index, idx, shift;
2927         uint16_t nb_queue;
2928         char s[256];
2929         const char *p, *p0 = str;
2930         char *end;
2931         enum fieldnames {
2932                 FLD_HASH_INDEX = 0,
2933                 FLD_QUEUE,
2934                 _NUM_FLD
2935         };
2936         unsigned long int_fld[_NUM_FLD];
2937         char *str_fld[_NUM_FLD];
2938
2939         while ((p = strchr(p0,'(')) != NULL) {
2940                 ++p;
2941                 if((p0 = strchr(p,')')) == NULL)
2942                         return -1;
2943
2944                 size = p0 - p;
2945                 if(size >= sizeof(s))
2946                         return -1;
2947
2948                 snprintf(s, sizeof(s), "%.*s", size, p);
2949                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2950                         return -1;
2951                 for (i = 0; i < _NUM_FLD; i++) {
2952                         errno = 0;
2953                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2954                         if (errno != 0 || end == str_fld[i] ||
2955                                         int_fld[i] > 65535)
2956                                 return -1;
2957                 }
2958
2959                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2960                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2961
2962                 if (hash_index >= nb_entries) {
2963                         printf("Invalid RETA hash index=%d\n", hash_index);
2964                         return -1;
2965                 }
2966
2967                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2968                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2969                 reta_conf[idx].mask |= (1ULL << shift);
2970                 reta_conf[idx].reta[shift] = nb_queue;
2971         }
2972
2973         return 0;
2974 }
2975
2976 static void
2977 cmd_set_rss_reta_parsed(void *parsed_result,
2978                         __rte_unused struct cmdline *cl,
2979                         __rte_unused void *data)
2980 {
2981         int ret;
2982         struct rte_eth_dev_info dev_info;
2983         struct rte_eth_rss_reta_entry64 reta_conf[8];
2984         struct cmd_config_rss_reta *res = parsed_result;
2985
2986         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2987         if (ret != 0)
2988                 return;
2989
2990         if (dev_info.reta_size == 0) {
2991                 printf("Redirection table size is 0 which is "
2992                                         "invalid for RSS\n");
2993                 return;
2994         } else
2995                 printf("The reta size of port %d is %u\n",
2996                         res->port_id, dev_info.reta_size);
2997         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2998                 printf("Currently do not support more than %u entries of "
2999                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3000                 return;
3001         }
3002
3003         memset(reta_conf, 0, sizeof(reta_conf));
3004         if (!strcmp(res->list_name, "reta")) {
3005                 if (parse_reta_config(res->list_of_items, reta_conf,
3006                                                 dev_info.reta_size)) {
3007                         printf("Invalid RSS Redirection Table "
3008                                         "config entered\n");
3009                         return;
3010                 }
3011                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3012                                 reta_conf, dev_info.reta_size);
3013                 if (ret != 0)
3014                         printf("Bad redirection table parameter, "
3015                                         "return code = %d \n", ret);
3016         }
3017 }
3018
3019 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3020         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3021 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3022         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3023 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3024         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3025 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3026         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3027 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3028         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3029 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3030         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3031                                  NULL);
3032 cmdline_parse_inst_t cmd_config_rss_reta = {
3033         .f = cmd_set_rss_reta_parsed,
3034         .data = NULL,
3035         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3036         .tokens = {
3037                 (void *)&cmd_config_rss_reta_port,
3038                 (void *)&cmd_config_rss_reta_keyword,
3039                 (void *)&cmd_config_rss_reta_port_id,
3040                 (void *)&cmd_config_rss_reta_name,
3041                 (void *)&cmd_config_rss_reta_list_name,
3042                 (void *)&cmd_config_rss_reta_list_of_items,
3043                 NULL,
3044         },
3045 };
3046
3047 /* *** SHOW PORT RETA INFO *** */
3048 struct cmd_showport_reta {
3049         cmdline_fixed_string_t show;
3050         cmdline_fixed_string_t port;
3051         portid_t port_id;
3052         cmdline_fixed_string_t rss;
3053         cmdline_fixed_string_t reta;
3054         uint16_t size;
3055         cmdline_fixed_string_t list_of_items;
3056 };
3057
3058 static int
3059 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3060                            uint16_t nb_entries,
3061                            char *str)
3062 {
3063         uint32_t size;
3064         const char *p, *p0 = str;
3065         char s[256];
3066         char *end;
3067         char *str_fld[8];
3068         uint16_t i;
3069         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3070                         RTE_RETA_GROUP_SIZE;
3071         int ret;
3072
3073         p = strchr(p0, '(');
3074         if (p == NULL)
3075                 return -1;
3076         p++;
3077         p0 = strchr(p, ')');
3078         if (p0 == NULL)
3079                 return -1;
3080         size = p0 - p;
3081         if (size >= sizeof(s)) {
3082                 printf("The string size exceeds the internal buffer size\n");
3083                 return -1;
3084         }
3085         snprintf(s, sizeof(s), "%.*s", size, p);
3086         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3087         if (ret <= 0 || ret != num) {
3088                 printf("The bits of masks do not match the number of "
3089                                         "reta entries: %u\n", num);
3090                 return -1;
3091         }
3092         for (i = 0; i < ret; i++)
3093                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3094
3095         return 0;
3096 }
3097
3098 static void
3099 cmd_showport_reta_parsed(void *parsed_result,
3100                          __rte_unused struct cmdline *cl,
3101                          __rte_unused void *data)
3102 {
3103         struct cmd_showport_reta *res = parsed_result;
3104         struct rte_eth_rss_reta_entry64 reta_conf[8];
3105         struct rte_eth_dev_info dev_info;
3106         uint16_t max_reta_size;
3107         int ret;
3108
3109         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3110         if (ret != 0)
3111                 return;
3112
3113         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3114         if (res->size == 0 || res->size > max_reta_size) {
3115                 printf("Invalid redirection table size: %u (1-%u)\n",
3116                         res->size, max_reta_size);
3117                 return;
3118         }
3119
3120         memset(reta_conf, 0, sizeof(reta_conf));
3121         if (showport_parse_reta_config(reta_conf, res->size,
3122                                 res->list_of_items) < 0) {
3123                 printf("Invalid string: %s for reta masks\n",
3124                                         res->list_of_items);
3125                 return;
3126         }
3127         port_rss_reta_info(res->port_id, reta_conf, res->size);
3128 }
3129
3130 cmdline_parse_token_string_t cmd_showport_reta_show =
3131         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3132 cmdline_parse_token_string_t cmd_showport_reta_port =
3133         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3134 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3135         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3136 cmdline_parse_token_string_t cmd_showport_reta_rss =
3137         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3138 cmdline_parse_token_string_t cmd_showport_reta_reta =
3139         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3140 cmdline_parse_token_num_t cmd_showport_reta_size =
3141         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3142 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3143         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3144                                         list_of_items, NULL);
3145
3146 cmdline_parse_inst_t cmd_showport_reta = {
3147         .f = cmd_showport_reta_parsed,
3148         .data = NULL,
3149         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3150         .tokens = {
3151                 (void *)&cmd_showport_reta_show,
3152                 (void *)&cmd_showport_reta_port,
3153                 (void *)&cmd_showport_reta_port_id,
3154                 (void *)&cmd_showport_reta_rss,
3155                 (void *)&cmd_showport_reta_reta,
3156                 (void *)&cmd_showport_reta_size,
3157                 (void *)&cmd_showport_reta_list_of_items,
3158                 NULL,
3159         },
3160 };
3161
3162 /* *** Show RSS hash configuration *** */
3163 struct cmd_showport_rss_hash {
3164         cmdline_fixed_string_t show;
3165         cmdline_fixed_string_t port;
3166         portid_t port_id;
3167         cmdline_fixed_string_t rss_hash;
3168         cmdline_fixed_string_t rss_type;
3169         cmdline_fixed_string_t key; /* optional argument */
3170 };
3171
3172 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3173                                 __rte_unused struct cmdline *cl,
3174                                 void *show_rss_key)
3175 {
3176         struct cmd_showport_rss_hash *res = parsed_result;
3177
3178         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3179 }
3180
3181 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3182         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3183 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3184         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3185 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3186         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3187 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3188         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3189                                  "rss-hash");
3190 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3191         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3192
3193 cmdline_parse_inst_t cmd_showport_rss_hash = {
3194         .f = cmd_showport_rss_hash_parsed,
3195         .data = NULL,
3196         .help_str = "show port <port_id> rss-hash",
3197         .tokens = {
3198                 (void *)&cmd_showport_rss_hash_show,
3199                 (void *)&cmd_showport_rss_hash_port,
3200                 (void *)&cmd_showport_rss_hash_port_id,
3201                 (void *)&cmd_showport_rss_hash_rss_hash,
3202                 NULL,
3203         },
3204 };
3205
3206 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3207         .f = cmd_showport_rss_hash_parsed,
3208         .data = (void *)1,
3209         .help_str = "show port <port_id> rss-hash key",
3210         .tokens = {
3211                 (void *)&cmd_showport_rss_hash_show,
3212                 (void *)&cmd_showport_rss_hash_port,
3213                 (void *)&cmd_showport_rss_hash_port_id,
3214                 (void *)&cmd_showport_rss_hash_rss_hash,
3215                 (void *)&cmd_showport_rss_hash_rss_key,
3216                 NULL,
3217         },
3218 };
3219
3220 /* *** Configure DCB *** */
3221 struct cmd_config_dcb {
3222         cmdline_fixed_string_t port;
3223         cmdline_fixed_string_t config;
3224         portid_t port_id;
3225         cmdline_fixed_string_t dcb;
3226         cmdline_fixed_string_t vt;
3227         cmdline_fixed_string_t vt_en;
3228         uint8_t num_tcs;
3229         cmdline_fixed_string_t pfc;
3230         cmdline_fixed_string_t pfc_en;
3231 };
3232
3233 static void
3234 cmd_config_dcb_parsed(void *parsed_result,
3235                         __rte_unused struct cmdline *cl,
3236                         __rte_unused void *data)
3237 {
3238         struct cmd_config_dcb *res = parsed_result;
3239         portid_t port_id = res->port_id;
3240         struct rte_port *port;
3241         uint8_t pfc_en;
3242         int ret;
3243
3244         port = &ports[port_id];
3245         /** Check if the port is not started **/
3246         if (port->port_status != RTE_PORT_STOPPED) {
3247                 printf("Please stop port %d first\n", port_id);
3248                 return;
3249         }
3250
3251         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3252                 printf("The invalid number of traffic class,"
3253                         " only 4 or 8 allowed.\n");
3254                 return;
3255         }
3256
3257         if (nb_fwd_lcores < res->num_tcs) {
3258                 printf("nb_cores shouldn't be less than number of TCs.\n");
3259                 return;
3260         }
3261         if (!strncmp(res->pfc_en, "on", 2))
3262                 pfc_en = 1;
3263         else
3264                 pfc_en = 0;
3265
3266         /* DCB in VT mode */
3267         if (!strncmp(res->vt_en, "on", 2))
3268                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3269                                 (enum rte_eth_nb_tcs)res->num_tcs,
3270                                 pfc_en);
3271         else
3272                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3273                                 (enum rte_eth_nb_tcs)res->num_tcs,
3274                                 pfc_en);
3275
3276
3277         if (ret != 0) {
3278                 printf("Cannot initialize network ports.\n");
3279                 return;
3280         }
3281
3282         cmd_reconfig_device_queue(port_id, 1, 1);
3283 }
3284
3285 cmdline_parse_token_string_t cmd_config_dcb_port =
3286         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3287 cmdline_parse_token_string_t cmd_config_dcb_config =
3288         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3289 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3290         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3291 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3292         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3293 cmdline_parse_token_string_t cmd_config_dcb_vt =
3294         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3295 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3296         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3297 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3298         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3299 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3300         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3301 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3302         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3303
3304 cmdline_parse_inst_t cmd_config_dcb = {
3305         .f = cmd_config_dcb_parsed,
3306         .data = NULL,
3307         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3308         .tokens = {
3309                 (void *)&cmd_config_dcb_port,
3310                 (void *)&cmd_config_dcb_config,
3311                 (void *)&cmd_config_dcb_port_id,
3312                 (void *)&cmd_config_dcb_dcb,
3313                 (void *)&cmd_config_dcb_vt,
3314                 (void *)&cmd_config_dcb_vt_en,
3315                 (void *)&cmd_config_dcb_num_tcs,
3316                 (void *)&cmd_config_dcb_pfc,
3317                 (void *)&cmd_config_dcb_pfc_en,
3318                 NULL,
3319         },
3320 };
3321
3322 /* *** configure number of packets per burst *** */
3323 struct cmd_config_burst {
3324         cmdline_fixed_string_t port;
3325         cmdline_fixed_string_t keyword;
3326         cmdline_fixed_string_t all;
3327         cmdline_fixed_string_t name;
3328         uint16_t value;
3329 };
3330
3331 static void
3332 cmd_config_burst_parsed(void *parsed_result,
3333                         __rte_unused struct cmdline *cl,
3334                         __rte_unused void *data)
3335 {
3336         struct cmd_config_burst *res = parsed_result;
3337         struct rte_eth_dev_info dev_info;
3338         uint16_t rec_nb_pkts;
3339         int ret;
3340
3341         if (!all_ports_stopped()) {
3342                 printf("Please stop all ports first\n");
3343                 return;
3344         }
3345
3346         if (!strcmp(res->name, "burst")) {
3347                 if (res->value == 0) {
3348                         /* If user gives a value of zero, query the PMD for
3349                          * its recommended Rx burst size. Testpmd uses a single
3350                          * size for all ports, so assume all ports are the same
3351                          * NIC model and use the values from Port 0.
3352                          */
3353                         ret = eth_dev_info_get_print_err(0, &dev_info);
3354                         if (ret != 0)
3355                                 return;
3356
3357                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3358
3359                         if (rec_nb_pkts == 0) {
3360                                 printf("PMD does not recommend a burst size.\n"
3361                                         "User provided value must be between"
3362                                         " 1 and %d\n", MAX_PKT_BURST);
3363                                 return;
3364                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3365                                 printf("PMD recommended burst size of %d"
3366                                         " exceeds maximum value of %d\n",
3367                                         rec_nb_pkts, MAX_PKT_BURST);
3368                                 return;
3369                         }
3370                         printf("Using PMD-provided burst value of %d\n",
3371                                 rec_nb_pkts);
3372                         nb_pkt_per_burst = rec_nb_pkts;
3373                 } else if (res->value > MAX_PKT_BURST) {
3374                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3375                         return;
3376                 } else
3377                         nb_pkt_per_burst = res->value;
3378         } else {
3379                 printf("Unknown parameter\n");
3380                 return;
3381         }
3382
3383         init_port_config();
3384
3385         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3386 }
3387
3388 cmdline_parse_token_string_t cmd_config_burst_port =
3389         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3390 cmdline_parse_token_string_t cmd_config_burst_keyword =
3391         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3392 cmdline_parse_token_string_t cmd_config_burst_all =
3393         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3394 cmdline_parse_token_string_t cmd_config_burst_name =
3395         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3396 cmdline_parse_token_num_t cmd_config_burst_value =
3397         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3398
3399 cmdline_parse_inst_t cmd_config_burst = {
3400         .f = cmd_config_burst_parsed,
3401         .data = NULL,
3402         .help_str = "port config all burst <value>",
3403         .tokens = {
3404                 (void *)&cmd_config_burst_port,
3405                 (void *)&cmd_config_burst_keyword,
3406                 (void *)&cmd_config_burst_all,
3407                 (void *)&cmd_config_burst_name,
3408                 (void *)&cmd_config_burst_value,
3409                 NULL,
3410         },
3411 };
3412
3413 /* *** configure rx/tx queues *** */
3414 struct cmd_config_thresh {
3415         cmdline_fixed_string_t port;
3416         cmdline_fixed_string_t keyword;
3417         cmdline_fixed_string_t all;
3418         cmdline_fixed_string_t name;
3419         uint8_t value;
3420 };
3421
3422 static void
3423 cmd_config_thresh_parsed(void *parsed_result,
3424                         __rte_unused struct cmdline *cl,
3425                         __rte_unused void *data)
3426 {
3427         struct cmd_config_thresh *res = parsed_result;
3428
3429         if (!all_ports_stopped()) {
3430                 printf("Please stop all ports first\n");
3431                 return;
3432         }
3433
3434         if (!strcmp(res->name, "txpt"))
3435                 tx_pthresh = res->value;
3436         else if(!strcmp(res->name, "txht"))
3437                 tx_hthresh = res->value;
3438         else if(!strcmp(res->name, "txwt"))
3439                 tx_wthresh = res->value;
3440         else if(!strcmp(res->name, "rxpt"))
3441                 rx_pthresh = res->value;
3442         else if(!strcmp(res->name, "rxht"))
3443                 rx_hthresh = res->value;
3444         else if(!strcmp(res->name, "rxwt"))
3445                 rx_wthresh = res->value;
3446         else {
3447                 printf("Unknown parameter\n");
3448                 return;
3449         }
3450
3451         init_port_config();
3452
3453         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3454 }
3455
3456 cmdline_parse_token_string_t cmd_config_thresh_port =
3457         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3458 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3459         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3460 cmdline_parse_token_string_t cmd_config_thresh_all =
3461         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3462 cmdline_parse_token_string_t cmd_config_thresh_name =
3463         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3464                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3465 cmdline_parse_token_num_t cmd_config_thresh_value =
3466         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3467
3468 cmdline_parse_inst_t cmd_config_thresh = {
3469         .f = cmd_config_thresh_parsed,
3470         .data = NULL,
3471         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3472         .tokens = {
3473                 (void *)&cmd_config_thresh_port,
3474                 (void *)&cmd_config_thresh_keyword,
3475                 (void *)&cmd_config_thresh_all,
3476                 (void *)&cmd_config_thresh_name,
3477                 (void *)&cmd_config_thresh_value,
3478                 NULL,
3479         },
3480 };
3481
3482 /* *** configure free/rs threshold *** */
3483 struct cmd_config_threshold {
3484         cmdline_fixed_string_t port;
3485         cmdline_fixed_string_t keyword;
3486         cmdline_fixed_string_t all;
3487         cmdline_fixed_string_t name;
3488         uint16_t value;
3489 };
3490
3491 static void
3492 cmd_config_threshold_parsed(void *parsed_result,
3493                         __rte_unused struct cmdline *cl,
3494                         __rte_unused void *data)
3495 {
3496         struct cmd_config_threshold *res = parsed_result;
3497
3498         if (!all_ports_stopped()) {
3499                 printf("Please stop all ports first\n");
3500                 return;
3501         }
3502
3503         if (!strcmp(res->name, "txfreet"))
3504                 tx_free_thresh = res->value;
3505         else if (!strcmp(res->name, "txrst"))
3506                 tx_rs_thresh = res->value;
3507         else if (!strcmp(res->name, "rxfreet"))
3508                 rx_free_thresh = res->value;
3509         else {
3510                 printf("Unknown parameter\n");
3511                 return;
3512         }
3513
3514         init_port_config();
3515
3516         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3517 }
3518
3519 cmdline_parse_token_string_t cmd_config_threshold_port =
3520         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3521 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3522         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3523                                                                 "config");
3524 cmdline_parse_token_string_t cmd_config_threshold_all =
3525         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3526 cmdline_parse_token_string_t cmd_config_threshold_name =
3527         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3528                                                 "txfreet#txrst#rxfreet");
3529 cmdline_parse_token_num_t cmd_config_threshold_value =
3530         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3531
3532 cmdline_parse_inst_t cmd_config_threshold = {
3533         .f = cmd_config_threshold_parsed,
3534         .data = NULL,
3535         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3536         .tokens = {
3537                 (void *)&cmd_config_threshold_port,
3538                 (void *)&cmd_config_threshold_keyword,
3539                 (void *)&cmd_config_threshold_all,
3540                 (void *)&cmd_config_threshold_name,
3541                 (void *)&cmd_config_threshold_value,
3542                 NULL,
3543         },
3544 };
3545
3546 /* *** stop *** */
3547 struct cmd_stop_result {
3548         cmdline_fixed_string_t stop;
3549 };
3550
3551 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3552                             __rte_unused struct cmdline *cl,
3553                             __rte_unused void *data)
3554 {
3555         stop_packet_forwarding();
3556 }
3557
3558 cmdline_parse_token_string_t cmd_stop_stop =
3559         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3560
3561 cmdline_parse_inst_t cmd_stop = {
3562         .f = cmd_stop_parsed,
3563         .data = NULL,
3564         .help_str = "stop: Stop packet forwarding",
3565         .tokens = {
3566                 (void *)&cmd_stop_stop,
3567                 NULL,
3568         },
3569 };
3570
3571 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3572
3573 unsigned int
3574 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3575                 unsigned int *parsed_items, int check_unique_values)
3576 {
3577         unsigned int nb_item;
3578         unsigned int value;
3579         unsigned int i;
3580         unsigned int j;
3581         int value_ok;
3582         char c;
3583
3584         /*
3585          * First parse all items in the list and store their value.
3586          */
3587         value = 0;
3588         nb_item = 0;
3589         value_ok = 0;
3590         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3591                 c = str[i];
3592                 if ((c >= '0') && (c <= '9')) {
3593                         value = (unsigned int) (value * 10 + (c - '0'));
3594                         value_ok = 1;
3595                         continue;
3596                 }
3597                 if (c != ',') {
3598                         printf("character %c is not a decimal digit\n", c);
3599                         return 0;
3600                 }
3601                 if (! value_ok) {
3602                         printf("No valid value before comma\n");
3603                         return 0;
3604                 }
3605                 if (nb_item < max_items) {
3606                         parsed_items[nb_item] = value;
3607                         value_ok = 0;
3608                         value = 0;
3609                 }
3610                 nb_item++;
3611         }
3612         if (nb_item >= max_items) {
3613                 printf("Number of %s = %u > %u (maximum items)\n",
3614                        item_name, nb_item + 1, max_items);
3615                 return 0;
3616         }
3617         parsed_items[nb_item++] = value;
3618         if (! check_unique_values)
3619                 return nb_item;
3620
3621         /*
3622          * Then, check that all values in the list are differents.
3623          * No optimization here...
3624          */
3625         for (i = 0; i < nb_item; i++) {
3626                 for (j = i + 1; j < nb_item; j++) {
3627                         if (parsed_items[j] == parsed_items[i]) {
3628                                 printf("duplicated %s %u at index %u and %u\n",
3629                                        item_name, parsed_items[i], i, j);
3630                                 return 0;
3631                         }
3632                 }
3633         }
3634         return nb_item;
3635 }
3636
3637 struct cmd_set_list_result {
3638         cmdline_fixed_string_t cmd_keyword;
3639         cmdline_fixed_string_t list_name;
3640         cmdline_fixed_string_t list_of_items;
3641 };
3642
3643 static void cmd_set_list_parsed(void *parsed_result,
3644                                 __rte_unused struct cmdline *cl,
3645                                 __rte_unused void *data)
3646 {
3647         struct cmd_set_list_result *res;
3648         union {
3649                 unsigned int lcorelist[RTE_MAX_LCORE];
3650                 unsigned int portlist[RTE_MAX_ETHPORTS];
3651         } parsed_items;
3652         unsigned int nb_item;
3653
3654         if (test_done == 0) {
3655                 printf("Please stop forwarding first\n");
3656                 return;
3657         }
3658
3659         res = parsed_result;
3660         if (!strcmp(res->list_name, "corelist")) {
3661                 nb_item = parse_item_list(res->list_of_items, "core",
3662                                           RTE_MAX_LCORE,
3663                                           parsed_items.lcorelist, 1);
3664                 if (nb_item > 0) {
3665                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3666                         fwd_config_setup();
3667                 }
3668                 return;
3669         }
3670         if (!strcmp(res->list_name, "portlist")) {
3671                 nb_item = parse_item_list(res->list_of_items, "port",
3672                                           RTE_MAX_ETHPORTS,
3673                                           parsed_items.portlist, 1);
3674                 if (nb_item > 0) {
3675                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3676                         fwd_config_setup();
3677                 }
3678         }
3679 }
3680
3681 cmdline_parse_token_string_t cmd_set_list_keyword =
3682         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3683                                  "set");
3684 cmdline_parse_token_string_t cmd_set_list_name =
3685         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3686                                  "corelist#portlist");
3687 cmdline_parse_token_string_t cmd_set_list_of_items =
3688         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3689                                  NULL);
3690
3691 cmdline_parse_inst_t cmd_set_fwd_list = {
3692         .f = cmd_set_list_parsed,
3693         .data = NULL,
3694         .help_str = "set corelist|portlist <list0[,list1]*>",
3695         .tokens = {
3696                 (void *)&cmd_set_list_keyword,
3697                 (void *)&cmd_set_list_name,
3698                 (void *)&cmd_set_list_of_items,
3699                 NULL,
3700         },
3701 };
3702
3703 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3704
3705 struct cmd_setmask_result {
3706         cmdline_fixed_string_t set;
3707         cmdline_fixed_string_t mask;
3708         uint64_t hexavalue;
3709 };
3710
3711 static void cmd_set_mask_parsed(void *parsed_result,
3712                                 __rte_unused struct cmdline *cl,
3713                                 __rte_unused void *data)
3714 {
3715         struct cmd_setmask_result *res = parsed_result;
3716
3717         if (test_done == 0) {
3718                 printf("Please stop forwarding first\n");
3719                 return;
3720         }
3721         if (!strcmp(res->mask, "coremask")) {
3722                 set_fwd_lcores_mask(res->hexavalue);
3723                 fwd_config_setup();
3724         } else if (!strcmp(res->mask, "portmask")) {
3725                 set_fwd_ports_mask(res->hexavalue);
3726                 fwd_config_setup();
3727         }
3728 }
3729
3730 cmdline_parse_token_string_t cmd_setmask_set =
3731         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3732 cmdline_parse_token_string_t cmd_setmask_mask =
3733         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3734                                  "coremask#portmask");
3735 cmdline_parse_token_num_t cmd_setmask_value =
3736         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3737
3738 cmdline_parse_inst_t cmd_set_fwd_mask = {
3739         .f = cmd_set_mask_parsed,
3740         .data = NULL,
3741         .help_str = "set coremask|portmask <hexadecimal value>",
3742         .tokens = {
3743                 (void *)&cmd_setmask_set,
3744                 (void *)&cmd_setmask_mask,
3745                 (void *)&cmd_setmask_value,
3746                 NULL,
3747         },
3748 };
3749
3750 /*
3751  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3752  */
3753 struct cmd_set_result {
3754         cmdline_fixed_string_t set;
3755         cmdline_fixed_string_t what;
3756         uint16_t value;
3757 };
3758
3759 static void cmd_set_parsed(void *parsed_result,
3760                            __rte_unused struct cmdline *cl,
3761                            __rte_unused void *data)
3762 {
3763         struct cmd_set_result *res = parsed_result;
3764         if (!strcmp(res->what, "nbport")) {
3765                 set_fwd_ports_number(res->value);
3766                 fwd_config_setup();
3767         } else if (!strcmp(res->what, "nbcore")) {
3768                 set_fwd_lcores_number(res->value);
3769                 fwd_config_setup();
3770         } else if (!strcmp(res->what, "burst"))
3771                 set_nb_pkt_per_burst(res->value);
3772         else if (!strcmp(res->what, "verbose"))
3773                 set_verbose_level(res->value);
3774 }
3775
3776 cmdline_parse_token_string_t cmd_set_set =
3777         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3778 cmdline_parse_token_string_t cmd_set_what =
3779         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3780                                  "nbport#nbcore#burst#verbose");
3781 cmdline_parse_token_num_t cmd_set_value =
3782         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3783
3784 cmdline_parse_inst_t cmd_set_numbers = {
3785         .f = cmd_set_parsed,
3786         .data = NULL,
3787         .help_str = "set nbport|nbcore|burst|verbose <value>",
3788         .tokens = {
3789                 (void *)&cmd_set_set,
3790                 (void *)&cmd_set_what,
3791                 (void *)&cmd_set_value,
3792                 NULL,
3793         },
3794 };
3795
3796 /* *** SET LOG LEVEL CONFIGURATION *** */
3797
3798 struct cmd_set_log_result {
3799         cmdline_fixed_string_t set;
3800         cmdline_fixed_string_t log;
3801         cmdline_fixed_string_t type;
3802         uint32_t level;
3803 };
3804
3805 static void
3806 cmd_set_log_parsed(void *parsed_result,
3807                    __rte_unused struct cmdline *cl,
3808                    __rte_unused void *data)
3809 {
3810         struct cmd_set_log_result *res;
3811         int ret;
3812
3813         res = parsed_result;
3814         if (!strcmp(res->type, "global"))
3815                 rte_log_set_global_level(res->level);
3816         else {
3817                 ret = rte_log_set_level_regexp(res->type, res->level);
3818                 if (ret < 0)
3819                         printf("Unable to set log level\n");
3820         }
3821 }
3822
3823 cmdline_parse_token_string_t cmd_set_log_set =
3824         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3825 cmdline_parse_token_string_t cmd_set_log_log =
3826         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3827 cmdline_parse_token_string_t cmd_set_log_type =
3828         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3829 cmdline_parse_token_num_t cmd_set_log_level =
3830         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3831
3832 cmdline_parse_inst_t cmd_set_log = {
3833         .f = cmd_set_log_parsed,
3834         .data = NULL,
3835         .help_str = "set log global|<type> <level>",
3836         .tokens = {
3837                 (void *)&cmd_set_log_set,
3838                 (void *)&cmd_set_log_log,
3839                 (void *)&cmd_set_log_type,
3840                 (void *)&cmd_set_log_level,
3841                 NULL,
3842         },
3843 };
3844
3845 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3846
3847 struct cmd_set_rxoffs_result {
3848         cmdline_fixed_string_t cmd_keyword;
3849         cmdline_fixed_string_t rxoffs;
3850         cmdline_fixed_string_t seg_offsets;
3851 };
3852
3853 static void
3854 cmd_set_rxoffs_parsed(void *parsed_result,
3855                       __rte_unused struct cmdline *cl,
3856                       __rte_unused void *data)
3857 {
3858         struct cmd_set_rxoffs_result *res;
3859         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3860         unsigned int nb_segs;
3861
3862         res = parsed_result;
3863         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3864                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3865         if (nb_segs > 0)
3866                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3867 }
3868
3869 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3870         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3871                                  cmd_keyword, "set");
3872 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3873         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3874                                  rxoffs, "rxoffs");
3875 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3876         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3877                                  seg_offsets, NULL);
3878
3879 cmdline_parse_inst_t cmd_set_rxoffs = {
3880         .f = cmd_set_rxoffs_parsed,
3881         .data = NULL,
3882         .help_str = "set rxoffs <len0[,len1]*>",
3883         .tokens = {
3884                 (void *)&cmd_set_rxoffs_keyword,
3885                 (void *)&cmd_set_rxoffs_name,
3886                 (void *)&cmd_set_rxoffs_offsets,
3887                 NULL,
3888         },
3889 };
3890
3891 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3892
3893 struct cmd_set_rxpkts_result {
3894         cmdline_fixed_string_t cmd_keyword;
3895         cmdline_fixed_string_t rxpkts;
3896         cmdline_fixed_string_t seg_lengths;
3897 };
3898
3899 static void
3900 cmd_set_rxpkts_parsed(void *parsed_result,
3901                       __rte_unused struct cmdline *cl,
3902                       __rte_unused void *data)
3903 {
3904         struct cmd_set_rxpkts_result *res;
3905         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3906         unsigned int nb_segs;
3907
3908         res = parsed_result;
3909         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3910                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3911         if (nb_segs > 0)
3912                 set_rx_pkt_segments(seg_lengths, nb_segs);
3913 }
3914
3915 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3916         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3917                                  cmd_keyword, "set");
3918 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3919         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3920                                  rxpkts, "rxpkts");
3921 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3922         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3923                                  seg_lengths, NULL);
3924
3925 cmdline_parse_inst_t cmd_set_rxpkts = {
3926         .f = cmd_set_rxpkts_parsed,
3927         .data = NULL,
3928         .help_str = "set rxpkts <len0[,len1]*>",
3929         .tokens = {
3930                 (void *)&cmd_set_rxpkts_keyword,
3931                 (void *)&cmd_set_rxpkts_name,
3932                 (void *)&cmd_set_rxpkts_lengths,
3933                 NULL,
3934         },
3935 };
3936
3937 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3938
3939 struct cmd_set_txpkts_result {
3940         cmdline_fixed_string_t cmd_keyword;
3941         cmdline_fixed_string_t txpkts;
3942         cmdline_fixed_string_t seg_lengths;
3943 };
3944
3945 static void
3946 cmd_set_txpkts_parsed(void *parsed_result,
3947                       __rte_unused struct cmdline *cl,
3948                       __rte_unused void *data)
3949 {
3950         struct cmd_set_txpkts_result *res;
3951         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3952         unsigned int nb_segs;
3953
3954         res = parsed_result;
3955         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3956                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3957         if (nb_segs > 0)
3958                 set_tx_pkt_segments(seg_lengths, nb_segs);
3959 }
3960
3961 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3962         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3963                                  cmd_keyword, "set");
3964 cmdline_parse_token_string_t cmd_set_txpkts_name =
3965         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3966                                  txpkts, "txpkts");
3967 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3968         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3969                                  seg_lengths, NULL);
3970
3971 cmdline_parse_inst_t cmd_set_txpkts = {
3972         .f = cmd_set_txpkts_parsed,
3973         .data = NULL,
3974         .help_str = "set txpkts <len0[,len1]*>",
3975         .tokens = {
3976                 (void *)&cmd_set_txpkts_keyword,
3977                 (void *)&cmd_set_txpkts_name,
3978                 (void *)&cmd_set_txpkts_lengths,
3979                 NULL,
3980         },
3981 };
3982
3983 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3984
3985 struct cmd_set_txsplit_result {
3986         cmdline_fixed_string_t cmd_keyword;
3987         cmdline_fixed_string_t txsplit;
3988         cmdline_fixed_string_t mode;
3989 };
3990
3991 static void
3992 cmd_set_txsplit_parsed(void *parsed_result,
3993                       __rte_unused struct cmdline *cl,
3994                       __rte_unused void *data)
3995 {
3996         struct cmd_set_txsplit_result *res;
3997
3998         res = parsed_result;
3999         set_tx_pkt_split(res->mode);
4000 }
4001
4002 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4003         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4004                                  cmd_keyword, "set");
4005 cmdline_parse_token_string_t cmd_set_txsplit_name =
4006         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4007                                  txsplit, "txsplit");
4008 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4009         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4010                                  mode, NULL);
4011
4012 cmdline_parse_inst_t cmd_set_txsplit = {
4013         .f = cmd_set_txsplit_parsed,
4014         .data = NULL,
4015         .help_str = "set txsplit on|off|rand",
4016         .tokens = {
4017                 (void *)&cmd_set_txsplit_keyword,
4018                 (void *)&cmd_set_txsplit_name,
4019                 (void *)&cmd_set_txsplit_mode,
4020                 NULL,
4021         },
4022 };
4023
4024 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4025
4026 struct cmd_set_txtimes_result {
4027         cmdline_fixed_string_t cmd_keyword;
4028         cmdline_fixed_string_t txtimes;
4029         cmdline_fixed_string_t tx_times;
4030 };
4031
4032 static void
4033 cmd_set_txtimes_parsed(void *parsed_result,
4034                        __rte_unused struct cmdline *cl,
4035                        __rte_unused void *data)
4036 {
4037         struct cmd_set_txtimes_result *res;
4038         unsigned int tx_times[2] = {0, 0};
4039         unsigned int n_times;
4040
4041         res = parsed_result;
4042         n_times = parse_item_list(res->tx_times, "tx times",
4043                                   2, tx_times, 0);
4044         if (n_times == 2)
4045                 set_tx_pkt_times(tx_times);
4046 }
4047
4048 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4049         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4050                                  cmd_keyword, "set");
4051 cmdline_parse_token_string_t cmd_set_txtimes_name =
4052         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4053                                  txtimes, "txtimes");
4054 cmdline_parse_token_string_t cmd_set_txtimes_value =
4055         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4056                                  tx_times, NULL);
4057
4058 cmdline_parse_inst_t cmd_set_txtimes = {
4059         .f = cmd_set_txtimes_parsed,
4060         .data = NULL,
4061         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4062         .tokens = {
4063                 (void *)&cmd_set_txtimes_keyword,
4064                 (void *)&cmd_set_txtimes_name,
4065                 (void *)&cmd_set_txtimes_value,
4066                 NULL,
4067         },
4068 };
4069
4070 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4071 struct cmd_rx_vlan_filter_all_result {
4072         cmdline_fixed_string_t rx_vlan;
4073         cmdline_fixed_string_t what;
4074         cmdline_fixed_string_t all;
4075         portid_t port_id;
4076 };
4077
4078 static void
4079 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4080                               __rte_unused struct cmdline *cl,
4081                               __rte_unused void *data)
4082 {
4083         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4084
4085         if (!strcmp(res->what, "add"))
4086                 rx_vlan_all_filter_set(res->port_id, 1);
4087         else
4088                 rx_vlan_all_filter_set(res->port_id, 0);
4089 }
4090
4091 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4092         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4093                                  rx_vlan, "rx_vlan");
4094 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4095         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4096                                  what, "add#rm");
4097 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4098         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4099                                  all, "all");
4100 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4101         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4102                               port_id, UINT16);
4103
4104 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4105         .f = cmd_rx_vlan_filter_all_parsed,
4106         .data = NULL,
4107         .help_str = "rx_vlan add|rm all <port_id>: "
4108                 "Add/Remove all identifiers to/from the set of VLAN "
4109                 "identifiers filtered by a port",
4110         .tokens = {
4111                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4112                 (void *)&cmd_rx_vlan_filter_all_what,
4113                 (void *)&cmd_rx_vlan_filter_all_all,
4114                 (void *)&cmd_rx_vlan_filter_all_portid,
4115                 NULL,
4116         },
4117 };
4118
4119 /* *** VLAN OFFLOAD SET ON A PORT *** */
4120 struct cmd_vlan_offload_result {
4121         cmdline_fixed_string_t vlan;
4122         cmdline_fixed_string_t set;
4123         cmdline_fixed_string_t vlan_type;
4124         cmdline_fixed_string_t what;
4125         cmdline_fixed_string_t on;
4126         cmdline_fixed_string_t port_id;
4127 };
4128
4129 static void
4130 cmd_vlan_offload_parsed(void *parsed_result,
4131                           __rte_unused struct cmdline *cl,
4132                           __rte_unused void *data)
4133 {
4134         int on;
4135         struct cmd_vlan_offload_result *res = parsed_result;
4136         char *str;
4137         int i, len = 0;
4138         portid_t port_id = 0;
4139         unsigned int tmp;
4140
4141         str = res->port_id;
4142         len = strnlen(str, STR_TOKEN_SIZE);
4143         i = 0;
4144         /* Get port_id first */
4145         while(i < len){
4146                 if(str[i] == ',')
4147                         break;
4148
4149                 i++;
4150         }
4151         str[i]='\0';
4152         tmp = strtoul(str, NULL, 0);
4153         /* If port_id greater that what portid_t can represent, return */
4154         if(tmp >= RTE_MAX_ETHPORTS)
4155                 return;
4156         port_id = (portid_t)tmp;
4157
4158         if (!strcmp(res->on, "on"))
4159                 on = 1;
4160         else
4161                 on = 0;
4162
4163         if (!strcmp(res->what, "strip"))
4164                 rx_vlan_strip_set(port_id,  on);
4165         else if(!strcmp(res->what, "stripq")){
4166                 uint16_t queue_id = 0;
4167
4168                 /* No queue_id, return */
4169                 if(i + 1 >= len) {
4170                         printf("must specify (port,queue_id)\n");
4171                         return;
4172                 }
4173                 tmp = strtoul(str + i + 1, NULL, 0);
4174                 /* If queue_id greater that what 16-bits can represent, return */
4175                 if(tmp > 0xffff)
4176                         return;
4177
4178                 queue_id = (uint16_t)tmp;
4179                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4180         }
4181         else if (!strcmp(res->what, "filter"))
4182                 rx_vlan_filter_set(port_id, on);
4183         else if (!strcmp(res->what, "qinq_strip"))
4184                 rx_vlan_qinq_strip_set(port_id, on);
4185         else
4186                 vlan_extend_set(port_id, on);
4187
4188         return;
4189 }
4190
4191 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4192         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4193                                  vlan, "vlan");
4194 cmdline_parse_token_string_t cmd_vlan_offload_set =
4195         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4196                                  set, "set");
4197 cmdline_parse_token_string_t cmd_vlan_offload_what =
4198         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4199                                 what, "strip#filter#qinq_strip#extend#stripq");
4200 cmdline_parse_token_string_t cmd_vlan_offload_on =
4201         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4202                               on, "on#off");
4203 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4204         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4205                               port_id, NULL);
4206
4207 cmdline_parse_inst_t cmd_vlan_offload = {
4208         .f = cmd_vlan_offload_parsed,
4209         .data = NULL,
4210         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4211                 "<port_id[,queue_id]>: "
4212                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4213         .tokens = {
4214                 (void *)&cmd_vlan_offload_vlan,
4215                 (void *)&cmd_vlan_offload_set,
4216                 (void *)&cmd_vlan_offload_what,
4217                 (void *)&cmd_vlan_offload_on,
4218                 (void *)&cmd_vlan_offload_portid,
4219                 NULL,
4220         },
4221 };
4222
4223 /* *** VLAN TPID SET ON A PORT *** */
4224 struct cmd_vlan_tpid_result {
4225         cmdline_fixed_string_t vlan;
4226         cmdline_fixed_string_t set;
4227         cmdline_fixed_string_t vlan_type;
4228         cmdline_fixed_string_t what;
4229         uint16_t tp_id;
4230         portid_t port_id;
4231 };
4232
4233 static void
4234 cmd_vlan_tpid_parsed(void *parsed_result,
4235                           __rte_unused struct cmdline *cl,
4236                           __rte_unused void *data)
4237 {
4238         struct cmd_vlan_tpid_result *res = parsed_result;
4239         enum rte_vlan_type vlan_type;
4240
4241         if (!strcmp(res->vlan_type, "inner"))
4242                 vlan_type = ETH_VLAN_TYPE_INNER;
4243         else if (!strcmp(res->vlan_type, "outer"))
4244                 vlan_type = ETH_VLAN_TYPE_OUTER;
4245         else {
4246                 printf("Unknown vlan type\n");
4247                 return;
4248         }
4249         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4250 }
4251
4252 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4253         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4254                                  vlan, "vlan");
4255 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4256         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4257                                  set, "set");
4258 cmdline_parse_token_string_t cmd_vlan_type =
4259         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4260                                  vlan_type, "inner#outer");
4261 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4262         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4263                                  what, "tpid");
4264 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4265         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4266                               tp_id, UINT16);
4267 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4268         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4269                               port_id, UINT16);
4270
4271 cmdline_parse_inst_t cmd_vlan_tpid = {
4272         .f = cmd_vlan_tpid_parsed,
4273         .data = NULL,
4274         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4275                 "Set the VLAN Ether type",
4276         .tokens = {
4277                 (void *)&cmd_vlan_tpid_vlan,
4278                 (void *)&cmd_vlan_tpid_set,
4279                 (void *)&cmd_vlan_type,
4280                 (void *)&cmd_vlan_tpid_what,
4281                 (void *)&cmd_vlan_tpid_tpid,
4282                 (void *)&cmd_vlan_tpid_portid,
4283                 NULL,
4284         },
4285 };
4286
4287 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4288 struct cmd_rx_vlan_filter_result {
4289         cmdline_fixed_string_t rx_vlan;
4290         cmdline_fixed_string_t what;
4291         uint16_t vlan_id;
4292         portid_t port_id;
4293 };
4294
4295 static void
4296 cmd_rx_vlan_filter_parsed(void *parsed_result,
4297                           __rte_unused struct cmdline *cl,
4298                           __rte_unused void *data)
4299 {
4300         struct cmd_rx_vlan_filter_result *res = parsed_result;
4301
4302         if (!strcmp(res->what, "add"))
4303                 rx_vft_set(res->port_id, res->vlan_id, 1);
4304         else
4305                 rx_vft_set(res->port_id, res->vlan_id, 0);
4306 }
4307
4308 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4309         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4310                                  rx_vlan, "rx_vlan");
4311 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4312         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4313                                  what, "add#rm");
4314 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4315         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4316                               vlan_id, UINT16);
4317 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4318         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4319                               port_id, UINT16);
4320
4321 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4322         .f = cmd_rx_vlan_filter_parsed,
4323         .data = NULL,
4324         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4325                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4326                 "identifiers filtered by a port",
4327         .tokens = {
4328                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4329                 (void *)&cmd_rx_vlan_filter_what,
4330                 (void *)&cmd_rx_vlan_filter_vlanid,
4331                 (void *)&cmd_rx_vlan_filter_portid,
4332                 NULL,
4333         },
4334 };
4335
4336 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4337 struct cmd_tx_vlan_set_result {
4338         cmdline_fixed_string_t tx_vlan;
4339         cmdline_fixed_string_t set;
4340         portid_t port_id;
4341         uint16_t vlan_id;
4342 };
4343
4344 static void
4345 cmd_tx_vlan_set_parsed(void *parsed_result,
4346                        __rte_unused struct cmdline *cl,
4347                        __rte_unused void *data)
4348 {
4349         struct cmd_tx_vlan_set_result *res = parsed_result;
4350
4351         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4352                 return;
4353
4354         if (!port_is_stopped(res->port_id)) {
4355                 printf("Please stop port %d first\n", res->port_id);
4356                 return;
4357         }
4358
4359         tx_vlan_set(res->port_id, res->vlan_id);
4360
4361         cmd_reconfig_device_queue(res->port_id, 1, 1);
4362 }
4363
4364 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4365         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4366                                  tx_vlan, "tx_vlan");
4367 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4368         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4369                                  set, "set");
4370 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4371         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4372                               port_id, UINT16);
4373 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4374         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4375                               vlan_id, UINT16);
4376
4377 cmdline_parse_inst_t cmd_tx_vlan_set = {
4378         .f = cmd_tx_vlan_set_parsed,
4379         .data = NULL,
4380         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4381                 "Enable hardware insertion of a single VLAN header "
4382                 "with a given TAG Identifier in packets sent on a port",
4383         .tokens = {
4384                 (void *)&cmd_tx_vlan_set_tx_vlan,
4385                 (void *)&cmd_tx_vlan_set_set,
4386                 (void *)&cmd_tx_vlan_set_portid,
4387                 (void *)&cmd_tx_vlan_set_vlanid,
4388                 NULL,
4389         },
4390 };
4391
4392 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4393 struct cmd_tx_vlan_set_qinq_result {
4394         cmdline_fixed_string_t tx_vlan;
4395         cmdline_fixed_string_t set;
4396         portid_t port_id;
4397         uint16_t vlan_id;
4398         uint16_t vlan_id_outer;
4399 };
4400
4401 static void
4402 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4403                             __rte_unused struct cmdline *cl,
4404                             __rte_unused void *data)
4405 {
4406         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4407
4408         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4409                 return;
4410
4411         if (!port_is_stopped(res->port_id)) {
4412                 printf("Please stop port %d first\n", res->port_id);
4413                 return;
4414         }
4415
4416         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4417
4418         cmd_reconfig_device_queue(res->port_id, 1, 1);
4419 }
4420
4421 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4422         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4423                 tx_vlan, "tx_vlan");
4424 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4425         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4426                 set, "set");
4427 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4428         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4429                 port_id, UINT16);
4430 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4431         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4432                 vlan_id, UINT16);
4433 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4434         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4435                 vlan_id_outer, UINT16);
4436
4437 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4438         .f = cmd_tx_vlan_set_qinq_parsed,
4439         .data = NULL,
4440         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4441                 "Enable hardware insertion of double VLAN header "
4442                 "with given TAG Identifiers in packets sent on a port",
4443         .tokens = {
4444                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4445                 (void *)&cmd_tx_vlan_set_qinq_set,
4446                 (void *)&cmd_tx_vlan_set_qinq_portid,
4447                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4448                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4449                 NULL,
4450         },
4451 };
4452
4453 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4454 struct cmd_tx_vlan_set_pvid_result {
4455         cmdline_fixed_string_t tx_vlan;
4456         cmdline_fixed_string_t set;
4457         cmdline_fixed_string_t pvid;
4458         portid_t port_id;
4459         uint16_t vlan_id;
4460         cmdline_fixed_string_t mode;
4461 };
4462
4463 static void
4464 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4465                             __rte_unused struct cmdline *cl,
4466                             __rte_unused void *data)
4467 {
4468         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4469
4470         if (strcmp(res->mode, "on") == 0)
4471                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4472         else
4473                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4474 }
4475
4476 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4477         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4478                                  tx_vlan, "tx_vlan");
4479 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4480         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4481                                  set, "set");
4482 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4483         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4484                                  pvid, "pvid");
4485 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4486         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4487                              port_id, UINT16);
4488 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4489         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4490                               vlan_id, UINT16);
4491 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4492         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4493                                  mode, "on#off");
4494
4495 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4496         .f = cmd_tx_vlan_set_pvid_parsed,
4497         .data = NULL,
4498         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4499         .tokens = {
4500                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4501                 (void *)&cmd_tx_vlan_set_pvid_set,
4502                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4503                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4504                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4505                 (void *)&cmd_tx_vlan_set_pvid_mode,
4506                 NULL,
4507         },
4508 };
4509
4510 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4511 struct cmd_tx_vlan_reset_result {
4512         cmdline_fixed_string_t tx_vlan;
4513         cmdline_fixed_string_t reset;
4514         portid_t port_id;
4515 };
4516
4517 static void
4518 cmd_tx_vlan_reset_parsed(void *parsed_result,
4519                          __rte_unused struct cmdline *cl,
4520                          __rte_unused void *data)
4521 {
4522         struct cmd_tx_vlan_reset_result *res = parsed_result;
4523
4524         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4525                 return;
4526
4527         if (!port_is_stopped(res->port_id)) {
4528                 printf("Please stop port %d first\n", res->port_id);
4529                 return;
4530         }
4531
4532         tx_vlan_reset(res->port_id);
4533
4534         cmd_reconfig_device_queue(res->port_id, 1, 1);
4535 }
4536
4537 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4538         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4539                                  tx_vlan, "tx_vlan");
4540 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4541         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4542                                  reset, "reset");
4543 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4544         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4545                               port_id, UINT16);
4546
4547 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4548         .f = cmd_tx_vlan_reset_parsed,
4549         .data = NULL,
4550         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4551                 "VLAN header in packets sent on a port",
4552         .tokens = {
4553                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4554                 (void *)&cmd_tx_vlan_reset_reset,
4555                 (void *)&cmd_tx_vlan_reset_portid,
4556                 NULL,
4557         },
4558 };
4559
4560
4561 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4562 struct cmd_csum_result {
4563         cmdline_fixed_string_t csum;
4564         cmdline_fixed_string_t mode;
4565         cmdline_fixed_string_t proto;
4566         cmdline_fixed_string_t hwsw;
4567         portid_t port_id;
4568 };
4569
4570 static void
4571 csum_show(int port_id)
4572 {
4573         struct rte_eth_dev_info dev_info;
4574         uint64_t tx_offloads;
4575         int ret;
4576
4577         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4578         printf("Parse tunnel is %s\n",
4579                 (ports[port_id].parse_tunnel) ? "on" : "off");
4580         printf("IP checksum offload is %s\n",
4581                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4582         printf("UDP checksum offload is %s\n",
4583                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4584         printf("TCP checksum offload is %s\n",
4585                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4586         printf("SCTP checksum offload is %s\n",
4587                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4588         printf("Outer-Ip checksum offload is %s\n",
4589                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4590         printf("Outer-Udp checksum offload is %s\n",
4591                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4592
4593         /* display warnings if configuration is not supported by the NIC */
4594         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4595         if (ret != 0)
4596                 return;
4597
4598         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4599                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4600                 printf("Warning: hardware IP checksum enabled but not "
4601                         "supported by port %d\n", port_id);
4602         }
4603         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4604                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4605                 printf("Warning: hardware UDP checksum enabled but not "
4606                         "supported by port %d\n", port_id);
4607         }
4608         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4609                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4610                 printf("Warning: hardware TCP checksum enabled but not "
4611                         "supported by port %d\n", port_id);
4612         }
4613         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4614                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4615                 printf("Warning: hardware SCTP checksum enabled but not "
4616                         "supported by port %d\n", port_id);
4617         }
4618         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4619                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4620                 printf("Warning: hardware outer IP checksum enabled but not "
4621                         "supported by port %d\n", port_id);
4622         }
4623         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4624                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4625                         == 0) {
4626                 printf("Warning: hardware outer UDP checksum enabled but not "
4627                         "supported by port %d\n", port_id);
4628         }
4629 }
4630
4631 static void
4632 cmd_config_queue_tx_offloads(struct rte_port *port)
4633 {
4634         int k;
4635
4636         /* Apply queue tx offloads configuration */
4637         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4638                 port->tx_conf[k].offloads =
4639                         port->dev_conf.txmode.offloads;
4640 }
4641
4642 static void
4643 cmd_csum_parsed(void *parsed_result,
4644                        __rte_unused struct cmdline *cl,
4645                        __rte_unused void *data)
4646 {
4647         struct cmd_csum_result *res = parsed_result;
4648         int hw = 0;
4649         uint64_t csum_offloads = 0;
4650         struct rte_eth_dev_info dev_info;
4651         int ret;
4652
4653         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4654                 printf("invalid port %d\n", res->port_id);
4655                 return;
4656         }
4657         if (!port_is_stopped(res->port_id)) {
4658                 printf("Please stop port %d first\n", res->port_id);
4659                 return;
4660         }
4661
4662         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4663         if (ret != 0)
4664                 return;
4665
4666         if (!strcmp(res->mode, "set")) {
4667
4668                 if (!strcmp(res->hwsw, "hw"))
4669                         hw = 1;
4670
4671                 if (!strcmp(res->proto, "ip")) {
4672                         if (hw == 0 || (dev_info.tx_offload_capa &
4673                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4674                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4675                         } else {
4676                                 printf("IP checksum offload is not supported "
4677                                        "by port %u\n", res->port_id);
4678                         }
4679                 } else if (!strcmp(res->proto, "udp")) {
4680                         if (hw == 0 || (dev_info.tx_offload_capa &
4681                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4682                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4683                         } else {
4684                                 printf("UDP checksum offload is not supported "
4685                                        "by port %u\n", res->port_id);
4686                         }
4687                 } else if (!strcmp(res->proto, "tcp")) {
4688                         if (hw == 0 || (dev_info.tx_offload_capa &
4689                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4690                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4691                         } else {
4692                                 printf("TCP checksum offload is not supported "
4693                                        "by port %u\n", res->port_id);
4694                         }
4695                 } else if (!strcmp(res->proto, "sctp")) {
4696                         if (hw == 0 || (dev_info.tx_offload_capa &
4697                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4698                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4699                         } else {
4700                                 printf("SCTP checksum offload is not supported "
4701                                        "by port %u\n", res->port_id);
4702                         }
4703                 } else if (!strcmp(res->proto, "outer-ip")) {
4704                         if (hw == 0 || (dev_info.tx_offload_capa &
4705                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4706                                 csum_offloads |=
4707                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4708                         } else {
4709                                 printf("Outer IP checksum offload is not "
4710                                        "supported by port %u\n", res->port_id);
4711                         }
4712                 } else if (!strcmp(res->proto, "outer-udp")) {
4713                         if (hw == 0 || (dev_info.tx_offload_capa &
4714                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4715                                 csum_offloads |=
4716                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4717                         } else {
4718                                 printf("Outer UDP checksum offload is not "
4719                                        "supported by port %u\n", res->port_id);
4720                         }
4721                 }
4722
4723                 if (hw) {
4724                         ports[res->port_id].dev_conf.txmode.offloads |=
4725                                                         csum_offloads;
4726                 } else {
4727                         ports[res->port_id].dev_conf.txmode.offloads &=
4728                                                         (~csum_offloads);
4729                 }
4730                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4731         }
4732         csum_show(res->port_id);
4733
4734         cmd_reconfig_device_queue(res->port_id, 1, 1);
4735 }
4736
4737 cmdline_parse_token_string_t cmd_csum_csum =
4738         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4739                                 csum, "csum");
4740 cmdline_parse_token_string_t cmd_csum_mode =
4741         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4742                                 mode, "set");
4743 cmdline_parse_token_string_t cmd_csum_proto =
4744         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4745                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4746 cmdline_parse_token_string_t cmd_csum_hwsw =
4747         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4748                                 hwsw, "hw#sw");
4749 cmdline_parse_token_num_t cmd_csum_portid =
4750         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4751                                 port_id, UINT16);
4752
4753 cmdline_parse_inst_t cmd_csum_set = {
4754         .f = cmd_csum_parsed,
4755         .data = NULL,
4756         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4757                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4758                 "using csum forward engine",
4759         .tokens = {
4760                 (void *)&cmd_csum_csum,
4761                 (void *)&cmd_csum_mode,
4762                 (void *)&cmd_csum_proto,
4763                 (void *)&cmd_csum_hwsw,
4764                 (void *)&cmd_csum_portid,
4765                 NULL,
4766         },
4767 };
4768
4769 cmdline_parse_token_string_t cmd_csum_mode_show =
4770         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4771                                 mode, "show");
4772
4773 cmdline_parse_inst_t cmd_csum_show = {
4774         .f = cmd_csum_parsed,
4775         .data = NULL,
4776         .help_str = "csum show <port_id>: Show checksum offload configuration",
4777         .tokens = {
4778                 (void *)&cmd_csum_csum,
4779                 (void *)&cmd_csum_mode_show,
4780                 (void *)&cmd_csum_portid,
4781                 NULL,
4782         },
4783 };
4784
4785 /* Enable/disable tunnel parsing */
4786 struct cmd_csum_tunnel_result {
4787         cmdline_fixed_string_t csum;
4788         cmdline_fixed_string_t parse;
4789         cmdline_fixed_string_t onoff;
4790         portid_t port_id;
4791 };
4792
4793 static void
4794 cmd_csum_tunnel_parsed(void *parsed_result,
4795                        __rte_unused struct cmdline *cl,
4796                        __rte_unused void *data)
4797 {
4798         struct cmd_csum_tunnel_result *res = parsed_result;
4799
4800         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4801                 return;
4802
4803         if (!strcmp(res->onoff, "on"))
4804                 ports[res->port_id].parse_tunnel = 1;
4805         else
4806                 ports[res->port_id].parse_tunnel = 0;
4807
4808         csum_show(res->port_id);
4809 }
4810
4811 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4812         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4813                                 csum, "csum");
4814 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4815         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4816                                 parse, "parse-tunnel");
4817 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4818         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4819                                 onoff, "on#off");
4820 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4821         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4822                                 port_id, UINT16);
4823
4824 cmdline_parse_inst_t cmd_csum_tunnel = {
4825         .f = cmd_csum_tunnel_parsed,
4826         .data = NULL,
4827         .help_str = "csum parse-tunnel on|off <port_id>: "
4828                 "Enable/Disable parsing of tunnels for csum engine",
4829         .tokens = {
4830                 (void *)&cmd_csum_tunnel_csum,
4831                 (void *)&cmd_csum_tunnel_parse,
4832                 (void *)&cmd_csum_tunnel_onoff,
4833                 (void *)&cmd_csum_tunnel_portid,
4834                 NULL,
4835         },
4836 };
4837
4838 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4839 struct cmd_tso_set_result {
4840         cmdline_fixed_string_t tso;
4841         cmdline_fixed_string_t mode;
4842         uint16_t tso_segsz;
4843         portid_t port_id;
4844 };
4845
4846 static void
4847 cmd_tso_set_parsed(void *parsed_result,
4848                        __rte_unused struct cmdline *cl,
4849                        __rte_unused void *data)
4850 {
4851         struct cmd_tso_set_result *res = parsed_result;
4852         struct rte_eth_dev_info dev_info;
4853         int ret;
4854
4855         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4856                 return;
4857         if (!port_is_stopped(res->port_id)) {
4858                 printf("Please stop port %d first\n", res->port_id);
4859                 return;
4860         }
4861
4862         if (!strcmp(res->mode, "set"))
4863                 ports[res->port_id].tso_segsz = res->tso_segsz;
4864
4865         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4866         if (ret != 0)
4867                 return;
4868
4869         if ((ports[res->port_id].tso_segsz != 0) &&
4870                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4871                 printf("Error: TSO is not supported by port %d\n",
4872                        res->port_id);
4873                 return;
4874         }
4875
4876         if (ports[res->port_id].tso_segsz == 0) {
4877                 ports[res->port_id].dev_conf.txmode.offloads &=
4878                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4879                 printf("TSO for non-tunneled packets is disabled\n");
4880         } else {
4881                 ports[res->port_id].dev_conf.txmode.offloads |=
4882                                                 DEV_TX_OFFLOAD_TCP_TSO;
4883                 printf("TSO segment size for non-tunneled packets is %d\n",
4884                         ports[res->port_id].tso_segsz);
4885         }
4886         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4887
4888         /* display warnings if configuration is not supported by the NIC */
4889         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4890         if (ret != 0)
4891                 return;
4892
4893         if ((ports[res->port_id].tso_segsz != 0) &&
4894                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4895                 printf("Warning: TSO enabled but not "
4896                         "supported by port %d\n", res->port_id);
4897         }
4898
4899         cmd_reconfig_device_queue(res->port_id, 1, 1);
4900 }
4901
4902 cmdline_parse_token_string_t cmd_tso_set_tso =
4903         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4904                                 tso, "tso");
4905 cmdline_parse_token_string_t cmd_tso_set_mode =
4906         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4907                                 mode, "set");
4908 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4909         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4910                                 tso_segsz, UINT16);
4911 cmdline_parse_token_num_t cmd_tso_set_portid =
4912         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4913                                 port_id, UINT16);
4914
4915 cmdline_parse_inst_t cmd_tso_set = {
4916         .f = cmd_tso_set_parsed,
4917         .data = NULL,
4918         .help_str = "tso set <tso_segsz> <port_id>: "
4919                 "Set TSO segment size of non-tunneled packets for csum engine "
4920                 "(0 to disable)",
4921         .tokens = {
4922                 (void *)&cmd_tso_set_tso,
4923                 (void *)&cmd_tso_set_mode,
4924                 (void *)&cmd_tso_set_tso_segsz,
4925                 (void *)&cmd_tso_set_portid,
4926                 NULL,
4927         },
4928 };
4929
4930 cmdline_parse_token_string_t cmd_tso_show_mode =
4931         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4932                                 mode, "show");
4933
4934
4935 cmdline_parse_inst_t cmd_tso_show = {
4936         .f = cmd_tso_set_parsed,
4937         .data = NULL,
4938         .help_str = "tso show <port_id>: "
4939                 "Show TSO segment size of non-tunneled packets for csum engine",
4940         .tokens = {
4941                 (void *)&cmd_tso_set_tso,
4942                 (void *)&cmd_tso_show_mode,
4943                 (void *)&cmd_tso_set_portid,
4944                 NULL,
4945         },
4946 };
4947
4948 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4949 struct cmd_tunnel_tso_set_result {
4950         cmdline_fixed_string_t tso;
4951         cmdline_fixed_string_t mode;
4952         uint16_t tso_segsz;
4953         portid_t port_id;
4954 };
4955
4956 static struct rte_eth_dev_info
4957 check_tunnel_tso_nic_support(portid_t port_id)
4958 {
4959         struct rte_eth_dev_info dev_info;
4960
4961         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4962                 return dev_info;
4963
4964         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4965                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4966                        "not enabled for port %d\n", port_id);
4967         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4968                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4969                        "not enabled for port %d\n", port_id);
4970         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4971                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4972                        "not enabled for port %d\n", port_id);
4973         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4974                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4975                        "not enabled for port %d\n", port_id);
4976         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4977                 printf("Warning: IP TUNNEL TSO not supported therefore "
4978                        "not enabled for port %d\n", port_id);
4979         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4980                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4981                        "not enabled for port %d\n", port_id);
4982         return dev_info;
4983 }
4984
4985 static void
4986 cmd_tunnel_tso_set_parsed(void *parsed_result,
4987                           __rte_unused struct cmdline *cl,
4988                           __rte_unused void *data)
4989 {
4990         struct cmd_tunnel_tso_set_result *res = parsed_result;
4991         struct rte_eth_dev_info dev_info;
4992
4993         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4994                 return;
4995         if (!port_is_stopped(res->port_id)) {
4996                 printf("Please stop port %d first\n", res->port_id);
4997                 return;
4998         }
4999
5000         if (!strcmp(res->mode, "set"))
5001                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5002
5003         dev_info = check_tunnel_tso_nic_support(res->port_id);
5004         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5005                 ports[res->port_id].dev_conf.txmode.offloads &=
5006                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5007                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
5008                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5009                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5010                           DEV_TX_OFFLOAD_IP_TNL_TSO |
5011                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
5012                 printf("TSO for tunneled packets is disabled\n");
5013         } else {
5014                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5015                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5016                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5017                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5018                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5019                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5020
5021                 ports[res->port_id].dev_conf.txmode.offloads |=
5022                         (tso_offloads & dev_info.tx_offload_capa);
5023                 printf("TSO segment size for tunneled packets is %d\n",
5024                         ports[res->port_id].tunnel_tso_segsz);
5025
5026                 /* Below conditions are needed to make it work:
5027                  * (1) tunnel TSO is supported by the NIC;
5028                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5029                  * are recognized;
5030                  * (3) for tunneled pkts with outer L3 of IPv4,
5031                  * "csum set outer-ip" must be set to hw, because after tso,
5032                  * total_len of outer IP header is changed, and the checksum
5033                  * of outer IP header calculated by sw should be wrong; that
5034                  * is not necessary for IPv6 tunneled pkts because there's no
5035                  * checksum in IP header anymore.
5036                  */
5037
5038                 if (!ports[res->port_id].parse_tunnel)
5039                         printf("Warning: csum parse_tunnel must be set "
5040                                 "so that tunneled packets are recognized\n");
5041                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5042                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5043                         printf("Warning: csum set outer-ip must be set to hw "
5044                                 "if outer L3 is IPv4; not necessary for IPv6\n");
5045         }
5046
5047         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5048         cmd_reconfig_device_queue(res->port_id, 1, 1);
5049 }
5050
5051 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5052         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5053                                 tso, "tunnel_tso");
5054 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5055         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5056                                 mode, "set");
5057 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5058         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5059                                 tso_segsz, UINT16);
5060 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5061         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5062                                 port_id, UINT16);
5063
5064 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5065         .f = cmd_tunnel_tso_set_parsed,
5066         .data = NULL,
5067         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5068                 "Set TSO segment size of tunneled packets for csum engine "
5069                 "(0 to disable)",
5070         .tokens = {
5071                 (void *)&cmd_tunnel_tso_set_tso,
5072                 (void *)&cmd_tunnel_tso_set_mode,
5073                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5074                 (void *)&cmd_tunnel_tso_set_portid,
5075                 NULL,
5076         },
5077 };
5078
5079 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5080         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5081                                 mode, "show");
5082
5083
5084 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5085         .f = cmd_tunnel_tso_set_parsed,
5086         .data = NULL,
5087         .help_str = "tunnel_tso show <port_id> "
5088                 "Show TSO segment size of tunneled packets for csum engine",
5089         .tokens = {
5090                 (void *)&cmd_tunnel_tso_set_tso,
5091                 (void *)&cmd_tunnel_tso_show_mode,
5092                 (void *)&cmd_tunnel_tso_set_portid,
5093                 NULL,
5094         },
5095 };
5096
5097 /* *** SET GRO FOR A PORT *** */
5098 struct cmd_gro_enable_result {
5099         cmdline_fixed_string_t cmd_set;
5100         cmdline_fixed_string_t cmd_port;
5101         cmdline_fixed_string_t cmd_keyword;
5102         cmdline_fixed_string_t cmd_onoff;
5103         portid_t cmd_pid;
5104 };
5105
5106 static void
5107 cmd_gro_enable_parsed(void *parsed_result,
5108                 __rte_unused struct cmdline *cl,
5109                 __rte_unused void *data)
5110 {
5111         struct cmd_gro_enable_result *res;
5112
5113         res = parsed_result;
5114         if (!strcmp(res->cmd_keyword, "gro"))
5115                 setup_gro(res->cmd_onoff, res->cmd_pid);
5116 }
5117
5118 cmdline_parse_token_string_t cmd_gro_enable_set =
5119         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5120                         cmd_set, "set");
5121 cmdline_parse_token_string_t cmd_gro_enable_port =
5122         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5123                         cmd_keyword, "port");
5124 cmdline_parse_token_num_t cmd_gro_enable_pid =
5125         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5126                         cmd_pid, UINT16);
5127 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5128         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5129                         cmd_keyword, "gro");
5130 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5131         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5132                         cmd_onoff, "on#off");
5133
5134 cmdline_parse_inst_t cmd_gro_enable = {
5135         .f = cmd_gro_enable_parsed,
5136         .data = NULL,
5137         .help_str = "set port <port_id> gro on|off",
5138         .tokens = {
5139                 (void *)&cmd_gro_enable_set,
5140                 (void *)&cmd_gro_enable_port,
5141                 (void *)&cmd_gro_enable_pid,
5142                 (void *)&cmd_gro_enable_keyword,
5143                 (void *)&cmd_gro_enable_onoff,
5144                 NULL,
5145         },
5146 };
5147
5148 /* *** DISPLAY GRO CONFIGURATION *** */
5149 struct cmd_gro_show_result {
5150         cmdline_fixed_string_t cmd_show;
5151         cmdline_fixed_string_t cmd_port;
5152         cmdline_fixed_string_t cmd_keyword;
5153         portid_t cmd_pid;
5154 };
5155
5156 static void
5157 cmd_gro_show_parsed(void *parsed_result,
5158                 __rte_unused struct cmdline *cl,
5159                 __rte_unused void *data)
5160 {
5161         struct cmd_gro_show_result *res;
5162
5163         res = parsed_result;
5164         if (!strcmp(res->cmd_keyword, "gro"))
5165                 show_gro(res->cmd_pid);
5166 }
5167
5168 cmdline_parse_token_string_t cmd_gro_show_show =
5169         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5170                         cmd_show, "show");
5171 cmdline_parse_token_string_t cmd_gro_show_port =
5172         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5173                         cmd_port, "port");
5174 cmdline_parse_token_num_t cmd_gro_show_pid =
5175         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5176                         cmd_pid, UINT16);
5177 cmdline_parse_token_string_t cmd_gro_show_keyword =
5178         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5179                         cmd_keyword, "gro");
5180
5181 cmdline_parse_inst_t cmd_gro_show = {
5182         .f = cmd_gro_show_parsed,
5183         .data = NULL,
5184         .help_str = "show port <port_id> gro",
5185         .tokens = {
5186                 (void *)&cmd_gro_show_show,
5187                 (void *)&cmd_gro_show_port,
5188                 (void *)&cmd_gro_show_pid,
5189                 (void *)&cmd_gro_show_keyword,
5190                 NULL,
5191         },
5192 };
5193
5194 /* *** SET FLUSH CYCLES FOR GRO *** */
5195 struct cmd_gro_flush_result {
5196         cmdline_fixed_string_t cmd_set;
5197         cmdline_fixed_string_t cmd_keyword;
5198         cmdline_fixed_string_t cmd_flush;
5199         uint8_t cmd_cycles;
5200 };
5201
5202 static void
5203 cmd_gro_flush_parsed(void *parsed_result,
5204                 __rte_unused struct cmdline *cl,
5205                 __rte_unused void *data)
5206 {
5207         struct cmd_gro_flush_result *res;
5208
5209         res = parsed_result;
5210         if ((!strcmp(res->cmd_keyword, "gro")) &&
5211                         (!strcmp(res->cmd_flush, "flush")))
5212                 setup_gro_flush_cycles(res->cmd_cycles);
5213 }
5214
5215 cmdline_parse_token_string_t cmd_gro_flush_set =
5216         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5217                         cmd_set, "set");
5218 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5219         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5220                         cmd_keyword, "gro");
5221 cmdline_parse_token_string_t cmd_gro_flush_flush =
5222         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5223                         cmd_flush, "flush");
5224 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5225         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5226                         cmd_cycles, UINT8);
5227
5228 cmdline_parse_inst_t cmd_gro_flush = {
5229         .f = cmd_gro_flush_parsed,
5230         .data = NULL,
5231         .help_str = "set gro flush <cycles>",
5232         .tokens = {
5233                 (void *)&cmd_gro_flush_set,
5234                 (void *)&cmd_gro_flush_keyword,
5235                 (void *)&cmd_gro_flush_flush,
5236                 (void *)&cmd_gro_flush_cycles,
5237                 NULL,
5238         },
5239 };
5240
5241 /* *** ENABLE/DISABLE GSO *** */
5242 struct cmd_gso_enable_result {
5243         cmdline_fixed_string_t cmd_set;
5244         cmdline_fixed_string_t cmd_port;
5245         cmdline_fixed_string_t cmd_keyword;
5246         cmdline_fixed_string_t cmd_mode;
5247         portid_t cmd_pid;
5248 };
5249
5250 static void
5251 cmd_gso_enable_parsed(void *parsed_result,
5252                 __rte_unused struct cmdline *cl,
5253                 __rte_unused void *data)
5254 {
5255         struct cmd_gso_enable_result *res;
5256
5257         res = parsed_result;
5258         if (!strcmp(res->cmd_keyword, "gso"))
5259                 setup_gso(res->cmd_mode, res->cmd_pid);
5260 }
5261
5262 cmdline_parse_token_string_t cmd_gso_enable_set =
5263         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5264                         cmd_set, "set");
5265 cmdline_parse_token_string_t cmd_gso_enable_port =
5266         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5267                         cmd_port, "port");
5268 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5269         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5270                         cmd_keyword, "gso");
5271 cmdline_parse_token_string_t cmd_gso_enable_mode =
5272         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5273                         cmd_mode, "on#off");
5274 cmdline_parse_token_num_t cmd_gso_enable_pid =
5275         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5276                         cmd_pid, UINT16);
5277
5278 cmdline_parse_inst_t cmd_gso_enable = {
5279         .f = cmd_gso_enable_parsed,
5280         .data = NULL,
5281         .help_str = "set port <port_id> gso on|off",
5282         .tokens = {
5283                 (void *)&cmd_gso_enable_set,
5284                 (void *)&cmd_gso_enable_port,
5285                 (void *)&cmd_gso_enable_pid,
5286                 (void *)&cmd_gso_enable_keyword,
5287                 (void *)&cmd_gso_enable_mode,
5288                 NULL,
5289         },
5290 };
5291
5292 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5293 struct cmd_gso_size_result {
5294         cmdline_fixed_string_t cmd_set;
5295         cmdline_fixed_string_t cmd_keyword;
5296         cmdline_fixed_string_t cmd_segsz;
5297         uint16_t cmd_size;
5298 };
5299
5300 static void
5301 cmd_gso_size_parsed(void *parsed_result,
5302                        __rte_unused struct cmdline *cl,
5303                        __rte_unused void *data)
5304 {
5305         struct cmd_gso_size_result *res = parsed_result;
5306
5307         if (test_done == 0) {
5308                 printf("Before setting GSO segsz, please first"
5309                                 " stop forwarding\n");
5310                 return;
5311         }
5312
5313         if (!strcmp(res->cmd_keyword, "gso") &&
5314                         !strcmp(res->cmd_segsz, "segsz")) {
5315                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5316                         printf("gso_size should be larger than %zu."
5317                                         " Please input a legal value\n",
5318                                         RTE_GSO_SEG_SIZE_MIN);
5319                 else
5320                         gso_max_segment_size = res->cmd_size;
5321         }
5322 }
5323
5324 cmdline_parse_token_string_t cmd_gso_size_set =
5325         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5326                                 cmd_set, "set");
5327 cmdline_parse_token_string_t cmd_gso_size_keyword =
5328         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5329                                 cmd_keyword, "gso");
5330 cmdline_parse_token_string_t cmd_gso_size_segsz =
5331         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5332                                 cmd_segsz, "segsz");
5333 cmdline_parse_token_num_t cmd_gso_size_size =
5334         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5335                                 cmd_size, UINT16);
5336
5337 cmdline_parse_inst_t cmd_gso_size = {
5338         .f = cmd_gso_size_parsed,
5339         .data = NULL,
5340         .help_str = "set gso segsz <length>",
5341         .tokens = {
5342                 (void *)&cmd_gso_size_set,
5343                 (void *)&cmd_gso_size_keyword,
5344                 (void *)&cmd_gso_size_segsz,
5345                 (void *)&cmd_gso_size_size,
5346                 NULL,
5347         },
5348 };
5349
5350 /* *** SHOW GSO CONFIGURATION *** */
5351 struct cmd_gso_show_result {
5352         cmdline_fixed_string_t cmd_show;
5353         cmdline_fixed_string_t cmd_port;
5354         cmdline_fixed_string_t cmd_keyword;
5355         portid_t cmd_pid;
5356 };
5357
5358 static void
5359 cmd_gso_show_parsed(void *parsed_result,
5360                        __rte_unused struct cmdline *cl,
5361                        __rte_unused void *data)
5362 {
5363         struct cmd_gso_show_result *res = parsed_result;
5364
5365         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5366                 printf("invalid port id %u\n", res->cmd_pid);
5367                 return;
5368         }
5369         if (!strcmp(res->cmd_keyword, "gso")) {
5370                 if (gso_ports[res->cmd_pid].enable) {
5371                         printf("Max GSO'd packet size: %uB\n"
5372                                         "Supported GSO types: TCP/IPv4, "
5373                                         "UDP/IPv4, VxLAN with inner "
5374                                         "TCP/IPv4 packet, GRE with inner "
5375                                         "TCP/IPv4 packet\n",
5376                                         gso_max_segment_size);
5377                 } else
5378                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5379         }
5380 }
5381
5382 cmdline_parse_token_string_t cmd_gso_show_show =
5383 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5384                 cmd_show, "show");
5385 cmdline_parse_token_string_t cmd_gso_show_port =
5386 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5387                 cmd_port, "port");
5388 cmdline_parse_token_string_t cmd_gso_show_keyword =
5389         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5390                                 cmd_keyword, "gso");
5391 cmdline_parse_token_num_t cmd_gso_show_pid =
5392         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5393                                 cmd_pid, UINT16);
5394
5395 cmdline_parse_inst_t cmd_gso_show = {
5396         .f = cmd_gso_show_parsed,
5397         .data = NULL,
5398         .help_str = "show port <port_id> gso",
5399         .tokens = {
5400                 (void *)&cmd_gso_show_show,
5401                 (void *)&cmd_gso_show_port,
5402                 (void *)&cmd_gso_show_pid,
5403                 (void *)&cmd_gso_show_keyword,
5404                 NULL,
5405         },
5406 };
5407
5408 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5409 struct cmd_set_flush_rx {
5410         cmdline_fixed_string_t set;
5411         cmdline_fixed_string_t flush_rx;
5412         cmdline_fixed_string_t mode;
5413 };
5414
5415 static void
5416 cmd_set_flush_rx_parsed(void *parsed_result,
5417                 __rte_unused struct cmdline *cl,
5418                 __rte_unused void *data)
5419 {
5420         struct cmd_set_flush_rx *res = parsed_result;
5421         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5422 }
5423
5424 cmdline_parse_token_string_t cmd_setflushrx_set =
5425         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5426                         set, "set");
5427 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5428         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5429                         flush_rx, "flush_rx");
5430 cmdline_parse_token_string_t cmd_setflushrx_mode =
5431         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5432                         mode, "on#off");
5433
5434
5435 cmdline_parse_inst_t cmd_set_flush_rx = {
5436         .f = cmd_set_flush_rx_parsed,
5437         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5438         .data = NULL,
5439         .tokens = {
5440                 (void *)&cmd_setflushrx_set,
5441                 (void *)&cmd_setflushrx_flush_rx,
5442                 (void *)&cmd_setflushrx_mode,
5443                 NULL,
5444         },
5445 };
5446
5447 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5448 struct cmd_set_link_check {
5449         cmdline_fixed_string_t set;
5450         cmdline_fixed_string_t link_check;
5451         cmdline_fixed_string_t mode;
5452 };
5453
5454 static void
5455 cmd_set_link_check_parsed(void *parsed_result,
5456                 __rte_unused struct cmdline *cl,
5457                 __rte_unused void *data)
5458 {
5459         struct cmd_set_link_check *res = parsed_result;
5460         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5461 }
5462
5463 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5464         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5465                         set, "set");
5466 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5467         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5468                         link_check, "link_check");
5469 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5470         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5471                         mode, "on#off");
5472
5473
5474 cmdline_parse_inst_t cmd_set_link_check = {
5475         .f = cmd_set_link_check_parsed,
5476         .help_str = "set link_check on|off: Enable/Disable link status check "
5477                     "when starting/stopping a port",
5478         .data = NULL,
5479         .tokens = {
5480                 (void *)&cmd_setlinkcheck_set,
5481                 (void *)&cmd_setlinkcheck_link_check,
5482                 (void *)&cmd_setlinkcheck_mode,
5483                 NULL,
5484         },
5485 };
5486
5487 /* *** SET NIC BYPASS MODE *** */
5488 struct cmd_set_bypass_mode_result {
5489         cmdline_fixed_string_t set;
5490         cmdline_fixed_string_t bypass;
5491         cmdline_fixed_string_t mode;
5492         cmdline_fixed_string_t value;
5493         portid_t port_id;
5494 };
5495
5496 static void
5497 cmd_set_bypass_mode_parsed(void *parsed_result,
5498                 __rte_unused struct cmdline *cl,
5499                 __rte_unused void *data)
5500 {
5501         struct cmd_set_bypass_mode_result *res = parsed_result;
5502         portid_t port_id = res->port_id;
5503         int32_t rc = -EINVAL;
5504
5505 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5506         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5507
5508         if (!strcmp(res->value, "bypass"))
5509                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5510         else if (!strcmp(res->value, "isolate"))
5511                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5512         else
5513                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5514
5515         /* Set the bypass mode for the relevant port. */
5516         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5517 #endif
5518         if (rc != 0)
5519                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5520 }
5521
5522 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5523         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5524                         set, "set");
5525 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5526         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5527                         bypass, "bypass");
5528 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5529         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5530                         mode, "mode");
5531 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5532         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5533                         value, "normal#bypass#isolate");
5534 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5535         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5536                                 port_id, UINT16);
5537
5538 cmdline_parse_inst_t cmd_set_bypass_mode = {
5539         .f = cmd_set_bypass_mode_parsed,
5540         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5541                     "Set the NIC bypass mode for port_id",
5542         .data = NULL,
5543         .tokens = {
5544                 (void *)&cmd_setbypass_mode_set,
5545                 (void *)&cmd_setbypass_mode_bypass,
5546                 (void *)&cmd_setbypass_mode_mode,
5547                 (void *)&cmd_setbypass_mode_value,
5548                 (void *)&cmd_setbypass_mode_port,
5549                 NULL,
5550         },
5551 };
5552
5553 /* *** SET NIC BYPASS EVENT *** */
5554 struct cmd_set_bypass_event_result {
5555         cmdline_fixed_string_t set;
5556         cmdline_fixed_string_t bypass;
5557         cmdline_fixed_string_t event;
5558         cmdline_fixed_string_t event_value;
5559         cmdline_fixed_string_t mode;
5560         cmdline_fixed_string_t mode_value;
5561         portid_t port_id;
5562 };
5563
5564 static void
5565 cmd_set_bypass_event_parsed(void *parsed_result,
5566                 __rte_unused struct cmdline *cl,
5567                 __rte_unused void *data)
5568 {
5569         int32_t rc = -EINVAL;
5570         struct cmd_set_bypass_event_result *res = parsed_result;
5571         portid_t port_id = res->port_id;
5572
5573 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5574         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5575         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5576
5577         if (!strcmp(res->event_value, "timeout"))
5578                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5579         else if (!strcmp(res->event_value, "os_on"))
5580                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5581         else if (!strcmp(res->event_value, "os_off"))
5582                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5583         else if (!strcmp(res->event_value, "power_on"))
5584                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5585         else if (!strcmp(res->event_value, "power_off"))
5586                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5587         else
5588                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5589
5590         if (!strcmp(res->mode_value, "bypass"))
5591                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5592         else if (!strcmp(res->mode_value, "isolate"))
5593                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5594         else
5595                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5596
5597         /* Set the watchdog timeout. */
5598         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5599
5600                 rc = -EINVAL;
5601                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5602                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5603                                                            bypass_timeout);
5604                 }
5605                 if (rc != 0) {
5606                         printf("Failed to set timeout value %u "
5607                         "for port %d, errto code: %d.\n",
5608                         bypass_timeout, port_id, rc);
5609                 }
5610         }
5611
5612         /* Set the bypass event to transition to bypass mode. */
5613         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5614                                               bypass_mode);
5615 #endif
5616
5617         if (rc != 0)
5618                 printf("\t Failed to set bypass event for port = %d.\n",
5619                        port_id);
5620 }
5621
5622 cmdline_parse_token_string_t cmd_setbypass_event_set =
5623         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5624                         set, "set");
5625 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5626         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5627                         bypass, "bypass");
5628 cmdline_parse_token_string_t cmd_setbypass_event_event =
5629         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5630                         event, "event");
5631 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5633                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5634 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5636                         mode, "mode");
5637 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5639                         mode_value, "normal#bypass#isolate");
5640 cmdline_parse_token_num_t cmd_setbypass_event_port =
5641         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5642                                 port_id, UINT16);
5643
5644 cmdline_parse_inst_t cmd_set_bypass_event = {
5645         .f = cmd_set_bypass_event_parsed,
5646         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5647                 "power_off mode normal|bypass|isolate <port_id>: "
5648                 "Set the NIC bypass event mode for port_id",
5649         .data = NULL,
5650         .tokens = {
5651                 (void *)&cmd_setbypass_event_set,
5652                 (void *)&cmd_setbypass_event_bypass,
5653                 (void *)&cmd_setbypass_event_event,
5654                 (void *)&cmd_setbypass_event_event_value,
5655                 (void *)&cmd_setbypass_event_mode,
5656                 (void *)&cmd_setbypass_event_mode_value,
5657                 (void *)&cmd_setbypass_event_port,
5658                 NULL,
5659         },
5660 };
5661
5662
5663 /* *** SET NIC BYPASS TIMEOUT *** */
5664 struct cmd_set_bypass_timeout_result {
5665         cmdline_fixed_string_t set;
5666         cmdline_fixed_string_t bypass;
5667         cmdline_fixed_string_t timeout;
5668         cmdline_fixed_string_t value;
5669 };
5670
5671 static void
5672 cmd_set_bypass_timeout_parsed(void *parsed_result,
5673                 __rte_unused struct cmdline *cl,
5674                 __rte_unused void *data)
5675 {
5676         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5677
5678 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5679         if (!strcmp(res->value, "1.5"))
5680                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5681         else if (!strcmp(res->value, "2"))
5682                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5683         else if (!strcmp(res->value, "3"))
5684                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5685         else if (!strcmp(res->value, "4"))
5686                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5687         else if (!strcmp(res->value, "8"))
5688                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5689         else if (!strcmp(res->value, "16"))
5690                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5691         else if (!strcmp(res->value, "32"))
5692                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5693         else
5694                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5695 #endif
5696 }
5697
5698 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5699         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5700                         set, "set");
5701 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5702         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5703                         bypass, "bypass");
5704 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5705         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5706                         timeout, "timeout");
5707 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5708         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5709                         value, "0#1.5#2#3#4#8#16#32");
5710
5711 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5712         .f = cmd_set_bypass_timeout_parsed,
5713         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5714                 "Set the NIC bypass watchdog timeout in seconds",
5715         .data = NULL,
5716         .tokens = {
5717                 (void *)&cmd_setbypass_timeout_set,
5718                 (void *)&cmd_setbypass_timeout_bypass,
5719                 (void *)&cmd_setbypass_timeout_timeout,
5720                 (void *)&cmd_setbypass_timeout_value,
5721                 NULL,
5722         },
5723 };
5724
5725 /* *** SHOW NIC BYPASS MODE *** */
5726 struct cmd_show_bypass_config_result {
5727         cmdline_fixed_string_t show;
5728         cmdline_fixed_string_t bypass;
5729         cmdline_fixed_string_t config;
5730         portid_t port_id;
5731 };
5732
5733 static void
5734 cmd_show_bypass_config_parsed(void *parsed_result,
5735                 __rte_unused struct cmdline *cl,
5736                 __rte_unused void *data)
5737 {
5738         struct cmd_show_bypass_config_result *res = parsed_result;
5739         portid_t port_id = res->port_id;
5740         int rc = -EINVAL;
5741 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5742         uint32_t event_mode;
5743         uint32_t bypass_mode;
5744         uint32_t timeout = bypass_timeout;
5745         unsigned int i;
5746
5747         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5748                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5749         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5750                 {"UNKNOWN", "normal", "bypass", "isolate"};
5751         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5752                 "NONE",
5753                 "OS/board on",
5754                 "power supply on",
5755                 "OS/board off",
5756                 "power supply off",
5757                 "timeout"};
5758
5759         /* Display the bypass mode.*/
5760         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5761                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5762                 return;
5763         }
5764         else {
5765                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5766                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5767
5768                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5769         }
5770
5771         /* Display the bypass timeout.*/
5772         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5773                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5774
5775         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5776
5777         /* Display the bypass events and associated modes. */
5778         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5779
5780                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5781                         printf("\tFailed to get bypass mode for event = %s\n",
5782                                 events[i]);
5783                 } else {
5784                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5785                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5786
5787                         printf("\tbypass event: %-16s = %s\n", events[i],
5788                                 modes[event_mode]);
5789                 }
5790         }
5791 #endif
5792         if (rc != 0)
5793                 printf("\tFailed to get bypass configuration for port = %d\n",
5794                        port_id);
5795 }
5796
5797 cmdline_parse_token_string_t cmd_showbypass_config_show =
5798         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5799                         show, "show");
5800 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5801         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5802                         bypass, "bypass");
5803 cmdline_parse_token_string_t cmd_showbypass_config_config =
5804         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5805                         config, "config");
5806 cmdline_parse_token_num_t cmd_showbypass_config_port =
5807         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5808                                 port_id, UINT16);
5809
5810 cmdline_parse_inst_t cmd_show_bypass_config = {
5811         .f = cmd_show_bypass_config_parsed,
5812         .help_str = "show bypass config <port_id>: "
5813                     "Show the NIC bypass config for port_id",
5814         .data = NULL,
5815         .tokens = {
5816                 (void *)&cmd_showbypass_config_show,
5817                 (void *)&cmd_showbypass_config_bypass,
5818                 (void *)&cmd_showbypass_config_config,
5819                 (void *)&cmd_showbypass_config_port,
5820                 NULL,
5821         },
5822 };
5823
5824 #ifdef RTE_NET_BOND
5825 /* *** SET BONDING MODE *** */
5826 struct cmd_set_bonding_mode_result {
5827         cmdline_fixed_string_t set;
5828         cmdline_fixed_string_t bonding;
5829         cmdline_fixed_string_t mode;
5830         uint8_t value;
5831         portid_t port_id;
5832 };
5833
5834 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5835                 __rte_unused  struct cmdline *cl,
5836                 __rte_unused void *data)
5837 {
5838         struct cmd_set_bonding_mode_result *res = parsed_result;
5839         portid_t port_id = res->port_id;
5840
5841         /* Set the bonding mode for the relevant port. */
5842         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5843                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5844 }
5845
5846 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5847 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5848                 set, "set");
5849 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5850 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5851                 bonding, "bonding");
5852 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5853 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5854                 mode, "mode");
5855 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5856 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5857                 value, UINT8);
5858 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5859 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5860                 port_id, UINT16);
5861
5862 cmdline_parse_inst_t cmd_set_bonding_mode = {
5863                 .f = cmd_set_bonding_mode_parsed,
5864                 .help_str = "set bonding mode <mode_value> <port_id>: "
5865                         "Set the bonding mode for port_id",
5866                 .data = NULL,
5867                 .tokens = {
5868                                 (void *) &cmd_setbonding_mode_set,
5869                                 (void *) &cmd_setbonding_mode_bonding,
5870                                 (void *) &cmd_setbonding_mode_mode,
5871                                 (void *) &cmd_setbonding_mode_value,
5872                                 (void *) &cmd_setbonding_mode_port,
5873                                 NULL
5874                 }
5875 };
5876
5877 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5878 struct cmd_set_bonding_lacp_dedicated_queues_result {
5879         cmdline_fixed_string_t set;
5880         cmdline_fixed_string_t bonding;
5881         cmdline_fixed_string_t lacp;
5882         cmdline_fixed_string_t dedicated_queues;
5883         portid_t port_id;
5884         cmdline_fixed_string_t mode;
5885 };
5886
5887 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5888                 __rte_unused  struct cmdline *cl,
5889                 __rte_unused void *data)
5890 {
5891         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5892         portid_t port_id = res->port_id;
5893         struct rte_port *port;
5894
5895         port = &ports[port_id];
5896
5897         /** Check if the port is not started **/
5898         if (port->port_status != RTE_PORT_STOPPED) {
5899                 printf("Please stop port %d first\n", port_id);
5900                 return;
5901         }
5902
5903         if (!strcmp(res->mode, "enable")) {
5904                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5905                         printf("Dedicate queues for LACP control packets"
5906                                         " enabled\n");
5907                 else
5908                         printf("Enabling dedicate queues for LACP control "
5909                                         "packets on port %d failed\n", port_id);
5910         } else if (!strcmp(res->mode, "disable")) {
5911                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5912                         printf("Dedicated queues for LACP control packets "
5913                                         "disabled\n");
5914                 else
5915                         printf("Disabling dedicated queues for LACP control "
5916                                         "traffic on port %d failed\n", port_id);
5917         }
5918 }
5919
5920 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5921 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5922                 set, "set");
5923 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5924 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5925                 bonding, "bonding");
5926 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5928                 lacp, "lacp");
5929 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5930 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5931                 dedicated_queues, "dedicated_queues");
5932 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5933 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5934                 port_id, UINT16);
5935 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5936 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5937                 mode, "enable#disable");
5938
5939 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5940                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5941                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5942                         "enable|disable: "
5943                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5944                 .data = NULL,
5945                 .tokens = {
5946                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5947                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5948                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5949                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5950                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5951                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5952                         NULL
5953                 }
5954 };
5955
5956 /* *** SET BALANCE XMIT POLICY *** */
5957 struct cmd_set_bonding_balance_xmit_policy_result {
5958         cmdline_fixed_string_t set;
5959         cmdline_fixed_string_t bonding;
5960         cmdline_fixed_string_t balance_xmit_policy;
5961         portid_t port_id;
5962         cmdline_fixed_string_t policy;
5963 };
5964
5965 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5966                 __rte_unused  struct cmdline *cl,
5967                 __rte_unused void *data)
5968 {
5969         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5970         portid_t port_id = res->port_id;
5971         uint8_t policy;
5972
5973         if (!strcmp(res->policy, "l2")) {
5974                 policy = BALANCE_XMIT_POLICY_LAYER2;
5975         } else if (!strcmp(res->policy, "l23")) {
5976                 policy = BALANCE_XMIT_POLICY_LAYER23;
5977         } else if (!strcmp(res->policy, "l34")) {
5978                 policy = BALANCE_XMIT_POLICY_LAYER34;
5979         } else {
5980                 printf("\t Invalid xmit policy selection");
5981                 return;
5982         }
5983
5984         /* Set the bonding mode for the relevant port. */
5985         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5986                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5987                                 port_id);
5988         }
5989 }
5990
5991 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5992 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5993                 set, "set");
5994 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5995 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5996                 bonding, "bonding");
5997 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5998 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5999                 balance_xmit_policy, "balance_xmit_policy");
6000 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6001 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6002                 port_id, UINT16);
6003 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6004 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6005                 policy, "l2#l23#l34");
6006
6007 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6008                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6009                 .help_str = "set bonding balance_xmit_policy <port_id> "
6010                         "l2|l23|l34: "
6011                         "Set the bonding balance_xmit_policy for port_id",
6012                 .data = NULL,
6013                 .tokens = {
6014                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6015                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6016                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6017                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6018                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6019                                 NULL
6020                 }
6021 };
6022
6023 /* *** SHOW NIC BONDING CONFIGURATION *** */
6024 struct cmd_show_bonding_config_result {
6025         cmdline_fixed_string_t show;
6026         cmdline_fixed_string_t bonding;
6027         cmdline_fixed_string_t config;
6028         portid_t port_id;
6029 };
6030
6031 static void cmd_show_bonding_config_parsed(void *parsed_result,
6032                 __rte_unused  struct cmdline *cl,
6033                 __rte_unused void *data)
6034 {
6035         struct cmd_show_bonding_config_result *res = parsed_result;
6036         int bonding_mode, agg_mode;
6037         portid_t slaves[RTE_MAX_ETHPORTS];
6038         int num_slaves, num_active_slaves;
6039         int primary_id;
6040         int i;
6041         portid_t port_id = res->port_id;
6042
6043         /* Display the bonding mode.*/
6044         bonding_mode = rte_eth_bond_mode_get(port_id);
6045         if (bonding_mode < 0) {
6046                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
6047                 return;
6048         } else
6049                 printf("\tBonding mode: %d\n", bonding_mode);
6050
6051         if (bonding_mode == BONDING_MODE_BALANCE) {
6052                 int balance_xmit_policy;
6053
6054                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6055                 if (balance_xmit_policy < 0) {
6056                         printf("\tFailed to get balance xmit policy for port = %d\n",
6057                                         port_id);
6058                         return;
6059                 } else {
6060                         printf("\tBalance Xmit Policy: ");
6061
6062                         switch (balance_xmit_policy) {
6063                         case BALANCE_XMIT_POLICY_LAYER2:
6064                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6065                                 break;
6066                         case BALANCE_XMIT_POLICY_LAYER23:
6067                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6068                                 break;
6069                         case BALANCE_XMIT_POLICY_LAYER34:
6070                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6071                                 break;
6072                         }
6073                         printf("\n");
6074                 }
6075         }
6076
6077         if (bonding_mode == BONDING_MODE_8023AD) {
6078                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6079                 printf("\tIEEE802.3AD Aggregator Mode: ");
6080                 switch (agg_mode) {
6081                 case AGG_BANDWIDTH:
6082                         printf("bandwidth");
6083                         break;
6084                 case AGG_STABLE:
6085                         printf("stable");
6086                         break;
6087                 case AGG_COUNT:
6088                         printf("count");
6089                         break;
6090                 }
6091                 printf("\n");
6092         }
6093
6094         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6095
6096         if (num_slaves < 0) {
6097                 printf("\tFailed to get slave list for port = %d\n", port_id);
6098                 return;
6099         }
6100         if (num_slaves > 0) {
6101                 printf("\tSlaves (%d): [", num_slaves);
6102                 for (i = 0; i < num_slaves - 1; i++)
6103                         printf("%d ", slaves[i]);
6104
6105                 printf("%d]\n", slaves[num_slaves - 1]);
6106         } else {
6107                 printf("\tSlaves: []\n");
6108
6109         }
6110
6111         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6112                         RTE_MAX_ETHPORTS);
6113
6114         if (num_active_slaves < 0) {
6115                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6116                 return;
6117         }
6118         if (num_active_slaves > 0) {
6119                 printf("\tActive Slaves (%d): [", num_active_slaves);
6120                 for (i = 0; i < num_active_slaves - 1; i++)
6121                         printf("%d ", slaves[i]);
6122
6123                 printf("%d]\n", slaves[num_active_slaves - 1]);
6124
6125         } else {
6126                 printf("\tActive Slaves: []\n");
6127
6128         }
6129
6130         primary_id = rte_eth_bond_primary_get(port_id);
6131         if (primary_id < 0) {
6132                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6133                 return;
6134         } else
6135                 printf("\tPrimary: [%d]\n", primary_id);
6136
6137 }
6138
6139 cmdline_parse_token_string_t cmd_showbonding_config_show =
6140 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6141                 show, "show");
6142 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6143 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6144                 bonding, "bonding");
6145 cmdline_parse_token_string_t cmd_showbonding_config_config =
6146 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6147                 config, "config");
6148 cmdline_parse_token_num_t cmd_showbonding_config_port =
6149 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6150                 port_id, UINT16);
6151
6152 cmdline_parse_inst_t cmd_show_bonding_config = {
6153                 .f = cmd_show_bonding_config_parsed,
6154                 .help_str = "show bonding config <port_id>: "
6155                         "Show the bonding config for port_id",
6156                 .data = NULL,
6157                 .tokens = {
6158                                 (void *)&cmd_showbonding_config_show,
6159                                 (void *)&cmd_showbonding_config_bonding,
6160                                 (void *)&cmd_showbonding_config_config,
6161                                 (void *)&cmd_showbonding_config_port,
6162                                 NULL
6163                 }
6164 };
6165
6166 /* *** SET BONDING PRIMARY *** */
6167 struct cmd_set_bonding_primary_result {
6168         cmdline_fixed_string_t set;
6169         cmdline_fixed_string_t bonding;
6170         cmdline_fixed_string_t primary;
6171         portid_t slave_id;
6172         portid_t port_id;
6173 };
6174
6175 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6176                 __rte_unused  struct cmdline *cl,
6177                 __rte_unused void *data)
6178 {
6179         struct cmd_set_bonding_primary_result *res = parsed_result;
6180         portid_t master_port_id = res->port_id;
6181         portid_t slave_port_id = res->slave_id;
6182
6183         /* Set the primary slave for a bonded device. */
6184         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6185                 printf("\t Failed to set primary slave for port = %d.\n",
6186                                 master_port_id);
6187                 return;
6188         }
6189         init_port_config();
6190 }
6191
6192 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6193 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6194                 set, "set");
6195 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6196 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6197                 bonding, "bonding");
6198 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6199 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6200                 primary, "primary");
6201 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6202 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6203                 slave_id, UINT16);
6204 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6205 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6206                 port_id, UINT16);
6207
6208 cmdline_parse_inst_t cmd_set_bonding_primary = {
6209                 .f = cmd_set_bonding_primary_parsed,
6210                 .help_str = "set bonding primary <slave_id> <port_id>: "
6211                         "Set the primary slave for port_id",
6212                 .data = NULL,
6213                 .tokens = {
6214                                 (void *)&cmd_setbonding_primary_set,
6215                                 (void *)&cmd_setbonding_primary_bonding,
6216                                 (void *)&cmd_setbonding_primary_primary,
6217                                 (void *)&cmd_setbonding_primary_slave,
6218                                 (void *)&cmd_setbonding_primary_port,
6219                                 NULL
6220                 }
6221 };
6222
6223 /* *** ADD SLAVE *** */
6224 struct cmd_add_bonding_slave_result {
6225         cmdline_fixed_string_t add;
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_add_bonding_slave_parsed(void *parsed_result,
6233                 __rte_unused  struct cmdline *cl,
6234                 __rte_unused void *data)
6235 {
6236         struct cmd_add_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         /* add the slave for a bonded device. */
6241         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6242                 printf("\t Failed to add slave %d to master port = %d.\n",
6243                                 slave_port_id, master_port_id);
6244                 return;
6245         }
6246         init_port_config();
6247         set_port_slave_flag(slave_port_id);
6248 }
6249
6250 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6251 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6252                 add, "add");
6253 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6254 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6255                 bonding, "bonding");
6256 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6257 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6258                 slave, "slave");
6259 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6260 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6261                 slave_id, UINT16);
6262 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6263 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6264                 port_id, UINT16);
6265
6266 cmdline_parse_inst_t cmd_add_bonding_slave = {
6267                 .f = cmd_add_bonding_slave_parsed,
6268                 .help_str = "add bonding slave <slave_id> <port_id>: "
6269                         "Add a slave device to a bonded device",
6270                 .data = NULL,
6271                 .tokens = {
6272                                 (void *)&cmd_addbonding_slave_add,
6273                                 (void *)&cmd_addbonding_slave_bonding,
6274                                 (void *)&cmd_addbonding_slave_slave,
6275                                 (void *)&cmd_addbonding_slave_slaveid,
6276                                 (void *)&cmd_addbonding_slave_port,
6277                                 NULL
6278                 }
6279 };
6280
6281 /* *** REMOVE SLAVE *** */
6282 struct cmd_remove_bonding_slave_result {
6283         cmdline_fixed_string_t remove;
6284         cmdline_fixed_string_t bonding;
6285         cmdline_fixed_string_t slave;
6286         portid_t slave_id;
6287         portid_t port_id;
6288 };
6289
6290 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6291                 __rte_unused  struct cmdline *cl,
6292                 __rte_unused void *data)
6293 {
6294         struct cmd_remove_bonding_slave_result *res = parsed_result;
6295         portid_t master_port_id = res->port_id;
6296         portid_t slave_port_id = res->slave_id;
6297
6298         /* remove the slave from a bonded device. */
6299         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6300                 printf("\t Failed to remove slave %d from master port = %d.\n",
6301                                 slave_port_id, master_port_id);
6302                 return;
6303         }
6304         init_port_config();
6305         clear_port_slave_flag(slave_port_id);
6306 }
6307
6308 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6309                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6310                                 remove, "remove");
6311 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6312                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6313                                 bonding, "bonding");
6314 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6315                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6316                                 slave, "slave");
6317 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6318                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6319                                 slave_id, UINT16);
6320 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6321                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6322                                 port_id, UINT16);
6323
6324 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6325                 .f = cmd_remove_bonding_slave_parsed,
6326                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6327                         "Remove a slave device from a bonded device",
6328                 .data = NULL,
6329                 .tokens = {
6330                                 (void *)&cmd_removebonding_slave_remove,
6331                                 (void *)&cmd_removebonding_slave_bonding,
6332                                 (void *)&cmd_removebonding_slave_slave,
6333                                 (void *)&cmd_removebonding_slave_slaveid,
6334                                 (void *)&cmd_removebonding_slave_port,
6335                                 NULL
6336                 }
6337 };
6338
6339 /* *** CREATE BONDED DEVICE *** */
6340 struct cmd_create_bonded_device_result {
6341         cmdline_fixed_string_t create;
6342         cmdline_fixed_string_t bonded;
6343         cmdline_fixed_string_t device;
6344         uint8_t mode;
6345         uint8_t socket;
6346 };
6347
6348 static int bond_dev_num = 0;
6349
6350 static void cmd_create_bonded_device_parsed(void *parsed_result,
6351                 __rte_unused  struct cmdline *cl,
6352                 __rte_unused void *data)
6353 {
6354         struct cmd_create_bonded_device_result *res = parsed_result;
6355         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6356         int port_id;
6357         int ret;
6358
6359         if (test_done == 0) {
6360                 printf("Please stop forwarding first\n");
6361                 return;
6362         }
6363
6364         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6365                         bond_dev_num++);
6366
6367         /* Create a new bonded device. */
6368         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6369         if (port_id < 0) {
6370                 printf("\t Failed to create bonded device.\n");
6371                 return;
6372         } else {
6373                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6374                                 port_id);
6375
6376                 /* Update number of ports */
6377                 nb_ports = rte_eth_dev_count_avail();
6378                 reconfig(port_id, res->socket);
6379                 ret = rte_eth_promiscuous_enable(port_id);
6380                 if (ret != 0)
6381                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6382                                 port_id, rte_strerror(-ret));
6383
6384                 ports[port_id].need_setup = 0;
6385                 ports[port_id].port_status = RTE_PORT_STOPPED;
6386         }
6387
6388 }
6389
6390 cmdline_parse_token_string_t cmd_createbonded_device_create =
6391                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6392                                 create, "create");
6393 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6394                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6395                                 bonded, "bonded");
6396 cmdline_parse_token_string_t cmd_createbonded_device_device =
6397                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6398                                 device, "device");
6399 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6400                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6401                                 mode, UINT8);
6402 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6403                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6404                                 socket, UINT8);
6405
6406 cmdline_parse_inst_t cmd_create_bonded_device = {
6407                 .f = cmd_create_bonded_device_parsed,
6408                 .help_str = "create bonded device <mode> <socket>: "
6409                         "Create a new bonded device with specific bonding mode and socket",
6410                 .data = NULL,
6411                 .tokens = {
6412                                 (void *)&cmd_createbonded_device_create,
6413                                 (void *)&cmd_createbonded_device_bonded,
6414                                 (void *)&cmd_createbonded_device_device,
6415                                 (void *)&cmd_createbonded_device_mode,
6416                                 (void *)&cmd_createbonded_device_socket,
6417                                 NULL
6418                 }
6419 };
6420
6421 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6422 struct cmd_set_bond_mac_addr_result {
6423         cmdline_fixed_string_t set;
6424         cmdline_fixed_string_t bonding;
6425         cmdline_fixed_string_t mac_addr;
6426         uint16_t port_num;
6427         struct rte_ether_addr address;
6428 };
6429
6430 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6431                 __rte_unused  struct cmdline *cl,
6432                 __rte_unused void *data)
6433 {
6434         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6435         int ret;
6436
6437         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6438                 return;
6439
6440         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6441
6442         /* check the return value and print it if is < 0 */
6443         if (ret < 0)
6444                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6445 }
6446
6447 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6448                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6449 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6450                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6451                                 "bonding");
6452 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6453                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6454                                 "mac_addr");
6455 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6456                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6457                                 port_num, UINT16);
6458 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6459                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6460
6461 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6462                 .f = cmd_set_bond_mac_addr_parsed,
6463                 .data = (void *) 0,
6464                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6465                 .tokens = {
6466                                 (void *)&cmd_set_bond_mac_addr_set,
6467                                 (void *)&cmd_set_bond_mac_addr_bonding,
6468                                 (void *)&cmd_set_bond_mac_addr_mac,
6469                                 (void *)&cmd_set_bond_mac_addr_portnum,
6470                                 (void *)&cmd_set_bond_mac_addr_addr,
6471                                 NULL
6472                 }
6473 };
6474
6475
6476 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6477 struct cmd_set_bond_mon_period_result {
6478         cmdline_fixed_string_t set;
6479         cmdline_fixed_string_t bonding;
6480         cmdline_fixed_string_t mon_period;
6481         uint16_t port_num;
6482         uint32_t period_ms;
6483 };
6484
6485 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6486                 __rte_unused  struct cmdline *cl,
6487                 __rte_unused void *data)
6488 {
6489         struct cmd_set_bond_mon_period_result *res = parsed_result;
6490         int ret;
6491
6492         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6493
6494         /* check the return value and print it if is < 0 */
6495         if (ret < 0)
6496                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6497 }
6498
6499 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6500                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6501                                 set, "set");
6502 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6503                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6504                                 bonding, "bonding");
6505 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6506                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6507                                 mon_period,     "mon_period");
6508 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6509                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6510                                 port_num, UINT16);
6511 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6512                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6513                                 period_ms, UINT32);
6514
6515 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6516                 .f = cmd_set_bond_mon_period_parsed,
6517                 .data = (void *) 0,
6518                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6519                 .tokens = {
6520                                 (void *)&cmd_set_bond_mon_period_set,
6521                                 (void *)&cmd_set_bond_mon_period_bonding,
6522                                 (void *)&cmd_set_bond_mon_period_mon_period,
6523                                 (void *)&cmd_set_bond_mon_period_portnum,
6524                                 (void *)&cmd_set_bond_mon_period_period_ms,
6525                                 NULL
6526                 }
6527 };
6528
6529
6530
6531 struct cmd_set_bonding_agg_mode_policy_result {
6532         cmdline_fixed_string_t set;
6533         cmdline_fixed_string_t bonding;
6534         cmdline_fixed_string_t agg_mode;
6535         uint16_t port_num;
6536         cmdline_fixed_string_t policy;
6537 };
6538
6539
6540 static void
6541 cmd_set_bonding_agg_mode(void *parsed_result,
6542                 __rte_unused struct cmdline *cl,
6543                 __rte_unused void *data)
6544 {
6545         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6546         uint8_t policy = AGG_BANDWIDTH;
6547
6548         if (!strcmp(res->policy, "bandwidth"))
6549                 policy = AGG_BANDWIDTH;
6550         else if (!strcmp(res->policy, "stable"))
6551                 policy = AGG_STABLE;
6552         else if (!strcmp(res->policy, "count"))
6553                 policy = AGG_COUNT;
6554
6555         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6556 }
6557
6558
6559 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6560         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6561                                 set, "set");
6562 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6563         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6564                                 bonding, "bonding");
6565
6566 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6567         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6568                                 agg_mode, "agg_mode");
6569
6570 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6571         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6572                                 port_num, UINT16);
6573
6574 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6575         TOKEN_STRING_INITIALIZER(
6576                         struct cmd_set_bonding_balance_xmit_policy_result,
6577                 policy, "stable#bandwidth#count");
6578
6579 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6580         .f = cmd_set_bonding_agg_mode,
6581         .data = (void *) 0,
6582         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6583         .tokens = {
6584                         (void *)&cmd_set_bonding_agg_mode_set,
6585                         (void *)&cmd_set_bonding_agg_mode_bonding,
6586                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6587                         (void *)&cmd_set_bonding_agg_mode_portnum,
6588                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6589                         NULL
6590                 }
6591 };
6592
6593
6594 #endif /* RTE_NET_BOND */
6595
6596 /* *** SET FORWARDING MODE *** */
6597 struct cmd_set_fwd_mode_result {
6598         cmdline_fixed_string_t set;
6599         cmdline_fixed_string_t fwd;
6600         cmdline_fixed_string_t mode;
6601 };
6602
6603 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6604                                     __rte_unused struct cmdline *cl,
6605                                     __rte_unused void *data)
6606 {
6607         struct cmd_set_fwd_mode_result *res = parsed_result;
6608
6609         retry_enabled = 0;
6610         set_pkt_forwarding_mode(res->mode);
6611 }
6612
6613 cmdline_parse_token_string_t cmd_setfwd_set =
6614         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6615 cmdline_parse_token_string_t cmd_setfwd_fwd =
6616         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6617 cmdline_parse_token_string_t cmd_setfwd_mode =
6618         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6619                 "" /* defined at init */);
6620
6621 cmdline_parse_inst_t cmd_set_fwd_mode = {
6622         .f = cmd_set_fwd_mode_parsed,
6623         .data = NULL,
6624         .help_str = NULL, /* defined at init */
6625         .tokens = {
6626                 (void *)&cmd_setfwd_set,
6627                 (void *)&cmd_setfwd_fwd,
6628                 (void *)&cmd_setfwd_mode,
6629                 NULL,
6630         },
6631 };
6632
6633 static void cmd_set_fwd_mode_init(void)
6634 {
6635         char *modes, *c;
6636         static char token[128];
6637         static char help[256];
6638         cmdline_parse_token_string_t *token_struct;
6639
6640         modes = list_pkt_forwarding_modes();
6641         snprintf(help, sizeof(help), "set fwd %s: "
6642                 "Set packet forwarding mode", modes);
6643         cmd_set_fwd_mode.help_str = help;
6644
6645         /* string token separator is # */
6646         for (c = token; *modes != '\0'; modes++)
6647                 if (*modes == '|')
6648                         *c++ = '#';
6649                 else
6650                         *c++ = *modes;
6651         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6652         token_struct->string_data.str = token;
6653 }
6654
6655 /* *** SET RETRY FORWARDING MODE *** */
6656 struct cmd_set_fwd_retry_mode_result {
6657         cmdline_fixed_string_t set;
6658         cmdline_fixed_string_t fwd;
6659         cmdline_fixed_string_t mode;
6660         cmdline_fixed_string_t retry;
6661 };
6662
6663 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6664                             __rte_unused struct cmdline *cl,
6665                             __rte_unused void *data)
6666 {
6667         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6668
6669         retry_enabled = 1;
6670         set_pkt_forwarding_mode(res->mode);
6671 }
6672
6673 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6674         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6675                         set, "set");
6676 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6677         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6678                         fwd, "fwd");
6679 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6680         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6681                         mode,
6682                 "" /* defined at init */);
6683 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6684         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6685                         retry, "retry");
6686
6687 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6688         .f = cmd_set_fwd_retry_mode_parsed,
6689         .data = NULL,
6690         .help_str = NULL, /* defined at init */
6691         .tokens = {
6692                 (void *)&cmd_setfwd_retry_set,
6693                 (void *)&cmd_setfwd_retry_fwd,
6694                 (void *)&cmd_setfwd_retry_mode,
6695                 (void *)&cmd_setfwd_retry_retry,
6696                 NULL,
6697         },
6698 };
6699
6700 static void cmd_set_fwd_retry_mode_init(void)
6701 {
6702         char *modes, *c;
6703         static char token[128];
6704         static char help[256];
6705         cmdline_parse_token_string_t *token_struct;
6706
6707         modes = list_pkt_forwarding_retry_modes();
6708         snprintf(help, sizeof(help), "set fwd %s retry: "
6709                 "Set packet forwarding mode with retry", modes);
6710         cmd_set_fwd_retry_mode.help_str = help;
6711
6712         /* string token separator is # */
6713         for (c = token; *modes != '\0'; modes++)
6714                 if (*modes == '|')
6715                         *c++ = '#';
6716                 else
6717                         *c++ = *modes;
6718         token_struct = (cmdline_parse_token_string_t *)
6719                 cmd_set_fwd_retry_mode.tokens[2];
6720         token_struct->string_data.str = token;
6721 }
6722
6723 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6724 struct cmd_set_burst_tx_retry_result {
6725         cmdline_fixed_string_t set;
6726         cmdline_fixed_string_t burst;
6727         cmdline_fixed_string_t tx;
6728         cmdline_fixed_string_t delay;
6729         uint32_t time;
6730         cmdline_fixed_string_t retry;
6731         uint32_t retry_num;
6732 };
6733
6734 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6735                                         __rte_unused struct cmdline *cl,
6736                                         __rte_unused void *data)
6737 {
6738         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6739
6740         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6741                 && !strcmp(res->tx, "tx")) {
6742                 if (!strcmp(res->delay, "delay"))
6743                         burst_tx_delay_time = res->time;
6744                 if (!strcmp(res->retry, "retry"))
6745                         burst_tx_retry_num = res->retry_num;
6746         }
6747
6748 }
6749
6750 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6751         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6752 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6753         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6754                                  "burst");
6755 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6756         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6757 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6758         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6759 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6760         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6761 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6762         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6763 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6764         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6765
6766 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6767         .f = cmd_set_burst_tx_retry_parsed,
6768         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6769         .tokens = {
6770                 (void *)&cmd_set_burst_tx_retry_set,
6771                 (void *)&cmd_set_burst_tx_retry_burst,
6772                 (void *)&cmd_set_burst_tx_retry_tx,
6773                 (void *)&cmd_set_burst_tx_retry_delay,
6774                 (void *)&cmd_set_burst_tx_retry_time,
6775                 (void *)&cmd_set_burst_tx_retry_retry,
6776                 (void *)&cmd_set_burst_tx_retry_retry_num,
6777                 NULL,
6778         },
6779 };
6780
6781 /* *** SET PROMISC MODE *** */
6782 struct cmd_set_promisc_mode_result {
6783         cmdline_fixed_string_t set;
6784         cmdline_fixed_string_t promisc;
6785         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6786         uint16_t port_num;               /* valid if "allports" argument == 0 */
6787         cmdline_fixed_string_t mode;
6788 };
6789
6790 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6791                                         __rte_unused struct cmdline *cl,
6792                                         void *allports)
6793 {
6794         struct cmd_set_promisc_mode_result *res = parsed_result;
6795         int enable;
6796         portid_t i;
6797
6798         if (!strcmp(res->mode, "on"))
6799                 enable = 1;
6800         else
6801                 enable = 0;
6802
6803         /* all ports */
6804         if (allports) {
6805                 RTE_ETH_FOREACH_DEV(i)
6806                         eth_set_promisc_mode(i, enable);
6807         } else {
6808                 eth_set_promisc_mode(res->port_num, enable);
6809         }
6810 }
6811
6812 cmdline_parse_token_string_t cmd_setpromisc_set =
6813         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6814 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6815         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6816                                  "promisc");
6817 cmdline_parse_token_string_t cmd_setpromisc_portall =
6818         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6819                                  "all");
6820 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6821         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6822                               UINT16);
6823 cmdline_parse_token_string_t cmd_setpromisc_mode =
6824         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6825                                  "on#off");
6826
6827 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6828         .f = cmd_set_promisc_mode_parsed,
6829         .data = (void *)1,
6830         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6831         .tokens = {
6832                 (void *)&cmd_setpromisc_set,
6833                 (void *)&cmd_setpromisc_promisc,
6834                 (void *)&cmd_setpromisc_portall,
6835                 (void *)&cmd_setpromisc_mode,
6836                 NULL,
6837         },
6838 };
6839
6840 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6841         .f = cmd_set_promisc_mode_parsed,
6842         .data = (void *)0,
6843         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6844         .tokens = {
6845                 (void *)&cmd_setpromisc_set,
6846                 (void *)&cmd_setpromisc_promisc,
6847                 (void *)&cmd_setpromisc_portnum,
6848                 (void *)&cmd_setpromisc_mode,
6849                 NULL,
6850         },
6851 };
6852
6853 /* *** SET ALLMULTI MODE *** */
6854 struct cmd_set_allmulti_mode_result {
6855         cmdline_fixed_string_t set;
6856         cmdline_fixed_string_t allmulti;
6857         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6858         uint16_t port_num;               /* valid if "allports" argument == 0 */
6859         cmdline_fixed_string_t mode;
6860 };
6861
6862 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6863                                         __rte_unused struct cmdline *cl,
6864                                         void *allports)
6865 {
6866         struct cmd_set_allmulti_mode_result *res = parsed_result;
6867         int enable;
6868         portid_t i;
6869
6870         if (!strcmp(res->mode, "on"))
6871                 enable = 1;
6872         else
6873                 enable = 0;
6874
6875         /* all ports */
6876         if (allports) {
6877                 RTE_ETH_FOREACH_DEV(i) {
6878                         eth_set_allmulticast_mode(i, enable);
6879                 }
6880         }
6881         else {
6882                 eth_set_allmulticast_mode(res->port_num, enable);
6883         }
6884 }
6885
6886 cmdline_parse_token_string_t cmd_setallmulti_set =
6887         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6888 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6889         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6890                                  "allmulti");
6891 cmdline_parse_token_string_t cmd_setallmulti_portall =
6892         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6893                                  "all");
6894 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6895         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6896                               UINT16);
6897 cmdline_parse_token_string_t cmd_setallmulti_mode =
6898         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6899                                  "on#off");
6900
6901 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6902         .f = cmd_set_allmulti_mode_parsed,
6903         .data = (void *)1,
6904         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6905         .tokens = {
6906                 (void *)&cmd_setallmulti_set,
6907                 (void *)&cmd_setallmulti_allmulti,
6908                 (void *)&cmd_setallmulti_portall,
6909                 (void *)&cmd_setallmulti_mode,
6910                 NULL,
6911         },
6912 };
6913
6914 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6915         .f = cmd_set_allmulti_mode_parsed,
6916         .data = (void *)0,
6917         .help_str = "set allmulti <port_id> on|off: "
6918                 "Set allmulti mode on port_id",
6919         .tokens = {
6920                 (void *)&cmd_setallmulti_set,
6921                 (void *)&cmd_setallmulti_allmulti,
6922                 (void *)&cmd_setallmulti_portnum,
6923                 (void *)&cmd_setallmulti_mode,
6924                 NULL,
6925         },
6926 };
6927
6928 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6929 struct cmd_link_flow_ctrl_set_result {
6930         cmdline_fixed_string_t set;
6931         cmdline_fixed_string_t flow_ctrl;
6932         cmdline_fixed_string_t rx;
6933         cmdline_fixed_string_t rx_lfc_mode;
6934         cmdline_fixed_string_t tx;
6935         cmdline_fixed_string_t tx_lfc_mode;
6936         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6937         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6938         cmdline_fixed_string_t autoneg_str;
6939         cmdline_fixed_string_t autoneg;
6940         cmdline_fixed_string_t hw_str;
6941         uint32_t high_water;
6942         cmdline_fixed_string_t lw_str;
6943         uint32_t low_water;
6944         cmdline_fixed_string_t pt_str;
6945         uint16_t pause_time;
6946         cmdline_fixed_string_t xon_str;
6947         uint16_t send_xon;
6948         portid_t port_id;
6949 };
6950
6951 cmdline_parse_token_string_t cmd_lfc_set_set =
6952         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6953                                 set, "set");
6954 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6955         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6956                                 flow_ctrl, "flow_ctrl");
6957 cmdline_parse_token_string_t cmd_lfc_set_rx =
6958         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6959                                 rx, "rx");
6960 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6961         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6962                                 rx_lfc_mode, "on#off");
6963 cmdline_parse_token_string_t cmd_lfc_set_tx =
6964         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6965                                 tx, "tx");
6966 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6967         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6968                                 tx_lfc_mode, "on#off");
6969 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6970         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6971                                 hw_str, "high_water");
6972 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6973         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6974                                 high_water, UINT32);
6975 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6976         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6977                                 lw_str, "low_water");
6978 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6979         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6980                                 low_water, UINT32);
6981 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6982         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6983                                 pt_str, "pause_time");
6984 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6985         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6986                                 pause_time, UINT16);
6987 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6988         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6989                                 xon_str, "send_xon");
6990 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6991         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6992                                 send_xon, UINT16);
6993 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6994         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6995                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6996 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6997         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6998                                 mac_ctrl_frame_fwd_mode, "on#off");
6999 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7000         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7001                                 autoneg_str, "autoneg");
7002 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7003         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7004                                 autoneg, "on#off");
7005 cmdline_parse_token_num_t cmd_lfc_set_portid =
7006         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7007                                 port_id, UINT16);
7008
7009 /* forward declaration */
7010 static void
7011 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7012                               void *data);
7013
7014 cmdline_parse_inst_t cmd_link_flow_control_set = {
7015         .f = cmd_link_flow_ctrl_set_parsed,
7016         .data = NULL,
7017         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7018                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7019                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7020         .tokens = {
7021                 (void *)&cmd_lfc_set_set,
7022                 (void *)&cmd_lfc_set_flow_ctrl,
7023                 (void *)&cmd_lfc_set_rx,
7024                 (void *)&cmd_lfc_set_rx_mode,
7025                 (void *)&cmd_lfc_set_tx,
7026                 (void *)&cmd_lfc_set_tx_mode,
7027                 (void *)&cmd_lfc_set_high_water,
7028                 (void *)&cmd_lfc_set_low_water,
7029                 (void *)&cmd_lfc_set_pause_time,
7030                 (void *)&cmd_lfc_set_send_xon,
7031                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7032                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7033                 (void *)&cmd_lfc_set_autoneg_str,
7034                 (void *)&cmd_lfc_set_autoneg,
7035                 (void *)&cmd_lfc_set_portid,
7036                 NULL,
7037         },
7038 };
7039
7040 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7041         .f = cmd_link_flow_ctrl_set_parsed,
7042         .data = (void *)&cmd_link_flow_control_set_rx,
7043         .help_str = "set flow_ctrl rx on|off <port_id>: "
7044                 "Change rx flow control parameter",
7045         .tokens = {
7046                 (void *)&cmd_lfc_set_set,
7047                 (void *)&cmd_lfc_set_flow_ctrl,
7048                 (void *)&cmd_lfc_set_rx,
7049                 (void *)&cmd_lfc_set_rx_mode,
7050                 (void *)&cmd_lfc_set_portid,
7051                 NULL,
7052         },
7053 };
7054
7055 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7056         .f = cmd_link_flow_ctrl_set_parsed,
7057         .data = (void *)&cmd_link_flow_control_set_tx,
7058         .help_str = "set flow_ctrl tx on|off <port_id>: "
7059                 "Change tx flow control parameter",
7060         .tokens = {
7061                 (void *)&cmd_lfc_set_set,
7062                 (void *)&cmd_lfc_set_flow_ctrl,
7063                 (void *)&cmd_lfc_set_tx,
7064                 (void *)&cmd_lfc_set_tx_mode,
7065                 (void *)&cmd_lfc_set_portid,
7066                 NULL,
7067         },
7068 };
7069
7070 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7071         .f = cmd_link_flow_ctrl_set_parsed,
7072         .data = (void *)&cmd_link_flow_control_set_hw,
7073         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7074                 "Change high water flow control parameter",
7075         .tokens = {
7076                 (void *)&cmd_lfc_set_set,
7077                 (void *)&cmd_lfc_set_flow_ctrl,
7078                 (void *)&cmd_lfc_set_high_water_str,
7079                 (void *)&cmd_lfc_set_high_water,
7080                 (void *)&cmd_lfc_set_portid,
7081                 NULL,
7082         },
7083 };
7084
7085 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7086         .f = cmd_link_flow_ctrl_set_parsed,
7087         .data = (void *)&cmd_link_flow_control_set_lw,
7088         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7089                 "Change low water flow control parameter",
7090         .tokens = {
7091                 (void *)&cmd_lfc_set_set,
7092                 (void *)&cmd_lfc_set_flow_ctrl,
7093                 (void *)&cmd_lfc_set_low_water_str,
7094                 (void *)&cmd_lfc_set_low_water,
7095                 (void *)&cmd_lfc_set_portid,
7096                 NULL,
7097         },
7098 };
7099
7100 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7101         .f = cmd_link_flow_ctrl_set_parsed,
7102         .data = (void *)&cmd_link_flow_control_set_pt,
7103         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7104                 "Change pause time flow control parameter",
7105         .tokens = {
7106                 (void *)&cmd_lfc_set_set,
7107                 (void *)&cmd_lfc_set_flow_ctrl,
7108                 (void *)&cmd_lfc_set_pause_time_str,
7109                 (void *)&cmd_lfc_set_pause_time,
7110                 (void *)&cmd_lfc_set_portid,
7111                 NULL,
7112         },
7113 };
7114
7115 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7116         .f = cmd_link_flow_ctrl_set_parsed,
7117         .data = (void *)&cmd_link_flow_control_set_xon,
7118         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7119                 "Change send_xon flow control parameter",
7120         .tokens = {
7121                 (void *)&cmd_lfc_set_set,
7122                 (void *)&cmd_lfc_set_flow_ctrl,
7123                 (void *)&cmd_lfc_set_send_xon_str,
7124                 (void *)&cmd_lfc_set_send_xon,
7125                 (void *)&cmd_lfc_set_portid,
7126                 NULL,
7127         },
7128 };
7129
7130 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7131         .f = cmd_link_flow_ctrl_set_parsed,
7132         .data = (void *)&cmd_link_flow_control_set_macfwd,
7133         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7134                 "Change mac ctrl fwd flow control parameter",
7135         .tokens = {
7136                 (void *)&cmd_lfc_set_set,
7137                 (void *)&cmd_lfc_set_flow_ctrl,
7138                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7139                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7140                 (void *)&cmd_lfc_set_portid,
7141                 NULL,
7142         },
7143 };
7144
7145 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7146         .f = cmd_link_flow_ctrl_set_parsed,
7147         .data = (void *)&cmd_link_flow_control_set_autoneg,
7148         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7149                 "Change autoneg flow control parameter",
7150         .tokens = {
7151                 (void *)&cmd_lfc_set_set,
7152                 (void *)&cmd_lfc_set_flow_ctrl,
7153                 (void *)&cmd_lfc_set_autoneg_str,
7154                 (void *)&cmd_lfc_set_autoneg,
7155                 (void *)&cmd_lfc_set_portid,
7156                 NULL,
7157         },
7158 };
7159
7160 static void
7161 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7162                               __rte_unused struct cmdline *cl,
7163                               void *data)
7164 {
7165         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7166         cmdline_parse_inst_t *cmd = data;
7167         struct rte_eth_fc_conf fc_conf;
7168         int rx_fc_en = 0;
7169         int tx_fc_en = 0;
7170         int ret;
7171
7172         /*
7173          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7174          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7175          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7176          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7177          */
7178         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7179                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7180         };
7181
7182         /* Partial command line, retrieve current configuration */
7183         if (cmd) {
7184                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7185                 if (ret != 0) {
7186                         printf("cannot get current flow ctrl parameters, return"
7187                                "code = %d\n", ret);
7188                         return;
7189                 }
7190
7191                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7192                     (fc_conf.mode == RTE_FC_FULL))
7193                         rx_fc_en = 1;
7194                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7195                     (fc_conf.mode == RTE_FC_FULL))
7196                         tx_fc_en = 1;
7197         }
7198
7199         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7200                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7201
7202         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7203                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7204
7205         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7206
7207         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7208                 fc_conf.high_water = res->high_water;
7209
7210         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7211                 fc_conf.low_water = res->low_water;
7212
7213         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7214                 fc_conf.pause_time = res->pause_time;
7215
7216         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7217                 fc_conf.send_xon = res->send_xon;
7218
7219         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7220                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7221                         fc_conf.mac_ctrl_frame_fwd = 1;
7222                 else
7223                         fc_conf.mac_ctrl_frame_fwd = 0;
7224         }
7225
7226         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7227                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7228
7229         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7230         if (ret != 0)
7231                 printf("bad flow contrl parameter, return code = %d \n", ret);
7232 }
7233
7234 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7235 struct cmd_priority_flow_ctrl_set_result {
7236         cmdline_fixed_string_t set;
7237         cmdline_fixed_string_t pfc_ctrl;
7238         cmdline_fixed_string_t rx;
7239         cmdline_fixed_string_t rx_pfc_mode;
7240         cmdline_fixed_string_t tx;
7241         cmdline_fixed_string_t tx_pfc_mode;
7242         uint32_t high_water;
7243         uint32_t low_water;
7244         uint16_t pause_time;
7245         uint8_t  priority;
7246         portid_t port_id;
7247 };
7248
7249 static void
7250 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7251                        __rte_unused struct cmdline *cl,
7252                        __rte_unused void *data)
7253 {
7254         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7255         struct rte_eth_pfc_conf pfc_conf;
7256         int rx_fc_enable, tx_fc_enable;
7257         int ret;
7258
7259         /*
7260          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7261          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7262          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7263          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7264          */
7265         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7266                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7267         };
7268
7269         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7270         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7271         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7272         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7273         pfc_conf.fc.high_water = res->high_water;
7274         pfc_conf.fc.low_water  = res->low_water;
7275         pfc_conf.fc.pause_time = res->pause_time;
7276         pfc_conf.priority      = res->priority;
7277
7278         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7279         if (ret != 0)
7280                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7281 }
7282
7283 cmdline_parse_token_string_t cmd_pfc_set_set =
7284         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7285                                 set, "set");
7286 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7287         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7288                                 pfc_ctrl, "pfc_ctrl");
7289 cmdline_parse_token_string_t cmd_pfc_set_rx =
7290         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7291                                 rx, "rx");
7292 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7293         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7294                                 rx_pfc_mode, "on#off");
7295 cmdline_parse_token_string_t cmd_pfc_set_tx =
7296         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7297                                 tx, "tx");
7298 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7299         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7300                                 tx_pfc_mode, "on#off");
7301 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7302         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7303                                 high_water, UINT32);
7304 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7305         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7306                                 low_water, UINT32);
7307 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7308         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7309                                 pause_time, UINT16);
7310 cmdline_parse_token_num_t cmd_pfc_set_priority =
7311         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7312                                 priority, UINT8);
7313 cmdline_parse_token_num_t cmd_pfc_set_portid =
7314         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7315                                 port_id, UINT16);
7316
7317 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7318         .f = cmd_priority_flow_ctrl_set_parsed,
7319         .data = NULL,
7320         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7321                 "<pause_time> <priority> <port_id>: "
7322                 "Configure the Ethernet priority flow control",
7323         .tokens = {
7324                 (void *)&cmd_pfc_set_set,
7325                 (void *)&cmd_pfc_set_flow_ctrl,
7326                 (void *)&cmd_pfc_set_rx,
7327                 (void *)&cmd_pfc_set_rx_mode,
7328                 (void *)&cmd_pfc_set_tx,
7329                 (void *)&cmd_pfc_set_tx_mode,
7330                 (void *)&cmd_pfc_set_high_water,
7331                 (void *)&cmd_pfc_set_low_water,
7332                 (void *)&cmd_pfc_set_pause_time,
7333                 (void *)&cmd_pfc_set_priority,
7334                 (void *)&cmd_pfc_set_portid,
7335                 NULL,
7336         },
7337 };
7338
7339 /* *** RESET CONFIGURATION *** */
7340 struct cmd_reset_result {
7341         cmdline_fixed_string_t reset;
7342         cmdline_fixed_string_t def;
7343 };
7344
7345 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7346                              struct cmdline *cl,
7347                              __rte_unused void *data)
7348 {
7349         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7350         set_def_fwd_config();
7351 }
7352
7353 cmdline_parse_token_string_t cmd_reset_set =
7354         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7355 cmdline_parse_token_string_t cmd_reset_def =
7356         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7357                                  "default");
7358
7359 cmdline_parse_inst_t cmd_reset = {
7360         .f = cmd_reset_parsed,
7361         .data = NULL,
7362         .help_str = "set default: Reset default forwarding configuration",
7363         .tokens = {
7364                 (void *)&cmd_reset_set,
7365                 (void *)&cmd_reset_def,
7366                 NULL,
7367         },
7368 };
7369
7370 /* *** START FORWARDING *** */
7371 struct cmd_start_result {
7372         cmdline_fixed_string_t start;
7373 };
7374
7375 cmdline_parse_token_string_t cmd_start_start =
7376         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7377
7378 static void cmd_start_parsed(__rte_unused void *parsed_result,
7379                              __rte_unused struct cmdline *cl,
7380                              __rte_unused void *data)
7381 {
7382         start_packet_forwarding(0);
7383 }
7384
7385 cmdline_parse_inst_t cmd_start = {
7386         .f = cmd_start_parsed,
7387         .data = NULL,
7388         .help_str = "start: Start packet forwarding",
7389         .tokens = {
7390                 (void *)&cmd_start_start,
7391                 NULL,
7392         },
7393 };
7394
7395 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7396 struct cmd_start_tx_first_result {
7397         cmdline_fixed_string_t start;
7398         cmdline_fixed_string_t tx_first;
7399 };
7400
7401 static void
7402 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7403                           __rte_unused struct cmdline *cl,
7404                           __rte_unused void *data)
7405 {
7406         start_packet_forwarding(1);
7407 }
7408
7409 cmdline_parse_token_string_t cmd_start_tx_first_start =
7410         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7411                                  "start");
7412 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7413         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7414                                  tx_first, "tx_first");
7415
7416 cmdline_parse_inst_t cmd_start_tx_first = {
7417         .f = cmd_start_tx_first_parsed,
7418         .data = NULL,
7419         .help_str = "start tx_first: Start packet forwarding, "
7420                 "after sending 1 burst of packets",
7421         .tokens = {
7422                 (void *)&cmd_start_tx_first_start,
7423                 (void *)&cmd_start_tx_first_tx_first,
7424                 NULL,
7425         },
7426 };
7427
7428 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7429 struct cmd_start_tx_first_n_result {
7430         cmdline_fixed_string_t start;
7431         cmdline_fixed_string_t tx_first;
7432         uint32_t tx_num;
7433 };
7434
7435 static void
7436 cmd_start_tx_first_n_parsed(void *parsed_result,
7437                           __rte_unused struct cmdline *cl,
7438                           __rte_unused void *data)
7439 {
7440         struct cmd_start_tx_first_n_result *res = parsed_result;
7441
7442         start_packet_forwarding(res->tx_num);
7443 }
7444
7445 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7446         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7447                         start, "start");
7448 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7449         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7450                         tx_first, "tx_first");
7451 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7452         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7453                         tx_num, UINT32);
7454
7455 cmdline_parse_inst_t cmd_start_tx_first_n = {
7456         .f = cmd_start_tx_first_n_parsed,
7457         .data = NULL,
7458         .help_str = "start tx_first <num>: "
7459                 "packet forwarding, after sending <num> bursts of packets",
7460         .tokens = {
7461                 (void *)&cmd_start_tx_first_n_start,
7462                 (void *)&cmd_start_tx_first_n_tx_first,
7463                 (void *)&cmd_start_tx_first_n_tx_num,
7464                 NULL,
7465         },
7466 };
7467
7468 /* *** SET LINK UP *** */
7469 struct cmd_set_link_up_result {
7470         cmdline_fixed_string_t set;
7471         cmdline_fixed_string_t link_up;
7472         cmdline_fixed_string_t port;
7473         portid_t port_id;
7474 };
7475
7476 cmdline_parse_token_string_t cmd_set_link_up_set =
7477         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7478 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7479         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7480                                 "link-up");
7481 cmdline_parse_token_string_t cmd_set_link_up_port =
7482         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7483 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7484         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7485
7486 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7487                              __rte_unused struct cmdline *cl,
7488                              __rte_unused void *data)
7489 {
7490         struct cmd_set_link_up_result *res = parsed_result;
7491         dev_set_link_up(res->port_id);
7492 }
7493
7494 cmdline_parse_inst_t cmd_set_link_up = {
7495         .f = cmd_set_link_up_parsed,
7496         .data = NULL,
7497         .help_str = "set link-up port <port id>",
7498         .tokens = {
7499                 (void *)&cmd_set_link_up_set,
7500                 (void *)&cmd_set_link_up_link_up,
7501                 (void *)&cmd_set_link_up_port,
7502                 (void *)&cmd_set_link_up_port_id,
7503                 NULL,
7504         },
7505 };
7506
7507 /* *** SET LINK DOWN *** */
7508 struct cmd_set_link_down_result {
7509         cmdline_fixed_string_t set;
7510         cmdline_fixed_string_t link_down;
7511         cmdline_fixed_string_t port;
7512         portid_t port_id;
7513 };
7514
7515 cmdline_parse_token_string_t cmd_set_link_down_set =
7516         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7517 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7518         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7519                                 "link-down");
7520 cmdline_parse_token_string_t cmd_set_link_down_port =
7521         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7522 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7523         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7524
7525 static void cmd_set_link_down_parsed(
7526                                 __rte_unused void *parsed_result,
7527                                 __rte_unused struct cmdline *cl,
7528                                 __rte_unused void *data)
7529 {
7530         struct cmd_set_link_down_result *res = parsed_result;
7531         dev_set_link_down(res->port_id);
7532 }
7533
7534 cmdline_parse_inst_t cmd_set_link_down = {
7535         .f = cmd_set_link_down_parsed,
7536         .data = NULL,
7537         .help_str = "set link-down port <port id>",
7538         .tokens = {
7539                 (void *)&cmd_set_link_down_set,
7540                 (void *)&cmd_set_link_down_link_down,
7541                 (void *)&cmd_set_link_down_port,
7542                 (void *)&cmd_set_link_down_port_id,
7543                 NULL,
7544         },
7545 };
7546
7547 /* *** SHOW CFG *** */
7548 struct cmd_showcfg_result {
7549         cmdline_fixed_string_t show;
7550         cmdline_fixed_string_t cfg;
7551         cmdline_fixed_string_t what;
7552 };
7553
7554 static void cmd_showcfg_parsed(void *parsed_result,
7555                                __rte_unused struct cmdline *cl,
7556                                __rte_unused void *data)
7557 {
7558         struct cmd_showcfg_result *res = parsed_result;
7559         if (!strcmp(res->what, "rxtx"))
7560                 rxtx_config_display();
7561         else if (!strcmp(res->what, "cores"))
7562                 fwd_lcores_config_display();
7563         else if (!strcmp(res->what, "fwd"))
7564                 pkt_fwd_config_display(&cur_fwd_config);
7565         else if (!strcmp(res->what, "rxoffs"))
7566                 show_rx_pkt_offsets();
7567         else if (!strcmp(res->what, "rxpkts"))
7568                 show_rx_pkt_segments();
7569         else if (!strcmp(res->what, "txpkts"))
7570                 show_tx_pkt_segments();
7571         else if (!strcmp(res->what, "txtimes"))
7572                 show_tx_pkt_times();
7573 }
7574
7575 cmdline_parse_token_string_t cmd_showcfg_show =
7576         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7577 cmdline_parse_token_string_t cmd_showcfg_port =
7578         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7579 cmdline_parse_token_string_t cmd_showcfg_what =
7580         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7581                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7582
7583 cmdline_parse_inst_t cmd_showcfg = {
7584         .f = cmd_showcfg_parsed,
7585         .data = NULL,
7586         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7587         .tokens = {
7588                 (void *)&cmd_showcfg_show,
7589                 (void *)&cmd_showcfg_port,
7590                 (void *)&cmd_showcfg_what,
7591                 NULL,
7592         },
7593 };
7594
7595 /* *** SHOW ALL PORT INFO *** */
7596 struct cmd_showportall_result {
7597         cmdline_fixed_string_t show;
7598         cmdline_fixed_string_t port;
7599         cmdline_fixed_string_t what;
7600         cmdline_fixed_string_t all;
7601 };
7602
7603 static void cmd_showportall_parsed(void *parsed_result,
7604                                 __rte_unused struct cmdline *cl,
7605                                 __rte_unused void *data)
7606 {
7607         portid_t i;
7608
7609         struct cmd_showportall_result *res = parsed_result;
7610         if (!strcmp(res->show, "clear")) {
7611                 if (!strcmp(res->what, "stats"))
7612                         RTE_ETH_FOREACH_DEV(i)
7613                                 nic_stats_clear(i);
7614                 else if (!strcmp(res->what, "xstats"))
7615                         RTE_ETH_FOREACH_DEV(i)
7616                                 nic_xstats_clear(i);
7617         } else if (!strcmp(res->what, "info"))
7618                 RTE_ETH_FOREACH_DEV(i)
7619                         port_infos_display(i);
7620         else if (!strcmp(res->what, "summary")) {
7621                 port_summary_header_display();
7622                 RTE_ETH_FOREACH_DEV(i)
7623                         port_summary_display(i);
7624         }
7625         else if (!strcmp(res->what, "stats"))
7626                 RTE_ETH_FOREACH_DEV(i)
7627                         nic_stats_display(i);
7628         else if (!strcmp(res->what, "xstats"))
7629                 RTE_ETH_FOREACH_DEV(i)
7630                         nic_xstats_display(i);
7631         else if (!strcmp(res->what, "fdir"))
7632                 RTE_ETH_FOREACH_DEV(i)
7633                         fdir_get_infos(i);
7634         else if (!strcmp(res->what, "stat_qmap"))
7635                 RTE_ETH_FOREACH_DEV(i)
7636                         nic_stats_mapping_display(i);
7637         else if (!strcmp(res->what, "dcb_tc"))
7638                 RTE_ETH_FOREACH_DEV(i)
7639                         port_dcb_info_display(i);
7640         else if (!strcmp(res->what, "cap"))
7641                 RTE_ETH_FOREACH_DEV(i)
7642                         port_offload_cap_display(i);
7643 }
7644
7645 cmdline_parse_token_string_t cmd_showportall_show =
7646         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7647                                  "show#clear");
7648 cmdline_parse_token_string_t cmd_showportall_port =
7649         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7650 cmdline_parse_token_string_t cmd_showportall_what =
7651         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7652                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7653 cmdline_parse_token_string_t cmd_showportall_all =
7654         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7655 cmdline_parse_inst_t cmd_showportall = {
7656         .f = cmd_showportall_parsed,
7657         .data = NULL,
7658         .help_str = "show|clear port "
7659                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7660         .tokens = {
7661                 (void *)&cmd_showportall_show,
7662                 (void *)&cmd_showportall_port,
7663                 (void *)&cmd_showportall_what,
7664                 (void *)&cmd_showportall_all,
7665                 NULL,
7666         },
7667 };
7668
7669 /* *** SHOW PORT INFO *** */
7670 struct cmd_showport_result {
7671         cmdline_fixed_string_t show;
7672         cmdline_fixed_string_t port;
7673         cmdline_fixed_string_t what;
7674         uint16_t portnum;
7675 };
7676
7677 static void cmd_showport_parsed(void *parsed_result,
7678                                 __rte_unused struct cmdline *cl,
7679                                 __rte_unused void *data)
7680 {
7681         struct cmd_showport_result *res = parsed_result;
7682         if (!strcmp(res->show, "clear")) {
7683                 if (!strcmp(res->what, "stats"))
7684                         nic_stats_clear(res->portnum);
7685                 else if (!strcmp(res->what, "xstats"))
7686                         nic_xstats_clear(res->portnum);
7687         } else if (!strcmp(res->what, "info"))
7688                 port_infos_display(res->portnum);
7689         else if (!strcmp(res->what, "summary")) {
7690                 port_summary_header_display();
7691                 port_summary_display(res->portnum);
7692         }
7693         else if (!strcmp(res->what, "stats"))
7694                 nic_stats_display(res->portnum);
7695         else if (!strcmp(res->what, "xstats"))
7696                 nic_xstats_display(res->portnum);
7697         else if (!strcmp(res->what, "fdir"))
7698                  fdir_get_infos(res->portnum);
7699         else if (!strcmp(res->what, "stat_qmap"))
7700                 nic_stats_mapping_display(res->portnum);
7701         else if (!strcmp(res->what, "dcb_tc"))
7702                 port_dcb_info_display(res->portnum);
7703         else if (!strcmp(res->what, "cap"))
7704                 port_offload_cap_display(res->portnum);
7705 }
7706
7707 cmdline_parse_token_string_t cmd_showport_show =
7708         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7709                                  "show#clear");
7710 cmdline_parse_token_string_t cmd_showport_port =
7711         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7712 cmdline_parse_token_string_t cmd_showport_what =
7713         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7714                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7715 cmdline_parse_token_num_t cmd_showport_portnum =
7716         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7717
7718 cmdline_parse_inst_t cmd_showport = {
7719         .f = cmd_showport_parsed,
7720         .data = NULL,
7721         .help_str = "show|clear port "
7722                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7723                 "<port_id>",
7724         .tokens = {
7725                 (void *)&cmd_showport_show,
7726                 (void *)&cmd_showport_port,
7727                 (void *)&cmd_showport_what,
7728                 (void *)&cmd_showport_portnum,
7729                 NULL,
7730         },
7731 };
7732
7733 /* *** SHOW DEVICE INFO *** */
7734 struct cmd_showdevice_result {
7735         cmdline_fixed_string_t show;
7736         cmdline_fixed_string_t device;
7737         cmdline_fixed_string_t what;
7738         cmdline_fixed_string_t identifier;
7739 };
7740
7741 static void cmd_showdevice_parsed(void *parsed_result,
7742                                 __rte_unused struct cmdline *cl,
7743                                 __rte_unused void *data)
7744 {
7745         struct cmd_showdevice_result *res = parsed_result;
7746         if (!strcmp(res->what, "info")) {
7747                 if (!strcmp(res->identifier, "all"))
7748                         device_infos_display(NULL);
7749                 else
7750                         device_infos_display(res->identifier);
7751         }
7752 }
7753
7754 cmdline_parse_token_string_t cmd_showdevice_show =
7755         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7756                                  "show");
7757 cmdline_parse_token_string_t cmd_showdevice_device =
7758         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7759 cmdline_parse_token_string_t cmd_showdevice_what =
7760         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7761                                  "info");
7762 cmdline_parse_token_string_t cmd_showdevice_identifier =
7763         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7764                         identifier, NULL);
7765
7766 cmdline_parse_inst_t cmd_showdevice = {
7767         .f = cmd_showdevice_parsed,
7768         .data = NULL,
7769         .help_str = "show device info <identifier>|all",
7770         .tokens = {
7771                 (void *)&cmd_showdevice_show,
7772                 (void *)&cmd_showdevice_device,
7773                 (void *)&cmd_showdevice_what,
7774                 (void *)&cmd_showdevice_identifier,
7775                 NULL,
7776         },
7777 };
7778
7779 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7780 struct cmd_showeeprom_result {
7781         cmdline_fixed_string_t show;
7782         cmdline_fixed_string_t port;
7783         uint16_t portnum;
7784         cmdline_fixed_string_t type;
7785 };
7786
7787 static void cmd_showeeprom_parsed(void *parsed_result,
7788                 __rte_unused struct cmdline *cl,
7789                 __rte_unused void *data)
7790 {
7791         struct cmd_showeeprom_result *res = parsed_result;
7792
7793         if (!strcmp(res->type, "eeprom"))
7794                 port_eeprom_display(res->portnum);
7795         else if (!strcmp(res->type, "module_eeprom"))
7796                 port_module_eeprom_display(res->portnum);
7797         else
7798                 printf("Unknown argument\n");
7799 }
7800
7801 cmdline_parse_token_string_t cmd_showeeprom_show =
7802         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7803 cmdline_parse_token_string_t cmd_showeeprom_port =
7804         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7805 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7806         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7807 cmdline_parse_token_string_t cmd_showeeprom_type =
7808         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7809
7810 cmdline_parse_inst_t cmd_showeeprom = {
7811         .f = cmd_showeeprom_parsed,
7812         .data = NULL,
7813         .help_str = "show port <port_id> module_eeprom|eeprom",
7814         .tokens = {
7815                 (void *)&cmd_showeeprom_show,
7816                 (void *)&cmd_showeeprom_port,
7817                 (void *)&cmd_showeeprom_portnum,
7818                 (void *)&cmd_showeeprom_type,
7819                 NULL,
7820         },
7821 };
7822
7823 /* *** SHOW QUEUE INFO *** */
7824 struct cmd_showqueue_result {
7825         cmdline_fixed_string_t show;
7826         cmdline_fixed_string_t type;
7827         cmdline_fixed_string_t what;
7828         uint16_t portnum;
7829         uint16_t queuenum;
7830 };
7831
7832 static void
7833 cmd_showqueue_parsed(void *parsed_result,
7834         __rte_unused struct cmdline *cl,
7835         __rte_unused void *data)
7836 {
7837         struct cmd_showqueue_result *res = parsed_result;
7838
7839         if (!strcmp(res->type, "rxq"))
7840                 rx_queue_infos_display(res->portnum, res->queuenum);
7841         else if (!strcmp(res->type, "txq"))
7842                 tx_queue_infos_display(res->portnum, res->queuenum);
7843 }
7844
7845 cmdline_parse_token_string_t cmd_showqueue_show =
7846         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7847 cmdline_parse_token_string_t cmd_showqueue_type =
7848         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7849 cmdline_parse_token_string_t cmd_showqueue_what =
7850         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7851 cmdline_parse_token_num_t cmd_showqueue_portnum =
7852         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7853 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7854         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7855
7856 cmdline_parse_inst_t cmd_showqueue = {
7857         .f = cmd_showqueue_parsed,
7858         .data = NULL,
7859         .help_str = "show rxq|txq info <port_id> <queue_id>",
7860         .tokens = {
7861                 (void *)&cmd_showqueue_show,
7862                 (void *)&cmd_showqueue_type,
7863                 (void *)&cmd_showqueue_what,
7864                 (void *)&cmd_showqueue_portnum,
7865                 (void *)&cmd_showqueue_queuenum,
7866                 NULL,
7867         },
7868 };
7869
7870 /* show/clear fwd engine statistics */
7871 struct fwd_result {
7872         cmdline_fixed_string_t action;
7873         cmdline_fixed_string_t fwd;
7874         cmdline_fixed_string_t stats;
7875         cmdline_fixed_string_t all;
7876 };
7877
7878 cmdline_parse_token_string_t cmd_fwd_action =
7879         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7880 cmdline_parse_token_string_t cmd_fwd_fwd =
7881         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7882 cmdline_parse_token_string_t cmd_fwd_stats =
7883         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7884 cmdline_parse_token_string_t cmd_fwd_all =
7885         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7886
7887 static void
7888 cmd_showfwdall_parsed(void *parsed_result,
7889                       __rte_unused struct cmdline *cl,
7890                       __rte_unused void *data)
7891 {
7892         struct fwd_result *res = parsed_result;
7893
7894         if (!strcmp(res->action, "show"))
7895                 fwd_stats_display();
7896         else
7897                 fwd_stats_reset();
7898 }
7899
7900 static cmdline_parse_inst_t cmd_showfwdall = {
7901         .f = cmd_showfwdall_parsed,
7902         .data = NULL,
7903         .help_str = "show|clear fwd stats all",
7904         .tokens = {
7905                 (void *)&cmd_fwd_action,
7906                 (void *)&cmd_fwd_fwd,
7907                 (void *)&cmd_fwd_stats,
7908                 (void *)&cmd_fwd_all,
7909                 NULL,
7910         },
7911 };
7912
7913 /* *** READ PORT REGISTER *** */
7914 struct cmd_read_reg_result {
7915         cmdline_fixed_string_t read;
7916         cmdline_fixed_string_t reg;
7917         portid_t port_id;
7918         uint32_t reg_off;
7919 };
7920
7921 static void
7922 cmd_read_reg_parsed(void *parsed_result,
7923                     __rte_unused struct cmdline *cl,
7924                     __rte_unused void *data)
7925 {
7926         struct cmd_read_reg_result *res = parsed_result;
7927         port_reg_display(res->port_id, res->reg_off);
7928 }
7929
7930 cmdline_parse_token_string_t cmd_read_reg_read =
7931         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7932 cmdline_parse_token_string_t cmd_read_reg_reg =
7933         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7934 cmdline_parse_token_num_t cmd_read_reg_port_id =
7935         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7936 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7937         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7938
7939 cmdline_parse_inst_t cmd_read_reg = {
7940         .f = cmd_read_reg_parsed,
7941         .data = NULL,
7942         .help_str = "read reg <port_id> <reg_off>",
7943         .tokens = {
7944                 (void *)&cmd_read_reg_read,
7945                 (void *)&cmd_read_reg_reg,
7946                 (void *)&cmd_read_reg_port_id,
7947                 (void *)&cmd_read_reg_reg_off,
7948                 NULL,
7949         },
7950 };
7951
7952 /* *** READ PORT REGISTER BIT FIELD *** */
7953 struct cmd_read_reg_bit_field_result {
7954         cmdline_fixed_string_t read;
7955         cmdline_fixed_string_t regfield;
7956         portid_t port_id;
7957         uint32_t reg_off;
7958         uint8_t bit1_pos;
7959         uint8_t bit2_pos;
7960 };
7961
7962 static void
7963 cmd_read_reg_bit_field_parsed(void *parsed_result,
7964                               __rte_unused struct cmdline *cl,
7965                               __rte_unused void *data)
7966 {
7967         struct cmd_read_reg_bit_field_result *res = parsed_result;
7968         port_reg_bit_field_display(res->port_id, res->reg_off,
7969                                    res->bit1_pos, res->bit2_pos);
7970 }
7971
7972 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7973         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7974                                  "read");
7975 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7976         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7977                                  regfield, "regfield");
7978 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7979         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7980                               UINT16);
7981 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7982         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7983                               UINT32);
7984 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7985         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7986                               UINT8);
7987 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7988         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7989                               UINT8);
7990
7991 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7992         .f = cmd_read_reg_bit_field_parsed,
7993         .data = NULL,
7994         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7995         "Read register bit field between bit_x and bit_y included",
7996         .tokens = {
7997                 (void *)&cmd_read_reg_bit_field_read,
7998                 (void *)&cmd_read_reg_bit_field_regfield,
7999                 (void *)&cmd_read_reg_bit_field_port_id,
8000                 (void *)&cmd_read_reg_bit_field_reg_off,
8001                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8002                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8003                 NULL,
8004         },
8005 };
8006
8007 /* *** READ PORT REGISTER BIT *** */
8008 struct cmd_read_reg_bit_result {
8009         cmdline_fixed_string_t read;
8010         cmdline_fixed_string_t regbit;
8011         portid_t port_id;
8012         uint32_t reg_off;
8013         uint8_t bit_pos;
8014 };
8015
8016 static void
8017 cmd_read_reg_bit_parsed(void *parsed_result,
8018                         __rte_unused struct cmdline *cl,
8019                         __rte_unused void *data)
8020 {
8021         struct cmd_read_reg_bit_result *res = parsed_result;
8022         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8023 }
8024
8025 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8026         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8027 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8028         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8029                                  regbit, "regbit");
8030 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8031         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
8032 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8033         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
8034 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8035         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
8036
8037 cmdline_parse_inst_t cmd_read_reg_bit = {
8038         .f = cmd_read_reg_bit_parsed,
8039         .data = NULL,
8040         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8041         .tokens = {
8042                 (void *)&cmd_read_reg_bit_read,
8043                 (void *)&cmd_read_reg_bit_regbit,
8044                 (void *)&cmd_read_reg_bit_port_id,
8045                 (void *)&cmd_read_reg_bit_reg_off,
8046                 (void *)&cmd_read_reg_bit_bit_pos,
8047                 NULL,
8048         },
8049 };
8050
8051 /* *** WRITE PORT REGISTER *** */
8052 struct cmd_write_reg_result {
8053         cmdline_fixed_string_t write;
8054         cmdline_fixed_string_t reg;
8055         portid_t port_id;
8056         uint32_t reg_off;
8057         uint32_t value;
8058 };
8059
8060 static void
8061 cmd_write_reg_parsed(void *parsed_result,
8062                      __rte_unused struct cmdline *cl,
8063                      __rte_unused void *data)
8064 {
8065         struct cmd_write_reg_result *res = parsed_result;
8066         port_reg_set(res->port_id, res->reg_off, res->value);
8067 }
8068
8069 cmdline_parse_token_string_t cmd_write_reg_write =
8070         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8071 cmdline_parse_token_string_t cmd_write_reg_reg =
8072         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8073 cmdline_parse_token_num_t cmd_write_reg_port_id =
8074         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8075 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8076         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8077 cmdline_parse_token_num_t cmd_write_reg_value =
8078         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8079
8080 cmdline_parse_inst_t cmd_write_reg = {
8081         .f = cmd_write_reg_parsed,
8082         .data = NULL,
8083         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8084         .tokens = {
8085                 (void *)&cmd_write_reg_write,
8086                 (void *)&cmd_write_reg_reg,
8087                 (void *)&cmd_write_reg_port_id,
8088                 (void *)&cmd_write_reg_reg_off,
8089                 (void *)&cmd_write_reg_value,
8090                 NULL,
8091         },
8092 };
8093
8094 /* *** WRITE PORT REGISTER BIT FIELD *** */
8095 struct cmd_write_reg_bit_field_result {
8096         cmdline_fixed_string_t write;
8097         cmdline_fixed_string_t regfield;
8098         portid_t port_id;
8099         uint32_t reg_off;
8100         uint8_t bit1_pos;
8101         uint8_t bit2_pos;
8102         uint32_t value;
8103 };
8104
8105 static void
8106 cmd_write_reg_bit_field_parsed(void *parsed_result,
8107                                __rte_unused struct cmdline *cl,
8108                                __rte_unused void *data)
8109 {
8110         struct cmd_write_reg_bit_field_result *res = parsed_result;
8111         port_reg_bit_field_set(res->port_id, res->reg_off,
8112                           res->bit1_pos, res->bit2_pos, res->value);
8113 }
8114
8115 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8116         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8117                                  "write");
8118 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8119         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8120                                  regfield, "regfield");
8121 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8122         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8123                               UINT16);
8124 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8125         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8126                               UINT32);
8127 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8128         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8129                               UINT8);
8130 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8131         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8132                               UINT8);
8133 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8134         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8135                               UINT32);
8136
8137 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8138         .f = cmd_write_reg_bit_field_parsed,
8139         .data = NULL,
8140         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8141                 "<reg_value>: "
8142                 "Set register bit field between bit_x and bit_y included",
8143         .tokens = {
8144                 (void *)&cmd_write_reg_bit_field_write,
8145                 (void *)&cmd_write_reg_bit_field_regfield,
8146                 (void *)&cmd_write_reg_bit_field_port_id,
8147                 (void *)&cmd_write_reg_bit_field_reg_off,
8148                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8149                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8150                 (void *)&cmd_write_reg_bit_field_value,
8151                 NULL,
8152         },
8153 };
8154
8155 /* *** WRITE PORT REGISTER BIT *** */
8156 struct cmd_write_reg_bit_result {
8157         cmdline_fixed_string_t write;
8158         cmdline_fixed_string_t regbit;
8159         portid_t port_id;
8160         uint32_t reg_off;
8161         uint8_t bit_pos;
8162         uint8_t value;
8163 };
8164
8165 static void
8166 cmd_write_reg_bit_parsed(void *parsed_result,
8167                          __rte_unused struct cmdline *cl,
8168                          __rte_unused void *data)
8169 {
8170         struct cmd_write_reg_bit_result *res = parsed_result;
8171         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8172 }
8173
8174 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8175         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8176                                  "write");
8177 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8178         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8179                                  regbit, "regbit");
8180 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8181         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8182 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8183         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8184 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8185         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8186 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8187         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8188
8189 cmdline_parse_inst_t cmd_write_reg_bit = {
8190         .f = cmd_write_reg_bit_parsed,
8191         .data = NULL,
8192         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8193                 "0 <= bit_x <= 31",
8194         .tokens = {
8195                 (void *)&cmd_write_reg_bit_write,
8196                 (void *)&cmd_write_reg_bit_regbit,
8197                 (void *)&cmd_write_reg_bit_port_id,
8198                 (void *)&cmd_write_reg_bit_reg_off,
8199                 (void *)&cmd_write_reg_bit_bit_pos,
8200                 (void *)&cmd_write_reg_bit_value,
8201                 NULL,
8202         },
8203 };
8204
8205 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8206 struct cmd_read_rxd_txd_result {
8207         cmdline_fixed_string_t read;
8208         cmdline_fixed_string_t rxd_txd;
8209         portid_t port_id;
8210         uint16_t queue_id;
8211         uint16_t desc_id;
8212 };
8213
8214 static void
8215 cmd_read_rxd_txd_parsed(void *parsed_result,
8216                         __rte_unused struct cmdline *cl,
8217                         __rte_unused void *data)
8218 {
8219         struct cmd_read_rxd_txd_result *res = parsed_result;
8220
8221         if (!strcmp(res->rxd_txd, "rxd"))
8222                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8223         else if (!strcmp(res->rxd_txd, "txd"))
8224                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8225 }
8226
8227 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8228         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8229 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8230         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8231                                  "rxd#txd");
8232 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8233         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8234 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8235         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8236 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8237         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8238
8239 cmdline_parse_inst_t cmd_read_rxd_txd = {
8240         .f = cmd_read_rxd_txd_parsed,
8241         .data = NULL,
8242         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8243         .tokens = {
8244                 (void *)&cmd_read_rxd_txd_read,
8245                 (void *)&cmd_read_rxd_txd_rxd_txd,
8246                 (void *)&cmd_read_rxd_txd_port_id,
8247                 (void *)&cmd_read_rxd_txd_queue_id,
8248                 (void *)&cmd_read_rxd_txd_desc_id,
8249                 NULL,
8250         },
8251 };
8252
8253 /* *** QUIT *** */
8254 struct cmd_quit_result {
8255         cmdline_fixed_string_t quit;
8256 };
8257
8258 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8259                             struct cmdline *cl,
8260                             __rte_unused void *data)
8261 {
8262         cmdline_quit(cl);
8263 }
8264
8265 cmdline_parse_token_string_t cmd_quit_quit =
8266         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8267
8268 cmdline_parse_inst_t cmd_quit = {
8269         .f = cmd_quit_parsed,
8270         .data = NULL,
8271         .help_str = "quit: Exit application",
8272         .tokens = {
8273                 (void *)&cmd_quit_quit,
8274                 NULL,
8275         },
8276 };
8277
8278 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8279 struct cmd_mac_addr_result {
8280         cmdline_fixed_string_t mac_addr_cmd;
8281         cmdline_fixed_string_t what;
8282         uint16_t port_num;
8283         struct rte_ether_addr address;
8284 };
8285
8286 static void cmd_mac_addr_parsed(void *parsed_result,
8287                 __rte_unused struct cmdline *cl,
8288                 __rte_unused void *data)
8289 {
8290         struct cmd_mac_addr_result *res = parsed_result;
8291         int ret;
8292
8293         if (strcmp(res->what, "add") == 0)
8294                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8295         else if (strcmp(res->what, "set") == 0)
8296                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8297                                                        &res->address);
8298         else
8299                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8300
8301         /* check the return value and print it if is < 0 */
8302         if(ret < 0)
8303                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8304
8305 }
8306
8307 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8308         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8309                                 "mac_addr");
8310 cmdline_parse_token_string_t cmd_mac_addr_what =
8311         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8312                                 "add#remove#set");
8313 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8314                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8315                                         UINT16);
8316 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8317                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8318
8319 cmdline_parse_inst_t cmd_mac_addr = {
8320         .f = cmd_mac_addr_parsed,
8321         .data = (void *)0,
8322         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8323                         "Add/Remove/Set MAC address on port_id",
8324         .tokens = {
8325                 (void *)&cmd_mac_addr_cmd,
8326                 (void *)&cmd_mac_addr_what,
8327                 (void *)&cmd_mac_addr_portnum,
8328                 (void *)&cmd_mac_addr_addr,
8329                 NULL,
8330         },
8331 };
8332
8333 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8334 struct cmd_eth_peer_result {
8335         cmdline_fixed_string_t set;
8336         cmdline_fixed_string_t eth_peer;
8337         portid_t port_id;
8338         cmdline_fixed_string_t peer_addr;
8339 };
8340
8341 static void cmd_set_eth_peer_parsed(void *parsed_result,
8342                         __rte_unused struct cmdline *cl,
8343                         __rte_unused void *data)
8344 {
8345                 struct cmd_eth_peer_result *res = parsed_result;
8346
8347                 if (test_done == 0) {
8348                         printf("Please stop forwarding first\n");
8349                         return;
8350                 }
8351                 if (!strcmp(res->eth_peer, "eth-peer")) {
8352                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8353                         fwd_config_setup();
8354                 }
8355 }
8356 cmdline_parse_token_string_t cmd_eth_peer_set =
8357         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8358 cmdline_parse_token_string_t cmd_eth_peer =
8359         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8360 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8361         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8362 cmdline_parse_token_string_t cmd_eth_peer_addr =
8363         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8364
8365 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8366         .f = cmd_set_eth_peer_parsed,
8367         .data = NULL,
8368         .help_str = "set eth-peer <port_id> <peer_mac>",
8369         .tokens = {
8370                 (void *)&cmd_eth_peer_set,
8371                 (void *)&cmd_eth_peer,
8372                 (void *)&cmd_eth_peer_port_id,
8373                 (void *)&cmd_eth_peer_addr,
8374                 NULL,
8375         },
8376 };
8377
8378 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8379 struct cmd_set_qmap_result {
8380         cmdline_fixed_string_t set;
8381         cmdline_fixed_string_t qmap;
8382         cmdline_fixed_string_t what;
8383         portid_t port_id;
8384         uint16_t queue_id;
8385         uint8_t map_value;
8386 };
8387
8388 static void
8389 cmd_set_qmap_parsed(void *parsed_result,
8390                        __rte_unused struct cmdline *cl,
8391                        __rte_unused void *data)
8392 {
8393         struct cmd_set_qmap_result *res = parsed_result;
8394         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8395
8396         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8397 }
8398
8399 cmdline_parse_token_string_t cmd_setqmap_set =
8400         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8401                                  set, "set");
8402 cmdline_parse_token_string_t cmd_setqmap_qmap =
8403         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8404                                  qmap, "stat_qmap");
8405 cmdline_parse_token_string_t cmd_setqmap_what =
8406         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8407                                  what, "tx#rx");
8408 cmdline_parse_token_num_t cmd_setqmap_portid =
8409         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8410                               port_id, UINT16);
8411 cmdline_parse_token_num_t cmd_setqmap_queueid =
8412         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8413                               queue_id, UINT16);
8414 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8415         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8416                               map_value, UINT8);
8417
8418 cmdline_parse_inst_t cmd_set_qmap = {
8419         .f = cmd_set_qmap_parsed,
8420         .data = NULL,
8421         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8422                 "Set statistics mapping value on tx|rx queue_id of port_id",
8423         .tokens = {
8424                 (void *)&cmd_setqmap_set,
8425                 (void *)&cmd_setqmap_qmap,
8426                 (void *)&cmd_setqmap_what,
8427                 (void *)&cmd_setqmap_portid,
8428                 (void *)&cmd_setqmap_queueid,
8429                 (void *)&cmd_setqmap_mapvalue,
8430                 NULL,
8431         },
8432 };
8433
8434 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8435 struct cmd_set_xstats_hide_zero_result {
8436         cmdline_fixed_string_t keyword;
8437         cmdline_fixed_string_t name;
8438         cmdline_fixed_string_t on_off;
8439 };
8440
8441 static void
8442 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8443                         __rte_unused struct cmdline *cl,
8444                         __rte_unused void *data)
8445 {
8446         struct cmd_set_xstats_hide_zero_result *res;
8447         uint16_t on_off = 0;
8448
8449         res = parsed_result;
8450         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8451         set_xstats_hide_zero(on_off);
8452 }
8453
8454 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8455         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8456                                  keyword, "set");
8457 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8458         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8459                                  name, "xstats-hide-zero");
8460 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8461         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8462                                  on_off, "on#off");
8463
8464 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8465         .f = cmd_set_xstats_hide_zero_parsed,
8466         .data = NULL,
8467         .help_str = "set xstats-hide-zero on|off",
8468         .tokens = {
8469                 (void *)&cmd_set_xstats_hide_zero_keyword,
8470                 (void *)&cmd_set_xstats_hide_zero_name,
8471                 (void *)&cmd_set_xstats_hide_zero_on_off,
8472                 NULL,
8473         },
8474 };
8475
8476 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8477 struct cmd_set_record_core_cycles_result {
8478         cmdline_fixed_string_t keyword;
8479         cmdline_fixed_string_t name;
8480         cmdline_fixed_string_t on_off;
8481 };
8482
8483 static void
8484 cmd_set_record_core_cycles_parsed(void *parsed_result,
8485                         __rte_unused struct cmdline *cl,
8486                         __rte_unused void *data)
8487 {
8488         struct cmd_set_record_core_cycles_result *res;
8489         uint16_t on_off = 0;
8490
8491         res = parsed_result;
8492         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8493         set_record_core_cycles(on_off);
8494 }
8495
8496 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8497         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8498                                  keyword, "set");
8499 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8500         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8501                                  name, "record-core-cycles");
8502 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8503         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8504                                  on_off, "on#off");
8505
8506 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8507         .f = cmd_set_record_core_cycles_parsed,
8508         .data = NULL,
8509         .help_str = "set record-core-cycles on|off",
8510         .tokens = {
8511                 (void *)&cmd_set_record_core_cycles_keyword,
8512                 (void *)&cmd_set_record_core_cycles_name,
8513                 (void *)&cmd_set_record_core_cycles_on_off,
8514                 NULL,
8515         },
8516 };
8517
8518 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8519 struct cmd_set_record_burst_stats_result {
8520         cmdline_fixed_string_t keyword;
8521         cmdline_fixed_string_t name;
8522         cmdline_fixed_string_t on_off;
8523 };
8524
8525 static void
8526 cmd_set_record_burst_stats_parsed(void *parsed_result,
8527                         __rte_unused struct cmdline *cl,
8528                         __rte_unused void *data)
8529 {
8530         struct cmd_set_record_burst_stats_result *res;
8531         uint16_t on_off = 0;
8532
8533         res = parsed_result;
8534         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8535         set_record_burst_stats(on_off);
8536 }
8537
8538 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8539         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8540                                  keyword, "set");
8541 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8542         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8543                                  name, "record-burst-stats");
8544 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8545         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8546                                  on_off, "on#off");
8547
8548 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8549         .f = cmd_set_record_burst_stats_parsed,
8550         .data = NULL,
8551         .help_str = "set record-burst-stats on|off",
8552         .tokens = {
8553                 (void *)&cmd_set_record_burst_stats_keyword,
8554                 (void *)&cmd_set_record_burst_stats_name,
8555                 (void *)&cmd_set_record_burst_stats_on_off,
8556                 NULL,
8557         },
8558 };
8559
8560 /* *** CONFIGURE UNICAST HASH TABLE *** */
8561 struct cmd_set_uc_hash_table {
8562         cmdline_fixed_string_t set;
8563         cmdline_fixed_string_t port;
8564         portid_t port_id;
8565         cmdline_fixed_string_t what;
8566         struct rte_ether_addr address;
8567         cmdline_fixed_string_t mode;
8568 };
8569
8570 static void
8571 cmd_set_uc_hash_parsed(void *parsed_result,
8572                        __rte_unused struct cmdline *cl,
8573                        __rte_unused void *data)
8574 {
8575         int ret=0;
8576         struct cmd_set_uc_hash_table *res = parsed_result;
8577
8578         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8579
8580         if (strcmp(res->what, "uta") == 0)
8581                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8582                                                 &res->address,(uint8_t)is_on);
8583         if (ret < 0)
8584                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8585
8586 }
8587
8588 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8589         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8590                                  set, "set");
8591 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8592         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8593                                  port, "port");
8594 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8595         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8596                               port_id, UINT16);
8597 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8598         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8599                                  what, "uta");
8600 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8601         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8602                                 address);
8603 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8604         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8605                                  mode, "on#off");
8606
8607 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8608         .f = cmd_set_uc_hash_parsed,
8609         .data = NULL,
8610         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8611         .tokens = {
8612                 (void *)&cmd_set_uc_hash_set,
8613                 (void *)&cmd_set_uc_hash_port,
8614                 (void *)&cmd_set_uc_hash_portid,
8615                 (void *)&cmd_set_uc_hash_what,
8616                 (void *)&cmd_set_uc_hash_mac,
8617                 (void *)&cmd_set_uc_hash_mode,
8618                 NULL,
8619         },
8620 };
8621
8622 struct cmd_set_uc_all_hash_table {
8623         cmdline_fixed_string_t set;
8624         cmdline_fixed_string_t port;
8625         portid_t port_id;
8626         cmdline_fixed_string_t what;
8627         cmdline_fixed_string_t value;
8628         cmdline_fixed_string_t mode;
8629 };
8630
8631 static void
8632 cmd_set_uc_all_hash_parsed(void *parsed_result,
8633                        __rte_unused struct cmdline *cl,
8634                        __rte_unused void *data)
8635 {
8636         int ret=0;
8637         struct cmd_set_uc_all_hash_table *res = parsed_result;
8638
8639         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8640
8641         if ((strcmp(res->what, "uta") == 0) &&
8642                 (strcmp(res->value, "all") == 0))
8643                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8644         if (ret < 0)
8645                 printf("bad unicast hash table parameter,"
8646                         "return code = %d \n", ret);
8647 }
8648
8649 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8650         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8651                                  set, "set");
8652 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8653         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8654                                  port, "port");
8655 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8656         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8657                               port_id, UINT16);
8658 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8659         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8660                                  what, "uta");
8661 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8662         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8663                                 value,"all");
8664 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8665         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8666                                  mode, "on#off");
8667
8668 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8669         .f = cmd_set_uc_all_hash_parsed,
8670         .data = NULL,
8671         .help_str = "set port <port_id> uta all on|off",
8672         .tokens = {
8673                 (void *)&cmd_set_uc_all_hash_set,
8674                 (void *)&cmd_set_uc_all_hash_port,
8675                 (void *)&cmd_set_uc_all_hash_portid,
8676                 (void *)&cmd_set_uc_all_hash_what,
8677                 (void *)&cmd_set_uc_all_hash_value,
8678                 (void *)&cmd_set_uc_all_hash_mode,
8679                 NULL,
8680         },
8681 };
8682
8683 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8684 struct cmd_set_vf_traffic {
8685         cmdline_fixed_string_t set;
8686         cmdline_fixed_string_t port;
8687         portid_t port_id;
8688         cmdline_fixed_string_t vf;
8689         uint8_t vf_id;
8690         cmdline_fixed_string_t what;
8691         cmdline_fixed_string_t mode;
8692 };
8693
8694 static void
8695 cmd_set_vf_traffic_parsed(void *parsed_result,
8696                        __rte_unused struct cmdline *cl,
8697                        __rte_unused void *data)
8698 {
8699         struct cmd_set_vf_traffic *res = parsed_result;
8700         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8701         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8702
8703         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8704 }
8705
8706 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8707         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8708                                  set, "set");
8709 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8710         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8711                                  port, "port");
8712 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8713         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8714                               port_id, UINT16);
8715 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8716         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8717                                  vf, "vf");
8718 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8719         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8720                               vf_id, UINT8);
8721 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8722         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8723                                  what, "tx#rx");
8724 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8725         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8726                                  mode, "on#off");
8727
8728 cmdline_parse_inst_t cmd_set_vf_traffic = {
8729         .f = cmd_set_vf_traffic_parsed,
8730         .data = NULL,
8731         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8732         .tokens = {
8733                 (void *)&cmd_setvf_traffic_set,
8734                 (void *)&cmd_setvf_traffic_port,
8735                 (void *)&cmd_setvf_traffic_portid,
8736                 (void *)&cmd_setvf_traffic_vf,
8737                 (void *)&cmd_setvf_traffic_vfid,
8738                 (void *)&cmd_setvf_traffic_what,
8739                 (void *)&cmd_setvf_traffic_mode,
8740                 NULL,
8741         },
8742 };
8743
8744 /* *** CONFIGURE VF RECEIVE MODE *** */
8745 struct cmd_set_vf_rxmode {
8746         cmdline_fixed_string_t set;
8747         cmdline_fixed_string_t port;
8748         portid_t port_id;
8749         cmdline_fixed_string_t vf;
8750         uint8_t vf_id;
8751         cmdline_fixed_string_t what;
8752         cmdline_fixed_string_t mode;
8753         cmdline_fixed_string_t on;
8754 };
8755
8756 static void
8757 cmd_set_vf_rxmode_parsed(void *parsed_result,
8758                        __rte_unused struct cmdline *cl,
8759                        __rte_unused void *data)
8760 {
8761         int ret = -ENOTSUP;
8762         uint16_t vf_rxmode = 0;
8763         struct cmd_set_vf_rxmode *res = parsed_result;
8764
8765         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8766         if (!strcmp(res->what,"rxmode")) {
8767                 if (!strcmp(res->mode, "AUPE"))
8768                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8769                 else if (!strcmp(res->mode, "ROPE"))
8770                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8771                 else if (!strcmp(res->mode, "BAM"))
8772                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8773                 else if (!strncmp(res->mode, "MPE",3))
8774                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8775         }
8776
8777         RTE_SET_USED(is_on);
8778
8779 #ifdef RTE_NET_IXGBE
8780         if (ret == -ENOTSUP)
8781                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8782                                                   vf_rxmode, (uint8_t)is_on);
8783 #endif
8784 #ifdef RTE_NET_BNXT
8785         if (ret == -ENOTSUP)
8786                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8787                                                  vf_rxmode, (uint8_t)is_on);
8788 #endif
8789         if (ret < 0)
8790                 printf("bad VF receive mode parameter, return code = %d \n",
8791                 ret);
8792 }
8793
8794 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8795         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8796                                  set, "set");
8797 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8798         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8799                                  port, "port");
8800 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8801         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8802                               port_id, UINT16);
8803 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8804         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8805                                  vf, "vf");
8806 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8807         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8808                               vf_id, UINT8);
8809 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8810         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8811                                  what, "rxmode");
8812 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8813         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8814                                  mode, "AUPE#ROPE#BAM#MPE");
8815 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8816         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8817                                  on, "on#off");
8818
8819 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8820         .f = cmd_set_vf_rxmode_parsed,
8821         .data = NULL,
8822         .help_str = "set port <port_id> vf <vf_id> rxmode "
8823                 "AUPE|ROPE|BAM|MPE on|off",
8824         .tokens = {
8825                 (void *)&cmd_set_vf_rxmode_set,
8826                 (void *)&cmd_set_vf_rxmode_port,
8827                 (void *)&cmd_set_vf_rxmode_portid,
8828                 (void *)&cmd_set_vf_rxmode_vf,
8829                 (void *)&cmd_set_vf_rxmode_vfid,
8830                 (void *)&cmd_set_vf_rxmode_what,
8831                 (void *)&cmd_set_vf_rxmode_mode,
8832                 (void *)&cmd_set_vf_rxmode_on,
8833                 NULL,
8834         },
8835 };
8836
8837 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8838 struct cmd_vf_mac_addr_result {
8839         cmdline_fixed_string_t mac_addr_cmd;
8840         cmdline_fixed_string_t what;
8841         cmdline_fixed_string_t port;
8842         uint16_t port_num;
8843         cmdline_fixed_string_t vf;
8844         uint8_t vf_num;
8845         struct rte_ether_addr address;
8846 };
8847
8848 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8849                 __rte_unused struct cmdline *cl,
8850                 __rte_unused void *data)
8851 {
8852         struct cmd_vf_mac_addr_result *res = parsed_result;
8853         int ret = -ENOTSUP;
8854
8855         if (strcmp(res->what, "add") != 0)
8856                 return;
8857
8858 #ifdef RTE_NET_I40E
8859         if (ret == -ENOTSUP)
8860                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8861                                                    &res->address);
8862 #endif
8863 #ifdef RTE_NET_BNXT
8864         if (ret == -ENOTSUP)
8865                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8866                                                 res->vf_num);
8867 #endif
8868
8869         if(ret < 0)
8870                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8871
8872 }
8873
8874 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8875         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8876                                 mac_addr_cmd,"mac_addr");
8877 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8878         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8879                                 what,"add");
8880 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8881         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8882                                 port,"port");
8883 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8884         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8885                                 port_num, UINT16);
8886 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8887         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8888                                 vf,"vf");
8889 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8890         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8891                                 vf_num, UINT8);
8892 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8893         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8894                                 address);
8895
8896 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8897         .f = cmd_vf_mac_addr_parsed,
8898         .data = (void *)0,
8899         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8900                 "Add MAC address filtering for a VF on port_id",
8901         .tokens = {
8902                 (void *)&cmd_vf_mac_addr_cmd,
8903                 (void *)&cmd_vf_mac_addr_what,
8904                 (void *)&cmd_vf_mac_addr_port,
8905                 (void *)&cmd_vf_mac_addr_portnum,
8906                 (void *)&cmd_vf_mac_addr_vf,
8907                 (void *)&cmd_vf_mac_addr_vfnum,
8908                 (void *)&cmd_vf_mac_addr_addr,
8909                 NULL,
8910         },
8911 };
8912
8913 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8914 struct cmd_vf_rx_vlan_filter {
8915         cmdline_fixed_string_t rx_vlan;
8916         cmdline_fixed_string_t what;
8917         uint16_t vlan_id;
8918         cmdline_fixed_string_t port;
8919         portid_t port_id;
8920         cmdline_fixed_string_t vf;
8921         uint64_t vf_mask;
8922 };
8923
8924 static void
8925 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8926                           __rte_unused struct cmdline *cl,
8927                           __rte_unused void *data)
8928 {
8929         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8930         int ret = -ENOTSUP;
8931
8932         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8933
8934 #ifdef RTE_NET_IXGBE
8935         if (ret == -ENOTSUP)
8936                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8937                                 res->vlan_id, res->vf_mask, is_add);
8938 #endif
8939 #ifdef RTE_NET_I40E
8940         if (ret == -ENOTSUP)
8941                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8942                                 res->vlan_id, res->vf_mask, is_add);
8943 #endif
8944 #ifdef RTE_NET_BNXT
8945         if (ret == -ENOTSUP)
8946                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8947                                 res->vlan_id, res->vf_mask, is_add);
8948 #endif
8949
8950         switch (ret) {
8951         case 0:
8952                 break;
8953         case -EINVAL:
8954                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8955                                 res->vlan_id, res->vf_mask);
8956                 break;
8957         case -ENODEV:
8958                 printf("invalid port_id %d\n", res->port_id);
8959                 break;
8960         case -ENOTSUP:
8961                 printf("function not implemented or supported\n");
8962                 break;
8963         default:
8964                 printf("programming error: (%s)\n", strerror(-ret));
8965         }
8966 }
8967
8968 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8969         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8970                                  rx_vlan, "rx_vlan");
8971 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8972         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8973                                  what, "add#rm");
8974 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8975         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8976                               vlan_id, UINT16);
8977 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8978         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8979                                  port, "port");
8980 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8981         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8982                               port_id, UINT16);
8983 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8984         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8985                                  vf, "vf");
8986 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8987         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8988                               vf_mask, UINT64);
8989
8990 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8991         .f = cmd_vf_rx_vlan_filter_parsed,
8992         .data = NULL,
8993         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8994                 "(vf_mask = hexadecimal VF mask)",
8995         .tokens = {
8996                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8997                 (void *)&cmd_vf_rx_vlan_filter_what,
8998                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8999                 (void *)&cmd_vf_rx_vlan_filter_port,
9000                 (void *)&cmd_vf_rx_vlan_filter_portid,
9001                 (void *)&cmd_vf_rx_vlan_filter_vf,
9002                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9003                 NULL,
9004         },
9005 };
9006
9007 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9008 struct cmd_queue_rate_limit_result {
9009         cmdline_fixed_string_t set;
9010         cmdline_fixed_string_t port;
9011         uint16_t port_num;
9012         cmdline_fixed_string_t queue;
9013         uint8_t queue_num;
9014         cmdline_fixed_string_t rate;
9015         uint16_t rate_num;
9016 };
9017
9018 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9019                 __rte_unused struct cmdline *cl,
9020                 __rte_unused void *data)
9021 {
9022         struct cmd_queue_rate_limit_result *res = parsed_result;
9023         int ret = 0;
9024
9025         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9026                 && (strcmp(res->queue, "queue") == 0)
9027                 && (strcmp(res->rate, "rate") == 0))
9028                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9029                                         res->rate_num);
9030         if (ret < 0)
9031                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9032
9033 }
9034
9035 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9036         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9037                                 set, "set");
9038 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9039         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9040                                 port, "port");
9041 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9042         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9043                                 port_num, UINT16);
9044 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9045         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9046                                 queue, "queue");
9047 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9048         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9049                                 queue_num, UINT8);
9050 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9051         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9052                                 rate, "rate");
9053 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9054         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9055                                 rate_num, UINT16);
9056
9057 cmdline_parse_inst_t cmd_queue_rate_limit = {
9058         .f = cmd_queue_rate_limit_parsed,
9059         .data = (void *)0,
9060         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9061                 "Set rate limit for a queue on port_id",
9062         .tokens = {
9063                 (void *)&cmd_queue_rate_limit_set,
9064                 (void *)&cmd_queue_rate_limit_port,
9065                 (void *)&cmd_queue_rate_limit_portnum,
9066                 (void *)&cmd_queue_rate_limit_queue,
9067                 (void *)&cmd_queue_rate_limit_queuenum,
9068                 (void *)&cmd_queue_rate_limit_rate,
9069                 (void *)&cmd_queue_rate_limit_ratenum,
9070                 NULL,
9071         },
9072 };
9073
9074 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9075 struct cmd_vf_rate_limit_result {
9076         cmdline_fixed_string_t set;
9077         cmdline_fixed_string_t port;
9078         uint16_t port_num;
9079         cmdline_fixed_string_t vf;
9080         uint8_t vf_num;
9081         cmdline_fixed_string_t rate;
9082         uint16_t rate_num;
9083         cmdline_fixed_string_t q_msk;
9084         uint64_t q_msk_val;
9085 };
9086
9087 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9088                 __rte_unused struct cmdline *cl,
9089                 __rte_unused void *data)
9090 {
9091         struct cmd_vf_rate_limit_result *res = parsed_result;
9092         int ret = 0;
9093
9094         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9095                 && (strcmp(res->vf, "vf") == 0)
9096                 && (strcmp(res->rate, "rate") == 0)
9097                 && (strcmp(res->q_msk, "queue_mask") == 0))
9098                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9099                                         res->rate_num, res->q_msk_val);
9100         if (ret < 0)
9101                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9102
9103 }
9104
9105 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9106         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9107                                 set, "set");
9108 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9109         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9110                                 port, "port");
9111 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9112         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9113                                 port_num, UINT16);
9114 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9115         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9116                                 vf, "vf");
9117 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9118         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9119                                 vf_num, UINT8);
9120 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9121         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9122                                 rate, "rate");
9123 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9124         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9125                                 rate_num, UINT16);
9126 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9127         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9128                                 q_msk, "queue_mask");
9129 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9130         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9131                                 q_msk_val, UINT64);
9132
9133 cmdline_parse_inst_t cmd_vf_rate_limit = {
9134         .f = cmd_vf_rate_limit_parsed,
9135         .data = (void *)0,
9136         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9137                 "queue_mask <queue_mask_value>: "
9138                 "Set rate limit for queues of VF on port_id",
9139         .tokens = {
9140                 (void *)&cmd_vf_rate_limit_set,
9141                 (void *)&cmd_vf_rate_limit_port,
9142                 (void *)&cmd_vf_rate_limit_portnum,
9143                 (void *)&cmd_vf_rate_limit_vf,
9144                 (void *)&cmd_vf_rate_limit_vfnum,
9145                 (void *)&cmd_vf_rate_limit_rate,
9146                 (void *)&cmd_vf_rate_limit_ratenum,
9147                 (void *)&cmd_vf_rate_limit_q_msk,
9148                 (void *)&cmd_vf_rate_limit_q_msk_val,
9149                 NULL,
9150         },
9151 };
9152
9153 /* *** CONFIGURE TUNNEL UDP PORT *** */
9154 struct cmd_tunnel_udp_config {
9155         cmdline_fixed_string_t cmd;
9156         cmdline_fixed_string_t what;
9157         uint16_t udp_port;
9158         portid_t port_id;
9159 };
9160
9161 static void
9162 cmd_tunnel_udp_config_parsed(void *parsed_result,
9163                           __rte_unused struct cmdline *cl,
9164                           __rte_unused void *data)
9165 {
9166         struct cmd_tunnel_udp_config *res = parsed_result;
9167         struct rte_eth_udp_tunnel tunnel_udp;
9168         int ret;
9169
9170         tunnel_udp.udp_port = res->udp_port;
9171
9172         if (!strcmp(res->cmd, "rx_vxlan_port"))
9173                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9174
9175         if (!strcmp(res->what, "add"))
9176                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9177                                                       &tunnel_udp);
9178         else
9179                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9180                                                          &tunnel_udp);
9181
9182         if (ret < 0)
9183                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9184 }
9185
9186 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9187         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9188                                 cmd, "rx_vxlan_port");
9189 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9190         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9191                                 what, "add#rm");
9192 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9193         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9194                                 udp_port, UINT16);
9195 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9196         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9197                                 port_id, UINT16);
9198
9199 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9200         .f = cmd_tunnel_udp_config_parsed,
9201         .data = (void *)0,
9202         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9203                 "Add/Remove a tunneling UDP port filter",
9204         .tokens = {
9205                 (void *)&cmd_tunnel_udp_config_cmd,
9206                 (void *)&cmd_tunnel_udp_config_what,
9207                 (void *)&cmd_tunnel_udp_config_udp_port,
9208                 (void *)&cmd_tunnel_udp_config_port_id,
9209                 NULL,
9210         },
9211 };
9212
9213 struct cmd_config_tunnel_udp_port {
9214         cmdline_fixed_string_t port;
9215         cmdline_fixed_string_t config;
9216         portid_t port_id;
9217         cmdline_fixed_string_t udp_tunnel_port;
9218         cmdline_fixed_string_t action;
9219         cmdline_fixed_string_t tunnel_type;
9220         uint16_t udp_port;
9221 };
9222
9223 static void
9224 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9225                                __rte_unused struct cmdline *cl,
9226                                __rte_unused void *data)
9227 {
9228         struct cmd_config_tunnel_udp_port *res = parsed_result;
9229         struct rte_eth_udp_tunnel tunnel_udp;
9230         int ret = 0;
9231
9232         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9233                 return;
9234
9235         tunnel_udp.udp_port = res->udp_port;
9236
9237         if (!strcmp(res->tunnel_type, "vxlan")) {
9238                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9239         } else if (!strcmp(res->tunnel_type, "geneve")) {
9240                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9241         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9242                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9243         } else {
9244                 printf("Invalid tunnel type\n");
9245                 return;
9246         }
9247
9248         if (!strcmp(res->action, "add"))
9249                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9250                                                       &tunnel_udp);
9251         else
9252                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9253                                                          &tunnel_udp);
9254
9255         if (ret < 0)
9256                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9257 }
9258
9259 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9260         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9261                                  "port");
9262 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9263         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9264                                  "config");
9265 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9266         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9267                               UINT16);
9268 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9269         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9270                                  udp_tunnel_port,
9271                                  "udp_tunnel_port");
9272 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9273         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9274                                  "add#rm");
9275 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9276         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9277                                  "vxlan#geneve#vxlan-gpe");
9278 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9279         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9280                               UINT16);
9281
9282 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9283         .f = cmd_cfg_tunnel_udp_port_parsed,
9284         .data = NULL,
9285         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9286         .tokens = {
9287                 (void *)&cmd_config_tunnel_udp_port_port,
9288                 (void *)&cmd_config_tunnel_udp_port_config,
9289                 (void *)&cmd_config_tunnel_udp_port_port_id,
9290                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9291                 (void *)&cmd_config_tunnel_udp_port_action,
9292                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9293                 (void *)&cmd_config_tunnel_udp_port_value,
9294                 NULL,
9295         },
9296 };
9297
9298 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9299 struct cmd_set_mirror_mask_result {
9300         cmdline_fixed_string_t set;
9301         cmdline_fixed_string_t port;
9302         portid_t port_id;
9303         cmdline_fixed_string_t mirror;
9304         uint8_t rule_id;
9305         cmdline_fixed_string_t what;
9306         cmdline_fixed_string_t value;
9307         cmdline_fixed_string_t dstpool;
9308         uint8_t dstpool_id;
9309         cmdline_fixed_string_t on;
9310 };
9311
9312 cmdline_parse_token_string_t cmd_mirror_mask_set =
9313         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9314                                 set, "set");
9315 cmdline_parse_token_string_t cmd_mirror_mask_port =
9316         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9317                                 port, "port");
9318 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9319         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9320                                 port_id, UINT16);
9321 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9322         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9323                                 mirror, "mirror-rule");
9324 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9325         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9326                                 rule_id, UINT8);
9327 cmdline_parse_token_string_t cmd_mirror_mask_what =
9328         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9329                                 what, "pool-mirror-up#pool-mirror-down"
9330                                       "#vlan-mirror");
9331 cmdline_parse_token_string_t cmd_mirror_mask_value =
9332         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9333                                 value, NULL);
9334 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9335         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9336                                 dstpool, "dst-pool");
9337 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9338         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9339                                 dstpool_id, UINT8);
9340 cmdline_parse_token_string_t cmd_mirror_mask_on =
9341         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9342                                 on, "on#off");
9343
9344 static void
9345 cmd_set_mirror_mask_parsed(void *parsed_result,
9346                        __rte_unused struct cmdline *cl,
9347                        __rte_unused void *data)
9348 {
9349         int ret,nb_item,i;
9350         struct cmd_set_mirror_mask_result *res = parsed_result;
9351         struct rte_eth_mirror_conf mr_conf;
9352
9353         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9354
9355         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9356
9357         mr_conf.dst_pool = res->dstpool_id;
9358
9359         if (!strcmp(res->what, "pool-mirror-up")) {
9360                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9361                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9362         } else if (!strcmp(res->what, "pool-mirror-down")) {
9363                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9364                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9365         } else if (!strcmp(res->what, "vlan-mirror")) {
9366                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9367                 nb_item = parse_item_list(res->value, "vlan",
9368                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9369                 if (nb_item <= 0)
9370                         return;
9371
9372                 for (i = 0; i < nb_item; i++) {
9373                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9374                                 printf("Invalid vlan_id: must be < 4096\n");
9375                                 return;
9376                         }
9377
9378                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9379                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9380                 }
9381         }
9382
9383         if (!strcmp(res->on, "on"))
9384                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9385                                                 res->rule_id, 1);
9386         else
9387                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9388                                                 res->rule_id, 0);
9389         if (ret < 0)
9390                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9391 }
9392
9393 cmdline_parse_inst_t cmd_set_mirror_mask = {
9394                 .f = cmd_set_mirror_mask_parsed,
9395                 .data = NULL,
9396                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9397                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9398                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9399                 .tokens = {
9400                         (void *)&cmd_mirror_mask_set,
9401                         (void *)&cmd_mirror_mask_port,
9402                         (void *)&cmd_mirror_mask_portid,
9403                         (void *)&cmd_mirror_mask_mirror,
9404                         (void *)&cmd_mirror_mask_ruleid,
9405                         (void *)&cmd_mirror_mask_what,
9406                         (void *)&cmd_mirror_mask_value,
9407                         (void *)&cmd_mirror_mask_dstpool,
9408                         (void *)&cmd_mirror_mask_poolid,
9409                         (void *)&cmd_mirror_mask_on,
9410                         NULL,
9411                 },
9412 };
9413
9414 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9415 struct cmd_set_mirror_link_result {
9416         cmdline_fixed_string_t set;
9417         cmdline_fixed_string_t port;
9418         portid_t port_id;
9419         cmdline_fixed_string_t mirror;
9420         uint8_t rule_id;
9421         cmdline_fixed_string_t what;
9422         cmdline_fixed_string_t dstpool;
9423         uint8_t dstpool_id;
9424         cmdline_fixed_string_t on;
9425 };
9426
9427 cmdline_parse_token_string_t cmd_mirror_link_set =
9428         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9429                                  set, "set");
9430 cmdline_parse_token_string_t cmd_mirror_link_port =
9431         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9432                                 port, "port");
9433 cmdline_parse_token_num_t cmd_mirror_link_portid =
9434         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9435                                 port_id, UINT16);
9436 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9437         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9438                                 mirror, "mirror-rule");
9439 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9440         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9441                             rule_id, UINT8);
9442 cmdline_parse_token_string_t cmd_mirror_link_what =
9443         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9444                                 what, "uplink-mirror#downlink-mirror");
9445 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9446         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9447                                 dstpool, "dst-pool");
9448 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9449         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9450                                 dstpool_id, UINT8);
9451 cmdline_parse_token_string_t cmd_mirror_link_on =
9452         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9453                                 on, "on#off");
9454
9455 static void
9456 cmd_set_mirror_link_parsed(void *parsed_result,
9457                        __rte_unused struct cmdline *cl,
9458                        __rte_unused void *data)
9459 {
9460         int ret;
9461         struct cmd_set_mirror_link_result *res = parsed_result;
9462         struct rte_eth_mirror_conf mr_conf;
9463
9464         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9465         if (!strcmp(res->what, "uplink-mirror"))
9466                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9467         else
9468                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9469
9470         mr_conf.dst_pool = res->dstpool_id;
9471
9472         if (!strcmp(res->on, "on"))
9473                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9474                                                 res->rule_id, 1);
9475         else
9476                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9477                                                 res->rule_id, 0);
9478
9479         /* check the return value and print it if is < 0 */
9480         if (ret < 0)
9481                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9482
9483 }
9484
9485 cmdline_parse_inst_t cmd_set_mirror_link = {
9486                 .f = cmd_set_mirror_link_parsed,
9487                 .data = NULL,
9488                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9489                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9490                 .tokens = {
9491                         (void *)&cmd_mirror_link_set,
9492                         (void *)&cmd_mirror_link_port,
9493                         (void *)&cmd_mirror_link_portid,
9494                         (void *)&cmd_mirror_link_mirror,
9495                         (void *)&cmd_mirror_link_ruleid,
9496                         (void *)&cmd_mirror_link_what,
9497                         (void *)&cmd_mirror_link_dstpool,
9498                         (void *)&cmd_mirror_link_poolid,
9499                         (void *)&cmd_mirror_link_on,
9500                         NULL,
9501                 },
9502 };
9503
9504 /* *** RESET VM MIRROR RULE *** */
9505 struct cmd_rm_mirror_rule_result {
9506         cmdline_fixed_string_t reset;
9507         cmdline_fixed_string_t port;
9508         portid_t port_id;
9509         cmdline_fixed_string_t mirror;
9510         uint8_t rule_id;
9511 };
9512
9513 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9514         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9515                                  reset, "reset");
9516 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9517         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9518                                 port, "port");
9519 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9520         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9521                                 port_id, UINT16);
9522 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9523         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9524                                 mirror, "mirror-rule");
9525 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9526         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9527                                 rule_id, UINT8);
9528
9529 static void
9530 cmd_reset_mirror_rule_parsed(void *parsed_result,
9531                        __rte_unused struct cmdline *cl,
9532                        __rte_unused void *data)
9533 {
9534         int ret;
9535         struct cmd_set_mirror_link_result *res = parsed_result;
9536         /* check rule_id */
9537         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9538         if(ret < 0)
9539                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9540 }
9541
9542 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9543                 .f = cmd_reset_mirror_rule_parsed,
9544                 .data = NULL,
9545                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9546                 .tokens = {
9547                         (void *)&cmd_rm_mirror_rule_reset,
9548                         (void *)&cmd_rm_mirror_rule_port,
9549                         (void *)&cmd_rm_mirror_rule_portid,
9550                         (void *)&cmd_rm_mirror_rule_mirror,
9551                         (void *)&cmd_rm_mirror_rule_ruleid,
9552                         NULL,
9553                 },
9554 };
9555
9556 /* ******************************************************************************** */
9557
9558 struct cmd_dump_result {
9559         cmdline_fixed_string_t dump;
9560 };
9561
9562 static void
9563 dump_struct_sizes(void)
9564 {
9565 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9566         DUMP_SIZE(struct rte_mbuf);
9567         DUMP_SIZE(struct rte_mempool);
9568         DUMP_SIZE(struct rte_ring);
9569 #undef DUMP_SIZE
9570 }
9571
9572
9573 /* Dump the socket memory statistics on console */
9574 static void
9575 dump_socket_mem(FILE *f)
9576 {
9577         struct rte_malloc_socket_stats socket_stats;
9578         unsigned int i;
9579         size_t total = 0;
9580         size_t alloc = 0;
9581         size_t free = 0;
9582         unsigned int n_alloc = 0;
9583         unsigned int n_free = 0;
9584         static size_t last_allocs;
9585         static size_t last_total;
9586
9587
9588         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9589                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9590                     !socket_stats.heap_totalsz_bytes)
9591                         continue;
9592                 total += socket_stats.heap_totalsz_bytes;
9593                 alloc += socket_stats.heap_allocsz_bytes;
9594                 free += socket_stats.heap_freesz_bytes;
9595                 n_alloc += socket_stats.alloc_count;
9596                 n_free += socket_stats.free_count;
9597                 fprintf(f,
9598                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9599                         i,
9600                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9601                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9602                         (double)socket_stats.heap_allocsz_bytes * 100 /
9603                         (double)socket_stats.heap_totalsz_bytes,
9604                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9605                         socket_stats.alloc_count,
9606                         socket_stats.free_count);
9607         }
9608         fprintf(f,
9609                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9610                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9611                 (double)alloc * 100 / (double)total,
9612                 (double)free / (1024 * 1024),
9613                 n_alloc, n_free);
9614         if (last_allocs)
9615                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9616                         ((double)total - (double)last_total) / (1024 * 1024),
9617                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9618         last_allocs = alloc;
9619         last_total = total;
9620 }
9621
9622 static void cmd_dump_parsed(void *parsed_result,
9623                             __rte_unused struct cmdline *cl,
9624                             __rte_unused void *data)
9625 {
9626         struct cmd_dump_result *res = parsed_result;
9627
9628         if (!strcmp(res->dump, "dump_physmem"))
9629                 rte_dump_physmem_layout(stdout);
9630         else if (!strcmp(res->dump, "dump_socket_mem"))
9631                 dump_socket_mem(stdout);
9632         else if (!strcmp(res->dump, "dump_memzone"))
9633                 rte_memzone_dump(stdout);
9634         else if (!strcmp(res->dump, "dump_struct_sizes"))
9635                 dump_struct_sizes();
9636         else if (!strcmp(res->dump, "dump_ring"))
9637                 rte_ring_list_dump(stdout);
9638         else if (!strcmp(res->dump, "dump_mempool"))
9639                 rte_mempool_list_dump(stdout);
9640         else if (!strcmp(res->dump, "dump_devargs"))
9641                 rte_devargs_dump(stdout);
9642         else if (!strcmp(res->dump, "dump_log_types"))
9643                 rte_log_dump(stdout);
9644 }
9645
9646 cmdline_parse_token_string_t cmd_dump_dump =
9647         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9648                 "dump_physmem#"
9649                 "dump_memzone#"
9650                 "dump_socket_mem#"
9651                 "dump_struct_sizes#"
9652                 "dump_ring#"
9653                 "dump_mempool#"
9654                 "dump_devargs#"
9655                 "dump_log_types");
9656
9657 cmdline_parse_inst_t cmd_dump = {
9658         .f = cmd_dump_parsed,  /* function to call */
9659         .data = NULL,      /* 2nd arg of func */
9660         .help_str = "Dump status",
9661         .tokens = {        /* token list, NULL terminated */
9662                 (void *)&cmd_dump_dump,
9663                 NULL,
9664         },
9665 };
9666
9667 /* ******************************************************************************** */
9668
9669 struct cmd_dump_one_result {
9670         cmdline_fixed_string_t dump;
9671         cmdline_fixed_string_t name;
9672 };
9673
9674 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9675                                 __rte_unused void *data)
9676 {
9677         struct cmd_dump_one_result *res = parsed_result;
9678
9679         if (!strcmp(res->dump, "dump_ring")) {
9680                 struct rte_ring *r;
9681                 r = rte_ring_lookup(res->name);
9682                 if (r == NULL) {
9683                         cmdline_printf(cl, "Cannot find ring\n");
9684                         return;
9685                 }
9686                 rte_ring_dump(stdout, r);
9687         } else if (!strcmp(res->dump, "dump_mempool")) {
9688                 struct rte_mempool *mp;
9689                 mp = rte_mempool_lookup(res->name);
9690                 if (mp == NULL) {
9691                         cmdline_printf(cl, "Cannot find mempool\n");
9692                         return;
9693                 }
9694                 rte_mempool_dump(stdout, mp);
9695         }
9696 }
9697
9698 cmdline_parse_token_string_t cmd_dump_one_dump =
9699         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9700                                  "dump_ring#dump_mempool");
9701
9702 cmdline_parse_token_string_t cmd_dump_one_name =
9703         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9704
9705 cmdline_parse_inst_t cmd_dump_one = {
9706         .f = cmd_dump_one_parsed,  /* function to call */
9707         .data = NULL,      /* 2nd arg of func */
9708         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9709         .tokens = {        /* token list, NULL terminated */
9710                 (void *)&cmd_dump_one_dump,
9711                 (void *)&cmd_dump_one_name,
9712                 NULL,
9713         },
9714 };
9715
9716 /* *** queue region set *** */
9717 struct cmd_queue_region_result {
9718         cmdline_fixed_string_t set;
9719         cmdline_fixed_string_t port;
9720         portid_t port_id;
9721         cmdline_fixed_string_t cmd;
9722         cmdline_fixed_string_t region;
9723         uint8_t  region_id;
9724         cmdline_fixed_string_t queue_start_index;
9725         uint8_t  queue_id;
9726         cmdline_fixed_string_t queue_num;
9727         uint8_t  queue_num_value;
9728 };
9729
9730 static void
9731 cmd_queue_region_parsed(void *parsed_result,
9732                         __rte_unused struct cmdline *cl,
9733                         __rte_unused void *data)
9734 {
9735         struct cmd_queue_region_result *res = parsed_result;
9736         int ret = -ENOTSUP;
9737 #ifdef RTE_NET_I40E
9738         struct rte_pmd_i40e_queue_region_conf region_conf;
9739         enum rte_pmd_i40e_queue_region_op op_type;
9740 #endif
9741
9742         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9743                 return;
9744
9745 #ifdef RTE_NET_I40E
9746         memset(&region_conf, 0, sizeof(region_conf));
9747         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9748         region_conf.region_id = res->region_id;
9749         region_conf.queue_num = res->queue_num_value;
9750         region_conf.queue_start_index = res->queue_id;
9751
9752         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9753                                 op_type, &region_conf);
9754 #endif
9755
9756         switch (ret) {
9757         case 0:
9758                 break;
9759         case -ENOTSUP:
9760                 printf("function not implemented or supported\n");
9761                 break;
9762         default:
9763                 printf("queue region config error: (%s)\n", strerror(-ret));
9764         }
9765 }
9766
9767 cmdline_parse_token_string_t cmd_queue_region_set =
9768 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9769                 set, "set");
9770 cmdline_parse_token_string_t cmd_queue_region_port =
9771         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9772 cmdline_parse_token_num_t cmd_queue_region_port_id =
9773         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9774                                 port_id, UINT16);
9775 cmdline_parse_token_string_t cmd_queue_region_cmd =
9776         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9777                                  cmd, "queue-region");
9778 cmdline_parse_token_string_t cmd_queue_region_id =
9779         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9780                                 region, "region_id");
9781 cmdline_parse_token_num_t cmd_queue_region_index =
9782         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9783                                 region_id, UINT8);
9784 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9785         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9786                                 queue_start_index, "queue_start_index");
9787 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9788         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9789                                 queue_id, UINT8);
9790 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9791         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9792                                 queue_num, "queue_num");
9793 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9794         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9795                                 queue_num_value, UINT8);
9796
9797 cmdline_parse_inst_t cmd_queue_region = {
9798         .f = cmd_queue_region_parsed,
9799         .data = NULL,
9800         .help_str = "set port <port_id> queue-region region_id <value> "
9801                 "queue_start_index <value> queue_num <value>: Set a queue region",
9802         .tokens = {
9803                 (void *)&cmd_queue_region_set,
9804                 (void *)&cmd_queue_region_port,
9805                 (void *)&cmd_queue_region_port_id,
9806                 (void *)&cmd_queue_region_cmd,
9807                 (void *)&cmd_queue_region_id,
9808                 (void *)&cmd_queue_region_index,
9809                 (void *)&cmd_queue_region_queue_start_index,
9810                 (void *)&cmd_queue_region_queue_id,
9811                 (void *)&cmd_queue_region_queue_num,
9812                 (void *)&cmd_queue_region_queue_num_value,
9813                 NULL,
9814         },
9815 };
9816
9817 /* *** queue region and flowtype set *** */
9818 struct cmd_region_flowtype_result {
9819         cmdline_fixed_string_t set;
9820         cmdline_fixed_string_t port;
9821         portid_t port_id;
9822         cmdline_fixed_string_t cmd;
9823         cmdline_fixed_string_t region;
9824         uint8_t  region_id;
9825         cmdline_fixed_string_t flowtype;
9826         uint8_t  flowtype_id;
9827 };
9828
9829 static void
9830 cmd_region_flowtype_parsed(void *parsed_result,
9831                         __rte_unused struct cmdline *cl,
9832                         __rte_unused void *data)
9833 {
9834         struct cmd_region_flowtype_result *res = parsed_result;
9835         int ret = -ENOTSUP;
9836 #ifdef RTE_NET_I40E
9837         struct rte_pmd_i40e_queue_region_conf region_conf;
9838         enum rte_pmd_i40e_queue_region_op op_type;
9839 #endif
9840
9841         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9842                 return;
9843
9844 #ifdef RTE_NET_I40E
9845         memset(&region_conf, 0, sizeof(region_conf));
9846
9847         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9848         region_conf.region_id = res->region_id;
9849         region_conf.hw_flowtype = res->flowtype_id;
9850
9851         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9852                         op_type, &region_conf);
9853 #endif
9854
9855         switch (ret) {
9856         case 0:
9857                 break;
9858         case -ENOTSUP:
9859                 printf("function not implemented or supported\n");
9860                 break;
9861         default:
9862                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9863         }
9864 }
9865
9866 cmdline_parse_token_string_t cmd_region_flowtype_set =
9867 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9868                                 set, "set");
9869 cmdline_parse_token_string_t cmd_region_flowtype_port =
9870         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9871                                 port, "port");
9872 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9873         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9874                                 port_id, UINT16);
9875 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9876         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9877                                 cmd, "queue-region");
9878 cmdline_parse_token_string_t cmd_region_flowtype_index =
9879         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9880                                 region, "region_id");
9881 cmdline_parse_token_num_t cmd_region_flowtype_id =
9882         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9883                                 region_id, UINT8);
9884 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9885         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9886                                 flowtype, "flowtype");
9887 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9888         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9889                                 flowtype_id, UINT8);
9890 cmdline_parse_inst_t cmd_region_flowtype = {
9891         .f = cmd_region_flowtype_parsed,
9892         .data = NULL,
9893         .help_str = "set port <port_id> queue-region region_id <value> "
9894                 "flowtype <value>: Set a flowtype region index",
9895         .tokens = {
9896                 (void *)&cmd_region_flowtype_set,
9897                 (void *)&cmd_region_flowtype_port,
9898                 (void *)&cmd_region_flowtype_port_index,
9899                 (void *)&cmd_region_flowtype_cmd,
9900                 (void *)&cmd_region_flowtype_index,
9901                 (void *)&cmd_region_flowtype_id,
9902                 (void *)&cmd_region_flowtype_flow_index,
9903                 (void *)&cmd_region_flowtype_flow_id,
9904                 NULL,
9905         },
9906 };
9907
9908 /* *** User Priority (UP) to queue region (region_id) set *** */
9909 struct cmd_user_priority_region_result {
9910         cmdline_fixed_string_t set;
9911         cmdline_fixed_string_t port;
9912         portid_t port_id;
9913         cmdline_fixed_string_t cmd;
9914         cmdline_fixed_string_t user_priority;
9915         uint8_t  user_priority_id;
9916         cmdline_fixed_string_t region;
9917         uint8_t  region_id;
9918 };
9919
9920 static void
9921 cmd_user_priority_region_parsed(void *parsed_result,
9922                         __rte_unused struct cmdline *cl,
9923                         __rte_unused void *data)
9924 {
9925         struct cmd_user_priority_region_result *res = parsed_result;
9926         int ret = -ENOTSUP;
9927 #ifdef RTE_NET_I40E
9928         struct rte_pmd_i40e_queue_region_conf region_conf;
9929         enum rte_pmd_i40e_queue_region_op op_type;
9930 #endif
9931
9932         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9933                 return;
9934
9935 #ifdef RTE_NET_I40E
9936         memset(&region_conf, 0, sizeof(region_conf));
9937         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9938         region_conf.user_priority = res->user_priority_id;
9939         region_conf.region_id = res->region_id;
9940
9941         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9942                                 op_type, &region_conf);
9943 #endif
9944
9945         switch (ret) {
9946         case 0:
9947                 break;
9948         case -ENOTSUP:
9949                 printf("function not implemented or supported\n");
9950                 break;
9951         default:
9952                 printf("user_priority region config error: (%s)\n",
9953                                 strerror(-ret));
9954         }
9955 }
9956
9957 cmdline_parse_token_string_t cmd_user_priority_region_set =
9958         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9959                                 set, "set");
9960 cmdline_parse_token_string_t cmd_user_priority_region_port =
9961         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9962                                 port, "port");
9963 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9964         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9965                                 port_id, UINT16);
9966 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9967         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9968                                 cmd, "queue-region");
9969 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9970         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9971                                 user_priority, "UP");
9972 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9973         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9974                                 user_priority_id, UINT8);
9975 cmdline_parse_token_string_t cmd_user_priority_region_region =
9976         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9977                                 region, "region_id");
9978 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9979         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9980                                 region_id, UINT8);
9981
9982 cmdline_parse_inst_t cmd_user_priority_region = {
9983         .f = cmd_user_priority_region_parsed,
9984         .data = NULL,
9985         .help_str = "set port <port_id> queue-region UP <value> "
9986                 "region_id <value>: Set the mapping of User Priority (UP) "
9987                 "to queue region (region_id) ",
9988         .tokens = {
9989                 (void *)&cmd_user_priority_region_set,
9990                 (void *)&cmd_user_priority_region_port,
9991                 (void *)&cmd_user_priority_region_port_index,
9992                 (void *)&cmd_user_priority_region_cmd,
9993                 (void *)&cmd_user_priority_region_UP,
9994                 (void *)&cmd_user_priority_region_UP_id,
9995                 (void *)&cmd_user_priority_region_region,
9996                 (void *)&cmd_user_priority_region_region_id,
9997                 NULL,
9998         },
9999 };
10000
10001 /* *** flush all queue region related configuration *** */
10002 struct cmd_flush_queue_region_result {
10003         cmdline_fixed_string_t set;
10004         cmdline_fixed_string_t port;
10005         portid_t port_id;
10006         cmdline_fixed_string_t cmd;
10007         cmdline_fixed_string_t flush;
10008         cmdline_fixed_string_t what;
10009 };
10010
10011 static void
10012 cmd_flush_queue_region_parsed(void *parsed_result,
10013                         __rte_unused struct cmdline *cl,
10014                         __rte_unused void *data)
10015 {
10016         struct cmd_flush_queue_region_result *res = parsed_result;
10017         int ret = -ENOTSUP;
10018 #ifdef RTE_NET_I40E
10019         struct rte_pmd_i40e_queue_region_conf region_conf;
10020         enum rte_pmd_i40e_queue_region_op op_type;
10021 #endif
10022
10023         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10024                 return;
10025
10026 #ifdef RTE_NET_I40E
10027         memset(&region_conf, 0, sizeof(region_conf));
10028
10029         if (strcmp(res->what, "on") == 0)
10030                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10031         else
10032                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10033
10034         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10035                                 op_type, &region_conf);
10036 #endif
10037
10038         switch (ret) {
10039         case 0:
10040                 break;
10041         case -ENOTSUP:
10042                 printf("function not implemented or supported\n");
10043                 break;
10044         default:
10045                 printf("queue region config flush error: (%s)\n",
10046                                 strerror(-ret));
10047         }
10048 }
10049
10050 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10051         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10052                                 set, "set");
10053 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10054         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10055                                 port, "port");
10056 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10057         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10058                                 port_id, UINT16);
10059 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10060         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10061                                 cmd, "queue-region");
10062 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10063         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10064                                 flush, "flush");
10065 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10066         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10067                                 what, "on#off");
10068
10069 cmdline_parse_inst_t cmd_flush_queue_region = {
10070         .f = cmd_flush_queue_region_parsed,
10071         .data = NULL,
10072         .help_str = "set port <port_id> queue-region flush on|off"
10073                 ": flush all queue region related configuration",
10074         .tokens = {
10075                 (void *)&cmd_flush_queue_region_set,
10076                 (void *)&cmd_flush_queue_region_port,
10077                 (void *)&cmd_flush_queue_region_port_index,
10078                 (void *)&cmd_flush_queue_region_cmd,
10079                 (void *)&cmd_flush_queue_region_flush,
10080                 (void *)&cmd_flush_queue_region_what,
10081                 NULL,
10082         },
10083 };
10084
10085 /* *** get all queue region related configuration info *** */
10086 struct cmd_show_queue_region_info {
10087         cmdline_fixed_string_t show;
10088         cmdline_fixed_string_t port;
10089         portid_t port_id;
10090         cmdline_fixed_string_t cmd;
10091 };
10092
10093 static void
10094 cmd_show_queue_region_info_parsed(void *parsed_result,
10095                         __rte_unused struct cmdline *cl,
10096                         __rte_unused void *data)
10097 {
10098         struct cmd_show_queue_region_info *res = parsed_result;
10099         int ret = -ENOTSUP;
10100 #ifdef RTE_NET_I40E
10101         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10102         enum rte_pmd_i40e_queue_region_op op_type;
10103 #endif
10104
10105         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10106                 return;
10107
10108 #ifdef RTE_NET_I40E
10109         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10110
10111         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10112
10113         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10114                                         op_type, &rte_pmd_regions);
10115
10116         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10117 #endif
10118
10119         switch (ret) {
10120         case 0:
10121                 break;
10122         case -ENOTSUP:
10123                 printf("function not implemented or supported\n");
10124                 break;
10125         default:
10126                 printf("queue region config info show error: (%s)\n",
10127                                 strerror(-ret));
10128         }
10129 }
10130
10131 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10132 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10133                                 show, "show");
10134 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10135         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10136                                 port, "port");
10137 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10138         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10139                                 port_id, UINT16);
10140 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10141         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10142                                 cmd, "queue-region");
10143
10144 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10145         .f = cmd_show_queue_region_info_parsed,
10146         .data = NULL,
10147         .help_str = "show port <port_id> queue-region"
10148                 ": show all queue region related configuration info",
10149         .tokens = {
10150                 (void *)&cmd_show_queue_region_info_get,
10151                 (void *)&cmd_show_queue_region_info_port,
10152                 (void *)&cmd_show_queue_region_info_port_index,
10153                 (void *)&cmd_show_queue_region_info_cmd,
10154                 NULL,
10155         },
10156 };
10157
10158 /* *** Filters Control *** */
10159
10160 /* *** deal with flow director filter *** */
10161 struct cmd_flow_director_result {
10162         cmdline_fixed_string_t flow_director_filter;
10163         portid_t port_id;
10164         cmdline_fixed_string_t mode;
10165         cmdline_fixed_string_t mode_value;
10166         cmdline_fixed_string_t ops;
10167         cmdline_fixed_string_t flow;
10168         cmdline_fixed_string_t flow_type;
10169         cmdline_fixed_string_t ether;
10170         uint16_t ether_type;
10171         cmdline_fixed_string_t src;
10172         cmdline_ipaddr_t ip_src;
10173         uint16_t port_src;
10174         cmdline_fixed_string_t dst;
10175         cmdline_ipaddr_t ip_dst;
10176         uint16_t port_dst;
10177         cmdline_fixed_string_t verify_tag;
10178         uint32_t verify_tag_value;
10179         cmdline_fixed_string_t tos;
10180         uint8_t tos_value;
10181         cmdline_fixed_string_t proto;
10182         uint8_t proto_value;
10183         cmdline_fixed_string_t ttl;
10184         uint8_t ttl_value;
10185         cmdline_fixed_string_t vlan;
10186         uint16_t vlan_value;
10187         cmdline_fixed_string_t flexbytes;
10188         cmdline_fixed_string_t flexbytes_value;
10189         cmdline_fixed_string_t pf_vf;
10190         cmdline_fixed_string_t drop;
10191         cmdline_fixed_string_t queue;
10192         uint16_t  queue_id;
10193         cmdline_fixed_string_t fd_id;
10194         uint32_t  fd_id_value;
10195         cmdline_fixed_string_t mac;
10196         struct rte_ether_addr mac_addr;
10197         cmdline_fixed_string_t tunnel;
10198         cmdline_fixed_string_t tunnel_type;
10199         cmdline_fixed_string_t tunnel_id;
10200         uint32_t tunnel_id_value;
10201         cmdline_fixed_string_t packet;
10202         char filepath[];
10203 };
10204
10205 static inline int
10206 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10207 {
10208         char s[256];
10209         const char *p, *p0 = q_arg;
10210         char *end;
10211         unsigned long int_fld;
10212         char *str_fld[max_num];
10213         int i;
10214         unsigned size;
10215         int ret = -1;
10216
10217         p = strchr(p0, '(');
10218         if (p == NULL)
10219                 return -1;
10220         ++p;
10221         p0 = strchr(p, ')');
10222         if (p0 == NULL)
10223                 return -1;
10224
10225         size = p0 - p;
10226         if (size >= sizeof(s))
10227                 return -1;
10228
10229         snprintf(s, sizeof(s), "%.*s", size, p);
10230         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10231         if (ret < 0 || ret > max_num)
10232                 return -1;
10233         for (i = 0; i < ret; i++) {
10234                 errno = 0;
10235                 int_fld = strtoul(str_fld[i], &end, 0);
10236                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10237                         return -1;
10238                 flexbytes[i] = (uint8_t)int_fld;
10239         }
10240         return ret;
10241 }
10242
10243 static uint16_t
10244 str2flowtype(char *string)
10245 {
10246         uint8_t i = 0;
10247         static const struct {
10248                 char str[32];
10249                 uint16_t type;
10250         } flowtype_str[] = {
10251                 {"raw", RTE_ETH_FLOW_RAW},
10252                 {"ipv4", RTE_ETH_FLOW_IPV4},
10253                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10254                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10255                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10256                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10257                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10258                 {"ipv6", RTE_ETH_FLOW_IPV6},
10259                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10260                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10261                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10262                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10263                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10264                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10265         };
10266
10267         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10268                 if (!strcmp(flowtype_str[i].str, string))
10269                         return flowtype_str[i].type;
10270         }
10271
10272         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10273                 return (uint16_t)atoi(string);
10274
10275         return RTE_ETH_FLOW_UNKNOWN;
10276 }
10277
10278 static enum rte_eth_fdir_tunnel_type
10279 str2fdir_tunneltype(char *string)
10280 {
10281         uint8_t i = 0;
10282
10283         static const struct {
10284                 char str[32];
10285                 enum rte_eth_fdir_tunnel_type type;
10286         } tunneltype_str[] = {
10287                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10288                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10289         };
10290
10291         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10292                 if (!strcmp(tunneltype_str[i].str, string))
10293                         return tunneltype_str[i].type;
10294         }
10295         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10296 }
10297
10298 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10299 do { \
10300         if ((ip_addr).family == AF_INET) \
10301                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10302         else { \
10303                 printf("invalid parameter.\n"); \
10304                 return; \
10305         } \
10306 } while (0)
10307
10308 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10309 do { \
10310         if ((ip_addr).family == AF_INET6) \
10311                 rte_memcpy(&(ip), \
10312                                  &((ip_addr).addr.ipv6), \
10313                                  sizeof(struct in6_addr)); \
10314         else { \
10315                 printf("invalid parameter.\n"); \
10316                 return; \
10317         } \
10318 } while (0)
10319
10320 static void
10321 cmd_flow_director_filter_parsed(void *parsed_result,
10322                           __rte_unused struct cmdline *cl,
10323                           __rte_unused void *data)
10324 {
10325         struct cmd_flow_director_result *res = parsed_result;
10326         struct rte_eth_fdir_filter entry;
10327         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10328         char *end;
10329         unsigned long vf_id;
10330         int ret = 0;
10331
10332         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10333         if (ret < 0) {
10334                 printf("flow director is not supported on port %u.\n",
10335                         res->port_id);
10336                 return;
10337         }
10338         memset(flexbytes, 0, sizeof(flexbytes));
10339         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10340
10341         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10342                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10343                         printf("Please set mode to MAC-VLAN.\n");
10344                         return;
10345                 }
10346         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10347                 if (strcmp(res->mode_value, "Tunnel")) {
10348                         printf("Please set mode to Tunnel.\n");
10349                         return;
10350                 }
10351         } else {
10352                 if (!strcmp(res->mode_value, "raw")) {
10353 #ifdef RTE_NET_I40E
10354                         struct rte_pmd_i40e_flow_type_mapping
10355                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10356                         struct rte_pmd_i40e_pkt_template_conf conf;
10357                         uint16_t flow_type = str2flowtype(res->flow_type);
10358                         uint16_t i, port = res->port_id;
10359                         uint8_t add;
10360
10361                         memset(&conf, 0, sizeof(conf));
10362
10363                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10364                                 printf("Invalid flow type specified.\n");
10365                                 return;
10366                         }
10367                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10368                                                                  mapping);
10369                         if (ret)
10370                                 return;
10371                         if (mapping[flow_type].pctype == 0ULL) {
10372                                 printf("Invalid flow type specified.\n");
10373                                 return;
10374                         }
10375                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10376                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10377                                         conf.input.pctype = i;
10378                                         break;
10379                                 }
10380                         }
10381
10382                         conf.input.packet = open_file(res->filepath,
10383                                                 &conf.input.length);
10384                         if (!conf.input.packet)
10385                                 return;
10386                         if (!strcmp(res->drop, "drop"))
10387                                 conf.action.behavior =
10388                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10389                         else
10390                                 conf.action.behavior =
10391                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10392                         conf.action.report_status =
10393                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10394                         conf.action.rx_queue = res->queue_id;
10395                         conf.soft_id = res->fd_id_value;
10396                         add  = strcmp(res->ops, "del") ? 1 : 0;
10397                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10398                                                                         &conf,
10399                                                                         add);
10400                         if (ret < 0)
10401                                 printf("flow director config error: (%s)\n",
10402                                        strerror(-ret));
10403                         close_file(conf.input.packet);
10404 #endif
10405                         return;
10406                 } else if (strcmp(res->mode_value, "IP")) {
10407                         printf("Please set mode to IP or raw.\n");
10408                         return;
10409                 }
10410                 entry.input.flow_type = str2flowtype(res->flow_type);
10411         }
10412
10413         ret = parse_flexbytes(res->flexbytes_value,
10414                                         flexbytes,
10415                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10416         if (ret < 0) {
10417                 printf("error: Cannot parse flexbytes input.\n");
10418                 return;
10419         }
10420
10421         switch (entry.input.flow_type) {
10422         case RTE_ETH_FLOW_FRAG_IPV4:
10423         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10424                 entry.input.flow.ip4_flow.proto = res->proto_value;
10425                 /* fall-through */
10426         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10427         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10428                 IPV4_ADDR_TO_UINT(res->ip_dst,
10429                         entry.input.flow.ip4_flow.dst_ip);
10430                 IPV4_ADDR_TO_UINT(res->ip_src,
10431                         entry.input.flow.ip4_flow.src_ip);
10432                 entry.input.flow.ip4_flow.tos = res->tos_value;
10433                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10434                 /* need convert to big endian. */
10435                 entry.input.flow.udp4_flow.dst_port =
10436                                 rte_cpu_to_be_16(res->port_dst);
10437                 entry.input.flow.udp4_flow.src_port =
10438                                 rte_cpu_to_be_16(res->port_src);
10439                 break;
10440         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10441                 IPV4_ADDR_TO_UINT(res->ip_dst,
10442                         entry.input.flow.sctp4_flow.ip.dst_ip);
10443                 IPV4_ADDR_TO_UINT(res->ip_src,
10444                         entry.input.flow.sctp4_flow.ip.src_ip);
10445                 entry.input.flow.ip4_flow.tos = res->tos_value;
10446                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10447                 /* need convert to big endian. */
10448                 entry.input.flow.sctp4_flow.dst_port =
10449                                 rte_cpu_to_be_16(res->port_dst);
10450                 entry.input.flow.sctp4_flow.src_port =
10451                                 rte_cpu_to_be_16(res->port_src);
10452                 entry.input.flow.sctp4_flow.verify_tag =
10453                                 rte_cpu_to_be_32(res->verify_tag_value);
10454                 break;
10455         case RTE_ETH_FLOW_FRAG_IPV6:
10456         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10457                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10458                 /* fall-through */
10459         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10460         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10461                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10462                         entry.input.flow.ipv6_flow.dst_ip);
10463                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10464                         entry.input.flow.ipv6_flow.src_ip);
10465                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10466                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10467                 /* need convert to big endian. */
10468                 entry.input.flow.udp6_flow.dst_port =
10469                                 rte_cpu_to_be_16(res->port_dst);
10470                 entry.input.flow.udp6_flow.src_port =
10471                                 rte_cpu_to_be_16(res->port_src);
10472                 break;
10473         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10474                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10475                         entry.input.flow.sctp6_flow.ip.dst_ip);
10476                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10477                         entry.input.flow.sctp6_flow.ip.src_ip);
10478                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10479                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10480                 /* need convert to big endian. */
10481                 entry.input.flow.sctp6_flow.dst_port =
10482                                 rte_cpu_to_be_16(res->port_dst);
10483                 entry.input.flow.sctp6_flow.src_port =
10484                                 rte_cpu_to_be_16(res->port_src);
10485                 entry.input.flow.sctp6_flow.verify_tag =
10486                                 rte_cpu_to_be_32(res->verify_tag_value);
10487                 break;
10488         case RTE_ETH_FLOW_L2_PAYLOAD:
10489                 entry.input.flow.l2_flow.ether_type =
10490                         rte_cpu_to_be_16(res->ether_type);
10491                 break;
10492         default:
10493                 break;
10494         }
10495
10496         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10497                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10498                                  &res->mac_addr,
10499                                  sizeof(struct rte_ether_addr));
10500
10501         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10502                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10503                                  &res->mac_addr,
10504                                  sizeof(struct rte_ether_addr));
10505                 entry.input.flow.tunnel_flow.tunnel_type =
10506                         str2fdir_tunneltype(res->tunnel_type);
10507                 entry.input.flow.tunnel_flow.tunnel_id =
10508                         rte_cpu_to_be_32(res->tunnel_id_value);
10509         }
10510
10511         rte_memcpy(entry.input.flow_ext.flexbytes,
10512                    flexbytes,
10513                    RTE_ETH_FDIR_MAX_FLEXLEN);
10514
10515         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10516
10517         entry.action.flex_off = 0;  /*use 0 by default */
10518         if (!strcmp(res->drop, "drop"))
10519                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10520         else
10521                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10522
10523         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10524             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10525                 if (!strcmp(res->pf_vf, "pf"))
10526                         entry.input.flow_ext.is_vf = 0;
10527                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10528                         struct rte_eth_dev_info dev_info;
10529
10530                         ret = eth_dev_info_get_print_err(res->port_id,
10531                                                 &dev_info);
10532                         if (ret != 0)
10533                                 return;
10534
10535                         errno = 0;
10536                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10537                         if (errno != 0 || *end != '\0' ||
10538                             vf_id >= dev_info.max_vfs) {
10539                                 printf("invalid parameter %s.\n", res->pf_vf);
10540                                 return;
10541                         }
10542                         entry.input.flow_ext.is_vf = 1;
10543                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10544                 } else {
10545                         printf("invalid parameter %s.\n", res->pf_vf);
10546                         return;
10547                 }
10548         }
10549
10550         /* set to report FD ID by default */
10551         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10552         entry.action.rx_queue = res->queue_id;
10553         entry.soft_id = res->fd_id_value;
10554         if (!strcmp(res->ops, "add"))
10555                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10556                                              RTE_ETH_FILTER_ADD, &entry);
10557         else if (!strcmp(res->ops, "del"))
10558                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10559                                              RTE_ETH_FILTER_DELETE, &entry);
10560         else
10561                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10562                                              RTE_ETH_FILTER_UPDATE, &entry);
10563         if (ret < 0)
10564                 printf("flow director programming error: (%s)\n",
10565                         strerror(-ret));
10566 }
10567
10568 cmdline_parse_token_string_t cmd_flow_director_filter =
10569         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10570                                  flow_director_filter, "flow_director_filter");
10571 cmdline_parse_token_num_t cmd_flow_director_port_id =
10572         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10573                               port_id, UINT16);
10574 cmdline_parse_token_string_t cmd_flow_director_ops =
10575         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10576                                  ops, "add#del#update");
10577 cmdline_parse_token_string_t cmd_flow_director_flow =
10578         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10579                                  flow, "flow");
10580 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10581         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10582                 flow_type, NULL);
10583 cmdline_parse_token_string_t cmd_flow_director_ether =
10584         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10585                                  ether, "ether");
10586 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10587         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10588                               ether_type, UINT16);
10589 cmdline_parse_token_string_t cmd_flow_director_src =
10590         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10591                                  src, "src");
10592 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10593         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10594                                  ip_src);
10595 cmdline_parse_token_num_t cmd_flow_director_port_src =
10596         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10597                               port_src, UINT16);
10598 cmdline_parse_token_string_t cmd_flow_director_dst =
10599         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10600                                  dst, "dst");
10601 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10602         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10603                                  ip_dst);
10604 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10605         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10606                               port_dst, UINT16);
10607 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10608         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10609                                   verify_tag, "verify_tag");
10610 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10611         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10612                               verify_tag_value, UINT32);
10613 cmdline_parse_token_string_t cmd_flow_director_tos =
10614         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10615                                  tos, "tos");
10616 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10617         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10618                               tos_value, UINT8);
10619 cmdline_parse_token_string_t cmd_flow_director_proto =
10620         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10621                                  proto, "proto");
10622 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10623         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10624                               proto_value, UINT8);
10625 cmdline_parse_token_string_t cmd_flow_director_ttl =
10626         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10627                                  ttl, "ttl");
10628 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10629         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10630                               ttl_value, UINT8);
10631 cmdline_parse_token_string_t cmd_flow_director_vlan =
10632         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10633                                  vlan, "vlan");
10634 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10635         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10636                               vlan_value, UINT16);
10637 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10638         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10639                                  flexbytes, "flexbytes");
10640 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10641         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10642                               flexbytes_value, NULL);
10643 cmdline_parse_token_string_t cmd_flow_director_drop =
10644         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10645                                  drop, "drop#fwd");
10646 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10647         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10648                               pf_vf, NULL);
10649 cmdline_parse_token_string_t cmd_flow_director_queue =
10650         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10651                                  queue, "queue");
10652 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10653         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10654                               queue_id, UINT16);
10655 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10656         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10657                                  fd_id, "fd_id");
10658 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10659         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10660                               fd_id_value, UINT32);
10661
10662 cmdline_parse_token_string_t cmd_flow_director_mode =
10663         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10664                                  mode, "mode");
10665 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10666         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10667                                  mode_value, "IP");
10668 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10669         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10670                                  mode_value, "MAC-VLAN");
10671 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10672         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10673                                  mode_value, "Tunnel");
10674 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10675         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10676                                  mode_value, "raw");
10677 cmdline_parse_token_string_t cmd_flow_director_mac =
10678         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10679                                  mac, "mac");
10680 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10681         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10682                                     mac_addr);
10683 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10684         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10685                                  tunnel, "tunnel");
10686 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10687         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10688                                  tunnel_type, "NVGRE#VxLAN");
10689 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10690         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10691                                  tunnel_id, "tunnel-id");
10692 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10693         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10694                               tunnel_id_value, UINT32);
10695 cmdline_parse_token_string_t cmd_flow_director_packet =
10696         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10697                                  packet, "packet");
10698 cmdline_parse_token_string_t cmd_flow_director_filepath =
10699         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10700                                  filepath, NULL);
10701
10702 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10703         .f = cmd_flow_director_filter_parsed,
10704         .data = NULL,
10705         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10706                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10707                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10708                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10709                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10710                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10711                 "fd_id <fd_id_value>: "
10712                 "Add or delete an ip flow director entry on NIC",
10713         .tokens = {
10714                 (void *)&cmd_flow_director_filter,
10715                 (void *)&cmd_flow_director_port_id,
10716                 (void *)&cmd_flow_director_mode,
10717                 (void *)&cmd_flow_director_mode_ip,
10718                 (void *)&cmd_flow_director_ops,
10719                 (void *)&cmd_flow_director_flow,
10720                 (void *)&cmd_flow_director_flow_type,
10721                 (void *)&cmd_flow_director_src,
10722                 (void *)&cmd_flow_director_ip_src,
10723                 (void *)&cmd_flow_director_dst,
10724                 (void *)&cmd_flow_director_ip_dst,
10725                 (void *)&cmd_flow_director_tos,
10726                 (void *)&cmd_flow_director_tos_value,
10727                 (void *)&cmd_flow_director_proto,
10728                 (void *)&cmd_flow_director_proto_value,
10729                 (void *)&cmd_flow_director_ttl,
10730                 (void *)&cmd_flow_director_ttl_value,
10731                 (void *)&cmd_flow_director_vlan,
10732                 (void *)&cmd_flow_director_vlan_value,
10733                 (void *)&cmd_flow_director_flexbytes,
10734                 (void *)&cmd_flow_director_flexbytes_value,
10735                 (void *)&cmd_flow_director_drop,
10736                 (void *)&cmd_flow_director_pf_vf,
10737                 (void *)&cmd_flow_director_queue,
10738                 (void *)&cmd_flow_director_queue_id,
10739                 (void *)&cmd_flow_director_fd_id,
10740                 (void *)&cmd_flow_director_fd_id_value,
10741                 NULL,
10742         },
10743 };
10744
10745 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10746         .f = cmd_flow_director_filter_parsed,
10747         .data = NULL,
10748         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10749                 "director entry on NIC",
10750         .tokens = {
10751                 (void *)&cmd_flow_director_filter,
10752                 (void *)&cmd_flow_director_port_id,
10753                 (void *)&cmd_flow_director_mode,
10754                 (void *)&cmd_flow_director_mode_ip,
10755                 (void *)&cmd_flow_director_ops,
10756                 (void *)&cmd_flow_director_flow,
10757                 (void *)&cmd_flow_director_flow_type,
10758                 (void *)&cmd_flow_director_src,
10759                 (void *)&cmd_flow_director_ip_src,
10760                 (void *)&cmd_flow_director_port_src,
10761                 (void *)&cmd_flow_director_dst,
10762                 (void *)&cmd_flow_director_ip_dst,
10763                 (void *)&cmd_flow_director_port_dst,
10764                 (void *)&cmd_flow_director_tos,
10765                 (void *)&cmd_flow_director_tos_value,
10766                 (void *)&cmd_flow_director_ttl,
10767                 (void *)&cmd_flow_director_ttl_value,
10768                 (void *)&cmd_flow_director_vlan,
10769                 (void *)&cmd_flow_director_vlan_value,
10770                 (void *)&cmd_flow_director_flexbytes,
10771                 (void *)&cmd_flow_director_flexbytes_value,
10772                 (void *)&cmd_flow_director_drop,
10773                 (void *)&cmd_flow_director_pf_vf,
10774                 (void *)&cmd_flow_director_queue,
10775                 (void *)&cmd_flow_director_queue_id,
10776                 (void *)&cmd_flow_director_fd_id,
10777                 (void *)&cmd_flow_director_fd_id_value,
10778                 NULL,
10779         },
10780 };
10781
10782 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10783         .f = cmd_flow_director_filter_parsed,
10784         .data = NULL,
10785         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10786                 "director entry on NIC",
10787         .tokens = {
10788                 (void *)&cmd_flow_director_filter,
10789                 (void *)&cmd_flow_director_port_id,
10790                 (void *)&cmd_flow_director_mode,
10791                 (void *)&cmd_flow_director_mode_ip,
10792                 (void *)&cmd_flow_director_ops,
10793                 (void *)&cmd_flow_director_flow,
10794                 (void *)&cmd_flow_director_flow_type,
10795                 (void *)&cmd_flow_director_src,
10796                 (void *)&cmd_flow_director_ip_src,
10797                 (void *)&cmd_flow_director_port_src,
10798                 (void *)&cmd_flow_director_dst,
10799                 (void *)&cmd_flow_director_ip_dst,
10800                 (void *)&cmd_flow_director_port_dst,
10801                 (void *)&cmd_flow_director_verify_tag,
10802                 (void *)&cmd_flow_director_verify_tag_value,
10803                 (void *)&cmd_flow_director_tos,
10804                 (void *)&cmd_flow_director_tos_value,
10805                 (void *)&cmd_flow_director_ttl,
10806                 (void *)&cmd_flow_director_ttl_value,
10807                 (void *)&cmd_flow_director_vlan,
10808                 (void *)&cmd_flow_director_vlan_value,
10809                 (void *)&cmd_flow_director_flexbytes,
10810                 (void *)&cmd_flow_director_flexbytes_value,
10811                 (void *)&cmd_flow_director_drop,
10812                 (void *)&cmd_flow_director_pf_vf,
10813                 (void *)&cmd_flow_director_queue,
10814                 (void *)&cmd_flow_director_queue_id,
10815                 (void *)&cmd_flow_director_fd_id,
10816                 (void *)&cmd_flow_director_fd_id_value,
10817                 NULL,
10818         },
10819 };
10820
10821 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10822         .f = cmd_flow_director_filter_parsed,
10823         .data = NULL,
10824         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10825                 "director entry on NIC",
10826         .tokens = {
10827                 (void *)&cmd_flow_director_filter,
10828                 (void *)&cmd_flow_director_port_id,
10829                 (void *)&cmd_flow_director_mode,
10830                 (void *)&cmd_flow_director_mode_ip,
10831                 (void *)&cmd_flow_director_ops,
10832                 (void *)&cmd_flow_director_flow,
10833                 (void *)&cmd_flow_director_flow_type,
10834                 (void *)&cmd_flow_director_ether,
10835                 (void *)&cmd_flow_director_ether_type,
10836                 (void *)&cmd_flow_director_flexbytes,
10837                 (void *)&cmd_flow_director_flexbytes_value,
10838                 (void *)&cmd_flow_director_drop,
10839                 (void *)&cmd_flow_director_pf_vf,
10840                 (void *)&cmd_flow_director_queue,
10841                 (void *)&cmd_flow_director_queue_id,
10842                 (void *)&cmd_flow_director_fd_id,
10843                 (void *)&cmd_flow_director_fd_id_value,
10844                 NULL,
10845         },
10846 };
10847
10848 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10849         .f = cmd_flow_director_filter_parsed,
10850         .data = NULL,
10851         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10852                 "director entry on NIC",
10853         .tokens = {
10854                 (void *)&cmd_flow_director_filter,
10855                 (void *)&cmd_flow_director_port_id,
10856                 (void *)&cmd_flow_director_mode,
10857                 (void *)&cmd_flow_director_mode_mac_vlan,
10858                 (void *)&cmd_flow_director_ops,
10859                 (void *)&cmd_flow_director_mac,
10860                 (void *)&cmd_flow_director_mac_addr,
10861                 (void *)&cmd_flow_director_vlan,
10862                 (void *)&cmd_flow_director_vlan_value,
10863                 (void *)&cmd_flow_director_flexbytes,
10864                 (void *)&cmd_flow_director_flexbytes_value,
10865                 (void *)&cmd_flow_director_drop,
10866                 (void *)&cmd_flow_director_queue,
10867                 (void *)&cmd_flow_director_queue_id,
10868                 (void *)&cmd_flow_director_fd_id,
10869                 (void *)&cmd_flow_director_fd_id_value,
10870                 NULL,
10871         },
10872 };
10873
10874 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10875         .f = cmd_flow_director_filter_parsed,
10876         .data = NULL,
10877         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10878                 "director entry on NIC",
10879         .tokens = {
10880                 (void *)&cmd_flow_director_filter,
10881                 (void *)&cmd_flow_director_port_id,
10882                 (void *)&cmd_flow_director_mode,
10883                 (void *)&cmd_flow_director_mode_tunnel,
10884                 (void *)&cmd_flow_director_ops,
10885                 (void *)&cmd_flow_director_mac,
10886                 (void *)&cmd_flow_director_mac_addr,
10887                 (void *)&cmd_flow_director_vlan,
10888                 (void *)&cmd_flow_director_vlan_value,
10889                 (void *)&cmd_flow_director_tunnel,
10890                 (void *)&cmd_flow_director_tunnel_type,
10891                 (void *)&cmd_flow_director_tunnel_id,
10892                 (void *)&cmd_flow_director_tunnel_id_value,
10893                 (void *)&cmd_flow_director_flexbytes,
10894                 (void *)&cmd_flow_director_flexbytes_value,
10895                 (void *)&cmd_flow_director_drop,
10896                 (void *)&cmd_flow_director_queue,
10897                 (void *)&cmd_flow_director_queue_id,
10898                 (void *)&cmd_flow_director_fd_id,
10899                 (void *)&cmd_flow_director_fd_id_value,
10900                 NULL,
10901         },
10902 };
10903
10904 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10905         .f = cmd_flow_director_filter_parsed,
10906         .data = NULL,
10907         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10908                 "director entry on NIC",
10909         .tokens = {
10910                 (void *)&cmd_flow_director_filter,
10911                 (void *)&cmd_flow_director_port_id,
10912                 (void *)&cmd_flow_director_mode,
10913                 (void *)&cmd_flow_director_mode_raw,
10914                 (void *)&cmd_flow_director_ops,
10915                 (void *)&cmd_flow_director_flow,
10916                 (void *)&cmd_flow_director_flow_type,
10917                 (void *)&cmd_flow_director_drop,
10918                 (void *)&cmd_flow_director_queue,
10919                 (void *)&cmd_flow_director_queue_id,
10920                 (void *)&cmd_flow_director_fd_id,
10921                 (void *)&cmd_flow_director_fd_id_value,
10922                 (void *)&cmd_flow_director_packet,
10923                 (void *)&cmd_flow_director_filepath,
10924                 NULL,
10925         },
10926 };
10927
10928 struct cmd_flush_flow_director_result {
10929         cmdline_fixed_string_t flush_flow_director;
10930         portid_t port_id;
10931 };
10932
10933 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10934         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10935                                  flush_flow_director, "flush_flow_director");
10936 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10937         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10938                               port_id, UINT16);
10939
10940 static void
10941 cmd_flush_flow_director_parsed(void *parsed_result,
10942                           __rte_unused struct cmdline *cl,
10943                           __rte_unused void *data)
10944 {
10945         struct cmd_flow_director_result *res = parsed_result;
10946         int ret = 0;
10947
10948         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10949         if (ret < 0) {
10950                 printf("flow director is not supported on port %u.\n",
10951                         res->port_id);
10952                 return;
10953         }
10954
10955         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10956                         RTE_ETH_FILTER_FLUSH, NULL);
10957         if (ret < 0)
10958                 printf("flow director table flushing error: (%s)\n",
10959                         strerror(-ret));
10960 }
10961
10962 cmdline_parse_inst_t cmd_flush_flow_director = {
10963         .f = cmd_flush_flow_director_parsed,
10964         .data = NULL,
10965         .help_str = "flush_flow_director <port_id>: "
10966                 "Flush all flow director entries of a device on NIC",
10967         .tokens = {
10968                 (void *)&cmd_flush_flow_director_flush,
10969                 (void *)&cmd_flush_flow_director_port_id,
10970                 NULL,
10971         },
10972 };
10973
10974 /* *** deal with flow director mask *** */
10975 struct cmd_flow_director_mask_result {
10976         cmdline_fixed_string_t flow_director_mask;
10977         portid_t port_id;
10978         cmdline_fixed_string_t mode;
10979         cmdline_fixed_string_t mode_value;
10980         cmdline_fixed_string_t vlan;
10981         uint16_t vlan_mask;
10982         cmdline_fixed_string_t src_mask;
10983         cmdline_ipaddr_t ipv4_src;
10984         cmdline_ipaddr_t ipv6_src;
10985         uint16_t port_src;
10986         cmdline_fixed_string_t dst_mask;
10987         cmdline_ipaddr_t ipv4_dst;
10988         cmdline_ipaddr_t ipv6_dst;
10989         uint16_t port_dst;
10990         cmdline_fixed_string_t mac;
10991         uint8_t mac_addr_byte_mask;
10992         cmdline_fixed_string_t tunnel_id;
10993         uint32_t tunnel_id_mask;
10994         cmdline_fixed_string_t tunnel_type;
10995         uint8_t tunnel_type_mask;
10996 };
10997
10998 static void
10999 cmd_flow_director_mask_parsed(void *parsed_result,
11000                           __rte_unused struct cmdline *cl,
11001                           __rte_unused void *data)
11002 {
11003         struct cmd_flow_director_mask_result *res = parsed_result;
11004         struct rte_eth_fdir_masks *mask;
11005         struct rte_port *port;
11006
11007         port = &ports[res->port_id];
11008         /** Check if the port is not started **/
11009         if (port->port_status != RTE_PORT_STOPPED) {
11010                 printf("Please stop port %d first\n", res->port_id);
11011                 return;
11012         }
11013
11014         mask = &port->dev_conf.fdir_conf.mask;
11015
11016         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11017                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11018                         printf("Please set mode to MAC-VLAN.\n");
11019                         return;
11020                 }
11021
11022                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11023         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11024                 if (strcmp(res->mode_value, "Tunnel")) {
11025                         printf("Please set mode to Tunnel.\n");
11026                         return;
11027                 }
11028
11029                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11030                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11031                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11032                 mask->tunnel_type_mask = res->tunnel_type_mask;
11033         } else {
11034                 if (strcmp(res->mode_value, "IP")) {
11035                         printf("Please set mode to IP.\n");
11036                         return;
11037                 }
11038
11039                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11040                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11041                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11042                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11043                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11044                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11045                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11046         }
11047
11048         cmd_reconfig_device_queue(res->port_id, 1, 1);
11049 }
11050
11051 cmdline_parse_token_string_t cmd_flow_director_mask =
11052         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11053                                  flow_director_mask, "flow_director_mask");
11054 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11055         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11056                               port_id, UINT16);
11057 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11058         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11059                                  vlan, "vlan");
11060 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11061         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11062                               vlan_mask, UINT16);
11063 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11064         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11065                                  src_mask, "src_mask");
11066 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11067         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11068                                  ipv4_src);
11069 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11070         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11071                                  ipv6_src);
11072 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11073         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11074                               port_src, UINT16);
11075 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11076         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11077                                  dst_mask, "dst_mask");
11078 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11079         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11080                                  ipv4_dst);
11081 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11082         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11083                                  ipv6_dst);
11084 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11085         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11086                               port_dst, UINT16);
11087
11088 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11089         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11090                                  mode, "mode");
11091 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11092         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11093                                  mode_value, "IP");
11094 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11095         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11096                                  mode_value, "MAC-VLAN");
11097 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11098         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11099                                  mode_value, "Tunnel");
11100 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11101         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11102                                  mac, "mac");
11103 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11104         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11105                               mac_addr_byte_mask, UINT8);
11106 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11107         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11108                                  tunnel_type, "tunnel-type");
11109 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11110         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11111                               tunnel_type_mask, UINT8);
11112 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11113         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11114                                  tunnel_id, "tunnel-id");
11115 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11116         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11117                               tunnel_id_mask, UINT32);
11118
11119 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11120         .f = cmd_flow_director_mask_parsed,
11121         .data = NULL,
11122         .help_str = "flow_director_mask ... : "
11123                 "Set IP mode flow director's mask on NIC",
11124         .tokens = {
11125                 (void *)&cmd_flow_director_mask,
11126                 (void *)&cmd_flow_director_mask_port_id,
11127                 (void *)&cmd_flow_director_mask_mode,
11128                 (void *)&cmd_flow_director_mask_mode_ip,
11129                 (void *)&cmd_flow_director_mask_vlan,
11130                 (void *)&cmd_flow_director_mask_vlan_value,
11131                 (void *)&cmd_flow_director_mask_src,
11132                 (void *)&cmd_flow_director_mask_ipv4_src,
11133                 (void *)&cmd_flow_director_mask_ipv6_src,
11134                 (void *)&cmd_flow_director_mask_port_src,
11135                 (void *)&cmd_flow_director_mask_dst,
11136                 (void *)&cmd_flow_director_mask_ipv4_dst,
11137                 (void *)&cmd_flow_director_mask_ipv6_dst,
11138                 (void *)&cmd_flow_director_mask_port_dst,
11139                 NULL,
11140         },
11141 };
11142
11143 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11144         .f = cmd_flow_director_mask_parsed,
11145         .data = NULL,
11146         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11147                 "flow director's mask on NIC",
11148         .tokens = {
11149                 (void *)&cmd_flow_director_mask,
11150                 (void *)&cmd_flow_director_mask_port_id,
11151                 (void *)&cmd_flow_director_mask_mode,
11152                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11153                 (void *)&cmd_flow_director_mask_vlan,
11154                 (void *)&cmd_flow_director_mask_vlan_value,
11155                 NULL,
11156         },
11157 };
11158
11159 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11160         .f = cmd_flow_director_mask_parsed,
11161         .data = NULL,
11162         .help_str = "flow_director_mask ... : Set tunnel mode "
11163                 "flow director's mask on NIC",
11164         .tokens = {
11165                 (void *)&cmd_flow_director_mask,
11166                 (void *)&cmd_flow_director_mask_port_id,
11167                 (void *)&cmd_flow_director_mask_mode,
11168                 (void *)&cmd_flow_director_mask_mode_tunnel,
11169                 (void *)&cmd_flow_director_mask_vlan,
11170                 (void *)&cmd_flow_director_mask_vlan_value,
11171                 (void *)&cmd_flow_director_mask_mac,
11172                 (void *)&cmd_flow_director_mask_mac_value,
11173                 (void *)&cmd_flow_director_mask_tunnel_type,
11174                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11175                 (void *)&cmd_flow_director_mask_tunnel_id,
11176                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11177                 NULL,
11178         },
11179 };
11180
11181 /* *** deal with flow director mask on flexible payload *** */
11182 struct cmd_flow_director_flex_mask_result {
11183         cmdline_fixed_string_t flow_director_flexmask;
11184         portid_t port_id;
11185         cmdline_fixed_string_t flow;
11186         cmdline_fixed_string_t flow_type;
11187         cmdline_fixed_string_t mask;
11188 };
11189
11190 static void
11191 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11192                           __rte_unused struct cmdline *cl,
11193                           __rte_unused void *data)
11194 {
11195         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11196         struct rte_eth_fdir_info fdir_info;
11197         struct rte_eth_fdir_flex_mask flex_mask;
11198         struct rte_port *port;
11199         uint64_t flow_type_mask;
11200         uint16_t i;
11201         int ret;
11202
11203         port = &ports[res->port_id];
11204         /** Check if the port is not started **/
11205         if (port->port_status != RTE_PORT_STOPPED) {
11206                 printf("Please stop port %d first\n", res->port_id);
11207                 return;
11208         }
11209
11210         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11211         ret = parse_flexbytes(res->mask,
11212                         flex_mask.mask,
11213                         RTE_ETH_FDIR_MAX_FLEXLEN);
11214         if (ret < 0) {
11215                 printf("error: Cannot parse mask input.\n");
11216                 return;
11217         }
11218
11219         memset(&fdir_info, 0, sizeof(fdir_info));
11220         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11221                                 RTE_ETH_FILTER_INFO, &fdir_info);
11222         if (ret < 0) {
11223                 printf("Cannot get FDir filter info\n");
11224                 return;
11225         }
11226
11227         if (!strcmp(res->flow_type, "none")) {
11228                 /* means don't specify the flow type */
11229                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11230                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11231                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11232                                0, sizeof(struct rte_eth_fdir_flex_mask));
11233                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11234                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11235                                  &flex_mask,
11236                                  sizeof(struct rte_eth_fdir_flex_mask));
11237                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11238                 return;
11239         }
11240         flow_type_mask = fdir_info.flow_types_mask[0];
11241         if (!strcmp(res->flow_type, "all")) {
11242                 if (!flow_type_mask) {
11243                         printf("No flow type supported\n");
11244                         return;
11245                 }
11246                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11247                         if (flow_type_mask & (1ULL << i)) {
11248                                 flex_mask.flow_type = i;
11249                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11250                         }
11251                 }
11252                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11253                 return;
11254         }
11255         flex_mask.flow_type = str2flowtype(res->flow_type);
11256         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11257                 printf("Flow type %s not supported on port %d\n",
11258                                 res->flow_type, res->port_id);
11259                 return;
11260         }
11261         fdir_set_flex_mask(res->port_id, &flex_mask);
11262         cmd_reconfig_device_queue(res->port_id, 1, 1);
11263 }
11264
11265 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11267                                  flow_director_flexmask,
11268                                  "flow_director_flex_mask");
11269 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11270         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11271                               port_id, UINT16);
11272 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11273         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11274                                  flow, "flow");
11275 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11276         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11277                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11278                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11279 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11280         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11281                                  mask, NULL);
11282
11283 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11284         .f = cmd_flow_director_flex_mask_parsed,
11285         .data = NULL,
11286         .help_str = "flow_director_flex_mask ... : "
11287                 "Set flow director's flex mask on NIC",
11288         .tokens = {
11289                 (void *)&cmd_flow_director_flexmask,
11290                 (void *)&cmd_flow_director_flexmask_port_id,
11291                 (void *)&cmd_flow_director_flexmask_flow,
11292                 (void *)&cmd_flow_director_flexmask_flow_type,
11293                 (void *)&cmd_flow_director_flexmask_mask,
11294                 NULL,
11295         },
11296 };
11297
11298 /* *** deal with flow director flexible payload configuration *** */
11299 struct cmd_flow_director_flexpayload_result {
11300         cmdline_fixed_string_t flow_director_flexpayload;
11301         portid_t port_id;
11302         cmdline_fixed_string_t payload_layer;
11303         cmdline_fixed_string_t payload_cfg;
11304 };
11305
11306 static inline int
11307 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11308 {
11309         char s[256];
11310         const char *p, *p0 = q_arg;
11311         char *end;
11312         unsigned long int_fld;
11313         char *str_fld[max_num];
11314         int i;
11315         unsigned size;
11316         int ret = -1;
11317
11318         p = strchr(p0, '(');
11319         if (p == NULL)
11320                 return -1;
11321         ++p;
11322         p0 = strchr(p, ')');
11323         if (p0 == NULL)
11324                 return -1;
11325
11326         size = p0 - p;
11327         if (size >= sizeof(s))
11328                 return -1;
11329
11330         snprintf(s, sizeof(s), "%.*s", size, p);
11331         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11332         if (ret < 0 || ret > max_num)
11333                 return -1;
11334         for (i = 0; i < ret; i++) {
11335                 errno = 0;
11336                 int_fld = strtoul(str_fld[i], &end, 0);
11337                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11338                         return -1;
11339                 offsets[i] = (uint16_t)int_fld;
11340         }
11341         return ret;
11342 }
11343
11344 static void
11345 cmd_flow_director_flxpld_parsed(void *parsed_result,
11346                           __rte_unused struct cmdline *cl,
11347                           __rte_unused void *data)
11348 {
11349         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11350         struct rte_eth_flex_payload_cfg flex_cfg;
11351         struct rte_port *port;
11352         int ret = 0;
11353
11354         port = &ports[res->port_id];
11355         /** Check if the port is not started **/
11356         if (port->port_status != RTE_PORT_STOPPED) {
11357                 printf("Please stop port %d first\n", res->port_id);
11358                 return;
11359         }
11360
11361         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11362
11363         if (!strcmp(res->payload_layer, "raw"))
11364                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11365         else if (!strcmp(res->payload_layer, "l2"))
11366                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11367         else if (!strcmp(res->payload_layer, "l3"))
11368                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11369         else if (!strcmp(res->payload_layer, "l4"))
11370                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11371
11372         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11373                             RTE_ETH_FDIR_MAX_FLEXLEN);
11374         if (ret < 0) {
11375                 printf("error: Cannot parse flex payload input.\n");
11376                 return;
11377         }
11378
11379         fdir_set_flex_payload(res->port_id, &flex_cfg);
11380         cmd_reconfig_device_queue(res->port_id, 1, 1);
11381 }
11382
11383 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11384         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11385                                  flow_director_flexpayload,
11386                                  "flow_director_flex_payload");
11387 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11388         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11389                               port_id, UINT16);
11390 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11391         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11392                                  payload_layer, "raw#l2#l3#l4");
11393 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11394         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11395                                  payload_cfg, NULL);
11396
11397 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11398         .f = cmd_flow_director_flxpld_parsed,
11399         .data = NULL,
11400         .help_str = "flow_director_flexpayload ... : "
11401                 "Set flow director's flex payload on NIC",
11402         .tokens = {
11403                 (void *)&cmd_flow_director_flexpayload,
11404                 (void *)&cmd_flow_director_flexpayload_port_id,
11405                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11406                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11407                 NULL,
11408         },
11409 };
11410
11411 /* Generic flow interface command. */
11412 extern cmdline_parse_inst_t cmd_flow;
11413
11414 /* *** Classification Filters Control *** */
11415
11416 static enum rte_eth_input_set_field
11417 str2inset(char *string)
11418 {
11419         uint16_t i;
11420
11421         static const struct {
11422                 char str[32];
11423                 enum rte_eth_input_set_field inset;
11424         } inset_table[] = {
11425                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11426                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11427                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11428                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11429                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11430                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11431                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11432                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11433                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11434                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11435                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11436                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11437                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11438                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11439                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11440                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11441                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11442                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11443                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11444                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11445                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11446                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11447                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11448                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11449                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11450                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11451                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11452                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11453                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11454                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11455                 {"none", RTE_ETH_INPUT_SET_NONE},
11456         };
11457
11458         for (i = 0; i < RTE_DIM(inset_table); i++) {
11459                 if (!strcmp(string, inset_table[i].str))
11460                         return inset_table[i].inset;
11461         }
11462
11463         return RTE_ETH_INPUT_SET_UNKNOWN;
11464 }
11465
11466 /* Set flow director input set */
11467 struct cmd_set_fdir_input_set_result {
11468         cmdline_fixed_string_t set_fdir_input_set;
11469         portid_t port_id;
11470         cmdline_fixed_string_t flow_type;
11471         cmdline_fixed_string_t inset_field;
11472         cmdline_fixed_string_t select;
11473 };
11474
11475 static void
11476 cmd_set_fdir_input_set_parsed(void *parsed_result,
11477         __rte_unused struct cmdline *cl,
11478         __rte_unused void *data)
11479 {
11480         struct cmd_set_fdir_input_set_result *res = parsed_result;
11481         struct rte_eth_fdir_filter_info info;
11482
11483         memset(&info, 0, sizeof(info));
11484         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11485         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11486         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11487         info.info.input_set_conf.inset_size = 1;
11488         if (!strcmp(res->select, "select"))
11489                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11490         else if (!strcmp(res->select, "add"))
11491                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11492         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11493                 RTE_ETH_FILTER_SET, &info);
11494 }
11495
11496 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11497         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11498         set_fdir_input_set, "set_fdir_input_set");
11499 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11500         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11501         port_id, UINT16);
11502 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11503         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11504         flow_type,
11505         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11506         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11507 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11508         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11509         inset_field,
11510         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11511         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11512         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11513         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11514         "sctp-veri-tag#none");
11515 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11516         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11517         select, "select#add");
11518
11519 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11520         .f = cmd_set_fdir_input_set_parsed,
11521         .data = NULL,
11522         .help_str = "set_fdir_input_set <port_id> "
11523         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11524         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11525         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11526         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11527         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11528         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11529         "sctp-veri-tag|none select|add",
11530         .tokens = {
11531                 (void *)&cmd_set_fdir_input_set_cmd,
11532                 (void *)&cmd_set_fdir_input_set_port_id,
11533                 (void *)&cmd_set_fdir_input_set_flow_type,
11534                 (void *)&cmd_set_fdir_input_set_field,
11535                 (void *)&cmd_set_fdir_input_set_select,
11536                 NULL,
11537         },
11538 };
11539
11540 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11541 struct cmd_mcast_addr_result {
11542         cmdline_fixed_string_t mcast_addr_cmd;
11543         cmdline_fixed_string_t what;
11544         uint16_t port_num;
11545         struct rte_ether_addr mc_addr;
11546 };
11547
11548 static void cmd_mcast_addr_parsed(void *parsed_result,
11549                 __rte_unused struct cmdline *cl,
11550                 __rte_unused void *data)
11551 {
11552         struct cmd_mcast_addr_result *res = parsed_result;
11553
11554         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
11555                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11556                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11557                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11558                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11559                 return;
11560         }
11561         if (strcmp(res->what, "add") == 0)
11562                 mcast_addr_add(res->port_num, &res->mc_addr);
11563         else
11564                 mcast_addr_remove(res->port_num, &res->mc_addr);
11565 }
11566
11567 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11568         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11569                                  mcast_addr_cmd, "mcast_addr");
11570 cmdline_parse_token_string_t cmd_mcast_addr_what =
11571         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11572                                  "add#remove");
11573 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11574         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11575 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11576         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11577
11578 cmdline_parse_inst_t cmd_mcast_addr = {
11579         .f = cmd_mcast_addr_parsed,
11580         .data = (void *)0,
11581         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11582                 "Add/Remove multicast MAC address on port_id",
11583         .tokens = {
11584                 (void *)&cmd_mcast_addr_cmd,
11585                 (void *)&cmd_mcast_addr_what,
11586                 (void *)&cmd_mcast_addr_portnum,
11587                 (void *)&cmd_mcast_addr_addr,
11588                 NULL,
11589         },
11590 };
11591
11592 /* l2 tunnel config
11593  * only support E-tag now.
11594  */
11595
11596 /* Ether type config */
11597 struct cmd_config_l2_tunnel_eth_type_result {
11598         cmdline_fixed_string_t port;
11599         cmdline_fixed_string_t config;
11600         cmdline_fixed_string_t all;
11601         portid_t id;
11602         cmdline_fixed_string_t l2_tunnel;
11603         cmdline_fixed_string_t l2_tunnel_type;
11604         cmdline_fixed_string_t eth_type;
11605         uint16_t eth_type_val;
11606 };
11607
11608 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11609         TOKEN_STRING_INITIALIZER
11610                 (struct cmd_config_l2_tunnel_eth_type_result,
11611                  port, "port");
11612 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11613         TOKEN_STRING_INITIALIZER
11614                 (struct cmd_config_l2_tunnel_eth_type_result,
11615                  config, "config");
11616 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11617         TOKEN_STRING_INITIALIZER
11618                 (struct cmd_config_l2_tunnel_eth_type_result,
11619                  all, "all");
11620 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11621         TOKEN_NUM_INITIALIZER
11622                 (struct cmd_config_l2_tunnel_eth_type_result,
11623                  id, UINT16);
11624 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11625         TOKEN_STRING_INITIALIZER
11626                 (struct cmd_config_l2_tunnel_eth_type_result,
11627                  l2_tunnel, "l2-tunnel");
11628 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11629         TOKEN_STRING_INITIALIZER
11630                 (struct cmd_config_l2_tunnel_eth_type_result,
11631                  l2_tunnel_type, "E-tag");
11632 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11633         TOKEN_STRING_INITIALIZER
11634                 (struct cmd_config_l2_tunnel_eth_type_result,
11635                  eth_type, "ether-type");
11636 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11637         TOKEN_NUM_INITIALIZER
11638                 (struct cmd_config_l2_tunnel_eth_type_result,
11639                  eth_type_val, UINT16);
11640
11641 static enum rte_eth_tunnel_type
11642 str2fdir_l2_tunnel_type(char *string)
11643 {
11644         uint32_t i = 0;
11645
11646         static const struct {
11647                 char str[32];
11648                 enum rte_eth_tunnel_type type;
11649         } l2_tunnel_type_str[] = {
11650                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11651         };
11652
11653         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11654                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11655                         return l2_tunnel_type_str[i].type;
11656         }
11657         return RTE_TUNNEL_TYPE_NONE;
11658 }
11659
11660 /* ether type config for all ports */
11661 static void
11662 cmd_config_l2_tunnel_eth_type_all_parsed
11663         (void *parsed_result,
11664          __rte_unused struct cmdline *cl,
11665          __rte_unused void *data)
11666 {
11667         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11668         struct rte_eth_l2_tunnel_conf entry;
11669         portid_t pid;
11670
11671         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11672         entry.ether_type = res->eth_type_val;
11673
11674         RTE_ETH_FOREACH_DEV(pid) {
11675                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11676         }
11677 }
11678
11679 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11680         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11681         .data = NULL,
11682         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11683         .tokens = {
11684                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11685                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11686                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11687                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11688                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11689                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11690                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11691                 NULL,
11692         },
11693 };
11694
11695 /* ether type config for a specific port */
11696 static void
11697 cmd_config_l2_tunnel_eth_type_specific_parsed(
11698         void *parsed_result,
11699         __rte_unused struct cmdline *cl,
11700         __rte_unused void *data)
11701 {
11702         struct cmd_config_l2_tunnel_eth_type_result *res =
11703                  parsed_result;
11704         struct rte_eth_l2_tunnel_conf entry;
11705
11706         if (port_id_is_invalid(res->id, ENABLED_WARN))
11707                 return;
11708
11709         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11710         entry.ether_type = res->eth_type_val;
11711
11712         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11713 }
11714
11715 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11716         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11717         .data = NULL,
11718         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11719         .tokens = {
11720                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11721                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11722                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11723                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11724                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11725                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11726                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11727                 NULL,
11728         },
11729 };
11730
11731 /* Enable/disable l2 tunnel */
11732 struct cmd_config_l2_tunnel_en_dis_result {
11733         cmdline_fixed_string_t port;
11734         cmdline_fixed_string_t config;
11735         cmdline_fixed_string_t all;
11736         portid_t id;
11737         cmdline_fixed_string_t l2_tunnel;
11738         cmdline_fixed_string_t l2_tunnel_type;
11739         cmdline_fixed_string_t en_dis;
11740 };
11741
11742 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11743         TOKEN_STRING_INITIALIZER
11744                 (struct cmd_config_l2_tunnel_en_dis_result,
11745                  port, "port");
11746 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11747         TOKEN_STRING_INITIALIZER
11748                 (struct cmd_config_l2_tunnel_en_dis_result,
11749                  config, "config");
11750 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11751         TOKEN_STRING_INITIALIZER
11752                 (struct cmd_config_l2_tunnel_en_dis_result,
11753                  all, "all");
11754 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11755         TOKEN_NUM_INITIALIZER
11756                 (struct cmd_config_l2_tunnel_en_dis_result,
11757                  id, UINT16);
11758 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11759         TOKEN_STRING_INITIALIZER
11760                 (struct cmd_config_l2_tunnel_en_dis_result,
11761                  l2_tunnel, "l2-tunnel");
11762 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11763         TOKEN_STRING_INITIALIZER
11764                 (struct cmd_config_l2_tunnel_en_dis_result,
11765                  l2_tunnel_type, "E-tag");
11766 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11767         TOKEN_STRING_INITIALIZER
11768                 (struct cmd_config_l2_tunnel_en_dis_result,
11769                  en_dis, "enable#disable");
11770
11771 /* enable/disable l2 tunnel for all ports */
11772 static void
11773 cmd_config_l2_tunnel_en_dis_all_parsed(
11774         void *parsed_result,
11775         __rte_unused struct cmdline *cl,
11776         __rte_unused void *data)
11777 {
11778         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11779         struct rte_eth_l2_tunnel_conf entry;
11780         portid_t pid;
11781         uint8_t en;
11782
11783         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11784
11785         if (!strcmp("enable", res->en_dis))
11786                 en = 1;
11787         else
11788                 en = 0;
11789
11790         RTE_ETH_FOREACH_DEV(pid) {
11791                 rte_eth_dev_l2_tunnel_offload_set(pid,
11792                                                   &entry,
11793                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11794                                                   en);
11795         }
11796 }
11797
11798 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11799         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11800         .data = NULL,
11801         .help_str = "port config all l2-tunnel E-tag enable|disable",
11802         .tokens = {
11803                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11804                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11805                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11806                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11807                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11808                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11809                 NULL,
11810         },
11811 };
11812
11813 /* enable/disable l2 tunnel for a port */
11814 static void
11815 cmd_config_l2_tunnel_en_dis_specific_parsed(
11816         void *parsed_result,
11817         __rte_unused struct cmdline *cl,
11818         __rte_unused void *data)
11819 {
11820         struct cmd_config_l2_tunnel_en_dis_result *res =
11821                 parsed_result;
11822         struct rte_eth_l2_tunnel_conf entry;
11823
11824         if (port_id_is_invalid(res->id, ENABLED_WARN))
11825                 return;
11826
11827         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11828
11829         if (!strcmp("enable", res->en_dis))
11830                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11831                                                   &entry,
11832                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11833                                                   1);
11834         else
11835                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11836                                                   &entry,
11837                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11838                                                   0);
11839 }
11840
11841 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11842         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11843         .data = NULL,
11844         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11845         .tokens = {
11846                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11847                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11848                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11849                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11850                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11851                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11852                 NULL,
11853         },
11854 };
11855
11856 /* E-tag configuration */
11857
11858 /* Common result structure for all E-tag configuration */
11859 struct cmd_config_e_tag_result {
11860         cmdline_fixed_string_t e_tag;
11861         cmdline_fixed_string_t set;
11862         cmdline_fixed_string_t insertion;
11863         cmdline_fixed_string_t stripping;
11864         cmdline_fixed_string_t forwarding;
11865         cmdline_fixed_string_t filter;
11866         cmdline_fixed_string_t add;
11867         cmdline_fixed_string_t del;
11868         cmdline_fixed_string_t on;
11869         cmdline_fixed_string_t off;
11870         cmdline_fixed_string_t on_off;
11871         cmdline_fixed_string_t port_tag_id;
11872         uint32_t port_tag_id_val;
11873         cmdline_fixed_string_t e_tag_id;
11874         uint16_t e_tag_id_val;
11875         cmdline_fixed_string_t dst_pool;
11876         uint8_t dst_pool_val;
11877         cmdline_fixed_string_t port;
11878         portid_t port_id;
11879         cmdline_fixed_string_t vf;
11880         uint8_t vf_id;
11881 };
11882
11883 /* Common CLI fields for all E-tag configuration */
11884 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11885         TOKEN_STRING_INITIALIZER
11886                 (struct cmd_config_e_tag_result,
11887                  e_tag, "E-tag");
11888 cmdline_parse_token_string_t cmd_config_e_tag_set =
11889         TOKEN_STRING_INITIALIZER
11890                 (struct cmd_config_e_tag_result,
11891                  set, "set");
11892 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11893         TOKEN_STRING_INITIALIZER
11894                 (struct cmd_config_e_tag_result,
11895                  insertion, "insertion");
11896 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11897         TOKEN_STRING_INITIALIZER
11898                 (struct cmd_config_e_tag_result,
11899                  stripping, "stripping");
11900 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11901         TOKEN_STRING_INITIALIZER
11902                 (struct cmd_config_e_tag_result,
11903                  forwarding, "forwarding");
11904 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11905         TOKEN_STRING_INITIALIZER
11906                 (struct cmd_config_e_tag_result,
11907                  filter, "filter");
11908 cmdline_parse_token_string_t cmd_config_e_tag_add =
11909         TOKEN_STRING_INITIALIZER
11910                 (struct cmd_config_e_tag_result,
11911                  add, "add");
11912 cmdline_parse_token_string_t cmd_config_e_tag_del =
11913         TOKEN_STRING_INITIALIZER
11914                 (struct cmd_config_e_tag_result,
11915                  del, "del");
11916 cmdline_parse_token_string_t cmd_config_e_tag_on =
11917         TOKEN_STRING_INITIALIZER
11918                 (struct cmd_config_e_tag_result,
11919                  on, "on");
11920 cmdline_parse_token_string_t cmd_config_e_tag_off =
11921         TOKEN_STRING_INITIALIZER
11922                 (struct cmd_config_e_tag_result,
11923                  off, "off");
11924 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11925         TOKEN_STRING_INITIALIZER
11926                 (struct cmd_config_e_tag_result,
11927                  on_off, "on#off");
11928 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11929         TOKEN_STRING_INITIALIZER
11930                 (struct cmd_config_e_tag_result,
11931                  port_tag_id, "port-tag-id");
11932 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11933         TOKEN_NUM_INITIALIZER
11934                 (struct cmd_config_e_tag_result,
11935                  port_tag_id_val, UINT32);
11936 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11937         TOKEN_STRING_INITIALIZER
11938                 (struct cmd_config_e_tag_result,
11939                  e_tag_id, "e-tag-id");
11940 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11941         TOKEN_NUM_INITIALIZER
11942                 (struct cmd_config_e_tag_result,
11943                  e_tag_id_val, UINT16);
11944 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11945         TOKEN_STRING_INITIALIZER
11946                 (struct cmd_config_e_tag_result,
11947                  dst_pool, "dst-pool");
11948 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11949         TOKEN_NUM_INITIALIZER
11950                 (struct cmd_config_e_tag_result,
11951                  dst_pool_val, UINT8);
11952 cmdline_parse_token_string_t cmd_config_e_tag_port =
11953         TOKEN_STRING_INITIALIZER
11954                 (struct cmd_config_e_tag_result,
11955                  port, "port");
11956 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11957         TOKEN_NUM_INITIALIZER
11958                 (struct cmd_config_e_tag_result,
11959                  port_id, UINT16);
11960 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11961         TOKEN_STRING_INITIALIZER
11962                 (struct cmd_config_e_tag_result,
11963                  vf, "vf");
11964 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11965         TOKEN_NUM_INITIALIZER
11966                 (struct cmd_config_e_tag_result,
11967                  vf_id, UINT8);
11968
11969 /* E-tag insertion configuration */
11970 static void
11971 cmd_config_e_tag_insertion_en_parsed(
11972         void *parsed_result,
11973         __rte_unused struct cmdline *cl,
11974         __rte_unused void *data)
11975 {
11976         struct cmd_config_e_tag_result *res =
11977                 parsed_result;
11978         struct rte_eth_l2_tunnel_conf entry;
11979
11980         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11981                 return;
11982
11983         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11984         entry.tunnel_id = res->port_tag_id_val;
11985         entry.vf_id = res->vf_id;
11986         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11987                                           &entry,
11988                                           ETH_L2_TUNNEL_INSERTION_MASK,
11989                                           1);
11990 }
11991
11992 static void
11993 cmd_config_e_tag_insertion_dis_parsed(
11994         void *parsed_result,
11995         __rte_unused struct cmdline *cl,
11996         __rte_unused void *data)
11997 {
11998         struct cmd_config_e_tag_result *res =
11999                 parsed_result;
12000         struct rte_eth_l2_tunnel_conf entry;
12001
12002         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12003                 return;
12004
12005         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12006         entry.vf_id = res->vf_id;
12007
12008         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12009                                           &entry,
12010                                           ETH_L2_TUNNEL_INSERTION_MASK,
12011                                           0);
12012 }
12013
12014 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12015         .f = cmd_config_e_tag_insertion_en_parsed,
12016         .data = NULL,
12017         .help_str = "E-tag ... : E-tag insertion enable",
12018         .tokens = {
12019                 (void *)&cmd_config_e_tag_e_tag,
12020                 (void *)&cmd_config_e_tag_set,
12021                 (void *)&cmd_config_e_tag_insertion,
12022                 (void *)&cmd_config_e_tag_on,
12023                 (void *)&cmd_config_e_tag_port_tag_id,
12024                 (void *)&cmd_config_e_tag_port_tag_id_val,
12025                 (void *)&cmd_config_e_tag_port,
12026                 (void *)&cmd_config_e_tag_port_id,
12027                 (void *)&cmd_config_e_tag_vf,
12028                 (void *)&cmd_config_e_tag_vf_id,
12029                 NULL,
12030         },
12031 };
12032
12033 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12034         .f = cmd_config_e_tag_insertion_dis_parsed,
12035         .data = NULL,
12036         .help_str = "E-tag ... : E-tag insertion disable",
12037         .tokens = {
12038                 (void *)&cmd_config_e_tag_e_tag,
12039                 (void *)&cmd_config_e_tag_set,
12040                 (void *)&cmd_config_e_tag_insertion,
12041                 (void *)&cmd_config_e_tag_off,
12042                 (void *)&cmd_config_e_tag_port,
12043                 (void *)&cmd_config_e_tag_port_id,
12044                 (void *)&cmd_config_e_tag_vf,
12045                 (void *)&cmd_config_e_tag_vf_id,
12046                 NULL,
12047         },
12048 };
12049
12050 /* E-tag stripping configuration */
12051 static void
12052 cmd_config_e_tag_stripping_parsed(
12053         void *parsed_result,
12054         __rte_unused struct cmdline *cl,
12055         __rte_unused void *data)
12056 {
12057         struct cmd_config_e_tag_result *res =
12058                 parsed_result;
12059         struct rte_eth_l2_tunnel_conf entry;
12060
12061         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12062                 return;
12063
12064         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12065
12066         if (!strcmp(res->on_off, "on"))
12067                 rte_eth_dev_l2_tunnel_offload_set
12068                         (res->port_id,
12069                          &entry,
12070                          ETH_L2_TUNNEL_STRIPPING_MASK,
12071                          1);
12072         else
12073                 rte_eth_dev_l2_tunnel_offload_set
12074                         (res->port_id,
12075                          &entry,
12076                          ETH_L2_TUNNEL_STRIPPING_MASK,
12077                          0);
12078 }
12079
12080 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12081         .f = cmd_config_e_tag_stripping_parsed,
12082         .data = NULL,
12083         .help_str = "E-tag ... : E-tag stripping enable/disable",
12084         .tokens = {
12085                 (void *)&cmd_config_e_tag_e_tag,
12086                 (void *)&cmd_config_e_tag_set,
12087                 (void *)&cmd_config_e_tag_stripping,
12088                 (void *)&cmd_config_e_tag_on_off,
12089                 (void *)&cmd_config_e_tag_port,
12090                 (void *)&cmd_config_e_tag_port_id,
12091                 NULL,
12092         },
12093 };
12094
12095 /* E-tag forwarding configuration */
12096 static void
12097 cmd_config_e_tag_forwarding_parsed(
12098         void *parsed_result,
12099         __rte_unused struct cmdline *cl,
12100         __rte_unused void *data)
12101 {
12102         struct cmd_config_e_tag_result *res = parsed_result;
12103         struct rte_eth_l2_tunnel_conf entry;
12104
12105         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12106                 return;
12107
12108         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12109
12110         if (!strcmp(res->on_off, "on"))
12111                 rte_eth_dev_l2_tunnel_offload_set
12112                         (res->port_id,
12113                          &entry,
12114                          ETH_L2_TUNNEL_FORWARDING_MASK,
12115                          1);
12116         else
12117                 rte_eth_dev_l2_tunnel_offload_set
12118                         (res->port_id,
12119                          &entry,
12120                          ETH_L2_TUNNEL_FORWARDING_MASK,
12121                          0);
12122 }
12123
12124 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12125         .f = cmd_config_e_tag_forwarding_parsed,
12126         .data = NULL,
12127         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12128         .tokens = {
12129                 (void *)&cmd_config_e_tag_e_tag,
12130                 (void *)&cmd_config_e_tag_set,
12131                 (void *)&cmd_config_e_tag_forwarding,
12132                 (void *)&cmd_config_e_tag_on_off,
12133                 (void *)&cmd_config_e_tag_port,
12134                 (void *)&cmd_config_e_tag_port_id,
12135                 NULL,
12136         },
12137 };
12138
12139 /* vf vlan anti spoof configuration */
12140
12141 /* Common result structure for vf vlan anti spoof */
12142 struct cmd_vf_vlan_anti_spoof_result {
12143         cmdline_fixed_string_t set;
12144         cmdline_fixed_string_t vf;
12145         cmdline_fixed_string_t vlan;
12146         cmdline_fixed_string_t antispoof;
12147         portid_t port_id;
12148         uint32_t vf_id;
12149         cmdline_fixed_string_t on_off;
12150 };
12151
12152 /* Common CLI fields for vf vlan anti spoof enable disable */
12153 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12154         TOKEN_STRING_INITIALIZER
12155                 (struct cmd_vf_vlan_anti_spoof_result,
12156                  set, "set");
12157 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12158         TOKEN_STRING_INITIALIZER
12159                 (struct cmd_vf_vlan_anti_spoof_result,
12160                  vf, "vf");
12161 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12162         TOKEN_STRING_INITIALIZER
12163                 (struct cmd_vf_vlan_anti_spoof_result,
12164                  vlan, "vlan");
12165 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12166         TOKEN_STRING_INITIALIZER
12167                 (struct cmd_vf_vlan_anti_spoof_result,
12168                  antispoof, "antispoof");
12169 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12170         TOKEN_NUM_INITIALIZER
12171                 (struct cmd_vf_vlan_anti_spoof_result,
12172                  port_id, UINT16);
12173 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12174         TOKEN_NUM_INITIALIZER
12175                 (struct cmd_vf_vlan_anti_spoof_result,
12176                  vf_id, UINT32);
12177 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12178         TOKEN_STRING_INITIALIZER
12179                 (struct cmd_vf_vlan_anti_spoof_result,
12180                  on_off, "on#off");
12181
12182 static void
12183 cmd_set_vf_vlan_anti_spoof_parsed(
12184         void *parsed_result,
12185         __rte_unused struct cmdline *cl,
12186         __rte_unused void *data)
12187 {
12188         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12189         int ret = -ENOTSUP;
12190
12191         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12192
12193         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12194                 return;
12195
12196 #ifdef RTE_NET_IXGBE
12197         if (ret == -ENOTSUP)
12198                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12199                                 res->vf_id, is_on);
12200 #endif
12201 #ifdef RTE_NET_I40E
12202         if (ret == -ENOTSUP)
12203                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12204                                 res->vf_id, is_on);
12205 #endif
12206 #ifdef RTE_NET_BNXT
12207         if (ret == -ENOTSUP)
12208                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12209                                 res->vf_id, is_on);
12210 #endif
12211
12212         switch (ret) {
12213         case 0:
12214                 break;
12215         case -EINVAL:
12216                 printf("invalid vf_id %d\n", res->vf_id);
12217                 break;
12218         case -ENODEV:
12219                 printf("invalid port_id %d\n", res->port_id);
12220                 break;
12221         case -ENOTSUP:
12222                 printf("function not implemented\n");
12223                 break;
12224         default:
12225                 printf("programming error: (%s)\n", strerror(-ret));
12226         }
12227 }
12228
12229 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12230         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12231         .data = NULL,
12232         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12233         .tokens = {
12234                 (void *)&cmd_vf_vlan_anti_spoof_set,
12235                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12236                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12237                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12238                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12239                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12240                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12241                 NULL,
12242         },
12243 };
12244
12245 /* vf mac anti spoof configuration */
12246
12247 /* Common result structure for vf mac anti spoof */
12248 struct cmd_vf_mac_anti_spoof_result {
12249         cmdline_fixed_string_t set;
12250         cmdline_fixed_string_t vf;
12251         cmdline_fixed_string_t mac;
12252         cmdline_fixed_string_t antispoof;
12253         portid_t port_id;
12254         uint32_t vf_id;
12255         cmdline_fixed_string_t on_off;
12256 };
12257
12258 /* Common CLI fields for vf mac anti spoof enable disable */
12259 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12260         TOKEN_STRING_INITIALIZER
12261                 (struct cmd_vf_mac_anti_spoof_result,
12262                  set, "set");
12263 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12264         TOKEN_STRING_INITIALIZER
12265                 (struct cmd_vf_mac_anti_spoof_result,
12266                  vf, "vf");
12267 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12268         TOKEN_STRING_INITIALIZER
12269                 (struct cmd_vf_mac_anti_spoof_result,
12270                  mac, "mac");
12271 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12272         TOKEN_STRING_INITIALIZER
12273                 (struct cmd_vf_mac_anti_spoof_result,
12274                  antispoof, "antispoof");
12275 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12276         TOKEN_NUM_INITIALIZER
12277                 (struct cmd_vf_mac_anti_spoof_result,
12278                  port_id, UINT16);
12279 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12280         TOKEN_NUM_INITIALIZER
12281                 (struct cmd_vf_mac_anti_spoof_result,
12282                  vf_id, UINT32);
12283 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12284         TOKEN_STRING_INITIALIZER
12285                 (struct cmd_vf_mac_anti_spoof_result,
12286                  on_off, "on#off");
12287
12288 static void
12289 cmd_set_vf_mac_anti_spoof_parsed(
12290         void *parsed_result,
12291         __rte_unused struct cmdline *cl,
12292         __rte_unused void *data)
12293 {
12294         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12295         int ret = -ENOTSUP;
12296
12297         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12298
12299         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12300                 return;
12301
12302 #ifdef RTE_NET_IXGBE
12303         if (ret == -ENOTSUP)
12304                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12305                         res->vf_id, is_on);
12306 #endif
12307 #ifdef RTE_NET_I40E
12308         if (ret == -ENOTSUP)
12309                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12310                         res->vf_id, is_on);
12311 #endif
12312 #ifdef RTE_NET_BNXT
12313         if (ret == -ENOTSUP)
12314                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12315                         res->vf_id, is_on);
12316 #endif
12317
12318         switch (ret) {
12319         case 0:
12320                 break;
12321         case -EINVAL:
12322                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12323                 break;
12324         case -ENODEV:
12325                 printf("invalid port_id %d\n", res->port_id);
12326                 break;
12327         case -ENOTSUP:
12328                 printf("function not implemented\n");
12329                 break;
12330         default:
12331                 printf("programming error: (%s)\n", strerror(-ret));
12332         }
12333 }
12334
12335 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12336         .f = cmd_set_vf_mac_anti_spoof_parsed,
12337         .data = NULL,
12338         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12339         .tokens = {
12340                 (void *)&cmd_vf_mac_anti_spoof_set,
12341                 (void *)&cmd_vf_mac_anti_spoof_vf,
12342                 (void *)&cmd_vf_mac_anti_spoof_mac,
12343                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12344                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12345                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12346                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12347                 NULL,
12348         },
12349 };
12350
12351 /* vf vlan strip queue configuration */
12352
12353 /* Common result structure for vf mac anti spoof */
12354 struct cmd_vf_vlan_stripq_result {
12355         cmdline_fixed_string_t set;
12356         cmdline_fixed_string_t vf;
12357         cmdline_fixed_string_t vlan;
12358         cmdline_fixed_string_t stripq;
12359         portid_t port_id;
12360         uint16_t vf_id;
12361         cmdline_fixed_string_t on_off;
12362 };
12363
12364 /* Common CLI fields for vf vlan strip enable disable */
12365 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12366         TOKEN_STRING_INITIALIZER
12367                 (struct cmd_vf_vlan_stripq_result,
12368                  set, "set");
12369 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12370         TOKEN_STRING_INITIALIZER
12371                 (struct cmd_vf_vlan_stripq_result,
12372                  vf, "vf");
12373 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12374         TOKEN_STRING_INITIALIZER
12375                 (struct cmd_vf_vlan_stripq_result,
12376                  vlan, "vlan");
12377 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12378         TOKEN_STRING_INITIALIZER
12379                 (struct cmd_vf_vlan_stripq_result,
12380                  stripq, "stripq");
12381 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12382         TOKEN_NUM_INITIALIZER
12383                 (struct cmd_vf_vlan_stripq_result,
12384                  port_id, UINT16);
12385 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12386         TOKEN_NUM_INITIALIZER
12387                 (struct cmd_vf_vlan_stripq_result,
12388                  vf_id, UINT16);
12389 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12390         TOKEN_STRING_INITIALIZER
12391                 (struct cmd_vf_vlan_stripq_result,
12392                  on_off, "on#off");
12393
12394 static void
12395 cmd_set_vf_vlan_stripq_parsed(
12396         void *parsed_result,
12397         __rte_unused struct cmdline *cl,
12398         __rte_unused void *data)
12399 {
12400         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12401         int ret = -ENOTSUP;
12402
12403         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12404
12405         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12406                 return;
12407
12408 #ifdef RTE_NET_IXGBE
12409         if (ret == -ENOTSUP)
12410                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12411                         res->vf_id, is_on);
12412 #endif
12413 #ifdef RTE_NET_I40E
12414         if (ret == -ENOTSUP)
12415                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12416                         res->vf_id, is_on);
12417 #endif
12418 #ifdef RTE_NET_BNXT
12419         if (ret == -ENOTSUP)
12420                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12421                         res->vf_id, is_on);
12422 #endif
12423
12424         switch (ret) {
12425         case 0:
12426                 break;
12427         case -EINVAL:
12428                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12429                 break;
12430         case -ENODEV:
12431                 printf("invalid port_id %d\n", res->port_id);
12432                 break;
12433         case -ENOTSUP:
12434                 printf("function not implemented\n");
12435                 break;
12436         default:
12437                 printf("programming error: (%s)\n", strerror(-ret));
12438         }
12439 }
12440
12441 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12442         .f = cmd_set_vf_vlan_stripq_parsed,
12443         .data = NULL,
12444         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12445         .tokens = {
12446                 (void *)&cmd_vf_vlan_stripq_set,
12447                 (void *)&cmd_vf_vlan_stripq_vf,
12448                 (void *)&cmd_vf_vlan_stripq_vlan,
12449                 (void *)&cmd_vf_vlan_stripq_stripq,
12450                 (void *)&cmd_vf_vlan_stripq_port_id,
12451                 (void *)&cmd_vf_vlan_stripq_vf_id,
12452                 (void *)&cmd_vf_vlan_stripq_on_off,
12453                 NULL,
12454         },
12455 };
12456
12457 /* vf vlan insert configuration */
12458
12459 /* Common result structure for vf vlan insert */
12460 struct cmd_vf_vlan_insert_result {
12461         cmdline_fixed_string_t set;
12462         cmdline_fixed_string_t vf;
12463         cmdline_fixed_string_t vlan;
12464         cmdline_fixed_string_t insert;
12465         portid_t port_id;
12466         uint16_t vf_id;
12467         uint16_t vlan_id;
12468 };
12469
12470 /* Common CLI fields for vf vlan insert enable disable */
12471 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12472         TOKEN_STRING_INITIALIZER
12473                 (struct cmd_vf_vlan_insert_result,
12474                  set, "set");
12475 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12476         TOKEN_STRING_INITIALIZER
12477                 (struct cmd_vf_vlan_insert_result,
12478                  vf, "vf");
12479 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12480         TOKEN_STRING_INITIALIZER
12481                 (struct cmd_vf_vlan_insert_result,
12482                  vlan, "vlan");
12483 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12484         TOKEN_STRING_INITIALIZER
12485                 (struct cmd_vf_vlan_insert_result,
12486                  insert, "insert");
12487 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12488         TOKEN_NUM_INITIALIZER
12489                 (struct cmd_vf_vlan_insert_result,
12490                  port_id, UINT16);
12491 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12492         TOKEN_NUM_INITIALIZER
12493                 (struct cmd_vf_vlan_insert_result,
12494                  vf_id, UINT16);
12495 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12496         TOKEN_NUM_INITIALIZER
12497                 (struct cmd_vf_vlan_insert_result,
12498                  vlan_id, UINT16);
12499
12500 static void
12501 cmd_set_vf_vlan_insert_parsed(
12502         void *parsed_result,
12503         __rte_unused struct cmdline *cl,
12504         __rte_unused void *data)
12505 {
12506         struct cmd_vf_vlan_insert_result *res = parsed_result;
12507         int ret = -ENOTSUP;
12508
12509         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12510                 return;
12511
12512 #ifdef RTE_NET_IXGBE
12513         if (ret == -ENOTSUP)
12514                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12515                         res->vlan_id);
12516 #endif
12517 #ifdef RTE_NET_I40E
12518         if (ret == -ENOTSUP)
12519                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12520                         res->vlan_id);
12521 #endif
12522 #ifdef RTE_NET_BNXT
12523         if (ret == -ENOTSUP)
12524                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12525                         res->vlan_id);
12526 #endif
12527
12528         switch (ret) {
12529         case 0:
12530                 break;
12531         case -EINVAL:
12532                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12533                 break;
12534         case -ENODEV:
12535                 printf("invalid port_id %d\n", res->port_id);
12536                 break;
12537         case -ENOTSUP:
12538                 printf("function not implemented\n");
12539                 break;
12540         default:
12541                 printf("programming error: (%s)\n", strerror(-ret));
12542         }
12543 }
12544
12545 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12546         .f = cmd_set_vf_vlan_insert_parsed,
12547         .data = NULL,
12548         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12549         .tokens = {
12550                 (void *)&cmd_vf_vlan_insert_set,
12551                 (void *)&cmd_vf_vlan_insert_vf,
12552                 (void *)&cmd_vf_vlan_insert_vlan,
12553                 (void *)&cmd_vf_vlan_insert_insert,
12554                 (void *)&cmd_vf_vlan_insert_port_id,
12555                 (void *)&cmd_vf_vlan_insert_vf_id,
12556                 (void *)&cmd_vf_vlan_insert_vlan_id,
12557                 NULL,
12558         },
12559 };
12560
12561 /* tx loopback configuration */
12562
12563 /* Common result structure for tx loopback */
12564 struct cmd_tx_loopback_result {
12565         cmdline_fixed_string_t set;
12566         cmdline_fixed_string_t tx;
12567         cmdline_fixed_string_t loopback;
12568         portid_t port_id;
12569         cmdline_fixed_string_t on_off;
12570 };
12571
12572 /* Common CLI fields for tx loopback enable disable */
12573 cmdline_parse_token_string_t cmd_tx_loopback_set =
12574         TOKEN_STRING_INITIALIZER
12575                 (struct cmd_tx_loopback_result,
12576                  set, "set");
12577 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12578         TOKEN_STRING_INITIALIZER
12579                 (struct cmd_tx_loopback_result,
12580                  tx, "tx");
12581 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12582         TOKEN_STRING_INITIALIZER
12583                 (struct cmd_tx_loopback_result,
12584                  loopback, "loopback");
12585 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12586         TOKEN_NUM_INITIALIZER
12587                 (struct cmd_tx_loopback_result,
12588                  port_id, UINT16);
12589 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12590         TOKEN_STRING_INITIALIZER
12591                 (struct cmd_tx_loopback_result,
12592                  on_off, "on#off");
12593
12594 static void
12595 cmd_set_tx_loopback_parsed(
12596         void *parsed_result,
12597         __rte_unused struct cmdline *cl,
12598         __rte_unused void *data)
12599 {
12600         struct cmd_tx_loopback_result *res = parsed_result;
12601         int ret = -ENOTSUP;
12602
12603         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12604
12605         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12606                 return;
12607
12608 #ifdef RTE_NET_IXGBE
12609         if (ret == -ENOTSUP)
12610                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12611 #endif
12612 #ifdef RTE_NET_I40E
12613         if (ret == -ENOTSUP)
12614                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12615 #endif
12616 #ifdef RTE_NET_BNXT
12617         if (ret == -ENOTSUP)
12618                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12619 #endif
12620 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
12621         if (ret == -ENOTSUP)
12622                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12623 #endif
12624
12625         switch (ret) {
12626         case 0:
12627                 break;
12628         case -EINVAL:
12629                 printf("invalid is_on %d\n", is_on);
12630                 break;
12631         case -ENODEV:
12632                 printf("invalid port_id %d\n", res->port_id);
12633                 break;
12634         case -ENOTSUP:
12635                 printf("function not implemented\n");
12636                 break;
12637         default:
12638                 printf("programming error: (%s)\n", strerror(-ret));
12639         }
12640 }
12641
12642 cmdline_parse_inst_t cmd_set_tx_loopback = {
12643         .f = cmd_set_tx_loopback_parsed,
12644         .data = NULL,
12645         .help_str = "set tx loopback <port_id> on|off",
12646         .tokens = {
12647                 (void *)&cmd_tx_loopback_set,
12648                 (void *)&cmd_tx_loopback_tx,
12649                 (void *)&cmd_tx_loopback_loopback,
12650                 (void *)&cmd_tx_loopback_port_id,
12651                 (void *)&cmd_tx_loopback_on_off,
12652                 NULL,
12653         },
12654 };
12655
12656 /* all queues drop enable configuration */
12657
12658 /* Common result structure for all queues drop enable */
12659 struct cmd_all_queues_drop_en_result {
12660         cmdline_fixed_string_t set;
12661         cmdline_fixed_string_t all;
12662         cmdline_fixed_string_t queues;
12663         cmdline_fixed_string_t drop;
12664         portid_t port_id;
12665         cmdline_fixed_string_t on_off;
12666 };
12667
12668 /* Common CLI fields for tx loopback enable disable */
12669 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12670         TOKEN_STRING_INITIALIZER
12671                 (struct cmd_all_queues_drop_en_result,
12672                  set, "set");
12673 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12674         TOKEN_STRING_INITIALIZER
12675                 (struct cmd_all_queues_drop_en_result,
12676                  all, "all");
12677 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12678         TOKEN_STRING_INITIALIZER
12679                 (struct cmd_all_queues_drop_en_result,
12680                  queues, "queues");
12681 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12682         TOKEN_STRING_INITIALIZER
12683                 (struct cmd_all_queues_drop_en_result,
12684                  drop, "drop");
12685 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12686         TOKEN_NUM_INITIALIZER
12687                 (struct cmd_all_queues_drop_en_result,
12688                  port_id, UINT16);
12689 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12690         TOKEN_STRING_INITIALIZER
12691                 (struct cmd_all_queues_drop_en_result,
12692                  on_off, "on#off");
12693
12694 static void
12695 cmd_set_all_queues_drop_en_parsed(
12696         void *parsed_result,
12697         __rte_unused struct cmdline *cl,
12698         __rte_unused void *data)
12699 {
12700         struct cmd_all_queues_drop_en_result *res = parsed_result;
12701         int ret = -ENOTSUP;
12702         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12703
12704         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12705                 return;
12706
12707 #ifdef RTE_NET_IXGBE
12708         if (ret == -ENOTSUP)
12709                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12710 #endif
12711 #ifdef RTE_NET_BNXT
12712         if (ret == -ENOTSUP)
12713                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12714 #endif
12715         switch (ret) {
12716         case 0:
12717                 break;
12718         case -EINVAL:
12719                 printf("invalid is_on %d\n", is_on);
12720                 break;
12721         case -ENODEV:
12722                 printf("invalid port_id %d\n", res->port_id);
12723                 break;
12724         case -ENOTSUP:
12725                 printf("function not implemented\n");
12726                 break;
12727         default:
12728                 printf("programming error: (%s)\n", strerror(-ret));
12729         }
12730 }
12731
12732 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12733         .f = cmd_set_all_queues_drop_en_parsed,
12734         .data = NULL,
12735         .help_str = "set all queues drop <port_id> on|off",
12736         .tokens = {
12737                 (void *)&cmd_all_queues_drop_en_set,
12738                 (void *)&cmd_all_queues_drop_en_all,
12739                 (void *)&cmd_all_queues_drop_en_queues,
12740                 (void *)&cmd_all_queues_drop_en_drop,
12741                 (void *)&cmd_all_queues_drop_en_port_id,
12742                 (void *)&cmd_all_queues_drop_en_on_off,
12743                 NULL,
12744         },
12745 };
12746
12747 /* vf split drop enable configuration */
12748
12749 /* Common result structure for vf split drop enable */
12750 struct cmd_vf_split_drop_en_result {
12751         cmdline_fixed_string_t set;
12752         cmdline_fixed_string_t vf;
12753         cmdline_fixed_string_t split;
12754         cmdline_fixed_string_t drop;
12755         portid_t port_id;
12756         uint16_t vf_id;
12757         cmdline_fixed_string_t on_off;
12758 };
12759
12760 /* Common CLI fields for vf split drop enable disable */
12761 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12762         TOKEN_STRING_INITIALIZER
12763                 (struct cmd_vf_split_drop_en_result,
12764                  set, "set");
12765 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12766         TOKEN_STRING_INITIALIZER
12767                 (struct cmd_vf_split_drop_en_result,
12768                  vf, "vf");
12769 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12770         TOKEN_STRING_INITIALIZER
12771                 (struct cmd_vf_split_drop_en_result,
12772                  split, "split");
12773 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12774         TOKEN_STRING_INITIALIZER
12775                 (struct cmd_vf_split_drop_en_result,
12776                  drop, "drop");
12777 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12778         TOKEN_NUM_INITIALIZER
12779                 (struct cmd_vf_split_drop_en_result,
12780                  port_id, UINT16);
12781 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12782         TOKEN_NUM_INITIALIZER
12783                 (struct cmd_vf_split_drop_en_result,
12784                  vf_id, UINT16);
12785 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12786         TOKEN_STRING_INITIALIZER
12787                 (struct cmd_vf_split_drop_en_result,
12788                  on_off, "on#off");
12789
12790 static void
12791 cmd_set_vf_split_drop_en_parsed(
12792         void *parsed_result,
12793         __rte_unused struct cmdline *cl,
12794         __rte_unused void *data)
12795 {
12796         struct cmd_vf_split_drop_en_result *res = parsed_result;
12797         int ret = -ENOTSUP;
12798         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12799
12800         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12801                 return;
12802
12803 #ifdef RTE_NET_IXGBE
12804         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12805                         is_on);
12806 #endif
12807         switch (ret) {
12808         case 0:
12809                 break;
12810         case -EINVAL:
12811                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12812                 break;
12813         case -ENODEV:
12814                 printf("invalid port_id %d\n", res->port_id);
12815                 break;
12816         case -ENOTSUP:
12817                 printf("not supported on port %d\n", res->port_id);
12818                 break;
12819         default:
12820                 printf("programming error: (%s)\n", strerror(-ret));
12821         }
12822 }
12823
12824 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12825         .f = cmd_set_vf_split_drop_en_parsed,
12826         .data = NULL,
12827         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12828         .tokens = {
12829                 (void *)&cmd_vf_split_drop_en_set,
12830                 (void *)&cmd_vf_split_drop_en_vf,
12831                 (void *)&cmd_vf_split_drop_en_split,
12832                 (void *)&cmd_vf_split_drop_en_drop,
12833                 (void *)&cmd_vf_split_drop_en_port_id,
12834                 (void *)&cmd_vf_split_drop_en_vf_id,
12835                 (void *)&cmd_vf_split_drop_en_on_off,
12836                 NULL,
12837         },
12838 };
12839
12840 /* vf mac address configuration */
12841
12842 /* Common result structure for vf mac address */
12843 struct cmd_set_vf_mac_addr_result {
12844         cmdline_fixed_string_t set;
12845         cmdline_fixed_string_t vf;
12846         cmdline_fixed_string_t mac;
12847         cmdline_fixed_string_t addr;
12848         portid_t port_id;
12849         uint16_t vf_id;
12850         struct rte_ether_addr mac_addr;
12851
12852 };
12853
12854 /* Common CLI fields for vf split drop enable disable */
12855 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12856         TOKEN_STRING_INITIALIZER
12857                 (struct cmd_set_vf_mac_addr_result,
12858                  set, "set");
12859 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12860         TOKEN_STRING_INITIALIZER
12861                 (struct cmd_set_vf_mac_addr_result,
12862                  vf, "vf");
12863 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12864         TOKEN_STRING_INITIALIZER
12865                 (struct cmd_set_vf_mac_addr_result,
12866                  mac, "mac");
12867 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12868         TOKEN_STRING_INITIALIZER
12869                 (struct cmd_set_vf_mac_addr_result,
12870                  addr, "addr");
12871 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12872         TOKEN_NUM_INITIALIZER
12873                 (struct cmd_set_vf_mac_addr_result,
12874                  port_id, UINT16);
12875 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12876         TOKEN_NUM_INITIALIZER
12877                 (struct cmd_set_vf_mac_addr_result,
12878                  vf_id, UINT16);
12879 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12880         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12881                  mac_addr);
12882
12883 static void
12884 cmd_set_vf_mac_addr_parsed(
12885         void *parsed_result,
12886         __rte_unused struct cmdline *cl,
12887         __rte_unused void *data)
12888 {
12889         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12890         int ret = -ENOTSUP;
12891
12892         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12893                 return;
12894
12895 #ifdef RTE_NET_IXGBE
12896         if (ret == -ENOTSUP)
12897                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12898                                 &res->mac_addr);
12899 #endif
12900 #ifdef RTE_NET_I40E
12901         if (ret == -ENOTSUP)
12902                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12903                                 &res->mac_addr);
12904 #endif
12905 #ifdef RTE_NET_BNXT
12906         if (ret == -ENOTSUP)
12907                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12908                                 &res->mac_addr);
12909 #endif
12910
12911         switch (ret) {
12912         case 0:
12913                 break;
12914         case -EINVAL:
12915                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12916                 break;
12917         case -ENODEV:
12918                 printf("invalid port_id %d\n", res->port_id);
12919                 break;
12920         case -ENOTSUP:
12921                 printf("function not implemented\n");
12922                 break;
12923         default:
12924                 printf("programming error: (%s)\n", strerror(-ret));
12925         }
12926 }
12927
12928 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12929         .f = cmd_set_vf_mac_addr_parsed,
12930         .data = NULL,
12931         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12932         .tokens = {
12933                 (void *)&cmd_set_vf_mac_addr_set,
12934                 (void *)&cmd_set_vf_mac_addr_vf,
12935                 (void *)&cmd_set_vf_mac_addr_mac,
12936                 (void *)&cmd_set_vf_mac_addr_addr,
12937                 (void *)&cmd_set_vf_mac_addr_port_id,
12938                 (void *)&cmd_set_vf_mac_addr_vf_id,
12939                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12940                 NULL,
12941         },
12942 };
12943
12944 /* MACsec configuration */
12945
12946 /* Common result structure for MACsec offload enable */
12947 struct cmd_macsec_offload_on_result {
12948         cmdline_fixed_string_t set;
12949         cmdline_fixed_string_t macsec;
12950         cmdline_fixed_string_t offload;
12951         portid_t port_id;
12952         cmdline_fixed_string_t on;
12953         cmdline_fixed_string_t encrypt;
12954         cmdline_fixed_string_t en_on_off;
12955         cmdline_fixed_string_t replay_protect;
12956         cmdline_fixed_string_t rp_on_off;
12957 };
12958
12959 /* Common CLI fields for MACsec offload disable */
12960 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12961         TOKEN_STRING_INITIALIZER
12962                 (struct cmd_macsec_offload_on_result,
12963                  set, "set");
12964 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12965         TOKEN_STRING_INITIALIZER
12966                 (struct cmd_macsec_offload_on_result,
12967                  macsec, "macsec");
12968 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12969         TOKEN_STRING_INITIALIZER
12970                 (struct cmd_macsec_offload_on_result,
12971                  offload, "offload");
12972 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12973         TOKEN_NUM_INITIALIZER
12974                 (struct cmd_macsec_offload_on_result,
12975                  port_id, UINT16);
12976 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12977         TOKEN_STRING_INITIALIZER
12978                 (struct cmd_macsec_offload_on_result,
12979                  on, "on");
12980 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12981         TOKEN_STRING_INITIALIZER
12982                 (struct cmd_macsec_offload_on_result,
12983                  encrypt, "encrypt");
12984 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12985         TOKEN_STRING_INITIALIZER
12986                 (struct cmd_macsec_offload_on_result,
12987                  en_on_off, "on#off");
12988 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12989         TOKEN_STRING_INITIALIZER
12990                 (struct cmd_macsec_offload_on_result,
12991                  replay_protect, "replay-protect");
12992 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12993         TOKEN_STRING_INITIALIZER
12994                 (struct cmd_macsec_offload_on_result,
12995                  rp_on_off, "on#off");
12996
12997 static void
12998 cmd_set_macsec_offload_on_parsed(
12999         void *parsed_result,
13000         __rte_unused struct cmdline *cl,
13001         __rte_unused void *data)
13002 {
13003         struct cmd_macsec_offload_on_result *res = parsed_result;
13004         int ret = -ENOTSUP;
13005         portid_t port_id = res->port_id;
13006         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13007         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13008         struct rte_eth_dev_info dev_info;
13009
13010         if (port_id_is_invalid(port_id, ENABLED_WARN))
13011                 return;
13012         if (!port_is_stopped(port_id)) {
13013                 printf("Please stop port %d first\n", port_id);
13014                 return;
13015         }
13016
13017         ret = eth_dev_info_get_print_err(port_id, &dev_info);
13018         if (ret != 0)
13019                 return;
13020
13021         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13022 #ifdef RTE_NET_IXGBE
13023                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13024 #endif
13025         }
13026         RTE_SET_USED(en);
13027         RTE_SET_USED(rp);
13028
13029         switch (ret) {
13030         case 0:
13031                 ports[port_id].dev_conf.txmode.offloads |=
13032                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13033                 cmd_reconfig_device_queue(port_id, 1, 1);
13034                 break;
13035         case -ENODEV:
13036                 printf("invalid port_id %d\n", port_id);
13037                 break;
13038         case -ENOTSUP:
13039                 printf("not supported on port %d\n", port_id);
13040                 break;
13041         default:
13042                 printf("programming error: (%s)\n", strerror(-ret));
13043         }
13044 }
13045
13046 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13047         .f = cmd_set_macsec_offload_on_parsed,
13048         .data = NULL,
13049         .help_str = "set macsec offload <port_id> on "
13050                 "encrypt on|off replay-protect on|off",
13051         .tokens = {
13052                 (void *)&cmd_macsec_offload_on_set,
13053                 (void *)&cmd_macsec_offload_on_macsec,
13054                 (void *)&cmd_macsec_offload_on_offload,
13055                 (void *)&cmd_macsec_offload_on_port_id,
13056                 (void *)&cmd_macsec_offload_on_on,
13057                 (void *)&cmd_macsec_offload_on_encrypt,
13058                 (void *)&cmd_macsec_offload_on_en_on_off,
13059                 (void *)&cmd_macsec_offload_on_replay_protect,
13060                 (void *)&cmd_macsec_offload_on_rp_on_off,
13061                 NULL,
13062         },
13063 };
13064
13065 /* Common result structure for MACsec offload disable */
13066 struct cmd_macsec_offload_off_result {
13067         cmdline_fixed_string_t set;
13068         cmdline_fixed_string_t macsec;
13069         cmdline_fixed_string_t offload;
13070         portid_t port_id;
13071         cmdline_fixed_string_t off;
13072 };
13073
13074 /* Common CLI fields for MACsec offload disable */
13075 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13076         TOKEN_STRING_INITIALIZER
13077                 (struct cmd_macsec_offload_off_result,
13078                  set, "set");
13079 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13080         TOKEN_STRING_INITIALIZER
13081                 (struct cmd_macsec_offload_off_result,
13082                  macsec, "macsec");
13083 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13084         TOKEN_STRING_INITIALIZER
13085                 (struct cmd_macsec_offload_off_result,
13086                  offload, "offload");
13087 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13088         TOKEN_NUM_INITIALIZER
13089                 (struct cmd_macsec_offload_off_result,
13090                  port_id, UINT16);
13091 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13092         TOKEN_STRING_INITIALIZER
13093                 (struct cmd_macsec_offload_off_result,
13094                  off, "off");
13095
13096 static void
13097 cmd_set_macsec_offload_off_parsed(
13098         void *parsed_result,
13099         __rte_unused struct cmdline *cl,
13100         __rte_unused void *data)
13101 {
13102         struct cmd_macsec_offload_off_result *res = parsed_result;
13103         int ret = -ENOTSUP;
13104         struct rte_eth_dev_info dev_info;
13105         portid_t port_id = res->port_id;
13106
13107         if (port_id_is_invalid(port_id, ENABLED_WARN))
13108                 return;
13109         if (!port_is_stopped(port_id)) {
13110                 printf("Please stop port %d first\n", port_id);
13111                 return;
13112         }
13113
13114         ret = eth_dev_info_get_print_err(port_id, &dev_info);
13115         if (ret != 0)
13116                 return;
13117
13118         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13119 #ifdef RTE_NET_IXGBE
13120                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13121 #endif
13122         }
13123         switch (ret) {
13124         case 0:
13125                 ports[port_id].dev_conf.txmode.offloads &=
13126                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13127                 cmd_reconfig_device_queue(port_id, 1, 1);
13128                 break;
13129         case -ENODEV:
13130                 printf("invalid port_id %d\n", port_id);
13131                 break;
13132         case -ENOTSUP:
13133                 printf("not supported on port %d\n", port_id);
13134                 break;
13135         default:
13136                 printf("programming error: (%s)\n", strerror(-ret));
13137         }
13138 }
13139
13140 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13141         .f = cmd_set_macsec_offload_off_parsed,
13142         .data = NULL,
13143         .help_str = "set macsec offload <port_id> off",
13144         .tokens = {
13145                 (void *)&cmd_macsec_offload_off_set,
13146                 (void *)&cmd_macsec_offload_off_macsec,
13147                 (void *)&cmd_macsec_offload_off_offload,
13148                 (void *)&cmd_macsec_offload_off_port_id,
13149                 (void *)&cmd_macsec_offload_off_off,
13150                 NULL,
13151         },
13152 };
13153
13154 /* Common result structure for MACsec secure connection configure */
13155 struct cmd_macsec_sc_result {
13156         cmdline_fixed_string_t set;
13157         cmdline_fixed_string_t macsec;
13158         cmdline_fixed_string_t sc;
13159         cmdline_fixed_string_t tx_rx;
13160         portid_t port_id;
13161         struct rte_ether_addr mac;
13162         uint16_t pi;
13163 };
13164
13165 /* Common CLI fields for MACsec secure connection configure */
13166 cmdline_parse_token_string_t cmd_macsec_sc_set =
13167         TOKEN_STRING_INITIALIZER
13168                 (struct cmd_macsec_sc_result,
13169                  set, "set");
13170 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13171         TOKEN_STRING_INITIALIZER
13172                 (struct cmd_macsec_sc_result,
13173                  macsec, "macsec");
13174 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13175         TOKEN_STRING_INITIALIZER
13176                 (struct cmd_macsec_sc_result,
13177                  sc, "sc");
13178 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13179         TOKEN_STRING_INITIALIZER
13180                 (struct cmd_macsec_sc_result,
13181                  tx_rx, "tx#rx");
13182 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13183         TOKEN_NUM_INITIALIZER
13184                 (struct cmd_macsec_sc_result,
13185                  port_id, UINT16);
13186 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13187         TOKEN_ETHERADDR_INITIALIZER
13188                 (struct cmd_macsec_sc_result,
13189                  mac);
13190 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13191         TOKEN_NUM_INITIALIZER
13192                 (struct cmd_macsec_sc_result,
13193                  pi, UINT16);
13194
13195 static void
13196 cmd_set_macsec_sc_parsed(
13197         void *parsed_result,
13198         __rte_unused struct cmdline *cl,
13199         __rte_unused void *data)
13200 {
13201         struct cmd_macsec_sc_result *res = parsed_result;
13202         int ret = -ENOTSUP;
13203         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13204
13205 #ifdef RTE_NET_IXGBE
13206         ret = is_tx ?
13207                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13208                                 res->mac.addr_bytes) :
13209                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13210                                 res->mac.addr_bytes, res->pi);
13211 #endif
13212         RTE_SET_USED(is_tx);
13213
13214         switch (ret) {
13215         case 0:
13216                 break;
13217         case -ENODEV:
13218                 printf("invalid port_id %d\n", res->port_id);
13219                 break;
13220         case -ENOTSUP:
13221                 printf("not supported on port %d\n", res->port_id);
13222                 break;
13223         default:
13224                 printf("programming error: (%s)\n", strerror(-ret));
13225         }
13226 }
13227
13228 cmdline_parse_inst_t cmd_set_macsec_sc = {
13229         .f = cmd_set_macsec_sc_parsed,
13230         .data = NULL,
13231         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13232         .tokens = {
13233                 (void *)&cmd_macsec_sc_set,
13234                 (void *)&cmd_macsec_sc_macsec,
13235                 (void *)&cmd_macsec_sc_sc,
13236                 (void *)&cmd_macsec_sc_tx_rx,
13237                 (void *)&cmd_macsec_sc_port_id,
13238                 (void *)&cmd_macsec_sc_mac,
13239                 (void *)&cmd_macsec_sc_pi,
13240                 NULL,
13241         },
13242 };
13243
13244 /* Common result structure for MACsec secure connection configure */
13245 struct cmd_macsec_sa_result {
13246         cmdline_fixed_string_t set;
13247         cmdline_fixed_string_t macsec;
13248         cmdline_fixed_string_t sa;
13249         cmdline_fixed_string_t tx_rx;
13250         portid_t port_id;
13251         uint8_t idx;
13252         uint8_t an;
13253         uint32_t pn;
13254         cmdline_fixed_string_t key;
13255 };
13256
13257 /* Common CLI fields for MACsec secure connection configure */
13258 cmdline_parse_token_string_t cmd_macsec_sa_set =
13259         TOKEN_STRING_INITIALIZER
13260                 (struct cmd_macsec_sa_result,
13261                  set, "set");
13262 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13263         TOKEN_STRING_INITIALIZER
13264                 (struct cmd_macsec_sa_result,
13265                  macsec, "macsec");
13266 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13267         TOKEN_STRING_INITIALIZER
13268                 (struct cmd_macsec_sa_result,
13269                  sa, "sa");
13270 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13271         TOKEN_STRING_INITIALIZER
13272                 (struct cmd_macsec_sa_result,
13273                  tx_rx, "tx#rx");
13274 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13275         TOKEN_NUM_INITIALIZER
13276                 (struct cmd_macsec_sa_result,
13277                  port_id, UINT16);
13278 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13279         TOKEN_NUM_INITIALIZER
13280                 (struct cmd_macsec_sa_result,
13281                  idx, UINT8);
13282 cmdline_parse_token_num_t cmd_macsec_sa_an =
13283         TOKEN_NUM_INITIALIZER
13284                 (struct cmd_macsec_sa_result,
13285                  an, UINT8);
13286 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13287         TOKEN_NUM_INITIALIZER
13288                 (struct cmd_macsec_sa_result,
13289                  pn, UINT32);
13290 cmdline_parse_token_string_t cmd_macsec_sa_key =
13291         TOKEN_STRING_INITIALIZER
13292                 (struct cmd_macsec_sa_result,
13293                  key, NULL);
13294
13295 static void
13296 cmd_set_macsec_sa_parsed(
13297         void *parsed_result,
13298         __rte_unused struct cmdline *cl,
13299         __rte_unused void *data)
13300 {
13301         struct cmd_macsec_sa_result *res = parsed_result;
13302         int ret = -ENOTSUP;
13303         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13304         uint8_t key[16] = { 0 };
13305         uint8_t xdgt0;
13306         uint8_t xdgt1;
13307         int key_len;
13308         int i;
13309
13310         key_len = strlen(res->key) / 2;
13311         if (key_len > 16)
13312                 key_len = 16;
13313
13314         for (i = 0; i < key_len; i++) {
13315                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13316                 if (xdgt0 == 0xFF)
13317                         return;
13318                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13319                 if (xdgt1 == 0xFF)
13320                         return;
13321                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13322         }
13323
13324 #ifdef RTE_NET_IXGBE
13325         ret = is_tx ?
13326                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13327                         res->idx, res->an, res->pn, key) :
13328                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13329                         res->idx, res->an, res->pn, key);
13330 #endif
13331         RTE_SET_USED(is_tx);
13332         RTE_SET_USED(key);
13333
13334         switch (ret) {
13335         case 0:
13336                 break;
13337         case -EINVAL:
13338                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13339                 break;
13340         case -ENODEV:
13341                 printf("invalid port_id %d\n", res->port_id);
13342                 break;
13343         case -ENOTSUP:
13344                 printf("not supported on port %d\n", res->port_id);
13345                 break;
13346         default:
13347                 printf("programming error: (%s)\n", strerror(-ret));
13348         }
13349 }
13350
13351 cmdline_parse_inst_t cmd_set_macsec_sa = {
13352         .f = cmd_set_macsec_sa_parsed,
13353         .data = NULL,
13354         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13355         .tokens = {
13356                 (void *)&cmd_macsec_sa_set,
13357                 (void *)&cmd_macsec_sa_macsec,
13358                 (void *)&cmd_macsec_sa_sa,
13359                 (void *)&cmd_macsec_sa_tx_rx,
13360                 (void *)&cmd_macsec_sa_port_id,
13361                 (void *)&cmd_macsec_sa_idx,
13362                 (void *)&cmd_macsec_sa_an,
13363                 (void *)&cmd_macsec_sa_pn,
13364                 (void *)&cmd_macsec_sa_key,
13365                 NULL,
13366         },
13367 };
13368
13369 /* VF unicast promiscuous mode configuration */
13370
13371 /* Common result structure for VF unicast promiscuous mode */
13372 struct cmd_vf_promisc_result {
13373         cmdline_fixed_string_t set;
13374         cmdline_fixed_string_t vf;
13375         cmdline_fixed_string_t promisc;
13376         portid_t port_id;
13377         uint32_t vf_id;
13378         cmdline_fixed_string_t on_off;
13379 };
13380
13381 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13382 cmdline_parse_token_string_t cmd_vf_promisc_set =
13383         TOKEN_STRING_INITIALIZER
13384                 (struct cmd_vf_promisc_result,
13385                  set, "set");
13386 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13387         TOKEN_STRING_INITIALIZER
13388                 (struct cmd_vf_promisc_result,
13389                  vf, "vf");
13390 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13391         TOKEN_STRING_INITIALIZER
13392                 (struct cmd_vf_promisc_result,
13393                  promisc, "promisc");
13394 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13395         TOKEN_NUM_INITIALIZER
13396                 (struct cmd_vf_promisc_result,
13397                  port_id, UINT16);
13398 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13399         TOKEN_NUM_INITIALIZER
13400                 (struct cmd_vf_promisc_result,
13401                  vf_id, UINT32);
13402 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13403         TOKEN_STRING_INITIALIZER
13404                 (struct cmd_vf_promisc_result,
13405                  on_off, "on#off");
13406
13407 static void
13408 cmd_set_vf_promisc_parsed(
13409         void *parsed_result,
13410         __rte_unused struct cmdline *cl,
13411         __rte_unused void *data)
13412 {
13413         struct cmd_vf_promisc_result *res = parsed_result;
13414         int ret = -ENOTSUP;
13415
13416         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13417
13418         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13419                 return;
13420
13421 #ifdef RTE_NET_I40E
13422         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13423                                                   res->vf_id, is_on);
13424 #endif
13425
13426         switch (ret) {
13427         case 0:
13428                 break;
13429         case -EINVAL:
13430                 printf("invalid vf_id %d\n", res->vf_id);
13431                 break;
13432         case -ENODEV:
13433                 printf("invalid port_id %d\n", res->port_id);
13434                 break;
13435         case -ENOTSUP:
13436                 printf("function not implemented\n");
13437                 break;
13438         default:
13439                 printf("programming error: (%s)\n", strerror(-ret));
13440         }
13441 }
13442
13443 cmdline_parse_inst_t cmd_set_vf_promisc = {
13444         .f = cmd_set_vf_promisc_parsed,
13445         .data = NULL,
13446         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13447                 "Set unicast promiscuous mode for a VF from the PF",
13448         .tokens = {
13449                 (void *)&cmd_vf_promisc_set,
13450                 (void *)&cmd_vf_promisc_vf,
13451                 (void *)&cmd_vf_promisc_promisc,
13452                 (void *)&cmd_vf_promisc_port_id,
13453                 (void *)&cmd_vf_promisc_vf_id,
13454                 (void *)&cmd_vf_promisc_on_off,
13455                 NULL,
13456         },
13457 };
13458
13459 /* VF multicast promiscuous mode configuration */
13460
13461 /* Common result structure for VF multicast promiscuous mode */
13462 struct cmd_vf_allmulti_result {
13463         cmdline_fixed_string_t set;
13464         cmdline_fixed_string_t vf;
13465         cmdline_fixed_string_t allmulti;
13466         portid_t port_id;
13467         uint32_t vf_id;
13468         cmdline_fixed_string_t on_off;
13469 };
13470
13471 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13472 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13473         TOKEN_STRING_INITIALIZER
13474                 (struct cmd_vf_allmulti_result,
13475                  set, "set");
13476 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13477         TOKEN_STRING_INITIALIZER
13478                 (struct cmd_vf_allmulti_result,
13479                  vf, "vf");
13480 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13481         TOKEN_STRING_INITIALIZER
13482                 (struct cmd_vf_allmulti_result,
13483                  allmulti, "allmulti");
13484 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13485         TOKEN_NUM_INITIALIZER
13486                 (struct cmd_vf_allmulti_result,
13487                  port_id, UINT16);
13488 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13489         TOKEN_NUM_INITIALIZER
13490                 (struct cmd_vf_allmulti_result,
13491                  vf_id, UINT32);
13492 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13493         TOKEN_STRING_INITIALIZER
13494                 (struct cmd_vf_allmulti_result,
13495                  on_off, "on#off");
13496
13497 static void
13498 cmd_set_vf_allmulti_parsed(
13499         void *parsed_result,
13500         __rte_unused struct cmdline *cl,
13501         __rte_unused void *data)
13502 {
13503         struct cmd_vf_allmulti_result *res = parsed_result;
13504         int ret = -ENOTSUP;
13505
13506         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13507
13508         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13509                 return;
13510
13511 #ifdef RTE_NET_I40E
13512         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13513                                                     res->vf_id, is_on);
13514 #endif
13515
13516         switch (ret) {
13517         case 0:
13518                 break;
13519         case -EINVAL:
13520                 printf("invalid vf_id %d\n", res->vf_id);
13521                 break;
13522         case -ENODEV:
13523                 printf("invalid port_id %d\n", res->port_id);
13524                 break;
13525         case -ENOTSUP:
13526                 printf("function not implemented\n");
13527                 break;
13528         default:
13529                 printf("programming error: (%s)\n", strerror(-ret));
13530         }
13531 }
13532
13533 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13534         .f = cmd_set_vf_allmulti_parsed,
13535         .data = NULL,
13536         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13537                 "Set multicast promiscuous mode for a VF from the PF",
13538         .tokens = {
13539                 (void *)&cmd_vf_allmulti_set,
13540                 (void *)&cmd_vf_allmulti_vf,
13541                 (void *)&cmd_vf_allmulti_allmulti,
13542                 (void *)&cmd_vf_allmulti_port_id,
13543                 (void *)&cmd_vf_allmulti_vf_id,
13544                 (void *)&cmd_vf_allmulti_on_off,
13545                 NULL,
13546         },
13547 };
13548
13549 /* vf broadcast mode configuration */
13550
13551 /* Common result structure for vf broadcast */
13552 struct cmd_set_vf_broadcast_result {
13553         cmdline_fixed_string_t set;
13554         cmdline_fixed_string_t vf;
13555         cmdline_fixed_string_t broadcast;
13556         portid_t port_id;
13557         uint16_t vf_id;
13558         cmdline_fixed_string_t on_off;
13559 };
13560
13561 /* Common CLI fields for vf broadcast enable disable */
13562 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13563         TOKEN_STRING_INITIALIZER
13564                 (struct cmd_set_vf_broadcast_result,
13565                  set, "set");
13566 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13567         TOKEN_STRING_INITIALIZER
13568                 (struct cmd_set_vf_broadcast_result,
13569                  vf, "vf");
13570 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13571         TOKEN_STRING_INITIALIZER
13572                 (struct cmd_set_vf_broadcast_result,
13573                  broadcast, "broadcast");
13574 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13575         TOKEN_NUM_INITIALIZER
13576                 (struct cmd_set_vf_broadcast_result,
13577                  port_id, UINT16);
13578 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13579         TOKEN_NUM_INITIALIZER
13580                 (struct cmd_set_vf_broadcast_result,
13581                  vf_id, UINT16);
13582 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13583         TOKEN_STRING_INITIALIZER
13584                 (struct cmd_set_vf_broadcast_result,
13585                  on_off, "on#off");
13586
13587 static void
13588 cmd_set_vf_broadcast_parsed(
13589         void *parsed_result,
13590         __rte_unused struct cmdline *cl,
13591         __rte_unused void *data)
13592 {
13593         struct cmd_set_vf_broadcast_result *res = parsed_result;
13594         int ret = -ENOTSUP;
13595
13596         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13597
13598         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13599                 return;
13600
13601 #ifdef RTE_NET_I40E
13602         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13603                                             res->vf_id, is_on);
13604 #endif
13605
13606         switch (ret) {
13607         case 0:
13608                 break;
13609         case -EINVAL:
13610                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13611                 break;
13612         case -ENODEV:
13613                 printf("invalid port_id %d\n", res->port_id);
13614                 break;
13615         case -ENOTSUP:
13616                 printf("function not implemented\n");
13617                 break;
13618         default:
13619                 printf("programming error: (%s)\n", strerror(-ret));
13620         }
13621 }
13622
13623 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13624         .f = cmd_set_vf_broadcast_parsed,
13625         .data = NULL,
13626         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13627         .tokens = {
13628                 (void *)&cmd_set_vf_broadcast_set,
13629                 (void *)&cmd_set_vf_broadcast_vf,
13630                 (void *)&cmd_set_vf_broadcast_broadcast,
13631                 (void *)&cmd_set_vf_broadcast_port_id,
13632                 (void *)&cmd_set_vf_broadcast_vf_id,
13633                 (void *)&cmd_set_vf_broadcast_on_off,
13634                 NULL,
13635         },
13636 };
13637
13638 /* vf vlan tag configuration */
13639
13640 /* Common result structure for vf vlan tag */
13641 struct cmd_set_vf_vlan_tag_result {
13642         cmdline_fixed_string_t set;
13643         cmdline_fixed_string_t vf;
13644         cmdline_fixed_string_t vlan;
13645         cmdline_fixed_string_t tag;
13646         portid_t port_id;
13647         uint16_t vf_id;
13648         cmdline_fixed_string_t on_off;
13649 };
13650
13651 /* Common CLI fields for vf vlan tag enable disable */
13652 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13653         TOKEN_STRING_INITIALIZER
13654                 (struct cmd_set_vf_vlan_tag_result,
13655                  set, "set");
13656 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13657         TOKEN_STRING_INITIALIZER
13658                 (struct cmd_set_vf_vlan_tag_result,
13659                  vf, "vf");
13660 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13661         TOKEN_STRING_INITIALIZER
13662                 (struct cmd_set_vf_vlan_tag_result,
13663                  vlan, "vlan");
13664 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13665         TOKEN_STRING_INITIALIZER
13666                 (struct cmd_set_vf_vlan_tag_result,
13667                  tag, "tag");
13668 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13669         TOKEN_NUM_INITIALIZER
13670                 (struct cmd_set_vf_vlan_tag_result,
13671                  port_id, UINT16);
13672 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13673         TOKEN_NUM_INITIALIZER
13674                 (struct cmd_set_vf_vlan_tag_result,
13675                  vf_id, UINT16);
13676 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13677         TOKEN_STRING_INITIALIZER
13678                 (struct cmd_set_vf_vlan_tag_result,
13679                  on_off, "on#off");
13680
13681 static void
13682 cmd_set_vf_vlan_tag_parsed(
13683         void *parsed_result,
13684         __rte_unused struct cmdline *cl,
13685         __rte_unused void *data)
13686 {
13687         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13688         int ret = -ENOTSUP;
13689
13690         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13691
13692         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13693                 return;
13694
13695 #ifdef RTE_NET_I40E
13696         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13697                                            res->vf_id, is_on);
13698 #endif
13699
13700         switch (ret) {
13701         case 0:
13702                 break;
13703         case -EINVAL:
13704                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13705                 break;
13706         case -ENODEV:
13707                 printf("invalid port_id %d\n", res->port_id);
13708                 break;
13709         case -ENOTSUP:
13710                 printf("function not implemented\n");
13711                 break;
13712         default:
13713                 printf("programming error: (%s)\n", strerror(-ret));
13714         }
13715 }
13716
13717 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13718         .f = cmd_set_vf_vlan_tag_parsed,
13719         .data = NULL,
13720         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13721         .tokens = {
13722                 (void *)&cmd_set_vf_vlan_tag_set,
13723                 (void *)&cmd_set_vf_vlan_tag_vf,
13724                 (void *)&cmd_set_vf_vlan_tag_vlan,
13725                 (void *)&cmd_set_vf_vlan_tag_tag,
13726                 (void *)&cmd_set_vf_vlan_tag_port_id,
13727                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13728                 (void *)&cmd_set_vf_vlan_tag_on_off,
13729                 NULL,
13730         },
13731 };
13732
13733 /* Common definition of VF and TC TX bandwidth configuration */
13734 struct cmd_vf_tc_bw_result {
13735         cmdline_fixed_string_t set;
13736         cmdline_fixed_string_t vf;
13737         cmdline_fixed_string_t tc;
13738         cmdline_fixed_string_t tx;
13739         cmdline_fixed_string_t min_bw;
13740         cmdline_fixed_string_t max_bw;
13741         cmdline_fixed_string_t strict_link_prio;
13742         portid_t port_id;
13743         uint16_t vf_id;
13744         uint8_t tc_no;
13745         uint32_t bw;
13746         cmdline_fixed_string_t bw_list;
13747         uint8_t tc_map;
13748 };
13749
13750 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13751         TOKEN_STRING_INITIALIZER
13752                 (struct cmd_vf_tc_bw_result,
13753                  set, "set");
13754 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13755         TOKEN_STRING_INITIALIZER
13756                 (struct cmd_vf_tc_bw_result,
13757                  vf, "vf");
13758 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13759         TOKEN_STRING_INITIALIZER
13760                 (struct cmd_vf_tc_bw_result,
13761                  tc, "tc");
13762 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13763         TOKEN_STRING_INITIALIZER
13764                 (struct cmd_vf_tc_bw_result,
13765                  tx, "tx");
13766 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13767         TOKEN_STRING_INITIALIZER
13768                 (struct cmd_vf_tc_bw_result,
13769                  strict_link_prio, "strict-link-priority");
13770 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13771         TOKEN_STRING_INITIALIZER
13772                 (struct cmd_vf_tc_bw_result,
13773                  min_bw, "min-bandwidth");
13774 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13775         TOKEN_STRING_INITIALIZER
13776                 (struct cmd_vf_tc_bw_result,
13777                  max_bw, "max-bandwidth");
13778 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13779         TOKEN_NUM_INITIALIZER
13780                 (struct cmd_vf_tc_bw_result,
13781                  port_id, UINT16);
13782 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13783         TOKEN_NUM_INITIALIZER
13784                 (struct cmd_vf_tc_bw_result,
13785                  vf_id, UINT16);
13786 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13787         TOKEN_NUM_INITIALIZER
13788                 (struct cmd_vf_tc_bw_result,
13789                  tc_no, UINT8);
13790 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13791         TOKEN_NUM_INITIALIZER
13792                 (struct cmd_vf_tc_bw_result,
13793                  bw, UINT32);
13794 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13795         TOKEN_STRING_INITIALIZER
13796                 (struct cmd_vf_tc_bw_result,
13797                  bw_list, NULL);
13798 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13799         TOKEN_NUM_INITIALIZER
13800                 (struct cmd_vf_tc_bw_result,
13801                  tc_map, UINT8);
13802
13803 /* VF max bandwidth setting */
13804 static void
13805 cmd_vf_max_bw_parsed(
13806         void *parsed_result,
13807         __rte_unused struct cmdline *cl,
13808         __rte_unused void *data)
13809 {
13810         struct cmd_vf_tc_bw_result *res = parsed_result;
13811         int ret = -ENOTSUP;
13812
13813         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13814                 return;
13815
13816 #ifdef RTE_NET_I40E
13817         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13818                                          res->vf_id, res->bw);
13819 #endif
13820
13821         switch (ret) {
13822         case 0:
13823                 break;
13824         case -EINVAL:
13825                 printf("invalid vf_id %d or bandwidth %d\n",
13826                        res->vf_id, res->bw);
13827                 break;
13828         case -ENODEV:
13829                 printf("invalid port_id %d\n", res->port_id);
13830                 break;
13831         case -ENOTSUP:
13832                 printf("function not implemented\n");
13833                 break;
13834         default:
13835                 printf("programming error: (%s)\n", strerror(-ret));
13836         }
13837 }
13838
13839 cmdline_parse_inst_t cmd_vf_max_bw = {
13840         .f = cmd_vf_max_bw_parsed,
13841         .data = NULL,
13842         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13843         .tokens = {
13844                 (void *)&cmd_vf_tc_bw_set,
13845                 (void *)&cmd_vf_tc_bw_vf,
13846                 (void *)&cmd_vf_tc_bw_tx,
13847                 (void *)&cmd_vf_tc_bw_max_bw,
13848                 (void *)&cmd_vf_tc_bw_port_id,
13849                 (void *)&cmd_vf_tc_bw_vf_id,
13850                 (void *)&cmd_vf_tc_bw_bw,
13851                 NULL,
13852         },
13853 };
13854
13855 static int
13856 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13857                            uint8_t *tc_num,
13858                            char *str)
13859 {
13860         uint32_t size;
13861         const char *p, *p0 = str;
13862         char s[256];
13863         char *end;
13864         char *str_fld[16];
13865         uint16_t i;
13866         int ret;
13867
13868         p = strchr(p0, '(');
13869         if (p == NULL) {
13870                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13871                 return -1;
13872         }
13873         p++;
13874         p0 = strchr(p, ')');
13875         if (p0 == NULL) {
13876                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13877                 return -1;
13878         }
13879         size = p0 - p;
13880         if (size >= sizeof(s)) {
13881                 printf("The string size exceeds the internal buffer size\n");
13882                 return -1;
13883         }
13884         snprintf(s, sizeof(s), "%.*s", size, p);
13885         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13886         if (ret <= 0) {
13887                 printf("Failed to get the bandwidth list. ");
13888                 return -1;
13889         }
13890         *tc_num = ret;
13891         for (i = 0; i < ret; i++)
13892                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13893
13894         return 0;
13895 }
13896
13897 /* TC min bandwidth setting */
13898 static void
13899 cmd_vf_tc_min_bw_parsed(
13900         void *parsed_result,
13901         __rte_unused struct cmdline *cl,
13902         __rte_unused void *data)
13903 {
13904         struct cmd_vf_tc_bw_result *res = parsed_result;
13905         uint8_t tc_num;
13906         uint8_t bw[16];
13907         int ret = -ENOTSUP;
13908
13909         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13910                 return;
13911
13912         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13913         if (ret)
13914                 return;
13915
13916 #ifdef RTE_NET_I40E
13917         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13918                                               tc_num, bw);
13919 #endif
13920
13921         switch (ret) {
13922         case 0:
13923                 break;
13924         case -EINVAL:
13925                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13926                 break;
13927         case -ENODEV:
13928                 printf("invalid port_id %d\n", res->port_id);
13929                 break;
13930         case -ENOTSUP:
13931                 printf("function not implemented\n");
13932                 break;
13933         default:
13934                 printf("programming error: (%s)\n", strerror(-ret));
13935         }
13936 }
13937
13938 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13939         .f = cmd_vf_tc_min_bw_parsed,
13940         .data = NULL,
13941         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13942                     " <bw1, bw2, ...>",
13943         .tokens = {
13944                 (void *)&cmd_vf_tc_bw_set,
13945                 (void *)&cmd_vf_tc_bw_vf,
13946                 (void *)&cmd_vf_tc_bw_tc,
13947                 (void *)&cmd_vf_tc_bw_tx,
13948                 (void *)&cmd_vf_tc_bw_min_bw,
13949                 (void *)&cmd_vf_tc_bw_port_id,
13950                 (void *)&cmd_vf_tc_bw_vf_id,
13951                 (void *)&cmd_vf_tc_bw_bw_list,
13952                 NULL,
13953         },
13954 };
13955
13956 static void
13957 cmd_tc_min_bw_parsed(
13958         void *parsed_result,
13959         __rte_unused struct cmdline *cl,
13960         __rte_unused void *data)
13961 {
13962         struct cmd_vf_tc_bw_result *res = parsed_result;
13963         struct rte_port *port;
13964         uint8_t tc_num;
13965         uint8_t bw[16];
13966         int ret = -ENOTSUP;
13967
13968         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13969                 return;
13970
13971         port = &ports[res->port_id];
13972         /** Check if the port is not started **/
13973         if (port->port_status != RTE_PORT_STOPPED) {
13974                 printf("Please stop port %d first\n", res->port_id);
13975                 return;
13976         }
13977
13978         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13979         if (ret)
13980                 return;
13981
13982 #ifdef RTE_NET_IXGBE
13983         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13984 #endif
13985
13986         switch (ret) {
13987         case 0:
13988                 break;
13989         case -EINVAL:
13990                 printf("invalid bandwidth\n");
13991                 break;
13992         case -ENODEV:
13993                 printf("invalid port_id %d\n", res->port_id);
13994                 break;
13995         case -ENOTSUP:
13996                 printf("function not implemented\n");
13997                 break;
13998         default:
13999                 printf("programming error: (%s)\n", strerror(-ret));
14000         }
14001 }
14002
14003 cmdline_parse_inst_t cmd_tc_min_bw = {
14004         .f = cmd_tc_min_bw_parsed,
14005         .data = NULL,
14006         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14007         .tokens = {
14008                 (void *)&cmd_vf_tc_bw_set,
14009                 (void *)&cmd_vf_tc_bw_tc,
14010                 (void *)&cmd_vf_tc_bw_tx,
14011                 (void *)&cmd_vf_tc_bw_min_bw,
14012                 (void *)&cmd_vf_tc_bw_port_id,
14013                 (void *)&cmd_vf_tc_bw_bw_list,
14014                 NULL,
14015         },
14016 };
14017
14018 /* TC max bandwidth setting */
14019 static void
14020 cmd_vf_tc_max_bw_parsed(
14021         void *parsed_result,
14022         __rte_unused struct cmdline *cl,
14023         __rte_unused void *data)
14024 {
14025         struct cmd_vf_tc_bw_result *res = parsed_result;
14026         int ret = -ENOTSUP;
14027
14028         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14029                 return;
14030
14031 #ifdef RTE_NET_I40E
14032         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14033                                             res->tc_no, res->bw);
14034 #endif
14035
14036         switch (ret) {
14037         case 0:
14038                 break;
14039         case -EINVAL:
14040                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14041                        res->vf_id, res->tc_no, res->bw);
14042                 break;
14043         case -ENODEV:
14044                 printf("invalid port_id %d\n", res->port_id);
14045                 break;
14046         case -ENOTSUP:
14047                 printf("function not implemented\n");
14048                 break;
14049         default:
14050                 printf("programming error: (%s)\n", strerror(-ret));
14051         }
14052 }
14053
14054 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14055         .f = cmd_vf_tc_max_bw_parsed,
14056         .data = NULL,
14057         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14058                     " <bandwidth>",
14059         .tokens = {
14060                 (void *)&cmd_vf_tc_bw_set,
14061                 (void *)&cmd_vf_tc_bw_vf,
14062                 (void *)&cmd_vf_tc_bw_tc,
14063                 (void *)&cmd_vf_tc_bw_tx,
14064                 (void *)&cmd_vf_tc_bw_max_bw,
14065                 (void *)&cmd_vf_tc_bw_port_id,
14066                 (void *)&cmd_vf_tc_bw_vf_id,
14067                 (void *)&cmd_vf_tc_bw_tc_no,
14068                 (void *)&cmd_vf_tc_bw_bw,
14069                 NULL,
14070         },
14071 };
14072
14073 /** Set VXLAN encapsulation details */
14074 struct cmd_set_vxlan_result {
14075         cmdline_fixed_string_t set;
14076         cmdline_fixed_string_t vxlan;
14077         cmdline_fixed_string_t pos_token;
14078         cmdline_fixed_string_t ip_version;
14079         uint32_t vlan_present:1;
14080         uint32_t vni;
14081         uint16_t udp_src;
14082         uint16_t udp_dst;
14083         cmdline_ipaddr_t ip_src;
14084         cmdline_ipaddr_t ip_dst;
14085         uint16_t tci;
14086         uint8_t tos;
14087         uint8_t ttl;
14088         struct rte_ether_addr eth_src;
14089         struct rte_ether_addr eth_dst;
14090 };
14091
14092 cmdline_parse_token_string_t cmd_set_vxlan_set =
14093         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
14094 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
14095         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
14096 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
14097         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
14098                                  "vxlan-tos-ttl");
14099 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
14100         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
14101                                  "vxlan-with-vlan");
14102 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
14103         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14104                                  "ip-version");
14105 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
14106         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
14107                                  "ipv4#ipv6");
14108 cmdline_parse_token_string_t cmd_set_vxlan_vni =
14109         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14110                                  "vni");
14111 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
14112         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
14113 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
14114         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14115                                  "udp-src");
14116 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
14117         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
14118 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
14119         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14120                                  "udp-dst");
14121 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
14122         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
14123 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
14124         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14125                                  "ip-tos");
14126 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
14127         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
14128 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
14129         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14130                                  "ip-ttl");
14131 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
14132         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
14133 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
14134         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14135                                  "ip-src");
14136 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
14137         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
14138 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
14139         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14140                                  "ip-dst");
14141 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
14142         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
14143 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
14144         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14145                                  "vlan-tci");
14146 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
14147         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
14148 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
14149         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14150                                  "eth-src");
14151 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
14152         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
14153 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
14154         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14155                                  "eth-dst");
14156 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
14157         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
14158
14159 static void cmd_set_vxlan_parsed(void *parsed_result,
14160         __rte_unused struct cmdline *cl,
14161         __rte_unused void *data)
14162 {
14163         struct cmd_set_vxlan_result *res = parsed_result;
14164         union {
14165                 uint32_t vxlan_id;
14166                 uint8_t vni[4];
14167         } id = {
14168                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
14169         };
14170
14171         vxlan_encap_conf.select_tos_ttl = 0;
14172         if (strcmp(res->vxlan, "vxlan") == 0)
14173                 vxlan_encap_conf.select_vlan = 0;
14174         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
14175                 vxlan_encap_conf.select_vlan = 1;
14176         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
14177                 vxlan_encap_conf.select_vlan = 0;
14178                 vxlan_encap_conf.select_tos_ttl = 1;
14179         }
14180         if (strcmp(res->ip_version, "ipv4") == 0)
14181                 vxlan_encap_conf.select_ipv4 = 1;
14182         else if (strcmp(res->ip_version, "ipv6") == 0)
14183                 vxlan_encap_conf.select_ipv4 = 0;
14184         else
14185                 return;
14186         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
14187         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
14188         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
14189         vxlan_encap_conf.ip_tos = res->tos;
14190         vxlan_encap_conf.ip_ttl = res->ttl;
14191         if (vxlan_encap_conf.select_ipv4) {
14192                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
14193                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
14194         } else {
14195                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
14196                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
14197         }
14198         if (vxlan_encap_conf.select_vlan)
14199                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14200         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
14201                    RTE_ETHER_ADDR_LEN);
14202         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14203                    RTE_ETHER_ADDR_LEN);
14204 }
14205
14206 cmdline_parse_inst_t cmd_set_vxlan = {
14207         .f = cmd_set_vxlan_parsed,
14208         .data = NULL,
14209         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
14210                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
14211                 " eth-src <eth-src> eth-dst <eth-dst>",
14212         .tokens = {
14213                 (void *)&cmd_set_vxlan_set,
14214                 (void *)&cmd_set_vxlan_vxlan,
14215                 (void *)&cmd_set_vxlan_ip_version,
14216                 (void *)&cmd_set_vxlan_ip_version_value,
14217                 (void *)&cmd_set_vxlan_vni,
14218                 (void *)&cmd_set_vxlan_vni_value,
14219                 (void *)&cmd_set_vxlan_udp_src,
14220                 (void *)&cmd_set_vxlan_udp_src_value,
14221                 (void *)&cmd_set_vxlan_udp_dst,
14222                 (void *)&cmd_set_vxlan_udp_dst_value,
14223                 (void *)&cmd_set_vxlan_ip_src,
14224                 (void *)&cmd_set_vxlan_ip_src_value,
14225                 (void *)&cmd_set_vxlan_ip_dst,
14226                 (void *)&cmd_set_vxlan_ip_dst_value,
14227                 (void *)&cmd_set_vxlan_eth_src,
14228                 (void *)&cmd_set_vxlan_eth_src_value,
14229                 (void *)&cmd_set_vxlan_eth_dst,
14230                 (void *)&cmd_set_vxlan_eth_dst_value,
14231                 NULL,
14232         },
14233 };
14234
14235 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
14236         .f = cmd_set_vxlan_parsed,
14237         .data = NULL,
14238         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
14239                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
14240                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
14241                 " eth-dst <eth-dst>",
14242         .tokens = {
14243                 (void *)&cmd_set_vxlan_set,
14244                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
14245                 (void *)&cmd_set_vxlan_ip_version,
14246                 (void *)&cmd_set_vxlan_ip_version_value,
14247                 (void *)&cmd_set_vxlan_vni,
14248                 (void *)&cmd_set_vxlan_vni_value,
14249                 (void *)&cmd_set_vxlan_udp_src,
14250                 (void *)&cmd_set_vxlan_udp_src_value,
14251                 (void *)&cmd_set_vxlan_udp_dst,
14252                 (void *)&cmd_set_vxlan_udp_dst_value,
14253                 (void *)&cmd_set_vxlan_ip_tos,
14254                 (void *)&cmd_set_vxlan_ip_tos_value,
14255                 (void *)&cmd_set_vxlan_ip_ttl,
14256                 (void *)&cmd_set_vxlan_ip_ttl_value,
14257                 (void *)&cmd_set_vxlan_ip_src,
14258                 (void *)&cmd_set_vxlan_ip_src_value,
14259                 (void *)&cmd_set_vxlan_ip_dst,
14260                 (void *)&cmd_set_vxlan_ip_dst_value,
14261                 (void *)&cmd_set_vxlan_eth_src,
14262                 (void *)&cmd_set_vxlan_eth_src_value,
14263                 (void *)&cmd_set_vxlan_eth_dst,
14264                 (void *)&cmd_set_vxlan_eth_dst_value,
14265                 NULL,
14266         },
14267 };
14268
14269 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
14270         .f = cmd_set_vxlan_parsed,
14271         .data = NULL,
14272         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
14273                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
14274                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
14275                 " <eth-dst>",
14276         .tokens = {
14277                 (void *)&cmd_set_vxlan_set,
14278                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
14279                 (void *)&cmd_set_vxlan_ip_version,
14280                 (void *)&cmd_set_vxlan_ip_version_value,
14281                 (void *)&cmd_set_vxlan_vni,
14282                 (void *)&cmd_set_vxlan_vni_value,
14283                 (void *)&cmd_set_vxlan_udp_src,
14284                 (void *)&cmd_set_vxlan_udp_src_value,
14285                 (void *)&cmd_set_vxlan_udp_dst,
14286                 (void *)&cmd_set_vxlan_udp_dst_value,
14287                 (void *)&cmd_set_vxlan_ip_src,
14288                 (void *)&cmd_set_vxlan_ip_src_value,
14289                 (void *)&cmd_set_vxlan_ip_dst,
14290                 (void *)&cmd_set_vxlan_ip_dst_value,
14291                 (void *)&cmd_set_vxlan_vlan,
14292                 (void *)&cmd_set_vxlan_vlan_value,
14293                 (void *)&cmd_set_vxlan_eth_src,
14294                 (void *)&cmd_set_vxlan_eth_src_value,
14295                 (void *)&cmd_set_vxlan_eth_dst,
14296                 (void *)&cmd_set_vxlan_eth_dst_value,
14297                 NULL,
14298         },
14299 };
14300
14301 /** Set NVGRE encapsulation details */
14302 struct cmd_set_nvgre_result {
14303         cmdline_fixed_string_t set;
14304         cmdline_fixed_string_t nvgre;
14305         cmdline_fixed_string_t pos_token;
14306         cmdline_fixed_string_t ip_version;
14307         uint32_t tni;
14308         cmdline_ipaddr_t ip_src;
14309         cmdline_ipaddr_t ip_dst;
14310         uint16_t tci;
14311         struct rte_ether_addr eth_src;
14312         struct rte_ether_addr eth_dst;
14313 };
14314
14315 cmdline_parse_token_string_t cmd_set_nvgre_set =
14316         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
14317 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
14318         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
14319 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
14320         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
14321                                  "nvgre-with-vlan");
14322 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
14323         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14324                                  "ip-version");
14325 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
14326         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
14327                                  "ipv4#ipv6");
14328 cmdline_parse_token_string_t cmd_set_nvgre_tni =
14329         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14330                                  "tni");
14331 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
14332         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
14333 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
14334         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14335                                  "ip-src");
14336 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
14337         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
14338 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
14339         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14340                                  "ip-dst");
14341 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
14342         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
14343 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
14344         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14345                                  "vlan-tci");
14346 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
14347         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
14348 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
14349         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14350                                  "eth-src");
14351 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
14352         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
14353 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
14354         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14355                                  "eth-dst");
14356 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
14357         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
14358
14359 static void cmd_set_nvgre_parsed(void *parsed_result,
14360         __rte_unused struct cmdline *cl,
14361         __rte_unused void *data)
14362 {
14363         struct cmd_set_nvgre_result *res = parsed_result;
14364         union {
14365                 uint32_t nvgre_tni;
14366                 uint8_t tni[4];
14367         } id = {
14368                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
14369         };
14370
14371         if (strcmp(res->nvgre, "nvgre") == 0)
14372                 nvgre_encap_conf.select_vlan = 0;
14373         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
14374                 nvgre_encap_conf.select_vlan = 1;
14375         if (strcmp(res->ip_version, "ipv4") == 0)
14376                 nvgre_encap_conf.select_ipv4 = 1;
14377         else if (strcmp(res->ip_version, "ipv6") == 0)
14378                 nvgre_encap_conf.select_ipv4 = 0;
14379         else
14380                 return;
14381         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
14382         if (nvgre_encap_conf.select_ipv4) {
14383                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
14384                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
14385         } else {
14386                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
14387                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
14388         }
14389         if (nvgre_encap_conf.select_vlan)
14390                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14391         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
14392                    RTE_ETHER_ADDR_LEN);
14393         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14394                    RTE_ETHER_ADDR_LEN);
14395 }
14396
14397 cmdline_parse_inst_t cmd_set_nvgre = {
14398         .f = cmd_set_nvgre_parsed,
14399         .data = NULL,
14400         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
14401                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
14402                 " eth-dst <eth-dst>",
14403         .tokens = {
14404                 (void *)&cmd_set_nvgre_set,
14405                 (void *)&cmd_set_nvgre_nvgre,
14406                 (void *)&cmd_set_nvgre_ip_version,
14407                 (void *)&cmd_set_nvgre_ip_version_value,
14408                 (void *)&cmd_set_nvgre_tni,
14409                 (void *)&cmd_set_nvgre_tni_value,
14410                 (void *)&cmd_set_nvgre_ip_src,
14411                 (void *)&cmd_set_nvgre_ip_src_value,
14412                 (void *)&cmd_set_nvgre_ip_dst,
14413                 (void *)&cmd_set_nvgre_ip_dst_value,
14414                 (void *)&cmd_set_nvgre_eth_src,
14415                 (void *)&cmd_set_nvgre_eth_src_value,
14416                 (void *)&cmd_set_nvgre_eth_dst,
14417                 (void *)&cmd_set_nvgre_eth_dst_value,
14418                 NULL,
14419         },
14420 };
14421
14422 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
14423         .f = cmd_set_nvgre_parsed,
14424         .data = NULL,
14425         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
14426                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
14427                 " eth-src <eth-src> eth-dst <eth-dst>",
14428         .tokens = {
14429                 (void *)&cmd_set_nvgre_set,
14430                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
14431                 (void *)&cmd_set_nvgre_ip_version,
14432                 (void *)&cmd_set_nvgre_ip_version_value,
14433                 (void *)&cmd_set_nvgre_tni,
14434                 (void *)&cmd_set_nvgre_tni_value,
14435                 (void *)&cmd_set_nvgre_ip_src,
14436                 (void *)&cmd_set_nvgre_ip_src_value,
14437                 (void *)&cmd_set_nvgre_ip_dst,
14438                 (void *)&cmd_set_nvgre_ip_dst_value,
14439                 (void *)&cmd_set_nvgre_vlan,
14440                 (void *)&cmd_set_nvgre_vlan_value,
14441                 (void *)&cmd_set_nvgre_eth_src,
14442                 (void *)&cmd_set_nvgre_eth_src_value,
14443                 (void *)&cmd_set_nvgre_eth_dst,
14444                 (void *)&cmd_set_nvgre_eth_dst_value,
14445                 NULL,
14446         },
14447 };
14448
14449 /** Set L2 encapsulation details */
14450 struct cmd_set_l2_encap_result {
14451         cmdline_fixed_string_t set;
14452         cmdline_fixed_string_t l2_encap;
14453         cmdline_fixed_string_t pos_token;
14454         cmdline_fixed_string_t ip_version;
14455         uint32_t vlan_present:1;
14456         uint16_t tci;
14457         struct rte_ether_addr eth_src;
14458         struct rte_ether_addr eth_dst;
14459 };
14460
14461 cmdline_parse_token_string_t cmd_set_l2_encap_set =
14462         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
14463 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
14464         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
14465 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
14466         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
14467                                  "l2_encap-with-vlan");
14468 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
14469         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14470                                  "ip-version");
14471 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
14472         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
14473                                  "ipv4#ipv6");
14474 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
14475         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14476                                  "vlan-tci");
14477 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
14478         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
14479 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
14480         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14481                                  "eth-src");
14482 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
14483         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
14484 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
14485         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14486                                  "eth-dst");
14487 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
14488         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
14489
14490 static void cmd_set_l2_encap_parsed(void *parsed_result,
14491         __rte_unused struct cmdline *cl,
14492         __rte_unused void *data)
14493 {
14494         struct cmd_set_l2_encap_result *res = parsed_result;
14495
14496         if (strcmp(res->l2_encap, "l2_encap") == 0)
14497                 l2_encap_conf.select_vlan = 0;
14498         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
14499                 l2_encap_conf.select_vlan = 1;
14500         if (strcmp(res->ip_version, "ipv4") == 0)
14501                 l2_encap_conf.select_ipv4 = 1;
14502         else if (strcmp(res->ip_version, "ipv6") == 0)
14503                 l2_encap_conf.select_ipv4 = 0;
14504         else
14505                 return;
14506         if (l2_encap_conf.select_vlan)
14507                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14508         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
14509                    RTE_ETHER_ADDR_LEN);
14510         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14511                    RTE_ETHER_ADDR_LEN);
14512 }
14513
14514 cmdline_parse_inst_t cmd_set_l2_encap = {
14515         .f = cmd_set_l2_encap_parsed,
14516         .data = NULL,
14517         .help_str = "set l2_encap ip-version ipv4|ipv6"
14518                 " eth-src <eth-src> eth-dst <eth-dst>",
14519         .tokens = {
14520                 (void *)&cmd_set_l2_encap_set,
14521                 (void *)&cmd_set_l2_encap_l2_encap,
14522                 (void *)&cmd_set_l2_encap_ip_version,
14523                 (void *)&cmd_set_l2_encap_ip_version_value,
14524                 (void *)&cmd_set_l2_encap_eth_src,
14525                 (void *)&cmd_set_l2_encap_eth_src_value,
14526                 (void *)&cmd_set_l2_encap_eth_dst,
14527                 (void *)&cmd_set_l2_encap_eth_dst_value,
14528                 NULL,
14529         },
14530 };
14531
14532 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
14533         .f = cmd_set_l2_encap_parsed,
14534         .data = NULL,
14535         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
14536                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
14537         .tokens = {
14538                 (void *)&cmd_set_l2_encap_set,
14539                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
14540                 (void *)&cmd_set_l2_encap_ip_version,
14541                 (void *)&cmd_set_l2_encap_ip_version_value,
14542                 (void *)&cmd_set_l2_encap_vlan,
14543                 (void *)&cmd_set_l2_encap_vlan_value,
14544                 (void *)&cmd_set_l2_encap_eth_src,
14545                 (void *)&cmd_set_l2_encap_eth_src_value,
14546                 (void *)&cmd_set_l2_encap_eth_dst,
14547                 (void *)&cmd_set_l2_encap_eth_dst_value,
14548                 NULL,
14549         },
14550 };
14551
14552 /** Set L2 decapsulation details */
14553 struct cmd_set_l2_decap_result {
14554         cmdline_fixed_string_t set;
14555         cmdline_fixed_string_t l2_decap;
14556         cmdline_fixed_string_t pos_token;
14557         uint32_t vlan_present:1;
14558 };
14559
14560 cmdline_parse_token_string_t cmd_set_l2_decap_set =
14561         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
14562 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
14563         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
14564                                  "l2_decap");
14565 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
14566         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
14567                                  "l2_decap-with-vlan");
14568
14569 static void cmd_set_l2_decap_parsed(void *parsed_result,
14570         __rte_unused struct cmdline *cl,
14571         __rte_unused void *data)
14572 {
14573         struct cmd_set_l2_decap_result *res = parsed_result;
14574
14575         if (strcmp(res->l2_decap, "l2_decap") == 0)
14576                 l2_decap_conf.select_vlan = 0;
14577         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
14578                 l2_decap_conf.select_vlan = 1;
14579 }
14580
14581 cmdline_parse_inst_t cmd_set_l2_decap = {
14582         .f = cmd_set_l2_decap_parsed,
14583         .data = NULL,
14584         .help_str = "set l2_decap",
14585         .tokens = {
14586                 (void *)&cmd_set_l2_decap_set,
14587                 (void *)&cmd_set_l2_decap_l2_decap,
14588                 NULL,
14589         },
14590 };
14591
14592 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
14593         .f = cmd_set_l2_decap_parsed,
14594         .data = NULL,
14595         .help_str = "set l2_decap-with-vlan",
14596         .tokens = {
14597                 (void *)&cmd_set_l2_decap_set,
14598                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
14599                 NULL,
14600         },
14601 };
14602
14603 /** Set MPLSoGRE encapsulation details */
14604 struct cmd_set_mplsogre_encap_result {
14605         cmdline_fixed_string_t set;
14606         cmdline_fixed_string_t mplsogre;
14607         cmdline_fixed_string_t pos_token;
14608         cmdline_fixed_string_t ip_version;
14609         uint32_t vlan_present:1;
14610         uint32_t label;
14611         cmdline_ipaddr_t ip_src;
14612         cmdline_ipaddr_t ip_dst;
14613         uint16_t tci;
14614         struct rte_ether_addr eth_src;
14615         struct rte_ether_addr eth_dst;
14616 };
14617
14618 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
14619         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
14620                                  "set");
14621 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
14622         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
14623                                  "mplsogre_encap");
14624 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
14625         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14626                                  mplsogre, "mplsogre_encap-with-vlan");
14627 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
14628         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14629                                  pos_token, "ip-version");
14630 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
14631         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14632                                  ip_version, "ipv4#ipv6");
14633 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
14634         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14635                                  pos_token, "label");
14636 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
14637         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
14638                               UINT32);
14639 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
14640         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14641                                  pos_token, "ip-src");
14642 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
14643         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
14644 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
14645         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14646                                  pos_token, "ip-dst");
14647 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
14648         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
14649 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
14650         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14651                                  pos_token, "vlan-tci");
14652 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
14653         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
14654                               UINT16);
14655 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
14656         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14657                                  pos_token, "eth-src");
14658 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
14659         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14660                                     eth_src);
14661 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
14662         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14663                                  pos_token, "eth-dst");
14664 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
14665         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14666                                     eth_dst);
14667
14668 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
14669         __rte_unused struct cmdline *cl,
14670         __rte_unused void *data)
14671 {
14672         struct cmd_set_mplsogre_encap_result *res = parsed_result;
14673         union {
14674                 uint32_t mplsogre_label;
14675                 uint8_t label[4];
14676         } id = {
14677                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
14678         };
14679
14680         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
14681                 mplsogre_encap_conf.select_vlan = 0;
14682         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
14683                 mplsogre_encap_conf.select_vlan = 1;
14684         if (strcmp(res->ip_version, "ipv4") == 0)
14685                 mplsogre_encap_conf.select_ipv4 = 1;
14686         else if (strcmp(res->ip_version, "ipv6") == 0)
14687                 mplsogre_encap_conf.select_ipv4 = 0;
14688         else
14689                 return;
14690         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
14691         if (mplsogre_encap_conf.select_ipv4) {
14692                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
14693                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
14694         } else {
14695                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
14696                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
14697         }
14698         if (mplsogre_encap_conf.select_vlan)
14699                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14700         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
14701                    RTE_ETHER_ADDR_LEN);
14702         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14703                    RTE_ETHER_ADDR_LEN);
14704 }
14705
14706 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
14707         .f = cmd_set_mplsogre_encap_parsed,
14708         .data = NULL,
14709         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
14710                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
14711                 " eth-dst <eth-dst>",
14712         .tokens = {
14713                 (void *)&cmd_set_mplsogre_encap_set,
14714                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
14715                 (void *)&cmd_set_mplsogre_encap_ip_version,
14716                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
14717                 (void *)&cmd_set_mplsogre_encap_label,
14718                 (void *)&cmd_set_mplsogre_encap_label_value,
14719                 (void *)&cmd_set_mplsogre_encap_ip_src,
14720                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
14721                 (void *)&cmd_set_mplsogre_encap_ip_dst,
14722                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
14723                 (void *)&cmd_set_mplsogre_encap_eth_src,
14724                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
14725                 (void *)&cmd_set_mplsogre_encap_eth_dst,
14726                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
14727                 NULL,
14728         },
14729 };
14730
14731 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
14732         .f = cmd_set_mplsogre_encap_parsed,
14733         .data = NULL,
14734         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
14735                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
14736                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
14737         .tokens = {
14738                 (void *)&cmd_set_mplsogre_encap_set,
14739                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
14740                 (void *)&cmd_set_mplsogre_encap_ip_version,
14741                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
14742                 (void *)&cmd_set_mplsogre_encap_label,
14743                 (void *)&cmd_set_mplsogre_encap_label_value,
14744                 (void *)&cmd_set_mplsogre_encap_ip_src,
14745                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
14746                 (void *)&cmd_set_mplsogre_encap_ip_dst,
14747                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
14748                 (void *)&cmd_set_mplsogre_encap_vlan,
14749                 (void *)&cmd_set_mplsogre_encap_vlan_value,
14750                 (void *)&cmd_set_mplsogre_encap_eth_src,
14751                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
14752                 (void *)&cmd_set_mplsogre_encap_eth_dst,
14753                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
14754                 NULL,
14755         },
14756 };
14757
14758 /** Set MPLSoGRE decapsulation details */
14759 struct cmd_set_mplsogre_decap_result {
14760         cmdline_fixed_string_t set;
14761         cmdline_fixed_string_t mplsogre;
14762         cmdline_fixed_string_t pos_token;
14763         cmdline_fixed_string_t ip_version;
14764         uint32_t vlan_present:1;
14765 };
14766
14767 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
14768         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
14769                                  "set");
14770 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
14771         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
14772                                  "mplsogre_decap");
14773 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
14774         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
14775                                  mplsogre, "mplsogre_decap-with-vlan");
14776 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
14777         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
14778                                  pos_token, "ip-version");
14779 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
14780         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
14781                                  ip_version, "ipv4#ipv6");
14782
14783 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
14784         __rte_unused struct cmdline *cl,
14785         __rte_unused void *data)
14786 {
14787         struct cmd_set_mplsogre_decap_result *res = parsed_result;
14788
14789         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
14790                 mplsogre_decap_conf.select_vlan = 0;
14791         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
14792                 mplsogre_decap_conf.select_vlan = 1;
14793         if (strcmp(res->ip_version, "ipv4") == 0)
14794                 mplsogre_decap_conf.select_ipv4 = 1;
14795         else if (strcmp(res->ip_version, "ipv6") == 0)
14796                 mplsogre_decap_conf.select_ipv4 = 0;
14797 }
14798
14799 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
14800         .f = cmd_set_mplsogre_decap_parsed,
14801         .data = NULL,
14802         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
14803         .tokens = {
14804                 (void *)&cmd_set_mplsogre_decap_set,
14805                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
14806                 (void *)&cmd_set_mplsogre_decap_ip_version,
14807                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
14808                 NULL,
14809         },
14810 };
14811
14812 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
14813         .f = cmd_set_mplsogre_decap_parsed,
14814         .data = NULL,
14815         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
14816         .tokens = {
14817                 (void *)&cmd_set_mplsogre_decap_set,
14818                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
14819                 (void *)&cmd_set_mplsogre_decap_ip_version,
14820                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
14821                 NULL,
14822         },
14823 };
14824
14825 /** Set MPLSoUDP encapsulation details */
14826 struct cmd_set_mplsoudp_encap_result {
14827         cmdline_fixed_string_t set;
14828         cmdline_fixed_string_t mplsoudp;
14829         cmdline_fixed_string_t pos_token;
14830         cmdline_fixed_string_t ip_version;
14831         uint32_t vlan_present:1;
14832         uint32_t label;
14833         uint16_t udp_src;
14834         uint16_t udp_dst;
14835         cmdline_ipaddr_t ip_src;
14836         cmdline_ipaddr_t ip_dst;
14837         uint16_t tci;
14838         struct rte_ether_addr eth_src;
14839         struct rte_ether_addr eth_dst;
14840 };
14841
14842 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
14843         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
14844                                  "set");
14845 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
14846         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
14847                                  "mplsoudp_encap");
14848 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
14849         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14850                                  mplsoudp, "mplsoudp_encap-with-vlan");
14851 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
14852         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14853                                  pos_token, "ip-version");
14854 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
14855         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14856                                  ip_version, "ipv4#ipv6");
14857 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
14858         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14859                                  pos_token, "label");
14860 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
14861         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
14862                               UINT32);
14863 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
14864         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14865                                  pos_token, "udp-src");
14866 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
14867         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
14868                               UINT16);
14869 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
14870         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14871                                  pos_token, "udp-dst");
14872 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
14873         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
14874                               UINT16);
14875 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
14876         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14877                                  pos_token, "ip-src");
14878 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
14879         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
14880 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
14881         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14882                                  pos_token, "ip-dst");
14883 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
14884         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
14885 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
14886         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14887                                  pos_token, "vlan-tci");
14888 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
14889         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
14890                               UINT16);
14891 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
14892         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14893                                  pos_token, "eth-src");
14894 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
14895         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14896                                     eth_src);
14897 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
14898         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14899                                  pos_token, "eth-dst");
14900 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
14901         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14902                                     eth_dst);
14903
14904 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
14905         __rte_unused struct cmdline *cl,
14906         __rte_unused void *data)
14907 {
14908         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
14909         union {
14910                 uint32_t mplsoudp_label;
14911                 uint8_t label[4];
14912         } id = {
14913                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
14914         };
14915
14916         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
14917                 mplsoudp_encap_conf.select_vlan = 0;
14918         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
14919                 mplsoudp_encap_conf.select_vlan = 1;
14920         if (strcmp(res->ip_version, "ipv4") == 0)
14921                 mplsoudp_encap_conf.select_ipv4 = 1;
14922         else if (strcmp(res->ip_version, "ipv6") == 0)
14923                 mplsoudp_encap_conf.select_ipv4 = 0;
14924         else
14925                 return;
14926         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
14927         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
14928         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
14929         if (mplsoudp_encap_conf.select_ipv4) {
14930                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
14931                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
14932         } else {
14933                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
14934                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
14935         }
14936         if (mplsoudp_encap_conf.select_vlan)
14937                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14938         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
14939                    RTE_ETHER_ADDR_LEN);
14940         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14941                    RTE_ETHER_ADDR_LEN);
14942 }
14943
14944 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
14945         .f = cmd_set_mplsoudp_encap_parsed,
14946         .data = NULL,
14947         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
14948                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
14949                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
14950         .tokens = {
14951                 (void *)&cmd_set_mplsoudp_encap_set,
14952                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
14953                 (void *)&cmd_set_mplsoudp_encap_ip_version,
14954                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
14955                 (void *)&cmd_set_mplsoudp_encap_label,
14956                 (void *)&cmd_set_mplsoudp_encap_label_value,
14957                 (void *)&cmd_set_mplsoudp_encap_udp_src,
14958                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
14959                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
14960                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
14961                 (void *)&cmd_set_mplsoudp_encap_ip_src,
14962                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
14963                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
14964                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
14965                 (void *)&cmd_set_mplsoudp_encap_eth_src,
14966                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
14967                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
14968                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
14969                 NULL,
14970         },
14971 };
14972
14973 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
14974         .f = cmd_set_mplsoudp_encap_parsed,
14975         .data = NULL,
14976         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
14977                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
14978                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
14979                 " eth-src <eth-src> eth-dst <eth-dst>",
14980         .tokens = {
14981                 (void *)&cmd_set_mplsoudp_encap_set,
14982                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
14983                 (void *)&cmd_set_mplsoudp_encap_ip_version,
14984                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
14985                 (void *)&cmd_set_mplsoudp_encap_label,
14986                 (void *)&cmd_set_mplsoudp_encap_label_value,
14987                 (void *)&cmd_set_mplsoudp_encap_udp_src,
14988                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
14989                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
14990                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
14991                 (void *)&cmd_set_mplsoudp_encap_ip_src,
14992                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
14993                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
14994                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
14995                 (void *)&cmd_set_mplsoudp_encap_vlan,
14996                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
14997                 (void *)&cmd_set_mplsoudp_encap_eth_src,
14998                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
14999                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15000                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15001                 NULL,
15002         },
15003 };
15004
15005 /** Set MPLSoUDP decapsulation details */
15006 struct cmd_set_mplsoudp_decap_result {
15007         cmdline_fixed_string_t set;
15008         cmdline_fixed_string_t mplsoudp;
15009         cmdline_fixed_string_t pos_token;
15010         cmdline_fixed_string_t ip_version;
15011         uint32_t vlan_present:1;
15012 };
15013
15014 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
15015         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
15016                                  "set");
15017 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
15018         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
15019                                  "mplsoudp_decap");
15020 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
15021         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15022                                  mplsoudp, "mplsoudp_decap-with-vlan");
15023 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
15024         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15025                                  pos_token, "ip-version");
15026 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
15027         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15028                                  ip_version, "ipv4#ipv6");
15029
15030 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
15031         __rte_unused struct cmdline *cl,
15032         __rte_unused void *data)
15033 {
15034         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
15035
15036         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
15037                 mplsoudp_decap_conf.select_vlan = 0;
15038         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
15039                 mplsoudp_decap_conf.select_vlan = 1;
15040         if (strcmp(res->ip_version, "ipv4") == 0)
15041                 mplsoudp_decap_conf.select_ipv4 = 1;
15042         else if (strcmp(res->ip_version, "ipv6") == 0)
15043                 mplsoudp_decap_conf.select_ipv4 = 0;
15044 }
15045
15046 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
15047         .f = cmd_set_mplsoudp_decap_parsed,
15048         .data = NULL,
15049         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
15050         .tokens = {
15051                 (void *)&cmd_set_mplsoudp_decap_set,
15052                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
15053                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15054                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15055                 NULL,
15056         },
15057 };
15058
15059 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
15060         .f = cmd_set_mplsoudp_decap_parsed,
15061         .data = NULL,
15062         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
15063         .tokens = {
15064                 (void *)&cmd_set_mplsoudp_decap_set,
15065                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
15066                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15067                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15068                 NULL,
15069         },
15070 };
15071
15072 /* Strict link priority scheduling mode setting */
15073 static void
15074 cmd_strict_link_prio_parsed(
15075         void *parsed_result,
15076         __rte_unused struct cmdline *cl,
15077         __rte_unused void *data)
15078 {
15079         struct cmd_vf_tc_bw_result *res = parsed_result;
15080         int ret = -ENOTSUP;
15081
15082         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15083                 return;
15084
15085 #ifdef RTE_NET_I40E
15086         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
15087 #endif
15088
15089         switch (ret) {
15090         case 0:
15091                 break;
15092         case -EINVAL:
15093                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
15094                 break;
15095         case -ENODEV:
15096                 printf("invalid port_id %d\n", res->port_id);
15097                 break;
15098         case -ENOTSUP:
15099                 printf("function not implemented\n");
15100                 break;
15101         default:
15102                 printf("programming error: (%s)\n", strerror(-ret));
15103         }
15104 }
15105
15106 cmdline_parse_inst_t cmd_strict_link_prio = {
15107         .f = cmd_strict_link_prio_parsed,
15108         .data = NULL,
15109         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
15110         .tokens = {
15111                 (void *)&cmd_vf_tc_bw_set,
15112                 (void *)&cmd_vf_tc_bw_tx,
15113                 (void *)&cmd_vf_tc_bw_strict_link_prio,
15114                 (void *)&cmd_vf_tc_bw_port_id,
15115                 (void *)&cmd_vf_tc_bw_tc_map,
15116                 NULL,
15117         },
15118 };
15119
15120 /* Load dynamic device personalization*/
15121 struct cmd_ddp_add_result {
15122         cmdline_fixed_string_t ddp;
15123         cmdline_fixed_string_t add;
15124         portid_t port_id;
15125         char filepath[];
15126 };
15127
15128 cmdline_parse_token_string_t cmd_ddp_add_ddp =
15129         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
15130 cmdline_parse_token_string_t cmd_ddp_add_add =
15131         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
15132 cmdline_parse_token_num_t cmd_ddp_add_port_id =
15133         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
15134 cmdline_parse_token_string_t cmd_ddp_add_filepath =
15135         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
15136
15137 static void
15138 cmd_ddp_add_parsed(
15139         void *parsed_result,
15140         __rte_unused struct cmdline *cl,
15141         __rte_unused void *data)
15142 {
15143         struct cmd_ddp_add_result *res = parsed_result;
15144         uint8_t *buff;
15145         uint32_t size;
15146         char *filepath;
15147         char *file_fld[2];
15148         int file_num;
15149         int ret = -ENOTSUP;
15150
15151         if (!all_ports_stopped()) {
15152                 printf("Please stop all ports first\n");
15153                 return;
15154         }
15155
15156         filepath = strdup(res->filepath);
15157         if (filepath == NULL) {
15158                 printf("Failed to allocate memory\n");
15159                 return;
15160         }
15161         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
15162
15163         buff = open_file(file_fld[0], &size);
15164         if (!buff) {
15165                 free((void *)filepath);
15166                 return;
15167         }
15168
15169 #ifdef RTE_NET_I40E
15170         if (ret == -ENOTSUP)
15171                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15172                                                buff, size,
15173                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
15174 #endif
15175
15176         if (ret == -EEXIST)
15177                 printf("Profile has already existed.\n");
15178         else if (ret < 0)
15179                 printf("Failed to load profile.\n");
15180         else if (file_num == 2)
15181                 save_file(file_fld[1], buff, size);
15182
15183         close_file(buff);
15184         free((void *)filepath);
15185 }
15186
15187 cmdline_parse_inst_t cmd_ddp_add = {
15188         .f = cmd_ddp_add_parsed,
15189         .data = NULL,
15190         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
15191         .tokens = {
15192                 (void *)&cmd_ddp_add_ddp,
15193                 (void *)&cmd_ddp_add_add,
15194                 (void *)&cmd_ddp_add_port_id,
15195                 (void *)&cmd_ddp_add_filepath,
15196                 NULL,
15197         },
15198 };
15199
15200 /* Delete dynamic device personalization*/
15201 struct cmd_ddp_del_result {
15202         cmdline_fixed_string_t ddp;
15203         cmdline_fixed_string_t del;
15204         portid_t port_id;
15205         char filepath[];
15206 };
15207
15208 cmdline_parse_token_string_t cmd_ddp_del_ddp =
15209         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
15210 cmdline_parse_token_string_t cmd_ddp_del_del =
15211         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
15212 cmdline_parse_token_num_t cmd_ddp_del_port_id =
15213         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
15214 cmdline_parse_token_string_t cmd_ddp_del_filepath =
15215         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
15216
15217 static void
15218 cmd_ddp_del_parsed(
15219         void *parsed_result,
15220         __rte_unused struct cmdline *cl,
15221         __rte_unused void *data)
15222 {
15223         struct cmd_ddp_del_result *res = parsed_result;
15224         uint8_t *buff;
15225         uint32_t size;
15226         int ret = -ENOTSUP;
15227
15228         if (!all_ports_stopped()) {
15229                 printf("Please stop all ports first\n");
15230                 return;
15231         }
15232
15233         buff = open_file(res->filepath, &size);
15234         if (!buff)
15235                 return;
15236
15237 #ifdef RTE_NET_I40E
15238         if (ret == -ENOTSUP)
15239                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15240                                                buff, size,
15241                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15242 #endif
15243
15244         if (ret == -EACCES)
15245                 printf("Profile does not exist.\n");
15246         else if (ret < 0)
15247                 printf("Failed to delete profile.\n");
15248
15249         close_file(buff);
15250 }
15251
15252 cmdline_parse_inst_t cmd_ddp_del = {
15253         .f = cmd_ddp_del_parsed,
15254         .data = NULL,
15255         .help_str = "ddp del <port_id> <backup_profile_path>",
15256         .tokens = {
15257                 (void *)&cmd_ddp_del_ddp,
15258                 (void *)&cmd_ddp_del_del,
15259                 (void *)&cmd_ddp_del_port_id,
15260                 (void *)&cmd_ddp_del_filepath,
15261                 NULL,
15262         },
15263 };
15264
15265 /* Get dynamic device personalization profile info */
15266 struct cmd_ddp_info_result {
15267         cmdline_fixed_string_t ddp;
15268         cmdline_fixed_string_t get;
15269         cmdline_fixed_string_t info;
15270         char filepath[];
15271 };
15272
15273 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15274         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15275 cmdline_parse_token_string_t cmd_ddp_info_get =
15276         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15277 cmdline_parse_token_string_t cmd_ddp_info_info =
15278         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15279 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15280         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15281
15282 static void
15283 cmd_ddp_info_parsed(
15284         void *parsed_result,
15285         __rte_unused struct cmdline *cl,
15286         __rte_unused void *data)
15287 {
15288         struct cmd_ddp_info_result *res = parsed_result;
15289         uint8_t *pkg;
15290         uint32_t pkg_size;
15291         int ret = -ENOTSUP;
15292 #ifdef RTE_NET_I40E
15293         uint32_t i, j, n;
15294         uint8_t *buff;
15295         uint32_t buff_size = 0;
15296         struct rte_pmd_i40e_profile_info info;
15297         uint32_t dev_num = 0;
15298         struct rte_pmd_i40e_ddp_device_id *devs;
15299         uint32_t proto_num = 0;
15300         struct rte_pmd_i40e_proto_info *proto = NULL;
15301         uint32_t pctype_num = 0;
15302         struct rte_pmd_i40e_ptype_info *pctype;
15303         uint32_t ptype_num = 0;
15304         struct rte_pmd_i40e_ptype_info *ptype;
15305         uint8_t proto_id;
15306
15307 #endif
15308
15309         pkg = open_file(res->filepath, &pkg_size);
15310         if (!pkg)
15311                 return;
15312
15313 #ifdef RTE_NET_I40E
15314         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15315                                 (uint8_t *)&info, sizeof(info),
15316                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15317         if (!ret) {
15318                 printf("Global Track id:       0x%x\n", info.track_id);
15319                 printf("Global Version:        %d.%d.%d.%d\n",
15320                         info.version.major,
15321                         info.version.minor,
15322                         info.version.update,
15323                         info.version.draft);
15324                 printf("Global Package name:   %s\n\n", info.name);
15325         }
15326
15327         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15328                                 (uint8_t *)&info, sizeof(info),
15329                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15330         if (!ret) {
15331                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15332                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15333                         info.version.major,
15334                         info.version.minor,
15335                         info.version.update,
15336                         info.version.draft);
15337                 printf("i40e Profile name:     %s\n\n", info.name);
15338         }
15339
15340         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15341                                 (uint8_t *)&buff_size, sizeof(buff_size),
15342                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15343         if (!ret && buff_size) {
15344                 buff = (uint8_t *)malloc(buff_size);
15345                 if (buff) {
15346                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15347                                                 buff, buff_size,
15348                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15349                         if (!ret)
15350                                 printf("Package Notes:\n%s\n\n", buff);
15351                         free(buff);
15352                 }
15353         }
15354
15355         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15356                                 (uint8_t *)&dev_num, sizeof(dev_num),
15357                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15358         if (!ret && dev_num) {
15359                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15360                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15361                 if (devs) {
15362                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15363                                                 (uint8_t *)devs, buff_size,
15364                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15365                         if (!ret) {
15366                                 printf("List of supported devices:\n");
15367                                 for (i = 0; i < dev_num; i++) {
15368                                         printf("  %04X:%04X %04X:%04X\n",
15369                                                 devs[i].vendor_dev_id >> 16,
15370                                                 devs[i].vendor_dev_id & 0xFFFF,
15371                                                 devs[i].sub_vendor_dev_id >> 16,
15372                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15373                                 }
15374                                 printf("\n");
15375                         }
15376                         free(devs);
15377                 }
15378         }
15379
15380         /* get information about protocols and packet types */
15381         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15382                 (uint8_t *)&proto_num, sizeof(proto_num),
15383                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15384         if (ret || !proto_num)
15385                 goto no_print_return;
15386
15387         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15388         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15389         if (!proto)
15390                 goto no_print_return;
15391
15392         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15393                                         buff_size,
15394                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15395         if (!ret) {
15396                 printf("List of used protocols:\n");
15397                 for (i = 0; i < proto_num; i++)
15398                         printf("  %2u: %s\n", proto[i].proto_id,
15399                                proto[i].name);
15400                 printf("\n");
15401         }
15402         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15403                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15404                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15405         if (ret || !pctype_num)
15406                 goto no_print_pctypes;
15407
15408         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15409         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15410         if (!pctype)
15411                 goto no_print_pctypes;
15412
15413         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15414                                         buff_size,
15415                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15416         if (ret) {
15417                 free(pctype);
15418                 goto no_print_pctypes;
15419         }
15420
15421         printf("List of defined packet classification types:\n");
15422         for (i = 0; i < pctype_num; i++) {
15423                 printf("  %2u:", pctype[i].ptype_id);
15424                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15425                         proto_id = pctype[i].protocols[j];
15426                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15427                                 for (n = 0; n < proto_num; n++) {
15428                                         if (proto[n].proto_id == proto_id) {
15429                                                 printf(" %s", proto[n].name);
15430                                                 break;
15431                                         }
15432                                 }
15433                         }
15434                 }
15435                 printf("\n");
15436         }
15437         printf("\n");
15438         free(pctype);
15439
15440 no_print_pctypes:
15441
15442         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15443                                         sizeof(ptype_num),
15444                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15445         if (ret || !ptype_num)
15446                 goto no_print_return;
15447
15448         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15449         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15450         if (!ptype)
15451                 goto no_print_return;
15452
15453         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15454                                         buff_size,
15455                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15456         if (ret) {
15457                 free(ptype);
15458                 goto no_print_return;
15459         }
15460         printf("List of defined packet types:\n");
15461         for (i = 0; i < ptype_num; i++) {
15462                 printf("  %2u:", ptype[i].ptype_id);
15463                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15464                         proto_id = ptype[i].protocols[j];
15465                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15466                                 for (n = 0; n < proto_num; n++) {
15467                                         if (proto[n].proto_id == proto_id) {
15468                                                 printf(" %s", proto[n].name);
15469                                                 break;
15470                                         }
15471                                 }
15472                         }
15473                 }
15474                 printf("\n");
15475         }
15476         free(ptype);
15477         printf("\n");
15478
15479         ret = 0;
15480 no_print_return:
15481         if (proto)
15482                 free(proto);
15483 #endif
15484         if (ret == -ENOTSUP)
15485                 printf("Function not supported in PMD driver\n");
15486         close_file(pkg);
15487 }
15488
15489 cmdline_parse_inst_t cmd_ddp_get_info = {
15490         .f = cmd_ddp_info_parsed,
15491         .data = NULL,
15492         .help_str = "ddp get info <profile_path>",
15493         .tokens = {
15494                 (void *)&cmd_ddp_info_ddp,
15495                 (void *)&cmd_ddp_info_get,
15496                 (void *)&cmd_ddp_info_info,
15497                 (void *)&cmd_ddp_info_filepath,
15498                 NULL,
15499         },
15500 };
15501
15502 /* Get dynamic device personalization profile info list*/
15503 #define PROFILE_INFO_SIZE 48
15504 #define MAX_PROFILE_NUM 16
15505
15506 struct cmd_ddp_get_list_result {
15507         cmdline_fixed_string_t ddp;
15508         cmdline_fixed_string_t get;
15509         cmdline_fixed_string_t list;
15510         portid_t port_id;
15511 };
15512
15513 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15514         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15515 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15516         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15517 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15518         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15519 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15520         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15521
15522 static void
15523 cmd_ddp_get_list_parsed(
15524         __rte_unused void *parsed_result,
15525         __rte_unused struct cmdline *cl,
15526         __rte_unused void *data)
15527 {
15528 #ifdef RTE_NET_I40E
15529         struct cmd_ddp_get_list_result *res = parsed_result;
15530         struct rte_pmd_i40e_profile_list *p_list;
15531         struct rte_pmd_i40e_profile_info *p_info;
15532         uint32_t p_num;
15533         uint32_t size;
15534         uint32_t i;
15535 #endif
15536         int ret = -ENOTSUP;
15537
15538 #ifdef RTE_NET_I40E
15539         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15540         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15541         if (!p_list) {
15542                 printf("%s: Failed to malloc buffer\n", __func__);
15543                 return;
15544         }
15545
15546         if (ret == -ENOTSUP)
15547                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15548                                                 (uint8_t *)p_list, size);
15549
15550         if (!ret) {
15551                 p_num = p_list->p_count;
15552                 printf("Profile number is: %d\n\n", p_num);
15553
15554                 for (i = 0; i < p_num; i++) {
15555                         p_info = &p_list->p_info[i];
15556                         printf("Profile %d:\n", i);
15557                         printf("Track id:     0x%x\n", p_info->track_id);
15558                         printf("Version:      %d.%d.%d.%d\n",
15559                                p_info->version.major,
15560                                p_info->version.minor,
15561                                p_info->version.update,
15562                                p_info->version.draft);
15563                         printf("Profile name: %s\n\n", p_info->name);
15564                 }
15565         }
15566
15567         free(p_list);
15568 #endif
15569
15570         if (ret < 0)
15571                 printf("Failed to get ddp list\n");
15572 }
15573
15574 cmdline_parse_inst_t cmd_ddp_get_list = {
15575         .f = cmd_ddp_get_list_parsed,
15576         .data = NULL,
15577         .help_str = "ddp get list <port_id>",
15578         .tokens = {
15579                 (void *)&cmd_ddp_get_list_ddp,
15580                 (void *)&cmd_ddp_get_list_get,
15581                 (void *)&cmd_ddp_get_list_list,
15582                 (void *)&cmd_ddp_get_list_port_id,
15583                 NULL,
15584         },
15585 };
15586
15587 /* Configure input set */
15588 struct cmd_cfg_input_set_result {
15589         cmdline_fixed_string_t port;
15590         cmdline_fixed_string_t cfg;
15591         portid_t port_id;
15592         cmdline_fixed_string_t pctype;
15593         uint8_t pctype_id;
15594         cmdline_fixed_string_t inset_type;
15595         cmdline_fixed_string_t opt;
15596         cmdline_fixed_string_t field;
15597         uint8_t field_idx;
15598 };
15599
15600 static void
15601 cmd_cfg_input_set_parsed(
15602         __rte_unused void *parsed_result,
15603         __rte_unused struct cmdline *cl,
15604         __rte_unused void *data)
15605 {
15606 #ifdef RTE_NET_I40E
15607         struct cmd_cfg_input_set_result *res = parsed_result;
15608         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15609         struct rte_pmd_i40e_inset inset;
15610 #endif
15611         int ret = -ENOTSUP;
15612
15613         if (!all_ports_stopped()) {
15614                 printf("Please stop all ports first\n");
15615                 return;
15616         }
15617
15618 #ifdef RTE_NET_I40E
15619         if (!strcmp(res->inset_type, "hash_inset"))
15620                 inset_type = INSET_HASH;
15621         else if (!strcmp(res->inset_type, "fdir_inset"))
15622                 inset_type = INSET_FDIR;
15623         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15624                 inset_type = INSET_FDIR_FLX;
15625         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15626                                      &inset, inset_type);
15627         if (ret) {
15628                 printf("Failed to get input set.\n");
15629                 return;
15630         }
15631
15632         if (!strcmp(res->opt, "get")) {
15633                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15634                                                    res->field_idx);
15635                 if (ret)
15636                         printf("Field index %d is enabled.\n", res->field_idx);
15637                 else
15638                         printf("Field index %d is disabled.\n", res->field_idx);
15639                 return;
15640         } else if (!strcmp(res->opt, "set"))
15641                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15642                                                    res->field_idx);
15643         else if (!strcmp(res->opt, "clear"))
15644                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15645                                                      res->field_idx);
15646         if (ret) {
15647                 printf("Failed to configure input set field.\n");
15648                 return;
15649         }
15650
15651         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15652                                      &inset, inset_type);
15653         if (ret) {
15654                 printf("Failed to set input set.\n");
15655                 return;
15656         }
15657 #endif
15658
15659         if (ret == -ENOTSUP)
15660                 printf("Function not supported\n");
15661 }
15662
15663 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15664         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15665                                  port, "port");
15666 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15667         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15668                                  cfg, "config");
15669 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15670         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15671                               port_id, UINT16);
15672 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15673         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15674                                  pctype, "pctype");
15675 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15676         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15677                               pctype_id, UINT8);
15678 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15679         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15680                                  inset_type,
15681                                  "hash_inset#fdir_inset#fdir_flx_inset");
15682 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15683         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15684                                  opt, "get#set#clear");
15685 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15686         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15687                                  field, "field");
15688 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15689         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15690                               field_idx, UINT8);
15691
15692 cmdline_parse_inst_t cmd_cfg_input_set = {
15693         .f = cmd_cfg_input_set_parsed,
15694         .data = NULL,
15695         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15696                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15697         .tokens = {
15698                 (void *)&cmd_cfg_input_set_port,
15699                 (void *)&cmd_cfg_input_set_cfg,
15700                 (void *)&cmd_cfg_input_set_port_id,
15701                 (void *)&cmd_cfg_input_set_pctype,
15702                 (void *)&cmd_cfg_input_set_pctype_id,
15703                 (void *)&cmd_cfg_input_set_inset_type,
15704                 (void *)&cmd_cfg_input_set_opt,
15705                 (void *)&cmd_cfg_input_set_field,
15706                 (void *)&cmd_cfg_input_set_field_idx,
15707                 NULL,
15708         },
15709 };
15710
15711 /* Clear input set */
15712 struct cmd_clear_input_set_result {
15713         cmdline_fixed_string_t port;
15714         cmdline_fixed_string_t cfg;
15715         portid_t port_id;
15716         cmdline_fixed_string_t pctype;
15717         uint8_t pctype_id;
15718         cmdline_fixed_string_t inset_type;
15719         cmdline_fixed_string_t clear;
15720         cmdline_fixed_string_t all;
15721 };
15722
15723 static void
15724 cmd_clear_input_set_parsed(
15725         __rte_unused void *parsed_result,
15726         __rte_unused struct cmdline *cl,
15727         __rte_unused void *data)
15728 {
15729 #ifdef RTE_NET_I40E
15730         struct cmd_clear_input_set_result *res = parsed_result;
15731         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15732         struct rte_pmd_i40e_inset inset;
15733 #endif
15734         int ret = -ENOTSUP;
15735
15736         if (!all_ports_stopped()) {
15737                 printf("Please stop all ports first\n");
15738                 return;
15739         }
15740
15741 #ifdef RTE_NET_I40E
15742         if (!strcmp(res->inset_type, "hash_inset"))
15743                 inset_type = INSET_HASH;
15744         else if (!strcmp(res->inset_type, "fdir_inset"))
15745                 inset_type = INSET_FDIR;
15746         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15747                 inset_type = INSET_FDIR_FLX;
15748
15749         memset(&inset, 0, sizeof(inset));
15750
15751         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15752                                      &inset, inset_type);
15753         if (ret) {
15754                 printf("Failed to clear input set.\n");
15755                 return;
15756         }
15757
15758 #endif
15759
15760         if (ret == -ENOTSUP)
15761                 printf("Function not supported\n");
15762 }
15763
15764 cmdline_parse_token_string_t cmd_clear_input_set_port =
15765         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15766                                  port, "port");
15767 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15768         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15769                                  cfg, "config");
15770 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15771         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15772                               port_id, UINT16);
15773 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15774         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15775                                  pctype, "pctype");
15776 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15777         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15778                               pctype_id, UINT8);
15779 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15780         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15781                                  inset_type,
15782                                  "hash_inset#fdir_inset#fdir_flx_inset");
15783 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15784         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15785                                  clear, "clear");
15786 cmdline_parse_token_string_t cmd_clear_input_set_all =
15787         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15788                                  all, "all");
15789
15790 cmdline_parse_inst_t cmd_clear_input_set = {
15791         .f = cmd_clear_input_set_parsed,
15792         .data = NULL,
15793         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15794                     "fdir_inset|fdir_flx_inset clear all",
15795         .tokens = {
15796                 (void *)&cmd_clear_input_set_port,
15797                 (void *)&cmd_clear_input_set_cfg,
15798                 (void *)&cmd_clear_input_set_port_id,
15799                 (void *)&cmd_clear_input_set_pctype,
15800                 (void *)&cmd_clear_input_set_pctype_id,
15801                 (void *)&cmd_clear_input_set_inset_type,
15802                 (void *)&cmd_clear_input_set_clear,
15803                 (void *)&cmd_clear_input_set_all,
15804                 NULL,
15805         },
15806 };
15807
15808 /* show vf stats */
15809
15810 /* Common result structure for show vf stats */
15811 struct cmd_show_vf_stats_result {
15812         cmdline_fixed_string_t show;
15813         cmdline_fixed_string_t vf;
15814         cmdline_fixed_string_t stats;
15815         portid_t port_id;
15816         uint16_t vf_id;
15817 };
15818
15819 /* Common CLI fields show vf stats*/
15820 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15821         TOKEN_STRING_INITIALIZER
15822                 (struct cmd_show_vf_stats_result,
15823                  show, "show");
15824 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15825         TOKEN_STRING_INITIALIZER
15826                 (struct cmd_show_vf_stats_result,
15827                  vf, "vf");
15828 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15829         TOKEN_STRING_INITIALIZER
15830                 (struct cmd_show_vf_stats_result,
15831                  stats, "stats");
15832 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15833         TOKEN_NUM_INITIALIZER
15834                 (struct cmd_show_vf_stats_result,
15835                  port_id, UINT16);
15836 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15837         TOKEN_NUM_INITIALIZER
15838                 (struct cmd_show_vf_stats_result,
15839                  vf_id, UINT16);
15840
15841 static void
15842 cmd_show_vf_stats_parsed(
15843         void *parsed_result,
15844         __rte_unused struct cmdline *cl,
15845         __rte_unused void *data)
15846 {
15847         struct cmd_show_vf_stats_result *res = parsed_result;
15848         struct rte_eth_stats stats;
15849         int ret = -ENOTSUP;
15850         static const char *nic_stats_border = "########################";
15851
15852         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15853                 return;
15854
15855         memset(&stats, 0, sizeof(stats));
15856
15857 #ifdef RTE_NET_I40E
15858         if (ret == -ENOTSUP)
15859                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15860                                                 res->vf_id,
15861                                                 &stats);
15862 #endif
15863 #ifdef RTE_NET_BNXT
15864         if (ret == -ENOTSUP)
15865                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15866                                                 res->vf_id,
15867                                                 &stats);
15868 #endif
15869
15870         switch (ret) {
15871         case 0:
15872                 break;
15873         case -EINVAL:
15874                 printf("invalid vf_id %d\n", res->vf_id);
15875                 break;
15876         case -ENODEV:
15877                 printf("invalid port_id %d\n", res->port_id);
15878                 break;
15879         case -ENOTSUP:
15880                 printf("function not implemented\n");
15881                 break;
15882         default:
15883                 printf("programming error: (%s)\n", strerror(-ret));
15884         }
15885
15886         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15887                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15888
15889         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15890                "%-"PRIu64"\n",
15891                stats.ipackets, stats.imissed, stats.ibytes);
15892         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15893         printf("  RX-nombuf:  %-10"PRIu64"\n",
15894                stats.rx_nombuf);
15895         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15896                "%-"PRIu64"\n",
15897                stats.opackets, stats.oerrors, stats.obytes);
15898
15899         printf("  %s############################%s\n",
15900                                nic_stats_border, nic_stats_border);
15901 }
15902
15903 cmdline_parse_inst_t cmd_show_vf_stats = {
15904         .f = cmd_show_vf_stats_parsed,
15905         .data = NULL,
15906         .help_str = "show vf stats <port_id> <vf_id>",
15907         .tokens = {
15908                 (void *)&cmd_show_vf_stats_show,
15909                 (void *)&cmd_show_vf_stats_vf,
15910                 (void *)&cmd_show_vf_stats_stats,
15911                 (void *)&cmd_show_vf_stats_port_id,
15912                 (void *)&cmd_show_vf_stats_vf_id,
15913                 NULL,
15914         },
15915 };
15916
15917 /* clear vf stats */
15918
15919 /* Common result structure for clear vf stats */
15920 struct cmd_clear_vf_stats_result {
15921         cmdline_fixed_string_t clear;
15922         cmdline_fixed_string_t vf;
15923         cmdline_fixed_string_t stats;
15924         portid_t port_id;
15925         uint16_t vf_id;
15926 };
15927
15928 /* Common CLI fields clear vf stats*/
15929 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15930         TOKEN_STRING_INITIALIZER
15931                 (struct cmd_clear_vf_stats_result,
15932                  clear, "clear");
15933 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15934         TOKEN_STRING_INITIALIZER
15935                 (struct cmd_clear_vf_stats_result,
15936                  vf, "vf");
15937 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15938         TOKEN_STRING_INITIALIZER
15939                 (struct cmd_clear_vf_stats_result,
15940                  stats, "stats");
15941 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15942         TOKEN_NUM_INITIALIZER
15943                 (struct cmd_clear_vf_stats_result,
15944                  port_id, UINT16);
15945 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15946         TOKEN_NUM_INITIALIZER
15947                 (struct cmd_clear_vf_stats_result,
15948                  vf_id, UINT16);
15949
15950 static void
15951 cmd_clear_vf_stats_parsed(
15952         void *parsed_result,
15953         __rte_unused struct cmdline *cl,
15954         __rte_unused void *data)
15955 {
15956         struct cmd_clear_vf_stats_result *res = parsed_result;
15957         int ret = -ENOTSUP;
15958
15959         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15960                 return;
15961
15962 #ifdef RTE_NET_I40E
15963         if (ret == -ENOTSUP)
15964                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15965                                                   res->vf_id);
15966 #endif
15967 #ifdef RTE_NET_BNXT
15968         if (ret == -ENOTSUP)
15969                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15970                                                   res->vf_id);
15971 #endif
15972
15973         switch (ret) {
15974         case 0:
15975                 break;
15976         case -EINVAL:
15977                 printf("invalid vf_id %d\n", res->vf_id);
15978                 break;
15979         case -ENODEV:
15980                 printf("invalid port_id %d\n", res->port_id);
15981                 break;
15982         case -ENOTSUP:
15983                 printf("function not implemented\n");
15984                 break;
15985         default:
15986                 printf("programming error: (%s)\n", strerror(-ret));
15987         }
15988 }
15989
15990 cmdline_parse_inst_t cmd_clear_vf_stats = {
15991         .f = cmd_clear_vf_stats_parsed,
15992         .data = NULL,
15993         .help_str = "clear vf stats <port_id> <vf_id>",
15994         .tokens = {
15995                 (void *)&cmd_clear_vf_stats_clear,
15996                 (void *)&cmd_clear_vf_stats_vf,
15997                 (void *)&cmd_clear_vf_stats_stats,
15998                 (void *)&cmd_clear_vf_stats_port_id,
15999                 (void *)&cmd_clear_vf_stats_vf_id,
16000                 NULL,
16001         },
16002 };
16003
16004 /* port config pctype mapping reset */
16005
16006 /* Common result structure for port config pctype mapping reset */
16007 struct cmd_pctype_mapping_reset_result {
16008         cmdline_fixed_string_t port;
16009         cmdline_fixed_string_t config;
16010         portid_t port_id;
16011         cmdline_fixed_string_t pctype;
16012         cmdline_fixed_string_t mapping;
16013         cmdline_fixed_string_t reset;
16014 };
16015
16016 /* Common CLI fields for port config pctype mapping reset*/
16017 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
16018         TOKEN_STRING_INITIALIZER
16019                 (struct cmd_pctype_mapping_reset_result,
16020                  port, "port");
16021 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
16022         TOKEN_STRING_INITIALIZER
16023                 (struct cmd_pctype_mapping_reset_result,
16024                  config, "config");
16025 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
16026         TOKEN_NUM_INITIALIZER
16027                 (struct cmd_pctype_mapping_reset_result,
16028                  port_id, UINT16);
16029 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
16030         TOKEN_STRING_INITIALIZER
16031                 (struct cmd_pctype_mapping_reset_result,
16032                  pctype, "pctype");
16033 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
16034         TOKEN_STRING_INITIALIZER
16035                 (struct cmd_pctype_mapping_reset_result,
16036                  mapping, "mapping");
16037 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
16038         TOKEN_STRING_INITIALIZER
16039                 (struct cmd_pctype_mapping_reset_result,
16040                  reset, "reset");
16041
16042 static void
16043 cmd_pctype_mapping_reset_parsed(
16044         void *parsed_result,
16045         __rte_unused struct cmdline *cl,
16046         __rte_unused void *data)
16047 {
16048         struct cmd_pctype_mapping_reset_result *res = parsed_result;
16049         int ret = -ENOTSUP;
16050
16051         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16052                 return;
16053
16054 #ifdef RTE_NET_I40E
16055         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
16056 #endif
16057
16058         switch (ret) {
16059         case 0:
16060                 break;
16061         case -ENODEV:
16062                 printf("invalid port_id %d\n", res->port_id);
16063                 break;
16064         case -ENOTSUP:
16065                 printf("function not implemented\n");
16066                 break;
16067         default:
16068                 printf("programming error: (%s)\n", strerror(-ret));
16069         }
16070 }
16071
16072 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
16073         .f = cmd_pctype_mapping_reset_parsed,
16074         .data = NULL,
16075         .help_str = "port config <port_id> pctype mapping reset",
16076         .tokens = {
16077                 (void *)&cmd_pctype_mapping_reset_port,
16078                 (void *)&cmd_pctype_mapping_reset_config,
16079                 (void *)&cmd_pctype_mapping_reset_port_id,
16080                 (void *)&cmd_pctype_mapping_reset_pctype,
16081                 (void *)&cmd_pctype_mapping_reset_mapping,
16082                 (void *)&cmd_pctype_mapping_reset_reset,
16083                 NULL,
16084         },
16085 };
16086
16087 /* show port pctype mapping */
16088
16089 /* Common result structure for show port pctype mapping */
16090 struct cmd_pctype_mapping_get_result {
16091         cmdline_fixed_string_t show;
16092         cmdline_fixed_string_t port;
16093         portid_t port_id;
16094         cmdline_fixed_string_t pctype;
16095         cmdline_fixed_string_t mapping;
16096 };
16097
16098 /* Common CLI fields for pctype mapping get */
16099 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
16100         TOKEN_STRING_INITIALIZER
16101                 (struct cmd_pctype_mapping_get_result,
16102                  show, "show");
16103 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
16104         TOKEN_STRING_INITIALIZER
16105                 (struct cmd_pctype_mapping_get_result,
16106                  port, "port");
16107 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
16108         TOKEN_NUM_INITIALIZER
16109                 (struct cmd_pctype_mapping_get_result,
16110                  port_id, UINT16);
16111 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
16112         TOKEN_STRING_INITIALIZER
16113                 (struct cmd_pctype_mapping_get_result,
16114                  pctype, "pctype");
16115 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
16116         TOKEN_STRING_INITIALIZER
16117                 (struct cmd_pctype_mapping_get_result,
16118                  mapping, "mapping");
16119
16120 static void
16121 cmd_pctype_mapping_get_parsed(
16122         void *parsed_result,
16123         __rte_unused struct cmdline *cl,
16124         __rte_unused void *data)
16125 {
16126         struct cmd_pctype_mapping_get_result *res = parsed_result;
16127         int ret = -ENOTSUP;
16128 #ifdef RTE_NET_I40E
16129         struct rte_pmd_i40e_flow_type_mapping
16130                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
16131         int i, j, first_pctype;
16132 #endif
16133
16134         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16135                 return;
16136
16137 #ifdef RTE_NET_I40E
16138         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
16139 #endif
16140
16141         switch (ret) {
16142         case 0:
16143                 break;
16144         case -ENODEV:
16145                 printf("invalid port_id %d\n", res->port_id);
16146                 return;
16147         case -ENOTSUP:
16148                 printf("function not implemented\n");
16149                 return;
16150         default:
16151                 printf("programming error: (%s)\n", strerror(-ret));
16152                 return;
16153         }
16154
16155 #ifdef RTE_NET_I40E
16156         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
16157                 if (mapping[i].pctype != 0ULL) {
16158                         first_pctype = 1;
16159
16160                         printf("pctype: ");
16161                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
16162                                 if (mapping[i].pctype & (1ULL << j)) {
16163                                         printf(first_pctype ?
16164                                                "%02d" : ",%02d", j);
16165                                         first_pctype = 0;
16166                                 }
16167                         }
16168                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
16169                 }
16170         }
16171 #endif
16172 }
16173
16174 cmdline_parse_inst_t cmd_pctype_mapping_get = {
16175         .f = cmd_pctype_mapping_get_parsed,
16176         .data = NULL,
16177         .help_str = "show port <port_id> pctype mapping",
16178         .tokens = {
16179                 (void *)&cmd_pctype_mapping_get_show,
16180                 (void *)&cmd_pctype_mapping_get_port,
16181                 (void *)&cmd_pctype_mapping_get_port_id,
16182                 (void *)&cmd_pctype_mapping_get_pctype,
16183                 (void *)&cmd_pctype_mapping_get_mapping,
16184                 NULL,
16185         },
16186 };
16187
16188 /* port config pctype mapping update */
16189
16190 /* Common result structure for port config pctype mapping update */
16191 struct cmd_pctype_mapping_update_result {
16192         cmdline_fixed_string_t port;
16193         cmdline_fixed_string_t config;
16194         portid_t port_id;
16195         cmdline_fixed_string_t pctype;
16196         cmdline_fixed_string_t mapping;
16197         cmdline_fixed_string_t update;
16198         cmdline_fixed_string_t pctype_list;
16199         uint16_t flow_type;
16200 };
16201
16202 /* Common CLI fields for pctype mapping update*/
16203 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
16204         TOKEN_STRING_INITIALIZER
16205                 (struct cmd_pctype_mapping_update_result,
16206                  port, "port");
16207 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
16208         TOKEN_STRING_INITIALIZER
16209                 (struct cmd_pctype_mapping_update_result,
16210                  config, "config");
16211 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
16212         TOKEN_NUM_INITIALIZER
16213                 (struct cmd_pctype_mapping_update_result,
16214                  port_id, UINT16);
16215 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
16216         TOKEN_STRING_INITIALIZER
16217                 (struct cmd_pctype_mapping_update_result,
16218                  pctype, "pctype");
16219 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
16220         TOKEN_STRING_INITIALIZER
16221                 (struct cmd_pctype_mapping_update_result,
16222                  mapping, "mapping");
16223 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
16224         TOKEN_STRING_INITIALIZER
16225                 (struct cmd_pctype_mapping_update_result,
16226                  update, "update");
16227 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
16228         TOKEN_STRING_INITIALIZER
16229                 (struct cmd_pctype_mapping_update_result,
16230                  pctype_list, NULL);
16231 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
16232         TOKEN_NUM_INITIALIZER
16233                 (struct cmd_pctype_mapping_update_result,
16234                  flow_type, UINT16);
16235
16236 static void
16237 cmd_pctype_mapping_update_parsed(
16238         void *parsed_result,
16239         __rte_unused struct cmdline *cl,
16240         __rte_unused void *data)
16241 {
16242         struct cmd_pctype_mapping_update_result *res = parsed_result;
16243         int ret = -ENOTSUP;
16244 #ifdef RTE_NET_I40E
16245         struct rte_pmd_i40e_flow_type_mapping mapping;
16246         unsigned int i;
16247         unsigned int nb_item;
16248         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16249 #endif
16250
16251         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16252                 return;
16253
16254 #ifdef RTE_NET_I40E
16255         nb_item = parse_item_list(res->pctype_list, "pctypes",
16256                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16257         mapping.flow_type = res->flow_type;
16258         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16259                 mapping.pctype |= (1ULL << pctype_list[i]);
16260         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16261                                                 &mapping,
16262                                                 1,
16263                                                 0);
16264 #endif
16265
16266         switch (ret) {
16267         case 0:
16268                 break;
16269         case -EINVAL:
16270                 printf("invalid pctype or flow type\n");
16271                 break;
16272         case -ENODEV:
16273                 printf("invalid port_id %d\n", res->port_id);
16274                 break;
16275         case -ENOTSUP:
16276                 printf("function not implemented\n");
16277                 break;
16278         default:
16279                 printf("programming error: (%s)\n", strerror(-ret));
16280         }
16281 }
16282
16283 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16284         .f = cmd_pctype_mapping_update_parsed,
16285         .data = NULL,
16286         .help_str = "port config <port_id> pctype mapping update"
16287         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16288         .tokens = {
16289                 (void *)&cmd_pctype_mapping_update_port,
16290                 (void *)&cmd_pctype_mapping_update_config,
16291                 (void *)&cmd_pctype_mapping_update_port_id,
16292                 (void *)&cmd_pctype_mapping_update_pctype,
16293                 (void *)&cmd_pctype_mapping_update_mapping,
16294                 (void *)&cmd_pctype_mapping_update_update,
16295                 (void *)&cmd_pctype_mapping_update_pc_type,
16296                 (void *)&cmd_pctype_mapping_update_flow_type,
16297                 NULL,
16298         },
16299 };
16300
16301 /* ptype mapping get */
16302
16303 /* Common result structure for ptype mapping get */
16304 struct cmd_ptype_mapping_get_result {
16305         cmdline_fixed_string_t ptype;
16306         cmdline_fixed_string_t mapping;
16307         cmdline_fixed_string_t get;
16308         portid_t port_id;
16309         uint8_t valid_only;
16310 };
16311
16312 /* Common CLI fields for ptype mapping get */
16313 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16314         TOKEN_STRING_INITIALIZER
16315                 (struct cmd_ptype_mapping_get_result,
16316                  ptype, "ptype");
16317 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16318         TOKEN_STRING_INITIALIZER
16319                 (struct cmd_ptype_mapping_get_result,
16320                  mapping, "mapping");
16321 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16322         TOKEN_STRING_INITIALIZER
16323                 (struct cmd_ptype_mapping_get_result,
16324                  get, "get");
16325 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16326         TOKEN_NUM_INITIALIZER
16327                 (struct cmd_ptype_mapping_get_result,
16328                  port_id, UINT16);
16329 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16330         TOKEN_NUM_INITIALIZER
16331                 (struct cmd_ptype_mapping_get_result,
16332                  valid_only, UINT8);
16333
16334 static void
16335 cmd_ptype_mapping_get_parsed(
16336         void *parsed_result,
16337         __rte_unused struct cmdline *cl,
16338         __rte_unused void *data)
16339 {
16340         struct cmd_ptype_mapping_get_result *res = parsed_result;
16341         int ret = -ENOTSUP;
16342 #ifdef RTE_NET_I40E
16343         int max_ptype_num = 256;
16344         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16345         uint16_t count;
16346         int i;
16347 #endif
16348
16349         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16350                 return;
16351
16352 #ifdef RTE_NET_I40E
16353         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16354                                         mapping,
16355                                         max_ptype_num,
16356                                         &count,
16357                                         res->valid_only);
16358 #endif
16359
16360         switch (ret) {
16361         case 0:
16362                 break;
16363         case -ENODEV:
16364                 printf("invalid port_id %d\n", res->port_id);
16365                 break;
16366         case -ENOTSUP:
16367                 printf("function not implemented\n");
16368                 break;
16369         default:
16370                 printf("programming error: (%s)\n", strerror(-ret));
16371         }
16372
16373 #ifdef RTE_NET_I40E
16374         if (!ret) {
16375                 for (i = 0; i < count; i++)
16376                         printf("%3d\t0x%08x\n",
16377                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16378         }
16379 #endif
16380 }
16381
16382 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16383         .f = cmd_ptype_mapping_get_parsed,
16384         .data = NULL,
16385         .help_str = "ptype mapping get <port_id> <valid_only>",
16386         .tokens = {
16387                 (void *)&cmd_ptype_mapping_get_ptype,
16388                 (void *)&cmd_ptype_mapping_get_mapping,
16389                 (void *)&cmd_ptype_mapping_get_get,
16390                 (void *)&cmd_ptype_mapping_get_port_id,
16391                 (void *)&cmd_ptype_mapping_get_valid_only,
16392                 NULL,
16393         },
16394 };
16395
16396 /* ptype mapping replace */
16397
16398 /* Common result structure for ptype mapping replace */
16399 struct cmd_ptype_mapping_replace_result {
16400         cmdline_fixed_string_t ptype;
16401         cmdline_fixed_string_t mapping;
16402         cmdline_fixed_string_t replace;
16403         portid_t port_id;
16404         uint32_t target;
16405         uint8_t mask;
16406         uint32_t pkt_type;
16407 };
16408
16409 /* Common CLI fields for ptype mapping replace */
16410 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16411         TOKEN_STRING_INITIALIZER
16412                 (struct cmd_ptype_mapping_replace_result,
16413                  ptype, "ptype");
16414 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16415         TOKEN_STRING_INITIALIZER
16416                 (struct cmd_ptype_mapping_replace_result,
16417                  mapping, "mapping");
16418 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16419         TOKEN_STRING_INITIALIZER
16420                 (struct cmd_ptype_mapping_replace_result,
16421                  replace, "replace");
16422 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16423         TOKEN_NUM_INITIALIZER
16424                 (struct cmd_ptype_mapping_replace_result,
16425                  port_id, UINT16);
16426 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16427         TOKEN_NUM_INITIALIZER
16428                 (struct cmd_ptype_mapping_replace_result,
16429                  target, UINT32);
16430 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16431         TOKEN_NUM_INITIALIZER
16432                 (struct cmd_ptype_mapping_replace_result,
16433                  mask, UINT8);
16434 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16435         TOKEN_NUM_INITIALIZER
16436                 (struct cmd_ptype_mapping_replace_result,
16437                  pkt_type, UINT32);
16438
16439 static void
16440 cmd_ptype_mapping_replace_parsed(
16441         void *parsed_result,
16442         __rte_unused struct cmdline *cl,
16443         __rte_unused void *data)
16444 {
16445         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16446         int ret = -ENOTSUP;
16447
16448         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16449                 return;
16450
16451 #ifdef RTE_NET_I40E
16452         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16453                                         res->target,
16454                                         res->mask,
16455                                         res->pkt_type);
16456 #endif
16457
16458         switch (ret) {
16459         case 0:
16460                 break;
16461         case -EINVAL:
16462                 printf("invalid ptype 0x%8x or 0x%8x\n",
16463                                 res->target, res->pkt_type);
16464                 break;
16465         case -ENODEV:
16466                 printf("invalid port_id %d\n", res->port_id);
16467                 break;
16468         case -ENOTSUP:
16469                 printf("function not implemented\n");
16470                 break;
16471         default:
16472                 printf("programming error: (%s)\n", strerror(-ret));
16473         }
16474 }
16475
16476 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16477         .f = cmd_ptype_mapping_replace_parsed,
16478         .data = NULL,
16479         .help_str =
16480                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16481         .tokens = {
16482                 (void *)&cmd_ptype_mapping_replace_ptype,
16483                 (void *)&cmd_ptype_mapping_replace_mapping,
16484                 (void *)&cmd_ptype_mapping_replace_replace,
16485                 (void *)&cmd_ptype_mapping_replace_port_id,
16486                 (void *)&cmd_ptype_mapping_replace_target,
16487                 (void *)&cmd_ptype_mapping_replace_mask,
16488                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16489                 NULL,
16490         },
16491 };
16492
16493 /* ptype mapping reset */
16494
16495 /* Common result structure for ptype mapping reset */
16496 struct cmd_ptype_mapping_reset_result {
16497         cmdline_fixed_string_t ptype;
16498         cmdline_fixed_string_t mapping;
16499         cmdline_fixed_string_t reset;
16500         portid_t port_id;
16501 };
16502
16503 /* Common CLI fields for ptype mapping reset*/
16504 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16505         TOKEN_STRING_INITIALIZER
16506                 (struct cmd_ptype_mapping_reset_result,
16507                  ptype, "ptype");
16508 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16509         TOKEN_STRING_INITIALIZER
16510                 (struct cmd_ptype_mapping_reset_result,
16511                  mapping, "mapping");
16512 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16513         TOKEN_STRING_INITIALIZER
16514                 (struct cmd_ptype_mapping_reset_result,
16515                  reset, "reset");
16516 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16517         TOKEN_NUM_INITIALIZER
16518                 (struct cmd_ptype_mapping_reset_result,
16519                  port_id, UINT16);
16520
16521 static void
16522 cmd_ptype_mapping_reset_parsed(
16523         void *parsed_result,
16524         __rte_unused struct cmdline *cl,
16525         __rte_unused void *data)
16526 {
16527         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16528         int ret = -ENOTSUP;
16529
16530         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16531                 return;
16532
16533 #ifdef RTE_NET_I40E
16534         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16535 #endif
16536
16537         switch (ret) {
16538         case 0:
16539                 break;
16540         case -ENODEV:
16541                 printf("invalid port_id %d\n", res->port_id);
16542                 break;
16543         case -ENOTSUP:
16544                 printf("function not implemented\n");
16545                 break;
16546         default:
16547                 printf("programming error: (%s)\n", strerror(-ret));
16548         }
16549 }
16550
16551 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16552         .f = cmd_ptype_mapping_reset_parsed,
16553         .data = NULL,
16554         .help_str = "ptype mapping reset <port_id>",
16555         .tokens = {
16556                 (void *)&cmd_ptype_mapping_reset_ptype,
16557                 (void *)&cmd_ptype_mapping_reset_mapping,
16558                 (void *)&cmd_ptype_mapping_reset_reset,
16559                 (void *)&cmd_ptype_mapping_reset_port_id,
16560                 NULL,
16561         },
16562 };
16563
16564 /* ptype mapping update */
16565
16566 /* Common result structure for ptype mapping update */
16567 struct cmd_ptype_mapping_update_result {
16568         cmdline_fixed_string_t ptype;
16569         cmdline_fixed_string_t mapping;
16570         cmdline_fixed_string_t reset;
16571         portid_t port_id;
16572         uint8_t hw_ptype;
16573         uint32_t sw_ptype;
16574 };
16575
16576 /* Common CLI fields for ptype mapping update*/
16577 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16578         TOKEN_STRING_INITIALIZER
16579                 (struct cmd_ptype_mapping_update_result,
16580                  ptype, "ptype");
16581 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16582         TOKEN_STRING_INITIALIZER
16583                 (struct cmd_ptype_mapping_update_result,
16584                  mapping, "mapping");
16585 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16586         TOKEN_STRING_INITIALIZER
16587                 (struct cmd_ptype_mapping_update_result,
16588                  reset, "update");
16589 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16590         TOKEN_NUM_INITIALIZER
16591                 (struct cmd_ptype_mapping_update_result,
16592                  port_id, UINT16);
16593 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16594         TOKEN_NUM_INITIALIZER
16595                 (struct cmd_ptype_mapping_update_result,
16596                  hw_ptype, UINT8);
16597 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16598         TOKEN_NUM_INITIALIZER
16599                 (struct cmd_ptype_mapping_update_result,
16600                  sw_ptype, UINT32);
16601
16602 static void
16603 cmd_ptype_mapping_update_parsed(
16604         void *parsed_result,
16605         __rte_unused struct cmdline *cl,
16606         __rte_unused void *data)
16607 {
16608         struct cmd_ptype_mapping_update_result *res = parsed_result;
16609         int ret = -ENOTSUP;
16610 #ifdef RTE_NET_I40E
16611         struct rte_pmd_i40e_ptype_mapping mapping;
16612 #endif
16613         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16614                 return;
16615
16616 #ifdef RTE_NET_I40E
16617         mapping.hw_ptype = res->hw_ptype;
16618         mapping.sw_ptype = res->sw_ptype;
16619         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16620                                                 &mapping,
16621                                                 1,
16622                                                 0);
16623 #endif
16624
16625         switch (ret) {
16626         case 0:
16627                 break;
16628         case -EINVAL:
16629                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16630                 break;
16631         case -ENODEV:
16632                 printf("invalid port_id %d\n", res->port_id);
16633                 break;
16634         case -ENOTSUP:
16635                 printf("function not implemented\n");
16636                 break;
16637         default:
16638                 printf("programming error: (%s)\n", strerror(-ret));
16639         }
16640 }
16641
16642 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16643         .f = cmd_ptype_mapping_update_parsed,
16644         .data = NULL,
16645         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16646         .tokens = {
16647                 (void *)&cmd_ptype_mapping_update_ptype,
16648                 (void *)&cmd_ptype_mapping_update_mapping,
16649                 (void *)&cmd_ptype_mapping_update_update,
16650                 (void *)&cmd_ptype_mapping_update_port_id,
16651                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16652                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16653                 NULL,
16654         },
16655 };
16656
16657 /* Common result structure for file commands */
16658 struct cmd_cmdfile_result {
16659         cmdline_fixed_string_t load;
16660         cmdline_fixed_string_t filename;
16661 };
16662
16663 /* Common CLI fields for file commands */
16664 cmdline_parse_token_string_t cmd_load_cmdfile =
16665         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16666 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16667         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16668
16669 static void
16670 cmd_load_from_file_parsed(
16671         void *parsed_result,
16672         __rte_unused struct cmdline *cl,
16673         __rte_unused void *data)
16674 {
16675         struct cmd_cmdfile_result *res = parsed_result;
16676
16677         cmdline_read_from_file(res->filename);
16678 }
16679
16680 cmdline_parse_inst_t cmd_load_from_file = {
16681         .f = cmd_load_from_file_parsed,
16682         .data = NULL,
16683         .help_str = "load <filename>",
16684         .tokens = {
16685                 (void *)&cmd_load_cmdfile,
16686                 (void *)&cmd_load_cmdfile_filename,
16687                 NULL,
16688         },
16689 };
16690
16691 /* Get Rx offloads capabilities */
16692 struct cmd_rx_offload_get_capa_result {
16693         cmdline_fixed_string_t show;
16694         cmdline_fixed_string_t port;
16695         portid_t port_id;
16696         cmdline_fixed_string_t rx_offload;
16697         cmdline_fixed_string_t capabilities;
16698 };
16699
16700 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16701         TOKEN_STRING_INITIALIZER
16702                 (struct cmd_rx_offload_get_capa_result,
16703                  show, "show");
16704 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16705         TOKEN_STRING_INITIALIZER
16706                 (struct cmd_rx_offload_get_capa_result,
16707                  port, "port");
16708 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16709         TOKEN_NUM_INITIALIZER
16710                 (struct cmd_rx_offload_get_capa_result,
16711                  port_id, UINT16);
16712 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16713         TOKEN_STRING_INITIALIZER
16714                 (struct cmd_rx_offload_get_capa_result,
16715                  rx_offload, "rx_offload");
16716 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16717         TOKEN_STRING_INITIALIZER
16718                 (struct cmd_rx_offload_get_capa_result,
16719                  capabilities, "capabilities");
16720
16721 static void
16722 print_rx_offloads(uint64_t offloads)
16723 {
16724         uint64_t single_offload;
16725         int begin;
16726         int end;
16727         int bit;
16728
16729         if (offloads == 0)
16730                 return;
16731
16732         begin = __builtin_ctzll(offloads);
16733         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16734
16735         single_offload = 1ULL << begin;
16736         for (bit = begin; bit < end; bit++) {
16737                 if (offloads & single_offload)
16738                         printf(" %s",
16739                                rte_eth_dev_rx_offload_name(single_offload));
16740                 single_offload <<= 1;
16741         }
16742 }
16743
16744 static void
16745 cmd_rx_offload_get_capa_parsed(
16746         void *parsed_result,
16747         __rte_unused struct cmdline *cl,
16748         __rte_unused void *data)
16749 {
16750         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16751         struct rte_eth_dev_info dev_info;
16752         portid_t port_id = res->port_id;
16753         uint64_t queue_offloads;
16754         uint64_t port_offloads;
16755         int ret;
16756
16757         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16758         if (ret != 0)
16759                 return;
16760
16761         queue_offloads = dev_info.rx_queue_offload_capa;
16762         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16763
16764         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16765         printf("  Per Queue :");
16766         print_rx_offloads(queue_offloads);
16767
16768         printf("\n");
16769         printf("  Per Port  :");
16770         print_rx_offloads(port_offloads);
16771         printf("\n\n");
16772 }
16773
16774 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16775         .f = cmd_rx_offload_get_capa_parsed,
16776         .data = NULL,
16777         .help_str = "show port <port_id> rx_offload capabilities",
16778         .tokens = {
16779                 (void *)&cmd_rx_offload_get_capa_show,
16780                 (void *)&cmd_rx_offload_get_capa_port,
16781                 (void *)&cmd_rx_offload_get_capa_port_id,
16782                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16783                 (void *)&cmd_rx_offload_get_capa_capabilities,
16784                 NULL,
16785         }
16786 };
16787
16788 /* Get Rx offloads configuration */
16789 struct cmd_rx_offload_get_configuration_result {
16790         cmdline_fixed_string_t show;
16791         cmdline_fixed_string_t port;
16792         portid_t port_id;
16793         cmdline_fixed_string_t rx_offload;
16794         cmdline_fixed_string_t configuration;
16795 };
16796
16797 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16798         TOKEN_STRING_INITIALIZER
16799                 (struct cmd_rx_offload_get_configuration_result,
16800                  show, "show");
16801 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16802         TOKEN_STRING_INITIALIZER
16803                 (struct cmd_rx_offload_get_configuration_result,
16804                  port, "port");
16805 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16806         TOKEN_NUM_INITIALIZER
16807                 (struct cmd_rx_offload_get_configuration_result,
16808                  port_id, UINT16);
16809 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16810         TOKEN_STRING_INITIALIZER
16811                 (struct cmd_rx_offload_get_configuration_result,
16812                  rx_offload, "rx_offload");
16813 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16814         TOKEN_STRING_INITIALIZER
16815                 (struct cmd_rx_offload_get_configuration_result,
16816                  configuration, "configuration");
16817
16818 static void
16819 cmd_rx_offload_get_configuration_parsed(
16820         void *parsed_result,
16821         __rte_unused struct cmdline *cl,
16822         __rte_unused void *data)
16823 {
16824         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16825         struct rte_eth_dev_info dev_info;
16826         portid_t port_id = res->port_id;
16827         struct rte_port *port = &ports[port_id];
16828         uint64_t port_offloads;
16829         uint64_t queue_offloads;
16830         uint16_t nb_rx_queues;
16831         int q;
16832         int ret;
16833
16834         printf("Rx Offloading Configuration of port %d :\n", port_id);
16835
16836         port_offloads = port->dev_conf.rxmode.offloads;
16837         printf("  Port :");
16838         print_rx_offloads(port_offloads);
16839         printf("\n");
16840
16841         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16842         if (ret != 0)
16843                 return;
16844
16845         nb_rx_queues = dev_info.nb_rx_queues;
16846         for (q = 0; q < nb_rx_queues; q++) {
16847                 queue_offloads = port->rx_conf[q].offloads;
16848                 printf("  Queue[%2d] :", q);
16849                 print_rx_offloads(queue_offloads);
16850                 printf("\n");
16851         }
16852         printf("\n");
16853 }
16854
16855 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16856         .f = cmd_rx_offload_get_configuration_parsed,
16857         .data = NULL,
16858         .help_str = "show port <port_id> rx_offload configuration",
16859         .tokens = {
16860                 (void *)&cmd_rx_offload_get_configuration_show,
16861                 (void *)&cmd_rx_offload_get_configuration_port,
16862                 (void *)&cmd_rx_offload_get_configuration_port_id,
16863                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16864                 (void *)&cmd_rx_offload_get_configuration_configuration,
16865                 NULL,
16866         }
16867 };
16868
16869 /* Enable/Disable a per port offloading */
16870 struct cmd_config_per_port_rx_offload_result {
16871         cmdline_fixed_string_t port;
16872         cmdline_fixed_string_t config;
16873         portid_t port_id;
16874         cmdline_fixed_string_t rx_offload;
16875         cmdline_fixed_string_t offload;
16876         cmdline_fixed_string_t on_off;
16877 };
16878
16879 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16880         TOKEN_STRING_INITIALIZER
16881                 (struct cmd_config_per_port_rx_offload_result,
16882                  port, "port");
16883 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16884         TOKEN_STRING_INITIALIZER
16885                 (struct cmd_config_per_port_rx_offload_result,
16886                  config, "config");
16887 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16888         TOKEN_NUM_INITIALIZER
16889                 (struct cmd_config_per_port_rx_offload_result,
16890                  port_id, UINT16);
16891 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16892         TOKEN_STRING_INITIALIZER
16893                 (struct cmd_config_per_port_rx_offload_result,
16894                  rx_offload, "rx_offload");
16895 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16896         TOKEN_STRING_INITIALIZER
16897                 (struct cmd_config_per_port_rx_offload_result,
16898                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16899                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16900                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16901                            "scatter#buffer_split#timestamp#security#"
16902                            "keep_crc#rss_hash");
16903 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16904         TOKEN_STRING_INITIALIZER
16905                 (struct cmd_config_per_port_rx_offload_result,
16906                  on_off, "on#off");
16907
16908 static uint64_t
16909 search_rx_offload(const char *name)
16910 {
16911         uint64_t single_offload;
16912         const char *single_name;
16913         int found = 0;
16914         unsigned int bit;
16915
16916         single_offload = 1;
16917         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16918                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16919                 if (!strcasecmp(single_name, name)) {
16920                         found = 1;
16921                         break;
16922                 }
16923                 single_offload <<= 1;
16924         }
16925
16926         if (found)
16927                 return single_offload;
16928
16929         return 0;
16930 }
16931
16932 static void
16933 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16934                                 __rte_unused struct cmdline *cl,
16935                                 __rte_unused void *data)
16936 {
16937         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16938         portid_t port_id = res->port_id;
16939         struct rte_eth_dev_info dev_info;
16940         struct rte_port *port = &ports[port_id];
16941         uint64_t single_offload;
16942         uint16_t nb_rx_queues;
16943         int q;
16944         int ret;
16945
16946         if (port->port_status != RTE_PORT_STOPPED) {
16947                 printf("Error: Can't config offload when Port %d "
16948                        "is not stopped\n", port_id);
16949                 return;
16950         }
16951
16952         single_offload = search_rx_offload(res->offload);
16953         if (single_offload == 0) {
16954                 printf("Unknown offload name: %s\n", res->offload);
16955                 return;
16956         }
16957
16958         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16959         if (ret != 0)
16960                 return;
16961
16962         nb_rx_queues = dev_info.nb_rx_queues;
16963         if (!strcmp(res->on_off, "on")) {
16964                 port->dev_conf.rxmode.offloads |= single_offload;
16965                 for (q = 0; q < nb_rx_queues; q++)
16966                         port->rx_conf[q].offloads |= single_offload;
16967         } else {
16968                 port->dev_conf.rxmode.offloads &= ~single_offload;
16969                 for (q = 0; q < nb_rx_queues; q++)
16970                         port->rx_conf[q].offloads &= ~single_offload;
16971         }
16972
16973         cmd_reconfig_device_queue(port_id, 1, 1);
16974 }
16975
16976 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16977         .f = cmd_config_per_port_rx_offload_parsed,
16978         .data = NULL,
16979         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16980                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16981                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16982                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16983                     "keep_crc|rss_hash on|off",
16984         .tokens = {
16985                 (void *)&cmd_config_per_port_rx_offload_result_port,
16986                 (void *)&cmd_config_per_port_rx_offload_result_config,
16987                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16988                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16989                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16990                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16991                 NULL,
16992         }
16993 };
16994
16995 /* Enable/Disable a per queue offloading */
16996 struct cmd_config_per_queue_rx_offload_result {
16997         cmdline_fixed_string_t port;
16998         portid_t port_id;
16999         cmdline_fixed_string_t rxq;
17000         uint16_t queue_id;
17001         cmdline_fixed_string_t rx_offload;
17002         cmdline_fixed_string_t offload;
17003         cmdline_fixed_string_t on_off;
17004 };
17005
17006 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
17007         TOKEN_STRING_INITIALIZER
17008                 (struct cmd_config_per_queue_rx_offload_result,
17009                  port, "port");
17010 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
17011         TOKEN_NUM_INITIALIZER
17012                 (struct cmd_config_per_queue_rx_offload_result,
17013                  port_id, UINT16);
17014 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
17015         TOKEN_STRING_INITIALIZER
17016                 (struct cmd_config_per_queue_rx_offload_result,
17017                  rxq, "rxq");
17018 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
17019         TOKEN_NUM_INITIALIZER
17020                 (struct cmd_config_per_queue_rx_offload_result,
17021                  queue_id, UINT16);
17022 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
17023         TOKEN_STRING_INITIALIZER
17024                 (struct cmd_config_per_queue_rx_offload_result,
17025                  rx_offload, "rx_offload");
17026 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
17027         TOKEN_STRING_INITIALIZER
17028                 (struct cmd_config_per_queue_rx_offload_result,
17029                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17030                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17031                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17032                            "scatter#buffer_split#timestamp#security#keep_crc");
17033 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
17034         TOKEN_STRING_INITIALIZER
17035                 (struct cmd_config_per_queue_rx_offload_result,
17036                  on_off, "on#off");
17037
17038 static void
17039 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
17040                                 __rte_unused struct cmdline *cl,
17041                                 __rte_unused void *data)
17042 {
17043         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
17044         struct rte_eth_dev_info dev_info;
17045         portid_t port_id = res->port_id;
17046         uint16_t queue_id = res->queue_id;
17047         struct rte_port *port = &ports[port_id];
17048         uint64_t single_offload;
17049         int ret;
17050
17051         if (port->port_status != RTE_PORT_STOPPED) {
17052                 printf("Error: Can't config offload when Port %d "
17053                        "is not stopped\n", port_id);
17054                 return;
17055         }
17056
17057         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17058         if (ret != 0)
17059                 return;
17060
17061         if (queue_id >= dev_info.nb_rx_queues) {
17062                 printf("Error: input queue_id should be 0 ... "
17063                        "%d\n", dev_info.nb_rx_queues - 1);
17064                 return;
17065         }
17066
17067         single_offload = search_rx_offload(res->offload);
17068         if (single_offload == 0) {
17069                 printf("Unknown offload name: %s\n", res->offload);
17070                 return;
17071         }
17072
17073         if (!strcmp(res->on_off, "on"))
17074                 port->rx_conf[queue_id].offloads |= single_offload;
17075         else
17076                 port->rx_conf[queue_id].offloads &= ~single_offload;
17077
17078         cmd_reconfig_device_queue(port_id, 1, 1);
17079 }
17080
17081 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
17082         .f = cmd_config_per_queue_rx_offload_parsed,
17083         .data = NULL,
17084         .help_str = "port <port_id> rxq <queue_id> rx_offload "
17085                     "vlan_strip|ipv4_cksum|"
17086                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17087                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17088                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
17089                     "keep_crc on|off",
17090         .tokens = {
17091                 (void *)&cmd_config_per_queue_rx_offload_result_port,
17092                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
17093                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
17094                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
17095                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
17096                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
17097                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
17098                 NULL,
17099         }
17100 };
17101
17102 /* Get Tx offloads capabilities */
17103 struct cmd_tx_offload_get_capa_result {
17104         cmdline_fixed_string_t show;
17105         cmdline_fixed_string_t port;
17106         portid_t port_id;
17107         cmdline_fixed_string_t tx_offload;
17108         cmdline_fixed_string_t capabilities;
17109 };
17110
17111 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
17112         TOKEN_STRING_INITIALIZER
17113                 (struct cmd_tx_offload_get_capa_result,
17114                  show, "show");
17115 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
17116         TOKEN_STRING_INITIALIZER
17117                 (struct cmd_tx_offload_get_capa_result,
17118                  port, "port");
17119 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
17120         TOKEN_NUM_INITIALIZER
17121                 (struct cmd_tx_offload_get_capa_result,
17122                  port_id, UINT16);
17123 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
17124         TOKEN_STRING_INITIALIZER
17125                 (struct cmd_tx_offload_get_capa_result,
17126                  tx_offload, "tx_offload");
17127 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
17128         TOKEN_STRING_INITIALIZER
17129                 (struct cmd_tx_offload_get_capa_result,
17130                  capabilities, "capabilities");
17131
17132 static void
17133 print_tx_offloads(uint64_t offloads)
17134 {
17135         uint64_t single_offload;
17136         int begin;
17137         int end;
17138         int bit;
17139
17140         if (offloads == 0)
17141                 return;
17142
17143         begin = __builtin_ctzll(offloads);
17144         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17145
17146         single_offload = 1ULL << begin;
17147         for (bit = begin; bit < end; bit++) {
17148                 if (offloads & single_offload)
17149                         printf(" %s",
17150                                rte_eth_dev_tx_offload_name(single_offload));
17151                 single_offload <<= 1;
17152         }
17153 }
17154
17155 static void
17156 cmd_tx_offload_get_capa_parsed(
17157         void *parsed_result,
17158         __rte_unused struct cmdline *cl,
17159         __rte_unused void *data)
17160 {
17161         struct cmd_tx_offload_get_capa_result *res = parsed_result;
17162         struct rte_eth_dev_info dev_info;
17163         portid_t port_id = res->port_id;
17164         uint64_t queue_offloads;
17165         uint64_t port_offloads;
17166         int ret;
17167
17168         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17169         if (ret != 0)
17170                 return;
17171
17172         queue_offloads = dev_info.tx_queue_offload_capa;
17173         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
17174
17175         printf("Tx Offloading Capabilities of port %d :\n", port_id);
17176         printf("  Per Queue :");
17177         print_tx_offloads(queue_offloads);
17178
17179         printf("\n");
17180         printf("  Per Port  :");
17181         print_tx_offloads(port_offloads);
17182         printf("\n\n");
17183 }
17184
17185 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
17186         .f = cmd_tx_offload_get_capa_parsed,
17187         .data = NULL,
17188         .help_str = "show port <port_id> tx_offload capabilities",
17189         .tokens = {
17190                 (void *)&cmd_tx_offload_get_capa_show,
17191                 (void *)&cmd_tx_offload_get_capa_port,
17192                 (void *)&cmd_tx_offload_get_capa_port_id,
17193                 (void *)&cmd_tx_offload_get_capa_tx_offload,
17194                 (void *)&cmd_tx_offload_get_capa_capabilities,
17195                 NULL,
17196         }
17197 };
17198
17199 /* Get Tx offloads configuration */
17200 struct cmd_tx_offload_get_configuration_result {
17201         cmdline_fixed_string_t show;
17202         cmdline_fixed_string_t port;
17203         portid_t port_id;
17204         cmdline_fixed_string_t tx_offload;
17205         cmdline_fixed_string_t configuration;
17206 };
17207
17208 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
17209         TOKEN_STRING_INITIALIZER
17210                 (struct cmd_tx_offload_get_configuration_result,
17211                  show, "show");
17212 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
17213         TOKEN_STRING_INITIALIZER
17214                 (struct cmd_tx_offload_get_configuration_result,
17215                  port, "port");
17216 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
17217         TOKEN_NUM_INITIALIZER
17218                 (struct cmd_tx_offload_get_configuration_result,
17219                  port_id, UINT16);
17220 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
17221         TOKEN_STRING_INITIALIZER
17222                 (struct cmd_tx_offload_get_configuration_result,
17223                  tx_offload, "tx_offload");
17224 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
17225         TOKEN_STRING_INITIALIZER
17226                 (struct cmd_tx_offload_get_configuration_result,
17227                  configuration, "configuration");
17228
17229 static void
17230 cmd_tx_offload_get_configuration_parsed(
17231         void *parsed_result,
17232         __rte_unused struct cmdline *cl,
17233         __rte_unused void *data)
17234 {
17235         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
17236         struct rte_eth_dev_info dev_info;
17237         portid_t port_id = res->port_id;
17238         struct rte_port *port = &ports[port_id];
17239         uint64_t port_offloads;
17240         uint64_t queue_offloads;
17241         uint16_t nb_tx_queues;
17242         int q;
17243         int ret;
17244
17245         printf("Tx Offloading Configuration of port %d :\n", port_id);
17246
17247         port_offloads = port->dev_conf.txmode.offloads;
17248         printf("  Port :");
17249         print_tx_offloads(port_offloads);
17250         printf("\n");
17251
17252         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17253         if (ret != 0)
17254                 return;
17255
17256         nb_tx_queues = dev_info.nb_tx_queues;
17257         for (q = 0; q < nb_tx_queues; q++) {
17258                 queue_offloads = port->tx_conf[q].offloads;
17259                 printf("  Queue[%2d] :", q);
17260                 print_tx_offloads(queue_offloads);
17261                 printf("\n");
17262         }
17263         printf("\n");
17264 }
17265
17266 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17267         .f = cmd_tx_offload_get_configuration_parsed,
17268         .data = NULL,
17269         .help_str = "show port <port_id> tx_offload configuration",
17270         .tokens = {
17271                 (void *)&cmd_tx_offload_get_configuration_show,
17272                 (void *)&cmd_tx_offload_get_configuration_port,
17273                 (void *)&cmd_tx_offload_get_configuration_port_id,
17274                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17275                 (void *)&cmd_tx_offload_get_configuration_configuration,
17276                 NULL,
17277         }
17278 };
17279
17280 /* Enable/Disable a per port offloading */
17281 struct cmd_config_per_port_tx_offload_result {
17282         cmdline_fixed_string_t port;
17283         cmdline_fixed_string_t config;
17284         portid_t port_id;
17285         cmdline_fixed_string_t tx_offload;
17286         cmdline_fixed_string_t offload;
17287         cmdline_fixed_string_t on_off;
17288 };
17289
17290 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17291         TOKEN_STRING_INITIALIZER
17292                 (struct cmd_config_per_port_tx_offload_result,
17293                  port, "port");
17294 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17295         TOKEN_STRING_INITIALIZER
17296                 (struct cmd_config_per_port_tx_offload_result,
17297                  config, "config");
17298 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17299         TOKEN_NUM_INITIALIZER
17300                 (struct cmd_config_per_port_tx_offload_result,
17301                  port_id, UINT16);
17302 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17303         TOKEN_STRING_INITIALIZER
17304                 (struct cmd_config_per_port_tx_offload_result,
17305                  tx_offload, "tx_offload");
17306 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17307         TOKEN_STRING_INITIALIZER
17308                 (struct cmd_config_per_port_tx_offload_result,
17309                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17310                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17311                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17312                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17313                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
17314                           "send_on_timestamp");
17315 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17316         TOKEN_STRING_INITIALIZER
17317                 (struct cmd_config_per_port_tx_offload_result,
17318                  on_off, "on#off");
17319
17320 static uint64_t
17321 search_tx_offload(const char *name)
17322 {
17323         uint64_t single_offload;
17324         const char *single_name;
17325         int found = 0;
17326         unsigned int bit;
17327
17328         single_offload = 1;
17329         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17330                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17331                 if (single_name == NULL)
17332                         break;
17333                 if (!strcasecmp(single_name, name)) {
17334                         found = 1;
17335                         break;
17336                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17337                         break;
17338                 single_offload <<= 1;
17339         }
17340
17341         if (found)
17342                 return single_offload;
17343
17344         return 0;
17345 }
17346
17347 static void
17348 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17349                                 __rte_unused struct cmdline *cl,
17350                                 __rte_unused void *data)
17351 {
17352         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17353         portid_t port_id = res->port_id;
17354         struct rte_eth_dev_info dev_info;
17355         struct rte_port *port = &ports[port_id];
17356         uint64_t single_offload;
17357         uint16_t nb_tx_queues;
17358         int q;
17359         int ret;
17360
17361         if (port->port_status != RTE_PORT_STOPPED) {
17362                 printf("Error: Can't config offload when Port %d "
17363                        "is not stopped\n", port_id);
17364                 return;
17365         }
17366
17367         single_offload = search_tx_offload(res->offload);
17368         if (single_offload == 0) {
17369                 printf("Unknown offload name: %s\n", res->offload);
17370                 return;
17371         }
17372
17373         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17374         if (ret != 0)
17375                 return;
17376
17377         nb_tx_queues = dev_info.nb_tx_queues;
17378         if (!strcmp(res->on_off, "on")) {
17379                 port->dev_conf.txmode.offloads |= single_offload;
17380                 for (q = 0; q < nb_tx_queues; q++)
17381                         port->tx_conf[q].offloads |= single_offload;
17382         } else {
17383                 port->dev_conf.txmode.offloads &= ~single_offload;
17384                 for (q = 0; q < nb_tx_queues; q++)
17385                         port->tx_conf[q].offloads &= ~single_offload;
17386         }
17387
17388         cmd_reconfig_device_queue(port_id, 1, 1);
17389 }
17390
17391 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17392         .f = cmd_config_per_port_tx_offload_parsed,
17393         .data = NULL,
17394         .help_str = "port config <port_id> tx_offload "
17395                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17396                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17397                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17398                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17399                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
17400                     "send_on_timestamp on|off",
17401         .tokens = {
17402                 (void *)&cmd_config_per_port_tx_offload_result_port,
17403                 (void *)&cmd_config_per_port_tx_offload_result_config,
17404                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17405                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17406                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17407                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17408                 NULL,
17409         }
17410 };
17411
17412 /* Enable/Disable a per queue offloading */
17413 struct cmd_config_per_queue_tx_offload_result {
17414         cmdline_fixed_string_t port;
17415         portid_t port_id;
17416         cmdline_fixed_string_t txq;
17417         uint16_t queue_id;
17418         cmdline_fixed_string_t tx_offload;
17419         cmdline_fixed_string_t offload;
17420         cmdline_fixed_string_t on_off;
17421 };
17422
17423 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17424         TOKEN_STRING_INITIALIZER
17425                 (struct cmd_config_per_queue_tx_offload_result,
17426                  port, "port");
17427 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17428         TOKEN_NUM_INITIALIZER
17429                 (struct cmd_config_per_queue_tx_offload_result,
17430                  port_id, UINT16);
17431 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17432         TOKEN_STRING_INITIALIZER
17433                 (struct cmd_config_per_queue_tx_offload_result,
17434                  txq, "txq");
17435 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17436         TOKEN_NUM_INITIALIZER
17437                 (struct cmd_config_per_queue_tx_offload_result,
17438                  queue_id, UINT16);
17439 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17440         TOKEN_STRING_INITIALIZER
17441                 (struct cmd_config_per_queue_tx_offload_result,
17442                  tx_offload, "tx_offload");
17443 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17444         TOKEN_STRING_INITIALIZER
17445                 (struct cmd_config_per_queue_tx_offload_result,
17446                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17447                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17448                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17449                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17450                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
17451 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17452         TOKEN_STRING_INITIALIZER
17453                 (struct cmd_config_per_queue_tx_offload_result,
17454                  on_off, "on#off");
17455
17456 static void
17457 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17458                                 __rte_unused struct cmdline *cl,
17459                                 __rte_unused void *data)
17460 {
17461         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17462         struct rte_eth_dev_info dev_info;
17463         portid_t port_id = res->port_id;
17464         uint16_t queue_id = res->queue_id;
17465         struct rte_port *port = &ports[port_id];
17466         uint64_t single_offload;
17467         int ret;
17468
17469         if (port->port_status != RTE_PORT_STOPPED) {
17470                 printf("Error: Can't config offload when Port %d "
17471                        "is not stopped\n", port_id);
17472                 return;
17473         }
17474
17475         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17476         if (ret != 0)
17477                 return;
17478
17479         if (queue_id >= dev_info.nb_tx_queues) {
17480                 printf("Error: input queue_id should be 0 ... "
17481                        "%d\n", dev_info.nb_tx_queues - 1);
17482                 return;
17483         }
17484
17485         single_offload = search_tx_offload(res->offload);
17486         if (single_offload == 0) {
17487                 printf("Unknown offload name: %s\n", res->offload);
17488                 return;
17489         }
17490
17491         if (!strcmp(res->on_off, "on"))
17492                 port->tx_conf[queue_id].offloads |= single_offload;
17493         else
17494                 port->tx_conf[queue_id].offloads &= ~single_offload;
17495
17496         cmd_reconfig_device_queue(port_id, 1, 1);
17497 }
17498
17499 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17500         .f = cmd_config_per_queue_tx_offload_parsed,
17501         .data = NULL,
17502         .help_str = "port <port_id> txq <queue_id> tx_offload "
17503                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17504                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17505                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17506                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17507                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
17508                     "on|off",
17509         .tokens = {
17510                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17511                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17512                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17513                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17514                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17515                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17516                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17517                 NULL,
17518         }
17519 };
17520
17521 /* *** configure tx_metadata for specific port *** */
17522 struct cmd_config_tx_metadata_specific_result {
17523         cmdline_fixed_string_t port;
17524         cmdline_fixed_string_t keyword;
17525         uint16_t port_id;
17526         cmdline_fixed_string_t item;
17527         uint32_t value;
17528 };
17529
17530 static void
17531 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
17532                                 __rte_unused struct cmdline *cl,
17533                                 __rte_unused void *data)
17534 {
17535         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
17536
17537         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17538                 return;
17539         ports[res->port_id].tx_metadata = res->value;
17540         /* Add/remove callback to insert valid metadata in every Tx packet. */
17541         if (ports[res->port_id].tx_metadata)
17542                 add_tx_md_callback(res->port_id);
17543         else
17544                 remove_tx_md_callback(res->port_id);
17545         rte_flow_dynf_metadata_register();
17546 }
17547
17548 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
17549         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17550                         port, "port");
17551 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
17552         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17553                         keyword, "config");
17554 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
17555         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17556                         port_id, UINT16);
17557 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
17558         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17559                         item, "tx_metadata");
17560 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
17561         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17562                         value, UINT32);
17563
17564 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
17565         .f = cmd_config_tx_metadata_specific_parsed,
17566         .data = NULL,
17567         .help_str = "port config <port_id> tx_metadata <value>",
17568         .tokens = {
17569                 (void *)&cmd_config_tx_metadata_specific_port,
17570                 (void *)&cmd_config_tx_metadata_specific_keyword,
17571                 (void *)&cmd_config_tx_metadata_specific_id,
17572                 (void *)&cmd_config_tx_metadata_specific_item,
17573                 (void *)&cmd_config_tx_metadata_specific_value,
17574                 NULL,
17575         },
17576 };
17577
17578 /* *** set dynf *** */
17579 struct cmd_config_tx_dynf_specific_result {
17580         cmdline_fixed_string_t port;
17581         cmdline_fixed_string_t keyword;
17582         uint16_t port_id;
17583         cmdline_fixed_string_t item;
17584         cmdline_fixed_string_t name;
17585         cmdline_fixed_string_t value;
17586 };
17587
17588 static void
17589 cmd_config_dynf_specific_parsed(void *parsed_result,
17590                                 __rte_unused struct cmdline *cl,
17591                                 __rte_unused void *data)
17592 {
17593         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
17594         struct rte_mbuf_dynflag desc_flag;
17595         int flag;
17596         uint64_t old_port_flags;
17597
17598         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17599                 return;
17600         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
17601         if (flag <= 0) {
17602                 if (strlcpy(desc_flag.name, res->name,
17603                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
17604                         printf("Flag name too long\n");
17605                         return;
17606                 }
17607                 desc_flag.flags = 0;
17608                 flag = rte_mbuf_dynflag_register(&desc_flag);
17609                 if (flag < 0) {
17610                         printf("Can't register flag\n");
17611                         return;
17612                 }
17613                 strcpy(dynf_names[flag], desc_flag.name);
17614         }
17615         old_port_flags = ports[res->port_id].mbuf_dynf;
17616         if (!strcmp(res->value, "set")) {
17617                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
17618                 if (old_port_flags == 0)
17619                         add_tx_dynf_callback(res->port_id);
17620         } else {
17621                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
17622                 if (ports[res->port_id].mbuf_dynf == 0)
17623                         remove_tx_dynf_callback(res->port_id);
17624         }
17625 }
17626
17627 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
17628         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17629                         keyword, "port");
17630 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
17631         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17632                         keyword, "config");
17633 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
17634         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17635                         port_id, UINT16);
17636 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
17637         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17638                         item, "dynf");
17639 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
17640         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17641                         name, NULL);
17642 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
17643         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17644                         value, "set#clear");
17645
17646 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
17647         .f = cmd_config_dynf_specific_parsed,
17648         .data = NULL,
17649         .help_str = "port config <port id> dynf <name> set|clear",
17650         .tokens = {
17651                 (void *)&cmd_config_tx_dynf_specific_port,
17652                 (void *)&cmd_config_tx_dynf_specific_keyword,
17653                 (void *)&cmd_config_tx_dynf_specific_port_id,
17654                 (void *)&cmd_config_tx_dynf_specific_item,
17655                 (void *)&cmd_config_tx_dynf_specific_name,
17656                 (void *)&cmd_config_tx_dynf_specific_value,
17657                 NULL,
17658         },
17659 };
17660
17661 /* *** display tx_metadata per port configuration *** */
17662 struct cmd_show_tx_metadata_result {
17663         cmdline_fixed_string_t cmd_show;
17664         cmdline_fixed_string_t cmd_port;
17665         cmdline_fixed_string_t cmd_keyword;
17666         portid_t cmd_pid;
17667 };
17668
17669 static void
17670 cmd_show_tx_metadata_parsed(void *parsed_result,
17671                 __rte_unused struct cmdline *cl,
17672                 __rte_unused void *data)
17673 {
17674         struct cmd_show_tx_metadata_result *res = parsed_result;
17675
17676         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17677                 printf("invalid port id %u\n", res->cmd_pid);
17678                 return;
17679         }
17680         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
17681                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
17682                        ports[res->cmd_pid].tx_metadata);
17683         }
17684 }
17685
17686 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
17687         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17688                         cmd_show, "show");
17689 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
17690         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17691                         cmd_port, "port");
17692 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
17693         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
17694                         cmd_pid, UINT16);
17695 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
17696         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17697                         cmd_keyword, "tx_metadata");
17698
17699 cmdline_parse_inst_t cmd_show_tx_metadata = {
17700         .f = cmd_show_tx_metadata_parsed,
17701         .data = NULL,
17702         .help_str = "show port <port_id> tx_metadata",
17703         .tokens = {
17704                 (void *)&cmd_show_tx_metadata_show,
17705                 (void *)&cmd_show_tx_metadata_port,
17706                 (void *)&cmd_show_tx_metadata_pid,
17707                 (void *)&cmd_show_tx_metadata_keyword,
17708                 NULL,
17709         },
17710 };
17711
17712 /* *** show fec capability per port configuration *** */
17713 struct cmd_show_fec_capability_result {
17714         cmdline_fixed_string_t cmd_show;
17715         cmdline_fixed_string_t cmd_port;
17716         cmdline_fixed_string_t cmd_fec;
17717         cmdline_fixed_string_t cmd_keyword;
17718         portid_t cmd_pid;
17719 };
17720
17721 static void
17722 cmd_show_fec_capability_parsed(void *parsed_result,
17723                 __rte_unused struct cmdline *cl,
17724                 __rte_unused void *data)
17725 {
17726 #define FEC_CAP_NUM 2
17727         struct cmd_show_fec_capability_result *res = parsed_result;
17728         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
17729         unsigned int num = FEC_CAP_NUM;
17730         unsigned int ret_num;
17731         int ret;
17732
17733         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17734                 printf("Invalid port id %u\n", res->cmd_pid);
17735                 return;
17736         }
17737
17738         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
17739         if (ret == -ENOTSUP) {
17740                 printf("Function not implemented\n");
17741                 return;
17742         } else if (ret < 0) {
17743                 printf("Get FEC capability failed\n");
17744                 return;
17745         }
17746
17747         ret_num = (unsigned int)ret;
17748         show_fec_capability(ret_num, speed_fec_capa);
17749 }
17750
17751 cmdline_parse_token_string_t cmd_show_fec_capability_show =
17752         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17753                         cmd_show, "show");
17754 cmdline_parse_token_string_t cmd_show_fec_capability_port =
17755         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17756                         cmd_port, "port");
17757 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17758         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17759                         cmd_pid, UINT16);
17760 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17761         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17762                         cmd_fec, "fec");
17763 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17764         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17765                         cmd_keyword, "capabilities");
17766
17767 cmdline_parse_inst_t cmd_show_capability = {
17768         .f = cmd_show_fec_capability_parsed,
17769         .data = NULL,
17770         .help_str = "show port <port_id> fec capabilities",
17771         .tokens = {
17772                 (void *)&cmd_show_fec_capability_show,
17773                 (void *)&cmd_show_fec_capability_port,
17774                 (void *)&cmd_show_fec_capability_pid,
17775                 (void *)&cmd_show_fec_capability_fec,
17776                 (void *)&cmd_show_fec_capability_keyword,
17777                 NULL,
17778         },
17779 };
17780
17781 /* *** show fec mode per port configuration *** */
17782 struct cmd_show_fec_metadata_result {
17783         cmdline_fixed_string_t cmd_show;
17784         cmdline_fixed_string_t cmd_port;
17785         cmdline_fixed_string_t cmd_keyword;
17786         portid_t cmd_pid;
17787 };
17788
17789 static void
17790 cmd_show_fec_mode_parsed(void *parsed_result,
17791                 __rte_unused struct cmdline *cl,
17792                 __rte_unused void *data)
17793 {
17794 #define FEC_NAME_SIZE 16
17795         struct cmd_show_fec_metadata_result *res = parsed_result;
17796         uint32_t mode;
17797         char buf[FEC_NAME_SIZE];
17798         int ret;
17799
17800         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17801                 printf("Invalid port id %u\n", res->cmd_pid);
17802                 return;
17803         }
17804         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17805         if (ret == -ENOTSUP) {
17806                 printf("Function not implemented\n");
17807                 return;
17808         } else if (ret < 0) {
17809                 printf("Get FEC mode failed\n");
17810                 return;
17811         }
17812
17813         switch (mode) {
17814         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17815                 strlcpy(buf, "off", sizeof(buf));
17816                 break;
17817         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17818                 strlcpy(buf, "auto", sizeof(buf));
17819                 break;
17820         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17821                 strlcpy(buf, "baser", sizeof(buf));
17822                 break;
17823         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17824                 strlcpy(buf, "rs", sizeof(buf));
17825                 break;
17826         default:
17827                 return;
17828         }
17829
17830         printf("%s\n", buf);
17831 }
17832
17833 cmdline_parse_token_string_t cmd_show_fec_mode_show =
17834         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17835                         cmd_show, "show");
17836 cmdline_parse_token_string_t cmd_show_fec_mode_port =
17837         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17838                         cmd_port, "port");
17839 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17840         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17841                         cmd_pid, UINT16);
17842 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17843         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17844                         cmd_keyword, "fec_mode");
17845
17846 cmdline_parse_inst_t cmd_show_fec_mode = {
17847         .f = cmd_show_fec_mode_parsed,
17848         .data = NULL,
17849         .help_str = "show port <port_id> fec_mode",
17850         .tokens = {
17851                 (void *)&cmd_show_fec_mode_show,
17852                 (void *)&cmd_show_fec_mode_port,
17853                 (void *)&cmd_show_fec_mode_pid,
17854                 (void *)&cmd_show_fec_mode_keyword,
17855                 NULL,
17856         },
17857 };
17858
17859 /* *** set fec mode per port configuration *** */
17860 struct cmd_set_port_fec_mode {
17861         cmdline_fixed_string_t set;
17862         cmdline_fixed_string_t port;
17863         portid_t port_id;
17864         cmdline_fixed_string_t fec_mode;
17865         cmdline_fixed_string_t fec_value;
17866 };
17867
17868 /* Common CLI fields for set fec mode */
17869 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17870         TOKEN_STRING_INITIALIZER
17871                 (struct cmd_set_port_fec_mode,
17872                  set, "set");
17873 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17874         TOKEN_STRING_INITIALIZER
17875                 (struct cmd_set_port_fec_mode,
17876                  port, "port");
17877 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17878         TOKEN_NUM_INITIALIZER
17879                 (struct cmd_set_port_fec_mode,
17880                  port_id, UINT16);
17881 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17882         TOKEN_STRING_INITIALIZER
17883                 (struct cmd_set_port_fec_mode,
17884                  fec_mode, "fec_mode");
17885 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17886         TOKEN_STRING_INITIALIZER
17887                 (struct cmd_set_port_fec_mode,
17888                  fec_value, NULL);
17889
17890 static void
17891 cmd_set_port_fec_mode_parsed(
17892         void *parsed_result,
17893         __rte_unused struct cmdline *cl,
17894         __rte_unused void *data)
17895 {
17896         struct cmd_set_port_fec_mode *res = parsed_result;
17897         uint16_t port_id = res->port_id;
17898         uint32_t mode;
17899         int ret;
17900
17901         ret = parse_fec_mode(res->fec_value, &mode);
17902         if (ret < 0) {
17903                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
17904                         port_id);
17905                 return;
17906         }
17907
17908         ret = rte_eth_fec_set(port_id, mode);
17909         if (ret == -ENOTSUP) {
17910                 printf("Function not implemented\n");
17911                 return;
17912         } else if (ret < 0) {
17913                 printf("Set FEC mode failed\n");
17914                 return;
17915         }
17916 }
17917
17918 cmdline_parse_inst_t cmd_set_fec_mode = {
17919         .f = cmd_set_port_fec_mode_parsed,
17920         .data = NULL,
17921         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17922         .tokens = {
17923                 (void *)&cmd_set_port_fec_mode_set,
17924                 (void *)&cmd_set_port_fec_mode_port,
17925                 (void *)&cmd_set_port_fec_mode_port_id,
17926                 (void *)&cmd_set_port_fec_mode_str,
17927                 (void *)&cmd_set_port_fec_mode_value,
17928                 NULL,
17929         },
17930 };
17931
17932 /* show port supported ptypes */
17933
17934 /* Common result structure for show port ptypes */
17935 struct cmd_show_port_supported_ptypes_result {
17936         cmdline_fixed_string_t show;
17937         cmdline_fixed_string_t port;
17938         portid_t port_id;
17939         cmdline_fixed_string_t ptypes;
17940 };
17941
17942 /* Common CLI fields for show port ptypes */
17943 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17944         TOKEN_STRING_INITIALIZER
17945                 (struct cmd_show_port_supported_ptypes_result,
17946                  show, "show");
17947 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17948         TOKEN_STRING_INITIALIZER
17949                 (struct cmd_show_port_supported_ptypes_result,
17950                  port, "port");
17951 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17952         TOKEN_NUM_INITIALIZER
17953                 (struct cmd_show_port_supported_ptypes_result,
17954                  port_id, UINT16);
17955 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17956         TOKEN_STRING_INITIALIZER
17957                 (struct cmd_show_port_supported_ptypes_result,
17958                  ptypes, "ptypes");
17959
17960 static void
17961 cmd_show_port_supported_ptypes_parsed(
17962         void *parsed_result,
17963         __rte_unused struct cmdline *cl,
17964         __rte_unused void *data)
17965 {
17966 #define RSVD_PTYPE_MASK       0xf0000000
17967 #define MAX_PTYPES_PER_LAYER  16
17968 #define LTYPE_NAMESIZE        32
17969 #define PTYPE_NAMESIZE        256
17970         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17971         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17972         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17973         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17974         uint16_t port_id = res->port_id;
17975         int ret, i;
17976
17977         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17978         if (ret < 0)
17979                 return;
17980
17981         while (ptype_mask != RSVD_PTYPE_MASK) {
17982
17983                 switch (ptype_mask) {
17984                 case RTE_PTYPE_L2_MASK:
17985                         strlcpy(ltype, "L2", sizeof(ltype));
17986                         break;
17987                 case RTE_PTYPE_L3_MASK:
17988                         strlcpy(ltype, "L3", sizeof(ltype));
17989                         break;
17990                 case RTE_PTYPE_L4_MASK:
17991                         strlcpy(ltype, "L4", sizeof(ltype));
17992                         break;
17993                 case RTE_PTYPE_TUNNEL_MASK:
17994                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17995                         break;
17996                 case RTE_PTYPE_INNER_L2_MASK:
17997                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17998                         break;
17999                 case RTE_PTYPE_INNER_L3_MASK:
18000                         strlcpy(ltype, "Inner L3", sizeof(ltype));
18001                         break;
18002                 case RTE_PTYPE_INNER_L4_MASK:
18003                         strlcpy(ltype, "Inner L4", sizeof(ltype));
18004                         break;
18005                 default:
18006                         return;
18007                 }
18008
18009                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
18010                                                        ptype_mask, ptypes,
18011                                                        MAX_PTYPES_PER_LAYER);
18012
18013                 if (ret > 0)
18014                         printf("Supported %s ptypes:\n", ltype);
18015                 else
18016                         printf("%s ptypes unsupported\n", ltype);
18017
18018                 for (i = 0; i < ret; ++i) {
18019                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
18020                         printf("%s\n", buf);
18021                 }
18022
18023                 ptype_mask <<= 4;
18024         }
18025 }
18026
18027 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
18028         .f = cmd_show_port_supported_ptypes_parsed,
18029         .data = NULL,
18030         .help_str = "show port <port_id> ptypes",
18031         .tokens = {
18032                 (void *)&cmd_show_port_supported_ptypes_show,
18033                 (void *)&cmd_show_port_supported_ptypes_port,
18034                 (void *)&cmd_show_port_supported_ptypes_port_id,
18035                 (void *)&cmd_show_port_supported_ptypes_ptypes,
18036                 NULL,
18037         },
18038 };
18039
18040 /* *** display rx/tx descriptor status *** */
18041 struct cmd_show_rx_tx_desc_status_result {
18042         cmdline_fixed_string_t cmd_show;
18043         cmdline_fixed_string_t cmd_port;
18044         cmdline_fixed_string_t cmd_keyword;
18045         cmdline_fixed_string_t cmd_desc;
18046         cmdline_fixed_string_t cmd_status;
18047         portid_t cmd_pid;
18048         portid_t cmd_qid;
18049         portid_t cmd_did;
18050 };
18051
18052 static void
18053 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
18054                 __rte_unused struct cmdline *cl,
18055                 __rte_unused void *data)
18056 {
18057         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
18058         int rc;
18059
18060         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18061                 printf("invalid port id %u\n", res->cmd_pid);
18062                 return;
18063         }
18064
18065         if (!strcmp(res->cmd_keyword, "rxq")) {
18066                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
18067                                              res->cmd_did);
18068                 if (rc < 0) {
18069                         printf("Invalid queueid = %d\n", res->cmd_qid);
18070                         return;
18071                 }
18072                 if (rc == RTE_ETH_RX_DESC_AVAIL)
18073                         printf("Desc status = AVAILABLE\n");
18074                 else if (rc == RTE_ETH_RX_DESC_DONE)
18075                         printf("Desc status = DONE\n");
18076                 else
18077                         printf("Desc status = UNAVAILABLE\n");
18078         } else if (!strcmp(res->cmd_keyword, "txq")) {
18079                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
18080                                              res->cmd_did);
18081                 if (rc < 0) {
18082                         printf("Invalid queueid = %d\n", res->cmd_qid);
18083                         return;
18084                 }
18085                 if (rc == RTE_ETH_TX_DESC_FULL)
18086                         printf("Desc status = FULL\n");
18087                 else if (rc == RTE_ETH_TX_DESC_DONE)
18088                         printf("Desc status = DONE\n");
18089                 else
18090                         printf("Desc status = UNAVAILABLE\n");
18091         }
18092 }
18093
18094 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
18095         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18096                         cmd_show, "show");
18097 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
18098         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18099                         cmd_port, "port");
18100 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
18101         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18102                         cmd_pid, UINT16);
18103 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
18104         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18105                         cmd_keyword, "rxq#txq");
18106 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
18107         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18108                         cmd_qid, UINT16);
18109 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
18110         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18111                         cmd_desc, "desc");
18112 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
18113         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18114                         cmd_did, UINT16);
18115 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
18116         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18117                         cmd_status, "status");
18118 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
18119         .f = cmd_show_rx_tx_desc_status_parsed,
18120         .data = NULL,
18121         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
18122                 "status",
18123         .tokens = {
18124                 (void *)&cmd_show_rx_tx_desc_status_show,
18125                 (void *)&cmd_show_rx_tx_desc_status_port,
18126                 (void *)&cmd_show_rx_tx_desc_status_pid,
18127                 (void *)&cmd_show_rx_tx_desc_status_keyword,
18128                 (void *)&cmd_show_rx_tx_desc_status_qid,
18129                 (void *)&cmd_show_rx_tx_desc_status_desc,
18130                 (void *)&cmd_show_rx_tx_desc_status_did,
18131                 (void *)&cmd_show_rx_tx_desc_status_status,
18132                 NULL,
18133         },
18134 };
18135
18136 /* Common result structure for set port ptypes */
18137 struct cmd_set_port_ptypes_result {
18138         cmdline_fixed_string_t set;
18139         cmdline_fixed_string_t port;
18140         portid_t port_id;
18141         cmdline_fixed_string_t ptype_mask;
18142         uint32_t mask;
18143 };
18144
18145 /* Common CLI fields for set port ptypes */
18146 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
18147         TOKEN_STRING_INITIALIZER
18148                 (struct cmd_set_port_ptypes_result,
18149                  set, "set");
18150 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
18151         TOKEN_STRING_INITIALIZER
18152                 (struct cmd_set_port_ptypes_result,
18153                  port, "port");
18154 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
18155         TOKEN_NUM_INITIALIZER
18156                 (struct cmd_set_port_ptypes_result,
18157                  port_id, UINT16);
18158 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
18159         TOKEN_STRING_INITIALIZER
18160                 (struct cmd_set_port_ptypes_result,
18161                  ptype_mask, "ptype_mask");
18162 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
18163         TOKEN_NUM_INITIALIZER
18164                 (struct cmd_set_port_ptypes_result,
18165                  mask, UINT32);
18166
18167 static void
18168 cmd_set_port_ptypes_parsed(
18169         void *parsed_result,
18170         __rte_unused struct cmdline *cl,
18171         __rte_unused void *data)
18172 {
18173         struct cmd_set_port_ptypes_result *res = parsed_result;
18174 #define PTYPE_NAMESIZE        256
18175         char ptype_name[PTYPE_NAMESIZE];
18176         uint16_t port_id = res->port_id;
18177         uint32_t ptype_mask = res->mask;
18178         int ret, i;
18179
18180         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
18181                                                NULL, 0);
18182         if (ret <= 0) {
18183                 printf("Port %d doesn't support any ptypes.\n", port_id);
18184                 return;
18185         }
18186
18187         uint32_t ptypes[ret];
18188
18189         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
18190         if (ret < 0) {
18191                 printf("Unable to set requested ptypes for Port %d\n", port_id);
18192                 return;
18193         }
18194
18195         printf("Successfully set following ptypes for Port %d\n", port_id);
18196         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
18197                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
18198                 printf("%s\n", ptype_name);
18199         }
18200
18201         clear_ptypes = false;
18202 }
18203
18204 cmdline_parse_inst_t cmd_set_port_ptypes = {
18205         .f = cmd_set_port_ptypes_parsed,
18206         .data = NULL,
18207         .help_str = "set port <port_id> ptype_mask <mask>",
18208         .tokens = {
18209                 (void *)&cmd_set_port_ptypes_set,
18210                 (void *)&cmd_set_port_ptypes_port,
18211                 (void *)&cmd_set_port_ptypes_port_id,
18212                 (void *)&cmd_set_port_ptypes_mask_str,
18213                 (void *)&cmd_set_port_ptypes_mask_u32,
18214                 NULL,
18215         },
18216 };
18217
18218 /* *** display mac addresses added to a port *** */
18219 struct cmd_showport_macs_result {
18220         cmdline_fixed_string_t cmd_show;
18221         cmdline_fixed_string_t cmd_port;
18222         cmdline_fixed_string_t cmd_keyword;
18223         portid_t cmd_pid;
18224 };
18225
18226 static void
18227 cmd_showport_macs_parsed(void *parsed_result,
18228                 __rte_unused struct cmdline *cl,
18229                 __rte_unused void *data)
18230 {
18231         struct cmd_showport_macs_result *res = parsed_result;
18232
18233         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
18234                 return;
18235
18236         if (!strcmp(res->cmd_keyword, "macs"))
18237                 show_macs(res->cmd_pid);
18238         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
18239                 show_mcast_macs(res->cmd_pid);
18240 }
18241
18242 cmdline_parse_token_string_t cmd_showport_macs_show =
18243         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
18244                         cmd_show, "show");
18245 cmdline_parse_token_string_t cmd_showport_macs_port =
18246         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
18247                         cmd_port, "port");
18248 cmdline_parse_token_num_t cmd_showport_macs_pid =
18249         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
18250                         cmd_pid, UINT16);
18251 cmdline_parse_token_string_t cmd_showport_macs_keyword =
18252         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
18253                         cmd_keyword, "macs#mcast_macs");
18254
18255 cmdline_parse_inst_t cmd_showport_macs = {
18256         .f = cmd_showport_macs_parsed,
18257         .data = NULL,
18258         .help_str = "show port <port_id> macs|mcast_macs",
18259         .tokens = {
18260                 (void *)&cmd_showport_macs_show,
18261                 (void *)&cmd_showport_macs_port,
18262                 (void *)&cmd_showport_macs_pid,
18263                 (void *)&cmd_showport_macs_keyword,
18264                 NULL,
18265         },
18266 };
18267
18268 /* ******************************************************************************** */
18269
18270 /* list of instructions */
18271 cmdline_parse_ctx_t main_ctx[] = {
18272         (cmdline_parse_inst_t *)&cmd_help_brief,
18273         (cmdline_parse_inst_t *)&cmd_help_long,
18274         (cmdline_parse_inst_t *)&cmd_quit,
18275         (cmdline_parse_inst_t *)&cmd_load_from_file,
18276         (cmdline_parse_inst_t *)&cmd_showport,
18277         (cmdline_parse_inst_t *)&cmd_showqueue,
18278         (cmdline_parse_inst_t *)&cmd_showeeprom,
18279         (cmdline_parse_inst_t *)&cmd_showportall,
18280         (cmdline_parse_inst_t *)&cmd_showdevice,
18281         (cmdline_parse_inst_t *)&cmd_showcfg,
18282         (cmdline_parse_inst_t *)&cmd_showfwdall,
18283         (cmdline_parse_inst_t *)&cmd_start,
18284         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18285         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18286         (cmdline_parse_inst_t *)&cmd_set_link_up,
18287         (cmdline_parse_inst_t *)&cmd_set_link_down,
18288         (cmdline_parse_inst_t *)&cmd_reset,
18289         (cmdline_parse_inst_t *)&cmd_set_numbers,
18290         (cmdline_parse_inst_t *)&cmd_set_log,
18291         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
18292         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
18293         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18294         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18295         (cmdline_parse_inst_t *)&cmd_set_txtimes,
18296         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18297         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18298         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18299         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18300         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18301         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18302         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18303         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18304         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18305         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18306         (cmdline_parse_inst_t *)&cmd_set_link_check,
18307         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18308         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18309         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18310         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18311 #ifdef RTE_NET_BOND
18312         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18313         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18314         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18315         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18316         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18317         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18318         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18319         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18320         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18321         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18322         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18323 #endif
18324         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18325         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18326         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18327         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18328         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18329         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18330         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18331         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18332         (cmdline_parse_inst_t *)&cmd_csum_set,
18333         (cmdline_parse_inst_t *)&cmd_csum_show,
18334         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18335         (cmdline_parse_inst_t *)&cmd_tso_set,
18336         (cmdline_parse_inst_t *)&cmd_tso_show,
18337         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18338         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18339         (cmdline_parse_inst_t *)&cmd_gro_enable,
18340         (cmdline_parse_inst_t *)&cmd_gro_flush,
18341         (cmdline_parse_inst_t *)&cmd_gro_show,
18342         (cmdline_parse_inst_t *)&cmd_gso_enable,
18343         (cmdline_parse_inst_t *)&cmd_gso_size,
18344         (cmdline_parse_inst_t *)&cmd_gso_show,
18345         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18346         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18347         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18348         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18349         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18350         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18351         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18352         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18353         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18354         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18355         (cmdline_parse_inst_t *)&cmd_config_dcb,
18356         (cmdline_parse_inst_t *)&cmd_read_reg,
18357         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18358         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18359         (cmdline_parse_inst_t *)&cmd_write_reg,
18360         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18361         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18362         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18363         (cmdline_parse_inst_t *)&cmd_stop,
18364         (cmdline_parse_inst_t *)&cmd_mac_addr,
18365         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18366         (cmdline_parse_inst_t *)&cmd_set_qmap,
18367         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18368         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
18369         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
18370         (cmdline_parse_inst_t *)&cmd_operate_port,
18371         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18372         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18373         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18374         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
18375         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18376         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18377         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18378         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18379         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18380         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18381         (cmdline_parse_inst_t *)&cmd_config_mtu,
18382         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18383         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
18384         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18385         (cmdline_parse_inst_t *)&cmd_config_rss,
18386         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18387         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18388         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18389         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18390         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18391         (cmdline_parse_inst_t *)&cmd_showport_reta,
18392         (cmdline_parse_inst_t *)&cmd_showport_macs,
18393         (cmdline_parse_inst_t *)&cmd_config_burst,
18394         (cmdline_parse_inst_t *)&cmd_config_thresh,
18395         (cmdline_parse_inst_t *)&cmd_config_threshold,
18396         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18397         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18398         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18399         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18400         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18401         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18402         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18403         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18404         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18405         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18406         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18407         (cmdline_parse_inst_t *)&cmd_dump,
18408         (cmdline_parse_inst_t *)&cmd_dump_one,
18409         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18410         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18411         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18412         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18413         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18414         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18415         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18416         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18417         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18418         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18419         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18420         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18421         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18422         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18423         (cmdline_parse_inst_t *)&cmd_flow,
18424         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18425         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18426         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18427         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18428         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18429         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18430         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18431         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18432         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18433         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18434         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18435         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18436         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18437         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18438         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18439         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18440         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18441         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18442         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18443         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18444         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18445         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18446         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18447         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18448         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18449         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18450         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18451         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18452         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18453         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18454         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18455         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18456         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18457         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18458         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18459         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18460         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18461         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18462         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18463         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18464         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18465         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18466         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18467         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18468         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18469         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18470         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18471         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18472         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18473         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18474         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18475         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18476         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18477         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18478         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18479         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18480         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18481         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18482         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18483         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18484         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18485         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18486         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18487         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18488         (cmdline_parse_inst_t *)&cmd_ddp_add,
18489         (cmdline_parse_inst_t *)&cmd_ddp_del,
18490         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18491         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18492         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18493         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18494         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18495         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18496         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
18497         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
18498         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18499         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18500         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18501         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18502
18503         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18504         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18505         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18506         (cmdline_parse_inst_t *)&cmd_queue_region,
18507         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18508         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18509         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18510         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18511         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18512         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18513         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18514         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18515         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18516         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18517         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18518         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18519         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18520         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18521         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18522         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18523         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18524         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
18525         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18526         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18527         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18528         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18529         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18530         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18531         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18532         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18533         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18534         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18535         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18536         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18537         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18538         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18539         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18540         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18541         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18542         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18543 #ifdef RTE_LIB_BPF
18544         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18545         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18546 #endif
18547         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18548         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18549         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
18550         (cmdline_parse_inst_t *)&cmd_set_raw,
18551         (cmdline_parse_inst_t *)&cmd_show_set_raw,
18552         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
18553         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
18554         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
18555         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
18556         (cmdline_parse_inst_t *)&cmd_show_capability,
18557         NULL,
18558 };
18559
18560 /* read cmdline commands from file */
18561 void
18562 cmdline_read_from_file(const char *filename)
18563 {
18564         struct cmdline *cl;
18565
18566         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18567         if (cl == NULL) {
18568                 printf("Failed to create file based cmdline context: %s\n",
18569                        filename);
18570                 return;
18571         }
18572
18573         cmdline_interact(cl);
18574         cmdline_quit(cl);
18575
18576         cmdline_free(cl);
18577
18578         printf("Read CLI commands from %s\n", filename);
18579 }
18580
18581 /* prompt function, called from main on MAIN lcore */
18582 void
18583 prompt(void)
18584 {
18585         /* initialize non-constant commands */
18586         cmd_set_fwd_mode_init();
18587         cmd_set_fwd_retry_mode_init();
18588
18589         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18590         if (testpmd_cl == NULL)
18591                 return;
18592         cmdline_interact(testpmd_cl);
18593         cmdline_stdin_exit(testpmd_cl);
18594 }
18595
18596 void
18597 prompt_exit(void)
18598 {
18599         if (testpmd_cl != NULL)
18600                 cmdline_quit(testpmd_cl);
18601 }
18602
18603 static void
18604 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18605 {
18606         if (id == (portid_t)RTE_PORT_ALL) {
18607                 portid_t pid;
18608
18609                 RTE_ETH_FOREACH_DEV(pid) {
18610                         /* check if need_reconfig has been set to 1 */
18611                         if (ports[pid].need_reconfig == 0)
18612                                 ports[pid].need_reconfig = dev;
18613                         /* check if need_reconfig_queues has been set to 1 */
18614                         if (ports[pid].need_reconfig_queues == 0)
18615                                 ports[pid].need_reconfig_queues = queue;
18616                 }
18617         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18618                 /* check if need_reconfig has been set to 1 */
18619                 if (ports[id].need_reconfig == 0)
18620                         ports[id].need_reconfig = dev;
18621                 /* check if need_reconfig_queues has been set to 1 */
18622                 if (ports[id].need_reconfig_queues == 0)
18623                         ports[id].need_reconfig_queues = queue;
18624         }
18625 }