ethdev: remove redundant device info cleanup before get
[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 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22
23 #include <sys/queue.h>
24
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_flow.h>
48 #include <rte_gro.h>
49
50 #include <cmdline_rdline.h>
51 #include <cmdline_parse.h>
52 #include <cmdline_parse_num.h>
53 #include <cmdline_parse_string.h>
54 #include <cmdline_parse_ipaddr.h>
55 #include <cmdline_parse_etheraddr.h>
56 #include <cmdline_socket.h>
57 #include <cmdline.h>
58 #ifdef RTE_LIBRTE_PMD_BOND
59 #include <rte_eth_bond.h>
60 #include <rte_eth_bond_8023ad.h>
61 #endif
62 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
63 #include <rte_pmd_dpaa.h>
64 #endif
65 #ifdef RTE_LIBRTE_IXGBE_PMD
66 #include <rte_pmd_ixgbe.h>
67 #endif
68 #ifdef RTE_LIBRTE_I40E_PMD
69 #include <rte_pmd_i40e.h>
70 #endif
71 #ifdef RTE_LIBRTE_BNXT_PMD
72 #include <rte_pmd_bnxt.h>
73 #endif
74 #include "testpmd.h"
75 #include "cmdline_mtr.h"
76 #include "cmdline_tm.h"
77 #include "bpf_cmd.h"
78
79 static struct cmdline *testpmd_cl;
80
81 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
82
83 /* *** Help command with introduction. *** */
84 struct cmd_help_brief_result {
85         cmdline_fixed_string_t help;
86 };
87
88 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
89                                   struct cmdline *cl,
90                                   __attribute__((unused)) void *data)
91 {
92         cmdline_printf(
93                 cl,
94                 "\n"
95                 "Help is available for the following sections:\n\n"
96                 "    help control                    : Start and stop forwarding.\n"
97                 "    help display                    : Displaying port, stats and config "
98                 "information.\n"
99                 "    help config                     : Configuration information.\n"
100                 "    help ports                      : Configuring ports.\n"
101                 "    help registers                  : Reading and setting port registers.\n"
102                 "    help filters                    : Filters configuration help.\n"
103                 "    help traffic_management         : Traffic Management commmands.\n"
104                 "    help devices                    : Device related cmds.\n"
105                 "    help all                        : All of the above sections.\n\n"
106         );
107
108 }
109
110 cmdline_parse_token_string_t cmd_help_brief_help =
111         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
112
113 cmdline_parse_inst_t cmd_help_brief = {
114         .f = cmd_help_brief_parsed,
115         .data = NULL,
116         .help_str = "help: Show help",
117         .tokens = {
118                 (void *)&cmd_help_brief_help,
119                 NULL,
120         },
121 };
122
123 /* *** Help command with help sections. *** */
124 struct cmd_help_long_result {
125         cmdline_fixed_string_t help;
126         cmdline_fixed_string_t section;
127 };
128
129 static void cmd_help_long_parsed(void *parsed_result,
130                                  struct cmdline *cl,
131                                  __attribute__((unused)) void *data)
132 {
133         int show_all = 0;
134         struct cmd_help_long_result *res = parsed_result;
135
136         if (!strcmp(res->section, "all"))
137                 show_all = 1;
138
139         if (show_all || !strcmp(res->section, "control")) {
140
141                 cmdline_printf(
142                         cl,
143                         "\n"
144                         "Control forwarding:\n"
145                         "-------------------\n\n"
146
147                         "start\n"
148                         "    Start packet forwarding with current configuration.\n\n"
149
150                         "start tx_first\n"
151                         "    Start packet forwarding with current config"
152                         " after sending one burst of packets.\n\n"
153
154                         "stop\n"
155                         "    Stop packet forwarding, and display accumulated"
156                         " statistics.\n\n"
157
158                         "quit\n"
159                         "    Quit to prompt.\n\n"
160                 );
161         }
162
163         if (show_all || !strcmp(res->section, "display")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Display:\n"
169                         "--------\n\n"
170
171                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
172                         "    Display information for port_id, or all.\n\n"
173
174                         "show port X rss reta (size) (mask0,mask1,...)\n"
175                         "    Display the rss redirection table entry indicated"
176                         " by masks on port X. size is used to indicate the"
177                         " hardware supported reta size\n\n"
178
179                         "show port (port_id) rss-hash [key]\n"
180                         "    Display the RSS hash functions and RSS hash key of port\n\n"
181
182                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
183                         "    Clear information for port_id, or all.\n\n"
184
185                         "show (rxq|txq) info (port_id) (queue_id)\n"
186                         "    Display information for configured RX/TX queue.\n\n"
187
188                         "show config (rxtx|cores|fwd|txpkts)\n"
189                         "    Display the given configuration.\n\n"
190
191                         "read rxd (port_id) (queue_id) (rxd_id)\n"
192                         "    Display an RX descriptor of a port RX queue.\n\n"
193
194                         "read txd (port_id) (queue_id) (txd_id)\n"
195                         "    Display a TX descriptor of a port TX queue.\n\n"
196
197                         "ddp get list (port_id)\n"
198                         "    Get ddp profile info list\n\n"
199
200                         "ddp get info (profile_path)\n"
201                         "    Get ddp profile information.\n\n"
202
203                         "show vf stats (port_id) (vf_id)\n"
204                         "    Display a VF's statistics.\n\n"
205
206                         "clear vf stats (port_id) (vf_id)\n"
207                         "    Reset a VF's statistics.\n\n"
208
209                         "show port (port_id) pctype mapping\n"
210                         "    Get flow ptype to pctype mapping on a port\n\n"
211
212                         "show port meter stats (port_id) (meter_id) (clear)\n"
213                         "    Get meter stats on a port\n\n"
214
215                         "show fwd stats all\n"
216                         "    Display statistics for all fwd engines.\n\n"
217
218                         "clear fwd stats all\n"
219                         "    Clear statistics for all fwd engines.\n\n"
220
221                         "show port (port_id) rx_offload capabilities\n"
222                         "    List all per queue and per port Rx offloading"
223                         " capabilities of a port\n\n"
224
225                         "show port (port_id) rx_offload configuration\n"
226                         "    List port level and all queue level"
227                         " Rx offloading configuration\n\n"
228
229                         "show port (port_id) tx_offload capabilities\n"
230                         "    List all per queue and per port"
231                         " Tx offloading capabilities of a port\n\n"
232
233                         "show port (port_id) tx_offload configuration\n"
234                         "    List port level and all queue level"
235                         " Tx offloading configuration\n\n"
236
237                         "show port (port_id) tx_metadata\n"
238                         "    Show Tx metadata value set"
239                         " for a specific port\n\n"
240
241                         "show device info (<identifier>|all)"
242                         "       Show general information about devices probed.\n\n"
243                 );
244         }
245
246         if (show_all || !strcmp(res->section, "config")) {
247                 cmdline_printf(
248                         cl,
249                         "\n"
250                         "Configuration:\n"
251                         "--------------\n"
252                         "Configuration changes only become active when"
253                         " forwarding is started/restarted.\n\n"
254
255                         "set default\n"
256                         "    Reset forwarding to the default configuration.\n\n"
257
258                         "set verbose (level)\n"
259                         "    Set the debug verbosity level X.\n\n"
260
261                         "set log global|(type) (level)\n"
262                         "    Set the log level.\n\n"
263
264                         "set nbport (num)\n"
265                         "    Set number of ports.\n\n"
266
267                         "set nbcore (num)\n"
268                         "    Set number of cores.\n\n"
269
270                         "set coremask (mask)\n"
271                         "    Set the forwarding cores hexadecimal mask.\n\n"
272
273                         "set portmask (mask)\n"
274                         "    Set the forwarding ports hexadecimal mask.\n\n"
275
276                         "set burst (num)\n"
277                         "    Set number of packets per burst.\n\n"
278
279                         "set burst tx delay (microseconds) retry (num)\n"
280                         "    Set the transmit delay time and number of retries,"
281                         " effective when retry is enabled.\n\n"
282
283                         "set txpkts (x[,y]*)\n"
284                         "    Set the length of each segment of TXONLY"
285                         " and optionally CSUM packets.\n\n"
286
287                         "set txsplit (off|on|rand)\n"
288                         "    Set the split policy for the TX packets."
289                         " Right now only applicable for CSUM and TXONLY"
290                         " modes\n\n"
291
292                         "set corelist (x[,y]*)\n"
293                         "    Set the list of forwarding cores.\n\n"
294
295                         "set portlist (x[,y]*)\n"
296                         "    Set the list of forwarding ports.\n\n"
297
298                         "set port setup on (iterator|event)\n"
299                         "    Select how attached port is retrieved for setup.\n\n"
300
301                         "set tx loopback (port_id) (on|off)\n"
302                         "    Enable or disable tx loopback.\n\n"
303
304                         "set all queues drop (port_id) (on|off)\n"
305                         "    Set drop enable bit for all queues.\n\n"
306
307                         "set vf split drop (port_id) (vf_id) (on|off)\n"
308                         "    Set split drop enable bit for a VF from the PF.\n\n"
309
310                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
311                         "    Set MAC antispoof for a VF from the PF.\n\n"
312
313                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
314                         "    Enable MACsec offload.\n\n"
315
316                         "set macsec offload (port_id) off\n"
317                         "    Disable MACsec offload.\n\n"
318
319                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
320                         "    Configure MACsec secure connection (SC).\n\n"
321
322                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
323                         "    Configure MACsec secure association (SA).\n\n"
324
325                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
326                         "    Set VF broadcast for a VF from the PF.\n\n"
327
328                         "vlan set strip (on|off) (port_id)\n"
329                         "    Set the VLAN strip on a port.\n\n"
330
331                         "vlan set stripq (on|off) (port_id,queue_id)\n"
332                         "    Set the VLAN strip for a queue on a port.\n\n"
333
334                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
335                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
336
337                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
338                         "    Set VLAN insert for a VF from the PF.\n\n"
339
340                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
341                         "    Set VLAN antispoof for a VF from the PF.\n\n"
342
343                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
344                         "    Set VLAN tag for a VF from the PF.\n\n"
345
346                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
347                         "    Set a VF's max bandwidth(Mbps).\n\n"
348
349                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
350                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
351
352                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
353                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
354
355                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
356                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
357
358                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
359                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
360
361                         "vlan set filter (on|off) (port_id)\n"
362                         "    Set the VLAN filter on a port.\n\n"
363
364                         "vlan set qinq (on|off) (port_id)\n"
365                         "    Set the VLAN QinQ (extended queue in queue)"
366                         " on a port.\n\n"
367
368                         "vlan set (inner|outer) tpid (value) (port_id)\n"
369                         "    Set the VLAN TPID for Packet Filtering on"
370                         " a port\n\n"
371
372                         "rx_vlan add (vlan_id|all) (port_id)\n"
373                         "    Add a vlan_id, or all identifiers, to the set"
374                         " of VLAN identifiers filtered by port_id.\n\n"
375
376                         "rx_vlan rm (vlan_id|all) (port_id)\n"
377                         "    Remove a vlan_id, or all identifiers, from the set"
378                         " of VLAN identifiers filtered by port_id.\n\n"
379
380                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
381                         "    Add a vlan_id, to the set of VLAN identifiers"
382                         "filtered for VF(s) from port_id.\n\n"
383
384                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
385                         "    Remove a vlan_id, to the set of VLAN identifiers"
386                         "filtered for VF(s) from port_id.\n\n"
387
388                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
389                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
390                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
391                         "   add a tunnel filter of a port.\n\n"
392
393                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
394                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
395                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
396                         "   remove a tunnel filter of a port.\n\n"
397
398                         "rx_vxlan_port add (udp_port) (port_id)\n"
399                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
400
401                         "rx_vxlan_port rm (udp_port) (port_id)\n"
402                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
403
404                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
405                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
406                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
407
408                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
409                         "    Set port based TX VLAN insertion.\n\n"
410
411                         "tx_vlan reset (port_id)\n"
412                         "    Disable hardware insertion of a VLAN header in"
413                         " packets sent on a port.\n\n"
414
415                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
416                         "    Select hardware or software calculation of the"
417                         " checksum when transmitting a packet using the"
418                         " csum forward engine.\n"
419                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
420                         "    outer-ip concerns the outer IP layer in"
421                         "    outer-udp concerns the outer UDP layer in"
422                         " case the packet is recognized as a tunnel packet by"
423                         " the forward engine (vxlan, gre and ipip are supported)\n"
424                         "    Please check the NIC datasheet for HW limits.\n\n"
425
426                         "csum parse-tunnel (on|off) (tx_port_id)\n"
427                         "    If disabled, treat tunnel packets as non-tunneled"
428                         " packets (treat inner headers as payload). The port\n"
429                         "    argument is the port used for TX in csum forward"
430                         " engine.\n\n"
431
432                         "csum show (port_id)\n"
433                         "    Display tx checksum offload configuration\n\n"
434
435                         "tso set (segsize) (portid)\n"
436                         "    Enable TCP Segmentation Offload in csum forward"
437                         " engine.\n"
438                         "    Please check the NIC datasheet for HW limits.\n\n"
439
440                         "tso show (portid)"
441                         "    Display the status of TCP Segmentation Offload.\n\n"
442
443                         "set port (port_id) gro on|off\n"
444                         "    Enable or disable Generic Receive Offload in"
445                         " csum forwarding engine.\n\n"
446
447                         "show port (port_id) gro\n"
448                         "    Display GRO configuration.\n\n"
449
450                         "set gro flush (cycles)\n"
451                         "    Set the cycle to flush GROed packets from"
452                         " reassembly tables.\n\n"
453
454                         "set port (port_id) gso (on|off)"
455                         "    Enable or disable Generic Segmentation Offload in"
456                         " csum forwarding engine.\n\n"
457
458                         "set gso segsz (length)\n"
459                         "    Set max packet length for output GSO segments,"
460                         " including packet header and payload.\n\n"
461
462                         "show port (port_id) gso\n"
463                         "    Show GSO configuration.\n\n"
464
465                         "set fwd (%s)\n"
466                         "    Set packet forwarding mode.\n\n"
467
468                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
469                         "    Add a MAC address on port_id.\n\n"
470
471                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
472                         "    Remove a MAC address from port_id.\n\n"
473
474                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Set the default MAC address for port_id.\n\n"
476
477                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
478                         "    Add a MAC address for a VF on the port.\n\n"
479
480                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the MAC address for a VF from the PF.\n\n"
482
483                         "set eth-peer (port_id) (peer_addr)\n"
484                         "    set the peer address for certain port.\n\n"
485
486                         "set port (port_id) uta (mac_address|all) (on|off)\n"
487                         "    Add/Remove a or all unicast hash filter(s)"
488                         "from port X.\n\n"
489
490                         "set promisc (port_id|all) (on|off)\n"
491                         "    Set the promiscuous mode on port_id, or all.\n\n"
492
493                         "set allmulti (port_id|all) (on|off)\n"
494                         "    Set the allmulti mode on port_id, or all.\n\n"
495
496                         "set vf promisc (port_id) (vf_id) (on|off)\n"
497                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
498
499                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
500                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
503                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
504                         " (on|off) autoneg (on|off) (port_id)\n"
505                         "set flow_ctrl rx (on|off) (portid)\n"
506                         "set flow_ctrl tx (on|off) (portid)\n"
507                         "set flow_ctrl high_water (high_water) (portid)\n"
508                         "set flow_ctrl low_water (low_water) (portid)\n"
509                         "set flow_ctrl pause_time (pause_time) (portid)\n"
510                         "set flow_ctrl send_xon (send_xon) (portid)\n"
511                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
512                         "set flow_ctrl autoneg (on|off) (port_id)\n"
513                         "    Set the link flow control parameter on a port.\n\n"
514
515                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
516                         " (low_water) (pause_time) (priority) (port_id)\n"
517                         "    Set the priority flow control parameter on a"
518                         " port.\n\n"
519
520                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
521                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
522                         " queue on port.\n"
523                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
524                         " on port 0 to mapping 5.\n\n"
525
526                         "set xstats-hide-zero on|off\n"
527                         "    Set the option to hide the zero values"
528                         " for xstats display.\n"
529
530                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
531                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
532
533                         "set port (port_id) vf (vf_id) (mac_addr)"
534                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
535                         "   Add/Remove unicast or multicast MAC addr filter"
536                         " for a VF.\n\n"
537
538                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
539                         "|MPE) (on|off)\n"
540                         "    AUPE:accepts untagged VLAN;"
541                         "ROPE:accept unicast hash\n\n"
542                         "    BAM:accepts broadcast packets;"
543                         "MPE:accepts all multicast packets\n\n"
544                         "    Enable/Disable a VF receive mode of a port\n\n"
545
546                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
547                         "    Set rate limit for a queue of a port\n\n"
548
549                         "set port (port_id) vf (vf_id) rate (rate_num) "
550                         "queue_mask (queue_mask_value)\n"
551                         "    Set rate limit for queues in VF of a port\n\n"
552
553                         "set port (port_id) mirror-rule (rule_id)"
554                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
555                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
556                         "   Set pool or vlan type mirror rule on a port.\n"
557                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
558                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
559                         " to pool 0.\n\n"
560
561                         "set port (port_id) mirror-rule (rule_id)"
562                         " (uplink-mirror|downlink-mirror) dst-pool"
563                         " (pool_id) (on|off)\n"
564                         "   Set uplink or downlink type mirror rule on a port.\n"
565                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
566                         " 0 on' enable mirror income traffic to pool 0.\n\n"
567
568                         "reset port (port_id) mirror-rule (rule_id)\n"
569                         "   Reset a mirror rule.\n\n"
570
571                         "set flush_rx (on|off)\n"
572                         "   Flush (default) or don't flush RX streams before"
573                         " forwarding. Mainly used with PCAP drivers.\n\n"
574
575                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
576                         "   Set the bypass mode for the lowest port on bypass enabled"
577                         " NIC.\n\n"
578
579                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
580                         "mode (normal|bypass|isolate) (port_id)\n"
581                         "   Set the event required to initiate specified bypass mode for"
582                         " the lowest port on a bypass enabled NIC where:\n"
583                         "       timeout   = enable bypass after watchdog timeout.\n"
584                         "       os_on     = enable bypass when OS/board is powered on.\n"
585                         "       os_off    = enable bypass when OS/board is powered off.\n"
586                         "       power_on  = enable bypass when power supply is turned on.\n"
587                         "       power_off = enable bypass when power supply is turned off."
588                         "\n\n"
589
590                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
591                         "   Set the bypass watchdog timeout to 'n' seconds"
592                         " where 0 = instant.\n\n"
593
594                         "show bypass config (port_id)\n"
595                         "   Show the bypass configuration for a bypass enabled NIC"
596                         " using the lowest port on the NIC.\n\n"
597
598 #ifdef RTE_LIBRTE_PMD_BOND
599                         "create bonded device (mode) (socket)\n"
600                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
601
602                         "add bonding slave (slave_id) (port_id)\n"
603                         "       Add a slave device to a bonded device.\n\n"
604
605                         "remove bonding slave (slave_id) (port_id)\n"
606                         "       Remove a slave device from a bonded device.\n\n"
607
608                         "set bonding mode (value) (port_id)\n"
609                         "       Set the bonding mode on a bonded device.\n\n"
610
611                         "set bonding primary (slave_id) (port_id)\n"
612                         "       Set the primary slave for a bonded device.\n\n"
613
614                         "show bonding config (port_id)\n"
615                         "       Show the bonding config for port_id.\n\n"
616
617                         "set bonding mac_addr (port_id) (address)\n"
618                         "       Set the MAC address of a bonded device.\n\n"
619
620                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
621                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
622
623                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
624                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
625
626                         "set bonding mon_period (port_id) (value)\n"
627                         "       Set the bonding link status monitoring polling period in ms.\n\n"
628
629                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
630                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
631
632 #endif
633                         "set link-up port (port_id)\n"
634                         "       Set link up for a port.\n\n"
635
636                         "set link-down port (port_id)\n"
637                         "       Set link down for a port.\n\n"
638
639                         "E-tag set insertion on port-tag-id (value)"
640                         " port (port_id) vf (vf_id)\n"
641                         "    Enable E-tag insertion for a VF on a port\n\n"
642
643                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
644                         "    Disable E-tag insertion for a VF on a port\n\n"
645
646                         "E-tag set stripping (on|off) port (port_id)\n"
647                         "    Enable/disable E-tag stripping on a port\n\n"
648
649                         "E-tag set forwarding (on|off) port (port_id)\n"
650                         "    Enable/disable E-tag based forwarding"
651                         " on a port\n\n"
652
653                         "E-tag set filter add e-tag-id (value) dst-pool"
654                         " (pool_id) port (port_id)\n"
655                         "    Add an E-tag forwarding filter on a port\n\n"
656
657                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
658                         "    Delete an E-tag forwarding filter on a port\n\n"
659
660                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
661                         "    Load a profile package on a port\n\n"
662
663                         "ddp del (port_id) (backup_profile_path)\n"
664                         "    Delete a profile package from a port\n\n"
665
666                         "ptype mapping get (port_id) (valid_only)\n"
667                         "    Get ptype mapping on a port\n\n"
668
669                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
670                         "    Replace target with the pkt_type in ptype mapping\n\n"
671
672                         "ptype mapping reset (port_id)\n"
673                         "    Reset ptype mapping on a port\n\n"
674
675                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
676                         "    Update a ptype mapping item on a port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "queue_start_index (value) queue_num (value)\n"
680                         "    Set a queue region on a port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "flowtype (value)\n"
684                         "    Set a flowtype region index on a port\n\n"
685
686                         "set port (port_id) queue-region UP (value) region_id (value)\n"
687                         "    Set the mapping of User Priority to "
688                         "queue region on a port\n\n"
689
690                         "set port (port_id) queue-region flush (on|off)\n"
691                         "    flush all queue region related configuration\n\n"
692
693                         "show port meter cap (port_id)\n"
694                         "    Show port meter capability information\n\n"
695
696                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
697                         "    meter profile add - srtcm rfc 2697\n\n"
698
699                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
700                         "    meter profile add - trtcm rfc 2698\n\n"
701
702                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
703                         "    meter profile add - trtcm rfc 4115\n\n"
704
705                         "del port meter profile (port_id) (profile_id)\n"
706                         "    meter profile delete\n\n"
707
708                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
709                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
710                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
711                         "(dscp_tbl_entry63)]\n"
712                         "    meter create\n\n"
713
714                         "enable port meter (port_id) (mtr_id)\n"
715                         "    meter enable\n\n"
716
717                         "disable port meter (port_id) (mtr_id)\n"
718                         "    meter disable\n\n"
719
720                         "del port meter (port_id) (mtr_id)\n"
721                         "    meter delete\n\n"
722
723                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
724                         "    meter update meter profile\n\n"
725
726                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
727                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
728                         "    update meter dscp table entries\n\n"
729
730                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
731                         "(action0) [(action1) (action2)]\n"
732                         "    meter update policer action\n\n"
733
734                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
735                         "    meter update stats\n\n"
736
737                         "show port (port_id) queue-region\n"
738                         "    show all queue region related configuration info\n\n"
739
740                         , list_pkt_forwarding_modes()
741                 );
742         }
743
744         if (show_all || !strcmp(res->section, "ports")) {
745
746                 cmdline_printf(
747                         cl,
748                         "\n"
749                         "Port Operations:\n"
750                         "----------------\n\n"
751
752                         "port start (port_id|all)\n"
753                         "    Start all ports or port_id.\n\n"
754
755                         "port stop (port_id|all)\n"
756                         "    Stop all ports or port_id.\n\n"
757
758                         "port close (port_id|all)\n"
759                         "    Close all ports or port_id.\n\n"
760
761                         "port attach (ident)\n"
762                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
763
764                         "port detach (port_id)\n"
765                         "    Detach physical or virtual dev by port_id\n\n"
766
767                         "port config (port_id|all)"
768                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
769                         " duplex (half|full|auto)\n"
770                         "    Set speed and duplex for all ports or port_id\n\n"
771
772                         "port config (port_id|all) loopback (mode)\n"
773                         "    Set loopback mode for all ports or port_id\n\n"
774
775                         "port config all (rxq|txq|rxd|txd) (value)\n"
776                         "    Set number for rxq/txq/rxd/txd.\n\n"
777
778                         "port config all max-pkt-len (value)\n"
779                         "    Set the max packet length.\n\n"
780
781                         "port config all drop-en (on|off)\n"
782                         "    Enable or disable packet drop on all RX queues of all ports when no "
783                         "receive buffers available.\n\n"
784
785                         "port config all rss (all|default|ip|tcp|udp|sctp|"
786                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
787                         "    Set the RSS mode.\n\n"
788
789                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
790                         "    Set the RSS redirection table.\n\n"
791
792                         "port config (port_id) dcb vt (on|off) (traffic_class)"
793                         " pfc (on|off)\n"
794                         "    Set the DCB mode.\n\n"
795
796                         "port config all burst (value)\n"
797                         "    Set the number of packets per burst.\n\n"
798
799                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
800                         " (value)\n"
801                         "    Set the ring prefetch/host/writeback threshold"
802                         " for tx/rx queue.\n\n"
803
804                         "port config all (txfreet|txrst|rxfreet) (value)\n"
805                         "    Set free threshold for rx/tx, or set"
806                         " tx rs bit threshold.\n\n"
807                         "port config mtu X value\n"
808                         "    Set the MTU of port X to a given value\n\n"
809
810                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
811                         "    Set a rx/tx queue's ring size configuration, the new"
812                         " value will take effect after command that (re-)start the port"
813                         " or command that setup the specific queue\n\n"
814
815                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
816                         "    Start/stop a rx/tx queue of port X. Only take effect"
817                         " when port X is started\n\n"
818
819                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
820                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
821                         " take effect when port X is stopped.\n\n"
822
823                         "port (port_id) (rxq|txq) (queue_id) setup\n"
824                         "    Setup a rx/tx queue of port X.\n\n"
825
826                         "port config (port_id|all) l2-tunnel E-tag ether-type"
827                         " (value)\n"
828                         "    Set the value of E-tag ether-type.\n\n"
829
830                         "port config (port_id|all) l2-tunnel E-tag"
831                         " (enable|disable)\n"
832                         "    Enable/disable the E-tag support.\n\n"
833
834                         "port config (port_id) pctype mapping reset\n"
835                         "    Reset flow type to pctype mapping on a port\n\n"
836
837                         "port config (port_id) pctype mapping update"
838                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
839                         "    Update a flow type to pctype mapping item on a port\n\n"
840
841                         "port config (port_id) pctype (pctype_id) hash_inset|"
842                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
843                         " (field_idx)\n"
844                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
845
846                         "port config (port_id) pctype (pctype_id) hash_inset|"
847                         "fdir_inset|fdir_flx_inset clear all"
848                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
849
850                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
851                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
852
853                         "port config <port_id> rx_offload vlan_strip|"
854                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
855                         "outer_ipv4_cksum|macsec_strip|header_split|"
856                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
857                         "scatter|timestamp|security|keep_crc on|off\n"
858                         "     Enable or disable a per port Rx offloading"
859                         " on all Rx queues of a port\n\n"
860
861                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
862                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
863                         "outer_ipv4_cksum|macsec_strip|header_split|"
864                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
865                         "scatter|timestamp|security|keep_crc on|off\n"
866                         "    Enable or disable a per queue Rx offloading"
867                         " only on a specific Rx queue\n\n"
868
869                         "port config (port_id) tx_offload vlan_insert|"
870                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
871                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
872                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
873                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
874                         "security|match_metadata on|off\n"
875                         "    Enable or disable a per port Tx offloading"
876                         " on all Tx queues of a port\n\n"
877
878                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
879                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
880                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
881                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
882                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
883                         " on|off\n"
884                         "    Enable or disable a per queue Tx offloading"
885                         " only on a specific Tx queue\n\n"
886
887                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
888                         "    Load an eBPF program as a callback"
889                         " for particular RX/TX queue\n\n"
890
891                         "bpf-unload rx|tx (port) (queue)\n"
892                         "    Unload previously loaded eBPF program"
893                         " for particular RX/TX queue\n\n"
894
895                         "port config (port_id) tx_metadata (value)\n"
896                         "    Set Tx metadata value per port. Testpmd will add this value"
897                         " to any Tx packet sent from this port\n\n"
898                 );
899         }
900
901         if (show_all || !strcmp(res->section, "registers")) {
902
903                 cmdline_printf(
904                         cl,
905                         "\n"
906                         "Registers:\n"
907                         "----------\n\n"
908
909                         "read reg (port_id) (address)\n"
910                         "    Display value of a port register.\n\n"
911
912                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
913                         "    Display a port register bit field.\n\n"
914
915                         "read regbit (port_id) (address) (bit_x)\n"
916                         "    Display a single port register bit.\n\n"
917
918                         "write reg (port_id) (address) (value)\n"
919                         "    Set value of a port register.\n\n"
920
921                         "write regfield (port_id) (address) (bit_x) (bit_y)"
922                         " (value)\n"
923                         "    Set bit field of a port register.\n\n"
924
925                         "write regbit (port_id) (address) (bit_x) (value)\n"
926                         "    Set single bit value of a port register.\n\n"
927                 );
928         }
929         if (show_all || !strcmp(res->section, "filters")) {
930
931                 cmdline_printf(
932                         cl,
933                         "\n"
934                         "filters:\n"
935                         "--------\n\n"
936
937                         "ethertype_filter (port_id) (add|del)"
938                         " (mac_addr|mac_ignr) (mac_address) ethertype"
939                         " (ether_type) (drop|fwd) queue (queue_id)\n"
940                         "    Add/Del an ethertype filter.\n\n"
941
942                         "2tuple_filter (port_id) (add|del)"
943                         " dst_port (dst_port_value) protocol (protocol_value)"
944                         " mask (mask_value) tcp_flags (tcp_flags_value)"
945                         " priority (prio_value) queue (queue_id)\n"
946                         "    Add/Del a 2tuple filter.\n\n"
947
948                         "5tuple_filter (port_id) (add|del)"
949                         " dst_ip (dst_address) src_ip (src_address)"
950                         " dst_port (dst_port_value) src_port (src_port_value)"
951                         " protocol (protocol_value)"
952                         " mask (mask_value) tcp_flags (tcp_flags_value)"
953                         " priority (prio_value) queue (queue_id)\n"
954                         "    Add/Del a 5tuple filter.\n\n"
955
956                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
957                         "    Add/Del syn filter.\n\n"
958
959                         "flex_filter (port_id) (add|del) len (len_value)"
960                         " bytes (bytes_value) mask (mask_value)"
961                         " priority (prio_value) queue (queue_id)\n"
962                         "    Add/Del a flex filter.\n\n"
963
964                         "flow_director_filter (port_id) mode IP (add|del|update)"
965                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
966                         " src (src_ip_address) dst (dst_ip_address)"
967                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
968                         " vlan (vlan_value) flexbytes (flexbytes_value)"
969                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
970                         " fd_id (fd_id_value)\n"
971                         "    Add/Del an IP type flow director filter.\n\n"
972
973                         "flow_director_filter (port_id) mode IP (add|del|update)"
974                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
975                         " src (src_ip_address) (src_port)"
976                         " dst (dst_ip_address) (dst_port)"
977                         " tos (tos_value) ttl (ttl_value)"
978                         " vlan (vlan_value) flexbytes (flexbytes_value)"
979                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
980                         " fd_id (fd_id_value)\n"
981                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
982
983                         "flow_director_filter (port_id) mode IP (add|del|update)"
984                         " flow (ipv4-sctp|ipv6-sctp)"
985                         " src (src_ip_address) (src_port)"
986                         " dst (dst_ip_address) (dst_port)"
987                         " tag (verification_tag) "
988                         " tos (tos_value) ttl (ttl_value)"
989                         " vlan (vlan_value)"
990                         " flexbytes (flexbytes_value) (drop|fwd)"
991                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
992                         "    Add/Del a SCTP type flow director filter.\n\n"
993
994                         "flow_director_filter (port_id) mode IP (add|del|update)"
995                         " flow l2_payload ether (ethertype)"
996                         " flexbytes (flexbytes_value) (drop|fwd)"
997                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
998                         "    Add/Del a l2 payload type flow director filter.\n\n"
999
1000                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1001                         " mac (mac_address) vlan (vlan_value)"
1002                         " flexbytes (flexbytes_value) (drop|fwd)"
1003                         " queue (queue_id) fd_id (fd_id_value)\n"
1004                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1007                         " mac (mac_address) vlan (vlan_value)"
1008                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1009                         " flexbytes (flexbytes_value) (drop|fwd)"
1010                         " queue (queue_id) fd_id (fd_id_value)\n"
1011                         "    Add/Del a Tunnel flow director filter.\n\n"
1012
1013                         "flow_director_filter (port_id) mode raw (add|del|update)"
1014                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1015                         " fd_id (fd_id_value) packet (packet file name)\n"
1016                         "    Add/Del a raw type flow director filter.\n\n"
1017
1018                         "flush_flow_director (port_id)\n"
1019                         "    Flush all flow director entries of a device.\n\n"
1020
1021                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1022                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1023                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1024                         "    Set flow director IP mask.\n\n"
1025
1026                         "flow_director_mask (port_id) mode MAC-VLAN"
1027                         " vlan (vlan_value)\n"
1028                         "    Set flow director MAC-VLAN mask.\n\n"
1029
1030                         "flow_director_mask (port_id) mode Tunnel"
1031                         " vlan (vlan_value) mac (mac_value)"
1032                         " tunnel-type (tunnel_type_value)"
1033                         " tunnel-id (tunnel_id_value)\n"
1034                         "    Set flow director Tunnel mask.\n\n"
1035
1036                         "flow_director_flex_mask (port_id)"
1037                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1038                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1039                         " (mask)\n"
1040                         "    Configure mask of flex payload.\n\n"
1041
1042                         "flow_director_flex_payload (port_id)"
1043                         " (raw|l2|l3|l4) (config)\n"
1044                         "    Configure flex payload selection.\n\n"
1045
1046                         "get_sym_hash_ena_per_port (port_id)\n"
1047                         "    get symmetric hash enable configuration per port.\n\n"
1048
1049                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1050                         "    set symmetric hash enable configuration per port"
1051                         " to enable or disable.\n\n"
1052
1053                         "get_hash_global_config (port_id)\n"
1054                         "    Get the global configurations of hash filters.\n\n"
1055
1056                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1057                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1058                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1059                         " (enable|disable)\n"
1060                         "    Set the global configurations of hash filters.\n\n"
1061
1062                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1063                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1064                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1065                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1066                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1067                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1068                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1069                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1070                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1071                         "fld-8th|none) (select|add)\n"
1072                         "    Set the input set for hash.\n\n"
1073
1074                         "set_fdir_input_set (port_id) "
1075                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1076                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1077                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1078                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1079                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1080                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1081                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1082                         " (select|add)\n"
1083                         "    Set the input set for FDir.\n\n"
1084
1085                         "flow validate {port_id}"
1086                         " [group {group_id}] [priority {level}]"
1087                         " [ingress] [egress]"
1088                         " pattern {item} [/ {item} [...]] / end"
1089                         " actions {action} [/ {action} [...]] / end\n"
1090                         "    Check whether a flow rule can be created.\n\n"
1091
1092                         "flow create {port_id}"
1093                         " [group {group_id}] [priority {level}]"
1094                         " [ingress] [egress]"
1095                         " pattern {item} [/ {item} [...]] / end"
1096                         " actions {action} [/ {action} [...]] / end\n"
1097                         "    Create a flow rule.\n\n"
1098
1099                         "flow destroy {port_id} rule {rule_id} [...]\n"
1100                         "    Destroy specific flow rules.\n\n"
1101
1102                         "flow flush {port_id}\n"
1103                         "    Destroy all flow rules.\n\n"
1104
1105                         "flow query {port_id} {rule_id} {action}\n"
1106                         "    Query an existing flow rule.\n\n"
1107
1108                         "flow list {port_id} [group {group_id}] [...]\n"
1109                         "    List existing flow rules sorted by priority,"
1110                         " filtered by group identifiers.\n\n"
1111
1112                         "flow isolate {port_id} {boolean}\n"
1113                         "    Restrict ingress traffic to the defined"
1114                         " flow rules\n\n"
1115
1116                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1117                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1118                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1119                         "       Configure the VXLAN encapsulation for flows.\n\n"
1120
1121                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1122                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1123                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1124                         " eth-dst (eth-dst)\n"
1125                         "       Configure the VXLAN encapsulation for flows.\n\n"
1126
1127                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1128                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1129                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1130                         " eth-dst (eth-dst)\n"
1131                         "       Configure the VXLAN encapsulation for flows.\n\n"
1132
1133                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1134                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1135                         " (eth-dst)\n"
1136                         "       Configure the NVGRE encapsulation for flows.\n\n"
1137
1138                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1139                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1140                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1141                         "       Configure the NVGRE encapsulation for flows.\n\n"
1142
1143                         "set raw_encap {flow items}\n"
1144                         "       Configure the encapsulation with raw data.\n\n"
1145
1146                         "set raw_decap {flow items}\n"
1147                         "       Configure the decapsulation with raw data.\n\n"
1148
1149                 );
1150         }
1151
1152         if (show_all || !strcmp(res->section, "traffic_management")) {
1153                 cmdline_printf(
1154                         cl,
1155                         "\n"
1156                         "Traffic Management:\n"
1157                         "--------------\n"
1158                         "show port tm cap (port_id)\n"
1159                         "       Display the port TM capability.\n\n"
1160
1161                         "show port tm level cap (port_id) (level_id)\n"
1162                         "       Display the port TM hierarchical level capability.\n\n"
1163
1164                         "show port tm node cap (port_id) (node_id)\n"
1165                         "       Display the port TM node capability.\n\n"
1166
1167                         "show port tm node type (port_id) (node_id)\n"
1168                         "       Display the port TM node type.\n\n"
1169
1170                         "show port tm node stats (port_id) (node_id) (clear)\n"
1171                         "       Display the port TM node stats.\n\n"
1172
1173 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1174                         "set port tm hierarchy default (port_id)\n"
1175                         "       Set default traffic Management hierarchy on a port\n\n"
1176 #endif
1177
1178                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1179                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1180                         " (packet_length_adjust)\n"
1181                         "       Add port tm node private shaper profile.\n\n"
1182
1183                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1184                         "       Delete port tm node private shaper profile.\n\n"
1185
1186                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1187                         " (shaper_profile_id)\n"
1188                         "       Add/update port tm node shared shaper.\n\n"
1189
1190                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1191                         "       Delete port tm node shared shaper.\n\n"
1192
1193                         "set port tm node shaper profile (port_id) (node_id)"
1194                         " (shaper_profile_id)\n"
1195                         "       Set port tm node shaper profile.\n\n"
1196
1197                         "add port tm node wred profile (port_id) (wred_profile_id)"
1198                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1199                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1200                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1201                         "       Add port tm node wred profile.\n\n"
1202
1203                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1204                         "       Delete port tm node wred profile.\n\n"
1205
1206                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1207                         " (priority) (weight) (level_id) (shaper_profile_id)"
1208                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1209                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1210                         "       Add port tm nonleaf node.\n\n"
1211
1212                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1213                         " (priority) (weight) (level_id) (shaper_profile_id)"
1214                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1215                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1216                         "       Add port tm leaf node.\n\n"
1217
1218                         "del port tm node (port_id) (node_id)\n"
1219                         "       Delete port tm node.\n\n"
1220
1221                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1222                         " (priority) (weight)\n"
1223                         "       Set port tm node parent.\n\n"
1224
1225                         "suspend port tm node (port_id) (node_id)"
1226                         "       Suspend tm node.\n\n"
1227
1228                         "resume port tm node (port_id) (node_id)"
1229                         "       Resume tm node.\n\n"
1230
1231                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1232                         "       Commit tm hierarchy.\n\n"
1233
1234                         "set port tm mark ip_ecn (port) (green) (yellow)"
1235                         " (red)\n"
1236                         "    Enables/Disables the traffic management marking"
1237                         " for IP ECN (Explicit Congestion Notification)"
1238                         " packets on a given port\n\n"
1239
1240                         "set port tm mark ip_dscp (port) (green) (yellow)"
1241                         " (red)\n"
1242                         "    Enables/Disables the traffic management marking"
1243                         " on the port for IP dscp packets\n\n"
1244
1245                         "set port tm mark vlan_dei (port) (green) (yellow)"
1246                         " (red)\n"
1247                         "    Enables/Disables the traffic management marking"
1248                         " on the port for VLAN packets with DEI enabled\n\n"
1249                 );
1250         }
1251
1252         if (show_all || !strcmp(res->section, "devices")) {
1253                 cmdline_printf(
1254                         cl,
1255                         "\n"
1256                         "Device Operations:\n"
1257                         "--------------\n"
1258                         "device detach (identifier)\n"
1259                         "       Detach device by identifier.\n\n"
1260                 );
1261         }
1262
1263 }
1264
1265 cmdline_parse_token_string_t cmd_help_long_help =
1266         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1267
1268 cmdline_parse_token_string_t cmd_help_long_section =
1269         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1270                         "all#control#display#config#"
1271                         "ports#registers#filters#traffic_management#devices");
1272
1273 cmdline_parse_inst_t cmd_help_long = {
1274         .f = cmd_help_long_parsed,
1275         .data = NULL,
1276         .help_str = "help all|control|display|config|ports|register|"
1277                 "filters|traffic_management|devices: "
1278                 "Show help",
1279         .tokens = {
1280                 (void *)&cmd_help_long_help,
1281                 (void *)&cmd_help_long_section,
1282                 NULL,
1283         },
1284 };
1285
1286
1287 /* *** start/stop/close all ports *** */
1288 struct cmd_operate_port_result {
1289         cmdline_fixed_string_t keyword;
1290         cmdline_fixed_string_t name;
1291         cmdline_fixed_string_t value;
1292 };
1293
1294 static void cmd_operate_port_parsed(void *parsed_result,
1295                                 __attribute__((unused)) struct cmdline *cl,
1296                                 __attribute__((unused)) void *data)
1297 {
1298         struct cmd_operate_port_result *res = parsed_result;
1299
1300         if (!strcmp(res->name, "start"))
1301                 start_port(RTE_PORT_ALL);
1302         else if (!strcmp(res->name, "stop"))
1303                 stop_port(RTE_PORT_ALL);
1304         else if (!strcmp(res->name, "close"))
1305                 close_port(RTE_PORT_ALL);
1306         else if (!strcmp(res->name, "reset"))
1307                 reset_port(RTE_PORT_ALL);
1308         else
1309                 printf("Unknown parameter\n");
1310 }
1311
1312 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1313         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1314                                                                 "port");
1315 cmdline_parse_token_string_t cmd_operate_port_all_port =
1316         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1317                                                 "start#stop#close#reset");
1318 cmdline_parse_token_string_t cmd_operate_port_all_all =
1319         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1320
1321 cmdline_parse_inst_t cmd_operate_port = {
1322         .f = cmd_operate_port_parsed,
1323         .data = NULL,
1324         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1325         .tokens = {
1326                 (void *)&cmd_operate_port_all_cmd,
1327                 (void *)&cmd_operate_port_all_port,
1328                 (void *)&cmd_operate_port_all_all,
1329                 NULL,
1330         },
1331 };
1332
1333 /* *** start/stop/close specific port *** */
1334 struct cmd_operate_specific_port_result {
1335         cmdline_fixed_string_t keyword;
1336         cmdline_fixed_string_t name;
1337         uint8_t value;
1338 };
1339
1340 static void cmd_operate_specific_port_parsed(void *parsed_result,
1341                         __attribute__((unused)) struct cmdline *cl,
1342                                 __attribute__((unused)) void *data)
1343 {
1344         struct cmd_operate_specific_port_result *res = parsed_result;
1345
1346         if (!strcmp(res->name, "start"))
1347                 start_port(res->value);
1348         else if (!strcmp(res->name, "stop"))
1349                 stop_port(res->value);
1350         else if (!strcmp(res->name, "close"))
1351                 close_port(res->value);
1352         else if (!strcmp(res->name, "reset"))
1353                 reset_port(res->value);
1354         else
1355                 printf("Unknown parameter\n");
1356 }
1357
1358 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1359         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1360                                                         keyword, "port");
1361 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1362         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1363                                                 name, "start#stop#close#reset");
1364 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1365         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1366                                                         value, UINT8);
1367
1368 cmdline_parse_inst_t cmd_operate_specific_port = {
1369         .f = cmd_operate_specific_port_parsed,
1370         .data = NULL,
1371         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1372         .tokens = {
1373                 (void *)&cmd_operate_specific_port_cmd,
1374                 (void *)&cmd_operate_specific_port_port,
1375                 (void *)&cmd_operate_specific_port_id,
1376                 NULL,
1377         },
1378 };
1379
1380 /* *** enable port setup (after attach) via iterator or event *** */
1381 struct cmd_set_port_setup_on_result {
1382         cmdline_fixed_string_t set;
1383         cmdline_fixed_string_t port;
1384         cmdline_fixed_string_t setup;
1385         cmdline_fixed_string_t on;
1386         cmdline_fixed_string_t mode;
1387 };
1388
1389 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1390                                 __attribute__((unused)) struct cmdline *cl,
1391                                 __attribute__((unused)) void *data)
1392 {
1393         struct cmd_set_port_setup_on_result *res = parsed_result;
1394
1395         if (strcmp(res->mode, "event") == 0)
1396                 setup_on_probe_event = true;
1397         else if (strcmp(res->mode, "iterator") == 0)
1398                 setup_on_probe_event = false;
1399         else
1400                 printf("Unknown mode\n");
1401 }
1402
1403 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1404         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1405                         set, "set");
1406 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1407         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1408                         port, "port");
1409 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1410         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1411                         setup, "setup");
1412 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1413         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1414                         on, "on");
1415 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1416         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1417                         mode, "iterator#event");
1418
1419 cmdline_parse_inst_t cmd_set_port_setup_on = {
1420         .f = cmd_set_port_setup_on_parsed,
1421         .data = NULL,
1422         .help_str = "set port setup on iterator|event",
1423         .tokens = {
1424                 (void *)&cmd_set_port_setup_on_set,
1425                 (void *)&cmd_set_port_setup_on_port,
1426                 (void *)&cmd_set_port_setup_on_setup,
1427                 (void *)&cmd_set_port_setup_on_on,
1428                 (void *)&cmd_set_port_setup_on_mode,
1429                 NULL,
1430         },
1431 };
1432
1433 /* *** attach a specified port *** */
1434 struct cmd_operate_attach_port_result {
1435         cmdline_fixed_string_t port;
1436         cmdline_fixed_string_t keyword;
1437         cmdline_fixed_string_t identifier;
1438 };
1439
1440 static void cmd_operate_attach_port_parsed(void *parsed_result,
1441                                 __attribute__((unused)) struct cmdline *cl,
1442                                 __attribute__((unused)) void *data)
1443 {
1444         struct cmd_operate_attach_port_result *res = parsed_result;
1445
1446         if (!strcmp(res->keyword, "attach"))
1447                 attach_port(res->identifier);
1448         else
1449                 printf("Unknown parameter\n");
1450 }
1451
1452 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1453         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1454                         port, "port");
1455 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1456         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1457                         keyword, "attach");
1458 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1459         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1460                         identifier, NULL);
1461
1462 cmdline_parse_inst_t cmd_operate_attach_port = {
1463         .f = cmd_operate_attach_port_parsed,
1464         .data = NULL,
1465         .help_str = "port attach <identifier>: "
1466                 "(identifier: pci address or virtual dev name)",
1467         .tokens = {
1468                 (void *)&cmd_operate_attach_port_port,
1469                 (void *)&cmd_operate_attach_port_keyword,
1470                 (void *)&cmd_operate_attach_port_identifier,
1471                 NULL,
1472         },
1473 };
1474
1475 /* *** detach a specified port *** */
1476 struct cmd_operate_detach_port_result {
1477         cmdline_fixed_string_t port;
1478         cmdline_fixed_string_t keyword;
1479         portid_t port_id;
1480 };
1481
1482 static void cmd_operate_detach_port_parsed(void *parsed_result,
1483                                 __attribute__((unused)) struct cmdline *cl,
1484                                 __attribute__((unused)) void *data)
1485 {
1486         struct cmd_operate_detach_port_result *res = parsed_result;
1487
1488         if (!strcmp(res->keyword, "detach"))
1489                 detach_port_device(res->port_id);
1490         else
1491                 printf("Unknown parameter\n");
1492 }
1493
1494 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1495         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1496                         port, "port");
1497 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1498         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1499                         keyword, "detach");
1500 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1501         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1502                         port_id, UINT16);
1503
1504 cmdline_parse_inst_t cmd_operate_detach_port = {
1505         .f = cmd_operate_detach_port_parsed,
1506         .data = NULL,
1507         .help_str = "port detach <port_id>",
1508         .tokens = {
1509                 (void *)&cmd_operate_detach_port_port,
1510                 (void *)&cmd_operate_detach_port_keyword,
1511                 (void *)&cmd_operate_detach_port_port_id,
1512                 NULL,
1513         },
1514 };
1515
1516 /* *** detach device by identifier *** */
1517 struct cmd_operate_detach_device_result {
1518         cmdline_fixed_string_t device;
1519         cmdline_fixed_string_t keyword;
1520         cmdline_fixed_string_t identifier;
1521 };
1522
1523 static void cmd_operate_detach_device_parsed(void *parsed_result,
1524                                 __attribute__((unused)) struct cmdline *cl,
1525                                 __attribute__((unused)) void *data)
1526 {
1527         struct cmd_operate_detach_device_result *res = parsed_result;
1528
1529         if (!strcmp(res->keyword, "detach"))
1530                 detach_device(res->identifier);
1531         else
1532                 printf("Unknown parameter\n");
1533 }
1534
1535 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1536         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1537                         device, "device");
1538 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1539         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1540                         keyword, "detach");
1541 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1542         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1543                         identifier, NULL);
1544
1545 cmdline_parse_inst_t cmd_operate_detach_device = {
1546         .f = cmd_operate_detach_device_parsed,
1547         .data = NULL,
1548         .help_str = "device detach <identifier>:"
1549                 "(identifier: pci address or virtual dev name)",
1550         .tokens = {
1551                 (void *)&cmd_operate_detach_device_device,
1552                 (void *)&cmd_operate_detach_device_keyword,
1553                 (void *)&cmd_operate_detach_device_identifier,
1554                 NULL,
1555         },
1556 };
1557 /* *** configure speed for all ports *** */
1558 struct cmd_config_speed_all {
1559         cmdline_fixed_string_t port;
1560         cmdline_fixed_string_t keyword;
1561         cmdline_fixed_string_t all;
1562         cmdline_fixed_string_t item1;
1563         cmdline_fixed_string_t item2;
1564         cmdline_fixed_string_t value1;
1565         cmdline_fixed_string_t value2;
1566 };
1567
1568 static int
1569 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1570 {
1571
1572         int duplex;
1573
1574         if (!strcmp(duplexstr, "half")) {
1575                 duplex = ETH_LINK_HALF_DUPLEX;
1576         } else if (!strcmp(duplexstr, "full")) {
1577                 duplex = ETH_LINK_FULL_DUPLEX;
1578         } else if (!strcmp(duplexstr, "auto")) {
1579                 duplex = ETH_LINK_FULL_DUPLEX;
1580         } else {
1581                 printf("Unknown duplex parameter\n");
1582                 return -1;
1583         }
1584
1585         if (!strcmp(speedstr, "10")) {
1586                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1587                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1588         } else if (!strcmp(speedstr, "100")) {
1589                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1590                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1591         } else {
1592                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1593                         printf("Invalid speed/duplex parameters\n");
1594                         return -1;
1595                 }
1596                 if (!strcmp(speedstr, "1000")) {
1597                         *speed = ETH_LINK_SPEED_1G;
1598                 } else if (!strcmp(speedstr, "10000")) {
1599                         *speed = ETH_LINK_SPEED_10G;
1600                 } else if (!strcmp(speedstr, "25000")) {
1601                         *speed = ETH_LINK_SPEED_25G;
1602                 } else if (!strcmp(speedstr, "40000")) {
1603                         *speed = ETH_LINK_SPEED_40G;
1604                 } else if (!strcmp(speedstr, "50000")) {
1605                         *speed = ETH_LINK_SPEED_50G;
1606                 } else if (!strcmp(speedstr, "100000")) {
1607                         *speed = ETH_LINK_SPEED_100G;
1608                 } else if (!strcmp(speedstr, "auto")) {
1609                         *speed = ETH_LINK_SPEED_AUTONEG;
1610                 } else {
1611                         printf("Unknown speed parameter\n");
1612                         return -1;
1613                 }
1614         }
1615
1616         return 0;
1617 }
1618
1619 static void
1620 cmd_config_speed_all_parsed(void *parsed_result,
1621                         __attribute__((unused)) struct cmdline *cl,
1622                         __attribute__((unused)) void *data)
1623 {
1624         struct cmd_config_speed_all *res = parsed_result;
1625         uint32_t link_speed;
1626         portid_t pid;
1627
1628         if (!all_ports_stopped()) {
1629                 printf("Please stop all ports first\n");
1630                 return;
1631         }
1632
1633         if (parse_and_check_speed_duplex(res->value1, res->value2,
1634                         &link_speed) < 0)
1635                 return;
1636
1637         RTE_ETH_FOREACH_DEV(pid) {
1638                 ports[pid].dev_conf.link_speeds = link_speed;
1639         }
1640
1641         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1642 }
1643
1644 cmdline_parse_token_string_t cmd_config_speed_all_port =
1645         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1646 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1648                                                         "config");
1649 cmdline_parse_token_string_t cmd_config_speed_all_all =
1650         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1651 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1652         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1653 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1654         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1655                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1656 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1657         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1658 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1660                                                 "half#full#auto");
1661
1662 cmdline_parse_inst_t cmd_config_speed_all = {
1663         .f = cmd_config_speed_all_parsed,
1664         .data = NULL,
1665         .help_str = "port config all speed "
1666                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1667                                                         "half|full|auto",
1668         .tokens = {
1669                 (void *)&cmd_config_speed_all_port,
1670                 (void *)&cmd_config_speed_all_keyword,
1671                 (void *)&cmd_config_speed_all_all,
1672                 (void *)&cmd_config_speed_all_item1,
1673                 (void *)&cmd_config_speed_all_value1,
1674                 (void *)&cmd_config_speed_all_item2,
1675                 (void *)&cmd_config_speed_all_value2,
1676                 NULL,
1677         },
1678 };
1679
1680 /* *** configure speed for specific port *** */
1681 struct cmd_config_speed_specific {
1682         cmdline_fixed_string_t port;
1683         cmdline_fixed_string_t keyword;
1684         portid_t id;
1685         cmdline_fixed_string_t item1;
1686         cmdline_fixed_string_t item2;
1687         cmdline_fixed_string_t value1;
1688         cmdline_fixed_string_t value2;
1689 };
1690
1691 static void
1692 cmd_config_speed_specific_parsed(void *parsed_result,
1693                                 __attribute__((unused)) struct cmdline *cl,
1694                                 __attribute__((unused)) void *data)
1695 {
1696         struct cmd_config_speed_specific *res = parsed_result;
1697         uint32_t link_speed;
1698
1699         if (!all_ports_stopped()) {
1700                 printf("Please stop all ports first\n");
1701                 return;
1702         }
1703
1704         if (port_id_is_invalid(res->id, ENABLED_WARN))
1705                 return;
1706
1707         if (parse_and_check_speed_duplex(res->value1, res->value2,
1708                         &link_speed) < 0)
1709                 return;
1710
1711         ports[res->id].dev_conf.link_speeds = link_speed;
1712
1713         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1714 }
1715
1716
1717 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1719                                                                 "port");
1720 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1722                                                                 "config");
1723 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1724         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1725 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1726         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1727                                                                 "speed");
1728 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1729         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1730                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1731 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1733                                                                 "duplex");
1734 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1735         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1736                                                         "half#full#auto");
1737
1738 cmdline_parse_inst_t cmd_config_speed_specific = {
1739         .f = cmd_config_speed_specific_parsed,
1740         .data = NULL,
1741         .help_str = "port config <port_id> speed "
1742                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1743                                                         "half|full|auto",
1744         .tokens = {
1745                 (void *)&cmd_config_speed_specific_port,
1746                 (void *)&cmd_config_speed_specific_keyword,
1747                 (void *)&cmd_config_speed_specific_id,
1748                 (void *)&cmd_config_speed_specific_item1,
1749                 (void *)&cmd_config_speed_specific_value1,
1750                 (void *)&cmd_config_speed_specific_item2,
1751                 (void *)&cmd_config_speed_specific_value2,
1752                 NULL,
1753         },
1754 };
1755
1756 /* *** configure loopback for all ports *** */
1757 struct cmd_config_loopback_all {
1758         cmdline_fixed_string_t port;
1759         cmdline_fixed_string_t keyword;
1760         cmdline_fixed_string_t all;
1761         cmdline_fixed_string_t item;
1762         uint32_t mode;
1763 };
1764
1765 static void
1766 cmd_config_loopback_all_parsed(void *parsed_result,
1767                         __attribute__((unused)) struct cmdline *cl,
1768                         __attribute__((unused)) void *data)
1769 {
1770         struct cmd_config_loopback_all *res = parsed_result;
1771         portid_t pid;
1772
1773         if (!all_ports_stopped()) {
1774                 printf("Please stop all ports first\n");
1775                 return;
1776         }
1777
1778         RTE_ETH_FOREACH_DEV(pid) {
1779                 ports[pid].dev_conf.lpbk_mode = res->mode;
1780         }
1781
1782         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1783 }
1784
1785 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1786         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1787 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1788         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1789                                                         "config");
1790 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1792 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1793         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1794                                                         "loopback");
1795 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1796         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1797
1798 cmdline_parse_inst_t cmd_config_loopback_all = {
1799         .f = cmd_config_loopback_all_parsed,
1800         .data = NULL,
1801         .help_str = "port config all loopback <mode>",
1802         .tokens = {
1803                 (void *)&cmd_config_loopback_all_port,
1804                 (void *)&cmd_config_loopback_all_keyword,
1805                 (void *)&cmd_config_loopback_all_all,
1806                 (void *)&cmd_config_loopback_all_item,
1807                 (void *)&cmd_config_loopback_all_mode,
1808                 NULL,
1809         },
1810 };
1811
1812 /* *** configure loopback for specific port *** */
1813 struct cmd_config_loopback_specific {
1814         cmdline_fixed_string_t port;
1815         cmdline_fixed_string_t keyword;
1816         uint16_t port_id;
1817         cmdline_fixed_string_t item;
1818         uint32_t mode;
1819 };
1820
1821 static void
1822 cmd_config_loopback_specific_parsed(void *parsed_result,
1823                                 __attribute__((unused)) struct cmdline *cl,
1824                                 __attribute__((unused)) void *data)
1825 {
1826         struct cmd_config_loopback_specific *res = parsed_result;
1827
1828         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1829                 return;
1830
1831         if (!port_is_stopped(res->port_id)) {
1832                 printf("Please stop port %u first\n", res->port_id);
1833                 return;
1834         }
1835
1836         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1837
1838         cmd_reconfig_device_queue(res->port_id, 1, 1);
1839 }
1840
1841
1842 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1843         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1844                                                                 "port");
1845 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1847                                                                 "config");
1848 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1849         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1850                                                                 UINT16);
1851 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1853                                                                 "loopback");
1854 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1855         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1856                               UINT32);
1857
1858 cmdline_parse_inst_t cmd_config_loopback_specific = {
1859         .f = cmd_config_loopback_specific_parsed,
1860         .data = NULL,
1861         .help_str = "port config <port_id> loopback <mode>",
1862         .tokens = {
1863                 (void *)&cmd_config_loopback_specific_port,
1864                 (void *)&cmd_config_loopback_specific_keyword,
1865                 (void *)&cmd_config_loopback_specific_id,
1866                 (void *)&cmd_config_loopback_specific_item,
1867                 (void *)&cmd_config_loopback_specific_mode,
1868                 NULL,
1869         },
1870 };
1871
1872 /* *** configure txq/rxq, txd/rxd *** */
1873 struct cmd_config_rx_tx {
1874         cmdline_fixed_string_t port;
1875         cmdline_fixed_string_t keyword;
1876         cmdline_fixed_string_t all;
1877         cmdline_fixed_string_t name;
1878         uint16_t value;
1879 };
1880
1881 static void
1882 cmd_config_rx_tx_parsed(void *parsed_result,
1883                         __attribute__((unused)) struct cmdline *cl,
1884                         __attribute__((unused)) void *data)
1885 {
1886         struct cmd_config_rx_tx *res = parsed_result;
1887
1888         if (!all_ports_stopped()) {
1889                 printf("Please stop all ports first\n");
1890                 return;
1891         }
1892         if (!strcmp(res->name, "rxq")) {
1893                 if (!res->value && !nb_txq) {
1894                         printf("Warning: Either rx or tx queues should be non zero\n");
1895                         return;
1896                 }
1897                 if (check_nb_rxq(res->value) != 0)
1898                         return;
1899                 nb_rxq = res->value;
1900         }
1901         else if (!strcmp(res->name, "txq")) {
1902                 if (!res->value && !nb_rxq) {
1903                         printf("Warning: Either rx or tx queues should be non zero\n");
1904                         return;
1905                 }
1906                 if (check_nb_txq(res->value) != 0)
1907                         return;
1908                 nb_txq = res->value;
1909         }
1910         else if (!strcmp(res->name, "rxd")) {
1911                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1912                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1913                                         res->value, RTE_TEST_RX_DESC_MAX);
1914                         return;
1915                 }
1916                 nb_rxd = res->value;
1917         } else if (!strcmp(res->name, "txd")) {
1918                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1919                         printf("txd %d invalid - must be > 0 && <= %d\n",
1920                                         res->value, RTE_TEST_TX_DESC_MAX);
1921                         return;
1922                 }
1923                 nb_txd = res->value;
1924         } else {
1925                 printf("Unknown parameter\n");
1926                 return;
1927         }
1928
1929         fwd_config_setup();
1930
1931         init_port_config();
1932
1933         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1934 }
1935
1936 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1937         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1938 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1939         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1940 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1941         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1942 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1943         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1944                                                 "rxq#txq#rxd#txd");
1945 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1946         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1947
1948 cmdline_parse_inst_t cmd_config_rx_tx = {
1949         .f = cmd_config_rx_tx_parsed,
1950         .data = NULL,
1951         .help_str = "port config all rxq|txq|rxd|txd <value>",
1952         .tokens = {
1953                 (void *)&cmd_config_rx_tx_port,
1954                 (void *)&cmd_config_rx_tx_keyword,
1955                 (void *)&cmd_config_rx_tx_all,
1956                 (void *)&cmd_config_rx_tx_name,
1957                 (void *)&cmd_config_rx_tx_value,
1958                 NULL,
1959         },
1960 };
1961
1962 /* *** config max packet length *** */
1963 struct cmd_config_max_pkt_len_result {
1964         cmdline_fixed_string_t port;
1965         cmdline_fixed_string_t keyword;
1966         cmdline_fixed_string_t all;
1967         cmdline_fixed_string_t name;
1968         uint32_t value;
1969 };
1970
1971 static void
1972 cmd_config_max_pkt_len_parsed(void *parsed_result,
1973                                 __attribute__((unused)) struct cmdline *cl,
1974                                 __attribute__((unused)) void *data)
1975 {
1976         struct cmd_config_max_pkt_len_result *res = parsed_result;
1977         portid_t pid;
1978
1979         if (!all_ports_stopped()) {
1980                 printf("Please stop all ports first\n");
1981                 return;
1982         }
1983
1984         RTE_ETH_FOREACH_DEV(pid) {
1985                 struct rte_port *port = &ports[pid];
1986                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1987
1988                 if (!strcmp(res->name, "max-pkt-len")) {
1989                         if (res->value < RTE_ETHER_MIN_LEN) {
1990                                 printf("max-pkt-len can not be less than %d\n",
1991                                                 RTE_ETHER_MIN_LEN);
1992                                 return;
1993                         }
1994                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1995                                 return;
1996
1997                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1998                         if (res->value > RTE_ETHER_MAX_LEN)
1999                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2000                         else
2001                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2002                         port->dev_conf.rxmode.offloads = rx_offloads;
2003                 } else {
2004                         printf("Unknown parameter\n");
2005                         return;
2006                 }
2007         }
2008
2009         init_port_config();
2010
2011         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2012 }
2013
2014 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2015         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2016                                                                 "port");
2017 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2018         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2019                                                                 "config");
2020 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2021         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2022                                                                 "all");
2023 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2024         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2025                                                                 "max-pkt-len");
2026 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2027         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2028                                                                 UINT32);
2029
2030 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2031         .f = cmd_config_max_pkt_len_parsed,
2032         .data = NULL,
2033         .help_str = "port config all max-pkt-len <value>",
2034         .tokens = {
2035                 (void *)&cmd_config_max_pkt_len_port,
2036                 (void *)&cmd_config_max_pkt_len_keyword,
2037                 (void *)&cmd_config_max_pkt_len_all,
2038                 (void *)&cmd_config_max_pkt_len_name,
2039                 (void *)&cmd_config_max_pkt_len_value,
2040                 NULL,
2041         },
2042 };
2043
2044 /* *** configure port MTU *** */
2045 struct cmd_config_mtu_result {
2046         cmdline_fixed_string_t port;
2047         cmdline_fixed_string_t keyword;
2048         cmdline_fixed_string_t mtu;
2049         portid_t port_id;
2050         uint16_t value;
2051 };
2052
2053 static void
2054 cmd_config_mtu_parsed(void *parsed_result,
2055                       __attribute__((unused)) struct cmdline *cl,
2056                       __attribute__((unused)) void *data)
2057 {
2058         struct cmd_config_mtu_result *res = parsed_result;
2059
2060         if (res->value < RTE_ETHER_MIN_LEN) {
2061                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2062                 return;
2063         }
2064         port_mtu_set(res->port_id, res->value);
2065 }
2066
2067 cmdline_parse_token_string_t cmd_config_mtu_port =
2068         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2069                                  "port");
2070 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2071         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2072                                  "config");
2073 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2074         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2075                                  "mtu");
2076 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2077         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2078 cmdline_parse_token_num_t cmd_config_mtu_value =
2079         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2080
2081 cmdline_parse_inst_t cmd_config_mtu = {
2082         .f = cmd_config_mtu_parsed,
2083         .data = NULL,
2084         .help_str = "port config mtu <port_id> <value>",
2085         .tokens = {
2086                 (void *)&cmd_config_mtu_port,
2087                 (void *)&cmd_config_mtu_keyword,
2088                 (void *)&cmd_config_mtu_mtu,
2089                 (void *)&cmd_config_mtu_port_id,
2090                 (void *)&cmd_config_mtu_value,
2091                 NULL,
2092         },
2093 };
2094
2095 /* *** configure rx mode *** */
2096 struct cmd_config_rx_mode_flag {
2097         cmdline_fixed_string_t port;
2098         cmdline_fixed_string_t keyword;
2099         cmdline_fixed_string_t all;
2100         cmdline_fixed_string_t name;
2101         cmdline_fixed_string_t value;
2102 };
2103
2104 static void
2105 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2106                                 __attribute__((unused)) struct cmdline *cl,
2107                                 __attribute__((unused)) void *data)
2108 {
2109         struct cmd_config_rx_mode_flag *res = parsed_result;
2110
2111         if (!all_ports_stopped()) {
2112                 printf("Please stop all ports first\n");
2113                 return;
2114         }
2115
2116         if (!strcmp(res->name, "drop-en")) {
2117                 if (!strcmp(res->value, "on"))
2118                         rx_drop_en = 1;
2119                 else if (!strcmp(res->value, "off"))
2120                         rx_drop_en = 0;
2121                 else {
2122                         printf("Unknown parameter\n");
2123                         return;
2124                 }
2125         } else {
2126                 printf("Unknown parameter\n");
2127                 return;
2128         }
2129
2130         init_port_config();
2131
2132         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2133 }
2134
2135 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2136         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2137 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2138         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2139                                                                 "config");
2140 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2141         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2142 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2143         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2144                                         "drop-en");
2145 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2146         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2147                                                         "on#off");
2148
2149 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2150         .f = cmd_config_rx_mode_flag_parsed,
2151         .data = NULL,
2152         .help_str = "port config all drop-en on|off",
2153         .tokens = {
2154                 (void *)&cmd_config_rx_mode_flag_port,
2155                 (void *)&cmd_config_rx_mode_flag_keyword,
2156                 (void *)&cmd_config_rx_mode_flag_all,
2157                 (void *)&cmd_config_rx_mode_flag_name,
2158                 (void *)&cmd_config_rx_mode_flag_value,
2159                 NULL,
2160         },
2161 };
2162
2163 /* *** configure rss *** */
2164 struct cmd_config_rss {
2165         cmdline_fixed_string_t port;
2166         cmdline_fixed_string_t keyword;
2167         cmdline_fixed_string_t all;
2168         cmdline_fixed_string_t name;
2169         cmdline_fixed_string_t value;
2170 };
2171
2172 static void
2173 cmd_config_rss_parsed(void *parsed_result,
2174                         __attribute__((unused)) struct cmdline *cl,
2175                         __attribute__((unused)) void *data)
2176 {
2177         struct cmd_config_rss *res = parsed_result;
2178         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2179         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2180         int use_default = 0;
2181         int all_updated = 1;
2182         int diag;
2183         uint16_t i;
2184
2185         if (!strcmp(res->value, "all"))
2186                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2187                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2188                                         ETH_RSS_L2_PAYLOAD;
2189         else if (!strcmp(res->value, "ip"))
2190                 rss_conf.rss_hf = ETH_RSS_IP;
2191         else if (!strcmp(res->value, "udp"))
2192                 rss_conf.rss_hf = ETH_RSS_UDP;
2193         else if (!strcmp(res->value, "tcp"))
2194                 rss_conf.rss_hf = ETH_RSS_TCP;
2195         else if (!strcmp(res->value, "sctp"))
2196                 rss_conf.rss_hf = ETH_RSS_SCTP;
2197         else if (!strcmp(res->value, "ether"))
2198                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2199         else if (!strcmp(res->value, "port"))
2200                 rss_conf.rss_hf = ETH_RSS_PORT;
2201         else if (!strcmp(res->value, "vxlan"))
2202                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2203         else if (!strcmp(res->value, "geneve"))
2204                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2205         else if (!strcmp(res->value, "nvgre"))
2206                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2207         else if (!strcmp(res->value, "none"))
2208                 rss_conf.rss_hf = 0;
2209         else if (!strcmp(res->value, "default"))
2210                 use_default = 1;
2211         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2212                                                 atoi(res->value) < 64)
2213                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2214         else {
2215                 printf("Unknown parameter\n");
2216                 return;
2217         }
2218         rss_conf.rss_key = NULL;
2219         /* Update global configuration for RSS types. */
2220         RTE_ETH_FOREACH_DEV(i) {
2221                 struct rte_eth_rss_conf local_rss_conf;
2222
2223                 rte_eth_dev_info_get(i, &dev_info);
2224                 if (use_default)
2225                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2226
2227                 local_rss_conf = rss_conf;
2228                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2229                         dev_info.flow_type_rss_offloads;
2230                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2231                         printf("Port %u modified RSS hash function based on hardware support,"
2232                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2233                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2234                 }
2235                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2236                 if (diag < 0) {
2237                         all_updated = 0;
2238                         printf("Configuration of RSS hash at ethernet port %d "
2239                                 "failed with error (%d): %s.\n",
2240                                 i, -diag, strerror(-diag));
2241                 }
2242         }
2243         if (all_updated && !use_default)
2244                 rss_hf = rss_conf.rss_hf;
2245 }
2246
2247 cmdline_parse_token_string_t cmd_config_rss_port =
2248         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2249 cmdline_parse_token_string_t cmd_config_rss_keyword =
2250         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2251 cmdline_parse_token_string_t cmd_config_rss_all =
2252         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2253 cmdline_parse_token_string_t cmd_config_rss_name =
2254         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2255 cmdline_parse_token_string_t cmd_config_rss_value =
2256         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2257
2258 cmdline_parse_inst_t cmd_config_rss = {
2259         .f = cmd_config_rss_parsed,
2260         .data = NULL,
2261         .help_str = "port config all rss "
2262                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2263         .tokens = {
2264                 (void *)&cmd_config_rss_port,
2265                 (void *)&cmd_config_rss_keyword,
2266                 (void *)&cmd_config_rss_all,
2267                 (void *)&cmd_config_rss_name,
2268                 (void *)&cmd_config_rss_value,
2269                 NULL,
2270         },
2271 };
2272
2273 /* *** configure rss hash key *** */
2274 struct cmd_config_rss_hash_key {
2275         cmdline_fixed_string_t port;
2276         cmdline_fixed_string_t config;
2277         portid_t port_id;
2278         cmdline_fixed_string_t rss_hash_key;
2279         cmdline_fixed_string_t rss_type;
2280         cmdline_fixed_string_t key;
2281 };
2282
2283 static uint8_t
2284 hexa_digit_to_value(char hexa_digit)
2285 {
2286         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2287                 return (uint8_t) (hexa_digit - '0');
2288         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2289                 return (uint8_t) ((hexa_digit - 'a') + 10);
2290         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2291                 return (uint8_t) ((hexa_digit - 'A') + 10);
2292         /* Invalid hexa digit */
2293         return 0xFF;
2294 }
2295
2296 static uint8_t
2297 parse_and_check_key_hexa_digit(char *key, int idx)
2298 {
2299         uint8_t hexa_v;
2300
2301         hexa_v = hexa_digit_to_value(key[idx]);
2302         if (hexa_v == 0xFF)
2303                 printf("invalid key: character %c at position %d is not a "
2304                        "valid hexa digit\n", key[idx], idx);
2305         return hexa_v;
2306 }
2307
2308 static void
2309 cmd_config_rss_hash_key_parsed(void *parsed_result,
2310                                __attribute__((unused)) struct cmdline *cl,
2311                                __attribute__((unused)) void *data)
2312 {
2313         struct cmd_config_rss_hash_key *res = parsed_result;
2314         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2315         uint8_t xdgt0;
2316         uint8_t xdgt1;
2317         int i;
2318         struct rte_eth_dev_info dev_info;
2319         uint8_t hash_key_size;
2320         uint32_t key_len;
2321
2322         rte_eth_dev_info_get(res->port_id, &dev_info);
2323         if (dev_info.hash_key_size > 0 &&
2324                         dev_info.hash_key_size <= sizeof(hash_key))
2325                 hash_key_size = dev_info.hash_key_size;
2326         else {
2327                 printf("dev_info did not provide a valid hash key size\n");
2328                 return;
2329         }
2330         /* Check the length of the RSS hash key */
2331         key_len = strlen(res->key);
2332         if (key_len != (hash_key_size * 2)) {
2333                 printf("key length: %d invalid - key must be a string of %d"
2334                            " hexa-decimal numbers\n",
2335                            (int) key_len, hash_key_size * 2);
2336                 return;
2337         }
2338         /* Translate RSS hash key into binary representation */
2339         for (i = 0; i < hash_key_size; i++) {
2340                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2341                 if (xdgt0 == 0xFF)
2342                         return;
2343                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2344                 if (xdgt1 == 0xFF)
2345                         return;
2346                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2347         }
2348         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2349                         hash_key_size);
2350 }
2351
2352 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2353         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2354 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2355         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2356                                  "config");
2357 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2358         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2359 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2360         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2361                                  rss_hash_key, "rss-hash-key");
2362 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2363         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2364                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2365                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2366                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2367                                  "ipv6-tcp-ex#ipv6-udp-ex");
2368 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2369         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2370
2371 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2372         .f = cmd_config_rss_hash_key_parsed,
2373         .data = NULL,
2374         .help_str = "port config <port_id> rss-hash-key "
2375                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2376                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2377                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2378                 "<string of hex digits (variable length, NIC dependent)>",
2379         .tokens = {
2380                 (void *)&cmd_config_rss_hash_key_port,
2381                 (void *)&cmd_config_rss_hash_key_config,
2382                 (void *)&cmd_config_rss_hash_key_port_id,
2383                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2384                 (void *)&cmd_config_rss_hash_key_rss_type,
2385                 (void *)&cmd_config_rss_hash_key_value,
2386                 NULL,
2387         },
2388 };
2389
2390 /* *** configure port rxq/txq ring size *** */
2391 struct cmd_config_rxtx_ring_size {
2392         cmdline_fixed_string_t port;
2393         cmdline_fixed_string_t config;
2394         portid_t portid;
2395         cmdline_fixed_string_t rxtxq;
2396         uint16_t qid;
2397         cmdline_fixed_string_t rsize;
2398         uint16_t size;
2399 };
2400
2401 static void
2402 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2403                                  __attribute__((unused)) struct cmdline *cl,
2404                                  __attribute__((unused)) void *data)
2405 {
2406         struct cmd_config_rxtx_ring_size *res = parsed_result;
2407         struct rte_port *port;
2408         uint8_t isrx;
2409
2410         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2411                 return;
2412
2413         if (res->portid == (portid_t)RTE_PORT_ALL) {
2414                 printf("Invalid port id\n");
2415                 return;
2416         }
2417
2418         port = &ports[res->portid];
2419
2420         if (!strcmp(res->rxtxq, "rxq"))
2421                 isrx = 1;
2422         else if (!strcmp(res->rxtxq, "txq"))
2423                 isrx = 0;
2424         else {
2425                 printf("Unknown parameter\n");
2426                 return;
2427         }
2428
2429         if (isrx && rx_queue_id_is_invalid(res->qid))
2430                 return;
2431         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2432                 return;
2433
2434         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2435                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2436                        rx_free_thresh);
2437                 return;
2438         }
2439
2440         if (isrx)
2441                 port->nb_rx_desc[res->qid] = res->size;
2442         else
2443                 port->nb_tx_desc[res->qid] = res->size;
2444
2445         cmd_reconfig_device_queue(res->portid, 0, 1);
2446 }
2447
2448 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2449         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2450                                  port, "port");
2451 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2452         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2453                                  config, "config");
2454 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2455         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2456                                  portid, UINT16);
2457 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2458         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2459                                  rxtxq, "rxq#txq");
2460 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2461         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2462                               qid, UINT16);
2463 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2464         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2465                                  rsize, "ring_size");
2466 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2467         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2468                               size, UINT16);
2469
2470 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2471         .f = cmd_config_rxtx_ring_size_parsed,
2472         .data = NULL,
2473         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2474         .tokens = {
2475                 (void *)&cmd_config_rxtx_ring_size_port,
2476                 (void *)&cmd_config_rxtx_ring_size_config,
2477                 (void *)&cmd_config_rxtx_ring_size_portid,
2478                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2479                 (void *)&cmd_config_rxtx_ring_size_qid,
2480                 (void *)&cmd_config_rxtx_ring_size_rsize,
2481                 (void *)&cmd_config_rxtx_ring_size_size,
2482                 NULL,
2483         },
2484 };
2485
2486 /* *** configure port rxq/txq start/stop *** */
2487 struct cmd_config_rxtx_queue {
2488         cmdline_fixed_string_t port;
2489         portid_t portid;
2490         cmdline_fixed_string_t rxtxq;
2491         uint16_t qid;
2492         cmdline_fixed_string_t opname;
2493 };
2494
2495 static void
2496 cmd_config_rxtx_queue_parsed(void *parsed_result,
2497                         __attribute__((unused)) struct cmdline *cl,
2498                         __attribute__((unused)) void *data)
2499 {
2500         struct cmd_config_rxtx_queue *res = parsed_result;
2501         uint8_t isrx;
2502         uint8_t isstart;
2503         int ret = 0;
2504
2505         if (test_done == 0) {
2506                 printf("Please stop forwarding first\n");
2507                 return;
2508         }
2509
2510         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2511                 return;
2512
2513         if (port_is_started(res->portid) != 1) {
2514                 printf("Please start port %u first\n", res->portid);
2515                 return;
2516         }
2517
2518         if (!strcmp(res->rxtxq, "rxq"))
2519                 isrx = 1;
2520         else if (!strcmp(res->rxtxq, "txq"))
2521                 isrx = 0;
2522         else {
2523                 printf("Unknown parameter\n");
2524                 return;
2525         }
2526
2527         if (isrx && rx_queue_id_is_invalid(res->qid))
2528                 return;
2529         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2530                 return;
2531
2532         if (!strcmp(res->opname, "start"))
2533                 isstart = 1;
2534         else if (!strcmp(res->opname, "stop"))
2535                 isstart = 0;
2536         else {
2537                 printf("Unknown parameter\n");
2538                 return;
2539         }
2540
2541         if (isstart && isrx)
2542                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2543         else if (!isstart && isrx)
2544                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2545         else if (isstart && !isrx)
2546                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2547         else
2548                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2549
2550         if (ret == -ENOTSUP)
2551                 printf("Function not supported in PMD driver\n");
2552 }
2553
2554 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2555         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2556 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2557         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2558 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2559         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2560 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2561         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2562 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2563         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2564                                                 "start#stop");
2565
2566 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2567         .f = cmd_config_rxtx_queue_parsed,
2568         .data = NULL,
2569         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2570         .tokens = {
2571                 (void *)&cmd_config_rxtx_queue_port,
2572                 (void *)&cmd_config_rxtx_queue_portid,
2573                 (void *)&cmd_config_rxtx_queue_rxtxq,
2574                 (void *)&cmd_config_rxtx_queue_qid,
2575                 (void *)&cmd_config_rxtx_queue_opname,
2576                 NULL,
2577         },
2578 };
2579
2580 /* *** configure port rxq/txq deferred start on/off *** */
2581 struct cmd_config_deferred_start_rxtx_queue {
2582         cmdline_fixed_string_t port;
2583         portid_t port_id;
2584         cmdline_fixed_string_t rxtxq;
2585         uint16_t qid;
2586         cmdline_fixed_string_t opname;
2587         cmdline_fixed_string_t state;
2588 };
2589
2590 static void
2591 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2592                         __attribute__((unused)) struct cmdline *cl,
2593                         __attribute__((unused)) void *data)
2594 {
2595         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2596         struct rte_port *port;
2597         uint8_t isrx;
2598         uint8_t ison;
2599         uint8_t needreconfig = 0;
2600
2601         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2602                 return;
2603
2604         if (port_is_started(res->port_id) != 0) {
2605                 printf("Please stop port %u first\n", res->port_id);
2606                 return;
2607         }
2608
2609         port = &ports[res->port_id];
2610
2611         isrx = !strcmp(res->rxtxq, "rxq");
2612
2613         if (isrx && rx_queue_id_is_invalid(res->qid))
2614                 return;
2615         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2616                 return;
2617
2618         ison = !strcmp(res->state, "on");
2619
2620         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2621                 port->rx_conf[res->qid].rx_deferred_start = ison;
2622                 needreconfig = 1;
2623         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2624                 port->tx_conf[res->qid].tx_deferred_start = ison;
2625                 needreconfig = 1;
2626         }
2627
2628         if (needreconfig)
2629                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2630 }
2631
2632 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2633         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2634                                                 port, "port");
2635 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2636         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2637                                                 port_id, UINT16);
2638 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2639         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2640                                                 rxtxq, "rxq#txq");
2641 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2642         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2643                                                 qid, UINT16);
2644 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2645         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2646                                                 opname, "deferred_start");
2647 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2648         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2649                                                 state, "on#off");
2650
2651 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2652         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2653         .data = NULL,
2654         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2655         .tokens = {
2656                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2657                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2658                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2659                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2660                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2661                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2662                 NULL,
2663         },
2664 };
2665
2666 /* *** configure port rxq/txq setup *** */
2667 struct cmd_setup_rxtx_queue {
2668         cmdline_fixed_string_t port;
2669         portid_t portid;
2670         cmdline_fixed_string_t rxtxq;
2671         uint16_t qid;
2672         cmdline_fixed_string_t setup;
2673 };
2674
2675 /* Common CLI fields for queue setup */
2676 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2677         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2678 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2679         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2680 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2681         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2682 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2683         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2684 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2685         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2686
2687 static void
2688 cmd_setup_rxtx_queue_parsed(
2689         void *parsed_result,
2690         __attribute__((unused)) struct cmdline *cl,
2691         __attribute__((unused)) void *data)
2692 {
2693         struct cmd_setup_rxtx_queue *res = parsed_result;
2694         struct rte_port *port;
2695         struct rte_mempool *mp;
2696         unsigned int socket_id;
2697         uint8_t isrx = 0;
2698         int ret;
2699
2700         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2701                 return;
2702
2703         if (res->portid == (portid_t)RTE_PORT_ALL) {
2704                 printf("Invalid port id\n");
2705                 return;
2706         }
2707
2708         if (!strcmp(res->rxtxq, "rxq"))
2709                 isrx = 1;
2710         else if (!strcmp(res->rxtxq, "txq"))
2711                 isrx = 0;
2712         else {
2713                 printf("Unknown parameter\n");
2714                 return;
2715         }
2716
2717         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2718                 printf("Invalid rx queue\n");
2719                 return;
2720         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2721                 printf("Invalid tx queue\n");
2722                 return;
2723         }
2724
2725         port = &ports[res->portid];
2726         if (isrx) {
2727                 socket_id = rxring_numa[res->portid];
2728                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2729                         socket_id = port->socket_id;
2730
2731                 mp = mbuf_pool_find(socket_id);
2732                 if (mp == NULL) {
2733                         printf("Failed to setup RX queue: "
2734                                 "No mempool allocation"
2735                                 " on the socket %d\n",
2736                                 rxring_numa[res->portid]);
2737                         return;
2738                 }
2739                 ret = rte_eth_rx_queue_setup(res->portid,
2740                                              res->qid,
2741                                              port->nb_rx_desc[res->qid],
2742                                              socket_id,
2743                                              &port->rx_conf[res->qid],
2744                                              mp);
2745                 if (ret)
2746                         printf("Failed to setup RX queue\n");
2747         } else {
2748                 socket_id = txring_numa[res->portid];
2749                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2750                         socket_id = port->socket_id;
2751
2752                 ret = rte_eth_tx_queue_setup(res->portid,
2753                                              res->qid,
2754                                              port->nb_tx_desc[res->qid],
2755                                              socket_id,
2756                                              &port->tx_conf[res->qid]);
2757                 if (ret)
2758                         printf("Failed to setup TX queue\n");
2759         }
2760 }
2761
2762 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2763         .f = cmd_setup_rxtx_queue_parsed,
2764         .data = NULL,
2765         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2766         .tokens = {
2767                 (void *)&cmd_setup_rxtx_queue_port,
2768                 (void *)&cmd_setup_rxtx_queue_portid,
2769                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2770                 (void *)&cmd_setup_rxtx_queue_qid,
2771                 (void *)&cmd_setup_rxtx_queue_setup,
2772                 NULL,
2773         },
2774 };
2775
2776
2777 /* *** Configure RSS RETA *** */
2778 struct cmd_config_rss_reta {
2779         cmdline_fixed_string_t port;
2780         cmdline_fixed_string_t keyword;
2781         portid_t port_id;
2782         cmdline_fixed_string_t name;
2783         cmdline_fixed_string_t list_name;
2784         cmdline_fixed_string_t list_of_items;
2785 };
2786
2787 static int
2788 parse_reta_config(const char *str,
2789                   struct rte_eth_rss_reta_entry64 *reta_conf,
2790                   uint16_t nb_entries)
2791 {
2792         int i;
2793         unsigned size;
2794         uint16_t hash_index, idx, shift;
2795         uint16_t nb_queue;
2796         char s[256];
2797         const char *p, *p0 = str;
2798         char *end;
2799         enum fieldnames {
2800                 FLD_HASH_INDEX = 0,
2801                 FLD_QUEUE,
2802                 _NUM_FLD
2803         };
2804         unsigned long int_fld[_NUM_FLD];
2805         char *str_fld[_NUM_FLD];
2806
2807         while ((p = strchr(p0,'(')) != NULL) {
2808                 ++p;
2809                 if((p0 = strchr(p,')')) == NULL)
2810                         return -1;
2811
2812                 size = p0 - p;
2813                 if(size >= sizeof(s))
2814                         return -1;
2815
2816                 snprintf(s, sizeof(s), "%.*s", size, p);
2817                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2818                         return -1;
2819                 for (i = 0; i < _NUM_FLD; i++) {
2820                         errno = 0;
2821                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2822                         if (errno != 0 || end == str_fld[i] ||
2823                                         int_fld[i] > 65535)
2824                                 return -1;
2825                 }
2826
2827                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2828                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2829
2830                 if (hash_index >= nb_entries) {
2831                         printf("Invalid RETA hash index=%d\n", hash_index);
2832                         return -1;
2833                 }
2834
2835                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2836                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2837                 reta_conf[idx].mask |= (1ULL << shift);
2838                 reta_conf[idx].reta[shift] = nb_queue;
2839         }
2840
2841         return 0;
2842 }
2843
2844 static void
2845 cmd_set_rss_reta_parsed(void *parsed_result,
2846                         __attribute__((unused)) struct cmdline *cl,
2847                         __attribute__((unused)) void *data)
2848 {
2849         int ret;
2850         struct rte_eth_dev_info dev_info;
2851         struct rte_eth_rss_reta_entry64 reta_conf[8];
2852         struct cmd_config_rss_reta *res = parsed_result;
2853
2854         rte_eth_dev_info_get(res->port_id, &dev_info);
2855         if (dev_info.reta_size == 0) {
2856                 printf("Redirection table size is 0 which is "
2857                                         "invalid for RSS\n");
2858                 return;
2859         } else
2860                 printf("The reta size of port %d is %u\n",
2861                         res->port_id, dev_info.reta_size);
2862         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2863                 printf("Currently do not support more than %u entries of "
2864                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2865                 return;
2866         }
2867
2868         memset(reta_conf, 0, sizeof(reta_conf));
2869         if (!strcmp(res->list_name, "reta")) {
2870                 if (parse_reta_config(res->list_of_items, reta_conf,
2871                                                 dev_info.reta_size)) {
2872                         printf("Invalid RSS Redirection Table "
2873                                         "config entered\n");
2874                         return;
2875                 }
2876                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2877                                 reta_conf, dev_info.reta_size);
2878                 if (ret != 0)
2879                         printf("Bad redirection table parameter, "
2880                                         "return code = %d \n", ret);
2881         }
2882 }
2883
2884 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2885         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2886 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2887         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2888 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2889         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2890 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2891         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2892 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2893         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2894 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2895         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2896                                  NULL);
2897 cmdline_parse_inst_t cmd_config_rss_reta = {
2898         .f = cmd_set_rss_reta_parsed,
2899         .data = NULL,
2900         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2901         .tokens = {
2902                 (void *)&cmd_config_rss_reta_port,
2903                 (void *)&cmd_config_rss_reta_keyword,
2904                 (void *)&cmd_config_rss_reta_port_id,
2905                 (void *)&cmd_config_rss_reta_name,
2906                 (void *)&cmd_config_rss_reta_list_name,
2907                 (void *)&cmd_config_rss_reta_list_of_items,
2908                 NULL,
2909         },
2910 };
2911
2912 /* *** SHOW PORT RETA INFO *** */
2913 struct cmd_showport_reta {
2914         cmdline_fixed_string_t show;
2915         cmdline_fixed_string_t port;
2916         portid_t port_id;
2917         cmdline_fixed_string_t rss;
2918         cmdline_fixed_string_t reta;
2919         uint16_t size;
2920         cmdline_fixed_string_t list_of_items;
2921 };
2922
2923 static int
2924 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2925                            uint16_t nb_entries,
2926                            char *str)
2927 {
2928         uint32_t size;
2929         const char *p, *p0 = str;
2930         char s[256];
2931         char *end;
2932         char *str_fld[8];
2933         uint16_t i;
2934         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2935                         RTE_RETA_GROUP_SIZE;
2936         int ret;
2937
2938         p = strchr(p0, '(');
2939         if (p == NULL)
2940                 return -1;
2941         p++;
2942         p0 = strchr(p, ')');
2943         if (p0 == NULL)
2944                 return -1;
2945         size = p0 - p;
2946         if (size >= sizeof(s)) {
2947                 printf("The string size exceeds the internal buffer size\n");
2948                 return -1;
2949         }
2950         snprintf(s, sizeof(s), "%.*s", size, p);
2951         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2952         if (ret <= 0 || ret != num) {
2953                 printf("The bits of masks do not match the number of "
2954                                         "reta entries: %u\n", num);
2955                 return -1;
2956         }
2957         for (i = 0; i < ret; i++)
2958                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2959
2960         return 0;
2961 }
2962
2963 static void
2964 cmd_showport_reta_parsed(void *parsed_result,
2965                          __attribute__((unused)) struct cmdline *cl,
2966                          __attribute__((unused)) void *data)
2967 {
2968         struct cmd_showport_reta *res = parsed_result;
2969         struct rte_eth_rss_reta_entry64 reta_conf[8];
2970         struct rte_eth_dev_info dev_info;
2971         uint16_t max_reta_size;
2972
2973         rte_eth_dev_info_get(res->port_id, &dev_info);
2974         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2975         if (res->size == 0 || res->size > max_reta_size) {
2976                 printf("Invalid redirection table size: %u (1-%u)\n",
2977                         res->size, max_reta_size);
2978                 return;
2979         }
2980
2981         memset(reta_conf, 0, sizeof(reta_conf));
2982         if (showport_parse_reta_config(reta_conf, res->size,
2983                                 res->list_of_items) < 0) {
2984                 printf("Invalid string: %s for reta masks\n",
2985                                         res->list_of_items);
2986                 return;
2987         }
2988         port_rss_reta_info(res->port_id, reta_conf, res->size);
2989 }
2990
2991 cmdline_parse_token_string_t cmd_showport_reta_show =
2992         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2993 cmdline_parse_token_string_t cmd_showport_reta_port =
2994         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2995 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2996         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2997 cmdline_parse_token_string_t cmd_showport_reta_rss =
2998         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2999 cmdline_parse_token_string_t cmd_showport_reta_reta =
3000         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3001 cmdline_parse_token_num_t cmd_showport_reta_size =
3002         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3003 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3004         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3005                                         list_of_items, NULL);
3006
3007 cmdline_parse_inst_t cmd_showport_reta = {
3008         .f = cmd_showport_reta_parsed,
3009         .data = NULL,
3010         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3011         .tokens = {
3012                 (void *)&cmd_showport_reta_show,
3013                 (void *)&cmd_showport_reta_port,
3014                 (void *)&cmd_showport_reta_port_id,
3015                 (void *)&cmd_showport_reta_rss,
3016                 (void *)&cmd_showport_reta_reta,
3017                 (void *)&cmd_showport_reta_size,
3018                 (void *)&cmd_showport_reta_list_of_items,
3019                 NULL,
3020         },
3021 };
3022
3023 /* *** Show RSS hash configuration *** */
3024 struct cmd_showport_rss_hash {
3025         cmdline_fixed_string_t show;
3026         cmdline_fixed_string_t port;
3027         portid_t port_id;
3028         cmdline_fixed_string_t rss_hash;
3029         cmdline_fixed_string_t rss_type;
3030         cmdline_fixed_string_t key; /* optional argument */
3031 };
3032
3033 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3034                                 __attribute__((unused)) struct cmdline *cl,
3035                                 void *show_rss_key)
3036 {
3037         struct cmd_showport_rss_hash *res = parsed_result;
3038
3039         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3040 }
3041
3042 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3043         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3044 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3045         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3046 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3047         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3048 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3049         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3050                                  "rss-hash");
3051 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3052         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3053
3054 cmdline_parse_inst_t cmd_showport_rss_hash = {
3055         .f = cmd_showport_rss_hash_parsed,
3056         .data = NULL,
3057         .help_str = "show port <port_id> rss-hash",
3058         .tokens = {
3059                 (void *)&cmd_showport_rss_hash_show,
3060                 (void *)&cmd_showport_rss_hash_port,
3061                 (void *)&cmd_showport_rss_hash_port_id,
3062                 (void *)&cmd_showport_rss_hash_rss_hash,
3063                 NULL,
3064         },
3065 };
3066
3067 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3068         .f = cmd_showport_rss_hash_parsed,
3069         .data = (void *)1,
3070         .help_str = "show port <port_id> rss-hash key",
3071         .tokens = {
3072                 (void *)&cmd_showport_rss_hash_show,
3073                 (void *)&cmd_showport_rss_hash_port,
3074                 (void *)&cmd_showport_rss_hash_port_id,
3075                 (void *)&cmd_showport_rss_hash_rss_hash,
3076                 (void *)&cmd_showport_rss_hash_rss_key,
3077                 NULL,
3078         },
3079 };
3080
3081 /* *** Configure DCB *** */
3082 struct cmd_config_dcb {
3083         cmdline_fixed_string_t port;
3084         cmdline_fixed_string_t config;
3085         portid_t port_id;
3086         cmdline_fixed_string_t dcb;
3087         cmdline_fixed_string_t vt;
3088         cmdline_fixed_string_t vt_en;
3089         uint8_t num_tcs;
3090         cmdline_fixed_string_t pfc;
3091         cmdline_fixed_string_t pfc_en;
3092 };
3093
3094 static void
3095 cmd_config_dcb_parsed(void *parsed_result,
3096                         __attribute__((unused)) struct cmdline *cl,
3097                         __attribute__((unused)) void *data)
3098 {
3099         struct cmd_config_dcb *res = parsed_result;
3100         portid_t port_id = res->port_id;
3101         struct rte_port *port;
3102         uint8_t pfc_en;
3103         int ret;
3104
3105         port = &ports[port_id];
3106         /** Check if the port is not started **/
3107         if (port->port_status != RTE_PORT_STOPPED) {
3108                 printf("Please stop port %d first\n", port_id);
3109                 return;
3110         }
3111
3112         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3113                 printf("The invalid number of traffic class,"
3114                         " only 4 or 8 allowed.\n");
3115                 return;
3116         }
3117
3118         if (nb_fwd_lcores < res->num_tcs) {
3119                 printf("nb_cores shouldn't be less than number of TCs.\n");
3120                 return;
3121         }
3122         if (!strncmp(res->pfc_en, "on", 2))
3123                 pfc_en = 1;
3124         else
3125                 pfc_en = 0;
3126
3127         /* DCB in VT mode */
3128         if (!strncmp(res->vt_en, "on", 2))
3129                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3130                                 (enum rte_eth_nb_tcs)res->num_tcs,
3131                                 pfc_en);
3132         else
3133                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3134                                 (enum rte_eth_nb_tcs)res->num_tcs,
3135                                 pfc_en);
3136
3137
3138         if (ret != 0) {
3139                 printf("Cannot initialize network ports.\n");
3140                 return;
3141         }
3142
3143         cmd_reconfig_device_queue(port_id, 1, 1);
3144 }
3145
3146 cmdline_parse_token_string_t cmd_config_dcb_port =
3147         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3148 cmdline_parse_token_string_t cmd_config_dcb_config =
3149         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3150 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3151         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3152 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3153         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3154 cmdline_parse_token_string_t cmd_config_dcb_vt =
3155         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3156 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3157         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3158 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3159         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3160 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3161         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3162 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3163         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3164
3165 cmdline_parse_inst_t cmd_config_dcb = {
3166         .f = cmd_config_dcb_parsed,
3167         .data = NULL,
3168         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3169         .tokens = {
3170                 (void *)&cmd_config_dcb_port,
3171                 (void *)&cmd_config_dcb_config,
3172                 (void *)&cmd_config_dcb_port_id,
3173                 (void *)&cmd_config_dcb_dcb,
3174                 (void *)&cmd_config_dcb_vt,
3175                 (void *)&cmd_config_dcb_vt_en,
3176                 (void *)&cmd_config_dcb_num_tcs,
3177                 (void *)&cmd_config_dcb_pfc,
3178                 (void *)&cmd_config_dcb_pfc_en,
3179                 NULL,
3180         },
3181 };
3182
3183 /* *** configure number of packets per burst *** */
3184 struct cmd_config_burst {
3185         cmdline_fixed_string_t port;
3186         cmdline_fixed_string_t keyword;
3187         cmdline_fixed_string_t all;
3188         cmdline_fixed_string_t name;
3189         uint16_t value;
3190 };
3191
3192 static void
3193 cmd_config_burst_parsed(void *parsed_result,
3194                         __attribute__((unused)) struct cmdline *cl,
3195                         __attribute__((unused)) void *data)
3196 {
3197         struct cmd_config_burst *res = parsed_result;
3198         struct rte_eth_dev_info dev_info;
3199         uint16_t rec_nb_pkts;
3200
3201         if (!all_ports_stopped()) {
3202                 printf("Please stop all ports first\n");
3203                 return;
3204         }
3205
3206         if (!strcmp(res->name, "burst")) {
3207                 if (res->value == 0) {
3208                         /* If user gives a value of zero, query the PMD for
3209                          * its recommended Rx burst size. Testpmd uses a single
3210                          * size for all ports, so assume all ports are the same
3211                          * NIC model and use the values from Port 0.
3212                          */
3213                         rte_eth_dev_info_get(0, &dev_info);
3214                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3215
3216                         if (rec_nb_pkts == 0) {
3217                                 printf("PMD does not recommend a burst size.\n"
3218                                         "User provided value must be between"
3219                                         " 1 and %d\n", MAX_PKT_BURST);
3220                                 return;
3221                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3222                                 printf("PMD recommended burst size of %d"
3223                                         " exceeds maximum value of %d\n",
3224                                         rec_nb_pkts, MAX_PKT_BURST);
3225                                 return;
3226                         }
3227                         printf("Using PMD-provided burst value of %d\n",
3228                                 rec_nb_pkts);
3229                         nb_pkt_per_burst = rec_nb_pkts;
3230                 } else if (res->value > MAX_PKT_BURST) {
3231                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3232                         return;
3233                 } else
3234                         nb_pkt_per_burst = res->value;
3235         } else {
3236                 printf("Unknown parameter\n");
3237                 return;
3238         }
3239
3240         init_port_config();
3241
3242         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3243 }
3244
3245 cmdline_parse_token_string_t cmd_config_burst_port =
3246         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3247 cmdline_parse_token_string_t cmd_config_burst_keyword =
3248         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3249 cmdline_parse_token_string_t cmd_config_burst_all =
3250         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3251 cmdline_parse_token_string_t cmd_config_burst_name =
3252         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3253 cmdline_parse_token_num_t cmd_config_burst_value =
3254         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3255
3256 cmdline_parse_inst_t cmd_config_burst = {
3257         .f = cmd_config_burst_parsed,
3258         .data = NULL,
3259         .help_str = "port config all burst <value>",
3260         .tokens = {
3261                 (void *)&cmd_config_burst_port,
3262                 (void *)&cmd_config_burst_keyword,
3263                 (void *)&cmd_config_burst_all,
3264                 (void *)&cmd_config_burst_name,
3265                 (void *)&cmd_config_burst_value,
3266                 NULL,
3267         },
3268 };
3269
3270 /* *** configure rx/tx queues *** */
3271 struct cmd_config_thresh {
3272         cmdline_fixed_string_t port;
3273         cmdline_fixed_string_t keyword;
3274         cmdline_fixed_string_t all;
3275         cmdline_fixed_string_t name;
3276         uint8_t value;
3277 };
3278
3279 static void
3280 cmd_config_thresh_parsed(void *parsed_result,
3281                         __attribute__((unused)) struct cmdline *cl,
3282                         __attribute__((unused)) void *data)
3283 {
3284         struct cmd_config_thresh *res = parsed_result;
3285
3286         if (!all_ports_stopped()) {
3287                 printf("Please stop all ports first\n");
3288                 return;
3289         }
3290
3291         if (!strcmp(res->name, "txpt"))
3292                 tx_pthresh = res->value;
3293         else if(!strcmp(res->name, "txht"))
3294                 tx_hthresh = res->value;
3295         else if(!strcmp(res->name, "txwt"))
3296                 tx_wthresh = res->value;
3297         else if(!strcmp(res->name, "rxpt"))
3298                 rx_pthresh = res->value;
3299         else if(!strcmp(res->name, "rxht"))
3300                 rx_hthresh = res->value;
3301         else if(!strcmp(res->name, "rxwt"))
3302                 rx_wthresh = res->value;
3303         else {
3304                 printf("Unknown parameter\n");
3305                 return;
3306         }
3307
3308         init_port_config();
3309
3310         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3311 }
3312
3313 cmdline_parse_token_string_t cmd_config_thresh_port =
3314         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3315 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3316         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3317 cmdline_parse_token_string_t cmd_config_thresh_all =
3318         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3319 cmdline_parse_token_string_t cmd_config_thresh_name =
3320         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3321                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3322 cmdline_parse_token_num_t cmd_config_thresh_value =
3323         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3324
3325 cmdline_parse_inst_t cmd_config_thresh = {
3326         .f = cmd_config_thresh_parsed,
3327         .data = NULL,
3328         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3329         .tokens = {
3330                 (void *)&cmd_config_thresh_port,
3331                 (void *)&cmd_config_thresh_keyword,
3332                 (void *)&cmd_config_thresh_all,
3333                 (void *)&cmd_config_thresh_name,
3334                 (void *)&cmd_config_thresh_value,
3335                 NULL,
3336         },
3337 };
3338
3339 /* *** configure free/rs threshold *** */
3340 struct cmd_config_threshold {
3341         cmdline_fixed_string_t port;
3342         cmdline_fixed_string_t keyword;
3343         cmdline_fixed_string_t all;
3344         cmdline_fixed_string_t name;
3345         uint16_t value;
3346 };
3347
3348 static void
3349 cmd_config_threshold_parsed(void *parsed_result,
3350                         __attribute__((unused)) struct cmdline *cl,
3351                         __attribute__((unused)) void *data)
3352 {
3353         struct cmd_config_threshold *res = parsed_result;
3354
3355         if (!all_ports_stopped()) {
3356                 printf("Please stop all ports first\n");
3357                 return;
3358         }
3359
3360         if (!strcmp(res->name, "txfreet"))
3361                 tx_free_thresh = res->value;
3362         else if (!strcmp(res->name, "txrst"))
3363                 tx_rs_thresh = res->value;
3364         else if (!strcmp(res->name, "rxfreet"))
3365                 rx_free_thresh = res->value;
3366         else {
3367                 printf("Unknown parameter\n");
3368                 return;
3369         }
3370
3371         init_port_config();
3372
3373         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3374 }
3375
3376 cmdline_parse_token_string_t cmd_config_threshold_port =
3377         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3378 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3379         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3380                                                                 "config");
3381 cmdline_parse_token_string_t cmd_config_threshold_all =
3382         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3383 cmdline_parse_token_string_t cmd_config_threshold_name =
3384         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3385                                                 "txfreet#txrst#rxfreet");
3386 cmdline_parse_token_num_t cmd_config_threshold_value =
3387         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3388
3389 cmdline_parse_inst_t cmd_config_threshold = {
3390         .f = cmd_config_threshold_parsed,
3391         .data = NULL,
3392         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3393         .tokens = {
3394                 (void *)&cmd_config_threshold_port,
3395                 (void *)&cmd_config_threshold_keyword,
3396                 (void *)&cmd_config_threshold_all,
3397                 (void *)&cmd_config_threshold_name,
3398                 (void *)&cmd_config_threshold_value,
3399                 NULL,
3400         },
3401 };
3402
3403 /* *** stop *** */
3404 struct cmd_stop_result {
3405         cmdline_fixed_string_t stop;
3406 };
3407
3408 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3409                             __attribute__((unused)) struct cmdline *cl,
3410                             __attribute__((unused)) void *data)
3411 {
3412         stop_packet_forwarding();
3413 }
3414
3415 cmdline_parse_token_string_t cmd_stop_stop =
3416         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3417
3418 cmdline_parse_inst_t cmd_stop = {
3419         .f = cmd_stop_parsed,
3420         .data = NULL,
3421         .help_str = "stop: Stop packet forwarding",
3422         .tokens = {
3423                 (void *)&cmd_stop_stop,
3424                 NULL,
3425         },
3426 };
3427
3428 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3429
3430 unsigned int
3431 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3432                 unsigned int *parsed_items, int check_unique_values)
3433 {
3434         unsigned int nb_item;
3435         unsigned int value;
3436         unsigned int i;
3437         unsigned int j;
3438         int value_ok;
3439         char c;
3440
3441         /*
3442          * First parse all items in the list and store their value.
3443          */
3444         value = 0;
3445         nb_item = 0;
3446         value_ok = 0;
3447         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3448                 c = str[i];
3449                 if ((c >= '0') && (c <= '9')) {
3450                         value = (unsigned int) (value * 10 + (c - '0'));
3451                         value_ok = 1;
3452                         continue;
3453                 }
3454                 if (c != ',') {
3455                         printf("character %c is not a decimal digit\n", c);
3456                         return 0;
3457                 }
3458                 if (! value_ok) {
3459                         printf("No valid value before comma\n");
3460                         return 0;
3461                 }
3462                 if (nb_item < max_items) {
3463                         parsed_items[nb_item] = value;
3464                         value_ok = 0;
3465                         value = 0;
3466                 }
3467                 nb_item++;
3468         }
3469         if (nb_item >= max_items) {
3470                 printf("Number of %s = %u > %u (maximum items)\n",
3471                        item_name, nb_item + 1, max_items);
3472                 return 0;
3473         }
3474         parsed_items[nb_item++] = value;
3475         if (! check_unique_values)
3476                 return nb_item;
3477
3478         /*
3479          * Then, check that all values in the list are differents.
3480          * No optimization here...
3481          */
3482         for (i = 0; i < nb_item; i++) {
3483                 for (j = i + 1; j < nb_item; j++) {
3484                         if (parsed_items[j] == parsed_items[i]) {
3485                                 printf("duplicated %s %u at index %u and %u\n",
3486                                        item_name, parsed_items[i], i, j);
3487                                 return 0;
3488                         }
3489                 }
3490         }
3491         return nb_item;
3492 }
3493
3494 struct cmd_set_list_result {
3495         cmdline_fixed_string_t cmd_keyword;
3496         cmdline_fixed_string_t list_name;
3497         cmdline_fixed_string_t list_of_items;
3498 };
3499
3500 static void cmd_set_list_parsed(void *parsed_result,
3501                                 __attribute__((unused)) struct cmdline *cl,
3502                                 __attribute__((unused)) void *data)
3503 {
3504         struct cmd_set_list_result *res;
3505         union {
3506                 unsigned int lcorelist[RTE_MAX_LCORE];
3507                 unsigned int portlist[RTE_MAX_ETHPORTS];
3508         } parsed_items;
3509         unsigned int nb_item;
3510
3511         if (test_done == 0) {
3512                 printf("Please stop forwarding first\n");
3513                 return;
3514         }
3515
3516         res = parsed_result;
3517         if (!strcmp(res->list_name, "corelist")) {
3518                 nb_item = parse_item_list(res->list_of_items, "core",
3519                                           RTE_MAX_LCORE,
3520                                           parsed_items.lcorelist, 1);
3521                 if (nb_item > 0) {
3522                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3523                         fwd_config_setup();
3524                 }
3525                 return;
3526         }
3527         if (!strcmp(res->list_name, "portlist")) {
3528                 nb_item = parse_item_list(res->list_of_items, "port",
3529                                           RTE_MAX_ETHPORTS,
3530                                           parsed_items.portlist, 1);
3531                 if (nb_item > 0) {
3532                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3533                         fwd_config_setup();
3534                 }
3535         }
3536 }
3537
3538 cmdline_parse_token_string_t cmd_set_list_keyword =
3539         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3540                                  "set");
3541 cmdline_parse_token_string_t cmd_set_list_name =
3542         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3543                                  "corelist#portlist");
3544 cmdline_parse_token_string_t cmd_set_list_of_items =
3545         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3546                                  NULL);
3547
3548 cmdline_parse_inst_t cmd_set_fwd_list = {
3549         .f = cmd_set_list_parsed,
3550         .data = NULL,
3551         .help_str = "set corelist|portlist <list0[,list1]*>",
3552         .tokens = {
3553                 (void *)&cmd_set_list_keyword,
3554                 (void *)&cmd_set_list_name,
3555                 (void *)&cmd_set_list_of_items,
3556                 NULL,
3557         },
3558 };
3559
3560 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3561
3562 struct cmd_setmask_result {
3563         cmdline_fixed_string_t set;
3564         cmdline_fixed_string_t mask;
3565         uint64_t hexavalue;
3566 };
3567
3568 static void cmd_set_mask_parsed(void *parsed_result,
3569                                 __attribute__((unused)) struct cmdline *cl,
3570                                 __attribute__((unused)) void *data)
3571 {
3572         struct cmd_setmask_result *res = parsed_result;
3573
3574         if (test_done == 0) {
3575                 printf("Please stop forwarding first\n");
3576                 return;
3577         }
3578         if (!strcmp(res->mask, "coremask")) {
3579                 set_fwd_lcores_mask(res->hexavalue);
3580                 fwd_config_setup();
3581         } else if (!strcmp(res->mask, "portmask")) {
3582                 set_fwd_ports_mask(res->hexavalue);
3583                 fwd_config_setup();
3584         }
3585 }
3586
3587 cmdline_parse_token_string_t cmd_setmask_set =
3588         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3589 cmdline_parse_token_string_t cmd_setmask_mask =
3590         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3591                                  "coremask#portmask");
3592 cmdline_parse_token_num_t cmd_setmask_value =
3593         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3594
3595 cmdline_parse_inst_t cmd_set_fwd_mask = {
3596         .f = cmd_set_mask_parsed,
3597         .data = NULL,
3598         .help_str = "set coremask|portmask <hexadecimal value>",
3599         .tokens = {
3600                 (void *)&cmd_setmask_set,
3601                 (void *)&cmd_setmask_mask,
3602                 (void *)&cmd_setmask_value,
3603                 NULL,
3604         },
3605 };
3606
3607 /*
3608  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3609  */
3610 struct cmd_set_result {
3611         cmdline_fixed_string_t set;
3612         cmdline_fixed_string_t what;
3613         uint16_t value;
3614 };
3615
3616 static void cmd_set_parsed(void *parsed_result,
3617                            __attribute__((unused)) struct cmdline *cl,
3618                            __attribute__((unused)) void *data)
3619 {
3620         struct cmd_set_result *res = parsed_result;
3621         if (!strcmp(res->what, "nbport")) {
3622                 set_fwd_ports_number(res->value);
3623                 fwd_config_setup();
3624         } else if (!strcmp(res->what, "nbcore")) {
3625                 set_fwd_lcores_number(res->value);
3626                 fwd_config_setup();
3627         } else if (!strcmp(res->what, "burst"))
3628                 set_nb_pkt_per_burst(res->value);
3629         else if (!strcmp(res->what, "verbose"))
3630                 set_verbose_level(res->value);
3631 }
3632
3633 cmdline_parse_token_string_t cmd_set_set =
3634         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3635 cmdline_parse_token_string_t cmd_set_what =
3636         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3637                                  "nbport#nbcore#burst#verbose");
3638 cmdline_parse_token_num_t cmd_set_value =
3639         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3640
3641 cmdline_parse_inst_t cmd_set_numbers = {
3642         .f = cmd_set_parsed,
3643         .data = NULL,
3644         .help_str = "set nbport|nbcore|burst|verbose <value>",
3645         .tokens = {
3646                 (void *)&cmd_set_set,
3647                 (void *)&cmd_set_what,
3648                 (void *)&cmd_set_value,
3649                 NULL,
3650         },
3651 };
3652
3653 /* *** SET LOG LEVEL CONFIGURATION *** */
3654
3655 struct cmd_set_log_result {
3656         cmdline_fixed_string_t set;
3657         cmdline_fixed_string_t log;
3658         cmdline_fixed_string_t type;
3659         uint32_t level;
3660 };
3661
3662 static void
3663 cmd_set_log_parsed(void *parsed_result,
3664                    __attribute__((unused)) struct cmdline *cl,
3665                    __attribute__((unused)) void *data)
3666 {
3667         struct cmd_set_log_result *res;
3668         int ret;
3669
3670         res = parsed_result;
3671         if (!strcmp(res->type, "global"))
3672                 rte_log_set_global_level(res->level);
3673         else {
3674                 ret = rte_log_set_level_regexp(res->type, res->level);
3675                 if (ret < 0)
3676                         printf("Unable to set log level\n");
3677         }
3678 }
3679
3680 cmdline_parse_token_string_t cmd_set_log_set =
3681         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3682 cmdline_parse_token_string_t cmd_set_log_log =
3683         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3684 cmdline_parse_token_string_t cmd_set_log_type =
3685         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3686 cmdline_parse_token_num_t cmd_set_log_level =
3687         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3688
3689 cmdline_parse_inst_t cmd_set_log = {
3690         .f = cmd_set_log_parsed,
3691         .data = NULL,
3692         .help_str = "set log global|<type> <level>",
3693         .tokens = {
3694                 (void *)&cmd_set_log_set,
3695                 (void *)&cmd_set_log_log,
3696                 (void *)&cmd_set_log_type,
3697                 (void *)&cmd_set_log_level,
3698                 NULL,
3699         },
3700 };
3701
3702 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3703
3704 struct cmd_set_txpkts_result {
3705         cmdline_fixed_string_t cmd_keyword;
3706         cmdline_fixed_string_t txpkts;
3707         cmdline_fixed_string_t seg_lengths;
3708 };
3709
3710 static void
3711 cmd_set_txpkts_parsed(void *parsed_result,
3712                       __attribute__((unused)) struct cmdline *cl,
3713                       __attribute__((unused)) void *data)
3714 {
3715         struct cmd_set_txpkts_result *res;
3716         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3717         unsigned int nb_segs;
3718
3719         res = parsed_result;
3720         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3721                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3722         if (nb_segs > 0)
3723                 set_tx_pkt_segments(seg_lengths, nb_segs);
3724 }
3725
3726 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3727         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3728                                  cmd_keyword, "set");
3729 cmdline_parse_token_string_t cmd_set_txpkts_name =
3730         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3731                                  txpkts, "txpkts");
3732 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3733         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3734                                  seg_lengths, NULL);
3735
3736 cmdline_parse_inst_t cmd_set_txpkts = {
3737         .f = cmd_set_txpkts_parsed,
3738         .data = NULL,
3739         .help_str = "set txpkts <len0[,len1]*>",
3740         .tokens = {
3741                 (void *)&cmd_set_txpkts_keyword,
3742                 (void *)&cmd_set_txpkts_name,
3743                 (void *)&cmd_set_txpkts_lengths,
3744                 NULL,
3745         },
3746 };
3747
3748 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3749
3750 struct cmd_set_txsplit_result {
3751         cmdline_fixed_string_t cmd_keyword;
3752         cmdline_fixed_string_t txsplit;
3753         cmdline_fixed_string_t mode;
3754 };
3755
3756 static void
3757 cmd_set_txsplit_parsed(void *parsed_result,
3758                       __attribute__((unused)) struct cmdline *cl,
3759                       __attribute__((unused)) void *data)
3760 {
3761         struct cmd_set_txsplit_result *res;
3762
3763         res = parsed_result;
3764         set_tx_pkt_split(res->mode);
3765 }
3766
3767 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3768         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3769                                  cmd_keyword, "set");
3770 cmdline_parse_token_string_t cmd_set_txsplit_name =
3771         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3772                                  txsplit, "txsplit");
3773 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3774         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3775                                  mode, NULL);
3776
3777 cmdline_parse_inst_t cmd_set_txsplit = {
3778         .f = cmd_set_txsplit_parsed,
3779         .data = NULL,
3780         .help_str = "set txsplit on|off|rand",
3781         .tokens = {
3782                 (void *)&cmd_set_txsplit_keyword,
3783                 (void *)&cmd_set_txsplit_name,
3784                 (void *)&cmd_set_txsplit_mode,
3785                 NULL,
3786         },
3787 };
3788
3789 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3790 struct cmd_rx_vlan_filter_all_result {
3791         cmdline_fixed_string_t rx_vlan;
3792         cmdline_fixed_string_t what;
3793         cmdline_fixed_string_t all;
3794         portid_t port_id;
3795 };
3796
3797 static void
3798 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3799                               __attribute__((unused)) struct cmdline *cl,
3800                               __attribute__((unused)) void *data)
3801 {
3802         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3803
3804         if (!strcmp(res->what, "add"))
3805                 rx_vlan_all_filter_set(res->port_id, 1);
3806         else
3807                 rx_vlan_all_filter_set(res->port_id, 0);
3808 }
3809
3810 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3811         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3812                                  rx_vlan, "rx_vlan");
3813 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3814         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3815                                  what, "add#rm");
3816 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3817         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3818                                  all, "all");
3819 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3820         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3821                               port_id, UINT16);
3822
3823 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3824         .f = cmd_rx_vlan_filter_all_parsed,
3825         .data = NULL,
3826         .help_str = "rx_vlan add|rm all <port_id>: "
3827                 "Add/Remove all identifiers to/from the set of VLAN "
3828                 "identifiers filtered by a port",
3829         .tokens = {
3830                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3831                 (void *)&cmd_rx_vlan_filter_all_what,
3832                 (void *)&cmd_rx_vlan_filter_all_all,
3833                 (void *)&cmd_rx_vlan_filter_all_portid,
3834                 NULL,
3835         },
3836 };
3837
3838 /* *** VLAN OFFLOAD SET ON A PORT *** */
3839 struct cmd_vlan_offload_result {
3840         cmdline_fixed_string_t vlan;
3841         cmdline_fixed_string_t set;
3842         cmdline_fixed_string_t vlan_type;
3843         cmdline_fixed_string_t what;
3844         cmdline_fixed_string_t on;
3845         cmdline_fixed_string_t port_id;
3846 };
3847
3848 static void
3849 cmd_vlan_offload_parsed(void *parsed_result,
3850                           __attribute__((unused)) struct cmdline *cl,
3851                           __attribute__((unused)) void *data)
3852 {
3853         int on;
3854         struct cmd_vlan_offload_result *res = parsed_result;
3855         char *str;
3856         int i, len = 0;
3857         portid_t port_id = 0;
3858         unsigned int tmp;
3859
3860         str = res->port_id;
3861         len = strnlen(str, STR_TOKEN_SIZE);
3862         i = 0;
3863         /* Get port_id first */
3864         while(i < len){
3865                 if(str[i] == ',')
3866                         break;
3867
3868                 i++;
3869         }
3870         str[i]='\0';
3871         tmp = strtoul(str, NULL, 0);
3872         /* If port_id greater that what portid_t can represent, return */
3873         if(tmp >= RTE_MAX_ETHPORTS)
3874                 return;
3875         port_id = (portid_t)tmp;
3876
3877         if (!strcmp(res->on, "on"))
3878                 on = 1;
3879         else
3880                 on = 0;
3881
3882         if (!strcmp(res->what, "strip"))
3883                 rx_vlan_strip_set(port_id,  on);
3884         else if(!strcmp(res->what, "stripq")){
3885                 uint16_t queue_id = 0;
3886
3887                 /* No queue_id, return */
3888                 if(i + 1 >= len) {
3889                         printf("must specify (port,queue_id)\n");
3890                         return;
3891                 }
3892                 tmp = strtoul(str + i + 1, NULL, 0);
3893                 /* If queue_id greater that what 16-bits can represent, return */
3894                 if(tmp > 0xffff)
3895                         return;
3896
3897                 queue_id = (uint16_t)tmp;
3898                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3899         }
3900         else if (!strcmp(res->what, "filter"))
3901                 rx_vlan_filter_set(port_id, on);
3902         else
3903                 vlan_extend_set(port_id, on);
3904
3905         return;
3906 }
3907
3908 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3909         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3910                                  vlan, "vlan");
3911 cmdline_parse_token_string_t cmd_vlan_offload_set =
3912         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3913                                  set, "set");
3914 cmdline_parse_token_string_t cmd_vlan_offload_what =
3915         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3916                                  what, "strip#filter#qinq#stripq");
3917 cmdline_parse_token_string_t cmd_vlan_offload_on =
3918         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3919                               on, "on#off");
3920 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3921         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3922                               port_id, NULL);
3923
3924 cmdline_parse_inst_t cmd_vlan_offload = {
3925         .f = cmd_vlan_offload_parsed,
3926         .data = NULL,
3927         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3928                 "<port_id[,queue_id]>: "
3929                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3930         .tokens = {
3931                 (void *)&cmd_vlan_offload_vlan,
3932                 (void *)&cmd_vlan_offload_set,
3933                 (void *)&cmd_vlan_offload_what,
3934                 (void *)&cmd_vlan_offload_on,
3935                 (void *)&cmd_vlan_offload_portid,
3936                 NULL,
3937         },
3938 };
3939
3940 /* *** VLAN TPID SET ON A PORT *** */
3941 struct cmd_vlan_tpid_result {
3942         cmdline_fixed_string_t vlan;
3943         cmdline_fixed_string_t set;
3944         cmdline_fixed_string_t vlan_type;
3945         cmdline_fixed_string_t what;
3946         uint16_t tp_id;
3947         portid_t port_id;
3948 };
3949
3950 static void
3951 cmd_vlan_tpid_parsed(void *parsed_result,
3952                           __attribute__((unused)) struct cmdline *cl,
3953                           __attribute__((unused)) void *data)
3954 {
3955         struct cmd_vlan_tpid_result *res = parsed_result;
3956         enum rte_vlan_type vlan_type;
3957
3958         if (!strcmp(res->vlan_type, "inner"))
3959                 vlan_type = ETH_VLAN_TYPE_INNER;
3960         else if (!strcmp(res->vlan_type, "outer"))
3961                 vlan_type = ETH_VLAN_TYPE_OUTER;
3962         else {
3963                 printf("Unknown vlan type\n");
3964                 return;
3965         }
3966         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3967 }
3968
3969 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3970         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3971                                  vlan, "vlan");
3972 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3973         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3974                                  set, "set");
3975 cmdline_parse_token_string_t cmd_vlan_type =
3976         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3977                                  vlan_type, "inner#outer");
3978 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3979         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3980                                  what, "tpid");
3981 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3982         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3983                               tp_id, UINT16);
3984 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3985         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3986                               port_id, UINT16);
3987
3988 cmdline_parse_inst_t cmd_vlan_tpid = {
3989         .f = cmd_vlan_tpid_parsed,
3990         .data = NULL,
3991         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3992                 "Set the VLAN Ether type",
3993         .tokens = {
3994                 (void *)&cmd_vlan_tpid_vlan,
3995                 (void *)&cmd_vlan_tpid_set,
3996                 (void *)&cmd_vlan_type,
3997                 (void *)&cmd_vlan_tpid_what,
3998                 (void *)&cmd_vlan_tpid_tpid,
3999                 (void *)&cmd_vlan_tpid_portid,
4000                 NULL,
4001         },
4002 };
4003
4004 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4005 struct cmd_rx_vlan_filter_result {
4006         cmdline_fixed_string_t rx_vlan;
4007         cmdline_fixed_string_t what;
4008         uint16_t vlan_id;
4009         portid_t port_id;
4010 };
4011
4012 static void
4013 cmd_rx_vlan_filter_parsed(void *parsed_result,
4014                           __attribute__((unused)) struct cmdline *cl,
4015                           __attribute__((unused)) void *data)
4016 {
4017         struct cmd_rx_vlan_filter_result *res = parsed_result;
4018
4019         if (!strcmp(res->what, "add"))
4020                 rx_vft_set(res->port_id, res->vlan_id, 1);
4021         else
4022                 rx_vft_set(res->port_id, res->vlan_id, 0);
4023 }
4024
4025 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4026         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4027                                  rx_vlan, "rx_vlan");
4028 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4029         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4030                                  what, "add#rm");
4031 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4032         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4033                               vlan_id, UINT16);
4034 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4035         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4036                               port_id, UINT16);
4037
4038 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4039         .f = cmd_rx_vlan_filter_parsed,
4040         .data = NULL,
4041         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4042                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4043                 "identifiers filtered by a port",
4044         .tokens = {
4045                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4046                 (void *)&cmd_rx_vlan_filter_what,
4047                 (void *)&cmd_rx_vlan_filter_vlanid,
4048                 (void *)&cmd_rx_vlan_filter_portid,
4049                 NULL,
4050         },
4051 };
4052
4053 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4054 struct cmd_tx_vlan_set_result {
4055         cmdline_fixed_string_t tx_vlan;
4056         cmdline_fixed_string_t set;
4057         portid_t port_id;
4058         uint16_t vlan_id;
4059 };
4060
4061 static void
4062 cmd_tx_vlan_set_parsed(void *parsed_result,
4063                        __attribute__((unused)) struct cmdline *cl,
4064                        __attribute__((unused)) void *data)
4065 {
4066         struct cmd_tx_vlan_set_result *res = parsed_result;
4067
4068         if (!port_is_stopped(res->port_id)) {
4069                 printf("Please stop port %d first\n", res->port_id);
4070                 return;
4071         }
4072
4073         tx_vlan_set(res->port_id, res->vlan_id);
4074
4075         cmd_reconfig_device_queue(res->port_id, 1, 1);
4076 }
4077
4078 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4079         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4080                                  tx_vlan, "tx_vlan");
4081 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4082         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4083                                  set, "set");
4084 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4085         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4086                               port_id, UINT16);
4087 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4088         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4089                               vlan_id, UINT16);
4090
4091 cmdline_parse_inst_t cmd_tx_vlan_set = {
4092         .f = cmd_tx_vlan_set_parsed,
4093         .data = NULL,
4094         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4095                 "Enable hardware insertion of a single VLAN header "
4096                 "with a given TAG Identifier in packets sent on a port",
4097         .tokens = {
4098                 (void *)&cmd_tx_vlan_set_tx_vlan,
4099                 (void *)&cmd_tx_vlan_set_set,
4100                 (void *)&cmd_tx_vlan_set_portid,
4101                 (void *)&cmd_tx_vlan_set_vlanid,
4102                 NULL,
4103         },
4104 };
4105
4106 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4107 struct cmd_tx_vlan_set_qinq_result {
4108         cmdline_fixed_string_t tx_vlan;
4109         cmdline_fixed_string_t set;
4110         portid_t port_id;
4111         uint16_t vlan_id;
4112         uint16_t vlan_id_outer;
4113 };
4114
4115 static void
4116 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4117                             __attribute__((unused)) struct cmdline *cl,
4118                             __attribute__((unused)) void *data)
4119 {
4120         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4121
4122         if (!port_is_stopped(res->port_id)) {
4123                 printf("Please stop port %d first\n", res->port_id);
4124                 return;
4125         }
4126
4127         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4128
4129         cmd_reconfig_device_queue(res->port_id, 1, 1);
4130 }
4131
4132 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4133         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4134                 tx_vlan, "tx_vlan");
4135 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4136         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4137                 set, "set");
4138 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4139         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4140                 port_id, UINT16);
4141 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4142         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4143                 vlan_id, UINT16);
4144 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4145         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4146                 vlan_id_outer, UINT16);
4147
4148 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4149         .f = cmd_tx_vlan_set_qinq_parsed,
4150         .data = NULL,
4151         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4152                 "Enable hardware insertion of double VLAN header "
4153                 "with given TAG Identifiers in packets sent on a port",
4154         .tokens = {
4155                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4156                 (void *)&cmd_tx_vlan_set_qinq_set,
4157                 (void *)&cmd_tx_vlan_set_qinq_portid,
4158                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4159                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4160                 NULL,
4161         },
4162 };
4163
4164 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4165 struct cmd_tx_vlan_set_pvid_result {
4166         cmdline_fixed_string_t tx_vlan;
4167         cmdline_fixed_string_t set;
4168         cmdline_fixed_string_t pvid;
4169         portid_t port_id;
4170         uint16_t vlan_id;
4171         cmdline_fixed_string_t mode;
4172 };
4173
4174 static void
4175 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4176                             __attribute__((unused)) struct cmdline *cl,
4177                             __attribute__((unused)) void *data)
4178 {
4179         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4180
4181         if (strcmp(res->mode, "on") == 0)
4182                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4183         else
4184                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4185 }
4186
4187 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4188         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4189                                  tx_vlan, "tx_vlan");
4190 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4191         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4192                                  set, "set");
4193 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4194         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4195                                  pvid, "pvid");
4196 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4197         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4198                              port_id, UINT16);
4199 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4200         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4201                               vlan_id, UINT16);
4202 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4203         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4204                                  mode, "on#off");
4205
4206 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4207         .f = cmd_tx_vlan_set_pvid_parsed,
4208         .data = NULL,
4209         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4210         .tokens = {
4211                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4212                 (void *)&cmd_tx_vlan_set_pvid_set,
4213                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4214                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4215                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4216                 (void *)&cmd_tx_vlan_set_pvid_mode,
4217                 NULL,
4218         },
4219 };
4220
4221 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4222 struct cmd_tx_vlan_reset_result {
4223         cmdline_fixed_string_t tx_vlan;
4224         cmdline_fixed_string_t reset;
4225         portid_t port_id;
4226 };
4227
4228 static void
4229 cmd_tx_vlan_reset_parsed(void *parsed_result,
4230                          __attribute__((unused)) struct cmdline *cl,
4231                          __attribute__((unused)) void *data)
4232 {
4233         struct cmd_tx_vlan_reset_result *res = parsed_result;
4234
4235         if (!port_is_stopped(res->port_id)) {
4236                 printf("Please stop port %d first\n", res->port_id);
4237                 return;
4238         }
4239
4240         tx_vlan_reset(res->port_id);
4241
4242         cmd_reconfig_device_queue(res->port_id, 1, 1);
4243 }
4244
4245 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4246         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4247                                  tx_vlan, "tx_vlan");
4248 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4249         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4250                                  reset, "reset");
4251 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4252         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4253                               port_id, UINT16);
4254
4255 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4256         .f = cmd_tx_vlan_reset_parsed,
4257         .data = NULL,
4258         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4259                 "VLAN header in packets sent on a port",
4260         .tokens = {
4261                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4262                 (void *)&cmd_tx_vlan_reset_reset,
4263                 (void *)&cmd_tx_vlan_reset_portid,
4264                 NULL,
4265         },
4266 };
4267
4268
4269 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4270 struct cmd_csum_result {
4271         cmdline_fixed_string_t csum;
4272         cmdline_fixed_string_t mode;
4273         cmdline_fixed_string_t proto;
4274         cmdline_fixed_string_t hwsw;
4275         portid_t port_id;
4276 };
4277
4278 static void
4279 csum_show(int port_id)
4280 {
4281         struct rte_eth_dev_info dev_info;
4282         uint64_t tx_offloads;
4283
4284         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4285         printf("Parse tunnel is %s\n",
4286                 (ports[port_id].parse_tunnel) ? "on" : "off");
4287         printf("IP checksum offload is %s\n",
4288                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4289         printf("UDP checksum offload is %s\n",
4290                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4291         printf("TCP checksum offload is %s\n",
4292                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4293         printf("SCTP checksum offload is %s\n",
4294                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4295         printf("Outer-Ip checksum offload is %s\n",
4296                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4297         printf("Outer-Udp checksum offload is %s\n",
4298                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4299
4300         /* display warnings if configuration is not supported by the NIC */
4301         rte_eth_dev_info_get(port_id, &dev_info);
4302         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4303                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4304                 printf("Warning: hardware IP checksum enabled but not "
4305                         "supported by port %d\n", port_id);
4306         }
4307         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4308                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4309                 printf("Warning: hardware UDP checksum enabled but not "
4310                         "supported by port %d\n", port_id);
4311         }
4312         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4313                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4314                 printf("Warning: hardware TCP checksum enabled but not "
4315                         "supported by port %d\n", port_id);
4316         }
4317         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4318                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4319                 printf("Warning: hardware SCTP checksum enabled but not "
4320                         "supported by port %d\n", port_id);
4321         }
4322         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4323                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4324                 printf("Warning: hardware outer IP checksum enabled but not "
4325                         "supported by port %d\n", port_id);
4326         }
4327         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4328                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4329                         == 0) {
4330                 printf("Warning: hardware outer UDP checksum enabled but not "
4331                         "supported by port %d\n", port_id);
4332         }
4333 }
4334
4335 static void
4336 cmd_config_queue_tx_offloads(struct rte_port *port)
4337 {
4338         int k;
4339
4340         /* Apply queue tx offloads configuration */
4341         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4342                 port->tx_conf[k].offloads =
4343                         port->dev_conf.txmode.offloads;
4344 }
4345
4346 static void
4347 cmd_csum_parsed(void *parsed_result,
4348                        __attribute__((unused)) struct cmdline *cl,
4349                        __attribute__((unused)) void *data)
4350 {
4351         struct cmd_csum_result *res = parsed_result;
4352         int hw = 0;
4353         uint64_t csum_offloads = 0;
4354         struct rte_eth_dev_info dev_info;
4355
4356         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4357                 printf("invalid port %d\n", res->port_id);
4358                 return;
4359         }
4360         if (!port_is_stopped(res->port_id)) {
4361                 printf("Please stop port %d first\n", res->port_id);
4362                 return;
4363         }
4364
4365         rte_eth_dev_info_get(res->port_id, &dev_info);
4366         if (!strcmp(res->mode, "set")) {
4367
4368                 if (!strcmp(res->hwsw, "hw"))
4369                         hw = 1;
4370
4371                 if (!strcmp(res->proto, "ip")) {
4372                         if (hw == 0 || (dev_info.tx_offload_capa &
4373                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4374                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4375                         } else {
4376                                 printf("IP checksum offload is not supported "
4377                                        "by port %u\n", res->port_id);
4378                         }
4379                 } else if (!strcmp(res->proto, "udp")) {
4380                         if (hw == 0 || (dev_info.tx_offload_capa &
4381                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4382                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4383                         } else {
4384                                 printf("UDP checksum offload is not supported "
4385                                        "by port %u\n", res->port_id);
4386                         }
4387                 } else if (!strcmp(res->proto, "tcp")) {
4388                         if (hw == 0 || (dev_info.tx_offload_capa &
4389                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4390                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4391                         } else {
4392                                 printf("TCP checksum offload is not supported "
4393                                        "by port %u\n", res->port_id);
4394                         }
4395                 } else if (!strcmp(res->proto, "sctp")) {
4396                         if (hw == 0 || (dev_info.tx_offload_capa &
4397                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4398                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4399                         } else {
4400                                 printf("SCTP checksum offload is not supported "
4401                                        "by port %u\n", res->port_id);
4402                         }
4403                 } else if (!strcmp(res->proto, "outer-ip")) {
4404                         if (hw == 0 || (dev_info.tx_offload_capa &
4405                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4406                                 csum_offloads |=
4407                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4408                         } else {
4409                                 printf("Outer IP checksum offload is not "
4410                                        "supported by port %u\n", res->port_id);
4411                         }
4412                 } else if (!strcmp(res->proto, "outer-udp")) {
4413                         if (hw == 0 || (dev_info.tx_offload_capa &
4414                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4415                                 csum_offloads |=
4416                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4417                         } else {
4418                                 printf("Outer UDP checksum offload is not "
4419                                        "supported by port %u\n", res->port_id);
4420                         }
4421                 }
4422
4423                 if (hw) {
4424                         ports[res->port_id].dev_conf.txmode.offloads |=
4425                                                         csum_offloads;
4426                 } else {
4427                         ports[res->port_id].dev_conf.txmode.offloads &=
4428                                                         (~csum_offloads);
4429                 }
4430                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4431         }
4432         csum_show(res->port_id);
4433
4434         cmd_reconfig_device_queue(res->port_id, 1, 1);
4435 }
4436
4437 cmdline_parse_token_string_t cmd_csum_csum =
4438         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4439                                 csum, "csum");
4440 cmdline_parse_token_string_t cmd_csum_mode =
4441         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4442                                 mode, "set");
4443 cmdline_parse_token_string_t cmd_csum_proto =
4444         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4445                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4446 cmdline_parse_token_string_t cmd_csum_hwsw =
4447         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4448                                 hwsw, "hw#sw");
4449 cmdline_parse_token_num_t cmd_csum_portid =
4450         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4451                                 port_id, UINT16);
4452
4453 cmdline_parse_inst_t cmd_csum_set = {
4454         .f = cmd_csum_parsed,
4455         .data = NULL,
4456         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4457                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4458                 "using csum forward engine",
4459         .tokens = {
4460                 (void *)&cmd_csum_csum,
4461                 (void *)&cmd_csum_mode,
4462                 (void *)&cmd_csum_proto,
4463                 (void *)&cmd_csum_hwsw,
4464                 (void *)&cmd_csum_portid,
4465                 NULL,
4466         },
4467 };
4468
4469 cmdline_parse_token_string_t cmd_csum_mode_show =
4470         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4471                                 mode, "show");
4472
4473 cmdline_parse_inst_t cmd_csum_show = {
4474         .f = cmd_csum_parsed,
4475         .data = NULL,
4476         .help_str = "csum show <port_id>: Show checksum offload configuration",
4477         .tokens = {
4478                 (void *)&cmd_csum_csum,
4479                 (void *)&cmd_csum_mode_show,
4480                 (void *)&cmd_csum_portid,
4481                 NULL,
4482         },
4483 };
4484
4485 /* Enable/disable tunnel parsing */
4486 struct cmd_csum_tunnel_result {
4487         cmdline_fixed_string_t csum;
4488         cmdline_fixed_string_t parse;
4489         cmdline_fixed_string_t onoff;
4490         portid_t port_id;
4491 };
4492
4493 static void
4494 cmd_csum_tunnel_parsed(void *parsed_result,
4495                        __attribute__((unused)) struct cmdline *cl,
4496                        __attribute__((unused)) void *data)
4497 {
4498         struct cmd_csum_tunnel_result *res = parsed_result;
4499
4500         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4501                 return;
4502
4503         if (!strcmp(res->onoff, "on"))
4504                 ports[res->port_id].parse_tunnel = 1;
4505         else
4506                 ports[res->port_id].parse_tunnel = 0;
4507
4508         csum_show(res->port_id);
4509 }
4510
4511 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4512         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4513                                 csum, "csum");
4514 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4515         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4516                                 parse, "parse-tunnel");
4517 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4518         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4519                                 onoff, "on#off");
4520 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4521         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4522                                 port_id, UINT16);
4523
4524 cmdline_parse_inst_t cmd_csum_tunnel = {
4525         .f = cmd_csum_tunnel_parsed,
4526         .data = NULL,
4527         .help_str = "csum parse-tunnel on|off <port_id>: "
4528                 "Enable/Disable parsing of tunnels for csum engine",
4529         .tokens = {
4530                 (void *)&cmd_csum_tunnel_csum,
4531                 (void *)&cmd_csum_tunnel_parse,
4532                 (void *)&cmd_csum_tunnel_onoff,
4533                 (void *)&cmd_csum_tunnel_portid,
4534                 NULL,
4535         },
4536 };
4537
4538 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4539 struct cmd_tso_set_result {
4540         cmdline_fixed_string_t tso;
4541         cmdline_fixed_string_t mode;
4542         uint16_t tso_segsz;
4543         portid_t port_id;
4544 };
4545
4546 static void
4547 cmd_tso_set_parsed(void *parsed_result,
4548                        __attribute__((unused)) struct cmdline *cl,
4549                        __attribute__((unused)) void *data)
4550 {
4551         struct cmd_tso_set_result *res = parsed_result;
4552         struct rte_eth_dev_info dev_info;
4553
4554         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4555                 return;
4556         if (!port_is_stopped(res->port_id)) {
4557                 printf("Please stop port %d first\n", res->port_id);
4558                 return;
4559         }
4560
4561         if (!strcmp(res->mode, "set"))
4562                 ports[res->port_id].tso_segsz = res->tso_segsz;
4563
4564         rte_eth_dev_info_get(res->port_id, &dev_info);
4565         if ((ports[res->port_id].tso_segsz != 0) &&
4566                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4567                 printf("Error: TSO is not supported by port %d\n",
4568                        res->port_id);
4569                 return;
4570         }
4571
4572         if (ports[res->port_id].tso_segsz == 0) {
4573                 ports[res->port_id].dev_conf.txmode.offloads &=
4574                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4575                 printf("TSO for non-tunneled packets is disabled\n");
4576         } else {
4577                 ports[res->port_id].dev_conf.txmode.offloads |=
4578                                                 DEV_TX_OFFLOAD_TCP_TSO;
4579                 printf("TSO segment size for non-tunneled packets is %d\n",
4580                         ports[res->port_id].tso_segsz);
4581         }
4582         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4583
4584         /* display warnings if configuration is not supported by the NIC */
4585         rte_eth_dev_info_get(res->port_id, &dev_info);
4586         if ((ports[res->port_id].tso_segsz != 0) &&
4587                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4588                 printf("Warning: TSO enabled but not "
4589                         "supported by port %d\n", res->port_id);
4590         }
4591
4592         cmd_reconfig_device_queue(res->port_id, 1, 1);
4593 }
4594
4595 cmdline_parse_token_string_t cmd_tso_set_tso =
4596         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4597                                 tso, "tso");
4598 cmdline_parse_token_string_t cmd_tso_set_mode =
4599         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4600                                 mode, "set");
4601 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4602         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4603                                 tso_segsz, UINT16);
4604 cmdline_parse_token_num_t cmd_tso_set_portid =
4605         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4606                                 port_id, UINT16);
4607
4608 cmdline_parse_inst_t cmd_tso_set = {
4609         .f = cmd_tso_set_parsed,
4610         .data = NULL,
4611         .help_str = "tso set <tso_segsz> <port_id>: "
4612                 "Set TSO segment size of non-tunneled packets for csum engine "
4613                 "(0 to disable)",
4614         .tokens = {
4615                 (void *)&cmd_tso_set_tso,
4616                 (void *)&cmd_tso_set_mode,
4617                 (void *)&cmd_tso_set_tso_segsz,
4618                 (void *)&cmd_tso_set_portid,
4619                 NULL,
4620         },
4621 };
4622
4623 cmdline_parse_token_string_t cmd_tso_show_mode =
4624         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4625                                 mode, "show");
4626
4627
4628 cmdline_parse_inst_t cmd_tso_show = {
4629         .f = cmd_tso_set_parsed,
4630         .data = NULL,
4631         .help_str = "tso show <port_id>: "
4632                 "Show TSO segment size of non-tunneled packets for csum engine",
4633         .tokens = {
4634                 (void *)&cmd_tso_set_tso,
4635                 (void *)&cmd_tso_show_mode,
4636                 (void *)&cmd_tso_set_portid,
4637                 NULL,
4638         },
4639 };
4640
4641 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4642 struct cmd_tunnel_tso_set_result {
4643         cmdline_fixed_string_t tso;
4644         cmdline_fixed_string_t mode;
4645         uint16_t tso_segsz;
4646         portid_t port_id;
4647 };
4648
4649 static struct rte_eth_dev_info
4650 check_tunnel_tso_nic_support(portid_t port_id)
4651 {
4652         struct rte_eth_dev_info dev_info;
4653
4654         rte_eth_dev_info_get(port_id, &dev_info);
4655         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4656                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4657                        "not enabled for port %d\n", port_id);
4658         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4659                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4660                        "not enabled for port %d\n", port_id);
4661         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4662                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4663                        "not enabled for port %d\n", port_id);
4664         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4665                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4666                        "not enabled for port %d\n", port_id);
4667         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4668                 printf("Warning: IP TUNNEL TSO not supported therefore "
4669                        "not enabled for port %d\n", port_id);
4670         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4671                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4672                        "not enabled for port %d\n", port_id);
4673         return dev_info;
4674 }
4675
4676 static void
4677 cmd_tunnel_tso_set_parsed(void *parsed_result,
4678                           __attribute__((unused)) struct cmdline *cl,
4679                           __attribute__((unused)) void *data)
4680 {
4681         struct cmd_tunnel_tso_set_result *res = parsed_result;
4682         struct rte_eth_dev_info dev_info;
4683
4684         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4685                 return;
4686         if (!port_is_stopped(res->port_id)) {
4687                 printf("Please stop port %d first\n", res->port_id);
4688                 return;
4689         }
4690
4691         if (!strcmp(res->mode, "set"))
4692                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4693
4694         dev_info = check_tunnel_tso_nic_support(res->port_id);
4695         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4696                 ports[res->port_id].dev_conf.txmode.offloads &=
4697                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4698                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4699                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4700                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4701                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4702                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4703                 printf("TSO for tunneled packets is disabled\n");
4704         } else {
4705                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4706                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4707                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4708                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4709                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4710                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4711
4712                 ports[res->port_id].dev_conf.txmode.offloads |=
4713                         (tso_offloads & dev_info.tx_offload_capa);
4714                 printf("TSO segment size for tunneled packets is %d\n",
4715                         ports[res->port_id].tunnel_tso_segsz);
4716
4717                 /* Below conditions are needed to make it work:
4718                  * (1) tunnel TSO is supported by the NIC;
4719                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4720                  * are recognized;
4721                  * (3) for tunneled pkts with outer L3 of IPv4,
4722                  * "csum set outer-ip" must be set to hw, because after tso,
4723                  * total_len of outer IP header is changed, and the checksum
4724                  * of outer IP header calculated by sw should be wrong; that
4725                  * is not necessary for IPv6 tunneled pkts because there's no
4726                  * checksum in IP header anymore.
4727                  */
4728
4729                 if (!ports[res->port_id].parse_tunnel)
4730                         printf("Warning: csum parse_tunnel must be set "
4731                                 "so that tunneled packets are recognized\n");
4732                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4733                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4734                         printf("Warning: csum set outer-ip must be set to hw "
4735                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4736         }
4737
4738         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4739         cmd_reconfig_device_queue(res->port_id, 1, 1);
4740 }
4741
4742 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4743         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4744                                 tso, "tunnel_tso");
4745 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4746         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4747                                 mode, "set");
4748 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4749         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4750                                 tso_segsz, UINT16);
4751 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4752         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4753                                 port_id, UINT16);
4754
4755 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4756         .f = cmd_tunnel_tso_set_parsed,
4757         .data = NULL,
4758         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4759                 "Set TSO segment size of tunneled packets for csum engine "
4760                 "(0 to disable)",
4761         .tokens = {
4762                 (void *)&cmd_tunnel_tso_set_tso,
4763                 (void *)&cmd_tunnel_tso_set_mode,
4764                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4765                 (void *)&cmd_tunnel_tso_set_portid,
4766                 NULL,
4767         },
4768 };
4769
4770 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4771         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4772                                 mode, "show");
4773
4774
4775 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4776         .f = cmd_tunnel_tso_set_parsed,
4777         .data = NULL,
4778         .help_str = "tunnel_tso show <port_id> "
4779                 "Show TSO segment size of tunneled packets for csum engine",
4780         .tokens = {
4781                 (void *)&cmd_tunnel_tso_set_tso,
4782                 (void *)&cmd_tunnel_tso_show_mode,
4783                 (void *)&cmd_tunnel_tso_set_portid,
4784                 NULL,
4785         },
4786 };
4787
4788 /* *** SET GRO FOR A PORT *** */
4789 struct cmd_gro_enable_result {
4790         cmdline_fixed_string_t cmd_set;
4791         cmdline_fixed_string_t cmd_port;
4792         cmdline_fixed_string_t cmd_keyword;
4793         cmdline_fixed_string_t cmd_onoff;
4794         portid_t cmd_pid;
4795 };
4796
4797 static void
4798 cmd_gro_enable_parsed(void *parsed_result,
4799                 __attribute__((unused)) struct cmdline *cl,
4800                 __attribute__((unused)) void *data)
4801 {
4802         struct cmd_gro_enable_result *res;
4803
4804         res = parsed_result;
4805         if (!strcmp(res->cmd_keyword, "gro"))
4806                 setup_gro(res->cmd_onoff, res->cmd_pid);
4807 }
4808
4809 cmdline_parse_token_string_t cmd_gro_enable_set =
4810         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4811                         cmd_set, "set");
4812 cmdline_parse_token_string_t cmd_gro_enable_port =
4813         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4814                         cmd_keyword, "port");
4815 cmdline_parse_token_num_t cmd_gro_enable_pid =
4816         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4817                         cmd_pid, UINT16);
4818 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4819         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4820                         cmd_keyword, "gro");
4821 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4822         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4823                         cmd_onoff, "on#off");
4824
4825 cmdline_parse_inst_t cmd_gro_enable = {
4826         .f = cmd_gro_enable_parsed,
4827         .data = NULL,
4828         .help_str = "set port <port_id> gro on|off",
4829         .tokens = {
4830                 (void *)&cmd_gro_enable_set,
4831                 (void *)&cmd_gro_enable_port,
4832                 (void *)&cmd_gro_enable_pid,
4833                 (void *)&cmd_gro_enable_keyword,
4834                 (void *)&cmd_gro_enable_onoff,
4835                 NULL,
4836         },
4837 };
4838
4839 /* *** DISPLAY GRO CONFIGURATION *** */
4840 struct cmd_gro_show_result {
4841         cmdline_fixed_string_t cmd_show;
4842         cmdline_fixed_string_t cmd_port;
4843         cmdline_fixed_string_t cmd_keyword;
4844         portid_t cmd_pid;
4845 };
4846
4847 static void
4848 cmd_gro_show_parsed(void *parsed_result,
4849                 __attribute__((unused)) struct cmdline *cl,
4850                 __attribute__((unused)) void *data)
4851 {
4852         struct cmd_gro_show_result *res;
4853
4854         res = parsed_result;
4855         if (!strcmp(res->cmd_keyword, "gro"))
4856                 show_gro(res->cmd_pid);
4857 }
4858
4859 cmdline_parse_token_string_t cmd_gro_show_show =
4860         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4861                         cmd_show, "show");
4862 cmdline_parse_token_string_t cmd_gro_show_port =
4863         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4864                         cmd_port, "port");
4865 cmdline_parse_token_num_t cmd_gro_show_pid =
4866         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4867                         cmd_pid, UINT16);
4868 cmdline_parse_token_string_t cmd_gro_show_keyword =
4869         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4870                         cmd_keyword, "gro");
4871
4872 cmdline_parse_inst_t cmd_gro_show = {
4873         .f = cmd_gro_show_parsed,
4874         .data = NULL,
4875         .help_str = "show port <port_id> gro",
4876         .tokens = {
4877                 (void *)&cmd_gro_show_show,
4878                 (void *)&cmd_gro_show_port,
4879                 (void *)&cmd_gro_show_pid,
4880                 (void *)&cmd_gro_show_keyword,
4881                 NULL,
4882         },
4883 };
4884
4885 /* *** SET FLUSH CYCLES FOR GRO *** */
4886 struct cmd_gro_flush_result {
4887         cmdline_fixed_string_t cmd_set;
4888         cmdline_fixed_string_t cmd_keyword;
4889         cmdline_fixed_string_t cmd_flush;
4890         uint8_t cmd_cycles;
4891 };
4892
4893 static void
4894 cmd_gro_flush_parsed(void *parsed_result,
4895                 __attribute__((unused)) struct cmdline *cl,
4896                 __attribute__((unused)) void *data)
4897 {
4898         struct cmd_gro_flush_result *res;
4899
4900         res = parsed_result;
4901         if ((!strcmp(res->cmd_keyword, "gro")) &&
4902                         (!strcmp(res->cmd_flush, "flush")))
4903                 setup_gro_flush_cycles(res->cmd_cycles);
4904 }
4905
4906 cmdline_parse_token_string_t cmd_gro_flush_set =
4907         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4908                         cmd_set, "set");
4909 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4910         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4911                         cmd_keyword, "gro");
4912 cmdline_parse_token_string_t cmd_gro_flush_flush =
4913         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4914                         cmd_flush, "flush");
4915 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4916         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4917                         cmd_cycles, UINT8);
4918
4919 cmdline_parse_inst_t cmd_gro_flush = {
4920         .f = cmd_gro_flush_parsed,
4921         .data = NULL,
4922         .help_str = "set gro flush <cycles>",
4923         .tokens = {
4924                 (void *)&cmd_gro_flush_set,
4925                 (void *)&cmd_gro_flush_keyword,
4926                 (void *)&cmd_gro_flush_flush,
4927                 (void *)&cmd_gro_flush_cycles,
4928                 NULL,
4929         },
4930 };
4931
4932 /* *** ENABLE/DISABLE GSO *** */
4933 struct cmd_gso_enable_result {
4934         cmdline_fixed_string_t cmd_set;
4935         cmdline_fixed_string_t cmd_port;
4936         cmdline_fixed_string_t cmd_keyword;
4937         cmdline_fixed_string_t cmd_mode;
4938         portid_t cmd_pid;
4939 };
4940
4941 static void
4942 cmd_gso_enable_parsed(void *parsed_result,
4943                 __attribute__((unused)) struct cmdline *cl,
4944                 __attribute__((unused)) void *data)
4945 {
4946         struct cmd_gso_enable_result *res;
4947
4948         res = parsed_result;
4949         if (!strcmp(res->cmd_keyword, "gso"))
4950                 setup_gso(res->cmd_mode, res->cmd_pid);
4951 }
4952
4953 cmdline_parse_token_string_t cmd_gso_enable_set =
4954         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4955                         cmd_set, "set");
4956 cmdline_parse_token_string_t cmd_gso_enable_port =
4957         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4958                         cmd_port, "port");
4959 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4960         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4961                         cmd_keyword, "gso");
4962 cmdline_parse_token_string_t cmd_gso_enable_mode =
4963         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4964                         cmd_mode, "on#off");
4965 cmdline_parse_token_num_t cmd_gso_enable_pid =
4966         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4967                         cmd_pid, UINT16);
4968
4969 cmdline_parse_inst_t cmd_gso_enable = {
4970         .f = cmd_gso_enable_parsed,
4971         .data = NULL,
4972         .help_str = "set port <port_id> gso on|off",
4973         .tokens = {
4974                 (void *)&cmd_gso_enable_set,
4975                 (void *)&cmd_gso_enable_port,
4976                 (void *)&cmd_gso_enable_pid,
4977                 (void *)&cmd_gso_enable_keyword,
4978                 (void *)&cmd_gso_enable_mode,
4979                 NULL,
4980         },
4981 };
4982
4983 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4984 struct cmd_gso_size_result {
4985         cmdline_fixed_string_t cmd_set;
4986         cmdline_fixed_string_t cmd_keyword;
4987         cmdline_fixed_string_t cmd_segsz;
4988         uint16_t cmd_size;
4989 };
4990
4991 static void
4992 cmd_gso_size_parsed(void *parsed_result,
4993                        __attribute__((unused)) struct cmdline *cl,
4994                        __attribute__((unused)) void *data)
4995 {
4996         struct cmd_gso_size_result *res = parsed_result;
4997
4998         if (test_done == 0) {
4999                 printf("Before setting GSO segsz, please first"
5000                                 " stop fowarding\n");
5001                 return;
5002         }
5003
5004         if (!strcmp(res->cmd_keyword, "gso") &&
5005                         !strcmp(res->cmd_segsz, "segsz")) {
5006                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5007                         printf("gso_size should be larger than %zu."
5008                                         " Please input a legal value\n",
5009                                         RTE_GSO_SEG_SIZE_MIN);
5010                 else
5011                         gso_max_segment_size = res->cmd_size;
5012         }
5013 }
5014
5015 cmdline_parse_token_string_t cmd_gso_size_set =
5016         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5017                                 cmd_set, "set");
5018 cmdline_parse_token_string_t cmd_gso_size_keyword =
5019         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5020                                 cmd_keyword, "gso");
5021 cmdline_parse_token_string_t cmd_gso_size_segsz =
5022         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5023                                 cmd_segsz, "segsz");
5024 cmdline_parse_token_num_t cmd_gso_size_size =
5025         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5026                                 cmd_size, UINT16);
5027
5028 cmdline_parse_inst_t cmd_gso_size = {
5029         .f = cmd_gso_size_parsed,
5030         .data = NULL,
5031         .help_str = "set gso segsz <length>",
5032         .tokens = {
5033                 (void *)&cmd_gso_size_set,
5034                 (void *)&cmd_gso_size_keyword,
5035                 (void *)&cmd_gso_size_segsz,
5036                 (void *)&cmd_gso_size_size,
5037                 NULL,
5038         },
5039 };
5040
5041 /* *** SHOW GSO CONFIGURATION *** */
5042 struct cmd_gso_show_result {
5043         cmdline_fixed_string_t cmd_show;
5044         cmdline_fixed_string_t cmd_port;
5045         cmdline_fixed_string_t cmd_keyword;
5046         portid_t cmd_pid;
5047 };
5048
5049 static void
5050 cmd_gso_show_parsed(void *parsed_result,
5051                        __attribute__((unused)) struct cmdline *cl,
5052                        __attribute__((unused)) void *data)
5053 {
5054         struct cmd_gso_show_result *res = parsed_result;
5055
5056         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5057                 printf("invalid port id %u\n", res->cmd_pid);
5058                 return;
5059         }
5060         if (!strcmp(res->cmd_keyword, "gso")) {
5061                 if (gso_ports[res->cmd_pid].enable) {
5062                         printf("Max GSO'd packet size: %uB\n"
5063                                         "Supported GSO types: TCP/IPv4, "
5064                                         "UDP/IPv4, VxLAN with inner "
5065                                         "TCP/IPv4 packet, GRE with inner "
5066                                         "TCP/IPv4 packet\n",
5067                                         gso_max_segment_size);
5068                 } else
5069                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5070         }
5071 }
5072
5073 cmdline_parse_token_string_t cmd_gso_show_show =
5074 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5075                 cmd_show, "show");
5076 cmdline_parse_token_string_t cmd_gso_show_port =
5077 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5078                 cmd_port, "port");
5079 cmdline_parse_token_string_t cmd_gso_show_keyword =
5080         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5081                                 cmd_keyword, "gso");
5082 cmdline_parse_token_num_t cmd_gso_show_pid =
5083         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5084                                 cmd_pid, UINT16);
5085
5086 cmdline_parse_inst_t cmd_gso_show = {
5087         .f = cmd_gso_show_parsed,
5088         .data = NULL,
5089         .help_str = "show port <port_id> gso",
5090         .tokens = {
5091                 (void *)&cmd_gso_show_show,
5092                 (void *)&cmd_gso_show_port,
5093                 (void *)&cmd_gso_show_pid,
5094                 (void *)&cmd_gso_show_keyword,
5095                 NULL,
5096         },
5097 };
5098
5099 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5100 struct cmd_set_flush_rx {
5101         cmdline_fixed_string_t set;
5102         cmdline_fixed_string_t flush_rx;
5103         cmdline_fixed_string_t mode;
5104 };
5105
5106 static void
5107 cmd_set_flush_rx_parsed(void *parsed_result,
5108                 __attribute__((unused)) struct cmdline *cl,
5109                 __attribute__((unused)) void *data)
5110 {
5111         struct cmd_set_flush_rx *res = parsed_result;
5112         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5113 }
5114
5115 cmdline_parse_token_string_t cmd_setflushrx_set =
5116         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5117                         set, "set");
5118 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5119         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5120                         flush_rx, "flush_rx");
5121 cmdline_parse_token_string_t cmd_setflushrx_mode =
5122         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5123                         mode, "on#off");
5124
5125
5126 cmdline_parse_inst_t cmd_set_flush_rx = {
5127         .f = cmd_set_flush_rx_parsed,
5128         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5129         .data = NULL,
5130         .tokens = {
5131                 (void *)&cmd_setflushrx_set,
5132                 (void *)&cmd_setflushrx_flush_rx,
5133                 (void *)&cmd_setflushrx_mode,
5134                 NULL,
5135         },
5136 };
5137
5138 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5139 struct cmd_set_link_check {
5140         cmdline_fixed_string_t set;
5141         cmdline_fixed_string_t link_check;
5142         cmdline_fixed_string_t mode;
5143 };
5144
5145 static void
5146 cmd_set_link_check_parsed(void *parsed_result,
5147                 __attribute__((unused)) struct cmdline *cl,
5148                 __attribute__((unused)) void *data)
5149 {
5150         struct cmd_set_link_check *res = parsed_result;
5151         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5152 }
5153
5154 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5155         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5156                         set, "set");
5157 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5158         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5159                         link_check, "link_check");
5160 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5161         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5162                         mode, "on#off");
5163
5164
5165 cmdline_parse_inst_t cmd_set_link_check = {
5166         .f = cmd_set_link_check_parsed,
5167         .help_str = "set link_check on|off: Enable/Disable link status check "
5168                     "when starting/stopping a port",
5169         .data = NULL,
5170         .tokens = {
5171                 (void *)&cmd_setlinkcheck_set,
5172                 (void *)&cmd_setlinkcheck_link_check,
5173                 (void *)&cmd_setlinkcheck_mode,
5174                 NULL,
5175         },
5176 };
5177
5178 /* *** SET NIC BYPASS MODE *** */
5179 struct cmd_set_bypass_mode_result {
5180         cmdline_fixed_string_t set;
5181         cmdline_fixed_string_t bypass;
5182         cmdline_fixed_string_t mode;
5183         cmdline_fixed_string_t value;
5184         portid_t port_id;
5185 };
5186
5187 static void
5188 cmd_set_bypass_mode_parsed(void *parsed_result,
5189                 __attribute__((unused)) struct cmdline *cl,
5190                 __attribute__((unused)) void *data)
5191 {
5192         struct cmd_set_bypass_mode_result *res = parsed_result;
5193         portid_t port_id = res->port_id;
5194         int32_t rc = -EINVAL;
5195
5196 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5197         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5198
5199         if (!strcmp(res->value, "bypass"))
5200                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5201         else if (!strcmp(res->value, "isolate"))
5202                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5203         else
5204                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5205
5206         /* Set the bypass mode for the relevant port. */
5207         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5208 #endif
5209         if (rc != 0)
5210                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5211 }
5212
5213 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5214         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5215                         set, "set");
5216 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5217         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5218                         bypass, "bypass");
5219 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5220         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5221                         mode, "mode");
5222 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5223         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5224                         value, "normal#bypass#isolate");
5225 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5226         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5227                                 port_id, UINT16);
5228
5229 cmdline_parse_inst_t cmd_set_bypass_mode = {
5230         .f = cmd_set_bypass_mode_parsed,
5231         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5232                     "Set the NIC bypass mode for port_id",
5233         .data = NULL,
5234         .tokens = {
5235                 (void *)&cmd_setbypass_mode_set,
5236                 (void *)&cmd_setbypass_mode_bypass,
5237                 (void *)&cmd_setbypass_mode_mode,
5238                 (void *)&cmd_setbypass_mode_value,
5239                 (void *)&cmd_setbypass_mode_port,
5240                 NULL,
5241         },
5242 };
5243
5244 /* *** SET NIC BYPASS EVENT *** */
5245 struct cmd_set_bypass_event_result {
5246         cmdline_fixed_string_t set;
5247         cmdline_fixed_string_t bypass;
5248         cmdline_fixed_string_t event;
5249         cmdline_fixed_string_t event_value;
5250         cmdline_fixed_string_t mode;
5251         cmdline_fixed_string_t mode_value;
5252         portid_t port_id;
5253 };
5254
5255 static void
5256 cmd_set_bypass_event_parsed(void *parsed_result,
5257                 __attribute__((unused)) struct cmdline *cl,
5258                 __attribute__((unused)) void *data)
5259 {
5260         int32_t rc = -EINVAL;
5261         struct cmd_set_bypass_event_result *res = parsed_result;
5262         portid_t port_id = res->port_id;
5263
5264 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5265         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5266         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5267
5268         if (!strcmp(res->event_value, "timeout"))
5269                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5270         else if (!strcmp(res->event_value, "os_on"))
5271                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5272         else if (!strcmp(res->event_value, "os_off"))
5273                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5274         else if (!strcmp(res->event_value, "power_on"))
5275                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5276         else if (!strcmp(res->event_value, "power_off"))
5277                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5278         else
5279                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5280
5281         if (!strcmp(res->mode_value, "bypass"))
5282                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5283         else if (!strcmp(res->mode_value, "isolate"))
5284                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5285         else
5286                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5287
5288         /* Set the watchdog timeout. */
5289         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5290
5291                 rc = -EINVAL;
5292                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5293                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5294                                                            bypass_timeout);
5295                 }
5296                 if (rc != 0) {
5297                         printf("Failed to set timeout value %u "
5298                         "for port %d, errto code: %d.\n",
5299                         bypass_timeout, port_id, rc);
5300                 }
5301         }
5302
5303         /* Set the bypass event to transition to bypass mode. */
5304         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5305                                               bypass_mode);
5306 #endif
5307
5308         if (rc != 0)
5309                 printf("\t Failed to set bypass event for port = %d.\n",
5310                        port_id);
5311 }
5312
5313 cmdline_parse_token_string_t cmd_setbypass_event_set =
5314         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5315                         set, "set");
5316 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5317         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5318                         bypass, "bypass");
5319 cmdline_parse_token_string_t cmd_setbypass_event_event =
5320         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5321                         event, "event");
5322 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5323         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5324                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5325 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5326         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5327                         mode, "mode");
5328 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5329         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5330                         mode_value, "normal#bypass#isolate");
5331 cmdline_parse_token_num_t cmd_setbypass_event_port =
5332         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5333                                 port_id, UINT16);
5334
5335 cmdline_parse_inst_t cmd_set_bypass_event = {
5336         .f = cmd_set_bypass_event_parsed,
5337         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5338                 "power_off mode normal|bypass|isolate <port_id>: "
5339                 "Set the NIC bypass event mode for port_id",
5340         .data = NULL,
5341         .tokens = {
5342                 (void *)&cmd_setbypass_event_set,
5343                 (void *)&cmd_setbypass_event_bypass,
5344                 (void *)&cmd_setbypass_event_event,
5345                 (void *)&cmd_setbypass_event_event_value,
5346                 (void *)&cmd_setbypass_event_mode,
5347                 (void *)&cmd_setbypass_event_mode_value,
5348                 (void *)&cmd_setbypass_event_port,
5349                 NULL,
5350         },
5351 };
5352
5353
5354 /* *** SET NIC BYPASS TIMEOUT *** */
5355 struct cmd_set_bypass_timeout_result {
5356         cmdline_fixed_string_t set;
5357         cmdline_fixed_string_t bypass;
5358         cmdline_fixed_string_t timeout;
5359         cmdline_fixed_string_t value;
5360 };
5361
5362 static void
5363 cmd_set_bypass_timeout_parsed(void *parsed_result,
5364                 __attribute__((unused)) struct cmdline *cl,
5365                 __attribute__((unused)) void *data)
5366 {
5367         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5368
5369 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5370         if (!strcmp(res->value, "1.5"))
5371                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5372         else if (!strcmp(res->value, "2"))
5373                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5374         else if (!strcmp(res->value, "3"))
5375                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5376         else if (!strcmp(res->value, "4"))
5377                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5378         else if (!strcmp(res->value, "8"))
5379                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5380         else if (!strcmp(res->value, "16"))
5381                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5382         else if (!strcmp(res->value, "32"))
5383                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5384         else
5385                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5386 #endif
5387 }
5388
5389 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5390         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5391                         set, "set");
5392 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5393         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5394                         bypass, "bypass");
5395 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5396         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5397                         timeout, "timeout");
5398 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5399         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5400                         value, "0#1.5#2#3#4#8#16#32");
5401
5402 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5403         .f = cmd_set_bypass_timeout_parsed,
5404         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5405                 "Set the NIC bypass watchdog timeout in seconds",
5406         .data = NULL,
5407         .tokens = {
5408                 (void *)&cmd_setbypass_timeout_set,
5409                 (void *)&cmd_setbypass_timeout_bypass,
5410                 (void *)&cmd_setbypass_timeout_timeout,
5411                 (void *)&cmd_setbypass_timeout_value,
5412                 NULL,
5413         },
5414 };
5415
5416 /* *** SHOW NIC BYPASS MODE *** */
5417 struct cmd_show_bypass_config_result {
5418         cmdline_fixed_string_t show;
5419         cmdline_fixed_string_t bypass;
5420         cmdline_fixed_string_t config;
5421         portid_t port_id;
5422 };
5423
5424 static void
5425 cmd_show_bypass_config_parsed(void *parsed_result,
5426                 __attribute__((unused)) struct cmdline *cl,
5427                 __attribute__((unused)) void *data)
5428 {
5429         struct cmd_show_bypass_config_result *res = parsed_result;
5430         portid_t port_id = res->port_id;
5431         int rc = -EINVAL;
5432 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5433         uint32_t event_mode;
5434         uint32_t bypass_mode;
5435         uint32_t timeout = bypass_timeout;
5436         int i;
5437
5438         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5439                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5440         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5441                 {"UNKNOWN", "normal", "bypass", "isolate"};
5442         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5443                 "NONE",
5444                 "OS/board on",
5445                 "power supply on",
5446                 "OS/board off",
5447                 "power supply off",
5448                 "timeout"};
5449         int num_events = (sizeof events) / (sizeof events[0]);
5450
5451         /* Display the bypass mode.*/
5452         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5453                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5454                 return;
5455         }
5456         else {
5457                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5458                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5459
5460                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5461         }
5462
5463         /* Display the bypass timeout.*/
5464         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5465                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5466
5467         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5468
5469         /* Display the bypass events and associated modes. */
5470         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5471
5472                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5473                         printf("\tFailed to get bypass mode for event = %s\n",
5474                                 events[i]);
5475                 } else {
5476                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5477                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5478
5479                         printf("\tbypass event: %-16s = %s\n", events[i],
5480                                 modes[event_mode]);
5481                 }
5482         }
5483 #endif
5484         if (rc != 0)
5485                 printf("\tFailed to get bypass configuration for port = %d\n",
5486                        port_id);
5487 }
5488
5489 cmdline_parse_token_string_t cmd_showbypass_config_show =
5490         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5491                         show, "show");
5492 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5493         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5494                         bypass, "bypass");
5495 cmdline_parse_token_string_t cmd_showbypass_config_config =
5496         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5497                         config, "config");
5498 cmdline_parse_token_num_t cmd_showbypass_config_port =
5499         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5500                                 port_id, UINT16);
5501
5502 cmdline_parse_inst_t cmd_show_bypass_config = {
5503         .f = cmd_show_bypass_config_parsed,
5504         .help_str = "show bypass config <port_id>: "
5505                     "Show the NIC bypass config for port_id",
5506         .data = NULL,
5507         .tokens = {
5508                 (void *)&cmd_showbypass_config_show,
5509                 (void *)&cmd_showbypass_config_bypass,
5510                 (void *)&cmd_showbypass_config_config,
5511                 (void *)&cmd_showbypass_config_port,
5512                 NULL,
5513         },
5514 };
5515
5516 #ifdef RTE_LIBRTE_PMD_BOND
5517 /* *** SET BONDING MODE *** */
5518 struct cmd_set_bonding_mode_result {
5519         cmdline_fixed_string_t set;
5520         cmdline_fixed_string_t bonding;
5521         cmdline_fixed_string_t mode;
5522         uint8_t value;
5523         portid_t port_id;
5524 };
5525
5526 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5527                 __attribute__((unused))  struct cmdline *cl,
5528                 __attribute__((unused)) void *data)
5529 {
5530         struct cmd_set_bonding_mode_result *res = parsed_result;
5531         portid_t port_id = res->port_id;
5532
5533         /* Set the bonding mode for the relevant port. */
5534         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5535                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5536 }
5537
5538 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5539 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5540                 set, "set");
5541 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5542 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5543                 bonding, "bonding");
5544 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5545 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5546                 mode, "mode");
5547 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5548 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5549                 value, UINT8);
5550 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5551 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5552                 port_id, UINT16);
5553
5554 cmdline_parse_inst_t cmd_set_bonding_mode = {
5555                 .f = cmd_set_bonding_mode_parsed,
5556                 .help_str = "set bonding mode <mode_value> <port_id>: "
5557                         "Set the bonding mode for port_id",
5558                 .data = NULL,
5559                 .tokens = {
5560                                 (void *) &cmd_setbonding_mode_set,
5561                                 (void *) &cmd_setbonding_mode_bonding,
5562                                 (void *) &cmd_setbonding_mode_mode,
5563                                 (void *) &cmd_setbonding_mode_value,
5564                                 (void *) &cmd_setbonding_mode_port,
5565                                 NULL
5566                 }
5567 };
5568
5569 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5570 struct cmd_set_bonding_lacp_dedicated_queues_result {
5571         cmdline_fixed_string_t set;
5572         cmdline_fixed_string_t bonding;
5573         cmdline_fixed_string_t lacp;
5574         cmdline_fixed_string_t dedicated_queues;
5575         portid_t port_id;
5576         cmdline_fixed_string_t mode;
5577 };
5578
5579 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5580                 __attribute__((unused))  struct cmdline *cl,
5581                 __attribute__((unused)) void *data)
5582 {
5583         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5584         portid_t port_id = res->port_id;
5585         struct rte_port *port;
5586
5587         port = &ports[port_id];
5588
5589         /** Check if the port is not started **/
5590         if (port->port_status != RTE_PORT_STOPPED) {
5591                 printf("Please stop port %d first\n", port_id);
5592                 return;
5593         }
5594
5595         if (!strcmp(res->mode, "enable")) {
5596                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5597                         printf("Dedicate queues for LACP control packets"
5598                                         " enabled\n");
5599                 else
5600                         printf("Enabling dedicate queues for LACP control "
5601                                         "packets on port %d failed\n", port_id);
5602         } else if (!strcmp(res->mode, "disable")) {
5603                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5604                         printf("Dedicated queues for LACP control packets "
5605                                         "disabled\n");
5606                 else
5607                         printf("Disabling dedicated queues for LACP control "
5608                                         "traffic on port %d failed\n", port_id);
5609         }
5610 }
5611
5612 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5613 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5614                 set, "set");
5615 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5616 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5617                 bonding, "bonding");
5618 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5619 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5620                 lacp, "lacp");
5621 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5622 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5623                 dedicated_queues, "dedicated_queues");
5624 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5625 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5626                 port_id, UINT16);
5627 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5628 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5629                 mode, "enable#disable");
5630
5631 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5632                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5633                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5634                         "enable|disable: "
5635                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5636                 .data = NULL,
5637                 .tokens = {
5638                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5639                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5640                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5641                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5642                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5643                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5644                         NULL
5645                 }
5646 };
5647
5648 /* *** SET BALANCE XMIT POLICY *** */
5649 struct cmd_set_bonding_balance_xmit_policy_result {
5650         cmdline_fixed_string_t set;
5651         cmdline_fixed_string_t bonding;
5652         cmdline_fixed_string_t balance_xmit_policy;
5653         portid_t port_id;
5654         cmdline_fixed_string_t policy;
5655 };
5656
5657 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5658                 __attribute__((unused))  struct cmdline *cl,
5659                 __attribute__((unused)) void *data)
5660 {
5661         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5662         portid_t port_id = res->port_id;
5663         uint8_t policy;
5664
5665         if (!strcmp(res->policy, "l2")) {
5666                 policy = BALANCE_XMIT_POLICY_LAYER2;
5667         } else if (!strcmp(res->policy, "l23")) {
5668                 policy = BALANCE_XMIT_POLICY_LAYER23;
5669         } else if (!strcmp(res->policy, "l34")) {
5670                 policy = BALANCE_XMIT_POLICY_LAYER34;
5671         } else {
5672                 printf("\t Invalid xmit policy selection");
5673                 return;
5674         }
5675
5676         /* Set the bonding mode for the relevant port. */
5677         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5678                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5679                                 port_id);
5680         }
5681 }
5682
5683 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5684 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5685                 set, "set");
5686 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5687 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5688                 bonding, "bonding");
5689 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5690 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5691                 balance_xmit_policy, "balance_xmit_policy");
5692 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5693 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5694                 port_id, UINT16);
5695 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5696 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5697                 policy, "l2#l23#l34");
5698
5699 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5700                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5701                 .help_str = "set bonding balance_xmit_policy <port_id> "
5702                         "l2|l23|l34: "
5703                         "Set the bonding balance_xmit_policy for port_id",
5704                 .data = NULL,
5705                 .tokens = {
5706                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5707                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5708                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5709                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5710                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5711                                 NULL
5712                 }
5713 };
5714
5715 /* *** SHOW NIC BONDING CONFIGURATION *** */
5716 struct cmd_show_bonding_config_result {
5717         cmdline_fixed_string_t show;
5718         cmdline_fixed_string_t bonding;
5719         cmdline_fixed_string_t config;
5720         portid_t port_id;
5721 };
5722
5723 static void cmd_show_bonding_config_parsed(void *parsed_result,
5724                 __attribute__((unused))  struct cmdline *cl,
5725                 __attribute__((unused)) void *data)
5726 {
5727         struct cmd_show_bonding_config_result *res = parsed_result;
5728         int bonding_mode, agg_mode;
5729         portid_t slaves[RTE_MAX_ETHPORTS];
5730         int num_slaves, num_active_slaves;
5731         int primary_id;
5732         int i;
5733         portid_t port_id = res->port_id;
5734
5735         /* Display the bonding mode.*/
5736         bonding_mode = rte_eth_bond_mode_get(port_id);
5737         if (bonding_mode < 0) {
5738                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5739                 return;
5740         } else
5741                 printf("\tBonding mode: %d\n", bonding_mode);
5742
5743         if (bonding_mode == BONDING_MODE_BALANCE) {
5744                 int balance_xmit_policy;
5745
5746                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5747                 if (balance_xmit_policy < 0) {
5748                         printf("\tFailed to get balance xmit policy for port = %d\n",
5749                                         port_id);
5750                         return;
5751                 } else {
5752                         printf("\tBalance Xmit Policy: ");
5753
5754                         switch (balance_xmit_policy) {
5755                         case BALANCE_XMIT_POLICY_LAYER2:
5756                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5757                                 break;
5758                         case BALANCE_XMIT_POLICY_LAYER23:
5759                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5760                                 break;
5761                         case BALANCE_XMIT_POLICY_LAYER34:
5762                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5763                                 break;
5764                         }
5765                         printf("\n");
5766                 }
5767         }
5768
5769         if (bonding_mode == BONDING_MODE_8023AD) {
5770                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5771                 printf("\tIEEE802.3AD Aggregator Mode: ");
5772                 switch (agg_mode) {
5773                 case AGG_BANDWIDTH:
5774                         printf("bandwidth");
5775                         break;
5776                 case AGG_STABLE:
5777                         printf("stable");
5778                         break;
5779                 case AGG_COUNT:
5780                         printf("count");
5781                         break;
5782                 }
5783                 printf("\n");
5784         }
5785
5786         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5787
5788         if (num_slaves < 0) {
5789                 printf("\tFailed to get slave list for port = %d\n", port_id);
5790                 return;
5791         }
5792         if (num_slaves > 0) {
5793                 printf("\tSlaves (%d): [", num_slaves);
5794                 for (i = 0; i < num_slaves - 1; i++)
5795                         printf("%d ", slaves[i]);
5796
5797                 printf("%d]\n", slaves[num_slaves - 1]);
5798         } else {
5799                 printf("\tSlaves: []\n");
5800
5801         }
5802
5803         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5804                         RTE_MAX_ETHPORTS);
5805
5806         if (num_active_slaves < 0) {
5807                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5808                 return;
5809         }
5810         if (num_active_slaves > 0) {
5811                 printf("\tActive Slaves (%d): [", num_active_slaves);
5812                 for (i = 0; i < num_active_slaves - 1; i++)
5813                         printf("%d ", slaves[i]);
5814
5815                 printf("%d]\n", slaves[num_active_slaves - 1]);
5816
5817         } else {
5818                 printf("\tActive Slaves: []\n");
5819
5820         }
5821
5822         primary_id = rte_eth_bond_primary_get(port_id);
5823         if (primary_id < 0) {
5824                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5825                 return;
5826         } else
5827                 printf("\tPrimary: [%d]\n", primary_id);
5828
5829 }
5830
5831 cmdline_parse_token_string_t cmd_showbonding_config_show =
5832 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5833                 show, "show");
5834 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5835 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5836                 bonding, "bonding");
5837 cmdline_parse_token_string_t cmd_showbonding_config_config =
5838 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5839                 config, "config");
5840 cmdline_parse_token_num_t cmd_showbonding_config_port =
5841 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5842                 port_id, UINT16);
5843
5844 cmdline_parse_inst_t cmd_show_bonding_config = {
5845                 .f = cmd_show_bonding_config_parsed,
5846                 .help_str = "show bonding config <port_id>: "
5847                         "Show the bonding config for port_id",
5848                 .data = NULL,
5849                 .tokens = {
5850                                 (void *)&cmd_showbonding_config_show,
5851                                 (void *)&cmd_showbonding_config_bonding,
5852                                 (void *)&cmd_showbonding_config_config,
5853                                 (void *)&cmd_showbonding_config_port,
5854                                 NULL
5855                 }
5856 };
5857
5858 /* *** SET BONDING PRIMARY *** */
5859 struct cmd_set_bonding_primary_result {
5860         cmdline_fixed_string_t set;
5861         cmdline_fixed_string_t bonding;
5862         cmdline_fixed_string_t primary;
5863         portid_t slave_id;
5864         portid_t port_id;
5865 };
5866
5867 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5868                 __attribute__((unused))  struct cmdline *cl,
5869                 __attribute__((unused)) void *data)
5870 {
5871         struct cmd_set_bonding_primary_result *res = parsed_result;
5872         portid_t master_port_id = res->port_id;
5873         portid_t slave_port_id = res->slave_id;
5874
5875         /* Set the primary slave for a bonded device. */
5876         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5877                 printf("\t Failed to set primary slave for port = %d.\n",
5878                                 master_port_id);
5879                 return;
5880         }
5881         init_port_config();
5882 }
5883
5884 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5885 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5886                 set, "set");
5887 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5888 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5889                 bonding, "bonding");
5890 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5891 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5892                 primary, "primary");
5893 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5894 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5895                 slave_id, UINT16);
5896 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5897 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5898                 port_id, UINT16);
5899
5900 cmdline_parse_inst_t cmd_set_bonding_primary = {
5901                 .f = cmd_set_bonding_primary_parsed,
5902                 .help_str = "set bonding primary <slave_id> <port_id>: "
5903                         "Set the primary slave for port_id",
5904                 .data = NULL,
5905                 .tokens = {
5906                                 (void *)&cmd_setbonding_primary_set,
5907                                 (void *)&cmd_setbonding_primary_bonding,
5908                                 (void *)&cmd_setbonding_primary_primary,
5909                                 (void *)&cmd_setbonding_primary_slave,
5910                                 (void *)&cmd_setbonding_primary_port,
5911                                 NULL
5912                 }
5913 };
5914
5915 /* *** ADD SLAVE *** */
5916 struct cmd_add_bonding_slave_result {
5917         cmdline_fixed_string_t add;
5918         cmdline_fixed_string_t bonding;
5919         cmdline_fixed_string_t slave;
5920         portid_t slave_id;
5921         portid_t port_id;
5922 };
5923
5924 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5925                 __attribute__((unused))  struct cmdline *cl,
5926                 __attribute__((unused)) void *data)
5927 {
5928         struct cmd_add_bonding_slave_result *res = parsed_result;
5929         portid_t master_port_id = res->port_id;
5930         portid_t slave_port_id = res->slave_id;
5931
5932         /* add the slave for a bonded device. */
5933         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5934                 printf("\t Failed to add slave %d to master port = %d.\n",
5935                                 slave_port_id, master_port_id);
5936                 return;
5937         }
5938         init_port_config();
5939         set_port_slave_flag(slave_port_id);
5940 }
5941
5942 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5943 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5944                 add, "add");
5945 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5946 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5947                 bonding, "bonding");
5948 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5949 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5950                 slave, "slave");
5951 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5952 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5953                 slave_id, UINT16);
5954 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5955 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5956                 port_id, UINT16);
5957
5958 cmdline_parse_inst_t cmd_add_bonding_slave = {
5959                 .f = cmd_add_bonding_slave_parsed,
5960                 .help_str = "add bonding slave <slave_id> <port_id>: "
5961                         "Add a slave device to a bonded device",
5962                 .data = NULL,
5963                 .tokens = {
5964                                 (void *)&cmd_addbonding_slave_add,
5965                                 (void *)&cmd_addbonding_slave_bonding,
5966                                 (void *)&cmd_addbonding_slave_slave,
5967                                 (void *)&cmd_addbonding_slave_slaveid,
5968                                 (void *)&cmd_addbonding_slave_port,
5969                                 NULL
5970                 }
5971 };
5972
5973 /* *** REMOVE SLAVE *** */
5974 struct cmd_remove_bonding_slave_result {
5975         cmdline_fixed_string_t remove;
5976         cmdline_fixed_string_t bonding;
5977         cmdline_fixed_string_t slave;
5978         portid_t slave_id;
5979         portid_t port_id;
5980 };
5981
5982 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5983                 __attribute__((unused))  struct cmdline *cl,
5984                 __attribute__((unused)) void *data)
5985 {
5986         struct cmd_remove_bonding_slave_result *res = parsed_result;
5987         portid_t master_port_id = res->port_id;
5988         portid_t slave_port_id = res->slave_id;
5989
5990         /* remove the slave from a bonded device. */
5991         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5992                 printf("\t Failed to remove slave %d from master port = %d.\n",
5993                                 slave_port_id, master_port_id);
5994                 return;
5995         }
5996         init_port_config();
5997         clear_port_slave_flag(slave_port_id);
5998 }
5999
6000 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6001                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6002                                 remove, "remove");
6003 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6004                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6005                                 bonding, "bonding");
6006 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6007                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6008                                 slave, "slave");
6009 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6010                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6011                                 slave_id, UINT16);
6012 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6013                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6014                                 port_id, UINT16);
6015
6016 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6017                 .f = cmd_remove_bonding_slave_parsed,
6018                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6019                         "Remove a slave device from a bonded device",
6020                 .data = NULL,
6021                 .tokens = {
6022                                 (void *)&cmd_removebonding_slave_remove,
6023                                 (void *)&cmd_removebonding_slave_bonding,
6024                                 (void *)&cmd_removebonding_slave_slave,
6025                                 (void *)&cmd_removebonding_slave_slaveid,
6026                                 (void *)&cmd_removebonding_slave_port,
6027                                 NULL
6028                 }
6029 };
6030
6031 /* *** CREATE BONDED DEVICE *** */
6032 struct cmd_create_bonded_device_result {
6033         cmdline_fixed_string_t create;
6034         cmdline_fixed_string_t bonded;
6035         cmdline_fixed_string_t device;
6036         uint8_t mode;
6037         uint8_t socket;
6038 };
6039
6040 static int bond_dev_num = 0;
6041
6042 static void cmd_create_bonded_device_parsed(void *parsed_result,
6043                 __attribute__((unused))  struct cmdline *cl,
6044                 __attribute__((unused)) void *data)
6045 {
6046         struct cmd_create_bonded_device_result *res = parsed_result;
6047         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6048         int port_id;
6049
6050         if (test_done == 0) {
6051                 printf("Please stop forwarding first\n");
6052                 return;
6053         }
6054
6055         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6056                         bond_dev_num++);
6057
6058         /* Create a new bonded device. */
6059         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6060         if (port_id < 0) {
6061                 printf("\t Failed to create bonded device.\n");
6062                 return;
6063         } else {
6064                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6065                                 port_id);
6066
6067                 /* Update number of ports */
6068                 nb_ports = rte_eth_dev_count_avail();
6069                 reconfig(port_id, res->socket);
6070                 rte_eth_promiscuous_enable(port_id);
6071                 ports[port_id].need_setup = 0;
6072                 ports[port_id].port_status = RTE_PORT_STOPPED;
6073         }
6074
6075 }
6076
6077 cmdline_parse_token_string_t cmd_createbonded_device_create =
6078                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6079                                 create, "create");
6080 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6081                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6082                                 bonded, "bonded");
6083 cmdline_parse_token_string_t cmd_createbonded_device_device =
6084                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6085                                 device, "device");
6086 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6087                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6088                                 mode, UINT8);
6089 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6090                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6091                                 socket, UINT8);
6092
6093 cmdline_parse_inst_t cmd_create_bonded_device = {
6094                 .f = cmd_create_bonded_device_parsed,
6095                 .help_str = "create bonded device <mode> <socket>: "
6096                         "Create a new bonded device with specific bonding mode and socket",
6097                 .data = NULL,
6098                 .tokens = {
6099                                 (void *)&cmd_createbonded_device_create,
6100                                 (void *)&cmd_createbonded_device_bonded,
6101                                 (void *)&cmd_createbonded_device_device,
6102                                 (void *)&cmd_createbonded_device_mode,
6103                                 (void *)&cmd_createbonded_device_socket,
6104                                 NULL
6105                 }
6106 };
6107
6108 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6109 struct cmd_set_bond_mac_addr_result {
6110         cmdline_fixed_string_t set;
6111         cmdline_fixed_string_t bonding;
6112         cmdline_fixed_string_t mac_addr;
6113         uint16_t port_num;
6114         struct rte_ether_addr address;
6115 };
6116
6117 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6118                 __attribute__((unused))  struct cmdline *cl,
6119                 __attribute__((unused)) void *data)
6120 {
6121         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6122         int ret;
6123
6124         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6125                 return;
6126
6127         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6128
6129         /* check the return value and print it if is < 0 */
6130         if (ret < 0)
6131                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6132 }
6133
6134 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6135                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6136 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6137                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6138                                 "bonding");
6139 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6140                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6141                                 "mac_addr");
6142 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6143                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6144                                 port_num, UINT16);
6145 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6146                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6147
6148 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6149                 .f = cmd_set_bond_mac_addr_parsed,
6150                 .data = (void *) 0,
6151                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6152                 .tokens = {
6153                                 (void *)&cmd_set_bond_mac_addr_set,
6154                                 (void *)&cmd_set_bond_mac_addr_bonding,
6155                                 (void *)&cmd_set_bond_mac_addr_mac,
6156                                 (void *)&cmd_set_bond_mac_addr_portnum,
6157                                 (void *)&cmd_set_bond_mac_addr_addr,
6158                                 NULL
6159                 }
6160 };
6161
6162
6163 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6164 struct cmd_set_bond_mon_period_result {
6165         cmdline_fixed_string_t set;
6166         cmdline_fixed_string_t bonding;
6167         cmdline_fixed_string_t mon_period;
6168         uint16_t port_num;
6169         uint32_t period_ms;
6170 };
6171
6172 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6173                 __attribute__((unused))  struct cmdline *cl,
6174                 __attribute__((unused)) void *data)
6175 {
6176         struct cmd_set_bond_mon_period_result *res = parsed_result;
6177         int ret;
6178
6179         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6180
6181         /* check the return value and print it if is < 0 */
6182         if (ret < 0)
6183                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6184 }
6185
6186 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6187                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6188                                 set, "set");
6189 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6190                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6191                                 bonding, "bonding");
6192 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6193                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6194                                 mon_period,     "mon_period");
6195 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6196                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6197                                 port_num, UINT16);
6198 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6199                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6200                                 period_ms, UINT32);
6201
6202 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6203                 .f = cmd_set_bond_mon_period_parsed,
6204                 .data = (void *) 0,
6205                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6206                 .tokens = {
6207                                 (void *)&cmd_set_bond_mon_period_set,
6208                                 (void *)&cmd_set_bond_mon_period_bonding,
6209                                 (void *)&cmd_set_bond_mon_period_mon_period,
6210                                 (void *)&cmd_set_bond_mon_period_portnum,
6211                                 (void *)&cmd_set_bond_mon_period_period_ms,
6212                                 NULL
6213                 }
6214 };
6215
6216
6217
6218 struct cmd_set_bonding_agg_mode_policy_result {
6219         cmdline_fixed_string_t set;
6220         cmdline_fixed_string_t bonding;
6221         cmdline_fixed_string_t agg_mode;
6222         uint16_t port_num;
6223         cmdline_fixed_string_t policy;
6224 };
6225
6226
6227 static void
6228 cmd_set_bonding_agg_mode(void *parsed_result,
6229                 __attribute__((unused)) struct cmdline *cl,
6230                 __attribute__((unused)) void *data)
6231 {
6232         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6233         uint8_t policy = AGG_BANDWIDTH;
6234
6235         if (!strcmp(res->policy, "bandwidth"))
6236                 policy = AGG_BANDWIDTH;
6237         else if (!strcmp(res->policy, "stable"))
6238                 policy = AGG_STABLE;
6239         else if (!strcmp(res->policy, "count"))
6240                 policy = AGG_COUNT;
6241
6242         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6243 }
6244
6245
6246 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6247         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6248                                 set, "set");
6249 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6250         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6251                                 bonding, "bonding");
6252
6253 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6254         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6255                                 agg_mode, "agg_mode");
6256
6257 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6258         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6259                                 port_num, UINT16);
6260
6261 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6262         TOKEN_STRING_INITIALIZER(
6263                         struct cmd_set_bonding_balance_xmit_policy_result,
6264                 policy, "stable#bandwidth#count");
6265
6266 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6267         .f = cmd_set_bonding_agg_mode,
6268         .data = (void *) 0,
6269         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6270         .tokens = {
6271                         (void *)&cmd_set_bonding_agg_mode_set,
6272                         (void *)&cmd_set_bonding_agg_mode_bonding,
6273                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6274                         (void *)&cmd_set_bonding_agg_mode_portnum,
6275                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6276                         NULL
6277                 }
6278 };
6279
6280
6281 #endif /* RTE_LIBRTE_PMD_BOND */
6282
6283 /* *** SET FORWARDING MODE *** */
6284 struct cmd_set_fwd_mode_result {
6285         cmdline_fixed_string_t set;
6286         cmdline_fixed_string_t fwd;
6287         cmdline_fixed_string_t mode;
6288 };
6289
6290 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6291                                     __attribute__((unused)) struct cmdline *cl,
6292                                     __attribute__((unused)) void *data)
6293 {
6294         struct cmd_set_fwd_mode_result *res = parsed_result;
6295
6296         retry_enabled = 0;
6297         set_pkt_forwarding_mode(res->mode);
6298 }
6299
6300 cmdline_parse_token_string_t cmd_setfwd_set =
6301         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6302 cmdline_parse_token_string_t cmd_setfwd_fwd =
6303         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6304 cmdline_parse_token_string_t cmd_setfwd_mode =
6305         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6306                 "" /* defined at init */);
6307
6308 cmdline_parse_inst_t cmd_set_fwd_mode = {
6309         .f = cmd_set_fwd_mode_parsed,
6310         .data = NULL,
6311         .help_str = NULL, /* defined at init */
6312         .tokens = {
6313                 (void *)&cmd_setfwd_set,
6314                 (void *)&cmd_setfwd_fwd,
6315                 (void *)&cmd_setfwd_mode,
6316                 NULL,
6317         },
6318 };
6319
6320 static void cmd_set_fwd_mode_init(void)
6321 {
6322         char *modes, *c;
6323         static char token[128];
6324         static char help[256];
6325         cmdline_parse_token_string_t *token_struct;
6326
6327         modes = list_pkt_forwarding_modes();
6328         snprintf(help, sizeof(help), "set fwd %s: "
6329                 "Set packet forwarding mode", modes);
6330         cmd_set_fwd_mode.help_str = help;
6331
6332         /* string token separator is # */
6333         for (c = token; *modes != '\0'; modes++)
6334                 if (*modes == '|')
6335                         *c++ = '#';
6336                 else
6337                         *c++ = *modes;
6338         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6339         token_struct->string_data.str = token;
6340 }
6341
6342 /* *** SET RETRY FORWARDING MODE *** */
6343 struct cmd_set_fwd_retry_mode_result {
6344         cmdline_fixed_string_t set;
6345         cmdline_fixed_string_t fwd;
6346         cmdline_fixed_string_t mode;
6347         cmdline_fixed_string_t retry;
6348 };
6349
6350 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6351                             __attribute__((unused)) struct cmdline *cl,
6352                             __attribute__((unused)) void *data)
6353 {
6354         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6355
6356         retry_enabled = 1;
6357         set_pkt_forwarding_mode(res->mode);
6358 }
6359
6360 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6361         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6362                         set, "set");
6363 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6364         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6365                         fwd, "fwd");
6366 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6367         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6368                         mode,
6369                 "" /* defined at init */);
6370 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6371         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6372                         retry, "retry");
6373
6374 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6375         .f = cmd_set_fwd_retry_mode_parsed,
6376         .data = NULL,
6377         .help_str = NULL, /* defined at init */
6378         .tokens = {
6379                 (void *)&cmd_setfwd_retry_set,
6380                 (void *)&cmd_setfwd_retry_fwd,
6381                 (void *)&cmd_setfwd_retry_mode,
6382                 (void *)&cmd_setfwd_retry_retry,
6383                 NULL,
6384         },
6385 };
6386
6387 static void cmd_set_fwd_retry_mode_init(void)
6388 {
6389         char *modes, *c;
6390         static char token[128];
6391         static char help[256];
6392         cmdline_parse_token_string_t *token_struct;
6393
6394         modes = list_pkt_forwarding_retry_modes();
6395         snprintf(help, sizeof(help), "set fwd %s retry: "
6396                 "Set packet forwarding mode with retry", modes);
6397         cmd_set_fwd_retry_mode.help_str = help;
6398
6399         /* string token separator is # */
6400         for (c = token; *modes != '\0'; modes++)
6401                 if (*modes == '|')
6402                         *c++ = '#';
6403                 else
6404                         *c++ = *modes;
6405         token_struct = (cmdline_parse_token_string_t *)
6406                 cmd_set_fwd_retry_mode.tokens[2];
6407         token_struct->string_data.str = token;
6408 }
6409
6410 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6411 struct cmd_set_burst_tx_retry_result {
6412         cmdline_fixed_string_t set;
6413         cmdline_fixed_string_t burst;
6414         cmdline_fixed_string_t tx;
6415         cmdline_fixed_string_t delay;
6416         uint32_t time;
6417         cmdline_fixed_string_t retry;
6418         uint32_t retry_num;
6419 };
6420
6421 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6422                                         __attribute__((unused)) struct cmdline *cl,
6423                                         __attribute__((unused)) void *data)
6424 {
6425         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6426
6427         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6428                 && !strcmp(res->tx, "tx")) {
6429                 if (!strcmp(res->delay, "delay"))
6430                         burst_tx_delay_time = res->time;
6431                 if (!strcmp(res->retry, "retry"))
6432                         burst_tx_retry_num = res->retry_num;
6433         }
6434
6435 }
6436
6437 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6438         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6439 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6440         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6441                                  "burst");
6442 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6443         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6444 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6445         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6446 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6447         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6448 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6449         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6450 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6451         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6452
6453 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6454         .f = cmd_set_burst_tx_retry_parsed,
6455         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6456         .tokens = {
6457                 (void *)&cmd_set_burst_tx_retry_set,
6458                 (void *)&cmd_set_burst_tx_retry_burst,
6459                 (void *)&cmd_set_burst_tx_retry_tx,
6460                 (void *)&cmd_set_burst_tx_retry_delay,
6461                 (void *)&cmd_set_burst_tx_retry_time,
6462                 (void *)&cmd_set_burst_tx_retry_retry,
6463                 (void *)&cmd_set_burst_tx_retry_retry_num,
6464                 NULL,
6465         },
6466 };
6467
6468 /* *** SET PROMISC MODE *** */
6469 struct cmd_set_promisc_mode_result {
6470         cmdline_fixed_string_t set;
6471         cmdline_fixed_string_t promisc;
6472         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6473         uint16_t port_num;               /* valid if "allports" argument == 0 */
6474         cmdline_fixed_string_t mode;
6475 };
6476
6477 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6478                                         __attribute__((unused)) struct cmdline *cl,
6479                                         void *allports)
6480 {
6481         struct cmd_set_promisc_mode_result *res = parsed_result;
6482         int enable;
6483         portid_t i;
6484
6485         if (!strcmp(res->mode, "on"))
6486                 enable = 1;
6487         else
6488                 enable = 0;
6489
6490         /* all ports */
6491         if (allports) {
6492                 RTE_ETH_FOREACH_DEV(i) {
6493                         if (enable)
6494                                 rte_eth_promiscuous_enable(i);
6495                         else
6496                                 rte_eth_promiscuous_disable(i);
6497                 }
6498         }
6499         else {
6500                 if (enable)
6501                         rte_eth_promiscuous_enable(res->port_num);
6502                 else
6503                         rte_eth_promiscuous_disable(res->port_num);
6504         }
6505 }
6506
6507 cmdline_parse_token_string_t cmd_setpromisc_set =
6508         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6509 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6510         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6511                                  "promisc");
6512 cmdline_parse_token_string_t cmd_setpromisc_portall =
6513         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6514                                  "all");
6515 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6516         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6517                               UINT16);
6518 cmdline_parse_token_string_t cmd_setpromisc_mode =
6519         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6520                                  "on#off");
6521
6522 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6523         .f = cmd_set_promisc_mode_parsed,
6524         .data = (void *)1,
6525         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6526         .tokens = {
6527                 (void *)&cmd_setpromisc_set,
6528                 (void *)&cmd_setpromisc_promisc,
6529                 (void *)&cmd_setpromisc_portall,
6530                 (void *)&cmd_setpromisc_mode,
6531                 NULL,
6532         },
6533 };
6534
6535 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6536         .f = cmd_set_promisc_mode_parsed,
6537         .data = (void *)0,
6538         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6539         .tokens = {
6540                 (void *)&cmd_setpromisc_set,
6541                 (void *)&cmd_setpromisc_promisc,
6542                 (void *)&cmd_setpromisc_portnum,
6543                 (void *)&cmd_setpromisc_mode,
6544                 NULL,
6545         },
6546 };
6547
6548 /* *** SET ALLMULTI MODE *** */
6549 struct cmd_set_allmulti_mode_result {
6550         cmdline_fixed_string_t set;
6551         cmdline_fixed_string_t allmulti;
6552         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6553         uint16_t port_num;               /* valid if "allports" argument == 0 */
6554         cmdline_fixed_string_t mode;
6555 };
6556
6557 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6558                                         __attribute__((unused)) struct cmdline *cl,
6559                                         void *allports)
6560 {
6561         struct cmd_set_allmulti_mode_result *res = parsed_result;
6562         int enable;
6563         portid_t i;
6564
6565         if (!strcmp(res->mode, "on"))
6566                 enable = 1;
6567         else
6568                 enable = 0;
6569
6570         /* all ports */
6571         if (allports) {
6572                 RTE_ETH_FOREACH_DEV(i) {
6573                         if (enable)
6574                                 rte_eth_allmulticast_enable(i);
6575                         else
6576                                 rte_eth_allmulticast_disable(i);
6577                 }
6578         }
6579         else {
6580                 if (enable)
6581                         rte_eth_allmulticast_enable(res->port_num);
6582                 else
6583                         rte_eth_allmulticast_disable(res->port_num);
6584         }
6585 }
6586
6587 cmdline_parse_token_string_t cmd_setallmulti_set =
6588         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6589 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6590         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6591                                  "allmulti");
6592 cmdline_parse_token_string_t cmd_setallmulti_portall =
6593         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6594                                  "all");
6595 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6596         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6597                               UINT16);
6598 cmdline_parse_token_string_t cmd_setallmulti_mode =
6599         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6600                                  "on#off");
6601
6602 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6603         .f = cmd_set_allmulti_mode_parsed,
6604         .data = (void *)1,
6605         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6606         .tokens = {
6607                 (void *)&cmd_setallmulti_set,
6608                 (void *)&cmd_setallmulti_allmulti,
6609                 (void *)&cmd_setallmulti_portall,
6610                 (void *)&cmd_setallmulti_mode,
6611                 NULL,
6612         },
6613 };
6614
6615 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6616         .f = cmd_set_allmulti_mode_parsed,
6617         .data = (void *)0,
6618         .help_str = "set allmulti <port_id> on|off: "
6619                 "Set allmulti mode on port_id",
6620         .tokens = {
6621                 (void *)&cmd_setallmulti_set,
6622                 (void *)&cmd_setallmulti_allmulti,
6623                 (void *)&cmd_setallmulti_portnum,
6624                 (void *)&cmd_setallmulti_mode,
6625                 NULL,
6626         },
6627 };
6628
6629 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6630 struct cmd_link_flow_ctrl_set_result {
6631         cmdline_fixed_string_t set;
6632         cmdline_fixed_string_t flow_ctrl;
6633         cmdline_fixed_string_t rx;
6634         cmdline_fixed_string_t rx_lfc_mode;
6635         cmdline_fixed_string_t tx;
6636         cmdline_fixed_string_t tx_lfc_mode;
6637         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6638         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6639         cmdline_fixed_string_t autoneg_str;
6640         cmdline_fixed_string_t autoneg;
6641         cmdline_fixed_string_t hw_str;
6642         uint32_t high_water;
6643         cmdline_fixed_string_t lw_str;
6644         uint32_t low_water;
6645         cmdline_fixed_string_t pt_str;
6646         uint16_t pause_time;
6647         cmdline_fixed_string_t xon_str;
6648         uint16_t send_xon;
6649         portid_t port_id;
6650 };
6651
6652 cmdline_parse_token_string_t cmd_lfc_set_set =
6653         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6654                                 set, "set");
6655 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6656         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6657                                 flow_ctrl, "flow_ctrl");
6658 cmdline_parse_token_string_t cmd_lfc_set_rx =
6659         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6660                                 rx, "rx");
6661 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6662         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6663                                 rx_lfc_mode, "on#off");
6664 cmdline_parse_token_string_t cmd_lfc_set_tx =
6665         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6666                                 tx, "tx");
6667 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6668         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6669                                 tx_lfc_mode, "on#off");
6670 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6671         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6672                                 hw_str, "high_water");
6673 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6674         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6675                                 high_water, UINT32);
6676 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6677         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6678                                 lw_str, "low_water");
6679 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6680         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6681                                 low_water, UINT32);
6682 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6683         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6684                                 pt_str, "pause_time");
6685 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6686         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6687                                 pause_time, UINT16);
6688 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6689         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6690                                 xon_str, "send_xon");
6691 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6692         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6693                                 send_xon, UINT16);
6694 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6695         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6696                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6697 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6698         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6699                                 mac_ctrl_frame_fwd_mode, "on#off");
6700 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6701         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6702                                 autoneg_str, "autoneg");
6703 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6704         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6705                                 autoneg, "on#off");
6706 cmdline_parse_token_num_t cmd_lfc_set_portid =
6707         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6708                                 port_id, UINT16);
6709
6710 /* forward declaration */
6711 static void
6712 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6713                               void *data);
6714
6715 cmdline_parse_inst_t cmd_link_flow_control_set = {
6716         .f = cmd_link_flow_ctrl_set_parsed,
6717         .data = NULL,
6718         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6719                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6720                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6721         .tokens = {
6722                 (void *)&cmd_lfc_set_set,
6723                 (void *)&cmd_lfc_set_flow_ctrl,
6724                 (void *)&cmd_lfc_set_rx,
6725                 (void *)&cmd_lfc_set_rx_mode,
6726                 (void *)&cmd_lfc_set_tx,
6727                 (void *)&cmd_lfc_set_tx_mode,
6728                 (void *)&cmd_lfc_set_high_water,
6729                 (void *)&cmd_lfc_set_low_water,
6730                 (void *)&cmd_lfc_set_pause_time,
6731                 (void *)&cmd_lfc_set_send_xon,
6732                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6733                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6734                 (void *)&cmd_lfc_set_autoneg_str,
6735                 (void *)&cmd_lfc_set_autoneg,
6736                 (void *)&cmd_lfc_set_portid,
6737                 NULL,
6738         },
6739 };
6740
6741 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6742         .f = cmd_link_flow_ctrl_set_parsed,
6743         .data = (void *)&cmd_link_flow_control_set_rx,
6744         .help_str = "set flow_ctrl rx on|off <port_id>: "
6745                 "Change rx flow control parameter",
6746         .tokens = {
6747                 (void *)&cmd_lfc_set_set,
6748                 (void *)&cmd_lfc_set_flow_ctrl,
6749                 (void *)&cmd_lfc_set_rx,
6750                 (void *)&cmd_lfc_set_rx_mode,
6751                 (void *)&cmd_lfc_set_portid,
6752                 NULL,
6753         },
6754 };
6755
6756 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6757         .f = cmd_link_flow_ctrl_set_parsed,
6758         .data = (void *)&cmd_link_flow_control_set_tx,
6759         .help_str = "set flow_ctrl tx on|off <port_id>: "
6760                 "Change tx flow control parameter",
6761         .tokens = {
6762                 (void *)&cmd_lfc_set_set,
6763                 (void *)&cmd_lfc_set_flow_ctrl,
6764                 (void *)&cmd_lfc_set_tx,
6765                 (void *)&cmd_lfc_set_tx_mode,
6766                 (void *)&cmd_lfc_set_portid,
6767                 NULL,
6768         },
6769 };
6770
6771 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6772         .f = cmd_link_flow_ctrl_set_parsed,
6773         .data = (void *)&cmd_link_flow_control_set_hw,
6774         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6775                 "Change high water flow control parameter",
6776         .tokens = {
6777                 (void *)&cmd_lfc_set_set,
6778                 (void *)&cmd_lfc_set_flow_ctrl,
6779                 (void *)&cmd_lfc_set_high_water_str,
6780                 (void *)&cmd_lfc_set_high_water,
6781                 (void *)&cmd_lfc_set_portid,
6782                 NULL,
6783         },
6784 };
6785
6786 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6787         .f = cmd_link_flow_ctrl_set_parsed,
6788         .data = (void *)&cmd_link_flow_control_set_lw,
6789         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6790                 "Change low water flow control parameter",
6791         .tokens = {
6792                 (void *)&cmd_lfc_set_set,
6793                 (void *)&cmd_lfc_set_flow_ctrl,
6794                 (void *)&cmd_lfc_set_low_water_str,
6795                 (void *)&cmd_lfc_set_low_water,
6796                 (void *)&cmd_lfc_set_portid,
6797                 NULL,
6798         },
6799 };
6800
6801 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6802         .f = cmd_link_flow_ctrl_set_parsed,
6803         .data = (void *)&cmd_link_flow_control_set_pt,
6804         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6805                 "Change pause time flow control parameter",
6806         .tokens = {
6807                 (void *)&cmd_lfc_set_set,
6808                 (void *)&cmd_lfc_set_flow_ctrl,
6809                 (void *)&cmd_lfc_set_pause_time_str,
6810                 (void *)&cmd_lfc_set_pause_time,
6811                 (void *)&cmd_lfc_set_portid,
6812                 NULL,
6813         },
6814 };
6815
6816 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6817         .f = cmd_link_flow_ctrl_set_parsed,
6818         .data = (void *)&cmd_link_flow_control_set_xon,
6819         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6820                 "Change send_xon flow control parameter",
6821         .tokens = {
6822                 (void *)&cmd_lfc_set_set,
6823                 (void *)&cmd_lfc_set_flow_ctrl,
6824                 (void *)&cmd_lfc_set_send_xon_str,
6825                 (void *)&cmd_lfc_set_send_xon,
6826                 (void *)&cmd_lfc_set_portid,
6827                 NULL,
6828         },
6829 };
6830
6831 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6832         .f = cmd_link_flow_ctrl_set_parsed,
6833         .data = (void *)&cmd_link_flow_control_set_macfwd,
6834         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6835                 "Change mac ctrl fwd flow control parameter",
6836         .tokens = {
6837                 (void *)&cmd_lfc_set_set,
6838                 (void *)&cmd_lfc_set_flow_ctrl,
6839                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6840                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6841                 (void *)&cmd_lfc_set_portid,
6842                 NULL,
6843         },
6844 };
6845
6846 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6847         .f = cmd_link_flow_ctrl_set_parsed,
6848         .data = (void *)&cmd_link_flow_control_set_autoneg,
6849         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6850                 "Change autoneg flow control parameter",
6851         .tokens = {
6852                 (void *)&cmd_lfc_set_set,
6853                 (void *)&cmd_lfc_set_flow_ctrl,
6854                 (void *)&cmd_lfc_set_autoneg_str,
6855                 (void *)&cmd_lfc_set_autoneg,
6856                 (void *)&cmd_lfc_set_portid,
6857                 NULL,
6858         },
6859 };
6860
6861 static void
6862 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6863                               __attribute__((unused)) struct cmdline *cl,
6864                               void *data)
6865 {
6866         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6867         cmdline_parse_inst_t *cmd = data;
6868         struct rte_eth_fc_conf fc_conf;
6869         int rx_fc_en = 0;
6870         int tx_fc_en = 0;
6871         int ret;
6872
6873         /*
6874          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6875          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6876          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6877          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6878          */
6879         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6880                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6881         };
6882
6883         /* Partial command line, retrieve current configuration */
6884         if (cmd) {
6885                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6886                 if (ret != 0) {
6887                         printf("cannot get current flow ctrl parameters, return"
6888                                "code = %d\n", ret);
6889                         return;
6890                 }
6891
6892                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6893                     (fc_conf.mode == RTE_FC_FULL))
6894                         rx_fc_en = 1;
6895                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6896                     (fc_conf.mode == RTE_FC_FULL))
6897                         tx_fc_en = 1;
6898         }
6899
6900         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6901                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6902
6903         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6904                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6905
6906         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6907
6908         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6909                 fc_conf.high_water = res->high_water;
6910
6911         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6912                 fc_conf.low_water = res->low_water;
6913
6914         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6915                 fc_conf.pause_time = res->pause_time;
6916
6917         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6918                 fc_conf.send_xon = res->send_xon;
6919
6920         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6921                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6922                         fc_conf.mac_ctrl_frame_fwd = 1;
6923                 else
6924                         fc_conf.mac_ctrl_frame_fwd = 0;
6925         }
6926
6927         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6928                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6929
6930         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6931         if (ret != 0)
6932                 printf("bad flow contrl parameter, return code = %d \n", ret);
6933 }
6934
6935 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6936 struct cmd_priority_flow_ctrl_set_result {
6937         cmdline_fixed_string_t set;
6938         cmdline_fixed_string_t pfc_ctrl;
6939         cmdline_fixed_string_t rx;
6940         cmdline_fixed_string_t rx_pfc_mode;
6941         cmdline_fixed_string_t tx;
6942         cmdline_fixed_string_t tx_pfc_mode;
6943         uint32_t high_water;
6944         uint32_t low_water;
6945         uint16_t pause_time;
6946         uint8_t  priority;
6947         portid_t port_id;
6948 };
6949
6950 static void
6951 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6952                        __attribute__((unused)) struct cmdline *cl,
6953                        __attribute__((unused)) void *data)
6954 {
6955         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6956         struct rte_eth_pfc_conf pfc_conf;
6957         int rx_fc_enable, tx_fc_enable;
6958         int ret;
6959
6960         /*
6961          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6962          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6963          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6964          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6965          */
6966         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6967                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6968         };
6969
6970         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6971         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6972         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6973         pfc_conf.fc.high_water = res->high_water;
6974         pfc_conf.fc.low_water  = res->low_water;
6975         pfc_conf.fc.pause_time = res->pause_time;
6976         pfc_conf.priority      = res->priority;
6977
6978         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6979         if (ret != 0)
6980                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6981 }
6982
6983 cmdline_parse_token_string_t cmd_pfc_set_set =
6984         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6985                                 set, "set");
6986 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6987         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6988                                 pfc_ctrl, "pfc_ctrl");
6989 cmdline_parse_token_string_t cmd_pfc_set_rx =
6990         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6991                                 rx, "rx");
6992 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6993         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6994                                 rx_pfc_mode, "on#off");
6995 cmdline_parse_token_string_t cmd_pfc_set_tx =
6996         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6997                                 tx, "tx");
6998 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6999         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7000                                 tx_pfc_mode, "on#off");
7001 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7002         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7003                                 high_water, UINT32);
7004 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7005         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7006                                 low_water, UINT32);
7007 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7008         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7009                                 pause_time, UINT16);
7010 cmdline_parse_token_num_t cmd_pfc_set_priority =
7011         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7012                                 priority, UINT8);
7013 cmdline_parse_token_num_t cmd_pfc_set_portid =
7014         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7015                                 port_id, UINT16);
7016
7017 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7018         .f = cmd_priority_flow_ctrl_set_parsed,
7019         .data = NULL,
7020         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7021                 "<pause_time> <priority> <port_id>: "
7022                 "Configure the Ethernet priority flow control",
7023         .tokens = {
7024                 (void *)&cmd_pfc_set_set,
7025                 (void *)&cmd_pfc_set_flow_ctrl,
7026                 (void *)&cmd_pfc_set_rx,
7027                 (void *)&cmd_pfc_set_rx_mode,
7028                 (void *)&cmd_pfc_set_tx,
7029                 (void *)&cmd_pfc_set_tx_mode,
7030                 (void *)&cmd_pfc_set_high_water,
7031                 (void *)&cmd_pfc_set_low_water,
7032                 (void *)&cmd_pfc_set_pause_time,
7033                 (void *)&cmd_pfc_set_priority,
7034                 (void *)&cmd_pfc_set_portid,
7035                 NULL,
7036         },
7037 };
7038
7039 /* *** RESET CONFIGURATION *** */
7040 struct cmd_reset_result {
7041         cmdline_fixed_string_t reset;
7042         cmdline_fixed_string_t def;
7043 };
7044
7045 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7046                              struct cmdline *cl,
7047                              __attribute__((unused)) void *data)
7048 {
7049         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7050         set_def_fwd_config();
7051 }
7052
7053 cmdline_parse_token_string_t cmd_reset_set =
7054         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7055 cmdline_parse_token_string_t cmd_reset_def =
7056         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7057                                  "default");
7058
7059 cmdline_parse_inst_t cmd_reset = {
7060         .f = cmd_reset_parsed,
7061         .data = NULL,
7062         .help_str = "set default: Reset default forwarding configuration",
7063         .tokens = {
7064                 (void *)&cmd_reset_set,
7065                 (void *)&cmd_reset_def,
7066                 NULL,
7067         },
7068 };
7069
7070 /* *** START FORWARDING *** */
7071 struct cmd_start_result {
7072         cmdline_fixed_string_t start;
7073 };
7074
7075 cmdline_parse_token_string_t cmd_start_start =
7076         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7077
7078 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7079                              __attribute__((unused)) struct cmdline *cl,
7080                              __attribute__((unused)) void *data)
7081 {
7082         start_packet_forwarding(0);
7083 }
7084
7085 cmdline_parse_inst_t cmd_start = {
7086         .f = cmd_start_parsed,
7087         .data = NULL,
7088         .help_str = "start: Start packet forwarding",
7089         .tokens = {
7090                 (void *)&cmd_start_start,
7091                 NULL,
7092         },
7093 };
7094
7095 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7096 struct cmd_start_tx_first_result {
7097         cmdline_fixed_string_t start;
7098         cmdline_fixed_string_t tx_first;
7099 };
7100
7101 static void
7102 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7103                           __attribute__((unused)) struct cmdline *cl,
7104                           __attribute__((unused)) void *data)
7105 {
7106         start_packet_forwarding(1);
7107 }
7108
7109 cmdline_parse_token_string_t cmd_start_tx_first_start =
7110         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7111                                  "start");
7112 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7113         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7114                                  tx_first, "tx_first");
7115
7116 cmdline_parse_inst_t cmd_start_tx_first = {
7117         .f = cmd_start_tx_first_parsed,
7118         .data = NULL,
7119         .help_str = "start tx_first: Start packet forwarding, "
7120                 "after sending 1 burst of packets",
7121         .tokens = {
7122                 (void *)&cmd_start_tx_first_start,
7123                 (void *)&cmd_start_tx_first_tx_first,
7124                 NULL,
7125         },
7126 };
7127
7128 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7129 struct cmd_start_tx_first_n_result {
7130         cmdline_fixed_string_t start;
7131         cmdline_fixed_string_t tx_first;
7132         uint32_t tx_num;
7133 };
7134
7135 static void
7136 cmd_start_tx_first_n_parsed(void *parsed_result,
7137                           __attribute__((unused)) struct cmdline *cl,
7138                           __attribute__((unused)) void *data)
7139 {
7140         struct cmd_start_tx_first_n_result *res = parsed_result;
7141
7142         start_packet_forwarding(res->tx_num);
7143 }
7144
7145 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7146         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7147                         start, "start");
7148 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7149         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7150                         tx_first, "tx_first");
7151 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7152         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7153                         tx_num, UINT32);
7154
7155 cmdline_parse_inst_t cmd_start_tx_first_n = {
7156         .f = cmd_start_tx_first_n_parsed,
7157         .data = NULL,
7158         .help_str = "start tx_first <num>: "
7159                 "packet forwarding, after sending <num> bursts of packets",
7160         .tokens = {
7161                 (void *)&cmd_start_tx_first_n_start,
7162                 (void *)&cmd_start_tx_first_n_tx_first,
7163                 (void *)&cmd_start_tx_first_n_tx_num,
7164                 NULL,
7165         },
7166 };
7167
7168 /* *** SET LINK UP *** */
7169 struct cmd_set_link_up_result {
7170         cmdline_fixed_string_t set;
7171         cmdline_fixed_string_t link_up;
7172         cmdline_fixed_string_t port;
7173         portid_t port_id;
7174 };
7175
7176 cmdline_parse_token_string_t cmd_set_link_up_set =
7177         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7178 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7179         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7180                                 "link-up");
7181 cmdline_parse_token_string_t cmd_set_link_up_port =
7182         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7183 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7184         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7185
7186 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7187                              __attribute__((unused)) struct cmdline *cl,
7188                              __attribute__((unused)) void *data)
7189 {
7190         struct cmd_set_link_up_result *res = parsed_result;
7191         dev_set_link_up(res->port_id);
7192 }
7193
7194 cmdline_parse_inst_t cmd_set_link_up = {
7195         .f = cmd_set_link_up_parsed,
7196         .data = NULL,
7197         .help_str = "set link-up port <port id>",
7198         .tokens = {
7199                 (void *)&cmd_set_link_up_set,
7200                 (void *)&cmd_set_link_up_link_up,
7201                 (void *)&cmd_set_link_up_port,
7202                 (void *)&cmd_set_link_up_port_id,
7203                 NULL,
7204         },
7205 };
7206
7207 /* *** SET LINK DOWN *** */
7208 struct cmd_set_link_down_result {
7209         cmdline_fixed_string_t set;
7210         cmdline_fixed_string_t link_down;
7211         cmdline_fixed_string_t port;
7212         portid_t port_id;
7213 };
7214
7215 cmdline_parse_token_string_t cmd_set_link_down_set =
7216         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7217 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7218         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7219                                 "link-down");
7220 cmdline_parse_token_string_t cmd_set_link_down_port =
7221         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7222 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7223         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7224
7225 static void cmd_set_link_down_parsed(
7226                                 __attribute__((unused)) void *parsed_result,
7227                                 __attribute__((unused)) struct cmdline *cl,
7228                                 __attribute__((unused)) void *data)
7229 {
7230         struct cmd_set_link_down_result *res = parsed_result;
7231         dev_set_link_down(res->port_id);
7232 }
7233
7234 cmdline_parse_inst_t cmd_set_link_down = {
7235         .f = cmd_set_link_down_parsed,
7236         .data = NULL,
7237         .help_str = "set link-down port <port id>",
7238         .tokens = {
7239                 (void *)&cmd_set_link_down_set,
7240                 (void *)&cmd_set_link_down_link_down,
7241                 (void *)&cmd_set_link_down_port,
7242                 (void *)&cmd_set_link_down_port_id,
7243                 NULL,
7244         },
7245 };
7246
7247 /* *** SHOW CFG *** */
7248 struct cmd_showcfg_result {
7249         cmdline_fixed_string_t show;
7250         cmdline_fixed_string_t cfg;
7251         cmdline_fixed_string_t what;
7252 };
7253
7254 static void cmd_showcfg_parsed(void *parsed_result,
7255                                __attribute__((unused)) struct cmdline *cl,
7256                                __attribute__((unused)) void *data)
7257 {
7258         struct cmd_showcfg_result *res = parsed_result;
7259         if (!strcmp(res->what, "rxtx"))
7260                 rxtx_config_display();
7261         else if (!strcmp(res->what, "cores"))
7262                 fwd_lcores_config_display();
7263         else if (!strcmp(res->what, "fwd"))
7264                 pkt_fwd_config_display(&cur_fwd_config);
7265         else if (!strcmp(res->what, "txpkts"))
7266                 show_tx_pkt_segments();
7267 }
7268
7269 cmdline_parse_token_string_t cmd_showcfg_show =
7270         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7271 cmdline_parse_token_string_t cmd_showcfg_port =
7272         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7273 cmdline_parse_token_string_t cmd_showcfg_what =
7274         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7275                                  "rxtx#cores#fwd#txpkts");
7276
7277 cmdline_parse_inst_t cmd_showcfg = {
7278         .f = cmd_showcfg_parsed,
7279         .data = NULL,
7280         .help_str = "show config rxtx|cores|fwd|txpkts",
7281         .tokens = {
7282                 (void *)&cmd_showcfg_show,
7283                 (void *)&cmd_showcfg_port,
7284                 (void *)&cmd_showcfg_what,
7285                 NULL,
7286         },
7287 };
7288
7289 /* *** SHOW ALL PORT INFO *** */
7290 struct cmd_showportall_result {
7291         cmdline_fixed_string_t show;
7292         cmdline_fixed_string_t port;
7293         cmdline_fixed_string_t what;
7294         cmdline_fixed_string_t all;
7295 };
7296
7297 static void cmd_showportall_parsed(void *parsed_result,
7298                                 __attribute__((unused)) struct cmdline *cl,
7299                                 __attribute__((unused)) void *data)
7300 {
7301         portid_t i;
7302
7303         struct cmd_showportall_result *res = parsed_result;
7304         if (!strcmp(res->show, "clear")) {
7305                 if (!strcmp(res->what, "stats"))
7306                         RTE_ETH_FOREACH_DEV(i)
7307                                 nic_stats_clear(i);
7308                 else if (!strcmp(res->what, "xstats"))
7309                         RTE_ETH_FOREACH_DEV(i)
7310                                 nic_xstats_clear(i);
7311         } else if (!strcmp(res->what, "info"))
7312                 RTE_ETH_FOREACH_DEV(i)
7313                         port_infos_display(i);
7314         else if (!strcmp(res->what, "summary")) {
7315                 port_summary_header_display();
7316                 RTE_ETH_FOREACH_DEV(i)
7317                         port_summary_display(i);
7318         }
7319         else if (!strcmp(res->what, "stats"))
7320                 RTE_ETH_FOREACH_DEV(i)
7321                         nic_stats_display(i);
7322         else if (!strcmp(res->what, "xstats"))
7323                 RTE_ETH_FOREACH_DEV(i)
7324                         nic_xstats_display(i);
7325         else if (!strcmp(res->what, "fdir"))
7326                 RTE_ETH_FOREACH_DEV(i)
7327                         fdir_get_infos(i);
7328         else if (!strcmp(res->what, "stat_qmap"))
7329                 RTE_ETH_FOREACH_DEV(i)
7330                         nic_stats_mapping_display(i);
7331         else if (!strcmp(res->what, "dcb_tc"))
7332                 RTE_ETH_FOREACH_DEV(i)
7333                         port_dcb_info_display(i);
7334         else if (!strcmp(res->what, "cap"))
7335                 RTE_ETH_FOREACH_DEV(i)
7336                         port_offload_cap_display(i);
7337 }
7338
7339 cmdline_parse_token_string_t cmd_showportall_show =
7340         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7341                                  "show#clear");
7342 cmdline_parse_token_string_t cmd_showportall_port =
7343         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7344 cmdline_parse_token_string_t cmd_showportall_what =
7345         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7346                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7347 cmdline_parse_token_string_t cmd_showportall_all =
7348         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7349 cmdline_parse_inst_t cmd_showportall = {
7350         .f = cmd_showportall_parsed,
7351         .data = NULL,
7352         .help_str = "show|clear port "
7353                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7354         .tokens = {
7355                 (void *)&cmd_showportall_show,
7356                 (void *)&cmd_showportall_port,
7357                 (void *)&cmd_showportall_what,
7358                 (void *)&cmd_showportall_all,
7359                 NULL,
7360         },
7361 };
7362
7363 /* *** SHOW PORT INFO *** */
7364 struct cmd_showport_result {
7365         cmdline_fixed_string_t show;
7366         cmdline_fixed_string_t port;
7367         cmdline_fixed_string_t what;
7368         uint16_t portnum;
7369 };
7370
7371 static void cmd_showport_parsed(void *parsed_result,
7372                                 __attribute__((unused)) struct cmdline *cl,
7373                                 __attribute__((unused)) void *data)
7374 {
7375         struct cmd_showport_result *res = parsed_result;
7376         if (!strcmp(res->show, "clear")) {
7377                 if (!strcmp(res->what, "stats"))
7378                         nic_stats_clear(res->portnum);
7379                 else if (!strcmp(res->what, "xstats"))
7380                         nic_xstats_clear(res->portnum);
7381         } else if (!strcmp(res->what, "info"))
7382                 port_infos_display(res->portnum);
7383         else if (!strcmp(res->what, "summary")) {
7384                 port_summary_header_display();
7385                 port_summary_display(res->portnum);
7386         }
7387         else if (!strcmp(res->what, "stats"))
7388                 nic_stats_display(res->portnum);
7389         else if (!strcmp(res->what, "xstats"))
7390                 nic_xstats_display(res->portnum);
7391         else if (!strcmp(res->what, "fdir"))
7392                  fdir_get_infos(res->portnum);
7393         else if (!strcmp(res->what, "stat_qmap"))
7394                 nic_stats_mapping_display(res->portnum);
7395         else if (!strcmp(res->what, "dcb_tc"))
7396                 port_dcb_info_display(res->portnum);
7397         else if (!strcmp(res->what, "cap"))
7398                 port_offload_cap_display(res->portnum);
7399 }
7400
7401 cmdline_parse_token_string_t cmd_showport_show =
7402         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7403                                  "show#clear");
7404 cmdline_parse_token_string_t cmd_showport_port =
7405         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7406 cmdline_parse_token_string_t cmd_showport_what =
7407         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7408                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7409 cmdline_parse_token_num_t cmd_showport_portnum =
7410         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7411
7412 cmdline_parse_inst_t cmd_showport = {
7413         .f = cmd_showport_parsed,
7414         .data = NULL,
7415         .help_str = "show|clear port "
7416                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7417                 "<port_id>",
7418         .tokens = {
7419                 (void *)&cmd_showport_show,
7420                 (void *)&cmd_showport_port,
7421                 (void *)&cmd_showport_what,
7422                 (void *)&cmd_showport_portnum,
7423                 NULL,
7424         },
7425 };
7426
7427 /* *** SHOW DEVICE INFO *** */
7428 struct cmd_showdevice_result {
7429         cmdline_fixed_string_t show;
7430         cmdline_fixed_string_t device;
7431         cmdline_fixed_string_t what;
7432         cmdline_fixed_string_t identifier;
7433 };
7434
7435 static void cmd_showdevice_parsed(void *parsed_result,
7436                                 __attribute__((unused)) struct cmdline *cl,
7437                                 __attribute__((unused)) void *data)
7438 {
7439         struct cmd_showdevice_result *res = parsed_result;
7440         if (!strcmp(res->what, "info")) {
7441                 if (!strcmp(res->identifier, "all"))
7442                         device_infos_display(NULL);
7443                 else
7444                         device_infos_display(res->identifier);
7445         }
7446 }
7447
7448 cmdline_parse_token_string_t cmd_showdevice_show =
7449         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7450                                  "show");
7451 cmdline_parse_token_string_t cmd_showdevice_device =
7452         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7453 cmdline_parse_token_string_t cmd_showdevice_what =
7454         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7455                                  "info");
7456 cmdline_parse_token_string_t cmd_showdevice_identifier =
7457         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7458                         identifier, NULL);
7459
7460 cmdline_parse_inst_t cmd_showdevice = {
7461         .f = cmd_showdevice_parsed,
7462         .data = NULL,
7463         .help_str = "show device info <identifier>|all",
7464         .tokens = {
7465                 (void *)&cmd_showdevice_show,
7466                 (void *)&cmd_showdevice_device,
7467                 (void *)&cmd_showdevice_what,
7468                 (void *)&cmd_showdevice_identifier,
7469                 NULL,
7470         },
7471 };
7472 /* *** SHOW QUEUE INFO *** */
7473 struct cmd_showqueue_result {
7474         cmdline_fixed_string_t show;
7475         cmdline_fixed_string_t type;
7476         cmdline_fixed_string_t what;
7477         uint16_t portnum;
7478         uint16_t queuenum;
7479 };
7480
7481 static void
7482 cmd_showqueue_parsed(void *parsed_result,
7483         __attribute__((unused)) struct cmdline *cl,
7484         __attribute__((unused)) void *data)
7485 {
7486         struct cmd_showqueue_result *res = parsed_result;
7487
7488         if (!strcmp(res->type, "rxq"))
7489                 rx_queue_infos_display(res->portnum, res->queuenum);
7490         else if (!strcmp(res->type, "txq"))
7491                 tx_queue_infos_display(res->portnum, res->queuenum);
7492 }
7493
7494 cmdline_parse_token_string_t cmd_showqueue_show =
7495         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7496 cmdline_parse_token_string_t cmd_showqueue_type =
7497         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7498 cmdline_parse_token_string_t cmd_showqueue_what =
7499         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7500 cmdline_parse_token_num_t cmd_showqueue_portnum =
7501         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7502 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7503         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7504
7505 cmdline_parse_inst_t cmd_showqueue = {
7506         .f = cmd_showqueue_parsed,
7507         .data = NULL,
7508         .help_str = "show rxq|txq info <port_id> <queue_id>",
7509         .tokens = {
7510                 (void *)&cmd_showqueue_show,
7511                 (void *)&cmd_showqueue_type,
7512                 (void *)&cmd_showqueue_what,
7513                 (void *)&cmd_showqueue_portnum,
7514                 (void *)&cmd_showqueue_queuenum,
7515                 NULL,
7516         },
7517 };
7518
7519 /* show/clear fwd engine statistics */
7520 struct fwd_result {
7521         cmdline_fixed_string_t action;
7522         cmdline_fixed_string_t fwd;
7523         cmdline_fixed_string_t stats;
7524         cmdline_fixed_string_t all;
7525 };
7526
7527 cmdline_parse_token_string_t cmd_fwd_action =
7528         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7529 cmdline_parse_token_string_t cmd_fwd_fwd =
7530         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7531 cmdline_parse_token_string_t cmd_fwd_stats =
7532         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7533 cmdline_parse_token_string_t cmd_fwd_all =
7534         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7535
7536 static void
7537 cmd_showfwdall_parsed(void *parsed_result,
7538                       __rte_unused struct cmdline *cl,
7539                       __rte_unused void *data)
7540 {
7541         struct fwd_result *res = parsed_result;
7542
7543         if (!strcmp(res->action, "show"))
7544                 fwd_stats_display();
7545         else
7546                 fwd_stats_reset();
7547 }
7548
7549 static cmdline_parse_inst_t cmd_showfwdall = {
7550         .f = cmd_showfwdall_parsed,
7551         .data = NULL,
7552         .help_str = "show|clear fwd stats all",
7553         .tokens = {
7554                 (void *)&cmd_fwd_action,
7555                 (void *)&cmd_fwd_fwd,
7556                 (void *)&cmd_fwd_stats,
7557                 (void *)&cmd_fwd_all,
7558                 NULL,
7559         },
7560 };
7561
7562 /* *** READ PORT REGISTER *** */
7563 struct cmd_read_reg_result {
7564         cmdline_fixed_string_t read;
7565         cmdline_fixed_string_t reg;
7566         portid_t port_id;
7567         uint32_t reg_off;
7568 };
7569
7570 static void
7571 cmd_read_reg_parsed(void *parsed_result,
7572                     __attribute__((unused)) struct cmdline *cl,
7573                     __attribute__((unused)) void *data)
7574 {
7575         struct cmd_read_reg_result *res = parsed_result;
7576         port_reg_display(res->port_id, res->reg_off);
7577 }
7578
7579 cmdline_parse_token_string_t cmd_read_reg_read =
7580         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7581 cmdline_parse_token_string_t cmd_read_reg_reg =
7582         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7583 cmdline_parse_token_num_t cmd_read_reg_port_id =
7584         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7585 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7586         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7587
7588 cmdline_parse_inst_t cmd_read_reg = {
7589         .f = cmd_read_reg_parsed,
7590         .data = NULL,
7591         .help_str = "read reg <port_id> <reg_off>",
7592         .tokens = {
7593                 (void *)&cmd_read_reg_read,
7594                 (void *)&cmd_read_reg_reg,
7595                 (void *)&cmd_read_reg_port_id,
7596                 (void *)&cmd_read_reg_reg_off,
7597                 NULL,
7598         },
7599 };
7600
7601 /* *** READ PORT REGISTER BIT FIELD *** */
7602 struct cmd_read_reg_bit_field_result {
7603         cmdline_fixed_string_t read;
7604         cmdline_fixed_string_t regfield;
7605         portid_t port_id;
7606         uint32_t reg_off;
7607         uint8_t bit1_pos;
7608         uint8_t bit2_pos;
7609 };
7610
7611 static void
7612 cmd_read_reg_bit_field_parsed(void *parsed_result,
7613                               __attribute__((unused)) struct cmdline *cl,
7614                               __attribute__((unused)) void *data)
7615 {
7616         struct cmd_read_reg_bit_field_result *res = parsed_result;
7617         port_reg_bit_field_display(res->port_id, res->reg_off,
7618                                    res->bit1_pos, res->bit2_pos);
7619 }
7620
7621 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7622         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7623                                  "read");
7624 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7625         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7626                                  regfield, "regfield");
7627 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7628         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7629                               UINT16);
7630 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7631         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7632                               UINT32);
7633 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7634         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7635                               UINT8);
7636 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7637         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7638                               UINT8);
7639
7640 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7641         .f = cmd_read_reg_bit_field_parsed,
7642         .data = NULL,
7643         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7644         "Read register bit field between bit_x and bit_y included",
7645         .tokens = {
7646                 (void *)&cmd_read_reg_bit_field_read,
7647                 (void *)&cmd_read_reg_bit_field_regfield,
7648                 (void *)&cmd_read_reg_bit_field_port_id,
7649                 (void *)&cmd_read_reg_bit_field_reg_off,
7650                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7651                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7652                 NULL,
7653         },
7654 };
7655
7656 /* *** READ PORT REGISTER BIT *** */
7657 struct cmd_read_reg_bit_result {
7658         cmdline_fixed_string_t read;
7659         cmdline_fixed_string_t regbit;
7660         portid_t port_id;
7661         uint32_t reg_off;
7662         uint8_t bit_pos;
7663 };
7664
7665 static void
7666 cmd_read_reg_bit_parsed(void *parsed_result,
7667                         __attribute__((unused)) struct cmdline *cl,
7668                         __attribute__((unused)) void *data)
7669 {
7670         struct cmd_read_reg_bit_result *res = parsed_result;
7671         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7672 }
7673
7674 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7675         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7676 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7677         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7678                                  regbit, "regbit");
7679 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7680         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7681 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7682         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7683 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7684         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7685
7686 cmdline_parse_inst_t cmd_read_reg_bit = {
7687         .f = cmd_read_reg_bit_parsed,
7688         .data = NULL,
7689         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7690         .tokens = {
7691                 (void *)&cmd_read_reg_bit_read,
7692                 (void *)&cmd_read_reg_bit_regbit,
7693                 (void *)&cmd_read_reg_bit_port_id,
7694                 (void *)&cmd_read_reg_bit_reg_off,
7695                 (void *)&cmd_read_reg_bit_bit_pos,
7696                 NULL,
7697         },
7698 };
7699
7700 /* *** WRITE PORT REGISTER *** */
7701 struct cmd_write_reg_result {
7702         cmdline_fixed_string_t write;
7703         cmdline_fixed_string_t reg;
7704         portid_t port_id;
7705         uint32_t reg_off;
7706         uint32_t value;
7707 };
7708
7709 static void
7710 cmd_write_reg_parsed(void *parsed_result,
7711                      __attribute__((unused)) struct cmdline *cl,
7712                      __attribute__((unused)) void *data)
7713 {
7714         struct cmd_write_reg_result *res = parsed_result;
7715         port_reg_set(res->port_id, res->reg_off, res->value);
7716 }
7717
7718 cmdline_parse_token_string_t cmd_write_reg_write =
7719         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7720 cmdline_parse_token_string_t cmd_write_reg_reg =
7721         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7722 cmdline_parse_token_num_t cmd_write_reg_port_id =
7723         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7724 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7725         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7726 cmdline_parse_token_num_t cmd_write_reg_value =
7727         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7728
7729 cmdline_parse_inst_t cmd_write_reg = {
7730         .f = cmd_write_reg_parsed,
7731         .data = NULL,
7732         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7733         .tokens = {
7734                 (void *)&cmd_write_reg_write,
7735                 (void *)&cmd_write_reg_reg,
7736                 (void *)&cmd_write_reg_port_id,
7737                 (void *)&cmd_write_reg_reg_off,
7738                 (void *)&cmd_write_reg_value,
7739                 NULL,
7740         },
7741 };
7742
7743 /* *** WRITE PORT REGISTER BIT FIELD *** */
7744 struct cmd_write_reg_bit_field_result {
7745         cmdline_fixed_string_t write;
7746         cmdline_fixed_string_t regfield;
7747         portid_t port_id;
7748         uint32_t reg_off;
7749         uint8_t bit1_pos;
7750         uint8_t bit2_pos;
7751         uint32_t value;
7752 };
7753
7754 static void
7755 cmd_write_reg_bit_field_parsed(void *parsed_result,
7756                                __attribute__((unused)) struct cmdline *cl,
7757                                __attribute__((unused)) void *data)
7758 {
7759         struct cmd_write_reg_bit_field_result *res = parsed_result;
7760         port_reg_bit_field_set(res->port_id, res->reg_off,
7761                           res->bit1_pos, res->bit2_pos, res->value);
7762 }
7763
7764 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7765         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7766                                  "write");
7767 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7768         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7769                                  regfield, "regfield");
7770 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7771         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7772                               UINT16);
7773 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7774         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7775                               UINT32);
7776 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7777         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7778                               UINT8);
7779 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7780         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7781                               UINT8);
7782 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7783         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7784                               UINT32);
7785
7786 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7787         .f = cmd_write_reg_bit_field_parsed,
7788         .data = NULL,
7789         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7790                 "<reg_value>: "
7791                 "Set register bit field between bit_x and bit_y included",
7792         .tokens = {
7793                 (void *)&cmd_write_reg_bit_field_write,
7794                 (void *)&cmd_write_reg_bit_field_regfield,
7795                 (void *)&cmd_write_reg_bit_field_port_id,
7796                 (void *)&cmd_write_reg_bit_field_reg_off,
7797                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7798                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7799                 (void *)&cmd_write_reg_bit_field_value,
7800                 NULL,
7801         },
7802 };
7803
7804 /* *** WRITE PORT REGISTER BIT *** */
7805 struct cmd_write_reg_bit_result {
7806         cmdline_fixed_string_t write;
7807         cmdline_fixed_string_t regbit;
7808         portid_t port_id;
7809         uint32_t reg_off;
7810         uint8_t bit_pos;
7811         uint8_t value;
7812 };
7813
7814 static void
7815 cmd_write_reg_bit_parsed(void *parsed_result,
7816                          __attribute__((unused)) struct cmdline *cl,
7817                          __attribute__((unused)) void *data)
7818 {
7819         struct cmd_write_reg_bit_result *res = parsed_result;
7820         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7821 }
7822
7823 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7824         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7825                                  "write");
7826 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7827         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7828                                  regbit, "regbit");
7829 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7830         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7831 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7832         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7833 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7834         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7835 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7836         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7837
7838 cmdline_parse_inst_t cmd_write_reg_bit = {
7839         .f = cmd_write_reg_bit_parsed,
7840         .data = NULL,
7841         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7842                 "0 <= bit_x <= 31",
7843         .tokens = {
7844                 (void *)&cmd_write_reg_bit_write,
7845                 (void *)&cmd_write_reg_bit_regbit,
7846                 (void *)&cmd_write_reg_bit_port_id,
7847                 (void *)&cmd_write_reg_bit_reg_off,
7848                 (void *)&cmd_write_reg_bit_bit_pos,
7849                 (void *)&cmd_write_reg_bit_value,
7850                 NULL,
7851         },
7852 };
7853
7854 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7855 struct cmd_read_rxd_txd_result {
7856         cmdline_fixed_string_t read;
7857         cmdline_fixed_string_t rxd_txd;
7858         portid_t port_id;
7859         uint16_t queue_id;
7860         uint16_t desc_id;
7861 };
7862
7863 static void
7864 cmd_read_rxd_txd_parsed(void *parsed_result,
7865                         __attribute__((unused)) struct cmdline *cl,
7866                         __attribute__((unused)) void *data)
7867 {
7868         struct cmd_read_rxd_txd_result *res = parsed_result;
7869
7870         if (!strcmp(res->rxd_txd, "rxd"))
7871                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7872         else if (!strcmp(res->rxd_txd, "txd"))
7873                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7874 }
7875
7876 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7877         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7878 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7879         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7880                                  "rxd#txd");
7881 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7882         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7883 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7884         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7885 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7886         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7887
7888 cmdline_parse_inst_t cmd_read_rxd_txd = {
7889         .f = cmd_read_rxd_txd_parsed,
7890         .data = NULL,
7891         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7892         .tokens = {
7893                 (void *)&cmd_read_rxd_txd_read,
7894                 (void *)&cmd_read_rxd_txd_rxd_txd,
7895                 (void *)&cmd_read_rxd_txd_port_id,
7896                 (void *)&cmd_read_rxd_txd_queue_id,
7897                 (void *)&cmd_read_rxd_txd_desc_id,
7898                 NULL,
7899         },
7900 };
7901
7902 /* *** QUIT *** */
7903 struct cmd_quit_result {
7904         cmdline_fixed_string_t quit;
7905 };
7906
7907 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7908                             struct cmdline *cl,
7909                             __attribute__((unused)) void *data)
7910 {
7911         cmdline_quit(cl);
7912 }
7913
7914 cmdline_parse_token_string_t cmd_quit_quit =
7915         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7916
7917 cmdline_parse_inst_t cmd_quit = {
7918         .f = cmd_quit_parsed,
7919         .data = NULL,
7920         .help_str = "quit: Exit application",
7921         .tokens = {
7922                 (void *)&cmd_quit_quit,
7923                 NULL,
7924         },
7925 };
7926
7927 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7928 struct cmd_mac_addr_result {
7929         cmdline_fixed_string_t mac_addr_cmd;
7930         cmdline_fixed_string_t what;
7931         uint16_t port_num;
7932         struct rte_ether_addr address;
7933 };
7934
7935 static void cmd_mac_addr_parsed(void *parsed_result,
7936                 __attribute__((unused)) struct cmdline *cl,
7937                 __attribute__((unused)) void *data)
7938 {
7939         struct cmd_mac_addr_result *res = parsed_result;
7940         int ret;
7941
7942         if (strcmp(res->what, "add") == 0)
7943                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7944         else if (strcmp(res->what, "set") == 0)
7945                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7946                                                        &res->address);
7947         else
7948                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7949
7950         /* check the return value and print it if is < 0 */
7951         if(ret < 0)
7952                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7953
7954 }
7955
7956 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7957         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7958                                 "mac_addr");
7959 cmdline_parse_token_string_t cmd_mac_addr_what =
7960         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7961                                 "add#remove#set");
7962 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7963                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7964                                         UINT16);
7965 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7966                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7967
7968 cmdline_parse_inst_t cmd_mac_addr = {
7969         .f = cmd_mac_addr_parsed,
7970         .data = (void *)0,
7971         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7972                         "Add/Remove/Set MAC address on port_id",
7973         .tokens = {
7974                 (void *)&cmd_mac_addr_cmd,
7975                 (void *)&cmd_mac_addr_what,
7976                 (void *)&cmd_mac_addr_portnum,
7977                 (void *)&cmd_mac_addr_addr,
7978                 NULL,
7979         },
7980 };
7981
7982 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7983 struct cmd_eth_peer_result {
7984         cmdline_fixed_string_t set;
7985         cmdline_fixed_string_t eth_peer;
7986         portid_t port_id;
7987         cmdline_fixed_string_t peer_addr;
7988 };
7989
7990 static void cmd_set_eth_peer_parsed(void *parsed_result,
7991                         __attribute__((unused)) struct cmdline *cl,
7992                         __attribute__((unused)) void *data)
7993 {
7994                 struct cmd_eth_peer_result *res = parsed_result;
7995
7996                 if (test_done == 0) {
7997                         printf("Please stop forwarding first\n");
7998                         return;
7999                 }
8000                 if (!strcmp(res->eth_peer, "eth-peer")) {
8001                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8002                         fwd_config_setup();
8003                 }
8004 }
8005 cmdline_parse_token_string_t cmd_eth_peer_set =
8006         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8007 cmdline_parse_token_string_t cmd_eth_peer =
8008         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8009 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8010         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8011 cmdline_parse_token_string_t cmd_eth_peer_addr =
8012         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8013
8014 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8015         .f = cmd_set_eth_peer_parsed,
8016         .data = NULL,
8017         .help_str = "set eth-peer <port_id> <peer_mac>",
8018         .tokens = {
8019                 (void *)&cmd_eth_peer_set,
8020                 (void *)&cmd_eth_peer,
8021                 (void *)&cmd_eth_peer_port_id,
8022                 (void *)&cmd_eth_peer_addr,
8023                 NULL,
8024         },
8025 };
8026
8027 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8028 struct cmd_set_qmap_result {
8029         cmdline_fixed_string_t set;
8030         cmdline_fixed_string_t qmap;
8031         cmdline_fixed_string_t what;
8032         portid_t port_id;
8033         uint16_t queue_id;
8034         uint8_t map_value;
8035 };
8036
8037 static void
8038 cmd_set_qmap_parsed(void *parsed_result,
8039                        __attribute__((unused)) struct cmdline *cl,
8040                        __attribute__((unused)) void *data)
8041 {
8042         struct cmd_set_qmap_result *res = parsed_result;
8043         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8044
8045         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8046 }
8047
8048 cmdline_parse_token_string_t cmd_setqmap_set =
8049         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8050                                  set, "set");
8051 cmdline_parse_token_string_t cmd_setqmap_qmap =
8052         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8053                                  qmap, "stat_qmap");
8054 cmdline_parse_token_string_t cmd_setqmap_what =
8055         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8056                                  what, "tx#rx");
8057 cmdline_parse_token_num_t cmd_setqmap_portid =
8058         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8059                               port_id, UINT16);
8060 cmdline_parse_token_num_t cmd_setqmap_queueid =
8061         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8062                               queue_id, UINT16);
8063 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8064         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8065                               map_value, UINT8);
8066
8067 cmdline_parse_inst_t cmd_set_qmap = {
8068         .f = cmd_set_qmap_parsed,
8069         .data = NULL,
8070         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8071                 "Set statistics mapping value on tx|rx queue_id of port_id",
8072         .tokens = {
8073                 (void *)&cmd_setqmap_set,
8074                 (void *)&cmd_setqmap_qmap,
8075                 (void *)&cmd_setqmap_what,
8076                 (void *)&cmd_setqmap_portid,
8077                 (void *)&cmd_setqmap_queueid,
8078                 (void *)&cmd_setqmap_mapvalue,
8079                 NULL,
8080         },
8081 };
8082
8083 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8084 struct cmd_set_xstats_hide_zero_result {
8085         cmdline_fixed_string_t keyword;
8086         cmdline_fixed_string_t name;
8087         cmdline_fixed_string_t on_off;
8088 };
8089
8090 static void
8091 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8092                         __attribute__((unused)) struct cmdline *cl,
8093                         __attribute__((unused)) void *data)
8094 {
8095         struct cmd_set_xstats_hide_zero_result *res;
8096         uint16_t on_off = 0;
8097
8098         res = parsed_result;
8099         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8100         set_xstats_hide_zero(on_off);
8101 }
8102
8103 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8104         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8105                                  keyword, "set");
8106 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8107         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8108                                  name, "xstats-hide-zero");
8109 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8110         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8111                                  on_off, "on#off");
8112
8113 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8114         .f = cmd_set_xstats_hide_zero_parsed,
8115         .data = NULL,
8116         .help_str = "set xstats-hide-zero on|off",
8117         .tokens = {
8118                 (void *)&cmd_set_xstats_hide_zero_keyword,
8119                 (void *)&cmd_set_xstats_hide_zero_name,
8120                 (void *)&cmd_set_xstats_hide_zero_on_off,
8121                 NULL,
8122         },
8123 };
8124
8125 /* *** CONFIGURE UNICAST HASH TABLE *** */
8126 struct cmd_set_uc_hash_table {
8127         cmdline_fixed_string_t set;
8128         cmdline_fixed_string_t port;
8129         portid_t port_id;
8130         cmdline_fixed_string_t what;
8131         struct rte_ether_addr address;
8132         cmdline_fixed_string_t mode;
8133 };
8134
8135 static void
8136 cmd_set_uc_hash_parsed(void *parsed_result,
8137                        __attribute__((unused)) struct cmdline *cl,
8138                        __attribute__((unused)) void *data)
8139 {
8140         int ret=0;
8141         struct cmd_set_uc_hash_table *res = parsed_result;
8142
8143         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8144
8145         if (strcmp(res->what, "uta") == 0)
8146                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8147                                                 &res->address,(uint8_t)is_on);
8148         if (ret < 0)
8149                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8150
8151 }
8152
8153 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8154         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8155                                  set, "set");
8156 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8157         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8158                                  port, "port");
8159 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8160         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8161                               port_id, UINT16);
8162 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8163         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8164                                  what, "uta");
8165 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8166         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8167                                 address);
8168 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8169         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8170                                  mode, "on#off");
8171
8172 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8173         .f = cmd_set_uc_hash_parsed,
8174         .data = NULL,
8175         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8176         .tokens = {
8177                 (void *)&cmd_set_uc_hash_set,
8178                 (void *)&cmd_set_uc_hash_port,
8179                 (void *)&cmd_set_uc_hash_portid,
8180                 (void *)&cmd_set_uc_hash_what,
8181                 (void *)&cmd_set_uc_hash_mac,
8182                 (void *)&cmd_set_uc_hash_mode,
8183                 NULL,
8184         },
8185 };
8186
8187 struct cmd_set_uc_all_hash_table {
8188         cmdline_fixed_string_t set;
8189         cmdline_fixed_string_t port;
8190         portid_t port_id;
8191         cmdline_fixed_string_t what;
8192         cmdline_fixed_string_t value;
8193         cmdline_fixed_string_t mode;
8194 };
8195
8196 static void
8197 cmd_set_uc_all_hash_parsed(void *parsed_result,
8198                        __attribute__((unused)) struct cmdline *cl,
8199                        __attribute__((unused)) void *data)
8200 {
8201         int ret=0;
8202         struct cmd_set_uc_all_hash_table *res = parsed_result;
8203
8204         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8205
8206         if ((strcmp(res->what, "uta") == 0) &&
8207                 (strcmp(res->value, "all") == 0))
8208                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8209         if (ret < 0)
8210                 printf("bad unicast hash table parameter,"
8211                         "return code = %d \n", ret);
8212 }
8213
8214 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8215         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8216                                  set, "set");
8217 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8218         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8219                                  port, "port");
8220 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8221         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8222                               port_id, UINT16);
8223 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8224         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8225                                  what, "uta");
8226 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8227         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8228                                 value,"all");
8229 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8230         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8231                                  mode, "on#off");
8232
8233 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8234         .f = cmd_set_uc_all_hash_parsed,
8235         .data = NULL,
8236         .help_str = "set port <port_id> uta all on|off",
8237         .tokens = {
8238                 (void *)&cmd_set_uc_all_hash_set,
8239                 (void *)&cmd_set_uc_all_hash_port,
8240                 (void *)&cmd_set_uc_all_hash_portid,
8241                 (void *)&cmd_set_uc_all_hash_what,
8242                 (void *)&cmd_set_uc_all_hash_value,
8243                 (void *)&cmd_set_uc_all_hash_mode,
8244                 NULL,
8245         },
8246 };
8247
8248 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8249 struct cmd_set_vf_macvlan_filter {
8250         cmdline_fixed_string_t set;
8251         cmdline_fixed_string_t port;
8252         portid_t port_id;
8253         cmdline_fixed_string_t vf;
8254         uint8_t vf_id;
8255         struct rte_ether_addr address;
8256         cmdline_fixed_string_t filter_type;
8257         cmdline_fixed_string_t mode;
8258 };
8259
8260 static void
8261 cmd_set_vf_macvlan_parsed(void *parsed_result,
8262                        __attribute__((unused)) struct cmdline *cl,
8263                        __attribute__((unused)) void *data)
8264 {
8265         int is_on, ret = 0;
8266         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8267         struct rte_eth_mac_filter filter;
8268
8269         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8270
8271         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8272
8273         /* set VF MAC filter */
8274         filter.is_vf = 1;
8275
8276         /* set VF ID */
8277         filter.dst_id = res->vf_id;
8278
8279         if (!strcmp(res->filter_type, "exact-mac"))
8280                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8281         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8282                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8283         else if (!strcmp(res->filter_type, "hashmac"))
8284                 filter.filter_type = RTE_MAC_HASH_MATCH;
8285         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8286                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8287
8288         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8289
8290         if (is_on)
8291                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8292                                         RTE_ETH_FILTER_MACVLAN,
8293                                         RTE_ETH_FILTER_ADD,
8294                                          &filter);
8295         else
8296                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8297                                         RTE_ETH_FILTER_MACVLAN,
8298                                         RTE_ETH_FILTER_DELETE,
8299                                         &filter);
8300
8301         if (ret < 0)
8302                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8303
8304 }
8305
8306 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8307         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8308                                  set, "set");
8309 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8310         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8311                                  port, "port");
8312 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8313         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8314                               port_id, UINT16);
8315 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8316         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8317                                  vf, "vf");
8318 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8319         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8320                                 vf_id, UINT8);
8321 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8322         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8323                                 address);
8324 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8325         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8326                                 filter_type, "exact-mac#exact-mac-vlan"
8327                                 "#hashmac#hashmac-vlan");
8328 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8329         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8330                                  mode, "on#off");
8331
8332 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8333         .f = cmd_set_vf_macvlan_parsed,
8334         .data = NULL,
8335         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8336                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8337                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8338                 "hash match rule: hash match of MAC and exact match of VLAN",
8339         .tokens = {
8340                 (void *)&cmd_set_vf_macvlan_set,
8341                 (void *)&cmd_set_vf_macvlan_port,
8342                 (void *)&cmd_set_vf_macvlan_portid,
8343                 (void *)&cmd_set_vf_macvlan_vf,
8344                 (void *)&cmd_set_vf_macvlan_vf_id,
8345                 (void *)&cmd_set_vf_macvlan_mac,
8346                 (void *)&cmd_set_vf_macvlan_filter_type,
8347                 (void *)&cmd_set_vf_macvlan_mode,
8348                 NULL,
8349         },
8350 };
8351
8352 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8353 struct cmd_set_vf_traffic {
8354         cmdline_fixed_string_t set;
8355         cmdline_fixed_string_t port;
8356         portid_t port_id;
8357         cmdline_fixed_string_t vf;
8358         uint8_t vf_id;
8359         cmdline_fixed_string_t what;
8360         cmdline_fixed_string_t mode;
8361 };
8362
8363 static void
8364 cmd_set_vf_traffic_parsed(void *parsed_result,
8365                        __attribute__((unused)) struct cmdline *cl,
8366                        __attribute__((unused)) void *data)
8367 {
8368         struct cmd_set_vf_traffic *res = parsed_result;
8369         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8370         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8371
8372         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8373 }
8374
8375 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8376         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8377                                  set, "set");
8378 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8379         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8380                                  port, "port");
8381 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8382         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8383                               port_id, UINT16);
8384 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8385         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8386                                  vf, "vf");
8387 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8388         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8389                               vf_id, UINT8);
8390 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8391         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8392                                  what, "tx#rx");
8393 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8394         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8395                                  mode, "on#off");
8396
8397 cmdline_parse_inst_t cmd_set_vf_traffic = {
8398         .f = cmd_set_vf_traffic_parsed,
8399         .data = NULL,
8400         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8401         .tokens = {
8402                 (void *)&cmd_setvf_traffic_set,
8403                 (void *)&cmd_setvf_traffic_port,
8404                 (void *)&cmd_setvf_traffic_portid,
8405                 (void *)&cmd_setvf_traffic_vf,
8406                 (void *)&cmd_setvf_traffic_vfid,
8407                 (void *)&cmd_setvf_traffic_what,
8408                 (void *)&cmd_setvf_traffic_mode,
8409                 NULL,
8410         },
8411 };
8412
8413 /* *** CONFIGURE VF RECEIVE MODE *** */
8414 struct cmd_set_vf_rxmode {
8415         cmdline_fixed_string_t set;
8416         cmdline_fixed_string_t port;
8417         portid_t port_id;
8418         cmdline_fixed_string_t vf;
8419         uint8_t vf_id;
8420         cmdline_fixed_string_t what;
8421         cmdline_fixed_string_t mode;
8422         cmdline_fixed_string_t on;
8423 };
8424
8425 static void
8426 cmd_set_vf_rxmode_parsed(void *parsed_result,
8427                        __attribute__((unused)) struct cmdline *cl,
8428                        __attribute__((unused)) void *data)
8429 {
8430         int ret = -ENOTSUP;
8431         uint16_t vf_rxmode = 0;
8432         struct cmd_set_vf_rxmode *res = parsed_result;
8433
8434         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8435         if (!strcmp(res->what,"rxmode")) {
8436                 if (!strcmp(res->mode, "AUPE"))
8437                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8438                 else if (!strcmp(res->mode, "ROPE"))
8439                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8440                 else if (!strcmp(res->mode, "BAM"))
8441                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8442                 else if (!strncmp(res->mode, "MPE",3))
8443                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8444         }
8445
8446         RTE_SET_USED(is_on);
8447
8448 #ifdef RTE_LIBRTE_IXGBE_PMD
8449         if (ret == -ENOTSUP)
8450                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8451                                                   vf_rxmode, (uint8_t)is_on);
8452 #endif
8453 #ifdef RTE_LIBRTE_BNXT_PMD
8454         if (ret == -ENOTSUP)
8455                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8456                                                  vf_rxmode, (uint8_t)is_on);
8457 #endif
8458         if (ret < 0)
8459                 printf("bad VF receive mode parameter, return code = %d \n",
8460                 ret);
8461 }
8462
8463 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8464         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8465                                  set, "set");
8466 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8467         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8468                                  port, "port");
8469 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8470         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8471                               port_id, UINT16);
8472 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8473         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8474                                  vf, "vf");
8475 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8476         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8477                               vf_id, UINT8);
8478 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8479         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8480                                  what, "rxmode");
8481 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8482         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8483                                  mode, "AUPE#ROPE#BAM#MPE");
8484 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8485         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8486                                  on, "on#off");
8487
8488 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8489         .f = cmd_set_vf_rxmode_parsed,
8490         .data = NULL,
8491         .help_str = "set port <port_id> vf <vf_id> rxmode "
8492                 "AUPE|ROPE|BAM|MPE on|off",
8493         .tokens = {
8494                 (void *)&cmd_set_vf_rxmode_set,
8495                 (void *)&cmd_set_vf_rxmode_port,
8496                 (void *)&cmd_set_vf_rxmode_portid,
8497                 (void *)&cmd_set_vf_rxmode_vf,
8498                 (void *)&cmd_set_vf_rxmode_vfid,
8499                 (void *)&cmd_set_vf_rxmode_what,
8500                 (void *)&cmd_set_vf_rxmode_mode,
8501                 (void *)&cmd_set_vf_rxmode_on,
8502                 NULL,
8503         },
8504 };
8505
8506 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8507 struct cmd_vf_mac_addr_result {
8508         cmdline_fixed_string_t mac_addr_cmd;
8509         cmdline_fixed_string_t what;
8510         cmdline_fixed_string_t port;
8511         uint16_t port_num;
8512         cmdline_fixed_string_t vf;
8513         uint8_t vf_num;
8514         struct rte_ether_addr address;
8515 };
8516
8517 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8518                 __attribute__((unused)) struct cmdline *cl,
8519                 __attribute__((unused)) void *data)
8520 {
8521         struct cmd_vf_mac_addr_result *res = parsed_result;
8522         int ret = -ENOTSUP;
8523
8524         if (strcmp(res->what, "add") != 0)
8525                 return;
8526
8527 #ifdef RTE_LIBRTE_I40E_PMD
8528         if (ret == -ENOTSUP)
8529                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8530                                                    &res->address);
8531 #endif
8532 #ifdef RTE_LIBRTE_BNXT_PMD
8533         if (ret == -ENOTSUP)
8534                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8535                                                 res->vf_num);
8536 #endif
8537
8538         if(ret < 0)
8539                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8540
8541 }
8542
8543 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8544         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8545                                 mac_addr_cmd,"mac_addr");
8546 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8547         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8548                                 what,"add");
8549 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8550         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8551                                 port,"port");
8552 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8553         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8554                                 port_num, UINT16);
8555 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8556         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8557                                 vf,"vf");
8558 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8559         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8560                                 vf_num, UINT8);
8561 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8562         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8563                                 address);
8564
8565 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8566         .f = cmd_vf_mac_addr_parsed,
8567         .data = (void *)0,
8568         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8569                 "Add MAC address filtering for a VF on port_id",
8570         .tokens = {
8571                 (void *)&cmd_vf_mac_addr_cmd,
8572                 (void *)&cmd_vf_mac_addr_what,
8573                 (void *)&cmd_vf_mac_addr_port,
8574                 (void *)&cmd_vf_mac_addr_portnum,
8575                 (void *)&cmd_vf_mac_addr_vf,
8576                 (void *)&cmd_vf_mac_addr_vfnum,
8577                 (void *)&cmd_vf_mac_addr_addr,
8578                 NULL,
8579         },
8580 };
8581
8582 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8583 struct cmd_vf_rx_vlan_filter {
8584         cmdline_fixed_string_t rx_vlan;
8585         cmdline_fixed_string_t what;
8586         uint16_t vlan_id;
8587         cmdline_fixed_string_t port;
8588         portid_t port_id;
8589         cmdline_fixed_string_t vf;
8590         uint64_t vf_mask;
8591 };
8592
8593 static void
8594 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8595                           __attribute__((unused)) struct cmdline *cl,
8596                           __attribute__((unused)) void *data)
8597 {
8598         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8599         int ret = -ENOTSUP;
8600
8601         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8602
8603 #ifdef RTE_LIBRTE_IXGBE_PMD
8604         if (ret == -ENOTSUP)
8605                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8606                                 res->vlan_id, res->vf_mask, is_add);
8607 #endif
8608 #ifdef RTE_LIBRTE_I40E_PMD
8609         if (ret == -ENOTSUP)
8610                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8611                                 res->vlan_id, res->vf_mask, is_add);
8612 #endif
8613 #ifdef RTE_LIBRTE_BNXT_PMD
8614         if (ret == -ENOTSUP)
8615                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8616                                 res->vlan_id, res->vf_mask, is_add);
8617 #endif
8618
8619         switch (ret) {
8620         case 0:
8621                 break;
8622         case -EINVAL:
8623                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8624                                 res->vlan_id, res->vf_mask);
8625                 break;
8626         case -ENODEV:
8627                 printf("invalid port_id %d\n", res->port_id);
8628                 break;
8629         case -ENOTSUP:
8630                 printf("function not implemented or supported\n");
8631                 break;
8632         default:
8633                 printf("programming error: (%s)\n", strerror(-ret));
8634         }
8635 }
8636
8637 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8638         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8639                                  rx_vlan, "rx_vlan");
8640 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8641         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8642                                  what, "add#rm");
8643 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8644         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8645                               vlan_id, UINT16);
8646 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8647         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8648                                  port, "port");
8649 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8650         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8651                               port_id, UINT16);
8652 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8653         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8654                                  vf, "vf");
8655 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8656         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8657                               vf_mask, UINT64);
8658
8659 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8660         .f = cmd_vf_rx_vlan_filter_parsed,
8661         .data = NULL,
8662         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8663                 "(vf_mask = hexadecimal VF mask)",
8664         .tokens = {
8665                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8666                 (void *)&cmd_vf_rx_vlan_filter_what,
8667                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8668                 (void *)&cmd_vf_rx_vlan_filter_port,
8669                 (void *)&cmd_vf_rx_vlan_filter_portid,
8670                 (void *)&cmd_vf_rx_vlan_filter_vf,
8671                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8672                 NULL,
8673         },
8674 };
8675
8676 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8677 struct cmd_queue_rate_limit_result {
8678         cmdline_fixed_string_t set;
8679         cmdline_fixed_string_t port;
8680         uint16_t port_num;
8681         cmdline_fixed_string_t queue;
8682         uint8_t queue_num;
8683         cmdline_fixed_string_t rate;
8684         uint16_t rate_num;
8685 };
8686
8687 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8688                 __attribute__((unused)) struct cmdline *cl,
8689                 __attribute__((unused)) void *data)
8690 {
8691         struct cmd_queue_rate_limit_result *res = parsed_result;
8692         int ret = 0;
8693
8694         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8695                 && (strcmp(res->queue, "queue") == 0)
8696                 && (strcmp(res->rate, "rate") == 0))
8697                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8698                                         res->rate_num);
8699         if (ret < 0)
8700                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8701
8702 }
8703
8704 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8705         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8706                                 set, "set");
8707 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8708         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8709                                 port, "port");
8710 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8711         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8712                                 port_num, UINT16);
8713 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8714         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8715                                 queue, "queue");
8716 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8717         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8718                                 queue_num, UINT8);
8719 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8720         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8721                                 rate, "rate");
8722 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8723         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8724                                 rate_num, UINT16);
8725
8726 cmdline_parse_inst_t cmd_queue_rate_limit = {
8727         .f = cmd_queue_rate_limit_parsed,
8728         .data = (void *)0,
8729         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8730                 "Set rate limit for a queue on port_id",
8731         .tokens = {
8732                 (void *)&cmd_queue_rate_limit_set,
8733                 (void *)&cmd_queue_rate_limit_port,
8734                 (void *)&cmd_queue_rate_limit_portnum,
8735                 (void *)&cmd_queue_rate_limit_queue,
8736                 (void *)&cmd_queue_rate_limit_queuenum,
8737                 (void *)&cmd_queue_rate_limit_rate,
8738                 (void *)&cmd_queue_rate_limit_ratenum,
8739                 NULL,
8740         },
8741 };
8742
8743 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8744 struct cmd_vf_rate_limit_result {
8745         cmdline_fixed_string_t set;
8746         cmdline_fixed_string_t port;
8747         uint16_t port_num;
8748         cmdline_fixed_string_t vf;
8749         uint8_t vf_num;
8750         cmdline_fixed_string_t rate;
8751         uint16_t rate_num;
8752         cmdline_fixed_string_t q_msk;
8753         uint64_t q_msk_val;
8754 };
8755
8756 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8757                 __attribute__((unused)) struct cmdline *cl,
8758                 __attribute__((unused)) void *data)
8759 {
8760         struct cmd_vf_rate_limit_result *res = parsed_result;
8761         int ret = 0;
8762
8763         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8764                 && (strcmp(res->vf, "vf") == 0)
8765                 && (strcmp(res->rate, "rate") == 0)
8766                 && (strcmp(res->q_msk, "queue_mask") == 0))
8767                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8768                                         res->rate_num, res->q_msk_val);
8769         if (ret < 0)
8770                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8771
8772 }
8773
8774 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8775         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8776                                 set, "set");
8777 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8778         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8779                                 port, "port");
8780 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8781         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8782                                 port_num, UINT16);
8783 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8784         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8785                                 vf, "vf");
8786 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8787         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8788                                 vf_num, UINT8);
8789 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8790         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8791                                 rate, "rate");
8792 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8793         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8794                                 rate_num, UINT16);
8795 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8796         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8797                                 q_msk, "queue_mask");
8798 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8799         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8800                                 q_msk_val, UINT64);
8801
8802 cmdline_parse_inst_t cmd_vf_rate_limit = {
8803         .f = cmd_vf_rate_limit_parsed,
8804         .data = (void *)0,
8805         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8806                 "queue_mask <queue_mask_value>: "
8807                 "Set rate limit for queues of VF on port_id",
8808         .tokens = {
8809                 (void *)&cmd_vf_rate_limit_set,
8810                 (void *)&cmd_vf_rate_limit_port,
8811                 (void *)&cmd_vf_rate_limit_portnum,
8812                 (void *)&cmd_vf_rate_limit_vf,
8813                 (void *)&cmd_vf_rate_limit_vfnum,
8814                 (void *)&cmd_vf_rate_limit_rate,
8815                 (void *)&cmd_vf_rate_limit_ratenum,
8816                 (void *)&cmd_vf_rate_limit_q_msk,
8817                 (void *)&cmd_vf_rate_limit_q_msk_val,
8818                 NULL,
8819         },
8820 };
8821
8822 /* *** ADD TUNNEL FILTER OF A PORT *** */
8823 struct cmd_tunnel_filter_result {
8824         cmdline_fixed_string_t cmd;
8825         cmdline_fixed_string_t what;
8826         portid_t port_id;
8827         struct rte_ether_addr outer_mac;
8828         struct rte_ether_addr inner_mac;
8829         cmdline_ipaddr_t ip_value;
8830         uint16_t inner_vlan;
8831         cmdline_fixed_string_t tunnel_type;
8832         cmdline_fixed_string_t filter_type;
8833         uint32_t tenant_id;
8834         uint16_t queue_num;
8835 };
8836
8837 static void
8838 cmd_tunnel_filter_parsed(void *parsed_result,
8839                           __attribute__((unused)) struct cmdline *cl,
8840                           __attribute__((unused)) void *data)
8841 {
8842         struct cmd_tunnel_filter_result *res = parsed_result;
8843         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8844         int ret = 0;
8845
8846         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8847
8848         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8849         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8850         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8851
8852         if (res->ip_value.family == AF_INET) {
8853                 tunnel_filter_conf.ip_addr.ipv4_addr =
8854                         res->ip_value.addr.ipv4.s_addr;
8855                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8856         } else {
8857                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8858                         &(res->ip_value.addr.ipv6),
8859                         sizeof(struct in6_addr));
8860                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8861         }
8862
8863         if (!strcmp(res->filter_type, "imac-ivlan"))
8864                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8865         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8866                 tunnel_filter_conf.filter_type =
8867                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8868         else if (!strcmp(res->filter_type, "imac-tenid"))
8869                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8870         else if (!strcmp(res->filter_type, "imac"))
8871                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8872         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8873                 tunnel_filter_conf.filter_type =
8874                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8875         else if (!strcmp(res->filter_type, "oip"))
8876                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8877         else if (!strcmp(res->filter_type, "iip"))
8878                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8879         else {
8880                 printf("The filter type is not supported");
8881                 return;
8882         }
8883
8884         if (!strcmp(res->tunnel_type, "vxlan"))
8885                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8886         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8887                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8888         else if (!strcmp(res->tunnel_type, "nvgre"))
8889                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8890         else if (!strcmp(res->tunnel_type, "ipingre"))
8891                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8892         else {
8893                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8894                 return;
8895         }
8896
8897         tunnel_filter_conf.tenant_id = res->tenant_id;
8898         tunnel_filter_conf.queue_id = res->queue_num;
8899         if (!strcmp(res->what, "add"))
8900                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8901                                         RTE_ETH_FILTER_TUNNEL,
8902                                         RTE_ETH_FILTER_ADD,
8903                                         &tunnel_filter_conf);
8904         else
8905                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8906                                         RTE_ETH_FILTER_TUNNEL,
8907                                         RTE_ETH_FILTER_DELETE,
8908                                         &tunnel_filter_conf);
8909         if (ret < 0)
8910                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8911                                 strerror(-ret));
8912
8913 }
8914 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8915         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8916         cmd, "tunnel_filter");
8917 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8918         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8919         what, "add#rm");
8920 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8921         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8922         port_id, UINT16);
8923 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8924         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8925         outer_mac);
8926 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8927         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8928         inner_mac);
8929 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8930         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8931         inner_vlan, UINT16);
8932 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8933         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8934         ip_value);
8935 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8936         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8937         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8938
8939 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8940         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8941         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8942                 "imac#omac-imac-tenid");
8943 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8944         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8945         tenant_id, UINT32);
8946 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8947         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8948         queue_num, UINT16);
8949
8950 cmdline_parse_inst_t cmd_tunnel_filter = {
8951         .f = cmd_tunnel_filter_parsed,
8952         .data = (void *)0,
8953         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8954                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8955                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8956                 "<queue_id>: Add/Rm tunnel filter of a port",
8957         .tokens = {
8958                 (void *)&cmd_tunnel_filter_cmd,
8959                 (void *)&cmd_tunnel_filter_what,
8960                 (void *)&cmd_tunnel_filter_port_id,
8961                 (void *)&cmd_tunnel_filter_outer_mac,
8962                 (void *)&cmd_tunnel_filter_inner_mac,
8963                 (void *)&cmd_tunnel_filter_ip_value,
8964                 (void *)&cmd_tunnel_filter_innner_vlan,
8965                 (void *)&cmd_tunnel_filter_tunnel_type,
8966                 (void *)&cmd_tunnel_filter_filter_type,
8967                 (void *)&cmd_tunnel_filter_tenant_id,
8968                 (void *)&cmd_tunnel_filter_queue_num,
8969                 NULL,
8970         },
8971 };
8972
8973 /* *** CONFIGURE TUNNEL UDP PORT *** */
8974 struct cmd_tunnel_udp_config {
8975         cmdline_fixed_string_t cmd;
8976         cmdline_fixed_string_t what;
8977         uint16_t udp_port;
8978         portid_t port_id;
8979 };
8980
8981 static void
8982 cmd_tunnel_udp_config_parsed(void *parsed_result,
8983                           __attribute__((unused)) struct cmdline *cl,
8984                           __attribute__((unused)) void *data)
8985 {
8986         struct cmd_tunnel_udp_config *res = parsed_result;
8987         struct rte_eth_udp_tunnel tunnel_udp;
8988         int ret;
8989
8990         tunnel_udp.udp_port = res->udp_port;
8991
8992         if (!strcmp(res->cmd, "rx_vxlan_port"))
8993                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8994
8995         if (!strcmp(res->what, "add"))
8996                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8997                                                       &tunnel_udp);
8998         else
8999                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9000                                                          &tunnel_udp);
9001
9002         if (ret < 0)
9003                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9004 }
9005
9006 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9007         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9008                                 cmd, "rx_vxlan_port");
9009 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9010         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9011                                 what, "add#rm");
9012 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9013         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9014                                 udp_port, UINT16);
9015 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9016         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9017                                 port_id, UINT16);
9018
9019 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9020         .f = cmd_tunnel_udp_config_parsed,
9021         .data = (void *)0,
9022         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9023                 "Add/Remove a tunneling UDP port filter",
9024         .tokens = {
9025                 (void *)&cmd_tunnel_udp_config_cmd,
9026                 (void *)&cmd_tunnel_udp_config_what,
9027                 (void *)&cmd_tunnel_udp_config_udp_port,
9028                 (void *)&cmd_tunnel_udp_config_port_id,
9029                 NULL,
9030         },
9031 };
9032
9033 struct cmd_config_tunnel_udp_port {
9034         cmdline_fixed_string_t port;
9035         cmdline_fixed_string_t config;
9036         portid_t port_id;
9037         cmdline_fixed_string_t udp_tunnel_port;
9038         cmdline_fixed_string_t action;
9039         cmdline_fixed_string_t tunnel_type;
9040         uint16_t udp_port;
9041 };
9042
9043 static void
9044 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9045                                __attribute__((unused)) struct cmdline *cl,
9046                                __attribute__((unused)) void *data)
9047 {
9048         struct cmd_config_tunnel_udp_port *res = parsed_result;
9049         struct rte_eth_udp_tunnel tunnel_udp;
9050         int ret = 0;
9051
9052         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9053                 return;
9054
9055         tunnel_udp.udp_port = res->udp_port;
9056
9057         if (!strcmp(res->tunnel_type, "vxlan")) {
9058                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9059         } else if (!strcmp(res->tunnel_type, "geneve")) {
9060                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9061         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9062                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9063         } else {
9064                 printf("Invalid tunnel type\n");
9065                 return;
9066         }
9067
9068         if (!strcmp(res->action, "add"))
9069                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9070                                                       &tunnel_udp);
9071         else
9072                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9073                                                          &tunnel_udp);
9074
9075         if (ret < 0)
9076                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9077 }
9078
9079 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9080         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9081                                  "port");
9082 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9083         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9084                                  "config");
9085 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9086         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9087                               UINT16);
9088 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9089         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9090                                  udp_tunnel_port,
9091                                  "udp_tunnel_port");
9092 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9093         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9094                                  "add#rm");
9095 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9096         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9097                                  "vxlan#geneve#vxlan-gpe");
9098 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9099         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9100                               UINT16);
9101
9102 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9103         .f = cmd_cfg_tunnel_udp_port_parsed,
9104         .data = NULL,
9105         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9106         .tokens = {
9107                 (void *)&cmd_config_tunnel_udp_port_port,
9108                 (void *)&cmd_config_tunnel_udp_port_config,
9109                 (void *)&cmd_config_tunnel_udp_port_port_id,
9110                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9111                 (void *)&cmd_config_tunnel_udp_port_action,
9112                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9113                 (void *)&cmd_config_tunnel_udp_port_value,
9114                 NULL,
9115         },
9116 };
9117
9118 /* *** GLOBAL CONFIG *** */
9119 struct cmd_global_config_result {
9120         cmdline_fixed_string_t cmd;
9121         portid_t port_id;
9122         cmdline_fixed_string_t cfg_type;
9123         uint8_t len;
9124 };
9125
9126 static void
9127 cmd_global_config_parsed(void *parsed_result,
9128                          __attribute__((unused)) struct cmdline *cl,
9129                          __attribute__((unused)) void *data)
9130 {
9131         struct cmd_global_config_result *res = parsed_result;
9132         struct rte_eth_global_cfg conf;
9133         int ret;
9134
9135         memset(&conf, 0, sizeof(conf));
9136         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9137         conf.cfg.gre_key_len = res->len;
9138         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9139                                       RTE_ETH_FILTER_SET, &conf);
9140         if (ret != 0)
9141                 printf("Global config error\n");
9142 }
9143
9144 cmdline_parse_token_string_t cmd_global_config_cmd =
9145         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9146                 "global_config");
9147 cmdline_parse_token_num_t cmd_global_config_port_id =
9148         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9149                                UINT16);
9150 cmdline_parse_token_string_t cmd_global_config_type =
9151         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9152                 cfg_type, "gre-key-len");
9153 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9154         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9155                 len, UINT8);
9156
9157 cmdline_parse_inst_t cmd_global_config = {
9158         .f = cmd_global_config_parsed,
9159         .data = (void *)NULL,
9160         .help_str = "global_config <port_id> gre-key-len <key_len>",
9161         .tokens = {
9162                 (void *)&cmd_global_config_cmd,
9163                 (void *)&cmd_global_config_port_id,
9164                 (void *)&cmd_global_config_type,
9165                 (void *)&cmd_global_config_gre_key_len,
9166                 NULL,
9167         },
9168 };
9169
9170 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9171 struct cmd_set_mirror_mask_result {
9172         cmdline_fixed_string_t set;
9173         cmdline_fixed_string_t port;
9174         portid_t port_id;
9175         cmdline_fixed_string_t mirror;
9176         uint8_t rule_id;
9177         cmdline_fixed_string_t what;
9178         cmdline_fixed_string_t value;
9179         cmdline_fixed_string_t dstpool;
9180         uint8_t dstpool_id;
9181         cmdline_fixed_string_t on;
9182 };
9183
9184 cmdline_parse_token_string_t cmd_mirror_mask_set =
9185         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9186                                 set, "set");
9187 cmdline_parse_token_string_t cmd_mirror_mask_port =
9188         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9189                                 port, "port");
9190 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9191         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9192                                 port_id, UINT16);
9193 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9194         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9195                                 mirror, "mirror-rule");
9196 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9197         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9198                                 rule_id, UINT8);
9199 cmdline_parse_token_string_t cmd_mirror_mask_what =
9200         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9201                                 what, "pool-mirror-up#pool-mirror-down"
9202                                       "#vlan-mirror");
9203 cmdline_parse_token_string_t cmd_mirror_mask_value =
9204         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9205                                 value, NULL);
9206 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9207         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9208                                 dstpool, "dst-pool");
9209 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9210         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9211                                 dstpool_id, UINT8);
9212 cmdline_parse_token_string_t cmd_mirror_mask_on =
9213         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9214                                 on, "on#off");
9215
9216 static void
9217 cmd_set_mirror_mask_parsed(void *parsed_result,
9218                        __attribute__((unused)) struct cmdline *cl,
9219                        __attribute__((unused)) void *data)
9220 {
9221         int ret,nb_item,i;
9222         struct cmd_set_mirror_mask_result *res = parsed_result;
9223         struct rte_eth_mirror_conf mr_conf;
9224
9225         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9226
9227         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9228
9229         mr_conf.dst_pool = res->dstpool_id;
9230
9231         if (!strcmp(res->what, "pool-mirror-up")) {
9232                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9233                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9234         } else if (!strcmp(res->what, "pool-mirror-down")) {
9235                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9236                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9237         } else if (!strcmp(res->what, "vlan-mirror")) {
9238                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9239                 nb_item = parse_item_list(res->value, "vlan",
9240                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9241                 if (nb_item <= 0)
9242                         return;
9243
9244                 for (i = 0; i < nb_item; i++) {
9245                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9246                                 printf("Invalid vlan_id: must be < 4096\n");
9247                                 return;
9248                         }
9249
9250                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9251                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9252                 }
9253         }
9254
9255         if (!strcmp(res->on, "on"))
9256                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9257                                                 res->rule_id, 1);
9258         else
9259                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9260                                                 res->rule_id, 0);
9261         if (ret < 0)
9262                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9263 }
9264
9265 cmdline_parse_inst_t cmd_set_mirror_mask = {
9266                 .f = cmd_set_mirror_mask_parsed,
9267                 .data = NULL,
9268                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9269                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9270                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9271                 .tokens = {
9272                         (void *)&cmd_mirror_mask_set,
9273                         (void *)&cmd_mirror_mask_port,
9274                         (void *)&cmd_mirror_mask_portid,
9275                         (void *)&cmd_mirror_mask_mirror,
9276                         (void *)&cmd_mirror_mask_ruleid,
9277                         (void *)&cmd_mirror_mask_what,
9278                         (void *)&cmd_mirror_mask_value,
9279                         (void *)&cmd_mirror_mask_dstpool,
9280                         (void *)&cmd_mirror_mask_poolid,
9281                         (void *)&cmd_mirror_mask_on,
9282                         NULL,
9283                 },
9284 };
9285
9286 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9287 struct cmd_set_mirror_link_result {
9288         cmdline_fixed_string_t set;
9289         cmdline_fixed_string_t port;
9290         portid_t port_id;
9291         cmdline_fixed_string_t mirror;
9292         uint8_t rule_id;
9293         cmdline_fixed_string_t what;
9294         cmdline_fixed_string_t dstpool;
9295         uint8_t dstpool_id;
9296         cmdline_fixed_string_t on;
9297 };
9298
9299 cmdline_parse_token_string_t cmd_mirror_link_set =
9300         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9301                                  set, "set");
9302 cmdline_parse_token_string_t cmd_mirror_link_port =
9303         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9304                                 port, "port");
9305 cmdline_parse_token_num_t cmd_mirror_link_portid =
9306         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9307                                 port_id, UINT16);
9308 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9309         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9310                                 mirror, "mirror-rule");
9311 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9312         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9313                             rule_id, UINT8);
9314 cmdline_parse_token_string_t cmd_mirror_link_what =
9315         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9316                                 what, "uplink-mirror#downlink-mirror");
9317 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9318         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9319                                 dstpool, "dst-pool");
9320 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9321         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9322                                 dstpool_id, UINT8);
9323 cmdline_parse_token_string_t cmd_mirror_link_on =
9324         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9325                                 on, "on#off");
9326
9327 static void
9328 cmd_set_mirror_link_parsed(void *parsed_result,
9329                        __attribute__((unused)) struct cmdline *cl,
9330                        __attribute__((unused)) void *data)
9331 {
9332         int ret;
9333         struct cmd_set_mirror_link_result *res = parsed_result;
9334         struct rte_eth_mirror_conf mr_conf;
9335
9336         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9337         if (!strcmp(res->what, "uplink-mirror"))
9338                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9339         else
9340                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9341
9342         mr_conf.dst_pool = res->dstpool_id;
9343
9344         if (!strcmp(res->on, "on"))
9345                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9346                                                 res->rule_id, 1);
9347         else
9348                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9349                                                 res->rule_id, 0);
9350
9351         /* check the return value and print it if is < 0 */
9352         if (ret < 0)
9353                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9354
9355 }
9356
9357 cmdline_parse_inst_t cmd_set_mirror_link = {
9358                 .f = cmd_set_mirror_link_parsed,
9359                 .data = NULL,
9360                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9361                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9362                 .tokens = {
9363                         (void *)&cmd_mirror_link_set,
9364                         (void *)&cmd_mirror_link_port,
9365                         (void *)&cmd_mirror_link_portid,
9366                         (void *)&cmd_mirror_link_mirror,
9367                         (void *)&cmd_mirror_link_ruleid,
9368                         (void *)&cmd_mirror_link_what,
9369                         (void *)&cmd_mirror_link_dstpool,
9370                         (void *)&cmd_mirror_link_poolid,
9371                         (void *)&cmd_mirror_link_on,
9372                         NULL,
9373                 },
9374 };
9375
9376 /* *** RESET VM MIRROR RULE *** */
9377 struct cmd_rm_mirror_rule_result {
9378         cmdline_fixed_string_t reset;
9379         cmdline_fixed_string_t port;
9380         portid_t port_id;
9381         cmdline_fixed_string_t mirror;
9382         uint8_t rule_id;
9383 };
9384
9385 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9386         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9387                                  reset, "reset");
9388 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9389         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9390                                 port, "port");
9391 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9392         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9393                                 port_id, UINT16);
9394 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9395         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9396                                 mirror, "mirror-rule");
9397 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9398         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9399                                 rule_id, UINT8);
9400
9401 static void
9402 cmd_reset_mirror_rule_parsed(void *parsed_result,
9403                        __attribute__((unused)) struct cmdline *cl,
9404                        __attribute__((unused)) void *data)
9405 {
9406         int ret;
9407         struct cmd_set_mirror_link_result *res = parsed_result;
9408         /* check rule_id */
9409         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9410         if(ret < 0)
9411                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9412 }
9413
9414 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9415                 .f = cmd_reset_mirror_rule_parsed,
9416                 .data = NULL,
9417                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9418                 .tokens = {
9419                         (void *)&cmd_rm_mirror_rule_reset,
9420                         (void *)&cmd_rm_mirror_rule_port,
9421                         (void *)&cmd_rm_mirror_rule_portid,
9422                         (void *)&cmd_rm_mirror_rule_mirror,
9423                         (void *)&cmd_rm_mirror_rule_ruleid,
9424                         NULL,
9425                 },
9426 };
9427
9428 /* ******************************************************************************** */
9429
9430 struct cmd_dump_result {
9431         cmdline_fixed_string_t dump;
9432 };
9433
9434 static void
9435 dump_struct_sizes(void)
9436 {
9437 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9438         DUMP_SIZE(struct rte_mbuf);
9439         DUMP_SIZE(struct rte_mempool);
9440         DUMP_SIZE(struct rte_ring);
9441 #undef DUMP_SIZE
9442 }
9443
9444 static void cmd_dump_parsed(void *parsed_result,
9445                             __attribute__((unused)) struct cmdline *cl,
9446                             __attribute__((unused)) void *data)
9447 {
9448         struct cmd_dump_result *res = parsed_result;
9449
9450         if (!strcmp(res->dump, "dump_physmem"))
9451                 rte_dump_physmem_layout(stdout);
9452         else if (!strcmp(res->dump, "dump_memzone"))
9453                 rte_memzone_dump(stdout);
9454         else if (!strcmp(res->dump, "dump_struct_sizes"))
9455                 dump_struct_sizes();
9456         else if (!strcmp(res->dump, "dump_ring"))
9457                 rte_ring_list_dump(stdout);
9458         else if (!strcmp(res->dump, "dump_mempool"))
9459                 rte_mempool_list_dump(stdout);
9460         else if (!strcmp(res->dump, "dump_devargs"))
9461                 rte_devargs_dump(stdout);
9462         else if (!strcmp(res->dump, "dump_log_types"))
9463                 rte_log_dump(stdout);
9464 }
9465
9466 cmdline_parse_token_string_t cmd_dump_dump =
9467         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9468                 "dump_physmem#"
9469                 "dump_memzone#"
9470                 "dump_struct_sizes#"
9471                 "dump_ring#"
9472                 "dump_mempool#"
9473                 "dump_devargs#"
9474                 "dump_log_types");
9475
9476 cmdline_parse_inst_t cmd_dump = {
9477         .f = cmd_dump_parsed,  /* function to call */
9478         .data = NULL,      /* 2nd arg of func */
9479         .help_str = "Dump status",
9480         .tokens = {        /* token list, NULL terminated */
9481                 (void *)&cmd_dump_dump,
9482                 NULL,
9483         },
9484 };
9485
9486 /* ******************************************************************************** */
9487
9488 struct cmd_dump_one_result {
9489         cmdline_fixed_string_t dump;
9490         cmdline_fixed_string_t name;
9491 };
9492
9493 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9494                                 __attribute__((unused)) void *data)
9495 {
9496         struct cmd_dump_one_result *res = parsed_result;
9497
9498         if (!strcmp(res->dump, "dump_ring")) {
9499                 struct rte_ring *r;
9500                 r = rte_ring_lookup(res->name);
9501                 if (r == NULL) {
9502                         cmdline_printf(cl, "Cannot find ring\n");
9503                         return;
9504                 }
9505                 rte_ring_dump(stdout, r);
9506         } else if (!strcmp(res->dump, "dump_mempool")) {
9507                 struct rte_mempool *mp;
9508                 mp = rte_mempool_lookup(res->name);
9509                 if (mp == NULL) {
9510                         cmdline_printf(cl, "Cannot find mempool\n");
9511                         return;
9512                 }
9513                 rte_mempool_dump(stdout, mp);
9514         }
9515 }
9516
9517 cmdline_parse_token_string_t cmd_dump_one_dump =
9518         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9519                                  "dump_ring#dump_mempool");
9520
9521 cmdline_parse_token_string_t cmd_dump_one_name =
9522         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9523
9524 cmdline_parse_inst_t cmd_dump_one = {
9525         .f = cmd_dump_one_parsed,  /* function to call */
9526         .data = NULL,      /* 2nd arg of func */
9527         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9528         .tokens = {        /* token list, NULL terminated */
9529                 (void *)&cmd_dump_one_dump,
9530                 (void *)&cmd_dump_one_name,
9531                 NULL,
9532         },
9533 };
9534
9535 /* *** Add/Del syn filter *** */
9536 struct cmd_syn_filter_result {
9537         cmdline_fixed_string_t filter;
9538         portid_t port_id;
9539         cmdline_fixed_string_t ops;
9540         cmdline_fixed_string_t priority;
9541         cmdline_fixed_string_t high;
9542         cmdline_fixed_string_t queue;
9543         uint16_t queue_id;
9544 };
9545
9546 static void
9547 cmd_syn_filter_parsed(void *parsed_result,
9548                         __attribute__((unused)) struct cmdline *cl,
9549                         __attribute__((unused)) void *data)
9550 {
9551         struct cmd_syn_filter_result *res = parsed_result;
9552         struct rte_eth_syn_filter syn_filter;
9553         int ret = 0;
9554
9555         ret = rte_eth_dev_filter_supported(res->port_id,
9556                                         RTE_ETH_FILTER_SYN);
9557         if (ret < 0) {
9558                 printf("syn filter is not supported on port %u.\n",
9559                                 res->port_id);
9560                 return;
9561         }
9562
9563         memset(&syn_filter, 0, sizeof(syn_filter));
9564
9565         if (!strcmp(res->ops, "add")) {
9566                 if (!strcmp(res->high, "high"))
9567                         syn_filter.hig_pri = 1;
9568                 else
9569                         syn_filter.hig_pri = 0;
9570
9571                 syn_filter.queue = res->queue_id;
9572                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9573                                                 RTE_ETH_FILTER_SYN,
9574                                                 RTE_ETH_FILTER_ADD,
9575                                                 &syn_filter);
9576         } else
9577                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9578                                                 RTE_ETH_FILTER_SYN,
9579                                                 RTE_ETH_FILTER_DELETE,
9580                                                 &syn_filter);
9581
9582         if (ret < 0)
9583                 printf("syn filter programming error: (%s)\n",
9584                                 strerror(-ret));
9585 }
9586
9587 cmdline_parse_token_string_t cmd_syn_filter_filter =
9588         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9589         filter, "syn_filter");
9590 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9591         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9592         port_id, UINT16);
9593 cmdline_parse_token_string_t cmd_syn_filter_ops =
9594         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9595         ops, "add#del");
9596 cmdline_parse_token_string_t cmd_syn_filter_priority =
9597         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9598                                 priority, "priority");
9599 cmdline_parse_token_string_t cmd_syn_filter_high =
9600         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9601                                 high, "high#low");
9602 cmdline_parse_token_string_t cmd_syn_filter_queue =
9603         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9604                                 queue, "queue");
9605 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9606         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9607                                 queue_id, UINT16);
9608
9609 cmdline_parse_inst_t cmd_syn_filter = {
9610         .f = cmd_syn_filter_parsed,
9611         .data = NULL,
9612         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9613                 "<queue_id>: Add/Delete syn filter",
9614         .tokens = {
9615                 (void *)&cmd_syn_filter_filter,
9616                 (void *)&cmd_syn_filter_port_id,
9617                 (void *)&cmd_syn_filter_ops,
9618                 (void *)&cmd_syn_filter_priority,
9619                 (void *)&cmd_syn_filter_high,
9620                 (void *)&cmd_syn_filter_queue,
9621                 (void *)&cmd_syn_filter_queue_id,
9622                 NULL,
9623         },
9624 };
9625
9626 /* *** queue region set *** */
9627 struct cmd_queue_region_result {
9628         cmdline_fixed_string_t set;
9629         cmdline_fixed_string_t port;
9630         portid_t port_id;
9631         cmdline_fixed_string_t cmd;
9632         cmdline_fixed_string_t region;
9633         uint8_t  region_id;
9634         cmdline_fixed_string_t queue_start_index;
9635         uint8_t  queue_id;
9636         cmdline_fixed_string_t queue_num;
9637         uint8_t  queue_num_value;
9638 };
9639
9640 static void
9641 cmd_queue_region_parsed(void *parsed_result,
9642                         __attribute__((unused)) struct cmdline *cl,
9643                         __attribute__((unused)) void *data)
9644 {
9645         struct cmd_queue_region_result *res = parsed_result;
9646         int ret = -ENOTSUP;
9647 #ifdef RTE_LIBRTE_I40E_PMD
9648         struct rte_pmd_i40e_queue_region_conf region_conf;
9649         enum rte_pmd_i40e_queue_region_op op_type;
9650 #endif
9651
9652         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9653                 return;
9654
9655 #ifdef RTE_LIBRTE_I40E_PMD
9656         memset(&region_conf, 0, sizeof(region_conf));
9657         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9658         region_conf.region_id = res->region_id;
9659         region_conf.queue_num = res->queue_num_value;
9660         region_conf.queue_start_index = res->queue_id;
9661
9662         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9663                                 op_type, &region_conf);
9664 #endif
9665
9666         switch (ret) {
9667         case 0:
9668                 break;
9669         case -ENOTSUP:
9670                 printf("function not implemented or supported\n");
9671                 break;
9672         default:
9673                 printf("queue region config error: (%s)\n", strerror(-ret));
9674         }
9675 }
9676
9677 cmdline_parse_token_string_t cmd_queue_region_set =
9678 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9679                 set, "set");
9680 cmdline_parse_token_string_t cmd_queue_region_port =
9681         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9682 cmdline_parse_token_num_t cmd_queue_region_port_id =
9683         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9684                                 port_id, UINT16);
9685 cmdline_parse_token_string_t cmd_queue_region_cmd =
9686         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9687                                  cmd, "queue-region");
9688 cmdline_parse_token_string_t cmd_queue_region_id =
9689         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9690                                 region, "region_id");
9691 cmdline_parse_token_num_t cmd_queue_region_index =
9692         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9693                                 region_id, UINT8);
9694 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9695         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9696                                 queue_start_index, "queue_start_index");
9697 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9698         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9699                                 queue_id, UINT8);
9700 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9701         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9702                                 queue_num, "queue_num");
9703 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9704         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9705                                 queue_num_value, UINT8);
9706
9707 cmdline_parse_inst_t cmd_queue_region = {
9708         .f = cmd_queue_region_parsed,
9709         .data = NULL,
9710         .help_str = "set port <port_id> queue-region region_id <value> "
9711                 "queue_start_index <value> queue_num <value>: Set a queue region",
9712         .tokens = {
9713                 (void *)&cmd_queue_region_set,
9714                 (void *)&cmd_queue_region_port,
9715                 (void *)&cmd_queue_region_port_id,
9716                 (void *)&cmd_queue_region_cmd,
9717                 (void *)&cmd_queue_region_id,
9718                 (void *)&cmd_queue_region_index,
9719                 (void *)&cmd_queue_region_queue_start_index,
9720                 (void *)&cmd_queue_region_queue_id,
9721                 (void *)&cmd_queue_region_queue_num,
9722                 (void *)&cmd_queue_region_queue_num_value,
9723                 NULL,
9724         },
9725 };
9726
9727 /* *** queue region and flowtype set *** */
9728 struct cmd_region_flowtype_result {
9729         cmdline_fixed_string_t set;
9730         cmdline_fixed_string_t port;
9731         portid_t port_id;
9732         cmdline_fixed_string_t cmd;
9733         cmdline_fixed_string_t region;
9734         uint8_t  region_id;
9735         cmdline_fixed_string_t flowtype;
9736         uint8_t  flowtype_id;
9737 };
9738
9739 static void
9740 cmd_region_flowtype_parsed(void *parsed_result,
9741                         __attribute__((unused)) struct cmdline *cl,
9742                         __attribute__((unused)) void *data)
9743 {
9744         struct cmd_region_flowtype_result *res = parsed_result;
9745         int ret = -ENOTSUP;
9746 #ifdef RTE_LIBRTE_I40E_PMD
9747         struct rte_pmd_i40e_queue_region_conf region_conf;
9748         enum rte_pmd_i40e_queue_region_op op_type;
9749 #endif
9750
9751         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9752                 return;
9753
9754 #ifdef RTE_LIBRTE_I40E_PMD
9755         memset(&region_conf, 0, sizeof(region_conf));
9756
9757         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9758         region_conf.region_id = res->region_id;
9759         region_conf.hw_flowtype = res->flowtype_id;
9760
9761         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9762                         op_type, &region_conf);
9763 #endif
9764
9765         switch (ret) {
9766         case 0:
9767                 break;
9768         case -ENOTSUP:
9769                 printf("function not implemented or supported\n");
9770                 break;
9771         default:
9772                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9773         }
9774 }
9775
9776 cmdline_parse_token_string_t cmd_region_flowtype_set =
9777 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9778                                 set, "set");
9779 cmdline_parse_token_string_t cmd_region_flowtype_port =
9780         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9781                                 port, "port");
9782 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9783         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9784                                 port_id, UINT16);
9785 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9786         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9787                                 cmd, "queue-region");
9788 cmdline_parse_token_string_t cmd_region_flowtype_index =
9789         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9790                                 region, "region_id");
9791 cmdline_parse_token_num_t cmd_region_flowtype_id =
9792         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9793                                 region_id, UINT8);
9794 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9795         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9796                                 flowtype, "flowtype");
9797 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9798         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9799                                 flowtype_id, UINT8);
9800 cmdline_parse_inst_t cmd_region_flowtype = {
9801         .f = cmd_region_flowtype_parsed,
9802         .data = NULL,
9803         .help_str = "set port <port_id> queue-region region_id <value> "
9804                 "flowtype <value>: Set a flowtype region index",
9805         .tokens = {
9806                 (void *)&cmd_region_flowtype_set,
9807                 (void *)&cmd_region_flowtype_port,
9808                 (void *)&cmd_region_flowtype_port_index,
9809                 (void *)&cmd_region_flowtype_cmd,
9810                 (void *)&cmd_region_flowtype_index,
9811                 (void *)&cmd_region_flowtype_id,
9812                 (void *)&cmd_region_flowtype_flow_index,
9813                 (void *)&cmd_region_flowtype_flow_id,
9814                 NULL,
9815         },
9816 };
9817
9818 /* *** User Priority (UP) to queue region (region_id) set *** */
9819 struct cmd_user_priority_region_result {
9820         cmdline_fixed_string_t set;
9821         cmdline_fixed_string_t port;
9822         portid_t port_id;
9823         cmdline_fixed_string_t cmd;
9824         cmdline_fixed_string_t user_priority;
9825         uint8_t  user_priority_id;
9826         cmdline_fixed_string_t region;
9827         uint8_t  region_id;
9828 };
9829
9830 static void
9831 cmd_user_priority_region_parsed(void *parsed_result,
9832                         __attribute__((unused)) struct cmdline *cl,
9833                         __attribute__((unused)) void *data)
9834 {
9835         struct cmd_user_priority_region_result *res = parsed_result;
9836         int ret = -ENOTSUP;
9837 #ifdef RTE_LIBRTE_I40E_PMD
9838         struct rte_pmd_i40e_queue_region_conf region_conf;
9839         enum rte_pmd_i40e_queue_region_op op_type;
9840 #endif
9841
9842         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9843                 return;
9844
9845 #ifdef RTE_LIBRTE_I40E_PMD
9846         memset(&region_conf, 0, sizeof(region_conf));
9847         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9848         region_conf.user_priority = res->user_priority_id;
9849         region_conf.region_id = res->region_id;
9850
9851         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9852                                 op_type, &region_conf);
9853 #endif
9854
9855         switch (ret) {
9856         case 0:
9857                 break;
9858         case -ENOTSUP:
9859                 printf("function not implemented or supported\n");
9860                 break;
9861         default:
9862                 printf("user_priority region config error: (%s)\n",
9863                                 strerror(-ret));
9864         }
9865 }
9866
9867 cmdline_parse_token_string_t cmd_user_priority_region_set =
9868         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9869                                 set, "set");
9870 cmdline_parse_token_string_t cmd_user_priority_region_port =
9871         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9872                                 port, "port");
9873 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9874         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9875                                 port_id, UINT16);
9876 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9877         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9878                                 cmd, "queue-region");
9879 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9880         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9881                                 user_priority, "UP");
9882 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9883         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9884                                 user_priority_id, UINT8);
9885 cmdline_parse_token_string_t cmd_user_priority_region_region =
9886         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9887                                 region, "region_id");
9888 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9889         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9890                                 region_id, UINT8);
9891
9892 cmdline_parse_inst_t cmd_user_priority_region = {
9893         .f = cmd_user_priority_region_parsed,
9894         .data = NULL,
9895         .help_str = "set port <port_id> queue-region UP <value> "
9896                 "region_id <value>: Set the mapping of User Priority (UP) "
9897                 "to queue region (region_id) ",
9898         .tokens = {
9899                 (void *)&cmd_user_priority_region_set,
9900                 (void *)&cmd_user_priority_region_port,
9901                 (void *)&cmd_user_priority_region_port_index,
9902                 (void *)&cmd_user_priority_region_cmd,
9903                 (void *)&cmd_user_priority_region_UP,
9904                 (void *)&cmd_user_priority_region_UP_id,
9905                 (void *)&cmd_user_priority_region_region,
9906                 (void *)&cmd_user_priority_region_region_id,
9907                 NULL,
9908         },
9909 };
9910
9911 /* *** flush all queue region related configuration *** */
9912 struct cmd_flush_queue_region_result {
9913         cmdline_fixed_string_t set;
9914         cmdline_fixed_string_t port;
9915         portid_t port_id;
9916         cmdline_fixed_string_t cmd;
9917         cmdline_fixed_string_t flush;
9918         cmdline_fixed_string_t what;
9919 };
9920
9921 static void
9922 cmd_flush_queue_region_parsed(void *parsed_result,
9923                         __attribute__((unused)) struct cmdline *cl,
9924                         __attribute__((unused)) void *data)
9925 {
9926         struct cmd_flush_queue_region_result *res = parsed_result;
9927         int ret = -ENOTSUP;
9928 #ifdef RTE_LIBRTE_I40E_PMD
9929         struct rte_pmd_i40e_queue_region_conf region_conf;
9930         enum rte_pmd_i40e_queue_region_op op_type;
9931 #endif
9932
9933         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9934                 return;
9935
9936 #ifdef RTE_LIBRTE_I40E_PMD
9937         memset(&region_conf, 0, sizeof(region_conf));
9938
9939         if (strcmp(res->what, "on") == 0)
9940                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9941         else
9942                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9943
9944         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9945                                 op_type, &region_conf);
9946 #endif
9947
9948         switch (ret) {
9949         case 0:
9950                 break;
9951         case -ENOTSUP:
9952                 printf("function not implemented or supported\n");
9953                 break;
9954         default:
9955                 printf("queue region config flush error: (%s)\n",
9956                                 strerror(-ret));
9957         }
9958 }
9959
9960 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9961         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9962                                 set, "set");
9963 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9964         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9965                                 port, "port");
9966 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9967         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9968                                 port_id, UINT16);
9969 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9970         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9971                                 cmd, "queue-region");
9972 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9973         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9974                                 flush, "flush");
9975 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9976         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9977                                 what, "on#off");
9978
9979 cmdline_parse_inst_t cmd_flush_queue_region = {
9980         .f = cmd_flush_queue_region_parsed,
9981         .data = NULL,
9982         .help_str = "set port <port_id> queue-region flush on|off"
9983                 ": flush all queue region related configuration",
9984         .tokens = {
9985                 (void *)&cmd_flush_queue_region_set,
9986                 (void *)&cmd_flush_queue_region_port,
9987                 (void *)&cmd_flush_queue_region_port_index,
9988                 (void *)&cmd_flush_queue_region_cmd,
9989                 (void *)&cmd_flush_queue_region_flush,
9990                 (void *)&cmd_flush_queue_region_what,
9991                 NULL,
9992         },
9993 };
9994
9995 /* *** get all queue region related configuration info *** */
9996 struct cmd_show_queue_region_info {
9997         cmdline_fixed_string_t show;
9998         cmdline_fixed_string_t port;
9999         portid_t port_id;
10000         cmdline_fixed_string_t cmd;
10001 };
10002
10003 static void
10004 cmd_show_queue_region_info_parsed(void *parsed_result,
10005                         __attribute__((unused)) struct cmdline *cl,
10006                         __attribute__((unused)) void *data)
10007 {
10008         struct cmd_show_queue_region_info *res = parsed_result;
10009         int ret = -ENOTSUP;
10010 #ifdef RTE_LIBRTE_I40E_PMD
10011         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10012         enum rte_pmd_i40e_queue_region_op op_type;
10013 #endif
10014
10015         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10016                 return;
10017
10018 #ifdef RTE_LIBRTE_I40E_PMD
10019         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10020
10021         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10022
10023         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10024                                         op_type, &rte_pmd_regions);
10025
10026         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10027 #endif
10028
10029         switch (ret) {
10030         case 0:
10031                 break;
10032         case -ENOTSUP:
10033                 printf("function not implemented or supported\n");
10034                 break;
10035         default:
10036                 printf("queue region config info show error: (%s)\n",
10037                                 strerror(-ret));
10038         }
10039 }
10040
10041 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10042 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10043                                 show, "show");
10044 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10045         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10046                                 port, "port");
10047 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10048         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10049                                 port_id, UINT16);
10050 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10051         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10052                                 cmd, "queue-region");
10053
10054 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10055         .f = cmd_show_queue_region_info_parsed,
10056         .data = NULL,
10057         .help_str = "show port <port_id> queue-region"
10058                 ": show all queue region related configuration info",
10059         .tokens = {
10060                 (void *)&cmd_show_queue_region_info_get,
10061                 (void *)&cmd_show_queue_region_info_port,
10062                 (void *)&cmd_show_queue_region_info_port_index,
10063                 (void *)&cmd_show_queue_region_info_cmd,
10064                 NULL,
10065         },
10066 };
10067
10068 /* *** ADD/REMOVE A 2tuple FILTER *** */
10069 struct cmd_2tuple_filter_result {
10070         cmdline_fixed_string_t filter;
10071         portid_t port_id;
10072         cmdline_fixed_string_t ops;
10073         cmdline_fixed_string_t dst_port;
10074         uint16_t dst_port_value;
10075         cmdline_fixed_string_t protocol;
10076         uint8_t protocol_value;
10077         cmdline_fixed_string_t mask;
10078         uint8_t  mask_value;
10079         cmdline_fixed_string_t tcp_flags;
10080         uint8_t tcp_flags_value;
10081         cmdline_fixed_string_t priority;
10082         uint8_t  priority_value;
10083         cmdline_fixed_string_t queue;
10084         uint16_t  queue_id;
10085 };
10086
10087 static void
10088 cmd_2tuple_filter_parsed(void *parsed_result,
10089                         __attribute__((unused)) struct cmdline *cl,
10090                         __attribute__((unused)) void *data)
10091 {
10092         struct rte_eth_ntuple_filter filter;
10093         struct cmd_2tuple_filter_result *res = parsed_result;
10094         int ret = 0;
10095
10096         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10097         if (ret < 0) {
10098                 printf("ntuple filter is not supported on port %u.\n",
10099                         res->port_id);
10100                 return;
10101         }
10102
10103         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10104
10105         filter.flags = RTE_2TUPLE_FLAGS;
10106         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10107         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10108         filter.proto = res->protocol_value;
10109         filter.priority = res->priority_value;
10110         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10111                 printf("nonzero tcp_flags is only meaningful"
10112                         " when protocol is TCP.\n");
10113                 return;
10114         }
10115         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10116                 printf("invalid TCP flags.\n");
10117                 return;
10118         }
10119
10120         if (res->tcp_flags_value != 0) {
10121                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10122                 filter.tcp_flags = res->tcp_flags_value;
10123         }
10124
10125         /* need convert to big endian. */
10126         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10127         filter.queue = res->queue_id;
10128
10129         if (!strcmp(res->ops, "add"))
10130                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10131                                 RTE_ETH_FILTER_NTUPLE,
10132                                 RTE_ETH_FILTER_ADD,
10133                                 &filter);
10134         else
10135                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10136                                 RTE_ETH_FILTER_NTUPLE,
10137                                 RTE_ETH_FILTER_DELETE,
10138                                 &filter);
10139         if (ret < 0)
10140                 printf("2tuple filter programming error: (%s)\n",
10141                         strerror(-ret));
10142
10143 }
10144
10145 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10146         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10147                                  filter, "2tuple_filter");
10148 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10149         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10150                                 port_id, UINT16);
10151 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10152         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10153                                  ops, "add#del");
10154 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10155         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10156                                 dst_port, "dst_port");
10157 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10158         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10159                                 dst_port_value, UINT16);
10160 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10161         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10162                                 protocol, "protocol");
10163 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10164         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10165                                 protocol_value, UINT8);
10166 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10167         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10168                                 mask, "mask");
10169 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10170         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10171                                 mask_value, INT8);
10172 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10173         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10174                                 tcp_flags, "tcp_flags");
10175 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10176         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10177                                 tcp_flags_value, UINT8);
10178 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10179         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10180                                 priority, "priority");
10181 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10182         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10183                                 priority_value, UINT8);
10184 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10185         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10186                                 queue, "queue");
10187 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10188         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10189                                 queue_id, UINT16);
10190
10191 cmdline_parse_inst_t cmd_2tuple_filter = {
10192         .f = cmd_2tuple_filter_parsed,
10193         .data = NULL,
10194         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10195                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10196                 "<queue_id>: Add a 2tuple filter",
10197         .tokens = {
10198                 (void *)&cmd_2tuple_filter_filter,
10199                 (void *)&cmd_2tuple_filter_port_id,
10200                 (void *)&cmd_2tuple_filter_ops,
10201                 (void *)&cmd_2tuple_filter_dst_port,
10202                 (void *)&cmd_2tuple_filter_dst_port_value,
10203                 (void *)&cmd_2tuple_filter_protocol,
10204                 (void *)&cmd_2tuple_filter_protocol_value,
10205                 (void *)&cmd_2tuple_filter_mask,
10206                 (void *)&cmd_2tuple_filter_mask_value,
10207                 (void *)&cmd_2tuple_filter_tcp_flags,
10208                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10209                 (void *)&cmd_2tuple_filter_priority,
10210                 (void *)&cmd_2tuple_filter_priority_value,
10211                 (void *)&cmd_2tuple_filter_queue,
10212                 (void *)&cmd_2tuple_filter_queue_id,
10213                 NULL,
10214         },
10215 };
10216
10217 /* *** ADD/REMOVE A 5tuple FILTER *** */
10218 struct cmd_5tuple_filter_result {
10219         cmdline_fixed_string_t filter;
10220         portid_t port_id;
10221         cmdline_fixed_string_t ops;
10222         cmdline_fixed_string_t dst_ip;
10223         cmdline_ipaddr_t dst_ip_value;
10224         cmdline_fixed_string_t src_ip;
10225         cmdline_ipaddr_t src_ip_value;
10226         cmdline_fixed_string_t dst_port;
10227         uint16_t dst_port_value;
10228         cmdline_fixed_string_t src_port;
10229         uint16_t src_port_value;
10230         cmdline_fixed_string_t protocol;
10231         uint8_t protocol_value;
10232         cmdline_fixed_string_t mask;
10233         uint8_t  mask_value;
10234         cmdline_fixed_string_t tcp_flags;
10235         uint8_t tcp_flags_value;
10236         cmdline_fixed_string_t priority;
10237         uint8_t  priority_value;
10238         cmdline_fixed_string_t queue;
10239         uint16_t  queue_id;
10240 };
10241
10242 static void
10243 cmd_5tuple_filter_parsed(void *parsed_result,
10244                         __attribute__((unused)) struct cmdline *cl,
10245                         __attribute__((unused)) void *data)
10246 {
10247         struct rte_eth_ntuple_filter filter;
10248         struct cmd_5tuple_filter_result *res = parsed_result;
10249         int ret = 0;
10250
10251         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10252         if (ret < 0) {
10253                 printf("ntuple filter is not supported on port %u.\n",
10254                         res->port_id);
10255                 return;
10256         }
10257
10258         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10259
10260         filter.flags = RTE_5TUPLE_FLAGS;
10261         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10262         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10263         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10264         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10265         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10266         filter.proto = res->protocol_value;
10267         filter.priority = res->priority_value;
10268         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10269                 printf("nonzero tcp_flags is only meaningful"
10270                         " when protocol is TCP.\n");
10271                 return;
10272         }
10273         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10274                 printf("invalid TCP flags.\n");
10275                 return;
10276         }
10277
10278         if (res->tcp_flags_value != 0) {
10279                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10280                 filter.tcp_flags = res->tcp_flags_value;
10281         }
10282
10283         if (res->dst_ip_value.family == AF_INET)
10284                 /* no need to convert, already big endian. */
10285                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10286         else {
10287                 if (filter.dst_ip_mask == 0) {
10288                         printf("can not support ipv6 involved compare.\n");
10289                         return;
10290                 }
10291                 filter.dst_ip = 0;
10292         }
10293
10294         if (res->src_ip_value.family == AF_INET)
10295                 /* no need to convert, already big endian. */
10296                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10297         else {
10298                 if (filter.src_ip_mask == 0) {
10299                         printf("can not support ipv6 involved compare.\n");
10300                         return;
10301                 }
10302                 filter.src_ip = 0;
10303         }
10304         /* need convert to big endian. */
10305         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10306         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10307         filter.queue = res->queue_id;
10308
10309         if (!strcmp(res->ops, "add"))
10310                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10311                                 RTE_ETH_FILTER_NTUPLE,
10312                                 RTE_ETH_FILTER_ADD,
10313                                 &filter);
10314         else
10315                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10316                                 RTE_ETH_FILTER_NTUPLE,
10317                                 RTE_ETH_FILTER_DELETE,
10318                                 &filter);
10319         if (ret < 0)
10320                 printf("5tuple filter programming error: (%s)\n",
10321                         strerror(-ret));
10322 }
10323
10324 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10325         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10326                                  filter, "5tuple_filter");
10327 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10328         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10329                                 port_id, UINT16);
10330 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10331         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10332                                  ops, "add#del");
10333 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10334         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10335                                 dst_ip, "dst_ip");
10336 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10337         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10338                                 dst_ip_value);
10339 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10340         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10341                                 src_ip, "src_ip");
10342 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10343         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10344                                 src_ip_value);
10345 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10346         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10347                                 dst_port, "dst_port");
10348 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10349         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10350                                 dst_port_value, UINT16);
10351 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10352         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10353                                 src_port, "src_port");
10354 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10355         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10356                                 src_port_value, UINT16);
10357 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10358         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10359                                 protocol, "protocol");
10360 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10361         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10362                                 protocol_value, UINT8);
10363 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10364         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10365                                 mask, "mask");
10366 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10367         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10368                                 mask_value, INT8);
10369 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10370         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10371                                 tcp_flags, "tcp_flags");
10372 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10373         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10374                                 tcp_flags_value, UINT8);
10375 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10376         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10377                                 priority, "priority");
10378 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10379         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10380                                 priority_value, UINT8);
10381 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10382         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10383                                 queue, "queue");
10384 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10385         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10386                                 queue_id, UINT16);
10387
10388 cmdline_parse_inst_t cmd_5tuple_filter = {
10389         .f = cmd_5tuple_filter_parsed,
10390         .data = NULL,
10391         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10392                 "src_ip <value> dst_port <value> src_port <value> "
10393                 "protocol <value>  mask <value> tcp_flags <value> "
10394                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10395         .tokens = {
10396                 (void *)&cmd_5tuple_filter_filter,
10397                 (void *)&cmd_5tuple_filter_port_id,
10398                 (void *)&cmd_5tuple_filter_ops,
10399                 (void *)&cmd_5tuple_filter_dst_ip,
10400                 (void *)&cmd_5tuple_filter_dst_ip_value,
10401                 (void *)&cmd_5tuple_filter_src_ip,
10402                 (void *)&cmd_5tuple_filter_src_ip_value,
10403                 (void *)&cmd_5tuple_filter_dst_port,
10404                 (void *)&cmd_5tuple_filter_dst_port_value,
10405                 (void *)&cmd_5tuple_filter_src_port,
10406                 (void *)&cmd_5tuple_filter_src_port_value,
10407                 (void *)&cmd_5tuple_filter_protocol,
10408                 (void *)&cmd_5tuple_filter_protocol_value,
10409                 (void *)&cmd_5tuple_filter_mask,
10410                 (void *)&cmd_5tuple_filter_mask_value,
10411                 (void *)&cmd_5tuple_filter_tcp_flags,
10412                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10413                 (void *)&cmd_5tuple_filter_priority,
10414                 (void *)&cmd_5tuple_filter_priority_value,
10415                 (void *)&cmd_5tuple_filter_queue,
10416                 (void *)&cmd_5tuple_filter_queue_id,
10417                 NULL,
10418         },
10419 };
10420
10421 /* *** ADD/REMOVE A flex FILTER *** */
10422 struct cmd_flex_filter_result {
10423         cmdline_fixed_string_t filter;
10424         cmdline_fixed_string_t ops;
10425         portid_t port_id;
10426         cmdline_fixed_string_t len;
10427         uint8_t len_value;
10428         cmdline_fixed_string_t bytes;
10429         cmdline_fixed_string_t bytes_value;
10430         cmdline_fixed_string_t mask;
10431         cmdline_fixed_string_t mask_value;
10432         cmdline_fixed_string_t priority;
10433         uint8_t priority_value;
10434         cmdline_fixed_string_t queue;
10435         uint16_t queue_id;
10436 };
10437
10438 static int xdigit2val(unsigned char c)
10439 {
10440         int val;
10441         if (isdigit(c))
10442                 val = c - '0';
10443         else if (isupper(c))
10444                 val = c - 'A' + 10;
10445         else
10446                 val = c - 'a' + 10;
10447         return val;
10448 }
10449
10450 static void
10451 cmd_flex_filter_parsed(void *parsed_result,
10452                           __attribute__((unused)) struct cmdline *cl,
10453                           __attribute__((unused)) void *data)
10454 {
10455         int ret = 0;
10456         struct rte_eth_flex_filter filter;
10457         struct cmd_flex_filter_result *res = parsed_result;
10458         char *bytes_ptr, *mask_ptr;
10459         uint16_t len, i, j = 0;
10460         char c;
10461         int val;
10462         uint8_t byte = 0;
10463
10464         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10465                 printf("the len exceed the max length 128\n");
10466                 return;
10467         }
10468         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10469         filter.len = res->len_value;
10470         filter.priority = res->priority_value;
10471         filter.queue = res->queue_id;
10472         bytes_ptr = res->bytes_value;
10473         mask_ptr = res->mask_value;
10474
10475          /* translate bytes string to array. */
10476         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10477                 (bytes_ptr[1] == 'X')))
10478                 bytes_ptr += 2;
10479         len = strnlen(bytes_ptr, res->len_value * 2);
10480         if (len == 0 || (len % 8 != 0)) {
10481                 printf("please check len and bytes input\n");
10482                 return;
10483         }
10484         for (i = 0; i < len; i++) {
10485                 c = bytes_ptr[i];
10486                 if (isxdigit(c) == 0) {
10487                         /* invalid characters. */
10488                         printf("invalid input\n");
10489                         return;
10490                 }
10491                 val = xdigit2val(c);
10492                 if (i % 2) {
10493                         byte |= val;
10494                         filter.bytes[j] = byte;
10495                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10496                         j++;
10497                         byte = 0;
10498                 } else
10499                         byte |= val << 4;
10500         }
10501         printf("\n");
10502          /* translate mask string to uint8_t array. */
10503         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10504                 (mask_ptr[1] == 'X')))
10505                 mask_ptr += 2;
10506         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10507         if (len == 0) {
10508                 printf("invalid input\n");
10509                 return;
10510         }
10511         j = 0;
10512         byte = 0;
10513         for (i = 0; i < len; i++) {
10514                 c = mask_ptr[i];
10515                 if (isxdigit(c) == 0) {
10516                         /* invalid characters. */
10517                         printf("invalid input\n");
10518                         return;
10519                 }
10520                 val = xdigit2val(c);
10521                 if (i % 2) {
10522                         byte |= val;
10523                         filter.mask[j] = byte;
10524                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10525                         j++;
10526                         byte = 0;
10527                 } else
10528                         byte |= val << 4;
10529         }
10530         printf("\n");
10531
10532         if (!strcmp(res->ops, "add"))
10533                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10534                                 RTE_ETH_FILTER_FLEXIBLE,
10535                                 RTE_ETH_FILTER_ADD,
10536                                 &filter);
10537         else
10538                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10539                                 RTE_ETH_FILTER_FLEXIBLE,
10540                                 RTE_ETH_FILTER_DELETE,
10541                                 &filter);
10542
10543         if (ret < 0)
10544                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10545 }
10546
10547 cmdline_parse_token_string_t cmd_flex_filter_filter =
10548         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10549                                 filter, "flex_filter");
10550 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10551         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10552                                 port_id, UINT16);
10553 cmdline_parse_token_string_t cmd_flex_filter_ops =
10554         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10555                                 ops, "add#del");
10556 cmdline_parse_token_string_t cmd_flex_filter_len =
10557         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10558                                 len, "len");
10559 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10560         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10561                                 len_value, UINT8);
10562 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10563         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10564                                 bytes, "bytes");
10565 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10566         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10567                                 bytes_value, NULL);
10568 cmdline_parse_token_string_t cmd_flex_filter_mask =
10569         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10570                                 mask, "mask");
10571 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10572         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10573                                 mask_value, NULL);
10574 cmdline_parse_token_string_t cmd_flex_filter_priority =
10575         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10576                                 priority, "priority");
10577 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10578         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10579                                 priority_value, UINT8);
10580 cmdline_parse_token_string_t cmd_flex_filter_queue =
10581         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10582                                 queue, "queue");
10583 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10584         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10585                                 queue_id, UINT16);
10586 cmdline_parse_inst_t cmd_flex_filter = {
10587         .f = cmd_flex_filter_parsed,
10588         .data = NULL,
10589         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10590                 "<value> mask <value> priority <value> queue <queue_id>: "
10591                 "Add/Del a flex filter",
10592         .tokens = {
10593                 (void *)&cmd_flex_filter_filter,
10594                 (void *)&cmd_flex_filter_port_id,
10595                 (void *)&cmd_flex_filter_ops,
10596                 (void *)&cmd_flex_filter_len,
10597                 (void *)&cmd_flex_filter_len_value,
10598                 (void *)&cmd_flex_filter_bytes,
10599                 (void *)&cmd_flex_filter_bytes_value,
10600                 (void *)&cmd_flex_filter_mask,
10601                 (void *)&cmd_flex_filter_mask_value,
10602                 (void *)&cmd_flex_filter_priority,
10603                 (void *)&cmd_flex_filter_priority_value,
10604                 (void *)&cmd_flex_filter_queue,
10605                 (void *)&cmd_flex_filter_queue_id,
10606                 NULL,
10607         },
10608 };
10609
10610 /* *** Filters Control *** */
10611
10612 /* *** deal with ethertype filter *** */
10613 struct cmd_ethertype_filter_result {
10614         cmdline_fixed_string_t filter;
10615         portid_t port_id;
10616         cmdline_fixed_string_t ops;
10617         cmdline_fixed_string_t mac;
10618         struct rte_ether_addr mac_addr;
10619         cmdline_fixed_string_t ethertype;
10620         uint16_t ethertype_value;
10621         cmdline_fixed_string_t drop;
10622         cmdline_fixed_string_t queue;
10623         uint16_t  queue_id;
10624 };
10625
10626 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10627         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10628                                  filter, "ethertype_filter");
10629 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10630         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10631                               port_id, UINT16);
10632 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10633         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10634                                  ops, "add#del");
10635 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10636         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10637                                  mac, "mac_addr#mac_ignr");
10638 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10639         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10640                                      mac_addr);
10641 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10642         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10643                                  ethertype, "ethertype");
10644 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10645         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10646                               ethertype_value, UINT16);
10647 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10648         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10649                                  drop, "drop#fwd");
10650 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10651         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10652                                  queue, "queue");
10653 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10654         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10655                               queue_id, UINT16);
10656
10657 static void
10658 cmd_ethertype_filter_parsed(void *parsed_result,
10659                           __attribute__((unused)) struct cmdline *cl,
10660                           __attribute__((unused)) void *data)
10661 {
10662         struct cmd_ethertype_filter_result *res = parsed_result;
10663         struct rte_eth_ethertype_filter filter;
10664         int ret = 0;
10665
10666         ret = rte_eth_dev_filter_supported(res->port_id,
10667                         RTE_ETH_FILTER_ETHERTYPE);
10668         if (ret < 0) {
10669                 printf("ethertype filter is not supported on port %u.\n",
10670                         res->port_id);
10671                 return;
10672         }
10673
10674         memset(&filter, 0, sizeof(filter));
10675         if (!strcmp(res->mac, "mac_addr")) {
10676                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10677                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10678                         sizeof(struct rte_ether_addr));
10679         }
10680         if (!strcmp(res->drop, "drop"))
10681                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10682         filter.ether_type = res->ethertype_value;
10683         filter.queue = res->queue_id;
10684
10685         if (!strcmp(res->ops, "add"))
10686                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10687                                 RTE_ETH_FILTER_ETHERTYPE,
10688                                 RTE_ETH_FILTER_ADD,
10689                                 &filter);
10690         else
10691                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10692                                 RTE_ETH_FILTER_ETHERTYPE,
10693                                 RTE_ETH_FILTER_DELETE,
10694                                 &filter);
10695         if (ret < 0)
10696                 printf("ethertype filter programming error: (%s)\n",
10697                         strerror(-ret));
10698 }
10699
10700 cmdline_parse_inst_t cmd_ethertype_filter = {
10701         .f = cmd_ethertype_filter_parsed,
10702         .data = NULL,
10703         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10704                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10705                 "Add or delete an ethertype filter entry",
10706         .tokens = {
10707                 (void *)&cmd_ethertype_filter_filter,
10708                 (void *)&cmd_ethertype_filter_port_id,
10709                 (void *)&cmd_ethertype_filter_ops,
10710                 (void *)&cmd_ethertype_filter_mac,
10711                 (void *)&cmd_ethertype_filter_mac_addr,
10712                 (void *)&cmd_ethertype_filter_ethertype,
10713                 (void *)&cmd_ethertype_filter_ethertype_value,
10714                 (void *)&cmd_ethertype_filter_drop,
10715                 (void *)&cmd_ethertype_filter_queue,
10716                 (void *)&cmd_ethertype_filter_queue_id,
10717                 NULL,
10718         },
10719 };
10720
10721 /* *** deal with flow director filter *** */
10722 struct cmd_flow_director_result {
10723         cmdline_fixed_string_t flow_director_filter;
10724         portid_t port_id;
10725         cmdline_fixed_string_t mode;
10726         cmdline_fixed_string_t mode_value;
10727         cmdline_fixed_string_t ops;
10728         cmdline_fixed_string_t flow;
10729         cmdline_fixed_string_t flow_type;
10730         cmdline_fixed_string_t ether;
10731         uint16_t ether_type;
10732         cmdline_fixed_string_t src;
10733         cmdline_ipaddr_t ip_src;
10734         uint16_t port_src;
10735         cmdline_fixed_string_t dst;
10736         cmdline_ipaddr_t ip_dst;
10737         uint16_t port_dst;
10738         cmdline_fixed_string_t verify_tag;
10739         uint32_t verify_tag_value;
10740         cmdline_fixed_string_t tos;
10741         uint8_t tos_value;
10742         cmdline_fixed_string_t proto;
10743         uint8_t proto_value;
10744         cmdline_fixed_string_t ttl;
10745         uint8_t ttl_value;
10746         cmdline_fixed_string_t vlan;
10747         uint16_t vlan_value;
10748         cmdline_fixed_string_t flexbytes;
10749         cmdline_fixed_string_t flexbytes_value;
10750         cmdline_fixed_string_t pf_vf;
10751         cmdline_fixed_string_t drop;
10752         cmdline_fixed_string_t queue;
10753         uint16_t  queue_id;
10754         cmdline_fixed_string_t fd_id;
10755         uint32_t  fd_id_value;
10756         cmdline_fixed_string_t mac;
10757         struct rte_ether_addr mac_addr;
10758         cmdline_fixed_string_t tunnel;
10759         cmdline_fixed_string_t tunnel_type;
10760         cmdline_fixed_string_t tunnel_id;
10761         uint32_t tunnel_id_value;
10762         cmdline_fixed_string_t packet;
10763         char filepath[];
10764 };
10765
10766 static inline int
10767 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10768 {
10769         char s[256];
10770         const char *p, *p0 = q_arg;
10771         char *end;
10772         unsigned long int_fld;
10773         char *str_fld[max_num];
10774         int i;
10775         unsigned size;
10776         int ret = -1;
10777
10778         p = strchr(p0, '(');
10779         if (p == NULL)
10780                 return -1;
10781         ++p;
10782         p0 = strchr(p, ')');
10783         if (p0 == NULL)
10784                 return -1;
10785
10786         size = p0 - p;
10787         if (size >= sizeof(s))
10788                 return -1;
10789
10790         snprintf(s, sizeof(s), "%.*s", size, p);
10791         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10792         if (ret < 0 || ret > max_num)
10793                 return -1;
10794         for (i = 0; i < ret; i++) {
10795                 errno = 0;
10796                 int_fld = strtoul(str_fld[i], &end, 0);
10797                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10798                         return -1;
10799                 flexbytes[i] = (uint8_t)int_fld;
10800         }
10801         return ret;
10802 }
10803
10804 static uint16_t
10805 str2flowtype(char *string)
10806 {
10807         uint8_t i = 0;
10808         static const struct {
10809                 char str[32];
10810                 uint16_t type;
10811         } flowtype_str[] = {
10812                 {"raw", RTE_ETH_FLOW_RAW},
10813                 {"ipv4", RTE_ETH_FLOW_IPV4},
10814                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10815                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10816                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10817                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10818                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10819                 {"ipv6", RTE_ETH_FLOW_IPV6},
10820                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10821                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10822                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10823                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10824                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10825                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10826         };
10827
10828         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10829                 if (!strcmp(flowtype_str[i].str, string))
10830                         return flowtype_str[i].type;
10831         }
10832
10833         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10834                 return (uint16_t)atoi(string);
10835
10836         return RTE_ETH_FLOW_UNKNOWN;
10837 }
10838
10839 static enum rte_eth_fdir_tunnel_type
10840 str2fdir_tunneltype(char *string)
10841 {
10842         uint8_t i = 0;
10843
10844         static const struct {
10845                 char str[32];
10846                 enum rte_eth_fdir_tunnel_type type;
10847         } tunneltype_str[] = {
10848                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10849                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10850         };
10851
10852         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10853                 if (!strcmp(tunneltype_str[i].str, string))
10854                         return tunneltype_str[i].type;
10855         }
10856         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10857 }
10858
10859 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10860 do { \
10861         if ((ip_addr).family == AF_INET) \
10862                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10863         else { \
10864                 printf("invalid parameter.\n"); \
10865                 return; \
10866         } \
10867 } while (0)
10868
10869 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10870 do { \
10871         if ((ip_addr).family == AF_INET6) \
10872                 rte_memcpy(&(ip), \
10873                                  &((ip_addr).addr.ipv6), \
10874                                  sizeof(struct in6_addr)); \
10875         else { \
10876                 printf("invalid parameter.\n"); \
10877                 return; \
10878         } \
10879 } while (0)
10880
10881 static void
10882 cmd_flow_director_filter_parsed(void *parsed_result,
10883                           __attribute__((unused)) struct cmdline *cl,
10884                           __attribute__((unused)) void *data)
10885 {
10886         struct cmd_flow_director_result *res = parsed_result;
10887         struct rte_eth_fdir_filter entry;
10888         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10889         char *end;
10890         unsigned long vf_id;
10891         int ret = 0;
10892
10893         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10894         if (ret < 0) {
10895                 printf("flow director is not supported on port %u.\n",
10896                         res->port_id);
10897                 return;
10898         }
10899         memset(flexbytes, 0, sizeof(flexbytes));
10900         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10901
10902         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10903                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10904                         printf("Please set mode to MAC-VLAN.\n");
10905                         return;
10906                 }
10907         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10908                 if (strcmp(res->mode_value, "Tunnel")) {
10909                         printf("Please set mode to Tunnel.\n");
10910                         return;
10911                 }
10912         } else {
10913                 if (!strcmp(res->mode_value, "raw")) {
10914 #ifdef RTE_LIBRTE_I40E_PMD
10915                         struct rte_pmd_i40e_flow_type_mapping
10916                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10917                         struct rte_pmd_i40e_pkt_template_conf conf;
10918                         uint16_t flow_type = str2flowtype(res->flow_type);
10919                         uint16_t i, port = res->port_id;
10920                         uint8_t add;
10921
10922                         memset(&conf, 0, sizeof(conf));
10923
10924                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10925                                 printf("Invalid flow type specified.\n");
10926                                 return;
10927                         }
10928                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10929                                                                  mapping);
10930                         if (ret)
10931                                 return;
10932                         if (mapping[flow_type].pctype == 0ULL) {
10933                                 printf("Invalid flow type specified.\n");
10934                                 return;
10935                         }
10936                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10937                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10938                                         conf.input.pctype = i;
10939                                         break;
10940                                 }
10941                         }
10942
10943                         conf.input.packet = open_file(res->filepath,
10944                                                 &conf.input.length);
10945                         if (!conf.input.packet)
10946                                 return;
10947                         if (!strcmp(res->drop, "drop"))
10948                                 conf.action.behavior =
10949                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10950                         else
10951                                 conf.action.behavior =
10952                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10953                         conf.action.report_status =
10954                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10955                         conf.action.rx_queue = res->queue_id;
10956                         conf.soft_id = res->fd_id_value;
10957                         add  = strcmp(res->ops, "del") ? 1 : 0;
10958                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10959                                                                         &conf,
10960                                                                         add);
10961                         if (ret < 0)
10962                                 printf("flow director config error: (%s)\n",
10963                                        strerror(-ret));
10964                         close_file(conf.input.packet);
10965 #endif
10966                         return;
10967                 } else if (strcmp(res->mode_value, "IP")) {
10968                         printf("Please set mode to IP or raw.\n");
10969                         return;
10970                 }
10971                 entry.input.flow_type = str2flowtype(res->flow_type);
10972         }
10973
10974         ret = parse_flexbytes(res->flexbytes_value,
10975                                         flexbytes,
10976                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10977         if (ret < 0) {
10978                 printf("error: Cannot parse flexbytes input.\n");
10979                 return;
10980         }
10981
10982         switch (entry.input.flow_type) {
10983         case RTE_ETH_FLOW_FRAG_IPV4:
10984         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10985                 entry.input.flow.ip4_flow.proto = res->proto_value;
10986                 /* fall-through */
10987         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10988         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10989                 IPV4_ADDR_TO_UINT(res->ip_dst,
10990                         entry.input.flow.ip4_flow.dst_ip);
10991                 IPV4_ADDR_TO_UINT(res->ip_src,
10992                         entry.input.flow.ip4_flow.src_ip);
10993                 entry.input.flow.ip4_flow.tos = res->tos_value;
10994                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10995                 /* need convert to big endian. */
10996                 entry.input.flow.udp4_flow.dst_port =
10997                                 rte_cpu_to_be_16(res->port_dst);
10998                 entry.input.flow.udp4_flow.src_port =
10999                                 rte_cpu_to_be_16(res->port_src);
11000                 break;
11001         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11002                 IPV4_ADDR_TO_UINT(res->ip_dst,
11003                         entry.input.flow.sctp4_flow.ip.dst_ip);
11004                 IPV4_ADDR_TO_UINT(res->ip_src,
11005                         entry.input.flow.sctp4_flow.ip.src_ip);
11006                 entry.input.flow.ip4_flow.tos = res->tos_value;
11007                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11008                 /* need convert to big endian. */
11009                 entry.input.flow.sctp4_flow.dst_port =
11010                                 rte_cpu_to_be_16(res->port_dst);
11011                 entry.input.flow.sctp4_flow.src_port =
11012                                 rte_cpu_to_be_16(res->port_src);
11013                 entry.input.flow.sctp4_flow.verify_tag =
11014                                 rte_cpu_to_be_32(res->verify_tag_value);
11015                 break;
11016         case RTE_ETH_FLOW_FRAG_IPV6:
11017         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11018                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11019                 /* fall-through */
11020         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11021         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11022                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11023                         entry.input.flow.ipv6_flow.dst_ip);
11024                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11025                         entry.input.flow.ipv6_flow.src_ip);
11026                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11027                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11028                 /* need convert to big endian. */
11029                 entry.input.flow.udp6_flow.dst_port =
11030                                 rte_cpu_to_be_16(res->port_dst);
11031                 entry.input.flow.udp6_flow.src_port =
11032                                 rte_cpu_to_be_16(res->port_src);
11033                 break;
11034         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11035                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11036                         entry.input.flow.sctp6_flow.ip.dst_ip);
11037                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11038                         entry.input.flow.sctp6_flow.ip.src_ip);
11039                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11040                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11041                 /* need convert to big endian. */
11042                 entry.input.flow.sctp6_flow.dst_port =
11043                                 rte_cpu_to_be_16(res->port_dst);
11044                 entry.input.flow.sctp6_flow.src_port =
11045                                 rte_cpu_to_be_16(res->port_src);
11046                 entry.input.flow.sctp6_flow.verify_tag =
11047                                 rte_cpu_to_be_32(res->verify_tag_value);
11048                 break;
11049         case RTE_ETH_FLOW_L2_PAYLOAD:
11050                 entry.input.flow.l2_flow.ether_type =
11051                         rte_cpu_to_be_16(res->ether_type);
11052                 break;
11053         default:
11054                 break;
11055         }
11056
11057         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11058                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11059                                  &res->mac_addr,
11060                                  sizeof(struct rte_ether_addr));
11061
11062         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11063                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11064                                  &res->mac_addr,
11065                                  sizeof(struct rte_ether_addr));
11066                 entry.input.flow.tunnel_flow.tunnel_type =
11067                         str2fdir_tunneltype(res->tunnel_type);
11068                 entry.input.flow.tunnel_flow.tunnel_id =
11069                         rte_cpu_to_be_32(res->tunnel_id_value);
11070         }
11071
11072         rte_memcpy(entry.input.flow_ext.flexbytes,
11073                    flexbytes,
11074                    RTE_ETH_FDIR_MAX_FLEXLEN);
11075
11076         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11077
11078         entry.action.flex_off = 0;  /*use 0 by default */
11079         if (!strcmp(res->drop, "drop"))
11080                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11081         else
11082                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11083
11084         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11085             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11086                 if (!strcmp(res->pf_vf, "pf"))
11087                         entry.input.flow_ext.is_vf = 0;
11088                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11089                         struct rte_eth_dev_info dev_info;
11090
11091                         rte_eth_dev_info_get(res->port_id, &dev_info);
11092                         errno = 0;
11093                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11094                         if (errno != 0 || *end != '\0' ||
11095                             vf_id >= dev_info.max_vfs) {
11096                                 printf("invalid parameter %s.\n", res->pf_vf);
11097                                 return;
11098                         }
11099                         entry.input.flow_ext.is_vf = 1;
11100                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11101                 } else {
11102                         printf("invalid parameter %s.\n", res->pf_vf);
11103                         return;
11104                 }
11105         }
11106
11107         /* set to report FD ID by default */
11108         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11109         entry.action.rx_queue = res->queue_id;
11110         entry.soft_id = res->fd_id_value;
11111         if (!strcmp(res->ops, "add"))
11112                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11113                                              RTE_ETH_FILTER_ADD, &entry);
11114         else if (!strcmp(res->ops, "del"))
11115                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11116                                              RTE_ETH_FILTER_DELETE, &entry);
11117         else
11118                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11119                                              RTE_ETH_FILTER_UPDATE, &entry);
11120         if (ret < 0)
11121                 printf("flow director programming error: (%s)\n",
11122                         strerror(-ret));
11123 }
11124
11125 cmdline_parse_token_string_t cmd_flow_director_filter =
11126         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11127                                  flow_director_filter, "flow_director_filter");
11128 cmdline_parse_token_num_t cmd_flow_director_port_id =
11129         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11130                               port_id, UINT16);
11131 cmdline_parse_token_string_t cmd_flow_director_ops =
11132         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11133                                  ops, "add#del#update");
11134 cmdline_parse_token_string_t cmd_flow_director_flow =
11135         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11136                                  flow, "flow");
11137 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11138         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11139                 flow_type, NULL);
11140 cmdline_parse_token_string_t cmd_flow_director_ether =
11141         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11142                                  ether, "ether");
11143 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11144         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11145                               ether_type, UINT16);
11146 cmdline_parse_token_string_t cmd_flow_director_src =
11147         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11148                                  src, "src");
11149 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11150         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11151                                  ip_src);
11152 cmdline_parse_token_num_t cmd_flow_director_port_src =
11153         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11154                               port_src, UINT16);
11155 cmdline_parse_token_string_t cmd_flow_director_dst =
11156         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11157                                  dst, "dst");
11158 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11159         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11160                                  ip_dst);
11161 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11162         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11163                               port_dst, UINT16);
11164 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11165         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11166                                   verify_tag, "verify_tag");
11167 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11168         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11169                               verify_tag_value, UINT32);
11170 cmdline_parse_token_string_t cmd_flow_director_tos =
11171         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11172                                  tos, "tos");
11173 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11174         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11175                               tos_value, UINT8);
11176 cmdline_parse_token_string_t cmd_flow_director_proto =
11177         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11178                                  proto, "proto");
11179 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11180         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11181                               proto_value, UINT8);
11182 cmdline_parse_token_string_t cmd_flow_director_ttl =
11183         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11184                                  ttl, "ttl");
11185 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11186         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11187                               ttl_value, UINT8);
11188 cmdline_parse_token_string_t cmd_flow_director_vlan =
11189         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11190                                  vlan, "vlan");
11191 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11192         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11193                               vlan_value, UINT16);
11194 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11195         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11196                                  flexbytes, "flexbytes");
11197 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11198         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11199                               flexbytes_value, NULL);
11200 cmdline_parse_token_string_t cmd_flow_director_drop =
11201         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11202                                  drop, "drop#fwd");
11203 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11204         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11205                               pf_vf, NULL);
11206 cmdline_parse_token_string_t cmd_flow_director_queue =
11207         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11208                                  queue, "queue");
11209 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11210         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11211                               queue_id, UINT16);
11212 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11213         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11214                                  fd_id, "fd_id");
11215 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11216         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11217                               fd_id_value, UINT32);
11218
11219 cmdline_parse_token_string_t cmd_flow_director_mode =
11220         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11221                                  mode, "mode");
11222 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11223         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11224                                  mode_value, "IP");
11225 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11226         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11227                                  mode_value, "MAC-VLAN");
11228 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11229         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11230                                  mode_value, "Tunnel");
11231 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11232         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11233                                  mode_value, "raw");
11234 cmdline_parse_token_string_t cmd_flow_director_mac =
11235         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11236                                  mac, "mac");
11237 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11238         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11239                                     mac_addr);
11240 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11241         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11242                                  tunnel, "tunnel");
11243 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11244         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11245                                  tunnel_type, "NVGRE#VxLAN");
11246 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11247         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11248                                  tunnel_id, "tunnel-id");
11249 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11250         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11251                               tunnel_id_value, UINT32);
11252 cmdline_parse_token_string_t cmd_flow_director_packet =
11253         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11254                                  packet, "packet");
11255 cmdline_parse_token_string_t cmd_flow_director_filepath =
11256         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11257                                  filepath, NULL);
11258
11259 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11260         .f = cmd_flow_director_filter_parsed,
11261         .data = NULL,
11262         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11263                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11264                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11265                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11266                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11267                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11268                 "fd_id <fd_id_value>: "
11269                 "Add or delete an ip flow director entry on NIC",
11270         .tokens = {
11271                 (void *)&cmd_flow_director_filter,
11272                 (void *)&cmd_flow_director_port_id,
11273                 (void *)&cmd_flow_director_mode,
11274                 (void *)&cmd_flow_director_mode_ip,
11275                 (void *)&cmd_flow_director_ops,
11276                 (void *)&cmd_flow_director_flow,
11277                 (void *)&cmd_flow_director_flow_type,
11278                 (void *)&cmd_flow_director_src,
11279                 (void *)&cmd_flow_director_ip_src,
11280                 (void *)&cmd_flow_director_dst,
11281                 (void *)&cmd_flow_director_ip_dst,
11282                 (void *)&cmd_flow_director_tos,
11283                 (void *)&cmd_flow_director_tos_value,
11284                 (void *)&cmd_flow_director_proto,
11285                 (void *)&cmd_flow_director_proto_value,
11286                 (void *)&cmd_flow_director_ttl,
11287                 (void *)&cmd_flow_director_ttl_value,
11288                 (void *)&cmd_flow_director_vlan,
11289                 (void *)&cmd_flow_director_vlan_value,
11290                 (void *)&cmd_flow_director_flexbytes,
11291                 (void *)&cmd_flow_director_flexbytes_value,
11292                 (void *)&cmd_flow_director_drop,
11293                 (void *)&cmd_flow_director_pf_vf,
11294                 (void *)&cmd_flow_director_queue,
11295                 (void *)&cmd_flow_director_queue_id,
11296                 (void *)&cmd_flow_director_fd_id,
11297                 (void *)&cmd_flow_director_fd_id_value,
11298                 NULL,
11299         },
11300 };
11301
11302 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11303         .f = cmd_flow_director_filter_parsed,
11304         .data = NULL,
11305         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11306                 "director entry on NIC",
11307         .tokens = {
11308                 (void *)&cmd_flow_director_filter,
11309                 (void *)&cmd_flow_director_port_id,
11310                 (void *)&cmd_flow_director_mode,
11311                 (void *)&cmd_flow_director_mode_ip,
11312                 (void *)&cmd_flow_director_ops,
11313                 (void *)&cmd_flow_director_flow,
11314                 (void *)&cmd_flow_director_flow_type,
11315                 (void *)&cmd_flow_director_src,
11316                 (void *)&cmd_flow_director_ip_src,
11317                 (void *)&cmd_flow_director_port_src,
11318                 (void *)&cmd_flow_director_dst,
11319                 (void *)&cmd_flow_director_ip_dst,
11320                 (void *)&cmd_flow_director_port_dst,
11321                 (void *)&cmd_flow_director_tos,
11322                 (void *)&cmd_flow_director_tos_value,
11323                 (void *)&cmd_flow_director_ttl,
11324                 (void *)&cmd_flow_director_ttl_value,
11325                 (void *)&cmd_flow_director_vlan,
11326                 (void *)&cmd_flow_director_vlan_value,
11327                 (void *)&cmd_flow_director_flexbytes,
11328                 (void *)&cmd_flow_director_flexbytes_value,
11329                 (void *)&cmd_flow_director_drop,
11330                 (void *)&cmd_flow_director_pf_vf,
11331                 (void *)&cmd_flow_director_queue,
11332                 (void *)&cmd_flow_director_queue_id,
11333                 (void *)&cmd_flow_director_fd_id,
11334                 (void *)&cmd_flow_director_fd_id_value,
11335                 NULL,
11336         },
11337 };
11338
11339 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11340         .f = cmd_flow_director_filter_parsed,
11341         .data = NULL,
11342         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11343                 "director entry on NIC",
11344         .tokens = {
11345                 (void *)&cmd_flow_director_filter,
11346                 (void *)&cmd_flow_director_port_id,
11347                 (void *)&cmd_flow_director_mode,
11348                 (void *)&cmd_flow_director_mode_ip,
11349                 (void *)&cmd_flow_director_ops,
11350                 (void *)&cmd_flow_director_flow,
11351                 (void *)&cmd_flow_director_flow_type,
11352                 (void *)&cmd_flow_director_src,
11353                 (void *)&cmd_flow_director_ip_src,
11354                 (void *)&cmd_flow_director_port_src,
11355                 (void *)&cmd_flow_director_dst,
11356                 (void *)&cmd_flow_director_ip_dst,
11357                 (void *)&cmd_flow_director_port_dst,
11358                 (void *)&cmd_flow_director_verify_tag,
11359                 (void *)&cmd_flow_director_verify_tag_value,
11360                 (void *)&cmd_flow_director_tos,
11361                 (void *)&cmd_flow_director_tos_value,
11362                 (void *)&cmd_flow_director_ttl,
11363                 (void *)&cmd_flow_director_ttl_value,
11364                 (void *)&cmd_flow_director_vlan,
11365                 (void *)&cmd_flow_director_vlan_value,
11366                 (void *)&cmd_flow_director_flexbytes,
11367                 (void *)&cmd_flow_director_flexbytes_value,
11368                 (void *)&cmd_flow_director_drop,
11369                 (void *)&cmd_flow_director_pf_vf,
11370                 (void *)&cmd_flow_director_queue,
11371                 (void *)&cmd_flow_director_queue_id,
11372                 (void *)&cmd_flow_director_fd_id,
11373                 (void *)&cmd_flow_director_fd_id_value,
11374                 NULL,
11375         },
11376 };
11377
11378 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11379         .f = cmd_flow_director_filter_parsed,
11380         .data = NULL,
11381         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11382                 "director entry on NIC",
11383         .tokens = {
11384                 (void *)&cmd_flow_director_filter,
11385                 (void *)&cmd_flow_director_port_id,
11386                 (void *)&cmd_flow_director_mode,
11387                 (void *)&cmd_flow_director_mode_ip,
11388                 (void *)&cmd_flow_director_ops,
11389                 (void *)&cmd_flow_director_flow,
11390                 (void *)&cmd_flow_director_flow_type,
11391                 (void *)&cmd_flow_director_ether,
11392                 (void *)&cmd_flow_director_ether_type,
11393                 (void *)&cmd_flow_director_flexbytes,
11394                 (void *)&cmd_flow_director_flexbytes_value,
11395                 (void *)&cmd_flow_director_drop,
11396                 (void *)&cmd_flow_director_pf_vf,
11397                 (void *)&cmd_flow_director_queue,
11398                 (void *)&cmd_flow_director_queue_id,
11399                 (void *)&cmd_flow_director_fd_id,
11400                 (void *)&cmd_flow_director_fd_id_value,
11401                 NULL,
11402         },
11403 };
11404
11405 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11406         .f = cmd_flow_director_filter_parsed,
11407         .data = NULL,
11408         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11409                 "director entry on NIC",
11410         .tokens = {
11411                 (void *)&cmd_flow_director_filter,
11412                 (void *)&cmd_flow_director_port_id,
11413                 (void *)&cmd_flow_director_mode,
11414                 (void *)&cmd_flow_director_mode_mac_vlan,
11415                 (void *)&cmd_flow_director_ops,
11416                 (void *)&cmd_flow_director_mac,
11417                 (void *)&cmd_flow_director_mac_addr,
11418                 (void *)&cmd_flow_director_vlan,
11419                 (void *)&cmd_flow_director_vlan_value,
11420                 (void *)&cmd_flow_director_flexbytes,
11421                 (void *)&cmd_flow_director_flexbytes_value,
11422                 (void *)&cmd_flow_director_drop,
11423                 (void *)&cmd_flow_director_queue,
11424                 (void *)&cmd_flow_director_queue_id,
11425                 (void *)&cmd_flow_director_fd_id,
11426                 (void *)&cmd_flow_director_fd_id_value,
11427                 NULL,
11428         },
11429 };
11430
11431 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11432         .f = cmd_flow_director_filter_parsed,
11433         .data = NULL,
11434         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11435                 "director entry on NIC",
11436         .tokens = {
11437                 (void *)&cmd_flow_director_filter,
11438                 (void *)&cmd_flow_director_port_id,
11439                 (void *)&cmd_flow_director_mode,
11440                 (void *)&cmd_flow_director_mode_tunnel,
11441                 (void *)&cmd_flow_director_ops,
11442                 (void *)&cmd_flow_director_mac,
11443                 (void *)&cmd_flow_director_mac_addr,
11444                 (void *)&cmd_flow_director_vlan,
11445                 (void *)&cmd_flow_director_vlan_value,
11446                 (void *)&cmd_flow_director_tunnel,
11447                 (void *)&cmd_flow_director_tunnel_type,
11448                 (void *)&cmd_flow_director_tunnel_id,
11449                 (void *)&cmd_flow_director_tunnel_id_value,
11450                 (void *)&cmd_flow_director_flexbytes,
11451                 (void *)&cmd_flow_director_flexbytes_value,
11452                 (void *)&cmd_flow_director_drop,
11453                 (void *)&cmd_flow_director_queue,
11454                 (void *)&cmd_flow_director_queue_id,
11455                 (void *)&cmd_flow_director_fd_id,
11456                 (void *)&cmd_flow_director_fd_id_value,
11457                 NULL,
11458         },
11459 };
11460
11461 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11462         .f = cmd_flow_director_filter_parsed,
11463         .data = NULL,
11464         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11465                 "director entry on NIC",
11466         .tokens = {
11467                 (void *)&cmd_flow_director_filter,
11468                 (void *)&cmd_flow_director_port_id,
11469                 (void *)&cmd_flow_director_mode,
11470                 (void *)&cmd_flow_director_mode_raw,
11471                 (void *)&cmd_flow_director_ops,
11472                 (void *)&cmd_flow_director_flow,
11473                 (void *)&cmd_flow_director_flow_type,
11474                 (void *)&cmd_flow_director_drop,
11475                 (void *)&cmd_flow_director_queue,
11476                 (void *)&cmd_flow_director_queue_id,
11477                 (void *)&cmd_flow_director_fd_id,
11478                 (void *)&cmd_flow_director_fd_id_value,
11479                 (void *)&cmd_flow_director_packet,
11480                 (void *)&cmd_flow_director_filepath,
11481                 NULL,
11482         },
11483 };
11484
11485 struct cmd_flush_flow_director_result {
11486         cmdline_fixed_string_t flush_flow_director;
11487         portid_t port_id;
11488 };
11489
11490 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11491         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11492                                  flush_flow_director, "flush_flow_director");
11493 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11494         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11495                               port_id, UINT16);
11496
11497 static void
11498 cmd_flush_flow_director_parsed(void *parsed_result,
11499                           __attribute__((unused)) struct cmdline *cl,
11500                           __attribute__((unused)) void *data)
11501 {
11502         struct cmd_flow_director_result *res = parsed_result;
11503         int ret = 0;
11504
11505         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11506         if (ret < 0) {
11507                 printf("flow director is not supported on port %u.\n",
11508                         res->port_id);
11509                 return;
11510         }
11511
11512         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11513                         RTE_ETH_FILTER_FLUSH, NULL);
11514         if (ret < 0)
11515                 printf("flow director table flushing error: (%s)\n",
11516                         strerror(-ret));
11517 }
11518
11519 cmdline_parse_inst_t cmd_flush_flow_director = {
11520         .f = cmd_flush_flow_director_parsed,
11521         .data = NULL,
11522         .help_str = "flush_flow_director <port_id>: "
11523                 "Flush all flow director entries of a device on NIC",
11524         .tokens = {
11525                 (void *)&cmd_flush_flow_director_flush,
11526                 (void *)&cmd_flush_flow_director_port_id,
11527                 NULL,
11528         },
11529 };
11530
11531 /* *** deal with flow director mask *** */
11532 struct cmd_flow_director_mask_result {
11533         cmdline_fixed_string_t flow_director_mask;
11534         portid_t port_id;
11535         cmdline_fixed_string_t mode;
11536         cmdline_fixed_string_t mode_value;
11537         cmdline_fixed_string_t vlan;
11538         uint16_t vlan_mask;
11539         cmdline_fixed_string_t src_mask;
11540         cmdline_ipaddr_t ipv4_src;
11541         cmdline_ipaddr_t ipv6_src;
11542         uint16_t port_src;
11543         cmdline_fixed_string_t dst_mask;
11544         cmdline_ipaddr_t ipv4_dst;
11545         cmdline_ipaddr_t ipv6_dst;
11546         uint16_t port_dst;
11547         cmdline_fixed_string_t mac;
11548         uint8_t mac_addr_byte_mask;
11549         cmdline_fixed_string_t tunnel_id;
11550         uint32_t tunnel_id_mask;
11551         cmdline_fixed_string_t tunnel_type;
11552         uint8_t tunnel_type_mask;
11553 };
11554
11555 static void
11556 cmd_flow_director_mask_parsed(void *parsed_result,
11557                           __attribute__((unused)) struct cmdline *cl,
11558                           __attribute__((unused)) void *data)
11559 {
11560         struct cmd_flow_director_mask_result *res = parsed_result;
11561         struct rte_eth_fdir_masks *mask;
11562         struct rte_port *port;
11563
11564         port = &ports[res->port_id];
11565         /** Check if the port is not started **/
11566         if (port->port_status != RTE_PORT_STOPPED) {
11567                 printf("Please stop port %d first\n", res->port_id);
11568                 return;
11569         }
11570
11571         mask = &port->dev_conf.fdir_conf.mask;
11572
11573         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11574                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11575                         printf("Please set mode to MAC-VLAN.\n");
11576                         return;
11577                 }
11578
11579                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11580         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11581                 if (strcmp(res->mode_value, "Tunnel")) {
11582                         printf("Please set mode to Tunnel.\n");
11583                         return;
11584                 }
11585
11586                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11587                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11588                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11589                 mask->tunnel_type_mask = res->tunnel_type_mask;
11590         } else {
11591                 if (strcmp(res->mode_value, "IP")) {
11592                         printf("Please set mode to IP.\n");
11593                         return;
11594                 }
11595
11596                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11597                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11598                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11599                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11600                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11601                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11602                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11603         }
11604
11605         cmd_reconfig_device_queue(res->port_id, 1, 1);
11606 }
11607
11608 cmdline_parse_token_string_t cmd_flow_director_mask =
11609         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11610                                  flow_director_mask, "flow_director_mask");
11611 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11612         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11613                               port_id, UINT16);
11614 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11615         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11616                                  vlan, "vlan");
11617 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11618         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11619                               vlan_mask, UINT16);
11620 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11621         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11622                                  src_mask, "src_mask");
11623 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11624         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11625                                  ipv4_src);
11626 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11627         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11628                                  ipv6_src);
11629 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11630         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11631                               port_src, UINT16);
11632 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11633         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11634                                  dst_mask, "dst_mask");
11635 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11636         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11637                                  ipv4_dst);
11638 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11639         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11640                                  ipv6_dst);
11641 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11642         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11643                               port_dst, UINT16);
11644
11645 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11646         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11647                                  mode, "mode");
11648 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11649         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11650                                  mode_value, "IP");
11651 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11652         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11653                                  mode_value, "MAC-VLAN");
11654 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11655         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11656                                  mode_value, "Tunnel");
11657 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11658         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11659                                  mac, "mac");
11660 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11661         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11662                               mac_addr_byte_mask, UINT8);
11663 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11664         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11665                                  tunnel_type, "tunnel-type");
11666 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11667         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11668                               tunnel_type_mask, UINT8);
11669 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11670         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11671                                  tunnel_id, "tunnel-id");
11672 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11673         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11674                               tunnel_id_mask, UINT32);
11675
11676 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11677         .f = cmd_flow_director_mask_parsed,
11678         .data = NULL,
11679         .help_str = "flow_director_mask ... : "
11680                 "Set IP mode flow director's mask on NIC",
11681         .tokens = {
11682                 (void *)&cmd_flow_director_mask,
11683                 (void *)&cmd_flow_director_mask_port_id,
11684                 (void *)&cmd_flow_director_mask_mode,
11685                 (void *)&cmd_flow_director_mask_mode_ip,
11686                 (void *)&cmd_flow_director_mask_vlan,
11687                 (void *)&cmd_flow_director_mask_vlan_value,
11688                 (void *)&cmd_flow_director_mask_src,
11689                 (void *)&cmd_flow_director_mask_ipv4_src,
11690                 (void *)&cmd_flow_director_mask_ipv6_src,
11691                 (void *)&cmd_flow_director_mask_port_src,
11692                 (void *)&cmd_flow_director_mask_dst,
11693                 (void *)&cmd_flow_director_mask_ipv4_dst,
11694                 (void *)&cmd_flow_director_mask_ipv6_dst,
11695                 (void *)&cmd_flow_director_mask_port_dst,
11696                 NULL,
11697         },
11698 };
11699
11700 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11701         .f = cmd_flow_director_mask_parsed,
11702         .data = NULL,
11703         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11704                 "flow director's mask on NIC",
11705         .tokens = {
11706                 (void *)&cmd_flow_director_mask,
11707                 (void *)&cmd_flow_director_mask_port_id,
11708                 (void *)&cmd_flow_director_mask_mode,
11709                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11710                 (void *)&cmd_flow_director_mask_vlan,
11711                 (void *)&cmd_flow_director_mask_vlan_value,
11712                 NULL,
11713         },
11714 };
11715
11716 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11717         .f = cmd_flow_director_mask_parsed,
11718         .data = NULL,
11719         .help_str = "flow_director_mask ... : Set tunnel mode "
11720                 "flow director's mask on NIC",
11721         .tokens = {
11722                 (void *)&cmd_flow_director_mask,
11723                 (void *)&cmd_flow_director_mask_port_id,
11724                 (void *)&cmd_flow_director_mask_mode,
11725                 (void *)&cmd_flow_director_mask_mode_tunnel,
11726                 (void *)&cmd_flow_director_mask_vlan,
11727                 (void *)&cmd_flow_director_mask_vlan_value,
11728                 (void *)&cmd_flow_director_mask_mac,
11729                 (void *)&cmd_flow_director_mask_mac_value,
11730                 (void *)&cmd_flow_director_mask_tunnel_type,
11731                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11732                 (void *)&cmd_flow_director_mask_tunnel_id,
11733                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11734                 NULL,
11735         },
11736 };
11737
11738 /* *** deal with flow director mask on flexible payload *** */
11739 struct cmd_flow_director_flex_mask_result {
11740         cmdline_fixed_string_t flow_director_flexmask;
11741         portid_t port_id;
11742         cmdline_fixed_string_t flow;
11743         cmdline_fixed_string_t flow_type;
11744         cmdline_fixed_string_t mask;
11745 };
11746
11747 static void
11748 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11749                           __attribute__((unused)) struct cmdline *cl,
11750                           __attribute__((unused)) void *data)
11751 {
11752         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11753         struct rte_eth_fdir_info fdir_info;
11754         struct rte_eth_fdir_flex_mask flex_mask;
11755         struct rte_port *port;
11756         uint64_t flow_type_mask;
11757         uint16_t i;
11758         int ret;
11759
11760         port = &ports[res->port_id];
11761         /** Check if the port is not started **/
11762         if (port->port_status != RTE_PORT_STOPPED) {
11763                 printf("Please stop port %d first\n", res->port_id);
11764                 return;
11765         }
11766
11767         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11768         ret = parse_flexbytes(res->mask,
11769                         flex_mask.mask,
11770                         RTE_ETH_FDIR_MAX_FLEXLEN);
11771         if (ret < 0) {
11772                 printf("error: Cannot parse mask input.\n");
11773                 return;
11774         }
11775
11776         memset(&fdir_info, 0, sizeof(fdir_info));
11777         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11778                                 RTE_ETH_FILTER_INFO, &fdir_info);
11779         if (ret < 0) {
11780                 printf("Cannot get FDir filter info\n");
11781                 return;
11782         }
11783
11784         if (!strcmp(res->flow_type, "none")) {
11785                 /* means don't specify the flow type */
11786                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11787                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11788                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11789                                0, sizeof(struct rte_eth_fdir_flex_mask));
11790                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11791                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11792                                  &flex_mask,
11793                                  sizeof(struct rte_eth_fdir_flex_mask));
11794                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11795                 return;
11796         }
11797         flow_type_mask = fdir_info.flow_types_mask[0];
11798         if (!strcmp(res->flow_type, "all")) {
11799                 if (!flow_type_mask) {
11800                         printf("No flow type supported\n");
11801                         return;
11802                 }
11803                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11804                         if (flow_type_mask & (1ULL << i)) {
11805                                 flex_mask.flow_type = i;
11806                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11807                         }
11808                 }
11809                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11810                 return;
11811         }
11812         flex_mask.flow_type = str2flowtype(res->flow_type);
11813         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11814                 printf("Flow type %s not supported on port %d\n",
11815                                 res->flow_type, res->port_id);
11816                 return;
11817         }
11818         fdir_set_flex_mask(res->port_id, &flex_mask);
11819         cmd_reconfig_device_queue(res->port_id, 1, 1);
11820 }
11821
11822 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11823         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11824                                  flow_director_flexmask,
11825                                  "flow_director_flex_mask");
11826 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11827         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11828                               port_id, UINT16);
11829 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11830         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11831                                  flow, "flow");
11832 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11833         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11834                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11835                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11836 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11837         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11838                                  mask, NULL);
11839
11840 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11841         .f = cmd_flow_director_flex_mask_parsed,
11842         .data = NULL,
11843         .help_str = "flow_director_flex_mask ... : "
11844                 "Set flow director's flex mask on NIC",
11845         .tokens = {
11846                 (void *)&cmd_flow_director_flexmask,
11847                 (void *)&cmd_flow_director_flexmask_port_id,
11848                 (void *)&cmd_flow_director_flexmask_flow,
11849                 (void *)&cmd_flow_director_flexmask_flow_type,
11850                 (void *)&cmd_flow_director_flexmask_mask,
11851                 NULL,
11852         },
11853 };
11854
11855 /* *** deal with flow director flexible payload configuration *** */
11856 struct cmd_flow_director_flexpayload_result {
11857         cmdline_fixed_string_t flow_director_flexpayload;
11858         portid_t port_id;
11859         cmdline_fixed_string_t payload_layer;
11860         cmdline_fixed_string_t payload_cfg;
11861 };
11862
11863 static inline int
11864 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11865 {
11866         char s[256];
11867         const char *p, *p0 = q_arg;
11868         char *end;
11869         unsigned long int_fld;
11870         char *str_fld[max_num];
11871         int i;
11872         unsigned size;
11873         int ret = -1;
11874
11875         p = strchr(p0, '(');
11876         if (p == NULL)
11877                 return -1;
11878         ++p;
11879         p0 = strchr(p, ')');
11880         if (p0 == NULL)
11881                 return -1;
11882
11883         size = p0 - p;
11884         if (size >= sizeof(s))
11885                 return -1;
11886
11887         snprintf(s, sizeof(s), "%.*s", size, p);
11888         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11889         if (ret < 0 || ret > max_num)
11890                 return -1;
11891         for (i = 0; i < ret; i++) {
11892                 errno = 0;
11893                 int_fld = strtoul(str_fld[i], &end, 0);
11894                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11895                         return -1;
11896                 offsets[i] = (uint16_t)int_fld;
11897         }
11898         return ret;
11899 }
11900
11901 static void
11902 cmd_flow_director_flxpld_parsed(void *parsed_result,
11903                           __attribute__((unused)) struct cmdline *cl,
11904                           __attribute__((unused)) void *data)
11905 {
11906         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11907         struct rte_eth_flex_payload_cfg flex_cfg;
11908         struct rte_port *port;
11909         int ret = 0;
11910
11911         port = &ports[res->port_id];
11912         /** Check if the port is not started **/
11913         if (port->port_status != RTE_PORT_STOPPED) {
11914                 printf("Please stop port %d first\n", res->port_id);
11915                 return;
11916         }
11917
11918         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11919
11920         if (!strcmp(res->payload_layer, "raw"))
11921                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11922         else if (!strcmp(res->payload_layer, "l2"))
11923                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11924         else if (!strcmp(res->payload_layer, "l3"))
11925                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11926         else if (!strcmp(res->payload_layer, "l4"))
11927                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11928
11929         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11930                             RTE_ETH_FDIR_MAX_FLEXLEN);
11931         if (ret < 0) {
11932                 printf("error: Cannot parse flex payload input.\n");
11933                 return;
11934         }
11935
11936         fdir_set_flex_payload(res->port_id, &flex_cfg);
11937         cmd_reconfig_device_queue(res->port_id, 1, 1);
11938 }
11939
11940 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11941         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11942                                  flow_director_flexpayload,
11943                                  "flow_director_flex_payload");
11944 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11945         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11946                               port_id, UINT16);
11947 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11948         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11949                                  payload_layer, "raw#l2#l3#l4");
11950 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11951         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11952                                  payload_cfg, NULL);
11953
11954 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11955         .f = cmd_flow_director_flxpld_parsed,
11956         .data = NULL,
11957         .help_str = "flow_director_flexpayload ... : "
11958                 "Set flow director's flex payload on NIC",
11959         .tokens = {
11960                 (void *)&cmd_flow_director_flexpayload,
11961                 (void *)&cmd_flow_director_flexpayload_port_id,
11962                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11963                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11964                 NULL,
11965         },
11966 };
11967
11968 /* Generic flow interface command. */
11969 extern cmdline_parse_inst_t cmd_flow;
11970
11971 /* *** Classification Filters Control *** */
11972 /* *** Get symmetric hash enable per port *** */
11973 struct cmd_get_sym_hash_ena_per_port_result {
11974         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11975         portid_t port_id;
11976 };
11977
11978 static void
11979 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11980                                  __rte_unused struct cmdline *cl,
11981                                  __rte_unused void *data)
11982 {
11983         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11984         struct rte_eth_hash_filter_info info;
11985         int ret;
11986
11987         if (rte_eth_dev_filter_supported(res->port_id,
11988                                 RTE_ETH_FILTER_HASH) < 0) {
11989                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11990                                                         res->port_id);
11991                 return;
11992         }
11993
11994         memset(&info, 0, sizeof(info));
11995         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11996         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11997                                                 RTE_ETH_FILTER_GET, &info);
11998
11999         if (ret < 0) {
12000                 printf("Cannot get symmetric hash enable per port "
12001                                         "on port %u\n", res->port_id);
12002                 return;
12003         }
12004
12005         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12006                                 "enabled" : "disabled", res->port_id);
12007 }
12008
12009 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12010         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12011                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12012 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12013         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12014                 port_id, UINT16);
12015
12016 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12017         .f = cmd_get_sym_hash_per_port_parsed,
12018         .data = NULL,
12019         .help_str = "get_sym_hash_ena_per_port <port_id>",
12020         .tokens = {
12021                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12022                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12023                 NULL,
12024         },
12025 };
12026
12027 /* *** Set symmetric hash enable per port *** */
12028 struct cmd_set_sym_hash_ena_per_port_result {
12029         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12030         cmdline_fixed_string_t enable;
12031         portid_t port_id;
12032 };
12033
12034 static void
12035 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12036                                  __rte_unused struct cmdline *cl,
12037                                  __rte_unused void *data)
12038 {
12039         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12040         struct rte_eth_hash_filter_info info;
12041         int ret;
12042
12043         if (rte_eth_dev_filter_supported(res->port_id,
12044                                 RTE_ETH_FILTER_HASH) < 0) {
12045                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12046                                                         res->port_id);
12047                 return;
12048         }
12049
12050         memset(&info, 0, sizeof(info));
12051         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12052         if (!strcmp(res->enable, "enable"))
12053                 info.info.enable = 1;
12054         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12055                                         RTE_ETH_FILTER_SET, &info);
12056         if (ret < 0) {
12057                 printf("Cannot set symmetric hash enable per port on "
12058                                         "port %u\n", res->port_id);
12059                 return;
12060         }
12061         printf("Symmetric hash has been set to %s on port %u\n",
12062                                         res->enable, res->port_id);
12063 }
12064
12065 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12066         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12067                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12068 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12069         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12070                 port_id, UINT16);
12071 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12072         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12073                 enable, "enable#disable");
12074
12075 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12076         .f = cmd_set_sym_hash_per_port_parsed,
12077         .data = NULL,
12078         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12079         .tokens = {
12080                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12081                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12082                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12083                 NULL,
12084         },
12085 };
12086
12087 /* Get global config of hash function */
12088 struct cmd_get_hash_global_config_result {
12089         cmdline_fixed_string_t get_hash_global_config;
12090         portid_t port_id;
12091 };
12092
12093 static char *
12094 flowtype_to_str(uint16_t ftype)
12095 {
12096         uint16_t i;
12097         static struct {
12098                 char str[16];
12099                 uint16_t ftype;
12100         } ftype_table[] = {
12101                 {"ipv4", RTE_ETH_FLOW_IPV4},
12102                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12103                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12104                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12105                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12106                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12107                 {"ipv6", RTE_ETH_FLOW_IPV6},
12108                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12109                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12110                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12111                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12112                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12113                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12114                 {"port", RTE_ETH_FLOW_PORT},
12115                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12116                 {"geneve", RTE_ETH_FLOW_GENEVE},
12117                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12118                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12119         };
12120
12121         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12122                 if (ftype_table[i].ftype == ftype)
12123                         return ftype_table[i].str;
12124         }
12125
12126         return NULL;
12127 }
12128
12129 static void
12130 cmd_get_hash_global_config_parsed(void *parsed_result,
12131                                   __rte_unused struct cmdline *cl,
12132                                   __rte_unused void *data)
12133 {
12134         struct cmd_get_hash_global_config_result *res = parsed_result;
12135         struct rte_eth_hash_filter_info info;
12136         uint32_t idx, offset;
12137         uint16_t i;
12138         char *str;
12139         int ret;
12140
12141         if (rte_eth_dev_filter_supported(res->port_id,
12142                         RTE_ETH_FILTER_HASH) < 0) {
12143                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12144                                                         res->port_id);
12145                 return;
12146         }
12147
12148         memset(&info, 0, sizeof(info));
12149         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12150         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12151                                         RTE_ETH_FILTER_GET, &info);
12152         if (ret < 0) {
12153                 printf("Cannot get hash global configurations by port %d\n",
12154                                                         res->port_id);
12155                 return;
12156         }
12157
12158         switch (info.info.global_conf.hash_func) {
12159         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12160                 printf("Hash function is Toeplitz\n");
12161                 break;
12162         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12163                 printf("Hash function is Simple XOR\n");
12164                 break;
12165         default:
12166                 printf("Unknown hash function\n");
12167                 break;
12168         }
12169
12170         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12171                 idx = i / UINT64_BIT;
12172                 offset = i % UINT64_BIT;
12173                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12174                                                 (1ULL << offset)))
12175                         continue;
12176                 str = flowtype_to_str(i);
12177                 if (!str)
12178                         continue;
12179                 printf("Symmetric hash is %s globally for flow type %s "
12180                                                         "by port %d\n",
12181                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12182                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12183                                                         res->port_id);
12184         }
12185 }
12186
12187 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12188         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12189                 get_hash_global_config, "get_hash_global_config");
12190 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12191         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12192                 port_id, UINT16);
12193
12194 cmdline_parse_inst_t cmd_get_hash_global_config = {
12195         .f = cmd_get_hash_global_config_parsed,
12196         .data = NULL,
12197         .help_str = "get_hash_global_config <port_id>",
12198         .tokens = {
12199                 (void *)&cmd_get_hash_global_config_all,
12200                 (void *)&cmd_get_hash_global_config_port_id,
12201                 NULL,
12202         },
12203 };
12204
12205 /* Set global config of hash function */
12206 struct cmd_set_hash_global_config_result {
12207         cmdline_fixed_string_t set_hash_global_config;
12208         portid_t port_id;
12209         cmdline_fixed_string_t hash_func;
12210         cmdline_fixed_string_t flow_type;
12211         cmdline_fixed_string_t enable;
12212 };
12213
12214 static void
12215 cmd_set_hash_global_config_parsed(void *parsed_result,
12216                                   __rte_unused struct cmdline *cl,
12217                                   __rte_unused void *data)
12218 {
12219         struct cmd_set_hash_global_config_result *res = parsed_result;
12220         struct rte_eth_hash_filter_info info;
12221         uint32_t ftype, idx, offset;
12222         int ret;
12223
12224         if (rte_eth_dev_filter_supported(res->port_id,
12225                                 RTE_ETH_FILTER_HASH) < 0) {
12226                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12227                                                         res->port_id);
12228                 return;
12229         }
12230         memset(&info, 0, sizeof(info));
12231         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12232         if (!strcmp(res->hash_func, "toeplitz"))
12233                 info.info.global_conf.hash_func =
12234                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12235         else if (!strcmp(res->hash_func, "simple_xor"))
12236                 info.info.global_conf.hash_func =
12237                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12238         else if (!strcmp(res->hash_func, "default"))
12239                 info.info.global_conf.hash_func =
12240                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12241
12242         ftype = str2flowtype(res->flow_type);
12243         idx = ftype / UINT64_BIT;
12244         offset = ftype % UINT64_BIT;
12245         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12246         if (!strcmp(res->enable, "enable"))
12247                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12248                                                 (1ULL << offset);
12249         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12250                                         RTE_ETH_FILTER_SET, &info);
12251         if (ret < 0)
12252                 printf("Cannot set global hash configurations by port %d\n",
12253                                                         res->port_id);
12254         else
12255                 printf("Global hash configurations have been set "
12256                         "successfully by port %d\n", res->port_id);
12257 }
12258
12259 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12260         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12261                 set_hash_global_config, "set_hash_global_config");
12262 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12263         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12264                 port_id, UINT16);
12265 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12266         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12267                 hash_func, "toeplitz#simple_xor#default");
12268 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12269         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12270                 flow_type,
12271                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12272                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12273 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12274         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12275                 enable, "enable#disable");
12276
12277 cmdline_parse_inst_t cmd_set_hash_global_config = {
12278         .f = cmd_set_hash_global_config_parsed,
12279         .data = NULL,
12280         .help_str = "set_hash_global_config <port_id> "
12281                 "toeplitz|simple_xor|default "
12282                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12283                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12284                 "l2_payload enable|disable",
12285         .tokens = {
12286                 (void *)&cmd_set_hash_global_config_all,
12287                 (void *)&cmd_set_hash_global_config_port_id,
12288                 (void *)&cmd_set_hash_global_config_hash_func,
12289                 (void *)&cmd_set_hash_global_config_flow_type,
12290                 (void *)&cmd_set_hash_global_config_enable,
12291                 NULL,
12292         },
12293 };
12294
12295 /* Set hash input set */
12296 struct cmd_set_hash_input_set_result {
12297         cmdline_fixed_string_t set_hash_input_set;
12298         portid_t port_id;
12299         cmdline_fixed_string_t flow_type;
12300         cmdline_fixed_string_t inset_field;
12301         cmdline_fixed_string_t select;
12302 };
12303
12304 static enum rte_eth_input_set_field
12305 str2inset(char *string)
12306 {
12307         uint16_t i;
12308
12309         static const struct {
12310                 char str[32];
12311                 enum rte_eth_input_set_field inset;
12312         } inset_table[] = {
12313                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12314                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12315                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12316                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12317                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12318                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12319                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12320                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12321                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12322                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12323                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12324                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12325                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12326                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12327                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12328                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12329                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12330                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12331                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12332                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12333                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12334                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12335                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12336                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12337                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12338                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12339                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12340                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12341                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12342                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12343                 {"none", RTE_ETH_INPUT_SET_NONE},
12344         };
12345
12346         for (i = 0; i < RTE_DIM(inset_table); i++) {
12347                 if (!strcmp(string, inset_table[i].str))
12348                         return inset_table[i].inset;
12349         }
12350
12351         return RTE_ETH_INPUT_SET_UNKNOWN;
12352 }
12353
12354 static void
12355 cmd_set_hash_input_set_parsed(void *parsed_result,
12356                               __rte_unused struct cmdline *cl,
12357                               __rte_unused void *data)
12358 {
12359         struct cmd_set_hash_input_set_result *res = parsed_result;
12360         struct rte_eth_hash_filter_info info;
12361
12362         memset(&info, 0, sizeof(info));
12363         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12364         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12365         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12366         info.info.input_set_conf.inset_size = 1;
12367         if (!strcmp(res->select, "select"))
12368                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12369         else if (!strcmp(res->select, "add"))
12370                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12371         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12372                                 RTE_ETH_FILTER_SET, &info);
12373 }
12374
12375 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12376         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12377                 set_hash_input_set, "set_hash_input_set");
12378 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12379         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12380                 port_id, UINT16);
12381 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12382         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12383                 flow_type, NULL);
12384 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12385         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12386                 inset_field,
12387                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12388                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12389                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12390                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12391                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12392                 "fld-8th#none");
12393 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12394         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12395                 select, "select#add");
12396
12397 cmdline_parse_inst_t cmd_set_hash_input_set = {
12398         .f = cmd_set_hash_input_set_parsed,
12399         .data = NULL,
12400         .help_str = "set_hash_input_set <port_id> "
12401         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12402         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12403         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12404         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12405         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12406         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12407         "fld-7th|fld-8th|none select|add",
12408         .tokens = {
12409                 (void *)&cmd_set_hash_input_set_cmd,
12410                 (void *)&cmd_set_hash_input_set_port_id,
12411                 (void *)&cmd_set_hash_input_set_flow_type,
12412                 (void *)&cmd_set_hash_input_set_field,
12413                 (void *)&cmd_set_hash_input_set_select,
12414                 NULL,
12415         },
12416 };
12417
12418 /* Set flow director input set */
12419 struct cmd_set_fdir_input_set_result {
12420         cmdline_fixed_string_t set_fdir_input_set;
12421         portid_t port_id;
12422         cmdline_fixed_string_t flow_type;
12423         cmdline_fixed_string_t inset_field;
12424         cmdline_fixed_string_t select;
12425 };
12426
12427 static void
12428 cmd_set_fdir_input_set_parsed(void *parsed_result,
12429         __rte_unused struct cmdline *cl,
12430         __rte_unused void *data)
12431 {
12432         struct cmd_set_fdir_input_set_result *res = parsed_result;
12433         struct rte_eth_fdir_filter_info info;
12434
12435         memset(&info, 0, sizeof(info));
12436         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12437         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12438         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12439         info.info.input_set_conf.inset_size = 1;
12440         if (!strcmp(res->select, "select"))
12441                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12442         else if (!strcmp(res->select, "add"))
12443                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12444         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12445                 RTE_ETH_FILTER_SET, &info);
12446 }
12447
12448 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12449         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12450         set_fdir_input_set, "set_fdir_input_set");
12451 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12452         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12453         port_id, UINT16);
12454 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12455         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12456         flow_type,
12457         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12458         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12459 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12460         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12461         inset_field,
12462         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12463         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12464         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12465         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12466         "sctp-veri-tag#none");
12467 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12468         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12469         select, "select#add");
12470
12471 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12472         .f = cmd_set_fdir_input_set_parsed,
12473         .data = NULL,
12474         .help_str = "set_fdir_input_set <port_id> "
12475         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12476         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12477         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12478         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12479         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12480         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12481         "sctp-veri-tag|none select|add",
12482         .tokens = {
12483                 (void *)&cmd_set_fdir_input_set_cmd,
12484                 (void *)&cmd_set_fdir_input_set_port_id,
12485                 (void *)&cmd_set_fdir_input_set_flow_type,
12486                 (void *)&cmd_set_fdir_input_set_field,
12487                 (void *)&cmd_set_fdir_input_set_select,
12488                 NULL,
12489         },
12490 };
12491
12492 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12493 struct cmd_mcast_addr_result {
12494         cmdline_fixed_string_t mcast_addr_cmd;
12495         cmdline_fixed_string_t what;
12496         uint16_t port_num;
12497         struct rte_ether_addr mc_addr;
12498 };
12499
12500 static void cmd_mcast_addr_parsed(void *parsed_result,
12501                 __attribute__((unused)) struct cmdline *cl,
12502                 __attribute__((unused)) void *data)
12503 {
12504         struct cmd_mcast_addr_result *res = parsed_result;
12505
12506         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12507                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12508                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12509                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12510                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12511                 return;
12512         }
12513         if (strcmp(res->what, "add") == 0)
12514                 mcast_addr_add(res->port_num, &res->mc_addr);
12515         else
12516                 mcast_addr_remove(res->port_num, &res->mc_addr);
12517 }
12518
12519 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12520         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12521                                  mcast_addr_cmd, "mcast_addr");
12522 cmdline_parse_token_string_t cmd_mcast_addr_what =
12523         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12524                                  "add#remove");
12525 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12526         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12527 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12528         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12529
12530 cmdline_parse_inst_t cmd_mcast_addr = {
12531         .f = cmd_mcast_addr_parsed,
12532         .data = (void *)0,
12533         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12534                 "Add/Remove multicast MAC address on port_id",
12535         .tokens = {
12536                 (void *)&cmd_mcast_addr_cmd,
12537                 (void *)&cmd_mcast_addr_what,
12538                 (void *)&cmd_mcast_addr_portnum,
12539                 (void *)&cmd_mcast_addr_addr,
12540                 NULL,
12541         },
12542 };
12543
12544 /* l2 tunnel config
12545  * only support E-tag now.
12546  */
12547
12548 /* Ether type config */
12549 struct cmd_config_l2_tunnel_eth_type_result {
12550         cmdline_fixed_string_t port;
12551         cmdline_fixed_string_t config;
12552         cmdline_fixed_string_t all;
12553         portid_t id;
12554         cmdline_fixed_string_t l2_tunnel;
12555         cmdline_fixed_string_t l2_tunnel_type;
12556         cmdline_fixed_string_t eth_type;
12557         uint16_t eth_type_val;
12558 };
12559
12560 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12561         TOKEN_STRING_INITIALIZER
12562                 (struct cmd_config_l2_tunnel_eth_type_result,
12563                  port, "port");
12564 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12565         TOKEN_STRING_INITIALIZER
12566                 (struct cmd_config_l2_tunnel_eth_type_result,
12567                  config, "config");
12568 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12569         TOKEN_STRING_INITIALIZER
12570                 (struct cmd_config_l2_tunnel_eth_type_result,
12571                  all, "all");
12572 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12573         TOKEN_NUM_INITIALIZER
12574                 (struct cmd_config_l2_tunnel_eth_type_result,
12575                  id, UINT16);
12576 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12577         TOKEN_STRING_INITIALIZER
12578                 (struct cmd_config_l2_tunnel_eth_type_result,
12579                  l2_tunnel, "l2-tunnel");
12580 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12581         TOKEN_STRING_INITIALIZER
12582                 (struct cmd_config_l2_tunnel_eth_type_result,
12583                  l2_tunnel_type, "E-tag");
12584 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12585         TOKEN_STRING_INITIALIZER
12586                 (struct cmd_config_l2_tunnel_eth_type_result,
12587                  eth_type, "ether-type");
12588 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12589         TOKEN_NUM_INITIALIZER
12590                 (struct cmd_config_l2_tunnel_eth_type_result,
12591                  eth_type_val, UINT16);
12592
12593 static enum rte_eth_tunnel_type
12594 str2fdir_l2_tunnel_type(char *string)
12595 {
12596         uint32_t i = 0;
12597
12598         static const struct {
12599                 char str[32];
12600                 enum rte_eth_tunnel_type type;
12601         } l2_tunnel_type_str[] = {
12602                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12603         };
12604
12605         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12606                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12607                         return l2_tunnel_type_str[i].type;
12608         }
12609         return RTE_TUNNEL_TYPE_NONE;
12610 }
12611
12612 /* ether type config for all ports */
12613 static void
12614 cmd_config_l2_tunnel_eth_type_all_parsed
12615         (void *parsed_result,
12616          __attribute__((unused)) struct cmdline *cl,
12617          __attribute__((unused)) void *data)
12618 {
12619         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12620         struct rte_eth_l2_tunnel_conf entry;
12621         portid_t pid;
12622
12623         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12624         entry.ether_type = res->eth_type_val;
12625
12626         RTE_ETH_FOREACH_DEV(pid) {
12627                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12628         }
12629 }
12630
12631 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12632         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12633         .data = NULL,
12634         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12635         .tokens = {
12636                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12637                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12638                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12639                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12640                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12641                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12642                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12643                 NULL,
12644         },
12645 };
12646
12647 /* ether type config for a specific port */
12648 static void
12649 cmd_config_l2_tunnel_eth_type_specific_parsed(
12650         void *parsed_result,
12651         __attribute__((unused)) struct cmdline *cl,
12652         __attribute__((unused)) void *data)
12653 {
12654         struct cmd_config_l2_tunnel_eth_type_result *res =
12655                  parsed_result;
12656         struct rte_eth_l2_tunnel_conf entry;
12657
12658         if (port_id_is_invalid(res->id, ENABLED_WARN))
12659                 return;
12660
12661         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12662         entry.ether_type = res->eth_type_val;
12663
12664         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12665 }
12666
12667 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12668         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12669         .data = NULL,
12670         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12671         .tokens = {
12672                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12673                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12674                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12675                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12676                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12677                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12678                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12679                 NULL,
12680         },
12681 };
12682
12683 /* Enable/disable l2 tunnel */
12684 struct cmd_config_l2_tunnel_en_dis_result {
12685         cmdline_fixed_string_t port;
12686         cmdline_fixed_string_t config;
12687         cmdline_fixed_string_t all;
12688         portid_t id;
12689         cmdline_fixed_string_t l2_tunnel;
12690         cmdline_fixed_string_t l2_tunnel_type;
12691         cmdline_fixed_string_t en_dis;
12692 };
12693
12694 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12695         TOKEN_STRING_INITIALIZER
12696                 (struct cmd_config_l2_tunnel_en_dis_result,
12697                  port, "port");
12698 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12699         TOKEN_STRING_INITIALIZER
12700                 (struct cmd_config_l2_tunnel_en_dis_result,
12701                  config, "config");
12702 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12703         TOKEN_STRING_INITIALIZER
12704                 (struct cmd_config_l2_tunnel_en_dis_result,
12705                  all, "all");
12706 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12707         TOKEN_NUM_INITIALIZER
12708                 (struct cmd_config_l2_tunnel_en_dis_result,
12709                  id, UINT16);
12710 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12711         TOKEN_STRING_INITIALIZER
12712                 (struct cmd_config_l2_tunnel_en_dis_result,
12713                  l2_tunnel, "l2-tunnel");
12714 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12715         TOKEN_STRING_INITIALIZER
12716                 (struct cmd_config_l2_tunnel_en_dis_result,
12717                  l2_tunnel_type, "E-tag");
12718 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12719         TOKEN_STRING_INITIALIZER
12720                 (struct cmd_config_l2_tunnel_en_dis_result,
12721                  en_dis, "enable#disable");
12722
12723 /* enable/disable l2 tunnel for all ports */
12724 static void
12725 cmd_config_l2_tunnel_en_dis_all_parsed(
12726         void *parsed_result,
12727         __attribute__((unused)) struct cmdline *cl,
12728         __attribute__((unused)) void *data)
12729 {
12730         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12731         struct rte_eth_l2_tunnel_conf entry;
12732         portid_t pid;
12733         uint8_t en;
12734
12735         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12736
12737         if (!strcmp("enable", res->en_dis))
12738                 en = 1;
12739         else
12740                 en = 0;
12741
12742         RTE_ETH_FOREACH_DEV(pid) {
12743                 rte_eth_dev_l2_tunnel_offload_set(pid,
12744                                                   &entry,
12745                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12746                                                   en);
12747         }
12748 }
12749
12750 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12751         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12752         .data = NULL,
12753         .help_str = "port config all l2-tunnel E-tag enable|disable",
12754         .tokens = {
12755                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12756                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12757                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12758                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12759                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12760                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12761                 NULL,
12762         },
12763 };
12764
12765 /* enable/disable l2 tunnel for a port */
12766 static void
12767 cmd_config_l2_tunnel_en_dis_specific_parsed(
12768         void *parsed_result,
12769         __attribute__((unused)) struct cmdline *cl,
12770         __attribute__((unused)) void *data)
12771 {
12772         struct cmd_config_l2_tunnel_en_dis_result *res =
12773                 parsed_result;
12774         struct rte_eth_l2_tunnel_conf entry;
12775
12776         if (port_id_is_invalid(res->id, ENABLED_WARN))
12777                 return;
12778
12779         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12780
12781         if (!strcmp("enable", res->en_dis))
12782                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12783                                                   &entry,
12784                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12785                                                   1);
12786         else
12787                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12788                                                   &entry,
12789                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12790                                                   0);
12791 }
12792
12793 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12794         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12795         .data = NULL,
12796         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12797         .tokens = {
12798                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12799                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12800                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12801                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12802                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12803                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12804                 NULL,
12805         },
12806 };
12807
12808 /* E-tag configuration */
12809
12810 /* Common result structure for all E-tag configuration */
12811 struct cmd_config_e_tag_result {
12812         cmdline_fixed_string_t e_tag;
12813         cmdline_fixed_string_t set;
12814         cmdline_fixed_string_t insertion;
12815         cmdline_fixed_string_t stripping;
12816         cmdline_fixed_string_t forwarding;
12817         cmdline_fixed_string_t filter;
12818         cmdline_fixed_string_t add;
12819         cmdline_fixed_string_t del;
12820         cmdline_fixed_string_t on;
12821         cmdline_fixed_string_t off;
12822         cmdline_fixed_string_t on_off;
12823         cmdline_fixed_string_t port_tag_id;
12824         uint32_t port_tag_id_val;
12825         cmdline_fixed_string_t e_tag_id;
12826         uint16_t e_tag_id_val;
12827         cmdline_fixed_string_t dst_pool;
12828         uint8_t dst_pool_val;
12829         cmdline_fixed_string_t port;
12830         portid_t port_id;
12831         cmdline_fixed_string_t vf;
12832         uint8_t vf_id;
12833 };
12834
12835 /* Common CLI fields for all E-tag configuration */
12836 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12837         TOKEN_STRING_INITIALIZER
12838                 (struct cmd_config_e_tag_result,
12839                  e_tag, "E-tag");
12840 cmdline_parse_token_string_t cmd_config_e_tag_set =
12841         TOKEN_STRING_INITIALIZER
12842                 (struct cmd_config_e_tag_result,
12843                  set, "set");
12844 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12845         TOKEN_STRING_INITIALIZER
12846                 (struct cmd_config_e_tag_result,
12847                  insertion, "insertion");
12848 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12849         TOKEN_STRING_INITIALIZER
12850                 (struct cmd_config_e_tag_result,
12851                  stripping, "stripping");
12852 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12853         TOKEN_STRING_INITIALIZER
12854                 (struct cmd_config_e_tag_result,
12855                  forwarding, "forwarding");
12856 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12857         TOKEN_STRING_INITIALIZER
12858                 (struct cmd_config_e_tag_result,
12859                  filter, "filter");
12860 cmdline_parse_token_string_t cmd_config_e_tag_add =
12861         TOKEN_STRING_INITIALIZER
12862                 (struct cmd_config_e_tag_result,
12863                  add, "add");
12864 cmdline_parse_token_string_t cmd_config_e_tag_del =
12865         TOKEN_STRING_INITIALIZER
12866                 (struct cmd_config_e_tag_result,
12867                  del, "del");
12868 cmdline_parse_token_string_t cmd_config_e_tag_on =
12869         TOKEN_STRING_INITIALIZER
12870                 (struct cmd_config_e_tag_result,
12871                  on, "on");
12872 cmdline_parse_token_string_t cmd_config_e_tag_off =
12873         TOKEN_STRING_INITIALIZER
12874                 (struct cmd_config_e_tag_result,
12875                  off, "off");
12876 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12877         TOKEN_STRING_INITIALIZER
12878                 (struct cmd_config_e_tag_result,
12879                  on_off, "on#off");
12880 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12881         TOKEN_STRING_INITIALIZER
12882                 (struct cmd_config_e_tag_result,
12883                  port_tag_id, "port-tag-id");
12884 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12885         TOKEN_NUM_INITIALIZER
12886                 (struct cmd_config_e_tag_result,
12887                  port_tag_id_val, UINT32);
12888 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12889         TOKEN_STRING_INITIALIZER
12890                 (struct cmd_config_e_tag_result,
12891                  e_tag_id, "e-tag-id");
12892 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12893         TOKEN_NUM_INITIALIZER
12894                 (struct cmd_config_e_tag_result,
12895                  e_tag_id_val, UINT16);
12896 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12897         TOKEN_STRING_INITIALIZER
12898                 (struct cmd_config_e_tag_result,
12899                  dst_pool, "dst-pool");
12900 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12901         TOKEN_NUM_INITIALIZER
12902                 (struct cmd_config_e_tag_result,
12903                  dst_pool_val, UINT8);
12904 cmdline_parse_token_string_t cmd_config_e_tag_port =
12905         TOKEN_STRING_INITIALIZER
12906                 (struct cmd_config_e_tag_result,
12907                  port, "port");
12908 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12909         TOKEN_NUM_INITIALIZER
12910                 (struct cmd_config_e_tag_result,
12911                  port_id, UINT16);
12912 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12913         TOKEN_STRING_INITIALIZER
12914                 (struct cmd_config_e_tag_result,
12915                  vf, "vf");
12916 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12917         TOKEN_NUM_INITIALIZER
12918                 (struct cmd_config_e_tag_result,
12919                  vf_id, UINT8);
12920
12921 /* E-tag insertion configuration */
12922 static void
12923 cmd_config_e_tag_insertion_en_parsed(
12924         void *parsed_result,
12925         __attribute__((unused)) struct cmdline *cl,
12926         __attribute__((unused)) void *data)
12927 {
12928         struct cmd_config_e_tag_result *res =
12929                 parsed_result;
12930         struct rte_eth_l2_tunnel_conf entry;
12931
12932         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12933                 return;
12934
12935         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12936         entry.tunnel_id = res->port_tag_id_val;
12937         entry.vf_id = res->vf_id;
12938         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12939                                           &entry,
12940                                           ETH_L2_TUNNEL_INSERTION_MASK,
12941                                           1);
12942 }
12943
12944 static void
12945 cmd_config_e_tag_insertion_dis_parsed(
12946         void *parsed_result,
12947         __attribute__((unused)) struct cmdline *cl,
12948         __attribute__((unused)) void *data)
12949 {
12950         struct cmd_config_e_tag_result *res =
12951                 parsed_result;
12952         struct rte_eth_l2_tunnel_conf entry;
12953
12954         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12955                 return;
12956
12957         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12958         entry.vf_id = res->vf_id;
12959
12960         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12961                                           &entry,
12962                                           ETH_L2_TUNNEL_INSERTION_MASK,
12963                                           0);
12964 }
12965
12966 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12967         .f = cmd_config_e_tag_insertion_en_parsed,
12968         .data = NULL,
12969         .help_str = "E-tag ... : E-tag insertion enable",
12970         .tokens = {
12971                 (void *)&cmd_config_e_tag_e_tag,
12972                 (void *)&cmd_config_e_tag_set,
12973                 (void *)&cmd_config_e_tag_insertion,
12974                 (void *)&cmd_config_e_tag_on,
12975                 (void *)&cmd_config_e_tag_port_tag_id,
12976                 (void *)&cmd_config_e_tag_port_tag_id_val,
12977                 (void *)&cmd_config_e_tag_port,
12978                 (void *)&cmd_config_e_tag_port_id,
12979                 (void *)&cmd_config_e_tag_vf,
12980                 (void *)&cmd_config_e_tag_vf_id,
12981                 NULL,
12982         },
12983 };
12984
12985 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12986         .f = cmd_config_e_tag_insertion_dis_parsed,
12987         .data = NULL,
12988         .help_str = "E-tag ... : E-tag insertion disable",
12989         .tokens = {
12990                 (void *)&cmd_config_e_tag_e_tag,
12991                 (void *)&cmd_config_e_tag_set,
12992                 (void *)&cmd_config_e_tag_insertion,
12993                 (void *)&cmd_config_e_tag_off,
12994                 (void *)&cmd_config_e_tag_port,
12995                 (void *)&cmd_config_e_tag_port_id,
12996                 (void *)&cmd_config_e_tag_vf,
12997                 (void *)&cmd_config_e_tag_vf_id,
12998                 NULL,
12999         },
13000 };
13001
13002 /* E-tag stripping configuration */
13003 static void
13004 cmd_config_e_tag_stripping_parsed(
13005         void *parsed_result,
13006         __attribute__((unused)) struct cmdline *cl,
13007         __attribute__((unused)) void *data)
13008 {
13009         struct cmd_config_e_tag_result *res =
13010                 parsed_result;
13011         struct rte_eth_l2_tunnel_conf entry;
13012
13013         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13014                 return;
13015
13016         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13017
13018         if (!strcmp(res->on_off, "on"))
13019                 rte_eth_dev_l2_tunnel_offload_set
13020                         (res->port_id,
13021                          &entry,
13022                          ETH_L2_TUNNEL_STRIPPING_MASK,
13023                          1);
13024         else
13025                 rte_eth_dev_l2_tunnel_offload_set
13026                         (res->port_id,
13027                          &entry,
13028                          ETH_L2_TUNNEL_STRIPPING_MASK,
13029                          0);
13030 }
13031
13032 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13033         .f = cmd_config_e_tag_stripping_parsed,
13034         .data = NULL,
13035         .help_str = "E-tag ... : E-tag stripping enable/disable",
13036         .tokens = {
13037                 (void *)&cmd_config_e_tag_e_tag,
13038                 (void *)&cmd_config_e_tag_set,
13039                 (void *)&cmd_config_e_tag_stripping,
13040                 (void *)&cmd_config_e_tag_on_off,
13041                 (void *)&cmd_config_e_tag_port,
13042                 (void *)&cmd_config_e_tag_port_id,
13043                 NULL,
13044         },
13045 };
13046
13047 /* E-tag forwarding configuration */
13048 static void
13049 cmd_config_e_tag_forwarding_parsed(
13050         void *parsed_result,
13051         __attribute__((unused)) struct cmdline *cl,
13052         __attribute__((unused)) void *data)
13053 {
13054         struct cmd_config_e_tag_result *res = parsed_result;
13055         struct rte_eth_l2_tunnel_conf entry;
13056
13057         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13058                 return;
13059
13060         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13061
13062         if (!strcmp(res->on_off, "on"))
13063                 rte_eth_dev_l2_tunnel_offload_set
13064                         (res->port_id,
13065                          &entry,
13066                          ETH_L2_TUNNEL_FORWARDING_MASK,
13067                          1);
13068         else
13069                 rte_eth_dev_l2_tunnel_offload_set
13070                         (res->port_id,
13071                          &entry,
13072                          ETH_L2_TUNNEL_FORWARDING_MASK,
13073                          0);
13074 }
13075
13076 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13077         .f = cmd_config_e_tag_forwarding_parsed,
13078         .data = NULL,
13079         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13080         .tokens = {
13081                 (void *)&cmd_config_e_tag_e_tag,
13082                 (void *)&cmd_config_e_tag_set,
13083                 (void *)&cmd_config_e_tag_forwarding,
13084                 (void *)&cmd_config_e_tag_on_off,
13085                 (void *)&cmd_config_e_tag_port,
13086                 (void *)&cmd_config_e_tag_port_id,
13087                 NULL,
13088         },
13089 };
13090
13091 /* E-tag filter configuration */
13092 static void
13093 cmd_config_e_tag_filter_add_parsed(
13094         void *parsed_result,
13095         __attribute__((unused)) struct cmdline *cl,
13096         __attribute__((unused)) void *data)
13097 {
13098         struct cmd_config_e_tag_result *res = parsed_result;
13099         struct rte_eth_l2_tunnel_conf entry;
13100         int ret = 0;
13101
13102         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13103                 return;
13104
13105         if (res->e_tag_id_val > 0x3fff) {
13106                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13107                 return;
13108         }
13109
13110         ret = rte_eth_dev_filter_supported(res->port_id,
13111                                            RTE_ETH_FILTER_L2_TUNNEL);
13112         if (ret < 0) {
13113                 printf("E-tag filter is not supported on port %u.\n",
13114                        res->port_id);
13115                 return;
13116         }
13117
13118         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13119         entry.tunnel_id = res->e_tag_id_val;
13120         entry.pool = res->dst_pool_val;
13121
13122         ret = rte_eth_dev_filter_ctrl(res->port_id,
13123                                       RTE_ETH_FILTER_L2_TUNNEL,
13124                                       RTE_ETH_FILTER_ADD,
13125                                       &entry);
13126         if (ret < 0)
13127                 printf("E-tag filter programming error: (%s)\n",
13128                        strerror(-ret));
13129 }
13130
13131 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13132         .f = cmd_config_e_tag_filter_add_parsed,
13133         .data = NULL,
13134         .help_str = "E-tag ... : E-tag filter add",
13135         .tokens = {
13136                 (void *)&cmd_config_e_tag_e_tag,
13137                 (void *)&cmd_config_e_tag_set,
13138                 (void *)&cmd_config_e_tag_filter,
13139                 (void *)&cmd_config_e_tag_add,
13140                 (void *)&cmd_config_e_tag_e_tag_id,
13141                 (void *)&cmd_config_e_tag_e_tag_id_val,
13142                 (void *)&cmd_config_e_tag_dst_pool,
13143                 (void *)&cmd_config_e_tag_dst_pool_val,
13144                 (void *)&cmd_config_e_tag_port,
13145                 (void *)&cmd_config_e_tag_port_id,
13146                 NULL,
13147         },
13148 };
13149
13150 static void
13151 cmd_config_e_tag_filter_del_parsed(
13152         void *parsed_result,
13153         __attribute__((unused)) struct cmdline *cl,
13154         __attribute__((unused)) void *data)
13155 {
13156         struct cmd_config_e_tag_result *res = parsed_result;
13157         struct rte_eth_l2_tunnel_conf entry;
13158         int ret = 0;
13159
13160         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13161                 return;
13162
13163         if (res->e_tag_id_val > 0x3fff) {
13164                 printf("e-tag-id must be less than 0x3fff.\n");
13165                 return;
13166         }
13167
13168         ret = rte_eth_dev_filter_supported(res->port_id,
13169                                            RTE_ETH_FILTER_L2_TUNNEL);
13170         if (ret < 0) {
13171                 printf("E-tag filter is not supported on port %u.\n",
13172                        res->port_id);
13173                 return;
13174         }
13175
13176         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13177         entry.tunnel_id = res->e_tag_id_val;
13178
13179         ret = rte_eth_dev_filter_ctrl(res->port_id,
13180                                       RTE_ETH_FILTER_L2_TUNNEL,
13181                                       RTE_ETH_FILTER_DELETE,
13182                                       &entry);
13183         if (ret < 0)
13184                 printf("E-tag filter programming error: (%s)\n",
13185                        strerror(-ret));
13186 }
13187
13188 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13189         .f = cmd_config_e_tag_filter_del_parsed,
13190         .data = NULL,
13191         .help_str = "E-tag ... : E-tag filter delete",
13192         .tokens = {
13193                 (void *)&cmd_config_e_tag_e_tag,
13194                 (void *)&cmd_config_e_tag_set,
13195                 (void *)&cmd_config_e_tag_filter,
13196                 (void *)&cmd_config_e_tag_del,
13197                 (void *)&cmd_config_e_tag_e_tag_id,
13198                 (void *)&cmd_config_e_tag_e_tag_id_val,
13199                 (void *)&cmd_config_e_tag_port,
13200                 (void *)&cmd_config_e_tag_port_id,
13201                 NULL,
13202         },
13203 };
13204
13205 /* vf vlan anti spoof configuration */
13206
13207 /* Common result structure for vf vlan anti spoof */
13208 struct cmd_vf_vlan_anti_spoof_result {
13209         cmdline_fixed_string_t set;
13210         cmdline_fixed_string_t vf;
13211         cmdline_fixed_string_t vlan;
13212         cmdline_fixed_string_t antispoof;
13213         portid_t port_id;
13214         uint32_t vf_id;
13215         cmdline_fixed_string_t on_off;
13216 };
13217
13218 /* Common CLI fields for vf vlan anti spoof enable disable */
13219 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13220         TOKEN_STRING_INITIALIZER
13221                 (struct cmd_vf_vlan_anti_spoof_result,
13222                  set, "set");
13223 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13224         TOKEN_STRING_INITIALIZER
13225                 (struct cmd_vf_vlan_anti_spoof_result,
13226                  vf, "vf");
13227 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13228         TOKEN_STRING_INITIALIZER
13229                 (struct cmd_vf_vlan_anti_spoof_result,
13230                  vlan, "vlan");
13231 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13232         TOKEN_STRING_INITIALIZER
13233                 (struct cmd_vf_vlan_anti_spoof_result,
13234                  antispoof, "antispoof");
13235 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13236         TOKEN_NUM_INITIALIZER
13237                 (struct cmd_vf_vlan_anti_spoof_result,
13238                  port_id, UINT16);
13239 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13240         TOKEN_NUM_INITIALIZER
13241                 (struct cmd_vf_vlan_anti_spoof_result,
13242                  vf_id, UINT32);
13243 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13244         TOKEN_STRING_INITIALIZER
13245                 (struct cmd_vf_vlan_anti_spoof_result,
13246                  on_off, "on#off");
13247
13248 static void
13249 cmd_set_vf_vlan_anti_spoof_parsed(
13250         void *parsed_result,
13251         __attribute__((unused)) struct cmdline *cl,
13252         __attribute__((unused)) void *data)
13253 {
13254         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13255         int ret = -ENOTSUP;
13256
13257         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13258
13259         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13260                 return;
13261
13262 #ifdef RTE_LIBRTE_IXGBE_PMD
13263         if (ret == -ENOTSUP)
13264                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13265                                 res->vf_id, is_on);
13266 #endif
13267 #ifdef RTE_LIBRTE_I40E_PMD
13268         if (ret == -ENOTSUP)
13269                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13270                                 res->vf_id, is_on);
13271 #endif
13272 #ifdef RTE_LIBRTE_BNXT_PMD
13273         if (ret == -ENOTSUP)
13274                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13275                                 res->vf_id, is_on);
13276 #endif
13277
13278         switch (ret) {
13279         case 0:
13280                 break;
13281         case -EINVAL:
13282                 printf("invalid vf_id %d\n", res->vf_id);
13283                 break;
13284         case -ENODEV:
13285                 printf("invalid port_id %d\n", res->port_id);
13286                 break;
13287         case -ENOTSUP:
13288                 printf("function not implemented\n");
13289                 break;
13290         default:
13291                 printf("programming error: (%s)\n", strerror(-ret));
13292         }
13293 }
13294
13295 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13296         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13297         .data = NULL,
13298         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13299         .tokens = {
13300                 (void *)&cmd_vf_vlan_anti_spoof_set,
13301                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13302                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13303                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13304                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13305                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13306                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13307                 NULL,
13308         },
13309 };
13310
13311 /* vf mac anti spoof configuration */
13312
13313 /* Common result structure for vf mac anti spoof */
13314 struct cmd_vf_mac_anti_spoof_result {
13315         cmdline_fixed_string_t set;
13316         cmdline_fixed_string_t vf;
13317         cmdline_fixed_string_t mac;
13318         cmdline_fixed_string_t antispoof;
13319         portid_t port_id;
13320         uint32_t vf_id;
13321         cmdline_fixed_string_t on_off;
13322 };
13323
13324 /* Common CLI fields for vf mac anti spoof enable disable */
13325 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13326         TOKEN_STRING_INITIALIZER
13327                 (struct cmd_vf_mac_anti_spoof_result,
13328                  set, "set");
13329 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13330         TOKEN_STRING_INITIALIZER
13331                 (struct cmd_vf_mac_anti_spoof_result,
13332                  vf, "vf");
13333 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13334         TOKEN_STRING_INITIALIZER
13335                 (struct cmd_vf_mac_anti_spoof_result,
13336                  mac, "mac");
13337 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13338         TOKEN_STRING_INITIALIZER
13339                 (struct cmd_vf_mac_anti_spoof_result,
13340                  antispoof, "antispoof");
13341 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13342         TOKEN_NUM_INITIALIZER
13343                 (struct cmd_vf_mac_anti_spoof_result,
13344                  port_id, UINT16);
13345 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13346         TOKEN_NUM_INITIALIZER
13347                 (struct cmd_vf_mac_anti_spoof_result,
13348                  vf_id, UINT32);
13349 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13350         TOKEN_STRING_INITIALIZER
13351                 (struct cmd_vf_mac_anti_spoof_result,
13352                  on_off, "on#off");
13353
13354 static void
13355 cmd_set_vf_mac_anti_spoof_parsed(
13356         void *parsed_result,
13357         __attribute__((unused)) struct cmdline *cl,
13358         __attribute__((unused)) void *data)
13359 {
13360         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13361         int ret = -ENOTSUP;
13362
13363         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13364
13365         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13366                 return;
13367
13368 #ifdef RTE_LIBRTE_IXGBE_PMD
13369         if (ret == -ENOTSUP)
13370                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13371                         res->vf_id, is_on);
13372 #endif
13373 #ifdef RTE_LIBRTE_I40E_PMD
13374         if (ret == -ENOTSUP)
13375                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13376                         res->vf_id, is_on);
13377 #endif
13378 #ifdef RTE_LIBRTE_BNXT_PMD
13379         if (ret == -ENOTSUP)
13380                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13381                         res->vf_id, is_on);
13382 #endif
13383
13384         switch (ret) {
13385         case 0:
13386                 break;
13387         case -EINVAL:
13388                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13389                 break;
13390         case -ENODEV:
13391                 printf("invalid port_id %d\n", res->port_id);
13392                 break;
13393         case -ENOTSUP:
13394                 printf("function not implemented\n");
13395                 break;
13396         default:
13397                 printf("programming error: (%s)\n", strerror(-ret));
13398         }
13399 }
13400
13401 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13402         .f = cmd_set_vf_mac_anti_spoof_parsed,
13403         .data = NULL,
13404         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13405         .tokens = {
13406                 (void *)&cmd_vf_mac_anti_spoof_set,
13407                 (void *)&cmd_vf_mac_anti_spoof_vf,
13408                 (void *)&cmd_vf_mac_anti_spoof_mac,
13409                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13410                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13411                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13412                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13413                 NULL,
13414         },
13415 };
13416
13417 /* vf vlan strip queue configuration */
13418
13419 /* Common result structure for vf mac anti spoof */
13420 struct cmd_vf_vlan_stripq_result {
13421         cmdline_fixed_string_t set;
13422         cmdline_fixed_string_t vf;
13423         cmdline_fixed_string_t vlan;
13424         cmdline_fixed_string_t stripq;
13425         portid_t port_id;
13426         uint16_t vf_id;
13427         cmdline_fixed_string_t on_off;
13428 };
13429
13430 /* Common CLI fields for vf vlan strip enable disable */
13431 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13432         TOKEN_STRING_INITIALIZER
13433                 (struct cmd_vf_vlan_stripq_result,
13434                  set, "set");
13435 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13436         TOKEN_STRING_INITIALIZER
13437                 (struct cmd_vf_vlan_stripq_result,
13438                  vf, "vf");
13439 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13440         TOKEN_STRING_INITIALIZER
13441                 (struct cmd_vf_vlan_stripq_result,
13442                  vlan, "vlan");
13443 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13444         TOKEN_STRING_INITIALIZER
13445                 (struct cmd_vf_vlan_stripq_result,
13446                  stripq, "stripq");
13447 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13448         TOKEN_NUM_INITIALIZER
13449                 (struct cmd_vf_vlan_stripq_result,
13450                  port_id, UINT16);
13451 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13452         TOKEN_NUM_INITIALIZER
13453                 (struct cmd_vf_vlan_stripq_result,
13454                  vf_id, UINT16);
13455 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13456         TOKEN_STRING_INITIALIZER
13457                 (struct cmd_vf_vlan_stripq_result,
13458                  on_off, "on#off");
13459
13460 static void
13461 cmd_set_vf_vlan_stripq_parsed(
13462         void *parsed_result,
13463         __attribute__((unused)) struct cmdline *cl,
13464         __attribute__((unused)) void *data)
13465 {
13466         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13467         int ret = -ENOTSUP;
13468
13469         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13470
13471         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13472                 return;
13473
13474 #ifdef RTE_LIBRTE_IXGBE_PMD
13475         if (ret == -ENOTSUP)
13476                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13477                         res->vf_id, is_on);
13478 #endif
13479 #ifdef RTE_LIBRTE_I40E_PMD
13480         if (ret == -ENOTSUP)
13481                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13482                         res->vf_id, is_on);
13483 #endif
13484 #ifdef RTE_LIBRTE_BNXT_PMD
13485         if (ret == -ENOTSUP)
13486                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13487                         res->vf_id, is_on);
13488 #endif
13489
13490         switch (ret) {
13491         case 0:
13492                 break;
13493         case -EINVAL:
13494                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13495                 break;
13496         case -ENODEV:
13497                 printf("invalid port_id %d\n", res->port_id);
13498                 break;
13499         case -ENOTSUP:
13500                 printf("function not implemented\n");
13501                 break;
13502         default:
13503                 printf("programming error: (%s)\n", strerror(-ret));
13504         }
13505 }
13506
13507 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13508         .f = cmd_set_vf_vlan_stripq_parsed,
13509         .data = NULL,
13510         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13511         .tokens = {
13512                 (void *)&cmd_vf_vlan_stripq_set,
13513                 (void *)&cmd_vf_vlan_stripq_vf,
13514                 (void *)&cmd_vf_vlan_stripq_vlan,
13515                 (void *)&cmd_vf_vlan_stripq_stripq,
13516                 (void *)&cmd_vf_vlan_stripq_port_id,
13517                 (void *)&cmd_vf_vlan_stripq_vf_id,
13518                 (void *)&cmd_vf_vlan_stripq_on_off,
13519                 NULL,
13520         },
13521 };
13522
13523 /* vf vlan insert configuration */
13524
13525 /* Common result structure for vf vlan insert */
13526 struct cmd_vf_vlan_insert_result {
13527         cmdline_fixed_string_t set;
13528         cmdline_fixed_string_t vf;
13529         cmdline_fixed_string_t vlan;
13530         cmdline_fixed_string_t insert;
13531         portid_t port_id;
13532         uint16_t vf_id;
13533         uint16_t vlan_id;
13534 };
13535
13536 /* Common CLI fields for vf vlan insert enable disable */
13537 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13538         TOKEN_STRING_INITIALIZER
13539                 (struct cmd_vf_vlan_insert_result,
13540                  set, "set");
13541 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13542         TOKEN_STRING_INITIALIZER
13543                 (struct cmd_vf_vlan_insert_result,
13544                  vf, "vf");
13545 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13546         TOKEN_STRING_INITIALIZER
13547                 (struct cmd_vf_vlan_insert_result,
13548                  vlan, "vlan");
13549 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13550         TOKEN_STRING_INITIALIZER
13551                 (struct cmd_vf_vlan_insert_result,
13552                  insert, "insert");
13553 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13554         TOKEN_NUM_INITIALIZER
13555                 (struct cmd_vf_vlan_insert_result,
13556                  port_id, UINT16);
13557 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13558         TOKEN_NUM_INITIALIZER
13559                 (struct cmd_vf_vlan_insert_result,
13560                  vf_id, UINT16);
13561 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13562         TOKEN_NUM_INITIALIZER
13563                 (struct cmd_vf_vlan_insert_result,
13564                  vlan_id, UINT16);
13565
13566 static void
13567 cmd_set_vf_vlan_insert_parsed(
13568         void *parsed_result,
13569         __attribute__((unused)) struct cmdline *cl,
13570         __attribute__((unused)) void *data)
13571 {
13572         struct cmd_vf_vlan_insert_result *res = parsed_result;
13573         int ret = -ENOTSUP;
13574
13575         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13576                 return;
13577
13578 #ifdef RTE_LIBRTE_IXGBE_PMD
13579         if (ret == -ENOTSUP)
13580                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13581                         res->vlan_id);
13582 #endif
13583 #ifdef RTE_LIBRTE_I40E_PMD
13584         if (ret == -ENOTSUP)
13585                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13586                         res->vlan_id);
13587 #endif
13588 #ifdef RTE_LIBRTE_BNXT_PMD
13589         if (ret == -ENOTSUP)
13590                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13591                         res->vlan_id);
13592 #endif
13593
13594         switch (ret) {
13595         case 0:
13596                 break;
13597         case -EINVAL:
13598                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13599                 break;
13600         case -ENODEV:
13601                 printf("invalid port_id %d\n", res->port_id);
13602                 break;
13603         case -ENOTSUP:
13604                 printf("function not implemented\n");
13605                 break;
13606         default:
13607                 printf("programming error: (%s)\n", strerror(-ret));
13608         }
13609 }
13610
13611 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13612         .f = cmd_set_vf_vlan_insert_parsed,
13613         .data = NULL,
13614         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13615         .tokens = {
13616                 (void *)&cmd_vf_vlan_insert_set,
13617                 (void *)&cmd_vf_vlan_insert_vf,
13618                 (void *)&cmd_vf_vlan_insert_vlan,
13619                 (void *)&cmd_vf_vlan_insert_insert,
13620                 (void *)&cmd_vf_vlan_insert_port_id,
13621                 (void *)&cmd_vf_vlan_insert_vf_id,
13622                 (void *)&cmd_vf_vlan_insert_vlan_id,
13623                 NULL,
13624         },
13625 };
13626
13627 /* tx loopback configuration */
13628
13629 /* Common result structure for tx loopback */
13630 struct cmd_tx_loopback_result {
13631         cmdline_fixed_string_t set;
13632         cmdline_fixed_string_t tx;
13633         cmdline_fixed_string_t loopback;
13634         portid_t port_id;
13635         cmdline_fixed_string_t on_off;
13636 };
13637
13638 /* Common CLI fields for tx loopback enable disable */
13639 cmdline_parse_token_string_t cmd_tx_loopback_set =
13640         TOKEN_STRING_INITIALIZER
13641                 (struct cmd_tx_loopback_result,
13642                  set, "set");
13643 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13644         TOKEN_STRING_INITIALIZER
13645                 (struct cmd_tx_loopback_result,
13646                  tx, "tx");
13647 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13648         TOKEN_STRING_INITIALIZER
13649                 (struct cmd_tx_loopback_result,
13650                  loopback, "loopback");
13651 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13652         TOKEN_NUM_INITIALIZER
13653                 (struct cmd_tx_loopback_result,
13654                  port_id, UINT16);
13655 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13656         TOKEN_STRING_INITIALIZER
13657                 (struct cmd_tx_loopback_result,
13658                  on_off, "on#off");
13659
13660 static void
13661 cmd_set_tx_loopback_parsed(
13662         void *parsed_result,
13663         __attribute__((unused)) struct cmdline *cl,
13664         __attribute__((unused)) void *data)
13665 {
13666         struct cmd_tx_loopback_result *res = parsed_result;
13667         int ret = -ENOTSUP;
13668
13669         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13670
13671         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13672                 return;
13673
13674 #ifdef RTE_LIBRTE_IXGBE_PMD
13675         if (ret == -ENOTSUP)
13676                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13677 #endif
13678 #ifdef RTE_LIBRTE_I40E_PMD
13679         if (ret == -ENOTSUP)
13680                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13681 #endif
13682 #ifdef RTE_LIBRTE_BNXT_PMD
13683         if (ret == -ENOTSUP)
13684                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13685 #endif
13686 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13687         if (ret == -ENOTSUP)
13688                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13689 #endif
13690
13691         switch (ret) {
13692         case 0:
13693                 break;
13694         case -EINVAL:
13695                 printf("invalid is_on %d\n", is_on);
13696                 break;
13697         case -ENODEV:
13698                 printf("invalid port_id %d\n", res->port_id);
13699                 break;
13700         case -ENOTSUP:
13701                 printf("function not implemented\n");
13702                 break;
13703         default:
13704                 printf("programming error: (%s)\n", strerror(-ret));
13705         }
13706 }
13707
13708 cmdline_parse_inst_t cmd_set_tx_loopback = {
13709         .f = cmd_set_tx_loopback_parsed,
13710         .data = NULL,
13711         .help_str = "set tx loopback <port_id> on|off",
13712         .tokens = {
13713                 (void *)&cmd_tx_loopback_set,
13714                 (void *)&cmd_tx_loopback_tx,
13715                 (void *)&cmd_tx_loopback_loopback,
13716                 (void *)&cmd_tx_loopback_port_id,
13717                 (void *)&cmd_tx_loopback_on_off,
13718                 NULL,
13719         },
13720 };
13721
13722 /* all queues drop enable configuration */
13723
13724 /* Common result structure for all queues drop enable */
13725 struct cmd_all_queues_drop_en_result {
13726         cmdline_fixed_string_t set;
13727         cmdline_fixed_string_t all;
13728         cmdline_fixed_string_t queues;
13729         cmdline_fixed_string_t drop;
13730         portid_t port_id;
13731         cmdline_fixed_string_t on_off;
13732 };
13733
13734 /* Common CLI fields for tx loopback enable disable */
13735 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13736         TOKEN_STRING_INITIALIZER
13737                 (struct cmd_all_queues_drop_en_result,
13738                  set, "set");
13739 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13740         TOKEN_STRING_INITIALIZER
13741                 (struct cmd_all_queues_drop_en_result,
13742                  all, "all");
13743 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13744         TOKEN_STRING_INITIALIZER
13745                 (struct cmd_all_queues_drop_en_result,
13746                  queues, "queues");
13747 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13748         TOKEN_STRING_INITIALIZER
13749                 (struct cmd_all_queues_drop_en_result,
13750                  drop, "drop");
13751 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13752         TOKEN_NUM_INITIALIZER
13753                 (struct cmd_all_queues_drop_en_result,
13754                  port_id, UINT16);
13755 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13756         TOKEN_STRING_INITIALIZER
13757                 (struct cmd_all_queues_drop_en_result,
13758                  on_off, "on#off");
13759
13760 static void
13761 cmd_set_all_queues_drop_en_parsed(
13762         void *parsed_result,
13763         __attribute__((unused)) struct cmdline *cl,
13764         __attribute__((unused)) void *data)
13765 {
13766         struct cmd_all_queues_drop_en_result *res = parsed_result;
13767         int ret = -ENOTSUP;
13768         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13769
13770         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13771                 return;
13772
13773 #ifdef RTE_LIBRTE_IXGBE_PMD
13774         if (ret == -ENOTSUP)
13775                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13776 #endif
13777 #ifdef RTE_LIBRTE_BNXT_PMD
13778         if (ret == -ENOTSUP)
13779                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13780 #endif
13781         switch (ret) {
13782         case 0:
13783                 break;
13784         case -EINVAL:
13785                 printf("invalid is_on %d\n", is_on);
13786                 break;
13787         case -ENODEV:
13788                 printf("invalid port_id %d\n", res->port_id);
13789                 break;
13790         case -ENOTSUP:
13791                 printf("function not implemented\n");
13792                 break;
13793         default:
13794                 printf("programming error: (%s)\n", strerror(-ret));
13795         }
13796 }
13797
13798 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13799         .f = cmd_set_all_queues_drop_en_parsed,
13800         .data = NULL,
13801         .help_str = "set all queues drop <port_id> on|off",
13802         .tokens = {
13803                 (void *)&cmd_all_queues_drop_en_set,
13804                 (void *)&cmd_all_queues_drop_en_all,
13805                 (void *)&cmd_all_queues_drop_en_queues,
13806                 (void *)&cmd_all_queues_drop_en_drop,
13807                 (void *)&cmd_all_queues_drop_en_port_id,
13808                 (void *)&cmd_all_queues_drop_en_on_off,
13809                 NULL,
13810         },
13811 };
13812
13813 /* vf split drop enable configuration */
13814
13815 /* Common result structure for vf split drop enable */
13816 struct cmd_vf_split_drop_en_result {
13817         cmdline_fixed_string_t set;
13818         cmdline_fixed_string_t vf;
13819         cmdline_fixed_string_t split;
13820         cmdline_fixed_string_t drop;
13821         portid_t port_id;
13822         uint16_t vf_id;
13823         cmdline_fixed_string_t on_off;
13824 };
13825
13826 /* Common CLI fields for vf split drop enable disable */
13827 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13828         TOKEN_STRING_INITIALIZER
13829                 (struct cmd_vf_split_drop_en_result,
13830                  set, "set");
13831 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13832         TOKEN_STRING_INITIALIZER
13833                 (struct cmd_vf_split_drop_en_result,
13834                  vf, "vf");
13835 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13836         TOKEN_STRING_INITIALIZER
13837                 (struct cmd_vf_split_drop_en_result,
13838                  split, "split");
13839 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13840         TOKEN_STRING_INITIALIZER
13841                 (struct cmd_vf_split_drop_en_result,
13842                  drop, "drop");
13843 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13844         TOKEN_NUM_INITIALIZER
13845                 (struct cmd_vf_split_drop_en_result,
13846                  port_id, UINT16);
13847 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13848         TOKEN_NUM_INITIALIZER
13849                 (struct cmd_vf_split_drop_en_result,
13850                  vf_id, UINT16);
13851 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13852         TOKEN_STRING_INITIALIZER
13853                 (struct cmd_vf_split_drop_en_result,
13854                  on_off, "on#off");
13855
13856 static void
13857 cmd_set_vf_split_drop_en_parsed(
13858         void *parsed_result,
13859         __attribute__((unused)) struct cmdline *cl,
13860         __attribute__((unused)) void *data)
13861 {
13862         struct cmd_vf_split_drop_en_result *res = parsed_result;
13863         int ret = -ENOTSUP;
13864         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13865
13866         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13867                 return;
13868
13869 #ifdef RTE_LIBRTE_IXGBE_PMD
13870         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13871                         is_on);
13872 #endif
13873         switch (ret) {
13874         case 0:
13875                 break;
13876         case -EINVAL:
13877                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13878                 break;
13879         case -ENODEV:
13880                 printf("invalid port_id %d\n", res->port_id);
13881                 break;
13882         case -ENOTSUP:
13883                 printf("not supported on port %d\n", res->port_id);
13884                 break;
13885         default:
13886                 printf("programming error: (%s)\n", strerror(-ret));
13887         }
13888 }
13889
13890 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13891         .f = cmd_set_vf_split_drop_en_parsed,
13892         .data = NULL,
13893         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13894         .tokens = {
13895                 (void *)&cmd_vf_split_drop_en_set,
13896                 (void *)&cmd_vf_split_drop_en_vf,
13897                 (void *)&cmd_vf_split_drop_en_split,
13898                 (void *)&cmd_vf_split_drop_en_drop,
13899                 (void *)&cmd_vf_split_drop_en_port_id,
13900                 (void *)&cmd_vf_split_drop_en_vf_id,
13901                 (void *)&cmd_vf_split_drop_en_on_off,
13902                 NULL,
13903         },
13904 };
13905
13906 /* vf mac address configuration */
13907
13908 /* Common result structure for vf mac address */
13909 struct cmd_set_vf_mac_addr_result {
13910         cmdline_fixed_string_t set;
13911         cmdline_fixed_string_t vf;
13912         cmdline_fixed_string_t mac;
13913         cmdline_fixed_string_t addr;
13914         portid_t port_id;
13915         uint16_t vf_id;
13916         struct rte_ether_addr mac_addr;
13917
13918 };
13919
13920 /* Common CLI fields for vf split drop enable disable */
13921 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13922         TOKEN_STRING_INITIALIZER
13923                 (struct cmd_set_vf_mac_addr_result,
13924                  set, "set");
13925 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13926         TOKEN_STRING_INITIALIZER
13927                 (struct cmd_set_vf_mac_addr_result,
13928                  vf, "vf");
13929 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13930         TOKEN_STRING_INITIALIZER
13931                 (struct cmd_set_vf_mac_addr_result,
13932                  mac, "mac");
13933 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13934         TOKEN_STRING_INITIALIZER
13935                 (struct cmd_set_vf_mac_addr_result,
13936                  addr, "addr");
13937 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13938         TOKEN_NUM_INITIALIZER
13939                 (struct cmd_set_vf_mac_addr_result,
13940                  port_id, UINT16);
13941 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13942         TOKEN_NUM_INITIALIZER
13943                 (struct cmd_set_vf_mac_addr_result,
13944                  vf_id, UINT16);
13945 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13946         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13947                  mac_addr);
13948
13949 static void
13950 cmd_set_vf_mac_addr_parsed(
13951         void *parsed_result,
13952         __attribute__((unused)) struct cmdline *cl,
13953         __attribute__((unused)) void *data)
13954 {
13955         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13956         int ret = -ENOTSUP;
13957
13958         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13959                 return;
13960
13961 #ifdef RTE_LIBRTE_IXGBE_PMD
13962         if (ret == -ENOTSUP)
13963                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13964                                 &res->mac_addr);
13965 #endif
13966 #ifdef RTE_LIBRTE_I40E_PMD
13967         if (ret == -ENOTSUP)
13968                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13969                                 &res->mac_addr);
13970 #endif
13971 #ifdef RTE_LIBRTE_BNXT_PMD
13972         if (ret == -ENOTSUP)
13973                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13974                                 &res->mac_addr);
13975 #endif
13976
13977         switch (ret) {
13978         case 0:
13979                 break;
13980         case -EINVAL:
13981                 printf("invalid vf_id %d or mac_addr\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_set_vf_mac_addr = {
13995         .f = cmd_set_vf_mac_addr_parsed,
13996         .data = NULL,
13997         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13998         .tokens = {
13999                 (void *)&cmd_set_vf_mac_addr_set,
14000                 (void *)&cmd_set_vf_mac_addr_vf,
14001                 (void *)&cmd_set_vf_mac_addr_mac,
14002                 (void *)&cmd_set_vf_mac_addr_addr,
14003                 (void *)&cmd_set_vf_mac_addr_port_id,
14004                 (void *)&cmd_set_vf_mac_addr_vf_id,
14005                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14006                 NULL,
14007         },
14008 };
14009
14010 /* MACsec configuration */
14011
14012 /* Common result structure for MACsec offload enable */
14013 struct cmd_macsec_offload_on_result {
14014         cmdline_fixed_string_t set;
14015         cmdline_fixed_string_t macsec;
14016         cmdline_fixed_string_t offload;
14017         portid_t port_id;
14018         cmdline_fixed_string_t on;
14019         cmdline_fixed_string_t encrypt;
14020         cmdline_fixed_string_t en_on_off;
14021         cmdline_fixed_string_t replay_protect;
14022         cmdline_fixed_string_t rp_on_off;
14023 };
14024
14025 /* Common CLI fields for MACsec offload disable */
14026 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14027         TOKEN_STRING_INITIALIZER
14028                 (struct cmd_macsec_offload_on_result,
14029                  set, "set");
14030 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14031         TOKEN_STRING_INITIALIZER
14032                 (struct cmd_macsec_offload_on_result,
14033                  macsec, "macsec");
14034 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14035         TOKEN_STRING_INITIALIZER
14036                 (struct cmd_macsec_offload_on_result,
14037                  offload, "offload");
14038 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14039         TOKEN_NUM_INITIALIZER
14040                 (struct cmd_macsec_offload_on_result,
14041                  port_id, UINT16);
14042 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14043         TOKEN_STRING_INITIALIZER
14044                 (struct cmd_macsec_offload_on_result,
14045                  on, "on");
14046 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14047         TOKEN_STRING_INITIALIZER
14048                 (struct cmd_macsec_offload_on_result,
14049                  encrypt, "encrypt");
14050 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14051         TOKEN_STRING_INITIALIZER
14052                 (struct cmd_macsec_offload_on_result,
14053                  en_on_off, "on#off");
14054 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14055         TOKEN_STRING_INITIALIZER
14056                 (struct cmd_macsec_offload_on_result,
14057                  replay_protect, "replay-protect");
14058 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14059         TOKEN_STRING_INITIALIZER
14060                 (struct cmd_macsec_offload_on_result,
14061                  rp_on_off, "on#off");
14062
14063 static void
14064 cmd_set_macsec_offload_on_parsed(
14065         void *parsed_result,
14066         __attribute__((unused)) struct cmdline *cl,
14067         __attribute__((unused)) void *data)
14068 {
14069         struct cmd_macsec_offload_on_result *res = parsed_result;
14070         int ret = -ENOTSUP;
14071         portid_t port_id = res->port_id;
14072         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14073         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14074         struct rte_eth_dev_info dev_info;
14075
14076         if (port_id_is_invalid(port_id, ENABLED_WARN))
14077                 return;
14078         if (!port_is_stopped(port_id)) {
14079                 printf("Please stop port %d first\n", port_id);
14080                 return;
14081         }
14082
14083         rte_eth_dev_info_get(port_id, &dev_info);
14084         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14085 #ifdef RTE_LIBRTE_IXGBE_PMD
14086                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14087 #endif
14088         }
14089         RTE_SET_USED(en);
14090         RTE_SET_USED(rp);
14091
14092         switch (ret) {
14093         case 0:
14094                 ports[port_id].dev_conf.txmode.offloads |=
14095                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14096                 cmd_reconfig_device_queue(port_id, 1, 1);
14097                 break;
14098         case -ENODEV:
14099                 printf("invalid port_id %d\n", port_id);
14100                 break;
14101         case -ENOTSUP:
14102                 printf("not supported on port %d\n", port_id);
14103                 break;
14104         default:
14105                 printf("programming error: (%s)\n", strerror(-ret));
14106         }
14107 }
14108
14109 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14110         .f = cmd_set_macsec_offload_on_parsed,
14111         .data = NULL,
14112         .help_str = "set macsec offload <port_id> on "
14113                 "encrypt on|off replay-protect on|off",
14114         .tokens = {
14115                 (void *)&cmd_macsec_offload_on_set,
14116                 (void *)&cmd_macsec_offload_on_macsec,
14117                 (void *)&cmd_macsec_offload_on_offload,
14118                 (void *)&cmd_macsec_offload_on_port_id,
14119                 (void *)&cmd_macsec_offload_on_on,
14120                 (void *)&cmd_macsec_offload_on_encrypt,
14121                 (void *)&cmd_macsec_offload_on_en_on_off,
14122                 (void *)&cmd_macsec_offload_on_replay_protect,
14123                 (void *)&cmd_macsec_offload_on_rp_on_off,
14124                 NULL,
14125         },
14126 };
14127
14128 /* Common result structure for MACsec offload disable */
14129 struct cmd_macsec_offload_off_result {
14130         cmdline_fixed_string_t set;
14131         cmdline_fixed_string_t macsec;
14132         cmdline_fixed_string_t offload;
14133         portid_t port_id;
14134         cmdline_fixed_string_t off;
14135 };
14136
14137 /* Common CLI fields for MACsec offload disable */
14138 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14139         TOKEN_STRING_INITIALIZER
14140                 (struct cmd_macsec_offload_off_result,
14141                  set, "set");
14142 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14143         TOKEN_STRING_INITIALIZER
14144                 (struct cmd_macsec_offload_off_result,
14145                  macsec, "macsec");
14146 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14147         TOKEN_STRING_INITIALIZER
14148                 (struct cmd_macsec_offload_off_result,
14149                  offload, "offload");
14150 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14151         TOKEN_NUM_INITIALIZER
14152                 (struct cmd_macsec_offload_off_result,
14153                  port_id, UINT16);
14154 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14155         TOKEN_STRING_INITIALIZER
14156                 (struct cmd_macsec_offload_off_result,
14157                  off, "off");
14158
14159 static void
14160 cmd_set_macsec_offload_off_parsed(
14161         void *parsed_result,
14162         __attribute__((unused)) struct cmdline *cl,
14163         __attribute__((unused)) void *data)
14164 {
14165         struct cmd_macsec_offload_off_result *res = parsed_result;
14166         int ret = -ENOTSUP;
14167         struct rte_eth_dev_info dev_info;
14168         portid_t port_id = res->port_id;
14169
14170         if (port_id_is_invalid(port_id, ENABLED_WARN))
14171                 return;
14172         if (!port_is_stopped(port_id)) {
14173                 printf("Please stop port %d first\n", port_id);
14174                 return;
14175         }
14176
14177         rte_eth_dev_info_get(port_id, &dev_info);
14178         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14179 #ifdef RTE_LIBRTE_IXGBE_PMD
14180                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14181 #endif
14182         }
14183         switch (ret) {
14184         case 0:
14185                 ports[port_id].dev_conf.txmode.offloads &=
14186                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14187                 cmd_reconfig_device_queue(port_id, 1, 1);
14188                 break;
14189         case -ENODEV:
14190                 printf("invalid port_id %d\n", port_id);
14191                 break;
14192         case -ENOTSUP:
14193                 printf("not supported on port %d\n", port_id);
14194                 break;
14195         default:
14196                 printf("programming error: (%s)\n", strerror(-ret));
14197         }
14198 }
14199
14200 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14201         .f = cmd_set_macsec_offload_off_parsed,
14202         .data = NULL,
14203         .help_str = "set macsec offload <port_id> off",
14204         .tokens = {
14205                 (void *)&cmd_macsec_offload_off_set,
14206                 (void *)&cmd_macsec_offload_off_macsec,
14207                 (void *)&cmd_macsec_offload_off_offload,
14208                 (void *)&cmd_macsec_offload_off_port_id,
14209                 (void *)&cmd_macsec_offload_off_off,
14210                 NULL,
14211         },
14212 };
14213
14214 /* Common result structure for MACsec secure connection configure */
14215 struct cmd_macsec_sc_result {
14216         cmdline_fixed_string_t set;
14217         cmdline_fixed_string_t macsec;
14218         cmdline_fixed_string_t sc;
14219         cmdline_fixed_string_t tx_rx;
14220         portid_t port_id;
14221         struct rte_ether_addr mac;
14222         uint16_t pi;
14223 };
14224
14225 /* Common CLI fields for MACsec secure connection configure */
14226 cmdline_parse_token_string_t cmd_macsec_sc_set =
14227         TOKEN_STRING_INITIALIZER
14228                 (struct cmd_macsec_sc_result,
14229                  set, "set");
14230 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14231         TOKEN_STRING_INITIALIZER
14232                 (struct cmd_macsec_sc_result,
14233                  macsec, "macsec");
14234 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14235         TOKEN_STRING_INITIALIZER
14236                 (struct cmd_macsec_sc_result,
14237                  sc, "sc");
14238 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14239         TOKEN_STRING_INITIALIZER
14240                 (struct cmd_macsec_sc_result,
14241                  tx_rx, "tx#rx");
14242 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14243         TOKEN_NUM_INITIALIZER
14244                 (struct cmd_macsec_sc_result,
14245                  port_id, UINT16);
14246 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14247         TOKEN_ETHERADDR_INITIALIZER
14248                 (struct cmd_macsec_sc_result,
14249                  mac);
14250 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14251         TOKEN_NUM_INITIALIZER
14252                 (struct cmd_macsec_sc_result,
14253                  pi, UINT16);
14254
14255 static void
14256 cmd_set_macsec_sc_parsed(
14257         void *parsed_result,
14258         __attribute__((unused)) struct cmdline *cl,
14259         __attribute__((unused)) void *data)
14260 {
14261         struct cmd_macsec_sc_result *res = parsed_result;
14262         int ret = -ENOTSUP;
14263         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14264
14265 #ifdef RTE_LIBRTE_IXGBE_PMD
14266         ret = is_tx ?
14267                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14268                                 res->mac.addr_bytes) :
14269                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14270                                 res->mac.addr_bytes, res->pi);
14271 #endif
14272         RTE_SET_USED(is_tx);
14273
14274         switch (ret) {
14275         case 0:
14276                 break;
14277         case -ENODEV:
14278                 printf("invalid port_id %d\n", res->port_id);
14279                 break;
14280         case -ENOTSUP:
14281                 printf("not supported on port %d\n", res->port_id);
14282                 break;
14283         default:
14284                 printf("programming error: (%s)\n", strerror(-ret));
14285         }
14286 }
14287
14288 cmdline_parse_inst_t cmd_set_macsec_sc = {
14289         .f = cmd_set_macsec_sc_parsed,
14290         .data = NULL,
14291         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14292         .tokens = {
14293                 (void *)&cmd_macsec_sc_set,
14294                 (void *)&cmd_macsec_sc_macsec,
14295                 (void *)&cmd_macsec_sc_sc,
14296                 (void *)&cmd_macsec_sc_tx_rx,
14297                 (void *)&cmd_macsec_sc_port_id,
14298                 (void *)&cmd_macsec_sc_mac,
14299                 (void *)&cmd_macsec_sc_pi,
14300                 NULL,
14301         },
14302 };
14303
14304 /* Common result structure for MACsec secure connection configure */
14305 struct cmd_macsec_sa_result {
14306         cmdline_fixed_string_t set;
14307         cmdline_fixed_string_t macsec;
14308         cmdline_fixed_string_t sa;
14309         cmdline_fixed_string_t tx_rx;
14310         portid_t port_id;
14311         uint8_t idx;
14312         uint8_t an;
14313         uint32_t pn;
14314         cmdline_fixed_string_t key;
14315 };
14316
14317 /* Common CLI fields for MACsec secure connection configure */
14318 cmdline_parse_token_string_t cmd_macsec_sa_set =
14319         TOKEN_STRING_INITIALIZER
14320                 (struct cmd_macsec_sa_result,
14321                  set, "set");
14322 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14323         TOKEN_STRING_INITIALIZER
14324                 (struct cmd_macsec_sa_result,
14325                  macsec, "macsec");
14326 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14327         TOKEN_STRING_INITIALIZER
14328                 (struct cmd_macsec_sa_result,
14329                  sa, "sa");
14330 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14331         TOKEN_STRING_INITIALIZER
14332                 (struct cmd_macsec_sa_result,
14333                  tx_rx, "tx#rx");
14334 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14335         TOKEN_NUM_INITIALIZER
14336                 (struct cmd_macsec_sa_result,
14337                  port_id, UINT16);
14338 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14339         TOKEN_NUM_INITIALIZER
14340                 (struct cmd_macsec_sa_result,
14341                  idx, UINT8);
14342 cmdline_parse_token_num_t cmd_macsec_sa_an =
14343         TOKEN_NUM_INITIALIZER
14344                 (struct cmd_macsec_sa_result,
14345                  an, UINT8);
14346 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14347         TOKEN_NUM_INITIALIZER
14348                 (struct cmd_macsec_sa_result,
14349                  pn, UINT32);
14350 cmdline_parse_token_string_t cmd_macsec_sa_key =
14351         TOKEN_STRING_INITIALIZER
14352                 (struct cmd_macsec_sa_result,
14353                  key, NULL);
14354
14355 static void
14356 cmd_set_macsec_sa_parsed(
14357         void *parsed_result,
14358         __attribute__((unused)) struct cmdline *cl,
14359         __attribute__((unused)) void *data)
14360 {
14361         struct cmd_macsec_sa_result *res = parsed_result;
14362         int ret = -ENOTSUP;
14363         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14364         uint8_t key[16] = { 0 };
14365         uint8_t xdgt0;
14366         uint8_t xdgt1;
14367         int key_len;
14368         int i;
14369
14370         key_len = strlen(res->key) / 2;
14371         if (key_len > 16)
14372                 key_len = 16;
14373
14374         for (i = 0; i < key_len; i++) {
14375                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14376                 if (xdgt0 == 0xFF)
14377                         return;
14378                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14379                 if (xdgt1 == 0xFF)
14380                         return;
14381                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14382         }
14383
14384 #ifdef RTE_LIBRTE_IXGBE_PMD
14385         ret = is_tx ?
14386                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14387                         res->idx, res->an, res->pn, key) :
14388                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14389                         res->idx, res->an, res->pn, key);
14390 #endif
14391         RTE_SET_USED(is_tx);
14392         RTE_SET_USED(key);
14393
14394         switch (ret) {
14395         case 0:
14396                 break;
14397         case -EINVAL:
14398                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14399                 break;
14400         case -ENODEV:
14401                 printf("invalid port_id %d\n", res->port_id);
14402                 break;
14403         case -ENOTSUP:
14404                 printf("not supported on port %d\n", res->port_id);
14405                 break;
14406         default:
14407                 printf("programming error: (%s)\n", strerror(-ret));
14408         }
14409 }
14410
14411 cmdline_parse_inst_t cmd_set_macsec_sa = {
14412         .f = cmd_set_macsec_sa_parsed,
14413         .data = NULL,
14414         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14415         .tokens = {
14416                 (void *)&cmd_macsec_sa_set,
14417                 (void *)&cmd_macsec_sa_macsec,
14418                 (void *)&cmd_macsec_sa_sa,
14419                 (void *)&cmd_macsec_sa_tx_rx,
14420                 (void *)&cmd_macsec_sa_port_id,
14421                 (void *)&cmd_macsec_sa_idx,
14422                 (void *)&cmd_macsec_sa_an,
14423                 (void *)&cmd_macsec_sa_pn,
14424                 (void *)&cmd_macsec_sa_key,
14425                 NULL,
14426         },
14427 };
14428
14429 /* VF unicast promiscuous mode configuration */
14430
14431 /* Common result structure for VF unicast promiscuous mode */
14432 struct cmd_vf_promisc_result {
14433         cmdline_fixed_string_t set;
14434         cmdline_fixed_string_t vf;
14435         cmdline_fixed_string_t promisc;
14436         portid_t port_id;
14437         uint32_t vf_id;
14438         cmdline_fixed_string_t on_off;
14439 };
14440
14441 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14442 cmdline_parse_token_string_t cmd_vf_promisc_set =
14443         TOKEN_STRING_INITIALIZER
14444                 (struct cmd_vf_promisc_result,
14445                  set, "set");
14446 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14447         TOKEN_STRING_INITIALIZER
14448                 (struct cmd_vf_promisc_result,
14449                  vf, "vf");
14450 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14451         TOKEN_STRING_INITIALIZER
14452                 (struct cmd_vf_promisc_result,
14453                  promisc, "promisc");
14454 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14455         TOKEN_NUM_INITIALIZER
14456                 (struct cmd_vf_promisc_result,
14457                  port_id, UINT16);
14458 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14459         TOKEN_NUM_INITIALIZER
14460                 (struct cmd_vf_promisc_result,
14461                  vf_id, UINT32);
14462 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14463         TOKEN_STRING_INITIALIZER
14464                 (struct cmd_vf_promisc_result,
14465                  on_off, "on#off");
14466
14467 static void
14468 cmd_set_vf_promisc_parsed(
14469         void *parsed_result,
14470         __attribute__((unused)) struct cmdline *cl,
14471         __attribute__((unused)) void *data)
14472 {
14473         struct cmd_vf_promisc_result *res = parsed_result;
14474         int ret = -ENOTSUP;
14475
14476         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14477
14478         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14479                 return;
14480
14481 #ifdef RTE_LIBRTE_I40E_PMD
14482         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14483                                                   res->vf_id, is_on);
14484 #endif
14485
14486         switch (ret) {
14487         case 0:
14488                 break;
14489         case -EINVAL:
14490                 printf("invalid vf_id %d\n", res->vf_id);
14491                 break;
14492         case -ENODEV:
14493                 printf("invalid port_id %d\n", res->port_id);
14494                 break;
14495         case -ENOTSUP:
14496                 printf("function not implemented\n");
14497                 break;
14498         default:
14499                 printf("programming error: (%s)\n", strerror(-ret));
14500         }
14501 }
14502
14503 cmdline_parse_inst_t cmd_set_vf_promisc = {
14504         .f = cmd_set_vf_promisc_parsed,
14505         .data = NULL,
14506         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14507                 "Set unicast promiscuous mode for a VF from the PF",
14508         .tokens = {
14509                 (void *)&cmd_vf_promisc_set,
14510                 (void *)&cmd_vf_promisc_vf,
14511                 (void *)&cmd_vf_promisc_promisc,
14512                 (void *)&cmd_vf_promisc_port_id,
14513                 (void *)&cmd_vf_promisc_vf_id,
14514                 (void *)&cmd_vf_promisc_on_off,
14515                 NULL,
14516         },
14517 };
14518
14519 /* VF multicast promiscuous mode configuration */
14520
14521 /* Common result structure for VF multicast promiscuous mode */
14522 struct cmd_vf_allmulti_result {
14523         cmdline_fixed_string_t set;
14524         cmdline_fixed_string_t vf;
14525         cmdline_fixed_string_t allmulti;
14526         portid_t port_id;
14527         uint32_t vf_id;
14528         cmdline_fixed_string_t on_off;
14529 };
14530
14531 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14532 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14533         TOKEN_STRING_INITIALIZER
14534                 (struct cmd_vf_allmulti_result,
14535                  set, "set");
14536 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14537         TOKEN_STRING_INITIALIZER
14538                 (struct cmd_vf_allmulti_result,
14539                  vf, "vf");
14540 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14541         TOKEN_STRING_INITIALIZER
14542                 (struct cmd_vf_allmulti_result,
14543                  allmulti, "allmulti");
14544 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14545         TOKEN_NUM_INITIALIZER
14546                 (struct cmd_vf_allmulti_result,
14547                  port_id, UINT16);
14548 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14549         TOKEN_NUM_INITIALIZER
14550                 (struct cmd_vf_allmulti_result,
14551                  vf_id, UINT32);
14552 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14553         TOKEN_STRING_INITIALIZER
14554                 (struct cmd_vf_allmulti_result,
14555                  on_off, "on#off");
14556
14557 static void
14558 cmd_set_vf_allmulti_parsed(
14559         void *parsed_result,
14560         __attribute__((unused)) struct cmdline *cl,
14561         __attribute__((unused)) void *data)
14562 {
14563         struct cmd_vf_allmulti_result *res = parsed_result;
14564         int ret = -ENOTSUP;
14565
14566         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14567
14568         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14569                 return;
14570
14571 #ifdef RTE_LIBRTE_I40E_PMD
14572         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14573                                                     res->vf_id, is_on);
14574 #endif
14575
14576         switch (ret) {
14577         case 0:
14578                 break;
14579         case -EINVAL:
14580                 printf("invalid vf_id %d\n", res->vf_id);
14581                 break;
14582         case -ENODEV:
14583                 printf("invalid port_id %d\n", res->port_id);
14584                 break;
14585         case -ENOTSUP:
14586                 printf("function not implemented\n");
14587                 break;
14588         default:
14589                 printf("programming error: (%s)\n", strerror(-ret));
14590         }
14591 }
14592
14593 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14594         .f = cmd_set_vf_allmulti_parsed,
14595         .data = NULL,
14596         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14597                 "Set multicast promiscuous mode for a VF from the PF",
14598         .tokens = {
14599                 (void *)&cmd_vf_allmulti_set,
14600                 (void *)&cmd_vf_allmulti_vf,
14601                 (void *)&cmd_vf_allmulti_allmulti,
14602                 (void *)&cmd_vf_allmulti_port_id,
14603                 (void *)&cmd_vf_allmulti_vf_id,
14604                 (void *)&cmd_vf_allmulti_on_off,
14605                 NULL,
14606         },
14607 };
14608
14609 /* vf broadcast mode configuration */
14610
14611 /* Common result structure for vf broadcast */
14612 struct cmd_set_vf_broadcast_result {
14613         cmdline_fixed_string_t set;
14614         cmdline_fixed_string_t vf;
14615         cmdline_fixed_string_t broadcast;
14616         portid_t port_id;
14617         uint16_t vf_id;
14618         cmdline_fixed_string_t on_off;
14619 };
14620
14621 /* Common CLI fields for vf broadcast enable disable */
14622 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14623         TOKEN_STRING_INITIALIZER
14624                 (struct cmd_set_vf_broadcast_result,
14625                  set, "set");
14626 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14627         TOKEN_STRING_INITIALIZER
14628                 (struct cmd_set_vf_broadcast_result,
14629                  vf, "vf");
14630 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14631         TOKEN_STRING_INITIALIZER
14632                 (struct cmd_set_vf_broadcast_result,
14633                  broadcast, "broadcast");
14634 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14635         TOKEN_NUM_INITIALIZER
14636                 (struct cmd_set_vf_broadcast_result,
14637                  port_id, UINT16);
14638 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14639         TOKEN_NUM_INITIALIZER
14640                 (struct cmd_set_vf_broadcast_result,
14641                  vf_id, UINT16);
14642 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14643         TOKEN_STRING_INITIALIZER
14644                 (struct cmd_set_vf_broadcast_result,
14645                  on_off, "on#off");
14646
14647 static void
14648 cmd_set_vf_broadcast_parsed(
14649         void *parsed_result,
14650         __attribute__((unused)) struct cmdline *cl,
14651         __attribute__((unused)) void *data)
14652 {
14653         struct cmd_set_vf_broadcast_result *res = parsed_result;
14654         int ret = -ENOTSUP;
14655
14656         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14657
14658         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14659                 return;
14660
14661 #ifdef RTE_LIBRTE_I40E_PMD
14662         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14663                                             res->vf_id, is_on);
14664 #endif
14665
14666         switch (ret) {
14667         case 0:
14668                 break;
14669         case -EINVAL:
14670                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14671                 break;
14672         case -ENODEV:
14673                 printf("invalid port_id %d\n", res->port_id);
14674                 break;
14675         case -ENOTSUP:
14676                 printf("function not implemented\n");
14677                 break;
14678         default:
14679                 printf("programming error: (%s)\n", strerror(-ret));
14680         }
14681 }
14682
14683 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14684         .f = cmd_set_vf_broadcast_parsed,
14685         .data = NULL,
14686         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14687         .tokens = {
14688                 (void *)&cmd_set_vf_broadcast_set,
14689                 (void *)&cmd_set_vf_broadcast_vf,
14690                 (void *)&cmd_set_vf_broadcast_broadcast,
14691                 (void *)&cmd_set_vf_broadcast_port_id,
14692                 (void *)&cmd_set_vf_broadcast_vf_id,
14693                 (void *)&cmd_set_vf_broadcast_on_off,
14694                 NULL,
14695         },
14696 };
14697
14698 /* vf vlan tag configuration */
14699
14700 /* Common result structure for vf vlan tag */
14701 struct cmd_set_vf_vlan_tag_result {
14702         cmdline_fixed_string_t set;
14703         cmdline_fixed_string_t vf;
14704         cmdline_fixed_string_t vlan;
14705         cmdline_fixed_string_t tag;
14706         portid_t port_id;
14707         uint16_t vf_id;
14708         cmdline_fixed_string_t on_off;
14709 };
14710
14711 /* Common CLI fields for vf vlan tag enable disable */
14712 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14713         TOKEN_STRING_INITIALIZER
14714                 (struct cmd_set_vf_vlan_tag_result,
14715                  set, "set");
14716 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14717         TOKEN_STRING_INITIALIZER
14718                 (struct cmd_set_vf_vlan_tag_result,
14719                  vf, "vf");
14720 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14721         TOKEN_STRING_INITIALIZER
14722                 (struct cmd_set_vf_vlan_tag_result,
14723                  vlan, "vlan");
14724 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14725         TOKEN_STRING_INITIALIZER
14726                 (struct cmd_set_vf_vlan_tag_result,
14727                  tag, "tag");
14728 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14729         TOKEN_NUM_INITIALIZER
14730                 (struct cmd_set_vf_vlan_tag_result,
14731                  port_id, UINT16);
14732 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14733         TOKEN_NUM_INITIALIZER
14734                 (struct cmd_set_vf_vlan_tag_result,
14735                  vf_id, UINT16);
14736 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14737         TOKEN_STRING_INITIALIZER
14738                 (struct cmd_set_vf_vlan_tag_result,
14739                  on_off, "on#off");
14740
14741 static void
14742 cmd_set_vf_vlan_tag_parsed(
14743         void *parsed_result,
14744         __attribute__((unused)) struct cmdline *cl,
14745         __attribute__((unused)) void *data)
14746 {
14747         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14748         int ret = -ENOTSUP;
14749
14750         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14751
14752         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14753                 return;
14754
14755 #ifdef RTE_LIBRTE_I40E_PMD
14756         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14757                                            res->vf_id, is_on);
14758 #endif
14759
14760         switch (ret) {
14761         case 0:
14762                 break;
14763         case -EINVAL:
14764                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14765                 break;
14766         case -ENODEV:
14767                 printf("invalid port_id %d\n", res->port_id);
14768                 break;
14769         case -ENOTSUP:
14770                 printf("function not implemented\n");
14771                 break;
14772         default:
14773                 printf("programming error: (%s)\n", strerror(-ret));
14774         }
14775 }
14776
14777 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14778         .f = cmd_set_vf_vlan_tag_parsed,
14779         .data = NULL,
14780         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14781         .tokens = {
14782                 (void *)&cmd_set_vf_vlan_tag_set,
14783                 (void *)&cmd_set_vf_vlan_tag_vf,
14784                 (void *)&cmd_set_vf_vlan_tag_vlan,
14785                 (void *)&cmd_set_vf_vlan_tag_tag,
14786                 (void *)&cmd_set_vf_vlan_tag_port_id,
14787                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14788                 (void *)&cmd_set_vf_vlan_tag_on_off,
14789                 NULL,
14790         },
14791 };
14792
14793 /* Common definition of VF and TC TX bandwidth configuration */
14794 struct cmd_vf_tc_bw_result {
14795         cmdline_fixed_string_t set;
14796         cmdline_fixed_string_t vf;
14797         cmdline_fixed_string_t tc;
14798         cmdline_fixed_string_t tx;
14799         cmdline_fixed_string_t min_bw;
14800         cmdline_fixed_string_t max_bw;
14801         cmdline_fixed_string_t strict_link_prio;
14802         portid_t port_id;
14803         uint16_t vf_id;
14804         uint8_t tc_no;
14805         uint32_t bw;
14806         cmdline_fixed_string_t bw_list;
14807         uint8_t tc_map;
14808 };
14809
14810 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14811         TOKEN_STRING_INITIALIZER
14812                 (struct cmd_vf_tc_bw_result,
14813                  set, "set");
14814 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14815         TOKEN_STRING_INITIALIZER
14816                 (struct cmd_vf_tc_bw_result,
14817                  vf, "vf");
14818 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14819         TOKEN_STRING_INITIALIZER
14820                 (struct cmd_vf_tc_bw_result,
14821                  tc, "tc");
14822 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14823         TOKEN_STRING_INITIALIZER
14824                 (struct cmd_vf_tc_bw_result,
14825                  tx, "tx");
14826 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14827         TOKEN_STRING_INITIALIZER
14828                 (struct cmd_vf_tc_bw_result,
14829                  strict_link_prio, "strict-link-priority");
14830 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14831         TOKEN_STRING_INITIALIZER
14832                 (struct cmd_vf_tc_bw_result,
14833                  min_bw, "min-bandwidth");
14834 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14835         TOKEN_STRING_INITIALIZER
14836                 (struct cmd_vf_tc_bw_result,
14837                  max_bw, "max-bandwidth");
14838 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14839         TOKEN_NUM_INITIALIZER
14840                 (struct cmd_vf_tc_bw_result,
14841                  port_id, UINT16);
14842 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14843         TOKEN_NUM_INITIALIZER
14844                 (struct cmd_vf_tc_bw_result,
14845                  vf_id, UINT16);
14846 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14847         TOKEN_NUM_INITIALIZER
14848                 (struct cmd_vf_tc_bw_result,
14849                  tc_no, UINT8);
14850 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14851         TOKEN_NUM_INITIALIZER
14852                 (struct cmd_vf_tc_bw_result,
14853                  bw, UINT32);
14854 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14855         TOKEN_STRING_INITIALIZER
14856                 (struct cmd_vf_tc_bw_result,
14857                  bw_list, NULL);
14858 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14859         TOKEN_NUM_INITIALIZER
14860                 (struct cmd_vf_tc_bw_result,
14861                  tc_map, UINT8);
14862
14863 /* VF max bandwidth setting */
14864 static void
14865 cmd_vf_max_bw_parsed(
14866         void *parsed_result,
14867         __attribute__((unused)) struct cmdline *cl,
14868         __attribute__((unused)) void *data)
14869 {
14870         struct cmd_vf_tc_bw_result *res = parsed_result;
14871         int ret = -ENOTSUP;
14872
14873         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14874                 return;
14875
14876 #ifdef RTE_LIBRTE_I40E_PMD
14877         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14878                                          res->vf_id, res->bw);
14879 #endif
14880
14881         switch (ret) {
14882         case 0:
14883                 break;
14884         case -EINVAL:
14885                 printf("invalid vf_id %d or bandwidth %d\n",
14886                        res->vf_id, res->bw);
14887                 break;
14888         case -ENODEV:
14889                 printf("invalid port_id %d\n", res->port_id);
14890                 break;
14891         case -ENOTSUP:
14892                 printf("function not implemented\n");
14893                 break;
14894         default:
14895                 printf("programming error: (%s)\n", strerror(-ret));
14896         }
14897 }
14898
14899 cmdline_parse_inst_t cmd_vf_max_bw = {
14900         .f = cmd_vf_max_bw_parsed,
14901         .data = NULL,
14902         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14903         .tokens = {
14904                 (void *)&cmd_vf_tc_bw_set,
14905                 (void *)&cmd_vf_tc_bw_vf,
14906                 (void *)&cmd_vf_tc_bw_tx,
14907                 (void *)&cmd_vf_tc_bw_max_bw,
14908                 (void *)&cmd_vf_tc_bw_port_id,
14909                 (void *)&cmd_vf_tc_bw_vf_id,
14910                 (void *)&cmd_vf_tc_bw_bw,
14911                 NULL,
14912         },
14913 };
14914
14915 static int
14916 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14917                            uint8_t *tc_num,
14918                            char *str)
14919 {
14920         uint32_t size;
14921         const char *p, *p0 = str;
14922         char s[256];
14923         char *end;
14924         char *str_fld[16];
14925         uint16_t i;
14926         int ret;
14927
14928         p = strchr(p0, '(');
14929         if (p == NULL) {
14930                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14931                 return -1;
14932         }
14933         p++;
14934         p0 = strchr(p, ')');
14935         if (p0 == NULL) {
14936                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14937                 return -1;
14938         }
14939         size = p0 - p;
14940         if (size >= sizeof(s)) {
14941                 printf("The string size exceeds the internal buffer size\n");
14942                 return -1;
14943         }
14944         snprintf(s, sizeof(s), "%.*s", size, p);
14945         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14946         if (ret <= 0) {
14947                 printf("Failed to get the bandwidth list. ");
14948                 return -1;
14949         }
14950         *tc_num = ret;
14951         for (i = 0; i < ret; i++)
14952                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14953
14954         return 0;
14955 }
14956
14957 /* TC min bandwidth setting */
14958 static void
14959 cmd_vf_tc_min_bw_parsed(
14960         void *parsed_result,
14961         __attribute__((unused)) struct cmdline *cl,
14962         __attribute__((unused)) void *data)
14963 {
14964         struct cmd_vf_tc_bw_result *res = parsed_result;
14965         uint8_t tc_num;
14966         uint8_t bw[16];
14967         int ret = -ENOTSUP;
14968
14969         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14970                 return;
14971
14972         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14973         if (ret)
14974                 return;
14975
14976 #ifdef RTE_LIBRTE_I40E_PMD
14977         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14978                                               tc_num, bw);
14979 #endif
14980
14981         switch (ret) {
14982         case 0:
14983                 break;
14984         case -EINVAL:
14985                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14986                 break;
14987         case -ENODEV:
14988                 printf("invalid port_id %d\n", res->port_id);
14989                 break;
14990         case -ENOTSUP:
14991                 printf("function not implemented\n");
14992                 break;
14993         default:
14994                 printf("programming error: (%s)\n", strerror(-ret));
14995         }
14996 }
14997
14998 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14999         .f = cmd_vf_tc_min_bw_parsed,
15000         .data = NULL,
15001         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15002                     " <bw1, bw2, ...>",
15003         .tokens = {
15004                 (void *)&cmd_vf_tc_bw_set,
15005                 (void *)&cmd_vf_tc_bw_vf,
15006                 (void *)&cmd_vf_tc_bw_tc,
15007                 (void *)&cmd_vf_tc_bw_tx,
15008                 (void *)&cmd_vf_tc_bw_min_bw,
15009                 (void *)&cmd_vf_tc_bw_port_id,
15010                 (void *)&cmd_vf_tc_bw_vf_id,
15011                 (void *)&cmd_vf_tc_bw_bw_list,
15012                 NULL,
15013         },
15014 };
15015
15016 static void
15017 cmd_tc_min_bw_parsed(
15018         void *parsed_result,
15019         __attribute__((unused)) struct cmdline *cl,
15020         __attribute__((unused)) void *data)
15021 {
15022         struct cmd_vf_tc_bw_result *res = parsed_result;
15023         struct rte_port *port;
15024         uint8_t tc_num;
15025         uint8_t bw[16];
15026         int ret = -ENOTSUP;
15027
15028         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15029                 return;
15030
15031         port = &ports[res->port_id];
15032         /** Check if the port is not started **/
15033         if (port->port_status != RTE_PORT_STOPPED) {
15034                 printf("Please stop port %d first\n", res->port_id);
15035                 return;
15036         }
15037
15038         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15039         if (ret)
15040                 return;
15041
15042 #ifdef RTE_LIBRTE_IXGBE_PMD
15043         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15044 #endif
15045
15046         switch (ret) {
15047         case 0:
15048                 break;
15049         case -EINVAL:
15050                 printf("invalid bandwidth\n");
15051                 break;
15052         case -ENODEV:
15053                 printf("invalid port_id %d\n", res->port_id);
15054                 break;
15055         case -ENOTSUP:
15056                 printf("function not implemented\n");
15057                 break;
15058         default:
15059                 printf("programming error: (%s)\n", strerror(-ret));
15060         }
15061 }
15062
15063 cmdline_parse_inst_t cmd_tc_min_bw = {
15064         .f = cmd_tc_min_bw_parsed,
15065         .data = NULL,
15066         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15067         .tokens = {
15068                 (void *)&cmd_vf_tc_bw_set,
15069                 (void *)&cmd_vf_tc_bw_tc,
15070                 (void *)&cmd_vf_tc_bw_tx,
15071                 (void *)&cmd_vf_tc_bw_min_bw,
15072                 (void *)&cmd_vf_tc_bw_port_id,
15073                 (void *)&cmd_vf_tc_bw_bw_list,
15074                 NULL,
15075         },
15076 };
15077
15078 /* TC max bandwidth setting */
15079 static void
15080 cmd_vf_tc_max_bw_parsed(
15081         void *parsed_result,
15082         __attribute__((unused)) struct cmdline *cl,
15083         __attribute__((unused)) void *data)
15084 {
15085         struct cmd_vf_tc_bw_result *res = parsed_result;
15086         int ret = -ENOTSUP;
15087
15088         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15089                 return;
15090
15091 #ifdef RTE_LIBRTE_I40E_PMD
15092         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15093                                             res->tc_no, res->bw);
15094 #endif
15095
15096         switch (ret) {
15097         case 0:
15098                 break;
15099         case -EINVAL:
15100                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15101                        res->vf_id, res->tc_no, res->bw);
15102                 break;
15103         case -ENODEV:
15104                 printf("invalid port_id %d\n", res->port_id);
15105                 break;
15106         case -ENOTSUP:
15107                 printf("function not implemented\n");
15108                 break;
15109         default:
15110                 printf("programming error: (%s)\n", strerror(-ret));
15111         }
15112 }
15113
15114 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15115         .f = cmd_vf_tc_max_bw_parsed,
15116         .data = NULL,
15117         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15118                     " <bandwidth>",
15119         .tokens = {
15120                 (void *)&cmd_vf_tc_bw_set,
15121                 (void *)&cmd_vf_tc_bw_vf,
15122                 (void *)&cmd_vf_tc_bw_tc,
15123                 (void *)&cmd_vf_tc_bw_tx,
15124                 (void *)&cmd_vf_tc_bw_max_bw,
15125                 (void *)&cmd_vf_tc_bw_port_id,
15126                 (void *)&cmd_vf_tc_bw_vf_id,
15127                 (void *)&cmd_vf_tc_bw_tc_no,
15128                 (void *)&cmd_vf_tc_bw_bw,
15129                 NULL,
15130         },
15131 };
15132
15133
15134 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15135
15136 /* *** Set Port default Traffic Management Hierarchy *** */
15137 struct cmd_set_port_tm_hierarchy_default_result {
15138         cmdline_fixed_string_t set;
15139         cmdline_fixed_string_t port;
15140         cmdline_fixed_string_t tm;
15141         cmdline_fixed_string_t hierarchy;
15142         cmdline_fixed_string_t def;
15143         portid_t port_id;
15144 };
15145
15146 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15147         TOKEN_STRING_INITIALIZER(
15148                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15149 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15150         TOKEN_STRING_INITIALIZER(
15151                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15152 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15153         TOKEN_STRING_INITIALIZER(
15154                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15155 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15156         TOKEN_STRING_INITIALIZER(
15157                 struct cmd_set_port_tm_hierarchy_default_result,
15158                         hierarchy, "hierarchy");
15159 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15160         TOKEN_STRING_INITIALIZER(
15161                 struct cmd_set_port_tm_hierarchy_default_result,
15162                         def, "default");
15163 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15164         TOKEN_NUM_INITIALIZER(
15165                 struct cmd_set_port_tm_hierarchy_default_result,
15166                         port_id, UINT16);
15167
15168 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15169         __attribute__((unused)) struct cmdline *cl,
15170         __attribute__((unused)) void *data)
15171 {
15172         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15173         struct rte_port *p;
15174         portid_t port_id = res->port_id;
15175
15176         if (port_id_is_invalid(port_id, ENABLED_WARN))
15177                 return;
15178
15179         p = &ports[port_id];
15180
15181         /* Forward mode: tm */
15182         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15183                 printf("  softnicfwd mode not enabled(error)\n");
15184                 return;
15185         }
15186
15187         /* Set the default tm hierarchy */
15188         p->softport.default_tm_hierarchy_enable = 1;
15189 }
15190
15191 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15192         .f = cmd_set_port_tm_hierarchy_default_parsed,
15193         .data = NULL,
15194         .help_str = "set port tm hierarchy default <port_id>",
15195         .tokens = {
15196                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15197                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15198                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15199                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15200                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15201                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15202                 NULL,
15203         },
15204 };
15205 #endif
15206
15207 /** Set VXLAN encapsulation details */
15208 struct cmd_set_vxlan_result {
15209         cmdline_fixed_string_t set;
15210         cmdline_fixed_string_t vxlan;
15211         cmdline_fixed_string_t pos_token;
15212         cmdline_fixed_string_t ip_version;
15213         uint32_t vlan_present:1;
15214         uint32_t vni;
15215         uint16_t udp_src;
15216         uint16_t udp_dst;
15217         cmdline_ipaddr_t ip_src;
15218         cmdline_ipaddr_t ip_dst;
15219         uint16_t tci;
15220         uint8_t tos;
15221         uint8_t ttl;
15222         struct rte_ether_addr eth_src;
15223         struct rte_ether_addr eth_dst;
15224 };
15225
15226 cmdline_parse_token_string_t cmd_set_vxlan_set =
15227         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15228 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15229         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15230 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15231         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15232                                  "vxlan-tos-ttl");
15233 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15234         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15235                                  "vxlan-with-vlan");
15236 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15237         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15238                                  "ip-version");
15239 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15240         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15241                                  "ipv4#ipv6");
15242 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15243         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15244                                  "vni");
15245 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15246         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15247 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15248         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15249                                  "udp-src");
15250 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15251         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15252 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15253         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15254                                  "udp-dst");
15255 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15256         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15257 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15258         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15259                                  "ip-tos");
15260 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15261         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15262 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15263         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15264                                  "ip-ttl");
15265 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15266         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15267 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15268         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15269                                  "ip-src");
15270 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15271         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15272 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15273         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15274                                  "ip-dst");
15275 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15276         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15277 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15278         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15279                                  "vlan-tci");
15280 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15281         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15282 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15283         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15284                                  "eth-src");
15285 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15286         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15287 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15288         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15289                                  "eth-dst");
15290 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15291         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15292
15293 static void cmd_set_vxlan_parsed(void *parsed_result,
15294         __attribute__((unused)) struct cmdline *cl,
15295         __attribute__((unused)) void *data)
15296 {
15297         struct cmd_set_vxlan_result *res = parsed_result;
15298         union {
15299                 uint32_t vxlan_id;
15300                 uint8_t vni[4];
15301         } id = {
15302                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15303         };
15304
15305         vxlan_encap_conf.select_tos_ttl = 0;
15306         if (strcmp(res->vxlan, "vxlan") == 0)
15307                 vxlan_encap_conf.select_vlan = 0;
15308         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15309                 vxlan_encap_conf.select_vlan = 1;
15310         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15311                 vxlan_encap_conf.select_vlan = 0;
15312                 vxlan_encap_conf.select_tos_ttl = 1;
15313         }
15314         if (strcmp(res->ip_version, "ipv4") == 0)
15315                 vxlan_encap_conf.select_ipv4 = 1;
15316         else if (strcmp(res->ip_version, "ipv6") == 0)
15317                 vxlan_encap_conf.select_ipv4 = 0;
15318         else
15319                 return;
15320         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15321         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15322         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15323         vxlan_encap_conf.ip_tos = res->tos;
15324         vxlan_encap_conf.ip_ttl = res->ttl;
15325         if (vxlan_encap_conf.select_ipv4) {
15326                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15327                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15328         } else {
15329                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15330                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15331         }
15332         if (vxlan_encap_conf.select_vlan)
15333                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15334         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15335                    RTE_ETHER_ADDR_LEN);
15336         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15337                    RTE_ETHER_ADDR_LEN);
15338 }
15339
15340 cmdline_parse_inst_t cmd_set_vxlan = {
15341         .f = cmd_set_vxlan_parsed,
15342         .data = NULL,
15343         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15344                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15345                 " eth-src <eth-src> eth-dst <eth-dst>",
15346         .tokens = {
15347                 (void *)&cmd_set_vxlan_set,
15348                 (void *)&cmd_set_vxlan_vxlan,
15349                 (void *)&cmd_set_vxlan_ip_version,
15350                 (void *)&cmd_set_vxlan_ip_version_value,
15351                 (void *)&cmd_set_vxlan_vni,
15352                 (void *)&cmd_set_vxlan_vni_value,
15353                 (void *)&cmd_set_vxlan_udp_src,
15354                 (void *)&cmd_set_vxlan_udp_src_value,
15355                 (void *)&cmd_set_vxlan_udp_dst,
15356                 (void *)&cmd_set_vxlan_udp_dst_value,
15357                 (void *)&cmd_set_vxlan_ip_src,
15358                 (void *)&cmd_set_vxlan_ip_src_value,
15359                 (void *)&cmd_set_vxlan_ip_dst,
15360                 (void *)&cmd_set_vxlan_ip_dst_value,
15361                 (void *)&cmd_set_vxlan_eth_src,
15362                 (void *)&cmd_set_vxlan_eth_src_value,
15363                 (void *)&cmd_set_vxlan_eth_dst,
15364                 (void *)&cmd_set_vxlan_eth_dst_value,
15365                 NULL,
15366         },
15367 };
15368
15369 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15370         .f = cmd_set_vxlan_parsed,
15371         .data = NULL,
15372         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15373                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15374                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15375                 " eth-dst <eth-dst>",
15376         .tokens = {
15377                 (void *)&cmd_set_vxlan_set,
15378                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15379                 (void *)&cmd_set_vxlan_ip_version,
15380                 (void *)&cmd_set_vxlan_ip_version_value,
15381                 (void *)&cmd_set_vxlan_vni,
15382                 (void *)&cmd_set_vxlan_vni_value,
15383                 (void *)&cmd_set_vxlan_udp_src,
15384                 (void *)&cmd_set_vxlan_udp_src_value,
15385                 (void *)&cmd_set_vxlan_udp_dst,
15386                 (void *)&cmd_set_vxlan_udp_dst_value,
15387                 (void *)&cmd_set_vxlan_ip_tos,
15388                 (void *)&cmd_set_vxlan_ip_tos_value,
15389                 (void *)&cmd_set_vxlan_ip_ttl,
15390                 (void *)&cmd_set_vxlan_ip_ttl_value,
15391                 (void *)&cmd_set_vxlan_ip_src,
15392                 (void *)&cmd_set_vxlan_ip_src_value,
15393                 (void *)&cmd_set_vxlan_ip_dst,
15394                 (void *)&cmd_set_vxlan_ip_dst_value,
15395                 (void *)&cmd_set_vxlan_eth_src,
15396                 (void *)&cmd_set_vxlan_eth_src_value,
15397                 (void *)&cmd_set_vxlan_eth_dst,
15398                 (void *)&cmd_set_vxlan_eth_dst_value,
15399                 NULL,
15400         },
15401 };
15402
15403 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15404         .f = cmd_set_vxlan_parsed,
15405         .data = NULL,
15406         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15407                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15408                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15409                 " <eth-dst>",
15410         .tokens = {
15411                 (void *)&cmd_set_vxlan_set,
15412                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15413                 (void *)&cmd_set_vxlan_ip_version,
15414                 (void *)&cmd_set_vxlan_ip_version_value,
15415                 (void *)&cmd_set_vxlan_vni,
15416                 (void *)&cmd_set_vxlan_vni_value,
15417                 (void *)&cmd_set_vxlan_udp_src,
15418                 (void *)&cmd_set_vxlan_udp_src_value,
15419                 (void *)&cmd_set_vxlan_udp_dst,
15420                 (void *)&cmd_set_vxlan_udp_dst_value,
15421                 (void *)&cmd_set_vxlan_ip_src,
15422                 (void *)&cmd_set_vxlan_ip_src_value,
15423                 (void *)&cmd_set_vxlan_ip_dst,
15424                 (void *)&cmd_set_vxlan_ip_dst_value,
15425                 (void *)&cmd_set_vxlan_vlan,
15426                 (void *)&cmd_set_vxlan_vlan_value,
15427                 (void *)&cmd_set_vxlan_eth_src,
15428                 (void *)&cmd_set_vxlan_eth_src_value,
15429                 (void *)&cmd_set_vxlan_eth_dst,
15430                 (void *)&cmd_set_vxlan_eth_dst_value,
15431                 NULL,
15432         },
15433 };
15434
15435 /** Set NVGRE encapsulation details */
15436 struct cmd_set_nvgre_result {
15437         cmdline_fixed_string_t set;
15438         cmdline_fixed_string_t nvgre;
15439         cmdline_fixed_string_t pos_token;
15440         cmdline_fixed_string_t ip_version;
15441         uint32_t tni;
15442         cmdline_ipaddr_t ip_src;
15443         cmdline_ipaddr_t ip_dst;
15444         uint16_t tci;
15445         struct rte_ether_addr eth_src;
15446         struct rte_ether_addr eth_dst;
15447 };
15448
15449 cmdline_parse_token_string_t cmd_set_nvgre_set =
15450         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15451 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15452         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15453 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15454         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15455                                  "nvgre-with-vlan");
15456 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15457         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15458                                  "ip-version");
15459 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15460         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15461                                  "ipv4#ipv6");
15462 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15463         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15464                                  "tni");
15465 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15466         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15467 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15468         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15469                                  "ip-src");
15470 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15471         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15472 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15473         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15474                                  "ip-dst");
15475 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15476         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15477 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15478         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15479                                  "vlan-tci");
15480 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15481         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15482 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15483         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15484                                  "eth-src");
15485 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15486         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15487 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15488         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15489                                  "eth-dst");
15490 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15491         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15492
15493 static void cmd_set_nvgre_parsed(void *parsed_result,
15494         __attribute__((unused)) struct cmdline *cl,
15495         __attribute__((unused)) void *data)
15496 {
15497         struct cmd_set_nvgre_result *res = parsed_result;
15498         union {
15499                 uint32_t nvgre_tni;
15500                 uint8_t tni[4];
15501         } id = {
15502                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15503         };
15504
15505         if (strcmp(res->nvgre, "nvgre") == 0)
15506                 nvgre_encap_conf.select_vlan = 0;
15507         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15508                 nvgre_encap_conf.select_vlan = 1;
15509         if (strcmp(res->ip_version, "ipv4") == 0)
15510                 nvgre_encap_conf.select_ipv4 = 1;
15511         else if (strcmp(res->ip_version, "ipv6") == 0)
15512                 nvgre_encap_conf.select_ipv4 = 0;
15513         else
15514                 return;
15515         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15516         if (nvgre_encap_conf.select_ipv4) {
15517                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15518                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15519         } else {
15520                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15521                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15522         }
15523         if (nvgre_encap_conf.select_vlan)
15524                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15525         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15526                    RTE_ETHER_ADDR_LEN);
15527         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15528                    RTE_ETHER_ADDR_LEN);
15529 }
15530
15531 cmdline_parse_inst_t cmd_set_nvgre = {
15532         .f = cmd_set_nvgre_parsed,
15533         .data = NULL,
15534         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15535                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15536                 " eth-dst <eth-dst>",
15537         .tokens = {
15538                 (void *)&cmd_set_nvgre_set,
15539                 (void *)&cmd_set_nvgre_nvgre,
15540                 (void *)&cmd_set_nvgre_ip_version,
15541                 (void *)&cmd_set_nvgre_ip_version_value,
15542                 (void *)&cmd_set_nvgre_tni,
15543                 (void *)&cmd_set_nvgre_tni_value,
15544                 (void *)&cmd_set_nvgre_ip_src,
15545                 (void *)&cmd_set_nvgre_ip_src_value,
15546                 (void *)&cmd_set_nvgre_ip_dst,
15547                 (void *)&cmd_set_nvgre_ip_dst_value,
15548                 (void *)&cmd_set_nvgre_eth_src,
15549                 (void *)&cmd_set_nvgre_eth_src_value,
15550                 (void *)&cmd_set_nvgre_eth_dst,
15551                 (void *)&cmd_set_nvgre_eth_dst_value,
15552                 NULL,
15553         },
15554 };
15555
15556 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15557         .f = cmd_set_nvgre_parsed,
15558         .data = NULL,
15559         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15560                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15561                 " eth-src <eth-src> eth-dst <eth-dst>",
15562         .tokens = {
15563                 (void *)&cmd_set_nvgre_set,
15564                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15565                 (void *)&cmd_set_nvgre_ip_version,
15566                 (void *)&cmd_set_nvgre_ip_version_value,
15567                 (void *)&cmd_set_nvgre_tni,
15568                 (void *)&cmd_set_nvgre_tni_value,
15569                 (void *)&cmd_set_nvgre_ip_src,
15570                 (void *)&cmd_set_nvgre_ip_src_value,
15571                 (void *)&cmd_set_nvgre_ip_dst,
15572                 (void *)&cmd_set_nvgre_ip_dst_value,
15573                 (void *)&cmd_set_nvgre_vlan,
15574                 (void *)&cmd_set_nvgre_vlan_value,
15575                 (void *)&cmd_set_nvgre_eth_src,
15576                 (void *)&cmd_set_nvgre_eth_src_value,
15577                 (void *)&cmd_set_nvgre_eth_dst,
15578                 (void *)&cmd_set_nvgre_eth_dst_value,
15579                 NULL,
15580         },
15581 };
15582
15583 /** Set L2 encapsulation details */
15584 struct cmd_set_l2_encap_result {
15585         cmdline_fixed_string_t set;
15586         cmdline_fixed_string_t l2_encap;
15587         cmdline_fixed_string_t pos_token;
15588         cmdline_fixed_string_t ip_version;
15589         uint32_t vlan_present:1;
15590         uint16_t tci;
15591         struct rte_ether_addr eth_src;
15592         struct rte_ether_addr eth_dst;
15593 };
15594
15595 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15596         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15597 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15598         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15599 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15600         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15601                                  "l2_encap-with-vlan");
15602 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15603         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15604                                  "ip-version");
15605 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15606         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15607                                  "ipv4#ipv6");
15608 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15609         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15610                                  "vlan-tci");
15611 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15612         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15613 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15614         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15615                                  "eth-src");
15616 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15617         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15618 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15619         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15620                                  "eth-dst");
15621 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15622         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15623
15624 static void cmd_set_l2_encap_parsed(void *parsed_result,
15625         __attribute__((unused)) struct cmdline *cl,
15626         __attribute__((unused)) void *data)
15627 {
15628         struct cmd_set_l2_encap_result *res = parsed_result;
15629
15630         if (strcmp(res->l2_encap, "l2_encap") == 0)
15631                 l2_encap_conf.select_vlan = 0;
15632         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15633                 l2_encap_conf.select_vlan = 1;
15634         if (strcmp(res->ip_version, "ipv4") == 0)
15635                 l2_encap_conf.select_ipv4 = 1;
15636         else if (strcmp(res->ip_version, "ipv6") == 0)
15637                 l2_encap_conf.select_ipv4 = 0;
15638         else
15639                 return;
15640         if (l2_encap_conf.select_vlan)
15641                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15642         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15643                    RTE_ETHER_ADDR_LEN);
15644         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15645                    RTE_ETHER_ADDR_LEN);
15646 }
15647
15648 cmdline_parse_inst_t cmd_set_l2_encap = {
15649         .f = cmd_set_l2_encap_parsed,
15650         .data = NULL,
15651         .help_str = "set l2_encap ip-version ipv4|ipv6"
15652                 " eth-src <eth-src> eth-dst <eth-dst>",
15653         .tokens = {
15654                 (void *)&cmd_set_l2_encap_set,
15655                 (void *)&cmd_set_l2_encap_l2_encap,
15656                 (void *)&cmd_set_l2_encap_ip_version,
15657                 (void *)&cmd_set_l2_encap_ip_version_value,
15658                 (void *)&cmd_set_l2_encap_eth_src,
15659                 (void *)&cmd_set_l2_encap_eth_src_value,
15660                 (void *)&cmd_set_l2_encap_eth_dst,
15661                 (void *)&cmd_set_l2_encap_eth_dst_value,
15662                 NULL,
15663         },
15664 };
15665
15666 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15667         .f = cmd_set_l2_encap_parsed,
15668         .data = NULL,
15669         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15670                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15671         .tokens = {
15672                 (void *)&cmd_set_l2_encap_set,
15673                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15674                 (void *)&cmd_set_l2_encap_ip_version,
15675                 (void *)&cmd_set_l2_encap_ip_version_value,
15676                 (void *)&cmd_set_l2_encap_vlan,
15677                 (void *)&cmd_set_l2_encap_vlan_value,
15678                 (void *)&cmd_set_l2_encap_eth_src,
15679                 (void *)&cmd_set_l2_encap_eth_src_value,
15680                 (void *)&cmd_set_l2_encap_eth_dst,
15681                 (void *)&cmd_set_l2_encap_eth_dst_value,
15682                 NULL,
15683         },
15684 };
15685
15686 /** Set L2 decapsulation details */
15687 struct cmd_set_l2_decap_result {
15688         cmdline_fixed_string_t set;
15689         cmdline_fixed_string_t l2_decap;
15690         cmdline_fixed_string_t pos_token;
15691         uint32_t vlan_present:1;
15692 };
15693
15694 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15695         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15696 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15697         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15698                                  "l2_decap");
15699 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15700         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15701                                  "l2_decap-with-vlan");
15702
15703 static void cmd_set_l2_decap_parsed(void *parsed_result,
15704         __attribute__((unused)) struct cmdline *cl,
15705         __attribute__((unused)) void *data)
15706 {
15707         struct cmd_set_l2_decap_result *res = parsed_result;
15708
15709         if (strcmp(res->l2_decap, "l2_decap") == 0)
15710                 l2_decap_conf.select_vlan = 0;
15711         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15712                 l2_decap_conf.select_vlan = 1;
15713 }
15714
15715 cmdline_parse_inst_t cmd_set_l2_decap = {
15716         .f = cmd_set_l2_decap_parsed,
15717         .data = NULL,
15718         .help_str = "set l2_decap",
15719         .tokens = {
15720                 (void *)&cmd_set_l2_decap_set,
15721                 (void *)&cmd_set_l2_decap_l2_decap,
15722                 NULL,
15723         },
15724 };
15725
15726 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15727         .f = cmd_set_l2_decap_parsed,
15728         .data = NULL,
15729         .help_str = "set l2_decap-with-vlan",
15730         .tokens = {
15731                 (void *)&cmd_set_l2_decap_set,
15732                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15733                 NULL,
15734         },
15735 };
15736
15737 /** Set MPLSoGRE encapsulation details */
15738 struct cmd_set_mplsogre_encap_result {
15739         cmdline_fixed_string_t set;
15740         cmdline_fixed_string_t mplsogre;
15741         cmdline_fixed_string_t pos_token;
15742         cmdline_fixed_string_t ip_version;
15743         uint32_t vlan_present:1;
15744         uint32_t label;
15745         cmdline_ipaddr_t ip_src;
15746         cmdline_ipaddr_t ip_dst;
15747         uint16_t tci;
15748         struct rte_ether_addr eth_src;
15749         struct rte_ether_addr eth_dst;
15750 };
15751
15752 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15753         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15754                                  "set");
15755 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15756         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15757                                  "mplsogre_encap");
15758 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15759         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15760                                  mplsogre, "mplsogre_encap-with-vlan");
15761 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15762         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15763                                  pos_token, "ip-version");
15764 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15765         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15766                                  ip_version, "ipv4#ipv6");
15767 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15768         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15769                                  pos_token, "label");
15770 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15771         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15772                               UINT32);
15773 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15774         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15775                                  pos_token, "ip-src");
15776 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15777         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15778 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15779         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15780                                  pos_token, "ip-dst");
15781 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15782         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15783 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15784         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15785                                  pos_token, "vlan-tci");
15786 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15787         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15788                               UINT16);
15789 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15790         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15791                                  pos_token, "eth-src");
15792 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15793         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15794                                     eth_src);
15795 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15796         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15797                                  pos_token, "eth-dst");
15798 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15799         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15800                                     eth_dst);
15801
15802 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15803         __attribute__((unused)) struct cmdline *cl,
15804         __attribute__((unused)) void *data)
15805 {
15806         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15807         union {
15808                 uint32_t mplsogre_label;
15809                 uint8_t label[4];
15810         } id = {
15811                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15812         };
15813
15814         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15815                 mplsogre_encap_conf.select_vlan = 0;
15816         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15817                 mplsogre_encap_conf.select_vlan = 1;
15818         if (strcmp(res->ip_version, "ipv4") == 0)
15819                 mplsogre_encap_conf.select_ipv4 = 1;
15820         else if (strcmp(res->ip_version, "ipv6") == 0)
15821                 mplsogre_encap_conf.select_ipv4 = 0;
15822         else
15823                 return;
15824         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15825         if (mplsogre_encap_conf.select_ipv4) {
15826                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15827                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15828         } else {
15829                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15830                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15831         }
15832         if (mplsogre_encap_conf.select_vlan)
15833                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15834         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15835                    RTE_ETHER_ADDR_LEN);
15836         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15837                    RTE_ETHER_ADDR_LEN);
15838 }
15839
15840 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15841         .f = cmd_set_mplsogre_encap_parsed,
15842         .data = NULL,
15843         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15844                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15845                 " eth-dst <eth-dst>",
15846         .tokens = {
15847                 (void *)&cmd_set_mplsogre_encap_set,
15848                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15849                 (void *)&cmd_set_mplsogre_encap_ip_version,
15850                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15851                 (void *)&cmd_set_mplsogre_encap_label,
15852                 (void *)&cmd_set_mplsogre_encap_label_value,
15853                 (void *)&cmd_set_mplsogre_encap_ip_src,
15854                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15855                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15856                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15857                 (void *)&cmd_set_mplsogre_encap_eth_src,
15858                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15859                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15860                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15861                 NULL,
15862         },
15863 };
15864
15865 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15866         .f = cmd_set_mplsogre_encap_parsed,
15867         .data = NULL,
15868         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15869                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15870                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15871         .tokens = {
15872                 (void *)&cmd_set_mplsogre_encap_set,
15873                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15874                 (void *)&cmd_set_mplsogre_encap_ip_version,
15875                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15876                 (void *)&cmd_set_mplsogre_encap_label,
15877                 (void *)&cmd_set_mplsogre_encap_label_value,
15878                 (void *)&cmd_set_mplsogre_encap_ip_src,
15879                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15880                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15881                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15882                 (void *)&cmd_set_mplsogre_encap_vlan,
15883                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15884                 (void *)&cmd_set_mplsogre_encap_eth_src,
15885                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15886                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15887                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15888                 NULL,
15889         },
15890 };
15891
15892 /** Set MPLSoGRE decapsulation details */
15893 struct cmd_set_mplsogre_decap_result {
15894         cmdline_fixed_string_t set;
15895         cmdline_fixed_string_t mplsogre;
15896         cmdline_fixed_string_t pos_token;
15897         cmdline_fixed_string_t ip_version;
15898         uint32_t vlan_present:1;
15899 };
15900
15901 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15902         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15903                                  "set");
15904 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15905         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15906                                  "mplsogre_decap");
15907 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15908         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15909                                  mplsogre, "mplsogre_decap-with-vlan");
15910 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15911         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15912                                  pos_token, "ip-version");
15913 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15914         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15915                                  ip_version, "ipv4#ipv6");
15916
15917 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15918         __attribute__((unused)) struct cmdline *cl,
15919         __attribute__((unused)) void *data)
15920 {
15921         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15922
15923         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15924                 mplsogre_decap_conf.select_vlan = 0;
15925         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15926                 mplsogre_decap_conf.select_vlan = 1;
15927         if (strcmp(res->ip_version, "ipv4") == 0)
15928                 mplsogre_decap_conf.select_ipv4 = 1;
15929         else if (strcmp(res->ip_version, "ipv6") == 0)
15930                 mplsogre_decap_conf.select_ipv4 = 0;
15931 }
15932
15933 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15934         .f = cmd_set_mplsogre_decap_parsed,
15935         .data = NULL,
15936         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15937         .tokens = {
15938                 (void *)&cmd_set_mplsogre_decap_set,
15939                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15940                 (void *)&cmd_set_mplsogre_decap_ip_version,
15941                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15942                 NULL,
15943         },
15944 };
15945
15946 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15947         .f = cmd_set_mplsogre_decap_parsed,
15948         .data = NULL,
15949         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15950         .tokens = {
15951                 (void *)&cmd_set_mplsogre_decap_set,
15952                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15953                 (void *)&cmd_set_mplsogre_decap_ip_version,
15954                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15955                 NULL,
15956         },
15957 };
15958
15959 /** Set MPLSoUDP encapsulation details */
15960 struct cmd_set_mplsoudp_encap_result {
15961         cmdline_fixed_string_t set;
15962         cmdline_fixed_string_t mplsoudp;
15963         cmdline_fixed_string_t pos_token;
15964         cmdline_fixed_string_t ip_version;
15965         uint32_t vlan_present:1;
15966         uint32_t label;
15967         uint16_t udp_src;
15968         uint16_t udp_dst;
15969         cmdline_ipaddr_t ip_src;
15970         cmdline_ipaddr_t ip_dst;
15971         uint16_t tci;
15972         struct rte_ether_addr eth_src;
15973         struct rte_ether_addr eth_dst;
15974 };
15975
15976 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15977         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15978                                  "set");
15979 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15980         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15981                                  "mplsoudp_encap");
15982 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15983         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15984                                  mplsoudp, "mplsoudp_encap-with-vlan");
15985 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15986         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15987                                  pos_token, "ip-version");
15988 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15989         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15990                                  ip_version, "ipv4#ipv6");
15991 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15992         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15993                                  pos_token, "label");
15994 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15995         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15996                               UINT32);
15997 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15998         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15999                                  pos_token, "udp-src");
16000 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16001         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16002                               UINT16);
16003 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16004         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16005                                  pos_token, "udp-dst");
16006 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16007         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16008                               UINT16);
16009 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16010         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16011                                  pos_token, "ip-src");
16012 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16013         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16014 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16015         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16016                                  pos_token, "ip-dst");
16017 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16018         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16019 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16020         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16021                                  pos_token, "vlan-tci");
16022 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16023         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16024                               UINT16);
16025 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16026         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16027                                  pos_token, "eth-src");
16028 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16029         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16030                                     eth_src);
16031 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16032         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16033                                  pos_token, "eth-dst");
16034 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16035         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16036                                     eth_dst);
16037
16038 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16039         __attribute__((unused)) struct cmdline *cl,
16040         __attribute__((unused)) void *data)
16041 {
16042         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16043         union {
16044                 uint32_t mplsoudp_label;
16045                 uint8_t label[4];
16046         } id = {
16047                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16048         };
16049
16050         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16051                 mplsoudp_encap_conf.select_vlan = 0;
16052         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16053                 mplsoudp_encap_conf.select_vlan = 1;
16054         if (strcmp(res->ip_version, "ipv4") == 0)
16055                 mplsoudp_encap_conf.select_ipv4 = 1;
16056         else if (strcmp(res->ip_version, "ipv6") == 0)
16057                 mplsoudp_encap_conf.select_ipv4 = 0;
16058         else
16059                 return;
16060         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16061         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16062         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16063         if (mplsoudp_encap_conf.select_ipv4) {
16064                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16065                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16066         } else {
16067                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16068                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16069         }
16070         if (mplsoudp_encap_conf.select_vlan)
16071                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16072         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16073                    RTE_ETHER_ADDR_LEN);
16074         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16075                    RTE_ETHER_ADDR_LEN);
16076 }
16077
16078 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16079         .f = cmd_set_mplsoudp_encap_parsed,
16080         .data = NULL,
16081         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16082                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16083                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16084         .tokens = {
16085                 (void *)&cmd_set_mplsoudp_encap_set,
16086                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16087                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16088                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16089                 (void *)&cmd_set_mplsoudp_encap_label,
16090                 (void *)&cmd_set_mplsoudp_encap_label_value,
16091                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16092                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16093                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16094                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16095                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16096                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16097                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16098                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16099                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16100                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16101                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16102                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16103                 NULL,
16104         },
16105 };
16106
16107 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16108         .f = cmd_set_mplsoudp_encap_parsed,
16109         .data = NULL,
16110         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16111                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16112                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16113                 " eth-src <eth-src> eth-dst <eth-dst>",
16114         .tokens = {
16115                 (void *)&cmd_set_mplsoudp_encap_set,
16116                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16117                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16118                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16119                 (void *)&cmd_set_mplsoudp_encap_label,
16120                 (void *)&cmd_set_mplsoudp_encap_label_value,
16121                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16122                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16123                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16124                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16125                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16126                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16127                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16128                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16129                 (void *)&cmd_set_mplsoudp_encap_vlan,
16130                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16131                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16132                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16133                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16134                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16135                 NULL,
16136         },
16137 };
16138
16139 /** Set MPLSoUDP decapsulation details */
16140 struct cmd_set_mplsoudp_decap_result {
16141         cmdline_fixed_string_t set;
16142         cmdline_fixed_string_t mplsoudp;
16143         cmdline_fixed_string_t pos_token;
16144         cmdline_fixed_string_t ip_version;
16145         uint32_t vlan_present:1;
16146 };
16147
16148 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16149         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16150                                  "set");
16151 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16152         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16153                                  "mplsoudp_decap");
16154 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16155         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16156                                  mplsoudp, "mplsoudp_decap-with-vlan");
16157 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16158         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16159                                  pos_token, "ip-version");
16160 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16161         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16162                                  ip_version, "ipv4#ipv6");
16163
16164 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16165         __attribute__((unused)) struct cmdline *cl,
16166         __attribute__((unused)) void *data)
16167 {
16168         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16169
16170         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16171                 mplsoudp_decap_conf.select_vlan = 0;
16172         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16173                 mplsoudp_decap_conf.select_vlan = 1;
16174         if (strcmp(res->ip_version, "ipv4") == 0)
16175                 mplsoudp_decap_conf.select_ipv4 = 1;
16176         else if (strcmp(res->ip_version, "ipv6") == 0)
16177                 mplsoudp_decap_conf.select_ipv4 = 0;
16178 }
16179
16180 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16181         .f = cmd_set_mplsoudp_decap_parsed,
16182         .data = NULL,
16183         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16184         .tokens = {
16185                 (void *)&cmd_set_mplsoudp_decap_set,
16186                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16187                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16188                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16189                 NULL,
16190         },
16191 };
16192
16193 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16194         .f = cmd_set_mplsoudp_decap_parsed,
16195         .data = NULL,
16196         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16197         .tokens = {
16198                 (void *)&cmd_set_mplsoudp_decap_set,
16199                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16200                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16201                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16202                 NULL,
16203         },
16204 };
16205
16206 /* Strict link priority scheduling mode setting */
16207 static void
16208 cmd_strict_link_prio_parsed(
16209         void *parsed_result,
16210         __attribute__((unused)) struct cmdline *cl,
16211         __attribute__((unused)) void *data)
16212 {
16213         struct cmd_vf_tc_bw_result *res = parsed_result;
16214         int ret = -ENOTSUP;
16215
16216         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16217                 return;
16218
16219 #ifdef RTE_LIBRTE_I40E_PMD
16220         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16221 #endif
16222
16223         switch (ret) {
16224         case 0:
16225                 break;
16226         case -EINVAL:
16227                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16228                 break;
16229         case -ENODEV:
16230                 printf("invalid port_id %d\n", res->port_id);
16231                 break;
16232         case -ENOTSUP:
16233                 printf("function not implemented\n");
16234                 break;
16235         default:
16236                 printf("programming error: (%s)\n", strerror(-ret));
16237         }
16238 }
16239
16240 cmdline_parse_inst_t cmd_strict_link_prio = {
16241         .f = cmd_strict_link_prio_parsed,
16242         .data = NULL,
16243         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16244         .tokens = {
16245                 (void *)&cmd_vf_tc_bw_set,
16246                 (void *)&cmd_vf_tc_bw_tx,
16247                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16248                 (void *)&cmd_vf_tc_bw_port_id,
16249                 (void *)&cmd_vf_tc_bw_tc_map,
16250                 NULL,
16251         },
16252 };
16253
16254 /* Load dynamic device personalization*/
16255 struct cmd_ddp_add_result {
16256         cmdline_fixed_string_t ddp;
16257         cmdline_fixed_string_t add;
16258         portid_t port_id;
16259         char filepath[];
16260 };
16261
16262 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16263         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16264 cmdline_parse_token_string_t cmd_ddp_add_add =
16265         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16266 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16267         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16268 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16269         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16270
16271 static void
16272 cmd_ddp_add_parsed(
16273         void *parsed_result,
16274         __attribute__((unused)) struct cmdline *cl,
16275         __attribute__((unused)) void *data)
16276 {
16277         struct cmd_ddp_add_result *res = parsed_result;
16278         uint8_t *buff;
16279         uint32_t size;
16280         char *filepath;
16281         char *file_fld[2];
16282         int file_num;
16283         int ret = -ENOTSUP;
16284
16285         if (!all_ports_stopped()) {
16286                 printf("Please stop all ports first\n");
16287                 return;
16288         }
16289
16290         filepath = strdup(res->filepath);
16291         if (filepath == NULL) {
16292                 printf("Failed to allocate memory\n");
16293                 return;
16294         }
16295         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16296
16297         buff = open_file(file_fld[0], &size);
16298         if (!buff) {
16299                 free((void *)filepath);
16300                 return;
16301         }
16302
16303 #ifdef RTE_LIBRTE_I40E_PMD
16304         if (ret == -ENOTSUP)
16305                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16306                                                buff, size,
16307                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16308 #endif
16309
16310         if (ret == -EEXIST)
16311                 printf("Profile has already existed.\n");
16312         else if (ret < 0)
16313                 printf("Failed to load profile.\n");
16314         else if (file_num == 2)
16315                 save_file(file_fld[1], buff, size);
16316
16317         close_file(buff);
16318         free((void *)filepath);
16319 }
16320
16321 cmdline_parse_inst_t cmd_ddp_add = {
16322         .f = cmd_ddp_add_parsed,
16323         .data = NULL,
16324         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16325         .tokens = {
16326                 (void *)&cmd_ddp_add_ddp,
16327                 (void *)&cmd_ddp_add_add,
16328                 (void *)&cmd_ddp_add_port_id,
16329                 (void *)&cmd_ddp_add_filepath,
16330                 NULL,
16331         },
16332 };
16333
16334 /* Delete dynamic device personalization*/
16335 struct cmd_ddp_del_result {
16336         cmdline_fixed_string_t ddp;
16337         cmdline_fixed_string_t del;
16338         portid_t port_id;
16339         char filepath[];
16340 };
16341
16342 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16343         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16344 cmdline_parse_token_string_t cmd_ddp_del_del =
16345         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16346 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16347         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16348 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16349         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16350
16351 static void
16352 cmd_ddp_del_parsed(
16353         void *parsed_result,
16354         __attribute__((unused)) struct cmdline *cl,
16355         __attribute__((unused)) void *data)
16356 {
16357         struct cmd_ddp_del_result *res = parsed_result;
16358         uint8_t *buff;
16359         uint32_t size;
16360         int ret = -ENOTSUP;
16361
16362         if (!all_ports_stopped()) {
16363                 printf("Please stop all ports first\n");
16364                 return;
16365         }
16366
16367         buff = open_file(res->filepath, &size);
16368         if (!buff)
16369                 return;
16370
16371 #ifdef RTE_LIBRTE_I40E_PMD
16372         if (ret == -ENOTSUP)
16373                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16374                                                buff, size,
16375                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16376 #endif
16377
16378         if (ret == -EACCES)
16379                 printf("Profile does not exist.\n");
16380         else if (ret < 0)
16381                 printf("Failed to delete profile.\n");
16382
16383         close_file(buff);
16384 }
16385
16386 cmdline_parse_inst_t cmd_ddp_del = {
16387         .f = cmd_ddp_del_parsed,
16388         .data = NULL,
16389         .help_str = "ddp del <port_id> <backup_profile_path>",
16390         .tokens = {
16391                 (void *)&cmd_ddp_del_ddp,
16392                 (void *)&cmd_ddp_del_del,
16393                 (void *)&cmd_ddp_del_port_id,
16394                 (void *)&cmd_ddp_del_filepath,
16395                 NULL,
16396         },
16397 };
16398
16399 /* Get dynamic device personalization profile info */
16400 struct cmd_ddp_info_result {
16401         cmdline_fixed_string_t ddp;
16402         cmdline_fixed_string_t get;
16403         cmdline_fixed_string_t info;
16404         char filepath[];
16405 };
16406
16407 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16408         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16409 cmdline_parse_token_string_t cmd_ddp_info_get =
16410         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16411 cmdline_parse_token_string_t cmd_ddp_info_info =
16412         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16413 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16414         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16415
16416 static void
16417 cmd_ddp_info_parsed(
16418         void *parsed_result,
16419         __attribute__((unused)) struct cmdline *cl,
16420         __attribute__((unused)) void *data)
16421 {
16422         struct cmd_ddp_info_result *res = parsed_result;
16423         uint8_t *pkg;
16424         uint32_t pkg_size;
16425         int ret = -ENOTSUP;
16426 #ifdef RTE_LIBRTE_I40E_PMD
16427         uint32_t i, j, n;
16428         uint8_t *buff;
16429         uint32_t buff_size = 0;
16430         struct rte_pmd_i40e_profile_info info;
16431         uint32_t dev_num = 0;
16432         struct rte_pmd_i40e_ddp_device_id *devs;
16433         uint32_t proto_num = 0;
16434         struct rte_pmd_i40e_proto_info *proto = NULL;
16435         uint32_t pctype_num = 0;
16436         struct rte_pmd_i40e_ptype_info *pctype;
16437         uint32_t ptype_num = 0;
16438         struct rte_pmd_i40e_ptype_info *ptype;
16439         uint8_t proto_id;
16440
16441 #endif
16442
16443         pkg = open_file(res->filepath, &pkg_size);
16444         if (!pkg)
16445                 return;
16446
16447 #ifdef RTE_LIBRTE_I40E_PMD
16448         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16449                                 (uint8_t *)&info, sizeof(info),
16450                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16451         if (!ret) {
16452                 printf("Global Track id:       0x%x\n", info.track_id);
16453                 printf("Global Version:        %d.%d.%d.%d\n",
16454                         info.version.major,
16455                         info.version.minor,
16456                         info.version.update,
16457                         info.version.draft);
16458                 printf("Global Package name:   %s\n\n", info.name);
16459         }
16460
16461         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16462                                 (uint8_t *)&info, sizeof(info),
16463                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16464         if (!ret) {
16465                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16466                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16467                         info.version.major,
16468                         info.version.minor,
16469                         info.version.update,
16470                         info.version.draft);
16471                 printf("i40e Profile name:     %s\n\n", info.name);
16472         }
16473
16474         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16475                                 (uint8_t *)&buff_size, sizeof(buff_size),
16476                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16477         if (!ret && buff_size) {
16478                 buff = (uint8_t *)malloc(buff_size);
16479                 if (buff) {
16480                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16481                                                 buff, buff_size,
16482                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16483                         if (!ret)
16484                                 printf("Package Notes:\n%s\n\n", buff);
16485                         free(buff);
16486                 }
16487         }
16488
16489         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16490                                 (uint8_t *)&dev_num, sizeof(dev_num),
16491                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16492         if (!ret && dev_num) {
16493                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16494                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16495                 if (devs) {
16496                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16497                                                 (uint8_t *)devs, buff_size,
16498                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16499                         if (!ret) {
16500                                 printf("List of supported devices:\n");
16501                                 for (i = 0; i < dev_num; i++) {
16502                                         printf("  %04X:%04X %04X:%04X\n",
16503                                                 devs[i].vendor_dev_id >> 16,
16504                                                 devs[i].vendor_dev_id & 0xFFFF,
16505                                                 devs[i].sub_vendor_dev_id >> 16,
16506                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16507                                 }
16508                                 printf("\n");
16509                         }
16510                         free(devs);
16511                 }
16512         }
16513
16514         /* get information about protocols and packet types */
16515         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16516                 (uint8_t *)&proto_num, sizeof(proto_num),
16517                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16518         if (ret || !proto_num)
16519                 goto no_print_return;
16520
16521         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16522         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16523         if (!proto)
16524                 goto no_print_return;
16525
16526         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16527                                         buff_size,
16528                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16529         if (!ret) {
16530                 printf("List of used protocols:\n");
16531                 for (i = 0; i < proto_num; i++)
16532                         printf("  %2u: %s\n", proto[i].proto_id,
16533                                proto[i].name);
16534                 printf("\n");
16535         }
16536         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16537                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16538                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16539         if (ret || !pctype_num)
16540                 goto no_print_pctypes;
16541
16542         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16543         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16544         if (!pctype)
16545                 goto no_print_pctypes;
16546
16547         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16548                                         buff_size,
16549                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16550         if (ret) {
16551                 free(pctype);
16552                 goto no_print_pctypes;
16553         }
16554
16555         printf("List of defined packet classification types:\n");
16556         for (i = 0; i < pctype_num; i++) {
16557                 printf("  %2u:", pctype[i].ptype_id);
16558                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16559                         proto_id = pctype[i].protocols[j];
16560                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16561                                 for (n = 0; n < proto_num; n++) {
16562                                         if (proto[n].proto_id == proto_id) {
16563                                                 printf(" %s", proto[n].name);
16564                                                 break;
16565                                         }
16566                                 }
16567                         }
16568                 }
16569                 printf("\n");
16570         }
16571         printf("\n");
16572         free(pctype);
16573
16574 no_print_pctypes:
16575
16576         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16577                                         sizeof(ptype_num),
16578                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16579         if (ret || !ptype_num)
16580                 goto no_print_return;
16581
16582         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16583         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16584         if (!ptype)
16585                 goto no_print_return;
16586
16587         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16588                                         buff_size,
16589                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16590         if (ret) {
16591                 free(ptype);
16592                 goto no_print_return;
16593         }
16594         printf("List of defined packet types:\n");
16595         for (i = 0; i < ptype_num; i++) {
16596                 printf("  %2u:", ptype[i].ptype_id);
16597                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16598                         proto_id = ptype[i].protocols[j];
16599                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16600                                 for (n = 0; n < proto_num; n++) {
16601                                         if (proto[n].proto_id == proto_id) {
16602                                                 printf(" %s", proto[n].name);
16603                                                 break;
16604                                         }
16605                                 }
16606                         }
16607                 }
16608                 printf("\n");
16609         }
16610         free(ptype);
16611         printf("\n");
16612
16613         ret = 0;
16614 no_print_return:
16615         if (proto)
16616                 free(proto);
16617 #endif
16618         if (ret == -ENOTSUP)
16619                 printf("Function not supported in PMD driver\n");
16620         close_file(pkg);
16621 }
16622
16623 cmdline_parse_inst_t cmd_ddp_get_info = {
16624         .f = cmd_ddp_info_parsed,
16625         .data = NULL,
16626         .help_str = "ddp get info <profile_path>",
16627         .tokens = {
16628                 (void *)&cmd_ddp_info_ddp,
16629                 (void *)&cmd_ddp_info_get,
16630                 (void *)&cmd_ddp_info_info,
16631                 (void *)&cmd_ddp_info_filepath,
16632                 NULL,
16633         },
16634 };
16635
16636 /* Get dynamic device personalization profile info list*/
16637 #define PROFILE_INFO_SIZE 48
16638 #define MAX_PROFILE_NUM 16
16639
16640 struct cmd_ddp_get_list_result {
16641         cmdline_fixed_string_t ddp;
16642         cmdline_fixed_string_t get;
16643         cmdline_fixed_string_t list;
16644         portid_t port_id;
16645 };
16646
16647 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16648         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16649 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16650         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16651 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16652         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16653 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16654         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16655
16656 static void
16657 cmd_ddp_get_list_parsed(
16658         __attribute__((unused)) void *parsed_result,
16659         __attribute__((unused)) struct cmdline *cl,
16660         __attribute__((unused)) void *data)
16661 {
16662 #ifdef RTE_LIBRTE_I40E_PMD
16663         struct cmd_ddp_get_list_result *res = parsed_result;
16664         struct rte_pmd_i40e_profile_list *p_list;
16665         struct rte_pmd_i40e_profile_info *p_info;
16666         uint32_t p_num;
16667         uint32_t size;
16668         uint32_t i;
16669 #endif
16670         int ret = -ENOTSUP;
16671
16672 #ifdef RTE_LIBRTE_I40E_PMD
16673         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16674         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16675         if (!p_list)
16676                 printf("%s: Failed to malloc buffer\n", __func__);
16677
16678         if (ret == -ENOTSUP)
16679                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16680                                                 (uint8_t *)p_list, size);
16681
16682         if (!ret) {
16683                 p_num = p_list->p_count;
16684                 printf("Profile number is: %d\n\n", p_num);
16685
16686                 for (i = 0; i < p_num; i++) {
16687                         p_info = &p_list->p_info[i];
16688                         printf("Profile %d:\n", i);
16689                         printf("Track id:     0x%x\n", p_info->track_id);
16690                         printf("Version:      %d.%d.%d.%d\n",
16691                                p_info->version.major,
16692                                p_info->version.minor,
16693                                p_info->version.update,
16694                                p_info->version.draft);
16695                         printf("Profile name: %s\n\n", p_info->name);
16696                 }
16697         }
16698
16699         free(p_list);
16700 #endif
16701
16702         if (ret < 0)
16703                 printf("Failed to get ddp list\n");
16704 }
16705
16706 cmdline_parse_inst_t cmd_ddp_get_list = {
16707         .f = cmd_ddp_get_list_parsed,
16708         .data = NULL,
16709         .help_str = "ddp get list <port_id>",
16710         .tokens = {
16711                 (void *)&cmd_ddp_get_list_ddp,
16712                 (void *)&cmd_ddp_get_list_get,
16713                 (void *)&cmd_ddp_get_list_list,
16714                 (void *)&cmd_ddp_get_list_port_id,
16715                 NULL,
16716         },
16717 };
16718
16719 /* Configure input set */
16720 struct cmd_cfg_input_set_result {
16721         cmdline_fixed_string_t port;
16722         cmdline_fixed_string_t cfg;
16723         portid_t port_id;
16724         cmdline_fixed_string_t pctype;
16725         uint8_t pctype_id;
16726         cmdline_fixed_string_t inset_type;
16727         cmdline_fixed_string_t opt;
16728         cmdline_fixed_string_t field;
16729         uint8_t field_idx;
16730 };
16731
16732 static void
16733 cmd_cfg_input_set_parsed(
16734         __attribute__((unused)) void *parsed_result,
16735         __attribute__((unused)) struct cmdline *cl,
16736         __attribute__((unused)) void *data)
16737 {
16738 #ifdef RTE_LIBRTE_I40E_PMD
16739         struct cmd_cfg_input_set_result *res = parsed_result;
16740         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16741         struct rte_pmd_i40e_inset inset;
16742 #endif
16743         int ret = -ENOTSUP;
16744
16745         if (!all_ports_stopped()) {
16746                 printf("Please stop all ports first\n");
16747                 return;
16748         }
16749
16750 #ifdef RTE_LIBRTE_I40E_PMD
16751         if (!strcmp(res->inset_type, "hash_inset"))
16752                 inset_type = INSET_HASH;
16753         else if (!strcmp(res->inset_type, "fdir_inset"))
16754                 inset_type = INSET_FDIR;
16755         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16756                 inset_type = INSET_FDIR_FLX;
16757         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16758                                      &inset, inset_type);
16759         if (ret) {
16760                 printf("Failed to get input set.\n");
16761                 return;
16762         }
16763
16764         if (!strcmp(res->opt, "get")) {
16765                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16766                                                    res->field_idx);
16767                 if (ret)
16768                         printf("Field index %d is enabled.\n", res->field_idx);
16769                 else
16770                         printf("Field index %d is disabled.\n", res->field_idx);
16771                 return;
16772         } else if (!strcmp(res->opt, "set"))
16773                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16774                                                    res->field_idx);
16775         else if (!strcmp(res->opt, "clear"))
16776                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16777                                                      res->field_idx);
16778         if (ret) {
16779                 printf("Failed to configure input set field.\n");
16780                 return;
16781         }
16782
16783         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16784                                      &inset, inset_type);
16785         if (ret) {
16786                 printf("Failed to set input set.\n");
16787                 return;
16788         }
16789 #endif
16790
16791         if (ret == -ENOTSUP)
16792                 printf("Function not supported\n");
16793 }
16794
16795 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16796         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16797                                  port, "port");
16798 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16799         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16800                                  cfg, "config");
16801 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16802         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16803                               port_id, UINT16);
16804 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16805         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16806                                  pctype, "pctype");
16807 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16808         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16809                               pctype_id, UINT8);
16810 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16811         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16812                                  inset_type,
16813                                  "hash_inset#fdir_inset#fdir_flx_inset");
16814 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16815         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16816                                  opt, "get#set#clear");
16817 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16818         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16819                                  field, "field");
16820 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16821         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16822                               field_idx, UINT8);
16823
16824 cmdline_parse_inst_t cmd_cfg_input_set = {
16825         .f = cmd_cfg_input_set_parsed,
16826         .data = NULL,
16827         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16828                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16829         .tokens = {
16830                 (void *)&cmd_cfg_input_set_port,
16831                 (void *)&cmd_cfg_input_set_cfg,
16832                 (void *)&cmd_cfg_input_set_port_id,
16833                 (void *)&cmd_cfg_input_set_pctype,
16834                 (void *)&cmd_cfg_input_set_pctype_id,
16835                 (void *)&cmd_cfg_input_set_inset_type,
16836                 (void *)&cmd_cfg_input_set_opt,
16837                 (void *)&cmd_cfg_input_set_field,
16838                 (void *)&cmd_cfg_input_set_field_idx,
16839                 NULL,
16840         },
16841 };
16842
16843 /* Clear input set */
16844 struct cmd_clear_input_set_result {
16845         cmdline_fixed_string_t port;
16846         cmdline_fixed_string_t cfg;
16847         portid_t port_id;
16848         cmdline_fixed_string_t pctype;
16849         uint8_t pctype_id;
16850         cmdline_fixed_string_t inset_type;
16851         cmdline_fixed_string_t clear;
16852         cmdline_fixed_string_t all;
16853 };
16854
16855 static void
16856 cmd_clear_input_set_parsed(
16857         __attribute__((unused)) void *parsed_result,
16858         __attribute__((unused)) struct cmdline *cl,
16859         __attribute__((unused)) void *data)
16860 {
16861 #ifdef RTE_LIBRTE_I40E_PMD
16862         struct cmd_clear_input_set_result *res = parsed_result;
16863         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16864         struct rte_pmd_i40e_inset inset;
16865 #endif
16866         int ret = -ENOTSUP;
16867
16868         if (!all_ports_stopped()) {
16869                 printf("Please stop all ports first\n");
16870                 return;
16871         }
16872
16873 #ifdef RTE_LIBRTE_I40E_PMD
16874         if (!strcmp(res->inset_type, "hash_inset"))
16875                 inset_type = INSET_HASH;
16876         else if (!strcmp(res->inset_type, "fdir_inset"))
16877                 inset_type = INSET_FDIR;
16878         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16879                 inset_type = INSET_FDIR_FLX;
16880
16881         memset(&inset, 0, sizeof(inset));
16882
16883         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16884                                      &inset, inset_type);
16885         if (ret) {
16886                 printf("Failed to clear input set.\n");
16887                 return;
16888         }
16889
16890 #endif
16891
16892         if (ret == -ENOTSUP)
16893                 printf("Function not supported\n");
16894 }
16895
16896 cmdline_parse_token_string_t cmd_clear_input_set_port =
16897         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16898                                  port, "port");
16899 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16900         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16901                                  cfg, "config");
16902 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16903         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16904                               port_id, UINT16);
16905 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16906         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16907                                  pctype, "pctype");
16908 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16909         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16910                               pctype_id, UINT8);
16911 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16912         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16913                                  inset_type,
16914                                  "hash_inset#fdir_inset#fdir_flx_inset");
16915 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16916         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16917                                  clear, "clear");
16918 cmdline_parse_token_string_t cmd_clear_input_set_all =
16919         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16920                                  all, "all");
16921
16922 cmdline_parse_inst_t cmd_clear_input_set = {
16923         .f = cmd_clear_input_set_parsed,
16924         .data = NULL,
16925         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16926                     "fdir_inset|fdir_flx_inset clear all",
16927         .tokens = {
16928                 (void *)&cmd_clear_input_set_port,
16929                 (void *)&cmd_clear_input_set_cfg,
16930                 (void *)&cmd_clear_input_set_port_id,
16931                 (void *)&cmd_clear_input_set_pctype,
16932                 (void *)&cmd_clear_input_set_pctype_id,
16933                 (void *)&cmd_clear_input_set_inset_type,
16934                 (void *)&cmd_clear_input_set_clear,
16935                 (void *)&cmd_clear_input_set_all,
16936                 NULL,
16937         },
16938 };
16939
16940 /* show vf stats */
16941
16942 /* Common result structure for show vf stats */
16943 struct cmd_show_vf_stats_result {
16944         cmdline_fixed_string_t show;
16945         cmdline_fixed_string_t vf;
16946         cmdline_fixed_string_t stats;
16947         portid_t port_id;
16948         uint16_t vf_id;
16949 };
16950
16951 /* Common CLI fields show vf stats*/
16952 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16953         TOKEN_STRING_INITIALIZER
16954                 (struct cmd_show_vf_stats_result,
16955                  show, "show");
16956 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16957         TOKEN_STRING_INITIALIZER
16958                 (struct cmd_show_vf_stats_result,
16959                  vf, "vf");
16960 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16961         TOKEN_STRING_INITIALIZER
16962                 (struct cmd_show_vf_stats_result,
16963                  stats, "stats");
16964 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16965         TOKEN_NUM_INITIALIZER
16966                 (struct cmd_show_vf_stats_result,
16967                  port_id, UINT16);
16968 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16969         TOKEN_NUM_INITIALIZER
16970                 (struct cmd_show_vf_stats_result,
16971                  vf_id, UINT16);
16972
16973 static void
16974 cmd_show_vf_stats_parsed(
16975         void *parsed_result,
16976         __attribute__((unused)) struct cmdline *cl,
16977         __attribute__((unused)) void *data)
16978 {
16979         struct cmd_show_vf_stats_result *res = parsed_result;
16980         struct rte_eth_stats stats;
16981         int ret = -ENOTSUP;
16982         static const char *nic_stats_border = "########################";
16983
16984         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16985                 return;
16986
16987         memset(&stats, 0, sizeof(stats));
16988
16989 #ifdef RTE_LIBRTE_I40E_PMD
16990         if (ret == -ENOTSUP)
16991                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16992                                                 res->vf_id,
16993                                                 &stats);
16994 #endif
16995 #ifdef RTE_LIBRTE_BNXT_PMD
16996         if (ret == -ENOTSUP)
16997                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16998                                                 res->vf_id,
16999                                                 &stats);
17000 #endif
17001
17002         switch (ret) {
17003         case 0:
17004                 break;
17005         case -EINVAL:
17006                 printf("invalid vf_id %d\n", res->vf_id);
17007                 break;
17008         case -ENODEV:
17009                 printf("invalid port_id %d\n", res->port_id);
17010                 break;
17011         case -ENOTSUP:
17012                 printf("function not implemented\n");
17013                 break;
17014         default:
17015                 printf("programming error: (%s)\n", strerror(-ret));
17016         }
17017
17018         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17019                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17020
17021         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17022                "%-"PRIu64"\n",
17023                stats.ipackets, stats.imissed, stats.ibytes);
17024         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17025         printf("  RX-nombuf:  %-10"PRIu64"\n",
17026                stats.rx_nombuf);
17027         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17028                "%-"PRIu64"\n",
17029                stats.opackets, stats.oerrors, stats.obytes);
17030
17031         printf("  %s############################%s\n",
17032                                nic_stats_border, nic_stats_border);
17033 }
17034
17035 cmdline_parse_inst_t cmd_show_vf_stats = {
17036         .f = cmd_show_vf_stats_parsed,
17037         .data = NULL,
17038         .help_str = "show vf stats <port_id> <vf_id>",
17039         .tokens = {
17040                 (void *)&cmd_show_vf_stats_show,
17041                 (void *)&cmd_show_vf_stats_vf,
17042                 (void *)&cmd_show_vf_stats_stats,
17043                 (void *)&cmd_show_vf_stats_port_id,
17044                 (void *)&cmd_show_vf_stats_vf_id,
17045                 NULL,
17046         },
17047 };
17048
17049 /* clear vf stats */
17050
17051 /* Common result structure for clear vf stats */
17052 struct cmd_clear_vf_stats_result {
17053         cmdline_fixed_string_t clear;
17054         cmdline_fixed_string_t vf;
17055         cmdline_fixed_string_t stats;
17056         portid_t port_id;
17057         uint16_t vf_id;
17058 };
17059
17060 /* Common CLI fields clear vf stats*/
17061 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17062         TOKEN_STRING_INITIALIZER
17063                 (struct cmd_clear_vf_stats_result,
17064                  clear, "clear");
17065 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17066         TOKEN_STRING_INITIALIZER
17067                 (struct cmd_clear_vf_stats_result,
17068                  vf, "vf");
17069 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17070         TOKEN_STRING_INITIALIZER
17071                 (struct cmd_clear_vf_stats_result,
17072                  stats, "stats");
17073 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17074         TOKEN_NUM_INITIALIZER
17075                 (struct cmd_clear_vf_stats_result,
17076                  port_id, UINT16);
17077 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17078         TOKEN_NUM_INITIALIZER
17079                 (struct cmd_clear_vf_stats_result,
17080                  vf_id, UINT16);
17081
17082 static void
17083 cmd_clear_vf_stats_parsed(
17084         void *parsed_result,
17085         __attribute__((unused)) struct cmdline *cl,
17086         __attribute__((unused)) void *data)
17087 {
17088         struct cmd_clear_vf_stats_result *res = parsed_result;
17089         int ret = -ENOTSUP;
17090
17091         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17092                 return;
17093
17094 #ifdef RTE_LIBRTE_I40E_PMD
17095         if (ret == -ENOTSUP)
17096                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17097                                                   res->vf_id);
17098 #endif
17099 #ifdef RTE_LIBRTE_BNXT_PMD
17100         if (ret == -ENOTSUP)
17101                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17102                                                   res->vf_id);
17103 #endif
17104
17105         switch (ret) {
17106         case 0:
17107                 break;
17108         case -EINVAL:
17109                 printf("invalid vf_id %d\n", res->vf_id);
17110                 break;
17111         case -ENODEV:
17112                 printf("invalid port_id %d\n", res->port_id);
17113                 break;
17114         case -ENOTSUP:
17115                 printf("function not implemented\n");
17116                 break;
17117         default:
17118                 printf("programming error: (%s)\n", strerror(-ret));
17119         }
17120 }
17121
17122 cmdline_parse_inst_t cmd_clear_vf_stats = {
17123         .f = cmd_clear_vf_stats_parsed,
17124         .data = NULL,
17125         .help_str = "clear vf stats <port_id> <vf_id>",
17126         .tokens = {
17127                 (void *)&cmd_clear_vf_stats_clear,
17128                 (void *)&cmd_clear_vf_stats_vf,
17129                 (void *)&cmd_clear_vf_stats_stats,
17130                 (void *)&cmd_clear_vf_stats_port_id,
17131                 (void *)&cmd_clear_vf_stats_vf_id,
17132                 NULL,
17133         },
17134 };
17135
17136 /* port config pctype mapping reset */
17137
17138 /* Common result structure for port config pctype mapping reset */
17139 struct cmd_pctype_mapping_reset_result {
17140         cmdline_fixed_string_t port;
17141         cmdline_fixed_string_t config;
17142         portid_t port_id;
17143         cmdline_fixed_string_t pctype;
17144         cmdline_fixed_string_t mapping;
17145         cmdline_fixed_string_t reset;
17146 };
17147
17148 /* Common CLI fields for port config pctype mapping reset*/
17149 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17150         TOKEN_STRING_INITIALIZER
17151                 (struct cmd_pctype_mapping_reset_result,
17152                  port, "port");
17153 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17154         TOKEN_STRING_INITIALIZER
17155                 (struct cmd_pctype_mapping_reset_result,
17156                  config, "config");
17157 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17158         TOKEN_NUM_INITIALIZER
17159                 (struct cmd_pctype_mapping_reset_result,
17160                  port_id, UINT16);
17161 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17162         TOKEN_STRING_INITIALIZER
17163                 (struct cmd_pctype_mapping_reset_result,
17164                  pctype, "pctype");
17165 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17166         TOKEN_STRING_INITIALIZER
17167                 (struct cmd_pctype_mapping_reset_result,
17168                  mapping, "mapping");
17169 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17170         TOKEN_STRING_INITIALIZER
17171                 (struct cmd_pctype_mapping_reset_result,
17172                  reset, "reset");
17173
17174 static void
17175 cmd_pctype_mapping_reset_parsed(
17176         void *parsed_result,
17177         __attribute__((unused)) struct cmdline *cl,
17178         __attribute__((unused)) void *data)
17179 {
17180         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17181         int ret = -ENOTSUP;
17182
17183         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17184                 return;
17185
17186 #ifdef RTE_LIBRTE_I40E_PMD
17187         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17188 #endif
17189
17190         switch (ret) {
17191         case 0:
17192                 break;
17193         case -ENODEV:
17194                 printf("invalid port_id %d\n", res->port_id);
17195                 break;
17196         case -ENOTSUP:
17197                 printf("function not implemented\n");
17198                 break;
17199         default:
17200                 printf("programming error: (%s)\n", strerror(-ret));
17201         }
17202 }
17203
17204 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17205         .f = cmd_pctype_mapping_reset_parsed,
17206         .data = NULL,
17207         .help_str = "port config <port_id> pctype mapping reset",
17208         .tokens = {
17209                 (void *)&cmd_pctype_mapping_reset_port,
17210                 (void *)&cmd_pctype_mapping_reset_config,
17211                 (void *)&cmd_pctype_mapping_reset_port_id,
17212                 (void *)&cmd_pctype_mapping_reset_pctype,
17213                 (void *)&cmd_pctype_mapping_reset_mapping,
17214                 (void *)&cmd_pctype_mapping_reset_reset,
17215                 NULL,
17216         },
17217 };
17218
17219 /* show port pctype mapping */
17220
17221 /* Common result structure for show port pctype mapping */
17222 struct cmd_pctype_mapping_get_result {
17223         cmdline_fixed_string_t show;
17224         cmdline_fixed_string_t port;
17225         portid_t port_id;
17226         cmdline_fixed_string_t pctype;
17227         cmdline_fixed_string_t mapping;
17228 };
17229
17230 /* Common CLI fields for pctype mapping get */
17231 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17232         TOKEN_STRING_INITIALIZER
17233                 (struct cmd_pctype_mapping_get_result,
17234                  show, "show");
17235 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17236         TOKEN_STRING_INITIALIZER
17237                 (struct cmd_pctype_mapping_get_result,
17238                  port, "port");
17239 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17240         TOKEN_NUM_INITIALIZER
17241                 (struct cmd_pctype_mapping_get_result,
17242                  port_id, UINT16);
17243 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17244         TOKEN_STRING_INITIALIZER
17245                 (struct cmd_pctype_mapping_get_result,
17246                  pctype, "pctype");
17247 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17248         TOKEN_STRING_INITIALIZER
17249                 (struct cmd_pctype_mapping_get_result,
17250                  mapping, "mapping");
17251
17252 static void
17253 cmd_pctype_mapping_get_parsed(
17254         void *parsed_result,
17255         __attribute__((unused)) struct cmdline *cl,
17256         __attribute__((unused)) void *data)
17257 {
17258         struct cmd_pctype_mapping_get_result *res = parsed_result;
17259         int ret = -ENOTSUP;
17260 #ifdef RTE_LIBRTE_I40E_PMD
17261         struct rte_pmd_i40e_flow_type_mapping
17262                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17263         int i, j, first_pctype;
17264 #endif
17265
17266         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17267                 return;
17268
17269 #ifdef RTE_LIBRTE_I40E_PMD
17270         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17271 #endif
17272
17273         switch (ret) {
17274         case 0:
17275                 break;
17276         case -ENODEV:
17277                 printf("invalid port_id %d\n", res->port_id);
17278                 return;
17279         case -ENOTSUP:
17280                 printf("function not implemented\n");
17281                 return;
17282         default:
17283                 printf("programming error: (%s)\n", strerror(-ret));
17284                 return;
17285         }
17286
17287 #ifdef RTE_LIBRTE_I40E_PMD
17288         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17289                 if (mapping[i].pctype != 0ULL) {
17290                         first_pctype = 1;
17291
17292                         printf("pctype: ");
17293                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17294                                 if (mapping[i].pctype & (1ULL << j)) {
17295                                         printf(first_pctype ?
17296                                                "%02d" : ",%02d", j);
17297                                         first_pctype = 0;
17298                                 }
17299                         }
17300                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17301                 }
17302         }
17303 #endif
17304 }
17305
17306 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17307         .f = cmd_pctype_mapping_get_parsed,
17308         .data = NULL,
17309         .help_str = "show port <port_id> pctype mapping",
17310         .tokens = {
17311                 (void *)&cmd_pctype_mapping_get_show,
17312                 (void *)&cmd_pctype_mapping_get_port,
17313                 (void *)&cmd_pctype_mapping_get_port_id,
17314                 (void *)&cmd_pctype_mapping_get_pctype,
17315                 (void *)&cmd_pctype_mapping_get_mapping,
17316                 NULL,
17317         },
17318 };
17319
17320 /* port config pctype mapping update */
17321
17322 /* Common result structure for port config pctype mapping update */
17323 struct cmd_pctype_mapping_update_result {
17324         cmdline_fixed_string_t port;
17325         cmdline_fixed_string_t config;
17326         portid_t port_id;
17327         cmdline_fixed_string_t pctype;
17328         cmdline_fixed_string_t mapping;
17329         cmdline_fixed_string_t update;
17330         cmdline_fixed_string_t pctype_list;
17331         uint16_t flow_type;
17332 };
17333
17334 /* Common CLI fields for pctype mapping update*/
17335 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17336         TOKEN_STRING_INITIALIZER
17337                 (struct cmd_pctype_mapping_update_result,
17338                  port, "port");
17339 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17340         TOKEN_STRING_INITIALIZER
17341                 (struct cmd_pctype_mapping_update_result,
17342                  config, "config");
17343 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17344         TOKEN_NUM_INITIALIZER
17345                 (struct cmd_pctype_mapping_update_result,
17346                  port_id, UINT16);
17347 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17348         TOKEN_STRING_INITIALIZER
17349                 (struct cmd_pctype_mapping_update_result,
17350                  pctype, "pctype");
17351 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17352         TOKEN_STRING_INITIALIZER
17353                 (struct cmd_pctype_mapping_update_result,
17354                  mapping, "mapping");
17355 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17356         TOKEN_STRING_INITIALIZER
17357                 (struct cmd_pctype_mapping_update_result,
17358                  update, "update");
17359 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17360         TOKEN_STRING_INITIALIZER
17361                 (struct cmd_pctype_mapping_update_result,
17362                  pctype_list, NULL);
17363 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17364         TOKEN_NUM_INITIALIZER
17365                 (struct cmd_pctype_mapping_update_result,
17366                  flow_type, UINT16);
17367
17368 static void
17369 cmd_pctype_mapping_update_parsed(
17370         void *parsed_result,
17371         __attribute__((unused)) struct cmdline *cl,
17372         __attribute__((unused)) void *data)
17373 {
17374         struct cmd_pctype_mapping_update_result *res = parsed_result;
17375         int ret = -ENOTSUP;
17376 #ifdef RTE_LIBRTE_I40E_PMD
17377         struct rte_pmd_i40e_flow_type_mapping mapping;
17378         unsigned int i;
17379         unsigned int nb_item;
17380         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17381 #endif
17382
17383         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17384                 return;
17385
17386 #ifdef RTE_LIBRTE_I40E_PMD
17387         nb_item = parse_item_list(res->pctype_list, "pctypes",
17388                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17389         mapping.flow_type = res->flow_type;
17390         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17391                 mapping.pctype |= (1ULL << pctype_list[i]);
17392         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17393                                                 &mapping,
17394                                                 1,
17395                                                 0);
17396 #endif
17397
17398         switch (ret) {
17399         case 0:
17400                 break;
17401         case -EINVAL:
17402                 printf("invalid pctype or flow type\n");
17403                 break;
17404         case -ENODEV:
17405                 printf("invalid port_id %d\n", res->port_id);
17406                 break;
17407         case -ENOTSUP:
17408                 printf("function not implemented\n");
17409                 break;
17410         default:
17411                 printf("programming error: (%s)\n", strerror(-ret));
17412         }
17413 }
17414
17415 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17416         .f = cmd_pctype_mapping_update_parsed,
17417         .data = NULL,
17418         .help_str = "port config <port_id> pctype mapping update"
17419         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17420         .tokens = {
17421                 (void *)&cmd_pctype_mapping_update_port,
17422                 (void *)&cmd_pctype_mapping_update_config,
17423                 (void *)&cmd_pctype_mapping_update_port_id,
17424                 (void *)&cmd_pctype_mapping_update_pctype,
17425                 (void *)&cmd_pctype_mapping_update_mapping,
17426                 (void *)&cmd_pctype_mapping_update_update,
17427                 (void *)&cmd_pctype_mapping_update_pc_type,
17428                 (void *)&cmd_pctype_mapping_update_flow_type,
17429                 NULL,
17430         },
17431 };
17432
17433 /* ptype mapping get */
17434
17435 /* Common result structure for ptype mapping get */
17436 struct cmd_ptype_mapping_get_result {
17437         cmdline_fixed_string_t ptype;
17438         cmdline_fixed_string_t mapping;
17439         cmdline_fixed_string_t get;
17440         portid_t port_id;
17441         uint8_t valid_only;
17442 };
17443
17444 /* Common CLI fields for ptype mapping get */
17445 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17446         TOKEN_STRING_INITIALIZER
17447                 (struct cmd_ptype_mapping_get_result,
17448                  ptype, "ptype");
17449 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17450         TOKEN_STRING_INITIALIZER
17451                 (struct cmd_ptype_mapping_get_result,
17452                  mapping, "mapping");
17453 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17454         TOKEN_STRING_INITIALIZER
17455                 (struct cmd_ptype_mapping_get_result,
17456                  get, "get");
17457 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17458         TOKEN_NUM_INITIALIZER
17459                 (struct cmd_ptype_mapping_get_result,
17460                  port_id, UINT16);
17461 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17462         TOKEN_NUM_INITIALIZER
17463                 (struct cmd_ptype_mapping_get_result,
17464                  valid_only, UINT8);
17465
17466 static void
17467 cmd_ptype_mapping_get_parsed(
17468         void *parsed_result,
17469         __attribute__((unused)) struct cmdline *cl,
17470         __attribute__((unused)) void *data)
17471 {
17472         struct cmd_ptype_mapping_get_result *res = parsed_result;
17473         int ret = -ENOTSUP;
17474 #ifdef RTE_LIBRTE_I40E_PMD
17475         int max_ptype_num = 256;
17476         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17477         uint16_t count;
17478         int i;
17479 #endif
17480
17481         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17482                 return;
17483
17484 #ifdef RTE_LIBRTE_I40E_PMD
17485         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17486                                         mapping,
17487                                         max_ptype_num,
17488                                         &count,
17489                                         res->valid_only);
17490 #endif
17491
17492         switch (ret) {
17493         case 0:
17494                 break;
17495         case -ENODEV:
17496                 printf("invalid port_id %d\n", res->port_id);
17497                 break;
17498         case -ENOTSUP:
17499                 printf("function not implemented\n");
17500                 break;
17501         default:
17502                 printf("programming error: (%s)\n", strerror(-ret));
17503         }
17504
17505 #ifdef RTE_LIBRTE_I40E_PMD
17506         if (!ret) {
17507                 for (i = 0; i < count; i++)
17508                         printf("%3d\t0x%08x\n",
17509                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17510         }
17511 #endif
17512 }
17513
17514 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17515         .f = cmd_ptype_mapping_get_parsed,
17516         .data = NULL,
17517         .help_str = "ptype mapping get <port_id> <valid_only>",
17518         .tokens = {
17519                 (void *)&cmd_ptype_mapping_get_ptype,
17520                 (void *)&cmd_ptype_mapping_get_mapping,
17521                 (void *)&cmd_ptype_mapping_get_get,
17522                 (void *)&cmd_ptype_mapping_get_port_id,
17523                 (void *)&cmd_ptype_mapping_get_valid_only,
17524                 NULL,
17525         },
17526 };
17527
17528 /* ptype mapping replace */
17529
17530 /* Common result structure for ptype mapping replace */
17531 struct cmd_ptype_mapping_replace_result {
17532         cmdline_fixed_string_t ptype;
17533         cmdline_fixed_string_t mapping;
17534         cmdline_fixed_string_t replace;
17535         portid_t port_id;
17536         uint32_t target;
17537         uint8_t mask;
17538         uint32_t pkt_type;
17539 };
17540
17541 /* Common CLI fields for ptype mapping replace */
17542 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17543         TOKEN_STRING_INITIALIZER
17544                 (struct cmd_ptype_mapping_replace_result,
17545                  ptype, "ptype");
17546 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17547         TOKEN_STRING_INITIALIZER
17548                 (struct cmd_ptype_mapping_replace_result,
17549                  mapping, "mapping");
17550 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17551         TOKEN_STRING_INITIALIZER
17552                 (struct cmd_ptype_mapping_replace_result,
17553                  replace, "replace");
17554 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17555         TOKEN_NUM_INITIALIZER
17556                 (struct cmd_ptype_mapping_replace_result,
17557                  port_id, UINT16);
17558 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17559         TOKEN_NUM_INITIALIZER
17560                 (struct cmd_ptype_mapping_replace_result,
17561                  target, UINT32);
17562 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17563         TOKEN_NUM_INITIALIZER
17564                 (struct cmd_ptype_mapping_replace_result,
17565                  mask, UINT8);
17566 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17567         TOKEN_NUM_INITIALIZER
17568                 (struct cmd_ptype_mapping_replace_result,
17569                  pkt_type, UINT32);
17570
17571 static void
17572 cmd_ptype_mapping_replace_parsed(
17573         void *parsed_result,
17574         __attribute__((unused)) struct cmdline *cl,
17575         __attribute__((unused)) void *data)
17576 {
17577         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17578         int ret = -ENOTSUP;
17579
17580         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17581                 return;
17582
17583 #ifdef RTE_LIBRTE_I40E_PMD
17584         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17585                                         res->target,
17586                                         res->mask,
17587                                         res->pkt_type);
17588 #endif
17589
17590         switch (ret) {
17591         case 0:
17592                 break;
17593         case -EINVAL:
17594                 printf("invalid ptype 0x%8x or 0x%8x\n",
17595                                 res->target, res->pkt_type);
17596                 break;
17597         case -ENODEV:
17598                 printf("invalid port_id %d\n", res->port_id);
17599                 break;
17600         case -ENOTSUP:
17601                 printf("function not implemented\n");
17602                 break;
17603         default:
17604                 printf("programming error: (%s)\n", strerror(-ret));
17605         }
17606 }
17607
17608 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17609         .f = cmd_ptype_mapping_replace_parsed,
17610         .data = NULL,
17611         .help_str =
17612                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17613         .tokens = {
17614                 (void *)&cmd_ptype_mapping_replace_ptype,
17615                 (void *)&cmd_ptype_mapping_replace_mapping,
17616                 (void *)&cmd_ptype_mapping_replace_replace,
17617                 (void *)&cmd_ptype_mapping_replace_port_id,
17618                 (void *)&cmd_ptype_mapping_replace_target,
17619                 (void *)&cmd_ptype_mapping_replace_mask,
17620                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17621                 NULL,
17622         },
17623 };
17624
17625 /* ptype mapping reset */
17626
17627 /* Common result structure for ptype mapping reset */
17628 struct cmd_ptype_mapping_reset_result {
17629         cmdline_fixed_string_t ptype;
17630         cmdline_fixed_string_t mapping;
17631         cmdline_fixed_string_t reset;
17632         portid_t port_id;
17633 };
17634
17635 /* Common CLI fields for ptype mapping reset*/
17636 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17637         TOKEN_STRING_INITIALIZER
17638                 (struct cmd_ptype_mapping_reset_result,
17639                  ptype, "ptype");
17640 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17641         TOKEN_STRING_INITIALIZER
17642                 (struct cmd_ptype_mapping_reset_result,
17643                  mapping, "mapping");
17644 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17645         TOKEN_STRING_INITIALIZER
17646                 (struct cmd_ptype_mapping_reset_result,
17647                  reset, "reset");
17648 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17649         TOKEN_NUM_INITIALIZER
17650                 (struct cmd_ptype_mapping_reset_result,
17651                  port_id, UINT16);
17652
17653 static void
17654 cmd_ptype_mapping_reset_parsed(
17655         void *parsed_result,
17656         __attribute__((unused)) struct cmdline *cl,
17657         __attribute__((unused)) void *data)
17658 {
17659         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17660         int ret = -ENOTSUP;
17661
17662         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17663                 return;
17664
17665 #ifdef RTE_LIBRTE_I40E_PMD
17666         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17667 #endif
17668
17669         switch (ret) {
17670         case 0:
17671                 break;
17672         case -ENODEV:
17673                 printf("invalid port_id %d\n", res->port_id);
17674                 break;
17675         case -ENOTSUP:
17676                 printf("function not implemented\n");
17677                 break;
17678         default:
17679                 printf("programming error: (%s)\n", strerror(-ret));
17680         }
17681 }
17682
17683 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17684         .f = cmd_ptype_mapping_reset_parsed,
17685         .data = NULL,
17686         .help_str = "ptype mapping reset <port_id>",
17687         .tokens = {
17688                 (void *)&cmd_ptype_mapping_reset_ptype,
17689                 (void *)&cmd_ptype_mapping_reset_mapping,
17690                 (void *)&cmd_ptype_mapping_reset_reset,
17691                 (void *)&cmd_ptype_mapping_reset_port_id,
17692                 NULL,
17693         },
17694 };
17695
17696 /* ptype mapping update */
17697
17698 /* Common result structure for ptype mapping update */
17699 struct cmd_ptype_mapping_update_result {
17700         cmdline_fixed_string_t ptype;
17701         cmdline_fixed_string_t mapping;
17702         cmdline_fixed_string_t reset;
17703         portid_t port_id;
17704         uint8_t hw_ptype;
17705         uint32_t sw_ptype;
17706 };
17707
17708 /* Common CLI fields for ptype mapping update*/
17709 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17710         TOKEN_STRING_INITIALIZER
17711                 (struct cmd_ptype_mapping_update_result,
17712                  ptype, "ptype");
17713 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17714         TOKEN_STRING_INITIALIZER
17715                 (struct cmd_ptype_mapping_update_result,
17716                  mapping, "mapping");
17717 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17718         TOKEN_STRING_INITIALIZER
17719                 (struct cmd_ptype_mapping_update_result,
17720                  reset, "update");
17721 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17722         TOKEN_NUM_INITIALIZER
17723                 (struct cmd_ptype_mapping_update_result,
17724                  port_id, UINT16);
17725 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17726         TOKEN_NUM_INITIALIZER
17727                 (struct cmd_ptype_mapping_update_result,
17728                  hw_ptype, UINT8);
17729 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17730         TOKEN_NUM_INITIALIZER
17731                 (struct cmd_ptype_mapping_update_result,
17732                  sw_ptype, UINT32);
17733
17734 static void
17735 cmd_ptype_mapping_update_parsed(
17736         void *parsed_result,
17737         __attribute__((unused)) struct cmdline *cl,
17738         __attribute__((unused)) void *data)
17739 {
17740         struct cmd_ptype_mapping_update_result *res = parsed_result;
17741         int ret = -ENOTSUP;
17742 #ifdef RTE_LIBRTE_I40E_PMD
17743         struct rte_pmd_i40e_ptype_mapping mapping;
17744 #endif
17745         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17746                 return;
17747
17748 #ifdef RTE_LIBRTE_I40E_PMD
17749         mapping.hw_ptype = res->hw_ptype;
17750         mapping.sw_ptype = res->sw_ptype;
17751         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17752                                                 &mapping,
17753                                                 1,
17754                                                 0);
17755 #endif
17756
17757         switch (ret) {
17758         case 0:
17759                 break;
17760         case -EINVAL:
17761                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17762                 break;
17763         case -ENODEV:
17764                 printf("invalid port_id %d\n", res->port_id);
17765                 break;
17766         case -ENOTSUP:
17767                 printf("function not implemented\n");
17768                 break;
17769         default:
17770                 printf("programming error: (%s)\n", strerror(-ret));
17771         }
17772 }
17773
17774 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17775         .f = cmd_ptype_mapping_update_parsed,
17776         .data = NULL,
17777         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17778         .tokens = {
17779                 (void *)&cmd_ptype_mapping_update_ptype,
17780                 (void *)&cmd_ptype_mapping_update_mapping,
17781                 (void *)&cmd_ptype_mapping_update_update,
17782                 (void *)&cmd_ptype_mapping_update_port_id,
17783                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17784                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17785                 NULL,
17786         },
17787 };
17788
17789 /* Common result structure for file commands */
17790 struct cmd_cmdfile_result {
17791         cmdline_fixed_string_t load;
17792         cmdline_fixed_string_t filename;
17793 };
17794
17795 /* Common CLI fields for file commands */
17796 cmdline_parse_token_string_t cmd_load_cmdfile =
17797         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17798 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17799         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17800
17801 static void
17802 cmd_load_from_file_parsed(
17803         void *parsed_result,
17804         __attribute__((unused)) struct cmdline *cl,
17805         __attribute__((unused)) void *data)
17806 {
17807         struct cmd_cmdfile_result *res = parsed_result;
17808
17809         cmdline_read_from_file(res->filename);
17810 }
17811
17812 cmdline_parse_inst_t cmd_load_from_file = {
17813         .f = cmd_load_from_file_parsed,
17814         .data = NULL,
17815         .help_str = "load <filename>",
17816         .tokens = {
17817                 (void *)&cmd_load_cmdfile,
17818                 (void *)&cmd_load_cmdfile_filename,
17819                 NULL,
17820         },
17821 };
17822
17823 /* Get Rx offloads capabilities */
17824 struct cmd_rx_offload_get_capa_result {
17825         cmdline_fixed_string_t show;
17826         cmdline_fixed_string_t port;
17827         portid_t port_id;
17828         cmdline_fixed_string_t rx_offload;
17829         cmdline_fixed_string_t capabilities;
17830 };
17831
17832 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17833         TOKEN_STRING_INITIALIZER
17834                 (struct cmd_rx_offload_get_capa_result,
17835                  show, "show");
17836 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17837         TOKEN_STRING_INITIALIZER
17838                 (struct cmd_rx_offload_get_capa_result,
17839                  port, "port");
17840 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17841         TOKEN_NUM_INITIALIZER
17842                 (struct cmd_rx_offload_get_capa_result,
17843                  port_id, UINT16);
17844 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17845         TOKEN_STRING_INITIALIZER
17846                 (struct cmd_rx_offload_get_capa_result,
17847                  rx_offload, "rx_offload");
17848 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17849         TOKEN_STRING_INITIALIZER
17850                 (struct cmd_rx_offload_get_capa_result,
17851                  capabilities, "capabilities");
17852
17853 static void
17854 print_rx_offloads(uint64_t offloads)
17855 {
17856         uint64_t single_offload;
17857         int begin;
17858         int end;
17859         int bit;
17860
17861         if (offloads == 0)
17862                 return;
17863
17864         begin = __builtin_ctzll(offloads);
17865         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17866
17867         single_offload = 1ULL << begin;
17868         for (bit = begin; bit < end; bit++) {
17869                 if (offloads & single_offload)
17870                         printf(" %s",
17871                                rte_eth_dev_rx_offload_name(single_offload));
17872                 single_offload <<= 1;
17873         }
17874 }
17875
17876 static void
17877 cmd_rx_offload_get_capa_parsed(
17878         void *parsed_result,
17879         __attribute__((unused)) struct cmdline *cl,
17880         __attribute__((unused)) void *data)
17881 {
17882         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17883         struct rte_eth_dev_info dev_info;
17884         portid_t port_id = res->port_id;
17885         uint64_t queue_offloads;
17886         uint64_t port_offloads;
17887
17888         rte_eth_dev_info_get(port_id, &dev_info);
17889         queue_offloads = dev_info.rx_queue_offload_capa;
17890         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17891
17892         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17893         printf("  Per Queue :");
17894         print_rx_offloads(queue_offloads);
17895
17896         printf("\n");
17897         printf("  Per Port  :");
17898         print_rx_offloads(port_offloads);
17899         printf("\n\n");
17900 }
17901
17902 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17903         .f = cmd_rx_offload_get_capa_parsed,
17904         .data = NULL,
17905         .help_str = "show port <port_id> rx_offload capabilities",
17906         .tokens = {
17907                 (void *)&cmd_rx_offload_get_capa_show,
17908                 (void *)&cmd_rx_offload_get_capa_port,
17909                 (void *)&cmd_rx_offload_get_capa_port_id,
17910                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17911                 (void *)&cmd_rx_offload_get_capa_capabilities,
17912                 NULL,
17913         }
17914 };
17915
17916 /* Get Rx offloads configuration */
17917 struct cmd_rx_offload_get_configuration_result {
17918         cmdline_fixed_string_t show;
17919         cmdline_fixed_string_t port;
17920         portid_t port_id;
17921         cmdline_fixed_string_t rx_offload;
17922         cmdline_fixed_string_t configuration;
17923 };
17924
17925 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17926         TOKEN_STRING_INITIALIZER
17927                 (struct cmd_rx_offload_get_configuration_result,
17928                  show, "show");
17929 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17930         TOKEN_STRING_INITIALIZER
17931                 (struct cmd_rx_offload_get_configuration_result,
17932                  port, "port");
17933 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17934         TOKEN_NUM_INITIALIZER
17935                 (struct cmd_rx_offload_get_configuration_result,
17936                  port_id, UINT16);
17937 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17938         TOKEN_STRING_INITIALIZER
17939                 (struct cmd_rx_offload_get_configuration_result,
17940                  rx_offload, "rx_offload");
17941 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17942         TOKEN_STRING_INITIALIZER
17943                 (struct cmd_rx_offload_get_configuration_result,
17944                  configuration, "configuration");
17945
17946 static void
17947 cmd_rx_offload_get_configuration_parsed(
17948         void *parsed_result,
17949         __attribute__((unused)) struct cmdline *cl,
17950         __attribute__((unused)) void *data)
17951 {
17952         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17953         struct rte_eth_dev_info dev_info;
17954         portid_t port_id = res->port_id;
17955         struct rte_port *port = &ports[port_id];
17956         uint64_t port_offloads;
17957         uint64_t queue_offloads;
17958         uint16_t nb_rx_queues;
17959         int q;
17960
17961         printf("Rx Offloading Configuration of port %d :\n", port_id);
17962
17963         port_offloads = port->dev_conf.rxmode.offloads;
17964         printf("  Port :");
17965         print_rx_offloads(port_offloads);
17966         printf("\n");
17967
17968         rte_eth_dev_info_get(port_id, &dev_info);
17969         nb_rx_queues = dev_info.nb_rx_queues;
17970         for (q = 0; q < nb_rx_queues; q++) {
17971                 queue_offloads = port->rx_conf[q].offloads;
17972                 printf("  Queue[%2d] :", q);
17973                 print_rx_offloads(queue_offloads);
17974                 printf("\n");
17975         }
17976         printf("\n");
17977 }
17978
17979 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17980         .f = cmd_rx_offload_get_configuration_parsed,
17981         .data = NULL,
17982         .help_str = "show port <port_id> rx_offload configuration",
17983         .tokens = {
17984                 (void *)&cmd_rx_offload_get_configuration_show,
17985                 (void *)&cmd_rx_offload_get_configuration_port,
17986                 (void *)&cmd_rx_offload_get_configuration_port_id,
17987                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17988                 (void *)&cmd_rx_offload_get_configuration_configuration,
17989                 NULL,
17990         }
17991 };
17992
17993 /* Enable/Disable a per port offloading */
17994 struct cmd_config_per_port_rx_offload_result {
17995         cmdline_fixed_string_t port;
17996         cmdline_fixed_string_t config;
17997         portid_t port_id;
17998         cmdline_fixed_string_t rx_offload;
17999         cmdline_fixed_string_t offload;
18000         cmdline_fixed_string_t on_off;
18001 };
18002
18003 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18004         TOKEN_STRING_INITIALIZER
18005                 (struct cmd_config_per_port_rx_offload_result,
18006                  port, "port");
18007 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18008         TOKEN_STRING_INITIALIZER
18009                 (struct cmd_config_per_port_rx_offload_result,
18010                  config, "config");
18011 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18012         TOKEN_NUM_INITIALIZER
18013                 (struct cmd_config_per_port_rx_offload_result,
18014                  port_id, UINT16);
18015 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18016         TOKEN_STRING_INITIALIZER
18017                 (struct cmd_config_per_port_rx_offload_result,
18018                  rx_offload, "rx_offload");
18019 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18020         TOKEN_STRING_INITIALIZER
18021                 (struct cmd_config_per_port_rx_offload_result,
18022                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18023                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18024                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18025                            "crc_strip#scatter#timestamp#security#keep_crc");
18026 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18027         TOKEN_STRING_INITIALIZER
18028                 (struct cmd_config_per_port_rx_offload_result,
18029                  on_off, "on#off");
18030
18031 static uint64_t
18032 search_rx_offload(const char *name)
18033 {
18034         uint64_t single_offload;
18035         const char *single_name;
18036         int found = 0;
18037         unsigned int bit;
18038
18039         single_offload = 1;
18040         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18041                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18042                 if (!strcasecmp(single_name, name)) {
18043                         found = 1;
18044                         break;
18045                 }
18046                 single_offload <<= 1;
18047         }
18048
18049         if (found)
18050                 return single_offload;
18051
18052         return 0;
18053 }
18054
18055 static void
18056 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18057                                 __attribute__((unused)) struct cmdline *cl,
18058                                 __attribute__((unused)) void *data)
18059 {
18060         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18061         portid_t port_id = res->port_id;
18062         struct rte_eth_dev_info dev_info;
18063         struct rte_port *port = &ports[port_id];
18064         uint64_t single_offload;
18065         uint16_t nb_rx_queues;
18066         int q;
18067
18068         if (port->port_status != RTE_PORT_STOPPED) {
18069                 printf("Error: Can't config offload when Port %d "
18070                        "is not stopped\n", port_id);
18071                 return;
18072         }
18073
18074         single_offload = search_rx_offload(res->offload);
18075         if (single_offload == 0) {
18076                 printf("Unknown offload name: %s\n", res->offload);
18077                 return;
18078         }
18079
18080         rte_eth_dev_info_get(port_id, &dev_info);
18081         nb_rx_queues = dev_info.nb_rx_queues;
18082         if (!strcmp(res->on_off, "on")) {
18083                 port->dev_conf.rxmode.offloads |= single_offload;
18084                 for (q = 0; q < nb_rx_queues; q++)
18085                         port->rx_conf[q].offloads |= single_offload;
18086         } else {
18087                 port->dev_conf.rxmode.offloads &= ~single_offload;
18088                 for (q = 0; q < nb_rx_queues; q++)
18089                         port->rx_conf[q].offloads &= ~single_offload;
18090         }
18091
18092         cmd_reconfig_device_queue(port_id, 1, 1);
18093 }
18094
18095 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18096         .f = cmd_config_per_port_rx_offload_parsed,
18097         .data = NULL,
18098         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18099                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18100                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18101                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18102                     "on|off",
18103         .tokens = {
18104                 (void *)&cmd_config_per_port_rx_offload_result_port,
18105                 (void *)&cmd_config_per_port_rx_offload_result_config,
18106                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18107                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18108                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18109                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18110                 NULL,
18111         }
18112 };
18113
18114 /* Enable/Disable a per queue offloading */
18115 struct cmd_config_per_queue_rx_offload_result {
18116         cmdline_fixed_string_t port;
18117         portid_t port_id;
18118         cmdline_fixed_string_t rxq;
18119         uint16_t queue_id;
18120         cmdline_fixed_string_t rx_offload;
18121         cmdline_fixed_string_t offload;
18122         cmdline_fixed_string_t on_off;
18123 };
18124
18125 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18126         TOKEN_STRING_INITIALIZER
18127                 (struct cmd_config_per_queue_rx_offload_result,
18128                  port, "port");
18129 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18130         TOKEN_NUM_INITIALIZER
18131                 (struct cmd_config_per_queue_rx_offload_result,
18132                  port_id, UINT16);
18133 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18134         TOKEN_STRING_INITIALIZER
18135                 (struct cmd_config_per_queue_rx_offload_result,
18136                  rxq, "rxq");
18137 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18138         TOKEN_NUM_INITIALIZER
18139                 (struct cmd_config_per_queue_rx_offload_result,
18140                  queue_id, UINT16);
18141 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18142         TOKEN_STRING_INITIALIZER
18143                 (struct cmd_config_per_queue_rx_offload_result,
18144                  rx_offload, "rx_offload");
18145 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18146         TOKEN_STRING_INITIALIZER
18147                 (struct cmd_config_per_queue_rx_offload_result,
18148                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18149                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18150                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18151                            "crc_strip#scatter#timestamp#security#keep_crc");
18152 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18153         TOKEN_STRING_INITIALIZER
18154                 (struct cmd_config_per_queue_rx_offload_result,
18155                  on_off, "on#off");
18156
18157 static void
18158 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18159                                 __attribute__((unused)) struct cmdline *cl,
18160                                 __attribute__((unused)) void *data)
18161 {
18162         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18163         struct rte_eth_dev_info dev_info;
18164         portid_t port_id = res->port_id;
18165         uint16_t queue_id = res->queue_id;
18166         struct rte_port *port = &ports[port_id];
18167         uint64_t single_offload;
18168
18169         if (port->port_status != RTE_PORT_STOPPED) {
18170                 printf("Error: Can't config offload when Port %d "
18171                        "is not stopped\n", port_id);
18172                 return;
18173         }
18174
18175         rte_eth_dev_info_get(port_id, &dev_info);
18176         if (queue_id >= dev_info.nb_rx_queues) {
18177                 printf("Error: input queue_id should be 0 ... "
18178                        "%d\n", dev_info.nb_rx_queues - 1);
18179                 return;
18180         }
18181
18182         single_offload = search_rx_offload(res->offload);
18183         if (single_offload == 0) {
18184                 printf("Unknown offload name: %s\n", res->offload);
18185                 return;
18186         }
18187
18188         if (!strcmp(res->on_off, "on"))
18189                 port->rx_conf[queue_id].offloads |= single_offload;
18190         else
18191                 port->rx_conf[queue_id].offloads &= ~single_offload;
18192
18193         cmd_reconfig_device_queue(port_id, 1, 1);
18194 }
18195
18196 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18197         .f = cmd_config_per_queue_rx_offload_parsed,
18198         .data = NULL,
18199         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18200                     "vlan_strip|ipv4_cksum|"
18201                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18202                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18203                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18204                     "on|off",
18205         .tokens = {
18206                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18207                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18208                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18209                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18210                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18211                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18212                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18213                 NULL,
18214         }
18215 };
18216
18217 /* Get Tx offloads capabilities */
18218 struct cmd_tx_offload_get_capa_result {
18219         cmdline_fixed_string_t show;
18220         cmdline_fixed_string_t port;
18221         portid_t port_id;
18222         cmdline_fixed_string_t tx_offload;
18223         cmdline_fixed_string_t capabilities;
18224 };
18225
18226 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18227         TOKEN_STRING_INITIALIZER
18228                 (struct cmd_tx_offload_get_capa_result,
18229                  show, "show");
18230 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18231         TOKEN_STRING_INITIALIZER
18232                 (struct cmd_tx_offload_get_capa_result,
18233                  port, "port");
18234 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18235         TOKEN_NUM_INITIALIZER
18236                 (struct cmd_tx_offload_get_capa_result,
18237                  port_id, UINT16);
18238 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18239         TOKEN_STRING_INITIALIZER
18240                 (struct cmd_tx_offload_get_capa_result,
18241                  tx_offload, "tx_offload");
18242 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18243         TOKEN_STRING_INITIALIZER
18244                 (struct cmd_tx_offload_get_capa_result,
18245                  capabilities, "capabilities");
18246
18247 static void
18248 print_tx_offloads(uint64_t offloads)
18249 {
18250         uint64_t single_offload;
18251         int begin;
18252         int end;
18253         int bit;
18254
18255         if (offloads == 0)
18256                 return;
18257
18258         begin = __builtin_ctzll(offloads);
18259         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18260
18261         single_offload = 1ULL << begin;
18262         for (bit = begin; bit < end; bit++) {
18263                 if (offloads & single_offload)
18264                         printf(" %s",
18265                                rte_eth_dev_tx_offload_name(single_offload));
18266                 single_offload <<= 1;
18267         }
18268 }
18269
18270 static void
18271 cmd_tx_offload_get_capa_parsed(
18272         void *parsed_result,
18273         __attribute__((unused)) struct cmdline *cl,
18274         __attribute__((unused)) void *data)
18275 {
18276         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18277         struct rte_eth_dev_info dev_info;
18278         portid_t port_id = res->port_id;
18279         uint64_t queue_offloads;
18280         uint64_t port_offloads;
18281
18282         rte_eth_dev_info_get(port_id, &dev_info);
18283         queue_offloads = dev_info.tx_queue_offload_capa;
18284         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18285
18286         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18287         printf("  Per Queue :");
18288         print_tx_offloads(queue_offloads);
18289
18290         printf("\n");
18291         printf("  Per Port  :");
18292         print_tx_offloads(port_offloads);
18293         printf("\n\n");
18294 }
18295
18296 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18297         .f = cmd_tx_offload_get_capa_parsed,
18298         .data = NULL,
18299         .help_str = "show port <port_id> tx_offload capabilities",
18300         .tokens = {
18301                 (void *)&cmd_tx_offload_get_capa_show,
18302                 (void *)&cmd_tx_offload_get_capa_port,
18303                 (void *)&cmd_tx_offload_get_capa_port_id,
18304                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18305                 (void *)&cmd_tx_offload_get_capa_capabilities,
18306                 NULL,
18307         }
18308 };
18309
18310 /* Get Tx offloads configuration */
18311 struct cmd_tx_offload_get_configuration_result {
18312         cmdline_fixed_string_t show;
18313         cmdline_fixed_string_t port;
18314         portid_t port_id;
18315         cmdline_fixed_string_t tx_offload;
18316         cmdline_fixed_string_t configuration;
18317 };
18318
18319 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18320         TOKEN_STRING_INITIALIZER
18321                 (struct cmd_tx_offload_get_configuration_result,
18322                  show, "show");
18323 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18324         TOKEN_STRING_INITIALIZER
18325                 (struct cmd_tx_offload_get_configuration_result,
18326                  port, "port");
18327 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18328         TOKEN_NUM_INITIALIZER
18329                 (struct cmd_tx_offload_get_configuration_result,
18330                  port_id, UINT16);
18331 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18332         TOKEN_STRING_INITIALIZER
18333                 (struct cmd_tx_offload_get_configuration_result,
18334                  tx_offload, "tx_offload");
18335 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18336         TOKEN_STRING_INITIALIZER
18337                 (struct cmd_tx_offload_get_configuration_result,
18338                  configuration, "configuration");
18339
18340 static void
18341 cmd_tx_offload_get_configuration_parsed(
18342         void *parsed_result,
18343         __attribute__((unused)) struct cmdline *cl,
18344         __attribute__((unused)) void *data)
18345 {
18346         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18347         struct rte_eth_dev_info dev_info;
18348         portid_t port_id = res->port_id;
18349         struct rte_port *port = &ports[port_id];
18350         uint64_t port_offloads;
18351         uint64_t queue_offloads;
18352         uint16_t nb_tx_queues;
18353         int q;
18354
18355         printf("Tx Offloading Configuration of port %d :\n", port_id);
18356
18357         port_offloads = port->dev_conf.txmode.offloads;
18358         printf("  Port :");
18359         print_tx_offloads(port_offloads);
18360         printf("\n");
18361
18362         rte_eth_dev_info_get(port_id, &dev_info);
18363         nb_tx_queues = dev_info.nb_tx_queues;
18364         for (q = 0; q < nb_tx_queues; q++) {
18365                 queue_offloads = port->tx_conf[q].offloads;
18366                 printf("  Queue[%2d] :", q);
18367                 print_tx_offloads(queue_offloads);
18368                 printf("\n");
18369         }
18370         printf("\n");
18371 }
18372
18373 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18374         .f = cmd_tx_offload_get_configuration_parsed,
18375         .data = NULL,
18376         .help_str = "show port <port_id> tx_offload configuration",
18377         .tokens = {
18378                 (void *)&cmd_tx_offload_get_configuration_show,
18379                 (void *)&cmd_tx_offload_get_configuration_port,
18380                 (void *)&cmd_tx_offload_get_configuration_port_id,
18381                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18382                 (void *)&cmd_tx_offload_get_configuration_configuration,
18383                 NULL,
18384         }
18385 };
18386
18387 /* Enable/Disable a per port offloading */
18388 struct cmd_config_per_port_tx_offload_result {
18389         cmdline_fixed_string_t port;
18390         cmdline_fixed_string_t config;
18391         portid_t port_id;
18392         cmdline_fixed_string_t tx_offload;
18393         cmdline_fixed_string_t offload;
18394         cmdline_fixed_string_t on_off;
18395 };
18396
18397 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18398         TOKEN_STRING_INITIALIZER
18399                 (struct cmd_config_per_port_tx_offload_result,
18400                  port, "port");
18401 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18402         TOKEN_STRING_INITIALIZER
18403                 (struct cmd_config_per_port_tx_offload_result,
18404                  config, "config");
18405 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18406         TOKEN_NUM_INITIALIZER
18407                 (struct cmd_config_per_port_tx_offload_result,
18408                  port_id, UINT16);
18409 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18410         TOKEN_STRING_INITIALIZER
18411                 (struct cmd_config_per_port_tx_offload_result,
18412                  tx_offload, "tx_offload");
18413 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18414         TOKEN_STRING_INITIALIZER
18415                 (struct cmd_config_per_port_tx_offload_result,
18416                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18417                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18418                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18419                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18420                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18421                           "match_metadata");
18422 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18423         TOKEN_STRING_INITIALIZER
18424                 (struct cmd_config_per_port_tx_offload_result,
18425                  on_off, "on#off");
18426
18427 static uint64_t
18428 search_tx_offload(const char *name)
18429 {
18430         uint64_t single_offload;
18431         const char *single_name;
18432         int found = 0;
18433         unsigned int bit;
18434
18435         single_offload = 1;
18436         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18437                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18438                 if (single_name == NULL)
18439                         break;
18440                 if (!strcasecmp(single_name, name)) {
18441                         found = 1;
18442                         break;
18443                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18444                         break;
18445                 single_offload <<= 1;
18446         }
18447
18448         if (found)
18449                 return single_offload;
18450
18451         return 0;
18452 }
18453
18454 static void
18455 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18456                                 __attribute__((unused)) struct cmdline *cl,
18457                                 __attribute__((unused)) void *data)
18458 {
18459         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18460         portid_t port_id = res->port_id;
18461         struct rte_eth_dev_info dev_info;
18462         struct rte_port *port = &ports[port_id];
18463         uint64_t single_offload;
18464         uint16_t nb_tx_queues;
18465         int q;
18466
18467         if (port->port_status != RTE_PORT_STOPPED) {
18468                 printf("Error: Can't config offload when Port %d "
18469                        "is not stopped\n", port_id);
18470                 return;
18471         }
18472
18473         single_offload = search_tx_offload(res->offload);
18474         if (single_offload == 0) {
18475                 printf("Unknown offload name: %s\n", res->offload);
18476                 return;
18477         }
18478
18479         rte_eth_dev_info_get(port_id, &dev_info);
18480         nb_tx_queues = dev_info.nb_tx_queues;
18481         if (!strcmp(res->on_off, "on")) {
18482                 port->dev_conf.txmode.offloads |= single_offload;
18483                 for (q = 0; q < nb_tx_queues; q++)
18484                         port->tx_conf[q].offloads |= single_offload;
18485         } else {
18486                 port->dev_conf.txmode.offloads &= ~single_offload;
18487                 for (q = 0; q < nb_tx_queues; q++)
18488                         port->tx_conf[q].offloads &= ~single_offload;
18489         }
18490
18491         cmd_reconfig_device_queue(port_id, 1, 1);
18492 }
18493
18494 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18495         .f = cmd_config_per_port_tx_offload_parsed,
18496         .data = NULL,
18497         .help_str = "port config <port_id> tx_offload "
18498                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18499                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18500                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18501                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18502                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18503                     "match_metadata on|off",
18504         .tokens = {
18505                 (void *)&cmd_config_per_port_tx_offload_result_port,
18506                 (void *)&cmd_config_per_port_tx_offload_result_config,
18507                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18508                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18509                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18510                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18511                 NULL,
18512         }
18513 };
18514
18515 /* Enable/Disable a per queue offloading */
18516 struct cmd_config_per_queue_tx_offload_result {
18517         cmdline_fixed_string_t port;
18518         portid_t port_id;
18519         cmdline_fixed_string_t txq;
18520         uint16_t queue_id;
18521         cmdline_fixed_string_t tx_offload;
18522         cmdline_fixed_string_t offload;
18523         cmdline_fixed_string_t on_off;
18524 };
18525
18526 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18527         TOKEN_STRING_INITIALIZER
18528                 (struct cmd_config_per_queue_tx_offload_result,
18529                  port, "port");
18530 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18531         TOKEN_NUM_INITIALIZER
18532                 (struct cmd_config_per_queue_tx_offload_result,
18533                  port_id, UINT16);
18534 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18535         TOKEN_STRING_INITIALIZER
18536                 (struct cmd_config_per_queue_tx_offload_result,
18537                  txq, "txq");
18538 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18539         TOKEN_NUM_INITIALIZER
18540                 (struct cmd_config_per_queue_tx_offload_result,
18541                  queue_id, UINT16);
18542 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18543         TOKEN_STRING_INITIALIZER
18544                 (struct cmd_config_per_queue_tx_offload_result,
18545                  tx_offload, "tx_offload");
18546 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18547         TOKEN_STRING_INITIALIZER
18548                 (struct cmd_config_per_queue_tx_offload_result,
18549                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18550                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18551                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18552                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18553                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18554 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18555         TOKEN_STRING_INITIALIZER
18556                 (struct cmd_config_per_queue_tx_offload_result,
18557                  on_off, "on#off");
18558
18559 static void
18560 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18561                                 __attribute__((unused)) struct cmdline *cl,
18562                                 __attribute__((unused)) void *data)
18563 {
18564         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18565         struct rte_eth_dev_info dev_info;
18566         portid_t port_id = res->port_id;
18567         uint16_t queue_id = res->queue_id;
18568         struct rte_port *port = &ports[port_id];
18569         uint64_t single_offload;
18570
18571         if (port->port_status != RTE_PORT_STOPPED) {
18572                 printf("Error: Can't config offload when Port %d "
18573                        "is not stopped\n", port_id);
18574                 return;
18575         }
18576
18577         rte_eth_dev_info_get(port_id, &dev_info);
18578         if (queue_id >= dev_info.nb_tx_queues) {
18579                 printf("Error: input queue_id should be 0 ... "
18580                        "%d\n", dev_info.nb_tx_queues - 1);
18581                 return;
18582         }
18583
18584         single_offload = search_tx_offload(res->offload);
18585         if (single_offload == 0) {
18586                 printf("Unknown offload name: %s\n", res->offload);
18587                 return;
18588         }
18589
18590         if (!strcmp(res->on_off, "on"))
18591                 port->tx_conf[queue_id].offloads |= single_offload;
18592         else
18593                 port->tx_conf[queue_id].offloads &= ~single_offload;
18594
18595         cmd_reconfig_device_queue(port_id, 1, 1);
18596 }
18597
18598 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18599         .f = cmd_config_per_queue_tx_offload_parsed,
18600         .data = NULL,
18601         .help_str = "port <port_id> txq <queue_id> tx_offload "
18602                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18603                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18604                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18605                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18606                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18607                     "on|off",
18608         .tokens = {
18609                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18610                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18611                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18612                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18613                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18614                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18615                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18616                 NULL,
18617         }
18618 };
18619
18620 /* *** configure tx_metadata for specific port *** */
18621 struct cmd_config_tx_metadata_specific_result {
18622         cmdline_fixed_string_t port;
18623         cmdline_fixed_string_t keyword;
18624         uint16_t port_id;
18625         cmdline_fixed_string_t item;
18626         uint32_t value;
18627 };
18628
18629 static void
18630 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18631                                 __attribute__((unused)) struct cmdline *cl,
18632                                 __attribute__((unused)) void *data)
18633 {
18634         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18635
18636         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18637                 return;
18638         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18639         /* Add/remove callback to insert valid metadata in every Tx packet. */
18640         if (ports[res->port_id].tx_metadata)
18641                 add_tx_md_callback(res->port_id);
18642         else
18643                 remove_tx_md_callback(res->port_id);
18644 }
18645
18646 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18647         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18648                         port, "port");
18649 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18650         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18651                         keyword, "config");
18652 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18653         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18654                         port_id, UINT16);
18655 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18656         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18657                         item, "tx_metadata");
18658 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18659         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18660                         value, UINT32);
18661
18662 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18663         .f = cmd_config_tx_metadata_specific_parsed,
18664         .data = NULL,
18665         .help_str = "port config <port_id> tx_metadata <value>",
18666         .tokens = {
18667                 (void *)&cmd_config_tx_metadata_specific_port,
18668                 (void *)&cmd_config_tx_metadata_specific_keyword,
18669                 (void *)&cmd_config_tx_metadata_specific_id,
18670                 (void *)&cmd_config_tx_metadata_specific_item,
18671                 (void *)&cmd_config_tx_metadata_specific_value,
18672                 NULL,
18673         },
18674 };
18675
18676 /* *** display tx_metadata per port configuration *** */
18677 struct cmd_show_tx_metadata_result {
18678         cmdline_fixed_string_t cmd_show;
18679         cmdline_fixed_string_t cmd_port;
18680         cmdline_fixed_string_t cmd_keyword;
18681         portid_t cmd_pid;
18682 };
18683
18684 static void
18685 cmd_show_tx_metadata_parsed(void *parsed_result,
18686                 __attribute__((unused)) struct cmdline *cl,
18687                 __attribute__((unused)) void *data)
18688 {
18689         struct cmd_show_tx_metadata_result *res = parsed_result;
18690
18691         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18692                 printf("invalid port id %u\n", res->cmd_pid);
18693                 return;
18694         }
18695         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18696                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18697                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18698         }
18699 }
18700
18701 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18702         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18703                         cmd_show, "show");
18704 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18705         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18706                         cmd_port, "port");
18707 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18708         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18709                         cmd_pid, UINT16);
18710 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18711         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18712                         cmd_keyword, "tx_metadata");
18713
18714 cmdline_parse_inst_t cmd_show_tx_metadata = {
18715         .f = cmd_show_tx_metadata_parsed,
18716         .data = NULL,
18717         .help_str = "show port <port_id> tx_metadata",
18718         .tokens = {
18719                 (void *)&cmd_show_tx_metadata_show,
18720                 (void *)&cmd_show_tx_metadata_port,
18721                 (void *)&cmd_show_tx_metadata_pid,
18722                 (void *)&cmd_show_tx_metadata_keyword,
18723                 NULL,
18724         },
18725 };
18726
18727 /* ******************************************************************************** */
18728
18729 /* list of instructions */
18730 cmdline_parse_ctx_t main_ctx[] = {
18731         (cmdline_parse_inst_t *)&cmd_help_brief,
18732         (cmdline_parse_inst_t *)&cmd_help_long,
18733         (cmdline_parse_inst_t *)&cmd_quit,
18734         (cmdline_parse_inst_t *)&cmd_load_from_file,
18735         (cmdline_parse_inst_t *)&cmd_showport,
18736         (cmdline_parse_inst_t *)&cmd_showqueue,
18737         (cmdline_parse_inst_t *)&cmd_showportall,
18738         (cmdline_parse_inst_t *)&cmd_showdevice,
18739         (cmdline_parse_inst_t *)&cmd_showcfg,
18740         (cmdline_parse_inst_t *)&cmd_showfwdall,
18741         (cmdline_parse_inst_t *)&cmd_start,
18742         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18743         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18744         (cmdline_parse_inst_t *)&cmd_set_link_up,
18745         (cmdline_parse_inst_t *)&cmd_set_link_down,
18746         (cmdline_parse_inst_t *)&cmd_reset,
18747         (cmdline_parse_inst_t *)&cmd_set_numbers,
18748         (cmdline_parse_inst_t *)&cmd_set_log,
18749         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18750         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18751         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18752         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18753         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18754         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18755         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18756         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18757         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18758         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18759         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18760         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18761         (cmdline_parse_inst_t *)&cmd_set_link_check,
18762         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18763         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18764         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18765         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18766 #ifdef RTE_LIBRTE_PMD_BOND
18767         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18768         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18769         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18770         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18771         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18772         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18773         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18774         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18775         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18776         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18777         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18778 #endif
18779         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18780         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18781         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18782         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18783         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18784         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18785         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18786         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18787         (cmdline_parse_inst_t *)&cmd_csum_set,
18788         (cmdline_parse_inst_t *)&cmd_csum_show,
18789         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18790         (cmdline_parse_inst_t *)&cmd_tso_set,
18791         (cmdline_parse_inst_t *)&cmd_tso_show,
18792         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18793         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18794         (cmdline_parse_inst_t *)&cmd_gro_enable,
18795         (cmdline_parse_inst_t *)&cmd_gro_flush,
18796         (cmdline_parse_inst_t *)&cmd_gro_show,
18797         (cmdline_parse_inst_t *)&cmd_gso_enable,
18798         (cmdline_parse_inst_t *)&cmd_gso_size,
18799         (cmdline_parse_inst_t *)&cmd_gso_show,
18800         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18801         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18802         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18803         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18804         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18805         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18806         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18807         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18808         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18809         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18810         (cmdline_parse_inst_t *)&cmd_config_dcb,
18811         (cmdline_parse_inst_t *)&cmd_read_reg,
18812         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18813         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18814         (cmdline_parse_inst_t *)&cmd_write_reg,
18815         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18816         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18817         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18818         (cmdline_parse_inst_t *)&cmd_stop,
18819         (cmdline_parse_inst_t *)&cmd_mac_addr,
18820         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18821         (cmdline_parse_inst_t *)&cmd_set_qmap,
18822         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18823         (cmdline_parse_inst_t *)&cmd_operate_port,
18824         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18825         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18826         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18827         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
18828         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18829         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18830         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18831         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18832         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18833         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18834         (cmdline_parse_inst_t *)&cmd_config_mtu,
18835         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18836         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18837         (cmdline_parse_inst_t *)&cmd_config_rss,
18838         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18839         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18840         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18841         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18842         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18843         (cmdline_parse_inst_t *)&cmd_showport_reta,
18844         (cmdline_parse_inst_t *)&cmd_config_burst,
18845         (cmdline_parse_inst_t *)&cmd_config_thresh,
18846         (cmdline_parse_inst_t *)&cmd_config_threshold,
18847         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18848         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18849         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18850         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18851         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18852         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18853         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18854         (cmdline_parse_inst_t *)&cmd_global_config,
18855         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18856         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18857         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18858         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18859         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18860         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18861         (cmdline_parse_inst_t *)&cmd_dump,
18862         (cmdline_parse_inst_t *)&cmd_dump_one,
18863         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18864         (cmdline_parse_inst_t *)&cmd_syn_filter,
18865         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18866         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18867         (cmdline_parse_inst_t *)&cmd_flex_filter,
18868         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18869         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18870         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18871         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18872         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18873         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18874         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18875         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18876         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18877         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18878         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18879         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18880         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18881         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18882         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18883         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18884         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18885         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18886         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18887         (cmdline_parse_inst_t *)&cmd_flow,
18888         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18889         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18890         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18891         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18892         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18893         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18894         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18895         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18896         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18897         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18898         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18899         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18900         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18901         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18902         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18903         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18904         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18905         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18906         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18907         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18908         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18909         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18910         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18911         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18912         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18913         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18914         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18915         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18916         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18917         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18918         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18919         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18920         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18921         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18922         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18923         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18924         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18925         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18926         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18927         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18928         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18929         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18930         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18931         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18932         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18933         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18934         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18935         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18936         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18937 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
18938         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
18939 #endif
18940         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18941         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18942         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18943         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18944         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18945         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18946         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18947         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18948         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18949         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18950         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18951         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18952         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18953         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18954         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18955         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18956         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18957         (cmdline_parse_inst_t *)&cmd_ddp_add,
18958         (cmdline_parse_inst_t *)&cmd_ddp_del,
18959         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18960         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18961         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18962         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18963         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18964         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18965         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18966         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18967         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18968         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18969
18970         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18971         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18972         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18973         (cmdline_parse_inst_t *)&cmd_queue_region,
18974         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18975         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18976         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18977         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18978         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18979         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18980         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18981         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18982         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18983         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18984         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18985         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18986         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18987         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18988         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18989         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18990         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18991         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18992         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18993         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18994         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18995         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18996         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18997         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18998         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18999         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19000         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19001         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19002         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19003         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19004         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19005         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19006         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19007         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19008         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19009 #ifdef RTE_LIBRTE_BPF
19010         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19011         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19012 #endif
19013         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19014         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19015         (cmdline_parse_inst_t *)&cmd_set_raw,
19016         NULL,
19017 };
19018
19019 /* read cmdline commands from file */
19020 void
19021 cmdline_read_from_file(const char *filename)
19022 {
19023         struct cmdline *cl;
19024
19025         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19026         if (cl == NULL) {
19027                 printf("Failed to create file based cmdline context: %s\n",
19028                        filename);
19029                 return;
19030         }
19031
19032         cmdline_interact(cl);
19033         cmdline_quit(cl);
19034
19035         cmdline_free(cl);
19036
19037         printf("Read CLI commands from %s\n", filename);
19038 }
19039
19040 /* prompt function, called from main on MASTER lcore */
19041 void
19042 prompt(void)
19043 {
19044         /* initialize non-constant commands */
19045         cmd_set_fwd_mode_init();
19046         cmd_set_fwd_retry_mode_init();
19047
19048         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19049         if (testpmd_cl == NULL)
19050                 return;
19051         cmdline_interact(testpmd_cl);
19052         cmdline_stdin_exit(testpmd_cl);
19053 }
19054
19055 void
19056 prompt_exit(void)
19057 {
19058         if (testpmd_cl != NULL)
19059                 cmdline_quit(testpmd_cl);
19060 }
19061
19062 static void
19063 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19064 {
19065         if (id == (portid_t)RTE_PORT_ALL) {
19066                 portid_t pid;
19067
19068                 RTE_ETH_FOREACH_DEV(pid) {
19069                         /* check if need_reconfig has been set to 1 */
19070                         if (ports[pid].need_reconfig == 0)
19071                                 ports[pid].need_reconfig = dev;
19072                         /* check if need_reconfig_queues has been set to 1 */
19073                         if (ports[pid].need_reconfig_queues == 0)
19074                                 ports[pid].need_reconfig_queues = queue;
19075                 }
19076         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19077                 /* check if need_reconfig has been set to 1 */
19078                 if (ports[id].need_reconfig == 0)
19079                         ports[id].need_reconfig = dev;
19080                 /* check if need_reconfig_queues has been set to 1 */
19081                 if (ports[id].need_reconfig_queues == 0)
19082                         ports[id].need_reconfig_queues = queue;
19083         }
19084 }