ethdev: remove legacy L2 tunnel filter type 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 /* *** GLOBAL CONFIG *** */
9299 struct cmd_global_config_result {
9300         cmdline_fixed_string_t cmd;
9301         portid_t port_id;
9302         cmdline_fixed_string_t cfg_type;
9303         uint8_t len;
9304 };
9305
9306 static void
9307 cmd_global_config_parsed(void *parsed_result,
9308                          __rte_unused struct cmdline *cl,
9309                          __rte_unused void *data)
9310 {
9311         struct cmd_global_config_result *res = parsed_result;
9312         struct rte_eth_global_cfg conf;
9313         int ret;
9314
9315         memset(&conf, 0, sizeof(conf));
9316         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9317         conf.cfg.gre_key_len = res->len;
9318         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9319                                       RTE_ETH_FILTER_SET, &conf);
9320 #ifdef RTE_NET_I40E
9321         if (ret == -ENOTSUP)
9322                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9323 #endif
9324         if (ret != 0)
9325                 printf("Global config error\n");
9326 }
9327
9328 cmdline_parse_token_string_t cmd_global_config_cmd =
9329         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9330                 "global_config");
9331 cmdline_parse_token_num_t cmd_global_config_port_id =
9332         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9333                                UINT16);
9334 cmdline_parse_token_string_t cmd_global_config_type =
9335         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9336                 cfg_type, "gre-key-len");
9337 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9338         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9339                 len, UINT8);
9340
9341 cmdline_parse_inst_t cmd_global_config = {
9342         .f = cmd_global_config_parsed,
9343         .data = (void *)NULL,
9344         .help_str = "global_config <port_id> gre-key-len <key_len>",
9345         .tokens = {
9346                 (void *)&cmd_global_config_cmd,
9347                 (void *)&cmd_global_config_port_id,
9348                 (void *)&cmd_global_config_type,
9349                 (void *)&cmd_global_config_gre_key_len,
9350                 NULL,
9351         },
9352 };
9353
9354 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9355 struct cmd_set_mirror_mask_result {
9356         cmdline_fixed_string_t set;
9357         cmdline_fixed_string_t port;
9358         portid_t port_id;
9359         cmdline_fixed_string_t mirror;
9360         uint8_t rule_id;
9361         cmdline_fixed_string_t what;
9362         cmdline_fixed_string_t value;
9363         cmdline_fixed_string_t dstpool;
9364         uint8_t dstpool_id;
9365         cmdline_fixed_string_t on;
9366 };
9367
9368 cmdline_parse_token_string_t cmd_mirror_mask_set =
9369         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9370                                 set, "set");
9371 cmdline_parse_token_string_t cmd_mirror_mask_port =
9372         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9373                                 port, "port");
9374 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9375         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9376                                 port_id, UINT16);
9377 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9378         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9379                                 mirror, "mirror-rule");
9380 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9381         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9382                                 rule_id, UINT8);
9383 cmdline_parse_token_string_t cmd_mirror_mask_what =
9384         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9385                                 what, "pool-mirror-up#pool-mirror-down"
9386                                       "#vlan-mirror");
9387 cmdline_parse_token_string_t cmd_mirror_mask_value =
9388         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9389                                 value, NULL);
9390 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9391         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9392                                 dstpool, "dst-pool");
9393 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9394         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9395                                 dstpool_id, UINT8);
9396 cmdline_parse_token_string_t cmd_mirror_mask_on =
9397         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9398                                 on, "on#off");
9399
9400 static void
9401 cmd_set_mirror_mask_parsed(void *parsed_result,
9402                        __rte_unused struct cmdline *cl,
9403                        __rte_unused void *data)
9404 {
9405         int ret,nb_item,i;
9406         struct cmd_set_mirror_mask_result *res = parsed_result;
9407         struct rte_eth_mirror_conf mr_conf;
9408
9409         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9410
9411         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9412
9413         mr_conf.dst_pool = res->dstpool_id;
9414
9415         if (!strcmp(res->what, "pool-mirror-up")) {
9416                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9417                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9418         } else if (!strcmp(res->what, "pool-mirror-down")) {
9419                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9420                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9421         } else if (!strcmp(res->what, "vlan-mirror")) {
9422                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9423                 nb_item = parse_item_list(res->value, "vlan",
9424                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9425                 if (nb_item <= 0)
9426                         return;
9427
9428                 for (i = 0; i < nb_item; i++) {
9429                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9430                                 printf("Invalid vlan_id: must be < 4096\n");
9431                                 return;
9432                         }
9433
9434                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9435                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9436                 }
9437         }
9438
9439         if (!strcmp(res->on, "on"))
9440                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9441                                                 res->rule_id, 1);
9442         else
9443                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9444                                                 res->rule_id, 0);
9445         if (ret < 0)
9446                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9447 }
9448
9449 cmdline_parse_inst_t cmd_set_mirror_mask = {
9450                 .f = cmd_set_mirror_mask_parsed,
9451                 .data = NULL,
9452                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9453                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9454                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9455                 .tokens = {
9456                         (void *)&cmd_mirror_mask_set,
9457                         (void *)&cmd_mirror_mask_port,
9458                         (void *)&cmd_mirror_mask_portid,
9459                         (void *)&cmd_mirror_mask_mirror,
9460                         (void *)&cmd_mirror_mask_ruleid,
9461                         (void *)&cmd_mirror_mask_what,
9462                         (void *)&cmd_mirror_mask_value,
9463                         (void *)&cmd_mirror_mask_dstpool,
9464                         (void *)&cmd_mirror_mask_poolid,
9465                         (void *)&cmd_mirror_mask_on,
9466                         NULL,
9467                 },
9468 };
9469
9470 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9471 struct cmd_set_mirror_link_result {
9472         cmdline_fixed_string_t set;
9473         cmdline_fixed_string_t port;
9474         portid_t port_id;
9475         cmdline_fixed_string_t mirror;
9476         uint8_t rule_id;
9477         cmdline_fixed_string_t what;
9478         cmdline_fixed_string_t dstpool;
9479         uint8_t dstpool_id;
9480         cmdline_fixed_string_t on;
9481 };
9482
9483 cmdline_parse_token_string_t cmd_mirror_link_set =
9484         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9485                                  set, "set");
9486 cmdline_parse_token_string_t cmd_mirror_link_port =
9487         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9488                                 port, "port");
9489 cmdline_parse_token_num_t cmd_mirror_link_portid =
9490         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9491                                 port_id, UINT16);
9492 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9493         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9494                                 mirror, "mirror-rule");
9495 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9496         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9497                             rule_id, UINT8);
9498 cmdline_parse_token_string_t cmd_mirror_link_what =
9499         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9500                                 what, "uplink-mirror#downlink-mirror");
9501 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9502         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9503                                 dstpool, "dst-pool");
9504 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9505         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9506                                 dstpool_id, UINT8);
9507 cmdline_parse_token_string_t cmd_mirror_link_on =
9508         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9509                                 on, "on#off");
9510
9511 static void
9512 cmd_set_mirror_link_parsed(void *parsed_result,
9513                        __rte_unused struct cmdline *cl,
9514                        __rte_unused void *data)
9515 {
9516         int ret;
9517         struct cmd_set_mirror_link_result *res = parsed_result;
9518         struct rte_eth_mirror_conf mr_conf;
9519
9520         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9521         if (!strcmp(res->what, "uplink-mirror"))
9522                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9523         else
9524                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9525
9526         mr_conf.dst_pool = res->dstpool_id;
9527
9528         if (!strcmp(res->on, "on"))
9529                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9530                                                 res->rule_id, 1);
9531         else
9532                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9533                                                 res->rule_id, 0);
9534
9535         /* check the return value and print it if is < 0 */
9536         if (ret < 0)
9537                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9538
9539 }
9540
9541 cmdline_parse_inst_t cmd_set_mirror_link = {
9542                 .f = cmd_set_mirror_link_parsed,
9543                 .data = NULL,
9544                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9545                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9546                 .tokens = {
9547                         (void *)&cmd_mirror_link_set,
9548                         (void *)&cmd_mirror_link_port,
9549                         (void *)&cmd_mirror_link_portid,
9550                         (void *)&cmd_mirror_link_mirror,
9551                         (void *)&cmd_mirror_link_ruleid,
9552                         (void *)&cmd_mirror_link_what,
9553                         (void *)&cmd_mirror_link_dstpool,
9554                         (void *)&cmd_mirror_link_poolid,
9555                         (void *)&cmd_mirror_link_on,
9556                         NULL,
9557                 },
9558 };
9559
9560 /* *** RESET VM MIRROR RULE *** */
9561 struct cmd_rm_mirror_rule_result {
9562         cmdline_fixed_string_t reset;
9563         cmdline_fixed_string_t port;
9564         portid_t port_id;
9565         cmdline_fixed_string_t mirror;
9566         uint8_t rule_id;
9567 };
9568
9569 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9570         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9571                                  reset, "reset");
9572 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9573         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9574                                 port, "port");
9575 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9576         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9577                                 port_id, UINT16);
9578 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9579         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9580                                 mirror, "mirror-rule");
9581 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9582         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9583                                 rule_id, UINT8);
9584
9585 static void
9586 cmd_reset_mirror_rule_parsed(void *parsed_result,
9587                        __rte_unused struct cmdline *cl,
9588                        __rte_unused void *data)
9589 {
9590         int ret;
9591         struct cmd_set_mirror_link_result *res = parsed_result;
9592         /* check rule_id */
9593         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9594         if(ret < 0)
9595                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9596 }
9597
9598 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9599                 .f = cmd_reset_mirror_rule_parsed,
9600                 .data = NULL,
9601                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9602                 .tokens = {
9603                         (void *)&cmd_rm_mirror_rule_reset,
9604                         (void *)&cmd_rm_mirror_rule_port,
9605                         (void *)&cmd_rm_mirror_rule_portid,
9606                         (void *)&cmd_rm_mirror_rule_mirror,
9607                         (void *)&cmd_rm_mirror_rule_ruleid,
9608                         NULL,
9609                 },
9610 };
9611
9612 /* ******************************************************************************** */
9613
9614 struct cmd_dump_result {
9615         cmdline_fixed_string_t dump;
9616 };
9617
9618 static void
9619 dump_struct_sizes(void)
9620 {
9621 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9622         DUMP_SIZE(struct rte_mbuf);
9623         DUMP_SIZE(struct rte_mempool);
9624         DUMP_SIZE(struct rte_ring);
9625 #undef DUMP_SIZE
9626 }
9627
9628
9629 /* Dump the socket memory statistics on console */
9630 static void
9631 dump_socket_mem(FILE *f)
9632 {
9633         struct rte_malloc_socket_stats socket_stats;
9634         unsigned int i;
9635         size_t total = 0;
9636         size_t alloc = 0;
9637         size_t free = 0;
9638         unsigned int n_alloc = 0;
9639         unsigned int n_free = 0;
9640         static size_t last_allocs;
9641         static size_t last_total;
9642
9643
9644         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9645                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9646                     !socket_stats.heap_totalsz_bytes)
9647                         continue;
9648                 total += socket_stats.heap_totalsz_bytes;
9649                 alloc += socket_stats.heap_allocsz_bytes;
9650                 free += socket_stats.heap_freesz_bytes;
9651                 n_alloc += socket_stats.alloc_count;
9652                 n_free += socket_stats.free_count;
9653                 fprintf(f,
9654                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9655                         i,
9656                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9657                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9658                         (double)socket_stats.heap_allocsz_bytes * 100 /
9659                         (double)socket_stats.heap_totalsz_bytes,
9660                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9661                         socket_stats.alloc_count,
9662                         socket_stats.free_count);
9663         }
9664         fprintf(f,
9665                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9666                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9667                 (double)alloc * 100 / (double)total,
9668                 (double)free / (1024 * 1024),
9669                 n_alloc, n_free);
9670         if (last_allocs)
9671                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9672                         ((double)total - (double)last_total) / (1024 * 1024),
9673                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9674         last_allocs = alloc;
9675         last_total = total;
9676 }
9677
9678 static void cmd_dump_parsed(void *parsed_result,
9679                             __rte_unused struct cmdline *cl,
9680                             __rte_unused void *data)
9681 {
9682         struct cmd_dump_result *res = parsed_result;
9683
9684         if (!strcmp(res->dump, "dump_physmem"))
9685                 rte_dump_physmem_layout(stdout);
9686         else if (!strcmp(res->dump, "dump_socket_mem"))
9687                 dump_socket_mem(stdout);
9688         else if (!strcmp(res->dump, "dump_memzone"))
9689                 rte_memzone_dump(stdout);
9690         else if (!strcmp(res->dump, "dump_struct_sizes"))
9691                 dump_struct_sizes();
9692         else if (!strcmp(res->dump, "dump_ring"))
9693                 rte_ring_list_dump(stdout);
9694         else if (!strcmp(res->dump, "dump_mempool"))
9695                 rte_mempool_list_dump(stdout);
9696         else if (!strcmp(res->dump, "dump_devargs"))
9697                 rte_devargs_dump(stdout);
9698         else if (!strcmp(res->dump, "dump_log_types"))
9699                 rte_log_dump(stdout);
9700 }
9701
9702 cmdline_parse_token_string_t cmd_dump_dump =
9703         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9704                 "dump_physmem#"
9705                 "dump_memzone#"
9706                 "dump_socket_mem#"
9707                 "dump_struct_sizes#"
9708                 "dump_ring#"
9709                 "dump_mempool#"
9710                 "dump_devargs#"
9711                 "dump_log_types");
9712
9713 cmdline_parse_inst_t cmd_dump = {
9714         .f = cmd_dump_parsed,  /* function to call */
9715         .data = NULL,      /* 2nd arg of func */
9716         .help_str = "Dump status",
9717         .tokens = {        /* token list, NULL terminated */
9718                 (void *)&cmd_dump_dump,
9719                 NULL,
9720         },
9721 };
9722
9723 /* ******************************************************************************** */
9724
9725 struct cmd_dump_one_result {
9726         cmdline_fixed_string_t dump;
9727         cmdline_fixed_string_t name;
9728 };
9729
9730 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9731                                 __rte_unused void *data)
9732 {
9733         struct cmd_dump_one_result *res = parsed_result;
9734
9735         if (!strcmp(res->dump, "dump_ring")) {
9736                 struct rte_ring *r;
9737                 r = rte_ring_lookup(res->name);
9738                 if (r == NULL) {
9739                         cmdline_printf(cl, "Cannot find ring\n");
9740                         return;
9741                 }
9742                 rte_ring_dump(stdout, r);
9743         } else if (!strcmp(res->dump, "dump_mempool")) {
9744                 struct rte_mempool *mp;
9745                 mp = rte_mempool_lookup(res->name);
9746                 if (mp == NULL) {
9747                         cmdline_printf(cl, "Cannot find mempool\n");
9748                         return;
9749                 }
9750                 rte_mempool_dump(stdout, mp);
9751         }
9752 }
9753
9754 cmdline_parse_token_string_t cmd_dump_one_dump =
9755         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9756                                  "dump_ring#dump_mempool");
9757
9758 cmdline_parse_token_string_t cmd_dump_one_name =
9759         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9760
9761 cmdline_parse_inst_t cmd_dump_one = {
9762         .f = cmd_dump_one_parsed,  /* function to call */
9763         .data = NULL,      /* 2nd arg of func */
9764         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9765         .tokens = {        /* token list, NULL terminated */
9766                 (void *)&cmd_dump_one_dump,
9767                 (void *)&cmd_dump_one_name,
9768                 NULL,
9769         },
9770 };
9771
9772 /* *** queue region set *** */
9773 struct cmd_queue_region_result {
9774         cmdline_fixed_string_t set;
9775         cmdline_fixed_string_t port;
9776         portid_t port_id;
9777         cmdline_fixed_string_t cmd;
9778         cmdline_fixed_string_t region;
9779         uint8_t  region_id;
9780         cmdline_fixed_string_t queue_start_index;
9781         uint8_t  queue_id;
9782         cmdline_fixed_string_t queue_num;
9783         uint8_t  queue_num_value;
9784 };
9785
9786 static void
9787 cmd_queue_region_parsed(void *parsed_result,
9788                         __rte_unused struct cmdline *cl,
9789                         __rte_unused void *data)
9790 {
9791         struct cmd_queue_region_result *res = parsed_result;
9792         int ret = -ENOTSUP;
9793 #ifdef RTE_NET_I40E
9794         struct rte_pmd_i40e_queue_region_conf region_conf;
9795         enum rte_pmd_i40e_queue_region_op op_type;
9796 #endif
9797
9798         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9799                 return;
9800
9801 #ifdef RTE_NET_I40E
9802         memset(&region_conf, 0, sizeof(region_conf));
9803         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9804         region_conf.region_id = res->region_id;
9805         region_conf.queue_num = res->queue_num_value;
9806         region_conf.queue_start_index = res->queue_id;
9807
9808         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9809                                 op_type, &region_conf);
9810 #endif
9811
9812         switch (ret) {
9813         case 0:
9814                 break;
9815         case -ENOTSUP:
9816                 printf("function not implemented or supported\n");
9817                 break;
9818         default:
9819                 printf("queue region config error: (%s)\n", strerror(-ret));
9820         }
9821 }
9822
9823 cmdline_parse_token_string_t cmd_queue_region_set =
9824 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9825                 set, "set");
9826 cmdline_parse_token_string_t cmd_queue_region_port =
9827         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9828 cmdline_parse_token_num_t cmd_queue_region_port_id =
9829         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9830                                 port_id, UINT16);
9831 cmdline_parse_token_string_t cmd_queue_region_cmd =
9832         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9833                                  cmd, "queue-region");
9834 cmdline_parse_token_string_t cmd_queue_region_id =
9835         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9836                                 region, "region_id");
9837 cmdline_parse_token_num_t cmd_queue_region_index =
9838         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9839                                 region_id, UINT8);
9840 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9841         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9842                                 queue_start_index, "queue_start_index");
9843 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9844         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9845                                 queue_id, UINT8);
9846 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9847         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9848                                 queue_num, "queue_num");
9849 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9850         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9851                                 queue_num_value, UINT8);
9852
9853 cmdline_parse_inst_t cmd_queue_region = {
9854         .f = cmd_queue_region_parsed,
9855         .data = NULL,
9856         .help_str = "set port <port_id> queue-region region_id <value> "
9857                 "queue_start_index <value> queue_num <value>: Set a queue region",
9858         .tokens = {
9859                 (void *)&cmd_queue_region_set,
9860                 (void *)&cmd_queue_region_port,
9861                 (void *)&cmd_queue_region_port_id,
9862                 (void *)&cmd_queue_region_cmd,
9863                 (void *)&cmd_queue_region_id,
9864                 (void *)&cmd_queue_region_index,
9865                 (void *)&cmd_queue_region_queue_start_index,
9866                 (void *)&cmd_queue_region_queue_id,
9867                 (void *)&cmd_queue_region_queue_num,
9868                 (void *)&cmd_queue_region_queue_num_value,
9869                 NULL,
9870         },
9871 };
9872
9873 /* *** queue region and flowtype set *** */
9874 struct cmd_region_flowtype_result {
9875         cmdline_fixed_string_t set;
9876         cmdline_fixed_string_t port;
9877         portid_t port_id;
9878         cmdline_fixed_string_t cmd;
9879         cmdline_fixed_string_t region;
9880         uint8_t  region_id;
9881         cmdline_fixed_string_t flowtype;
9882         uint8_t  flowtype_id;
9883 };
9884
9885 static void
9886 cmd_region_flowtype_parsed(void *parsed_result,
9887                         __rte_unused struct cmdline *cl,
9888                         __rte_unused void *data)
9889 {
9890         struct cmd_region_flowtype_result *res = parsed_result;
9891         int ret = -ENOTSUP;
9892 #ifdef RTE_NET_I40E
9893         struct rte_pmd_i40e_queue_region_conf region_conf;
9894         enum rte_pmd_i40e_queue_region_op op_type;
9895 #endif
9896
9897         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9898                 return;
9899
9900 #ifdef RTE_NET_I40E
9901         memset(&region_conf, 0, sizeof(region_conf));
9902
9903         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9904         region_conf.region_id = res->region_id;
9905         region_conf.hw_flowtype = res->flowtype_id;
9906
9907         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9908                         op_type, &region_conf);
9909 #endif
9910
9911         switch (ret) {
9912         case 0:
9913                 break;
9914         case -ENOTSUP:
9915                 printf("function not implemented or supported\n");
9916                 break;
9917         default:
9918                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9919         }
9920 }
9921
9922 cmdline_parse_token_string_t cmd_region_flowtype_set =
9923 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9924                                 set, "set");
9925 cmdline_parse_token_string_t cmd_region_flowtype_port =
9926         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9927                                 port, "port");
9928 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9929         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9930                                 port_id, UINT16);
9931 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9932         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9933                                 cmd, "queue-region");
9934 cmdline_parse_token_string_t cmd_region_flowtype_index =
9935         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9936                                 region, "region_id");
9937 cmdline_parse_token_num_t cmd_region_flowtype_id =
9938         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9939                                 region_id, UINT8);
9940 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9941         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9942                                 flowtype, "flowtype");
9943 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9944         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9945                                 flowtype_id, UINT8);
9946 cmdline_parse_inst_t cmd_region_flowtype = {
9947         .f = cmd_region_flowtype_parsed,
9948         .data = NULL,
9949         .help_str = "set port <port_id> queue-region region_id <value> "
9950                 "flowtype <value>: Set a flowtype region index",
9951         .tokens = {
9952                 (void *)&cmd_region_flowtype_set,
9953                 (void *)&cmd_region_flowtype_port,
9954                 (void *)&cmd_region_flowtype_port_index,
9955                 (void *)&cmd_region_flowtype_cmd,
9956                 (void *)&cmd_region_flowtype_index,
9957                 (void *)&cmd_region_flowtype_id,
9958                 (void *)&cmd_region_flowtype_flow_index,
9959                 (void *)&cmd_region_flowtype_flow_id,
9960                 NULL,
9961         },
9962 };
9963
9964 /* *** User Priority (UP) to queue region (region_id) set *** */
9965 struct cmd_user_priority_region_result {
9966         cmdline_fixed_string_t set;
9967         cmdline_fixed_string_t port;
9968         portid_t port_id;
9969         cmdline_fixed_string_t cmd;
9970         cmdline_fixed_string_t user_priority;
9971         uint8_t  user_priority_id;
9972         cmdline_fixed_string_t region;
9973         uint8_t  region_id;
9974 };
9975
9976 static void
9977 cmd_user_priority_region_parsed(void *parsed_result,
9978                         __rte_unused struct cmdline *cl,
9979                         __rte_unused void *data)
9980 {
9981         struct cmd_user_priority_region_result *res = parsed_result;
9982         int ret = -ENOTSUP;
9983 #ifdef RTE_NET_I40E
9984         struct rte_pmd_i40e_queue_region_conf region_conf;
9985         enum rte_pmd_i40e_queue_region_op op_type;
9986 #endif
9987
9988         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9989                 return;
9990
9991 #ifdef RTE_NET_I40E
9992         memset(&region_conf, 0, sizeof(region_conf));
9993         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9994         region_conf.user_priority = res->user_priority_id;
9995         region_conf.region_id = res->region_id;
9996
9997         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9998                                 op_type, &region_conf);
9999 #endif
10000
10001         switch (ret) {
10002         case 0:
10003                 break;
10004         case -ENOTSUP:
10005                 printf("function not implemented or supported\n");
10006                 break;
10007         default:
10008                 printf("user_priority region config error: (%s)\n",
10009                                 strerror(-ret));
10010         }
10011 }
10012
10013 cmdline_parse_token_string_t cmd_user_priority_region_set =
10014         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10015                                 set, "set");
10016 cmdline_parse_token_string_t cmd_user_priority_region_port =
10017         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10018                                 port, "port");
10019 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10020         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10021                                 port_id, UINT16);
10022 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10023         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10024                                 cmd, "queue-region");
10025 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10026         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10027                                 user_priority, "UP");
10028 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10029         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10030                                 user_priority_id, UINT8);
10031 cmdline_parse_token_string_t cmd_user_priority_region_region =
10032         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10033                                 region, "region_id");
10034 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10035         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10036                                 region_id, UINT8);
10037
10038 cmdline_parse_inst_t cmd_user_priority_region = {
10039         .f = cmd_user_priority_region_parsed,
10040         .data = NULL,
10041         .help_str = "set port <port_id> queue-region UP <value> "
10042                 "region_id <value>: Set the mapping of User Priority (UP) "
10043                 "to queue region (region_id) ",
10044         .tokens = {
10045                 (void *)&cmd_user_priority_region_set,
10046                 (void *)&cmd_user_priority_region_port,
10047                 (void *)&cmd_user_priority_region_port_index,
10048                 (void *)&cmd_user_priority_region_cmd,
10049                 (void *)&cmd_user_priority_region_UP,
10050                 (void *)&cmd_user_priority_region_UP_id,
10051                 (void *)&cmd_user_priority_region_region,
10052                 (void *)&cmd_user_priority_region_region_id,
10053                 NULL,
10054         },
10055 };
10056
10057 /* *** flush all queue region related configuration *** */
10058 struct cmd_flush_queue_region_result {
10059         cmdline_fixed_string_t set;
10060         cmdline_fixed_string_t port;
10061         portid_t port_id;
10062         cmdline_fixed_string_t cmd;
10063         cmdline_fixed_string_t flush;
10064         cmdline_fixed_string_t what;
10065 };
10066
10067 static void
10068 cmd_flush_queue_region_parsed(void *parsed_result,
10069                         __rte_unused struct cmdline *cl,
10070                         __rte_unused void *data)
10071 {
10072         struct cmd_flush_queue_region_result *res = parsed_result;
10073         int ret = -ENOTSUP;
10074 #ifdef RTE_NET_I40E
10075         struct rte_pmd_i40e_queue_region_conf region_conf;
10076         enum rte_pmd_i40e_queue_region_op op_type;
10077 #endif
10078
10079         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10080                 return;
10081
10082 #ifdef RTE_NET_I40E
10083         memset(&region_conf, 0, sizeof(region_conf));
10084
10085         if (strcmp(res->what, "on") == 0)
10086                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10087         else
10088                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10089
10090         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10091                                 op_type, &region_conf);
10092 #endif
10093
10094         switch (ret) {
10095         case 0:
10096                 break;
10097         case -ENOTSUP:
10098                 printf("function not implemented or supported\n");
10099                 break;
10100         default:
10101                 printf("queue region config flush error: (%s)\n",
10102                                 strerror(-ret));
10103         }
10104 }
10105
10106 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10107         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10108                                 set, "set");
10109 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10110         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10111                                 port, "port");
10112 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10113         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10114                                 port_id, UINT16);
10115 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10116         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10117                                 cmd, "queue-region");
10118 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10119         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10120                                 flush, "flush");
10121 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10122         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10123                                 what, "on#off");
10124
10125 cmdline_parse_inst_t cmd_flush_queue_region = {
10126         .f = cmd_flush_queue_region_parsed,
10127         .data = NULL,
10128         .help_str = "set port <port_id> queue-region flush on|off"
10129                 ": flush all queue region related configuration",
10130         .tokens = {
10131                 (void *)&cmd_flush_queue_region_set,
10132                 (void *)&cmd_flush_queue_region_port,
10133                 (void *)&cmd_flush_queue_region_port_index,
10134                 (void *)&cmd_flush_queue_region_cmd,
10135                 (void *)&cmd_flush_queue_region_flush,
10136                 (void *)&cmd_flush_queue_region_what,
10137                 NULL,
10138         },
10139 };
10140
10141 /* *** get all queue region related configuration info *** */
10142 struct cmd_show_queue_region_info {
10143         cmdline_fixed_string_t show;
10144         cmdline_fixed_string_t port;
10145         portid_t port_id;
10146         cmdline_fixed_string_t cmd;
10147 };
10148
10149 static void
10150 cmd_show_queue_region_info_parsed(void *parsed_result,
10151                         __rte_unused struct cmdline *cl,
10152                         __rte_unused void *data)
10153 {
10154         struct cmd_show_queue_region_info *res = parsed_result;
10155         int ret = -ENOTSUP;
10156 #ifdef RTE_NET_I40E
10157         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10158         enum rte_pmd_i40e_queue_region_op op_type;
10159 #endif
10160
10161         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10162                 return;
10163
10164 #ifdef RTE_NET_I40E
10165         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10166
10167         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10168
10169         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10170                                         op_type, &rte_pmd_regions);
10171
10172         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10173 #endif
10174
10175         switch (ret) {
10176         case 0:
10177                 break;
10178         case -ENOTSUP:
10179                 printf("function not implemented or supported\n");
10180                 break;
10181         default:
10182                 printf("queue region config info show error: (%s)\n",
10183                                 strerror(-ret));
10184         }
10185 }
10186
10187 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10188 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10189                                 show, "show");
10190 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10191         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10192                                 port, "port");
10193 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10194         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10195                                 port_id, UINT16);
10196 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10197         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10198                                 cmd, "queue-region");
10199
10200 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10201         .f = cmd_show_queue_region_info_parsed,
10202         .data = NULL,
10203         .help_str = "show port <port_id> queue-region"
10204                 ": show all queue region related configuration info",
10205         .tokens = {
10206                 (void *)&cmd_show_queue_region_info_get,
10207                 (void *)&cmd_show_queue_region_info_port,
10208                 (void *)&cmd_show_queue_region_info_port_index,
10209                 (void *)&cmd_show_queue_region_info_cmd,
10210                 NULL,
10211         },
10212 };
10213
10214 /* *** Filters Control *** */
10215
10216 /* *** deal with flow director filter *** */
10217 struct cmd_flow_director_result {
10218         cmdline_fixed_string_t flow_director_filter;
10219         portid_t port_id;
10220         cmdline_fixed_string_t mode;
10221         cmdline_fixed_string_t mode_value;
10222         cmdline_fixed_string_t ops;
10223         cmdline_fixed_string_t flow;
10224         cmdline_fixed_string_t flow_type;
10225         cmdline_fixed_string_t ether;
10226         uint16_t ether_type;
10227         cmdline_fixed_string_t src;
10228         cmdline_ipaddr_t ip_src;
10229         uint16_t port_src;
10230         cmdline_fixed_string_t dst;
10231         cmdline_ipaddr_t ip_dst;
10232         uint16_t port_dst;
10233         cmdline_fixed_string_t verify_tag;
10234         uint32_t verify_tag_value;
10235         cmdline_fixed_string_t tos;
10236         uint8_t tos_value;
10237         cmdline_fixed_string_t proto;
10238         uint8_t proto_value;
10239         cmdline_fixed_string_t ttl;
10240         uint8_t ttl_value;
10241         cmdline_fixed_string_t vlan;
10242         uint16_t vlan_value;
10243         cmdline_fixed_string_t flexbytes;
10244         cmdline_fixed_string_t flexbytes_value;
10245         cmdline_fixed_string_t pf_vf;
10246         cmdline_fixed_string_t drop;
10247         cmdline_fixed_string_t queue;
10248         uint16_t  queue_id;
10249         cmdline_fixed_string_t fd_id;
10250         uint32_t  fd_id_value;
10251         cmdline_fixed_string_t mac;
10252         struct rte_ether_addr mac_addr;
10253         cmdline_fixed_string_t tunnel;
10254         cmdline_fixed_string_t tunnel_type;
10255         cmdline_fixed_string_t tunnel_id;
10256         uint32_t tunnel_id_value;
10257         cmdline_fixed_string_t packet;
10258         char filepath[];
10259 };
10260
10261 static inline int
10262 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10263 {
10264         char s[256];
10265         const char *p, *p0 = q_arg;
10266         char *end;
10267         unsigned long int_fld;
10268         char *str_fld[max_num];
10269         int i;
10270         unsigned size;
10271         int ret = -1;
10272
10273         p = strchr(p0, '(');
10274         if (p == NULL)
10275                 return -1;
10276         ++p;
10277         p0 = strchr(p, ')');
10278         if (p0 == NULL)
10279                 return -1;
10280
10281         size = p0 - p;
10282         if (size >= sizeof(s))
10283                 return -1;
10284
10285         snprintf(s, sizeof(s), "%.*s", size, p);
10286         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10287         if (ret < 0 || ret > max_num)
10288                 return -1;
10289         for (i = 0; i < ret; i++) {
10290                 errno = 0;
10291                 int_fld = strtoul(str_fld[i], &end, 0);
10292                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10293                         return -1;
10294                 flexbytes[i] = (uint8_t)int_fld;
10295         }
10296         return ret;
10297 }
10298
10299 static uint16_t
10300 str2flowtype(char *string)
10301 {
10302         uint8_t i = 0;
10303         static const struct {
10304                 char str[32];
10305                 uint16_t type;
10306         } flowtype_str[] = {
10307                 {"raw", RTE_ETH_FLOW_RAW},
10308                 {"ipv4", RTE_ETH_FLOW_IPV4},
10309                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10310                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10311                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10312                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10313                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10314                 {"ipv6", RTE_ETH_FLOW_IPV6},
10315                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10316                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10317                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10318                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10319                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10320                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10321         };
10322
10323         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10324                 if (!strcmp(flowtype_str[i].str, string))
10325                         return flowtype_str[i].type;
10326         }
10327
10328         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10329                 return (uint16_t)atoi(string);
10330
10331         return RTE_ETH_FLOW_UNKNOWN;
10332 }
10333
10334 static enum rte_eth_fdir_tunnel_type
10335 str2fdir_tunneltype(char *string)
10336 {
10337         uint8_t i = 0;
10338
10339         static const struct {
10340                 char str[32];
10341                 enum rte_eth_fdir_tunnel_type type;
10342         } tunneltype_str[] = {
10343                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10344                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10345         };
10346
10347         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10348                 if (!strcmp(tunneltype_str[i].str, string))
10349                         return tunneltype_str[i].type;
10350         }
10351         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10352 }
10353
10354 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10355 do { \
10356         if ((ip_addr).family == AF_INET) \
10357                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10358         else { \
10359                 printf("invalid parameter.\n"); \
10360                 return; \
10361         } \
10362 } while (0)
10363
10364 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10365 do { \
10366         if ((ip_addr).family == AF_INET6) \
10367                 rte_memcpy(&(ip), \
10368                                  &((ip_addr).addr.ipv6), \
10369                                  sizeof(struct in6_addr)); \
10370         else { \
10371                 printf("invalid parameter.\n"); \
10372                 return; \
10373         } \
10374 } while (0)
10375
10376 static void
10377 cmd_flow_director_filter_parsed(void *parsed_result,
10378                           __rte_unused struct cmdline *cl,
10379                           __rte_unused void *data)
10380 {
10381         struct cmd_flow_director_result *res = parsed_result;
10382         struct rte_eth_fdir_filter entry;
10383         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10384         char *end;
10385         unsigned long vf_id;
10386         int ret = 0;
10387
10388         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10389         if (ret < 0) {
10390                 printf("flow director is not supported on port %u.\n",
10391                         res->port_id);
10392                 return;
10393         }
10394         memset(flexbytes, 0, sizeof(flexbytes));
10395         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10396
10397         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10398                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10399                         printf("Please set mode to MAC-VLAN.\n");
10400                         return;
10401                 }
10402         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10403                 if (strcmp(res->mode_value, "Tunnel")) {
10404                         printf("Please set mode to Tunnel.\n");
10405                         return;
10406                 }
10407         } else {
10408                 if (!strcmp(res->mode_value, "raw")) {
10409 #ifdef RTE_NET_I40E
10410                         struct rte_pmd_i40e_flow_type_mapping
10411                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10412                         struct rte_pmd_i40e_pkt_template_conf conf;
10413                         uint16_t flow_type = str2flowtype(res->flow_type);
10414                         uint16_t i, port = res->port_id;
10415                         uint8_t add;
10416
10417                         memset(&conf, 0, sizeof(conf));
10418
10419                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10420                                 printf("Invalid flow type specified.\n");
10421                                 return;
10422                         }
10423                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10424                                                                  mapping);
10425                         if (ret)
10426                                 return;
10427                         if (mapping[flow_type].pctype == 0ULL) {
10428                                 printf("Invalid flow type specified.\n");
10429                                 return;
10430                         }
10431                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10432                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10433                                         conf.input.pctype = i;
10434                                         break;
10435                                 }
10436                         }
10437
10438                         conf.input.packet = open_file(res->filepath,
10439                                                 &conf.input.length);
10440                         if (!conf.input.packet)
10441                                 return;
10442                         if (!strcmp(res->drop, "drop"))
10443                                 conf.action.behavior =
10444                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10445                         else
10446                                 conf.action.behavior =
10447                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10448                         conf.action.report_status =
10449                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10450                         conf.action.rx_queue = res->queue_id;
10451                         conf.soft_id = res->fd_id_value;
10452                         add  = strcmp(res->ops, "del") ? 1 : 0;
10453                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10454                                                                         &conf,
10455                                                                         add);
10456                         if (ret < 0)
10457                                 printf("flow director config error: (%s)\n",
10458                                        strerror(-ret));
10459                         close_file(conf.input.packet);
10460 #endif
10461                         return;
10462                 } else if (strcmp(res->mode_value, "IP")) {
10463                         printf("Please set mode to IP or raw.\n");
10464                         return;
10465                 }
10466                 entry.input.flow_type = str2flowtype(res->flow_type);
10467         }
10468
10469         ret = parse_flexbytes(res->flexbytes_value,
10470                                         flexbytes,
10471                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10472         if (ret < 0) {
10473                 printf("error: Cannot parse flexbytes input.\n");
10474                 return;
10475         }
10476
10477         switch (entry.input.flow_type) {
10478         case RTE_ETH_FLOW_FRAG_IPV4:
10479         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10480                 entry.input.flow.ip4_flow.proto = res->proto_value;
10481                 /* fall-through */
10482         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10483         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10484                 IPV4_ADDR_TO_UINT(res->ip_dst,
10485                         entry.input.flow.ip4_flow.dst_ip);
10486                 IPV4_ADDR_TO_UINT(res->ip_src,
10487                         entry.input.flow.ip4_flow.src_ip);
10488                 entry.input.flow.ip4_flow.tos = res->tos_value;
10489                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10490                 /* need convert to big endian. */
10491                 entry.input.flow.udp4_flow.dst_port =
10492                                 rte_cpu_to_be_16(res->port_dst);
10493                 entry.input.flow.udp4_flow.src_port =
10494                                 rte_cpu_to_be_16(res->port_src);
10495                 break;
10496         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10497                 IPV4_ADDR_TO_UINT(res->ip_dst,
10498                         entry.input.flow.sctp4_flow.ip.dst_ip);
10499                 IPV4_ADDR_TO_UINT(res->ip_src,
10500                         entry.input.flow.sctp4_flow.ip.src_ip);
10501                 entry.input.flow.ip4_flow.tos = res->tos_value;
10502                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10503                 /* need convert to big endian. */
10504                 entry.input.flow.sctp4_flow.dst_port =
10505                                 rte_cpu_to_be_16(res->port_dst);
10506                 entry.input.flow.sctp4_flow.src_port =
10507                                 rte_cpu_to_be_16(res->port_src);
10508                 entry.input.flow.sctp4_flow.verify_tag =
10509                                 rte_cpu_to_be_32(res->verify_tag_value);
10510                 break;
10511         case RTE_ETH_FLOW_FRAG_IPV6:
10512         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10513                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10514                 /* fall-through */
10515         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10516         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10517                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10518                         entry.input.flow.ipv6_flow.dst_ip);
10519                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10520                         entry.input.flow.ipv6_flow.src_ip);
10521                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10522                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10523                 /* need convert to big endian. */
10524                 entry.input.flow.udp6_flow.dst_port =
10525                                 rte_cpu_to_be_16(res->port_dst);
10526                 entry.input.flow.udp6_flow.src_port =
10527                                 rte_cpu_to_be_16(res->port_src);
10528                 break;
10529         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10530                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10531                         entry.input.flow.sctp6_flow.ip.dst_ip);
10532                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10533                         entry.input.flow.sctp6_flow.ip.src_ip);
10534                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10535                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10536                 /* need convert to big endian. */
10537                 entry.input.flow.sctp6_flow.dst_port =
10538                                 rte_cpu_to_be_16(res->port_dst);
10539                 entry.input.flow.sctp6_flow.src_port =
10540                                 rte_cpu_to_be_16(res->port_src);
10541                 entry.input.flow.sctp6_flow.verify_tag =
10542                                 rte_cpu_to_be_32(res->verify_tag_value);
10543                 break;
10544         case RTE_ETH_FLOW_L2_PAYLOAD:
10545                 entry.input.flow.l2_flow.ether_type =
10546                         rte_cpu_to_be_16(res->ether_type);
10547                 break;
10548         default:
10549                 break;
10550         }
10551
10552         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10553                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10554                                  &res->mac_addr,
10555                                  sizeof(struct rte_ether_addr));
10556
10557         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10558                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10559                                  &res->mac_addr,
10560                                  sizeof(struct rte_ether_addr));
10561                 entry.input.flow.tunnel_flow.tunnel_type =
10562                         str2fdir_tunneltype(res->tunnel_type);
10563                 entry.input.flow.tunnel_flow.tunnel_id =
10564                         rte_cpu_to_be_32(res->tunnel_id_value);
10565         }
10566
10567         rte_memcpy(entry.input.flow_ext.flexbytes,
10568                    flexbytes,
10569                    RTE_ETH_FDIR_MAX_FLEXLEN);
10570
10571         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10572
10573         entry.action.flex_off = 0;  /*use 0 by default */
10574         if (!strcmp(res->drop, "drop"))
10575                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10576         else
10577                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10578
10579         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10580             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10581                 if (!strcmp(res->pf_vf, "pf"))
10582                         entry.input.flow_ext.is_vf = 0;
10583                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10584                         struct rte_eth_dev_info dev_info;
10585
10586                         ret = eth_dev_info_get_print_err(res->port_id,
10587                                                 &dev_info);
10588                         if (ret != 0)
10589                                 return;
10590
10591                         errno = 0;
10592                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10593                         if (errno != 0 || *end != '\0' ||
10594                             vf_id >= dev_info.max_vfs) {
10595                                 printf("invalid parameter %s.\n", res->pf_vf);
10596                                 return;
10597                         }
10598                         entry.input.flow_ext.is_vf = 1;
10599                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10600                 } else {
10601                         printf("invalid parameter %s.\n", res->pf_vf);
10602                         return;
10603                 }
10604         }
10605
10606         /* set to report FD ID by default */
10607         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10608         entry.action.rx_queue = res->queue_id;
10609         entry.soft_id = res->fd_id_value;
10610         if (!strcmp(res->ops, "add"))
10611                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10612                                              RTE_ETH_FILTER_ADD, &entry);
10613         else if (!strcmp(res->ops, "del"))
10614                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10615                                              RTE_ETH_FILTER_DELETE, &entry);
10616         else
10617                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10618                                              RTE_ETH_FILTER_UPDATE, &entry);
10619         if (ret < 0)
10620                 printf("flow director programming error: (%s)\n",
10621                         strerror(-ret));
10622 }
10623
10624 cmdline_parse_token_string_t cmd_flow_director_filter =
10625         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10626                                  flow_director_filter, "flow_director_filter");
10627 cmdline_parse_token_num_t cmd_flow_director_port_id =
10628         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10629                               port_id, UINT16);
10630 cmdline_parse_token_string_t cmd_flow_director_ops =
10631         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10632                                  ops, "add#del#update");
10633 cmdline_parse_token_string_t cmd_flow_director_flow =
10634         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10635                                  flow, "flow");
10636 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10637         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10638                 flow_type, NULL);
10639 cmdline_parse_token_string_t cmd_flow_director_ether =
10640         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10641                                  ether, "ether");
10642 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10643         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10644                               ether_type, UINT16);
10645 cmdline_parse_token_string_t cmd_flow_director_src =
10646         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10647                                  src, "src");
10648 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10649         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10650                                  ip_src);
10651 cmdline_parse_token_num_t cmd_flow_director_port_src =
10652         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10653                               port_src, UINT16);
10654 cmdline_parse_token_string_t cmd_flow_director_dst =
10655         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10656                                  dst, "dst");
10657 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10658         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10659                                  ip_dst);
10660 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10661         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10662                               port_dst, UINT16);
10663 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10664         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10665                                   verify_tag, "verify_tag");
10666 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10667         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10668                               verify_tag_value, UINT32);
10669 cmdline_parse_token_string_t cmd_flow_director_tos =
10670         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10671                                  tos, "tos");
10672 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10673         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10674                               tos_value, UINT8);
10675 cmdline_parse_token_string_t cmd_flow_director_proto =
10676         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10677                                  proto, "proto");
10678 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10679         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10680                               proto_value, UINT8);
10681 cmdline_parse_token_string_t cmd_flow_director_ttl =
10682         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10683                                  ttl, "ttl");
10684 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10685         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10686                               ttl_value, UINT8);
10687 cmdline_parse_token_string_t cmd_flow_director_vlan =
10688         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10689                                  vlan, "vlan");
10690 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10691         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10692                               vlan_value, UINT16);
10693 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10694         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10695                                  flexbytes, "flexbytes");
10696 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10697         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10698                               flexbytes_value, NULL);
10699 cmdline_parse_token_string_t cmd_flow_director_drop =
10700         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10701                                  drop, "drop#fwd");
10702 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10703         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10704                               pf_vf, NULL);
10705 cmdline_parse_token_string_t cmd_flow_director_queue =
10706         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10707                                  queue, "queue");
10708 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10709         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10710                               queue_id, UINT16);
10711 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10712         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10713                                  fd_id, "fd_id");
10714 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10715         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10716                               fd_id_value, UINT32);
10717
10718 cmdline_parse_token_string_t cmd_flow_director_mode =
10719         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10720                                  mode, "mode");
10721 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10722         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10723                                  mode_value, "IP");
10724 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10725         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10726                                  mode_value, "MAC-VLAN");
10727 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10728         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10729                                  mode_value, "Tunnel");
10730 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10731         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10732                                  mode_value, "raw");
10733 cmdline_parse_token_string_t cmd_flow_director_mac =
10734         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10735                                  mac, "mac");
10736 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10737         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10738                                     mac_addr);
10739 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10740         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10741                                  tunnel, "tunnel");
10742 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10743         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10744                                  tunnel_type, "NVGRE#VxLAN");
10745 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10746         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10747                                  tunnel_id, "tunnel-id");
10748 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10749         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10750                               tunnel_id_value, UINT32);
10751 cmdline_parse_token_string_t cmd_flow_director_packet =
10752         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10753                                  packet, "packet");
10754 cmdline_parse_token_string_t cmd_flow_director_filepath =
10755         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10756                                  filepath, NULL);
10757
10758 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10759         .f = cmd_flow_director_filter_parsed,
10760         .data = NULL,
10761         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10762                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10763                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10764                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10765                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10766                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10767                 "fd_id <fd_id_value>: "
10768                 "Add or delete an ip flow director entry on NIC",
10769         .tokens = {
10770                 (void *)&cmd_flow_director_filter,
10771                 (void *)&cmd_flow_director_port_id,
10772                 (void *)&cmd_flow_director_mode,
10773                 (void *)&cmd_flow_director_mode_ip,
10774                 (void *)&cmd_flow_director_ops,
10775                 (void *)&cmd_flow_director_flow,
10776                 (void *)&cmd_flow_director_flow_type,
10777                 (void *)&cmd_flow_director_src,
10778                 (void *)&cmd_flow_director_ip_src,
10779                 (void *)&cmd_flow_director_dst,
10780                 (void *)&cmd_flow_director_ip_dst,
10781                 (void *)&cmd_flow_director_tos,
10782                 (void *)&cmd_flow_director_tos_value,
10783                 (void *)&cmd_flow_director_proto,
10784                 (void *)&cmd_flow_director_proto_value,
10785                 (void *)&cmd_flow_director_ttl,
10786                 (void *)&cmd_flow_director_ttl_value,
10787                 (void *)&cmd_flow_director_vlan,
10788                 (void *)&cmd_flow_director_vlan_value,
10789                 (void *)&cmd_flow_director_flexbytes,
10790                 (void *)&cmd_flow_director_flexbytes_value,
10791                 (void *)&cmd_flow_director_drop,
10792                 (void *)&cmd_flow_director_pf_vf,
10793                 (void *)&cmd_flow_director_queue,
10794                 (void *)&cmd_flow_director_queue_id,
10795                 (void *)&cmd_flow_director_fd_id,
10796                 (void *)&cmd_flow_director_fd_id_value,
10797                 NULL,
10798         },
10799 };
10800
10801 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10802         .f = cmd_flow_director_filter_parsed,
10803         .data = NULL,
10804         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10805                 "director entry on NIC",
10806         .tokens = {
10807                 (void *)&cmd_flow_director_filter,
10808                 (void *)&cmd_flow_director_port_id,
10809                 (void *)&cmd_flow_director_mode,
10810                 (void *)&cmd_flow_director_mode_ip,
10811                 (void *)&cmd_flow_director_ops,
10812                 (void *)&cmd_flow_director_flow,
10813                 (void *)&cmd_flow_director_flow_type,
10814                 (void *)&cmd_flow_director_src,
10815                 (void *)&cmd_flow_director_ip_src,
10816                 (void *)&cmd_flow_director_port_src,
10817                 (void *)&cmd_flow_director_dst,
10818                 (void *)&cmd_flow_director_ip_dst,
10819                 (void *)&cmd_flow_director_port_dst,
10820                 (void *)&cmd_flow_director_tos,
10821                 (void *)&cmd_flow_director_tos_value,
10822                 (void *)&cmd_flow_director_ttl,
10823                 (void *)&cmd_flow_director_ttl_value,
10824                 (void *)&cmd_flow_director_vlan,
10825                 (void *)&cmd_flow_director_vlan_value,
10826                 (void *)&cmd_flow_director_flexbytes,
10827                 (void *)&cmd_flow_director_flexbytes_value,
10828                 (void *)&cmd_flow_director_drop,
10829                 (void *)&cmd_flow_director_pf_vf,
10830                 (void *)&cmd_flow_director_queue,
10831                 (void *)&cmd_flow_director_queue_id,
10832                 (void *)&cmd_flow_director_fd_id,
10833                 (void *)&cmd_flow_director_fd_id_value,
10834                 NULL,
10835         },
10836 };
10837
10838 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10839         .f = cmd_flow_director_filter_parsed,
10840         .data = NULL,
10841         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10842                 "director entry on NIC",
10843         .tokens = {
10844                 (void *)&cmd_flow_director_filter,
10845                 (void *)&cmd_flow_director_port_id,
10846                 (void *)&cmd_flow_director_mode,
10847                 (void *)&cmd_flow_director_mode_ip,
10848                 (void *)&cmd_flow_director_ops,
10849                 (void *)&cmd_flow_director_flow,
10850                 (void *)&cmd_flow_director_flow_type,
10851                 (void *)&cmd_flow_director_src,
10852                 (void *)&cmd_flow_director_ip_src,
10853                 (void *)&cmd_flow_director_port_src,
10854                 (void *)&cmd_flow_director_dst,
10855                 (void *)&cmd_flow_director_ip_dst,
10856                 (void *)&cmd_flow_director_port_dst,
10857                 (void *)&cmd_flow_director_verify_tag,
10858                 (void *)&cmd_flow_director_verify_tag_value,
10859                 (void *)&cmd_flow_director_tos,
10860                 (void *)&cmd_flow_director_tos_value,
10861                 (void *)&cmd_flow_director_ttl,
10862                 (void *)&cmd_flow_director_ttl_value,
10863                 (void *)&cmd_flow_director_vlan,
10864                 (void *)&cmd_flow_director_vlan_value,
10865                 (void *)&cmd_flow_director_flexbytes,
10866                 (void *)&cmd_flow_director_flexbytes_value,
10867                 (void *)&cmd_flow_director_drop,
10868                 (void *)&cmd_flow_director_pf_vf,
10869                 (void *)&cmd_flow_director_queue,
10870                 (void *)&cmd_flow_director_queue_id,
10871                 (void *)&cmd_flow_director_fd_id,
10872                 (void *)&cmd_flow_director_fd_id_value,
10873                 NULL,
10874         },
10875 };
10876
10877 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10878         .f = cmd_flow_director_filter_parsed,
10879         .data = NULL,
10880         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10881                 "director entry on NIC",
10882         .tokens = {
10883                 (void *)&cmd_flow_director_filter,
10884                 (void *)&cmd_flow_director_port_id,
10885                 (void *)&cmd_flow_director_mode,
10886                 (void *)&cmd_flow_director_mode_ip,
10887                 (void *)&cmd_flow_director_ops,
10888                 (void *)&cmd_flow_director_flow,
10889                 (void *)&cmd_flow_director_flow_type,
10890                 (void *)&cmd_flow_director_ether,
10891                 (void *)&cmd_flow_director_ether_type,
10892                 (void *)&cmd_flow_director_flexbytes,
10893                 (void *)&cmd_flow_director_flexbytes_value,
10894                 (void *)&cmd_flow_director_drop,
10895                 (void *)&cmd_flow_director_pf_vf,
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_mac_vlan_flow_director = {
10905         .f = cmd_flow_director_filter_parsed,
10906         .data = NULL,
10907         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN 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_mac_vlan,
10914                 (void *)&cmd_flow_director_ops,
10915                 (void *)&cmd_flow_director_mac,
10916                 (void *)&cmd_flow_director_mac_addr,
10917                 (void *)&cmd_flow_director_vlan,
10918                 (void *)&cmd_flow_director_vlan_value,
10919                 (void *)&cmd_flow_director_flexbytes,
10920                 (void *)&cmd_flow_director_flexbytes_value,
10921                 (void *)&cmd_flow_director_drop,
10922                 (void *)&cmd_flow_director_queue,
10923                 (void *)&cmd_flow_director_queue_id,
10924                 (void *)&cmd_flow_director_fd_id,
10925                 (void *)&cmd_flow_director_fd_id_value,
10926                 NULL,
10927         },
10928 };
10929
10930 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10931         .f = cmd_flow_director_filter_parsed,
10932         .data = NULL,
10933         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10934                 "director entry on NIC",
10935         .tokens = {
10936                 (void *)&cmd_flow_director_filter,
10937                 (void *)&cmd_flow_director_port_id,
10938                 (void *)&cmd_flow_director_mode,
10939                 (void *)&cmd_flow_director_mode_tunnel,
10940                 (void *)&cmd_flow_director_ops,
10941                 (void *)&cmd_flow_director_mac,
10942                 (void *)&cmd_flow_director_mac_addr,
10943                 (void *)&cmd_flow_director_vlan,
10944                 (void *)&cmd_flow_director_vlan_value,
10945                 (void *)&cmd_flow_director_tunnel,
10946                 (void *)&cmd_flow_director_tunnel_type,
10947                 (void *)&cmd_flow_director_tunnel_id,
10948                 (void *)&cmd_flow_director_tunnel_id_value,
10949                 (void *)&cmd_flow_director_flexbytes,
10950                 (void *)&cmd_flow_director_flexbytes_value,
10951                 (void *)&cmd_flow_director_drop,
10952                 (void *)&cmd_flow_director_queue,
10953                 (void *)&cmd_flow_director_queue_id,
10954                 (void *)&cmd_flow_director_fd_id,
10955                 (void *)&cmd_flow_director_fd_id_value,
10956                 NULL,
10957         },
10958 };
10959
10960 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10961         .f = cmd_flow_director_filter_parsed,
10962         .data = NULL,
10963         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10964                 "director entry on NIC",
10965         .tokens = {
10966                 (void *)&cmd_flow_director_filter,
10967                 (void *)&cmd_flow_director_port_id,
10968                 (void *)&cmd_flow_director_mode,
10969                 (void *)&cmd_flow_director_mode_raw,
10970                 (void *)&cmd_flow_director_ops,
10971                 (void *)&cmd_flow_director_flow,
10972                 (void *)&cmd_flow_director_flow_type,
10973                 (void *)&cmd_flow_director_drop,
10974                 (void *)&cmd_flow_director_queue,
10975                 (void *)&cmd_flow_director_queue_id,
10976                 (void *)&cmd_flow_director_fd_id,
10977                 (void *)&cmd_flow_director_fd_id_value,
10978                 (void *)&cmd_flow_director_packet,
10979                 (void *)&cmd_flow_director_filepath,
10980                 NULL,
10981         },
10982 };
10983
10984 struct cmd_flush_flow_director_result {
10985         cmdline_fixed_string_t flush_flow_director;
10986         portid_t port_id;
10987 };
10988
10989 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10990         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10991                                  flush_flow_director, "flush_flow_director");
10992 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10993         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10994                               port_id, UINT16);
10995
10996 static void
10997 cmd_flush_flow_director_parsed(void *parsed_result,
10998                           __rte_unused struct cmdline *cl,
10999                           __rte_unused void *data)
11000 {
11001         struct cmd_flow_director_result *res = parsed_result;
11002         int ret = 0;
11003
11004         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11005         if (ret < 0) {
11006                 printf("flow director is not supported on port %u.\n",
11007                         res->port_id);
11008                 return;
11009         }
11010
11011         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11012                         RTE_ETH_FILTER_FLUSH, NULL);
11013         if (ret < 0)
11014                 printf("flow director table flushing error: (%s)\n",
11015                         strerror(-ret));
11016 }
11017
11018 cmdline_parse_inst_t cmd_flush_flow_director = {
11019         .f = cmd_flush_flow_director_parsed,
11020         .data = NULL,
11021         .help_str = "flush_flow_director <port_id>: "
11022                 "Flush all flow director entries of a device on NIC",
11023         .tokens = {
11024                 (void *)&cmd_flush_flow_director_flush,
11025                 (void *)&cmd_flush_flow_director_port_id,
11026                 NULL,
11027         },
11028 };
11029
11030 /* *** deal with flow director mask *** */
11031 struct cmd_flow_director_mask_result {
11032         cmdline_fixed_string_t flow_director_mask;
11033         portid_t port_id;
11034         cmdline_fixed_string_t mode;
11035         cmdline_fixed_string_t mode_value;
11036         cmdline_fixed_string_t vlan;
11037         uint16_t vlan_mask;
11038         cmdline_fixed_string_t src_mask;
11039         cmdline_ipaddr_t ipv4_src;
11040         cmdline_ipaddr_t ipv6_src;
11041         uint16_t port_src;
11042         cmdline_fixed_string_t dst_mask;
11043         cmdline_ipaddr_t ipv4_dst;
11044         cmdline_ipaddr_t ipv6_dst;
11045         uint16_t port_dst;
11046         cmdline_fixed_string_t mac;
11047         uint8_t mac_addr_byte_mask;
11048         cmdline_fixed_string_t tunnel_id;
11049         uint32_t tunnel_id_mask;
11050         cmdline_fixed_string_t tunnel_type;
11051         uint8_t tunnel_type_mask;
11052 };
11053
11054 static void
11055 cmd_flow_director_mask_parsed(void *parsed_result,
11056                           __rte_unused struct cmdline *cl,
11057                           __rte_unused void *data)
11058 {
11059         struct cmd_flow_director_mask_result *res = parsed_result;
11060         struct rte_eth_fdir_masks *mask;
11061         struct rte_port *port;
11062
11063         port = &ports[res->port_id];
11064         /** Check if the port is not started **/
11065         if (port->port_status != RTE_PORT_STOPPED) {
11066                 printf("Please stop port %d first\n", res->port_id);
11067                 return;
11068         }
11069
11070         mask = &port->dev_conf.fdir_conf.mask;
11071
11072         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11073                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11074                         printf("Please set mode to MAC-VLAN.\n");
11075                         return;
11076                 }
11077
11078                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11079         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11080                 if (strcmp(res->mode_value, "Tunnel")) {
11081                         printf("Please set mode to Tunnel.\n");
11082                         return;
11083                 }
11084
11085                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11086                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11087                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11088                 mask->tunnel_type_mask = res->tunnel_type_mask;
11089         } else {
11090                 if (strcmp(res->mode_value, "IP")) {
11091                         printf("Please set mode to IP.\n");
11092                         return;
11093                 }
11094
11095                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11096                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11097                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11098                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11099                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11100                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11101                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11102         }
11103
11104         cmd_reconfig_device_queue(res->port_id, 1, 1);
11105 }
11106
11107 cmdline_parse_token_string_t cmd_flow_director_mask =
11108         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11109                                  flow_director_mask, "flow_director_mask");
11110 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11111         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11112                               port_id, UINT16);
11113 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11114         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11115                                  vlan, "vlan");
11116 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11117         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11118                               vlan_mask, UINT16);
11119 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11120         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11121                                  src_mask, "src_mask");
11122 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11123         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11124                                  ipv4_src);
11125 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11126         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11127                                  ipv6_src);
11128 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11129         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11130                               port_src, UINT16);
11131 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11132         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11133                                  dst_mask, "dst_mask");
11134 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11135         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11136                                  ipv4_dst);
11137 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11138         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11139                                  ipv6_dst);
11140 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11141         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11142                               port_dst, UINT16);
11143
11144 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11145         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11146                                  mode, "mode");
11147 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11148         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11149                                  mode_value, "IP");
11150 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11151         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11152                                  mode_value, "MAC-VLAN");
11153 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11154         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11155                                  mode_value, "Tunnel");
11156 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11157         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11158                                  mac, "mac");
11159 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11160         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11161                               mac_addr_byte_mask, UINT8);
11162 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11163         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11164                                  tunnel_type, "tunnel-type");
11165 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11166         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11167                               tunnel_type_mask, UINT8);
11168 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11169         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11170                                  tunnel_id, "tunnel-id");
11171 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11172         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11173                               tunnel_id_mask, UINT32);
11174
11175 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11176         .f = cmd_flow_director_mask_parsed,
11177         .data = NULL,
11178         .help_str = "flow_director_mask ... : "
11179                 "Set IP mode flow director's mask on NIC",
11180         .tokens = {
11181                 (void *)&cmd_flow_director_mask,
11182                 (void *)&cmd_flow_director_mask_port_id,
11183                 (void *)&cmd_flow_director_mask_mode,
11184                 (void *)&cmd_flow_director_mask_mode_ip,
11185                 (void *)&cmd_flow_director_mask_vlan,
11186                 (void *)&cmd_flow_director_mask_vlan_value,
11187                 (void *)&cmd_flow_director_mask_src,
11188                 (void *)&cmd_flow_director_mask_ipv4_src,
11189                 (void *)&cmd_flow_director_mask_ipv6_src,
11190                 (void *)&cmd_flow_director_mask_port_src,
11191                 (void *)&cmd_flow_director_mask_dst,
11192                 (void *)&cmd_flow_director_mask_ipv4_dst,
11193                 (void *)&cmd_flow_director_mask_ipv6_dst,
11194                 (void *)&cmd_flow_director_mask_port_dst,
11195                 NULL,
11196         },
11197 };
11198
11199 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11200         .f = cmd_flow_director_mask_parsed,
11201         .data = NULL,
11202         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11203                 "flow director's mask on NIC",
11204         .tokens = {
11205                 (void *)&cmd_flow_director_mask,
11206                 (void *)&cmd_flow_director_mask_port_id,
11207                 (void *)&cmd_flow_director_mask_mode,
11208                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11209                 (void *)&cmd_flow_director_mask_vlan,
11210                 (void *)&cmd_flow_director_mask_vlan_value,
11211                 NULL,
11212         },
11213 };
11214
11215 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11216         .f = cmd_flow_director_mask_parsed,
11217         .data = NULL,
11218         .help_str = "flow_director_mask ... : Set tunnel mode "
11219                 "flow director's mask on NIC",
11220         .tokens = {
11221                 (void *)&cmd_flow_director_mask,
11222                 (void *)&cmd_flow_director_mask_port_id,
11223                 (void *)&cmd_flow_director_mask_mode,
11224                 (void *)&cmd_flow_director_mask_mode_tunnel,
11225                 (void *)&cmd_flow_director_mask_vlan,
11226                 (void *)&cmd_flow_director_mask_vlan_value,
11227                 (void *)&cmd_flow_director_mask_mac,
11228                 (void *)&cmd_flow_director_mask_mac_value,
11229                 (void *)&cmd_flow_director_mask_tunnel_type,
11230                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11231                 (void *)&cmd_flow_director_mask_tunnel_id,
11232                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11233                 NULL,
11234         },
11235 };
11236
11237 /* *** deal with flow director mask on flexible payload *** */
11238 struct cmd_flow_director_flex_mask_result {
11239         cmdline_fixed_string_t flow_director_flexmask;
11240         portid_t port_id;
11241         cmdline_fixed_string_t flow;
11242         cmdline_fixed_string_t flow_type;
11243         cmdline_fixed_string_t mask;
11244 };
11245
11246 static void
11247 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11248                           __rte_unused struct cmdline *cl,
11249                           __rte_unused void *data)
11250 {
11251         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11252         struct rte_eth_fdir_info fdir_info;
11253         struct rte_eth_fdir_flex_mask flex_mask;
11254         struct rte_port *port;
11255         uint64_t flow_type_mask;
11256         uint16_t i;
11257         int ret;
11258
11259         port = &ports[res->port_id];
11260         /** Check if the port is not started **/
11261         if (port->port_status != RTE_PORT_STOPPED) {
11262                 printf("Please stop port %d first\n", res->port_id);
11263                 return;
11264         }
11265
11266         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11267         ret = parse_flexbytes(res->mask,
11268                         flex_mask.mask,
11269                         RTE_ETH_FDIR_MAX_FLEXLEN);
11270         if (ret < 0) {
11271                 printf("error: Cannot parse mask input.\n");
11272                 return;
11273         }
11274
11275         memset(&fdir_info, 0, sizeof(fdir_info));
11276         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11277                                 RTE_ETH_FILTER_INFO, &fdir_info);
11278         if (ret < 0) {
11279                 printf("Cannot get FDir filter info\n");
11280                 return;
11281         }
11282
11283         if (!strcmp(res->flow_type, "none")) {
11284                 /* means don't specify the flow type */
11285                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11286                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11287                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11288                                0, sizeof(struct rte_eth_fdir_flex_mask));
11289                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11290                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11291                                  &flex_mask,
11292                                  sizeof(struct rte_eth_fdir_flex_mask));
11293                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11294                 return;
11295         }
11296         flow_type_mask = fdir_info.flow_types_mask[0];
11297         if (!strcmp(res->flow_type, "all")) {
11298                 if (!flow_type_mask) {
11299                         printf("No flow type supported\n");
11300                         return;
11301                 }
11302                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11303                         if (flow_type_mask & (1ULL << i)) {
11304                                 flex_mask.flow_type = i;
11305                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11306                         }
11307                 }
11308                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11309                 return;
11310         }
11311         flex_mask.flow_type = str2flowtype(res->flow_type);
11312         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11313                 printf("Flow type %s not supported on port %d\n",
11314                                 res->flow_type, res->port_id);
11315                 return;
11316         }
11317         fdir_set_flex_mask(res->port_id, &flex_mask);
11318         cmd_reconfig_device_queue(res->port_id, 1, 1);
11319 }
11320
11321 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11322         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11323                                  flow_director_flexmask,
11324                                  "flow_director_flex_mask");
11325 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11326         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11327                               port_id, UINT16);
11328 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11329         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11330                                  flow, "flow");
11331 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11332         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11333                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11334                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11335 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11336         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11337                                  mask, NULL);
11338
11339 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11340         .f = cmd_flow_director_flex_mask_parsed,
11341         .data = NULL,
11342         .help_str = "flow_director_flex_mask ... : "
11343                 "Set flow director's flex mask on NIC",
11344         .tokens = {
11345                 (void *)&cmd_flow_director_flexmask,
11346                 (void *)&cmd_flow_director_flexmask_port_id,
11347                 (void *)&cmd_flow_director_flexmask_flow,
11348                 (void *)&cmd_flow_director_flexmask_flow_type,
11349                 (void *)&cmd_flow_director_flexmask_mask,
11350                 NULL,
11351         },
11352 };
11353
11354 /* *** deal with flow director flexible payload configuration *** */
11355 struct cmd_flow_director_flexpayload_result {
11356         cmdline_fixed_string_t flow_director_flexpayload;
11357         portid_t port_id;
11358         cmdline_fixed_string_t payload_layer;
11359         cmdline_fixed_string_t payload_cfg;
11360 };
11361
11362 static inline int
11363 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11364 {
11365         char s[256];
11366         const char *p, *p0 = q_arg;
11367         char *end;
11368         unsigned long int_fld;
11369         char *str_fld[max_num];
11370         int i;
11371         unsigned size;
11372         int ret = -1;
11373
11374         p = strchr(p0, '(');
11375         if (p == NULL)
11376                 return -1;
11377         ++p;
11378         p0 = strchr(p, ')');
11379         if (p0 == NULL)
11380                 return -1;
11381
11382         size = p0 - p;
11383         if (size >= sizeof(s))
11384                 return -1;
11385
11386         snprintf(s, sizeof(s), "%.*s", size, p);
11387         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11388         if (ret < 0 || ret > max_num)
11389                 return -1;
11390         for (i = 0; i < ret; i++) {
11391                 errno = 0;
11392                 int_fld = strtoul(str_fld[i], &end, 0);
11393                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11394                         return -1;
11395                 offsets[i] = (uint16_t)int_fld;
11396         }
11397         return ret;
11398 }
11399
11400 static void
11401 cmd_flow_director_flxpld_parsed(void *parsed_result,
11402                           __rte_unused struct cmdline *cl,
11403                           __rte_unused void *data)
11404 {
11405         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11406         struct rte_eth_flex_payload_cfg flex_cfg;
11407         struct rte_port *port;
11408         int ret = 0;
11409
11410         port = &ports[res->port_id];
11411         /** Check if the port is not started **/
11412         if (port->port_status != RTE_PORT_STOPPED) {
11413                 printf("Please stop port %d first\n", res->port_id);
11414                 return;
11415         }
11416
11417         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11418
11419         if (!strcmp(res->payload_layer, "raw"))
11420                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11421         else if (!strcmp(res->payload_layer, "l2"))
11422                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11423         else if (!strcmp(res->payload_layer, "l3"))
11424                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11425         else if (!strcmp(res->payload_layer, "l4"))
11426                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11427
11428         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11429                             RTE_ETH_FDIR_MAX_FLEXLEN);
11430         if (ret < 0) {
11431                 printf("error: Cannot parse flex payload input.\n");
11432                 return;
11433         }
11434
11435         fdir_set_flex_payload(res->port_id, &flex_cfg);
11436         cmd_reconfig_device_queue(res->port_id, 1, 1);
11437 }
11438
11439 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11441                                  flow_director_flexpayload,
11442                                  "flow_director_flex_payload");
11443 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11444         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11445                               port_id, UINT16);
11446 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11447         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11448                                  payload_layer, "raw#l2#l3#l4");
11449 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11450         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11451                                  payload_cfg, NULL);
11452
11453 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11454         .f = cmd_flow_director_flxpld_parsed,
11455         .data = NULL,
11456         .help_str = "flow_director_flexpayload ... : "
11457                 "Set flow director's flex payload on NIC",
11458         .tokens = {
11459                 (void *)&cmd_flow_director_flexpayload,
11460                 (void *)&cmd_flow_director_flexpayload_port_id,
11461                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11462                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11463                 NULL,
11464         },
11465 };
11466
11467 /* Generic flow interface command. */
11468 extern cmdline_parse_inst_t cmd_flow;
11469
11470 /* *** Classification Filters Control *** */
11471
11472 static enum rte_eth_input_set_field
11473 str2inset(char *string)
11474 {
11475         uint16_t i;
11476
11477         static const struct {
11478                 char str[32];
11479                 enum rte_eth_input_set_field inset;
11480         } inset_table[] = {
11481                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11482                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11483                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11484                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11485                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11486                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11487                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11488                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11489                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11490                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11491                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11492                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11493                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11494                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11495                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11496                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11497                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11498                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11499                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11500                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11501                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11502                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11503                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11504                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11505                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11506                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11507                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11508                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11509                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11510                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11511                 {"none", RTE_ETH_INPUT_SET_NONE},
11512         };
11513
11514         for (i = 0; i < RTE_DIM(inset_table); i++) {
11515                 if (!strcmp(string, inset_table[i].str))
11516                         return inset_table[i].inset;
11517         }
11518
11519         return RTE_ETH_INPUT_SET_UNKNOWN;
11520 }
11521
11522 /* Set flow director input set */
11523 struct cmd_set_fdir_input_set_result {
11524         cmdline_fixed_string_t set_fdir_input_set;
11525         portid_t port_id;
11526         cmdline_fixed_string_t flow_type;
11527         cmdline_fixed_string_t inset_field;
11528         cmdline_fixed_string_t select;
11529 };
11530
11531 static void
11532 cmd_set_fdir_input_set_parsed(void *parsed_result,
11533         __rte_unused struct cmdline *cl,
11534         __rte_unused void *data)
11535 {
11536         struct cmd_set_fdir_input_set_result *res = parsed_result;
11537         struct rte_eth_fdir_filter_info info;
11538
11539         memset(&info, 0, sizeof(info));
11540         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11541         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11542         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11543         info.info.input_set_conf.inset_size = 1;
11544         if (!strcmp(res->select, "select"))
11545                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11546         else if (!strcmp(res->select, "add"))
11547                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11548         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11549                 RTE_ETH_FILTER_SET, &info);
11550 }
11551
11552 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11553         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11554         set_fdir_input_set, "set_fdir_input_set");
11555 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11556         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11557         port_id, UINT16);
11558 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11559         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11560         flow_type,
11561         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11562         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11563 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11564         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11565         inset_field,
11566         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11567         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11568         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11569         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11570         "sctp-veri-tag#none");
11571 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11572         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11573         select, "select#add");
11574
11575 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11576         .f = cmd_set_fdir_input_set_parsed,
11577         .data = NULL,
11578         .help_str = "set_fdir_input_set <port_id> "
11579         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11580         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11581         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11582         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11583         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11584         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11585         "sctp-veri-tag|none select|add",
11586         .tokens = {
11587                 (void *)&cmd_set_fdir_input_set_cmd,
11588                 (void *)&cmd_set_fdir_input_set_port_id,
11589                 (void *)&cmd_set_fdir_input_set_flow_type,
11590                 (void *)&cmd_set_fdir_input_set_field,
11591                 (void *)&cmd_set_fdir_input_set_select,
11592                 NULL,
11593         },
11594 };
11595
11596 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11597 struct cmd_mcast_addr_result {
11598         cmdline_fixed_string_t mcast_addr_cmd;
11599         cmdline_fixed_string_t what;
11600         uint16_t port_num;
11601         struct rte_ether_addr mc_addr;
11602 };
11603
11604 static void cmd_mcast_addr_parsed(void *parsed_result,
11605                 __rte_unused struct cmdline *cl,
11606                 __rte_unused void *data)
11607 {
11608         struct cmd_mcast_addr_result *res = parsed_result;
11609
11610         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
11611                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11612                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11613                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11614                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11615                 return;
11616         }
11617         if (strcmp(res->what, "add") == 0)
11618                 mcast_addr_add(res->port_num, &res->mc_addr);
11619         else
11620                 mcast_addr_remove(res->port_num, &res->mc_addr);
11621 }
11622
11623 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11624         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11625                                  mcast_addr_cmd, "mcast_addr");
11626 cmdline_parse_token_string_t cmd_mcast_addr_what =
11627         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11628                                  "add#remove");
11629 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11630         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11631 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11632         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11633
11634 cmdline_parse_inst_t cmd_mcast_addr = {
11635         .f = cmd_mcast_addr_parsed,
11636         .data = (void *)0,
11637         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11638                 "Add/Remove multicast MAC address on port_id",
11639         .tokens = {
11640                 (void *)&cmd_mcast_addr_cmd,
11641                 (void *)&cmd_mcast_addr_what,
11642                 (void *)&cmd_mcast_addr_portnum,
11643                 (void *)&cmd_mcast_addr_addr,
11644                 NULL,
11645         },
11646 };
11647
11648 /* l2 tunnel config
11649  * only support E-tag now.
11650  */
11651
11652 /* Ether type config */
11653 struct cmd_config_l2_tunnel_eth_type_result {
11654         cmdline_fixed_string_t port;
11655         cmdline_fixed_string_t config;
11656         cmdline_fixed_string_t all;
11657         portid_t id;
11658         cmdline_fixed_string_t l2_tunnel;
11659         cmdline_fixed_string_t l2_tunnel_type;
11660         cmdline_fixed_string_t eth_type;
11661         uint16_t eth_type_val;
11662 };
11663
11664 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11665         TOKEN_STRING_INITIALIZER
11666                 (struct cmd_config_l2_tunnel_eth_type_result,
11667                  port, "port");
11668 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11669         TOKEN_STRING_INITIALIZER
11670                 (struct cmd_config_l2_tunnel_eth_type_result,
11671                  config, "config");
11672 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11673         TOKEN_STRING_INITIALIZER
11674                 (struct cmd_config_l2_tunnel_eth_type_result,
11675                  all, "all");
11676 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11677         TOKEN_NUM_INITIALIZER
11678                 (struct cmd_config_l2_tunnel_eth_type_result,
11679                  id, UINT16);
11680 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11681         TOKEN_STRING_INITIALIZER
11682                 (struct cmd_config_l2_tunnel_eth_type_result,
11683                  l2_tunnel, "l2-tunnel");
11684 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11685         TOKEN_STRING_INITIALIZER
11686                 (struct cmd_config_l2_tunnel_eth_type_result,
11687                  l2_tunnel_type, "E-tag");
11688 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11689         TOKEN_STRING_INITIALIZER
11690                 (struct cmd_config_l2_tunnel_eth_type_result,
11691                  eth_type, "ether-type");
11692 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11693         TOKEN_NUM_INITIALIZER
11694                 (struct cmd_config_l2_tunnel_eth_type_result,
11695                  eth_type_val, UINT16);
11696
11697 static enum rte_eth_tunnel_type
11698 str2fdir_l2_tunnel_type(char *string)
11699 {
11700         uint32_t i = 0;
11701
11702         static const struct {
11703                 char str[32];
11704                 enum rte_eth_tunnel_type type;
11705         } l2_tunnel_type_str[] = {
11706                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11707         };
11708
11709         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11710                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11711                         return l2_tunnel_type_str[i].type;
11712         }
11713         return RTE_TUNNEL_TYPE_NONE;
11714 }
11715
11716 /* ether type config for all ports */
11717 static void
11718 cmd_config_l2_tunnel_eth_type_all_parsed
11719         (void *parsed_result,
11720          __rte_unused struct cmdline *cl,
11721          __rte_unused void *data)
11722 {
11723         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11724         struct rte_eth_l2_tunnel_conf entry;
11725         portid_t pid;
11726
11727         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11728         entry.ether_type = res->eth_type_val;
11729
11730         RTE_ETH_FOREACH_DEV(pid) {
11731                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11732         }
11733 }
11734
11735 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11736         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11737         .data = NULL,
11738         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11739         .tokens = {
11740                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11741                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11742                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11743                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11744                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11745                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11746                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11747                 NULL,
11748         },
11749 };
11750
11751 /* ether type config for a specific port */
11752 static void
11753 cmd_config_l2_tunnel_eth_type_specific_parsed(
11754         void *parsed_result,
11755         __rte_unused struct cmdline *cl,
11756         __rte_unused void *data)
11757 {
11758         struct cmd_config_l2_tunnel_eth_type_result *res =
11759                  parsed_result;
11760         struct rte_eth_l2_tunnel_conf entry;
11761
11762         if (port_id_is_invalid(res->id, ENABLED_WARN))
11763                 return;
11764
11765         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11766         entry.ether_type = res->eth_type_val;
11767
11768         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11769 }
11770
11771 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11772         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11773         .data = NULL,
11774         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11775         .tokens = {
11776                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11777                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11778                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11779                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11780                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11781                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11782                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11783                 NULL,
11784         },
11785 };
11786
11787 /* Enable/disable l2 tunnel */
11788 struct cmd_config_l2_tunnel_en_dis_result {
11789         cmdline_fixed_string_t port;
11790         cmdline_fixed_string_t config;
11791         cmdline_fixed_string_t all;
11792         portid_t id;
11793         cmdline_fixed_string_t l2_tunnel;
11794         cmdline_fixed_string_t l2_tunnel_type;
11795         cmdline_fixed_string_t en_dis;
11796 };
11797
11798 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11799         TOKEN_STRING_INITIALIZER
11800                 (struct cmd_config_l2_tunnel_en_dis_result,
11801                  port, "port");
11802 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11803         TOKEN_STRING_INITIALIZER
11804                 (struct cmd_config_l2_tunnel_en_dis_result,
11805                  config, "config");
11806 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11807         TOKEN_STRING_INITIALIZER
11808                 (struct cmd_config_l2_tunnel_en_dis_result,
11809                  all, "all");
11810 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11811         TOKEN_NUM_INITIALIZER
11812                 (struct cmd_config_l2_tunnel_en_dis_result,
11813                  id, UINT16);
11814 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11815         TOKEN_STRING_INITIALIZER
11816                 (struct cmd_config_l2_tunnel_en_dis_result,
11817                  l2_tunnel, "l2-tunnel");
11818 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11819         TOKEN_STRING_INITIALIZER
11820                 (struct cmd_config_l2_tunnel_en_dis_result,
11821                  l2_tunnel_type, "E-tag");
11822 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11823         TOKEN_STRING_INITIALIZER
11824                 (struct cmd_config_l2_tunnel_en_dis_result,
11825                  en_dis, "enable#disable");
11826
11827 /* enable/disable l2 tunnel for all ports */
11828 static void
11829 cmd_config_l2_tunnel_en_dis_all_parsed(
11830         void *parsed_result,
11831         __rte_unused struct cmdline *cl,
11832         __rte_unused void *data)
11833 {
11834         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11835         struct rte_eth_l2_tunnel_conf entry;
11836         portid_t pid;
11837         uint8_t en;
11838
11839         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11840
11841         if (!strcmp("enable", res->en_dis))
11842                 en = 1;
11843         else
11844                 en = 0;
11845
11846         RTE_ETH_FOREACH_DEV(pid) {
11847                 rte_eth_dev_l2_tunnel_offload_set(pid,
11848                                                   &entry,
11849                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11850                                                   en);
11851         }
11852 }
11853
11854 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11855         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11856         .data = NULL,
11857         .help_str = "port config all l2-tunnel E-tag enable|disable",
11858         .tokens = {
11859                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11860                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11861                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11862                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11863                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11864                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11865                 NULL,
11866         },
11867 };
11868
11869 /* enable/disable l2 tunnel for a port */
11870 static void
11871 cmd_config_l2_tunnel_en_dis_specific_parsed(
11872         void *parsed_result,
11873         __rte_unused struct cmdline *cl,
11874         __rte_unused void *data)
11875 {
11876         struct cmd_config_l2_tunnel_en_dis_result *res =
11877                 parsed_result;
11878         struct rte_eth_l2_tunnel_conf entry;
11879
11880         if (port_id_is_invalid(res->id, ENABLED_WARN))
11881                 return;
11882
11883         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11884
11885         if (!strcmp("enable", res->en_dis))
11886                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11887                                                   &entry,
11888                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11889                                                   1);
11890         else
11891                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11892                                                   &entry,
11893                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11894                                                   0);
11895 }
11896
11897 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11898         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11899         .data = NULL,
11900         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11901         .tokens = {
11902                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11903                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11904                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11905                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11906                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11907                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11908                 NULL,
11909         },
11910 };
11911
11912 /* E-tag configuration */
11913
11914 /* Common result structure for all E-tag configuration */
11915 struct cmd_config_e_tag_result {
11916         cmdline_fixed_string_t e_tag;
11917         cmdline_fixed_string_t set;
11918         cmdline_fixed_string_t insertion;
11919         cmdline_fixed_string_t stripping;
11920         cmdline_fixed_string_t forwarding;
11921         cmdline_fixed_string_t filter;
11922         cmdline_fixed_string_t add;
11923         cmdline_fixed_string_t del;
11924         cmdline_fixed_string_t on;
11925         cmdline_fixed_string_t off;
11926         cmdline_fixed_string_t on_off;
11927         cmdline_fixed_string_t port_tag_id;
11928         uint32_t port_tag_id_val;
11929         cmdline_fixed_string_t e_tag_id;
11930         uint16_t e_tag_id_val;
11931         cmdline_fixed_string_t dst_pool;
11932         uint8_t dst_pool_val;
11933         cmdline_fixed_string_t port;
11934         portid_t port_id;
11935         cmdline_fixed_string_t vf;
11936         uint8_t vf_id;
11937 };
11938
11939 /* Common CLI fields for all E-tag configuration */
11940 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11941         TOKEN_STRING_INITIALIZER
11942                 (struct cmd_config_e_tag_result,
11943                  e_tag, "E-tag");
11944 cmdline_parse_token_string_t cmd_config_e_tag_set =
11945         TOKEN_STRING_INITIALIZER
11946                 (struct cmd_config_e_tag_result,
11947                  set, "set");
11948 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11949         TOKEN_STRING_INITIALIZER
11950                 (struct cmd_config_e_tag_result,
11951                  insertion, "insertion");
11952 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11953         TOKEN_STRING_INITIALIZER
11954                 (struct cmd_config_e_tag_result,
11955                  stripping, "stripping");
11956 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11957         TOKEN_STRING_INITIALIZER
11958                 (struct cmd_config_e_tag_result,
11959                  forwarding, "forwarding");
11960 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11961         TOKEN_STRING_INITIALIZER
11962                 (struct cmd_config_e_tag_result,
11963                  filter, "filter");
11964 cmdline_parse_token_string_t cmd_config_e_tag_add =
11965         TOKEN_STRING_INITIALIZER
11966                 (struct cmd_config_e_tag_result,
11967                  add, "add");
11968 cmdline_parse_token_string_t cmd_config_e_tag_del =
11969         TOKEN_STRING_INITIALIZER
11970                 (struct cmd_config_e_tag_result,
11971                  del, "del");
11972 cmdline_parse_token_string_t cmd_config_e_tag_on =
11973         TOKEN_STRING_INITIALIZER
11974                 (struct cmd_config_e_tag_result,
11975                  on, "on");
11976 cmdline_parse_token_string_t cmd_config_e_tag_off =
11977         TOKEN_STRING_INITIALIZER
11978                 (struct cmd_config_e_tag_result,
11979                  off, "off");
11980 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11981         TOKEN_STRING_INITIALIZER
11982                 (struct cmd_config_e_tag_result,
11983                  on_off, "on#off");
11984 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11985         TOKEN_STRING_INITIALIZER
11986                 (struct cmd_config_e_tag_result,
11987                  port_tag_id, "port-tag-id");
11988 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11989         TOKEN_NUM_INITIALIZER
11990                 (struct cmd_config_e_tag_result,
11991                  port_tag_id_val, UINT32);
11992 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11993         TOKEN_STRING_INITIALIZER
11994                 (struct cmd_config_e_tag_result,
11995                  e_tag_id, "e-tag-id");
11996 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11997         TOKEN_NUM_INITIALIZER
11998                 (struct cmd_config_e_tag_result,
11999                  e_tag_id_val, UINT16);
12000 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12001         TOKEN_STRING_INITIALIZER
12002                 (struct cmd_config_e_tag_result,
12003                  dst_pool, "dst-pool");
12004 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12005         TOKEN_NUM_INITIALIZER
12006                 (struct cmd_config_e_tag_result,
12007                  dst_pool_val, UINT8);
12008 cmdline_parse_token_string_t cmd_config_e_tag_port =
12009         TOKEN_STRING_INITIALIZER
12010                 (struct cmd_config_e_tag_result,
12011                  port, "port");
12012 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12013         TOKEN_NUM_INITIALIZER
12014                 (struct cmd_config_e_tag_result,
12015                  port_id, UINT16);
12016 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12017         TOKEN_STRING_INITIALIZER
12018                 (struct cmd_config_e_tag_result,
12019                  vf, "vf");
12020 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12021         TOKEN_NUM_INITIALIZER
12022                 (struct cmd_config_e_tag_result,
12023                  vf_id, UINT8);
12024
12025 /* E-tag insertion configuration */
12026 static void
12027 cmd_config_e_tag_insertion_en_parsed(
12028         void *parsed_result,
12029         __rte_unused struct cmdline *cl,
12030         __rte_unused void *data)
12031 {
12032         struct cmd_config_e_tag_result *res =
12033                 parsed_result;
12034         struct rte_eth_l2_tunnel_conf entry;
12035
12036         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12037                 return;
12038
12039         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12040         entry.tunnel_id = res->port_tag_id_val;
12041         entry.vf_id = res->vf_id;
12042         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12043                                           &entry,
12044                                           ETH_L2_TUNNEL_INSERTION_MASK,
12045                                           1);
12046 }
12047
12048 static void
12049 cmd_config_e_tag_insertion_dis_parsed(
12050         void *parsed_result,
12051         __rte_unused struct cmdline *cl,
12052         __rte_unused void *data)
12053 {
12054         struct cmd_config_e_tag_result *res =
12055                 parsed_result;
12056         struct rte_eth_l2_tunnel_conf entry;
12057
12058         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12059                 return;
12060
12061         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12062         entry.vf_id = res->vf_id;
12063
12064         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12065                                           &entry,
12066                                           ETH_L2_TUNNEL_INSERTION_MASK,
12067                                           0);
12068 }
12069
12070 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12071         .f = cmd_config_e_tag_insertion_en_parsed,
12072         .data = NULL,
12073         .help_str = "E-tag ... : E-tag insertion enable",
12074         .tokens = {
12075                 (void *)&cmd_config_e_tag_e_tag,
12076                 (void *)&cmd_config_e_tag_set,
12077                 (void *)&cmd_config_e_tag_insertion,
12078                 (void *)&cmd_config_e_tag_on,
12079                 (void *)&cmd_config_e_tag_port_tag_id,
12080                 (void *)&cmd_config_e_tag_port_tag_id_val,
12081                 (void *)&cmd_config_e_tag_port,
12082                 (void *)&cmd_config_e_tag_port_id,
12083                 (void *)&cmd_config_e_tag_vf,
12084                 (void *)&cmd_config_e_tag_vf_id,
12085                 NULL,
12086         },
12087 };
12088
12089 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12090         .f = cmd_config_e_tag_insertion_dis_parsed,
12091         .data = NULL,
12092         .help_str = "E-tag ... : E-tag insertion disable",
12093         .tokens = {
12094                 (void *)&cmd_config_e_tag_e_tag,
12095                 (void *)&cmd_config_e_tag_set,
12096                 (void *)&cmd_config_e_tag_insertion,
12097                 (void *)&cmd_config_e_tag_off,
12098                 (void *)&cmd_config_e_tag_port,
12099                 (void *)&cmd_config_e_tag_port_id,
12100                 (void *)&cmd_config_e_tag_vf,
12101                 (void *)&cmd_config_e_tag_vf_id,
12102                 NULL,
12103         },
12104 };
12105
12106 /* E-tag stripping configuration */
12107 static void
12108 cmd_config_e_tag_stripping_parsed(
12109         void *parsed_result,
12110         __rte_unused struct cmdline *cl,
12111         __rte_unused void *data)
12112 {
12113         struct cmd_config_e_tag_result *res =
12114                 parsed_result;
12115         struct rte_eth_l2_tunnel_conf entry;
12116
12117         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12118                 return;
12119
12120         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12121
12122         if (!strcmp(res->on_off, "on"))
12123                 rte_eth_dev_l2_tunnel_offload_set
12124                         (res->port_id,
12125                          &entry,
12126                          ETH_L2_TUNNEL_STRIPPING_MASK,
12127                          1);
12128         else
12129                 rte_eth_dev_l2_tunnel_offload_set
12130                         (res->port_id,
12131                          &entry,
12132                          ETH_L2_TUNNEL_STRIPPING_MASK,
12133                          0);
12134 }
12135
12136 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12137         .f = cmd_config_e_tag_stripping_parsed,
12138         .data = NULL,
12139         .help_str = "E-tag ... : E-tag stripping enable/disable",
12140         .tokens = {
12141                 (void *)&cmd_config_e_tag_e_tag,
12142                 (void *)&cmd_config_e_tag_set,
12143                 (void *)&cmd_config_e_tag_stripping,
12144                 (void *)&cmd_config_e_tag_on_off,
12145                 (void *)&cmd_config_e_tag_port,
12146                 (void *)&cmd_config_e_tag_port_id,
12147                 NULL,
12148         },
12149 };
12150
12151 /* E-tag forwarding configuration */
12152 static void
12153 cmd_config_e_tag_forwarding_parsed(
12154         void *parsed_result,
12155         __rte_unused struct cmdline *cl,
12156         __rte_unused void *data)
12157 {
12158         struct cmd_config_e_tag_result *res = parsed_result;
12159         struct rte_eth_l2_tunnel_conf entry;
12160
12161         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12162                 return;
12163
12164         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12165
12166         if (!strcmp(res->on_off, "on"))
12167                 rte_eth_dev_l2_tunnel_offload_set
12168                         (res->port_id,
12169                          &entry,
12170                          ETH_L2_TUNNEL_FORWARDING_MASK,
12171                          1);
12172         else
12173                 rte_eth_dev_l2_tunnel_offload_set
12174                         (res->port_id,
12175                          &entry,
12176                          ETH_L2_TUNNEL_FORWARDING_MASK,
12177                          0);
12178 }
12179
12180 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12181         .f = cmd_config_e_tag_forwarding_parsed,
12182         .data = NULL,
12183         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12184         .tokens = {
12185                 (void *)&cmd_config_e_tag_e_tag,
12186                 (void *)&cmd_config_e_tag_set,
12187                 (void *)&cmd_config_e_tag_forwarding,
12188                 (void *)&cmd_config_e_tag_on_off,
12189                 (void *)&cmd_config_e_tag_port,
12190                 (void *)&cmd_config_e_tag_port_id,
12191                 NULL,
12192         },
12193 };
12194
12195 /* vf vlan anti spoof configuration */
12196
12197 /* Common result structure for vf vlan anti spoof */
12198 struct cmd_vf_vlan_anti_spoof_result {
12199         cmdline_fixed_string_t set;
12200         cmdline_fixed_string_t vf;
12201         cmdline_fixed_string_t vlan;
12202         cmdline_fixed_string_t antispoof;
12203         portid_t port_id;
12204         uint32_t vf_id;
12205         cmdline_fixed_string_t on_off;
12206 };
12207
12208 /* Common CLI fields for vf vlan anti spoof enable disable */
12209 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12210         TOKEN_STRING_INITIALIZER
12211                 (struct cmd_vf_vlan_anti_spoof_result,
12212                  set, "set");
12213 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12214         TOKEN_STRING_INITIALIZER
12215                 (struct cmd_vf_vlan_anti_spoof_result,
12216                  vf, "vf");
12217 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12218         TOKEN_STRING_INITIALIZER
12219                 (struct cmd_vf_vlan_anti_spoof_result,
12220                  vlan, "vlan");
12221 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12222         TOKEN_STRING_INITIALIZER
12223                 (struct cmd_vf_vlan_anti_spoof_result,
12224                  antispoof, "antispoof");
12225 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12226         TOKEN_NUM_INITIALIZER
12227                 (struct cmd_vf_vlan_anti_spoof_result,
12228                  port_id, UINT16);
12229 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12230         TOKEN_NUM_INITIALIZER
12231                 (struct cmd_vf_vlan_anti_spoof_result,
12232                  vf_id, UINT32);
12233 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12234         TOKEN_STRING_INITIALIZER
12235                 (struct cmd_vf_vlan_anti_spoof_result,
12236                  on_off, "on#off");
12237
12238 static void
12239 cmd_set_vf_vlan_anti_spoof_parsed(
12240         void *parsed_result,
12241         __rte_unused struct cmdline *cl,
12242         __rte_unused void *data)
12243 {
12244         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12245         int ret = -ENOTSUP;
12246
12247         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12248
12249         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12250                 return;
12251
12252 #ifdef RTE_NET_IXGBE
12253         if (ret == -ENOTSUP)
12254                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12255                                 res->vf_id, is_on);
12256 #endif
12257 #ifdef RTE_NET_I40E
12258         if (ret == -ENOTSUP)
12259                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12260                                 res->vf_id, is_on);
12261 #endif
12262 #ifdef RTE_NET_BNXT
12263         if (ret == -ENOTSUP)
12264                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12265                                 res->vf_id, is_on);
12266 #endif
12267
12268         switch (ret) {
12269         case 0:
12270                 break;
12271         case -EINVAL:
12272                 printf("invalid vf_id %d\n", res->vf_id);
12273                 break;
12274         case -ENODEV:
12275                 printf("invalid port_id %d\n", res->port_id);
12276                 break;
12277         case -ENOTSUP:
12278                 printf("function not implemented\n");
12279                 break;
12280         default:
12281                 printf("programming error: (%s)\n", strerror(-ret));
12282         }
12283 }
12284
12285 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12286         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12287         .data = NULL,
12288         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12289         .tokens = {
12290                 (void *)&cmd_vf_vlan_anti_spoof_set,
12291                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12292                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12293                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12294                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12295                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12296                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12297                 NULL,
12298         },
12299 };
12300
12301 /* vf mac anti spoof configuration */
12302
12303 /* Common result structure for vf mac anti spoof */
12304 struct cmd_vf_mac_anti_spoof_result {
12305         cmdline_fixed_string_t set;
12306         cmdline_fixed_string_t vf;
12307         cmdline_fixed_string_t mac;
12308         cmdline_fixed_string_t antispoof;
12309         portid_t port_id;
12310         uint32_t vf_id;
12311         cmdline_fixed_string_t on_off;
12312 };
12313
12314 /* Common CLI fields for vf mac anti spoof enable disable */
12315 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12316         TOKEN_STRING_INITIALIZER
12317                 (struct cmd_vf_mac_anti_spoof_result,
12318                  set, "set");
12319 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12320         TOKEN_STRING_INITIALIZER
12321                 (struct cmd_vf_mac_anti_spoof_result,
12322                  vf, "vf");
12323 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12324         TOKEN_STRING_INITIALIZER
12325                 (struct cmd_vf_mac_anti_spoof_result,
12326                  mac, "mac");
12327 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12328         TOKEN_STRING_INITIALIZER
12329                 (struct cmd_vf_mac_anti_spoof_result,
12330                  antispoof, "antispoof");
12331 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12332         TOKEN_NUM_INITIALIZER
12333                 (struct cmd_vf_mac_anti_spoof_result,
12334                  port_id, UINT16);
12335 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12336         TOKEN_NUM_INITIALIZER
12337                 (struct cmd_vf_mac_anti_spoof_result,
12338                  vf_id, UINT32);
12339 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12340         TOKEN_STRING_INITIALIZER
12341                 (struct cmd_vf_mac_anti_spoof_result,
12342                  on_off, "on#off");
12343
12344 static void
12345 cmd_set_vf_mac_anti_spoof_parsed(
12346         void *parsed_result,
12347         __rte_unused struct cmdline *cl,
12348         __rte_unused void *data)
12349 {
12350         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12351         int ret = -ENOTSUP;
12352
12353         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12354
12355         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12356                 return;
12357
12358 #ifdef RTE_NET_IXGBE
12359         if (ret == -ENOTSUP)
12360                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12361                         res->vf_id, is_on);
12362 #endif
12363 #ifdef RTE_NET_I40E
12364         if (ret == -ENOTSUP)
12365                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12366                         res->vf_id, is_on);
12367 #endif
12368 #ifdef RTE_NET_BNXT
12369         if (ret == -ENOTSUP)
12370                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12371                         res->vf_id, is_on);
12372 #endif
12373
12374         switch (ret) {
12375         case 0:
12376                 break;
12377         case -EINVAL:
12378                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12379                 break;
12380         case -ENODEV:
12381                 printf("invalid port_id %d\n", res->port_id);
12382                 break;
12383         case -ENOTSUP:
12384                 printf("function not implemented\n");
12385                 break;
12386         default:
12387                 printf("programming error: (%s)\n", strerror(-ret));
12388         }
12389 }
12390
12391 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12392         .f = cmd_set_vf_mac_anti_spoof_parsed,
12393         .data = NULL,
12394         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12395         .tokens = {
12396                 (void *)&cmd_vf_mac_anti_spoof_set,
12397                 (void *)&cmd_vf_mac_anti_spoof_vf,
12398                 (void *)&cmd_vf_mac_anti_spoof_mac,
12399                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12400                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12401                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12402                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12403                 NULL,
12404         },
12405 };
12406
12407 /* vf vlan strip queue configuration */
12408
12409 /* Common result structure for vf mac anti spoof */
12410 struct cmd_vf_vlan_stripq_result {
12411         cmdline_fixed_string_t set;
12412         cmdline_fixed_string_t vf;
12413         cmdline_fixed_string_t vlan;
12414         cmdline_fixed_string_t stripq;
12415         portid_t port_id;
12416         uint16_t vf_id;
12417         cmdline_fixed_string_t on_off;
12418 };
12419
12420 /* Common CLI fields for vf vlan strip enable disable */
12421 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12422         TOKEN_STRING_INITIALIZER
12423                 (struct cmd_vf_vlan_stripq_result,
12424                  set, "set");
12425 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12426         TOKEN_STRING_INITIALIZER
12427                 (struct cmd_vf_vlan_stripq_result,
12428                  vf, "vf");
12429 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12430         TOKEN_STRING_INITIALIZER
12431                 (struct cmd_vf_vlan_stripq_result,
12432                  vlan, "vlan");
12433 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12434         TOKEN_STRING_INITIALIZER
12435                 (struct cmd_vf_vlan_stripq_result,
12436                  stripq, "stripq");
12437 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12438         TOKEN_NUM_INITIALIZER
12439                 (struct cmd_vf_vlan_stripq_result,
12440                  port_id, UINT16);
12441 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12442         TOKEN_NUM_INITIALIZER
12443                 (struct cmd_vf_vlan_stripq_result,
12444                  vf_id, UINT16);
12445 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12446         TOKEN_STRING_INITIALIZER
12447                 (struct cmd_vf_vlan_stripq_result,
12448                  on_off, "on#off");
12449
12450 static void
12451 cmd_set_vf_vlan_stripq_parsed(
12452         void *parsed_result,
12453         __rte_unused struct cmdline *cl,
12454         __rte_unused void *data)
12455 {
12456         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12457         int ret = -ENOTSUP;
12458
12459         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12460
12461         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12462                 return;
12463
12464 #ifdef RTE_NET_IXGBE
12465         if (ret == -ENOTSUP)
12466                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12467                         res->vf_id, is_on);
12468 #endif
12469 #ifdef RTE_NET_I40E
12470         if (ret == -ENOTSUP)
12471                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12472                         res->vf_id, is_on);
12473 #endif
12474 #ifdef RTE_NET_BNXT
12475         if (ret == -ENOTSUP)
12476                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12477                         res->vf_id, is_on);
12478 #endif
12479
12480         switch (ret) {
12481         case 0:
12482                 break;
12483         case -EINVAL:
12484                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12485                 break;
12486         case -ENODEV:
12487                 printf("invalid port_id %d\n", res->port_id);
12488                 break;
12489         case -ENOTSUP:
12490                 printf("function not implemented\n");
12491                 break;
12492         default:
12493                 printf("programming error: (%s)\n", strerror(-ret));
12494         }
12495 }
12496
12497 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12498         .f = cmd_set_vf_vlan_stripq_parsed,
12499         .data = NULL,
12500         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12501         .tokens = {
12502                 (void *)&cmd_vf_vlan_stripq_set,
12503                 (void *)&cmd_vf_vlan_stripq_vf,
12504                 (void *)&cmd_vf_vlan_stripq_vlan,
12505                 (void *)&cmd_vf_vlan_stripq_stripq,
12506                 (void *)&cmd_vf_vlan_stripq_port_id,
12507                 (void *)&cmd_vf_vlan_stripq_vf_id,
12508                 (void *)&cmd_vf_vlan_stripq_on_off,
12509                 NULL,
12510         },
12511 };
12512
12513 /* vf vlan insert configuration */
12514
12515 /* Common result structure for vf vlan insert */
12516 struct cmd_vf_vlan_insert_result {
12517         cmdline_fixed_string_t set;
12518         cmdline_fixed_string_t vf;
12519         cmdline_fixed_string_t vlan;
12520         cmdline_fixed_string_t insert;
12521         portid_t port_id;
12522         uint16_t vf_id;
12523         uint16_t vlan_id;
12524 };
12525
12526 /* Common CLI fields for vf vlan insert enable disable */
12527 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12528         TOKEN_STRING_INITIALIZER
12529                 (struct cmd_vf_vlan_insert_result,
12530                  set, "set");
12531 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12532         TOKEN_STRING_INITIALIZER
12533                 (struct cmd_vf_vlan_insert_result,
12534                  vf, "vf");
12535 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12536         TOKEN_STRING_INITIALIZER
12537                 (struct cmd_vf_vlan_insert_result,
12538                  vlan, "vlan");
12539 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12540         TOKEN_STRING_INITIALIZER
12541                 (struct cmd_vf_vlan_insert_result,
12542                  insert, "insert");
12543 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12544         TOKEN_NUM_INITIALIZER
12545                 (struct cmd_vf_vlan_insert_result,
12546                  port_id, UINT16);
12547 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12548         TOKEN_NUM_INITIALIZER
12549                 (struct cmd_vf_vlan_insert_result,
12550                  vf_id, UINT16);
12551 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12552         TOKEN_NUM_INITIALIZER
12553                 (struct cmd_vf_vlan_insert_result,
12554                  vlan_id, UINT16);
12555
12556 static void
12557 cmd_set_vf_vlan_insert_parsed(
12558         void *parsed_result,
12559         __rte_unused struct cmdline *cl,
12560         __rte_unused void *data)
12561 {
12562         struct cmd_vf_vlan_insert_result *res = parsed_result;
12563         int ret = -ENOTSUP;
12564
12565         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12566                 return;
12567
12568 #ifdef RTE_NET_IXGBE
12569         if (ret == -ENOTSUP)
12570                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12571                         res->vlan_id);
12572 #endif
12573 #ifdef RTE_NET_I40E
12574         if (ret == -ENOTSUP)
12575                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12576                         res->vlan_id);
12577 #endif
12578 #ifdef RTE_NET_BNXT
12579         if (ret == -ENOTSUP)
12580                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12581                         res->vlan_id);
12582 #endif
12583
12584         switch (ret) {
12585         case 0:
12586                 break;
12587         case -EINVAL:
12588                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12589                 break;
12590         case -ENODEV:
12591                 printf("invalid port_id %d\n", res->port_id);
12592                 break;
12593         case -ENOTSUP:
12594                 printf("function not implemented\n");
12595                 break;
12596         default:
12597                 printf("programming error: (%s)\n", strerror(-ret));
12598         }
12599 }
12600
12601 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12602         .f = cmd_set_vf_vlan_insert_parsed,
12603         .data = NULL,
12604         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12605         .tokens = {
12606                 (void *)&cmd_vf_vlan_insert_set,
12607                 (void *)&cmd_vf_vlan_insert_vf,
12608                 (void *)&cmd_vf_vlan_insert_vlan,
12609                 (void *)&cmd_vf_vlan_insert_insert,
12610                 (void *)&cmd_vf_vlan_insert_port_id,
12611                 (void *)&cmd_vf_vlan_insert_vf_id,
12612                 (void *)&cmd_vf_vlan_insert_vlan_id,
12613                 NULL,
12614         },
12615 };
12616
12617 /* tx loopback configuration */
12618
12619 /* Common result structure for tx loopback */
12620 struct cmd_tx_loopback_result {
12621         cmdline_fixed_string_t set;
12622         cmdline_fixed_string_t tx;
12623         cmdline_fixed_string_t loopback;
12624         portid_t port_id;
12625         cmdline_fixed_string_t on_off;
12626 };
12627
12628 /* Common CLI fields for tx loopback enable disable */
12629 cmdline_parse_token_string_t cmd_tx_loopback_set =
12630         TOKEN_STRING_INITIALIZER
12631                 (struct cmd_tx_loopback_result,
12632                  set, "set");
12633 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12634         TOKEN_STRING_INITIALIZER
12635                 (struct cmd_tx_loopback_result,
12636                  tx, "tx");
12637 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12638         TOKEN_STRING_INITIALIZER
12639                 (struct cmd_tx_loopback_result,
12640                  loopback, "loopback");
12641 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12642         TOKEN_NUM_INITIALIZER
12643                 (struct cmd_tx_loopback_result,
12644                  port_id, UINT16);
12645 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12646         TOKEN_STRING_INITIALIZER
12647                 (struct cmd_tx_loopback_result,
12648                  on_off, "on#off");
12649
12650 static void
12651 cmd_set_tx_loopback_parsed(
12652         void *parsed_result,
12653         __rte_unused struct cmdline *cl,
12654         __rte_unused void *data)
12655 {
12656         struct cmd_tx_loopback_result *res = parsed_result;
12657         int ret = -ENOTSUP;
12658
12659         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12660
12661         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12662                 return;
12663
12664 #ifdef RTE_NET_IXGBE
12665         if (ret == -ENOTSUP)
12666                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12667 #endif
12668 #ifdef RTE_NET_I40E
12669         if (ret == -ENOTSUP)
12670                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12671 #endif
12672 #ifdef RTE_NET_BNXT
12673         if (ret == -ENOTSUP)
12674                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12675 #endif
12676 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
12677         if (ret == -ENOTSUP)
12678                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12679 #endif
12680
12681         switch (ret) {
12682         case 0:
12683                 break;
12684         case -EINVAL:
12685                 printf("invalid is_on %d\n", is_on);
12686                 break;
12687         case -ENODEV:
12688                 printf("invalid port_id %d\n", res->port_id);
12689                 break;
12690         case -ENOTSUP:
12691                 printf("function not implemented\n");
12692                 break;
12693         default:
12694                 printf("programming error: (%s)\n", strerror(-ret));
12695         }
12696 }
12697
12698 cmdline_parse_inst_t cmd_set_tx_loopback = {
12699         .f = cmd_set_tx_loopback_parsed,
12700         .data = NULL,
12701         .help_str = "set tx loopback <port_id> on|off",
12702         .tokens = {
12703                 (void *)&cmd_tx_loopback_set,
12704                 (void *)&cmd_tx_loopback_tx,
12705                 (void *)&cmd_tx_loopback_loopback,
12706                 (void *)&cmd_tx_loopback_port_id,
12707                 (void *)&cmd_tx_loopback_on_off,
12708                 NULL,
12709         },
12710 };
12711
12712 /* all queues drop enable configuration */
12713
12714 /* Common result structure for all queues drop enable */
12715 struct cmd_all_queues_drop_en_result {
12716         cmdline_fixed_string_t set;
12717         cmdline_fixed_string_t all;
12718         cmdline_fixed_string_t queues;
12719         cmdline_fixed_string_t drop;
12720         portid_t port_id;
12721         cmdline_fixed_string_t on_off;
12722 };
12723
12724 /* Common CLI fields for tx loopback enable disable */
12725 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12726         TOKEN_STRING_INITIALIZER
12727                 (struct cmd_all_queues_drop_en_result,
12728                  set, "set");
12729 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12730         TOKEN_STRING_INITIALIZER
12731                 (struct cmd_all_queues_drop_en_result,
12732                  all, "all");
12733 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12734         TOKEN_STRING_INITIALIZER
12735                 (struct cmd_all_queues_drop_en_result,
12736                  queues, "queues");
12737 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12738         TOKEN_STRING_INITIALIZER
12739                 (struct cmd_all_queues_drop_en_result,
12740                  drop, "drop");
12741 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12742         TOKEN_NUM_INITIALIZER
12743                 (struct cmd_all_queues_drop_en_result,
12744                  port_id, UINT16);
12745 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12746         TOKEN_STRING_INITIALIZER
12747                 (struct cmd_all_queues_drop_en_result,
12748                  on_off, "on#off");
12749
12750 static void
12751 cmd_set_all_queues_drop_en_parsed(
12752         void *parsed_result,
12753         __rte_unused struct cmdline *cl,
12754         __rte_unused void *data)
12755 {
12756         struct cmd_all_queues_drop_en_result *res = parsed_result;
12757         int ret = -ENOTSUP;
12758         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12759
12760         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12761                 return;
12762
12763 #ifdef RTE_NET_IXGBE
12764         if (ret == -ENOTSUP)
12765                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12766 #endif
12767 #ifdef RTE_NET_BNXT
12768         if (ret == -ENOTSUP)
12769                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12770 #endif
12771         switch (ret) {
12772         case 0:
12773                 break;
12774         case -EINVAL:
12775                 printf("invalid is_on %d\n", is_on);
12776                 break;
12777         case -ENODEV:
12778                 printf("invalid port_id %d\n", res->port_id);
12779                 break;
12780         case -ENOTSUP:
12781                 printf("function not implemented\n");
12782                 break;
12783         default:
12784                 printf("programming error: (%s)\n", strerror(-ret));
12785         }
12786 }
12787
12788 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12789         .f = cmd_set_all_queues_drop_en_parsed,
12790         .data = NULL,
12791         .help_str = "set all queues drop <port_id> on|off",
12792         .tokens = {
12793                 (void *)&cmd_all_queues_drop_en_set,
12794                 (void *)&cmd_all_queues_drop_en_all,
12795                 (void *)&cmd_all_queues_drop_en_queues,
12796                 (void *)&cmd_all_queues_drop_en_drop,
12797                 (void *)&cmd_all_queues_drop_en_port_id,
12798                 (void *)&cmd_all_queues_drop_en_on_off,
12799                 NULL,
12800         },
12801 };
12802
12803 /* vf split drop enable configuration */
12804
12805 /* Common result structure for vf split drop enable */
12806 struct cmd_vf_split_drop_en_result {
12807         cmdline_fixed_string_t set;
12808         cmdline_fixed_string_t vf;
12809         cmdline_fixed_string_t split;
12810         cmdline_fixed_string_t drop;
12811         portid_t port_id;
12812         uint16_t vf_id;
12813         cmdline_fixed_string_t on_off;
12814 };
12815
12816 /* Common CLI fields for vf split drop enable disable */
12817 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12818         TOKEN_STRING_INITIALIZER
12819                 (struct cmd_vf_split_drop_en_result,
12820                  set, "set");
12821 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12822         TOKEN_STRING_INITIALIZER
12823                 (struct cmd_vf_split_drop_en_result,
12824                  vf, "vf");
12825 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12826         TOKEN_STRING_INITIALIZER
12827                 (struct cmd_vf_split_drop_en_result,
12828                  split, "split");
12829 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12830         TOKEN_STRING_INITIALIZER
12831                 (struct cmd_vf_split_drop_en_result,
12832                  drop, "drop");
12833 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12834         TOKEN_NUM_INITIALIZER
12835                 (struct cmd_vf_split_drop_en_result,
12836                  port_id, UINT16);
12837 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12838         TOKEN_NUM_INITIALIZER
12839                 (struct cmd_vf_split_drop_en_result,
12840                  vf_id, UINT16);
12841 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12842         TOKEN_STRING_INITIALIZER
12843                 (struct cmd_vf_split_drop_en_result,
12844                  on_off, "on#off");
12845
12846 static void
12847 cmd_set_vf_split_drop_en_parsed(
12848         void *parsed_result,
12849         __rte_unused struct cmdline *cl,
12850         __rte_unused void *data)
12851 {
12852         struct cmd_vf_split_drop_en_result *res = parsed_result;
12853         int ret = -ENOTSUP;
12854         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12855
12856         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12857                 return;
12858
12859 #ifdef RTE_NET_IXGBE
12860         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12861                         is_on);
12862 #endif
12863         switch (ret) {
12864         case 0:
12865                 break;
12866         case -EINVAL:
12867                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12868                 break;
12869         case -ENODEV:
12870                 printf("invalid port_id %d\n", res->port_id);
12871                 break;
12872         case -ENOTSUP:
12873                 printf("not supported on port %d\n", res->port_id);
12874                 break;
12875         default:
12876                 printf("programming error: (%s)\n", strerror(-ret));
12877         }
12878 }
12879
12880 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12881         .f = cmd_set_vf_split_drop_en_parsed,
12882         .data = NULL,
12883         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12884         .tokens = {
12885                 (void *)&cmd_vf_split_drop_en_set,
12886                 (void *)&cmd_vf_split_drop_en_vf,
12887                 (void *)&cmd_vf_split_drop_en_split,
12888                 (void *)&cmd_vf_split_drop_en_drop,
12889                 (void *)&cmd_vf_split_drop_en_port_id,
12890                 (void *)&cmd_vf_split_drop_en_vf_id,
12891                 (void *)&cmd_vf_split_drop_en_on_off,
12892                 NULL,
12893         },
12894 };
12895
12896 /* vf mac address configuration */
12897
12898 /* Common result structure for vf mac address */
12899 struct cmd_set_vf_mac_addr_result {
12900         cmdline_fixed_string_t set;
12901         cmdline_fixed_string_t vf;
12902         cmdline_fixed_string_t mac;
12903         cmdline_fixed_string_t addr;
12904         portid_t port_id;
12905         uint16_t vf_id;
12906         struct rte_ether_addr mac_addr;
12907
12908 };
12909
12910 /* Common CLI fields for vf split drop enable disable */
12911 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12912         TOKEN_STRING_INITIALIZER
12913                 (struct cmd_set_vf_mac_addr_result,
12914                  set, "set");
12915 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12916         TOKEN_STRING_INITIALIZER
12917                 (struct cmd_set_vf_mac_addr_result,
12918                  vf, "vf");
12919 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12920         TOKEN_STRING_INITIALIZER
12921                 (struct cmd_set_vf_mac_addr_result,
12922                  mac, "mac");
12923 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12924         TOKEN_STRING_INITIALIZER
12925                 (struct cmd_set_vf_mac_addr_result,
12926                  addr, "addr");
12927 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12928         TOKEN_NUM_INITIALIZER
12929                 (struct cmd_set_vf_mac_addr_result,
12930                  port_id, UINT16);
12931 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12932         TOKEN_NUM_INITIALIZER
12933                 (struct cmd_set_vf_mac_addr_result,
12934                  vf_id, UINT16);
12935 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12936         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12937                  mac_addr);
12938
12939 static void
12940 cmd_set_vf_mac_addr_parsed(
12941         void *parsed_result,
12942         __rte_unused struct cmdline *cl,
12943         __rte_unused void *data)
12944 {
12945         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12946         int ret = -ENOTSUP;
12947
12948         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12949                 return;
12950
12951 #ifdef RTE_NET_IXGBE
12952         if (ret == -ENOTSUP)
12953                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12954                                 &res->mac_addr);
12955 #endif
12956 #ifdef RTE_NET_I40E
12957         if (ret == -ENOTSUP)
12958                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12959                                 &res->mac_addr);
12960 #endif
12961 #ifdef RTE_NET_BNXT
12962         if (ret == -ENOTSUP)
12963                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12964                                 &res->mac_addr);
12965 #endif
12966
12967         switch (ret) {
12968         case 0:
12969                 break;
12970         case -EINVAL:
12971                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12972                 break;
12973         case -ENODEV:
12974                 printf("invalid port_id %d\n", res->port_id);
12975                 break;
12976         case -ENOTSUP:
12977                 printf("function not implemented\n");
12978                 break;
12979         default:
12980                 printf("programming error: (%s)\n", strerror(-ret));
12981         }
12982 }
12983
12984 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12985         .f = cmd_set_vf_mac_addr_parsed,
12986         .data = NULL,
12987         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12988         .tokens = {
12989                 (void *)&cmd_set_vf_mac_addr_set,
12990                 (void *)&cmd_set_vf_mac_addr_vf,
12991                 (void *)&cmd_set_vf_mac_addr_mac,
12992                 (void *)&cmd_set_vf_mac_addr_addr,
12993                 (void *)&cmd_set_vf_mac_addr_port_id,
12994                 (void *)&cmd_set_vf_mac_addr_vf_id,
12995                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12996                 NULL,
12997         },
12998 };
12999
13000 /* MACsec configuration */
13001
13002 /* Common result structure for MACsec offload enable */
13003 struct cmd_macsec_offload_on_result {
13004         cmdline_fixed_string_t set;
13005         cmdline_fixed_string_t macsec;
13006         cmdline_fixed_string_t offload;
13007         portid_t port_id;
13008         cmdline_fixed_string_t on;
13009         cmdline_fixed_string_t encrypt;
13010         cmdline_fixed_string_t en_on_off;
13011         cmdline_fixed_string_t replay_protect;
13012         cmdline_fixed_string_t rp_on_off;
13013 };
13014
13015 /* Common CLI fields for MACsec offload disable */
13016 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13017         TOKEN_STRING_INITIALIZER
13018                 (struct cmd_macsec_offload_on_result,
13019                  set, "set");
13020 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13021         TOKEN_STRING_INITIALIZER
13022                 (struct cmd_macsec_offload_on_result,
13023                  macsec, "macsec");
13024 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13025         TOKEN_STRING_INITIALIZER
13026                 (struct cmd_macsec_offload_on_result,
13027                  offload, "offload");
13028 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13029         TOKEN_NUM_INITIALIZER
13030                 (struct cmd_macsec_offload_on_result,
13031                  port_id, UINT16);
13032 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13033         TOKEN_STRING_INITIALIZER
13034                 (struct cmd_macsec_offload_on_result,
13035                  on, "on");
13036 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13037         TOKEN_STRING_INITIALIZER
13038                 (struct cmd_macsec_offload_on_result,
13039                  encrypt, "encrypt");
13040 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13041         TOKEN_STRING_INITIALIZER
13042                 (struct cmd_macsec_offload_on_result,
13043                  en_on_off, "on#off");
13044 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13045         TOKEN_STRING_INITIALIZER
13046                 (struct cmd_macsec_offload_on_result,
13047                  replay_protect, "replay-protect");
13048 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13049         TOKEN_STRING_INITIALIZER
13050                 (struct cmd_macsec_offload_on_result,
13051                  rp_on_off, "on#off");
13052
13053 static void
13054 cmd_set_macsec_offload_on_parsed(
13055         void *parsed_result,
13056         __rte_unused struct cmdline *cl,
13057         __rte_unused void *data)
13058 {
13059         struct cmd_macsec_offload_on_result *res = parsed_result;
13060         int ret = -ENOTSUP;
13061         portid_t port_id = res->port_id;
13062         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13063         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13064         struct rte_eth_dev_info dev_info;
13065
13066         if (port_id_is_invalid(port_id, ENABLED_WARN))
13067                 return;
13068         if (!port_is_stopped(port_id)) {
13069                 printf("Please stop port %d first\n", port_id);
13070                 return;
13071         }
13072
13073         ret = eth_dev_info_get_print_err(port_id, &dev_info);
13074         if (ret != 0)
13075                 return;
13076
13077         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13078 #ifdef RTE_NET_IXGBE
13079                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13080 #endif
13081         }
13082         RTE_SET_USED(en);
13083         RTE_SET_USED(rp);
13084
13085         switch (ret) {
13086         case 0:
13087                 ports[port_id].dev_conf.txmode.offloads |=
13088                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13089                 cmd_reconfig_device_queue(port_id, 1, 1);
13090                 break;
13091         case -ENODEV:
13092                 printf("invalid port_id %d\n", port_id);
13093                 break;
13094         case -ENOTSUP:
13095                 printf("not supported on port %d\n", port_id);
13096                 break;
13097         default:
13098                 printf("programming error: (%s)\n", strerror(-ret));
13099         }
13100 }
13101
13102 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13103         .f = cmd_set_macsec_offload_on_parsed,
13104         .data = NULL,
13105         .help_str = "set macsec offload <port_id> on "
13106                 "encrypt on|off replay-protect on|off",
13107         .tokens = {
13108                 (void *)&cmd_macsec_offload_on_set,
13109                 (void *)&cmd_macsec_offload_on_macsec,
13110                 (void *)&cmd_macsec_offload_on_offload,
13111                 (void *)&cmd_macsec_offload_on_port_id,
13112                 (void *)&cmd_macsec_offload_on_on,
13113                 (void *)&cmd_macsec_offload_on_encrypt,
13114                 (void *)&cmd_macsec_offload_on_en_on_off,
13115                 (void *)&cmd_macsec_offload_on_replay_protect,
13116                 (void *)&cmd_macsec_offload_on_rp_on_off,
13117                 NULL,
13118         },
13119 };
13120
13121 /* Common result structure for MACsec offload disable */
13122 struct cmd_macsec_offload_off_result {
13123         cmdline_fixed_string_t set;
13124         cmdline_fixed_string_t macsec;
13125         cmdline_fixed_string_t offload;
13126         portid_t port_id;
13127         cmdline_fixed_string_t off;
13128 };
13129
13130 /* Common CLI fields for MACsec offload disable */
13131 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13132         TOKEN_STRING_INITIALIZER
13133                 (struct cmd_macsec_offload_off_result,
13134                  set, "set");
13135 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13136         TOKEN_STRING_INITIALIZER
13137                 (struct cmd_macsec_offload_off_result,
13138                  macsec, "macsec");
13139 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13140         TOKEN_STRING_INITIALIZER
13141                 (struct cmd_macsec_offload_off_result,
13142                  offload, "offload");
13143 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13144         TOKEN_NUM_INITIALIZER
13145                 (struct cmd_macsec_offload_off_result,
13146                  port_id, UINT16);
13147 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13148         TOKEN_STRING_INITIALIZER
13149                 (struct cmd_macsec_offload_off_result,
13150                  off, "off");
13151
13152 static void
13153 cmd_set_macsec_offload_off_parsed(
13154         void *parsed_result,
13155         __rte_unused struct cmdline *cl,
13156         __rte_unused void *data)
13157 {
13158         struct cmd_macsec_offload_off_result *res = parsed_result;
13159         int ret = -ENOTSUP;
13160         struct rte_eth_dev_info dev_info;
13161         portid_t port_id = res->port_id;
13162
13163         if (port_id_is_invalid(port_id, ENABLED_WARN))
13164                 return;
13165         if (!port_is_stopped(port_id)) {
13166                 printf("Please stop port %d first\n", port_id);
13167                 return;
13168         }
13169
13170         ret = eth_dev_info_get_print_err(port_id, &dev_info);
13171         if (ret != 0)
13172                 return;
13173
13174         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13175 #ifdef RTE_NET_IXGBE
13176                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13177 #endif
13178         }
13179         switch (ret) {
13180         case 0:
13181                 ports[port_id].dev_conf.txmode.offloads &=
13182                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13183                 cmd_reconfig_device_queue(port_id, 1, 1);
13184                 break;
13185         case -ENODEV:
13186                 printf("invalid port_id %d\n", port_id);
13187                 break;
13188         case -ENOTSUP:
13189                 printf("not supported on port %d\n", port_id);
13190                 break;
13191         default:
13192                 printf("programming error: (%s)\n", strerror(-ret));
13193         }
13194 }
13195
13196 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13197         .f = cmd_set_macsec_offload_off_parsed,
13198         .data = NULL,
13199         .help_str = "set macsec offload <port_id> off",
13200         .tokens = {
13201                 (void *)&cmd_macsec_offload_off_set,
13202                 (void *)&cmd_macsec_offload_off_macsec,
13203                 (void *)&cmd_macsec_offload_off_offload,
13204                 (void *)&cmd_macsec_offload_off_port_id,
13205                 (void *)&cmd_macsec_offload_off_off,
13206                 NULL,
13207         },
13208 };
13209
13210 /* Common result structure for MACsec secure connection configure */
13211 struct cmd_macsec_sc_result {
13212         cmdline_fixed_string_t set;
13213         cmdline_fixed_string_t macsec;
13214         cmdline_fixed_string_t sc;
13215         cmdline_fixed_string_t tx_rx;
13216         portid_t port_id;
13217         struct rte_ether_addr mac;
13218         uint16_t pi;
13219 };
13220
13221 /* Common CLI fields for MACsec secure connection configure */
13222 cmdline_parse_token_string_t cmd_macsec_sc_set =
13223         TOKEN_STRING_INITIALIZER
13224                 (struct cmd_macsec_sc_result,
13225                  set, "set");
13226 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13227         TOKEN_STRING_INITIALIZER
13228                 (struct cmd_macsec_sc_result,
13229                  macsec, "macsec");
13230 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13231         TOKEN_STRING_INITIALIZER
13232                 (struct cmd_macsec_sc_result,
13233                  sc, "sc");
13234 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13235         TOKEN_STRING_INITIALIZER
13236                 (struct cmd_macsec_sc_result,
13237                  tx_rx, "tx#rx");
13238 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13239         TOKEN_NUM_INITIALIZER
13240                 (struct cmd_macsec_sc_result,
13241                  port_id, UINT16);
13242 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13243         TOKEN_ETHERADDR_INITIALIZER
13244                 (struct cmd_macsec_sc_result,
13245                  mac);
13246 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13247         TOKEN_NUM_INITIALIZER
13248                 (struct cmd_macsec_sc_result,
13249                  pi, UINT16);
13250
13251 static void
13252 cmd_set_macsec_sc_parsed(
13253         void *parsed_result,
13254         __rte_unused struct cmdline *cl,
13255         __rte_unused void *data)
13256 {
13257         struct cmd_macsec_sc_result *res = parsed_result;
13258         int ret = -ENOTSUP;
13259         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13260
13261 #ifdef RTE_NET_IXGBE
13262         ret = is_tx ?
13263                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13264                                 res->mac.addr_bytes) :
13265                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13266                                 res->mac.addr_bytes, res->pi);
13267 #endif
13268         RTE_SET_USED(is_tx);
13269
13270         switch (ret) {
13271         case 0:
13272                 break;
13273         case -ENODEV:
13274                 printf("invalid port_id %d\n", res->port_id);
13275                 break;
13276         case -ENOTSUP:
13277                 printf("not supported on port %d\n", res->port_id);
13278                 break;
13279         default:
13280                 printf("programming error: (%s)\n", strerror(-ret));
13281         }
13282 }
13283
13284 cmdline_parse_inst_t cmd_set_macsec_sc = {
13285         .f = cmd_set_macsec_sc_parsed,
13286         .data = NULL,
13287         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13288         .tokens = {
13289                 (void *)&cmd_macsec_sc_set,
13290                 (void *)&cmd_macsec_sc_macsec,
13291                 (void *)&cmd_macsec_sc_sc,
13292                 (void *)&cmd_macsec_sc_tx_rx,
13293                 (void *)&cmd_macsec_sc_port_id,
13294                 (void *)&cmd_macsec_sc_mac,
13295                 (void *)&cmd_macsec_sc_pi,
13296                 NULL,
13297         },
13298 };
13299
13300 /* Common result structure for MACsec secure connection configure */
13301 struct cmd_macsec_sa_result {
13302         cmdline_fixed_string_t set;
13303         cmdline_fixed_string_t macsec;
13304         cmdline_fixed_string_t sa;
13305         cmdline_fixed_string_t tx_rx;
13306         portid_t port_id;
13307         uint8_t idx;
13308         uint8_t an;
13309         uint32_t pn;
13310         cmdline_fixed_string_t key;
13311 };
13312
13313 /* Common CLI fields for MACsec secure connection configure */
13314 cmdline_parse_token_string_t cmd_macsec_sa_set =
13315         TOKEN_STRING_INITIALIZER
13316                 (struct cmd_macsec_sa_result,
13317                  set, "set");
13318 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13319         TOKEN_STRING_INITIALIZER
13320                 (struct cmd_macsec_sa_result,
13321                  macsec, "macsec");
13322 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13323         TOKEN_STRING_INITIALIZER
13324                 (struct cmd_macsec_sa_result,
13325                  sa, "sa");
13326 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13327         TOKEN_STRING_INITIALIZER
13328                 (struct cmd_macsec_sa_result,
13329                  tx_rx, "tx#rx");
13330 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13331         TOKEN_NUM_INITIALIZER
13332                 (struct cmd_macsec_sa_result,
13333                  port_id, UINT16);
13334 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13335         TOKEN_NUM_INITIALIZER
13336                 (struct cmd_macsec_sa_result,
13337                  idx, UINT8);
13338 cmdline_parse_token_num_t cmd_macsec_sa_an =
13339         TOKEN_NUM_INITIALIZER
13340                 (struct cmd_macsec_sa_result,
13341                  an, UINT8);
13342 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13343         TOKEN_NUM_INITIALIZER
13344                 (struct cmd_macsec_sa_result,
13345                  pn, UINT32);
13346 cmdline_parse_token_string_t cmd_macsec_sa_key =
13347         TOKEN_STRING_INITIALIZER
13348                 (struct cmd_macsec_sa_result,
13349                  key, NULL);
13350
13351 static void
13352 cmd_set_macsec_sa_parsed(
13353         void *parsed_result,
13354         __rte_unused struct cmdline *cl,
13355         __rte_unused void *data)
13356 {
13357         struct cmd_macsec_sa_result *res = parsed_result;
13358         int ret = -ENOTSUP;
13359         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13360         uint8_t key[16] = { 0 };
13361         uint8_t xdgt0;
13362         uint8_t xdgt1;
13363         int key_len;
13364         int i;
13365
13366         key_len = strlen(res->key) / 2;
13367         if (key_len > 16)
13368                 key_len = 16;
13369
13370         for (i = 0; i < key_len; i++) {
13371                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13372                 if (xdgt0 == 0xFF)
13373                         return;
13374                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13375                 if (xdgt1 == 0xFF)
13376                         return;
13377                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13378         }
13379
13380 #ifdef RTE_NET_IXGBE
13381         ret = is_tx ?
13382                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13383                         res->idx, res->an, res->pn, key) :
13384                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13385                         res->idx, res->an, res->pn, key);
13386 #endif
13387         RTE_SET_USED(is_tx);
13388         RTE_SET_USED(key);
13389
13390         switch (ret) {
13391         case 0:
13392                 break;
13393         case -EINVAL:
13394                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13395                 break;
13396         case -ENODEV:
13397                 printf("invalid port_id %d\n", res->port_id);
13398                 break;
13399         case -ENOTSUP:
13400                 printf("not supported on port %d\n", res->port_id);
13401                 break;
13402         default:
13403                 printf("programming error: (%s)\n", strerror(-ret));
13404         }
13405 }
13406
13407 cmdline_parse_inst_t cmd_set_macsec_sa = {
13408         .f = cmd_set_macsec_sa_parsed,
13409         .data = NULL,
13410         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13411         .tokens = {
13412                 (void *)&cmd_macsec_sa_set,
13413                 (void *)&cmd_macsec_sa_macsec,
13414                 (void *)&cmd_macsec_sa_sa,
13415                 (void *)&cmd_macsec_sa_tx_rx,
13416                 (void *)&cmd_macsec_sa_port_id,
13417                 (void *)&cmd_macsec_sa_idx,
13418                 (void *)&cmd_macsec_sa_an,
13419                 (void *)&cmd_macsec_sa_pn,
13420                 (void *)&cmd_macsec_sa_key,
13421                 NULL,
13422         },
13423 };
13424
13425 /* VF unicast promiscuous mode configuration */
13426
13427 /* Common result structure for VF unicast promiscuous mode */
13428 struct cmd_vf_promisc_result {
13429         cmdline_fixed_string_t set;
13430         cmdline_fixed_string_t vf;
13431         cmdline_fixed_string_t promisc;
13432         portid_t port_id;
13433         uint32_t vf_id;
13434         cmdline_fixed_string_t on_off;
13435 };
13436
13437 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13438 cmdline_parse_token_string_t cmd_vf_promisc_set =
13439         TOKEN_STRING_INITIALIZER
13440                 (struct cmd_vf_promisc_result,
13441                  set, "set");
13442 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13443         TOKEN_STRING_INITIALIZER
13444                 (struct cmd_vf_promisc_result,
13445                  vf, "vf");
13446 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13447         TOKEN_STRING_INITIALIZER
13448                 (struct cmd_vf_promisc_result,
13449                  promisc, "promisc");
13450 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13451         TOKEN_NUM_INITIALIZER
13452                 (struct cmd_vf_promisc_result,
13453                  port_id, UINT16);
13454 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13455         TOKEN_NUM_INITIALIZER
13456                 (struct cmd_vf_promisc_result,
13457                  vf_id, UINT32);
13458 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13459         TOKEN_STRING_INITIALIZER
13460                 (struct cmd_vf_promisc_result,
13461                  on_off, "on#off");
13462
13463 static void
13464 cmd_set_vf_promisc_parsed(
13465         void *parsed_result,
13466         __rte_unused struct cmdline *cl,
13467         __rte_unused void *data)
13468 {
13469         struct cmd_vf_promisc_result *res = parsed_result;
13470         int ret = -ENOTSUP;
13471
13472         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13473
13474         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13475                 return;
13476
13477 #ifdef RTE_NET_I40E
13478         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13479                                                   res->vf_id, is_on);
13480 #endif
13481
13482         switch (ret) {
13483         case 0:
13484                 break;
13485         case -EINVAL:
13486                 printf("invalid vf_id %d\n", res->vf_id);
13487                 break;
13488         case -ENODEV:
13489                 printf("invalid port_id %d\n", res->port_id);
13490                 break;
13491         case -ENOTSUP:
13492                 printf("function not implemented\n");
13493                 break;
13494         default:
13495                 printf("programming error: (%s)\n", strerror(-ret));
13496         }
13497 }
13498
13499 cmdline_parse_inst_t cmd_set_vf_promisc = {
13500         .f = cmd_set_vf_promisc_parsed,
13501         .data = NULL,
13502         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13503                 "Set unicast promiscuous mode for a VF from the PF",
13504         .tokens = {
13505                 (void *)&cmd_vf_promisc_set,
13506                 (void *)&cmd_vf_promisc_vf,
13507                 (void *)&cmd_vf_promisc_promisc,
13508                 (void *)&cmd_vf_promisc_port_id,
13509                 (void *)&cmd_vf_promisc_vf_id,
13510                 (void *)&cmd_vf_promisc_on_off,
13511                 NULL,
13512         },
13513 };
13514
13515 /* VF multicast promiscuous mode configuration */
13516
13517 /* Common result structure for VF multicast promiscuous mode */
13518 struct cmd_vf_allmulti_result {
13519         cmdline_fixed_string_t set;
13520         cmdline_fixed_string_t vf;
13521         cmdline_fixed_string_t allmulti;
13522         portid_t port_id;
13523         uint32_t vf_id;
13524         cmdline_fixed_string_t on_off;
13525 };
13526
13527 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13528 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13529         TOKEN_STRING_INITIALIZER
13530                 (struct cmd_vf_allmulti_result,
13531                  set, "set");
13532 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13533         TOKEN_STRING_INITIALIZER
13534                 (struct cmd_vf_allmulti_result,
13535                  vf, "vf");
13536 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13537         TOKEN_STRING_INITIALIZER
13538                 (struct cmd_vf_allmulti_result,
13539                  allmulti, "allmulti");
13540 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13541         TOKEN_NUM_INITIALIZER
13542                 (struct cmd_vf_allmulti_result,
13543                  port_id, UINT16);
13544 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13545         TOKEN_NUM_INITIALIZER
13546                 (struct cmd_vf_allmulti_result,
13547                  vf_id, UINT32);
13548 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13549         TOKEN_STRING_INITIALIZER
13550                 (struct cmd_vf_allmulti_result,
13551                  on_off, "on#off");
13552
13553 static void
13554 cmd_set_vf_allmulti_parsed(
13555         void *parsed_result,
13556         __rte_unused struct cmdline *cl,
13557         __rte_unused void *data)
13558 {
13559         struct cmd_vf_allmulti_result *res = parsed_result;
13560         int ret = -ENOTSUP;
13561
13562         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13563
13564         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13565                 return;
13566
13567 #ifdef RTE_NET_I40E
13568         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13569                                                     res->vf_id, is_on);
13570 #endif
13571
13572         switch (ret) {
13573         case 0:
13574                 break;
13575         case -EINVAL:
13576                 printf("invalid vf_id %d\n", res->vf_id);
13577                 break;
13578         case -ENODEV:
13579                 printf("invalid port_id %d\n", res->port_id);
13580                 break;
13581         case -ENOTSUP:
13582                 printf("function not implemented\n");
13583                 break;
13584         default:
13585                 printf("programming error: (%s)\n", strerror(-ret));
13586         }
13587 }
13588
13589 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13590         .f = cmd_set_vf_allmulti_parsed,
13591         .data = NULL,
13592         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13593                 "Set multicast promiscuous mode for a VF from the PF",
13594         .tokens = {
13595                 (void *)&cmd_vf_allmulti_set,
13596                 (void *)&cmd_vf_allmulti_vf,
13597                 (void *)&cmd_vf_allmulti_allmulti,
13598                 (void *)&cmd_vf_allmulti_port_id,
13599                 (void *)&cmd_vf_allmulti_vf_id,
13600                 (void *)&cmd_vf_allmulti_on_off,
13601                 NULL,
13602         },
13603 };
13604
13605 /* vf broadcast mode configuration */
13606
13607 /* Common result structure for vf broadcast */
13608 struct cmd_set_vf_broadcast_result {
13609         cmdline_fixed_string_t set;
13610         cmdline_fixed_string_t vf;
13611         cmdline_fixed_string_t broadcast;
13612         portid_t port_id;
13613         uint16_t vf_id;
13614         cmdline_fixed_string_t on_off;
13615 };
13616
13617 /* Common CLI fields for vf broadcast enable disable */
13618 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13619         TOKEN_STRING_INITIALIZER
13620                 (struct cmd_set_vf_broadcast_result,
13621                  set, "set");
13622 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13623         TOKEN_STRING_INITIALIZER
13624                 (struct cmd_set_vf_broadcast_result,
13625                  vf, "vf");
13626 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13627         TOKEN_STRING_INITIALIZER
13628                 (struct cmd_set_vf_broadcast_result,
13629                  broadcast, "broadcast");
13630 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13631         TOKEN_NUM_INITIALIZER
13632                 (struct cmd_set_vf_broadcast_result,
13633                  port_id, UINT16);
13634 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13635         TOKEN_NUM_INITIALIZER
13636                 (struct cmd_set_vf_broadcast_result,
13637                  vf_id, UINT16);
13638 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13639         TOKEN_STRING_INITIALIZER
13640                 (struct cmd_set_vf_broadcast_result,
13641                  on_off, "on#off");
13642
13643 static void
13644 cmd_set_vf_broadcast_parsed(
13645         void *parsed_result,
13646         __rte_unused struct cmdline *cl,
13647         __rte_unused void *data)
13648 {
13649         struct cmd_set_vf_broadcast_result *res = parsed_result;
13650         int ret = -ENOTSUP;
13651
13652         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13653
13654         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13655                 return;
13656
13657 #ifdef RTE_NET_I40E
13658         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13659                                             res->vf_id, is_on);
13660 #endif
13661
13662         switch (ret) {
13663         case 0:
13664                 break;
13665         case -EINVAL:
13666                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13667                 break;
13668         case -ENODEV:
13669                 printf("invalid port_id %d\n", res->port_id);
13670                 break;
13671         case -ENOTSUP:
13672                 printf("function not implemented\n");
13673                 break;
13674         default:
13675                 printf("programming error: (%s)\n", strerror(-ret));
13676         }
13677 }
13678
13679 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13680         .f = cmd_set_vf_broadcast_parsed,
13681         .data = NULL,
13682         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13683         .tokens = {
13684                 (void *)&cmd_set_vf_broadcast_set,
13685                 (void *)&cmd_set_vf_broadcast_vf,
13686                 (void *)&cmd_set_vf_broadcast_broadcast,
13687                 (void *)&cmd_set_vf_broadcast_port_id,
13688                 (void *)&cmd_set_vf_broadcast_vf_id,
13689                 (void *)&cmd_set_vf_broadcast_on_off,
13690                 NULL,
13691         },
13692 };
13693
13694 /* vf vlan tag configuration */
13695
13696 /* Common result structure for vf vlan tag */
13697 struct cmd_set_vf_vlan_tag_result {
13698         cmdline_fixed_string_t set;
13699         cmdline_fixed_string_t vf;
13700         cmdline_fixed_string_t vlan;
13701         cmdline_fixed_string_t tag;
13702         portid_t port_id;
13703         uint16_t vf_id;
13704         cmdline_fixed_string_t on_off;
13705 };
13706
13707 /* Common CLI fields for vf vlan tag enable disable */
13708 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13709         TOKEN_STRING_INITIALIZER
13710                 (struct cmd_set_vf_vlan_tag_result,
13711                  set, "set");
13712 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13713         TOKEN_STRING_INITIALIZER
13714                 (struct cmd_set_vf_vlan_tag_result,
13715                  vf, "vf");
13716 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13717         TOKEN_STRING_INITIALIZER
13718                 (struct cmd_set_vf_vlan_tag_result,
13719                  vlan, "vlan");
13720 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13721         TOKEN_STRING_INITIALIZER
13722                 (struct cmd_set_vf_vlan_tag_result,
13723                  tag, "tag");
13724 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13725         TOKEN_NUM_INITIALIZER
13726                 (struct cmd_set_vf_vlan_tag_result,
13727                  port_id, UINT16);
13728 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13729         TOKEN_NUM_INITIALIZER
13730                 (struct cmd_set_vf_vlan_tag_result,
13731                  vf_id, UINT16);
13732 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13733         TOKEN_STRING_INITIALIZER
13734                 (struct cmd_set_vf_vlan_tag_result,
13735                  on_off, "on#off");
13736
13737 static void
13738 cmd_set_vf_vlan_tag_parsed(
13739         void *parsed_result,
13740         __rte_unused struct cmdline *cl,
13741         __rte_unused void *data)
13742 {
13743         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13744         int ret = -ENOTSUP;
13745
13746         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13747
13748         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13749                 return;
13750
13751 #ifdef RTE_NET_I40E
13752         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13753                                            res->vf_id, is_on);
13754 #endif
13755
13756         switch (ret) {
13757         case 0:
13758                 break;
13759         case -EINVAL:
13760                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13761                 break;
13762         case -ENODEV:
13763                 printf("invalid port_id %d\n", res->port_id);
13764                 break;
13765         case -ENOTSUP:
13766                 printf("function not implemented\n");
13767                 break;
13768         default:
13769                 printf("programming error: (%s)\n", strerror(-ret));
13770         }
13771 }
13772
13773 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13774         .f = cmd_set_vf_vlan_tag_parsed,
13775         .data = NULL,
13776         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13777         .tokens = {
13778                 (void *)&cmd_set_vf_vlan_tag_set,
13779                 (void *)&cmd_set_vf_vlan_tag_vf,
13780                 (void *)&cmd_set_vf_vlan_tag_vlan,
13781                 (void *)&cmd_set_vf_vlan_tag_tag,
13782                 (void *)&cmd_set_vf_vlan_tag_port_id,
13783                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13784                 (void *)&cmd_set_vf_vlan_tag_on_off,
13785                 NULL,
13786         },
13787 };
13788
13789 /* Common definition of VF and TC TX bandwidth configuration */
13790 struct cmd_vf_tc_bw_result {
13791         cmdline_fixed_string_t set;
13792         cmdline_fixed_string_t vf;
13793         cmdline_fixed_string_t tc;
13794         cmdline_fixed_string_t tx;
13795         cmdline_fixed_string_t min_bw;
13796         cmdline_fixed_string_t max_bw;
13797         cmdline_fixed_string_t strict_link_prio;
13798         portid_t port_id;
13799         uint16_t vf_id;
13800         uint8_t tc_no;
13801         uint32_t bw;
13802         cmdline_fixed_string_t bw_list;
13803         uint8_t tc_map;
13804 };
13805
13806 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13807         TOKEN_STRING_INITIALIZER
13808                 (struct cmd_vf_tc_bw_result,
13809                  set, "set");
13810 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13811         TOKEN_STRING_INITIALIZER
13812                 (struct cmd_vf_tc_bw_result,
13813                  vf, "vf");
13814 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13815         TOKEN_STRING_INITIALIZER
13816                 (struct cmd_vf_tc_bw_result,
13817                  tc, "tc");
13818 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13819         TOKEN_STRING_INITIALIZER
13820                 (struct cmd_vf_tc_bw_result,
13821                  tx, "tx");
13822 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13823         TOKEN_STRING_INITIALIZER
13824                 (struct cmd_vf_tc_bw_result,
13825                  strict_link_prio, "strict-link-priority");
13826 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13827         TOKEN_STRING_INITIALIZER
13828                 (struct cmd_vf_tc_bw_result,
13829                  min_bw, "min-bandwidth");
13830 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13831         TOKEN_STRING_INITIALIZER
13832                 (struct cmd_vf_tc_bw_result,
13833                  max_bw, "max-bandwidth");
13834 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13835         TOKEN_NUM_INITIALIZER
13836                 (struct cmd_vf_tc_bw_result,
13837                  port_id, UINT16);
13838 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13839         TOKEN_NUM_INITIALIZER
13840                 (struct cmd_vf_tc_bw_result,
13841                  vf_id, UINT16);
13842 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13843         TOKEN_NUM_INITIALIZER
13844                 (struct cmd_vf_tc_bw_result,
13845                  tc_no, UINT8);
13846 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13847         TOKEN_NUM_INITIALIZER
13848                 (struct cmd_vf_tc_bw_result,
13849                  bw, UINT32);
13850 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13851         TOKEN_STRING_INITIALIZER
13852                 (struct cmd_vf_tc_bw_result,
13853                  bw_list, NULL);
13854 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13855         TOKEN_NUM_INITIALIZER
13856                 (struct cmd_vf_tc_bw_result,
13857                  tc_map, UINT8);
13858
13859 /* VF max bandwidth setting */
13860 static void
13861 cmd_vf_max_bw_parsed(
13862         void *parsed_result,
13863         __rte_unused struct cmdline *cl,
13864         __rte_unused void *data)
13865 {
13866         struct cmd_vf_tc_bw_result *res = parsed_result;
13867         int ret = -ENOTSUP;
13868
13869         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13870                 return;
13871
13872 #ifdef RTE_NET_I40E
13873         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13874                                          res->vf_id, res->bw);
13875 #endif
13876
13877         switch (ret) {
13878         case 0:
13879                 break;
13880         case -EINVAL:
13881                 printf("invalid vf_id %d or bandwidth %d\n",
13882                        res->vf_id, res->bw);
13883                 break;
13884         case -ENODEV:
13885                 printf("invalid port_id %d\n", res->port_id);
13886                 break;
13887         case -ENOTSUP:
13888                 printf("function not implemented\n");
13889                 break;
13890         default:
13891                 printf("programming error: (%s)\n", strerror(-ret));
13892         }
13893 }
13894
13895 cmdline_parse_inst_t cmd_vf_max_bw = {
13896         .f = cmd_vf_max_bw_parsed,
13897         .data = NULL,
13898         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13899         .tokens = {
13900                 (void *)&cmd_vf_tc_bw_set,
13901                 (void *)&cmd_vf_tc_bw_vf,
13902                 (void *)&cmd_vf_tc_bw_tx,
13903                 (void *)&cmd_vf_tc_bw_max_bw,
13904                 (void *)&cmd_vf_tc_bw_port_id,
13905                 (void *)&cmd_vf_tc_bw_vf_id,
13906                 (void *)&cmd_vf_tc_bw_bw,
13907                 NULL,
13908         },
13909 };
13910
13911 static int
13912 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13913                            uint8_t *tc_num,
13914                            char *str)
13915 {
13916         uint32_t size;
13917         const char *p, *p0 = str;
13918         char s[256];
13919         char *end;
13920         char *str_fld[16];
13921         uint16_t i;
13922         int ret;
13923
13924         p = strchr(p0, '(');
13925         if (p == NULL) {
13926                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13927                 return -1;
13928         }
13929         p++;
13930         p0 = strchr(p, ')');
13931         if (p0 == NULL) {
13932                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13933                 return -1;
13934         }
13935         size = p0 - p;
13936         if (size >= sizeof(s)) {
13937                 printf("The string size exceeds the internal buffer size\n");
13938                 return -1;
13939         }
13940         snprintf(s, sizeof(s), "%.*s", size, p);
13941         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13942         if (ret <= 0) {
13943                 printf("Failed to get the bandwidth list. ");
13944                 return -1;
13945         }
13946         *tc_num = ret;
13947         for (i = 0; i < ret; i++)
13948                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13949
13950         return 0;
13951 }
13952
13953 /* TC min bandwidth setting */
13954 static void
13955 cmd_vf_tc_min_bw_parsed(
13956         void *parsed_result,
13957         __rte_unused struct cmdline *cl,
13958         __rte_unused void *data)
13959 {
13960         struct cmd_vf_tc_bw_result *res = parsed_result;
13961         uint8_t tc_num;
13962         uint8_t bw[16];
13963         int ret = -ENOTSUP;
13964
13965         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13966                 return;
13967
13968         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13969         if (ret)
13970                 return;
13971
13972 #ifdef RTE_NET_I40E
13973         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13974                                               tc_num, bw);
13975 #endif
13976
13977         switch (ret) {
13978         case 0:
13979                 break;
13980         case -EINVAL:
13981                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13982                 break;
13983         case -ENODEV:
13984                 printf("invalid port_id %d\n", res->port_id);
13985                 break;
13986         case -ENOTSUP:
13987                 printf("function not implemented\n");
13988                 break;
13989         default:
13990                 printf("programming error: (%s)\n", strerror(-ret));
13991         }
13992 }
13993
13994 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13995         .f = cmd_vf_tc_min_bw_parsed,
13996         .data = NULL,
13997         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13998                     " <bw1, bw2, ...>",
13999         .tokens = {
14000                 (void *)&cmd_vf_tc_bw_set,
14001                 (void *)&cmd_vf_tc_bw_vf,
14002                 (void *)&cmd_vf_tc_bw_tc,
14003                 (void *)&cmd_vf_tc_bw_tx,
14004                 (void *)&cmd_vf_tc_bw_min_bw,
14005                 (void *)&cmd_vf_tc_bw_port_id,
14006                 (void *)&cmd_vf_tc_bw_vf_id,
14007                 (void *)&cmd_vf_tc_bw_bw_list,
14008                 NULL,
14009         },
14010 };
14011
14012 static void
14013 cmd_tc_min_bw_parsed(
14014         void *parsed_result,
14015         __rte_unused struct cmdline *cl,
14016         __rte_unused void *data)
14017 {
14018         struct cmd_vf_tc_bw_result *res = parsed_result;
14019         struct rte_port *port;
14020         uint8_t tc_num;
14021         uint8_t bw[16];
14022         int ret = -ENOTSUP;
14023
14024         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14025                 return;
14026
14027         port = &ports[res->port_id];
14028         /** Check if the port is not started **/
14029         if (port->port_status != RTE_PORT_STOPPED) {
14030                 printf("Please stop port %d first\n", res->port_id);
14031                 return;
14032         }
14033
14034         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14035         if (ret)
14036                 return;
14037
14038 #ifdef RTE_NET_IXGBE
14039         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14040 #endif
14041
14042         switch (ret) {
14043         case 0:
14044                 break;
14045         case -EINVAL:
14046                 printf("invalid bandwidth\n");
14047                 break;
14048         case -ENODEV:
14049                 printf("invalid port_id %d\n", res->port_id);
14050                 break;
14051         case -ENOTSUP:
14052                 printf("function not implemented\n");
14053                 break;
14054         default:
14055                 printf("programming error: (%s)\n", strerror(-ret));
14056         }
14057 }
14058
14059 cmdline_parse_inst_t cmd_tc_min_bw = {
14060         .f = cmd_tc_min_bw_parsed,
14061         .data = NULL,
14062         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14063         .tokens = {
14064                 (void *)&cmd_vf_tc_bw_set,
14065                 (void *)&cmd_vf_tc_bw_tc,
14066                 (void *)&cmd_vf_tc_bw_tx,
14067                 (void *)&cmd_vf_tc_bw_min_bw,
14068                 (void *)&cmd_vf_tc_bw_port_id,
14069                 (void *)&cmd_vf_tc_bw_bw_list,
14070                 NULL,
14071         },
14072 };
14073
14074 /* TC max bandwidth setting */
14075 static void
14076 cmd_vf_tc_max_bw_parsed(
14077         void *parsed_result,
14078         __rte_unused struct cmdline *cl,
14079         __rte_unused void *data)
14080 {
14081         struct cmd_vf_tc_bw_result *res = parsed_result;
14082         int ret = -ENOTSUP;
14083
14084         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14085                 return;
14086
14087 #ifdef RTE_NET_I40E
14088         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14089                                             res->tc_no, res->bw);
14090 #endif
14091
14092         switch (ret) {
14093         case 0:
14094                 break;
14095         case -EINVAL:
14096                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14097                        res->vf_id, res->tc_no, res->bw);
14098                 break;
14099         case -ENODEV:
14100                 printf("invalid port_id %d\n", res->port_id);
14101                 break;
14102         case -ENOTSUP:
14103                 printf("function not implemented\n");
14104                 break;
14105         default:
14106                 printf("programming error: (%s)\n", strerror(-ret));
14107         }
14108 }
14109
14110 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14111         .f = cmd_vf_tc_max_bw_parsed,
14112         .data = NULL,
14113         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14114                     " <bandwidth>",
14115         .tokens = {
14116                 (void *)&cmd_vf_tc_bw_set,
14117                 (void *)&cmd_vf_tc_bw_vf,
14118                 (void *)&cmd_vf_tc_bw_tc,
14119                 (void *)&cmd_vf_tc_bw_tx,
14120                 (void *)&cmd_vf_tc_bw_max_bw,
14121                 (void *)&cmd_vf_tc_bw_port_id,
14122                 (void *)&cmd_vf_tc_bw_vf_id,
14123                 (void *)&cmd_vf_tc_bw_tc_no,
14124                 (void *)&cmd_vf_tc_bw_bw,
14125                 NULL,
14126         },
14127 };
14128
14129 /** Set VXLAN encapsulation details */
14130 struct cmd_set_vxlan_result {
14131         cmdline_fixed_string_t set;
14132         cmdline_fixed_string_t vxlan;
14133         cmdline_fixed_string_t pos_token;
14134         cmdline_fixed_string_t ip_version;
14135         uint32_t vlan_present:1;
14136         uint32_t vni;
14137         uint16_t udp_src;
14138         uint16_t udp_dst;
14139         cmdline_ipaddr_t ip_src;
14140         cmdline_ipaddr_t ip_dst;
14141         uint16_t tci;
14142         uint8_t tos;
14143         uint8_t ttl;
14144         struct rte_ether_addr eth_src;
14145         struct rte_ether_addr eth_dst;
14146 };
14147
14148 cmdline_parse_token_string_t cmd_set_vxlan_set =
14149         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
14150 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
14151         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
14152 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
14153         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
14154                                  "vxlan-tos-ttl");
14155 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
14156         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
14157                                  "vxlan-with-vlan");
14158 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
14159         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14160                                  "ip-version");
14161 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
14162         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
14163                                  "ipv4#ipv6");
14164 cmdline_parse_token_string_t cmd_set_vxlan_vni =
14165         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14166                                  "vni");
14167 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
14168         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
14169 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
14170         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14171                                  "udp-src");
14172 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
14173         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
14174 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
14175         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14176                                  "udp-dst");
14177 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
14178         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
14179 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
14180         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14181                                  "ip-tos");
14182 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
14183         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
14184 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
14185         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14186                                  "ip-ttl");
14187 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
14188         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
14189 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
14190         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14191                                  "ip-src");
14192 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
14193         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
14194 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
14195         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14196                                  "ip-dst");
14197 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
14198         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
14199 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
14200         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14201                                  "vlan-tci");
14202 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
14203         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
14204 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
14205         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14206                                  "eth-src");
14207 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
14208         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
14209 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
14210         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14211                                  "eth-dst");
14212 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
14213         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
14214
14215 static void cmd_set_vxlan_parsed(void *parsed_result,
14216         __rte_unused struct cmdline *cl,
14217         __rte_unused void *data)
14218 {
14219         struct cmd_set_vxlan_result *res = parsed_result;
14220         union {
14221                 uint32_t vxlan_id;
14222                 uint8_t vni[4];
14223         } id = {
14224                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
14225         };
14226
14227         vxlan_encap_conf.select_tos_ttl = 0;
14228         if (strcmp(res->vxlan, "vxlan") == 0)
14229                 vxlan_encap_conf.select_vlan = 0;
14230         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
14231                 vxlan_encap_conf.select_vlan = 1;
14232         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
14233                 vxlan_encap_conf.select_vlan = 0;
14234                 vxlan_encap_conf.select_tos_ttl = 1;
14235         }
14236         if (strcmp(res->ip_version, "ipv4") == 0)
14237                 vxlan_encap_conf.select_ipv4 = 1;
14238         else if (strcmp(res->ip_version, "ipv6") == 0)
14239                 vxlan_encap_conf.select_ipv4 = 0;
14240         else
14241                 return;
14242         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
14243         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
14244         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
14245         vxlan_encap_conf.ip_tos = res->tos;
14246         vxlan_encap_conf.ip_ttl = res->ttl;
14247         if (vxlan_encap_conf.select_ipv4) {
14248                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
14249                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
14250         } else {
14251                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
14252                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
14253         }
14254         if (vxlan_encap_conf.select_vlan)
14255                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14256         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
14257                    RTE_ETHER_ADDR_LEN);
14258         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14259                    RTE_ETHER_ADDR_LEN);
14260 }
14261
14262 cmdline_parse_inst_t cmd_set_vxlan = {
14263         .f = cmd_set_vxlan_parsed,
14264         .data = NULL,
14265         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
14266                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
14267                 " eth-src <eth-src> eth-dst <eth-dst>",
14268         .tokens = {
14269                 (void *)&cmd_set_vxlan_set,
14270                 (void *)&cmd_set_vxlan_vxlan,
14271                 (void *)&cmd_set_vxlan_ip_version,
14272                 (void *)&cmd_set_vxlan_ip_version_value,
14273                 (void *)&cmd_set_vxlan_vni,
14274                 (void *)&cmd_set_vxlan_vni_value,
14275                 (void *)&cmd_set_vxlan_udp_src,
14276                 (void *)&cmd_set_vxlan_udp_src_value,
14277                 (void *)&cmd_set_vxlan_udp_dst,
14278                 (void *)&cmd_set_vxlan_udp_dst_value,
14279                 (void *)&cmd_set_vxlan_ip_src,
14280                 (void *)&cmd_set_vxlan_ip_src_value,
14281                 (void *)&cmd_set_vxlan_ip_dst,
14282                 (void *)&cmd_set_vxlan_ip_dst_value,
14283                 (void *)&cmd_set_vxlan_eth_src,
14284                 (void *)&cmd_set_vxlan_eth_src_value,
14285                 (void *)&cmd_set_vxlan_eth_dst,
14286                 (void *)&cmd_set_vxlan_eth_dst_value,
14287                 NULL,
14288         },
14289 };
14290
14291 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
14292         .f = cmd_set_vxlan_parsed,
14293         .data = NULL,
14294         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
14295                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
14296                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
14297                 " eth-dst <eth-dst>",
14298         .tokens = {
14299                 (void *)&cmd_set_vxlan_set,
14300                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
14301                 (void *)&cmd_set_vxlan_ip_version,
14302                 (void *)&cmd_set_vxlan_ip_version_value,
14303                 (void *)&cmd_set_vxlan_vni,
14304                 (void *)&cmd_set_vxlan_vni_value,
14305                 (void *)&cmd_set_vxlan_udp_src,
14306                 (void *)&cmd_set_vxlan_udp_src_value,
14307                 (void *)&cmd_set_vxlan_udp_dst,
14308                 (void *)&cmd_set_vxlan_udp_dst_value,
14309                 (void *)&cmd_set_vxlan_ip_tos,
14310                 (void *)&cmd_set_vxlan_ip_tos_value,
14311                 (void *)&cmd_set_vxlan_ip_ttl,
14312                 (void *)&cmd_set_vxlan_ip_ttl_value,
14313                 (void *)&cmd_set_vxlan_ip_src,
14314                 (void *)&cmd_set_vxlan_ip_src_value,
14315                 (void *)&cmd_set_vxlan_ip_dst,
14316                 (void *)&cmd_set_vxlan_ip_dst_value,
14317                 (void *)&cmd_set_vxlan_eth_src,
14318                 (void *)&cmd_set_vxlan_eth_src_value,
14319                 (void *)&cmd_set_vxlan_eth_dst,
14320                 (void *)&cmd_set_vxlan_eth_dst_value,
14321                 NULL,
14322         },
14323 };
14324
14325 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
14326         .f = cmd_set_vxlan_parsed,
14327         .data = NULL,
14328         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
14329                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
14330                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
14331                 " <eth-dst>",
14332         .tokens = {
14333                 (void *)&cmd_set_vxlan_set,
14334                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
14335                 (void *)&cmd_set_vxlan_ip_version,
14336                 (void *)&cmd_set_vxlan_ip_version_value,
14337                 (void *)&cmd_set_vxlan_vni,
14338                 (void *)&cmd_set_vxlan_vni_value,
14339                 (void *)&cmd_set_vxlan_udp_src,
14340                 (void *)&cmd_set_vxlan_udp_src_value,
14341                 (void *)&cmd_set_vxlan_udp_dst,
14342                 (void *)&cmd_set_vxlan_udp_dst_value,
14343                 (void *)&cmd_set_vxlan_ip_src,
14344                 (void *)&cmd_set_vxlan_ip_src_value,
14345                 (void *)&cmd_set_vxlan_ip_dst,
14346                 (void *)&cmd_set_vxlan_ip_dst_value,
14347                 (void *)&cmd_set_vxlan_vlan,
14348                 (void *)&cmd_set_vxlan_vlan_value,
14349                 (void *)&cmd_set_vxlan_eth_src,
14350                 (void *)&cmd_set_vxlan_eth_src_value,
14351                 (void *)&cmd_set_vxlan_eth_dst,
14352                 (void *)&cmd_set_vxlan_eth_dst_value,
14353                 NULL,
14354         },
14355 };
14356
14357 /** Set NVGRE encapsulation details */
14358 struct cmd_set_nvgre_result {
14359         cmdline_fixed_string_t set;
14360         cmdline_fixed_string_t nvgre;
14361         cmdline_fixed_string_t pos_token;
14362         cmdline_fixed_string_t ip_version;
14363         uint32_t tni;
14364         cmdline_ipaddr_t ip_src;
14365         cmdline_ipaddr_t ip_dst;
14366         uint16_t tci;
14367         struct rte_ether_addr eth_src;
14368         struct rte_ether_addr eth_dst;
14369 };
14370
14371 cmdline_parse_token_string_t cmd_set_nvgre_set =
14372         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
14373 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
14374         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
14375 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
14376         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
14377                                  "nvgre-with-vlan");
14378 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
14379         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14380                                  "ip-version");
14381 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
14382         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
14383                                  "ipv4#ipv6");
14384 cmdline_parse_token_string_t cmd_set_nvgre_tni =
14385         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14386                                  "tni");
14387 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
14388         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
14389 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
14390         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14391                                  "ip-src");
14392 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
14393         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
14394 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
14395         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14396                                  "ip-dst");
14397 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
14398         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
14399 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
14400         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14401                                  "vlan-tci");
14402 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
14403         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
14404 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
14405         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14406                                  "eth-src");
14407 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
14408         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
14409 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
14410         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14411                                  "eth-dst");
14412 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
14413         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
14414
14415 static void cmd_set_nvgre_parsed(void *parsed_result,
14416         __rte_unused struct cmdline *cl,
14417         __rte_unused void *data)
14418 {
14419         struct cmd_set_nvgre_result *res = parsed_result;
14420         union {
14421                 uint32_t nvgre_tni;
14422                 uint8_t tni[4];
14423         } id = {
14424                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
14425         };
14426
14427         if (strcmp(res->nvgre, "nvgre") == 0)
14428                 nvgre_encap_conf.select_vlan = 0;
14429         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
14430                 nvgre_encap_conf.select_vlan = 1;
14431         if (strcmp(res->ip_version, "ipv4") == 0)
14432                 nvgre_encap_conf.select_ipv4 = 1;
14433         else if (strcmp(res->ip_version, "ipv6") == 0)
14434                 nvgre_encap_conf.select_ipv4 = 0;
14435         else
14436                 return;
14437         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
14438         if (nvgre_encap_conf.select_ipv4) {
14439                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
14440                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
14441         } else {
14442                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
14443                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
14444         }
14445         if (nvgre_encap_conf.select_vlan)
14446                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14447         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
14448                    RTE_ETHER_ADDR_LEN);
14449         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14450                    RTE_ETHER_ADDR_LEN);
14451 }
14452
14453 cmdline_parse_inst_t cmd_set_nvgre = {
14454         .f = cmd_set_nvgre_parsed,
14455         .data = NULL,
14456         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
14457                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
14458                 " eth-dst <eth-dst>",
14459         .tokens = {
14460                 (void *)&cmd_set_nvgre_set,
14461                 (void *)&cmd_set_nvgre_nvgre,
14462                 (void *)&cmd_set_nvgre_ip_version,
14463                 (void *)&cmd_set_nvgre_ip_version_value,
14464                 (void *)&cmd_set_nvgre_tni,
14465                 (void *)&cmd_set_nvgre_tni_value,
14466                 (void *)&cmd_set_nvgre_ip_src,
14467                 (void *)&cmd_set_nvgre_ip_src_value,
14468                 (void *)&cmd_set_nvgre_ip_dst,
14469                 (void *)&cmd_set_nvgre_ip_dst_value,
14470                 (void *)&cmd_set_nvgre_eth_src,
14471                 (void *)&cmd_set_nvgre_eth_src_value,
14472                 (void *)&cmd_set_nvgre_eth_dst,
14473                 (void *)&cmd_set_nvgre_eth_dst_value,
14474                 NULL,
14475         },
14476 };
14477
14478 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
14479         .f = cmd_set_nvgre_parsed,
14480         .data = NULL,
14481         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
14482                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
14483                 " eth-src <eth-src> eth-dst <eth-dst>",
14484         .tokens = {
14485                 (void *)&cmd_set_nvgre_set,
14486                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
14487                 (void *)&cmd_set_nvgre_ip_version,
14488                 (void *)&cmd_set_nvgre_ip_version_value,
14489                 (void *)&cmd_set_nvgre_tni,
14490                 (void *)&cmd_set_nvgre_tni_value,
14491                 (void *)&cmd_set_nvgre_ip_src,
14492                 (void *)&cmd_set_nvgre_ip_src_value,
14493                 (void *)&cmd_set_nvgre_ip_dst,
14494                 (void *)&cmd_set_nvgre_ip_dst_value,
14495                 (void *)&cmd_set_nvgre_vlan,
14496                 (void *)&cmd_set_nvgre_vlan_value,
14497                 (void *)&cmd_set_nvgre_eth_src,
14498                 (void *)&cmd_set_nvgre_eth_src_value,
14499                 (void *)&cmd_set_nvgre_eth_dst,
14500                 (void *)&cmd_set_nvgre_eth_dst_value,
14501                 NULL,
14502         },
14503 };
14504
14505 /** Set L2 encapsulation details */
14506 struct cmd_set_l2_encap_result {
14507         cmdline_fixed_string_t set;
14508         cmdline_fixed_string_t l2_encap;
14509         cmdline_fixed_string_t pos_token;
14510         cmdline_fixed_string_t ip_version;
14511         uint32_t vlan_present:1;
14512         uint16_t tci;
14513         struct rte_ether_addr eth_src;
14514         struct rte_ether_addr eth_dst;
14515 };
14516
14517 cmdline_parse_token_string_t cmd_set_l2_encap_set =
14518         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
14519 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
14520         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
14521 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
14522         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
14523                                  "l2_encap-with-vlan");
14524 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
14525         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14526                                  "ip-version");
14527 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
14528         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
14529                                  "ipv4#ipv6");
14530 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
14531         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14532                                  "vlan-tci");
14533 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
14534         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
14535 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
14536         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14537                                  "eth-src");
14538 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
14539         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
14540 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
14541         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14542                                  "eth-dst");
14543 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
14544         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
14545
14546 static void cmd_set_l2_encap_parsed(void *parsed_result,
14547         __rte_unused struct cmdline *cl,
14548         __rte_unused void *data)
14549 {
14550         struct cmd_set_l2_encap_result *res = parsed_result;
14551
14552         if (strcmp(res->l2_encap, "l2_encap") == 0)
14553                 l2_encap_conf.select_vlan = 0;
14554         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
14555                 l2_encap_conf.select_vlan = 1;
14556         if (strcmp(res->ip_version, "ipv4") == 0)
14557                 l2_encap_conf.select_ipv4 = 1;
14558         else if (strcmp(res->ip_version, "ipv6") == 0)
14559                 l2_encap_conf.select_ipv4 = 0;
14560         else
14561                 return;
14562         if (l2_encap_conf.select_vlan)
14563                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14564         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
14565                    RTE_ETHER_ADDR_LEN);
14566         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14567                    RTE_ETHER_ADDR_LEN);
14568 }
14569
14570 cmdline_parse_inst_t cmd_set_l2_encap = {
14571         .f = cmd_set_l2_encap_parsed,
14572         .data = NULL,
14573         .help_str = "set l2_encap ip-version ipv4|ipv6"
14574                 " eth-src <eth-src> eth-dst <eth-dst>",
14575         .tokens = {
14576                 (void *)&cmd_set_l2_encap_set,
14577                 (void *)&cmd_set_l2_encap_l2_encap,
14578                 (void *)&cmd_set_l2_encap_ip_version,
14579                 (void *)&cmd_set_l2_encap_ip_version_value,
14580                 (void *)&cmd_set_l2_encap_eth_src,
14581                 (void *)&cmd_set_l2_encap_eth_src_value,
14582                 (void *)&cmd_set_l2_encap_eth_dst,
14583                 (void *)&cmd_set_l2_encap_eth_dst_value,
14584                 NULL,
14585         },
14586 };
14587
14588 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
14589         .f = cmd_set_l2_encap_parsed,
14590         .data = NULL,
14591         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
14592                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
14593         .tokens = {
14594                 (void *)&cmd_set_l2_encap_set,
14595                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
14596                 (void *)&cmd_set_l2_encap_ip_version,
14597                 (void *)&cmd_set_l2_encap_ip_version_value,
14598                 (void *)&cmd_set_l2_encap_vlan,
14599                 (void *)&cmd_set_l2_encap_vlan_value,
14600                 (void *)&cmd_set_l2_encap_eth_src,
14601                 (void *)&cmd_set_l2_encap_eth_src_value,
14602                 (void *)&cmd_set_l2_encap_eth_dst,
14603                 (void *)&cmd_set_l2_encap_eth_dst_value,
14604                 NULL,
14605         },
14606 };
14607
14608 /** Set L2 decapsulation details */
14609 struct cmd_set_l2_decap_result {
14610         cmdline_fixed_string_t set;
14611         cmdline_fixed_string_t l2_decap;
14612         cmdline_fixed_string_t pos_token;
14613         uint32_t vlan_present:1;
14614 };
14615
14616 cmdline_parse_token_string_t cmd_set_l2_decap_set =
14617         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
14618 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
14619         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
14620                                  "l2_decap");
14621 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
14622         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
14623                                  "l2_decap-with-vlan");
14624
14625 static void cmd_set_l2_decap_parsed(void *parsed_result,
14626         __rte_unused struct cmdline *cl,
14627         __rte_unused void *data)
14628 {
14629         struct cmd_set_l2_decap_result *res = parsed_result;
14630
14631         if (strcmp(res->l2_decap, "l2_decap") == 0)
14632                 l2_decap_conf.select_vlan = 0;
14633         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
14634                 l2_decap_conf.select_vlan = 1;
14635 }
14636
14637 cmdline_parse_inst_t cmd_set_l2_decap = {
14638         .f = cmd_set_l2_decap_parsed,
14639         .data = NULL,
14640         .help_str = "set l2_decap",
14641         .tokens = {
14642                 (void *)&cmd_set_l2_decap_set,
14643                 (void *)&cmd_set_l2_decap_l2_decap,
14644                 NULL,
14645         },
14646 };
14647
14648 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
14649         .f = cmd_set_l2_decap_parsed,
14650         .data = NULL,
14651         .help_str = "set l2_decap-with-vlan",
14652         .tokens = {
14653                 (void *)&cmd_set_l2_decap_set,
14654                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
14655                 NULL,
14656         },
14657 };
14658
14659 /** Set MPLSoGRE encapsulation details */
14660 struct cmd_set_mplsogre_encap_result {
14661         cmdline_fixed_string_t set;
14662         cmdline_fixed_string_t mplsogre;
14663         cmdline_fixed_string_t pos_token;
14664         cmdline_fixed_string_t ip_version;
14665         uint32_t vlan_present:1;
14666         uint32_t label;
14667         cmdline_ipaddr_t ip_src;
14668         cmdline_ipaddr_t ip_dst;
14669         uint16_t tci;
14670         struct rte_ether_addr eth_src;
14671         struct rte_ether_addr eth_dst;
14672 };
14673
14674 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
14675         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
14676                                  "set");
14677 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
14678         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
14679                                  "mplsogre_encap");
14680 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
14681         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14682                                  mplsogre, "mplsogre_encap-with-vlan");
14683 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
14684         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14685                                  pos_token, "ip-version");
14686 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
14687         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14688                                  ip_version, "ipv4#ipv6");
14689 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
14690         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14691                                  pos_token, "label");
14692 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
14693         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
14694                               UINT32);
14695 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
14696         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14697                                  pos_token, "ip-src");
14698 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
14699         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
14700 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
14701         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14702                                  pos_token, "ip-dst");
14703 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
14704         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
14705 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
14706         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14707                                  pos_token, "vlan-tci");
14708 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
14709         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
14710                               UINT16);
14711 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
14712         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14713                                  pos_token, "eth-src");
14714 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
14715         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14716                                     eth_src);
14717 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
14718         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14719                                  pos_token, "eth-dst");
14720 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
14721         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14722                                     eth_dst);
14723
14724 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
14725         __rte_unused struct cmdline *cl,
14726         __rte_unused void *data)
14727 {
14728         struct cmd_set_mplsogre_encap_result *res = parsed_result;
14729         union {
14730                 uint32_t mplsogre_label;
14731                 uint8_t label[4];
14732         } id = {
14733                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
14734         };
14735
14736         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
14737                 mplsogre_encap_conf.select_vlan = 0;
14738         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
14739                 mplsogre_encap_conf.select_vlan = 1;
14740         if (strcmp(res->ip_version, "ipv4") == 0)
14741                 mplsogre_encap_conf.select_ipv4 = 1;
14742         else if (strcmp(res->ip_version, "ipv6") == 0)
14743                 mplsogre_encap_conf.select_ipv4 = 0;
14744         else
14745                 return;
14746         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
14747         if (mplsogre_encap_conf.select_ipv4) {
14748                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
14749                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
14750         } else {
14751                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
14752                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
14753         }
14754         if (mplsogre_encap_conf.select_vlan)
14755                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14756         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
14757                    RTE_ETHER_ADDR_LEN);
14758         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14759                    RTE_ETHER_ADDR_LEN);
14760 }
14761
14762 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
14763         .f = cmd_set_mplsogre_encap_parsed,
14764         .data = NULL,
14765         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
14766                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
14767                 " eth-dst <eth-dst>",
14768         .tokens = {
14769                 (void *)&cmd_set_mplsogre_encap_set,
14770                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
14771                 (void *)&cmd_set_mplsogre_encap_ip_version,
14772                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
14773                 (void *)&cmd_set_mplsogre_encap_label,
14774                 (void *)&cmd_set_mplsogre_encap_label_value,
14775                 (void *)&cmd_set_mplsogre_encap_ip_src,
14776                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
14777                 (void *)&cmd_set_mplsogre_encap_ip_dst,
14778                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
14779                 (void *)&cmd_set_mplsogre_encap_eth_src,
14780                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
14781                 (void *)&cmd_set_mplsogre_encap_eth_dst,
14782                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
14783                 NULL,
14784         },
14785 };
14786
14787 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
14788         .f = cmd_set_mplsogre_encap_parsed,
14789         .data = NULL,
14790         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
14791                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
14792                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
14793         .tokens = {
14794                 (void *)&cmd_set_mplsogre_encap_set,
14795                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
14796                 (void *)&cmd_set_mplsogre_encap_ip_version,
14797                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
14798                 (void *)&cmd_set_mplsogre_encap_label,
14799                 (void *)&cmd_set_mplsogre_encap_label_value,
14800                 (void *)&cmd_set_mplsogre_encap_ip_src,
14801                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
14802                 (void *)&cmd_set_mplsogre_encap_ip_dst,
14803                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
14804                 (void *)&cmd_set_mplsogre_encap_vlan,
14805                 (void *)&cmd_set_mplsogre_encap_vlan_value,
14806                 (void *)&cmd_set_mplsogre_encap_eth_src,
14807                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
14808                 (void *)&cmd_set_mplsogre_encap_eth_dst,
14809                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
14810                 NULL,
14811         },
14812 };
14813
14814 /** Set MPLSoGRE decapsulation details */
14815 struct cmd_set_mplsogre_decap_result {
14816         cmdline_fixed_string_t set;
14817         cmdline_fixed_string_t mplsogre;
14818         cmdline_fixed_string_t pos_token;
14819         cmdline_fixed_string_t ip_version;
14820         uint32_t vlan_present:1;
14821 };
14822
14823 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
14824         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
14825                                  "set");
14826 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
14827         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
14828                                  "mplsogre_decap");
14829 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
14830         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
14831                                  mplsogre, "mplsogre_decap-with-vlan");
14832 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
14833         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
14834                                  pos_token, "ip-version");
14835 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
14836         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
14837                                  ip_version, "ipv4#ipv6");
14838
14839 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
14840         __rte_unused struct cmdline *cl,
14841         __rte_unused void *data)
14842 {
14843         struct cmd_set_mplsogre_decap_result *res = parsed_result;
14844
14845         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
14846                 mplsogre_decap_conf.select_vlan = 0;
14847         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
14848                 mplsogre_decap_conf.select_vlan = 1;
14849         if (strcmp(res->ip_version, "ipv4") == 0)
14850                 mplsogre_decap_conf.select_ipv4 = 1;
14851         else if (strcmp(res->ip_version, "ipv6") == 0)
14852                 mplsogre_decap_conf.select_ipv4 = 0;
14853 }
14854
14855 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
14856         .f = cmd_set_mplsogre_decap_parsed,
14857         .data = NULL,
14858         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
14859         .tokens = {
14860                 (void *)&cmd_set_mplsogre_decap_set,
14861                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
14862                 (void *)&cmd_set_mplsogre_decap_ip_version,
14863                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
14864                 NULL,
14865         },
14866 };
14867
14868 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
14869         .f = cmd_set_mplsogre_decap_parsed,
14870         .data = NULL,
14871         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
14872         .tokens = {
14873                 (void *)&cmd_set_mplsogre_decap_set,
14874                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
14875                 (void *)&cmd_set_mplsogre_decap_ip_version,
14876                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
14877                 NULL,
14878         },
14879 };
14880
14881 /** Set MPLSoUDP encapsulation details */
14882 struct cmd_set_mplsoudp_encap_result {
14883         cmdline_fixed_string_t set;
14884         cmdline_fixed_string_t mplsoudp;
14885         cmdline_fixed_string_t pos_token;
14886         cmdline_fixed_string_t ip_version;
14887         uint32_t vlan_present:1;
14888         uint32_t label;
14889         uint16_t udp_src;
14890         uint16_t udp_dst;
14891         cmdline_ipaddr_t ip_src;
14892         cmdline_ipaddr_t ip_dst;
14893         uint16_t tci;
14894         struct rte_ether_addr eth_src;
14895         struct rte_ether_addr eth_dst;
14896 };
14897
14898 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
14899         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
14900                                  "set");
14901 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
14902         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
14903                                  "mplsoudp_encap");
14904 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
14905         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14906                                  mplsoudp, "mplsoudp_encap-with-vlan");
14907 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
14908         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14909                                  pos_token, "ip-version");
14910 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
14911         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14912                                  ip_version, "ipv4#ipv6");
14913 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
14914         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14915                                  pos_token, "label");
14916 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
14917         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
14918                               UINT32);
14919 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
14920         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14921                                  pos_token, "udp-src");
14922 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
14923         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
14924                               UINT16);
14925 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
14926         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14927                                  pos_token, "udp-dst");
14928 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
14929         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
14930                               UINT16);
14931 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
14932         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14933                                  pos_token, "ip-src");
14934 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
14935         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
14936 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
14937         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14938                                  pos_token, "ip-dst");
14939 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
14940         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
14941 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
14942         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14943                                  pos_token, "vlan-tci");
14944 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
14945         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
14946                               UINT16);
14947 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
14948         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14949                                  pos_token, "eth-src");
14950 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
14951         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14952                                     eth_src);
14953 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
14954         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14955                                  pos_token, "eth-dst");
14956 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
14957         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
14958                                     eth_dst);
14959
14960 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
14961         __rte_unused struct cmdline *cl,
14962         __rte_unused void *data)
14963 {
14964         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
14965         union {
14966                 uint32_t mplsoudp_label;
14967                 uint8_t label[4];
14968         } id = {
14969                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
14970         };
14971
14972         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
14973                 mplsoudp_encap_conf.select_vlan = 0;
14974         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
14975                 mplsoudp_encap_conf.select_vlan = 1;
14976         if (strcmp(res->ip_version, "ipv4") == 0)
14977                 mplsoudp_encap_conf.select_ipv4 = 1;
14978         else if (strcmp(res->ip_version, "ipv6") == 0)
14979                 mplsoudp_encap_conf.select_ipv4 = 0;
14980         else
14981                 return;
14982         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
14983         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
14984         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
14985         if (mplsoudp_encap_conf.select_ipv4) {
14986                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
14987                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
14988         } else {
14989                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
14990                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
14991         }
14992         if (mplsoudp_encap_conf.select_vlan)
14993                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14994         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
14995                    RTE_ETHER_ADDR_LEN);
14996         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14997                    RTE_ETHER_ADDR_LEN);
14998 }
14999
15000 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
15001         .f = cmd_set_mplsoudp_encap_parsed,
15002         .data = NULL,
15003         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
15004                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
15005                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
15006         .tokens = {
15007                 (void *)&cmd_set_mplsoudp_encap_set,
15008                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
15009                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15010                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15011                 (void *)&cmd_set_mplsoudp_encap_label,
15012                 (void *)&cmd_set_mplsoudp_encap_label_value,
15013                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15014                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15015                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15016                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15017                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15018                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15019                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15020                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15021                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15022                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15023                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15024                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15025                 NULL,
15026         },
15027 };
15028
15029 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
15030         .f = cmd_set_mplsoudp_encap_parsed,
15031         .data = NULL,
15032         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
15033                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
15034                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15035                 " eth-src <eth-src> eth-dst <eth-dst>",
15036         .tokens = {
15037                 (void *)&cmd_set_mplsoudp_encap_set,
15038                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
15039                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15040                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15041                 (void *)&cmd_set_mplsoudp_encap_label,
15042                 (void *)&cmd_set_mplsoudp_encap_label_value,
15043                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15044                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15045                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15046                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15047                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15048                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15049                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15050                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15051                 (void *)&cmd_set_mplsoudp_encap_vlan,
15052                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
15053                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15054                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15055                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15056                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15057                 NULL,
15058         },
15059 };
15060
15061 /** Set MPLSoUDP decapsulation details */
15062 struct cmd_set_mplsoudp_decap_result {
15063         cmdline_fixed_string_t set;
15064         cmdline_fixed_string_t mplsoudp;
15065         cmdline_fixed_string_t pos_token;
15066         cmdline_fixed_string_t ip_version;
15067         uint32_t vlan_present:1;
15068 };
15069
15070 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
15071         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
15072                                  "set");
15073 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
15074         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
15075                                  "mplsoudp_decap");
15076 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
15077         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15078                                  mplsoudp, "mplsoudp_decap-with-vlan");
15079 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
15080         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15081                                  pos_token, "ip-version");
15082 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
15083         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15084                                  ip_version, "ipv4#ipv6");
15085
15086 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
15087         __rte_unused struct cmdline *cl,
15088         __rte_unused void *data)
15089 {
15090         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
15091
15092         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
15093                 mplsoudp_decap_conf.select_vlan = 0;
15094         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
15095                 mplsoudp_decap_conf.select_vlan = 1;
15096         if (strcmp(res->ip_version, "ipv4") == 0)
15097                 mplsoudp_decap_conf.select_ipv4 = 1;
15098         else if (strcmp(res->ip_version, "ipv6") == 0)
15099                 mplsoudp_decap_conf.select_ipv4 = 0;
15100 }
15101
15102 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
15103         .f = cmd_set_mplsoudp_decap_parsed,
15104         .data = NULL,
15105         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
15106         .tokens = {
15107                 (void *)&cmd_set_mplsoudp_decap_set,
15108                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
15109                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15110                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15111                 NULL,
15112         },
15113 };
15114
15115 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
15116         .f = cmd_set_mplsoudp_decap_parsed,
15117         .data = NULL,
15118         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
15119         .tokens = {
15120                 (void *)&cmd_set_mplsoudp_decap_set,
15121                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
15122                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15123                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15124                 NULL,
15125         },
15126 };
15127
15128 /* Strict link priority scheduling mode setting */
15129 static void
15130 cmd_strict_link_prio_parsed(
15131         void *parsed_result,
15132         __rte_unused struct cmdline *cl,
15133         __rte_unused void *data)
15134 {
15135         struct cmd_vf_tc_bw_result *res = parsed_result;
15136         int ret = -ENOTSUP;
15137
15138         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15139                 return;
15140
15141 #ifdef RTE_NET_I40E
15142         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
15143 #endif
15144
15145         switch (ret) {
15146         case 0:
15147                 break;
15148         case -EINVAL:
15149                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
15150                 break;
15151         case -ENODEV:
15152                 printf("invalid port_id %d\n", res->port_id);
15153                 break;
15154         case -ENOTSUP:
15155                 printf("function not implemented\n");
15156                 break;
15157         default:
15158                 printf("programming error: (%s)\n", strerror(-ret));
15159         }
15160 }
15161
15162 cmdline_parse_inst_t cmd_strict_link_prio = {
15163         .f = cmd_strict_link_prio_parsed,
15164         .data = NULL,
15165         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
15166         .tokens = {
15167                 (void *)&cmd_vf_tc_bw_set,
15168                 (void *)&cmd_vf_tc_bw_tx,
15169                 (void *)&cmd_vf_tc_bw_strict_link_prio,
15170                 (void *)&cmd_vf_tc_bw_port_id,
15171                 (void *)&cmd_vf_tc_bw_tc_map,
15172                 NULL,
15173         },
15174 };
15175
15176 /* Load dynamic device personalization*/
15177 struct cmd_ddp_add_result {
15178         cmdline_fixed_string_t ddp;
15179         cmdline_fixed_string_t add;
15180         portid_t port_id;
15181         char filepath[];
15182 };
15183
15184 cmdline_parse_token_string_t cmd_ddp_add_ddp =
15185         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
15186 cmdline_parse_token_string_t cmd_ddp_add_add =
15187         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
15188 cmdline_parse_token_num_t cmd_ddp_add_port_id =
15189         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
15190 cmdline_parse_token_string_t cmd_ddp_add_filepath =
15191         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
15192
15193 static void
15194 cmd_ddp_add_parsed(
15195         void *parsed_result,
15196         __rte_unused struct cmdline *cl,
15197         __rte_unused void *data)
15198 {
15199         struct cmd_ddp_add_result *res = parsed_result;
15200         uint8_t *buff;
15201         uint32_t size;
15202         char *filepath;
15203         char *file_fld[2];
15204         int file_num;
15205         int ret = -ENOTSUP;
15206
15207         if (!all_ports_stopped()) {
15208                 printf("Please stop all ports first\n");
15209                 return;
15210         }
15211
15212         filepath = strdup(res->filepath);
15213         if (filepath == NULL) {
15214                 printf("Failed to allocate memory\n");
15215                 return;
15216         }
15217         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
15218
15219         buff = open_file(file_fld[0], &size);
15220         if (!buff) {
15221                 free((void *)filepath);
15222                 return;
15223         }
15224
15225 #ifdef RTE_NET_I40E
15226         if (ret == -ENOTSUP)
15227                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15228                                                buff, size,
15229                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
15230 #endif
15231
15232         if (ret == -EEXIST)
15233                 printf("Profile has already existed.\n");
15234         else if (ret < 0)
15235                 printf("Failed to load profile.\n");
15236         else if (file_num == 2)
15237                 save_file(file_fld[1], buff, size);
15238
15239         close_file(buff);
15240         free((void *)filepath);
15241 }
15242
15243 cmdline_parse_inst_t cmd_ddp_add = {
15244         .f = cmd_ddp_add_parsed,
15245         .data = NULL,
15246         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
15247         .tokens = {
15248                 (void *)&cmd_ddp_add_ddp,
15249                 (void *)&cmd_ddp_add_add,
15250                 (void *)&cmd_ddp_add_port_id,
15251                 (void *)&cmd_ddp_add_filepath,
15252                 NULL,
15253         },
15254 };
15255
15256 /* Delete dynamic device personalization*/
15257 struct cmd_ddp_del_result {
15258         cmdline_fixed_string_t ddp;
15259         cmdline_fixed_string_t del;
15260         portid_t port_id;
15261         char filepath[];
15262 };
15263
15264 cmdline_parse_token_string_t cmd_ddp_del_ddp =
15265         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
15266 cmdline_parse_token_string_t cmd_ddp_del_del =
15267         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
15268 cmdline_parse_token_num_t cmd_ddp_del_port_id =
15269         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
15270 cmdline_parse_token_string_t cmd_ddp_del_filepath =
15271         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
15272
15273 static void
15274 cmd_ddp_del_parsed(
15275         void *parsed_result,
15276         __rte_unused struct cmdline *cl,
15277         __rte_unused void *data)
15278 {
15279         struct cmd_ddp_del_result *res = parsed_result;
15280         uint8_t *buff;
15281         uint32_t size;
15282         int ret = -ENOTSUP;
15283
15284         if (!all_ports_stopped()) {
15285                 printf("Please stop all ports first\n");
15286                 return;
15287         }
15288
15289         buff = open_file(res->filepath, &size);
15290         if (!buff)
15291                 return;
15292
15293 #ifdef RTE_NET_I40E
15294         if (ret == -ENOTSUP)
15295                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15296                                                buff, size,
15297                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15298 #endif
15299
15300         if (ret == -EACCES)
15301                 printf("Profile does not exist.\n");
15302         else if (ret < 0)
15303                 printf("Failed to delete profile.\n");
15304
15305         close_file(buff);
15306 }
15307
15308 cmdline_parse_inst_t cmd_ddp_del = {
15309         .f = cmd_ddp_del_parsed,
15310         .data = NULL,
15311         .help_str = "ddp del <port_id> <backup_profile_path>",
15312         .tokens = {
15313                 (void *)&cmd_ddp_del_ddp,
15314                 (void *)&cmd_ddp_del_del,
15315                 (void *)&cmd_ddp_del_port_id,
15316                 (void *)&cmd_ddp_del_filepath,
15317                 NULL,
15318         },
15319 };
15320
15321 /* Get dynamic device personalization profile info */
15322 struct cmd_ddp_info_result {
15323         cmdline_fixed_string_t ddp;
15324         cmdline_fixed_string_t get;
15325         cmdline_fixed_string_t info;
15326         char filepath[];
15327 };
15328
15329 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15330         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15331 cmdline_parse_token_string_t cmd_ddp_info_get =
15332         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15333 cmdline_parse_token_string_t cmd_ddp_info_info =
15334         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15335 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15336         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15337
15338 static void
15339 cmd_ddp_info_parsed(
15340         void *parsed_result,
15341         __rte_unused struct cmdline *cl,
15342         __rte_unused void *data)
15343 {
15344         struct cmd_ddp_info_result *res = parsed_result;
15345         uint8_t *pkg;
15346         uint32_t pkg_size;
15347         int ret = -ENOTSUP;
15348 #ifdef RTE_NET_I40E
15349         uint32_t i, j, n;
15350         uint8_t *buff;
15351         uint32_t buff_size = 0;
15352         struct rte_pmd_i40e_profile_info info;
15353         uint32_t dev_num = 0;
15354         struct rte_pmd_i40e_ddp_device_id *devs;
15355         uint32_t proto_num = 0;
15356         struct rte_pmd_i40e_proto_info *proto = NULL;
15357         uint32_t pctype_num = 0;
15358         struct rte_pmd_i40e_ptype_info *pctype;
15359         uint32_t ptype_num = 0;
15360         struct rte_pmd_i40e_ptype_info *ptype;
15361         uint8_t proto_id;
15362
15363 #endif
15364
15365         pkg = open_file(res->filepath, &pkg_size);
15366         if (!pkg)
15367                 return;
15368
15369 #ifdef RTE_NET_I40E
15370         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15371                                 (uint8_t *)&info, sizeof(info),
15372                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15373         if (!ret) {
15374                 printf("Global Track id:       0x%x\n", info.track_id);
15375                 printf("Global Version:        %d.%d.%d.%d\n",
15376                         info.version.major,
15377                         info.version.minor,
15378                         info.version.update,
15379                         info.version.draft);
15380                 printf("Global Package name:   %s\n\n", info.name);
15381         }
15382
15383         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15384                                 (uint8_t *)&info, sizeof(info),
15385                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15386         if (!ret) {
15387                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15388                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15389                         info.version.major,
15390                         info.version.minor,
15391                         info.version.update,
15392                         info.version.draft);
15393                 printf("i40e Profile name:     %s\n\n", info.name);
15394         }
15395
15396         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15397                                 (uint8_t *)&buff_size, sizeof(buff_size),
15398                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15399         if (!ret && buff_size) {
15400                 buff = (uint8_t *)malloc(buff_size);
15401                 if (buff) {
15402                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15403                                                 buff, buff_size,
15404                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15405                         if (!ret)
15406                                 printf("Package Notes:\n%s\n\n", buff);
15407                         free(buff);
15408                 }
15409         }
15410
15411         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15412                                 (uint8_t *)&dev_num, sizeof(dev_num),
15413                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15414         if (!ret && dev_num) {
15415                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15416                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15417                 if (devs) {
15418                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15419                                                 (uint8_t *)devs, buff_size,
15420                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15421                         if (!ret) {
15422                                 printf("List of supported devices:\n");
15423                                 for (i = 0; i < dev_num; i++) {
15424                                         printf("  %04X:%04X %04X:%04X\n",
15425                                                 devs[i].vendor_dev_id >> 16,
15426                                                 devs[i].vendor_dev_id & 0xFFFF,
15427                                                 devs[i].sub_vendor_dev_id >> 16,
15428                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15429                                 }
15430                                 printf("\n");
15431                         }
15432                         free(devs);
15433                 }
15434         }
15435
15436         /* get information about protocols and packet types */
15437         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15438                 (uint8_t *)&proto_num, sizeof(proto_num),
15439                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15440         if (ret || !proto_num)
15441                 goto no_print_return;
15442
15443         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15444         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15445         if (!proto)
15446                 goto no_print_return;
15447
15448         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15449                                         buff_size,
15450                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15451         if (!ret) {
15452                 printf("List of used protocols:\n");
15453                 for (i = 0; i < proto_num; i++)
15454                         printf("  %2u: %s\n", proto[i].proto_id,
15455                                proto[i].name);
15456                 printf("\n");
15457         }
15458         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15459                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15460                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15461         if (ret || !pctype_num)
15462                 goto no_print_pctypes;
15463
15464         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15465         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15466         if (!pctype)
15467                 goto no_print_pctypes;
15468
15469         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15470                                         buff_size,
15471                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15472         if (ret) {
15473                 free(pctype);
15474                 goto no_print_pctypes;
15475         }
15476
15477         printf("List of defined packet classification types:\n");
15478         for (i = 0; i < pctype_num; i++) {
15479                 printf("  %2u:", pctype[i].ptype_id);
15480                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15481                         proto_id = pctype[i].protocols[j];
15482                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15483                                 for (n = 0; n < proto_num; n++) {
15484                                         if (proto[n].proto_id == proto_id) {
15485                                                 printf(" %s", proto[n].name);
15486                                                 break;
15487                                         }
15488                                 }
15489                         }
15490                 }
15491                 printf("\n");
15492         }
15493         printf("\n");
15494         free(pctype);
15495
15496 no_print_pctypes:
15497
15498         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15499                                         sizeof(ptype_num),
15500                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15501         if (ret || !ptype_num)
15502                 goto no_print_return;
15503
15504         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15505         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15506         if (!ptype)
15507                 goto no_print_return;
15508
15509         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15510                                         buff_size,
15511                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15512         if (ret) {
15513                 free(ptype);
15514                 goto no_print_return;
15515         }
15516         printf("List of defined packet types:\n");
15517         for (i = 0; i < ptype_num; i++) {
15518                 printf("  %2u:", ptype[i].ptype_id);
15519                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15520                         proto_id = ptype[i].protocols[j];
15521                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15522                                 for (n = 0; n < proto_num; n++) {
15523                                         if (proto[n].proto_id == proto_id) {
15524                                                 printf(" %s", proto[n].name);
15525                                                 break;
15526                                         }
15527                                 }
15528                         }
15529                 }
15530                 printf("\n");
15531         }
15532         free(ptype);
15533         printf("\n");
15534
15535         ret = 0;
15536 no_print_return:
15537         if (proto)
15538                 free(proto);
15539 #endif
15540         if (ret == -ENOTSUP)
15541                 printf("Function not supported in PMD driver\n");
15542         close_file(pkg);
15543 }
15544
15545 cmdline_parse_inst_t cmd_ddp_get_info = {
15546         .f = cmd_ddp_info_parsed,
15547         .data = NULL,
15548         .help_str = "ddp get info <profile_path>",
15549         .tokens = {
15550                 (void *)&cmd_ddp_info_ddp,
15551                 (void *)&cmd_ddp_info_get,
15552                 (void *)&cmd_ddp_info_info,
15553                 (void *)&cmd_ddp_info_filepath,
15554                 NULL,
15555         },
15556 };
15557
15558 /* Get dynamic device personalization profile info list*/
15559 #define PROFILE_INFO_SIZE 48
15560 #define MAX_PROFILE_NUM 16
15561
15562 struct cmd_ddp_get_list_result {
15563         cmdline_fixed_string_t ddp;
15564         cmdline_fixed_string_t get;
15565         cmdline_fixed_string_t list;
15566         portid_t port_id;
15567 };
15568
15569 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15570         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15571 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15572         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15573 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15574         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15575 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15576         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15577
15578 static void
15579 cmd_ddp_get_list_parsed(
15580         __rte_unused void *parsed_result,
15581         __rte_unused struct cmdline *cl,
15582         __rte_unused void *data)
15583 {
15584 #ifdef RTE_NET_I40E
15585         struct cmd_ddp_get_list_result *res = parsed_result;
15586         struct rte_pmd_i40e_profile_list *p_list;
15587         struct rte_pmd_i40e_profile_info *p_info;
15588         uint32_t p_num;
15589         uint32_t size;
15590         uint32_t i;
15591 #endif
15592         int ret = -ENOTSUP;
15593
15594 #ifdef RTE_NET_I40E
15595         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15596         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15597         if (!p_list) {
15598                 printf("%s: Failed to malloc buffer\n", __func__);
15599                 return;
15600         }
15601
15602         if (ret == -ENOTSUP)
15603                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15604                                                 (uint8_t *)p_list, size);
15605
15606         if (!ret) {
15607                 p_num = p_list->p_count;
15608                 printf("Profile number is: %d\n\n", p_num);
15609
15610                 for (i = 0; i < p_num; i++) {
15611                         p_info = &p_list->p_info[i];
15612                         printf("Profile %d:\n", i);
15613                         printf("Track id:     0x%x\n", p_info->track_id);
15614                         printf("Version:      %d.%d.%d.%d\n",
15615                                p_info->version.major,
15616                                p_info->version.minor,
15617                                p_info->version.update,
15618                                p_info->version.draft);
15619                         printf("Profile name: %s\n\n", p_info->name);
15620                 }
15621         }
15622
15623         free(p_list);
15624 #endif
15625
15626         if (ret < 0)
15627                 printf("Failed to get ddp list\n");
15628 }
15629
15630 cmdline_parse_inst_t cmd_ddp_get_list = {
15631         .f = cmd_ddp_get_list_parsed,
15632         .data = NULL,
15633         .help_str = "ddp get list <port_id>",
15634         .tokens = {
15635                 (void *)&cmd_ddp_get_list_ddp,
15636                 (void *)&cmd_ddp_get_list_get,
15637                 (void *)&cmd_ddp_get_list_list,
15638                 (void *)&cmd_ddp_get_list_port_id,
15639                 NULL,
15640         },
15641 };
15642
15643 /* Configure input set */
15644 struct cmd_cfg_input_set_result {
15645         cmdline_fixed_string_t port;
15646         cmdline_fixed_string_t cfg;
15647         portid_t port_id;
15648         cmdline_fixed_string_t pctype;
15649         uint8_t pctype_id;
15650         cmdline_fixed_string_t inset_type;
15651         cmdline_fixed_string_t opt;
15652         cmdline_fixed_string_t field;
15653         uint8_t field_idx;
15654 };
15655
15656 static void
15657 cmd_cfg_input_set_parsed(
15658         __rte_unused void *parsed_result,
15659         __rte_unused struct cmdline *cl,
15660         __rte_unused void *data)
15661 {
15662 #ifdef RTE_NET_I40E
15663         struct cmd_cfg_input_set_result *res = parsed_result;
15664         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15665         struct rte_pmd_i40e_inset inset;
15666 #endif
15667         int ret = -ENOTSUP;
15668
15669         if (!all_ports_stopped()) {
15670                 printf("Please stop all ports first\n");
15671                 return;
15672         }
15673
15674 #ifdef RTE_NET_I40E
15675         if (!strcmp(res->inset_type, "hash_inset"))
15676                 inset_type = INSET_HASH;
15677         else if (!strcmp(res->inset_type, "fdir_inset"))
15678                 inset_type = INSET_FDIR;
15679         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15680                 inset_type = INSET_FDIR_FLX;
15681         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15682                                      &inset, inset_type);
15683         if (ret) {
15684                 printf("Failed to get input set.\n");
15685                 return;
15686         }
15687
15688         if (!strcmp(res->opt, "get")) {
15689                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15690                                                    res->field_idx);
15691                 if (ret)
15692                         printf("Field index %d is enabled.\n", res->field_idx);
15693                 else
15694                         printf("Field index %d is disabled.\n", res->field_idx);
15695                 return;
15696         } else if (!strcmp(res->opt, "set"))
15697                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15698                                                    res->field_idx);
15699         else if (!strcmp(res->opt, "clear"))
15700                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15701                                                      res->field_idx);
15702         if (ret) {
15703                 printf("Failed to configure input set field.\n");
15704                 return;
15705         }
15706
15707         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15708                                      &inset, inset_type);
15709         if (ret) {
15710                 printf("Failed to set input set.\n");
15711                 return;
15712         }
15713 #endif
15714
15715         if (ret == -ENOTSUP)
15716                 printf("Function not supported\n");
15717 }
15718
15719 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15720         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15721                                  port, "port");
15722 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15723         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15724                                  cfg, "config");
15725 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15726         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15727                               port_id, UINT16);
15728 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15729         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15730                                  pctype, "pctype");
15731 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15732         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15733                               pctype_id, UINT8);
15734 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15735         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15736                                  inset_type,
15737                                  "hash_inset#fdir_inset#fdir_flx_inset");
15738 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15739         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15740                                  opt, "get#set#clear");
15741 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15742         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15743                                  field, "field");
15744 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15745         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15746                               field_idx, UINT8);
15747
15748 cmdline_parse_inst_t cmd_cfg_input_set = {
15749         .f = cmd_cfg_input_set_parsed,
15750         .data = NULL,
15751         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15752                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15753         .tokens = {
15754                 (void *)&cmd_cfg_input_set_port,
15755                 (void *)&cmd_cfg_input_set_cfg,
15756                 (void *)&cmd_cfg_input_set_port_id,
15757                 (void *)&cmd_cfg_input_set_pctype,
15758                 (void *)&cmd_cfg_input_set_pctype_id,
15759                 (void *)&cmd_cfg_input_set_inset_type,
15760                 (void *)&cmd_cfg_input_set_opt,
15761                 (void *)&cmd_cfg_input_set_field,
15762                 (void *)&cmd_cfg_input_set_field_idx,
15763                 NULL,
15764         },
15765 };
15766
15767 /* Clear input set */
15768 struct cmd_clear_input_set_result {
15769         cmdline_fixed_string_t port;
15770         cmdline_fixed_string_t cfg;
15771         portid_t port_id;
15772         cmdline_fixed_string_t pctype;
15773         uint8_t pctype_id;
15774         cmdline_fixed_string_t inset_type;
15775         cmdline_fixed_string_t clear;
15776         cmdline_fixed_string_t all;
15777 };
15778
15779 static void
15780 cmd_clear_input_set_parsed(
15781         __rte_unused void *parsed_result,
15782         __rte_unused struct cmdline *cl,
15783         __rte_unused void *data)
15784 {
15785 #ifdef RTE_NET_I40E
15786         struct cmd_clear_input_set_result *res = parsed_result;
15787         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15788         struct rte_pmd_i40e_inset inset;
15789 #endif
15790         int ret = -ENOTSUP;
15791
15792         if (!all_ports_stopped()) {
15793                 printf("Please stop all ports first\n");
15794                 return;
15795         }
15796
15797 #ifdef RTE_NET_I40E
15798         if (!strcmp(res->inset_type, "hash_inset"))
15799                 inset_type = INSET_HASH;
15800         else if (!strcmp(res->inset_type, "fdir_inset"))
15801                 inset_type = INSET_FDIR;
15802         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15803                 inset_type = INSET_FDIR_FLX;
15804
15805         memset(&inset, 0, sizeof(inset));
15806
15807         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15808                                      &inset, inset_type);
15809         if (ret) {
15810                 printf("Failed to clear input set.\n");
15811                 return;
15812         }
15813
15814 #endif
15815
15816         if (ret == -ENOTSUP)
15817                 printf("Function not supported\n");
15818 }
15819
15820 cmdline_parse_token_string_t cmd_clear_input_set_port =
15821         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15822                                  port, "port");
15823 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15824         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15825                                  cfg, "config");
15826 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15827         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15828                               port_id, UINT16);
15829 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15830         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15831                                  pctype, "pctype");
15832 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15833         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15834                               pctype_id, UINT8);
15835 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15836         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15837                                  inset_type,
15838                                  "hash_inset#fdir_inset#fdir_flx_inset");
15839 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15840         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15841                                  clear, "clear");
15842 cmdline_parse_token_string_t cmd_clear_input_set_all =
15843         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15844                                  all, "all");
15845
15846 cmdline_parse_inst_t cmd_clear_input_set = {
15847         .f = cmd_clear_input_set_parsed,
15848         .data = NULL,
15849         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15850                     "fdir_inset|fdir_flx_inset clear all",
15851         .tokens = {
15852                 (void *)&cmd_clear_input_set_port,
15853                 (void *)&cmd_clear_input_set_cfg,
15854                 (void *)&cmd_clear_input_set_port_id,
15855                 (void *)&cmd_clear_input_set_pctype,
15856                 (void *)&cmd_clear_input_set_pctype_id,
15857                 (void *)&cmd_clear_input_set_inset_type,
15858                 (void *)&cmd_clear_input_set_clear,
15859                 (void *)&cmd_clear_input_set_all,
15860                 NULL,
15861         },
15862 };
15863
15864 /* show vf stats */
15865
15866 /* Common result structure for show vf stats */
15867 struct cmd_show_vf_stats_result {
15868         cmdline_fixed_string_t show;
15869         cmdline_fixed_string_t vf;
15870         cmdline_fixed_string_t stats;
15871         portid_t port_id;
15872         uint16_t vf_id;
15873 };
15874
15875 /* Common CLI fields show vf stats*/
15876 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15877         TOKEN_STRING_INITIALIZER
15878                 (struct cmd_show_vf_stats_result,
15879                  show, "show");
15880 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15881         TOKEN_STRING_INITIALIZER
15882                 (struct cmd_show_vf_stats_result,
15883                  vf, "vf");
15884 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15885         TOKEN_STRING_INITIALIZER
15886                 (struct cmd_show_vf_stats_result,
15887                  stats, "stats");
15888 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15889         TOKEN_NUM_INITIALIZER
15890                 (struct cmd_show_vf_stats_result,
15891                  port_id, UINT16);
15892 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15893         TOKEN_NUM_INITIALIZER
15894                 (struct cmd_show_vf_stats_result,
15895                  vf_id, UINT16);
15896
15897 static void
15898 cmd_show_vf_stats_parsed(
15899         void *parsed_result,
15900         __rte_unused struct cmdline *cl,
15901         __rte_unused void *data)
15902 {
15903         struct cmd_show_vf_stats_result *res = parsed_result;
15904         struct rte_eth_stats stats;
15905         int ret = -ENOTSUP;
15906         static const char *nic_stats_border = "########################";
15907
15908         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15909                 return;
15910
15911         memset(&stats, 0, sizeof(stats));
15912
15913 #ifdef RTE_NET_I40E
15914         if (ret == -ENOTSUP)
15915                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15916                                                 res->vf_id,
15917                                                 &stats);
15918 #endif
15919 #ifdef RTE_NET_BNXT
15920         if (ret == -ENOTSUP)
15921                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15922                                                 res->vf_id,
15923                                                 &stats);
15924 #endif
15925
15926         switch (ret) {
15927         case 0:
15928                 break;
15929         case -EINVAL:
15930                 printf("invalid vf_id %d\n", res->vf_id);
15931                 break;
15932         case -ENODEV:
15933                 printf("invalid port_id %d\n", res->port_id);
15934                 break;
15935         case -ENOTSUP:
15936                 printf("function not implemented\n");
15937                 break;
15938         default:
15939                 printf("programming error: (%s)\n", strerror(-ret));
15940         }
15941
15942         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15943                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15944
15945         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15946                "%-"PRIu64"\n",
15947                stats.ipackets, stats.imissed, stats.ibytes);
15948         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15949         printf("  RX-nombuf:  %-10"PRIu64"\n",
15950                stats.rx_nombuf);
15951         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15952                "%-"PRIu64"\n",
15953                stats.opackets, stats.oerrors, stats.obytes);
15954
15955         printf("  %s############################%s\n",
15956                                nic_stats_border, nic_stats_border);
15957 }
15958
15959 cmdline_parse_inst_t cmd_show_vf_stats = {
15960         .f = cmd_show_vf_stats_parsed,
15961         .data = NULL,
15962         .help_str = "show vf stats <port_id> <vf_id>",
15963         .tokens = {
15964                 (void *)&cmd_show_vf_stats_show,
15965                 (void *)&cmd_show_vf_stats_vf,
15966                 (void *)&cmd_show_vf_stats_stats,
15967                 (void *)&cmd_show_vf_stats_port_id,
15968                 (void *)&cmd_show_vf_stats_vf_id,
15969                 NULL,
15970         },
15971 };
15972
15973 /* clear vf stats */
15974
15975 /* Common result structure for clear vf stats */
15976 struct cmd_clear_vf_stats_result {
15977         cmdline_fixed_string_t clear;
15978         cmdline_fixed_string_t vf;
15979         cmdline_fixed_string_t stats;
15980         portid_t port_id;
15981         uint16_t vf_id;
15982 };
15983
15984 /* Common CLI fields clear vf stats*/
15985 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15986         TOKEN_STRING_INITIALIZER
15987                 (struct cmd_clear_vf_stats_result,
15988                  clear, "clear");
15989 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15990         TOKEN_STRING_INITIALIZER
15991                 (struct cmd_clear_vf_stats_result,
15992                  vf, "vf");
15993 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15994         TOKEN_STRING_INITIALIZER
15995                 (struct cmd_clear_vf_stats_result,
15996                  stats, "stats");
15997 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15998         TOKEN_NUM_INITIALIZER
15999                 (struct cmd_clear_vf_stats_result,
16000                  port_id, UINT16);
16001 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
16002         TOKEN_NUM_INITIALIZER
16003                 (struct cmd_clear_vf_stats_result,
16004                  vf_id, UINT16);
16005
16006 static void
16007 cmd_clear_vf_stats_parsed(
16008         void *parsed_result,
16009         __rte_unused struct cmdline *cl,
16010         __rte_unused void *data)
16011 {
16012         struct cmd_clear_vf_stats_result *res = parsed_result;
16013         int ret = -ENOTSUP;
16014
16015         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16016                 return;
16017
16018 #ifdef RTE_NET_I40E
16019         if (ret == -ENOTSUP)
16020                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
16021                                                   res->vf_id);
16022 #endif
16023 #ifdef RTE_NET_BNXT
16024         if (ret == -ENOTSUP)
16025                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
16026                                                   res->vf_id);
16027 #endif
16028
16029         switch (ret) {
16030         case 0:
16031                 break;
16032         case -EINVAL:
16033                 printf("invalid vf_id %d\n", res->vf_id);
16034                 break;
16035         case -ENODEV:
16036                 printf("invalid port_id %d\n", res->port_id);
16037                 break;
16038         case -ENOTSUP:
16039                 printf("function not implemented\n");
16040                 break;
16041         default:
16042                 printf("programming error: (%s)\n", strerror(-ret));
16043         }
16044 }
16045
16046 cmdline_parse_inst_t cmd_clear_vf_stats = {
16047         .f = cmd_clear_vf_stats_parsed,
16048         .data = NULL,
16049         .help_str = "clear vf stats <port_id> <vf_id>",
16050         .tokens = {
16051                 (void *)&cmd_clear_vf_stats_clear,
16052                 (void *)&cmd_clear_vf_stats_vf,
16053                 (void *)&cmd_clear_vf_stats_stats,
16054                 (void *)&cmd_clear_vf_stats_port_id,
16055                 (void *)&cmd_clear_vf_stats_vf_id,
16056                 NULL,
16057         },
16058 };
16059
16060 /* port config pctype mapping reset */
16061
16062 /* Common result structure for port config pctype mapping reset */
16063 struct cmd_pctype_mapping_reset_result {
16064         cmdline_fixed_string_t port;
16065         cmdline_fixed_string_t config;
16066         portid_t port_id;
16067         cmdline_fixed_string_t pctype;
16068         cmdline_fixed_string_t mapping;
16069         cmdline_fixed_string_t reset;
16070 };
16071
16072 /* Common CLI fields for port config pctype mapping reset*/
16073 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
16074         TOKEN_STRING_INITIALIZER
16075                 (struct cmd_pctype_mapping_reset_result,
16076                  port, "port");
16077 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
16078         TOKEN_STRING_INITIALIZER
16079                 (struct cmd_pctype_mapping_reset_result,
16080                  config, "config");
16081 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
16082         TOKEN_NUM_INITIALIZER
16083                 (struct cmd_pctype_mapping_reset_result,
16084                  port_id, UINT16);
16085 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
16086         TOKEN_STRING_INITIALIZER
16087                 (struct cmd_pctype_mapping_reset_result,
16088                  pctype, "pctype");
16089 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
16090         TOKEN_STRING_INITIALIZER
16091                 (struct cmd_pctype_mapping_reset_result,
16092                  mapping, "mapping");
16093 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
16094         TOKEN_STRING_INITIALIZER
16095                 (struct cmd_pctype_mapping_reset_result,
16096                  reset, "reset");
16097
16098 static void
16099 cmd_pctype_mapping_reset_parsed(
16100         void *parsed_result,
16101         __rte_unused struct cmdline *cl,
16102         __rte_unused void *data)
16103 {
16104         struct cmd_pctype_mapping_reset_result *res = parsed_result;
16105         int ret = -ENOTSUP;
16106
16107         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16108                 return;
16109
16110 #ifdef RTE_NET_I40E
16111         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
16112 #endif
16113
16114         switch (ret) {
16115         case 0:
16116                 break;
16117         case -ENODEV:
16118                 printf("invalid port_id %d\n", res->port_id);
16119                 break;
16120         case -ENOTSUP:
16121                 printf("function not implemented\n");
16122                 break;
16123         default:
16124                 printf("programming error: (%s)\n", strerror(-ret));
16125         }
16126 }
16127
16128 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
16129         .f = cmd_pctype_mapping_reset_parsed,
16130         .data = NULL,
16131         .help_str = "port config <port_id> pctype mapping reset",
16132         .tokens = {
16133                 (void *)&cmd_pctype_mapping_reset_port,
16134                 (void *)&cmd_pctype_mapping_reset_config,
16135                 (void *)&cmd_pctype_mapping_reset_port_id,
16136                 (void *)&cmd_pctype_mapping_reset_pctype,
16137                 (void *)&cmd_pctype_mapping_reset_mapping,
16138                 (void *)&cmd_pctype_mapping_reset_reset,
16139                 NULL,
16140         },
16141 };
16142
16143 /* show port pctype mapping */
16144
16145 /* Common result structure for show port pctype mapping */
16146 struct cmd_pctype_mapping_get_result {
16147         cmdline_fixed_string_t show;
16148         cmdline_fixed_string_t port;
16149         portid_t port_id;
16150         cmdline_fixed_string_t pctype;
16151         cmdline_fixed_string_t mapping;
16152 };
16153
16154 /* Common CLI fields for pctype mapping get */
16155 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
16156         TOKEN_STRING_INITIALIZER
16157                 (struct cmd_pctype_mapping_get_result,
16158                  show, "show");
16159 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
16160         TOKEN_STRING_INITIALIZER
16161                 (struct cmd_pctype_mapping_get_result,
16162                  port, "port");
16163 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
16164         TOKEN_NUM_INITIALIZER
16165                 (struct cmd_pctype_mapping_get_result,
16166                  port_id, UINT16);
16167 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
16168         TOKEN_STRING_INITIALIZER
16169                 (struct cmd_pctype_mapping_get_result,
16170                  pctype, "pctype");
16171 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
16172         TOKEN_STRING_INITIALIZER
16173                 (struct cmd_pctype_mapping_get_result,
16174                  mapping, "mapping");
16175
16176 static void
16177 cmd_pctype_mapping_get_parsed(
16178         void *parsed_result,
16179         __rte_unused struct cmdline *cl,
16180         __rte_unused void *data)
16181 {
16182         struct cmd_pctype_mapping_get_result *res = parsed_result;
16183         int ret = -ENOTSUP;
16184 #ifdef RTE_NET_I40E
16185         struct rte_pmd_i40e_flow_type_mapping
16186                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
16187         int i, j, first_pctype;
16188 #endif
16189
16190         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16191                 return;
16192
16193 #ifdef RTE_NET_I40E
16194         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
16195 #endif
16196
16197         switch (ret) {
16198         case 0:
16199                 break;
16200         case -ENODEV:
16201                 printf("invalid port_id %d\n", res->port_id);
16202                 return;
16203         case -ENOTSUP:
16204                 printf("function not implemented\n");
16205                 return;
16206         default:
16207                 printf("programming error: (%s)\n", strerror(-ret));
16208                 return;
16209         }
16210
16211 #ifdef RTE_NET_I40E
16212         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
16213                 if (mapping[i].pctype != 0ULL) {
16214                         first_pctype = 1;
16215
16216                         printf("pctype: ");
16217                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
16218                                 if (mapping[i].pctype & (1ULL << j)) {
16219                                         printf(first_pctype ?
16220                                                "%02d" : ",%02d", j);
16221                                         first_pctype = 0;
16222                                 }
16223                         }
16224                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
16225                 }
16226         }
16227 #endif
16228 }
16229
16230 cmdline_parse_inst_t cmd_pctype_mapping_get = {
16231         .f = cmd_pctype_mapping_get_parsed,
16232         .data = NULL,
16233         .help_str = "show port <port_id> pctype mapping",
16234         .tokens = {
16235                 (void *)&cmd_pctype_mapping_get_show,
16236                 (void *)&cmd_pctype_mapping_get_port,
16237                 (void *)&cmd_pctype_mapping_get_port_id,
16238                 (void *)&cmd_pctype_mapping_get_pctype,
16239                 (void *)&cmd_pctype_mapping_get_mapping,
16240                 NULL,
16241         },
16242 };
16243
16244 /* port config pctype mapping update */
16245
16246 /* Common result structure for port config pctype mapping update */
16247 struct cmd_pctype_mapping_update_result {
16248         cmdline_fixed_string_t port;
16249         cmdline_fixed_string_t config;
16250         portid_t port_id;
16251         cmdline_fixed_string_t pctype;
16252         cmdline_fixed_string_t mapping;
16253         cmdline_fixed_string_t update;
16254         cmdline_fixed_string_t pctype_list;
16255         uint16_t flow_type;
16256 };
16257
16258 /* Common CLI fields for pctype mapping update*/
16259 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
16260         TOKEN_STRING_INITIALIZER
16261                 (struct cmd_pctype_mapping_update_result,
16262                  port, "port");
16263 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
16264         TOKEN_STRING_INITIALIZER
16265                 (struct cmd_pctype_mapping_update_result,
16266                  config, "config");
16267 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
16268         TOKEN_NUM_INITIALIZER
16269                 (struct cmd_pctype_mapping_update_result,
16270                  port_id, UINT16);
16271 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
16272         TOKEN_STRING_INITIALIZER
16273                 (struct cmd_pctype_mapping_update_result,
16274                  pctype, "pctype");
16275 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
16276         TOKEN_STRING_INITIALIZER
16277                 (struct cmd_pctype_mapping_update_result,
16278                  mapping, "mapping");
16279 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
16280         TOKEN_STRING_INITIALIZER
16281                 (struct cmd_pctype_mapping_update_result,
16282                  update, "update");
16283 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
16284         TOKEN_STRING_INITIALIZER
16285                 (struct cmd_pctype_mapping_update_result,
16286                  pctype_list, NULL);
16287 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
16288         TOKEN_NUM_INITIALIZER
16289                 (struct cmd_pctype_mapping_update_result,
16290                  flow_type, UINT16);
16291
16292 static void
16293 cmd_pctype_mapping_update_parsed(
16294         void *parsed_result,
16295         __rte_unused struct cmdline *cl,
16296         __rte_unused void *data)
16297 {
16298         struct cmd_pctype_mapping_update_result *res = parsed_result;
16299         int ret = -ENOTSUP;
16300 #ifdef RTE_NET_I40E
16301         struct rte_pmd_i40e_flow_type_mapping mapping;
16302         unsigned int i;
16303         unsigned int nb_item;
16304         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16305 #endif
16306
16307         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16308                 return;
16309
16310 #ifdef RTE_NET_I40E
16311         nb_item = parse_item_list(res->pctype_list, "pctypes",
16312                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16313         mapping.flow_type = res->flow_type;
16314         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16315                 mapping.pctype |= (1ULL << pctype_list[i]);
16316         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16317                                                 &mapping,
16318                                                 1,
16319                                                 0);
16320 #endif
16321
16322         switch (ret) {
16323         case 0:
16324                 break;
16325         case -EINVAL:
16326                 printf("invalid pctype or flow type\n");
16327                 break;
16328         case -ENODEV:
16329                 printf("invalid port_id %d\n", res->port_id);
16330                 break;
16331         case -ENOTSUP:
16332                 printf("function not implemented\n");
16333                 break;
16334         default:
16335                 printf("programming error: (%s)\n", strerror(-ret));
16336         }
16337 }
16338
16339 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16340         .f = cmd_pctype_mapping_update_parsed,
16341         .data = NULL,
16342         .help_str = "port config <port_id> pctype mapping update"
16343         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16344         .tokens = {
16345                 (void *)&cmd_pctype_mapping_update_port,
16346                 (void *)&cmd_pctype_mapping_update_config,
16347                 (void *)&cmd_pctype_mapping_update_port_id,
16348                 (void *)&cmd_pctype_mapping_update_pctype,
16349                 (void *)&cmd_pctype_mapping_update_mapping,
16350                 (void *)&cmd_pctype_mapping_update_update,
16351                 (void *)&cmd_pctype_mapping_update_pc_type,
16352                 (void *)&cmd_pctype_mapping_update_flow_type,
16353                 NULL,
16354         },
16355 };
16356
16357 /* ptype mapping get */
16358
16359 /* Common result structure for ptype mapping get */
16360 struct cmd_ptype_mapping_get_result {
16361         cmdline_fixed_string_t ptype;
16362         cmdline_fixed_string_t mapping;
16363         cmdline_fixed_string_t get;
16364         portid_t port_id;
16365         uint8_t valid_only;
16366 };
16367
16368 /* Common CLI fields for ptype mapping get */
16369 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16370         TOKEN_STRING_INITIALIZER
16371                 (struct cmd_ptype_mapping_get_result,
16372                  ptype, "ptype");
16373 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16374         TOKEN_STRING_INITIALIZER
16375                 (struct cmd_ptype_mapping_get_result,
16376                  mapping, "mapping");
16377 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16378         TOKEN_STRING_INITIALIZER
16379                 (struct cmd_ptype_mapping_get_result,
16380                  get, "get");
16381 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16382         TOKEN_NUM_INITIALIZER
16383                 (struct cmd_ptype_mapping_get_result,
16384                  port_id, UINT16);
16385 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16386         TOKEN_NUM_INITIALIZER
16387                 (struct cmd_ptype_mapping_get_result,
16388                  valid_only, UINT8);
16389
16390 static void
16391 cmd_ptype_mapping_get_parsed(
16392         void *parsed_result,
16393         __rte_unused struct cmdline *cl,
16394         __rte_unused void *data)
16395 {
16396         struct cmd_ptype_mapping_get_result *res = parsed_result;
16397         int ret = -ENOTSUP;
16398 #ifdef RTE_NET_I40E
16399         int max_ptype_num = 256;
16400         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16401         uint16_t count;
16402         int i;
16403 #endif
16404
16405         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16406                 return;
16407
16408 #ifdef RTE_NET_I40E
16409         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16410                                         mapping,
16411                                         max_ptype_num,
16412                                         &count,
16413                                         res->valid_only);
16414 #endif
16415
16416         switch (ret) {
16417         case 0:
16418                 break;
16419         case -ENODEV:
16420                 printf("invalid port_id %d\n", res->port_id);
16421                 break;
16422         case -ENOTSUP:
16423                 printf("function not implemented\n");
16424                 break;
16425         default:
16426                 printf("programming error: (%s)\n", strerror(-ret));
16427         }
16428
16429 #ifdef RTE_NET_I40E
16430         if (!ret) {
16431                 for (i = 0; i < count; i++)
16432                         printf("%3d\t0x%08x\n",
16433                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16434         }
16435 #endif
16436 }
16437
16438 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16439         .f = cmd_ptype_mapping_get_parsed,
16440         .data = NULL,
16441         .help_str = "ptype mapping get <port_id> <valid_only>",
16442         .tokens = {
16443                 (void *)&cmd_ptype_mapping_get_ptype,
16444                 (void *)&cmd_ptype_mapping_get_mapping,
16445                 (void *)&cmd_ptype_mapping_get_get,
16446                 (void *)&cmd_ptype_mapping_get_port_id,
16447                 (void *)&cmd_ptype_mapping_get_valid_only,
16448                 NULL,
16449         },
16450 };
16451
16452 /* ptype mapping replace */
16453
16454 /* Common result structure for ptype mapping replace */
16455 struct cmd_ptype_mapping_replace_result {
16456         cmdline_fixed_string_t ptype;
16457         cmdline_fixed_string_t mapping;
16458         cmdline_fixed_string_t replace;
16459         portid_t port_id;
16460         uint32_t target;
16461         uint8_t mask;
16462         uint32_t pkt_type;
16463 };
16464
16465 /* Common CLI fields for ptype mapping replace */
16466 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16467         TOKEN_STRING_INITIALIZER
16468                 (struct cmd_ptype_mapping_replace_result,
16469                  ptype, "ptype");
16470 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16471         TOKEN_STRING_INITIALIZER
16472                 (struct cmd_ptype_mapping_replace_result,
16473                  mapping, "mapping");
16474 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16475         TOKEN_STRING_INITIALIZER
16476                 (struct cmd_ptype_mapping_replace_result,
16477                  replace, "replace");
16478 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16479         TOKEN_NUM_INITIALIZER
16480                 (struct cmd_ptype_mapping_replace_result,
16481                  port_id, UINT16);
16482 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16483         TOKEN_NUM_INITIALIZER
16484                 (struct cmd_ptype_mapping_replace_result,
16485                  target, UINT32);
16486 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16487         TOKEN_NUM_INITIALIZER
16488                 (struct cmd_ptype_mapping_replace_result,
16489                  mask, UINT8);
16490 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16491         TOKEN_NUM_INITIALIZER
16492                 (struct cmd_ptype_mapping_replace_result,
16493                  pkt_type, UINT32);
16494
16495 static void
16496 cmd_ptype_mapping_replace_parsed(
16497         void *parsed_result,
16498         __rte_unused struct cmdline *cl,
16499         __rte_unused void *data)
16500 {
16501         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16502         int ret = -ENOTSUP;
16503
16504         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16505                 return;
16506
16507 #ifdef RTE_NET_I40E
16508         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16509                                         res->target,
16510                                         res->mask,
16511                                         res->pkt_type);
16512 #endif
16513
16514         switch (ret) {
16515         case 0:
16516                 break;
16517         case -EINVAL:
16518                 printf("invalid ptype 0x%8x or 0x%8x\n",
16519                                 res->target, res->pkt_type);
16520                 break;
16521         case -ENODEV:
16522                 printf("invalid port_id %d\n", res->port_id);
16523                 break;
16524         case -ENOTSUP:
16525                 printf("function not implemented\n");
16526                 break;
16527         default:
16528                 printf("programming error: (%s)\n", strerror(-ret));
16529         }
16530 }
16531
16532 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16533         .f = cmd_ptype_mapping_replace_parsed,
16534         .data = NULL,
16535         .help_str =
16536                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16537         .tokens = {
16538                 (void *)&cmd_ptype_mapping_replace_ptype,
16539                 (void *)&cmd_ptype_mapping_replace_mapping,
16540                 (void *)&cmd_ptype_mapping_replace_replace,
16541                 (void *)&cmd_ptype_mapping_replace_port_id,
16542                 (void *)&cmd_ptype_mapping_replace_target,
16543                 (void *)&cmd_ptype_mapping_replace_mask,
16544                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16545                 NULL,
16546         },
16547 };
16548
16549 /* ptype mapping reset */
16550
16551 /* Common result structure for ptype mapping reset */
16552 struct cmd_ptype_mapping_reset_result {
16553         cmdline_fixed_string_t ptype;
16554         cmdline_fixed_string_t mapping;
16555         cmdline_fixed_string_t reset;
16556         portid_t port_id;
16557 };
16558
16559 /* Common CLI fields for ptype mapping reset*/
16560 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16561         TOKEN_STRING_INITIALIZER
16562                 (struct cmd_ptype_mapping_reset_result,
16563                  ptype, "ptype");
16564 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16565         TOKEN_STRING_INITIALIZER
16566                 (struct cmd_ptype_mapping_reset_result,
16567                  mapping, "mapping");
16568 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16569         TOKEN_STRING_INITIALIZER
16570                 (struct cmd_ptype_mapping_reset_result,
16571                  reset, "reset");
16572 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16573         TOKEN_NUM_INITIALIZER
16574                 (struct cmd_ptype_mapping_reset_result,
16575                  port_id, UINT16);
16576
16577 static void
16578 cmd_ptype_mapping_reset_parsed(
16579         void *parsed_result,
16580         __rte_unused struct cmdline *cl,
16581         __rte_unused void *data)
16582 {
16583         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16584         int ret = -ENOTSUP;
16585
16586         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16587                 return;
16588
16589 #ifdef RTE_NET_I40E
16590         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16591 #endif
16592
16593         switch (ret) {
16594         case 0:
16595                 break;
16596         case -ENODEV:
16597                 printf("invalid port_id %d\n", res->port_id);
16598                 break;
16599         case -ENOTSUP:
16600                 printf("function not implemented\n");
16601                 break;
16602         default:
16603                 printf("programming error: (%s)\n", strerror(-ret));
16604         }
16605 }
16606
16607 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16608         .f = cmd_ptype_mapping_reset_parsed,
16609         .data = NULL,
16610         .help_str = "ptype mapping reset <port_id>",
16611         .tokens = {
16612                 (void *)&cmd_ptype_mapping_reset_ptype,
16613                 (void *)&cmd_ptype_mapping_reset_mapping,
16614                 (void *)&cmd_ptype_mapping_reset_reset,
16615                 (void *)&cmd_ptype_mapping_reset_port_id,
16616                 NULL,
16617         },
16618 };
16619
16620 /* ptype mapping update */
16621
16622 /* Common result structure for ptype mapping update */
16623 struct cmd_ptype_mapping_update_result {
16624         cmdline_fixed_string_t ptype;
16625         cmdline_fixed_string_t mapping;
16626         cmdline_fixed_string_t reset;
16627         portid_t port_id;
16628         uint8_t hw_ptype;
16629         uint32_t sw_ptype;
16630 };
16631
16632 /* Common CLI fields for ptype mapping update*/
16633 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16634         TOKEN_STRING_INITIALIZER
16635                 (struct cmd_ptype_mapping_update_result,
16636                  ptype, "ptype");
16637 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16638         TOKEN_STRING_INITIALIZER
16639                 (struct cmd_ptype_mapping_update_result,
16640                  mapping, "mapping");
16641 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16642         TOKEN_STRING_INITIALIZER
16643                 (struct cmd_ptype_mapping_update_result,
16644                  reset, "update");
16645 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16646         TOKEN_NUM_INITIALIZER
16647                 (struct cmd_ptype_mapping_update_result,
16648                  port_id, UINT16);
16649 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16650         TOKEN_NUM_INITIALIZER
16651                 (struct cmd_ptype_mapping_update_result,
16652                  hw_ptype, UINT8);
16653 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16654         TOKEN_NUM_INITIALIZER
16655                 (struct cmd_ptype_mapping_update_result,
16656                  sw_ptype, UINT32);
16657
16658 static void
16659 cmd_ptype_mapping_update_parsed(
16660         void *parsed_result,
16661         __rte_unused struct cmdline *cl,
16662         __rte_unused void *data)
16663 {
16664         struct cmd_ptype_mapping_update_result *res = parsed_result;
16665         int ret = -ENOTSUP;
16666 #ifdef RTE_NET_I40E
16667         struct rte_pmd_i40e_ptype_mapping mapping;
16668 #endif
16669         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16670                 return;
16671
16672 #ifdef RTE_NET_I40E
16673         mapping.hw_ptype = res->hw_ptype;
16674         mapping.sw_ptype = res->sw_ptype;
16675         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16676                                                 &mapping,
16677                                                 1,
16678                                                 0);
16679 #endif
16680
16681         switch (ret) {
16682         case 0:
16683                 break;
16684         case -EINVAL:
16685                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16686                 break;
16687         case -ENODEV:
16688                 printf("invalid port_id %d\n", res->port_id);
16689                 break;
16690         case -ENOTSUP:
16691                 printf("function not implemented\n");
16692                 break;
16693         default:
16694                 printf("programming error: (%s)\n", strerror(-ret));
16695         }
16696 }
16697
16698 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16699         .f = cmd_ptype_mapping_update_parsed,
16700         .data = NULL,
16701         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16702         .tokens = {
16703                 (void *)&cmd_ptype_mapping_update_ptype,
16704                 (void *)&cmd_ptype_mapping_update_mapping,
16705                 (void *)&cmd_ptype_mapping_update_update,
16706                 (void *)&cmd_ptype_mapping_update_port_id,
16707                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16708                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16709                 NULL,
16710         },
16711 };
16712
16713 /* Common result structure for file commands */
16714 struct cmd_cmdfile_result {
16715         cmdline_fixed_string_t load;
16716         cmdline_fixed_string_t filename;
16717 };
16718
16719 /* Common CLI fields for file commands */
16720 cmdline_parse_token_string_t cmd_load_cmdfile =
16721         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16722 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16723         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16724
16725 static void
16726 cmd_load_from_file_parsed(
16727         void *parsed_result,
16728         __rte_unused struct cmdline *cl,
16729         __rte_unused void *data)
16730 {
16731         struct cmd_cmdfile_result *res = parsed_result;
16732
16733         cmdline_read_from_file(res->filename);
16734 }
16735
16736 cmdline_parse_inst_t cmd_load_from_file = {
16737         .f = cmd_load_from_file_parsed,
16738         .data = NULL,
16739         .help_str = "load <filename>",
16740         .tokens = {
16741                 (void *)&cmd_load_cmdfile,
16742                 (void *)&cmd_load_cmdfile_filename,
16743                 NULL,
16744         },
16745 };
16746
16747 /* Get Rx offloads capabilities */
16748 struct cmd_rx_offload_get_capa_result {
16749         cmdline_fixed_string_t show;
16750         cmdline_fixed_string_t port;
16751         portid_t port_id;
16752         cmdline_fixed_string_t rx_offload;
16753         cmdline_fixed_string_t capabilities;
16754 };
16755
16756 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16757         TOKEN_STRING_INITIALIZER
16758                 (struct cmd_rx_offload_get_capa_result,
16759                  show, "show");
16760 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16761         TOKEN_STRING_INITIALIZER
16762                 (struct cmd_rx_offload_get_capa_result,
16763                  port, "port");
16764 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16765         TOKEN_NUM_INITIALIZER
16766                 (struct cmd_rx_offload_get_capa_result,
16767                  port_id, UINT16);
16768 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16769         TOKEN_STRING_INITIALIZER
16770                 (struct cmd_rx_offload_get_capa_result,
16771                  rx_offload, "rx_offload");
16772 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16773         TOKEN_STRING_INITIALIZER
16774                 (struct cmd_rx_offload_get_capa_result,
16775                  capabilities, "capabilities");
16776
16777 static void
16778 print_rx_offloads(uint64_t offloads)
16779 {
16780         uint64_t single_offload;
16781         int begin;
16782         int end;
16783         int bit;
16784
16785         if (offloads == 0)
16786                 return;
16787
16788         begin = __builtin_ctzll(offloads);
16789         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16790
16791         single_offload = 1ULL << begin;
16792         for (bit = begin; bit < end; bit++) {
16793                 if (offloads & single_offload)
16794                         printf(" %s",
16795                                rte_eth_dev_rx_offload_name(single_offload));
16796                 single_offload <<= 1;
16797         }
16798 }
16799
16800 static void
16801 cmd_rx_offload_get_capa_parsed(
16802         void *parsed_result,
16803         __rte_unused struct cmdline *cl,
16804         __rte_unused void *data)
16805 {
16806         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16807         struct rte_eth_dev_info dev_info;
16808         portid_t port_id = res->port_id;
16809         uint64_t queue_offloads;
16810         uint64_t port_offloads;
16811         int ret;
16812
16813         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16814         if (ret != 0)
16815                 return;
16816
16817         queue_offloads = dev_info.rx_queue_offload_capa;
16818         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16819
16820         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16821         printf("  Per Queue :");
16822         print_rx_offloads(queue_offloads);
16823
16824         printf("\n");
16825         printf("  Per Port  :");
16826         print_rx_offloads(port_offloads);
16827         printf("\n\n");
16828 }
16829
16830 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16831         .f = cmd_rx_offload_get_capa_parsed,
16832         .data = NULL,
16833         .help_str = "show port <port_id> rx_offload capabilities",
16834         .tokens = {
16835                 (void *)&cmd_rx_offload_get_capa_show,
16836                 (void *)&cmd_rx_offload_get_capa_port,
16837                 (void *)&cmd_rx_offload_get_capa_port_id,
16838                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16839                 (void *)&cmd_rx_offload_get_capa_capabilities,
16840                 NULL,
16841         }
16842 };
16843
16844 /* Get Rx offloads configuration */
16845 struct cmd_rx_offload_get_configuration_result {
16846         cmdline_fixed_string_t show;
16847         cmdline_fixed_string_t port;
16848         portid_t port_id;
16849         cmdline_fixed_string_t rx_offload;
16850         cmdline_fixed_string_t configuration;
16851 };
16852
16853 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16854         TOKEN_STRING_INITIALIZER
16855                 (struct cmd_rx_offload_get_configuration_result,
16856                  show, "show");
16857 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16858         TOKEN_STRING_INITIALIZER
16859                 (struct cmd_rx_offload_get_configuration_result,
16860                  port, "port");
16861 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16862         TOKEN_NUM_INITIALIZER
16863                 (struct cmd_rx_offload_get_configuration_result,
16864                  port_id, UINT16);
16865 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16866         TOKEN_STRING_INITIALIZER
16867                 (struct cmd_rx_offload_get_configuration_result,
16868                  rx_offload, "rx_offload");
16869 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16870         TOKEN_STRING_INITIALIZER
16871                 (struct cmd_rx_offload_get_configuration_result,
16872                  configuration, "configuration");
16873
16874 static void
16875 cmd_rx_offload_get_configuration_parsed(
16876         void *parsed_result,
16877         __rte_unused struct cmdline *cl,
16878         __rte_unused void *data)
16879 {
16880         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16881         struct rte_eth_dev_info dev_info;
16882         portid_t port_id = res->port_id;
16883         struct rte_port *port = &ports[port_id];
16884         uint64_t port_offloads;
16885         uint64_t queue_offloads;
16886         uint16_t nb_rx_queues;
16887         int q;
16888         int ret;
16889
16890         printf("Rx Offloading Configuration of port %d :\n", port_id);
16891
16892         port_offloads = port->dev_conf.rxmode.offloads;
16893         printf("  Port :");
16894         print_rx_offloads(port_offloads);
16895         printf("\n");
16896
16897         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16898         if (ret != 0)
16899                 return;
16900
16901         nb_rx_queues = dev_info.nb_rx_queues;
16902         for (q = 0; q < nb_rx_queues; q++) {
16903                 queue_offloads = port->rx_conf[q].offloads;
16904                 printf("  Queue[%2d] :", q);
16905                 print_rx_offloads(queue_offloads);
16906                 printf("\n");
16907         }
16908         printf("\n");
16909 }
16910
16911 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16912         .f = cmd_rx_offload_get_configuration_parsed,
16913         .data = NULL,
16914         .help_str = "show port <port_id> rx_offload configuration",
16915         .tokens = {
16916                 (void *)&cmd_rx_offload_get_configuration_show,
16917                 (void *)&cmd_rx_offload_get_configuration_port,
16918                 (void *)&cmd_rx_offload_get_configuration_port_id,
16919                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16920                 (void *)&cmd_rx_offload_get_configuration_configuration,
16921                 NULL,
16922         }
16923 };
16924
16925 /* Enable/Disable a per port offloading */
16926 struct cmd_config_per_port_rx_offload_result {
16927         cmdline_fixed_string_t port;
16928         cmdline_fixed_string_t config;
16929         portid_t port_id;
16930         cmdline_fixed_string_t rx_offload;
16931         cmdline_fixed_string_t offload;
16932         cmdline_fixed_string_t on_off;
16933 };
16934
16935 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16936         TOKEN_STRING_INITIALIZER
16937                 (struct cmd_config_per_port_rx_offload_result,
16938                  port, "port");
16939 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16940         TOKEN_STRING_INITIALIZER
16941                 (struct cmd_config_per_port_rx_offload_result,
16942                  config, "config");
16943 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16944         TOKEN_NUM_INITIALIZER
16945                 (struct cmd_config_per_port_rx_offload_result,
16946                  port_id, UINT16);
16947 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16948         TOKEN_STRING_INITIALIZER
16949                 (struct cmd_config_per_port_rx_offload_result,
16950                  rx_offload, "rx_offload");
16951 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16952         TOKEN_STRING_INITIALIZER
16953                 (struct cmd_config_per_port_rx_offload_result,
16954                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16955                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16956                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16957                            "scatter#buffer_split#timestamp#security#"
16958                            "keep_crc#rss_hash");
16959 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16960         TOKEN_STRING_INITIALIZER
16961                 (struct cmd_config_per_port_rx_offload_result,
16962                  on_off, "on#off");
16963
16964 static uint64_t
16965 search_rx_offload(const char *name)
16966 {
16967         uint64_t single_offload;
16968         const char *single_name;
16969         int found = 0;
16970         unsigned int bit;
16971
16972         single_offload = 1;
16973         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16974                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16975                 if (!strcasecmp(single_name, name)) {
16976                         found = 1;
16977                         break;
16978                 }
16979                 single_offload <<= 1;
16980         }
16981
16982         if (found)
16983                 return single_offload;
16984
16985         return 0;
16986 }
16987
16988 static void
16989 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16990                                 __rte_unused struct cmdline *cl,
16991                                 __rte_unused void *data)
16992 {
16993         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16994         portid_t port_id = res->port_id;
16995         struct rte_eth_dev_info dev_info;
16996         struct rte_port *port = &ports[port_id];
16997         uint64_t single_offload;
16998         uint16_t nb_rx_queues;
16999         int q;
17000         int ret;
17001
17002         if (port->port_status != RTE_PORT_STOPPED) {
17003                 printf("Error: Can't config offload when Port %d "
17004                        "is not stopped\n", port_id);
17005                 return;
17006         }
17007
17008         single_offload = search_rx_offload(res->offload);
17009         if (single_offload == 0) {
17010                 printf("Unknown offload name: %s\n", res->offload);
17011                 return;
17012         }
17013
17014         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17015         if (ret != 0)
17016                 return;
17017
17018         nb_rx_queues = dev_info.nb_rx_queues;
17019         if (!strcmp(res->on_off, "on")) {
17020                 port->dev_conf.rxmode.offloads |= single_offload;
17021                 for (q = 0; q < nb_rx_queues; q++)
17022                         port->rx_conf[q].offloads |= single_offload;
17023         } else {
17024                 port->dev_conf.rxmode.offloads &= ~single_offload;
17025                 for (q = 0; q < nb_rx_queues; q++)
17026                         port->rx_conf[q].offloads &= ~single_offload;
17027         }
17028
17029         cmd_reconfig_device_queue(port_id, 1, 1);
17030 }
17031
17032 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
17033         .f = cmd_config_per_port_rx_offload_parsed,
17034         .data = NULL,
17035         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
17036                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17037                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17038                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
17039                     "keep_crc|rss_hash on|off",
17040         .tokens = {
17041                 (void *)&cmd_config_per_port_rx_offload_result_port,
17042                 (void *)&cmd_config_per_port_rx_offload_result_config,
17043                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
17044                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
17045                 (void *)&cmd_config_per_port_rx_offload_result_offload,
17046                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
17047                 NULL,
17048         }
17049 };
17050
17051 /* Enable/Disable a per queue offloading */
17052 struct cmd_config_per_queue_rx_offload_result {
17053         cmdline_fixed_string_t port;
17054         portid_t port_id;
17055         cmdline_fixed_string_t rxq;
17056         uint16_t queue_id;
17057         cmdline_fixed_string_t rx_offload;
17058         cmdline_fixed_string_t offload;
17059         cmdline_fixed_string_t on_off;
17060 };
17061
17062 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
17063         TOKEN_STRING_INITIALIZER
17064                 (struct cmd_config_per_queue_rx_offload_result,
17065                  port, "port");
17066 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
17067         TOKEN_NUM_INITIALIZER
17068                 (struct cmd_config_per_queue_rx_offload_result,
17069                  port_id, UINT16);
17070 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
17071         TOKEN_STRING_INITIALIZER
17072                 (struct cmd_config_per_queue_rx_offload_result,
17073                  rxq, "rxq");
17074 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
17075         TOKEN_NUM_INITIALIZER
17076                 (struct cmd_config_per_queue_rx_offload_result,
17077                  queue_id, UINT16);
17078 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
17079         TOKEN_STRING_INITIALIZER
17080                 (struct cmd_config_per_queue_rx_offload_result,
17081                  rx_offload, "rx_offload");
17082 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
17083         TOKEN_STRING_INITIALIZER
17084                 (struct cmd_config_per_queue_rx_offload_result,
17085                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17086                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17087                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17088                            "scatter#buffer_split#timestamp#security#keep_crc");
17089 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
17090         TOKEN_STRING_INITIALIZER
17091                 (struct cmd_config_per_queue_rx_offload_result,
17092                  on_off, "on#off");
17093
17094 static void
17095 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
17096                                 __rte_unused struct cmdline *cl,
17097                                 __rte_unused void *data)
17098 {
17099         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
17100         struct rte_eth_dev_info dev_info;
17101         portid_t port_id = res->port_id;
17102         uint16_t queue_id = res->queue_id;
17103         struct rte_port *port = &ports[port_id];
17104         uint64_t single_offload;
17105         int ret;
17106
17107         if (port->port_status != RTE_PORT_STOPPED) {
17108                 printf("Error: Can't config offload when Port %d "
17109                        "is not stopped\n", port_id);
17110                 return;
17111         }
17112
17113         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17114         if (ret != 0)
17115                 return;
17116
17117         if (queue_id >= dev_info.nb_rx_queues) {
17118                 printf("Error: input queue_id should be 0 ... "
17119                        "%d\n", dev_info.nb_rx_queues - 1);
17120                 return;
17121         }
17122
17123         single_offload = search_rx_offload(res->offload);
17124         if (single_offload == 0) {
17125                 printf("Unknown offload name: %s\n", res->offload);
17126                 return;
17127         }
17128
17129         if (!strcmp(res->on_off, "on"))
17130                 port->rx_conf[queue_id].offloads |= single_offload;
17131         else
17132                 port->rx_conf[queue_id].offloads &= ~single_offload;
17133
17134         cmd_reconfig_device_queue(port_id, 1, 1);
17135 }
17136
17137 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
17138         .f = cmd_config_per_queue_rx_offload_parsed,
17139         .data = NULL,
17140         .help_str = "port <port_id> rxq <queue_id> rx_offload "
17141                     "vlan_strip|ipv4_cksum|"
17142                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17143                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17144                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
17145                     "keep_crc on|off",
17146         .tokens = {
17147                 (void *)&cmd_config_per_queue_rx_offload_result_port,
17148                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
17149                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
17150                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
17151                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
17152                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
17153                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
17154                 NULL,
17155         }
17156 };
17157
17158 /* Get Tx offloads capabilities */
17159 struct cmd_tx_offload_get_capa_result {
17160         cmdline_fixed_string_t show;
17161         cmdline_fixed_string_t port;
17162         portid_t port_id;
17163         cmdline_fixed_string_t tx_offload;
17164         cmdline_fixed_string_t capabilities;
17165 };
17166
17167 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
17168         TOKEN_STRING_INITIALIZER
17169                 (struct cmd_tx_offload_get_capa_result,
17170                  show, "show");
17171 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
17172         TOKEN_STRING_INITIALIZER
17173                 (struct cmd_tx_offload_get_capa_result,
17174                  port, "port");
17175 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
17176         TOKEN_NUM_INITIALIZER
17177                 (struct cmd_tx_offload_get_capa_result,
17178                  port_id, UINT16);
17179 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
17180         TOKEN_STRING_INITIALIZER
17181                 (struct cmd_tx_offload_get_capa_result,
17182                  tx_offload, "tx_offload");
17183 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
17184         TOKEN_STRING_INITIALIZER
17185                 (struct cmd_tx_offload_get_capa_result,
17186                  capabilities, "capabilities");
17187
17188 static void
17189 print_tx_offloads(uint64_t offloads)
17190 {
17191         uint64_t single_offload;
17192         int begin;
17193         int end;
17194         int bit;
17195
17196         if (offloads == 0)
17197                 return;
17198
17199         begin = __builtin_ctzll(offloads);
17200         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17201
17202         single_offload = 1ULL << begin;
17203         for (bit = begin; bit < end; bit++) {
17204                 if (offloads & single_offload)
17205                         printf(" %s",
17206                                rte_eth_dev_tx_offload_name(single_offload));
17207                 single_offload <<= 1;
17208         }
17209 }
17210
17211 static void
17212 cmd_tx_offload_get_capa_parsed(
17213         void *parsed_result,
17214         __rte_unused struct cmdline *cl,
17215         __rte_unused void *data)
17216 {
17217         struct cmd_tx_offload_get_capa_result *res = parsed_result;
17218         struct rte_eth_dev_info dev_info;
17219         portid_t port_id = res->port_id;
17220         uint64_t queue_offloads;
17221         uint64_t port_offloads;
17222         int ret;
17223
17224         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17225         if (ret != 0)
17226                 return;
17227
17228         queue_offloads = dev_info.tx_queue_offload_capa;
17229         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
17230
17231         printf("Tx Offloading Capabilities of port %d :\n", port_id);
17232         printf("  Per Queue :");
17233         print_tx_offloads(queue_offloads);
17234
17235         printf("\n");
17236         printf("  Per Port  :");
17237         print_tx_offloads(port_offloads);
17238         printf("\n\n");
17239 }
17240
17241 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
17242         .f = cmd_tx_offload_get_capa_parsed,
17243         .data = NULL,
17244         .help_str = "show port <port_id> tx_offload capabilities",
17245         .tokens = {
17246                 (void *)&cmd_tx_offload_get_capa_show,
17247                 (void *)&cmd_tx_offload_get_capa_port,
17248                 (void *)&cmd_tx_offload_get_capa_port_id,
17249                 (void *)&cmd_tx_offload_get_capa_tx_offload,
17250                 (void *)&cmd_tx_offload_get_capa_capabilities,
17251                 NULL,
17252         }
17253 };
17254
17255 /* Get Tx offloads configuration */
17256 struct cmd_tx_offload_get_configuration_result {
17257         cmdline_fixed_string_t show;
17258         cmdline_fixed_string_t port;
17259         portid_t port_id;
17260         cmdline_fixed_string_t tx_offload;
17261         cmdline_fixed_string_t configuration;
17262 };
17263
17264 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
17265         TOKEN_STRING_INITIALIZER
17266                 (struct cmd_tx_offload_get_configuration_result,
17267                  show, "show");
17268 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
17269         TOKEN_STRING_INITIALIZER
17270                 (struct cmd_tx_offload_get_configuration_result,
17271                  port, "port");
17272 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
17273         TOKEN_NUM_INITIALIZER
17274                 (struct cmd_tx_offload_get_configuration_result,
17275                  port_id, UINT16);
17276 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
17277         TOKEN_STRING_INITIALIZER
17278                 (struct cmd_tx_offload_get_configuration_result,
17279                  tx_offload, "tx_offload");
17280 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
17281         TOKEN_STRING_INITIALIZER
17282                 (struct cmd_tx_offload_get_configuration_result,
17283                  configuration, "configuration");
17284
17285 static void
17286 cmd_tx_offload_get_configuration_parsed(
17287         void *parsed_result,
17288         __rte_unused struct cmdline *cl,
17289         __rte_unused void *data)
17290 {
17291         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
17292         struct rte_eth_dev_info dev_info;
17293         portid_t port_id = res->port_id;
17294         struct rte_port *port = &ports[port_id];
17295         uint64_t port_offloads;
17296         uint64_t queue_offloads;
17297         uint16_t nb_tx_queues;
17298         int q;
17299         int ret;
17300
17301         printf("Tx Offloading Configuration of port %d :\n", port_id);
17302
17303         port_offloads = port->dev_conf.txmode.offloads;
17304         printf("  Port :");
17305         print_tx_offloads(port_offloads);
17306         printf("\n");
17307
17308         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17309         if (ret != 0)
17310                 return;
17311
17312         nb_tx_queues = dev_info.nb_tx_queues;
17313         for (q = 0; q < nb_tx_queues; q++) {
17314                 queue_offloads = port->tx_conf[q].offloads;
17315                 printf("  Queue[%2d] :", q);
17316                 print_tx_offloads(queue_offloads);
17317                 printf("\n");
17318         }
17319         printf("\n");
17320 }
17321
17322 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17323         .f = cmd_tx_offload_get_configuration_parsed,
17324         .data = NULL,
17325         .help_str = "show port <port_id> tx_offload configuration",
17326         .tokens = {
17327                 (void *)&cmd_tx_offload_get_configuration_show,
17328                 (void *)&cmd_tx_offload_get_configuration_port,
17329                 (void *)&cmd_tx_offload_get_configuration_port_id,
17330                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17331                 (void *)&cmd_tx_offload_get_configuration_configuration,
17332                 NULL,
17333         }
17334 };
17335
17336 /* Enable/Disable a per port offloading */
17337 struct cmd_config_per_port_tx_offload_result {
17338         cmdline_fixed_string_t port;
17339         cmdline_fixed_string_t config;
17340         portid_t port_id;
17341         cmdline_fixed_string_t tx_offload;
17342         cmdline_fixed_string_t offload;
17343         cmdline_fixed_string_t on_off;
17344 };
17345
17346 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17347         TOKEN_STRING_INITIALIZER
17348                 (struct cmd_config_per_port_tx_offload_result,
17349                  port, "port");
17350 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17351         TOKEN_STRING_INITIALIZER
17352                 (struct cmd_config_per_port_tx_offload_result,
17353                  config, "config");
17354 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17355         TOKEN_NUM_INITIALIZER
17356                 (struct cmd_config_per_port_tx_offload_result,
17357                  port_id, UINT16);
17358 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17359         TOKEN_STRING_INITIALIZER
17360                 (struct cmd_config_per_port_tx_offload_result,
17361                  tx_offload, "tx_offload");
17362 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17363         TOKEN_STRING_INITIALIZER
17364                 (struct cmd_config_per_port_tx_offload_result,
17365                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17366                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17367                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17368                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17369                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
17370                           "send_on_timestamp");
17371 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17372         TOKEN_STRING_INITIALIZER
17373                 (struct cmd_config_per_port_tx_offload_result,
17374                  on_off, "on#off");
17375
17376 static uint64_t
17377 search_tx_offload(const char *name)
17378 {
17379         uint64_t single_offload;
17380         const char *single_name;
17381         int found = 0;
17382         unsigned int bit;
17383
17384         single_offload = 1;
17385         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17386                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17387                 if (single_name == NULL)
17388                         break;
17389                 if (!strcasecmp(single_name, name)) {
17390                         found = 1;
17391                         break;
17392                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17393                         break;
17394                 single_offload <<= 1;
17395         }
17396
17397         if (found)
17398                 return single_offload;
17399
17400         return 0;
17401 }
17402
17403 static void
17404 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17405                                 __rte_unused struct cmdline *cl,
17406                                 __rte_unused void *data)
17407 {
17408         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17409         portid_t port_id = res->port_id;
17410         struct rte_eth_dev_info dev_info;
17411         struct rte_port *port = &ports[port_id];
17412         uint64_t single_offload;
17413         uint16_t nb_tx_queues;
17414         int q;
17415         int ret;
17416
17417         if (port->port_status != RTE_PORT_STOPPED) {
17418                 printf("Error: Can't config offload when Port %d "
17419                        "is not stopped\n", port_id);
17420                 return;
17421         }
17422
17423         single_offload = search_tx_offload(res->offload);
17424         if (single_offload == 0) {
17425                 printf("Unknown offload name: %s\n", res->offload);
17426                 return;
17427         }
17428
17429         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17430         if (ret != 0)
17431                 return;
17432
17433         nb_tx_queues = dev_info.nb_tx_queues;
17434         if (!strcmp(res->on_off, "on")) {
17435                 port->dev_conf.txmode.offloads |= single_offload;
17436                 for (q = 0; q < nb_tx_queues; q++)
17437                         port->tx_conf[q].offloads |= single_offload;
17438         } else {
17439                 port->dev_conf.txmode.offloads &= ~single_offload;
17440                 for (q = 0; q < nb_tx_queues; q++)
17441                         port->tx_conf[q].offloads &= ~single_offload;
17442         }
17443
17444         cmd_reconfig_device_queue(port_id, 1, 1);
17445 }
17446
17447 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17448         .f = cmd_config_per_port_tx_offload_parsed,
17449         .data = NULL,
17450         .help_str = "port config <port_id> tx_offload "
17451                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17452                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17453                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17454                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17455                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
17456                     "send_on_timestamp on|off",
17457         .tokens = {
17458                 (void *)&cmd_config_per_port_tx_offload_result_port,
17459                 (void *)&cmd_config_per_port_tx_offload_result_config,
17460                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17461                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17462                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17463                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17464                 NULL,
17465         }
17466 };
17467
17468 /* Enable/Disable a per queue offloading */
17469 struct cmd_config_per_queue_tx_offload_result {
17470         cmdline_fixed_string_t port;
17471         portid_t port_id;
17472         cmdline_fixed_string_t txq;
17473         uint16_t queue_id;
17474         cmdline_fixed_string_t tx_offload;
17475         cmdline_fixed_string_t offload;
17476         cmdline_fixed_string_t on_off;
17477 };
17478
17479 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17480         TOKEN_STRING_INITIALIZER
17481                 (struct cmd_config_per_queue_tx_offload_result,
17482                  port, "port");
17483 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17484         TOKEN_NUM_INITIALIZER
17485                 (struct cmd_config_per_queue_tx_offload_result,
17486                  port_id, UINT16);
17487 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17488         TOKEN_STRING_INITIALIZER
17489                 (struct cmd_config_per_queue_tx_offload_result,
17490                  txq, "txq");
17491 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17492         TOKEN_NUM_INITIALIZER
17493                 (struct cmd_config_per_queue_tx_offload_result,
17494                  queue_id, UINT16);
17495 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17496         TOKEN_STRING_INITIALIZER
17497                 (struct cmd_config_per_queue_tx_offload_result,
17498                  tx_offload, "tx_offload");
17499 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17500         TOKEN_STRING_INITIALIZER
17501                 (struct cmd_config_per_queue_tx_offload_result,
17502                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17503                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17504                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17505                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17506                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
17507 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17508         TOKEN_STRING_INITIALIZER
17509                 (struct cmd_config_per_queue_tx_offload_result,
17510                  on_off, "on#off");
17511
17512 static void
17513 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17514                                 __rte_unused struct cmdline *cl,
17515                                 __rte_unused void *data)
17516 {
17517         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17518         struct rte_eth_dev_info dev_info;
17519         portid_t port_id = res->port_id;
17520         uint16_t queue_id = res->queue_id;
17521         struct rte_port *port = &ports[port_id];
17522         uint64_t single_offload;
17523         int ret;
17524
17525         if (port->port_status != RTE_PORT_STOPPED) {
17526                 printf("Error: Can't config offload when Port %d "
17527                        "is not stopped\n", port_id);
17528                 return;
17529         }
17530
17531         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17532         if (ret != 0)
17533                 return;
17534
17535         if (queue_id >= dev_info.nb_tx_queues) {
17536                 printf("Error: input queue_id should be 0 ... "
17537                        "%d\n", dev_info.nb_tx_queues - 1);
17538                 return;
17539         }
17540
17541         single_offload = search_tx_offload(res->offload);
17542         if (single_offload == 0) {
17543                 printf("Unknown offload name: %s\n", res->offload);
17544                 return;
17545         }
17546
17547         if (!strcmp(res->on_off, "on"))
17548                 port->tx_conf[queue_id].offloads |= single_offload;
17549         else
17550                 port->tx_conf[queue_id].offloads &= ~single_offload;
17551
17552         cmd_reconfig_device_queue(port_id, 1, 1);
17553 }
17554
17555 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17556         .f = cmd_config_per_queue_tx_offload_parsed,
17557         .data = NULL,
17558         .help_str = "port <port_id> txq <queue_id> tx_offload "
17559                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17560                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17561                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17562                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17563                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
17564                     "on|off",
17565         .tokens = {
17566                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17567                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17568                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17569                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17570                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17571                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17572                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17573                 NULL,
17574         }
17575 };
17576
17577 /* *** configure tx_metadata for specific port *** */
17578 struct cmd_config_tx_metadata_specific_result {
17579         cmdline_fixed_string_t port;
17580         cmdline_fixed_string_t keyword;
17581         uint16_t port_id;
17582         cmdline_fixed_string_t item;
17583         uint32_t value;
17584 };
17585
17586 static void
17587 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
17588                                 __rte_unused struct cmdline *cl,
17589                                 __rte_unused void *data)
17590 {
17591         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
17592
17593         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17594                 return;
17595         ports[res->port_id].tx_metadata = res->value;
17596         /* Add/remove callback to insert valid metadata in every Tx packet. */
17597         if (ports[res->port_id].tx_metadata)
17598                 add_tx_md_callback(res->port_id);
17599         else
17600                 remove_tx_md_callback(res->port_id);
17601         rte_flow_dynf_metadata_register();
17602 }
17603
17604 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
17605         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17606                         port, "port");
17607 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
17608         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17609                         keyword, "config");
17610 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
17611         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17612                         port_id, UINT16);
17613 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
17614         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17615                         item, "tx_metadata");
17616 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
17617         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17618                         value, UINT32);
17619
17620 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
17621         .f = cmd_config_tx_metadata_specific_parsed,
17622         .data = NULL,
17623         .help_str = "port config <port_id> tx_metadata <value>",
17624         .tokens = {
17625                 (void *)&cmd_config_tx_metadata_specific_port,
17626                 (void *)&cmd_config_tx_metadata_specific_keyword,
17627                 (void *)&cmd_config_tx_metadata_specific_id,
17628                 (void *)&cmd_config_tx_metadata_specific_item,
17629                 (void *)&cmd_config_tx_metadata_specific_value,
17630                 NULL,
17631         },
17632 };
17633
17634 /* *** set dynf *** */
17635 struct cmd_config_tx_dynf_specific_result {
17636         cmdline_fixed_string_t port;
17637         cmdline_fixed_string_t keyword;
17638         uint16_t port_id;
17639         cmdline_fixed_string_t item;
17640         cmdline_fixed_string_t name;
17641         cmdline_fixed_string_t value;
17642 };
17643
17644 static void
17645 cmd_config_dynf_specific_parsed(void *parsed_result,
17646                                 __rte_unused struct cmdline *cl,
17647                                 __rte_unused void *data)
17648 {
17649         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
17650         struct rte_mbuf_dynflag desc_flag;
17651         int flag;
17652         uint64_t old_port_flags;
17653
17654         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17655                 return;
17656         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
17657         if (flag <= 0) {
17658                 if (strlcpy(desc_flag.name, res->name,
17659                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
17660                         printf("Flag name too long\n");
17661                         return;
17662                 }
17663                 desc_flag.flags = 0;
17664                 flag = rte_mbuf_dynflag_register(&desc_flag);
17665                 if (flag < 0) {
17666                         printf("Can't register flag\n");
17667                         return;
17668                 }
17669                 strcpy(dynf_names[flag], desc_flag.name);
17670         }
17671         old_port_flags = ports[res->port_id].mbuf_dynf;
17672         if (!strcmp(res->value, "set")) {
17673                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
17674                 if (old_port_flags == 0)
17675                         add_tx_dynf_callback(res->port_id);
17676         } else {
17677                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
17678                 if (ports[res->port_id].mbuf_dynf == 0)
17679                         remove_tx_dynf_callback(res->port_id);
17680         }
17681 }
17682
17683 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
17684         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17685                         keyword, "port");
17686 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
17687         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17688                         keyword, "config");
17689 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
17690         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17691                         port_id, UINT16);
17692 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
17693         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17694                         item, "dynf");
17695 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
17696         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17697                         name, NULL);
17698 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
17699         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17700                         value, "set#clear");
17701
17702 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
17703         .f = cmd_config_dynf_specific_parsed,
17704         .data = NULL,
17705         .help_str = "port config <port id> dynf <name> set|clear",
17706         .tokens = {
17707                 (void *)&cmd_config_tx_dynf_specific_port,
17708                 (void *)&cmd_config_tx_dynf_specific_keyword,
17709                 (void *)&cmd_config_tx_dynf_specific_port_id,
17710                 (void *)&cmd_config_tx_dynf_specific_item,
17711                 (void *)&cmd_config_tx_dynf_specific_name,
17712                 (void *)&cmd_config_tx_dynf_specific_value,
17713                 NULL,
17714         },
17715 };
17716
17717 /* *** display tx_metadata per port configuration *** */
17718 struct cmd_show_tx_metadata_result {
17719         cmdline_fixed_string_t cmd_show;
17720         cmdline_fixed_string_t cmd_port;
17721         cmdline_fixed_string_t cmd_keyword;
17722         portid_t cmd_pid;
17723 };
17724
17725 static void
17726 cmd_show_tx_metadata_parsed(void *parsed_result,
17727                 __rte_unused struct cmdline *cl,
17728                 __rte_unused void *data)
17729 {
17730         struct cmd_show_tx_metadata_result *res = parsed_result;
17731
17732         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17733                 printf("invalid port id %u\n", res->cmd_pid);
17734                 return;
17735         }
17736         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
17737                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
17738                        ports[res->cmd_pid].tx_metadata);
17739         }
17740 }
17741
17742 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
17743         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17744                         cmd_show, "show");
17745 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
17746         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17747                         cmd_port, "port");
17748 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
17749         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
17750                         cmd_pid, UINT16);
17751 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
17752         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17753                         cmd_keyword, "tx_metadata");
17754
17755 cmdline_parse_inst_t cmd_show_tx_metadata = {
17756         .f = cmd_show_tx_metadata_parsed,
17757         .data = NULL,
17758         .help_str = "show port <port_id> tx_metadata",
17759         .tokens = {
17760                 (void *)&cmd_show_tx_metadata_show,
17761                 (void *)&cmd_show_tx_metadata_port,
17762                 (void *)&cmd_show_tx_metadata_pid,
17763                 (void *)&cmd_show_tx_metadata_keyword,
17764                 NULL,
17765         },
17766 };
17767
17768 /* *** show fec capability per port configuration *** */
17769 struct cmd_show_fec_capability_result {
17770         cmdline_fixed_string_t cmd_show;
17771         cmdline_fixed_string_t cmd_port;
17772         cmdline_fixed_string_t cmd_fec;
17773         cmdline_fixed_string_t cmd_keyword;
17774         portid_t cmd_pid;
17775 };
17776
17777 static void
17778 cmd_show_fec_capability_parsed(void *parsed_result,
17779                 __rte_unused struct cmdline *cl,
17780                 __rte_unused void *data)
17781 {
17782 #define FEC_CAP_NUM 2
17783         struct cmd_show_fec_capability_result *res = parsed_result;
17784         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
17785         unsigned int num = FEC_CAP_NUM;
17786         unsigned int ret_num;
17787         int ret;
17788
17789         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17790                 printf("Invalid port id %u\n", res->cmd_pid);
17791                 return;
17792         }
17793
17794         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
17795         if (ret == -ENOTSUP) {
17796                 printf("Function not implemented\n");
17797                 return;
17798         } else if (ret < 0) {
17799                 printf("Get FEC capability failed\n");
17800                 return;
17801         }
17802
17803         ret_num = (unsigned int)ret;
17804         show_fec_capability(ret_num, speed_fec_capa);
17805 }
17806
17807 cmdline_parse_token_string_t cmd_show_fec_capability_show =
17808         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17809                         cmd_show, "show");
17810 cmdline_parse_token_string_t cmd_show_fec_capability_port =
17811         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17812                         cmd_port, "port");
17813 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17814         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17815                         cmd_pid, UINT16);
17816 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17817         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17818                         cmd_fec, "fec");
17819 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17820         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17821                         cmd_keyword, "capabilities");
17822
17823 cmdline_parse_inst_t cmd_show_capability = {
17824         .f = cmd_show_fec_capability_parsed,
17825         .data = NULL,
17826         .help_str = "show port <port_id> fec capabilities",
17827         .tokens = {
17828                 (void *)&cmd_show_fec_capability_show,
17829                 (void *)&cmd_show_fec_capability_port,
17830                 (void *)&cmd_show_fec_capability_pid,
17831                 (void *)&cmd_show_fec_capability_fec,
17832                 (void *)&cmd_show_fec_capability_keyword,
17833                 NULL,
17834         },
17835 };
17836
17837 /* *** show fec mode per port configuration *** */
17838 struct cmd_show_fec_metadata_result {
17839         cmdline_fixed_string_t cmd_show;
17840         cmdline_fixed_string_t cmd_port;
17841         cmdline_fixed_string_t cmd_keyword;
17842         portid_t cmd_pid;
17843 };
17844
17845 static void
17846 cmd_show_fec_mode_parsed(void *parsed_result,
17847                 __rte_unused struct cmdline *cl,
17848                 __rte_unused void *data)
17849 {
17850 #define FEC_NAME_SIZE 16
17851         struct cmd_show_fec_metadata_result *res = parsed_result;
17852         uint32_t mode;
17853         char buf[FEC_NAME_SIZE];
17854         int ret;
17855
17856         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17857                 printf("Invalid port id %u\n", res->cmd_pid);
17858                 return;
17859         }
17860         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17861         if (ret == -ENOTSUP) {
17862                 printf("Function not implemented\n");
17863                 return;
17864         } else if (ret < 0) {
17865                 printf("Get FEC mode failed\n");
17866                 return;
17867         }
17868
17869         switch (mode) {
17870         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17871                 strlcpy(buf, "off", sizeof(buf));
17872                 break;
17873         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17874                 strlcpy(buf, "auto", sizeof(buf));
17875                 break;
17876         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17877                 strlcpy(buf, "baser", sizeof(buf));
17878                 break;
17879         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17880                 strlcpy(buf, "rs", sizeof(buf));
17881                 break;
17882         default:
17883                 return;
17884         }
17885
17886         printf("%s\n", buf);
17887 }
17888
17889 cmdline_parse_token_string_t cmd_show_fec_mode_show =
17890         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17891                         cmd_show, "show");
17892 cmdline_parse_token_string_t cmd_show_fec_mode_port =
17893         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17894                         cmd_port, "port");
17895 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17896         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17897                         cmd_pid, UINT16);
17898 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17899         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17900                         cmd_keyword, "fec_mode");
17901
17902 cmdline_parse_inst_t cmd_show_fec_mode = {
17903         .f = cmd_show_fec_mode_parsed,
17904         .data = NULL,
17905         .help_str = "show port <port_id> fec_mode",
17906         .tokens = {
17907                 (void *)&cmd_show_fec_mode_show,
17908                 (void *)&cmd_show_fec_mode_port,
17909                 (void *)&cmd_show_fec_mode_pid,
17910                 (void *)&cmd_show_fec_mode_keyword,
17911                 NULL,
17912         },
17913 };
17914
17915 /* *** set fec mode per port configuration *** */
17916 struct cmd_set_port_fec_mode {
17917         cmdline_fixed_string_t set;
17918         cmdline_fixed_string_t port;
17919         portid_t port_id;
17920         cmdline_fixed_string_t fec_mode;
17921         cmdline_fixed_string_t fec_value;
17922 };
17923
17924 /* Common CLI fields for set fec mode */
17925 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17926         TOKEN_STRING_INITIALIZER
17927                 (struct cmd_set_port_fec_mode,
17928                  set, "set");
17929 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17930         TOKEN_STRING_INITIALIZER
17931                 (struct cmd_set_port_fec_mode,
17932                  port, "port");
17933 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17934         TOKEN_NUM_INITIALIZER
17935                 (struct cmd_set_port_fec_mode,
17936                  port_id, UINT16);
17937 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17938         TOKEN_STRING_INITIALIZER
17939                 (struct cmd_set_port_fec_mode,
17940                  fec_mode, "fec_mode");
17941 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17942         TOKEN_STRING_INITIALIZER
17943                 (struct cmd_set_port_fec_mode,
17944                  fec_value, NULL);
17945
17946 static void
17947 cmd_set_port_fec_mode_parsed(
17948         void *parsed_result,
17949         __rte_unused struct cmdline *cl,
17950         __rte_unused void *data)
17951 {
17952         struct cmd_set_port_fec_mode *res = parsed_result;
17953         uint16_t port_id = res->port_id;
17954         uint32_t mode;
17955         int ret;
17956
17957         ret = parse_fec_mode(res->fec_value, &mode);
17958         if (ret < 0) {
17959                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
17960                         port_id);
17961                 return;
17962         }
17963
17964         ret = rte_eth_fec_set(port_id, mode);
17965         if (ret == -ENOTSUP) {
17966                 printf("Function not implemented\n");
17967                 return;
17968         } else if (ret < 0) {
17969                 printf("Set FEC mode failed\n");
17970                 return;
17971         }
17972 }
17973
17974 cmdline_parse_inst_t cmd_set_fec_mode = {
17975         .f = cmd_set_port_fec_mode_parsed,
17976         .data = NULL,
17977         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17978         .tokens = {
17979                 (void *)&cmd_set_port_fec_mode_set,
17980                 (void *)&cmd_set_port_fec_mode_port,
17981                 (void *)&cmd_set_port_fec_mode_port_id,
17982                 (void *)&cmd_set_port_fec_mode_str,
17983                 (void *)&cmd_set_port_fec_mode_value,
17984                 NULL,
17985         },
17986 };
17987
17988 /* show port supported ptypes */
17989
17990 /* Common result structure for show port ptypes */
17991 struct cmd_show_port_supported_ptypes_result {
17992         cmdline_fixed_string_t show;
17993         cmdline_fixed_string_t port;
17994         portid_t port_id;
17995         cmdline_fixed_string_t ptypes;
17996 };
17997
17998 /* Common CLI fields for show port ptypes */
17999 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
18000         TOKEN_STRING_INITIALIZER
18001                 (struct cmd_show_port_supported_ptypes_result,
18002                  show, "show");
18003 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
18004         TOKEN_STRING_INITIALIZER
18005                 (struct cmd_show_port_supported_ptypes_result,
18006                  port, "port");
18007 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
18008         TOKEN_NUM_INITIALIZER
18009                 (struct cmd_show_port_supported_ptypes_result,
18010                  port_id, UINT16);
18011 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
18012         TOKEN_STRING_INITIALIZER
18013                 (struct cmd_show_port_supported_ptypes_result,
18014                  ptypes, "ptypes");
18015
18016 static void
18017 cmd_show_port_supported_ptypes_parsed(
18018         void *parsed_result,
18019         __rte_unused struct cmdline *cl,
18020         __rte_unused void *data)
18021 {
18022 #define RSVD_PTYPE_MASK       0xf0000000
18023 #define MAX_PTYPES_PER_LAYER  16
18024 #define LTYPE_NAMESIZE        32
18025 #define PTYPE_NAMESIZE        256
18026         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
18027         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
18028         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
18029         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
18030         uint16_t port_id = res->port_id;
18031         int ret, i;
18032
18033         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
18034         if (ret < 0)
18035                 return;
18036
18037         while (ptype_mask != RSVD_PTYPE_MASK) {
18038
18039                 switch (ptype_mask) {
18040                 case RTE_PTYPE_L2_MASK:
18041                         strlcpy(ltype, "L2", sizeof(ltype));
18042                         break;
18043                 case RTE_PTYPE_L3_MASK:
18044                         strlcpy(ltype, "L3", sizeof(ltype));
18045                         break;
18046                 case RTE_PTYPE_L4_MASK:
18047                         strlcpy(ltype, "L4", sizeof(ltype));
18048                         break;
18049                 case RTE_PTYPE_TUNNEL_MASK:
18050                         strlcpy(ltype, "Tunnel", sizeof(ltype));
18051                         break;
18052                 case RTE_PTYPE_INNER_L2_MASK:
18053                         strlcpy(ltype, "Inner L2", sizeof(ltype));
18054                         break;
18055                 case RTE_PTYPE_INNER_L3_MASK:
18056                         strlcpy(ltype, "Inner L3", sizeof(ltype));
18057                         break;
18058                 case RTE_PTYPE_INNER_L4_MASK:
18059                         strlcpy(ltype, "Inner L4", sizeof(ltype));
18060                         break;
18061                 default:
18062                         return;
18063                 }
18064
18065                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
18066                                                        ptype_mask, ptypes,
18067                                                        MAX_PTYPES_PER_LAYER);
18068
18069                 if (ret > 0)
18070                         printf("Supported %s ptypes:\n", ltype);
18071                 else
18072                         printf("%s ptypes unsupported\n", ltype);
18073
18074                 for (i = 0; i < ret; ++i) {
18075                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
18076                         printf("%s\n", buf);
18077                 }
18078
18079                 ptype_mask <<= 4;
18080         }
18081 }
18082
18083 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
18084         .f = cmd_show_port_supported_ptypes_parsed,
18085         .data = NULL,
18086         .help_str = "show port <port_id> ptypes",
18087         .tokens = {
18088                 (void *)&cmd_show_port_supported_ptypes_show,
18089                 (void *)&cmd_show_port_supported_ptypes_port,
18090                 (void *)&cmd_show_port_supported_ptypes_port_id,
18091                 (void *)&cmd_show_port_supported_ptypes_ptypes,
18092                 NULL,
18093         },
18094 };
18095
18096 /* *** display rx/tx descriptor status *** */
18097 struct cmd_show_rx_tx_desc_status_result {
18098         cmdline_fixed_string_t cmd_show;
18099         cmdline_fixed_string_t cmd_port;
18100         cmdline_fixed_string_t cmd_keyword;
18101         cmdline_fixed_string_t cmd_desc;
18102         cmdline_fixed_string_t cmd_status;
18103         portid_t cmd_pid;
18104         portid_t cmd_qid;
18105         portid_t cmd_did;
18106 };
18107
18108 static void
18109 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
18110                 __rte_unused struct cmdline *cl,
18111                 __rte_unused void *data)
18112 {
18113         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
18114         int rc;
18115
18116         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18117                 printf("invalid port id %u\n", res->cmd_pid);
18118                 return;
18119         }
18120
18121         if (!strcmp(res->cmd_keyword, "rxq")) {
18122                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
18123                                              res->cmd_did);
18124                 if (rc < 0) {
18125                         printf("Invalid queueid = %d\n", res->cmd_qid);
18126                         return;
18127                 }
18128                 if (rc == RTE_ETH_RX_DESC_AVAIL)
18129                         printf("Desc status = AVAILABLE\n");
18130                 else if (rc == RTE_ETH_RX_DESC_DONE)
18131                         printf("Desc status = DONE\n");
18132                 else
18133                         printf("Desc status = UNAVAILABLE\n");
18134         } else if (!strcmp(res->cmd_keyword, "txq")) {
18135                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
18136                                              res->cmd_did);
18137                 if (rc < 0) {
18138                         printf("Invalid queueid = %d\n", res->cmd_qid);
18139                         return;
18140                 }
18141                 if (rc == RTE_ETH_TX_DESC_FULL)
18142                         printf("Desc status = FULL\n");
18143                 else if (rc == RTE_ETH_TX_DESC_DONE)
18144                         printf("Desc status = DONE\n");
18145                 else
18146                         printf("Desc status = UNAVAILABLE\n");
18147         }
18148 }
18149
18150 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
18151         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18152                         cmd_show, "show");
18153 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
18154         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18155                         cmd_port, "port");
18156 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
18157         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18158                         cmd_pid, UINT16);
18159 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
18160         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18161                         cmd_keyword, "rxq#txq");
18162 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
18163         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18164                         cmd_qid, UINT16);
18165 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
18166         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18167                         cmd_desc, "desc");
18168 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
18169         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18170                         cmd_did, UINT16);
18171 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
18172         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18173                         cmd_status, "status");
18174 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
18175         .f = cmd_show_rx_tx_desc_status_parsed,
18176         .data = NULL,
18177         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
18178                 "status",
18179         .tokens = {
18180                 (void *)&cmd_show_rx_tx_desc_status_show,
18181                 (void *)&cmd_show_rx_tx_desc_status_port,
18182                 (void *)&cmd_show_rx_tx_desc_status_pid,
18183                 (void *)&cmd_show_rx_tx_desc_status_keyword,
18184                 (void *)&cmd_show_rx_tx_desc_status_qid,
18185                 (void *)&cmd_show_rx_tx_desc_status_desc,
18186                 (void *)&cmd_show_rx_tx_desc_status_did,
18187                 (void *)&cmd_show_rx_tx_desc_status_status,
18188                 NULL,
18189         },
18190 };
18191
18192 /* Common result structure for set port ptypes */
18193 struct cmd_set_port_ptypes_result {
18194         cmdline_fixed_string_t set;
18195         cmdline_fixed_string_t port;
18196         portid_t port_id;
18197         cmdline_fixed_string_t ptype_mask;
18198         uint32_t mask;
18199 };
18200
18201 /* Common CLI fields for set port ptypes */
18202 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
18203         TOKEN_STRING_INITIALIZER
18204                 (struct cmd_set_port_ptypes_result,
18205                  set, "set");
18206 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
18207         TOKEN_STRING_INITIALIZER
18208                 (struct cmd_set_port_ptypes_result,
18209                  port, "port");
18210 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
18211         TOKEN_NUM_INITIALIZER
18212                 (struct cmd_set_port_ptypes_result,
18213                  port_id, UINT16);
18214 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
18215         TOKEN_STRING_INITIALIZER
18216                 (struct cmd_set_port_ptypes_result,
18217                  ptype_mask, "ptype_mask");
18218 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
18219         TOKEN_NUM_INITIALIZER
18220                 (struct cmd_set_port_ptypes_result,
18221                  mask, UINT32);
18222
18223 static void
18224 cmd_set_port_ptypes_parsed(
18225         void *parsed_result,
18226         __rte_unused struct cmdline *cl,
18227         __rte_unused void *data)
18228 {
18229         struct cmd_set_port_ptypes_result *res = parsed_result;
18230 #define PTYPE_NAMESIZE        256
18231         char ptype_name[PTYPE_NAMESIZE];
18232         uint16_t port_id = res->port_id;
18233         uint32_t ptype_mask = res->mask;
18234         int ret, i;
18235
18236         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
18237                                                NULL, 0);
18238         if (ret <= 0) {
18239                 printf("Port %d doesn't support any ptypes.\n", port_id);
18240                 return;
18241         }
18242
18243         uint32_t ptypes[ret];
18244
18245         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
18246         if (ret < 0) {
18247                 printf("Unable to set requested ptypes for Port %d\n", port_id);
18248                 return;
18249         }
18250
18251         printf("Successfully set following ptypes for Port %d\n", port_id);
18252         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
18253                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
18254                 printf("%s\n", ptype_name);
18255         }
18256
18257         clear_ptypes = false;
18258 }
18259
18260 cmdline_parse_inst_t cmd_set_port_ptypes = {
18261         .f = cmd_set_port_ptypes_parsed,
18262         .data = NULL,
18263         .help_str = "set port <port_id> ptype_mask <mask>",
18264         .tokens = {
18265                 (void *)&cmd_set_port_ptypes_set,
18266                 (void *)&cmd_set_port_ptypes_port,
18267                 (void *)&cmd_set_port_ptypes_port_id,
18268                 (void *)&cmd_set_port_ptypes_mask_str,
18269                 (void *)&cmd_set_port_ptypes_mask_u32,
18270                 NULL,
18271         },
18272 };
18273
18274 /* *** display mac addresses added to a port *** */
18275 struct cmd_showport_macs_result {
18276         cmdline_fixed_string_t cmd_show;
18277         cmdline_fixed_string_t cmd_port;
18278         cmdline_fixed_string_t cmd_keyword;
18279         portid_t cmd_pid;
18280 };
18281
18282 static void
18283 cmd_showport_macs_parsed(void *parsed_result,
18284                 __rte_unused struct cmdline *cl,
18285                 __rte_unused void *data)
18286 {
18287         struct cmd_showport_macs_result *res = parsed_result;
18288
18289         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
18290                 return;
18291
18292         if (!strcmp(res->cmd_keyword, "macs"))
18293                 show_macs(res->cmd_pid);
18294         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
18295                 show_mcast_macs(res->cmd_pid);
18296 }
18297
18298 cmdline_parse_token_string_t cmd_showport_macs_show =
18299         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
18300                         cmd_show, "show");
18301 cmdline_parse_token_string_t cmd_showport_macs_port =
18302         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
18303                         cmd_port, "port");
18304 cmdline_parse_token_num_t cmd_showport_macs_pid =
18305         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
18306                         cmd_pid, UINT16);
18307 cmdline_parse_token_string_t cmd_showport_macs_keyword =
18308         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
18309                         cmd_keyword, "macs#mcast_macs");
18310
18311 cmdline_parse_inst_t cmd_showport_macs = {
18312         .f = cmd_showport_macs_parsed,
18313         .data = NULL,
18314         .help_str = "show port <port_id> macs|mcast_macs",
18315         .tokens = {
18316                 (void *)&cmd_showport_macs_show,
18317                 (void *)&cmd_showport_macs_port,
18318                 (void *)&cmd_showport_macs_pid,
18319                 (void *)&cmd_showport_macs_keyword,
18320                 NULL,
18321         },
18322 };
18323
18324 /* ******************************************************************************** */
18325
18326 /* list of instructions */
18327 cmdline_parse_ctx_t main_ctx[] = {
18328         (cmdline_parse_inst_t *)&cmd_help_brief,
18329         (cmdline_parse_inst_t *)&cmd_help_long,
18330         (cmdline_parse_inst_t *)&cmd_quit,
18331         (cmdline_parse_inst_t *)&cmd_load_from_file,
18332         (cmdline_parse_inst_t *)&cmd_showport,
18333         (cmdline_parse_inst_t *)&cmd_showqueue,
18334         (cmdline_parse_inst_t *)&cmd_showeeprom,
18335         (cmdline_parse_inst_t *)&cmd_showportall,
18336         (cmdline_parse_inst_t *)&cmd_showdevice,
18337         (cmdline_parse_inst_t *)&cmd_showcfg,
18338         (cmdline_parse_inst_t *)&cmd_showfwdall,
18339         (cmdline_parse_inst_t *)&cmd_start,
18340         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18341         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18342         (cmdline_parse_inst_t *)&cmd_set_link_up,
18343         (cmdline_parse_inst_t *)&cmd_set_link_down,
18344         (cmdline_parse_inst_t *)&cmd_reset,
18345         (cmdline_parse_inst_t *)&cmd_set_numbers,
18346         (cmdline_parse_inst_t *)&cmd_set_log,
18347         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
18348         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
18349         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18350         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18351         (cmdline_parse_inst_t *)&cmd_set_txtimes,
18352         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18353         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18354         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18355         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18356         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18357         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18358         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18359         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18360         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18361         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18362         (cmdline_parse_inst_t *)&cmd_set_link_check,
18363         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18364         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18365         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18366         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18367 #ifdef RTE_NET_BOND
18368         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18369         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18370         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18371         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18372         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18373         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18374         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18375         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18376         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18377         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18378         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18379 #endif
18380         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18381         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18382         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18383         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18384         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18385         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18386         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18387         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18388         (cmdline_parse_inst_t *)&cmd_csum_set,
18389         (cmdline_parse_inst_t *)&cmd_csum_show,
18390         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18391         (cmdline_parse_inst_t *)&cmd_tso_set,
18392         (cmdline_parse_inst_t *)&cmd_tso_show,
18393         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18394         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18395         (cmdline_parse_inst_t *)&cmd_gro_enable,
18396         (cmdline_parse_inst_t *)&cmd_gro_flush,
18397         (cmdline_parse_inst_t *)&cmd_gro_show,
18398         (cmdline_parse_inst_t *)&cmd_gso_enable,
18399         (cmdline_parse_inst_t *)&cmd_gso_size,
18400         (cmdline_parse_inst_t *)&cmd_gso_show,
18401         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18402         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18403         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18404         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18405         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18406         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18407         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18408         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18409         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18410         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18411         (cmdline_parse_inst_t *)&cmd_config_dcb,
18412         (cmdline_parse_inst_t *)&cmd_read_reg,
18413         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18414         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18415         (cmdline_parse_inst_t *)&cmd_write_reg,
18416         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18417         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18418         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18419         (cmdline_parse_inst_t *)&cmd_stop,
18420         (cmdline_parse_inst_t *)&cmd_mac_addr,
18421         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18422         (cmdline_parse_inst_t *)&cmd_set_qmap,
18423         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18424         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
18425         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
18426         (cmdline_parse_inst_t *)&cmd_operate_port,
18427         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18428         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18429         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18430         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
18431         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18432         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18433         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18434         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18435         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18436         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18437         (cmdline_parse_inst_t *)&cmd_config_mtu,
18438         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18439         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
18440         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18441         (cmdline_parse_inst_t *)&cmd_config_rss,
18442         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18443         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18444         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18445         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18446         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18447         (cmdline_parse_inst_t *)&cmd_showport_reta,
18448         (cmdline_parse_inst_t *)&cmd_showport_macs,
18449         (cmdline_parse_inst_t *)&cmd_config_burst,
18450         (cmdline_parse_inst_t *)&cmd_config_thresh,
18451         (cmdline_parse_inst_t *)&cmd_config_threshold,
18452         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18453         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18454         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18455         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18456         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18457         (cmdline_parse_inst_t *)&cmd_global_config,
18458         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18459         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18460         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18461         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18462         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18463         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18464         (cmdline_parse_inst_t *)&cmd_dump,
18465         (cmdline_parse_inst_t *)&cmd_dump_one,
18466         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18467         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18468         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18469         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18470         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18471         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18472         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18473         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18474         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18475         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18476         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18477         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18478         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18479         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18480         (cmdline_parse_inst_t *)&cmd_flow,
18481         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18482         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18483         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18484         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18485         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18486         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18487         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18488         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18489         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18490         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18491         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18492         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18493         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18494         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18495         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18496         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18497         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18498         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18499         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18500         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18501         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18502         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18503         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18504         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18505         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18506         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18507         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18508         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18509         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18510         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18511         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18512         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18513         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18514         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18515         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18516         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18517         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18518         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18519         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18520         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18521         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18522         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18523         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18524         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18525         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18526         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18527         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18528         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18529         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18530         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18531         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18532         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18533         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18534         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18535         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18536         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18537         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18538         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18539         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18540         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18541         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18542         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18543         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18544         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18545         (cmdline_parse_inst_t *)&cmd_ddp_add,
18546         (cmdline_parse_inst_t *)&cmd_ddp_del,
18547         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18548         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18549         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18550         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18551         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18552         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18553         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
18554         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
18555         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18556         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18557         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18558         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18559
18560         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18561         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18562         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18563         (cmdline_parse_inst_t *)&cmd_queue_region,
18564         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18565         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18566         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18567         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18568         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18569         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18570         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18571         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18572         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18573         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18574         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18575         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18576         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18577         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18578         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18579         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18580         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18581         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
18582         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18583         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18584         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18585         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18586         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18587         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18588         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18589         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18590         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18591         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18592         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18593         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18594         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18595         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18596         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18597         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18598         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18599         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18600 #ifdef RTE_LIB_BPF
18601         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18602         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18603 #endif
18604         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18605         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18606         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
18607         (cmdline_parse_inst_t *)&cmd_set_raw,
18608         (cmdline_parse_inst_t *)&cmd_show_set_raw,
18609         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
18610         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
18611         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
18612         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
18613         (cmdline_parse_inst_t *)&cmd_show_capability,
18614         NULL,
18615 };
18616
18617 /* read cmdline commands from file */
18618 void
18619 cmdline_read_from_file(const char *filename)
18620 {
18621         struct cmdline *cl;
18622
18623         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18624         if (cl == NULL) {
18625                 printf("Failed to create file based cmdline context: %s\n",
18626                        filename);
18627                 return;
18628         }
18629
18630         cmdline_interact(cl);
18631         cmdline_quit(cl);
18632
18633         cmdline_free(cl);
18634
18635         printf("Read CLI commands from %s\n", filename);
18636 }
18637
18638 /* prompt function, called from main on MAIN lcore */
18639 void
18640 prompt(void)
18641 {
18642         /* initialize non-constant commands */
18643         cmd_set_fwd_mode_init();
18644         cmd_set_fwd_retry_mode_init();
18645
18646         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18647         if (testpmd_cl == NULL)
18648                 return;
18649         cmdline_interact(testpmd_cl);
18650         cmdline_stdin_exit(testpmd_cl);
18651 }
18652
18653 void
18654 prompt_exit(void)
18655 {
18656         if (testpmd_cl != NULL)
18657                 cmdline_quit(testpmd_cl);
18658 }
18659
18660 static void
18661 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18662 {
18663         if (id == (portid_t)RTE_PORT_ALL) {
18664                 portid_t pid;
18665
18666                 RTE_ETH_FOREACH_DEV(pid) {
18667                         /* check if need_reconfig has been set to 1 */
18668                         if (ports[pid].need_reconfig == 0)
18669                                 ports[pid].need_reconfig = dev;
18670                         /* check if need_reconfig_queues has been set to 1 */
18671                         if (ports[pid].need_reconfig_queues == 0)
18672                                 ports[pid].need_reconfig_queues = queue;
18673                 }
18674         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18675                 /* check if need_reconfig has been set to 1 */
18676                 if (ports[id].need_reconfig == 0)
18677                         ports[id].need_reconfig = dev;
18678                 /* check if need_reconfig_queues has been set to 1 */
18679                 if (ports[id].need_reconfig_queues == 0)
18680                         ports[id].need_reconfig_queues = queue;
18681         }
18682 }