net: add rte prefix to ether structures
[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 all                        : All of the above sections.\n\n"
105         );
106
107 }
108
109 cmdline_parse_token_string_t cmd_help_brief_help =
110         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
111
112 cmdline_parse_inst_t cmd_help_brief = {
113         .f = cmd_help_brief_parsed,
114         .data = NULL,
115         .help_str = "help: Show help",
116         .tokens = {
117                 (void *)&cmd_help_brief_help,
118                 NULL,
119         },
120 };
121
122 /* *** Help command with help sections. *** */
123 struct cmd_help_long_result {
124         cmdline_fixed_string_t help;
125         cmdline_fixed_string_t section;
126 };
127
128 static void cmd_help_long_parsed(void *parsed_result,
129                                  struct cmdline *cl,
130                                  __attribute__((unused)) void *data)
131 {
132         int show_all = 0;
133         struct cmd_help_long_result *res = parsed_result;
134
135         if (!strcmp(res->section, "all"))
136                 show_all = 1;
137
138         if (show_all || !strcmp(res->section, "control")) {
139
140                 cmdline_printf(
141                         cl,
142                         "\n"
143                         "Control forwarding:\n"
144                         "-------------------\n\n"
145
146                         "start\n"
147                         "    Start packet forwarding with current configuration.\n\n"
148
149                         "start tx_first\n"
150                         "    Start packet forwarding with current config"
151                         " after sending one burst of packets.\n\n"
152
153                         "stop\n"
154                         "    Stop packet forwarding, and display accumulated"
155                         " statistics.\n\n"
156
157                         "quit\n"
158                         "    Quit to prompt.\n\n"
159                 );
160         }
161
162         if (show_all || !strcmp(res->section, "display")) {
163
164                 cmdline_printf(
165                         cl,
166                         "\n"
167                         "Display:\n"
168                         "--------\n\n"
169
170                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
171                         "    Display information for port_id, or all.\n\n"
172
173                         "show port X rss reta (size) (mask0,mask1,...)\n"
174                         "    Display the rss redirection table entry indicated"
175                         " by masks on port X. size is used to indicate the"
176                         " hardware supported reta size\n\n"
177
178                         "show port (port_id) rss-hash [key]\n"
179                         "    Display the RSS hash functions and RSS hash key of port\n\n"
180
181                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
182                         "    Clear information for port_id, or all.\n\n"
183
184                         "show (rxq|txq) info (port_id) (queue_id)\n"
185                         "    Display information for configured RX/TX queue.\n\n"
186
187                         "show config (rxtx|cores|fwd|txpkts)\n"
188                         "    Display the given configuration.\n\n"
189
190                         "read rxd (port_id) (queue_id) (rxd_id)\n"
191                         "    Display an RX descriptor of a port RX queue.\n\n"
192
193                         "read txd (port_id) (queue_id) (txd_id)\n"
194                         "    Display a TX descriptor of a port TX queue.\n\n"
195
196                         "ddp get list (port_id)\n"
197                         "    Get ddp profile info list\n\n"
198
199                         "ddp get info (profile_path)\n"
200                         "    Get ddp profile information.\n\n"
201
202                         "show vf stats (port_id) (vf_id)\n"
203                         "    Display a VF's statistics.\n\n"
204
205                         "clear vf stats (port_id) (vf_id)\n"
206                         "    Reset a VF's statistics.\n\n"
207
208                         "show port (port_id) pctype mapping\n"
209                         "    Get flow ptype to pctype mapping on a port\n\n"
210
211                         "show port meter stats (port_id) (meter_id) (clear)\n"
212                         "    Get meter stats on a port\n\n"
213
214                         "show fwd stats all\n"
215                         "    Display statistics for all fwd engines.\n\n"
216
217                         "clear fwd stats all\n"
218                         "    Clear statistics for all fwd engines.\n\n"
219
220                         "show port (port_id) rx_offload capabilities\n"
221                         "    List all per queue and per port Rx offloading"
222                         " capabilities of a port\n\n"
223
224                         "show port (port_id) rx_offload configuration\n"
225                         "    List port level and all queue level"
226                         " Rx offloading configuration\n\n"
227
228                         "show port (port_id) tx_offload capabilities\n"
229                         "    List all per queue and per port"
230                         " Tx offloading capabilities of a port\n\n"
231
232                         "show port (port_id) tx_offload configuration\n"
233                         "    List port level and all queue level"
234                         " Tx offloading configuration\n\n"
235
236                         "show port (port_id) tx_metadata\n"
237                         "    Show Tx metadata value set"
238                         " for a specific port\n\n"
239                 );
240         }
241
242         if (show_all || !strcmp(res->section, "config")) {
243                 cmdline_printf(
244                         cl,
245                         "\n"
246                         "Configuration:\n"
247                         "--------------\n"
248                         "Configuration changes only become active when"
249                         " forwarding is started/restarted.\n\n"
250
251                         "set default\n"
252                         "    Reset forwarding to the default configuration.\n\n"
253
254                         "set verbose (level)\n"
255                         "    Set the debug verbosity level X.\n\n"
256
257                         "set log global|(type) (level)\n"
258                         "    Set the log level.\n\n"
259
260                         "set nbport (num)\n"
261                         "    Set number of ports.\n\n"
262
263                         "set nbcore (num)\n"
264                         "    Set number of cores.\n\n"
265
266                         "set coremask (mask)\n"
267                         "    Set the forwarding cores hexadecimal mask.\n\n"
268
269                         "set portmask (mask)\n"
270                         "    Set the forwarding ports hexadecimal mask.\n\n"
271
272                         "set burst (num)\n"
273                         "    Set number of packets per burst.\n\n"
274
275                         "set burst tx delay (microseconds) retry (num)\n"
276                         "    Set the transmit delay time and number of retries,"
277                         " effective when retry is enabled.\n\n"
278
279                         "set txpkts (x[,y]*)\n"
280                         "    Set the length of each segment of TXONLY"
281                         " and optionally CSUM packets.\n\n"
282
283                         "set txsplit (off|on|rand)\n"
284                         "    Set the split policy for the TX packets."
285                         " Right now only applicable for CSUM and TXONLY"
286                         " modes\n\n"
287
288                         "set corelist (x[,y]*)\n"
289                         "    Set the list of forwarding cores.\n\n"
290
291                         "set portlist (x[,y]*)\n"
292                         "    Set the list of forwarding ports.\n\n"
293
294                         "set port setup on (iterator|event)\n"
295                         "    Select how attached port is retrieved for setup.\n\n"
296
297                         "set tx loopback (port_id) (on|off)\n"
298                         "    Enable or disable tx loopback.\n\n"
299
300                         "set all queues drop (port_id) (on|off)\n"
301                         "    Set drop enable bit for all queues.\n\n"
302
303                         "set vf split drop (port_id) (vf_id) (on|off)\n"
304                         "    Set split drop enable bit for a VF from the PF.\n\n"
305
306                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
307                         "    Set MAC antispoof for a VF from the PF.\n\n"
308
309                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
310                         "    Enable MACsec offload.\n\n"
311
312                         "set macsec offload (port_id) off\n"
313                         "    Disable MACsec offload.\n\n"
314
315                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
316                         "    Configure MACsec secure connection (SC).\n\n"
317
318                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
319                         "    Configure MACsec secure association (SA).\n\n"
320
321                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
322                         "    Set VF broadcast for a VF from the PF.\n\n"
323
324                         "vlan set strip (on|off) (port_id)\n"
325                         "    Set the VLAN strip on a port.\n\n"
326
327                         "vlan set stripq (on|off) (port_id,queue_id)\n"
328                         "    Set the VLAN strip for a queue on a port.\n\n"
329
330                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
331                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
332
333                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
334                         "    Set VLAN insert for a VF from the PF.\n\n"
335
336                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
337                         "    Set VLAN antispoof for a VF from the PF.\n\n"
338
339                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
340                         "    Set VLAN tag for a VF from the PF.\n\n"
341
342                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
343                         "    Set a VF's max bandwidth(Mbps).\n\n"
344
345                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
346                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
347
348                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
349                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
350
351                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
352                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
353
354                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
355                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
356
357                         "vlan set filter (on|off) (port_id)\n"
358                         "    Set the VLAN filter on a port.\n\n"
359
360                         "vlan set qinq (on|off) (port_id)\n"
361                         "    Set the VLAN QinQ (extended queue in queue)"
362                         " on a port.\n\n"
363
364                         "vlan set (inner|outer) tpid (value) (port_id)\n"
365                         "    Set the VLAN TPID for Packet Filtering on"
366                         " a port\n\n"
367
368                         "rx_vlan add (vlan_id|all) (port_id)\n"
369                         "    Add a vlan_id, or all identifiers, to the set"
370                         " of VLAN identifiers filtered by port_id.\n\n"
371
372                         "rx_vlan rm (vlan_id|all) (port_id)\n"
373                         "    Remove a vlan_id, or all identifiers, from the set"
374                         " of VLAN identifiers filtered by port_id.\n\n"
375
376                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
377                         "    Add a vlan_id, to the set of VLAN identifiers"
378                         "filtered for VF(s) from port_id.\n\n"
379
380                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
381                         "    Remove a vlan_id, to the set of VLAN identifiers"
382                         "filtered for VF(s) from port_id.\n\n"
383
384                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
385                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
386                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
387                         "   add a tunnel filter of a port.\n\n"
388
389                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
390                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
391                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
392                         "   remove a tunnel filter of a port.\n\n"
393
394                         "rx_vxlan_port add (udp_port) (port_id)\n"
395                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
396
397                         "rx_vxlan_port rm (udp_port) (port_id)\n"
398                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
399
400                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
401                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
402                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
403
404                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
405                         "    Set port based TX VLAN insertion.\n\n"
406
407                         "tx_vlan reset (port_id)\n"
408                         "    Disable hardware insertion of a VLAN header in"
409                         " packets sent on a port.\n\n"
410
411                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
412                         "    Select hardware or software calculation of the"
413                         " checksum when transmitting a packet using the"
414                         " csum forward engine.\n"
415                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
416                         "    outer-ip concerns the outer IP layer in"
417                         "    outer-udp concerns the outer UDP layer in"
418                         " case the packet is recognized as a tunnel packet by"
419                         " the forward engine (vxlan, gre and ipip are supported)\n"
420                         "    Please check the NIC datasheet for HW limits.\n\n"
421
422                         "csum parse-tunnel (on|off) (tx_port_id)\n"
423                         "    If disabled, treat tunnel packets as non-tunneled"
424                         " packets (treat inner headers as payload). The port\n"
425                         "    argument is the port used for TX in csum forward"
426                         " engine.\n\n"
427
428                         "csum show (port_id)\n"
429                         "    Display tx checksum offload configuration\n\n"
430
431                         "tso set (segsize) (portid)\n"
432                         "    Enable TCP Segmentation Offload in csum forward"
433                         " engine.\n"
434                         "    Please check the NIC datasheet for HW limits.\n\n"
435
436                         "tso show (portid)"
437                         "    Display the status of TCP Segmentation Offload.\n\n"
438
439                         "set port (port_id) gro on|off\n"
440                         "    Enable or disable Generic Receive Offload in"
441                         " csum forwarding engine.\n\n"
442
443                         "show port (port_id) gro\n"
444                         "    Display GRO configuration.\n\n"
445
446                         "set gro flush (cycles)\n"
447                         "    Set the cycle to flush GROed packets from"
448                         " reassembly tables.\n\n"
449
450                         "set port (port_id) gso (on|off)"
451                         "    Enable or disable Generic Segmentation Offload in"
452                         " csum forwarding engine.\n\n"
453
454                         "set gso segsz (length)\n"
455                         "    Set max packet length for output GSO segments,"
456                         " including packet header and payload.\n\n"
457
458                         "show port (port_id) gso\n"
459                         "    Show GSO configuration.\n\n"
460
461                         "set fwd (%s)\n"
462                         "    Set packet forwarding mode.\n\n"
463
464                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
465                         "    Add a MAC address on port_id.\n\n"
466
467                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Remove a MAC address from port_id.\n\n"
469
470                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
471                         "    Set the default MAC address for port_id.\n\n"
472
473                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
474                         "    Add a MAC address for a VF on the port.\n\n"
475
476                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
477                         "    Set the MAC address for a VF from the PF.\n\n"
478
479                         "set eth-peer (port_id) (peer_addr)\n"
480                         "    set the peer address for certain port.\n\n"
481
482                         "set port (port_id) uta (mac_address|all) (on|off)\n"
483                         "    Add/Remove a or all unicast hash filter(s)"
484                         "from port X.\n\n"
485
486                         "set promisc (port_id|all) (on|off)\n"
487                         "    Set the promiscuous mode on port_id, or all.\n\n"
488
489                         "set allmulti (port_id|all) (on|off)\n"
490                         "    Set the allmulti mode on port_id, or all.\n\n"
491
492                         "set vf promisc (port_id) (vf_id) (on|off)\n"
493                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
494
495                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
496                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
497
498                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
499                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
500                         " (on|off) autoneg (on|off) (port_id)\n"
501                         "set flow_ctrl rx (on|off) (portid)\n"
502                         "set flow_ctrl tx (on|off) (portid)\n"
503                         "set flow_ctrl high_water (high_water) (portid)\n"
504                         "set flow_ctrl low_water (low_water) (portid)\n"
505                         "set flow_ctrl pause_time (pause_time) (portid)\n"
506                         "set flow_ctrl send_xon (send_xon) (portid)\n"
507                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
508                         "set flow_ctrl autoneg (on|off) (port_id)\n"
509                         "    Set the link flow control parameter on a port.\n\n"
510
511                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
512                         " (low_water) (pause_time) (priority) (port_id)\n"
513                         "    Set the priority flow control parameter on a"
514                         " port.\n\n"
515
516                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
517                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
518                         " queue on port.\n"
519                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
520                         " on port 0 to mapping 5.\n\n"
521
522                         "set xstats-hide-zero on|off\n"
523                         "    Set the option to hide the zero values"
524                         " for xstats display.\n"
525
526                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
527                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
528
529                         "set port (port_id) vf (vf_id) (mac_addr)"
530                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
531                         "   Add/Remove unicast or multicast MAC addr filter"
532                         " for a VF.\n\n"
533
534                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
535                         "|MPE) (on|off)\n"
536                         "    AUPE:accepts untagged VLAN;"
537                         "ROPE:accept unicast hash\n\n"
538                         "    BAM:accepts broadcast packets;"
539                         "MPE:accepts all multicast packets\n\n"
540                         "    Enable/Disable a VF receive mode of a port\n\n"
541
542                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
543                         "    Set rate limit for a queue of a port\n\n"
544
545                         "set port (port_id) vf (vf_id) rate (rate_num) "
546                         "queue_mask (queue_mask_value)\n"
547                         "    Set rate limit for queues in VF of a port\n\n"
548
549                         "set port (port_id) mirror-rule (rule_id)"
550                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
551                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
552                         "   Set pool or vlan type mirror rule on a port.\n"
553                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
554                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
555                         " to pool 0.\n\n"
556
557                         "set port (port_id) mirror-rule (rule_id)"
558                         " (uplink-mirror|downlink-mirror) dst-pool"
559                         " (pool_id) (on|off)\n"
560                         "   Set uplink or downlink type mirror rule on a port.\n"
561                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
562                         " 0 on' enable mirror income traffic to pool 0.\n\n"
563
564                         "reset port (port_id) mirror-rule (rule_id)\n"
565                         "   Reset a mirror rule.\n\n"
566
567                         "set flush_rx (on|off)\n"
568                         "   Flush (default) or don't flush RX streams before"
569                         " forwarding. Mainly used with PCAP drivers.\n\n"
570
571                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
572                         "   Set the bypass mode for the lowest port on bypass enabled"
573                         " NIC.\n\n"
574
575                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
576                         "mode (normal|bypass|isolate) (port_id)\n"
577                         "   Set the event required to initiate specified bypass mode for"
578                         " the lowest port on a bypass enabled NIC where:\n"
579                         "       timeout   = enable bypass after watchdog timeout.\n"
580                         "       os_on     = enable bypass when OS/board is powered on.\n"
581                         "       os_off    = enable bypass when OS/board is powered off.\n"
582                         "       power_on  = enable bypass when power supply is turned on.\n"
583                         "       power_off = enable bypass when power supply is turned off."
584                         "\n\n"
585
586                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
587                         "   Set the bypass watchdog timeout to 'n' seconds"
588                         " where 0 = instant.\n\n"
589
590                         "show bypass config (port_id)\n"
591                         "   Show the bypass configuration for a bypass enabled NIC"
592                         " using the lowest port on the NIC.\n\n"
593
594 #ifdef RTE_LIBRTE_PMD_BOND
595                         "create bonded device (mode) (socket)\n"
596                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
597
598                         "add bonding slave (slave_id) (port_id)\n"
599                         "       Add a slave device to a bonded device.\n\n"
600
601                         "remove bonding slave (slave_id) (port_id)\n"
602                         "       Remove a slave device from a bonded device.\n\n"
603
604                         "set bonding mode (value) (port_id)\n"
605                         "       Set the bonding mode on a bonded device.\n\n"
606
607                         "set bonding primary (slave_id) (port_id)\n"
608                         "       Set the primary slave for a bonded device.\n\n"
609
610                         "show bonding config (port_id)\n"
611                         "       Show the bonding config for port_id.\n\n"
612
613                         "set bonding mac_addr (port_id) (address)\n"
614                         "       Set the MAC address of a bonded device.\n\n"
615
616                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
617                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
618
619                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
620                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
621
622                         "set bonding mon_period (port_id) (value)\n"
623                         "       Set the bonding link status monitoring polling period in ms.\n\n"
624
625                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
626                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
627
628 #endif
629                         "set link-up port (port_id)\n"
630                         "       Set link up for a port.\n\n"
631
632                         "set link-down port (port_id)\n"
633                         "       Set link down for a port.\n\n"
634
635                         "E-tag set insertion on port-tag-id (value)"
636                         " port (port_id) vf (vf_id)\n"
637                         "    Enable E-tag insertion for a VF on a port\n\n"
638
639                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
640                         "    Disable E-tag insertion for a VF on a port\n\n"
641
642                         "E-tag set stripping (on|off) port (port_id)\n"
643                         "    Enable/disable E-tag stripping on a port\n\n"
644
645                         "E-tag set forwarding (on|off) port (port_id)\n"
646                         "    Enable/disable E-tag based forwarding"
647                         " on a port\n\n"
648
649                         "E-tag set filter add e-tag-id (value) dst-pool"
650                         " (pool_id) port (port_id)\n"
651                         "    Add an E-tag forwarding filter on a port\n\n"
652
653                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
654                         "    Delete an E-tag forwarding filter on a port\n\n"
655
656                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
657                         "    Load a profile package on a port\n\n"
658
659                         "ddp del (port_id) (backup_profile_path)\n"
660                         "    Delete a profile package from a port\n\n"
661
662                         "ptype mapping get (port_id) (valid_only)\n"
663                         "    Get ptype mapping on a port\n\n"
664
665                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
666                         "    Replace target with the pkt_type in ptype mapping\n\n"
667
668                         "ptype mapping reset (port_id)\n"
669                         "    Reset ptype mapping on a port\n\n"
670
671                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
672                         "    Update a ptype mapping item on a port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "queue_start_index (value) queue_num (value)\n"
676                         "    Set a queue region on a port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "flowtype (value)\n"
680                         "    Set a flowtype region index on a port\n\n"
681
682                         "set port (port_id) queue-region UP (value) region_id (value)\n"
683                         "    Set the mapping of User Priority to "
684                         "queue region on a port\n\n"
685
686                         "set port (port_id) queue-region flush (on|off)\n"
687                         "    flush all queue region related configuration\n\n"
688
689                         "show port meter cap (port_id)\n"
690                         "    Show port meter capability information\n\n"
691
692                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
693                         "    meter profile add - srtcm rfc 2697\n\n"
694
695                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
696                         "    meter profile add - trtcm rfc 2698\n\n"
697
698                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
699                         "    meter profile add - trtcm rfc 4115\n\n"
700
701                         "del port meter profile (port_id) (profile_id)\n"
702                         "    meter profile delete\n\n"
703
704                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
705                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
706                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
707                         "(dscp_tbl_entry63)]\n"
708                         "    meter create\n\n"
709
710                         "enable port meter (port_id) (mtr_id)\n"
711                         "    meter enable\n\n"
712
713                         "disable port meter (port_id) (mtr_id)\n"
714                         "    meter disable\n\n"
715
716                         "del port meter (port_id) (mtr_id)\n"
717                         "    meter delete\n\n"
718
719                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
720                         "    meter update meter profile\n\n"
721
722                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
723                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
724                         "    update meter dscp table entries\n\n"
725
726                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
727                         "(action0) [(action1) (action2)]\n"
728                         "    meter update policer action\n\n"
729
730                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
731                         "    meter update stats\n\n"
732
733                         "show port (port_id) queue-region\n"
734                         "    show all queue region related configuration info\n\n"
735
736                         "vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
737                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
738                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
739                         "       Configure the VXLAN encapsulation for flows.\n\n"
740
741                         "vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
742                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
743                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
744                         " eth-dst (eth-dst)\n"
745                         "       Configure the VXLAN encapsulation for flows.\n\n"
746
747                         "vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
748                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
749                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
750                         " eth-dst (eth-dst)\n"
751                         "       Configure the VXLAN encapsulation for flows.\n\n"
752
753                         "nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
754                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
755                         " (eth-dst)\n"
756                         "       Configure the NVGRE encapsulation for flows.\n\n"
757
758                         "nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
759                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
760                         " eth-src (eth-src) eth-dst (eth-dst)\n"
761                         "       Configure the NVGRE encapsulation for flows.\n\n"
762
763                         , list_pkt_forwarding_modes()
764                 );
765         }
766
767         if (show_all || !strcmp(res->section, "ports")) {
768
769                 cmdline_printf(
770                         cl,
771                         "\n"
772                         "Port Operations:\n"
773                         "----------------\n\n"
774
775                         "port start (port_id|all)\n"
776                         "    Start all ports or port_id.\n\n"
777
778                         "port stop (port_id|all)\n"
779                         "    Stop all ports or port_id.\n\n"
780
781                         "port close (port_id|all)\n"
782                         "    Close all ports or port_id.\n\n"
783
784                         "port attach (ident)\n"
785                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
786
787                         "port detach (port_id)\n"
788                         "    Detach physical or virtual dev by port_id\n\n"
789
790                         "port config (port_id|all)"
791                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
792                         " duplex (half|full|auto)\n"
793                         "    Set speed and duplex for all ports or port_id\n\n"
794
795                         "port config (port_id|all) loopback (mode)\n"
796                         "    Set loopback mode for all ports or port_id\n\n"
797
798                         "port config all (rxq|txq|rxd|txd) (value)\n"
799                         "    Set number for rxq/txq/rxd/txd.\n\n"
800
801                         "port config all max-pkt-len (value)\n"
802                         "    Set the max packet length.\n\n"
803
804                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
805                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
806                         " (on|off)\n"
807                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
808                         " for ports.\n\n"
809
810                         "port config all rss (all|default|ip|tcp|udp|sctp|"
811                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
812                         "    Set the RSS mode.\n\n"
813
814                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
815                         "    Set the RSS redirection table.\n\n"
816
817                         "port config (port_id) dcb vt (on|off) (traffic_class)"
818                         " pfc (on|off)\n"
819                         "    Set the DCB mode.\n\n"
820
821                         "port config all burst (value)\n"
822                         "    Set the number of packets per burst.\n\n"
823
824                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
825                         " (value)\n"
826                         "    Set the ring prefetch/host/writeback threshold"
827                         " for tx/rx queue.\n\n"
828
829                         "port config all (txfreet|txrst|rxfreet) (value)\n"
830                         "    Set free threshold for rx/tx, or set"
831                         " tx rs bit threshold.\n\n"
832                         "port config mtu X value\n"
833                         "    Set the MTU of port X to a given value\n\n"
834
835                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
836                         "    Set a rx/tx queue's ring size configuration, the new"
837                         " value will take effect after command that (re-)start the port"
838                         " or command that setup the specific queue\n\n"
839
840                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
841                         "    Start/stop a rx/tx queue of port X. Only take effect"
842                         " when port X is started\n\n"
843
844                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
845                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
846                         " take effect when port X is stopped.\n\n"
847
848                         "port (port_id) (rxq|txq) (queue_id) setup\n"
849                         "    Setup a rx/tx queue of port X.\n\n"
850
851                         "port config (port_id|all) l2-tunnel E-tag ether-type"
852                         " (value)\n"
853                         "    Set the value of E-tag ether-type.\n\n"
854
855                         "port config (port_id|all) l2-tunnel E-tag"
856                         " (enable|disable)\n"
857                         "    Enable/disable the E-tag support.\n\n"
858
859                         "port config (port_id) pctype mapping reset\n"
860                         "    Reset flow type to pctype mapping on a port\n\n"
861
862                         "port config (port_id) pctype mapping update"
863                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
864                         "    Update a flow type to pctype mapping item on a port\n\n"
865
866                         "port config (port_id) pctype (pctype_id) hash_inset|"
867                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
868                         " (field_idx)\n"
869                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
870
871                         "port config (port_id) pctype (pctype_id) hash_inset|"
872                         "fdir_inset|fdir_flx_inset clear all"
873                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
874
875                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
876                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
877
878                         "port config <port_id> rx_offload vlan_strip|"
879                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
880                         "outer_ipv4_cksum|macsec_strip|header_split|"
881                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
882                         "scatter|timestamp|security|keep_crc on|off\n"
883                         "     Enable or disable a per port Rx offloading"
884                         " on all Rx queues of a port\n\n"
885
886                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
887                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
888                         "outer_ipv4_cksum|macsec_strip|header_split|"
889                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
890                         "scatter|timestamp|security|keep_crc on|off\n"
891                         "    Enable or disable a per queue Rx offloading"
892                         " only on a specific Rx queue\n\n"
893
894                         "port config (port_id) tx_offload vlan_insert|"
895                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
896                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
897                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
898                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
899                         "security|match_metadata on|off\n"
900                         "    Enable or disable a per port Tx offloading"
901                         " on all Tx queues of a port\n\n"
902
903                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
904                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
905                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
906                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
907                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
908                         " on|off\n"
909                         "    Enable or disable a per queue Tx offloading"
910                         " only on a specific Tx queue\n\n"
911
912                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
913                         "    Load an eBPF program as a callback"
914                         " for particular RX/TX queue\n\n"
915
916                         "bpf-unload rx|tx (port) (queue)\n"
917                         "    Unload previously loaded eBPF program"
918                         " for particular RX/TX queue\n\n"
919
920                         "port config (port_id) tx_metadata (value)\n"
921                         "    Set Tx metadata value per port. Testpmd will add this value"
922                         " to any Tx packet sent from this port\n\n"
923                 );
924         }
925
926         if (show_all || !strcmp(res->section, "registers")) {
927
928                 cmdline_printf(
929                         cl,
930                         "\n"
931                         "Registers:\n"
932                         "----------\n\n"
933
934                         "read reg (port_id) (address)\n"
935                         "    Display value of a port register.\n\n"
936
937                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
938                         "    Display a port register bit field.\n\n"
939
940                         "read regbit (port_id) (address) (bit_x)\n"
941                         "    Display a single port register bit.\n\n"
942
943                         "write reg (port_id) (address) (value)\n"
944                         "    Set value of a port register.\n\n"
945
946                         "write regfield (port_id) (address) (bit_x) (bit_y)"
947                         " (value)\n"
948                         "    Set bit field of a port register.\n\n"
949
950                         "write regbit (port_id) (address) (bit_x) (value)\n"
951                         "    Set single bit value of a port register.\n\n"
952                 );
953         }
954         if (show_all || !strcmp(res->section, "filters")) {
955
956                 cmdline_printf(
957                         cl,
958                         "\n"
959                         "filters:\n"
960                         "--------\n\n"
961
962                         "ethertype_filter (port_id) (add|del)"
963                         " (mac_addr|mac_ignr) (mac_address) ethertype"
964                         " (ether_type) (drop|fwd) queue (queue_id)\n"
965                         "    Add/Del an ethertype filter.\n\n"
966
967                         "2tuple_filter (port_id) (add|del)"
968                         " dst_port (dst_port_value) protocol (protocol_value)"
969                         " mask (mask_value) tcp_flags (tcp_flags_value)"
970                         " priority (prio_value) queue (queue_id)\n"
971                         "    Add/Del a 2tuple filter.\n\n"
972
973                         "5tuple_filter (port_id) (add|del)"
974                         " dst_ip (dst_address) src_ip (src_address)"
975                         " dst_port (dst_port_value) src_port (src_port_value)"
976                         " protocol (protocol_value)"
977                         " mask (mask_value) tcp_flags (tcp_flags_value)"
978                         " priority (prio_value) queue (queue_id)\n"
979                         "    Add/Del a 5tuple filter.\n\n"
980
981                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
982                         "    Add/Del syn filter.\n\n"
983
984                         "flex_filter (port_id) (add|del) len (len_value)"
985                         " bytes (bytes_value) mask (mask_value)"
986                         " priority (prio_value) queue (queue_id)\n"
987                         "    Add/Del a flex filter.\n\n"
988
989                         "flow_director_filter (port_id) mode IP (add|del|update)"
990                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
991                         " src (src_ip_address) dst (dst_ip_address)"
992                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
993                         " vlan (vlan_value) flexbytes (flexbytes_value)"
994                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
995                         " fd_id (fd_id_value)\n"
996                         "    Add/Del an IP type flow director filter.\n\n"
997
998                         "flow_director_filter (port_id) mode IP (add|del|update)"
999                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1000                         " src (src_ip_address) (src_port)"
1001                         " dst (dst_ip_address) (dst_port)"
1002                         " tos (tos_value) ttl (ttl_value)"
1003                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1004                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1005                         " fd_id (fd_id_value)\n"
1006                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1007
1008                         "flow_director_filter (port_id) mode IP (add|del|update)"
1009                         " flow (ipv4-sctp|ipv6-sctp)"
1010                         " src (src_ip_address) (src_port)"
1011                         " dst (dst_ip_address) (dst_port)"
1012                         " tag (verification_tag) "
1013                         " tos (tos_value) ttl (ttl_value)"
1014                         " vlan (vlan_value)"
1015                         " flexbytes (flexbytes_value) (drop|fwd)"
1016                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1017                         "    Add/Del a SCTP type flow director filter.\n\n"
1018
1019                         "flow_director_filter (port_id) mode IP (add|del|update)"
1020                         " flow l2_payload ether (ethertype)"
1021                         " flexbytes (flexbytes_value) (drop|fwd)"
1022                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1023                         "    Add/Del a l2 payload type flow director filter.\n\n"
1024
1025                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1026                         " mac (mac_address) vlan (vlan_value)"
1027                         " flexbytes (flexbytes_value) (drop|fwd)"
1028                         " queue (queue_id) fd_id (fd_id_value)\n"
1029                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1030
1031                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1032                         " mac (mac_address) vlan (vlan_value)"
1033                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1034                         " flexbytes (flexbytes_value) (drop|fwd)"
1035                         " queue (queue_id) fd_id (fd_id_value)\n"
1036                         "    Add/Del a Tunnel flow director filter.\n\n"
1037
1038                         "flow_director_filter (port_id) mode raw (add|del|update)"
1039                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1040                         " fd_id (fd_id_value) packet (packet file name)\n"
1041                         "    Add/Del a raw type flow director filter.\n\n"
1042
1043                         "flush_flow_director (port_id)\n"
1044                         "    Flush all flow director entries of a device.\n\n"
1045
1046                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1047                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1048                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1049                         "    Set flow director IP mask.\n\n"
1050
1051                         "flow_director_mask (port_id) mode MAC-VLAN"
1052                         " vlan (vlan_value)\n"
1053                         "    Set flow director MAC-VLAN mask.\n\n"
1054
1055                         "flow_director_mask (port_id) mode Tunnel"
1056                         " vlan (vlan_value) mac (mac_value)"
1057                         " tunnel-type (tunnel_type_value)"
1058                         " tunnel-id (tunnel_id_value)\n"
1059                         "    Set flow director Tunnel mask.\n\n"
1060
1061                         "flow_director_flex_mask (port_id)"
1062                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1063                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1064                         " (mask)\n"
1065                         "    Configure mask of flex payload.\n\n"
1066
1067                         "flow_director_flex_payload (port_id)"
1068                         " (raw|l2|l3|l4) (config)\n"
1069                         "    Configure flex payload selection.\n\n"
1070
1071                         "get_sym_hash_ena_per_port (port_id)\n"
1072                         "    get symmetric hash enable configuration per port.\n\n"
1073
1074                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1075                         "    set symmetric hash enable configuration per port"
1076                         " to enable or disable.\n\n"
1077
1078                         "get_hash_global_config (port_id)\n"
1079                         "    Get the global configurations of hash filters.\n\n"
1080
1081                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1082                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1083                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1084                         " (enable|disable)\n"
1085                         "    Set the global configurations of hash filters.\n\n"
1086
1087                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1088                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1089                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1090                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1091                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1092                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1093                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1094                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1095                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1096                         "fld-8th|none) (select|add)\n"
1097                         "    Set the input set for hash.\n\n"
1098
1099                         "set_fdir_input_set (port_id) "
1100                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1101                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1102                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1103                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1104                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1105                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1106                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1107                         " (select|add)\n"
1108                         "    Set the input set for FDir.\n\n"
1109
1110                         "flow validate {port_id}"
1111                         " [group {group_id}] [priority {level}]"
1112                         " [ingress] [egress]"
1113                         " pattern {item} [/ {item} [...]] / end"
1114                         " actions {action} [/ {action} [...]] / end\n"
1115                         "    Check whether a flow rule can be created.\n\n"
1116
1117                         "flow create {port_id}"
1118                         " [group {group_id}] [priority {level}]"
1119                         " [ingress] [egress]"
1120                         " pattern {item} [/ {item} [...]] / end"
1121                         " actions {action} [/ {action} [...]] / end\n"
1122                         "    Create a flow rule.\n\n"
1123
1124                         "flow destroy {port_id} rule {rule_id} [...]\n"
1125                         "    Destroy specific flow rules.\n\n"
1126
1127                         "flow flush {port_id}\n"
1128                         "    Destroy all flow rules.\n\n"
1129
1130                         "flow query {port_id} {rule_id} {action}\n"
1131                         "    Query an existing flow rule.\n\n"
1132
1133                         "flow list {port_id} [group {group_id}] [...]\n"
1134                         "    List existing flow rules sorted by priority,"
1135                         " filtered by group identifiers.\n\n"
1136
1137                         "flow isolate {port_id} {boolean}\n"
1138                         "    Restrict ingress traffic to the defined"
1139                         " flow rules\n\n"
1140                 );
1141         }
1142
1143         if (show_all || !strcmp(res->section, "traffic_management")) {
1144                 cmdline_printf(
1145                         cl,
1146                         "\n"
1147                         "Traffic Management:\n"
1148                         "--------------\n"
1149                         "show port tm cap (port_id)\n"
1150                         "       Display the port TM capability.\n\n"
1151
1152                         "show port tm level cap (port_id) (level_id)\n"
1153                         "       Display the port TM hierarchical level capability.\n\n"
1154
1155                         "show port tm node cap (port_id) (node_id)\n"
1156                         "       Display the port TM node capability.\n\n"
1157
1158                         "show port tm node type (port_id) (node_id)\n"
1159                         "       Display the port TM node type.\n\n"
1160
1161                         "show port tm node stats (port_id) (node_id) (clear)\n"
1162                         "       Display the port TM node stats.\n\n"
1163
1164 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1165                         "set port tm hierarchy default (port_id)\n"
1166                         "       Set default traffic Management hierarchy on a port\n\n"
1167 #endif
1168
1169                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1170                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1171                         " (packet_length_adjust)\n"
1172                         "       Add port tm node private shaper profile.\n\n"
1173
1174                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1175                         "       Delete port tm node private shaper profile.\n\n"
1176
1177                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1178                         " (shaper_profile_id)\n"
1179                         "       Add/update port tm node shared shaper.\n\n"
1180
1181                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1182                         "       Delete port tm node shared shaper.\n\n"
1183
1184                         "set port tm node shaper profile (port_id) (node_id)"
1185                         " (shaper_profile_id)\n"
1186                         "       Set port tm node shaper profile.\n\n"
1187
1188                         "add port tm node wred profile (port_id) (wred_profile_id)"
1189                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1190                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1191                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1192                         "       Add port tm node wred profile.\n\n"
1193
1194                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1195                         "       Delete port tm node wred profile.\n\n"
1196
1197                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1198                         " (priority) (weight) (level_id) (shaper_profile_id)"
1199                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1200                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1201                         "       Add port tm nonleaf node.\n\n"
1202
1203                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1204                         " (priority) (weight) (level_id) (shaper_profile_id)"
1205                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1206                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1207                         "       Add port tm leaf node.\n\n"
1208
1209                         "del port tm node (port_id) (node_id)\n"
1210                         "       Delete port tm node.\n\n"
1211
1212                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1213                         " (priority) (weight)\n"
1214                         "       Set port tm node parent.\n\n"
1215
1216                         "suspend port tm node (port_id) (node_id)"
1217                         "       Suspend tm node.\n\n"
1218
1219                         "resume port tm node (port_id) (node_id)"
1220                         "       Resume tm node.\n\n"
1221
1222                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1223                         "       Commit tm hierarchy.\n\n"
1224
1225                         "set port tm mark ip_ecn (port) (green) (yellow)"
1226                         " (red)\n"
1227                         "    Enables/Disables the traffic management marking"
1228                         " for IP ECN (Explicit Congestion Notification)"
1229                         " packets on a given port\n\n"
1230
1231                         "set port tm mark ip_dscp (port) (green) (yellow)"
1232                         " (red)\n"
1233                         "    Enables/Disables the traffic management marking"
1234                         " on the port for IP dscp packets\n\n"
1235
1236                         "set port tm mark vlan_dei (port) (green) (yellow)"
1237                         " (red)\n"
1238                         "    Enables/Disables the traffic management marking"
1239                         " on the port for VLAN packets with DEI enabled\n\n"
1240                 );
1241         }
1242
1243 }
1244
1245 cmdline_parse_token_string_t cmd_help_long_help =
1246         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1247
1248 cmdline_parse_token_string_t cmd_help_long_section =
1249         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1250                         "all#control#display#config#"
1251                         "ports#registers#filters#traffic_management");
1252
1253 cmdline_parse_inst_t cmd_help_long = {
1254         .f = cmd_help_long_parsed,
1255         .data = NULL,
1256         .help_str = "help all|control|display|config|ports|register|"
1257                 "filters|traffic_management: "
1258                 "Show help",
1259         .tokens = {
1260                 (void *)&cmd_help_long_help,
1261                 (void *)&cmd_help_long_section,
1262                 NULL,
1263         },
1264 };
1265
1266
1267 /* *** start/stop/close all ports *** */
1268 struct cmd_operate_port_result {
1269         cmdline_fixed_string_t keyword;
1270         cmdline_fixed_string_t name;
1271         cmdline_fixed_string_t value;
1272 };
1273
1274 static void cmd_operate_port_parsed(void *parsed_result,
1275                                 __attribute__((unused)) struct cmdline *cl,
1276                                 __attribute__((unused)) void *data)
1277 {
1278         struct cmd_operate_port_result *res = parsed_result;
1279
1280         if (!strcmp(res->name, "start"))
1281                 start_port(RTE_PORT_ALL);
1282         else if (!strcmp(res->name, "stop"))
1283                 stop_port(RTE_PORT_ALL);
1284         else if (!strcmp(res->name, "close"))
1285                 close_port(RTE_PORT_ALL);
1286         else if (!strcmp(res->name, "reset"))
1287                 reset_port(RTE_PORT_ALL);
1288         else
1289                 printf("Unknown parameter\n");
1290 }
1291
1292 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1293         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1294                                                                 "port");
1295 cmdline_parse_token_string_t cmd_operate_port_all_port =
1296         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1297                                                 "start#stop#close#reset");
1298 cmdline_parse_token_string_t cmd_operate_port_all_all =
1299         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1300
1301 cmdline_parse_inst_t cmd_operate_port = {
1302         .f = cmd_operate_port_parsed,
1303         .data = NULL,
1304         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1305         .tokens = {
1306                 (void *)&cmd_operate_port_all_cmd,
1307                 (void *)&cmd_operate_port_all_port,
1308                 (void *)&cmd_operate_port_all_all,
1309                 NULL,
1310         },
1311 };
1312
1313 /* *** start/stop/close specific port *** */
1314 struct cmd_operate_specific_port_result {
1315         cmdline_fixed_string_t keyword;
1316         cmdline_fixed_string_t name;
1317         uint8_t value;
1318 };
1319
1320 static void cmd_operate_specific_port_parsed(void *parsed_result,
1321                         __attribute__((unused)) struct cmdline *cl,
1322                                 __attribute__((unused)) void *data)
1323 {
1324         struct cmd_operate_specific_port_result *res = parsed_result;
1325
1326         if (!strcmp(res->name, "start"))
1327                 start_port(res->value);
1328         else if (!strcmp(res->name, "stop"))
1329                 stop_port(res->value);
1330         else if (!strcmp(res->name, "close"))
1331                 close_port(res->value);
1332         else if (!strcmp(res->name, "reset"))
1333                 reset_port(res->value);
1334         else
1335                 printf("Unknown parameter\n");
1336 }
1337
1338 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1339         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1340                                                         keyword, "port");
1341 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1342         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1343                                                 name, "start#stop#close#reset");
1344 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1345         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1346                                                         value, UINT8);
1347
1348 cmdline_parse_inst_t cmd_operate_specific_port = {
1349         .f = cmd_operate_specific_port_parsed,
1350         .data = NULL,
1351         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1352         .tokens = {
1353                 (void *)&cmd_operate_specific_port_cmd,
1354                 (void *)&cmd_operate_specific_port_port,
1355                 (void *)&cmd_operate_specific_port_id,
1356                 NULL,
1357         },
1358 };
1359
1360 /* *** enable port setup (after attach) via iterator or event *** */
1361 struct cmd_set_port_setup_on_result {
1362         cmdline_fixed_string_t set;
1363         cmdline_fixed_string_t port;
1364         cmdline_fixed_string_t setup;
1365         cmdline_fixed_string_t on;
1366         cmdline_fixed_string_t mode;
1367 };
1368
1369 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1370                                 __attribute__((unused)) struct cmdline *cl,
1371                                 __attribute__((unused)) void *data)
1372 {
1373         struct cmd_set_port_setup_on_result *res = parsed_result;
1374
1375         if (strcmp(res->mode, "event") == 0)
1376                 setup_on_probe_event = true;
1377         else if (strcmp(res->mode, "iterator") == 0)
1378                 setup_on_probe_event = false;
1379         else
1380                 printf("Unknown mode\n");
1381 }
1382
1383 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1384         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1385                         set, "set");
1386 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1387         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1388                         port, "port");
1389 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1390         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1391                         setup, "setup");
1392 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1393         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1394                         on, "on");
1395 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1396         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1397                         mode, "iterator#event");
1398
1399 cmdline_parse_inst_t cmd_set_port_setup_on = {
1400         .f = cmd_set_port_setup_on_parsed,
1401         .data = NULL,
1402         .help_str = "set port setup on iterator|event",
1403         .tokens = {
1404                 (void *)&cmd_set_port_setup_on_set,
1405                 (void *)&cmd_set_port_setup_on_port,
1406                 (void *)&cmd_set_port_setup_on_setup,
1407                 (void *)&cmd_set_port_setup_on_on,
1408                 (void *)&cmd_set_port_setup_on_mode,
1409                 NULL,
1410         },
1411 };
1412
1413 /* *** attach a specified port *** */
1414 struct cmd_operate_attach_port_result {
1415         cmdline_fixed_string_t port;
1416         cmdline_fixed_string_t keyword;
1417         cmdline_fixed_string_t identifier;
1418 };
1419
1420 static void cmd_operate_attach_port_parsed(void *parsed_result,
1421                                 __attribute__((unused)) struct cmdline *cl,
1422                                 __attribute__((unused)) void *data)
1423 {
1424         struct cmd_operate_attach_port_result *res = parsed_result;
1425
1426         if (!strcmp(res->keyword, "attach"))
1427                 attach_port(res->identifier);
1428         else
1429                 printf("Unknown parameter\n");
1430 }
1431
1432 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1433         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1434                         port, "port");
1435 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1436         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1437                         keyword, "attach");
1438 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1439         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1440                         identifier, NULL);
1441
1442 cmdline_parse_inst_t cmd_operate_attach_port = {
1443         .f = cmd_operate_attach_port_parsed,
1444         .data = NULL,
1445         .help_str = "port attach <identifier>: "
1446                 "(identifier: pci address or virtual dev name)",
1447         .tokens = {
1448                 (void *)&cmd_operate_attach_port_port,
1449                 (void *)&cmd_operate_attach_port_keyword,
1450                 (void *)&cmd_operate_attach_port_identifier,
1451                 NULL,
1452         },
1453 };
1454
1455 /* *** detach a specified port *** */
1456 struct cmd_operate_detach_port_result {
1457         cmdline_fixed_string_t port;
1458         cmdline_fixed_string_t keyword;
1459         portid_t port_id;
1460 };
1461
1462 static void cmd_operate_detach_port_parsed(void *parsed_result,
1463                                 __attribute__((unused)) struct cmdline *cl,
1464                                 __attribute__((unused)) void *data)
1465 {
1466         struct cmd_operate_detach_port_result *res = parsed_result;
1467
1468         if (!strcmp(res->keyword, "detach"))
1469                 detach_port_device(res->port_id);
1470         else
1471                 printf("Unknown parameter\n");
1472 }
1473
1474 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1475         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1476                         port, "port");
1477 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1478         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1479                         keyword, "detach");
1480 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1481         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1482                         port_id, UINT16);
1483
1484 cmdline_parse_inst_t cmd_operate_detach_port = {
1485         .f = cmd_operate_detach_port_parsed,
1486         .data = NULL,
1487         .help_str = "port detach <port_id>",
1488         .tokens = {
1489                 (void *)&cmd_operate_detach_port_port,
1490                 (void *)&cmd_operate_detach_port_keyword,
1491                 (void *)&cmd_operate_detach_port_port_id,
1492                 NULL,
1493         },
1494 };
1495
1496 /* *** configure speed for all ports *** */
1497 struct cmd_config_speed_all {
1498         cmdline_fixed_string_t port;
1499         cmdline_fixed_string_t keyword;
1500         cmdline_fixed_string_t all;
1501         cmdline_fixed_string_t item1;
1502         cmdline_fixed_string_t item2;
1503         cmdline_fixed_string_t value1;
1504         cmdline_fixed_string_t value2;
1505 };
1506
1507 static int
1508 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1509 {
1510
1511         int duplex;
1512
1513         if (!strcmp(duplexstr, "half")) {
1514                 duplex = ETH_LINK_HALF_DUPLEX;
1515         } else if (!strcmp(duplexstr, "full")) {
1516                 duplex = ETH_LINK_FULL_DUPLEX;
1517         } else if (!strcmp(duplexstr, "auto")) {
1518                 duplex = ETH_LINK_FULL_DUPLEX;
1519         } else {
1520                 printf("Unknown duplex parameter\n");
1521                 return -1;
1522         }
1523
1524         if (!strcmp(speedstr, "10")) {
1525                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1526                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1527         } else if (!strcmp(speedstr, "100")) {
1528                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1529                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1530         } else {
1531                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1532                         printf("Invalid speed/duplex parameters\n");
1533                         return -1;
1534                 }
1535                 if (!strcmp(speedstr, "1000")) {
1536                         *speed = ETH_LINK_SPEED_1G;
1537                 } else if (!strcmp(speedstr, "10000")) {
1538                         *speed = ETH_LINK_SPEED_10G;
1539                 } else if (!strcmp(speedstr, "25000")) {
1540                         *speed = ETH_LINK_SPEED_25G;
1541                 } else if (!strcmp(speedstr, "40000")) {
1542                         *speed = ETH_LINK_SPEED_40G;
1543                 } else if (!strcmp(speedstr, "50000")) {
1544                         *speed = ETH_LINK_SPEED_50G;
1545                 } else if (!strcmp(speedstr, "100000")) {
1546                         *speed = ETH_LINK_SPEED_100G;
1547                 } else if (!strcmp(speedstr, "auto")) {
1548                         *speed = ETH_LINK_SPEED_AUTONEG;
1549                 } else {
1550                         printf("Unknown speed parameter\n");
1551                         return -1;
1552                 }
1553         }
1554
1555         return 0;
1556 }
1557
1558 static void
1559 cmd_config_speed_all_parsed(void *parsed_result,
1560                         __attribute__((unused)) struct cmdline *cl,
1561                         __attribute__((unused)) void *data)
1562 {
1563         struct cmd_config_speed_all *res = parsed_result;
1564         uint32_t link_speed;
1565         portid_t pid;
1566
1567         if (!all_ports_stopped()) {
1568                 printf("Please stop all ports first\n");
1569                 return;
1570         }
1571
1572         if (parse_and_check_speed_duplex(res->value1, res->value2,
1573                         &link_speed) < 0)
1574                 return;
1575
1576         RTE_ETH_FOREACH_DEV(pid) {
1577                 ports[pid].dev_conf.link_speeds = link_speed;
1578         }
1579
1580         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1581 }
1582
1583 cmdline_parse_token_string_t cmd_config_speed_all_port =
1584         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1585 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1586         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1587                                                         "config");
1588 cmdline_parse_token_string_t cmd_config_speed_all_all =
1589         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1590 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1591         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1592 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1593         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1594                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1595 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1596         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1597 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1598         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1599                                                 "half#full#auto");
1600
1601 cmdline_parse_inst_t cmd_config_speed_all = {
1602         .f = cmd_config_speed_all_parsed,
1603         .data = NULL,
1604         .help_str = "port config all speed "
1605                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1606                                                         "half|full|auto",
1607         .tokens = {
1608                 (void *)&cmd_config_speed_all_port,
1609                 (void *)&cmd_config_speed_all_keyword,
1610                 (void *)&cmd_config_speed_all_all,
1611                 (void *)&cmd_config_speed_all_item1,
1612                 (void *)&cmd_config_speed_all_value1,
1613                 (void *)&cmd_config_speed_all_item2,
1614                 (void *)&cmd_config_speed_all_value2,
1615                 NULL,
1616         },
1617 };
1618
1619 /* *** configure speed for specific port *** */
1620 struct cmd_config_speed_specific {
1621         cmdline_fixed_string_t port;
1622         cmdline_fixed_string_t keyword;
1623         portid_t id;
1624         cmdline_fixed_string_t item1;
1625         cmdline_fixed_string_t item2;
1626         cmdline_fixed_string_t value1;
1627         cmdline_fixed_string_t value2;
1628 };
1629
1630 static void
1631 cmd_config_speed_specific_parsed(void *parsed_result,
1632                                 __attribute__((unused)) struct cmdline *cl,
1633                                 __attribute__((unused)) void *data)
1634 {
1635         struct cmd_config_speed_specific *res = parsed_result;
1636         uint32_t link_speed;
1637
1638         if (!all_ports_stopped()) {
1639                 printf("Please stop all ports first\n");
1640                 return;
1641         }
1642
1643         if (port_id_is_invalid(res->id, ENABLED_WARN))
1644                 return;
1645
1646         if (parse_and_check_speed_duplex(res->value1, res->value2,
1647                         &link_speed) < 0)
1648                 return;
1649
1650         ports[res->id].dev_conf.link_speeds = link_speed;
1651
1652         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1653 }
1654
1655
1656 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1657         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1658                                                                 "port");
1659 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1660         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1661                                                                 "config");
1662 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1663         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1664 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1666                                                                 "speed");
1667 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1668         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1669                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1670 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1671         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1672                                                                 "duplex");
1673 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1675                                                         "half#full#auto");
1676
1677 cmdline_parse_inst_t cmd_config_speed_specific = {
1678         .f = cmd_config_speed_specific_parsed,
1679         .data = NULL,
1680         .help_str = "port config <port_id> speed "
1681                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1682                                                         "half|full|auto",
1683         .tokens = {
1684                 (void *)&cmd_config_speed_specific_port,
1685                 (void *)&cmd_config_speed_specific_keyword,
1686                 (void *)&cmd_config_speed_specific_id,
1687                 (void *)&cmd_config_speed_specific_item1,
1688                 (void *)&cmd_config_speed_specific_value1,
1689                 (void *)&cmd_config_speed_specific_item2,
1690                 (void *)&cmd_config_speed_specific_value2,
1691                 NULL,
1692         },
1693 };
1694
1695 /* *** configure loopback for all ports *** */
1696 struct cmd_config_loopback_all {
1697         cmdline_fixed_string_t port;
1698         cmdline_fixed_string_t keyword;
1699         cmdline_fixed_string_t all;
1700         cmdline_fixed_string_t item;
1701         uint32_t mode;
1702 };
1703
1704 static void
1705 cmd_config_loopback_all_parsed(void *parsed_result,
1706                         __attribute__((unused)) struct cmdline *cl,
1707                         __attribute__((unused)) void *data)
1708 {
1709         struct cmd_config_loopback_all *res = parsed_result;
1710         portid_t pid;
1711
1712         if (!all_ports_stopped()) {
1713                 printf("Please stop all ports first\n");
1714                 return;
1715         }
1716
1717         RTE_ETH_FOREACH_DEV(pid) {
1718                 ports[pid].dev_conf.lpbk_mode = res->mode;
1719         }
1720
1721         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1722 }
1723
1724 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1725         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1726 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1727         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1728                                                         "config");
1729 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1730         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1731 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1733                                                         "loopback");
1734 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1735         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1736
1737 cmdline_parse_inst_t cmd_config_loopback_all = {
1738         .f = cmd_config_loopback_all_parsed,
1739         .data = NULL,
1740         .help_str = "port config all loopback <mode>",
1741         .tokens = {
1742                 (void *)&cmd_config_loopback_all_port,
1743                 (void *)&cmd_config_loopback_all_keyword,
1744                 (void *)&cmd_config_loopback_all_all,
1745                 (void *)&cmd_config_loopback_all_item,
1746                 (void *)&cmd_config_loopback_all_mode,
1747                 NULL,
1748         },
1749 };
1750
1751 /* *** configure loopback for specific port *** */
1752 struct cmd_config_loopback_specific {
1753         cmdline_fixed_string_t port;
1754         cmdline_fixed_string_t keyword;
1755         uint16_t port_id;
1756         cmdline_fixed_string_t item;
1757         uint32_t mode;
1758 };
1759
1760 static void
1761 cmd_config_loopback_specific_parsed(void *parsed_result,
1762                                 __attribute__((unused)) struct cmdline *cl,
1763                                 __attribute__((unused)) void *data)
1764 {
1765         struct cmd_config_loopback_specific *res = parsed_result;
1766
1767         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1768                 return;
1769
1770         if (!port_is_stopped(res->port_id)) {
1771                 printf("Please stop port %u first\n", res->port_id);
1772                 return;
1773         }
1774
1775         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1776
1777         cmd_reconfig_device_queue(res->port_id, 1, 1);
1778 }
1779
1780
1781 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1782         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1783                                                                 "port");
1784 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1785         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1786                                                                 "config");
1787 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1788         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1789                                                                 UINT16);
1790 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1792                                                                 "loopback");
1793 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1794         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1795                               UINT32);
1796
1797 cmdline_parse_inst_t cmd_config_loopback_specific = {
1798         .f = cmd_config_loopback_specific_parsed,
1799         .data = NULL,
1800         .help_str = "port config <port_id> loopback <mode>",
1801         .tokens = {
1802                 (void *)&cmd_config_loopback_specific_port,
1803                 (void *)&cmd_config_loopback_specific_keyword,
1804                 (void *)&cmd_config_loopback_specific_id,
1805                 (void *)&cmd_config_loopback_specific_item,
1806                 (void *)&cmd_config_loopback_specific_mode,
1807                 NULL,
1808         },
1809 };
1810
1811 /* *** configure txq/rxq, txd/rxd *** */
1812 struct cmd_config_rx_tx {
1813         cmdline_fixed_string_t port;
1814         cmdline_fixed_string_t keyword;
1815         cmdline_fixed_string_t all;
1816         cmdline_fixed_string_t name;
1817         uint16_t value;
1818 };
1819
1820 static void
1821 cmd_config_rx_tx_parsed(void *parsed_result,
1822                         __attribute__((unused)) struct cmdline *cl,
1823                         __attribute__((unused)) void *data)
1824 {
1825         struct cmd_config_rx_tx *res = parsed_result;
1826
1827         if (!all_ports_stopped()) {
1828                 printf("Please stop all ports first\n");
1829                 return;
1830         }
1831         if (!strcmp(res->name, "rxq")) {
1832                 if (!res->value && !nb_txq) {
1833                         printf("Warning: Either rx or tx queues should be non zero\n");
1834                         return;
1835                 }
1836                 if (check_nb_rxq(res->value) != 0)
1837                         return;
1838                 nb_rxq = res->value;
1839         }
1840         else if (!strcmp(res->name, "txq")) {
1841                 if (!res->value && !nb_rxq) {
1842                         printf("Warning: Either rx or tx queues should be non zero\n");
1843                         return;
1844                 }
1845                 if (check_nb_txq(res->value) != 0)
1846                         return;
1847                 nb_txq = res->value;
1848         }
1849         else if (!strcmp(res->name, "rxd")) {
1850                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1851                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1852                                         res->value, RTE_TEST_RX_DESC_MAX);
1853                         return;
1854                 }
1855                 nb_rxd = res->value;
1856         } else if (!strcmp(res->name, "txd")) {
1857                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1858                         printf("txd %d invalid - must be > 0 && <= %d\n",
1859                                         res->value, RTE_TEST_TX_DESC_MAX);
1860                         return;
1861                 }
1862                 nb_txd = res->value;
1863         } else {
1864                 printf("Unknown parameter\n");
1865                 return;
1866         }
1867
1868         fwd_config_setup();
1869
1870         init_port_config();
1871
1872         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1873 }
1874
1875 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1876         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1877 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1878         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1879 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1880         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1881 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1882         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1883                                                 "rxq#txq#rxd#txd");
1884 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1885         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1886
1887 cmdline_parse_inst_t cmd_config_rx_tx = {
1888         .f = cmd_config_rx_tx_parsed,
1889         .data = NULL,
1890         .help_str = "port config all rxq|txq|rxd|txd <value>",
1891         .tokens = {
1892                 (void *)&cmd_config_rx_tx_port,
1893                 (void *)&cmd_config_rx_tx_keyword,
1894                 (void *)&cmd_config_rx_tx_all,
1895                 (void *)&cmd_config_rx_tx_name,
1896                 (void *)&cmd_config_rx_tx_value,
1897                 NULL,
1898         },
1899 };
1900
1901 /* *** config max packet length *** */
1902 struct cmd_config_max_pkt_len_result {
1903         cmdline_fixed_string_t port;
1904         cmdline_fixed_string_t keyword;
1905         cmdline_fixed_string_t all;
1906         cmdline_fixed_string_t name;
1907         uint32_t value;
1908 };
1909
1910 static void
1911 cmd_config_max_pkt_len_parsed(void *parsed_result,
1912                                 __attribute__((unused)) struct cmdline *cl,
1913                                 __attribute__((unused)) void *data)
1914 {
1915         struct cmd_config_max_pkt_len_result *res = parsed_result;
1916         portid_t pid;
1917
1918         if (!all_ports_stopped()) {
1919                 printf("Please stop all ports first\n");
1920                 return;
1921         }
1922
1923         RTE_ETH_FOREACH_DEV(pid) {
1924                 struct rte_port *port = &ports[pid];
1925                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1926
1927                 if (!strcmp(res->name, "max-pkt-len")) {
1928                         if (res->value < ETHER_MIN_LEN) {
1929                                 printf("max-pkt-len can not be less than %d\n",
1930                                                 ETHER_MIN_LEN);
1931                                 return;
1932                         }
1933                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1934                                 return;
1935
1936                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1937                         if (res->value > ETHER_MAX_LEN)
1938                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1939                         else
1940                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1941                         port->dev_conf.rxmode.offloads = rx_offloads;
1942                 } else {
1943                         printf("Unknown parameter\n");
1944                         return;
1945                 }
1946         }
1947
1948         init_port_config();
1949
1950         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1951 }
1952
1953 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1954         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1955                                                                 "port");
1956 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1957         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1958                                                                 "config");
1959 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1960         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1961                                                                 "all");
1962 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1963         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1964                                                                 "max-pkt-len");
1965 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1966         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1967                                                                 UINT32);
1968
1969 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1970         .f = cmd_config_max_pkt_len_parsed,
1971         .data = NULL,
1972         .help_str = "port config all max-pkt-len <value>",
1973         .tokens = {
1974                 (void *)&cmd_config_max_pkt_len_port,
1975                 (void *)&cmd_config_max_pkt_len_keyword,
1976                 (void *)&cmd_config_max_pkt_len_all,
1977                 (void *)&cmd_config_max_pkt_len_name,
1978                 (void *)&cmd_config_max_pkt_len_value,
1979                 NULL,
1980         },
1981 };
1982
1983 /* *** configure port MTU *** */
1984 struct cmd_config_mtu_result {
1985         cmdline_fixed_string_t port;
1986         cmdline_fixed_string_t keyword;
1987         cmdline_fixed_string_t mtu;
1988         portid_t port_id;
1989         uint16_t value;
1990 };
1991
1992 static void
1993 cmd_config_mtu_parsed(void *parsed_result,
1994                       __attribute__((unused)) struct cmdline *cl,
1995                       __attribute__((unused)) void *data)
1996 {
1997         struct cmd_config_mtu_result *res = parsed_result;
1998
1999         if (res->value < ETHER_MIN_LEN) {
2000                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
2001                 return;
2002         }
2003         port_mtu_set(res->port_id, res->value);
2004 }
2005
2006 cmdline_parse_token_string_t cmd_config_mtu_port =
2007         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2008                                  "port");
2009 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2010         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2011                                  "config");
2012 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2013         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2014                                  "mtu");
2015 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2016         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2017 cmdline_parse_token_num_t cmd_config_mtu_value =
2018         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2019
2020 cmdline_parse_inst_t cmd_config_mtu = {
2021         .f = cmd_config_mtu_parsed,
2022         .data = NULL,
2023         .help_str = "port config mtu <port_id> <value>",
2024         .tokens = {
2025                 (void *)&cmd_config_mtu_port,
2026                 (void *)&cmd_config_mtu_keyword,
2027                 (void *)&cmd_config_mtu_mtu,
2028                 (void *)&cmd_config_mtu_port_id,
2029                 (void *)&cmd_config_mtu_value,
2030                 NULL,
2031         },
2032 };
2033
2034 /* *** configure rx mode *** */
2035 struct cmd_config_rx_mode_flag {
2036         cmdline_fixed_string_t port;
2037         cmdline_fixed_string_t keyword;
2038         cmdline_fixed_string_t all;
2039         cmdline_fixed_string_t name;
2040         cmdline_fixed_string_t value;
2041 };
2042
2043 static void
2044 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2045                                 __attribute__((unused)) struct cmdline *cl,
2046                                 __attribute__((unused)) void *data)
2047 {
2048         struct cmd_config_rx_mode_flag *res = parsed_result;
2049         portid_t pid;
2050
2051         if (!all_ports_stopped()) {
2052                 printf("Please stop all ports first\n");
2053                 return;
2054         }
2055
2056         RTE_ETH_FOREACH_DEV(pid) {
2057                 struct rte_port *port;
2058                 uint64_t rx_offloads;
2059
2060                 port = &ports[pid];
2061                 rx_offloads = port->dev_conf.rxmode.offloads;
2062                 if (!strcmp(res->name, "crc-strip")) {
2063                         if (!strcmp(res->value, "on")) {
2064                                 rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
2065                         } else if (!strcmp(res->value, "off")) {
2066                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
2067                         } else {
2068                                 printf("Unknown parameter\n");
2069                                 return;
2070                         }
2071                 } else if (!strcmp(res->name, "scatter")) {
2072                         if (!strcmp(res->value, "on")) {
2073                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
2074                         } else if (!strcmp(res->value, "off")) {
2075                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
2076                         } else {
2077                                 printf("Unknown parameter\n");
2078                                 return;
2079                         }
2080                 } else if (!strcmp(res->name, "rx-cksum")) {
2081                         if (!strcmp(res->value, "on"))
2082                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
2083                         else if (!strcmp(res->value, "off"))
2084                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
2085                         else {
2086                                 printf("Unknown parameter\n");
2087                                 return;
2088                         }
2089                 } else if (!strcmp(res->name, "rx-timestamp")) {
2090                         if (!strcmp(res->value, "on"))
2091                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
2092                         else if (!strcmp(res->value, "off"))
2093                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
2094                         else {
2095                                 printf("Unknown parameter\n");
2096                                 return;
2097                         }
2098                 } else if (!strcmp(res->name, "hw-vlan")) {
2099                         if (!strcmp(res->value, "on")) {
2100                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
2101                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2102                         } else if (!strcmp(res->value, "off")) {
2103                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
2104                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2105                         } else {
2106                                 printf("Unknown parameter\n");
2107                                 return;
2108                         }
2109                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
2110                         if (!strcmp(res->value, "on"))
2111                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2112                         else if (!strcmp(res->value, "off"))
2113                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2114                         else {
2115                                 printf("Unknown parameter\n");
2116                                 return;
2117                         }
2118                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
2119                         if (!strcmp(res->value, "on"))
2120                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2121                         else if (!strcmp(res->value, "off"))
2122                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2123                         else {
2124                                 printf("Unknown parameter\n");
2125                                 return;
2126                         }
2127                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
2128                         if (!strcmp(res->value, "on"))
2129                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2130                         else if (!strcmp(res->value, "off"))
2131                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2132                         else {
2133                                 printf("Unknown parameter\n");
2134                                 return;
2135                         }
2136                 } else if (!strcmp(res->name, "drop-en")) {
2137                         if (!strcmp(res->value, "on"))
2138                                 rx_drop_en = 1;
2139                         else if (!strcmp(res->value, "off"))
2140                                 rx_drop_en = 0;
2141                         else {
2142                                 printf("Unknown parameter\n");
2143                                 return;
2144                         }
2145                 } else {
2146                         printf("Unknown parameter\n");
2147                         return;
2148                 }
2149                 port->dev_conf.rxmode.offloads = rx_offloads;
2150         }
2151
2152         init_port_config();
2153
2154         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2155 }
2156
2157 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2158         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2159 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2160         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2161                                                                 "config");
2162 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2163         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2164 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2165         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2166                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2167                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2168 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2169         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2170                                                         "on#off");
2171
2172 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2173         .f = cmd_config_rx_mode_flag_parsed,
2174         .data = NULL,
2175         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2176                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2177         .tokens = {
2178                 (void *)&cmd_config_rx_mode_flag_port,
2179                 (void *)&cmd_config_rx_mode_flag_keyword,
2180                 (void *)&cmd_config_rx_mode_flag_all,
2181                 (void *)&cmd_config_rx_mode_flag_name,
2182                 (void *)&cmd_config_rx_mode_flag_value,
2183                 NULL,
2184         },
2185 };
2186
2187 /* *** configure rss *** */
2188 struct cmd_config_rss {
2189         cmdline_fixed_string_t port;
2190         cmdline_fixed_string_t keyword;
2191         cmdline_fixed_string_t all;
2192         cmdline_fixed_string_t name;
2193         cmdline_fixed_string_t value;
2194 };
2195
2196 static void
2197 cmd_config_rss_parsed(void *parsed_result,
2198                         __attribute__((unused)) struct cmdline *cl,
2199                         __attribute__((unused)) void *data)
2200 {
2201         struct cmd_config_rss *res = parsed_result;
2202         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2203         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2204         int use_default = 0;
2205         int all_updated = 1;
2206         int diag;
2207         uint16_t i;
2208
2209         if (!strcmp(res->value, "all"))
2210                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2211                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2212                                         ETH_RSS_L2_PAYLOAD;
2213         else if (!strcmp(res->value, "ip"))
2214                 rss_conf.rss_hf = ETH_RSS_IP;
2215         else if (!strcmp(res->value, "udp"))
2216                 rss_conf.rss_hf = ETH_RSS_UDP;
2217         else if (!strcmp(res->value, "tcp"))
2218                 rss_conf.rss_hf = ETH_RSS_TCP;
2219         else if (!strcmp(res->value, "sctp"))
2220                 rss_conf.rss_hf = ETH_RSS_SCTP;
2221         else if (!strcmp(res->value, "ether"))
2222                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2223         else if (!strcmp(res->value, "port"))
2224                 rss_conf.rss_hf = ETH_RSS_PORT;
2225         else if (!strcmp(res->value, "vxlan"))
2226                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2227         else if (!strcmp(res->value, "geneve"))
2228                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2229         else if (!strcmp(res->value, "nvgre"))
2230                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2231         else if (!strcmp(res->value, "none"))
2232                 rss_conf.rss_hf = 0;
2233         else if (!strcmp(res->value, "default"))
2234                 use_default = 1;
2235         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2236                                                 atoi(res->value) < 64)
2237                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2238         else {
2239                 printf("Unknown parameter\n");
2240                 return;
2241         }
2242         rss_conf.rss_key = NULL;
2243         /* Update global configuration for RSS types. */
2244         RTE_ETH_FOREACH_DEV(i) {
2245                 struct rte_eth_rss_conf local_rss_conf;
2246
2247                 rte_eth_dev_info_get(i, &dev_info);
2248                 if (use_default)
2249                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2250
2251                 local_rss_conf = rss_conf;
2252                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2253                         dev_info.flow_type_rss_offloads;
2254                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2255                         printf("Port %u modified RSS hash function based on hardware support,"
2256                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2257                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2258                 }
2259                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2260                 if (diag < 0) {
2261                         all_updated = 0;
2262                         printf("Configuration of RSS hash at ethernet port %d "
2263                                 "failed with error (%d): %s.\n",
2264                                 i, -diag, strerror(-diag));
2265                 }
2266         }
2267         if (all_updated && !use_default)
2268                 rss_hf = rss_conf.rss_hf;
2269 }
2270
2271 cmdline_parse_token_string_t cmd_config_rss_port =
2272         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2273 cmdline_parse_token_string_t cmd_config_rss_keyword =
2274         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2275 cmdline_parse_token_string_t cmd_config_rss_all =
2276         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2277 cmdline_parse_token_string_t cmd_config_rss_name =
2278         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2279 cmdline_parse_token_string_t cmd_config_rss_value =
2280         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2281
2282 cmdline_parse_inst_t cmd_config_rss = {
2283         .f = cmd_config_rss_parsed,
2284         .data = NULL,
2285         .help_str = "port config all rss "
2286                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2287         .tokens = {
2288                 (void *)&cmd_config_rss_port,
2289                 (void *)&cmd_config_rss_keyword,
2290                 (void *)&cmd_config_rss_all,
2291                 (void *)&cmd_config_rss_name,
2292                 (void *)&cmd_config_rss_value,
2293                 NULL,
2294         },
2295 };
2296
2297 /* *** configure rss hash key *** */
2298 struct cmd_config_rss_hash_key {
2299         cmdline_fixed_string_t port;
2300         cmdline_fixed_string_t config;
2301         portid_t port_id;
2302         cmdline_fixed_string_t rss_hash_key;
2303         cmdline_fixed_string_t rss_type;
2304         cmdline_fixed_string_t key;
2305 };
2306
2307 static uint8_t
2308 hexa_digit_to_value(char hexa_digit)
2309 {
2310         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2311                 return (uint8_t) (hexa_digit - '0');
2312         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2313                 return (uint8_t) ((hexa_digit - 'a') + 10);
2314         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2315                 return (uint8_t) ((hexa_digit - 'A') + 10);
2316         /* Invalid hexa digit */
2317         return 0xFF;
2318 }
2319
2320 static uint8_t
2321 parse_and_check_key_hexa_digit(char *key, int idx)
2322 {
2323         uint8_t hexa_v;
2324
2325         hexa_v = hexa_digit_to_value(key[idx]);
2326         if (hexa_v == 0xFF)
2327                 printf("invalid key: character %c at position %d is not a "
2328                        "valid hexa digit\n", key[idx], idx);
2329         return hexa_v;
2330 }
2331
2332 static void
2333 cmd_config_rss_hash_key_parsed(void *parsed_result,
2334                                __attribute__((unused)) struct cmdline *cl,
2335                                __attribute__((unused)) void *data)
2336 {
2337         struct cmd_config_rss_hash_key *res = parsed_result;
2338         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2339         uint8_t xdgt0;
2340         uint8_t xdgt1;
2341         int i;
2342         struct rte_eth_dev_info dev_info;
2343         uint8_t hash_key_size;
2344         uint32_t key_len;
2345
2346         memset(&dev_info, 0, sizeof(dev_info));
2347         rte_eth_dev_info_get(res->port_id, &dev_info);
2348         if (dev_info.hash_key_size > 0 &&
2349                         dev_info.hash_key_size <= sizeof(hash_key))
2350                 hash_key_size = dev_info.hash_key_size;
2351         else {
2352                 printf("dev_info did not provide a valid hash key size\n");
2353                 return;
2354         }
2355         /* Check the length of the RSS hash key */
2356         key_len = strlen(res->key);
2357         if (key_len != (hash_key_size * 2)) {
2358                 printf("key length: %d invalid - key must be a string of %d"
2359                            " hexa-decimal numbers\n",
2360                            (int) key_len, hash_key_size * 2);
2361                 return;
2362         }
2363         /* Translate RSS hash key into binary representation */
2364         for (i = 0; i < hash_key_size; i++) {
2365                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2366                 if (xdgt0 == 0xFF)
2367                         return;
2368                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2369                 if (xdgt1 == 0xFF)
2370                         return;
2371                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2372         }
2373         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2374                         hash_key_size);
2375 }
2376
2377 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2378         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2379 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2380         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2381                                  "config");
2382 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2383         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2384 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2385         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2386                                  rss_hash_key, "rss-hash-key");
2387 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2388         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2389                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2390                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2391                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2392                                  "ipv6-tcp-ex#ipv6-udp-ex");
2393 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2394         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2395
2396 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2397         .f = cmd_config_rss_hash_key_parsed,
2398         .data = NULL,
2399         .help_str = "port config <port_id> rss-hash-key "
2400                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2401                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2402                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2403                 "<string of hex digits (variable length, NIC dependent)>",
2404         .tokens = {
2405                 (void *)&cmd_config_rss_hash_key_port,
2406                 (void *)&cmd_config_rss_hash_key_config,
2407                 (void *)&cmd_config_rss_hash_key_port_id,
2408                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2409                 (void *)&cmd_config_rss_hash_key_rss_type,
2410                 (void *)&cmd_config_rss_hash_key_value,
2411                 NULL,
2412         },
2413 };
2414
2415 /* *** configure port rxq/txq ring size *** */
2416 struct cmd_config_rxtx_ring_size {
2417         cmdline_fixed_string_t port;
2418         cmdline_fixed_string_t config;
2419         portid_t portid;
2420         cmdline_fixed_string_t rxtxq;
2421         uint16_t qid;
2422         cmdline_fixed_string_t rsize;
2423         uint16_t size;
2424 };
2425
2426 static void
2427 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2428                                  __attribute__((unused)) struct cmdline *cl,
2429                                  __attribute__((unused)) void *data)
2430 {
2431         struct cmd_config_rxtx_ring_size *res = parsed_result;
2432         struct rte_port *port;
2433         uint8_t isrx;
2434
2435         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2436                 return;
2437
2438         if (res->portid == (portid_t)RTE_PORT_ALL) {
2439                 printf("Invalid port id\n");
2440                 return;
2441         }
2442
2443         port = &ports[res->portid];
2444
2445         if (!strcmp(res->rxtxq, "rxq"))
2446                 isrx = 1;
2447         else if (!strcmp(res->rxtxq, "txq"))
2448                 isrx = 0;
2449         else {
2450                 printf("Unknown parameter\n");
2451                 return;
2452         }
2453
2454         if (isrx && rx_queue_id_is_invalid(res->qid))
2455                 return;
2456         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2457                 return;
2458
2459         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2460                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2461                        rx_free_thresh);
2462                 return;
2463         }
2464
2465         if (isrx)
2466                 port->nb_rx_desc[res->qid] = res->size;
2467         else
2468                 port->nb_tx_desc[res->qid] = res->size;
2469
2470         cmd_reconfig_device_queue(res->portid, 0, 1);
2471 }
2472
2473 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2474         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2475                                  port, "port");
2476 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2477         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2478                                  config, "config");
2479 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2480         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2481                                  portid, UINT16);
2482 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2483         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2484                                  rxtxq, "rxq#txq");
2485 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2486         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2487                               qid, UINT16);
2488 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2489         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2490                                  rsize, "ring_size");
2491 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2492         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2493                               size, UINT16);
2494
2495 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2496         .f = cmd_config_rxtx_ring_size_parsed,
2497         .data = NULL,
2498         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2499         .tokens = {
2500                 (void *)&cmd_config_rxtx_ring_size_port,
2501                 (void *)&cmd_config_rxtx_ring_size_config,
2502                 (void *)&cmd_config_rxtx_ring_size_portid,
2503                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2504                 (void *)&cmd_config_rxtx_ring_size_qid,
2505                 (void *)&cmd_config_rxtx_ring_size_rsize,
2506                 (void *)&cmd_config_rxtx_ring_size_size,
2507                 NULL,
2508         },
2509 };
2510
2511 /* *** configure port rxq/txq start/stop *** */
2512 struct cmd_config_rxtx_queue {
2513         cmdline_fixed_string_t port;
2514         portid_t portid;
2515         cmdline_fixed_string_t rxtxq;
2516         uint16_t qid;
2517         cmdline_fixed_string_t opname;
2518 };
2519
2520 static void
2521 cmd_config_rxtx_queue_parsed(void *parsed_result,
2522                         __attribute__((unused)) struct cmdline *cl,
2523                         __attribute__((unused)) void *data)
2524 {
2525         struct cmd_config_rxtx_queue *res = parsed_result;
2526         uint8_t isrx;
2527         uint8_t isstart;
2528         int ret = 0;
2529
2530         if (test_done == 0) {
2531                 printf("Please stop forwarding first\n");
2532                 return;
2533         }
2534
2535         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2536                 return;
2537
2538         if (port_is_started(res->portid) != 1) {
2539                 printf("Please start port %u first\n", res->portid);
2540                 return;
2541         }
2542
2543         if (!strcmp(res->rxtxq, "rxq"))
2544                 isrx = 1;
2545         else if (!strcmp(res->rxtxq, "txq"))
2546                 isrx = 0;
2547         else {
2548                 printf("Unknown parameter\n");
2549                 return;
2550         }
2551
2552         if (isrx && rx_queue_id_is_invalid(res->qid))
2553                 return;
2554         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2555                 return;
2556
2557         if (!strcmp(res->opname, "start"))
2558                 isstart = 1;
2559         else if (!strcmp(res->opname, "stop"))
2560                 isstart = 0;
2561         else {
2562                 printf("Unknown parameter\n");
2563                 return;
2564         }
2565
2566         if (isstart && isrx)
2567                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2568         else if (!isstart && isrx)
2569                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2570         else if (isstart && !isrx)
2571                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2572         else
2573                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2574
2575         if (ret == -ENOTSUP)
2576                 printf("Function not supported in PMD driver\n");
2577 }
2578
2579 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2580         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2581 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2582         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2583 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2584         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2585 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2586         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2587 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2588         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2589                                                 "start#stop");
2590
2591 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2592         .f = cmd_config_rxtx_queue_parsed,
2593         .data = NULL,
2594         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2595         .tokens = {
2596                 (void *)&cmd_config_rxtx_queue_port,
2597                 (void *)&cmd_config_rxtx_queue_portid,
2598                 (void *)&cmd_config_rxtx_queue_rxtxq,
2599                 (void *)&cmd_config_rxtx_queue_qid,
2600                 (void *)&cmd_config_rxtx_queue_opname,
2601                 NULL,
2602         },
2603 };
2604
2605 /* *** configure port rxq/txq deferred start on/off *** */
2606 struct cmd_config_deferred_start_rxtx_queue {
2607         cmdline_fixed_string_t port;
2608         portid_t port_id;
2609         cmdline_fixed_string_t rxtxq;
2610         uint16_t qid;
2611         cmdline_fixed_string_t opname;
2612         cmdline_fixed_string_t state;
2613 };
2614
2615 static void
2616 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2617                         __attribute__((unused)) struct cmdline *cl,
2618                         __attribute__((unused)) void *data)
2619 {
2620         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2621         struct rte_port *port;
2622         uint8_t isrx;
2623         uint8_t ison;
2624         uint8_t needreconfig = 0;
2625
2626         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2627                 return;
2628
2629         if (port_is_started(res->port_id) != 0) {
2630                 printf("Please stop port %u first\n", res->port_id);
2631                 return;
2632         }
2633
2634         port = &ports[res->port_id];
2635
2636         isrx = !strcmp(res->rxtxq, "rxq");
2637
2638         if (isrx && rx_queue_id_is_invalid(res->qid))
2639                 return;
2640         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2641                 return;
2642
2643         ison = !strcmp(res->state, "on");
2644
2645         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2646                 port->rx_conf[res->qid].rx_deferred_start = ison;
2647                 needreconfig = 1;
2648         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2649                 port->tx_conf[res->qid].tx_deferred_start = ison;
2650                 needreconfig = 1;
2651         }
2652
2653         if (needreconfig)
2654                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2655 }
2656
2657 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2658         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2659                                                 port, "port");
2660 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2661         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2662                                                 port_id, UINT16);
2663 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2664         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2665                                                 rxtxq, "rxq#txq");
2666 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2667         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2668                                                 qid, UINT16);
2669 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2670         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2671                                                 opname, "deferred_start");
2672 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2673         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2674                                                 state, "on#off");
2675
2676 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2677         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2678         .data = NULL,
2679         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2680         .tokens = {
2681                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2682                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2683                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2684                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2685                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2686                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2687                 NULL,
2688         },
2689 };
2690
2691 /* *** configure port rxq/txq setup *** */
2692 struct cmd_setup_rxtx_queue {
2693         cmdline_fixed_string_t port;
2694         portid_t portid;
2695         cmdline_fixed_string_t rxtxq;
2696         uint16_t qid;
2697         cmdline_fixed_string_t setup;
2698 };
2699
2700 /* Common CLI fields for queue setup */
2701 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2702         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2703 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2704         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2705 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2706         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2707 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2708         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2709 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2710         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2711
2712 static void
2713 cmd_setup_rxtx_queue_parsed(
2714         void *parsed_result,
2715         __attribute__((unused)) struct cmdline *cl,
2716         __attribute__((unused)) void *data)
2717 {
2718         struct cmd_setup_rxtx_queue *res = parsed_result;
2719         struct rte_port *port;
2720         struct rte_mempool *mp;
2721         unsigned int socket_id;
2722         uint8_t isrx = 0;
2723         int ret;
2724
2725         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2726                 return;
2727
2728         if (res->portid == (portid_t)RTE_PORT_ALL) {
2729                 printf("Invalid port id\n");
2730                 return;
2731         }
2732
2733         if (!strcmp(res->rxtxq, "rxq"))
2734                 isrx = 1;
2735         else if (!strcmp(res->rxtxq, "txq"))
2736                 isrx = 0;
2737         else {
2738                 printf("Unknown parameter\n");
2739                 return;
2740         }
2741
2742         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2743                 printf("Invalid rx queue\n");
2744                 return;
2745         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2746                 printf("Invalid tx queue\n");
2747                 return;
2748         }
2749
2750         port = &ports[res->portid];
2751         if (isrx) {
2752                 socket_id = rxring_numa[res->portid];
2753                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2754                         socket_id = port->socket_id;
2755
2756                 mp = mbuf_pool_find(socket_id);
2757                 if (mp == NULL) {
2758                         printf("Failed to setup RX queue: "
2759                                 "No mempool allocation"
2760                                 " on the socket %d\n",
2761                                 rxring_numa[res->portid]);
2762                         return;
2763                 }
2764                 ret = rte_eth_rx_queue_setup(res->portid,
2765                                              res->qid,
2766                                              port->nb_rx_desc[res->qid],
2767                                              socket_id,
2768                                              &port->rx_conf[res->qid],
2769                                              mp);
2770                 if (ret)
2771                         printf("Failed to setup RX queue\n");
2772         } else {
2773                 socket_id = txring_numa[res->portid];
2774                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2775                         socket_id = port->socket_id;
2776
2777                 ret = rte_eth_tx_queue_setup(res->portid,
2778                                              res->qid,
2779                                              port->nb_tx_desc[res->qid],
2780                                              socket_id,
2781                                              &port->tx_conf[res->qid]);
2782                 if (ret)
2783                         printf("Failed to setup TX queue\n");
2784         }
2785 }
2786
2787 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2788         .f = cmd_setup_rxtx_queue_parsed,
2789         .data = NULL,
2790         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2791         .tokens = {
2792                 (void *)&cmd_setup_rxtx_queue_port,
2793                 (void *)&cmd_setup_rxtx_queue_portid,
2794                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2795                 (void *)&cmd_setup_rxtx_queue_qid,
2796                 (void *)&cmd_setup_rxtx_queue_setup,
2797                 NULL,
2798         },
2799 };
2800
2801
2802 /* *** Configure RSS RETA *** */
2803 struct cmd_config_rss_reta {
2804         cmdline_fixed_string_t port;
2805         cmdline_fixed_string_t keyword;
2806         portid_t port_id;
2807         cmdline_fixed_string_t name;
2808         cmdline_fixed_string_t list_name;
2809         cmdline_fixed_string_t list_of_items;
2810 };
2811
2812 static int
2813 parse_reta_config(const char *str,
2814                   struct rte_eth_rss_reta_entry64 *reta_conf,
2815                   uint16_t nb_entries)
2816 {
2817         int i;
2818         unsigned size;
2819         uint16_t hash_index, idx, shift;
2820         uint16_t nb_queue;
2821         char s[256];
2822         const char *p, *p0 = str;
2823         char *end;
2824         enum fieldnames {
2825                 FLD_HASH_INDEX = 0,
2826                 FLD_QUEUE,
2827                 _NUM_FLD
2828         };
2829         unsigned long int_fld[_NUM_FLD];
2830         char *str_fld[_NUM_FLD];
2831
2832         while ((p = strchr(p0,'(')) != NULL) {
2833                 ++p;
2834                 if((p0 = strchr(p,')')) == NULL)
2835                         return -1;
2836
2837                 size = p0 - p;
2838                 if(size >= sizeof(s))
2839                         return -1;
2840
2841                 snprintf(s, sizeof(s), "%.*s", size, p);
2842                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2843                         return -1;
2844                 for (i = 0; i < _NUM_FLD; i++) {
2845                         errno = 0;
2846                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2847                         if (errno != 0 || end == str_fld[i] ||
2848                                         int_fld[i] > 65535)
2849                                 return -1;
2850                 }
2851
2852                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2853                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2854
2855                 if (hash_index >= nb_entries) {
2856                         printf("Invalid RETA hash index=%d\n", hash_index);
2857                         return -1;
2858                 }
2859
2860                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2861                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2862                 reta_conf[idx].mask |= (1ULL << shift);
2863                 reta_conf[idx].reta[shift] = nb_queue;
2864         }
2865
2866         return 0;
2867 }
2868
2869 static void
2870 cmd_set_rss_reta_parsed(void *parsed_result,
2871                         __attribute__((unused)) struct cmdline *cl,
2872                         __attribute__((unused)) void *data)
2873 {
2874         int ret;
2875         struct rte_eth_dev_info dev_info;
2876         struct rte_eth_rss_reta_entry64 reta_conf[8];
2877         struct cmd_config_rss_reta *res = parsed_result;
2878
2879         memset(&dev_info, 0, sizeof(dev_info));
2880         rte_eth_dev_info_get(res->port_id, &dev_info);
2881         if (dev_info.reta_size == 0) {
2882                 printf("Redirection table size is 0 which is "
2883                                         "invalid for RSS\n");
2884                 return;
2885         } else
2886                 printf("The reta size of port %d is %u\n",
2887                         res->port_id, dev_info.reta_size);
2888         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2889                 printf("Currently do not support more than %u entries of "
2890                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2891                 return;
2892         }
2893
2894         memset(reta_conf, 0, sizeof(reta_conf));
2895         if (!strcmp(res->list_name, "reta")) {
2896                 if (parse_reta_config(res->list_of_items, reta_conf,
2897                                                 dev_info.reta_size)) {
2898                         printf("Invalid RSS Redirection Table "
2899                                         "config entered\n");
2900                         return;
2901                 }
2902                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2903                                 reta_conf, dev_info.reta_size);
2904                 if (ret != 0)
2905                         printf("Bad redirection table parameter, "
2906                                         "return code = %d \n", ret);
2907         }
2908 }
2909
2910 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2911         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2912 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2913         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2914 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2915         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2916 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2917         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2918 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2919         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2920 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2921         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2922                                  NULL);
2923 cmdline_parse_inst_t cmd_config_rss_reta = {
2924         .f = cmd_set_rss_reta_parsed,
2925         .data = NULL,
2926         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2927         .tokens = {
2928                 (void *)&cmd_config_rss_reta_port,
2929                 (void *)&cmd_config_rss_reta_keyword,
2930                 (void *)&cmd_config_rss_reta_port_id,
2931                 (void *)&cmd_config_rss_reta_name,
2932                 (void *)&cmd_config_rss_reta_list_name,
2933                 (void *)&cmd_config_rss_reta_list_of_items,
2934                 NULL,
2935         },
2936 };
2937
2938 /* *** SHOW PORT RETA INFO *** */
2939 struct cmd_showport_reta {
2940         cmdline_fixed_string_t show;
2941         cmdline_fixed_string_t port;
2942         portid_t port_id;
2943         cmdline_fixed_string_t rss;
2944         cmdline_fixed_string_t reta;
2945         uint16_t size;
2946         cmdline_fixed_string_t list_of_items;
2947 };
2948
2949 static int
2950 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2951                            uint16_t nb_entries,
2952                            char *str)
2953 {
2954         uint32_t size;
2955         const char *p, *p0 = str;
2956         char s[256];
2957         char *end;
2958         char *str_fld[8];
2959         uint16_t i;
2960         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2961                         RTE_RETA_GROUP_SIZE;
2962         int ret;
2963
2964         p = strchr(p0, '(');
2965         if (p == NULL)
2966                 return -1;
2967         p++;
2968         p0 = strchr(p, ')');
2969         if (p0 == NULL)
2970                 return -1;
2971         size = p0 - p;
2972         if (size >= sizeof(s)) {
2973                 printf("The string size exceeds the internal buffer size\n");
2974                 return -1;
2975         }
2976         snprintf(s, sizeof(s), "%.*s", size, p);
2977         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2978         if (ret <= 0 || ret != num) {
2979                 printf("The bits of masks do not match the number of "
2980                                         "reta entries: %u\n", num);
2981                 return -1;
2982         }
2983         for (i = 0; i < ret; i++)
2984                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2985
2986         return 0;
2987 }
2988
2989 static void
2990 cmd_showport_reta_parsed(void *parsed_result,
2991                          __attribute__((unused)) struct cmdline *cl,
2992                          __attribute__((unused)) void *data)
2993 {
2994         struct cmd_showport_reta *res = parsed_result;
2995         struct rte_eth_rss_reta_entry64 reta_conf[8];
2996         struct rte_eth_dev_info dev_info;
2997         uint16_t max_reta_size;
2998
2999         memset(&dev_info, 0, sizeof(dev_info));
3000         rte_eth_dev_info_get(res->port_id, &dev_info);
3001         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3002         if (res->size == 0 || res->size > max_reta_size) {
3003                 printf("Invalid redirection table size: %u (1-%u)\n",
3004                         res->size, max_reta_size);
3005                 return;
3006         }
3007
3008         memset(reta_conf, 0, sizeof(reta_conf));
3009         if (showport_parse_reta_config(reta_conf, res->size,
3010                                 res->list_of_items) < 0) {
3011                 printf("Invalid string: %s for reta masks\n",
3012                                         res->list_of_items);
3013                 return;
3014         }
3015         port_rss_reta_info(res->port_id, reta_conf, res->size);
3016 }
3017
3018 cmdline_parse_token_string_t cmd_showport_reta_show =
3019         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3020 cmdline_parse_token_string_t cmd_showport_reta_port =
3021         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3022 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3023         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3024 cmdline_parse_token_string_t cmd_showport_reta_rss =
3025         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3026 cmdline_parse_token_string_t cmd_showport_reta_reta =
3027         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3028 cmdline_parse_token_num_t cmd_showport_reta_size =
3029         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3030 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3031         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3032                                         list_of_items, NULL);
3033
3034 cmdline_parse_inst_t cmd_showport_reta = {
3035         .f = cmd_showport_reta_parsed,
3036         .data = NULL,
3037         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3038         .tokens = {
3039                 (void *)&cmd_showport_reta_show,
3040                 (void *)&cmd_showport_reta_port,
3041                 (void *)&cmd_showport_reta_port_id,
3042                 (void *)&cmd_showport_reta_rss,
3043                 (void *)&cmd_showport_reta_reta,
3044                 (void *)&cmd_showport_reta_size,
3045                 (void *)&cmd_showport_reta_list_of_items,
3046                 NULL,
3047         },
3048 };
3049
3050 /* *** Show RSS hash configuration *** */
3051 struct cmd_showport_rss_hash {
3052         cmdline_fixed_string_t show;
3053         cmdline_fixed_string_t port;
3054         portid_t port_id;
3055         cmdline_fixed_string_t rss_hash;
3056         cmdline_fixed_string_t rss_type;
3057         cmdline_fixed_string_t key; /* optional argument */
3058 };
3059
3060 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3061                                 __attribute__((unused)) struct cmdline *cl,
3062                                 void *show_rss_key)
3063 {
3064         struct cmd_showport_rss_hash *res = parsed_result;
3065
3066         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3067 }
3068
3069 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3070         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3071 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3072         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3073 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3074         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3075 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3076         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3077                                  "rss-hash");
3078 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3079         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3080
3081 cmdline_parse_inst_t cmd_showport_rss_hash = {
3082         .f = cmd_showport_rss_hash_parsed,
3083         .data = NULL,
3084         .help_str = "show port <port_id> rss-hash",
3085         .tokens = {
3086                 (void *)&cmd_showport_rss_hash_show,
3087                 (void *)&cmd_showport_rss_hash_port,
3088                 (void *)&cmd_showport_rss_hash_port_id,
3089                 (void *)&cmd_showport_rss_hash_rss_hash,
3090                 NULL,
3091         },
3092 };
3093
3094 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3095         .f = cmd_showport_rss_hash_parsed,
3096         .data = (void *)1,
3097         .help_str = "show port <port_id> rss-hash key",
3098         .tokens = {
3099                 (void *)&cmd_showport_rss_hash_show,
3100                 (void *)&cmd_showport_rss_hash_port,
3101                 (void *)&cmd_showport_rss_hash_port_id,
3102                 (void *)&cmd_showport_rss_hash_rss_hash,
3103                 (void *)&cmd_showport_rss_hash_rss_key,
3104                 NULL,
3105         },
3106 };
3107
3108 /* *** Configure DCB *** */
3109 struct cmd_config_dcb {
3110         cmdline_fixed_string_t port;
3111         cmdline_fixed_string_t config;
3112         portid_t port_id;
3113         cmdline_fixed_string_t dcb;
3114         cmdline_fixed_string_t vt;
3115         cmdline_fixed_string_t vt_en;
3116         uint8_t num_tcs;
3117         cmdline_fixed_string_t pfc;
3118         cmdline_fixed_string_t pfc_en;
3119 };
3120
3121 static void
3122 cmd_config_dcb_parsed(void *parsed_result,
3123                         __attribute__((unused)) struct cmdline *cl,
3124                         __attribute__((unused)) void *data)
3125 {
3126         struct cmd_config_dcb *res = parsed_result;
3127         portid_t port_id = res->port_id;
3128         struct rte_port *port;
3129         uint8_t pfc_en;
3130         int ret;
3131
3132         port = &ports[port_id];
3133         /** Check if the port is not started **/
3134         if (port->port_status != RTE_PORT_STOPPED) {
3135                 printf("Please stop port %d first\n", port_id);
3136                 return;
3137         }
3138
3139         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3140                 printf("The invalid number of traffic class,"
3141                         " only 4 or 8 allowed.\n");
3142                 return;
3143         }
3144
3145         if (nb_fwd_lcores < res->num_tcs) {
3146                 printf("nb_cores shouldn't be less than number of TCs.\n");
3147                 return;
3148         }
3149         if (!strncmp(res->pfc_en, "on", 2))
3150                 pfc_en = 1;
3151         else
3152                 pfc_en = 0;
3153
3154         /* DCB in VT mode */
3155         if (!strncmp(res->vt_en, "on", 2))
3156                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3157                                 (enum rte_eth_nb_tcs)res->num_tcs,
3158                                 pfc_en);
3159         else
3160                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3161                                 (enum rte_eth_nb_tcs)res->num_tcs,
3162                                 pfc_en);
3163
3164
3165         if (ret != 0) {
3166                 printf("Cannot initialize network ports.\n");
3167                 return;
3168         }
3169
3170         cmd_reconfig_device_queue(port_id, 1, 1);
3171 }
3172
3173 cmdline_parse_token_string_t cmd_config_dcb_port =
3174         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3175 cmdline_parse_token_string_t cmd_config_dcb_config =
3176         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3177 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3178         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3179 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3180         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3181 cmdline_parse_token_string_t cmd_config_dcb_vt =
3182         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3183 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3184         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3185 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3186         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3187 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3188         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3189 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3190         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3191
3192 cmdline_parse_inst_t cmd_config_dcb = {
3193         .f = cmd_config_dcb_parsed,
3194         .data = NULL,
3195         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3196         .tokens = {
3197                 (void *)&cmd_config_dcb_port,
3198                 (void *)&cmd_config_dcb_config,
3199                 (void *)&cmd_config_dcb_port_id,
3200                 (void *)&cmd_config_dcb_dcb,
3201                 (void *)&cmd_config_dcb_vt,
3202                 (void *)&cmd_config_dcb_vt_en,
3203                 (void *)&cmd_config_dcb_num_tcs,
3204                 (void *)&cmd_config_dcb_pfc,
3205                 (void *)&cmd_config_dcb_pfc_en,
3206                 NULL,
3207         },
3208 };
3209
3210 /* *** configure number of packets per burst *** */
3211 struct cmd_config_burst {
3212         cmdline_fixed_string_t port;
3213         cmdline_fixed_string_t keyword;
3214         cmdline_fixed_string_t all;
3215         cmdline_fixed_string_t name;
3216         uint16_t value;
3217 };
3218
3219 static void
3220 cmd_config_burst_parsed(void *parsed_result,
3221                         __attribute__((unused)) struct cmdline *cl,
3222                         __attribute__((unused)) void *data)
3223 {
3224         struct cmd_config_burst *res = parsed_result;
3225         struct rte_eth_dev_info dev_info;
3226         uint16_t rec_nb_pkts;
3227
3228         if (!all_ports_stopped()) {
3229                 printf("Please stop all ports first\n");
3230                 return;
3231         }
3232
3233         if (!strcmp(res->name, "burst")) {
3234                 if (res->value == 0) {
3235                         /* If user gives a value of zero, query the PMD for
3236                          * its recommended Rx burst size. Testpmd uses a single
3237                          * size for all ports, so assume all ports are the same
3238                          * NIC model and use the values from Port 0.
3239                          */
3240                         rte_eth_dev_info_get(0, &dev_info);
3241                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3242
3243                         if (rec_nb_pkts == 0) {
3244                                 printf("PMD does not recommend a burst size.\n"
3245                                         "User provided value must be between"
3246                                         " 1 and %d\n", MAX_PKT_BURST);
3247                                 return;
3248                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3249                                 printf("PMD recommended burst size of %d"
3250                                         " exceeds maximum value of %d\n",
3251                                         rec_nb_pkts, MAX_PKT_BURST);
3252                                 return;
3253                         }
3254                         printf("Using PMD-provided burst value of %d\n",
3255                                 rec_nb_pkts);
3256                         nb_pkt_per_burst = rec_nb_pkts;
3257                 } else if (res->value > MAX_PKT_BURST) {
3258                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3259                         return;
3260                 } else
3261                         nb_pkt_per_burst = res->value;
3262         } else {
3263                 printf("Unknown parameter\n");
3264                 return;
3265         }
3266
3267         init_port_config();
3268
3269         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3270 }
3271
3272 cmdline_parse_token_string_t cmd_config_burst_port =
3273         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3274 cmdline_parse_token_string_t cmd_config_burst_keyword =
3275         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3276 cmdline_parse_token_string_t cmd_config_burst_all =
3277         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3278 cmdline_parse_token_string_t cmd_config_burst_name =
3279         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3280 cmdline_parse_token_num_t cmd_config_burst_value =
3281         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3282
3283 cmdline_parse_inst_t cmd_config_burst = {
3284         .f = cmd_config_burst_parsed,
3285         .data = NULL,
3286         .help_str = "port config all burst <value>",
3287         .tokens = {
3288                 (void *)&cmd_config_burst_port,
3289                 (void *)&cmd_config_burst_keyword,
3290                 (void *)&cmd_config_burst_all,
3291                 (void *)&cmd_config_burst_name,
3292                 (void *)&cmd_config_burst_value,
3293                 NULL,
3294         },
3295 };
3296
3297 /* *** configure rx/tx queues *** */
3298 struct cmd_config_thresh {
3299         cmdline_fixed_string_t port;
3300         cmdline_fixed_string_t keyword;
3301         cmdline_fixed_string_t all;
3302         cmdline_fixed_string_t name;
3303         uint8_t value;
3304 };
3305
3306 static void
3307 cmd_config_thresh_parsed(void *parsed_result,
3308                         __attribute__((unused)) struct cmdline *cl,
3309                         __attribute__((unused)) void *data)
3310 {
3311         struct cmd_config_thresh *res = parsed_result;
3312
3313         if (!all_ports_stopped()) {
3314                 printf("Please stop all ports first\n");
3315                 return;
3316         }
3317
3318         if (!strcmp(res->name, "txpt"))
3319                 tx_pthresh = res->value;
3320         else if(!strcmp(res->name, "txht"))
3321                 tx_hthresh = res->value;
3322         else if(!strcmp(res->name, "txwt"))
3323                 tx_wthresh = res->value;
3324         else if(!strcmp(res->name, "rxpt"))
3325                 rx_pthresh = res->value;
3326         else if(!strcmp(res->name, "rxht"))
3327                 rx_hthresh = res->value;
3328         else if(!strcmp(res->name, "rxwt"))
3329                 rx_wthresh = res->value;
3330         else {
3331                 printf("Unknown parameter\n");
3332                 return;
3333         }
3334
3335         init_port_config();
3336
3337         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3338 }
3339
3340 cmdline_parse_token_string_t cmd_config_thresh_port =
3341         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3342 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3343         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3344 cmdline_parse_token_string_t cmd_config_thresh_all =
3345         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3346 cmdline_parse_token_string_t cmd_config_thresh_name =
3347         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3348                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3349 cmdline_parse_token_num_t cmd_config_thresh_value =
3350         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3351
3352 cmdline_parse_inst_t cmd_config_thresh = {
3353         .f = cmd_config_thresh_parsed,
3354         .data = NULL,
3355         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3356         .tokens = {
3357                 (void *)&cmd_config_thresh_port,
3358                 (void *)&cmd_config_thresh_keyword,
3359                 (void *)&cmd_config_thresh_all,
3360                 (void *)&cmd_config_thresh_name,
3361                 (void *)&cmd_config_thresh_value,
3362                 NULL,
3363         },
3364 };
3365
3366 /* *** configure free/rs threshold *** */
3367 struct cmd_config_threshold {
3368         cmdline_fixed_string_t port;
3369         cmdline_fixed_string_t keyword;
3370         cmdline_fixed_string_t all;
3371         cmdline_fixed_string_t name;
3372         uint16_t value;
3373 };
3374
3375 static void
3376 cmd_config_threshold_parsed(void *parsed_result,
3377                         __attribute__((unused)) struct cmdline *cl,
3378                         __attribute__((unused)) void *data)
3379 {
3380         struct cmd_config_threshold *res = parsed_result;
3381
3382         if (!all_ports_stopped()) {
3383                 printf("Please stop all ports first\n");
3384                 return;
3385         }
3386
3387         if (!strcmp(res->name, "txfreet"))
3388                 tx_free_thresh = res->value;
3389         else if (!strcmp(res->name, "txrst"))
3390                 tx_rs_thresh = res->value;
3391         else if (!strcmp(res->name, "rxfreet"))
3392                 rx_free_thresh = res->value;
3393         else {
3394                 printf("Unknown parameter\n");
3395                 return;
3396         }
3397
3398         init_port_config();
3399
3400         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3401 }
3402
3403 cmdline_parse_token_string_t cmd_config_threshold_port =
3404         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3405 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3406         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3407                                                                 "config");
3408 cmdline_parse_token_string_t cmd_config_threshold_all =
3409         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3410 cmdline_parse_token_string_t cmd_config_threshold_name =
3411         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3412                                                 "txfreet#txrst#rxfreet");
3413 cmdline_parse_token_num_t cmd_config_threshold_value =
3414         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3415
3416 cmdline_parse_inst_t cmd_config_threshold = {
3417         .f = cmd_config_threshold_parsed,
3418         .data = NULL,
3419         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3420         .tokens = {
3421                 (void *)&cmd_config_threshold_port,
3422                 (void *)&cmd_config_threshold_keyword,
3423                 (void *)&cmd_config_threshold_all,
3424                 (void *)&cmd_config_threshold_name,
3425                 (void *)&cmd_config_threshold_value,
3426                 NULL,
3427         },
3428 };
3429
3430 /* *** stop *** */
3431 struct cmd_stop_result {
3432         cmdline_fixed_string_t stop;
3433 };
3434
3435 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3436                             __attribute__((unused)) struct cmdline *cl,
3437                             __attribute__((unused)) void *data)
3438 {
3439         stop_packet_forwarding();
3440 }
3441
3442 cmdline_parse_token_string_t cmd_stop_stop =
3443         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3444
3445 cmdline_parse_inst_t cmd_stop = {
3446         .f = cmd_stop_parsed,
3447         .data = NULL,
3448         .help_str = "stop: Stop packet forwarding",
3449         .tokens = {
3450                 (void *)&cmd_stop_stop,
3451                 NULL,
3452         },
3453 };
3454
3455 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3456
3457 unsigned int
3458 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3459                 unsigned int *parsed_items, int check_unique_values)
3460 {
3461         unsigned int nb_item;
3462         unsigned int value;
3463         unsigned int i;
3464         unsigned int j;
3465         int value_ok;
3466         char c;
3467
3468         /*
3469          * First parse all items in the list and store their value.
3470          */
3471         value = 0;
3472         nb_item = 0;
3473         value_ok = 0;
3474         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3475                 c = str[i];
3476                 if ((c >= '0') && (c <= '9')) {
3477                         value = (unsigned int) (value * 10 + (c - '0'));
3478                         value_ok = 1;
3479                         continue;
3480                 }
3481                 if (c != ',') {
3482                         printf("character %c is not a decimal digit\n", c);
3483                         return 0;
3484                 }
3485                 if (! value_ok) {
3486                         printf("No valid value before comma\n");
3487                         return 0;
3488                 }
3489                 if (nb_item < max_items) {
3490                         parsed_items[nb_item] = value;
3491                         value_ok = 0;
3492                         value = 0;
3493                 }
3494                 nb_item++;
3495         }
3496         if (nb_item >= max_items) {
3497                 printf("Number of %s = %u > %u (maximum items)\n",
3498                        item_name, nb_item + 1, max_items);
3499                 return 0;
3500         }
3501         parsed_items[nb_item++] = value;
3502         if (! check_unique_values)
3503                 return nb_item;
3504
3505         /*
3506          * Then, check that all values in the list are differents.
3507          * No optimization here...
3508          */
3509         for (i = 0; i < nb_item; i++) {
3510                 for (j = i + 1; j < nb_item; j++) {
3511                         if (parsed_items[j] == parsed_items[i]) {
3512                                 printf("duplicated %s %u at index %u and %u\n",
3513                                        item_name, parsed_items[i], i, j);
3514                                 return 0;
3515                         }
3516                 }
3517         }
3518         return nb_item;
3519 }
3520
3521 struct cmd_set_list_result {
3522         cmdline_fixed_string_t cmd_keyword;
3523         cmdline_fixed_string_t list_name;
3524         cmdline_fixed_string_t list_of_items;
3525 };
3526
3527 static void cmd_set_list_parsed(void *parsed_result,
3528                                 __attribute__((unused)) struct cmdline *cl,
3529                                 __attribute__((unused)) void *data)
3530 {
3531         struct cmd_set_list_result *res;
3532         union {
3533                 unsigned int lcorelist[RTE_MAX_LCORE];
3534                 unsigned int portlist[RTE_MAX_ETHPORTS];
3535         } parsed_items;
3536         unsigned int nb_item;
3537
3538         if (test_done == 0) {
3539                 printf("Please stop forwarding first\n");
3540                 return;
3541         }
3542
3543         res = parsed_result;
3544         if (!strcmp(res->list_name, "corelist")) {
3545                 nb_item = parse_item_list(res->list_of_items, "core",
3546                                           RTE_MAX_LCORE,
3547                                           parsed_items.lcorelist, 1);
3548                 if (nb_item > 0) {
3549                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3550                         fwd_config_setup();
3551                 }
3552                 return;
3553         }
3554         if (!strcmp(res->list_name, "portlist")) {
3555                 nb_item = parse_item_list(res->list_of_items, "port",
3556                                           RTE_MAX_ETHPORTS,
3557                                           parsed_items.portlist, 1);
3558                 if (nb_item > 0) {
3559                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3560                         fwd_config_setup();
3561                 }
3562         }
3563 }
3564
3565 cmdline_parse_token_string_t cmd_set_list_keyword =
3566         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3567                                  "set");
3568 cmdline_parse_token_string_t cmd_set_list_name =
3569         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3570                                  "corelist#portlist");
3571 cmdline_parse_token_string_t cmd_set_list_of_items =
3572         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3573                                  NULL);
3574
3575 cmdline_parse_inst_t cmd_set_fwd_list = {
3576         .f = cmd_set_list_parsed,
3577         .data = NULL,
3578         .help_str = "set corelist|portlist <list0[,list1]*>",
3579         .tokens = {
3580                 (void *)&cmd_set_list_keyword,
3581                 (void *)&cmd_set_list_name,
3582                 (void *)&cmd_set_list_of_items,
3583                 NULL,
3584         },
3585 };
3586
3587 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3588
3589 struct cmd_setmask_result {
3590         cmdline_fixed_string_t set;
3591         cmdline_fixed_string_t mask;
3592         uint64_t hexavalue;
3593 };
3594
3595 static void cmd_set_mask_parsed(void *parsed_result,
3596                                 __attribute__((unused)) struct cmdline *cl,
3597                                 __attribute__((unused)) void *data)
3598 {
3599         struct cmd_setmask_result *res = parsed_result;
3600
3601         if (test_done == 0) {
3602                 printf("Please stop forwarding first\n");
3603                 return;
3604         }
3605         if (!strcmp(res->mask, "coremask")) {
3606                 set_fwd_lcores_mask(res->hexavalue);
3607                 fwd_config_setup();
3608         } else if (!strcmp(res->mask, "portmask")) {
3609                 set_fwd_ports_mask(res->hexavalue);
3610                 fwd_config_setup();
3611         }
3612 }
3613
3614 cmdline_parse_token_string_t cmd_setmask_set =
3615         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3616 cmdline_parse_token_string_t cmd_setmask_mask =
3617         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3618                                  "coremask#portmask");
3619 cmdline_parse_token_num_t cmd_setmask_value =
3620         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3621
3622 cmdline_parse_inst_t cmd_set_fwd_mask = {
3623         .f = cmd_set_mask_parsed,
3624         .data = NULL,
3625         .help_str = "set coremask|portmask <hexadecimal value>",
3626         .tokens = {
3627                 (void *)&cmd_setmask_set,
3628                 (void *)&cmd_setmask_mask,
3629                 (void *)&cmd_setmask_value,
3630                 NULL,
3631         },
3632 };
3633
3634 /*
3635  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3636  */
3637 struct cmd_set_result {
3638         cmdline_fixed_string_t set;
3639         cmdline_fixed_string_t what;
3640         uint16_t value;
3641 };
3642
3643 static void cmd_set_parsed(void *parsed_result,
3644                            __attribute__((unused)) struct cmdline *cl,
3645                            __attribute__((unused)) void *data)
3646 {
3647         struct cmd_set_result *res = parsed_result;
3648         if (!strcmp(res->what, "nbport")) {
3649                 set_fwd_ports_number(res->value);
3650                 fwd_config_setup();
3651         } else if (!strcmp(res->what, "nbcore")) {
3652                 set_fwd_lcores_number(res->value);
3653                 fwd_config_setup();
3654         } else if (!strcmp(res->what, "burst"))
3655                 set_nb_pkt_per_burst(res->value);
3656         else if (!strcmp(res->what, "verbose"))
3657                 set_verbose_level(res->value);
3658 }
3659
3660 cmdline_parse_token_string_t cmd_set_set =
3661         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3662 cmdline_parse_token_string_t cmd_set_what =
3663         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3664                                  "nbport#nbcore#burst#verbose");
3665 cmdline_parse_token_num_t cmd_set_value =
3666         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3667
3668 cmdline_parse_inst_t cmd_set_numbers = {
3669         .f = cmd_set_parsed,
3670         .data = NULL,
3671         .help_str = "set nbport|nbcore|burst|verbose <value>",
3672         .tokens = {
3673                 (void *)&cmd_set_set,
3674                 (void *)&cmd_set_what,
3675                 (void *)&cmd_set_value,
3676                 NULL,
3677         },
3678 };
3679
3680 /* *** SET LOG LEVEL CONFIGURATION *** */
3681
3682 struct cmd_set_log_result {
3683         cmdline_fixed_string_t set;
3684         cmdline_fixed_string_t log;
3685         cmdline_fixed_string_t type;
3686         uint32_t level;
3687 };
3688
3689 static void
3690 cmd_set_log_parsed(void *parsed_result,
3691                    __attribute__((unused)) struct cmdline *cl,
3692                    __attribute__((unused)) void *data)
3693 {
3694         struct cmd_set_log_result *res;
3695         int ret;
3696
3697         res = parsed_result;
3698         if (!strcmp(res->type, "global"))
3699                 rte_log_set_global_level(res->level);
3700         else {
3701                 ret = rte_log_set_level_regexp(res->type, res->level);
3702                 if (ret < 0)
3703                         printf("Unable to set log level\n");
3704         }
3705 }
3706
3707 cmdline_parse_token_string_t cmd_set_log_set =
3708         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3709 cmdline_parse_token_string_t cmd_set_log_log =
3710         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3711 cmdline_parse_token_string_t cmd_set_log_type =
3712         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3713 cmdline_parse_token_num_t cmd_set_log_level =
3714         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3715
3716 cmdline_parse_inst_t cmd_set_log = {
3717         .f = cmd_set_log_parsed,
3718         .data = NULL,
3719         .help_str = "set log global|<type> <level>",
3720         .tokens = {
3721                 (void *)&cmd_set_log_set,
3722                 (void *)&cmd_set_log_log,
3723                 (void *)&cmd_set_log_type,
3724                 (void *)&cmd_set_log_level,
3725                 NULL,
3726         },
3727 };
3728
3729 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3730
3731 struct cmd_set_txpkts_result {
3732         cmdline_fixed_string_t cmd_keyword;
3733         cmdline_fixed_string_t txpkts;
3734         cmdline_fixed_string_t seg_lengths;
3735 };
3736
3737 static void
3738 cmd_set_txpkts_parsed(void *parsed_result,
3739                       __attribute__((unused)) struct cmdline *cl,
3740                       __attribute__((unused)) void *data)
3741 {
3742         struct cmd_set_txpkts_result *res;
3743         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3744         unsigned int nb_segs;
3745
3746         res = parsed_result;
3747         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3748                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3749         if (nb_segs > 0)
3750                 set_tx_pkt_segments(seg_lengths, nb_segs);
3751 }
3752
3753 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3754         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3755                                  cmd_keyword, "set");
3756 cmdline_parse_token_string_t cmd_set_txpkts_name =
3757         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3758                                  txpkts, "txpkts");
3759 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3760         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3761                                  seg_lengths, NULL);
3762
3763 cmdline_parse_inst_t cmd_set_txpkts = {
3764         .f = cmd_set_txpkts_parsed,
3765         .data = NULL,
3766         .help_str = "set txpkts <len0[,len1]*>",
3767         .tokens = {
3768                 (void *)&cmd_set_txpkts_keyword,
3769                 (void *)&cmd_set_txpkts_name,
3770                 (void *)&cmd_set_txpkts_lengths,
3771                 NULL,
3772         },
3773 };
3774
3775 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3776
3777 struct cmd_set_txsplit_result {
3778         cmdline_fixed_string_t cmd_keyword;
3779         cmdline_fixed_string_t txsplit;
3780         cmdline_fixed_string_t mode;
3781 };
3782
3783 static void
3784 cmd_set_txsplit_parsed(void *parsed_result,
3785                       __attribute__((unused)) struct cmdline *cl,
3786                       __attribute__((unused)) void *data)
3787 {
3788         struct cmd_set_txsplit_result *res;
3789
3790         res = parsed_result;
3791         set_tx_pkt_split(res->mode);
3792 }
3793
3794 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3795         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3796                                  cmd_keyword, "set");
3797 cmdline_parse_token_string_t cmd_set_txsplit_name =
3798         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3799                                  txsplit, "txsplit");
3800 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3801         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3802                                  mode, NULL);
3803
3804 cmdline_parse_inst_t cmd_set_txsplit = {
3805         .f = cmd_set_txsplit_parsed,
3806         .data = NULL,
3807         .help_str = "set txsplit on|off|rand",
3808         .tokens = {
3809                 (void *)&cmd_set_txsplit_keyword,
3810                 (void *)&cmd_set_txsplit_name,
3811                 (void *)&cmd_set_txsplit_mode,
3812                 NULL,
3813         },
3814 };
3815
3816 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3817 struct cmd_rx_vlan_filter_all_result {
3818         cmdline_fixed_string_t rx_vlan;
3819         cmdline_fixed_string_t what;
3820         cmdline_fixed_string_t all;
3821         portid_t port_id;
3822 };
3823
3824 static void
3825 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3826                               __attribute__((unused)) struct cmdline *cl,
3827                               __attribute__((unused)) void *data)
3828 {
3829         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3830
3831         if (!strcmp(res->what, "add"))
3832                 rx_vlan_all_filter_set(res->port_id, 1);
3833         else
3834                 rx_vlan_all_filter_set(res->port_id, 0);
3835 }
3836
3837 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3838         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3839                                  rx_vlan, "rx_vlan");
3840 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3841         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3842                                  what, "add#rm");
3843 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3844         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3845                                  all, "all");
3846 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3847         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3848                               port_id, UINT16);
3849
3850 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3851         .f = cmd_rx_vlan_filter_all_parsed,
3852         .data = NULL,
3853         .help_str = "rx_vlan add|rm all <port_id>: "
3854                 "Add/Remove all identifiers to/from the set of VLAN "
3855                 "identifiers filtered by a port",
3856         .tokens = {
3857                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3858                 (void *)&cmd_rx_vlan_filter_all_what,
3859                 (void *)&cmd_rx_vlan_filter_all_all,
3860                 (void *)&cmd_rx_vlan_filter_all_portid,
3861                 NULL,
3862         },
3863 };
3864
3865 /* *** VLAN OFFLOAD SET ON A PORT *** */
3866 struct cmd_vlan_offload_result {
3867         cmdline_fixed_string_t vlan;
3868         cmdline_fixed_string_t set;
3869         cmdline_fixed_string_t vlan_type;
3870         cmdline_fixed_string_t what;
3871         cmdline_fixed_string_t on;
3872         cmdline_fixed_string_t port_id;
3873 };
3874
3875 static void
3876 cmd_vlan_offload_parsed(void *parsed_result,
3877                           __attribute__((unused)) struct cmdline *cl,
3878                           __attribute__((unused)) void *data)
3879 {
3880         int on;
3881         struct cmd_vlan_offload_result *res = parsed_result;
3882         char *str;
3883         int i, len = 0;
3884         portid_t port_id = 0;
3885         unsigned int tmp;
3886
3887         str = res->port_id;
3888         len = strnlen(str, STR_TOKEN_SIZE);
3889         i = 0;
3890         /* Get port_id first */
3891         while(i < len){
3892                 if(str[i] == ',')
3893                         break;
3894
3895                 i++;
3896         }
3897         str[i]='\0';
3898         tmp = strtoul(str, NULL, 0);
3899         /* If port_id greater that what portid_t can represent, return */
3900         if(tmp >= RTE_MAX_ETHPORTS)
3901                 return;
3902         port_id = (portid_t)tmp;
3903
3904         if (!strcmp(res->on, "on"))
3905                 on = 1;
3906         else
3907                 on = 0;
3908
3909         if (!strcmp(res->what, "strip"))
3910                 rx_vlan_strip_set(port_id,  on);
3911         else if(!strcmp(res->what, "stripq")){
3912                 uint16_t queue_id = 0;
3913
3914                 /* No queue_id, return */
3915                 if(i + 1 >= len) {
3916                         printf("must specify (port,queue_id)\n");
3917                         return;
3918                 }
3919                 tmp = strtoul(str + i + 1, NULL, 0);
3920                 /* If queue_id greater that what 16-bits can represent, return */
3921                 if(tmp > 0xffff)
3922                         return;
3923
3924                 queue_id = (uint16_t)tmp;
3925                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3926         }
3927         else if (!strcmp(res->what, "filter"))
3928                 rx_vlan_filter_set(port_id, on);
3929         else
3930                 vlan_extend_set(port_id, on);
3931
3932         return;
3933 }
3934
3935 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3936         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3937                                  vlan, "vlan");
3938 cmdline_parse_token_string_t cmd_vlan_offload_set =
3939         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3940                                  set, "set");
3941 cmdline_parse_token_string_t cmd_vlan_offload_what =
3942         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3943                                  what, "strip#filter#qinq#stripq");
3944 cmdline_parse_token_string_t cmd_vlan_offload_on =
3945         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3946                               on, "on#off");
3947 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3948         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3949                               port_id, NULL);
3950
3951 cmdline_parse_inst_t cmd_vlan_offload = {
3952         .f = cmd_vlan_offload_parsed,
3953         .data = NULL,
3954         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3955                 "<port_id[,queue_id]>: "
3956                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3957         .tokens = {
3958                 (void *)&cmd_vlan_offload_vlan,
3959                 (void *)&cmd_vlan_offload_set,
3960                 (void *)&cmd_vlan_offload_what,
3961                 (void *)&cmd_vlan_offload_on,
3962                 (void *)&cmd_vlan_offload_portid,
3963                 NULL,
3964         },
3965 };
3966
3967 /* *** VLAN TPID SET ON A PORT *** */
3968 struct cmd_vlan_tpid_result {
3969         cmdline_fixed_string_t vlan;
3970         cmdline_fixed_string_t set;
3971         cmdline_fixed_string_t vlan_type;
3972         cmdline_fixed_string_t what;
3973         uint16_t tp_id;
3974         portid_t port_id;
3975 };
3976
3977 static void
3978 cmd_vlan_tpid_parsed(void *parsed_result,
3979                           __attribute__((unused)) struct cmdline *cl,
3980                           __attribute__((unused)) void *data)
3981 {
3982         struct cmd_vlan_tpid_result *res = parsed_result;
3983         enum rte_vlan_type vlan_type;
3984
3985         if (!strcmp(res->vlan_type, "inner"))
3986                 vlan_type = ETH_VLAN_TYPE_INNER;
3987         else if (!strcmp(res->vlan_type, "outer"))
3988                 vlan_type = ETH_VLAN_TYPE_OUTER;
3989         else {
3990                 printf("Unknown vlan type\n");
3991                 return;
3992         }
3993         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3994 }
3995
3996 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3997         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3998                                  vlan, "vlan");
3999 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4000         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4001                                  set, "set");
4002 cmdline_parse_token_string_t cmd_vlan_type =
4003         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4004                                  vlan_type, "inner#outer");
4005 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4006         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4007                                  what, "tpid");
4008 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4009         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4010                               tp_id, UINT16);
4011 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4012         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4013                               port_id, UINT16);
4014
4015 cmdline_parse_inst_t cmd_vlan_tpid = {
4016         .f = cmd_vlan_tpid_parsed,
4017         .data = NULL,
4018         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4019                 "Set the VLAN Ether type",
4020         .tokens = {
4021                 (void *)&cmd_vlan_tpid_vlan,
4022                 (void *)&cmd_vlan_tpid_set,
4023                 (void *)&cmd_vlan_type,
4024                 (void *)&cmd_vlan_tpid_what,
4025                 (void *)&cmd_vlan_tpid_tpid,
4026                 (void *)&cmd_vlan_tpid_portid,
4027                 NULL,
4028         },
4029 };
4030
4031 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4032 struct cmd_rx_vlan_filter_result {
4033         cmdline_fixed_string_t rx_vlan;
4034         cmdline_fixed_string_t what;
4035         uint16_t vlan_id;
4036         portid_t port_id;
4037 };
4038
4039 static void
4040 cmd_rx_vlan_filter_parsed(void *parsed_result,
4041                           __attribute__((unused)) struct cmdline *cl,
4042                           __attribute__((unused)) void *data)
4043 {
4044         struct cmd_rx_vlan_filter_result *res = parsed_result;
4045
4046         if (!strcmp(res->what, "add"))
4047                 rx_vft_set(res->port_id, res->vlan_id, 1);
4048         else
4049                 rx_vft_set(res->port_id, res->vlan_id, 0);
4050 }
4051
4052 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4053         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4054                                  rx_vlan, "rx_vlan");
4055 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4056         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4057                                  what, "add#rm");
4058 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4059         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4060                               vlan_id, UINT16);
4061 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4062         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4063                               port_id, UINT16);
4064
4065 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4066         .f = cmd_rx_vlan_filter_parsed,
4067         .data = NULL,
4068         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4069                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4070                 "identifiers filtered by a port",
4071         .tokens = {
4072                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4073                 (void *)&cmd_rx_vlan_filter_what,
4074                 (void *)&cmd_rx_vlan_filter_vlanid,
4075                 (void *)&cmd_rx_vlan_filter_portid,
4076                 NULL,
4077         },
4078 };
4079
4080 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4081 struct cmd_tx_vlan_set_result {
4082         cmdline_fixed_string_t tx_vlan;
4083         cmdline_fixed_string_t set;
4084         portid_t port_id;
4085         uint16_t vlan_id;
4086 };
4087
4088 static void
4089 cmd_tx_vlan_set_parsed(void *parsed_result,
4090                        __attribute__((unused)) struct cmdline *cl,
4091                        __attribute__((unused)) void *data)
4092 {
4093         struct cmd_tx_vlan_set_result *res = parsed_result;
4094
4095         if (!port_is_stopped(res->port_id)) {
4096                 printf("Please stop port %d first\n", res->port_id);
4097                 return;
4098         }
4099
4100         tx_vlan_set(res->port_id, res->vlan_id);
4101
4102         cmd_reconfig_device_queue(res->port_id, 1, 1);
4103 }
4104
4105 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4106         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4107                                  tx_vlan, "tx_vlan");
4108 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4109         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4110                                  set, "set");
4111 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4112         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4113                               port_id, UINT16);
4114 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4115         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4116                               vlan_id, UINT16);
4117
4118 cmdline_parse_inst_t cmd_tx_vlan_set = {
4119         .f = cmd_tx_vlan_set_parsed,
4120         .data = NULL,
4121         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4122                 "Enable hardware insertion of a single VLAN header "
4123                 "with a given TAG Identifier in packets sent on a port",
4124         .tokens = {
4125                 (void *)&cmd_tx_vlan_set_tx_vlan,
4126                 (void *)&cmd_tx_vlan_set_set,
4127                 (void *)&cmd_tx_vlan_set_portid,
4128                 (void *)&cmd_tx_vlan_set_vlanid,
4129                 NULL,
4130         },
4131 };
4132
4133 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4134 struct cmd_tx_vlan_set_qinq_result {
4135         cmdline_fixed_string_t tx_vlan;
4136         cmdline_fixed_string_t set;
4137         portid_t port_id;
4138         uint16_t vlan_id;
4139         uint16_t vlan_id_outer;
4140 };
4141
4142 static void
4143 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4144                             __attribute__((unused)) struct cmdline *cl,
4145                             __attribute__((unused)) void *data)
4146 {
4147         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4148
4149         if (!port_is_stopped(res->port_id)) {
4150                 printf("Please stop port %d first\n", res->port_id);
4151                 return;
4152         }
4153
4154         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4155
4156         cmd_reconfig_device_queue(res->port_id, 1, 1);
4157 }
4158
4159 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4160         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4161                 tx_vlan, "tx_vlan");
4162 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4163         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4164                 set, "set");
4165 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4166         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4167                 port_id, UINT16);
4168 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4169         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4170                 vlan_id, UINT16);
4171 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4172         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4173                 vlan_id_outer, UINT16);
4174
4175 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4176         .f = cmd_tx_vlan_set_qinq_parsed,
4177         .data = NULL,
4178         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4179                 "Enable hardware insertion of double VLAN header "
4180                 "with given TAG Identifiers in packets sent on a port",
4181         .tokens = {
4182                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4183                 (void *)&cmd_tx_vlan_set_qinq_set,
4184                 (void *)&cmd_tx_vlan_set_qinq_portid,
4185                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4186                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4187                 NULL,
4188         },
4189 };
4190
4191 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4192 struct cmd_tx_vlan_set_pvid_result {
4193         cmdline_fixed_string_t tx_vlan;
4194         cmdline_fixed_string_t set;
4195         cmdline_fixed_string_t pvid;
4196         portid_t port_id;
4197         uint16_t vlan_id;
4198         cmdline_fixed_string_t mode;
4199 };
4200
4201 static void
4202 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4203                             __attribute__((unused)) struct cmdline *cl,
4204                             __attribute__((unused)) void *data)
4205 {
4206         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4207
4208         if (strcmp(res->mode, "on") == 0)
4209                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4210         else
4211                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4212 }
4213
4214 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4215         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4216                                  tx_vlan, "tx_vlan");
4217 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4218         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4219                                  set, "set");
4220 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4221         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4222                                  pvid, "pvid");
4223 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4224         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4225                              port_id, UINT16);
4226 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4227         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4228                               vlan_id, UINT16);
4229 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4230         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4231                                  mode, "on#off");
4232
4233 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4234         .f = cmd_tx_vlan_set_pvid_parsed,
4235         .data = NULL,
4236         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4237         .tokens = {
4238                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4239                 (void *)&cmd_tx_vlan_set_pvid_set,
4240                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4241                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4242                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4243                 (void *)&cmd_tx_vlan_set_pvid_mode,
4244                 NULL,
4245         },
4246 };
4247
4248 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4249 struct cmd_tx_vlan_reset_result {
4250         cmdline_fixed_string_t tx_vlan;
4251         cmdline_fixed_string_t reset;
4252         portid_t port_id;
4253 };
4254
4255 static void
4256 cmd_tx_vlan_reset_parsed(void *parsed_result,
4257                          __attribute__((unused)) struct cmdline *cl,
4258                          __attribute__((unused)) void *data)
4259 {
4260         struct cmd_tx_vlan_reset_result *res = parsed_result;
4261
4262         if (!port_is_stopped(res->port_id)) {
4263                 printf("Please stop port %d first\n", res->port_id);
4264                 return;
4265         }
4266
4267         tx_vlan_reset(res->port_id);
4268
4269         cmd_reconfig_device_queue(res->port_id, 1, 1);
4270 }
4271
4272 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4273         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4274                                  tx_vlan, "tx_vlan");
4275 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4276         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4277                                  reset, "reset");
4278 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4279         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4280                               port_id, UINT16);
4281
4282 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4283         .f = cmd_tx_vlan_reset_parsed,
4284         .data = NULL,
4285         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4286                 "VLAN header in packets sent on a port",
4287         .tokens = {
4288                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4289                 (void *)&cmd_tx_vlan_reset_reset,
4290                 (void *)&cmd_tx_vlan_reset_portid,
4291                 NULL,
4292         },
4293 };
4294
4295
4296 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4297 struct cmd_csum_result {
4298         cmdline_fixed_string_t csum;
4299         cmdline_fixed_string_t mode;
4300         cmdline_fixed_string_t proto;
4301         cmdline_fixed_string_t hwsw;
4302         portid_t port_id;
4303 };
4304
4305 static void
4306 csum_show(int port_id)
4307 {
4308         struct rte_eth_dev_info dev_info;
4309         uint64_t tx_offloads;
4310
4311         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4312         printf("Parse tunnel is %s\n",
4313                 (ports[port_id].parse_tunnel) ? "on" : "off");
4314         printf("IP checksum offload is %s\n",
4315                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4316         printf("UDP checksum offload is %s\n",
4317                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4318         printf("TCP checksum offload is %s\n",
4319                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4320         printf("SCTP checksum offload is %s\n",
4321                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4322         printf("Outer-Ip checksum offload is %s\n",
4323                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4324         printf("Outer-Udp checksum offload is %s\n",
4325                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4326
4327         /* display warnings if configuration is not supported by the NIC */
4328         rte_eth_dev_info_get(port_id, &dev_info);
4329         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4330                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4331                 printf("Warning: hardware IP checksum enabled but not "
4332                         "supported by port %d\n", port_id);
4333         }
4334         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4335                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4336                 printf("Warning: hardware UDP checksum enabled but not "
4337                         "supported by port %d\n", port_id);
4338         }
4339         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4340                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4341                 printf("Warning: hardware TCP checksum enabled but not "
4342                         "supported by port %d\n", port_id);
4343         }
4344         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4345                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4346                 printf("Warning: hardware SCTP checksum enabled but not "
4347                         "supported by port %d\n", port_id);
4348         }
4349         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4350                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4351                 printf("Warning: hardware outer IP checksum enabled but not "
4352                         "supported by port %d\n", port_id);
4353         }
4354         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4355                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4356                         == 0) {
4357                 printf("Warning: hardware outer UDP checksum enabled but not "
4358                         "supported by port %d\n", port_id);
4359         }
4360 }
4361
4362 static void
4363 cmd_csum_parsed(void *parsed_result,
4364                        __attribute__((unused)) struct cmdline *cl,
4365                        __attribute__((unused)) void *data)
4366 {
4367         struct cmd_csum_result *res = parsed_result;
4368         int hw = 0;
4369         uint64_t csum_offloads = 0;
4370         struct rte_eth_dev_info dev_info;
4371
4372         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4373                 printf("invalid port %d\n", res->port_id);
4374                 return;
4375         }
4376         if (!port_is_stopped(res->port_id)) {
4377                 printf("Please stop port %d first\n", res->port_id);
4378                 return;
4379         }
4380
4381         rte_eth_dev_info_get(res->port_id, &dev_info);
4382         if (!strcmp(res->mode, "set")) {
4383
4384                 if (!strcmp(res->hwsw, "hw"))
4385                         hw = 1;
4386
4387                 if (!strcmp(res->proto, "ip")) {
4388                         if (hw == 0 || (dev_info.tx_offload_capa &
4389                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4390                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4391                         } else {
4392                                 printf("IP checksum offload is not supported "
4393                                        "by port %u\n", res->port_id);
4394                         }
4395                 } else if (!strcmp(res->proto, "udp")) {
4396                         if (hw == 0 || (dev_info.tx_offload_capa &
4397                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4398                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4399                         } else {
4400                                 printf("UDP checksum offload is not supported "
4401                                        "by port %u\n", res->port_id);
4402                         }
4403                 } else if (!strcmp(res->proto, "tcp")) {
4404                         if (hw == 0 || (dev_info.tx_offload_capa &
4405                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4406                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4407                         } else {
4408                                 printf("TCP checksum offload is not supported "
4409                                        "by port %u\n", res->port_id);
4410                         }
4411                 } else if (!strcmp(res->proto, "sctp")) {
4412                         if (hw == 0 || (dev_info.tx_offload_capa &
4413                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4414                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4415                         } else {
4416                                 printf("SCTP checksum offload is not supported "
4417                                        "by port %u\n", res->port_id);
4418                         }
4419                 } else if (!strcmp(res->proto, "outer-ip")) {
4420                         if (hw == 0 || (dev_info.tx_offload_capa &
4421                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4422                                 csum_offloads |=
4423                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4424                         } else {
4425                                 printf("Outer IP checksum offload is not "
4426                                        "supported by port %u\n", res->port_id);
4427                         }
4428                 } else if (!strcmp(res->proto, "outer-udp")) {
4429                         if (hw == 0 || (dev_info.tx_offload_capa &
4430                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4431                                 csum_offloads |=
4432                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4433                         } else {
4434                                 printf("Outer UDP checksum offload is not "
4435                                        "supported by port %u\n", res->port_id);
4436                         }
4437                 }
4438
4439                 if (hw) {
4440                         ports[res->port_id].dev_conf.txmode.offloads |=
4441                                                         csum_offloads;
4442                 } else {
4443                         ports[res->port_id].dev_conf.txmode.offloads &=
4444                                                         (~csum_offloads);
4445                 }
4446         }
4447         csum_show(res->port_id);
4448
4449         cmd_reconfig_device_queue(res->port_id, 1, 1);
4450 }
4451
4452 cmdline_parse_token_string_t cmd_csum_csum =
4453         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4454                                 csum, "csum");
4455 cmdline_parse_token_string_t cmd_csum_mode =
4456         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4457                                 mode, "set");
4458 cmdline_parse_token_string_t cmd_csum_proto =
4459         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4460                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4461 cmdline_parse_token_string_t cmd_csum_hwsw =
4462         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4463                                 hwsw, "hw#sw");
4464 cmdline_parse_token_num_t cmd_csum_portid =
4465         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4466                                 port_id, UINT16);
4467
4468 cmdline_parse_inst_t cmd_csum_set = {
4469         .f = cmd_csum_parsed,
4470         .data = NULL,
4471         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4472                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4473                 "using csum forward engine",
4474         .tokens = {
4475                 (void *)&cmd_csum_csum,
4476                 (void *)&cmd_csum_mode,
4477                 (void *)&cmd_csum_proto,
4478                 (void *)&cmd_csum_hwsw,
4479                 (void *)&cmd_csum_portid,
4480                 NULL,
4481         },
4482 };
4483
4484 cmdline_parse_token_string_t cmd_csum_mode_show =
4485         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4486                                 mode, "show");
4487
4488 cmdline_parse_inst_t cmd_csum_show = {
4489         .f = cmd_csum_parsed,
4490         .data = NULL,
4491         .help_str = "csum show <port_id>: Show checksum offload configuration",
4492         .tokens = {
4493                 (void *)&cmd_csum_csum,
4494                 (void *)&cmd_csum_mode_show,
4495                 (void *)&cmd_csum_portid,
4496                 NULL,
4497         },
4498 };
4499
4500 /* Enable/disable tunnel parsing */
4501 struct cmd_csum_tunnel_result {
4502         cmdline_fixed_string_t csum;
4503         cmdline_fixed_string_t parse;
4504         cmdline_fixed_string_t onoff;
4505         portid_t port_id;
4506 };
4507
4508 static void
4509 cmd_csum_tunnel_parsed(void *parsed_result,
4510                        __attribute__((unused)) struct cmdline *cl,
4511                        __attribute__((unused)) void *data)
4512 {
4513         struct cmd_csum_tunnel_result *res = parsed_result;
4514
4515         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4516                 return;
4517
4518         if (!strcmp(res->onoff, "on"))
4519                 ports[res->port_id].parse_tunnel = 1;
4520         else
4521                 ports[res->port_id].parse_tunnel = 0;
4522
4523         csum_show(res->port_id);
4524 }
4525
4526 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4527         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4528                                 csum, "csum");
4529 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4530         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4531                                 parse, "parse-tunnel");
4532 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4533         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4534                                 onoff, "on#off");
4535 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4536         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4537                                 port_id, UINT16);
4538
4539 cmdline_parse_inst_t cmd_csum_tunnel = {
4540         .f = cmd_csum_tunnel_parsed,
4541         .data = NULL,
4542         .help_str = "csum parse-tunnel on|off <port_id>: "
4543                 "Enable/Disable parsing of tunnels for csum engine",
4544         .tokens = {
4545                 (void *)&cmd_csum_tunnel_csum,
4546                 (void *)&cmd_csum_tunnel_parse,
4547                 (void *)&cmd_csum_tunnel_onoff,
4548                 (void *)&cmd_csum_tunnel_portid,
4549                 NULL,
4550         },
4551 };
4552
4553 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4554 struct cmd_tso_set_result {
4555         cmdline_fixed_string_t tso;
4556         cmdline_fixed_string_t mode;
4557         uint16_t tso_segsz;
4558         portid_t port_id;
4559 };
4560
4561 static void
4562 cmd_tso_set_parsed(void *parsed_result,
4563                        __attribute__((unused)) struct cmdline *cl,
4564                        __attribute__((unused)) void *data)
4565 {
4566         struct cmd_tso_set_result *res = parsed_result;
4567         struct rte_eth_dev_info dev_info;
4568
4569         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4570                 return;
4571         if (!port_is_stopped(res->port_id)) {
4572                 printf("Please stop port %d first\n", res->port_id);
4573                 return;
4574         }
4575
4576         if (!strcmp(res->mode, "set"))
4577                 ports[res->port_id].tso_segsz = res->tso_segsz;
4578
4579         rte_eth_dev_info_get(res->port_id, &dev_info);
4580         if ((ports[res->port_id].tso_segsz != 0) &&
4581                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4582                 printf("Error: TSO is not supported by port %d\n",
4583                        res->port_id);
4584                 return;
4585         }
4586
4587         if (ports[res->port_id].tso_segsz == 0) {
4588                 ports[res->port_id].dev_conf.txmode.offloads &=
4589                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4590                 printf("TSO for non-tunneled packets is disabled\n");
4591         } else {
4592                 ports[res->port_id].dev_conf.txmode.offloads |=
4593                                                 DEV_TX_OFFLOAD_TCP_TSO;
4594                 printf("TSO segment size for non-tunneled packets is %d\n",
4595                         ports[res->port_id].tso_segsz);
4596         }
4597
4598         /* display warnings if configuration is not supported by the NIC */
4599         rte_eth_dev_info_get(res->port_id, &dev_info);
4600         if ((ports[res->port_id].tso_segsz != 0) &&
4601                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4602                 printf("Warning: TSO enabled but not "
4603                         "supported by port %d\n", res->port_id);
4604         }
4605
4606         cmd_reconfig_device_queue(res->port_id, 1, 1);
4607 }
4608
4609 cmdline_parse_token_string_t cmd_tso_set_tso =
4610         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4611                                 tso, "tso");
4612 cmdline_parse_token_string_t cmd_tso_set_mode =
4613         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4614                                 mode, "set");
4615 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4616         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4617                                 tso_segsz, UINT16);
4618 cmdline_parse_token_num_t cmd_tso_set_portid =
4619         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4620                                 port_id, UINT16);
4621
4622 cmdline_parse_inst_t cmd_tso_set = {
4623         .f = cmd_tso_set_parsed,
4624         .data = NULL,
4625         .help_str = "tso set <tso_segsz> <port_id>: "
4626                 "Set TSO segment size of non-tunneled packets for csum engine "
4627                 "(0 to disable)",
4628         .tokens = {
4629                 (void *)&cmd_tso_set_tso,
4630                 (void *)&cmd_tso_set_mode,
4631                 (void *)&cmd_tso_set_tso_segsz,
4632                 (void *)&cmd_tso_set_portid,
4633                 NULL,
4634         },
4635 };
4636
4637 cmdline_parse_token_string_t cmd_tso_show_mode =
4638         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4639                                 mode, "show");
4640
4641
4642 cmdline_parse_inst_t cmd_tso_show = {
4643         .f = cmd_tso_set_parsed,
4644         .data = NULL,
4645         .help_str = "tso show <port_id>: "
4646                 "Show TSO segment size of non-tunneled packets for csum engine",
4647         .tokens = {
4648                 (void *)&cmd_tso_set_tso,
4649                 (void *)&cmd_tso_show_mode,
4650                 (void *)&cmd_tso_set_portid,
4651                 NULL,
4652         },
4653 };
4654
4655 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4656 struct cmd_tunnel_tso_set_result {
4657         cmdline_fixed_string_t tso;
4658         cmdline_fixed_string_t mode;
4659         uint16_t tso_segsz;
4660         portid_t port_id;
4661 };
4662
4663 static struct rte_eth_dev_info
4664 check_tunnel_tso_nic_support(portid_t port_id)
4665 {
4666         struct rte_eth_dev_info dev_info;
4667
4668         rte_eth_dev_info_get(port_id, &dev_info);
4669         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4670                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4671                        "not enabled for port %d\n", port_id);
4672         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4673                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4674                        "not enabled for port %d\n", port_id);
4675         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4676                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4677                        "not enabled for port %d\n", port_id);
4678         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4679                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4680                        "not enabled for port %d\n", port_id);
4681         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4682                 printf("Warning: IP TUNNEL TSO not supported therefore "
4683                        "not enabled for port %d\n", port_id);
4684         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4685                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4686                        "not enabled for port %d\n", port_id);
4687         return dev_info;
4688 }
4689
4690 static void
4691 cmd_tunnel_tso_set_parsed(void *parsed_result,
4692                           __attribute__((unused)) struct cmdline *cl,
4693                           __attribute__((unused)) void *data)
4694 {
4695         struct cmd_tunnel_tso_set_result *res = parsed_result;
4696         struct rte_eth_dev_info dev_info;
4697
4698         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4699                 return;
4700         if (!port_is_stopped(res->port_id)) {
4701                 printf("Please stop port %d first\n", res->port_id);
4702                 return;
4703         }
4704
4705         if (!strcmp(res->mode, "set"))
4706                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4707
4708         dev_info = check_tunnel_tso_nic_support(res->port_id);
4709         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4710                 ports[res->port_id].dev_conf.txmode.offloads &=
4711                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4712                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4713                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4714                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4715                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4716                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4717                 printf("TSO for tunneled packets is disabled\n");
4718         } else {
4719                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4720                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4721                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4722                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4723                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4724                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4725
4726                 ports[res->port_id].dev_conf.txmode.offloads |=
4727                         (tso_offloads & dev_info.tx_offload_capa);
4728                 printf("TSO segment size for tunneled packets is %d\n",
4729                         ports[res->port_id].tunnel_tso_segsz);
4730
4731                 /* Below conditions are needed to make it work:
4732                  * (1) tunnel TSO is supported by the NIC;
4733                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4734                  * are recognized;
4735                  * (3) for tunneled pkts with outer L3 of IPv4,
4736                  * "csum set outer-ip" must be set to hw, because after tso,
4737                  * total_len of outer IP header is changed, and the checksum
4738                  * of outer IP header calculated by sw should be wrong; that
4739                  * is not necessary for IPv6 tunneled pkts because there's no
4740                  * checksum in IP header anymore.
4741                  */
4742
4743                 if (!ports[res->port_id].parse_tunnel)
4744                         printf("Warning: csum parse_tunnel must be set "
4745                                 "so that tunneled packets are recognized\n");
4746                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4747                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4748                         printf("Warning: csum set outer-ip must be set to hw "
4749                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4750         }
4751
4752         cmd_reconfig_device_queue(res->port_id, 1, 1);
4753 }
4754
4755 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4756         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4757                                 tso, "tunnel_tso");
4758 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4759         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4760                                 mode, "set");
4761 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4762         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4763                                 tso_segsz, UINT16);
4764 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4765         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4766                                 port_id, UINT16);
4767
4768 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4769         .f = cmd_tunnel_tso_set_parsed,
4770         .data = NULL,
4771         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4772                 "Set TSO segment size of tunneled packets for csum engine "
4773                 "(0 to disable)",
4774         .tokens = {
4775                 (void *)&cmd_tunnel_tso_set_tso,
4776                 (void *)&cmd_tunnel_tso_set_mode,
4777                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4778                 (void *)&cmd_tunnel_tso_set_portid,
4779                 NULL,
4780         },
4781 };
4782
4783 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4784         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4785                                 mode, "show");
4786
4787
4788 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4789         .f = cmd_tunnel_tso_set_parsed,
4790         .data = NULL,
4791         .help_str = "tunnel_tso show <port_id> "
4792                 "Show TSO segment size of tunneled packets for csum engine",
4793         .tokens = {
4794                 (void *)&cmd_tunnel_tso_set_tso,
4795                 (void *)&cmd_tunnel_tso_show_mode,
4796                 (void *)&cmd_tunnel_tso_set_portid,
4797                 NULL,
4798         },
4799 };
4800
4801 /* *** SET GRO FOR A PORT *** */
4802 struct cmd_gro_enable_result {
4803         cmdline_fixed_string_t cmd_set;
4804         cmdline_fixed_string_t cmd_port;
4805         cmdline_fixed_string_t cmd_keyword;
4806         cmdline_fixed_string_t cmd_onoff;
4807         portid_t cmd_pid;
4808 };
4809
4810 static void
4811 cmd_gro_enable_parsed(void *parsed_result,
4812                 __attribute__((unused)) struct cmdline *cl,
4813                 __attribute__((unused)) void *data)
4814 {
4815         struct cmd_gro_enable_result *res;
4816
4817         res = parsed_result;
4818         if (!strcmp(res->cmd_keyword, "gro"))
4819                 setup_gro(res->cmd_onoff, res->cmd_pid);
4820 }
4821
4822 cmdline_parse_token_string_t cmd_gro_enable_set =
4823         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4824                         cmd_set, "set");
4825 cmdline_parse_token_string_t cmd_gro_enable_port =
4826         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4827                         cmd_keyword, "port");
4828 cmdline_parse_token_num_t cmd_gro_enable_pid =
4829         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4830                         cmd_pid, UINT16);
4831 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4832         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4833                         cmd_keyword, "gro");
4834 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4835         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4836                         cmd_onoff, "on#off");
4837
4838 cmdline_parse_inst_t cmd_gro_enable = {
4839         .f = cmd_gro_enable_parsed,
4840         .data = NULL,
4841         .help_str = "set port <port_id> gro on|off",
4842         .tokens = {
4843                 (void *)&cmd_gro_enable_set,
4844                 (void *)&cmd_gro_enable_port,
4845                 (void *)&cmd_gro_enable_pid,
4846                 (void *)&cmd_gro_enable_keyword,
4847                 (void *)&cmd_gro_enable_onoff,
4848                 NULL,
4849         },
4850 };
4851
4852 /* *** DISPLAY GRO CONFIGURATION *** */
4853 struct cmd_gro_show_result {
4854         cmdline_fixed_string_t cmd_show;
4855         cmdline_fixed_string_t cmd_port;
4856         cmdline_fixed_string_t cmd_keyword;
4857         portid_t cmd_pid;
4858 };
4859
4860 static void
4861 cmd_gro_show_parsed(void *parsed_result,
4862                 __attribute__((unused)) struct cmdline *cl,
4863                 __attribute__((unused)) void *data)
4864 {
4865         struct cmd_gro_show_result *res;
4866
4867         res = parsed_result;
4868         if (!strcmp(res->cmd_keyword, "gro"))
4869                 show_gro(res->cmd_pid);
4870 }
4871
4872 cmdline_parse_token_string_t cmd_gro_show_show =
4873         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4874                         cmd_show, "show");
4875 cmdline_parse_token_string_t cmd_gro_show_port =
4876         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4877                         cmd_port, "port");
4878 cmdline_parse_token_num_t cmd_gro_show_pid =
4879         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4880                         cmd_pid, UINT16);
4881 cmdline_parse_token_string_t cmd_gro_show_keyword =
4882         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4883                         cmd_keyword, "gro");
4884
4885 cmdline_parse_inst_t cmd_gro_show = {
4886         .f = cmd_gro_show_parsed,
4887         .data = NULL,
4888         .help_str = "show port <port_id> gro",
4889         .tokens = {
4890                 (void *)&cmd_gro_show_show,
4891                 (void *)&cmd_gro_show_port,
4892                 (void *)&cmd_gro_show_pid,
4893                 (void *)&cmd_gro_show_keyword,
4894                 NULL,
4895         },
4896 };
4897
4898 /* *** SET FLUSH CYCLES FOR GRO *** */
4899 struct cmd_gro_flush_result {
4900         cmdline_fixed_string_t cmd_set;
4901         cmdline_fixed_string_t cmd_keyword;
4902         cmdline_fixed_string_t cmd_flush;
4903         uint8_t cmd_cycles;
4904 };
4905
4906 static void
4907 cmd_gro_flush_parsed(void *parsed_result,
4908                 __attribute__((unused)) struct cmdline *cl,
4909                 __attribute__((unused)) void *data)
4910 {
4911         struct cmd_gro_flush_result *res;
4912
4913         res = parsed_result;
4914         if ((!strcmp(res->cmd_keyword, "gro")) &&
4915                         (!strcmp(res->cmd_flush, "flush")))
4916                 setup_gro_flush_cycles(res->cmd_cycles);
4917 }
4918
4919 cmdline_parse_token_string_t cmd_gro_flush_set =
4920         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4921                         cmd_set, "set");
4922 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4923         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4924                         cmd_keyword, "gro");
4925 cmdline_parse_token_string_t cmd_gro_flush_flush =
4926         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4927                         cmd_flush, "flush");
4928 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4929         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4930                         cmd_cycles, UINT8);
4931
4932 cmdline_parse_inst_t cmd_gro_flush = {
4933         .f = cmd_gro_flush_parsed,
4934         .data = NULL,
4935         .help_str = "set gro flush <cycles>",
4936         .tokens = {
4937                 (void *)&cmd_gro_flush_set,
4938                 (void *)&cmd_gro_flush_keyword,
4939                 (void *)&cmd_gro_flush_flush,
4940                 (void *)&cmd_gro_flush_cycles,
4941                 NULL,
4942         },
4943 };
4944
4945 /* *** ENABLE/DISABLE GSO *** */
4946 struct cmd_gso_enable_result {
4947         cmdline_fixed_string_t cmd_set;
4948         cmdline_fixed_string_t cmd_port;
4949         cmdline_fixed_string_t cmd_keyword;
4950         cmdline_fixed_string_t cmd_mode;
4951         portid_t cmd_pid;
4952 };
4953
4954 static void
4955 cmd_gso_enable_parsed(void *parsed_result,
4956                 __attribute__((unused)) struct cmdline *cl,
4957                 __attribute__((unused)) void *data)
4958 {
4959         struct cmd_gso_enable_result *res;
4960
4961         res = parsed_result;
4962         if (!strcmp(res->cmd_keyword, "gso"))
4963                 setup_gso(res->cmd_mode, res->cmd_pid);
4964 }
4965
4966 cmdline_parse_token_string_t cmd_gso_enable_set =
4967         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4968                         cmd_set, "set");
4969 cmdline_parse_token_string_t cmd_gso_enable_port =
4970         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4971                         cmd_port, "port");
4972 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4973         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4974                         cmd_keyword, "gso");
4975 cmdline_parse_token_string_t cmd_gso_enable_mode =
4976         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4977                         cmd_mode, "on#off");
4978 cmdline_parse_token_num_t cmd_gso_enable_pid =
4979         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4980                         cmd_pid, UINT16);
4981
4982 cmdline_parse_inst_t cmd_gso_enable = {
4983         .f = cmd_gso_enable_parsed,
4984         .data = NULL,
4985         .help_str = "set port <port_id> gso on|off",
4986         .tokens = {
4987                 (void *)&cmd_gso_enable_set,
4988                 (void *)&cmd_gso_enable_port,
4989                 (void *)&cmd_gso_enable_pid,
4990                 (void *)&cmd_gso_enable_keyword,
4991                 (void *)&cmd_gso_enable_mode,
4992                 NULL,
4993         },
4994 };
4995
4996 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4997 struct cmd_gso_size_result {
4998         cmdline_fixed_string_t cmd_set;
4999         cmdline_fixed_string_t cmd_keyword;
5000         cmdline_fixed_string_t cmd_segsz;
5001         uint16_t cmd_size;
5002 };
5003
5004 static void
5005 cmd_gso_size_parsed(void *parsed_result,
5006                        __attribute__((unused)) struct cmdline *cl,
5007                        __attribute__((unused)) void *data)
5008 {
5009         struct cmd_gso_size_result *res = parsed_result;
5010
5011         if (test_done == 0) {
5012                 printf("Before setting GSO segsz, please first"
5013                                 " stop fowarding\n");
5014                 return;
5015         }
5016
5017         if (!strcmp(res->cmd_keyword, "gso") &&
5018                         !strcmp(res->cmd_segsz, "segsz")) {
5019                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5020                         printf("gso_size should be larger than %zu."
5021                                         " Please input a legal value\n",
5022                                         RTE_GSO_SEG_SIZE_MIN);
5023                 else
5024                         gso_max_segment_size = res->cmd_size;
5025         }
5026 }
5027
5028 cmdline_parse_token_string_t cmd_gso_size_set =
5029         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5030                                 cmd_set, "set");
5031 cmdline_parse_token_string_t cmd_gso_size_keyword =
5032         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5033                                 cmd_keyword, "gso");
5034 cmdline_parse_token_string_t cmd_gso_size_segsz =
5035         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5036                                 cmd_segsz, "segsz");
5037 cmdline_parse_token_num_t cmd_gso_size_size =
5038         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5039                                 cmd_size, UINT16);
5040
5041 cmdline_parse_inst_t cmd_gso_size = {
5042         .f = cmd_gso_size_parsed,
5043         .data = NULL,
5044         .help_str = "set gso segsz <length>",
5045         .tokens = {
5046                 (void *)&cmd_gso_size_set,
5047                 (void *)&cmd_gso_size_keyword,
5048                 (void *)&cmd_gso_size_segsz,
5049                 (void *)&cmd_gso_size_size,
5050                 NULL,
5051         },
5052 };
5053
5054 /* *** SHOW GSO CONFIGURATION *** */
5055 struct cmd_gso_show_result {
5056         cmdline_fixed_string_t cmd_show;
5057         cmdline_fixed_string_t cmd_port;
5058         cmdline_fixed_string_t cmd_keyword;
5059         portid_t cmd_pid;
5060 };
5061
5062 static void
5063 cmd_gso_show_parsed(void *parsed_result,
5064                        __attribute__((unused)) struct cmdline *cl,
5065                        __attribute__((unused)) void *data)
5066 {
5067         struct cmd_gso_show_result *res = parsed_result;
5068
5069         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5070                 printf("invalid port id %u\n", res->cmd_pid);
5071                 return;
5072         }
5073         if (!strcmp(res->cmd_keyword, "gso")) {
5074                 if (gso_ports[res->cmd_pid].enable) {
5075                         printf("Max GSO'd packet size: %uB\n"
5076                                         "Supported GSO types: TCP/IPv4, "
5077                                         "UDP/IPv4, VxLAN with inner "
5078                                         "TCP/IPv4 packet, GRE with inner "
5079                                         "TCP/IPv4 packet\n",
5080                                         gso_max_segment_size);
5081                 } else
5082                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5083         }
5084 }
5085
5086 cmdline_parse_token_string_t cmd_gso_show_show =
5087 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5088                 cmd_show, "show");
5089 cmdline_parse_token_string_t cmd_gso_show_port =
5090 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5091                 cmd_port, "port");
5092 cmdline_parse_token_string_t cmd_gso_show_keyword =
5093         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5094                                 cmd_keyword, "gso");
5095 cmdline_parse_token_num_t cmd_gso_show_pid =
5096         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5097                                 cmd_pid, UINT16);
5098
5099 cmdline_parse_inst_t cmd_gso_show = {
5100         .f = cmd_gso_show_parsed,
5101         .data = NULL,
5102         .help_str = "show port <port_id> gso",
5103         .tokens = {
5104                 (void *)&cmd_gso_show_show,
5105                 (void *)&cmd_gso_show_port,
5106                 (void *)&cmd_gso_show_pid,
5107                 (void *)&cmd_gso_show_keyword,
5108                 NULL,
5109         },
5110 };
5111
5112 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5113 struct cmd_set_flush_rx {
5114         cmdline_fixed_string_t set;
5115         cmdline_fixed_string_t flush_rx;
5116         cmdline_fixed_string_t mode;
5117 };
5118
5119 static void
5120 cmd_set_flush_rx_parsed(void *parsed_result,
5121                 __attribute__((unused)) struct cmdline *cl,
5122                 __attribute__((unused)) void *data)
5123 {
5124         struct cmd_set_flush_rx *res = parsed_result;
5125         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5126 }
5127
5128 cmdline_parse_token_string_t cmd_setflushrx_set =
5129         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5130                         set, "set");
5131 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5132         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5133                         flush_rx, "flush_rx");
5134 cmdline_parse_token_string_t cmd_setflushrx_mode =
5135         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5136                         mode, "on#off");
5137
5138
5139 cmdline_parse_inst_t cmd_set_flush_rx = {
5140         .f = cmd_set_flush_rx_parsed,
5141         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5142         .data = NULL,
5143         .tokens = {
5144                 (void *)&cmd_setflushrx_set,
5145                 (void *)&cmd_setflushrx_flush_rx,
5146                 (void *)&cmd_setflushrx_mode,
5147                 NULL,
5148         },
5149 };
5150
5151 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5152 struct cmd_set_link_check {
5153         cmdline_fixed_string_t set;
5154         cmdline_fixed_string_t link_check;
5155         cmdline_fixed_string_t mode;
5156 };
5157
5158 static void
5159 cmd_set_link_check_parsed(void *parsed_result,
5160                 __attribute__((unused)) struct cmdline *cl,
5161                 __attribute__((unused)) void *data)
5162 {
5163         struct cmd_set_link_check *res = parsed_result;
5164         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5165 }
5166
5167 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5168         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5169                         set, "set");
5170 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5171         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5172                         link_check, "link_check");
5173 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5174         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5175                         mode, "on#off");
5176
5177
5178 cmdline_parse_inst_t cmd_set_link_check = {
5179         .f = cmd_set_link_check_parsed,
5180         .help_str = "set link_check on|off: Enable/Disable link status check "
5181                     "when starting/stopping a port",
5182         .data = NULL,
5183         .tokens = {
5184                 (void *)&cmd_setlinkcheck_set,
5185                 (void *)&cmd_setlinkcheck_link_check,
5186                 (void *)&cmd_setlinkcheck_mode,
5187                 NULL,
5188         },
5189 };
5190
5191 /* *** SET NIC BYPASS MODE *** */
5192 struct cmd_set_bypass_mode_result {
5193         cmdline_fixed_string_t set;
5194         cmdline_fixed_string_t bypass;
5195         cmdline_fixed_string_t mode;
5196         cmdline_fixed_string_t value;
5197         portid_t port_id;
5198 };
5199
5200 static void
5201 cmd_set_bypass_mode_parsed(void *parsed_result,
5202                 __attribute__((unused)) struct cmdline *cl,
5203                 __attribute__((unused)) void *data)
5204 {
5205         struct cmd_set_bypass_mode_result *res = parsed_result;
5206         portid_t port_id = res->port_id;
5207         int32_t rc = -EINVAL;
5208
5209 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5210         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5211
5212         if (!strcmp(res->value, "bypass"))
5213                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5214         else if (!strcmp(res->value, "isolate"))
5215                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5216         else
5217                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5218
5219         /* Set the bypass mode for the relevant port. */
5220         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5221 #endif
5222         if (rc != 0)
5223                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5224 }
5225
5226 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5227         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5228                         set, "set");
5229 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5230         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5231                         bypass, "bypass");
5232 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5233         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5234                         mode, "mode");
5235 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5236         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5237                         value, "normal#bypass#isolate");
5238 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5239         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5240                                 port_id, UINT16);
5241
5242 cmdline_parse_inst_t cmd_set_bypass_mode = {
5243         .f = cmd_set_bypass_mode_parsed,
5244         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5245                     "Set the NIC bypass mode for port_id",
5246         .data = NULL,
5247         .tokens = {
5248                 (void *)&cmd_setbypass_mode_set,
5249                 (void *)&cmd_setbypass_mode_bypass,
5250                 (void *)&cmd_setbypass_mode_mode,
5251                 (void *)&cmd_setbypass_mode_value,
5252                 (void *)&cmd_setbypass_mode_port,
5253                 NULL,
5254         },
5255 };
5256
5257 /* *** SET NIC BYPASS EVENT *** */
5258 struct cmd_set_bypass_event_result {
5259         cmdline_fixed_string_t set;
5260         cmdline_fixed_string_t bypass;
5261         cmdline_fixed_string_t event;
5262         cmdline_fixed_string_t event_value;
5263         cmdline_fixed_string_t mode;
5264         cmdline_fixed_string_t mode_value;
5265         portid_t port_id;
5266 };
5267
5268 static void
5269 cmd_set_bypass_event_parsed(void *parsed_result,
5270                 __attribute__((unused)) struct cmdline *cl,
5271                 __attribute__((unused)) void *data)
5272 {
5273         int32_t rc = -EINVAL;
5274         struct cmd_set_bypass_event_result *res = parsed_result;
5275         portid_t port_id = res->port_id;
5276
5277 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5278         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5279         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5280
5281         if (!strcmp(res->event_value, "timeout"))
5282                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5283         else if (!strcmp(res->event_value, "os_on"))
5284                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5285         else if (!strcmp(res->event_value, "os_off"))
5286                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5287         else if (!strcmp(res->event_value, "power_on"))
5288                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5289         else if (!strcmp(res->event_value, "power_off"))
5290                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5291         else
5292                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5293
5294         if (!strcmp(res->mode_value, "bypass"))
5295                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5296         else if (!strcmp(res->mode_value, "isolate"))
5297                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5298         else
5299                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5300
5301         /* Set the watchdog timeout. */
5302         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5303
5304                 rc = -EINVAL;
5305                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5306                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5307                                                            bypass_timeout);
5308                 }
5309                 if (rc != 0) {
5310                         printf("Failed to set timeout value %u "
5311                         "for port %d, errto code: %d.\n",
5312                         bypass_timeout, port_id, rc);
5313                 }
5314         }
5315
5316         /* Set the bypass event to transition to bypass mode. */
5317         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5318                                               bypass_mode);
5319 #endif
5320
5321         if (rc != 0)
5322                 printf("\t Failed to set bypass event for port = %d.\n",
5323                        port_id);
5324 }
5325
5326 cmdline_parse_token_string_t cmd_setbypass_event_set =
5327         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5328                         set, "set");
5329 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5330         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5331                         bypass, "bypass");
5332 cmdline_parse_token_string_t cmd_setbypass_event_event =
5333         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5334                         event, "event");
5335 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5336         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5337                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5338 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5339         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5340                         mode, "mode");
5341 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5342         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5343                         mode_value, "normal#bypass#isolate");
5344 cmdline_parse_token_num_t cmd_setbypass_event_port =
5345         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5346                                 port_id, UINT16);
5347
5348 cmdline_parse_inst_t cmd_set_bypass_event = {
5349         .f = cmd_set_bypass_event_parsed,
5350         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5351                 "power_off mode normal|bypass|isolate <port_id>: "
5352                 "Set the NIC bypass event mode for port_id",
5353         .data = NULL,
5354         .tokens = {
5355                 (void *)&cmd_setbypass_event_set,
5356                 (void *)&cmd_setbypass_event_bypass,
5357                 (void *)&cmd_setbypass_event_event,
5358                 (void *)&cmd_setbypass_event_event_value,
5359                 (void *)&cmd_setbypass_event_mode,
5360                 (void *)&cmd_setbypass_event_mode_value,
5361                 (void *)&cmd_setbypass_event_port,
5362                 NULL,
5363         },
5364 };
5365
5366
5367 /* *** SET NIC BYPASS TIMEOUT *** */
5368 struct cmd_set_bypass_timeout_result {
5369         cmdline_fixed_string_t set;
5370         cmdline_fixed_string_t bypass;
5371         cmdline_fixed_string_t timeout;
5372         cmdline_fixed_string_t value;
5373 };
5374
5375 static void
5376 cmd_set_bypass_timeout_parsed(void *parsed_result,
5377                 __attribute__((unused)) struct cmdline *cl,
5378                 __attribute__((unused)) void *data)
5379 {
5380         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5381
5382 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5383         if (!strcmp(res->value, "1.5"))
5384                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5385         else if (!strcmp(res->value, "2"))
5386                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5387         else if (!strcmp(res->value, "3"))
5388                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5389         else if (!strcmp(res->value, "4"))
5390                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5391         else if (!strcmp(res->value, "8"))
5392                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5393         else if (!strcmp(res->value, "16"))
5394                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5395         else if (!strcmp(res->value, "32"))
5396                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5397         else
5398                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5399 #endif
5400 }
5401
5402 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5403         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5404                         set, "set");
5405 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5406         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5407                         bypass, "bypass");
5408 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5409         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5410                         timeout, "timeout");
5411 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5412         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5413                         value, "0#1.5#2#3#4#8#16#32");
5414
5415 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5416         .f = cmd_set_bypass_timeout_parsed,
5417         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5418                 "Set the NIC bypass watchdog timeout in seconds",
5419         .data = NULL,
5420         .tokens = {
5421                 (void *)&cmd_setbypass_timeout_set,
5422                 (void *)&cmd_setbypass_timeout_bypass,
5423                 (void *)&cmd_setbypass_timeout_timeout,
5424                 (void *)&cmd_setbypass_timeout_value,
5425                 NULL,
5426         },
5427 };
5428
5429 /* *** SHOW NIC BYPASS MODE *** */
5430 struct cmd_show_bypass_config_result {
5431         cmdline_fixed_string_t show;
5432         cmdline_fixed_string_t bypass;
5433         cmdline_fixed_string_t config;
5434         portid_t port_id;
5435 };
5436
5437 static void
5438 cmd_show_bypass_config_parsed(void *parsed_result,
5439                 __attribute__((unused)) struct cmdline *cl,
5440                 __attribute__((unused)) void *data)
5441 {
5442         struct cmd_show_bypass_config_result *res = parsed_result;
5443         portid_t port_id = res->port_id;
5444         int rc = -EINVAL;
5445 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5446         uint32_t event_mode;
5447         uint32_t bypass_mode;
5448         uint32_t timeout = bypass_timeout;
5449         int i;
5450
5451         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5452                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5453         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5454                 {"UNKNOWN", "normal", "bypass", "isolate"};
5455         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5456                 "NONE",
5457                 "OS/board on",
5458                 "power supply on",
5459                 "OS/board off",
5460                 "power supply off",
5461                 "timeout"};
5462         int num_events = (sizeof events) / (sizeof events[0]);
5463
5464         /* Display the bypass mode.*/
5465         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5466                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5467                 return;
5468         }
5469         else {
5470                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5471                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5472
5473                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5474         }
5475
5476         /* Display the bypass timeout.*/
5477         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5478                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5479
5480         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5481
5482         /* Display the bypass events and associated modes. */
5483         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5484
5485                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5486                         printf("\tFailed to get bypass mode for event = %s\n",
5487                                 events[i]);
5488                 } else {
5489                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5490                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5491
5492                         printf("\tbypass event: %-16s = %s\n", events[i],
5493                                 modes[event_mode]);
5494                 }
5495         }
5496 #endif
5497         if (rc != 0)
5498                 printf("\tFailed to get bypass configuration for port = %d\n",
5499                        port_id);
5500 }
5501
5502 cmdline_parse_token_string_t cmd_showbypass_config_show =
5503         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5504                         show, "show");
5505 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5506         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5507                         bypass, "bypass");
5508 cmdline_parse_token_string_t cmd_showbypass_config_config =
5509         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5510                         config, "config");
5511 cmdline_parse_token_num_t cmd_showbypass_config_port =
5512         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5513                                 port_id, UINT16);
5514
5515 cmdline_parse_inst_t cmd_show_bypass_config = {
5516         .f = cmd_show_bypass_config_parsed,
5517         .help_str = "show bypass config <port_id>: "
5518                     "Show the NIC bypass config for port_id",
5519         .data = NULL,
5520         .tokens = {
5521                 (void *)&cmd_showbypass_config_show,
5522                 (void *)&cmd_showbypass_config_bypass,
5523                 (void *)&cmd_showbypass_config_config,
5524                 (void *)&cmd_showbypass_config_port,
5525                 NULL,
5526         },
5527 };
5528
5529 #ifdef RTE_LIBRTE_PMD_BOND
5530 /* *** SET BONDING MODE *** */
5531 struct cmd_set_bonding_mode_result {
5532         cmdline_fixed_string_t set;
5533         cmdline_fixed_string_t bonding;
5534         cmdline_fixed_string_t mode;
5535         uint8_t value;
5536         portid_t port_id;
5537 };
5538
5539 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5540                 __attribute__((unused))  struct cmdline *cl,
5541                 __attribute__((unused)) void *data)
5542 {
5543         struct cmd_set_bonding_mode_result *res = parsed_result;
5544         portid_t port_id = res->port_id;
5545
5546         /* Set the bonding mode for the relevant port. */
5547         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5548                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5549 }
5550
5551 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5552 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5553                 set, "set");
5554 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5555 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5556                 bonding, "bonding");
5557 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5558 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5559                 mode, "mode");
5560 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5561 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5562                 value, UINT8);
5563 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5564 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5565                 port_id, UINT16);
5566
5567 cmdline_parse_inst_t cmd_set_bonding_mode = {
5568                 .f = cmd_set_bonding_mode_parsed,
5569                 .help_str = "set bonding mode <mode_value> <port_id>: "
5570                         "Set the bonding mode for port_id",
5571                 .data = NULL,
5572                 .tokens = {
5573                                 (void *) &cmd_setbonding_mode_set,
5574                                 (void *) &cmd_setbonding_mode_bonding,
5575                                 (void *) &cmd_setbonding_mode_mode,
5576                                 (void *) &cmd_setbonding_mode_value,
5577                                 (void *) &cmd_setbonding_mode_port,
5578                                 NULL
5579                 }
5580 };
5581
5582 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5583 struct cmd_set_bonding_lacp_dedicated_queues_result {
5584         cmdline_fixed_string_t set;
5585         cmdline_fixed_string_t bonding;
5586         cmdline_fixed_string_t lacp;
5587         cmdline_fixed_string_t dedicated_queues;
5588         portid_t port_id;
5589         cmdline_fixed_string_t mode;
5590 };
5591
5592 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5593                 __attribute__((unused))  struct cmdline *cl,
5594                 __attribute__((unused)) void *data)
5595 {
5596         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5597         portid_t port_id = res->port_id;
5598         struct rte_port *port;
5599
5600         port = &ports[port_id];
5601
5602         /** Check if the port is not started **/
5603         if (port->port_status != RTE_PORT_STOPPED) {
5604                 printf("Please stop port %d first\n", port_id);
5605                 return;
5606         }
5607
5608         if (!strcmp(res->mode, "enable")) {
5609                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5610                         printf("Dedicate queues for LACP control packets"
5611                                         " enabled\n");
5612                 else
5613                         printf("Enabling dedicate queues for LACP control "
5614                                         "packets on port %d failed\n", port_id);
5615         } else if (!strcmp(res->mode, "disable")) {
5616                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5617                         printf("Dedicated queues for LACP control packets "
5618                                         "disabled\n");
5619                 else
5620                         printf("Disabling dedicated queues for LACP control "
5621                                         "traffic on port %d failed\n", port_id);
5622         }
5623 }
5624
5625 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5626 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5627                 set, "set");
5628 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5629 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5630                 bonding, "bonding");
5631 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5632 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5633                 lacp, "lacp");
5634 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5635 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5636                 dedicated_queues, "dedicated_queues");
5637 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5638 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5639                 port_id, UINT16);
5640 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5641 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5642                 mode, "enable#disable");
5643
5644 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5645                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5646                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5647                         "enable|disable: "
5648                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5649                 .data = NULL,
5650                 .tokens = {
5651                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5652                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5653                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5654                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5655                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5656                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5657                         NULL
5658                 }
5659 };
5660
5661 /* *** SET BALANCE XMIT POLICY *** */
5662 struct cmd_set_bonding_balance_xmit_policy_result {
5663         cmdline_fixed_string_t set;
5664         cmdline_fixed_string_t bonding;
5665         cmdline_fixed_string_t balance_xmit_policy;
5666         portid_t port_id;
5667         cmdline_fixed_string_t policy;
5668 };
5669
5670 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5671                 __attribute__((unused))  struct cmdline *cl,
5672                 __attribute__((unused)) void *data)
5673 {
5674         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5675         portid_t port_id = res->port_id;
5676         uint8_t policy;
5677
5678         if (!strcmp(res->policy, "l2")) {
5679                 policy = BALANCE_XMIT_POLICY_LAYER2;
5680         } else if (!strcmp(res->policy, "l23")) {
5681                 policy = BALANCE_XMIT_POLICY_LAYER23;
5682         } else if (!strcmp(res->policy, "l34")) {
5683                 policy = BALANCE_XMIT_POLICY_LAYER34;
5684         } else {
5685                 printf("\t Invalid xmit policy selection");
5686                 return;
5687         }
5688
5689         /* Set the bonding mode for the relevant port. */
5690         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5691                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5692                                 port_id);
5693         }
5694 }
5695
5696 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5697 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5698                 set, "set");
5699 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5700 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5701                 bonding, "bonding");
5702 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5703 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5704                 balance_xmit_policy, "balance_xmit_policy");
5705 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5706 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5707                 port_id, UINT16);
5708 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5709 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5710                 policy, "l2#l23#l34");
5711
5712 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5713                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5714                 .help_str = "set bonding balance_xmit_policy <port_id> "
5715                         "l2|l23|l34: "
5716                         "Set the bonding balance_xmit_policy for port_id",
5717                 .data = NULL,
5718                 .tokens = {
5719                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5720                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5721                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5722                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5723                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5724                                 NULL
5725                 }
5726 };
5727
5728 /* *** SHOW NIC BONDING CONFIGURATION *** */
5729 struct cmd_show_bonding_config_result {
5730         cmdline_fixed_string_t show;
5731         cmdline_fixed_string_t bonding;
5732         cmdline_fixed_string_t config;
5733         portid_t port_id;
5734 };
5735
5736 static void cmd_show_bonding_config_parsed(void *parsed_result,
5737                 __attribute__((unused))  struct cmdline *cl,
5738                 __attribute__((unused)) void *data)
5739 {
5740         struct cmd_show_bonding_config_result *res = parsed_result;
5741         int bonding_mode, agg_mode;
5742         portid_t slaves[RTE_MAX_ETHPORTS];
5743         int num_slaves, num_active_slaves;
5744         int primary_id;
5745         int i;
5746         portid_t port_id = res->port_id;
5747
5748         /* Display the bonding mode.*/
5749         bonding_mode = rte_eth_bond_mode_get(port_id);
5750         if (bonding_mode < 0) {
5751                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5752                 return;
5753         } else
5754                 printf("\tBonding mode: %d\n", bonding_mode);
5755
5756         if (bonding_mode == BONDING_MODE_BALANCE) {
5757                 int balance_xmit_policy;
5758
5759                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5760                 if (balance_xmit_policy < 0) {
5761                         printf("\tFailed to get balance xmit policy for port = %d\n",
5762                                         port_id);
5763                         return;
5764                 } else {
5765                         printf("\tBalance Xmit Policy: ");
5766
5767                         switch (balance_xmit_policy) {
5768                         case BALANCE_XMIT_POLICY_LAYER2:
5769                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5770                                 break;
5771                         case BALANCE_XMIT_POLICY_LAYER23:
5772                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5773                                 break;
5774                         case BALANCE_XMIT_POLICY_LAYER34:
5775                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5776                                 break;
5777                         }
5778                         printf("\n");
5779                 }
5780         }
5781
5782         if (bonding_mode == BONDING_MODE_8023AD) {
5783                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5784                 printf("\tIEEE802.3AD Aggregator Mode: ");
5785                 switch (agg_mode) {
5786                 case AGG_BANDWIDTH:
5787                         printf("bandwidth");
5788                         break;
5789                 case AGG_STABLE:
5790                         printf("stable");
5791                         break;
5792                 case AGG_COUNT:
5793                         printf("count");
5794                         break;
5795                 }
5796                 printf("\n");
5797         }
5798
5799         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5800
5801         if (num_slaves < 0) {
5802                 printf("\tFailed to get slave list for port = %d\n", port_id);
5803                 return;
5804         }
5805         if (num_slaves > 0) {
5806                 printf("\tSlaves (%d): [", num_slaves);
5807                 for (i = 0; i < num_slaves - 1; i++)
5808                         printf("%d ", slaves[i]);
5809
5810                 printf("%d]\n", slaves[num_slaves - 1]);
5811         } else {
5812                 printf("\tSlaves: []\n");
5813
5814         }
5815
5816         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5817                         RTE_MAX_ETHPORTS);
5818
5819         if (num_active_slaves < 0) {
5820                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5821                 return;
5822         }
5823         if (num_active_slaves > 0) {
5824                 printf("\tActive Slaves (%d): [", num_active_slaves);
5825                 for (i = 0; i < num_active_slaves - 1; i++)
5826                         printf("%d ", slaves[i]);
5827
5828                 printf("%d]\n", slaves[num_active_slaves - 1]);
5829
5830         } else {
5831                 printf("\tActive Slaves: []\n");
5832
5833         }
5834
5835         primary_id = rte_eth_bond_primary_get(port_id);
5836         if (primary_id < 0) {
5837                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5838                 return;
5839         } else
5840                 printf("\tPrimary: [%d]\n", primary_id);
5841
5842 }
5843
5844 cmdline_parse_token_string_t cmd_showbonding_config_show =
5845 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5846                 show, "show");
5847 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5848 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5849                 bonding, "bonding");
5850 cmdline_parse_token_string_t cmd_showbonding_config_config =
5851 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5852                 config, "config");
5853 cmdline_parse_token_num_t cmd_showbonding_config_port =
5854 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5855                 port_id, UINT16);
5856
5857 cmdline_parse_inst_t cmd_show_bonding_config = {
5858                 .f = cmd_show_bonding_config_parsed,
5859                 .help_str = "show bonding config <port_id>: "
5860                         "Show the bonding config for port_id",
5861                 .data = NULL,
5862                 .tokens = {
5863                                 (void *)&cmd_showbonding_config_show,
5864                                 (void *)&cmd_showbonding_config_bonding,
5865                                 (void *)&cmd_showbonding_config_config,
5866                                 (void *)&cmd_showbonding_config_port,
5867                                 NULL
5868                 }
5869 };
5870
5871 /* *** SET BONDING PRIMARY *** */
5872 struct cmd_set_bonding_primary_result {
5873         cmdline_fixed_string_t set;
5874         cmdline_fixed_string_t bonding;
5875         cmdline_fixed_string_t primary;
5876         portid_t slave_id;
5877         portid_t port_id;
5878 };
5879
5880 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5881                 __attribute__((unused))  struct cmdline *cl,
5882                 __attribute__((unused)) void *data)
5883 {
5884         struct cmd_set_bonding_primary_result *res = parsed_result;
5885         portid_t master_port_id = res->port_id;
5886         portid_t slave_port_id = res->slave_id;
5887
5888         /* Set the primary slave for a bonded device. */
5889         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5890                 printf("\t Failed to set primary slave for port = %d.\n",
5891                                 master_port_id);
5892                 return;
5893         }
5894         init_port_config();
5895 }
5896
5897 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5898 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5899                 set, "set");
5900 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5901 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5902                 bonding, "bonding");
5903 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5904 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5905                 primary, "primary");
5906 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5907 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5908                 slave_id, UINT16);
5909 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5910 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5911                 port_id, UINT16);
5912
5913 cmdline_parse_inst_t cmd_set_bonding_primary = {
5914                 .f = cmd_set_bonding_primary_parsed,
5915                 .help_str = "set bonding primary <slave_id> <port_id>: "
5916                         "Set the primary slave for port_id",
5917                 .data = NULL,
5918                 .tokens = {
5919                                 (void *)&cmd_setbonding_primary_set,
5920                                 (void *)&cmd_setbonding_primary_bonding,
5921                                 (void *)&cmd_setbonding_primary_primary,
5922                                 (void *)&cmd_setbonding_primary_slave,
5923                                 (void *)&cmd_setbonding_primary_port,
5924                                 NULL
5925                 }
5926 };
5927
5928 /* *** ADD SLAVE *** */
5929 struct cmd_add_bonding_slave_result {
5930         cmdline_fixed_string_t add;
5931         cmdline_fixed_string_t bonding;
5932         cmdline_fixed_string_t slave;
5933         portid_t slave_id;
5934         portid_t port_id;
5935 };
5936
5937 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5938                 __attribute__((unused))  struct cmdline *cl,
5939                 __attribute__((unused)) void *data)
5940 {
5941         struct cmd_add_bonding_slave_result *res = parsed_result;
5942         portid_t master_port_id = res->port_id;
5943         portid_t slave_port_id = res->slave_id;
5944
5945         /* add the slave for a bonded device. */
5946         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5947                 printf("\t Failed to add slave %d to master port = %d.\n",
5948                                 slave_port_id, master_port_id);
5949                 return;
5950         }
5951         init_port_config();
5952         set_port_slave_flag(slave_port_id);
5953 }
5954
5955 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5956 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5957                 add, "add");
5958 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5959 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5960                 bonding, "bonding");
5961 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5962 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5963                 slave, "slave");
5964 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5965 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5966                 slave_id, UINT16);
5967 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5968 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5969                 port_id, UINT16);
5970
5971 cmdline_parse_inst_t cmd_add_bonding_slave = {
5972                 .f = cmd_add_bonding_slave_parsed,
5973                 .help_str = "add bonding slave <slave_id> <port_id>: "
5974                         "Add a slave device to a bonded device",
5975                 .data = NULL,
5976                 .tokens = {
5977                                 (void *)&cmd_addbonding_slave_add,
5978                                 (void *)&cmd_addbonding_slave_bonding,
5979                                 (void *)&cmd_addbonding_slave_slave,
5980                                 (void *)&cmd_addbonding_slave_slaveid,
5981                                 (void *)&cmd_addbonding_slave_port,
5982                                 NULL
5983                 }
5984 };
5985
5986 /* *** REMOVE SLAVE *** */
5987 struct cmd_remove_bonding_slave_result {
5988         cmdline_fixed_string_t remove;
5989         cmdline_fixed_string_t bonding;
5990         cmdline_fixed_string_t slave;
5991         portid_t slave_id;
5992         portid_t port_id;
5993 };
5994
5995 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5996                 __attribute__((unused))  struct cmdline *cl,
5997                 __attribute__((unused)) void *data)
5998 {
5999         struct cmd_remove_bonding_slave_result *res = parsed_result;
6000         portid_t master_port_id = res->port_id;
6001         portid_t slave_port_id = res->slave_id;
6002
6003         /* remove the slave from a bonded device. */
6004         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6005                 printf("\t Failed to remove slave %d from master port = %d.\n",
6006                                 slave_port_id, master_port_id);
6007                 return;
6008         }
6009         init_port_config();
6010         clear_port_slave_flag(slave_port_id);
6011 }
6012
6013 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6014                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6015                                 remove, "remove");
6016 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6017                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6018                                 bonding, "bonding");
6019 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6020                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6021                                 slave, "slave");
6022 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6023                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6024                                 slave_id, UINT16);
6025 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6026                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6027                                 port_id, UINT16);
6028
6029 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6030                 .f = cmd_remove_bonding_slave_parsed,
6031                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6032                         "Remove a slave device from a bonded device",
6033                 .data = NULL,
6034                 .tokens = {
6035                                 (void *)&cmd_removebonding_slave_remove,
6036                                 (void *)&cmd_removebonding_slave_bonding,
6037                                 (void *)&cmd_removebonding_slave_slave,
6038                                 (void *)&cmd_removebonding_slave_slaveid,
6039                                 (void *)&cmd_removebonding_slave_port,
6040                                 NULL
6041                 }
6042 };
6043
6044 /* *** CREATE BONDED DEVICE *** */
6045 struct cmd_create_bonded_device_result {
6046         cmdline_fixed_string_t create;
6047         cmdline_fixed_string_t bonded;
6048         cmdline_fixed_string_t device;
6049         uint8_t mode;
6050         uint8_t socket;
6051 };
6052
6053 static int bond_dev_num = 0;
6054
6055 static void cmd_create_bonded_device_parsed(void *parsed_result,
6056                 __attribute__((unused))  struct cmdline *cl,
6057                 __attribute__((unused)) void *data)
6058 {
6059         struct cmd_create_bonded_device_result *res = parsed_result;
6060         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6061         int port_id;
6062
6063         if (test_done == 0) {
6064                 printf("Please stop forwarding first\n");
6065                 return;
6066         }
6067
6068         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6069                         bond_dev_num++);
6070
6071         /* Create a new bonded device. */
6072         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6073         if (port_id < 0) {
6074                 printf("\t Failed to create bonded device.\n");
6075                 return;
6076         } else {
6077                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6078                                 port_id);
6079
6080                 /* Update number of ports */
6081                 nb_ports = rte_eth_dev_count_avail();
6082                 reconfig(port_id, res->socket);
6083                 rte_eth_promiscuous_enable(port_id);
6084                 ports[port_id].need_setup = 0;
6085                 ports[port_id].port_status = RTE_PORT_STOPPED;
6086         }
6087
6088 }
6089
6090 cmdline_parse_token_string_t cmd_createbonded_device_create =
6091                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6092                                 create, "create");
6093 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6094                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6095                                 bonded, "bonded");
6096 cmdline_parse_token_string_t cmd_createbonded_device_device =
6097                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6098                                 device, "device");
6099 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6100                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6101                                 mode, UINT8);
6102 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6103                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6104                                 socket, UINT8);
6105
6106 cmdline_parse_inst_t cmd_create_bonded_device = {
6107                 .f = cmd_create_bonded_device_parsed,
6108                 .help_str = "create bonded device <mode> <socket>: "
6109                         "Create a new bonded device with specific bonding mode and socket",
6110                 .data = NULL,
6111                 .tokens = {
6112                                 (void *)&cmd_createbonded_device_create,
6113                                 (void *)&cmd_createbonded_device_bonded,
6114                                 (void *)&cmd_createbonded_device_device,
6115                                 (void *)&cmd_createbonded_device_mode,
6116                                 (void *)&cmd_createbonded_device_socket,
6117                                 NULL
6118                 }
6119 };
6120
6121 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6122 struct cmd_set_bond_mac_addr_result {
6123         cmdline_fixed_string_t set;
6124         cmdline_fixed_string_t bonding;
6125         cmdline_fixed_string_t mac_addr;
6126         uint16_t port_num;
6127         struct rte_ether_addr address;
6128 };
6129
6130 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6131                 __attribute__((unused))  struct cmdline *cl,
6132                 __attribute__((unused)) void *data)
6133 {
6134         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6135         int ret;
6136
6137         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6138                 return;
6139
6140         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6141
6142         /* check the return value and print it if is < 0 */
6143         if (ret < 0)
6144                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6145 }
6146
6147 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6148                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6149 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6150                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6151                                 "bonding");
6152 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6153                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6154                                 "mac_addr");
6155 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6156                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6157                                 port_num, UINT16);
6158 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6159                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6160
6161 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6162                 .f = cmd_set_bond_mac_addr_parsed,
6163                 .data = (void *) 0,
6164                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6165                 .tokens = {
6166                                 (void *)&cmd_set_bond_mac_addr_set,
6167                                 (void *)&cmd_set_bond_mac_addr_bonding,
6168                                 (void *)&cmd_set_bond_mac_addr_mac,
6169                                 (void *)&cmd_set_bond_mac_addr_portnum,
6170                                 (void *)&cmd_set_bond_mac_addr_addr,
6171                                 NULL
6172                 }
6173 };
6174
6175
6176 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6177 struct cmd_set_bond_mon_period_result {
6178         cmdline_fixed_string_t set;
6179         cmdline_fixed_string_t bonding;
6180         cmdline_fixed_string_t mon_period;
6181         uint16_t port_num;
6182         uint32_t period_ms;
6183 };
6184
6185 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6186                 __attribute__((unused))  struct cmdline *cl,
6187                 __attribute__((unused)) void *data)
6188 {
6189         struct cmd_set_bond_mon_period_result *res = parsed_result;
6190         int ret;
6191
6192         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6193
6194         /* check the return value and print it if is < 0 */
6195         if (ret < 0)
6196                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6197 }
6198
6199 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6200                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6201                                 set, "set");
6202 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6203                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6204                                 bonding, "bonding");
6205 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6206                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6207                                 mon_period,     "mon_period");
6208 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6209                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6210                                 port_num, UINT16);
6211 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6212                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6213                                 period_ms, UINT32);
6214
6215 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6216                 .f = cmd_set_bond_mon_period_parsed,
6217                 .data = (void *) 0,
6218                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6219                 .tokens = {
6220                                 (void *)&cmd_set_bond_mon_period_set,
6221                                 (void *)&cmd_set_bond_mon_period_bonding,
6222                                 (void *)&cmd_set_bond_mon_period_mon_period,
6223                                 (void *)&cmd_set_bond_mon_period_portnum,
6224                                 (void *)&cmd_set_bond_mon_period_period_ms,
6225                                 NULL
6226                 }
6227 };
6228
6229
6230
6231 struct cmd_set_bonding_agg_mode_policy_result {
6232         cmdline_fixed_string_t set;
6233         cmdline_fixed_string_t bonding;
6234         cmdline_fixed_string_t agg_mode;
6235         uint16_t port_num;
6236         cmdline_fixed_string_t policy;
6237 };
6238
6239
6240 static void
6241 cmd_set_bonding_agg_mode(void *parsed_result,
6242                 __attribute__((unused)) struct cmdline *cl,
6243                 __attribute__((unused)) void *data)
6244 {
6245         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6246         uint8_t policy = AGG_BANDWIDTH;
6247
6248         if (!strcmp(res->policy, "bandwidth"))
6249                 policy = AGG_BANDWIDTH;
6250         else if (!strcmp(res->policy, "stable"))
6251                 policy = AGG_STABLE;
6252         else if (!strcmp(res->policy, "count"))
6253                 policy = AGG_COUNT;
6254
6255         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6256 }
6257
6258
6259 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6260         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6261                                 set, "set");
6262 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6263         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6264                                 bonding, "bonding");
6265
6266 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6267         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6268                                 agg_mode, "agg_mode");
6269
6270 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6271         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6272                                 port_num, UINT16);
6273
6274 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6275         TOKEN_STRING_INITIALIZER(
6276                         struct cmd_set_bonding_balance_xmit_policy_result,
6277                 policy, "stable#bandwidth#count");
6278
6279 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6280         .f = cmd_set_bonding_agg_mode,
6281         .data = (void *) 0,
6282         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6283         .tokens = {
6284                         (void *)&cmd_set_bonding_agg_mode_set,
6285                         (void *)&cmd_set_bonding_agg_mode_bonding,
6286                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6287                         (void *)&cmd_set_bonding_agg_mode_portnum,
6288                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6289                         NULL
6290                 }
6291 };
6292
6293
6294 #endif /* RTE_LIBRTE_PMD_BOND */
6295
6296 /* *** SET FORWARDING MODE *** */
6297 struct cmd_set_fwd_mode_result {
6298         cmdline_fixed_string_t set;
6299         cmdline_fixed_string_t fwd;
6300         cmdline_fixed_string_t mode;
6301 };
6302
6303 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6304                                     __attribute__((unused)) struct cmdline *cl,
6305                                     __attribute__((unused)) void *data)
6306 {
6307         struct cmd_set_fwd_mode_result *res = parsed_result;
6308
6309         retry_enabled = 0;
6310         set_pkt_forwarding_mode(res->mode);
6311 }
6312
6313 cmdline_parse_token_string_t cmd_setfwd_set =
6314         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6315 cmdline_parse_token_string_t cmd_setfwd_fwd =
6316         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6317 cmdline_parse_token_string_t cmd_setfwd_mode =
6318         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6319                 "" /* defined at init */);
6320
6321 cmdline_parse_inst_t cmd_set_fwd_mode = {
6322         .f = cmd_set_fwd_mode_parsed,
6323         .data = NULL,
6324         .help_str = NULL, /* defined at init */
6325         .tokens = {
6326                 (void *)&cmd_setfwd_set,
6327                 (void *)&cmd_setfwd_fwd,
6328                 (void *)&cmd_setfwd_mode,
6329                 NULL,
6330         },
6331 };
6332
6333 static void cmd_set_fwd_mode_init(void)
6334 {
6335         char *modes, *c;
6336         static char token[128];
6337         static char help[256];
6338         cmdline_parse_token_string_t *token_struct;
6339
6340         modes = list_pkt_forwarding_modes();
6341         snprintf(help, sizeof(help), "set fwd %s: "
6342                 "Set packet forwarding mode", modes);
6343         cmd_set_fwd_mode.help_str = help;
6344
6345         /* string token separator is # */
6346         for (c = token; *modes != '\0'; modes++)
6347                 if (*modes == '|')
6348                         *c++ = '#';
6349                 else
6350                         *c++ = *modes;
6351         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6352         token_struct->string_data.str = token;
6353 }
6354
6355 /* *** SET RETRY FORWARDING MODE *** */
6356 struct cmd_set_fwd_retry_mode_result {
6357         cmdline_fixed_string_t set;
6358         cmdline_fixed_string_t fwd;
6359         cmdline_fixed_string_t mode;
6360         cmdline_fixed_string_t retry;
6361 };
6362
6363 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6364                             __attribute__((unused)) struct cmdline *cl,
6365                             __attribute__((unused)) void *data)
6366 {
6367         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6368
6369         retry_enabled = 1;
6370         set_pkt_forwarding_mode(res->mode);
6371 }
6372
6373 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6374         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6375                         set, "set");
6376 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6377         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6378                         fwd, "fwd");
6379 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6380         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6381                         mode,
6382                 "" /* defined at init */);
6383 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6384         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6385                         retry, "retry");
6386
6387 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6388         .f = cmd_set_fwd_retry_mode_parsed,
6389         .data = NULL,
6390         .help_str = NULL, /* defined at init */
6391         .tokens = {
6392                 (void *)&cmd_setfwd_retry_set,
6393                 (void *)&cmd_setfwd_retry_fwd,
6394                 (void *)&cmd_setfwd_retry_mode,
6395                 (void *)&cmd_setfwd_retry_retry,
6396                 NULL,
6397         },
6398 };
6399
6400 static void cmd_set_fwd_retry_mode_init(void)
6401 {
6402         char *modes, *c;
6403         static char token[128];
6404         static char help[256];
6405         cmdline_parse_token_string_t *token_struct;
6406
6407         modes = list_pkt_forwarding_retry_modes();
6408         snprintf(help, sizeof(help), "set fwd %s retry: "
6409                 "Set packet forwarding mode with retry", modes);
6410         cmd_set_fwd_retry_mode.help_str = help;
6411
6412         /* string token separator is # */
6413         for (c = token; *modes != '\0'; modes++)
6414                 if (*modes == '|')
6415                         *c++ = '#';
6416                 else
6417                         *c++ = *modes;
6418         token_struct = (cmdline_parse_token_string_t *)
6419                 cmd_set_fwd_retry_mode.tokens[2];
6420         token_struct->string_data.str = token;
6421 }
6422
6423 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6424 struct cmd_set_burst_tx_retry_result {
6425         cmdline_fixed_string_t set;
6426         cmdline_fixed_string_t burst;
6427         cmdline_fixed_string_t tx;
6428         cmdline_fixed_string_t delay;
6429         uint32_t time;
6430         cmdline_fixed_string_t retry;
6431         uint32_t retry_num;
6432 };
6433
6434 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6435                                         __attribute__((unused)) struct cmdline *cl,
6436                                         __attribute__((unused)) void *data)
6437 {
6438         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6439
6440         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6441                 && !strcmp(res->tx, "tx")) {
6442                 if (!strcmp(res->delay, "delay"))
6443                         burst_tx_delay_time = res->time;
6444                 if (!strcmp(res->retry, "retry"))
6445                         burst_tx_retry_num = res->retry_num;
6446         }
6447
6448 }
6449
6450 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6451         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6452 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6453         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6454                                  "burst");
6455 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6456         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6457 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6458         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6459 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6460         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6461 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6462         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6463 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6464         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6465
6466 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6467         .f = cmd_set_burst_tx_retry_parsed,
6468         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6469         .tokens = {
6470                 (void *)&cmd_set_burst_tx_retry_set,
6471                 (void *)&cmd_set_burst_tx_retry_burst,
6472                 (void *)&cmd_set_burst_tx_retry_tx,
6473                 (void *)&cmd_set_burst_tx_retry_delay,
6474                 (void *)&cmd_set_burst_tx_retry_time,
6475                 (void *)&cmd_set_burst_tx_retry_retry,
6476                 (void *)&cmd_set_burst_tx_retry_retry_num,
6477                 NULL,
6478         },
6479 };
6480
6481 /* *** SET PROMISC MODE *** */
6482 struct cmd_set_promisc_mode_result {
6483         cmdline_fixed_string_t set;
6484         cmdline_fixed_string_t promisc;
6485         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6486         uint16_t port_num;               /* valid if "allports" argument == 0 */
6487         cmdline_fixed_string_t mode;
6488 };
6489
6490 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6491                                         __attribute__((unused)) struct cmdline *cl,
6492                                         void *allports)
6493 {
6494         struct cmd_set_promisc_mode_result *res = parsed_result;
6495         int enable;
6496         portid_t i;
6497
6498         if (!strcmp(res->mode, "on"))
6499                 enable = 1;
6500         else
6501                 enable = 0;
6502
6503         /* all ports */
6504         if (allports) {
6505                 RTE_ETH_FOREACH_DEV(i) {
6506                         if (enable)
6507                                 rte_eth_promiscuous_enable(i);
6508                         else
6509                                 rte_eth_promiscuous_disable(i);
6510                 }
6511         }
6512         else {
6513                 if (enable)
6514                         rte_eth_promiscuous_enable(res->port_num);
6515                 else
6516                         rte_eth_promiscuous_disable(res->port_num);
6517         }
6518 }
6519
6520 cmdline_parse_token_string_t cmd_setpromisc_set =
6521         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6522 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6523         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6524                                  "promisc");
6525 cmdline_parse_token_string_t cmd_setpromisc_portall =
6526         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6527                                  "all");
6528 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6529         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6530                               UINT16);
6531 cmdline_parse_token_string_t cmd_setpromisc_mode =
6532         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6533                                  "on#off");
6534
6535 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6536         .f = cmd_set_promisc_mode_parsed,
6537         .data = (void *)1,
6538         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6539         .tokens = {
6540                 (void *)&cmd_setpromisc_set,
6541                 (void *)&cmd_setpromisc_promisc,
6542                 (void *)&cmd_setpromisc_portall,
6543                 (void *)&cmd_setpromisc_mode,
6544                 NULL,
6545         },
6546 };
6547
6548 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6549         .f = cmd_set_promisc_mode_parsed,
6550         .data = (void *)0,
6551         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6552         .tokens = {
6553                 (void *)&cmd_setpromisc_set,
6554                 (void *)&cmd_setpromisc_promisc,
6555                 (void *)&cmd_setpromisc_portnum,
6556                 (void *)&cmd_setpromisc_mode,
6557                 NULL,
6558         },
6559 };
6560
6561 /* *** SET ALLMULTI MODE *** */
6562 struct cmd_set_allmulti_mode_result {
6563         cmdline_fixed_string_t set;
6564         cmdline_fixed_string_t allmulti;
6565         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6566         uint16_t port_num;               /* valid if "allports" argument == 0 */
6567         cmdline_fixed_string_t mode;
6568 };
6569
6570 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6571                                         __attribute__((unused)) struct cmdline *cl,
6572                                         void *allports)
6573 {
6574         struct cmd_set_allmulti_mode_result *res = parsed_result;
6575         int enable;
6576         portid_t i;
6577
6578         if (!strcmp(res->mode, "on"))
6579                 enable = 1;
6580         else
6581                 enable = 0;
6582
6583         /* all ports */
6584         if (allports) {
6585                 RTE_ETH_FOREACH_DEV(i) {
6586                         if (enable)
6587                                 rte_eth_allmulticast_enable(i);
6588                         else
6589                                 rte_eth_allmulticast_disable(i);
6590                 }
6591         }
6592         else {
6593                 if (enable)
6594                         rte_eth_allmulticast_enable(res->port_num);
6595                 else
6596                         rte_eth_allmulticast_disable(res->port_num);
6597         }
6598 }
6599
6600 cmdline_parse_token_string_t cmd_setallmulti_set =
6601         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6602 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6603         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6604                                  "allmulti");
6605 cmdline_parse_token_string_t cmd_setallmulti_portall =
6606         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6607                                  "all");
6608 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6609         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6610                               UINT16);
6611 cmdline_parse_token_string_t cmd_setallmulti_mode =
6612         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6613                                  "on#off");
6614
6615 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6616         .f = cmd_set_allmulti_mode_parsed,
6617         .data = (void *)1,
6618         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6619         .tokens = {
6620                 (void *)&cmd_setallmulti_set,
6621                 (void *)&cmd_setallmulti_allmulti,
6622                 (void *)&cmd_setallmulti_portall,
6623                 (void *)&cmd_setallmulti_mode,
6624                 NULL,
6625         },
6626 };
6627
6628 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6629         .f = cmd_set_allmulti_mode_parsed,
6630         .data = (void *)0,
6631         .help_str = "set allmulti <port_id> on|off: "
6632                 "Set allmulti mode on port_id",
6633         .tokens = {
6634                 (void *)&cmd_setallmulti_set,
6635                 (void *)&cmd_setallmulti_allmulti,
6636                 (void *)&cmd_setallmulti_portnum,
6637                 (void *)&cmd_setallmulti_mode,
6638                 NULL,
6639         },
6640 };
6641
6642 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6643 struct cmd_link_flow_ctrl_set_result {
6644         cmdline_fixed_string_t set;
6645         cmdline_fixed_string_t flow_ctrl;
6646         cmdline_fixed_string_t rx;
6647         cmdline_fixed_string_t rx_lfc_mode;
6648         cmdline_fixed_string_t tx;
6649         cmdline_fixed_string_t tx_lfc_mode;
6650         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6651         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6652         cmdline_fixed_string_t autoneg_str;
6653         cmdline_fixed_string_t autoneg;
6654         cmdline_fixed_string_t hw_str;
6655         uint32_t high_water;
6656         cmdline_fixed_string_t lw_str;
6657         uint32_t low_water;
6658         cmdline_fixed_string_t pt_str;
6659         uint16_t pause_time;
6660         cmdline_fixed_string_t xon_str;
6661         uint16_t send_xon;
6662         portid_t port_id;
6663 };
6664
6665 cmdline_parse_token_string_t cmd_lfc_set_set =
6666         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6667                                 set, "set");
6668 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6669         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6670                                 flow_ctrl, "flow_ctrl");
6671 cmdline_parse_token_string_t cmd_lfc_set_rx =
6672         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6673                                 rx, "rx");
6674 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6675         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6676                                 rx_lfc_mode, "on#off");
6677 cmdline_parse_token_string_t cmd_lfc_set_tx =
6678         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6679                                 tx, "tx");
6680 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6681         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6682                                 tx_lfc_mode, "on#off");
6683 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6684         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6685                                 hw_str, "high_water");
6686 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6687         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6688                                 high_water, UINT32);
6689 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6690         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6691                                 lw_str, "low_water");
6692 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6693         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6694                                 low_water, UINT32);
6695 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6696         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6697                                 pt_str, "pause_time");
6698 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6699         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6700                                 pause_time, UINT16);
6701 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6702         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6703                                 xon_str, "send_xon");
6704 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6705         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6706                                 send_xon, UINT16);
6707 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6708         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6709                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6710 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6711         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6712                                 mac_ctrl_frame_fwd_mode, "on#off");
6713 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6714         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6715                                 autoneg_str, "autoneg");
6716 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6717         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6718                                 autoneg, "on#off");
6719 cmdline_parse_token_num_t cmd_lfc_set_portid =
6720         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6721                                 port_id, UINT16);
6722
6723 /* forward declaration */
6724 static void
6725 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6726                               void *data);
6727
6728 cmdline_parse_inst_t cmd_link_flow_control_set = {
6729         .f = cmd_link_flow_ctrl_set_parsed,
6730         .data = NULL,
6731         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6732                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6733                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6734         .tokens = {
6735                 (void *)&cmd_lfc_set_set,
6736                 (void *)&cmd_lfc_set_flow_ctrl,
6737                 (void *)&cmd_lfc_set_rx,
6738                 (void *)&cmd_lfc_set_rx_mode,
6739                 (void *)&cmd_lfc_set_tx,
6740                 (void *)&cmd_lfc_set_tx_mode,
6741                 (void *)&cmd_lfc_set_high_water,
6742                 (void *)&cmd_lfc_set_low_water,
6743                 (void *)&cmd_lfc_set_pause_time,
6744                 (void *)&cmd_lfc_set_send_xon,
6745                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6746                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6747                 (void *)&cmd_lfc_set_autoneg_str,
6748                 (void *)&cmd_lfc_set_autoneg,
6749                 (void *)&cmd_lfc_set_portid,
6750                 NULL,
6751         },
6752 };
6753
6754 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6755         .f = cmd_link_flow_ctrl_set_parsed,
6756         .data = (void *)&cmd_link_flow_control_set_rx,
6757         .help_str = "set flow_ctrl rx on|off <port_id>: "
6758                 "Change rx flow control parameter",
6759         .tokens = {
6760                 (void *)&cmd_lfc_set_set,
6761                 (void *)&cmd_lfc_set_flow_ctrl,
6762                 (void *)&cmd_lfc_set_rx,
6763                 (void *)&cmd_lfc_set_rx_mode,
6764                 (void *)&cmd_lfc_set_portid,
6765                 NULL,
6766         },
6767 };
6768
6769 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6770         .f = cmd_link_flow_ctrl_set_parsed,
6771         .data = (void *)&cmd_link_flow_control_set_tx,
6772         .help_str = "set flow_ctrl tx on|off <port_id>: "
6773                 "Change tx flow control parameter",
6774         .tokens = {
6775                 (void *)&cmd_lfc_set_set,
6776                 (void *)&cmd_lfc_set_flow_ctrl,
6777                 (void *)&cmd_lfc_set_tx,
6778                 (void *)&cmd_lfc_set_tx_mode,
6779                 (void *)&cmd_lfc_set_portid,
6780                 NULL,
6781         },
6782 };
6783
6784 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6785         .f = cmd_link_flow_ctrl_set_parsed,
6786         .data = (void *)&cmd_link_flow_control_set_hw,
6787         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6788                 "Change high water flow control parameter",
6789         .tokens = {
6790                 (void *)&cmd_lfc_set_set,
6791                 (void *)&cmd_lfc_set_flow_ctrl,
6792                 (void *)&cmd_lfc_set_high_water_str,
6793                 (void *)&cmd_lfc_set_high_water,
6794                 (void *)&cmd_lfc_set_portid,
6795                 NULL,
6796         },
6797 };
6798
6799 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6800         .f = cmd_link_flow_ctrl_set_parsed,
6801         .data = (void *)&cmd_link_flow_control_set_lw,
6802         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6803                 "Change low water flow control parameter",
6804         .tokens = {
6805                 (void *)&cmd_lfc_set_set,
6806                 (void *)&cmd_lfc_set_flow_ctrl,
6807                 (void *)&cmd_lfc_set_low_water_str,
6808                 (void *)&cmd_lfc_set_low_water,
6809                 (void *)&cmd_lfc_set_portid,
6810                 NULL,
6811         },
6812 };
6813
6814 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6815         .f = cmd_link_flow_ctrl_set_parsed,
6816         .data = (void *)&cmd_link_flow_control_set_pt,
6817         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6818                 "Change pause time flow control parameter",
6819         .tokens = {
6820                 (void *)&cmd_lfc_set_set,
6821                 (void *)&cmd_lfc_set_flow_ctrl,
6822                 (void *)&cmd_lfc_set_pause_time_str,
6823                 (void *)&cmd_lfc_set_pause_time,
6824                 (void *)&cmd_lfc_set_portid,
6825                 NULL,
6826         },
6827 };
6828
6829 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6830         .f = cmd_link_flow_ctrl_set_parsed,
6831         .data = (void *)&cmd_link_flow_control_set_xon,
6832         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6833                 "Change send_xon flow control parameter",
6834         .tokens = {
6835                 (void *)&cmd_lfc_set_set,
6836                 (void *)&cmd_lfc_set_flow_ctrl,
6837                 (void *)&cmd_lfc_set_send_xon_str,
6838                 (void *)&cmd_lfc_set_send_xon,
6839                 (void *)&cmd_lfc_set_portid,
6840                 NULL,
6841         },
6842 };
6843
6844 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6845         .f = cmd_link_flow_ctrl_set_parsed,
6846         .data = (void *)&cmd_link_flow_control_set_macfwd,
6847         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6848                 "Change mac ctrl fwd flow control parameter",
6849         .tokens = {
6850                 (void *)&cmd_lfc_set_set,
6851                 (void *)&cmd_lfc_set_flow_ctrl,
6852                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6853                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6854                 (void *)&cmd_lfc_set_portid,
6855                 NULL,
6856         },
6857 };
6858
6859 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6860         .f = cmd_link_flow_ctrl_set_parsed,
6861         .data = (void *)&cmd_link_flow_control_set_autoneg,
6862         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6863                 "Change autoneg flow control parameter",
6864         .tokens = {
6865                 (void *)&cmd_lfc_set_set,
6866                 (void *)&cmd_lfc_set_flow_ctrl,
6867                 (void *)&cmd_lfc_set_autoneg_str,
6868                 (void *)&cmd_lfc_set_autoneg,
6869                 (void *)&cmd_lfc_set_portid,
6870                 NULL,
6871         },
6872 };
6873
6874 static void
6875 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6876                               __attribute__((unused)) struct cmdline *cl,
6877                               void *data)
6878 {
6879         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6880         cmdline_parse_inst_t *cmd = data;
6881         struct rte_eth_fc_conf fc_conf;
6882         int rx_fc_en = 0;
6883         int tx_fc_en = 0;
6884         int ret;
6885
6886         /*
6887          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6888          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6889          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6890          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6891          */
6892         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6893                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6894         };
6895
6896         /* Partial command line, retrieve current configuration */
6897         if (cmd) {
6898                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6899                 if (ret != 0) {
6900                         printf("cannot get current flow ctrl parameters, return"
6901                                "code = %d\n", ret);
6902                         return;
6903                 }
6904
6905                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6906                     (fc_conf.mode == RTE_FC_FULL))
6907                         rx_fc_en = 1;
6908                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6909                     (fc_conf.mode == RTE_FC_FULL))
6910                         tx_fc_en = 1;
6911         }
6912
6913         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6914                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6915
6916         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6917                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6918
6919         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6920
6921         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6922                 fc_conf.high_water = res->high_water;
6923
6924         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6925                 fc_conf.low_water = res->low_water;
6926
6927         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6928                 fc_conf.pause_time = res->pause_time;
6929
6930         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6931                 fc_conf.send_xon = res->send_xon;
6932
6933         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6934                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6935                         fc_conf.mac_ctrl_frame_fwd = 1;
6936                 else
6937                         fc_conf.mac_ctrl_frame_fwd = 0;
6938         }
6939
6940         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6941                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6942
6943         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6944         if (ret != 0)
6945                 printf("bad flow contrl parameter, return code = %d \n", ret);
6946 }
6947
6948 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6949 struct cmd_priority_flow_ctrl_set_result {
6950         cmdline_fixed_string_t set;
6951         cmdline_fixed_string_t pfc_ctrl;
6952         cmdline_fixed_string_t rx;
6953         cmdline_fixed_string_t rx_pfc_mode;
6954         cmdline_fixed_string_t tx;
6955         cmdline_fixed_string_t tx_pfc_mode;
6956         uint32_t high_water;
6957         uint32_t low_water;
6958         uint16_t pause_time;
6959         uint8_t  priority;
6960         portid_t port_id;
6961 };
6962
6963 static void
6964 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6965                        __attribute__((unused)) struct cmdline *cl,
6966                        __attribute__((unused)) void *data)
6967 {
6968         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6969         struct rte_eth_pfc_conf pfc_conf;
6970         int rx_fc_enable, tx_fc_enable;
6971         int ret;
6972
6973         /*
6974          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6975          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6976          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6977          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6978          */
6979         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6980                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6981         };
6982
6983         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6984         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6985         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6986         pfc_conf.fc.high_water = res->high_water;
6987         pfc_conf.fc.low_water  = res->low_water;
6988         pfc_conf.fc.pause_time = res->pause_time;
6989         pfc_conf.priority      = res->priority;
6990
6991         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6992         if (ret != 0)
6993                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6994 }
6995
6996 cmdline_parse_token_string_t cmd_pfc_set_set =
6997         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6998                                 set, "set");
6999 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7000         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7001                                 pfc_ctrl, "pfc_ctrl");
7002 cmdline_parse_token_string_t cmd_pfc_set_rx =
7003         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7004                                 rx, "rx");
7005 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7006         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7007                                 rx_pfc_mode, "on#off");
7008 cmdline_parse_token_string_t cmd_pfc_set_tx =
7009         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7010                                 tx, "tx");
7011 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7012         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7013                                 tx_pfc_mode, "on#off");
7014 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7015         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7016                                 high_water, UINT32);
7017 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7018         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7019                                 low_water, UINT32);
7020 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7021         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7022                                 pause_time, UINT16);
7023 cmdline_parse_token_num_t cmd_pfc_set_priority =
7024         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7025                                 priority, UINT8);
7026 cmdline_parse_token_num_t cmd_pfc_set_portid =
7027         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7028                                 port_id, UINT16);
7029
7030 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7031         .f = cmd_priority_flow_ctrl_set_parsed,
7032         .data = NULL,
7033         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7034                 "<pause_time> <priority> <port_id>: "
7035                 "Configure the Ethernet priority flow control",
7036         .tokens = {
7037                 (void *)&cmd_pfc_set_set,
7038                 (void *)&cmd_pfc_set_flow_ctrl,
7039                 (void *)&cmd_pfc_set_rx,
7040                 (void *)&cmd_pfc_set_rx_mode,
7041                 (void *)&cmd_pfc_set_tx,
7042                 (void *)&cmd_pfc_set_tx_mode,
7043                 (void *)&cmd_pfc_set_high_water,
7044                 (void *)&cmd_pfc_set_low_water,
7045                 (void *)&cmd_pfc_set_pause_time,
7046                 (void *)&cmd_pfc_set_priority,
7047                 (void *)&cmd_pfc_set_portid,
7048                 NULL,
7049         },
7050 };
7051
7052 /* *** RESET CONFIGURATION *** */
7053 struct cmd_reset_result {
7054         cmdline_fixed_string_t reset;
7055         cmdline_fixed_string_t def;
7056 };
7057
7058 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7059                              struct cmdline *cl,
7060                              __attribute__((unused)) void *data)
7061 {
7062         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7063         set_def_fwd_config();
7064 }
7065
7066 cmdline_parse_token_string_t cmd_reset_set =
7067         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7068 cmdline_parse_token_string_t cmd_reset_def =
7069         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7070                                  "default");
7071
7072 cmdline_parse_inst_t cmd_reset = {
7073         .f = cmd_reset_parsed,
7074         .data = NULL,
7075         .help_str = "set default: Reset default forwarding configuration",
7076         .tokens = {
7077                 (void *)&cmd_reset_set,
7078                 (void *)&cmd_reset_def,
7079                 NULL,
7080         },
7081 };
7082
7083 /* *** START FORWARDING *** */
7084 struct cmd_start_result {
7085         cmdline_fixed_string_t start;
7086 };
7087
7088 cmdline_parse_token_string_t cmd_start_start =
7089         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7090
7091 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7092                              __attribute__((unused)) struct cmdline *cl,
7093                              __attribute__((unused)) void *data)
7094 {
7095         start_packet_forwarding(0);
7096 }
7097
7098 cmdline_parse_inst_t cmd_start = {
7099         .f = cmd_start_parsed,
7100         .data = NULL,
7101         .help_str = "start: Start packet forwarding",
7102         .tokens = {
7103                 (void *)&cmd_start_start,
7104                 NULL,
7105         },
7106 };
7107
7108 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7109 struct cmd_start_tx_first_result {
7110         cmdline_fixed_string_t start;
7111         cmdline_fixed_string_t tx_first;
7112 };
7113
7114 static void
7115 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7116                           __attribute__((unused)) struct cmdline *cl,
7117                           __attribute__((unused)) void *data)
7118 {
7119         start_packet_forwarding(1);
7120 }
7121
7122 cmdline_parse_token_string_t cmd_start_tx_first_start =
7123         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7124                                  "start");
7125 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7126         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7127                                  tx_first, "tx_first");
7128
7129 cmdline_parse_inst_t cmd_start_tx_first = {
7130         .f = cmd_start_tx_first_parsed,
7131         .data = NULL,
7132         .help_str = "start tx_first: Start packet forwarding, "
7133                 "after sending 1 burst of packets",
7134         .tokens = {
7135                 (void *)&cmd_start_tx_first_start,
7136                 (void *)&cmd_start_tx_first_tx_first,
7137                 NULL,
7138         },
7139 };
7140
7141 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7142 struct cmd_start_tx_first_n_result {
7143         cmdline_fixed_string_t start;
7144         cmdline_fixed_string_t tx_first;
7145         uint32_t tx_num;
7146 };
7147
7148 static void
7149 cmd_start_tx_first_n_parsed(void *parsed_result,
7150                           __attribute__((unused)) struct cmdline *cl,
7151                           __attribute__((unused)) void *data)
7152 {
7153         struct cmd_start_tx_first_n_result *res = parsed_result;
7154
7155         start_packet_forwarding(res->tx_num);
7156 }
7157
7158 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7159         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7160                         start, "start");
7161 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7162         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7163                         tx_first, "tx_first");
7164 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7165         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7166                         tx_num, UINT32);
7167
7168 cmdline_parse_inst_t cmd_start_tx_first_n = {
7169         .f = cmd_start_tx_first_n_parsed,
7170         .data = NULL,
7171         .help_str = "start tx_first <num>: "
7172                 "packet forwarding, after sending <num> bursts of packets",
7173         .tokens = {
7174                 (void *)&cmd_start_tx_first_n_start,
7175                 (void *)&cmd_start_tx_first_n_tx_first,
7176                 (void *)&cmd_start_tx_first_n_tx_num,
7177                 NULL,
7178         },
7179 };
7180
7181 /* *** SET LINK UP *** */
7182 struct cmd_set_link_up_result {
7183         cmdline_fixed_string_t set;
7184         cmdline_fixed_string_t link_up;
7185         cmdline_fixed_string_t port;
7186         portid_t port_id;
7187 };
7188
7189 cmdline_parse_token_string_t cmd_set_link_up_set =
7190         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7191 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7192         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7193                                 "link-up");
7194 cmdline_parse_token_string_t cmd_set_link_up_port =
7195         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7196 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7197         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7198
7199 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7200                              __attribute__((unused)) struct cmdline *cl,
7201                              __attribute__((unused)) void *data)
7202 {
7203         struct cmd_set_link_up_result *res = parsed_result;
7204         dev_set_link_up(res->port_id);
7205 }
7206
7207 cmdline_parse_inst_t cmd_set_link_up = {
7208         .f = cmd_set_link_up_parsed,
7209         .data = NULL,
7210         .help_str = "set link-up port <port id>",
7211         .tokens = {
7212                 (void *)&cmd_set_link_up_set,
7213                 (void *)&cmd_set_link_up_link_up,
7214                 (void *)&cmd_set_link_up_port,
7215                 (void *)&cmd_set_link_up_port_id,
7216                 NULL,
7217         },
7218 };
7219
7220 /* *** SET LINK DOWN *** */
7221 struct cmd_set_link_down_result {
7222         cmdline_fixed_string_t set;
7223         cmdline_fixed_string_t link_down;
7224         cmdline_fixed_string_t port;
7225         portid_t port_id;
7226 };
7227
7228 cmdline_parse_token_string_t cmd_set_link_down_set =
7229         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7230 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7231         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7232                                 "link-down");
7233 cmdline_parse_token_string_t cmd_set_link_down_port =
7234         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7235 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7236         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7237
7238 static void cmd_set_link_down_parsed(
7239                                 __attribute__((unused)) void *parsed_result,
7240                                 __attribute__((unused)) struct cmdline *cl,
7241                                 __attribute__((unused)) void *data)
7242 {
7243         struct cmd_set_link_down_result *res = parsed_result;
7244         dev_set_link_down(res->port_id);
7245 }
7246
7247 cmdline_parse_inst_t cmd_set_link_down = {
7248         .f = cmd_set_link_down_parsed,
7249         .data = NULL,
7250         .help_str = "set link-down port <port id>",
7251         .tokens = {
7252                 (void *)&cmd_set_link_down_set,
7253                 (void *)&cmd_set_link_down_link_down,
7254                 (void *)&cmd_set_link_down_port,
7255                 (void *)&cmd_set_link_down_port_id,
7256                 NULL,
7257         },
7258 };
7259
7260 /* *** SHOW CFG *** */
7261 struct cmd_showcfg_result {
7262         cmdline_fixed_string_t show;
7263         cmdline_fixed_string_t cfg;
7264         cmdline_fixed_string_t what;
7265 };
7266
7267 static void cmd_showcfg_parsed(void *parsed_result,
7268                                __attribute__((unused)) struct cmdline *cl,
7269                                __attribute__((unused)) void *data)
7270 {
7271         struct cmd_showcfg_result *res = parsed_result;
7272         if (!strcmp(res->what, "rxtx"))
7273                 rxtx_config_display();
7274         else if (!strcmp(res->what, "cores"))
7275                 fwd_lcores_config_display();
7276         else if (!strcmp(res->what, "fwd"))
7277                 pkt_fwd_config_display(&cur_fwd_config);
7278         else if (!strcmp(res->what, "txpkts"))
7279                 show_tx_pkt_segments();
7280 }
7281
7282 cmdline_parse_token_string_t cmd_showcfg_show =
7283         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7284 cmdline_parse_token_string_t cmd_showcfg_port =
7285         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7286 cmdline_parse_token_string_t cmd_showcfg_what =
7287         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7288                                  "rxtx#cores#fwd#txpkts");
7289
7290 cmdline_parse_inst_t cmd_showcfg = {
7291         .f = cmd_showcfg_parsed,
7292         .data = NULL,
7293         .help_str = "show config rxtx|cores|fwd|txpkts",
7294         .tokens = {
7295                 (void *)&cmd_showcfg_show,
7296                 (void *)&cmd_showcfg_port,
7297                 (void *)&cmd_showcfg_what,
7298                 NULL,
7299         },
7300 };
7301
7302 /* *** SHOW ALL PORT INFO *** */
7303 struct cmd_showportall_result {
7304         cmdline_fixed_string_t show;
7305         cmdline_fixed_string_t port;
7306         cmdline_fixed_string_t what;
7307         cmdline_fixed_string_t all;
7308 };
7309
7310 static void cmd_showportall_parsed(void *parsed_result,
7311                                 __attribute__((unused)) struct cmdline *cl,
7312                                 __attribute__((unused)) void *data)
7313 {
7314         portid_t i;
7315
7316         struct cmd_showportall_result *res = parsed_result;
7317         if (!strcmp(res->show, "clear")) {
7318                 if (!strcmp(res->what, "stats"))
7319                         RTE_ETH_FOREACH_DEV(i)
7320                                 nic_stats_clear(i);
7321                 else if (!strcmp(res->what, "xstats"))
7322                         RTE_ETH_FOREACH_DEV(i)
7323                                 nic_xstats_clear(i);
7324         } else if (!strcmp(res->what, "info"))
7325                 RTE_ETH_FOREACH_DEV(i)
7326                         port_infos_display(i);
7327         else if (!strcmp(res->what, "summary")) {
7328                 port_summary_header_display();
7329                 RTE_ETH_FOREACH_DEV(i)
7330                         port_summary_display(i);
7331         }
7332         else if (!strcmp(res->what, "stats"))
7333                 RTE_ETH_FOREACH_DEV(i)
7334                         nic_stats_display(i);
7335         else if (!strcmp(res->what, "xstats"))
7336                 RTE_ETH_FOREACH_DEV(i)
7337                         nic_xstats_display(i);
7338         else if (!strcmp(res->what, "fdir"))
7339                 RTE_ETH_FOREACH_DEV(i)
7340                         fdir_get_infos(i);
7341         else if (!strcmp(res->what, "stat_qmap"))
7342                 RTE_ETH_FOREACH_DEV(i)
7343                         nic_stats_mapping_display(i);
7344         else if (!strcmp(res->what, "dcb_tc"))
7345                 RTE_ETH_FOREACH_DEV(i)
7346                         port_dcb_info_display(i);
7347         else if (!strcmp(res->what, "cap"))
7348                 RTE_ETH_FOREACH_DEV(i)
7349                         port_offload_cap_display(i);
7350 }
7351
7352 cmdline_parse_token_string_t cmd_showportall_show =
7353         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7354                                  "show#clear");
7355 cmdline_parse_token_string_t cmd_showportall_port =
7356         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7357 cmdline_parse_token_string_t cmd_showportall_what =
7358         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7359                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7360 cmdline_parse_token_string_t cmd_showportall_all =
7361         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7362 cmdline_parse_inst_t cmd_showportall = {
7363         .f = cmd_showportall_parsed,
7364         .data = NULL,
7365         .help_str = "show|clear port "
7366                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7367         .tokens = {
7368                 (void *)&cmd_showportall_show,
7369                 (void *)&cmd_showportall_port,
7370                 (void *)&cmd_showportall_what,
7371                 (void *)&cmd_showportall_all,
7372                 NULL,
7373         },
7374 };
7375
7376 /* *** SHOW PORT INFO *** */
7377 struct cmd_showport_result {
7378         cmdline_fixed_string_t show;
7379         cmdline_fixed_string_t port;
7380         cmdline_fixed_string_t what;
7381         uint16_t portnum;
7382 };
7383
7384 static void cmd_showport_parsed(void *parsed_result,
7385                                 __attribute__((unused)) struct cmdline *cl,
7386                                 __attribute__((unused)) void *data)
7387 {
7388         struct cmd_showport_result *res = parsed_result;
7389         if (!strcmp(res->show, "clear")) {
7390                 if (!strcmp(res->what, "stats"))
7391                         nic_stats_clear(res->portnum);
7392                 else if (!strcmp(res->what, "xstats"))
7393                         nic_xstats_clear(res->portnum);
7394         } else if (!strcmp(res->what, "info"))
7395                 port_infos_display(res->portnum);
7396         else if (!strcmp(res->what, "summary")) {
7397                 port_summary_header_display();
7398                 port_summary_display(res->portnum);
7399         }
7400         else if (!strcmp(res->what, "stats"))
7401                 nic_stats_display(res->portnum);
7402         else if (!strcmp(res->what, "xstats"))
7403                 nic_xstats_display(res->portnum);
7404         else if (!strcmp(res->what, "fdir"))
7405                  fdir_get_infos(res->portnum);
7406         else if (!strcmp(res->what, "stat_qmap"))
7407                 nic_stats_mapping_display(res->portnum);
7408         else if (!strcmp(res->what, "dcb_tc"))
7409                 port_dcb_info_display(res->portnum);
7410         else if (!strcmp(res->what, "cap"))
7411                 port_offload_cap_display(res->portnum);
7412 }
7413
7414 cmdline_parse_token_string_t cmd_showport_show =
7415         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7416                                  "show#clear");
7417 cmdline_parse_token_string_t cmd_showport_port =
7418         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7419 cmdline_parse_token_string_t cmd_showport_what =
7420         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7421                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7422 cmdline_parse_token_num_t cmd_showport_portnum =
7423         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7424
7425 cmdline_parse_inst_t cmd_showport = {
7426         .f = cmd_showport_parsed,
7427         .data = NULL,
7428         .help_str = "show|clear port "
7429                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7430                 "<port_id>",
7431         .tokens = {
7432                 (void *)&cmd_showport_show,
7433                 (void *)&cmd_showport_port,
7434                 (void *)&cmd_showport_what,
7435                 (void *)&cmd_showport_portnum,
7436                 NULL,
7437         },
7438 };
7439
7440 /* *** SHOW QUEUE INFO *** */
7441 struct cmd_showqueue_result {
7442         cmdline_fixed_string_t show;
7443         cmdline_fixed_string_t type;
7444         cmdline_fixed_string_t what;
7445         uint16_t portnum;
7446         uint16_t queuenum;
7447 };
7448
7449 static void
7450 cmd_showqueue_parsed(void *parsed_result,
7451         __attribute__((unused)) struct cmdline *cl,
7452         __attribute__((unused)) void *data)
7453 {
7454         struct cmd_showqueue_result *res = parsed_result;
7455
7456         if (!strcmp(res->type, "rxq"))
7457                 rx_queue_infos_display(res->portnum, res->queuenum);
7458         else if (!strcmp(res->type, "txq"))
7459                 tx_queue_infos_display(res->portnum, res->queuenum);
7460 }
7461
7462 cmdline_parse_token_string_t cmd_showqueue_show =
7463         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7464 cmdline_parse_token_string_t cmd_showqueue_type =
7465         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7466 cmdline_parse_token_string_t cmd_showqueue_what =
7467         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7468 cmdline_parse_token_num_t cmd_showqueue_portnum =
7469         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7470 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7471         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7472
7473 cmdline_parse_inst_t cmd_showqueue = {
7474         .f = cmd_showqueue_parsed,
7475         .data = NULL,
7476         .help_str = "show rxq|txq info <port_id> <queue_id>",
7477         .tokens = {
7478                 (void *)&cmd_showqueue_show,
7479                 (void *)&cmd_showqueue_type,
7480                 (void *)&cmd_showqueue_what,
7481                 (void *)&cmd_showqueue_portnum,
7482                 (void *)&cmd_showqueue_queuenum,
7483                 NULL,
7484         },
7485 };
7486
7487 /* show/clear fwd engine statistics */
7488 struct fwd_result {
7489         cmdline_fixed_string_t action;
7490         cmdline_fixed_string_t fwd;
7491         cmdline_fixed_string_t stats;
7492         cmdline_fixed_string_t all;
7493 };
7494
7495 cmdline_parse_token_string_t cmd_fwd_action =
7496         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7497 cmdline_parse_token_string_t cmd_fwd_fwd =
7498         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7499 cmdline_parse_token_string_t cmd_fwd_stats =
7500         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7501 cmdline_parse_token_string_t cmd_fwd_all =
7502         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7503
7504 static void
7505 cmd_showfwdall_parsed(void *parsed_result,
7506                       __rte_unused struct cmdline *cl,
7507                       __rte_unused void *data)
7508 {
7509         struct fwd_result *res = parsed_result;
7510
7511         if (!strcmp(res->action, "show"))
7512                 fwd_stats_display();
7513         else
7514                 fwd_stats_reset();
7515 }
7516
7517 static cmdline_parse_inst_t cmd_showfwdall = {
7518         .f = cmd_showfwdall_parsed,
7519         .data = NULL,
7520         .help_str = "show|clear fwd stats all",
7521         .tokens = {
7522                 (void *)&cmd_fwd_action,
7523                 (void *)&cmd_fwd_fwd,
7524                 (void *)&cmd_fwd_stats,
7525                 (void *)&cmd_fwd_all,
7526                 NULL,
7527         },
7528 };
7529
7530 /* *** READ PORT REGISTER *** */
7531 struct cmd_read_reg_result {
7532         cmdline_fixed_string_t read;
7533         cmdline_fixed_string_t reg;
7534         portid_t port_id;
7535         uint32_t reg_off;
7536 };
7537
7538 static void
7539 cmd_read_reg_parsed(void *parsed_result,
7540                     __attribute__((unused)) struct cmdline *cl,
7541                     __attribute__((unused)) void *data)
7542 {
7543         struct cmd_read_reg_result *res = parsed_result;
7544         port_reg_display(res->port_id, res->reg_off);
7545 }
7546
7547 cmdline_parse_token_string_t cmd_read_reg_read =
7548         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7549 cmdline_parse_token_string_t cmd_read_reg_reg =
7550         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7551 cmdline_parse_token_num_t cmd_read_reg_port_id =
7552         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7553 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7554         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7555
7556 cmdline_parse_inst_t cmd_read_reg = {
7557         .f = cmd_read_reg_parsed,
7558         .data = NULL,
7559         .help_str = "read reg <port_id> <reg_off>",
7560         .tokens = {
7561                 (void *)&cmd_read_reg_read,
7562                 (void *)&cmd_read_reg_reg,
7563                 (void *)&cmd_read_reg_port_id,
7564                 (void *)&cmd_read_reg_reg_off,
7565                 NULL,
7566         },
7567 };
7568
7569 /* *** READ PORT REGISTER BIT FIELD *** */
7570 struct cmd_read_reg_bit_field_result {
7571         cmdline_fixed_string_t read;
7572         cmdline_fixed_string_t regfield;
7573         portid_t port_id;
7574         uint32_t reg_off;
7575         uint8_t bit1_pos;
7576         uint8_t bit2_pos;
7577 };
7578
7579 static void
7580 cmd_read_reg_bit_field_parsed(void *parsed_result,
7581                               __attribute__((unused)) struct cmdline *cl,
7582                               __attribute__((unused)) void *data)
7583 {
7584         struct cmd_read_reg_bit_field_result *res = parsed_result;
7585         port_reg_bit_field_display(res->port_id, res->reg_off,
7586                                    res->bit1_pos, res->bit2_pos);
7587 }
7588
7589 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7590         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7591                                  "read");
7592 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7593         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7594                                  regfield, "regfield");
7595 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7596         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7597                               UINT16);
7598 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7599         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7600                               UINT32);
7601 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7602         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7603                               UINT8);
7604 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7605         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7606                               UINT8);
7607
7608 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7609         .f = cmd_read_reg_bit_field_parsed,
7610         .data = NULL,
7611         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7612         "Read register bit field between bit_x and bit_y included",
7613         .tokens = {
7614                 (void *)&cmd_read_reg_bit_field_read,
7615                 (void *)&cmd_read_reg_bit_field_regfield,
7616                 (void *)&cmd_read_reg_bit_field_port_id,
7617                 (void *)&cmd_read_reg_bit_field_reg_off,
7618                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7619                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7620                 NULL,
7621         },
7622 };
7623
7624 /* *** READ PORT REGISTER BIT *** */
7625 struct cmd_read_reg_bit_result {
7626         cmdline_fixed_string_t read;
7627         cmdline_fixed_string_t regbit;
7628         portid_t port_id;
7629         uint32_t reg_off;
7630         uint8_t bit_pos;
7631 };
7632
7633 static void
7634 cmd_read_reg_bit_parsed(void *parsed_result,
7635                         __attribute__((unused)) struct cmdline *cl,
7636                         __attribute__((unused)) void *data)
7637 {
7638         struct cmd_read_reg_bit_result *res = parsed_result;
7639         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7640 }
7641
7642 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7643         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7644 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7645         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7646                                  regbit, "regbit");
7647 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7648         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7649 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7650         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7651 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7652         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7653
7654 cmdline_parse_inst_t cmd_read_reg_bit = {
7655         .f = cmd_read_reg_bit_parsed,
7656         .data = NULL,
7657         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7658         .tokens = {
7659                 (void *)&cmd_read_reg_bit_read,
7660                 (void *)&cmd_read_reg_bit_regbit,
7661                 (void *)&cmd_read_reg_bit_port_id,
7662                 (void *)&cmd_read_reg_bit_reg_off,
7663                 (void *)&cmd_read_reg_bit_bit_pos,
7664                 NULL,
7665         },
7666 };
7667
7668 /* *** WRITE PORT REGISTER *** */
7669 struct cmd_write_reg_result {
7670         cmdline_fixed_string_t write;
7671         cmdline_fixed_string_t reg;
7672         portid_t port_id;
7673         uint32_t reg_off;
7674         uint32_t value;
7675 };
7676
7677 static void
7678 cmd_write_reg_parsed(void *parsed_result,
7679                      __attribute__((unused)) struct cmdline *cl,
7680                      __attribute__((unused)) void *data)
7681 {
7682         struct cmd_write_reg_result *res = parsed_result;
7683         port_reg_set(res->port_id, res->reg_off, res->value);
7684 }
7685
7686 cmdline_parse_token_string_t cmd_write_reg_write =
7687         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7688 cmdline_parse_token_string_t cmd_write_reg_reg =
7689         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7690 cmdline_parse_token_num_t cmd_write_reg_port_id =
7691         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7692 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7693         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7694 cmdline_parse_token_num_t cmd_write_reg_value =
7695         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7696
7697 cmdline_parse_inst_t cmd_write_reg = {
7698         .f = cmd_write_reg_parsed,
7699         .data = NULL,
7700         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7701         .tokens = {
7702                 (void *)&cmd_write_reg_write,
7703                 (void *)&cmd_write_reg_reg,
7704                 (void *)&cmd_write_reg_port_id,
7705                 (void *)&cmd_write_reg_reg_off,
7706                 (void *)&cmd_write_reg_value,
7707                 NULL,
7708         },
7709 };
7710
7711 /* *** WRITE PORT REGISTER BIT FIELD *** */
7712 struct cmd_write_reg_bit_field_result {
7713         cmdline_fixed_string_t write;
7714         cmdline_fixed_string_t regfield;
7715         portid_t port_id;
7716         uint32_t reg_off;
7717         uint8_t bit1_pos;
7718         uint8_t bit2_pos;
7719         uint32_t value;
7720 };
7721
7722 static void
7723 cmd_write_reg_bit_field_parsed(void *parsed_result,
7724                                __attribute__((unused)) struct cmdline *cl,
7725                                __attribute__((unused)) void *data)
7726 {
7727         struct cmd_write_reg_bit_field_result *res = parsed_result;
7728         port_reg_bit_field_set(res->port_id, res->reg_off,
7729                           res->bit1_pos, res->bit2_pos, res->value);
7730 }
7731
7732 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7733         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7734                                  "write");
7735 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7736         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7737                                  regfield, "regfield");
7738 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7739         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7740                               UINT16);
7741 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7742         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7743                               UINT32);
7744 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7745         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7746                               UINT8);
7747 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7748         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7749                               UINT8);
7750 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7751         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7752                               UINT32);
7753
7754 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7755         .f = cmd_write_reg_bit_field_parsed,
7756         .data = NULL,
7757         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7758                 "<reg_value>: "
7759                 "Set register bit field between bit_x and bit_y included",
7760         .tokens = {
7761                 (void *)&cmd_write_reg_bit_field_write,
7762                 (void *)&cmd_write_reg_bit_field_regfield,
7763                 (void *)&cmd_write_reg_bit_field_port_id,
7764                 (void *)&cmd_write_reg_bit_field_reg_off,
7765                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7766                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7767                 (void *)&cmd_write_reg_bit_field_value,
7768                 NULL,
7769         },
7770 };
7771
7772 /* *** WRITE PORT REGISTER BIT *** */
7773 struct cmd_write_reg_bit_result {
7774         cmdline_fixed_string_t write;
7775         cmdline_fixed_string_t regbit;
7776         portid_t port_id;
7777         uint32_t reg_off;
7778         uint8_t bit_pos;
7779         uint8_t value;
7780 };
7781
7782 static void
7783 cmd_write_reg_bit_parsed(void *parsed_result,
7784                          __attribute__((unused)) struct cmdline *cl,
7785                          __attribute__((unused)) void *data)
7786 {
7787         struct cmd_write_reg_bit_result *res = parsed_result;
7788         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7789 }
7790
7791 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7792         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7793                                  "write");
7794 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7795         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7796                                  regbit, "regbit");
7797 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7798         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7799 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7800         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7801 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7802         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7803 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7804         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7805
7806 cmdline_parse_inst_t cmd_write_reg_bit = {
7807         .f = cmd_write_reg_bit_parsed,
7808         .data = NULL,
7809         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7810                 "0 <= bit_x <= 31",
7811         .tokens = {
7812                 (void *)&cmd_write_reg_bit_write,
7813                 (void *)&cmd_write_reg_bit_regbit,
7814                 (void *)&cmd_write_reg_bit_port_id,
7815                 (void *)&cmd_write_reg_bit_reg_off,
7816                 (void *)&cmd_write_reg_bit_bit_pos,
7817                 (void *)&cmd_write_reg_bit_value,
7818                 NULL,
7819         },
7820 };
7821
7822 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7823 struct cmd_read_rxd_txd_result {
7824         cmdline_fixed_string_t read;
7825         cmdline_fixed_string_t rxd_txd;
7826         portid_t port_id;
7827         uint16_t queue_id;
7828         uint16_t desc_id;
7829 };
7830
7831 static void
7832 cmd_read_rxd_txd_parsed(void *parsed_result,
7833                         __attribute__((unused)) struct cmdline *cl,
7834                         __attribute__((unused)) void *data)
7835 {
7836         struct cmd_read_rxd_txd_result *res = parsed_result;
7837
7838         if (!strcmp(res->rxd_txd, "rxd"))
7839                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7840         else if (!strcmp(res->rxd_txd, "txd"))
7841                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7842 }
7843
7844 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7845         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7846 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7847         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7848                                  "rxd#txd");
7849 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7850         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7851 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7852         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7853 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7854         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7855
7856 cmdline_parse_inst_t cmd_read_rxd_txd = {
7857         .f = cmd_read_rxd_txd_parsed,
7858         .data = NULL,
7859         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7860         .tokens = {
7861                 (void *)&cmd_read_rxd_txd_read,
7862                 (void *)&cmd_read_rxd_txd_rxd_txd,
7863                 (void *)&cmd_read_rxd_txd_port_id,
7864                 (void *)&cmd_read_rxd_txd_queue_id,
7865                 (void *)&cmd_read_rxd_txd_desc_id,
7866                 NULL,
7867         },
7868 };
7869
7870 /* *** QUIT *** */
7871 struct cmd_quit_result {
7872         cmdline_fixed_string_t quit;
7873 };
7874
7875 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7876                             struct cmdline *cl,
7877                             __attribute__((unused)) void *data)
7878 {
7879         cmdline_quit(cl);
7880 }
7881
7882 cmdline_parse_token_string_t cmd_quit_quit =
7883         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7884
7885 cmdline_parse_inst_t cmd_quit = {
7886         .f = cmd_quit_parsed,
7887         .data = NULL,
7888         .help_str = "quit: Exit application",
7889         .tokens = {
7890                 (void *)&cmd_quit_quit,
7891                 NULL,
7892         },
7893 };
7894
7895 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7896 struct cmd_mac_addr_result {
7897         cmdline_fixed_string_t mac_addr_cmd;
7898         cmdline_fixed_string_t what;
7899         uint16_t port_num;
7900         struct rte_ether_addr address;
7901 };
7902
7903 static void cmd_mac_addr_parsed(void *parsed_result,
7904                 __attribute__((unused)) struct cmdline *cl,
7905                 __attribute__((unused)) void *data)
7906 {
7907         struct cmd_mac_addr_result *res = parsed_result;
7908         int ret;
7909
7910         if (strcmp(res->what, "add") == 0)
7911                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7912         else if (strcmp(res->what, "set") == 0)
7913                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7914                                                        &res->address);
7915         else
7916                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7917
7918         /* check the return value and print it if is < 0 */
7919         if(ret < 0)
7920                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7921
7922 }
7923
7924 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7925         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7926                                 "mac_addr");
7927 cmdline_parse_token_string_t cmd_mac_addr_what =
7928         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7929                                 "add#remove#set");
7930 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7931                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7932                                         UINT16);
7933 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7934                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7935
7936 cmdline_parse_inst_t cmd_mac_addr = {
7937         .f = cmd_mac_addr_parsed,
7938         .data = (void *)0,
7939         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7940                         "Add/Remove/Set MAC address on port_id",
7941         .tokens = {
7942                 (void *)&cmd_mac_addr_cmd,
7943                 (void *)&cmd_mac_addr_what,
7944                 (void *)&cmd_mac_addr_portnum,
7945                 (void *)&cmd_mac_addr_addr,
7946                 NULL,
7947         },
7948 };
7949
7950 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7951 struct cmd_eth_peer_result {
7952         cmdline_fixed_string_t set;
7953         cmdline_fixed_string_t eth_peer;
7954         portid_t port_id;
7955         cmdline_fixed_string_t peer_addr;
7956 };
7957
7958 static void cmd_set_eth_peer_parsed(void *parsed_result,
7959                         __attribute__((unused)) struct cmdline *cl,
7960                         __attribute__((unused)) void *data)
7961 {
7962                 struct cmd_eth_peer_result *res = parsed_result;
7963
7964                 if (test_done == 0) {
7965                         printf("Please stop forwarding first\n");
7966                         return;
7967                 }
7968                 if (!strcmp(res->eth_peer, "eth-peer")) {
7969                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7970                         fwd_config_setup();
7971                 }
7972 }
7973 cmdline_parse_token_string_t cmd_eth_peer_set =
7974         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7975 cmdline_parse_token_string_t cmd_eth_peer =
7976         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7977 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7978         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7979 cmdline_parse_token_string_t cmd_eth_peer_addr =
7980         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7981
7982 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7983         .f = cmd_set_eth_peer_parsed,
7984         .data = NULL,
7985         .help_str = "set eth-peer <port_id> <peer_mac>",
7986         .tokens = {
7987                 (void *)&cmd_eth_peer_set,
7988                 (void *)&cmd_eth_peer,
7989                 (void *)&cmd_eth_peer_port_id,
7990                 (void *)&cmd_eth_peer_addr,
7991                 NULL,
7992         },
7993 };
7994
7995 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7996 struct cmd_set_qmap_result {
7997         cmdline_fixed_string_t set;
7998         cmdline_fixed_string_t qmap;
7999         cmdline_fixed_string_t what;
8000         portid_t port_id;
8001         uint16_t queue_id;
8002         uint8_t map_value;
8003 };
8004
8005 static void
8006 cmd_set_qmap_parsed(void *parsed_result,
8007                        __attribute__((unused)) struct cmdline *cl,
8008                        __attribute__((unused)) void *data)
8009 {
8010         struct cmd_set_qmap_result *res = parsed_result;
8011         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8012
8013         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8014 }
8015
8016 cmdline_parse_token_string_t cmd_setqmap_set =
8017         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8018                                  set, "set");
8019 cmdline_parse_token_string_t cmd_setqmap_qmap =
8020         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8021                                  qmap, "stat_qmap");
8022 cmdline_parse_token_string_t cmd_setqmap_what =
8023         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8024                                  what, "tx#rx");
8025 cmdline_parse_token_num_t cmd_setqmap_portid =
8026         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8027                               port_id, UINT16);
8028 cmdline_parse_token_num_t cmd_setqmap_queueid =
8029         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8030                               queue_id, UINT16);
8031 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8032         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8033                               map_value, UINT8);
8034
8035 cmdline_parse_inst_t cmd_set_qmap = {
8036         .f = cmd_set_qmap_parsed,
8037         .data = NULL,
8038         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8039                 "Set statistics mapping value on tx|rx queue_id of port_id",
8040         .tokens = {
8041                 (void *)&cmd_setqmap_set,
8042                 (void *)&cmd_setqmap_qmap,
8043                 (void *)&cmd_setqmap_what,
8044                 (void *)&cmd_setqmap_portid,
8045                 (void *)&cmd_setqmap_queueid,
8046                 (void *)&cmd_setqmap_mapvalue,
8047                 NULL,
8048         },
8049 };
8050
8051 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8052 struct cmd_set_xstats_hide_zero_result {
8053         cmdline_fixed_string_t keyword;
8054         cmdline_fixed_string_t name;
8055         cmdline_fixed_string_t on_off;
8056 };
8057
8058 static void
8059 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8060                         __attribute__((unused)) struct cmdline *cl,
8061                         __attribute__((unused)) void *data)
8062 {
8063         struct cmd_set_xstats_hide_zero_result *res;
8064         uint16_t on_off = 0;
8065
8066         res = parsed_result;
8067         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8068         set_xstats_hide_zero(on_off);
8069 }
8070
8071 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8072         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8073                                  keyword, "set");
8074 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8075         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8076                                  name, "xstats-hide-zero");
8077 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8078         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8079                                  on_off, "on#off");
8080
8081 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8082         .f = cmd_set_xstats_hide_zero_parsed,
8083         .data = NULL,
8084         .help_str = "set xstats-hide-zero on|off",
8085         .tokens = {
8086                 (void *)&cmd_set_xstats_hide_zero_keyword,
8087                 (void *)&cmd_set_xstats_hide_zero_name,
8088                 (void *)&cmd_set_xstats_hide_zero_on_off,
8089                 NULL,
8090         },
8091 };
8092
8093 /* *** CONFIGURE UNICAST HASH TABLE *** */
8094 struct cmd_set_uc_hash_table {
8095         cmdline_fixed_string_t set;
8096         cmdline_fixed_string_t port;
8097         portid_t port_id;
8098         cmdline_fixed_string_t what;
8099         struct rte_ether_addr address;
8100         cmdline_fixed_string_t mode;
8101 };
8102
8103 static void
8104 cmd_set_uc_hash_parsed(void *parsed_result,
8105                        __attribute__((unused)) struct cmdline *cl,
8106                        __attribute__((unused)) void *data)
8107 {
8108         int ret=0;
8109         struct cmd_set_uc_hash_table *res = parsed_result;
8110
8111         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8112
8113         if (strcmp(res->what, "uta") == 0)
8114                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8115                                                 &res->address,(uint8_t)is_on);
8116         if (ret < 0)
8117                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8118
8119 }
8120
8121 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8122         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8123                                  set, "set");
8124 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8125         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8126                                  port, "port");
8127 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8128         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8129                               port_id, UINT16);
8130 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8131         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8132                                  what, "uta");
8133 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8134         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8135                                 address);
8136 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8137         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8138                                  mode, "on#off");
8139
8140 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8141         .f = cmd_set_uc_hash_parsed,
8142         .data = NULL,
8143         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8144         .tokens = {
8145                 (void *)&cmd_set_uc_hash_set,
8146                 (void *)&cmd_set_uc_hash_port,
8147                 (void *)&cmd_set_uc_hash_portid,
8148                 (void *)&cmd_set_uc_hash_what,
8149                 (void *)&cmd_set_uc_hash_mac,
8150                 (void *)&cmd_set_uc_hash_mode,
8151                 NULL,
8152         },
8153 };
8154
8155 struct cmd_set_uc_all_hash_table {
8156         cmdline_fixed_string_t set;
8157         cmdline_fixed_string_t port;
8158         portid_t port_id;
8159         cmdline_fixed_string_t what;
8160         cmdline_fixed_string_t value;
8161         cmdline_fixed_string_t mode;
8162 };
8163
8164 static void
8165 cmd_set_uc_all_hash_parsed(void *parsed_result,
8166                        __attribute__((unused)) struct cmdline *cl,
8167                        __attribute__((unused)) void *data)
8168 {
8169         int ret=0;
8170         struct cmd_set_uc_all_hash_table *res = parsed_result;
8171
8172         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8173
8174         if ((strcmp(res->what, "uta") == 0) &&
8175                 (strcmp(res->value, "all") == 0))
8176                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8177         if (ret < 0)
8178                 printf("bad unicast hash table parameter,"
8179                         "return code = %d \n", ret);
8180 }
8181
8182 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8183         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8184                                  set, "set");
8185 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8186         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8187                                  port, "port");
8188 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8189         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8190                               port_id, UINT16);
8191 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8192         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8193                                  what, "uta");
8194 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8195         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8196                                 value,"all");
8197 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8198         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8199                                  mode, "on#off");
8200
8201 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8202         .f = cmd_set_uc_all_hash_parsed,
8203         .data = NULL,
8204         .help_str = "set port <port_id> uta all on|off",
8205         .tokens = {
8206                 (void *)&cmd_set_uc_all_hash_set,
8207                 (void *)&cmd_set_uc_all_hash_port,
8208                 (void *)&cmd_set_uc_all_hash_portid,
8209                 (void *)&cmd_set_uc_all_hash_what,
8210                 (void *)&cmd_set_uc_all_hash_value,
8211                 (void *)&cmd_set_uc_all_hash_mode,
8212                 NULL,
8213         },
8214 };
8215
8216 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8217 struct cmd_set_vf_macvlan_filter {
8218         cmdline_fixed_string_t set;
8219         cmdline_fixed_string_t port;
8220         portid_t port_id;
8221         cmdline_fixed_string_t vf;
8222         uint8_t vf_id;
8223         struct rte_ether_addr address;
8224         cmdline_fixed_string_t filter_type;
8225         cmdline_fixed_string_t mode;
8226 };
8227
8228 static void
8229 cmd_set_vf_macvlan_parsed(void *parsed_result,
8230                        __attribute__((unused)) struct cmdline *cl,
8231                        __attribute__((unused)) void *data)
8232 {
8233         int is_on, ret = 0;
8234         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8235         struct rte_eth_mac_filter filter;
8236
8237         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8238
8239         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
8240
8241         /* set VF MAC filter */
8242         filter.is_vf = 1;
8243
8244         /* set VF ID */
8245         filter.dst_id = res->vf_id;
8246
8247         if (!strcmp(res->filter_type, "exact-mac"))
8248                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8249         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8250                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8251         else if (!strcmp(res->filter_type, "hashmac"))
8252                 filter.filter_type = RTE_MAC_HASH_MATCH;
8253         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8254                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8255
8256         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8257
8258         if (is_on)
8259                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8260                                         RTE_ETH_FILTER_MACVLAN,
8261                                         RTE_ETH_FILTER_ADD,
8262                                          &filter);
8263         else
8264                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8265                                         RTE_ETH_FILTER_MACVLAN,
8266                                         RTE_ETH_FILTER_DELETE,
8267                                         &filter);
8268
8269         if (ret < 0)
8270                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8271
8272 }
8273
8274 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8275         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8276                                  set, "set");
8277 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8278         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8279                                  port, "port");
8280 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8281         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8282                               port_id, UINT16);
8283 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8284         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8285                                  vf, "vf");
8286 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8287         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8288                                 vf_id, UINT8);
8289 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8290         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8291                                 address);
8292 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8293         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8294                                 filter_type, "exact-mac#exact-mac-vlan"
8295                                 "#hashmac#hashmac-vlan");
8296 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8297         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8298                                  mode, "on#off");
8299
8300 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8301         .f = cmd_set_vf_macvlan_parsed,
8302         .data = NULL,
8303         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8304                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8305                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8306                 "hash match rule: hash match of MAC and exact match of VLAN",
8307         .tokens = {
8308                 (void *)&cmd_set_vf_macvlan_set,
8309                 (void *)&cmd_set_vf_macvlan_port,
8310                 (void *)&cmd_set_vf_macvlan_portid,
8311                 (void *)&cmd_set_vf_macvlan_vf,
8312                 (void *)&cmd_set_vf_macvlan_vf_id,
8313                 (void *)&cmd_set_vf_macvlan_mac,
8314                 (void *)&cmd_set_vf_macvlan_filter_type,
8315                 (void *)&cmd_set_vf_macvlan_mode,
8316                 NULL,
8317         },
8318 };
8319
8320 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8321 struct cmd_set_vf_traffic {
8322         cmdline_fixed_string_t set;
8323         cmdline_fixed_string_t port;
8324         portid_t port_id;
8325         cmdline_fixed_string_t vf;
8326         uint8_t vf_id;
8327         cmdline_fixed_string_t what;
8328         cmdline_fixed_string_t mode;
8329 };
8330
8331 static void
8332 cmd_set_vf_traffic_parsed(void *parsed_result,
8333                        __attribute__((unused)) struct cmdline *cl,
8334                        __attribute__((unused)) void *data)
8335 {
8336         struct cmd_set_vf_traffic *res = parsed_result;
8337         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8338         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8339
8340         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8341 }
8342
8343 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8344         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8345                                  set, "set");
8346 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8347         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8348                                  port, "port");
8349 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8350         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8351                               port_id, UINT16);
8352 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8353         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8354                                  vf, "vf");
8355 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8356         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8357                               vf_id, UINT8);
8358 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8359         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8360                                  what, "tx#rx");
8361 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8362         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8363                                  mode, "on#off");
8364
8365 cmdline_parse_inst_t cmd_set_vf_traffic = {
8366         .f = cmd_set_vf_traffic_parsed,
8367         .data = NULL,
8368         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8369         .tokens = {
8370                 (void *)&cmd_setvf_traffic_set,
8371                 (void *)&cmd_setvf_traffic_port,
8372                 (void *)&cmd_setvf_traffic_portid,
8373                 (void *)&cmd_setvf_traffic_vf,
8374                 (void *)&cmd_setvf_traffic_vfid,
8375                 (void *)&cmd_setvf_traffic_what,
8376                 (void *)&cmd_setvf_traffic_mode,
8377                 NULL,
8378         },
8379 };
8380
8381 /* *** CONFIGURE VF RECEIVE MODE *** */
8382 struct cmd_set_vf_rxmode {
8383         cmdline_fixed_string_t set;
8384         cmdline_fixed_string_t port;
8385         portid_t port_id;
8386         cmdline_fixed_string_t vf;
8387         uint8_t vf_id;
8388         cmdline_fixed_string_t what;
8389         cmdline_fixed_string_t mode;
8390         cmdline_fixed_string_t on;
8391 };
8392
8393 static void
8394 cmd_set_vf_rxmode_parsed(void *parsed_result,
8395                        __attribute__((unused)) struct cmdline *cl,
8396                        __attribute__((unused)) void *data)
8397 {
8398         int ret = -ENOTSUP;
8399         uint16_t rx_mode = 0;
8400         struct cmd_set_vf_rxmode *res = parsed_result;
8401
8402         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8403         if (!strcmp(res->what,"rxmode")) {
8404                 if (!strcmp(res->mode, "AUPE"))
8405                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8406                 else if (!strcmp(res->mode, "ROPE"))
8407                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8408                 else if (!strcmp(res->mode, "BAM"))
8409                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8410                 else if (!strncmp(res->mode, "MPE",3))
8411                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8412         }
8413
8414         RTE_SET_USED(is_on);
8415
8416 #ifdef RTE_LIBRTE_IXGBE_PMD
8417         if (ret == -ENOTSUP)
8418                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8419                                                   rx_mode, (uint8_t)is_on);
8420 #endif
8421 #ifdef RTE_LIBRTE_BNXT_PMD
8422         if (ret == -ENOTSUP)
8423                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8424                                                  rx_mode, (uint8_t)is_on);
8425 #endif
8426         if (ret < 0)
8427                 printf("bad VF receive mode parameter, return code = %d \n",
8428                 ret);
8429 }
8430
8431 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8432         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8433                                  set, "set");
8434 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8435         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8436                                  port, "port");
8437 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8438         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8439                               port_id, UINT16);
8440 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8441         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8442                                  vf, "vf");
8443 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8444         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8445                               vf_id, UINT8);
8446 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8447         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8448                                  what, "rxmode");
8449 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8450         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8451                                  mode, "AUPE#ROPE#BAM#MPE");
8452 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8453         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8454                                  on, "on#off");
8455
8456 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8457         .f = cmd_set_vf_rxmode_parsed,
8458         .data = NULL,
8459         .help_str = "set port <port_id> vf <vf_id> rxmode "
8460                 "AUPE|ROPE|BAM|MPE on|off",
8461         .tokens = {
8462                 (void *)&cmd_set_vf_rxmode_set,
8463                 (void *)&cmd_set_vf_rxmode_port,
8464                 (void *)&cmd_set_vf_rxmode_portid,
8465                 (void *)&cmd_set_vf_rxmode_vf,
8466                 (void *)&cmd_set_vf_rxmode_vfid,
8467                 (void *)&cmd_set_vf_rxmode_what,
8468                 (void *)&cmd_set_vf_rxmode_mode,
8469                 (void *)&cmd_set_vf_rxmode_on,
8470                 NULL,
8471         },
8472 };
8473
8474 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8475 struct cmd_vf_mac_addr_result {
8476         cmdline_fixed_string_t mac_addr_cmd;
8477         cmdline_fixed_string_t what;
8478         cmdline_fixed_string_t port;
8479         uint16_t port_num;
8480         cmdline_fixed_string_t vf;
8481         uint8_t vf_num;
8482         struct rte_ether_addr address;
8483 };
8484
8485 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8486                 __attribute__((unused)) struct cmdline *cl,
8487                 __attribute__((unused)) void *data)
8488 {
8489         struct cmd_vf_mac_addr_result *res = parsed_result;
8490         int ret = -ENOTSUP;
8491
8492         if (strcmp(res->what, "add") != 0)
8493                 return;
8494
8495 #ifdef RTE_LIBRTE_I40E_PMD
8496         if (ret == -ENOTSUP)
8497                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8498                                                    &res->address);
8499 #endif
8500 #ifdef RTE_LIBRTE_BNXT_PMD
8501         if (ret == -ENOTSUP)
8502                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8503                                                 res->vf_num);
8504 #endif
8505
8506         if(ret < 0)
8507                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8508
8509 }
8510
8511 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8512         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8513                                 mac_addr_cmd,"mac_addr");
8514 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8515         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8516                                 what,"add");
8517 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8518         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8519                                 port,"port");
8520 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8521         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8522                                 port_num, UINT16);
8523 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8524         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8525                                 vf,"vf");
8526 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8527         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8528                                 vf_num, UINT8);
8529 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8530         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8531                                 address);
8532
8533 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8534         .f = cmd_vf_mac_addr_parsed,
8535         .data = (void *)0,
8536         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8537                 "Add MAC address filtering for a VF on port_id",
8538         .tokens = {
8539                 (void *)&cmd_vf_mac_addr_cmd,
8540                 (void *)&cmd_vf_mac_addr_what,
8541                 (void *)&cmd_vf_mac_addr_port,
8542                 (void *)&cmd_vf_mac_addr_portnum,
8543                 (void *)&cmd_vf_mac_addr_vf,
8544                 (void *)&cmd_vf_mac_addr_vfnum,
8545                 (void *)&cmd_vf_mac_addr_addr,
8546                 NULL,
8547         },
8548 };
8549
8550 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8551 struct cmd_vf_rx_vlan_filter {
8552         cmdline_fixed_string_t rx_vlan;
8553         cmdline_fixed_string_t what;
8554         uint16_t vlan_id;
8555         cmdline_fixed_string_t port;
8556         portid_t port_id;
8557         cmdline_fixed_string_t vf;
8558         uint64_t vf_mask;
8559 };
8560
8561 static void
8562 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8563                           __attribute__((unused)) struct cmdline *cl,
8564                           __attribute__((unused)) void *data)
8565 {
8566         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8567         int ret = -ENOTSUP;
8568
8569         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8570
8571 #ifdef RTE_LIBRTE_IXGBE_PMD
8572         if (ret == -ENOTSUP)
8573                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8574                                 res->vlan_id, res->vf_mask, is_add);
8575 #endif
8576 #ifdef RTE_LIBRTE_I40E_PMD
8577         if (ret == -ENOTSUP)
8578                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8579                                 res->vlan_id, res->vf_mask, is_add);
8580 #endif
8581 #ifdef RTE_LIBRTE_BNXT_PMD
8582         if (ret == -ENOTSUP)
8583                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8584                                 res->vlan_id, res->vf_mask, is_add);
8585 #endif
8586
8587         switch (ret) {
8588         case 0:
8589                 break;
8590         case -EINVAL:
8591                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8592                                 res->vlan_id, res->vf_mask);
8593                 break;
8594         case -ENODEV:
8595                 printf("invalid port_id %d\n", res->port_id);
8596                 break;
8597         case -ENOTSUP:
8598                 printf("function not implemented or supported\n");
8599                 break;
8600         default:
8601                 printf("programming error: (%s)\n", strerror(-ret));
8602         }
8603 }
8604
8605 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8606         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8607                                  rx_vlan, "rx_vlan");
8608 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8609         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8610                                  what, "add#rm");
8611 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8612         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8613                               vlan_id, UINT16);
8614 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8615         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8616                                  port, "port");
8617 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8618         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8619                               port_id, UINT16);
8620 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8621         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8622                                  vf, "vf");
8623 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8624         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8625                               vf_mask, UINT64);
8626
8627 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8628         .f = cmd_vf_rx_vlan_filter_parsed,
8629         .data = NULL,
8630         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8631                 "(vf_mask = hexadecimal VF mask)",
8632         .tokens = {
8633                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8634                 (void *)&cmd_vf_rx_vlan_filter_what,
8635                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8636                 (void *)&cmd_vf_rx_vlan_filter_port,
8637                 (void *)&cmd_vf_rx_vlan_filter_portid,
8638                 (void *)&cmd_vf_rx_vlan_filter_vf,
8639                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8640                 NULL,
8641         },
8642 };
8643
8644 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8645 struct cmd_queue_rate_limit_result {
8646         cmdline_fixed_string_t set;
8647         cmdline_fixed_string_t port;
8648         uint16_t port_num;
8649         cmdline_fixed_string_t queue;
8650         uint8_t queue_num;
8651         cmdline_fixed_string_t rate;
8652         uint16_t rate_num;
8653 };
8654
8655 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8656                 __attribute__((unused)) struct cmdline *cl,
8657                 __attribute__((unused)) void *data)
8658 {
8659         struct cmd_queue_rate_limit_result *res = parsed_result;
8660         int ret = 0;
8661
8662         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8663                 && (strcmp(res->queue, "queue") == 0)
8664                 && (strcmp(res->rate, "rate") == 0))
8665                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8666                                         res->rate_num);
8667         if (ret < 0)
8668                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8669
8670 }
8671
8672 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8673         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8674                                 set, "set");
8675 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8676         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8677                                 port, "port");
8678 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8679         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8680                                 port_num, UINT16);
8681 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8682         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8683                                 queue, "queue");
8684 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8685         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8686                                 queue_num, UINT8);
8687 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8688         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8689                                 rate, "rate");
8690 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8691         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8692                                 rate_num, UINT16);
8693
8694 cmdline_parse_inst_t cmd_queue_rate_limit = {
8695         .f = cmd_queue_rate_limit_parsed,
8696         .data = (void *)0,
8697         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8698                 "Set rate limit for a queue on port_id",
8699         .tokens = {
8700                 (void *)&cmd_queue_rate_limit_set,
8701                 (void *)&cmd_queue_rate_limit_port,
8702                 (void *)&cmd_queue_rate_limit_portnum,
8703                 (void *)&cmd_queue_rate_limit_queue,
8704                 (void *)&cmd_queue_rate_limit_queuenum,
8705                 (void *)&cmd_queue_rate_limit_rate,
8706                 (void *)&cmd_queue_rate_limit_ratenum,
8707                 NULL,
8708         },
8709 };
8710
8711 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8712 struct cmd_vf_rate_limit_result {
8713         cmdline_fixed_string_t set;
8714         cmdline_fixed_string_t port;
8715         uint16_t port_num;
8716         cmdline_fixed_string_t vf;
8717         uint8_t vf_num;
8718         cmdline_fixed_string_t rate;
8719         uint16_t rate_num;
8720         cmdline_fixed_string_t q_msk;
8721         uint64_t q_msk_val;
8722 };
8723
8724 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8725                 __attribute__((unused)) struct cmdline *cl,
8726                 __attribute__((unused)) void *data)
8727 {
8728         struct cmd_vf_rate_limit_result *res = parsed_result;
8729         int ret = 0;
8730
8731         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8732                 && (strcmp(res->vf, "vf") == 0)
8733                 && (strcmp(res->rate, "rate") == 0)
8734                 && (strcmp(res->q_msk, "queue_mask") == 0))
8735                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8736                                         res->rate_num, res->q_msk_val);
8737         if (ret < 0)
8738                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8739
8740 }
8741
8742 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8743         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8744                                 set, "set");
8745 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8746         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8747                                 port, "port");
8748 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8749         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8750                                 port_num, UINT16);
8751 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8752         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8753                                 vf, "vf");
8754 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8755         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8756                                 vf_num, UINT8);
8757 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8758         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8759                                 rate, "rate");
8760 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8761         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8762                                 rate_num, UINT16);
8763 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8764         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8765                                 q_msk, "queue_mask");
8766 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8767         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8768                                 q_msk_val, UINT64);
8769
8770 cmdline_parse_inst_t cmd_vf_rate_limit = {
8771         .f = cmd_vf_rate_limit_parsed,
8772         .data = (void *)0,
8773         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8774                 "queue_mask <queue_mask_value>: "
8775                 "Set rate limit for queues of VF on port_id",
8776         .tokens = {
8777                 (void *)&cmd_vf_rate_limit_set,
8778                 (void *)&cmd_vf_rate_limit_port,
8779                 (void *)&cmd_vf_rate_limit_portnum,
8780                 (void *)&cmd_vf_rate_limit_vf,
8781                 (void *)&cmd_vf_rate_limit_vfnum,
8782                 (void *)&cmd_vf_rate_limit_rate,
8783                 (void *)&cmd_vf_rate_limit_ratenum,
8784                 (void *)&cmd_vf_rate_limit_q_msk,
8785                 (void *)&cmd_vf_rate_limit_q_msk_val,
8786                 NULL,
8787         },
8788 };
8789
8790 /* *** ADD TUNNEL FILTER OF A PORT *** */
8791 struct cmd_tunnel_filter_result {
8792         cmdline_fixed_string_t cmd;
8793         cmdline_fixed_string_t what;
8794         portid_t port_id;
8795         struct rte_ether_addr outer_mac;
8796         struct rte_ether_addr inner_mac;
8797         cmdline_ipaddr_t ip_value;
8798         uint16_t inner_vlan;
8799         cmdline_fixed_string_t tunnel_type;
8800         cmdline_fixed_string_t filter_type;
8801         uint32_t tenant_id;
8802         uint16_t queue_num;
8803 };
8804
8805 static void
8806 cmd_tunnel_filter_parsed(void *parsed_result,
8807                           __attribute__((unused)) struct cmdline *cl,
8808                           __attribute__((unused)) void *data)
8809 {
8810         struct cmd_tunnel_filter_result *res = parsed_result;
8811         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8812         int ret = 0;
8813
8814         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8815
8816         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8817         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8818         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8819
8820         if (res->ip_value.family == AF_INET) {
8821                 tunnel_filter_conf.ip_addr.ipv4_addr =
8822                         res->ip_value.addr.ipv4.s_addr;
8823                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8824         } else {
8825                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8826                         &(res->ip_value.addr.ipv6),
8827                         sizeof(struct in6_addr));
8828                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8829         }
8830
8831         if (!strcmp(res->filter_type, "imac-ivlan"))
8832                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8833         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8834                 tunnel_filter_conf.filter_type =
8835                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8836         else if (!strcmp(res->filter_type, "imac-tenid"))
8837                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8838         else if (!strcmp(res->filter_type, "imac"))
8839                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8840         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8841                 tunnel_filter_conf.filter_type =
8842                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8843         else if (!strcmp(res->filter_type, "oip"))
8844                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8845         else if (!strcmp(res->filter_type, "iip"))
8846                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8847         else {
8848                 printf("The filter type is not supported");
8849                 return;
8850         }
8851
8852         if (!strcmp(res->tunnel_type, "vxlan"))
8853                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8854         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8855                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8856         else if (!strcmp(res->tunnel_type, "nvgre"))
8857                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8858         else if (!strcmp(res->tunnel_type, "ipingre"))
8859                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8860         else {
8861                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8862                 return;
8863         }
8864
8865         tunnel_filter_conf.tenant_id = res->tenant_id;
8866         tunnel_filter_conf.queue_id = res->queue_num;
8867         if (!strcmp(res->what, "add"))
8868                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8869                                         RTE_ETH_FILTER_TUNNEL,
8870                                         RTE_ETH_FILTER_ADD,
8871                                         &tunnel_filter_conf);
8872         else
8873                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8874                                         RTE_ETH_FILTER_TUNNEL,
8875                                         RTE_ETH_FILTER_DELETE,
8876                                         &tunnel_filter_conf);
8877         if (ret < 0)
8878                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8879                                 strerror(-ret));
8880
8881 }
8882 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8883         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8884         cmd, "tunnel_filter");
8885 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8886         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8887         what, "add#rm");
8888 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8889         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8890         port_id, UINT16);
8891 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8892         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8893         outer_mac);
8894 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8895         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8896         inner_mac);
8897 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8898         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8899         inner_vlan, UINT16);
8900 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8901         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8902         ip_value);
8903 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8904         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8905         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8906
8907 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8908         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8909         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8910                 "imac#omac-imac-tenid");
8911 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8912         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8913         tenant_id, UINT32);
8914 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8915         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8916         queue_num, UINT16);
8917
8918 cmdline_parse_inst_t cmd_tunnel_filter = {
8919         .f = cmd_tunnel_filter_parsed,
8920         .data = (void *)0,
8921         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8922                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8923                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8924                 "<queue_id>: Add/Rm tunnel filter of a port",
8925         .tokens = {
8926                 (void *)&cmd_tunnel_filter_cmd,
8927                 (void *)&cmd_tunnel_filter_what,
8928                 (void *)&cmd_tunnel_filter_port_id,
8929                 (void *)&cmd_tunnel_filter_outer_mac,
8930                 (void *)&cmd_tunnel_filter_inner_mac,
8931                 (void *)&cmd_tunnel_filter_ip_value,
8932                 (void *)&cmd_tunnel_filter_innner_vlan,
8933                 (void *)&cmd_tunnel_filter_tunnel_type,
8934                 (void *)&cmd_tunnel_filter_filter_type,
8935                 (void *)&cmd_tunnel_filter_tenant_id,
8936                 (void *)&cmd_tunnel_filter_queue_num,
8937                 NULL,
8938         },
8939 };
8940
8941 /* *** CONFIGURE TUNNEL UDP PORT *** */
8942 struct cmd_tunnel_udp_config {
8943         cmdline_fixed_string_t cmd;
8944         cmdline_fixed_string_t what;
8945         uint16_t udp_port;
8946         portid_t port_id;
8947 };
8948
8949 static void
8950 cmd_tunnel_udp_config_parsed(void *parsed_result,
8951                           __attribute__((unused)) struct cmdline *cl,
8952                           __attribute__((unused)) void *data)
8953 {
8954         struct cmd_tunnel_udp_config *res = parsed_result;
8955         struct rte_eth_udp_tunnel tunnel_udp;
8956         int ret;
8957
8958         tunnel_udp.udp_port = res->udp_port;
8959
8960         if (!strcmp(res->cmd, "rx_vxlan_port"))
8961                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8962
8963         if (!strcmp(res->what, "add"))
8964                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8965                                                       &tunnel_udp);
8966         else
8967                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8968                                                          &tunnel_udp);
8969
8970         if (ret < 0)
8971                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8972 }
8973
8974 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8975         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8976                                 cmd, "rx_vxlan_port");
8977 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8978         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8979                                 what, "add#rm");
8980 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8981         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8982                                 udp_port, UINT16);
8983 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8984         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8985                                 port_id, UINT16);
8986
8987 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8988         .f = cmd_tunnel_udp_config_parsed,
8989         .data = (void *)0,
8990         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8991                 "Add/Remove a tunneling UDP port filter",
8992         .tokens = {
8993                 (void *)&cmd_tunnel_udp_config_cmd,
8994                 (void *)&cmd_tunnel_udp_config_what,
8995                 (void *)&cmd_tunnel_udp_config_udp_port,
8996                 (void *)&cmd_tunnel_udp_config_port_id,
8997                 NULL,
8998         },
8999 };
9000
9001 struct cmd_config_tunnel_udp_port {
9002         cmdline_fixed_string_t port;
9003         cmdline_fixed_string_t config;
9004         portid_t port_id;
9005         cmdline_fixed_string_t udp_tunnel_port;
9006         cmdline_fixed_string_t action;
9007         cmdline_fixed_string_t tunnel_type;
9008         uint16_t udp_port;
9009 };
9010
9011 static void
9012 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9013                                __attribute__((unused)) struct cmdline *cl,
9014                                __attribute__((unused)) void *data)
9015 {
9016         struct cmd_config_tunnel_udp_port *res = parsed_result;
9017         struct rte_eth_udp_tunnel tunnel_udp;
9018         int ret = 0;
9019
9020         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9021                 return;
9022
9023         tunnel_udp.udp_port = res->udp_port;
9024
9025         if (!strcmp(res->tunnel_type, "vxlan")) {
9026                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9027         } else if (!strcmp(res->tunnel_type, "geneve")) {
9028                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9029         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9030                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9031         } else {
9032                 printf("Invalid tunnel type\n");
9033                 return;
9034         }
9035
9036         if (!strcmp(res->action, "add"))
9037                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9038                                                       &tunnel_udp);
9039         else
9040                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9041                                                          &tunnel_udp);
9042
9043         if (ret < 0)
9044                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9045 }
9046
9047 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9048         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9049                                  "port");
9050 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9051         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9052                                  "config");
9053 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9054         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9055                               UINT16);
9056 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9057         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9058                                  udp_tunnel_port,
9059                                  "udp_tunnel_port");
9060 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9061         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9062                                  "add#rm");
9063 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9064         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9065                                  "vxlan#geneve#vxlan-gpe");
9066 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9067         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9068                               UINT16);
9069
9070 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9071         .f = cmd_cfg_tunnel_udp_port_parsed,
9072         .data = NULL,
9073         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9074         .tokens = {
9075                 (void *)&cmd_config_tunnel_udp_port_port,
9076                 (void *)&cmd_config_tunnel_udp_port_config,
9077                 (void *)&cmd_config_tunnel_udp_port_port_id,
9078                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9079                 (void *)&cmd_config_tunnel_udp_port_action,
9080                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9081                 (void *)&cmd_config_tunnel_udp_port_value,
9082                 NULL,
9083         },
9084 };
9085
9086 /* *** GLOBAL CONFIG *** */
9087 struct cmd_global_config_result {
9088         cmdline_fixed_string_t cmd;
9089         portid_t port_id;
9090         cmdline_fixed_string_t cfg_type;
9091         uint8_t len;
9092 };
9093
9094 static void
9095 cmd_global_config_parsed(void *parsed_result,
9096                          __attribute__((unused)) struct cmdline *cl,
9097                          __attribute__((unused)) void *data)
9098 {
9099         struct cmd_global_config_result *res = parsed_result;
9100         struct rte_eth_global_cfg conf;
9101         int ret;
9102
9103         memset(&conf, 0, sizeof(conf));
9104         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9105         conf.cfg.gre_key_len = res->len;
9106         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9107                                       RTE_ETH_FILTER_SET, &conf);
9108         if (ret != 0)
9109                 printf("Global config error\n");
9110 }
9111
9112 cmdline_parse_token_string_t cmd_global_config_cmd =
9113         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9114                 "global_config");
9115 cmdline_parse_token_num_t cmd_global_config_port_id =
9116         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9117                                UINT16);
9118 cmdline_parse_token_string_t cmd_global_config_type =
9119         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9120                 cfg_type, "gre-key-len");
9121 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9122         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9123                 len, UINT8);
9124
9125 cmdline_parse_inst_t cmd_global_config = {
9126         .f = cmd_global_config_parsed,
9127         .data = (void *)NULL,
9128         .help_str = "global_config <port_id> gre-key-len <key_len>",
9129         .tokens = {
9130                 (void *)&cmd_global_config_cmd,
9131                 (void *)&cmd_global_config_port_id,
9132                 (void *)&cmd_global_config_type,
9133                 (void *)&cmd_global_config_gre_key_len,
9134                 NULL,
9135         },
9136 };
9137
9138 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9139 struct cmd_set_mirror_mask_result {
9140         cmdline_fixed_string_t set;
9141         cmdline_fixed_string_t port;
9142         portid_t port_id;
9143         cmdline_fixed_string_t mirror;
9144         uint8_t rule_id;
9145         cmdline_fixed_string_t what;
9146         cmdline_fixed_string_t value;
9147         cmdline_fixed_string_t dstpool;
9148         uint8_t dstpool_id;
9149         cmdline_fixed_string_t on;
9150 };
9151
9152 cmdline_parse_token_string_t cmd_mirror_mask_set =
9153         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9154                                 set, "set");
9155 cmdline_parse_token_string_t cmd_mirror_mask_port =
9156         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9157                                 port, "port");
9158 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9159         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9160                                 port_id, UINT16);
9161 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9162         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9163                                 mirror, "mirror-rule");
9164 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9165         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9166                                 rule_id, UINT8);
9167 cmdline_parse_token_string_t cmd_mirror_mask_what =
9168         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9169                                 what, "pool-mirror-up#pool-mirror-down"
9170                                       "#vlan-mirror");
9171 cmdline_parse_token_string_t cmd_mirror_mask_value =
9172         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9173                                 value, NULL);
9174 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9175         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9176                                 dstpool, "dst-pool");
9177 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9178         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9179                                 dstpool_id, UINT8);
9180 cmdline_parse_token_string_t cmd_mirror_mask_on =
9181         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9182                                 on, "on#off");
9183
9184 static void
9185 cmd_set_mirror_mask_parsed(void *parsed_result,
9186                        __attribute__((unused)) struct cmdline *cl,
9187                        __attribute__((unused)) void *data)
9188 {
9189         int ret,nb_item,i;
9190         struct cmd_set_mirror_mask_result *res = parsed_result;
9191         struct rte_eth_mirror_conf mr_conf;
9192
9193         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9194
9195         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9196
9197         mr_conf.dst_pool = res->dstpool_id;
9198
9199         if (!strcmp(res->what, "pool-mirror-up")) {
9200                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9201                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9202         } else if (!strcmp(res->what, "pool-mirror-down")) {
9203                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9204                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9205         } else if (!strcmp(res->what, "vlan-mirror")) {
9206                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9207                 nb_item = parse_item_list(res->value, "vlan",
9208                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9209                 if (nb_item <= 0)
9210                         return;
9211
9212                 for (i = 0; i < nb_item; i++) {
9213                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
9214                                 printf("Invalid vlan_id: must be < 4096\n");
9215                                 return;
9216                         }
9217
9218                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9219                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9220                 }
9221         }
9222
9223         if (!strcmp(res->on, "on"))
9224                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9225                                                 res->rule_id, 1);
9226         else
9227                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9228                                                 res->rule_id, 0);
9229         if (ret < 0)
9230                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9231 }
9232
9233 cmdline_parse_inst_t cmd_set_mirror_mask = {
9234                 .f = cmd_set_mirror_mask_parsed,
9235                 .data = NULL,
9236                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9237                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9238                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9239                 .tokens = {
9240                         (void *)&cmd_mirror_mask_set,
9241                         (void *)&cmd_mirror_mask_port,
9242                         (void *)&cmd_mirror_mask_portid,
9243                         (void *)&cmd_mirror_mask_mirror,
9244                         (void *)&cmd_mirror_mask_ruleid,
9245                         (void *)&cmd_mirror_mask_what,
9246                         (void *)&cmd_mirror_mask_value,
9247                         (void *)&cmd_mirror_mask_dstpool,
9248                         (void *)&cmd_mirror_mask_poolid,
9249                         (void *)&cmd_mirror_mask_on,
9250                         NULL,
9251                 },
9252 };
9253
9254 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9255 struct cmd_set_mirror_link_result {
9256         cmdline_fixed_string_t set;
9257         cmdline_fixed_string_t port;
9258         portid_t port_id;
9259         cmdline_fixed_string_t mirror;
9260         uint8_t rule_id;
9261         cmdline_fixed_string_t what;
9262         cmdline_fixed_string_t dstpool;
9263         uint8_t dstpool_id;
9264         cmdline_fixed_string_t on;
9265 };
9266
9267 cmdline_parse_token_string_t cmd_mirror_link_set =
9268         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9269                                  set, "set");
9270 cmdline_parse_token_string_t cmd_mirror_link_port =
9271         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9272                                 port, "port");
9273 cmdline_parse_token_num_t cmd_mirror_link_portid =
9274         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9275                                 port_id, UINT16);
9276 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9277         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9278                                 mirror, "mirror-rule");
9279 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9280         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9281                             rule_id, UINT8);
9282 cmdline_parse_token_string_t cmd_mirror_link_what =
9283         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9284                                 what, "uplink-mirror#downlink-mirror");
9285 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9286         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9287                                 dstpool, "dst-pool");
9288 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9289         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9290                                 dstpool_id, UINT8);
9291 cmdline_parse_token_string_t cmd_mirror_link_on =
9292         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9293                                 on, "on#off");
9294
9295 static void
9296 cmd_set_mirror_link_parsed(void *parsed_result,
9297                        __attribute__((unused)) struct cmdline *cl,
9298                        __attribute__((unused)) void *data)
9299 {
9300         int ret;
9301         struct cmd_set_mirror_link_result *res = parsed_result;
9302         struct rte_eth_mirror_conf mr_conf;
9303
9304         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9305         if (!strcmp(res->what, "uplink-mirror"))
9306                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9307         else
9308                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9309
9310         mr_conf.dst_pool = res->dstpool_id;
9311
9312         if (!strcmp(res->on, "on"))
9313                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9314                                                 res->rule_id, 1);
9315         else
9316                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9317                                                 res->rule_id, 0);
9318
9319         /* check the return value and print it if is < 0 */
9320         if (ret < 0)
9321                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9322
9323 }
9324
9325 cmdline_parse_inst_t cmd_set_mirror_link = {
9326                 .f = cmd_set_mirror_link_parsed,
9327                 .data = NULL,
9328                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9329                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9330                 .tokens = {
9331                         (void *)&cmd_mirror_link_set,
9332                         (void *)&cmd_mirror_link_port,
9333                         (void *)&cmd_mirror_link_portid,
9334                         (void *)&cmd_mirror_link_mirror,
9335                         (void *)&cmd_mirror_link_ruleid,
9336                         (void *)&cmd_mirror_link_what,
9337                         (void *)&cmd_mirror_link_dstpool,
9338                         (void *)&cmd_mirror_link_poolid,
9339                         (void *)&cmd_mirror_link_on,
9340                         NULL,
9341                 },
9342 };
9343
9344 /* *** RESET VM MIRROR RULE *** */
9345 struct cmd_rm_mirror_rule_result {
9346         cmdline_fixed_string_t reset;
9347         cmdline_fixed_string_t port;
9348         portid_t port_id;
9349         cmdline_fixed_string_t mirror;
9350         uint8_t rule_id;
9351 };
9352
9353 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9354         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9355                                  reset, "reset");
9356 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9357         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9358                                 port, "port");
9359 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9360         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9361                                 port_id, UINT16);
9362 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9363         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9364                                 mirror, "mirror-rule");
9365 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9366         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9367                                 rule_id, UINT8);
9368
9369 static void
9370 cmd_reset_mirror_rule_parsed(void *parsed_result,
9371                        __attribute__((unused)) struct cmdline *cl,
9372                        __attribute__((unused)) void *data)
9373 {
9374         int ret;
9375         struct cmd_set_mirror_link_result *res = parsed_result;
9376         /* check rule_id */
9377         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9378         if(ret < 0)
9379                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9380 }
9381
9382 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9383                 .f = cmd_reset_mirror_rule_parsed,
9384                 .data = NULL,
9385                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9386                 .tokens = {
9387                         (void *)&cmd_rm_mirror_rule_reset,
9388                         (void *)&cmd_rm_mirror_rule_port,
9389                         (void *)&cmd_rm_mirror_rule_portid,
9390                         (void *)&cmd_rm_mirror_rule_mirror,
9391                         (void *)&cmd_rm_mirror_rule_ruleid,
9392                         NULL,
9393                 },
9394 };
9395
9396 /* ******************************************************************************** */
9397
9398 struct cmd_dump_result {
9399         cmdline_fixed_string_t dump;
9400 };
9401
9402 static void
9403 dump_struct_sizes(void)
9404 {
9405 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9406         DUMP_SIZE(struct rte_mbuf);
9407         DUMP_SIZE(struct rte_mempool);
9408         DUMP_SIZE(struct rte_ring);
9409 #undef DUMP_SIZE
9410 }
9411
9412 static void cmd_dump_parsed(void *parsed_result,
9413                             __attribute__((unused)) struct cmdline *cl,
9414                             __attribute__((unused)) void *data)
9415 {
9416         struct cmd_dump_result *res = parsed_result;
9417
9418         if (!strcmp(res->dump, "dump_physmem"))
9419                 rte_dump_physmem_layout(stdout);
9420         else if (!strcmp(res->dump, "dump_memzone"))
9421                 rte_memzone_dump(stdout);
9422         else if (!strcmp(res->dump, "dump_struct_sizes"))
9423                 dump_struct_sizes();
9424         else if (!strcmp(res->dump, "dump_ring"))
9425                 rte_ring_list_dump(stdout);
9426         else if (!strcmp(res->dump, "dump_mempool"))
9427                 rte_mempool_list_dump(stdout);
9428         else if (!strcmp(res->dump, "dump_devargs"))
9429                 rte_devargs_dump(stdout);
9430         else if (!strcmp(res->dump, "dump_log_types"))
9431                 rte_log_dump(stdout);
9432 }
9433
9434 cmdline_parse_token_string_t cmd_dump_dump =
9435         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9436                 "dump_physmem#"
9437                 "dump_memzone#"
9438                 "dump_struct_sizes#"
9439                 "dump_ring#"
9440                 "dump_mempool#"
9441                 "dump_devargs#"
9442                 "dump_log_types");
9443
9444 cmdline_parse_inst_t cmd_dump = {
9445         .f = cmd_dump_parsed,  /* function to call */
9446         .data = NULL,      /* 2nd arg of func */
9447         .help_str = "Dump status",
9448         .tokens = {        /* token list, NULL terminated */
9449                 (void *)&cmd_dump_dump,
9450                 NULL,
9451         },
9452 };
9453
9454 /* ******************************************************************************** */
9455
9456 struct cmd_dump_one_result {
9457         cmdline_fixed_string_t dump;
9458         cmdline_fixed_string_t name;
9459 };
9460
9461 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9462                                 __attribute__((unused)) void *data)
9463 {
9464         struct cmd_dump_one_result *res = parsed_result;
9465
9466         if (!strcmp(res->dump, "dump_ring")) {
9467                 struct rte_ring *r;
9468                 r = rte_ring_lookup(res->name);
9469                 if (r == NULL) {
9470                         cmdline_printf(cl, "Cannot find ring\n");
9471                         return;
9472                 }
9473                 rte_ring_dump(stdout, r);
9474         } else if (!strcmp(res->dump, "dump_mempool")) {
9475                 struct rte_mempool *mp;
9476                 mp = rte_mempool_lookup(res->name);
9477                 if (mp == NULL) {
9478                         cmdline_printf(cl, "Cannot find mempool\n");
9479                         return;
9480                 }
9481                 rte_mempool_dump(stdout, mp);
9482         }
9483 }
9484
9485 cmdline_parse_token_string_t cmd_dump_one_dump =
9486         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9487                                  "dump_ring#dump_mempool");
9488
9489 cmdline_parse_token_string_t cmd_dump_one_name =
9490         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9491
9492 cmdline_parse_inst_t cmd_dump_one = {
9493         .f = cmd_dump_one_parsed,  /* function to call */
9494         .data = NULL,      /* 2nd arg of func */
9495         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9496         .tokens = {        /* token list, NULL terminated */
9497                 (void *)&cmd_dump_one_dump,
9498                 (void *)&cmd_dump_one_name,
9499                 NULL,
9500         },
9501 };
9502
9503 /* *** Add/Del syn filter *** */
9504 struct cmd_syn_filter_result {
9505         cmdline_fixed_string_t filter;
9506         portid_t port_id;
9507         cmdline_fixed_string_t ops;
9508         cmdline_fixed_string_t priority;
9509         cmdline_fixed_string_t high;
9510         cmdline_fixed_string_t queue;
9511         uint16_t queue_id;
9512 };
9513
9514 static void
9515 cmd_syn_filter_parsed(void *parsed_result,
9516                         __attribute__((unused)) struct cmdline *cl,
9517                         __attribute__((unused)) void *data)
9518 {
9519         struct cmd_syn_filter_result *res = parsed_result;
9520         struct rte_eth_syn_filter syn_filter;
9521         int ret = 0;
9522
9523         ret = rte_eth_dev_filter_supported(res->port_id,
9524                                         RTE_ETH_FILTER_SYN);
9525         if (ret < 0) {
9526                 printf("syn filter is not supported on port %u.\n",
9527                                 res->port_id);
9528                 return;
9529         }
9530
9531         memset(&syn_filter, 0, sizeof(syn_filter));
9532
9533         if (!strcmp(res->ops, "add")) {
9534                 if (!strcmp(res->high, "high"))
9535                         syn_filter.hig_pri = 1;
9536                 else
9537                         syn_filter.hig_pri = 0;
9538
9539                 syn_filter.queue = res->queue_id;
9540                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9541                                                 RTE_ETH_FILTER_SYN,
9542                                                 RTE_ETH_FILTER_ADD,
9543                                                 &syn_filter);
9544         } else
9545                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9546                                                 RTE_ETH_FILTER_SYN,
9547                                                 RTE_ETH_FILTER_DELETE,
9548                                                 &syn_filter);
9549
9550         if (ret < 0)
9551                 printf("syn filter programming error: (%s)\n",
9552                                 strerror(-ret));
9553 }
9554
9555 cmdline_parse_token_string_t cmd_syn_filter_filter =
9556         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9557         filter, "syn_filter");
9558 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9559         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9560         port_id, UINT16);
9561 cmdline_parse_token_string_t cmd_syn_filter_ops =
9562         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9563         ops, "add#del");
9564 cmdline_parse_token_string_t cmd_syn_filter_priority =
9565         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9566                                 priority, "priority");
9567 cmdline_parse_token_string_t cmd_syn_filter_high =
9568         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9569                                 high, "high#low");
9570 cmdline_parse_token_string_t cmd_syn_filter_queue =
9571         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9572                                 queue, "queue");
9573 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9574         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9575                                 queue_id, UINT16);
9576
9577 cmdline_parse_inst_t cmd_syn_filter = {
9578         .f = cmd_syn_filter_parsed,
9579         .data = NULL,
9580         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9581                 "<queue_id>: Add/Delete syn filter",
9582         .tokens = {
9583                 (void *)&cmd_syn_filter_filter,
9584                 (void *)&cmd_syn_filter_port_id,
9585                 (void *)&cmd_syn_filter_ops,
9586                 (void *)&cmd_syn_filter_priority,
9587                 (void *)&cmd_syn_filter_high,
9588                 (void *)&cmd_syn_filter_queue,
9589                 (void *)&cmd_syn_filter_queue_id,
9590                 NULL,
9591         },
9592 };
9593
9594 /* *** queue region set *** */
9595 struct cmd_queue_region_result {
9596         cmdline_fixed_string_t set;
9597         cmdline_fixed_string_t port;
9598         portid_t port_id;
9599         cmdline_fixed_string_t cmd;
9600         cmdline_fixed_string_t region;
9601         uint8_t  region_id;
9602         cmdline_fixed_string_t queue_start_index;
9603         uint8_t  queue_id;
9604         cmdline_fixed_string_t queue_num;
9605         uint8_t  queue_num_value;
9606 };
9607
9608 static void
9609 cmd_queue_region_parsed(void *parsed_result,
9610                         __attribute__((unused)) struct cmdline *cl,
9611                         __attribute__((unused)) void *data)
9612 {
9613         struct cmd_queue_region_result *res = parsed_result;
9614         int ret = -ENOTSUP;
9615 #ifdef RTE_LIBRTE_I40E_PMD
9616         struct rte_pmd_i40e_queue_region_conf region_conf;
9617         enum rte_pmd_i40e_queue_region_op op_type;
9618 #endif
9619
9620         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9621                 return;
9622
9623 #ifdef RTE_LIBRTE_I40E_PMD
9624         memset(&region_conf, 0, sizeof(region_conf));
9625         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9626         region_conf.region_id = res->region_id;
9627         region_conf.queue_num = res->queue_num_value;
9628         region_conf.queue_start_index = res->queue_id;
9629
9630         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9631                                 op_type, &region_conf);
9632 #endif
9633
9634         switch (ret) {
9635         case 0:
9636                 break;
9637         case -ENOTSUP:
9638                 printf("function not implemented or supported\n");
9639                 break;
9640         default:
9641                 printf("queue region config error: (%s)\n", strerror(-ret));
9642         }
9643 }
9644
9645 cmdline_parse_token_string_t cmd_queue_region_set =
9646 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9647                 set, "set");
9648 cmdline_parse_token_string_t cmd_queue_region_port =
9649         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9650 cmdline_parse_token_num_t cmd_queue_region_port_id =
9651         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9652                                 port_id, UINT16);
9653 cmdline_parse_token_string_t cmd_queue_region_cmd =
9654         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9655                                  cmd, "queue-region");
9656 cmdline_parse_token_string_t cmd_queue_region_id =
9657         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9658                                 region, "region_id");
9659 cmdline_parse_token_num_t cmd_queue_region_index =
9660         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9661                                 region_id, UINT8);
9662 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9663         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9664                                 queue_start_index, "queue_start_index");
9665 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9666         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9667                                 queue_id, UINT8);
9668 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9669         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9670                                 queue_num, "queue_num");
9671 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9672         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9673                                 queue_num_value, UINT8);
9674
9675 cmdline_parse_inst_t cmd_queue_region = {
9676         .f = cmd_queue_region_parsed,
9677         .data = NULL,
9678         .help_str = "set port <port_id> queue-region region_id <value> "
9679                 "queue_start_index <value> queue_num <value>: Set a queue region",
9680         .tokens = {
9681                 (void *)&cmd_queue_region_set,
9682                 (void *)&cmd_queue_region_port,
9683                 (void *)&cmd_queue_region_port_id,
9684                 (void *)&cmd_queue_region_cmd,
9685                 (void *)&cmd_queue_region_id,
9686                 (void *)&cmd_queue_region_index,
9687                 (void *)&cmd_queue_region_queue_start_index,
9688                 (void *)&cmd_queue_region_queue_id,
9689                 (void *)&cmd_queue_region_queue_num,
9690                 (void *)&cmd_queue_region_queue_num_value,
9691                 NULL,
9692         },
9693 };
9694
9695 /* *** queue region and flowtype set *** */
9696 struct cmd_region_flowtype_result {
9697         cmdline_fixed_string_t set;
9698         cmdline_fixed_string_t port;
9699         portid_t port_id;
9700         cmdline_fixed_string_t cmd;
9701         cmdline_fixed_string_t region;
9702         uint8_t  region_id;
9703         cmdline_fixed_string_t flowtype;
9704         uint8_t  flowtype_id;
9705 };
9706
9707 static void
9708 cmd_region_flowtype_parsed(void *parsed_result,
9709                         __attribute__((unused)) struct cmdline *cl,
9710                         __attribute__((unused)) void *data)
9711 {
9712         struct cmd_region_flowtype_result *res = parsed_result;
9713         int ret = -ENOTSUP;
9714 #ifdef RTE_LIBRTE_I40E_PMD
9715         struct rte_pmd_i40e_queue_region_conf region_conf;
9716         enum rte_pmd_i40e_queue_region_op op_type;
9717 #endif
9718
9719         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9720                 return;
9721
9722 #ifdef RTE_LIBRTE_I40E_PMD
9723         memset(&region_conf, 0, sizeof(region_conf));
9724
9725         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9726         region_conf.region_id = res->region_id;
9727         region_conf.hw_flowtype = res->flowtype_id;
9728
9729         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9730                         op_type, &region_conf);
9731 #endif
9732
9733         switch (ret) {
9734         case 0:
9735                 break;
9736         case -ENOTSUP:
9737                 printf("function not implemented or supported\n");
9738                 break;
9739         default:
9740                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9741         }
9742 }
9743
9744 cmdline_parse_token_string_t cmd_region_flowtype_set =
9745 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9746                                 set, "set");
9747 cmdline_parse_token_string_t cmd_region_flowtype_port =
9748         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9749                                 port, "port");
9750 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9751         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9752                                 port_id, UINT16);
9753 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9754         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9755                                 cmd, "queue-region");
9756 cmdline_parse_token_string_t cmd_region_flowtype_index =
9757         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9758                                 region, "region_id");
9759 cmdline_parse_token_num_t cmd_region_flowtype_id =
9760         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9761                                 region_id, UINT8);
9762 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9763         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9764                                 flowtype, "flowtype");
9765 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9766         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9767                                 flowtype_id, UINT8);
9768 cmdline_parse_inst_t cmd_region_flowtype = {
9769         .f = cmd_region_flowtype_parsed,
9770         .data = NULL,
9771         .help_str = "set port <port_id> queue-region region_id <value> "
9772                 "flowtype <value>: Set a flowtype region index",
9773         .tokens = {
9774                 (void *)&cmd_region_flowtype_set,
9775                 (void *)&cmd_region_flowtype_port,
9776                 (void *)&cmd_region_flowtype_port_index,
9777                 (void *)&cmd_region_flowtype_cmd,
9778                 (void *)&cmd_region_flowtype_index,
9779                 (void *)&cmd_region_flowtype_id,
9780                 (void *)&cmd_region_flowtype_flow_index,
9781                 (void *)&cmd_region_flowtype_flow_id,
9782                 NULL,
9783         },
9784 };
9785
9786 /* *** User Priority (UP) to queue region (region_id) set *** */
9787 struct cmd_user_priority_region_result {
9788         cmdline_fixed_string_t set;
9789         cmdline_fixed_string_t port;
9790         portid_t port_id;
9791         cmdline_fixed_string_t cmd;
9792         cmdline_fixed_string_t user_priority;
9793         uint8_t  user_priority_id;
9794         cmdline_fixed_string_t region;
9795         uint8_t  region_id;
9796 };
9797
9798 static void
9799 cmd_user_priority_region_parsed(void *parsed_result,
9800                         __attribute__((unused)) struct cmdline *cl,
9801                         __attribute__((unused)) void *data)
9802 {
9803         struct cmd_user_priority_region_result *res = parsed_result;
9804         int ret = -ENOTSUP;
9805 #ifdef RTE_LIBRTE_I40E_PMD
9806         struct rte_pmd_i40e_queue_region_conf region_conf;
9807         enum rte_pmd_i40e_queue_region_op op_type;
9808 #endif
9809
9810         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9811                 return;
9812
9813 #ifdef RTE_LIBRTE_I40E_PMD
9814         memset(&region_conf, 0, sizeof(region_conf));
9815         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9816         region_conf.user_priority = res->user_priority_id;
9817         region_conf.region_id = res->region_id;
9818
9819         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9820                                 op_type, &region_conf);
9821 #endif
9822
9823         switch (ret) {
9824         case 0:
9825                 break;
9826         case -ENOTSUP:
9827                 printf("function not implemented or supported\n");
9828                 break;
9829         default:
9830                 printf("user_priority region config error: (%s)\n",
9831                                 strerror(-ret));
9832         }
9833 }
9834
9835 cmdline_parse_token_string_t cmd_user_priority_region_set =
9836         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9837                                 set, "set");
9838 cmdline_parse_token_string_t cmd_user_priority_region_port =
9839         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9840                                 port, "port");
9841 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9842         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9843                                 port_id, UINT16);
9844 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9845         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9846                                 cmd, "queue-region");
9847 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9848         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9849                                 user_priority, "UP");
9850 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9851         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9852                                 user_priority_id, UINT8);
9853 cmdline_parse_token_string_t cmd_user_priority_region_region =
9854         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9855                                 region, "region_id");
9856 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9857         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9858                                 region_id, UINT8);
9859
9860 cmdline_parse_inst_t cmd_user_priority_region = {
9861         .f = cmd_user_priority_region_parsed,
9862         .data = NULL,
9863         .help_str = "set port <port_id> queue-region UP <value> "
9864                 "region_id <value>: Set the mapping of User Priority (UP) "
9865                 "to queue region (region_id) ",
9866         .tokens = {
9867                 (void *)&cmd_user_priority_region_set,
9868                 (void *)&cmd_user_priority_region_port,
9869                 (void *)&cmd_user_priority_region_port_index,
9870                 (void *)&cmd_user_priority_region_cmd,
9871                 (void *)&cmd_user_priority_region_UP,
9872                 (void *)&cmd_user_priority_region_UP_id,
9873                 (void *)&cmd_user_priority_region_region,
9874                 (void *)&cmd_user_priority_region_region_id,
9875                 NULL,
9876         },
9877 };
9878
9879 /* *** flush all queue region related configuration *** */
9880 struct cmd_flush_queue_region_result {
9881         cmdline_fixed_string_t set;
9882         cmdline_fixed_string_t port;
9883         portid_t port_id;
9884         cmdline_fixed_string_t cmd;
9885         cmdline_fixed_string_t flush;
9886         cmdline_fixed_string_t what;
9887 };
9888
9889 static void
9890 cmd_flush_queue_region_parsed(void *parsed_result,
9891                         __attribute__((unused)) struct cmdline *cl,
9892                         __attribute__((unused)) void *data)
9893 {
9894         struct cmd_flush_queue_region_result *res = parsed_result;
9895         int ret = -ENOTSUP;
9896 #ifdef RTE_LIBRTE_I40E_PMD
9897         struct rte_pmd_i40e_queue_region_conf region_conf;
9898         enum rte_pmd_i40e_queue_region_op op_type;
9899 #endif
9900
9901         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9902                 return;
9903
9904 #ifdef RTE_LIBRTE_I40E_PMD
9905         memset(&region_conf, 0, sizeof(region_conf));
9906
9907         if (strcmp(res->what, "on") == 0)
9908                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9909         else
9910                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9911
9912         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9913                                 op_type, &region_conf);
9914 #endif
9915
9916         switch (ret) {
9917         case 0:
9918                 break;
9919         case -ENOTSUP:
9920                 printf("function not implemented or supported\n");
9921                 break;
9922         default:
9923                 printf("queue region config flush error: (%s)\n",
9924                                 strerror(-ret));
9925         }
9926 }
9927
9928 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9929         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9930                                 set, "set");
9931 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9932         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9933                                 port, "port");
9934 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9935         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9936                                 port_id, UINT16);
9937 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9938         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9939                                 cmd, "queue-region");
9940 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9941         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9942                                 flush, "flush");
9943 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9944         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9945                                 what, "on#off");
9946
9947 cmdline_parse_inst_t cmd_flush_queue_region = {
9948         .f = cmd_flush_queue_region_parsed,
9949         .data = NULL,
9950         .help_str = "set port <port_id> queue-region flush on|off"
9951                 ": flush all queue region related configuration",
9952         .tokens = {
9953                 (void *)&cmd_flush_queue_region_set,
9954                 (void *)&cmd_flush_queue_region_port,
9955                 (void *)&cmd_flush_queue_region_port_index,
9956                 (void *)&cmd_flush_queue_region_cmd,
9957                 (void *)&cmd_flush_queue_region_flush,
9958                 (void *)&cmd_flush_queue_region_what,
9959                 NULL,
9960         },
9961 };
9962
9963 /* *** get all queue region related configuration info *** */
9964 struct cmd_show_queue_region_info {
9965         cmdline_fixed_string_t show;
9966         cmdline_fixed_string_t port;
9967         portid_t port_id;
9968         cmdline_fixed_string_t cmd;
9969 };
9970
9971 static void
9972 cmd_show_queue_region_info_parsed(void *parsed_result,
9973                         __attribute__((unused)) struct cmdline *cl,
9974                         __attribute__((unused)) void *data)
9975 {
9976         struct cmd_show_queue_region_info *res = parsed_result;
9977         int ret = -ENOTSUP;
9978 #ifdef RTE_LIBRTE_I40E_PMD
9979         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9980         enum rte_pmd_i40e_queue_region_op op_type;
9981 #endif
9982
9983         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9984                 return;
9985
9986 #ifdef RTE_LIBRTE_I40E_PMD
9987         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9988
9989         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9990
9991         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9992                                         op_type, &rte_pmd_regions);
9993
9994         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9995 #endif
9996
9997         switch (ret) {
9998         case 0:
9999                 break;
10000         case -ENOTSUP:
10001                 printf("function not implemented or supported\n");
10002                 break;
10003         default:
10004                 printf("queue region config info show error: (%s)\n",
10005                                 strerror(-ret));
10006         }
10007 }
10008
10009 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10010 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10011                                 show, "show");
10012 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10013         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10014                                 port, "port");
10015 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10016         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10017                                 port_id, UINT16);
10018 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10019         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10020                                 cmd, "queue-region");
10021
10022 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10023         .f = cmd_show_queue_region_info_parsed,
10024         .data = NULL,
10025         .help_str = "show port <port_id> queue-region"
10026                 ": show all queue region related configuration info",
10027         .tokens = {
10028                 (void *)&cmd_show_queue_region_info_get,
10029                 (void *)&cmd_show_queue_region_info_port,
10030                 (void *)&cmd_show_queue_region_info_port_index,
10031                 (void *)&cmd_show_queue_region_info_cmd,
10032                 NULL,
10033         },
10034 };
10035
10036 /* *** ADD/REMOVE A 2tuple FILTER *** */
10037 struct cmd_2tuple_filter_result {
10038         cmdline_fixed_string_t filter;
10039         portid_t port_id;
10040         cmdline_fixed_string_t ops;
10041         cmdline_fixed_string_t dst_port;
10042         uint16_t dst_port_value;
10043         cmdline_fixed_string_t protocol;
10044         uint8_t protocol_value;
10045         cmdline_fixed_string_t mask;
10046         uint8_t  mask_value;
10047         cmdline_fixed_string_t tcp_flags;
10048         uint8_t tcp_flags_value;
10049         cmdline_fixed_string_t priority;
10050         uint8_t  priority_value;
10051         cmdline_fixed_string_t queue;
10052         uint16_t  queue_id;
10053 };
10054
10055 static void
10056 cmd_2tuple_filter_parsed(void *parsed_result,
10057                         __attribute__((unused)) struct cmdline *cl,
10058                         __attribute__((unused)) void *data)
10059 {
10060         struct rte_eth_ntuple_filter filter;
10061         struct cmd_2tuple_filter_result *res = parsed_result;
10062         int ret = 0;
10063
10064         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10065         if (ret < 0) {
10066                 printf("ntuple filter is not supported on port %u.\n",
10067                         res->port_id);
10068                 return;
10069         }
10070
10071         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10072
10073         filter.flags = RTE_2TUPLE_FLAGS;
10074         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10075         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10076         filter.proto = res->protocol_value;
10077         filter.priority = res->priority_value;
10078         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10079                 printf("nonzero tcp_flags is only meaningful"
10080                         " when protocol is TCP.\n");
10081                 return;
10082         }
10083         if (res->tcp_flags_value > TCP_FLAG_ALL) {
10084                 printf("invalid TCP flags.\n");
10085                 return;
10086         }
10087
10088         if (res->tcp_flags_value != 0) {
10089                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10090                 filter.tcp_flags = res->tcp_flags_value;
10091         }
10092
10093         /* need convert to big endian. */
10094         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10095         filter.queue = res->queue_id;
10096
10097         if (!strcmp(res->ops, "add"))
10098                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10099                                 RTE_ETH_FILTER_NTUPLE,
10100                                 RTE_ETH_FILTER_ADD,
10101                                 &filter);
10102         else
10103                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10104                                 RTE_ETH_FILTER_NTUPLE,
10105                                 RTE_ETH_FILTER_DELETE,
10106                                 &filter);
10107         if (ret < 0)
10108                 printf("2tuple filter programming error: (%s)\n",
10109                         strerror(-ret));
10110
10111 }
10112
10113 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10114         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10115                                  filter, "2tuple_filter");
10116 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10117         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10118                                 port_id, UINT16);
10119 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10120         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10121                                  ops, "add#del");
10122 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10123         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10124                                 dst_port, "dst_port");
10125 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10126         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10127                                 dst_port_value, UINT16);
10128 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10129         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10130                                 protocol, "protocol");
10131 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10132         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10133                                 protocol_value, UINT8);
10134 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10135         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10136                                 mask, "mask");
10137 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10138         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10139                                 mask_value, INT8);
10140 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10141         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10142                                 tcp_flags, "tcp_flags");
10143 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10144         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10145                                 tcp_flags_value, UINT8);
10146 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10147         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10148                                 priority, "priority");
10149 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10150         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10151                                 priority_value, UINT8);
10152 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10153         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10154                                 queue, "queue");
10155 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10156         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10157                                 queue_id, UINT16);
10158
10159 cmdline_parse_inst_t cmd_2tuple_filter = {
10160         .f = cmd_2tuple_filter_parsed,
10161         .data = NULL,
10162         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10163                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10164                 "<queue_id>: Add a 2tuple filter",
10165         .tokens = {
10166                 (void *)&cmd_2tuple_filter_filter,
10167                 (void *)&cmd_2tuple_filter_port_id,
10168                 (void *)&cmd_2tuple_filter_ops,
10169                 (void *)&cmd_2tuple_filter_dst_port,
10170                 (void *)&cmd_2tuple_filter_dst_port_value,
10171                 (void *)&cmd_2tuple_filter_protocol,
10172                 (void *)&cmd_2tuple_filter_protocol_value,
10173                 (void *)&cmd_2tuple_filter_mask,
10174                 (void *)&cmd_2tuple_filter_mask_value,
10175                 (void *)&cmd_2tuple_filter_tcp_flags,
10176                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10177                 (void *)&cmd_2tuple_filter_priority,
10178                 (void *)&cmd_2tuple_filter_priority_value,
10179                 (void *)&cmd_2tuple_filter_queue,
10180                 (void *)&cmd_2tuple_filter_queue_id,
10181                 NULL,
10182         },
10183 };
10184
10185 /* *** ADD/REMOVE A 5tuple FILTER *** */
10186 struct cmd_5tuple_filter_result {
10187         cmdline_fixed_string_t filter;
10188         portid_t port_id;
10189         cmdline_fixed_string_t ops;
10190         cmdline_fixed_string_t dst_ip;
10191         cmdline_ipaddr_t dst_ip_value;
10192         cmdline_fixed_string_t src_ip;
10193         cmdline_ipaddr_t src_ip_value;
10194         cmdline_fixed_string_t dst_port;
10195         uint16_t dst_port_value;
10196         cmdline_fixed_string_t src_port;
10197         uint16_t src_port_value;
10198         cmdline_fixed_string_t protocol;
10199         uint8_t protocol_value;
10200         cmdline_fixed_string_t mask;
10201         uint8_t  mask_value;
10202         cmdline_fixed_string_t tcp_flags;
10203         uint8_t tcp_flags_value;
10204         cmdline_fixed_string_t priority;
10205         uint8_t  priority_value;
10206         cmdline_fixed_string_t queue;
10207         uint16_t  queue_id;
10208 };
10209
10210 static void
10211 cmd_5tuple_filter_parsed(void *parsed_result,
10212                         __attribute__((unused)) struct cmdline *cl,
10213                         __attribute__((unused)) void *data)
10214 {
10215         struct rte_eth_ntuple_filter filter;
10216         struct cmd_5tuple_filter_result *res = parsed_result;
10217         int ret = 0;
10218
10219         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10220         if (ret < 0) {
10221                 printf("ntuple filter is not supported on port %u.\n",
10222                         res->port_id);
10223                 return;
10224         }
10225
10226         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10227
10228         filter.flags = RTE_5TUPLE_FLAGS;
10229         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10230         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10231         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10232         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10233         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10234         filter.proto = res->protocol_value;
10235         filter.priority = res->priority_value;
10236         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10237                 printf("nonzero tcp_flags is only meaningful"
10238                         " when protocol is TCP.\n");
10239                 return;
10240         }
10241         if (res->tcp_flags_value > TCP_FLAG_ALL) {
10242                 printf("invalid TCP flags.\n");
10243                 return;
10244         }
10245
10246         if (res->tcp_flags_value != 0) {
10247                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10248                 filter.tcp_flags = res->tcp_flags_value;
10249         }
10250
10251         if (res->dst_ip_value.family == AF_INET)
10252                 /* no need to convert, already big endian. */
10253                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10254         else {
10255                 if (filter.dst_ip_mask == 0) {
10256                         printf("can not support ipv6 involved compare.\n");
10257                         return;
10258                 }
10259                 filter.dst_ip = 0;
10260         }
10261
10262         if (res->src_ip_value.family == AF_INET)
10263                 /* no need to convert, already big endian. */
10264                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10265         else {
10266                 if (filter.src_ip_mask == 0) {
10267                         printf("can not support ipv6 involved compare.\n");
10268                         return;
10269                 }
10270                 filter.src_ip = 0;
10271         }
10272         /* need convert to big endian. */
10273         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10274         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10275         filter.queue = res->queue_id;
10276
10277         if (!strcmp(res->ops, "add"))
10278                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10279                                 RTE_ETH_FILTER_NTUPLE,
10280                                 RTE_ETH_FILTER_ADD,
10281                                 &filter);
10282         else
10283                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10284                                 RTE_ETH_FILTER_NTUPLE,
10285                                 RTE_ETH_FILTER_DELETE,
10286                                 &filter);
10287         if (ret < 0)
10288                 printf("5tuple filter programming error: (%s)\n",
10289                         strerror(-ret));
10290 }
10291
10292 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10293         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10294                                  filter, "5tuple_filter");
10295 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10296         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10297                                 port_id, UINT16);
10298 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10299         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10300                                  ops, "add#del");
10301 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10302         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10303                                 dst_ip, "dst_ip");
10304 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10305         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10306                                 dst_ip_value);
10307 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10308         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10309                                 src_ip, "src_ip");
10310 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10311         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10312                                 src_ip_value);
10313 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10314         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10315                                 dst_port, "dst_port");
10316 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10317         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10318                                 dst_port_value, UINT16);
10319 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10320         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10321                                 src_port, "src_port");
10322 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10323         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10324                                 src_port_value, UINT16);
10325 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10326         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10327                                 protocol, "protocol");
10328 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10329         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10330                                 protocol_value, UINT8);
10331 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10332         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10333                                 mask, "mask");
10334 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10335         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10336                                 mask_value, INT8);
10337 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10338         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10339                                 tcp_flags, "tcp_flags");
10340 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10341         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10342                                 tcp_flags_value, UINT8);
10343 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10344         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10345                                 priority, "priority");
10346 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10347         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10348                                 priority_value, UINT8);
10349 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10350         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10351                                 queue, "queue");
10352 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10353         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10354                                 queue_id, UINT16);
10355
10356 cmdline_parse_inst_t cmd_5tuple_filter = {
10357         .f = cmd_5tuple_filter_parsed,
10358         .data = NULL,
10359         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10360                 "src_ip <value> dst_port <value> src_port <value> "
10361                 "protocol <value>  mask <value> tcp_flags <value> "
10362                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10363         .tokens = {
10364                 (void *)&cmd_5tuple_filter_filter,
10365                 (void *)&cmd_5tuple_filter_port_id,
10366                 (void *)&cmd_5tuple_filter_ops,
10367                 (void *)&cmd_5tuple_filter_dst_ip,
10368                 (void *)&cmd_5tuple_filter_dst_ip_value,
10369                 (void *)&cmd_5tuple_filter_src_ip,
10370                 (void *)&cmd_5tuple_filter_src_ip_value,
10371                 (void *)&cmd_5tuple_filter_dst_port,
10372                 (void *)&cmd_5tuple_filter_dst_port_value,
10373                 (void *)&cmd_5tuple_filter_src_port,
10374                 (void *)&cmd_5tuple_filter_src_port_value,
10375                 (void *)&cmd_5tuple_filter_protocol,
10376                 (void *)&cmd_5tuple_filter_protocol_value,
10377                 (void *)&cmd_5tuple_filter_mask,
10378                 (void *)&cmd_5tuple_filter_mask_value,
10379                 (void *)&cmd_5tuple_filter_tcp_flags,
10380                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10381                 (void *)&cmd_5tuple_filter_priority,
10382                 (void *)&cmd_5tuple_filter_priority_value,
10383                 (void *)&cmd_5tuple_filter_queue,
10384                 (void *)&cmd_5tuple_filter_queue_id,
10385                 NULL,
10386         },
10387 };
10388
10389 /* *** ADD/REMOVE A flex FILTER *** */
10390 struct cmd_flex_filter_result {
10391         cmdline_fixed_string_t filter;
10392         cmdline_fixed_string_t ops;
10393         portid_t port_id;
10394         cmdline_fixed_string_t len;
10395         uint8_t len_value;
10396         cmdline_fixed_string_t bytes;
10397         cmdline_fixed_string_t bytes_value;
10398         cmdline_fixed_string_t mask;
10399         cmdline_fixed_string_t mask_value;
10400         cmdline_fixed_string_t priority;
10401         uint8_t priority_value;
10402         cmdline_fixed_string_t queue;
10403         uint16_t queue_id;
10404 };
10405
10406 static int xdigit2val(unsigned char c)
10407 {
10408         int val;
10409         if (isdigit(c))
10410                 val = c - '0';
10411         else if (isupper(c))
10412                 val = c - 'A' + 10;
10413         else
10414                 val = c - 'a' + 10;
10415         return val;
10416 }
10417
10418 static void
10419 cmd_flex_filter_parsed(void *parsed_result,
10420                           __attribute__((unused)) struct cmdline *cl,
10421                           __attribute__((unused)) void *data)
10422 {
10423         int ret = 0;
10424         struct rte_eth_flex_filter filter;
10425         struct cmd_flex_filter_result *res = parsed_result;
10426         char *bytes_ptr, *mask_ptr;
10427         uint16_t len, i, j = 0;
10428         char c;
10429         int val;
10430         uint8_t byte = 0;
10431
10432         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10433                 printf("the len exceed the max length 128\n");
10434                 return;
10435         }
10436         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10437         filter.len = res->len_value;
10438         filter.priority = res->priority_value;
10439         filter.queue = res->queue_id;
10440         bytes_ptr = res->bytes_value;
10441         mask_ptr = res->mask_value;
10442
10443          /* translate bytes string to array. */
10444         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10445                 (bytes_ptr[1] == 'X')))
10446                 bytes_ptr += 2;
10447         len = strnlen(bytes_ptr, res->len_value * 2);
10448         if (len == 0 || (len % 8 != 0)) {
10449                 printf("please check len and bytes input\n");
10450                 return;
10451         }
10452         for (i = 0; i < len; i++) {
10453                 c = bytes_ptr[i];
10454                 if (isxdigit(c) == 0) {
10455                         /* invalid characters. */
10456                         printf("invalid input\n");
10457                         return;
10458                 }
10459                 val = xdigit2val(c);
10460                 if (i % 2) {
10461                         byte |= val;
10462                         filter.bytes[j] = byte;
10463                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10464                         j++;
10465                         byte = 0;
10466                 } else
10467                         byte |= val << 4;
10468         }
10469         printf("\n");
10470          /* translate mask string to uint8_t array. */
10471         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10472                 (mask_ptr[1] == 'X')))
10473                 mask_ptr += 2;
10474         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10475         if (len == 0) {
10476                 printf("invalid input\n");
10477                 return;
10478         }
10479         j = 0;
10480         byte = 0;
10481         for (i = 0; i < len; i++) {
10482                 c = mask_ptr[i];
10483                 if (isxdigit(c) == 0) {
10484                         /* invalid characters. */
10485                         printf("invalid input\n");
10486                         return;
10487                 }
10488                 val = xdigit2val(c);
10489                 if (i % 2) {
10490                         byte |= val;
10491                         filter.mask[j] = byte;
10492                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10493                         j++;
10494                         byte = 0;
10495                 } else
10496                         byte |= val << 4;
10497         }
10498         printf("\n");
10499
10500         if (!strcmp(res->ops, "add"))
10501                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10502                                 RTE_ETH_FILTER_FLEXIBLE,
10503                                 RTE_ETH_FILTER_ADD,
10504                                 &filter);
10505         else
10506                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10507                                 RTE_ETH_FILTER_FLEXIBLE,
10508                                 RTE_ETH_FILTER_DELETE,
10509                                 &filter);
10510
10511         if (ret < 0)
10512                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10513 }
10514
10515 cmdline_parse_token_string_t cmd_flex_filter_filter =
10516         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10517                                 filter, "flex_filter");
10518 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10519         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10520                                 port_id, UINT16);
10521 cmdline_parse_token_string_t cmd_flex_filter_ops =
10522         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10523                                 ops, "add#del");
10524 cmdline_parse_token_string_t cmd_flex_filter_len =
10525         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10526                                 len, "len");
10527 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10528         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10529                                 len_value, UINT8);
10530 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10531         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10532                                 bytes, "bytes");
10533 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10534         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10535                                 bytes_value, NULL);
10536 cmdline_parse_token_string_t cmd_flex_filter_mask =
10537         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10538                                 mask, "mask");
10539 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10540         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10541                                 mask_value, NULL);
10542 cmdline_parse_token_string_t cmd_flex_filter_priority =
10543         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10544                                 priority, "priority");
10545 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10546         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10547                                 priority_value, UINT8);
10548 cmdline_parse_token_string_t cmd_flex_filter_queue =
10549         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10550                                 queue, "queue");
10551 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10552         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10553                                 queue_id, UINT16);
10554 cmdline_parse_inst_t cmd_flex_filter = {
10555         .f = cmd_flex_filter_parsed,
10556         .data = NULL,
10557         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10558                 "<value> mask <value> priority <value> queue <queue_id>: "
10559                 "Add/Del a flex filter",
10560         .tokens = {
10561                 (void *)&cmd_flex_filter_filter,
10562                 (void *)&cmd_flex_filter_port_id,
10563                 (void *)&cmd_flex_filter_ops,
10564                 (void *)&cmd_flex_filter_len,
10565                 (void *)&cmd_flex_filter_len_value,
10566                 (void *)&cmd_flex_filter_bytes,
10567                 (void *)&cmd_flex_filter_bytes_value,
10568                 (void *)&cmd_flex_filter_mask,
10569                 (void *)&cmd_flex_filter_mask_value,
10570                 (void *)&cmd_flex_filter_priority,
10571                 (void *)&cmd_flex_filter_priority_value,
10572                 (void *)&cmd_flex_filter_queue,
10573                 (void *)&cmd_flex_filter_queue_id,
10574                 NULL,
10575         },
10576 };
10577
10578 /* *** Filters Control *** */
10579
10580 /* *** deal with ethertype filter *** */
10581 struct cmd_ethertype_filter_result {
10582         cmdline_fixed_string_t filter;
10583         portid_t port_id;
10584         cmdline_fixed_string_t ops;
10585         cmdline_fixed_string_t mac;
10586         struct rte_ether_addr mac_addr;
10587         cmdline_fixed_string_t ethertype;
10588         uint16_t ethertype_value;
10589         cmdline_fixed_string_t drop;
10590         cmdline_fixed_string_t queue;
10591         uint16_t  queue_id;
10592 };
10593
10594 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10595         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10596                                  filter, "ethertype_filter");
10597 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10598         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10599                               port_id, UINT16);
10600 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10601         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10602                                  ops, "add#del");
10603 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10604         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10605                                  mac, "mac_addr#mac_ignr");
10606 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10607         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10608                                      mac_addr);
10609 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10610         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10611                                  ethertype, "ethertype");
10612 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10613         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10614                               ethertype_value, UINT16);
10615 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10616         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10617                                  drop, "drop#fwd");
10618 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10619         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10620                                  queue, "queue");
10621 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10622         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10623                               queue_id, UINT16);
10624
10625 static void
10626 cmd_ethertype_filter_parsed(void *parsed_result,
10627                           __attribute__((unused)) struct cmdline *cl,
10628                           __attribute__((unused)) void *data)
10629 {
10630         struct cmd_ethertype_filter_result *res = parsed_result;
10631         struct rte_eth_ethertype_filter filter;
10632         int ret = 0;
10633
10634         ret = rte_eth_dev_filter_supported(res->port_id,
10635                         RTE_ETH_FILTER_ETHERTYPE);
10636         if (ret < 0) {
10637                 printf("ethertype filter is not supported on port %u.\n",
10638                         res->port_id);
10639                 return;
10640         }
10641
10642         memset(&filter, 0, sizeof(filter));
10643         if (!strcmp(res->mac, "mac_addr")) {
10644                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10645                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10646                         sizeof(struct rte_ether_addr));
10647         }
10648         if (!strcmp(res->drop, "drop"))
10649                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10650         filter.ether_type = res->ethertype_value;
10651         filter.queue = res->queue_id;
10652
10653         if (!strcmp(res->ops, "add"))
10654                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10655                                 RTE_ETH_FILTER_ETHERTYPE,
10656                                 RTE_ETH_FILTER_ADD,
10657                                 &filter);
10658         else
10659                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10660                                 RTE_ETH_FILTER_ETHERTYPE,
10661                                 RTE_ETH_FILTER_DELETE,
10662                                 &filter);
10663         if (ret < 0)
10664                 printf("ethertype filter programming error: (%s)\n",
10665                         strerror(-ret));
10666 }
10667
10668 cmdline_parse_inst_t cmd_ethertype_filter = {
10669         .f = cmd_ethertype_filter_parsed,
10670         .data = NULL,
10671         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10672                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10673                 "Add or delete an ethertype filter entry",
10674         .tokens = {
10675                 (void *)&cmd_ethertype_filter_filter,
10676                 (void *)&cmd_ethertype_filter_port_id,
10677                 (void *)&cmd_ethertype_filter_ops,
10678                 (void *)&cmd_ethertype_filter_mac,
10679                 (void *)&cmd_ethertype_filter_mac_addr,
10680                 (void *)&cmd_ethertype_filter_ethertype,
10681                 (void *)&cmd_ethertype_filter_ethertype_value,
10682                 (void *)&cmd_ethertype_filter_drop,
10683                 (void *)&cmd_ethertype_filter_queue,
10684                 (void *)&cmd_ethertype_filter_queue_id,
10685                 NULL,
10686         },
10687 };
10688
10689 /* *** deal with flow director filter *** */
10690 struct cmd_flow_director_result {
10691         cmdline_fixed_string_t flow_director_filter;
10692         portid_t port_id;
10693         cmdline_fixed_string_t mode;
10694         cmdline_fixed_string_t mode_value;
10695         cmdline_fixed_string_t ops;
10696         cmdline_fixed_string_t flow;
10697         cmdline_fixed_string_t flow_type;
10698         cmdline_fixed_string_t ether;
10699         uint16_t ether_type;
10700         cmdline_fixed_string_t src;
10701         cmdline_ipaddr_t ip_src;
10702         uint16_t port_src;
10703         cmdline_fixed_string_t dst;
10704         cmdline_ipaddr_t ip_dst;
10705         uint16_t port_dst;
10706         cmdline_fixed_string_t verify_tag;
10707         uint32_t verify_tag_value;
10708         cmdline_fixed_string_t tos;
10709         uint8_t tos_value;
10710         cmdline_fixed_string_t proto;
10711         uint8_t proto_value;
10712         cmdline_fixed_string_t ttl;
10713         uint8_t ttl_value;
10714         cmdline_fixed_string_t vlan;
10715         uint16_t vlan_value;
10716         cmdline_fixed_string_t flexbytes;
10717         cmdline_fixed_string_t flexbytes_value;
10718         cmdline_fixed_string_t pf_vf;
10719         cmdline_fixed_string_t drop;
10720         cmdline_fixed_string_t queue;
10721         uint16_t  queue_id;
10722         cmdline_fixed_string_t fd_id;
10723         uint32_t  fd_id_value;
10724         cmdline_fixed_string_t mac;
10725         struct rte_ether_addr mac_addr;
10726         cmdline_fixed_string_t tunnel;
10727         cmdline_fixed_string_t tunnel_type;
10728         cmdline_fixed_string_t tunnel_id;
10729         uint32_t tunnel_id_value;
10730         cmdline_fixed_string_t packet;
10731         char filepath[];
10732 };
10733
10734 static inline int
10735 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10736 {
10737         char s[256];
10738         const char *p, *p0 = q_arg;
10739         char *end;
10740         unsigned long int_fld;
10741         char *str_fld[max_num];
10742         int i;
10743         unsigned size;
10744         int ret = -1;
10745
10746         p = strchr(p0, '(');
10747         if (p == NULL)
10748                 return -1;
10749         ++p;
10750         p0 = strchr(p, ')');
10751         if (p0 == NULL)
10752                 return -1;
10753
10754         size = p0 - p;
10755         if (size >= sizeof(s))
10756                 return -1;
10757
10758         snprintf(s, sizeof(s), "%.*s", size, p);
10759         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10760         if (ret < 0 || ret > max_num)
10761                 return -1;
10762         for (i = 0; i < ret; i++) {
10763                 errno = 0;
10764                 int_fld = strtoul(str_fld[i], &end, 0);
10765                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10766                         return -1;
10767                 flexbytes[i] = (uint8_t)int_fld;
10768         }
10769         return ret;
10770 }
10771
10772 static uint16_t
10773 str2flowtype(char *string)
10774 {
10775         uint8_t i = 0;
10776         static const struct {
10777                 char str[32];
10778                 uint16_t type;
10779         } flowtype_str[] = {
10780                 {"raw", RTE_ETH_FLOW_RAW},
10781                 {"ipv4", RTE_ETH_FLOW_IPV4},
10782                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10783                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10784                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10785                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10786                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10787                 {"ipv6", RTE_ETH_FLOW_IPV6},
10788                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10789                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10790                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10791                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10792                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10793                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10794         };
10795
10796         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10797                 if (!strcmp(flowtype_str[i].str, string))
10798                         return flowtype_str[i].type;
10799         }
10800
10801         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10802                 return (uint16_t)atoi(string);
10803
10804         return RTE_ETH_FLOW_UNKNOWN;
10805 }
10806
10807 static enum rte_eth_fdir_tunnel_type
10808 str2fdir_tunneltype(char *string)
10809 {
10810         uint8_t i = 0;
10811
10812         static const struct {
10813                 char str[32];
10814                 enum rte_eth_fdir_tunnel_type type;
10815         } tunneltype_str[] = {
10816                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10817                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10818         };
10819
10820         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10821                 if (!strcmp(tunneltype_str[i].str, string))
10822                         return tunneltype_str[i].type;
10823         }
10824         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10825 }
10826
10827 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10828 do { \
10829         if ((ip_addr).family == AF_INET) \
10830                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10831         else { \
10832                 printf("invalid parameter.\n"); \
10833                 return; \
10834         } \
10835 } while (0)
10836
10837 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10838 do { \
10839         if ((ip_addr).family == AF_INET6) \
10840                 rte_memcpy(&(ip), \
10841                                  &((ip_addr).addr.ipv6), \
10842                                  sizeof(struct in6_addr)); \
10843         else { \
10844                 printf("invalid parameter.\n"); \
10845                 return; \
10846         } \
10847 } while (0)
10848
10849 static void
10850 cmd_flow_director_filter_parsed(void *parsed_result,
10851                           __attribute__((unused)) struct cmdline *cl,
10852                           __attribute__((unused)) void *data)
10853 {
10854         struct cmd_flow_director_result *res = parsed_result;
10855         struct rte_eth_fdir_filter entry;
10856         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10857         char *end;
10858         unsigned long vf_id;
10859         int ret = 0;
10860
10861         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10862         if (ret < 0) {
10863                 printf("flow director is not supported on port %u.\n",
10864                         res->port_id);
10865                 return;
10866         }
10867         memset(flexbytes, 0, sizeof(flexbytes));
10868         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10869
10870         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10871                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10872                         printf("Please set mode to MAC-VLAN.\n");
10873                         return;
10874                 }
10875         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10876                 if (strcmp(res->mode_value, "Tunnel")) {
10877                         printf("Please set mode to Tunnel.\n");
10878                         return;
10879                 }
10880         } else {
10881                 if (!strcmp(res->mode_value, "raw")) {
10882 #ifdef RTE_LIBRTE_I40E_PMD
10883                         struct rte_pmd_i40e_flow_type_mapping
10884                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10885                         struct rte_pmd_i40e_pkt_template_conf conf;
10886                         uint16_t flow_type = str2flowtype(res->flow_type);
10887                         uint16_t i, port = res->port_id;
10888                         uint8_t add;
10889
10890                         memset(&conf, 0, sizeof(conf));
10891
10892                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10893                                 printf("Invalid flow type specified.\n");
10894                                 return;
10895                         }
10896                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10897                                                                  mapping);
10898                         if (ret)
10899                                 return;
10900                         if (mapping[flow_type].pctype == 0ULL) {
10901                                 printf("Invalid flow type specified.\n");
10902                                 return;
10903                         }
10904                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10905                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10906                                         conf.input.pctype = i;
10907                                         break;
10908                                 }
10909                         }
10910
10911                         conf.input.packet = open_file(res->filepath,
10912                                                 &conf.input.length);
10913                         if (!conf.input.packet)
10914                                 return;
10915                         if (!strcmp(res->drop, "drop"))
10916                                 conf.action.behavior =
10917                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10918                         else
10919                                 conf.action.behavior =
10920                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10921                         conf.action.report_status =
10922                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10923                         conf.action.rx_queue = res->queue_id;
10924                         conf.soft_id = res->fd_id_value;
10925                         add  = strcmp(res->ops, "del") ? 1 : 0;
10926                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10927                                                                         &conf,
10928                                                                         add);
10929                         if (ret < 0)
10930                                 printf("flow director config error: (%s)\n",
10931                                        strerror(-ret));
10932                         close_file(conf.input.packet);
10933 #endif
10934                         return;
10935                 } else if (strcmp(res->mode_value, "IP")) {
10936                         printf("Please set mode to IP or raw.\n");
10937                         return;
10938                 }
10939                 entry.input.flow_type = str2flowtype(res->flow_type);
10940         }
10941
10942         ret = parse_flexbytes(res->flexbytes_value,
10943                                         flexbytes,
10944                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10945         if (ret < 0) {
10946                 printf("error: Cannot parse flexbytes input.\n");
10947                 return;
10948         }
10949
10950         switch (entry.input.flow_type) {
10951         case RTE_ETH_FLOW_FRAG_IPV4:
10952         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10953                 entry.input.flow.ip4_flow.proto = res->proto_value;
10954                 /* fall-through */
10955         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10956         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10957                 IPV4_ADDR_TO_UINT(res->ip_dst,
10958                         entry.input.flow.ip4_flow.dst_ip);
10959                 IPV4_ADDR_TO_UINT(res->ip_src,
10960                         entry.input.flow.ip4_flow.src_ip);
10961                 entry.input.flow.ip4_flow.tos = res->tos_value;
10962                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10963                 /* need convert to big endian. */
10964                 entry.input.flow.udp4_flow.dst_port =
10965                                 rte_cpu_to_be_16(res->port_dst);
10966                 entry.input.flow.udp4_flow.src_port =
10967                                 rte_cpu_to_be_16(res->port_src);
10968                 break;
10969         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10970                 IPV4_ADDR_TO_UINT(res->ip_dst,
10971                         entry.input.flow.sctp4_flow.ip.dst_ip);
10972                 IPV4_ADDR_TO_UINT(res->ip_src,
10973                         entry.input.flow.sctp4_flow.ip.src_ip);
10974                 entry.input.flow.ip4_flow.tos = res->tos_value;
10975                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10976                 /* need convert to big endian. */
10977                 entry.input.flow.sctp4_flow.dst_port =
10978                                 rte_cpu_to_be_16(res->port_dst);
10979                 entry.input.flow.sctp4_flow.src_port =
10980                                 rte_cpu_to_be_16(res->port_src);
10981                 entry.input.flow.sctp4_flow.verify_tag =
10982                                 rte_cpu_to_be_32(res->verify_tag_value);
10983                 break;
10984         case RTE_ETH_FLOW_FRAG_IPV6:
10985         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10986                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10987                 /* fall-through */
10988         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10989         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10990                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10991                         entry.input.flow.ipv6_flow.dst_ip);
10992                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10993                         entry.input.flow.ipv6_flow.src_ip);
10994                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10995                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10996                 /* need convert to big endian. */
10997                 entry.input.flow.udp6_flow.dst_port =
10998                                 rte_cpu_to_be_16(res->port_dst);
10999                 entry.input.flow.udp6_flow.src_port =
11000                                 rte_cpu_to_be_16(res->port_src);
11001                 break;
11002         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11003                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11004                         entry.input.flow.sctp6_flow.ip.dst_ip);
11005                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11006                         entry.input.flow.sctp6_flow.ip.src_ip);
11007                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11008                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11009                 /* need convert to big endian. */
11010                 entry.input.flow.sctp6_flow.dst_port =
11011                                 rte_cpu_to_be_16(res->port_dst);
11012                 entry.input.flow.sctp6_flow.src_port =
11013                                 rte_cpu_to_be_16(res->port_src);
11014                 entry.input.flow.sctp6_flow.verify_tag =
11015                                 rte_cpu_to_be_32(res->verify_tag_value);
11016                 break;
11017         case RTE_ETH_FLOW_L2_PAYLOAD:
11018                 entry.input.flow.l2_flow.ether_type =
11019                         rte_cpu_to_be_16(res->ether_type);
11020                 break;
11021         default:
11022                 break;
11023         }
11024
11025         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11026                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11027                                  &res->mac_addr,
11028                                  sizeof(struct rte_ether_addr));
11029
11030         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11031                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11032                                  &res->mac_addr,
11033                                  sizeof(struct rte_ether_addr));
11034                 entry.input.flow.tunnel_flow.tunnel_type =
11035                         str2fdir_tunneltype(res->tunnel_type);
11036                 entry.input.flow.tunnel_flow.tunnel_id =
11037                         rte_cpu_to_be_32(res->tunnel_id_value);
11038         }
11039
11040         rte_memcpy(entry.input.flow_ext.flexbytes,
11041                    flexbytes,
11042                    RTE_ETH_FDIR_MAX_FLEXLEN);
11043
11044         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11045
11046         entry.action.flex_off = 0;  /*use 0 by default */
11047         if (!strcmp(res->drop, "drop"))
11048                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11049         else
11050                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11051
11052         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11053             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11054                 if (!strcmp(res->pf_vf, "pf"))
11055                         entry.input.flow_ext.is_vf = 0;
11056                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11057                         struct rte_eth_dev_info dev_info;
11058
11059                         memset(&dev_info, 0, sizeof(dev_info));
11060                         rte_eth_dev_info_get(res->port_id, &dev_info);
11061                         errno = 0;
11062                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11063                         if (errno != 0 || *end != '\0' ||
11064                             vf_id >= dev_info.max_vfs) {
11065                                 printf("invalid parameter %s.\n", res->pf_vf);
11066                                 return;
11067                         }
11068                         entry.input.flow_ext.is_vf = 1;
11069                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11070                 } else {
11071                         printf("invalid parameter %s.\n", res->pf_vf);
11072                         return;
11073                 }
11074         }
11075
11076         /* set to report FD ID by default */
11077         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11078         entry.action.rx_queue = res->queue_id;
11079         entry.soft_id = res->fd_id_value;
11080         if (!strcmp(res->ops, "add"))
11081                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11082                                              RTE_ETH_FILTER_ADD, &entry);
11083         else if (!strcmp(res->ops, "del"))
11084                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11085                                              RTE_ETH_FILTER_DELETE, &entry);
11086         else
11087                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11088                                              RTE_ETH_FILTER_UPDATE, &entry);
11089         if (ret < 0)
11090                 printf("flow director programming error: (%s)\n",
11091                         strerror(-ret));
11092 }
11093
11094 cmdline_parse_token_string_t cmd_flow_director_filter =
11095         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11096                                  flow_director_filter, "flow_director_filter");
11097 cmdline_parse_token_num_t cmd_flow_director_port_id =
11098         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11099                               port_id, UINT16);
11100 cmdline_parse_token_string_t cmd_flow_director_ops =
11101         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11102                                  ops, "add#del#update");
11103 cmdline_parse_token_string_t cmd_flow_director_flow =
11104         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11105                                  flow, "flow");
11106 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11107         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11108                 flow_type, NULL);
11109 cmdline_parse_token_string_t cmd_flow_director_ether =
11110         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11111                                  ether, "ether");
11112 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11113         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11114                               ether_type, UINT16);
11115 cmdline_parse_token_string_t cmd_flow_director_src =
11116         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11117                                  src, "src");
11118 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11119         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11120                                  ip_src);
11121 cmdline_parse_token_num_t cmd_flow_director_port_src =
11122         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11123                               port_src, UINT16);
11124 cmdline_parse_token_string_t cmd_flow_director_dst =
11125         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11126                                  dst, "dst");
11127 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11128         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11129                                  ip_dst);
11130 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11131         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11132                               port_dst, UINT16);
11133 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11134         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11135                                   verify_tag, "verify_tag");
11136 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11137         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11138                               verify_tag_value, UINT32);
11139 cmdline_parse_token_string_t cmd_flow_director_tos =
11140         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11141                                  tos, "tos");
11142 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11143         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11144                               tos_value, UINT8);
11145 cmdline_parse_token_string_t cmd_flow_director_proto =
11146         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11147                                  proto, "proto");
11148 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11149         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11150                               proto_value, UINT8);
11151 cmdline_parse_token_string_t cmd_flow_director_ttl =
11152         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11153                                  ttl, "ttl");
11154 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11155         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11156                               ttl_value, UINT8);
11157 cmdline_parse_token_string_t cmd_flow_director_vlan =
11158         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11159                                  vlan, "vlan");
11160 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11161         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11162                               vlan_value, UINT16);
11163 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11164         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11165                                  flexbytes, "flexbytes");
11166 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11167         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11168                               flexbytes_value, NULL);
11169 cmdline_parse_token_string_t cmd_flow_director_drop =
11170         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11171                                  drop, "drop#fwd");
11172 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11173         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11174                               pf_vf, NULL);
11175 cmdline_parse_token_string_t cmd_flow_director_queue =
11176         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11177                                  queue, "queue");
11178 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11179         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11180                               queue_id, UINT16);
11181 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11182         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11183                                  fd_id, "fd_id");
11184 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11185         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11186                               fd_id_value, UINT32);
11187
11188 cmdline_parse_token_string_t cmd_flow_director_mode =
11189         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11190                                  mode, "mode");
11191 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11192         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11193                                  mode_value, "IP");
11194 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11195         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11196                                  mode_value, "MAC-VLAN");
11197 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11198         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11199                                  mode_value, "Tunnel");
11200 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11201         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11202                                  mode_value, "raw");
11203 cmdline_parse_token_string_t cmd_flow_director_mac =
11204         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11205                                  mac, "mac");
11206 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11207         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11208                                     mac_addr);
11209 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11210         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11211                                  tunnel, "tunnel");
11212 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11213         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11214                                  tunnel_type, "NVGRE#VxLAN");
11215 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11216         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11217                                  tunnel_id, "tunnel-id");
11218 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11219         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11220                               tunnel_id_value, UINT32);
11221 cmdline_parse_token_string_t cmd_flow_director_packet =
11222         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11223                                  packet, "packet");
11224 cmdline_parse_token_string_t cmd_flow_director_filepath =
11225         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11226                                  filepath, NULL);
11227
11228 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11229         .f = cmd_flow_director_filter_parsed,
11230         .data = NULL,
11231         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11232                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11233                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11234                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11235                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11236                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11237                 "fd_id <fd_id_value>: "
11238                 "Add or delete an ip flow director entry on NIC",
11239         .tokens = {
11240                 (void *)&cmd_flow_director_filter,
11241                 (void *)&cmd_flow_director_port_id,
11242                 (void *)&cmd_flow_director_mode,
11243                 (void *)&cmd_flow_director_mode_ip,
11244                 (void *)&cmd_flow_director_ops,
11245                 (void *)&cmd_flow_director_flow,
11246                 (void *)&cmd_flow_director_flow_type,
11247                 (void *)&cmd_flow_director_src,
11248                 (void *)&cmd_flow_director_ip_src,
11249                 (void *)&cmd_flow_director_dst,
11250                 (void *)&cmd_flow_director_ip_dst,
11251                 (void *)&cmd_flow_director_tos,
11252                 (void *)&cmd_flow_director_tos_value,
11253                 (void *)&cmd_flow_director_proto,
11254                 (void *)&cmd_flow_director_proto_value,
11255                 (void *)&cmd_flow_director_ttl,
11256                 (void *)&cmd_flow_director_ttl_value,
11257                 (void *)&cmd_flow_director_vlan,
11258                 (void *)&cmd_flow_director_vlan_value,
11259                 (void *)&cmd_flow_director_flexbytes,
11260                 (void *)&cmd_flow_director_flexbytes_value,
11261                 (void *)&cmd_flow_director_drop,
11262                 (void *)&cmd_flow_director_pf_vf,
11263                 (void *)&cmd_flow_director_queue,
11264                 (void *)&cmd_flow_director_queue_id,
11265                 (void *)&cmd_flow_director_fd_id,
11266                 (void *)&cmd_flow_director_fd_id_value,
11267                 NULL,
11268         },
11269 };
11270
11271 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11272         .f = cmd_flow_director_filter_parsed,
11273         .data = NULL,
11274         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11275                 "director entry on NIC",
11276         .tokens = {
11277                 (void *)&cmd_flow_director_filter,
11278                 (void *)&cmd_flow_director_port_id,
11279                 (void *)&cmd_flow_director_mode,
11280                 (void *)&cmd_flow_director_mode_ip,
11281                 (void *)&cmd_flow_director_ops,
11282                 (void *)&cmd_flow_director_flow,
11283                 (void *)&cmd_flow_director_flow_type,
11284                 (void *)&cmd_flow_director_src,
11285                 (void *)&cmd_flow_director_ip_src,
11286                 (void *)&cmd_flow_director_port_src,
11287                 (void *)&cmd_flow_director_dst,
11288                 (void *)&cmd_flow_director_ip_dst,
11289                 (void *)&cmd_flow_director_port_dst,
11290                 (void *)&cmd_flow_director_tos,
11291                 (void *)&cmd_flow_director_tos_value,
11292                 (void *)&cmd_flow_director_ttl,
11293                 (void *)&cmd_flow_director_ttl_value,
11294                 (void *)&cmd_flow_director_vlan,
11295                 (void *)&cmd_flow_director_vlan_value,
11296                 (void *)&cmd_flow_director_flexbytes,
11297                 (void *)&cmd_flow_director_flexbytes_value,
11298                 (void *)&cmd_flow_director_drop,
11299                 (void *)&cmd_flow_director_pf_vf,
11300                 (void *)&cmd_flow_director_queue,
11301                 (void *)&cmd_flow_director_queue_id,
11302                 (void *)&cmd_flow_director_fd_id,
11303                 (void *)&cmd_flow_director_fd_id_value,
11304                 NULL,
11305         },
11306 };
11307
11308 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11309         .f = cmd_flow_director_filter_parsed,
11310         .data = NULL,
11311         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11312                 "director entry on NIC",
11313         .tokens = {
11314                 (void *)&cmd_flow_director_filter,
11315                 (void *)&cmd_flow_director_port_id,
11316                 (void *)&cmd_flow_director_mode,
11317                 (void *)&cmd_flow_director_mode_ip,
11318                 (void *)&cmd_flow_director_ops,
11319                 (void *)&cmd_flow_director_flow,
11320                 (void *)&cmd_flow_director_flow_type,
11321                 (void *)&cmd_flow_director_src,
11322                 (void *)&cmd_flow_director_ip_src,
11323                 (void *)&cmd_flow_director_port_src,
11324                 (void *)&cmd_flow_director_dst,
11325                 (void *)&cmd_flow_director_ip_dst,
11326                 (void *)&cmd_flow_director_port_dst,
11327                 (void *)&cmd_flow_director_verify_tag,
11328                 (void *)&cmd_flow_director_verify_tag_value,
11329                 (void *)&cmd_flow_director_tos,
11330                 (void *)&cmd_flow_director_tos_value,
11331                 (void *)&cmd_flow_director_ttl,
11332                 (void *)&cmd_flow_director_ttl_value,
11333                 (void *)&cmd_flow_director_vlan,
11334                 (void *)&cmd_flow_director_vlan_value,
11335                 (void *)&cmd_flow_director_flexbytes,
11336                 (void *)&cmd_flow_director_flexbytes_value,
11337                 (void *)&cmd_flow_director_drop,
11338                 (void *)&cmd_flow_director_pf_vf,
11339                 (void *)&cmd_flow_director_queue,
11340                 (void *)&cmd_flow_director_queue_id,
11341                 (void *)&cmd_flow_director_fd_id,
11342                 (void *)&cmd_flow_director_fd_id_value,
11343                 NULL,
11344         },
11345 };
11346
11347 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11348         .f = cmd_flow_director_filter_parsed,
11349         .data = NULL,
11350         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11351                 "director entry on NIC",
11352         .tokens = {
11353                 (void *)&cmd_flow_director_filter,
11354                 (void *)&cmd_flow_director_port_id,
11355                 (void *)&cmd_flow_director_mode,
11356                 (void *)&cmd_flow_director_mode_ip,
11357                 (void *)&cmd_flow_director_ops,
11358                 (void *)&cmd_flow_director_flow,
11359                 (void *)&cmd_flow_director_flow_type,
11360                 (void *)&cmd_flow_director_ether,
11361                 (void *)&cmd_flow_director_ether_type,
11362                 (void *)&cmd_flow_director_flexbytes,
11363                 (void *)&cmd_flow_director_flexbytes_value,
11364                 (void *)&cmd_flow_director_drop,
11365                 (void *)&cmd_flow_director_pf_vf,
11366                 (void *)&cmd_flow_director_queue,
11367                 (void *)&cmd_flow_director_queue_id,
11368                 (void *)&cmd_flow_director_fd_id,
11369                 (void *)&cmd_flow_director_fd_id_value,
11370                 NULL,
11371         },
11372 };
11373
11374 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11375         .f = cmd_flow_director_filter_parsed,
11376         .data = NULL,
11377         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11378                 "director entry on NIC",
11379         .tokens = {
11380                 (void *)&cmd_flow_director_filter,
11381                 (void *)&cmd_flow_director_port_id,
11382                 (void *)&cmd_flow_director_mode,
11383                 (void *)&cmd_flow_director_mode_mac_vlan,
11384                 (void *)&cmd_flow_director_ops,
11385                 (void *)&cmd_flow_director_mac,
11386                 (void *)&cmd_flow_director_mac_addr,
11387                 (void *)&cmd_flow_director_vlan,
11388                 (void *)&cmd_flow_director_vlan_value,
11389                 (void *)&cmd_flow_director_flexbytes,
11390                 (void *)&cmd_flow_director_flexbytes_value,
11391                 (void *)&cmd_flow_director_drop,
11392                 (void *)&cmd_flow_director_queue,
11393                 (void *)&cmd_flow_director_queue_id,
11394                 (void *)&cmd_flow_director_fd_id,
11395                 (void *)&cmd_flow_director_fd_id_value,
11396                 NULL,
11397         },
11398 };
11399
11400 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11401         .f = cmd_flow_director_filter_parsed,
11402         .data = NULL,
11403         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11404                 "director entry on NIC",
11405         .tokens = {
11406                 (void *)&cmd_flow_director_filter,
11407                 (void *)&cmd_flow_director_port_id,
11408                 (void *)&cmd_flow_director_mode,
11409                 (void *)&cmd_flow_director_mode_tunnel,
11410                 (void *)&cmd_flow_director_ops,
11411                 (void *)&cmd_flow_director_mac,
11412                 (void *)&cmd_flow_director_mac_addr,
11413                 (void *)&cmd_flow_director_vlan,
11414                 (void *)&cmd_flow_director_vlan_value,
11415                 (void *)&cmd_flow_director_tunnel,
11416                 (void *)&cmd_flow_director_tunnel_type,
11417                 (void *)&cmd_flow_director_tunnel_id,
11418                 (void *)&cmd_flow_director_tunnel_id_value,
11419                 (void *)&cmd_flow_director_flexbytes,
11420                 (void *)&cmd_flow_director_flexbytes_value,
11421                 (void *)&cmd_flow_director_drop,
11422                 (void *)&cmd_flow_director_queue,
11423                 (void *)&cmd_flow_director_queue_id,
11424                 (void *)&cmd_flow_director_fd_id,
11425                 (void *)&cmd_flow_director_fd_id_value,
11426                 NULL,
11427         },
11428 };
11429
11430 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11431         .f = cmd_flow_director_filter_parsed,
11432         .data = NULL,
11433         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11434                 "director entry on NIC",
11435         .tokens = {
11436                 (void *)&cmd_flow_director_filter,
11437                 (void *)&cmd_flow_director_port_id,
11438                 (void *)&cmd_flow_director_mode,
11439                 (void *)&cmd_flow_director_mode_raw,
11440                 (void *)&cmd_flow_director_ops,
11441                 (void *)&cmd_flow_director_flow,
11442                 (void *)&cmd_flow_director_flow_type,
11443                 (void *)&cmd_flow_director_drop,
11444                 (void *)&cmd_flow_director_queue,
11445                 (void *)&cmd_flow_director_queue_id,
11446                 (void *)&cmd_flow_director_fd_id,
11447                 (void *)&cmd_flow_director_fd_id_value,
11448                 (void *)&cmd_flow_director_packet,
11449                 (void *)&cmd_flow_director_filepath,
11450                 NULL,
11451         },
11452 };
11453
11454 struct cmd_flush_flow_director_result {
11455         cmdline_fixed_string_t flush_flow_director;
11456         portid_t port_id;
11457 };
11458
11459 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11460         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11461                                  flush_flow_director, "flush_flow_director");
11462 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11463         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11464                               port_id, UINT16);
11465
11466 static void
11467 cmd_flush_flow_director_parsed(void *parsed_result,
11468                           __attribute__((unused)) struct cmdline *cl,
11469                           __attribute__((unused)) void *data)
11470 {
11471         struct cmd_flow_director_result *res = parsed_result;
11472         int ret = 0;
11473
11474         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11475         if (ret < 0) {
11476                 printf("flow director is not supported on port %u.\n",
11477                         res->port_id);
11478                 return;
11479         }
11480
11481         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11482                         RTE_ETH_FILTER_FLUSH, NULL);
11483         if (ret < 0)
11484                 printf("flow director table flushing error: (%s)\n",
11485                         strerror(-ret));
11486 }
11487
11488 cmdline_parse_inst_t cmd_flush_flow_director = {
11489         .f = cmd_flush_flow_director_parsed,
11490         .data = NULL,
11491         .help_str = "flush_flow_director <port_id>: "
11492                 "Flush all flow director entries of a device on NIC",
11493         .tokens = {
11494                 (void *)&cmd_flush_flow_director_flush,
11495                 (void *)&cmd_flush_flow_director_port_id,
11496                 NULL,
11497         },
11498 };
11499
11500 /* *** deal with flow director mask *** */
11501 struct cmd_flow_director_mask_result {
11502         cmdline_fixed_string_t flow_director_mask;
11503         portid_t port_id;
11504         cmdline_fixed_string_t mode;
11505         cmdline_fixed_string_t mode_value;
11506         cmdline_fixed_string_t vlan;
11507         uint16_t vlan_mask;
11508         cmdline_fixed_string_t src_mask;
11509         cmdline_ipaddr_t ipv4_src;
11510         cmdline_ipaddr_t ipv6_src;
11511         uint16_t port_src;
11512         cmdline_fixed_string_t dst_mask;
11513         cmdline_ipaddr_t ipv4_dst;
11514         cmdline_ipaddr_t ipv6_dst;
11515         uint16_t port_dst;
11516         cmdline_fixed_string_t mac;
11517         uint8_t mac_addr_byte_mask;
11518         cmdline_fixed_string_t tunnel_id;
11519         uint32_t tunnel_id_mask;
11520         cmdline_fixed_string_t tunnel_type;
11521         uint8_t tunnel_type_mask;
11522 };
11523
11524 static void
11525 cmd_flow_director_mask_parsed(void *parsed_result,
11526                           __attribute__((unused)) struct cmdline *cl,
11527                           __attribute__((unused)) void *data)
11528 {
11529         struct cmd_flow_director_mask_result *res = parsed_result;
11530         struct rte_eth_fdir_masks *mask;
11531         struct rte_port *port;
11532
11533         port = &ports[res->port_id];
11534         /** Check if the port is not started **/
11535         if (port->port_status != RTE_PORT_STOPPED) {
11536                 printf("Please stop port %d first\n", res->port_id);
11537                 return;
11538         }
11539
11540         mask = &port->dev_conf.fdir_conf.mask;
11541
11542         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11543                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11544                         printf("Please set mode to MAC-VLAN.\n");
11545                         return;
11546                 }
11547
11548                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11549         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11550                 if (strcmp(res->mode_value, "Tunnel")) {
11551                         printf("Please set mode to Tunnel.\n");
11552                         return;
11553                 }
11554
11555                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11556                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11557                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11558                 mask->tunnel_type_mask = res->tunnel_type_mask;
11559         } else {
11560                 if (strcmp(res->mode_value, "IP")) {
11561                         printf("Please set mode to IP.\n");
11562                         return;
11563                 }
11564
11565                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11566                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11567                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11568                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11569                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11570                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11571                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11572         }
11573
11574         cmd_reconfig_device_queue(res->port_id, 1, 1);
11575 }
11576
11577 cmdline_parse_token_string_t cmd_flow_director_mask =
11578         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11579                                  flow_director_mask, "flow_director_mask");
11580 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11581         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11582                               port_id, UINT16);
11583 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11584         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11585                                  vlan, "vlan");
11586 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11587         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11588                               vlan_mask, UINT16);
11589 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11590         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11591                                  src_mask, "src_mask");
11592 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11593         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11594                                  ipv4_src);
11595 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11596         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11597                                  ipv6_src);
11598 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11599         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11600                               port_src, UINT16);
11601 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11602         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11603                                  dst_mask, "dst_mask");
11604 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11605         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11606                                  ipv4_dst);
11607 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11608         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11609                                  ipv6_dst);
11610 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11611         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11612                               port_dst, UINT16);
11613
11614 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11615         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11616                                  mode, "mode");
11617 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11618         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11619                                  mode_value, "IP");
11620 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11621         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11622                                  mode_value, "MAC-VLAN");
11623 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11624         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11625                                  mode_value, "Tunnel");
11626 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11627         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11628                                  mac, "mac");
11629 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11630         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11631                               mac_addr_byte_mask, UINT8);
11632 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11633         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11634                                  tunnel_type, "tunnel-type");
11635 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11636         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11637                               tunnel_type_mask, UINT8);
11638 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11639         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11640                                  tunnel_id, "tunnel-id");
11641 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11642         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11643                               tunnel_id_mask, UINT32);
11644
11645 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11646         .f = cmd_flow_director_mask_parsed,
11647         .data = NULL,
11648         .help_str = "flow_director_mask ... : "
11649                 "Set IP mode flow director's mask on NIC",
11650         .tokens = {
11651                 (void *)&cmd_flow_director_mask,
11652                 (void *)&cmd_flow_director_mask_port_id,
11653                 (void *)&cmd_flow_director_mask_mode,
11654                 (void *)&cmd_flow_director_mask_mode_ip,
11655                 (void *)&cmd_flow_director_mask_vlan,
11656                 (void *)&cmd_flow_director_mask_vlan_value,
11657                 (void *)&cmd_flow_director_mask_src,
11658                 (void *)&cmd_flow_director_mask_ipv4_src,
11659                 (void *)&cmd_flow_director_mask_ipv6_src,
11660                 (void *)&cmd_flow_director_mask_port_src,
11661                 (void *)&cmd_flow_director_mask_dst,
11662                 (void *)&cmd_flow_director_mask_ipv4_dst,
11663                 (void *)&cmd_flow_director_mask_ipv6_dst,
11664                 (void *)&cmd_flow_director_mask_port_dst,
11665                 NULL,
11666         },
11667 };
11668
11669 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11670         .f = cmd_flow_director_mask_parsed,
11671         .data = NULL,
11672         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11673                 "flow director's mask on NIC",
11674         .tokens = {
11675                 (void *)&cmd_flow_director_mask,
11676                 (void *)&cmd_flow_director_mask_port_id,
11677                 (void *)&cmd_flow_director_mask_mode,
11678                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11679                 (void *)&cmd_flow_director_mask_vlan,
11680                 (void *)&cmd_flow_director_mask_vlan_value,
11681                 NULL,
11682         },
11683 };
11684
11685 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11686         .f = cmd_flow_director_mask_parsed,
11687         .data = NULL,
11688         .help_str = "flow_director_mask ... : Set tunnel mode "
11689                 "flow director's mask on NIC",
11690         .tokens = {
11691                 (void *)&cmd_flow_director_mask,
11692                 (void *)&cmd_flow_director_mask_port_id,
11693                 (void *)&cmd_flow_director_mask_mode,
11694                 (void *)&cmd_flow_director_mask_mode_tunnel,
11695                 (void *)&cmd_flow_director_mask_vlan,
11696                 (void *)&cmd_flow_director_mask_vlan_value,
11697                 (void *)&cmd_flow_director_mask_mac,
11698                 (void *)&cmd_flow_director_mask_mac_value,
11699                 (void *)&cmd_flow_director_mask_tunnel_type,
11700                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11701                 (void *)&cmd_flow_director_mask_tunnel_id,
11702                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11703                 NULL,
11704         },
11705 };
11706
11707 /* *** deal with flow director mask on flexible payload *** */
11708 struct cmd_flow_director_flex_mask_result {
11709         cmdline_fixed_string_t flow_director_flexmask;
11710         portid_t port_id;
11711         cmdline_fixed_string_t flow;
11712         cmdline_fixed_string_t flow_type;
11713         cmdline_fixed_string_t mask;
11714 };
11715
11716 static void
11717 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11718                           __attribute__((unused)) struct cmdline *cl,
11719                           __attribute__((unused)) void *data)
11720 {
11721         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11722         struct rte_eth_fdir_info fdir_info;
11723         struct rte_eth_fdir_flex_mask flex_mask;
11724         struct rte_port *port;
11725         uint64_t flow_type_mask;
11726         uint16_t i;
11727         int ret;
11728
11729         port = &ports[res->port_id];
11730         /** Check if the port is not started **/
11731         if (port->port_status != RTE_PORT_STOPPED) {
11732                 printf("Please stop port %d first\n", res->port_id);
11733                 return;
11734         }
11735
11736         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11737         ret = parse_flexbytes(res->mask,
11738                         flex_mask.mask,
11739                         RTE_ETH_FDIR_MAX_FLEXLEN);
11740         if (ret < 0) {
11741                 printf("error: Cannot parse mask input.\n");
11742                 return;
11743         }
11744
11745         memset(&fdir_info, 0, sizeof(fdir_info));
11746         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11747                                 RTE_ETH_FILTER_INFO, &fdir_info);
11748         if (ret < 0) {
11749                 printf("Cannot get FDir filter info\n");
11750                 return;
11751         }
11752
11753         if (!strcmp(res->flow_type, "none")) {
11754                 /* means don't specify the flow type */
11755                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11756                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11757                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11758                                0, sizeof(struct rte_eth_fdir_flex_mask));
11759                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11760                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11761                                  &flex_mask,
11762                                  sizeof(struct rte_eth_fdir_flex_mask));
11763                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11764                 return;
11765         }
11766         flow_type_mask = fdir_info.flow_types_mask[0];
11767         if (!strcmp(res->flow_type, "all")) {
11768                 if (!flow_type_mask) {
11769                         printf("No flow type supported\n");
11770                         return;
11771                 }
11772                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11773                         if (flow_type_mask & (1ULL << i)) {
11774                                 flex_mask.flow_type = i;
11775                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11776                         }
11777                 }
11778                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11779                 return;
11780         }
11781         flex_mask.flow_type = str2flowtype(res->flow_type);
11782         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11783                 printf("Flow type %s not supported on port %d\n",
11784                                 res->flow_type, res->port_id);
11785                 return;
11786         }
11787         fdir_set_flex_mask(res->port_id, &flex_mask);
11788         cmd_reconfig_device_queue(res->port_id, 1, 1);
11789 }
11790
11791 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11792         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11793                                  flow_director_flexmask,
11794                                  "flow_director_flex_mask");
11795 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11796         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11797                               port_id, UINT16);
11798 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11799         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11800                                  flow, "flow");
11801 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11802         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11803                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11804                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11805 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11806         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11807                                  mask, NULL);
11808
11809 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11810         .f = cmd_flow_director_flex_mask_parsed,
11811         .data = NULL,
11812         .help_str = "flow_director_flex_mask ... : "
11813                 "Set flow director's flex mask on NIC",
11814         .tokens = {
11815                 (void *)&cmd_flow_director_flexmask,
11816                 (void *)&cmd_flow_director_flexmask_port_id,
11817                 (void *)&cmd_flow_director_flexmask_flow,
11818                 (void *)&cmd_flow_director_flexmask_flow_type,
11819                 (void *)&cmd_flow_director_flexmask_mask,
11820                 NULL,
11821         },
11822 };
11823
11824 /* *** deal with flow director flexible payload configuration *** */
11825 struct cmd_flow_director_flexpayload_result {
11826         cmdline_fixed_string_t flow_director_flexpayload;
11827         portid_t port_id;
11828         cmdline_fixed_string_t payload_layer;
11829         cmdline_fixed_string_t payload_cfg;
11830 };
11831
11832 static inline int
11833 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11834 {
11835         char s[256];
11836         const char *p, *p0 = q_arg;
11837         char *end;
11838         unsigned long int_fld;
11839         char *str_fld[max_num];
11840         int i;
11841         unsigned size;
11842         int ret = -1;
11843
11844         p = strchr(p0, '(');
11845         if (p == NULL)
11846                 return -1;
11847         ++p;
11848         p0 = strchr(p, ')');
11849         if (p0 == NULL)
11850                 return -1;
11851
11852         size = p0 - p;
11853         if (size >= sizeof(s))
11854                 return -1;
11855
11856         snprintf(s, sizeof(s), "%.*s", size, p);
11857         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11858         if (ret < 0 || ret > max_num)
11859                 return -1;
11860         for (i = 0; i < ret; i++) {
11861                 errno = 0;
11862                 int_fld = strtoul(str_fld[i], &end, 0);
11863                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11864                         return -1;
11865                 offsets[i] = (uint16_t)int_fld;
11866         }
11867         return ret;
11868 }
11869
11870 static void
11871 cmd_flow_director_flxpld_parsed(void *parsed_result,
11872                           __attribute__((unused)) struct cmdline *cl,
11873                           __attribute__((unused)) void *data)
11874 {
11875         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11876         struct rte_eth_flex_payload_cfg flex_cfg;
11877         struct rte_port *port;
11878         int ret = 0;
11879
11880         port = &ports[res->port_id];
11881         /** Check if the port is not started **/
11882         if (port->port_status != RTE_PORT_STOPPED) {
11883                 printf("Please stop port %d first\n", res->port_id);
11884                 return;
11885         }
11886
11887         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11888
11889         if (!strcmp(res->payload_layer, "raw"))
11890                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11891         else if (!strcmp(res->payload_layer, "l2"))
11892                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11893         else if (!strcmp(res->payload_layer, "l3"))
11894                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11895         else if (!strcmp(res->payload_layer, "l4"))
11896                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11897
11898         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11899                             RTE_ETH_FDIR_MAX_FLEXLEN);
11900         if (ret < 0) {
11901                 printf("error: Cannot parse flex payload input.\n");
11902                 return;
11903         }
11904
11905         fdir_set_flex_payload(res->port_id, &flex_cfg);
11906         cmd_reconfig_device_queue(res->port_id, 1, 1);
11907 }
11908
11909 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11910         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11911                                  flow_director_flexpayload,
11912                                  "flow_director_flex_payload");
11913 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11914         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11915                               port_id, UINT16);
11916 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11917         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11918                                  payload_layer, "raw#l2#l3#l4");
11919 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11920         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11921                                  payload_cfg, NULL);
11922
11923 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11924         .f = cmd_flow_director_flxpld_parsed,
11925         .data = NULL,
11926         .help_str = "flow_director_flexpayload ... : "
11927                 "Set flow director's flex payload on NIC",
11928         .tokens = {
11929                 (void *)&cmd_flow_director_flexpayload,
11930                 (void *)&cmd_flow_director_flexpayload_port_id,
11931                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11932                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11933                 NULL,
11934         },
11935 };
11936
11937 /* Generic flow interface command. */
11938 extern cmdline_parse_inst_t cmd_flow;
11939
11940 /* *** Classification Filters Control *** */
11941 /* *** Get symmetric hash enable per port *** */
11942 struct cmd_get_sym_hash_ena_per_port_result {
11943         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11944         portid_t port_id;
11945 };
11946
11947 static void
11948 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11949                                  __rte_unused struct cmdline *cl,
11950                                  __rte_unused void *data)
11951 {
11952         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11953         struct rte_eth_hash_filter_info info;
11954         int ret;
11955
11956         if (rte_eth_dev_filter_supported(res->port_id,
11957                                 RTE_ETH_FILTER_HASH) < 0) {
11958                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11959                                                         res->port_id);
11960                 return;
11961         }
11962
11963         memset(&info, 0, sizeof(info));
11964         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11965         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11966                                                 RTE_ETH_FILTER_GET, &info);
11967
11968         if (ret < 0) {
11969                 printf("Cannot get symmetric hash enable per port "
11970                                         "on port %u\n", res->port_id);
11971                 return;
11972         }
11973
11974         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11975                                 "enabled" : "disabled", res->port_id);
11976 }
11977
11978 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11979         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11980                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11981 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11982         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11983                 port_id, UINT16);
11984
11985 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11986         .f = cmd_get_sym_hash_per_port_parsed,
11987         .data = NULL,
11988         .help_str = "get_sym_hash_ena_per_port <port_id>",
11989         .tokens = {
11990                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11991                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11992                 NULL,
11993         },
11994 };
11995
11996 /* *** Set symmetric hash enable per port *** */
11997 struct cmd_set_sym_hash_ena_per_port_result {
11998         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11999         cmdline_fixed_string_t enable;
12000         portid_t port_id;
12001 };
12002
12003 static void
12004 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12005                                  __rte_unused struct cmdline *cl,
12006                                  __rte_unused void *data)
12007 {
12008         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12009         struct rte_eth_hash_filter_info info;
12010         int ret;
12011
12012         if (rte_eth_dev_filter_supported(res->port_id,
12013                                 RTE_ETH_FILTER_HASH) < 0) {
12014                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12015                                                         res->port_id);
12016                 return;
12017         }
12018
12019         memset(&info, 0, sizeof(info));
12020         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12021         if (!strcmp(res->enable, "enable"))
12022                 info.info.enable = 1;
12023         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12024                                         RTE_ETH_FILTER_SET, &info);
12025         if (ret < 0) {
12026                 printf("Cannot set symmetric hash enable per port on "
12027                                         "port %u\n", res->port_id);
12028                 return;
12029         }
12030         printf("Symmetric hash has been set to %s on port %u\n",
12031                                         res->enable, res->port_id);
12032 }
12033
12034 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12035         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12036                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12037 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12038         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12039                 port_id, UINT16);
12040 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12041         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12042                 enable, "enable#disable");
12043
12044 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12045         .f = cmd_set_sym_hash_per_port_parsed,
12046         .data = NULL,
12047         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12048         .tokens = {
12049                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12050                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12051                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12052                 NULL,
12053         },
12054 };
12055
12056 /* Get global config of hash function */
12057 struct cmd_get_hash_global_config_result {
12058         cmdline_fixed_string_t get_hash_global_config;
12059         portid_t port_id;
12060 };
12061
12062 static char *
12063 flowtype_to_str(uint16_t ftype)
12064 {
12065         uint16_t i;
12066         static struct {
12067                 char str[16];
12068                 uint16_t ftype;
12069         } ftype_table[] = {
12070                 {"ipv4", RTE_ETH_FLOW_IPV4},
12071                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12072                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12073                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12074                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12075                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12076                 {"ipv6", RTE_ETH_FLOW_IPV6},
12077                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12078                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12079                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12080                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12081                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12082                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12083                 {"port", RTE_ETH_FLOW_PORT},
12084                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12085                 {"geneve", RTE_ETH_FLOW_GENEVE},
12086                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12087                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12088         };
12089
12090         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12091                 if (ftype_table[i].ftype == ftype)
12092                         return ftype_table[i].str;
12093         }
12094
12095         return NULL;
12096 }
12097
12098 static void
12099 cmd_get_hash_global_config_parsed(void *parsed_result,
12100                                   __rte_unused struct cmdline *cl,
12101                                   __rte_unused void *data)
12102 {
12103         struct cmd_get_hash_global_config_result *res = parsed_result;
12104         struct rte_eth_hash_filter_info info;
12105         uint32_t idx, offset;
12106         uint16_t i;
12107         char *str;
12108         int ret;
12109
12110         if (rte_eth_dev_filter_supported(res->port_id,
12111                         RTE_ETH_FILTER_HASH) < 0) {
12112                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12113                                                         res->port_id);
12114                 return;
12115         }
12116
12117         memset(&info, 0, sizeof(info));
12118         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12119         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12120                                         RTE_ETH_FILTER_GET, &info);
12121         if (ret < 0) {
12122                 printf("Cannot get hash global configurations by port %d\n",
12123                                                         res->port_id);
12124                 return;
12125         }
12126
12127         switch (info.info.global_conf.hash_func) {
12128         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12129                 printf("Hash function is Toeplitz\n");
12130                 break;
12131         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12132                 printf("Hash function is Simple XOR\n");
12133                 break;
12134         default:
12135                 printf("Unknown hash function\n");
12136                 break;
12137         }
12138
12139         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12140                 idx = i / UINT64_BIT;
12141                 offset = i % UINT64_BIT;
12142                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12143                                                 (1ULL << offset)))
12144                         continue;
12145                 str = flowtype_to_str(i);
12146                 if (!str)
12147                         continue;
12148                 printf("Symmetric hash is %s globally for flow type %s "
12149                                                         "by port %d\n",
12150                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12151                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12152                                                         res->port_id);
12153         }
12154 }
12155
12156 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12157         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12158                 get_hash_global_config, "get_hash_global_config");
12159 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12160         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12161                 port_id, UINT16);
12162
12163 cmdline_parse_inst_t cmd_get_hash_global_config = {
12164         .f = cmd_get_hash_global_config_parsed,
12165         .data = NULL,
12166         .help_str = "get_hash_global_config <port_id>",
12167         .tokens = {
12168                 (void *)&cmd_get_hash_global_config_all,
12169                 (void *)&cmd_get_hash_global_config_port_id,
12170                 NULL,
12171         },
12172 };
12173
12174 /* Set global config of hash function */
12175 struct cmd_set_hash_global_config_result {
12176         cmdline_fixed_string_t set_hash_global_config;
12177         portid_t port_id;
12178         cmdline_fixed_string_t hash_func;
12179         cmdline_fixed_string_t flow_type;
12180         cmdline_fixed_string_t enable;
12181 };
12182
12183 static void
12184 cmd_set_hash_global_config_parsed(void *parsed_result,
12185                                   __rte_unused struct cmdline *cl,
12186                                   __rte_unused void *data)
12187 {
12188         struct cmd_set_hash_global_config_result *res = parsed_result;
12189         struct rte_eth_hash_filter_info info;
12190         uint32_t ftype, idx, offset;
12191         int ret;
12192
12193         if (rte_eth_dev_filter_supported(res->port_id,
12194                                 RTE_ETH_FILTER_HASH) < 0) {
12195                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12196                                                         res->port_id);
12197                 return;
12198         }
12199         memset(&info, 0, sizeof(info));
12200         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12201         if (!strcmp(res->hash_func, "toeplitz"))
12202                 info.info.global_conf.hash_func =
12203                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12204         else if (!strcmp(res->hash_func, "simple_xor"))
12205                 info.info.global_conf.hash_func =
12206                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12207         else if (!strcmp(res->hash_func, "default"))
12208                 info.info.global_conf.hash_func =
12209                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12210
12211         ftype = str2flowtype(res->flow_type);
12212         idx = ftype / UINT64_BIT;
12213         offset = ftype % UINT64_BIT;
12214         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12215         if (!strcmp(res->enable, "enable"))
12216                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12217                                                 (1ULL << offset);
12218         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12219                                         RTE_ETH_FILTER_SET, &info);
12220         if (ret < 0)
12221                 printf("Cannot set global hash configurations by port %d\n",
12222                                                         res->port_id);
12223         else
12224                 printf("Global hash configurations have been set "
12225                         "successfully by port %d\n", res->port_id);
12226 }
12227
12228 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12229         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12230                 set_hash_global_config, "set_hash_global_config");
12231 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12232         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12233                 port_id, UINT16);
12234 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12235         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12236                 hash_func, "toeplitz#simple_xor#default");
12237 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12238         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12239                 flow_type,
12240                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12241                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12242 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12243         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12244                 enable, "enable#disable");
12245
12246 cmdline_parse_inst_t cmd_set_hash_global_config = {
12247         .f = cmd_set_hash_global_config_parsed,
12248         .data = NULL,
12249         .help_str = "set_hash_global_config <port_id> "
12250                 "toeplitz|simple_xor|default "
12251                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12252                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12253                 "l2_payload enable|disable",
12254         .tokens = {
12255                 (void *)&cmd_set_hash_global_config_all,
12256                 (void *)&cmd_set_hash_global_config_port_id,
12257                 (void *)&cmd_set_hash_global_config_hash_func,
12258                 (void *)&cmd_set_hash_global_config_flow_type,
12259                 (void *)&cmd_set_hash_global_config_enable,
12260                 NULL,
12261         },
12262 };
12263
12264 /* Set hash input set */
12265 struct cmd_set_hash_input_set_result {
12266         cmdline_fixed_string_t set_hash_input_set;
12267         portid_t port_id;
12268         cmdline_fixed_string_t flow_type;
12269         cmdline_fixed_string_t inset_field;
12270         cmdline_fixed_string_t select;
12271 };
12272
12273 static enum rte_eth_input_set_field
12274 str2inset(char *string)
12275 {
12276         uint16_t i;
12277
12278         static const struct {
12279                 char str[32];
12280                 enum rte_eth_input_set_field inset;
12281         } inset_table[] = {
12282                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12283                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12284                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12285                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12286                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12287                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12288                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12289                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12290                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12291                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12292                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12293                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12294                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12295                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12296                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12297                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12298                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12299                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12300                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12301                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12302                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12303                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12304                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12305                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12306                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12307                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12308                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12309                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12310                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12311                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12312                 {"none", RTE_ETH_INPUT_SET_NONE},
12313         };
12314
12315         for (i = 0; i < RTE_DIM(inset_table); i++) {
12316                 if (!strcmp(string, inset_table[i].str))
12317                         return inset_table[i].inset;
12318         }
12319
12320         return RTE_ETH_INPUT_SET_UNKNOWN;
12321 }
12322
12323 static void
12324 cmd_set_hash_input_set_parsed(void *parsed_result,
12325                               __rte_unused struct cmdline *cl,
12326                               __rte_unused void *data)
12327 {
12328         struct cmd_set_hash_input_set_result *res = parsed_result;
12329         struct rte_eth_hash_filter_info info;
12330
12331         memset(&info, 0, sizeof(info));
12332         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12333         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12334         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12335         info.info.input_set_conf.inset_size = 1;
12336         if (!strcmp(res->select, "select"))
12337                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12338         else if (!strcmp(res->select, "add"))
12339                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12340         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12341                                 RTE_ETH_FILTER_SET, &info);
12342 }
12343
12344 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12345         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12346                 set_hash_input_set, "set_hash_input_set");
12347 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12348         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12349                 port_id, UINT16);
12350 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12351         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12352                 flow_type, NULL);
12353 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12354         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12355                 inset_field,
12356                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12357                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12358                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12359                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12360                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12361                 "fld-8th#none");
12362 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12363         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12364                 select, "select#add");
12365
12366 cmdline_parse_inst_t cmd_set_hash_input_set = {
12367         .f = cmd_set_hash_input_set_parsed,
12368         .data = NULL,
12369         .help_str = "set_hash_input_set <port_id> "
12370         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12371         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12372         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12373         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12374         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12375         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12376         "fld-7th|fld-8th|none select|add",
12377         .tokens = {
12378                 (void *)&cmd_set_hash_input_set_cmd,
12379                 (void *)&cmd_set_hash_input_set_port_id,
12380                 (void *)&cmd_set_hash_input_set_flow_type,
12381                 (void *)&cmd_set_hash_input_set_field,
12382                 (void *)&cmd_set_hash_input_set_select,
12383                 NULL,
12384         },
12385 };
12386
12387 /* Set flow director input set */
12388 struct cmd_set_fdir_input_set_result {
12389         cmdline_fixed_string_t set_fdir_input_set;
12390         portid_t port_id;
12391         cmdline_fixed_string_t flow_type;
12392         cmdline_fixed_string_t inset_field;
12393         cmdline_fixed_string_t select;
12394 };
12395
12396 static void
12397 cmd_set_fdir_input_set_parsed(void *parsed_result,
12398         __rte_unused struct cmdline *cl,
12399         __rte_unused void *data)
12400 {
12401         struct cmd_set_fdir_input_set_result *res = parsed_result;
12402         struct rte_eth_fdir_filter_info info;
12403
12404         memset(&info, 0, sizeof(info));
12405         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12406         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12407         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12408         info.info.input_set_conf.inset_size = 1;
12409         if (!strcmp(res->select, "select"))
12410                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12411         else if (!strcmp(res->select, "add"))
12412                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12413         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12414                 RTE_ETH_FILTER_SET, &info);
12415 }
12416
12417 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12418         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12419         set_fdir_input_set, "set_fdir_input_set");
12420 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12421         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12422         port_id, UINT16);
12423 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12424         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12425         flow_type,
12426         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12427         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12428 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12429         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12430         inset_field,
12431         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12432         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12433         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12434         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12435         "sctp-veri-tag#none");
12436 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12437         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12438         select, "select#add");
12439
12440 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12441         .f = cmd_set_fdir_input_set_parsed,
12442         .data = NULL,
12443         .help_str = "set_fdir_input_set <port_id> "
12444         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12445         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12446         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12447         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12448         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12449         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12450         "sctp-veri-tag|none select|add",
12451         .tokens = {
12452                 (void *)&cmd_set_fdir_input_set_cmd,
12453                 (void *)&cmd_set_fdir_input_set_port_id,
12454                 (void *)&cmd_set_fdir_input_set_flow_type,
12455                 (void *)&cmd_set_fdir_input_set_field,
12456                 (void *)&cmd_set_fdir_input_set_select,
12457                 NULL,
12458         },
12459 };
12460
12461 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12462 struct cmd_mcast_addr_result {
12463         cmdline_fixed_string_t mcast_addr_cmd;
12464         cmdline_fixed_string_t what;
12465         uint16_t port_num;
12466         struct rte_ether_addr mc_addr;
12467 };
12468
12469 static void cmd_mcast_addr_parsed(void *parsed_result,
12470                 __attribute__((unused)) struct cmdline *cl,
12471                 __attribute__((unused)) void *data)
12472 {
12473         struct cmd_mcast_addr_result *res = parsed_result;
12474
12475         if (!is_multicast_ether_addr(&res->mc_addr)) {
12476                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12477                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12478                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12479                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12480                 return;
12481         }
12482         if (strcmp(res->what, "add") == 0)
12483                 mcast_addr_add(res->port_num, &res->mc_addr);
12484         else
12485                 mcast_addr_remove(res->port_num, &res->mc_addr);
12486 }
12487
12488 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12489         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12490                                  mcast_addr_cmd, "mcast_addr");
12491 cmdline_parse_token_string_t cmd_mcast_addr_what =
12492         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12493                                  "add#remove");
12494 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12495         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12496 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12497         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12498
12499 cmdline_parse_inst_t cmd_mcast_addr = {
12500         .f = cmd_mcast_addr_parsed,
12501         .data = (void *)0,
12502         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12503                 "Add/Remove multicast MAC address on port_id",
12504         .tokens = {
12505                 (void *)&cmd_mcast_addr_cmd,
12506                 (void *)&cmd_mcast_addr_what,
12507                 (void *)&cmd_mcast_addr_portnum,
12508                 (void *)&cmd_mcast_addr_addr,
12509                 NULL,
12510         },
12511 };
12512
12513 /* l2 tunnel config
12514  * only support E-tag now.
12515  */
12516
12517 /* Ether type config */
12518 struct cmd_config_l2_tunnel_eth_type_result {
12519         cmdline_fixed_string_t port;
12520         cmdline_fixed_string_t config;
12521         cmdline_fixed_string_t all;
12522         portid_t id;
12523         cmdline_fixed_string_t l2_tunnel;
12524         cmdline_fixed_string_t l2_tunnel_type;
12525         cmdline_fixed_string_t eth_type;
12526         uint16_t eth_type_val;
12527 };
12528
12529 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12530         TOKEN_STRING_INITIALIZER
12531                 (struct cmd_config_l2_tunnel_eth_type_result,
12532                  port, "port");
12533 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12534         TOKEN_STRING_INITIALIZER
12535                 (struct cmd_config_l2_tunnel_eth_type_result,
12536                  config, "config");
12537 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12538         TOKEN_STRING_INITIALIZER
12539                 (struct cmd_config_l2_tunnel_eth_type_result,
12540                  all, "all");
12541 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12542         TOKEN_NUM_INITIALIZER
12543                 (struct cmd_config_l2_tunnel_eth_type_result,
12544                  id, UINT16);
12545 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12546         TOKEN_STRING_INITIALIZER
12547                 (struct cmd_config_l2_tunnel_eth_type_result,
12548                  l2_tunnel, "l2-tunnel");
12549 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12550         TOKEN_STRING_INITIALIZER
12551                 (struct cmd_config_l2_tunnel_eth_type_result,
12552                  l2_tunnel_type, "E-tag");
12553 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12554         TOKEN_STRING_INITIALIZER
12555                 (struct cmd_config_l2_tunnel_eth_type_result,
12556                  eth_type, "ether-type");
12557 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12558         TOKEN_NUM_INITIALIZER
12559                 (struct cmd_config_l2_tunnel_eth_type_result,
12560                  eth_type_val, UINT16);
12561
12562 static enum rte_eth_tunnel_type
12563 str2fdir_l2_tunnel_type(char *string)
12564 {
12565         uint32_t i = 0;
12566
12567         static const struct {
12568                 char str[32];
12569                 enum rte_eth_tunnel_type type;
12570         } l2_tunnel_type_str[] = {
12571                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12572         };
12573
12574         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12575                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12576                         return l2_tunnel_type_str[i].type;
12577         }
12578         return RTE_TUNNEL_TYPE_NONE;
12579 }
12580
12581 /* ether type config for all ports */
12582 static void
12583 cmd_config_l2_tunnel_eth_type_all_parsed
12584         (void *parsed_result,
12585          __attribute__((unused)) struct cmdline *cl,
12586          __attribute__((unused)) void *data)
12587 {
12588         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12589         struct rte_eth_l2_tunnel_conf entry;
12590         portid_t pid;
12591
12592         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12593         entry.ether_type = res->eth_type_val;
12594
12595         RTE_ETH_FOREACH_DEV(pid) {
12596                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12597         }
12598 }
12599
12600 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12601         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12602         .data = NULL,
12603         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12604         .tokens = {
12605                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12606                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12607                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12608                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12609                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12610                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12611                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12612                 NULL,
12613         },
12614 };
12615
12616 /* ether type config for a specific port */
12617 static void
12618 cmd_config_l2_tunnel_eth_type_specific_parsed(
12619         void *parsed_result,
12620         __attribute__((unused)) struct cmdline *cl,
12621         __attribute__((unused)) void *data)
12622 {
12623         struct cmd_config_l2_tunnel_eth_type_result *res =
12624                  parsed_result;
12625         struct rte_eth_l2_tunnel_conf entry;
12626
12627         if (port_id_is_invalid(res->id, ENABLED_WARN))
12628                 return;
12629
12630         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12631         entry.ether_type = res->eth_type_val;
12632
12633         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12634 }
12635
12636 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12637         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12638         .data = NULL,
12639         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12640         .tokens = {
12641                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12642                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12643                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12644                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12645                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12646                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12647                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12648                 NULL,
12649         },
12650 };
12651
12652 /* Enable/disable l2 tunnel */
12653 struct cmd_config_l2_tunnel_en_dis_result {
12654         cmdline_fixed_string_t port;
12655         cmdline_fixed_string_t config;
12656         cmdline_fixed_string_t all;
12657         portid_t id;
12658         cmdline_fixed_string_t l2_tunnel;
12659         cmdline_fixed_string_t l2_tunnel_type;
12660         cmdline_fixed_string_t en_dis;
12661 };
12662
12663 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12664         TOKEN_STRING_INITIALIZER
12665                 (struct cmd_config_l2_tunnel_en_dis_result,
12666                  port, "port");
12667 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12668         TOKEN_STRING_INITIALIZER
12669                 (struct cmd_config_l2_tunnel_en_dis_result,
12670                  config, "config");
12671 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12672         TOKEN_STRING_INITIALIZER
12673                 (struct cmd_config_l2_tunnel_en_dis_result,
12674                  all, "all");
12675 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12676         TOKEN_NUM_INITIALIZER
12677                 (struct cmd_config_l2_tunnel_en_dis_result,
12678                  id, UINT16);
12679 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12680         TOKEN_STRING_INITIALIZER
12681                 (struct cmd_config_l2_tunnel_en_dis_result,
12682                  l2_tunnel, "l2-tunnel");
12683 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12684         TOKEN_STRING_INITIALIZER
12685                 (struct cmd_config_l2_tunnel_en_dis_result,
12686                  l2_tunnel_type, "E-tag");
12687 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12688         TOKEN_STRING_INITIALIZER
12689                 (struct cmd_config_l2_tunnel_en_dis_result,
12690                  en_dis, "enable#disable");
12691
12692 /* enable/disable l2 tunnel for all ports */
12693 static void
12694 cmd_config_l2_tunnel_en_dis_all_parsed(
12695         void *parsed_result,
12696         __attribute__((unused)) struct cmdline *cl,
12697         __attribute__((unused)) void *data)
12698 {
12699         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12700         struct rte_eth_l2_tunnel_conf entry;
12701         portid_t pid;
12702         uint8_t en;
12703
12704         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12705
12706         if (!strcmp("enable", res->en_dis))
12707                 en = 1;
12708         else
12709                 en = 0;
12710
12711         RTE_ETH_FOREACH_DEV(pid) {
12712                 rte_eth_dev_l2_tunnel_offload_set(pid,
12713                                                   &entry,
12714                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12715                                                   en);
12716         }
12717 }
12718
12719 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12720         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12721         .data = NULL,
12722         .help_str = "port config all l2-tunnel E-tag enable|disable",
12723         .tokens = {
12724                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12725                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12726                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12727                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12728                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12729                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12730                 NULL,
12731         },
12732 };
12733
12734 /* enable/disable l2 tunnel for a port */
12735 static void
12736 cmd_config_l2_tunnel_en_dis_specific_parsed(
12737         void *parsed_result,
12738         __attribute__((unused)) struct cmdline *cl,
12739         __attribute__((unused)) void *data)
12740 {
12741         struct cmd_config_l2_tunnel_en_dis_result *res =
12742                 parsed_result;
12743         struct rte_eth_l2_tunnel_conf entry;
12744
12745         if (port_id_is_invalid(res->id, ENABLED_WARN))
12746                 return;
12747
12748         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12749
12750         if (!strcmp("enable", res->en_dis))
12751                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12752                                                   &entry,
12753                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12754                                                   1);
12755         else
12756                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12757                                                   &entry,
12758                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12759                                                   0);
12760 }
12761
12762 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12763         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12764         .data = NULL,
12765         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12766         .tokens = {
12767                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12768                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12769                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12770                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12771                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12772                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12773                 NULL,
12774         },
12775 };
12776
12777 /* E-tag configuration */
12778
12779 /* Common result structure for all E-tag configuration */
12780 struct cmd_config_e_tag_result {
12781         cmdline_fixed_string_t e_tag;
12782         cmdline_fixed_string_t set;
12783         cmdline_fixed_string_t insertion;
12784         cmdline_fixed_string_t stripping;
12785         cmdline_fixed_string_t forwarding;
12786         cmdline_fixed_string_t filter;
12787         cmdline_fixed_string_t add;
12788         cmdline_fixed_string_t del;
12789         cmdline_fixed_string_t on;
12790         cmdline_fixed_string_t off;
12791         cmdline_fixed_string_t on_off;
12792         cmdline_fixed_string_t port_tag_id;
12793         uint32_t port_tag_id_val;
12794         cmdline_fixed_string_t e_tag_id;
12795         uint16_t e_tag_id_val;
12796         cmdline_fixed_string_t dst_pool;
12797         uint8_t dst_pool_val;
12798         cmdline_fixed_string_t port;
12799         portid_t port_id;
12800         cmdline_fixed_string_t vf;
12801         uint8_t vf_id;
12802 };
12803
12804 /* Common CLI fields for all E-tag configuration */
12805 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12806         TOKEN_STRING_INITIALIZER
12807                 (struct cmd_config_e_tag_result,
12808                  e_tag, "E-tag");
12809 cmdline_parse_token_string_t cmd_config_e_tag_set =
12810         TOKEN_STRING_INITIALIZER
12811                 (struct cmd_config_e_tag_result,
12812                  set, "set");
12813 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12814         TOKEN_STRING_INITIALIZER
12815                 (struct cmd_config_e_tag_result,
12816                  insertion, "insertion");
12817 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12818         TOKEN_STRING_INITIALIZER
12819                 (struct cmd_config_e_tag_result,
12820                  stripping, "stripping");
12821 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12822         TOKEN_STRING_INITIALIZER
12823                 (struct cmd_config_e_tag_result,
12824                  forwarding, "forwarding");
12825 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12826         TOKEN_STRING_INITIALIZER
12827                 (struct cmd_config_e_tag_result,
12828                  filter, "filter");
12829 cmdline_parse_token_string_t cmd_config_e_tag_add =
12830         TOKEN_STRING_INITIALIZER
12831                 (struct cmd_config_e_tag_result,
12832                  add, "add");
12833 cmdline_parse_token_string_t cmd_config_e_tag_del =
12834         TOKEN_STRING_INITIALIZER
12835                 (struct cmd_config_e_tag_result,
12836                  del, "del");
12837 cmdline_parse_token_string_t cmd_config_e_tag_on =
12838         TOKEN_STRING_INITIALIZER
12839                 (struct cmd_config_e_tag_result,
12840                  on, "on");
12841 cmdline_parse_token_string_t cmd_config_e_tag_off =
12842         TOKEN_STRING_INITIALIZER
12843                 (struct cmd_config_e_tag_result,
12844                  off, "off");
12845 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12846         TOKEN_STRING_INITIALIZER
12847                 (struct cmd_config_e_tag_result,
12848                  on_off, "on#off");
12849 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12850         TOKEN_STRING_INITIALIZER
12851                 (struct cmd_config_e_tag_result,
12852                  port_tag_id, "port-tag-id");
12853 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12854         TOKEN_NUM_INITIALIZER
12855                 (struct cmd_config_e_tag_result,
12856                  port_tag_id_val, UINT32);
12857 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12858         TOKEN_STRING_INITIALIZER
12859                 (struct cmd_config_e_tag_result,
12860                  e_tag_id, "e-tag-id");
12861 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12862         TOKEN_NUM_INITIALIZER
12863                 (struct cmd_config_e_tag_result,
12864                  e_tag_id_val, UINT16);
12865 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12866         TOKEN_STRING_INITIALIZER
12867                 (struct cmd_config_e_tag_result,
12868                  dst_pool, "dst-pool");
12869 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12870         TOKEN_NUM_INITIALIZER
12871                 (struct cmd_config_e_tag_result,
12872                  dst_pool_val, UINT8);
12873 cmdline_parse_token_string_t cmd_config_e_tag_port =
12874         TOKEN_STRING_INITIALIZER
12875                 (struct cmd_config_e_tag_result,
12876                  port, "port");
12877 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12878         TOKEN_NUM_INITIALIZER
12879                 (struct cmd_config_e_tag_result,
12880                  port_id, UINT16);
12881 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12882         TOKEN_STRING_INITIALIZER
12883                 (struct cmd_config_e_tag_result,
12884                  vf, "vf");
12885 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12886         TOKEN_NUM_INITIALIZER
12887                 (struct cmd_config_e_tag_result,
12888                  vf_id, UINT8);
12889
12890 /* E-tag insertion configuration */
12891 static void
12892 cmd_config_e_tag_insertion_en_parsed(
12893         void *parsed_result,
12894         __attribute__((unused)) struct cmdline *cl,
12895         __attribute__((unused)) void *data)
12896 {
12897         struct cmd_config_e_tag_result *res =
12898                 parsed_result;
12899         struct rte_eth_l2_tunnel_conf entry;
12900
12901         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12902                 return;
12903
12904         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12905         entry.tunnel_id = res->port_tag_id_val;
12906         entry.vf_id = res->vf_id;
12907         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12908                                           &entry,
12909                                           ETH_L2_TUNNEL_INSERTION_MASK,
12910                                           1);
12911 }
12912
12913 static void
12914 cmd_config_e_tag_insertion_dis_parsed(
12915         void *parsed_result,
12916         __attribute__((unused)) struct cmdline *cl,
12917         __attribute__((unused)) void *data)
12918 {
12919         struct cmd_config_e_tag_result *res =
12920                 parsed_result;
12921         struct rte_eth_l2_tunnel_conf entry;
12922
12923         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12924                 return;
12925
12926         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12927         entry.vf_id = res->vf_id;
12928
12929         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12930                                           &entry,
12931                                           ETH_L2_TUNNEL_INSERTION_MASK,
12932                                           0);
12933 }
12934
12935 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12936         .f = cmd_config_e_tag_insertion_en_parsed,
12937         .data = NULL,
12938         .help_str = "E-tag ... : E-tag insertion enable",
12939         .tokens = {
12940                 (void *)&cmd_config_e_tag_e_tag,
12941                 (void *)&cmd_config_e_tag_set,
12942                 (void *)&cmd_config_e_tag_insertion,
12943                 (void *)&cmd_config_e_tag_on,
12944                 (void *)&cmd_config_e_tag_port_tag_id,
12945                 (void *)&cmd_config_e_tag_port_tag_id_val,
12946                 (void *)&cmd_config_e_tag_port,
12947                 (void *)&cmd_config_e_tag_port_id,
12948                 (void *)&cmd_config_e_tag_vf,
12949                 (void *)&cmd_config_e_tag_vf_id,
12950                 NULL,
12951         },
12952 };
12953
12954 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12955         .f = cmd_config_e_tag_insertion_dis_parsed,
12956         .data = NULL,
12957         .help_str = "E-tag ... : E-tag insertion disable",
12958         .tokens = {
12959                 (void *)&cmd_config_e_tag_e_tag,
12960                 (void *)&cmd_config_e_tag_set,
12961                 (void *)&cmd_config_e_tag_insertion,
12962                 (void *)&cmd_config_e_tag_off,
12963                 (void *)&cmd_config_e_tag_port,
12964                 (void *)&cmd_config_e_tag_port_id,
12965                 (void *)&cmd_config_e_tag_vf,
12966                 (void *)&cmd_config_e_tag_vf_id,
12967                 NULL,
12968         },
12969 };
12970
12971 /* E-tag stripping configuration */
12972 static void
12973 cmd_config_e_tag_stripping_parsed(
12974         void *parsed_result,
12975         __attribute__((unused)) struct cmdline *cl,
12976         __attribute__((unused)) void *data)
12977 {
12978         struct cmd_config_e_tag_result *res =
12979                 parsed_result;
12980         struct rte_eth_l2_tunnel_conf entry;
12981
12982         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12983                 return;
12984
12985         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12986
12987         if (!strcmp(res->on_off, "on"))
12988                 rte_eth_dev_l2_tunnel_offload_set
12989                         (res->port_id,
12990                          &entry,
12991                          ETH_L2_TUNNEL_STRIPPING_MASK,
12992                          1);
12993         else
12994                 rte_eth_dev_l2_tunnel_offload_set
12995                         (res->port_id,
12996                          &entry,
12997                          ETH_L2_TUNNEL_STRIPPING_MASK,
12998                          0);
12999 }
13000
13001 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13002         .f = cmd_config_e_tag_stripping_parsed,
13003         .data = NULL,
13004         .help_str = "E-tag ... : E-tag stripping enable/disable",
13005         .tokens = {
13006                 (void *)&cmd_config_e_tag_e_tag,
13007                 (void *)&cmd_config_e_tag_set,
13008                 (void *)&cmd_config_e_tag_stripping,
13009                 (void *)&cmd_config_e_tag_on_off,
13010                 (void *)&cmd_config_e_tag_port,
13011                 (void *)&cmd_config_e_tag_port_id,
13012                 NULL,
13013         },
13014 };
13015
13016 /* E-tag forwarding configuration */
13017 static void
13018 cmd_config_e_tag_forwarding_parsed(
13019         void *parsed_result,
13020         __attribute__((unused)) struct cmdline *cl,
13021         __attribute__((unused)) void *data)
13022 {
13023         struct cmd_config_e_tag_result *res = parsed_result;
13024         struct rte_eth_l2_tunnel_conf entry;
13025
13026         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13027                 return;
13028
13029         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13030
13031         if (!strcmp(res->on_off, "on"))
13032                 rte_eth_dev_l2_tunnel_offload_set
13033                         (res->port_id,
13034                          &entry,
13035                          ETH_L2_TUNNEL_FORWARDING_MASK,
13036                          1);
13037         else
13038                 rte_eth_dev_l2_tunnel_offload_set
13039                         (res->port_id,
13040                          &entry,
13041                          ETH_L2_TUNNEL_FORWARDING_MASK,
13042                          0);
13043 }
13044
13045 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13046         .f = cmd_config_e_tag_forwarding_parsed,
13047         .data = NULL,
13048         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13049         .tokens = {
13050                 (void *)&cmd_config_e_tag_e_tag,
13051                 (void *)&cmd_config_e_tag_set,
13052                 (void *)&cmd_config_e_tag_forwarding,
13053                 (void *)&cmd_config_e_tag_on_off,
13054                 (void *)&cmd_config_e_tag_port,
13055                 (void *)&cmd_config_e_tag_port_id,
13056                 NULL,
13057         },
13058 };
13059
13060 /* E-tag filter configuration */
13061 static void
13062 cmd_config_e_tag_filter_add_parsed(
13063         void *parsed_result,
13064         __attribute__((unused)) struct cmdline *cl,
13065         __attribute__((unused)) void *data)
13066 {
13067         struct cmd_config_e_tag_result *res = parsed_result;
13068         struct rte_eth_l2_tunnel_conf entry;
13069         int ret = 0;
13070
13071         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13072                 return;
13073
13074         if (res->e_tag_id_val > 0x3fff) {
13075                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13076                 return;
13077         }
13078
13079         ret = rte_eth_dev_filter_supported(res->port_id,
13080                                            RTE_ETH_FILTER_L2_TUNNEL);
13081         if (ret < 0) {
13082                 printf("E-tag filter is not supported on port %u.\n",
13083                        res->port_id);
13084                 return;
13085         }
13086
13087         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13088         entry.tunnel_id = res->e_tag_id_val;
13089         entry.pool = res->dst_pool_val;
13090
13091         ret = rte_eth_dev_filter_ctrl(res->port_id,
13092                                       RTE_ETH_FILTER_L2_TUNNEL,
13093                                       RTE_ETH_FILTER_ADD,
13094                                       &entry);
13095         if (ret < 0)
13096                 printf("E-tag filter programming error: (%s)\n",
13097                        strerror(-ret));
13098 }
13099
13100 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13101         .f = cmd_config_e_tag_filter_add_parsed,
13102         .data = NULL,
13103         .help_str = "E-tag ... : E-tag filter add",
13104         .tokens = {
13105                 (void *)&cmd_config_e_tag_e_tag,
13106                 (void *)&cmd_config_e_tag_set,
13107                 (void *)&cmd_config_e_tag_filter,
13108                 (void *)&cmd_config_e_tag_add,
13109                 (void *)&cmd_config_e_tag_e_tag_id,
13110                 (void *)&cmd_config_e_tag_e_tag_id_val,
13111                 (void *)&cmd_config_e_tag_dst_pool,
13112                 (void *)&cmd_config_e_tag_dst_pool_val,
13113                 (void *)&cmd_config_e_tag_port,
13114                 (void *)&cmd_config_e_tag_port_id,
13115                 NULL,
13116         },
13117 };
13118
13119 static void
13120 cmd_config_e_tag_filter_del_parsed(
13121         void *parsed_result,
13122         __attribute__((unused)) struct cmdline *cl,
13123         __attribute__((unused)) void *data)
13124 {
13125         struct cmd_config_e_tag_result *res = parsed_result;
13126         struct rte_eth_l2_tunnel_conf entry;
13127         int ret = 0;
13128
13129         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13130                 return;
13131
13132         if (res->e_tag_id_val > 0x3fff) {
13133                 printf("e-tag-id must be less than 0x3fff.\n");
13134                 return;
13135         }
13136
13137         ret = rte_eth_dev_filter_supported(res->port_id,
13138                                            RTE_ETH_FILTER_L2_TUNNEL);
13139         if (ret < 0) {
13140                 printf("E-tag filter is not supported on port %u.\n",
13141                        res->port_id);
13142                 return;
13143         }
13144
13145         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13146         entry.tunnel_id = res->e_tag_id_val;
13147
13148         ret = rte_eth_dev_filter_ctrl(res->port_id,
13149                                       RTE_ETH_FILTER_L2_TUNNEL,
13150                                       RTE_ETH_FILTER_DELETE,
13151                                       &entry);
13152         if (ret < 0)
13153                 printf("E-tag filter programming error: (%s)\n",
13154                        strerror(-ret));
13155 }
13156
13157 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13158         .f = cmd_config_e_tag_filter_del_parsed,
13159         .data = NULL,
13160         .help_str = "E-tag ... : E-tag filter delete",
13161         .tokens = {
13162                 (void *)&cmd_config_e_tag_e_tag,
13163                 (void *)&cmd_config_e_tag_set,
13164                 (void *)&cmd_config_e_tag_filter,
13165                 (void *)&cmd_config_e_tag_del,
13166                 (void *)&cmd_config_e_tag_e_tag_id,
13167                 (void *)&cmd_config_e_tag_e_tag_id_val,
13168                 (void *)&cmd_config_e_tag_port,
13169                 (void *)&cmd_config_e_tag_port_id,
13170                 NULL,
13171         },
13172 };
13173
13174 /* vf vlan anti spoof configuration */
13175
13176 /* Common result structure for vf vlan anti spoof */
13177 struct cmd_vf_vlan_anti_spoof_result {
13178         cmdline_fixed_string_t set;
13179         cmdline_fixed_string_t vf;
13180         cmdline_fixed_string_t vlan;
13181         cmdline_fixed_string_t antispoof;
13182         portid_t port_id;
13183         uint32_t vf_id;
13184         cmdline_fixed_string_t on_off;
13185 };
13186
13187 /* Common CLI fields for vf vlan anti spoof enable disable */
13188 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13189         TOKEN_STRING_INITIALIZER
13190                 (struct cmd_vf_vlan_anti_spoof_result,
13191                  set, "set");
13192 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13193         TOKEN_STRING_INITIALIZER
13194                 (struct cmd_vf_vlan_anti_spoof_result,
13195                  vf, "vf");
13196 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13197         TOKEN_STRING_INITIALIZER
13198                 (struct cmd_vf_vlan_anti_spoof_result,
13199                  vlan, "vlan");
13200 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13201         TOKEN_STRING_INITIALIZER
13202                 (struct cmd_vf_vlan_anti_spoof_result,
13203                  antispoof, "antispoof");
13204 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13205         TOKEN_NUM_INITIALIZER
13206                 (struct cmd_vf_vlan_anti_spoof_result,
13207                  port_id, UINT16);
13208 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13209         TOKEN_NUM_INITIALIZER
13210                 (struct cmd_vf_vlan_anti_spoof_result,
13211                  vf_id, UINT32);
13212 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13213         TOKEN_STRING_INITIALIZER
13214                 (struct cmd_vf_vlan_anti_spoof_result,
13215                  on_off, "on#off");
13216
13217 static void
13218 cmd_set_vf_vlan_anti_spoof_parsed(
13219         void *parsed_result,
13220         __attribute__((unused)) struct cmdline *cl,
13221         __attribute__((unused)) void *data)
13222 {
13223         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13224         int ret = -ENOTSUP;
13225
13226         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13227
13228         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13229                 return;
13230
13231 #ifdef RTE_LIBRTE_IXGBE_PMD
13232         if (ret == -ENOTSUP)
13233                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13234                                 res->vf_id, is_on);
13235 #endif
13236 #ifdef RTE_LIBRTE_I40E_PMD
13237         if (ret == -ENOTSUP)
13238                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13239                                 res->vf_id, is_on);
13240 #endif
13241 #ifdef RTE_LIBRTE_BNXT_PMD
13242         if (ret == -ENOTSUP)
13243                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13244                                 res->vf_id, is_on);
13245 #endif
13246
13247         switch (ret) {
13248         case 0:
13249                 break;
13250         case -EINVAL:
13251                 printf("invalid vf_id %d\n", res->vf_id);
13252                 break;
13253         case -ENODEV:
13254                 printf("invalid port_id %d\n", res->port_id);
13255                 break;
13256         case -ENOTSUP:
13257                 printf("function not implemented\n");
13258                 break;
13259         default:
13260                 printf("programming error: (%s)\n", strerror(-ret));
13261         }
13262 }
13263
13264 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13265         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13266         .data = NULL,
13267         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13268         .tokens = {
13269                 (void *)&cmd_vf_vlan_anti_spoof_set,
13270                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13271                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13272                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13273                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13274                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13275                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13276                 NULL,
13277         },
13278 };
13279
13280 /* vf mac anti spoof configuration */
13281
13282 /* Common result structure for vf mac anti spoof */
13283 struct cmd_vf_mac_anti_spoof_result {
13284         cmdline_fixed_string_t set;
13285         cmdline_fixed_string_t vf;
13286         cmdline_fixed_string_t mac;
13287         cmdline_fixed_string_t antispoof;
13288         portid_t port_id;
13289         uint32_t vf_id;
13290         cmdline_fixed_string_t on_off;
13291 };
13292
13293 /* Common CLI fields for vf mac anti spoof enable disable */
13294 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13295         TOKEN_STRING_INITIALIZER
13296                 (struct cmd_vf_mac_anti_spoof_result,
13297                  set, "set");
13298 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13299         TOKEN_STRING_INITIALIZER
13300                 (struct cmd_vf_mac_anti_spoof_result,
13301                  vf, "vf");
13302 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13303         TOKEN_STRING_INITIALIZER
13304                 (struct cmd_vf_mac_anti_spoof_result,
13305                  mac, "mac");
13306 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13307         TOKEN_STRING_INITIALIZER
13308                 (struct cmd_vf_mac_anti_spoof_result,
13309                  antispoof, "antispoof");
13310 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13311         TOKEN_NUM_INITIALIZER
13312                 (struct cmd_vf_mac_anti_spoof_result,
13313                  port_id, UINT16);
13314 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13315         TOKEN_NUM_INITIALIZER
13316                 (struct cmd_vf_mac_anti_spoof_result,
13317                  vf_id, UINT32);
13318 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13319         TOKEN_STRING_INITIALIZER
13320                 (struct cmd_vf_mac_anti_spoof_result,
13321                  on_off, "on#off");
13322
13323 static void
13324 cmd_set_vf_mac_anti_spoof_parsed(
13325         void *parsed_result,
13326         __attribute__((unused)) struct cmdline *cl,
13327         __attribute__((unused)) void *data)
13328 {
13329         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13330         int ret = -ENOTSUP;
13331
13332         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13333
13334         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13335                 return;
13336
13337 #ifdef RTE_LIBRTE_IXGBE_PMD
13338         if (ret == -ENOTSUP)
13339                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13340                         res->vf_id, is_on);
13341 #endif
13342 #ifdef RTE_LIBRTE_I40E_PMD
13343         if (ret == -ENOTSUP)
13344                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13345                         res->vf_id, is_on);
13346 #endif
13347 #ifdef RTE_LIBRTE_BNXT_PMD
13348         if (ret == -ENOTSUP)
13349                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13350                         res->vf_id, is_on);
13351 #endif
13352
13353         switch (ret) {
13354         case 0:
13355                 break;
13356         case -EINVAL:
13357                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13358                 break;
13359         case -ENODEV:
13360                 printf("invalid port_id %d\n", res->port_id);
13361                 break;
13362         case -ENOTSUP:
13363                 printf("function not implemented\n");
13364                 break;
13365         default:
13366                 printf("programming error: (%s)\n", strerror(-ret));
13367         }
13368 }
13369
13370 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13371         .f = cmd_set_vf_mac_anti_spoof_parsed,
13372         .data = NULL,
13373         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13374         .tokens = {
13375                 (void *)&cmd_vf_mac_anti_spoof_set,
13376                 (void *)&cmd_vf_mac_anti_spoof_vf,
13377                 (void *)&cmd_vf_mac_anti_spoof_mac,
13378                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13379                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13380                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13381                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13382                 NULL,
13383         },
13384 };
13385
13386 /* vf vlan strip queue configuration */
13387
13388 /* Common result structure for vf mac anti spoof */
13389 struct cmd_vf_vlan_stripq_result {
13390         cmdline_fixed_string_t set;
13391         cmdline_fixed_string_t vf;
13392         cmdline_fixed_string_t vlan;
13393         cmdline_fixed_string_t stripq;
13394         portid_t port_id;
13395         uint16_t vf_id;
13396         cmdline_fixed_string_t on_off;
13397 };
13398
13399 /* Common CLI fields for vf vlan strip enable disable */
13400 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13401         TOKEN_STRING_INITIALIZER
13402                 (struct cmd_vf_vlan_stripq_result,
13403                  set, "set");
13404 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13405         TOKEN_STRING_INITIALIZER
13406                 (struct cmd_vf_vlan_stripq_result,
13407                  vf, "vf");
13408 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13409         TOKEN_STRING_INITIALIZER
13410                 (struct cmd_vf_vlan_stripq_result,
13411                  vlan, "vlan");
13412 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13413         TOKEN_STRING_INITIALIZER
13414                 (struct cmd_vf_vlan_stripq_result,
13415                  stripq, "stripq");
13416 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13417         TOKEN_NUM_INITIALIZER
13418                 (struct cmd_vf_vlan_stripq_result,
13419                  port_id, UINT16);
13420 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13421         TOKEN_NUM_INITIALIZER
13422                 (struct cmd_vf_vlan_stripq_result,
13423                  vf_id, UINT16);
13424 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13425         TOKEN_STRING_INITIALIZER
13426                 (struct cmd_vf_vlan_stripq_result,
13427                  on_off, "on#off");
13428
13429 static void
13430 cmd_set_vf_vlan_stripq_parsed(
13431         void *parsed_result,
13432         __attribute__((unused)) struct cmdline *cl,
13433         __attribute__((unused)) void *data)
13434 {
13435         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13436         int ret = -ENOTSUP;
13437
13438         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13439
13440         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13441                 return;
13442
13443 #ifdef RTE_LIBRTE_IXGBE_PMD
13444         if (ret == -ENOTSUP)
13445                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13446                         res->vf_id, is_on);
13447 #endif
13448 #ifdef RTE_LIBRTE_I40E_PMD
13449         if (ret == -ENOTSUP)
13450                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13451                         res->vf_id, is_on);
13452 #endif
13453 #ifdef RTE_LIBRTE_BNXT_PMD
13454         if (ret == -ENOTSUP)
13455                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13456                         res->vf_id, is_on);
13457 #endif
13458
13459         switch (ret) {
13460         case 0:
13461                 break;
13462         case -EINVAL:
13463                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13464                 break;
13465         case -ENODEV:
13466                 printf("invalid port_id %d\n", res->port_id);
13467                 break;
13468         case -ENOTSUP:
13469                 printf("function not implemented\n");
13470                 break;
13471         default:
13472                 printf("programming error: (%s)\n", strerror(-ret));
13473         }
13474 }
13475
13476 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13477         .f = cmd_set_vf_vlan_stripq_parsed,
13478         .data = NULL,
13479         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13480         .tokens = {
13481                 (void *)&cmd_vf_vlan_stripq_set,
13482                 (void *)&cmd_vf_vlan_stripq_vf,
13483                 (void *)&cmd_vf_vlan_stripq_vlan,
13484                 (void *)&cmd_vf_vlan_stripq_stripq,
13485                 (void *)&cmd_vf_vlan_stripq_port_id,
13486                 (void *)&cmd_vf_vlan_stripq_vf_id,
13487                 (void *)&cmd_vf_vlan_stripq_on_off,
13488                 NULL,
13489         },
13490 };
13491
13492 /* vf vlan insert configuration */
13493
13494 /* Common result structure for vf vlan insert */
13495 struct cmd_vf_vlan_insert_result {
13496         cmdline_fixed_string_t set;
13497         cmdline_fixed_string_t vf;
13498         cmdline_fixed_string_t vlan;
13499         cmdline_fixed_string_t insert;
13500         portid_t port_id;
13501         uint16_t vf_id;
13502         uint16_t vlan_id;
13503 };
13504
13505 /* Common CLI fields for vf vlan insert enable disable */
13506 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13507         TOKEN_STRING_INITIALIZER
13508                 (struct cmd_vf_vlan_insert_result,
13509                  set, "set");
13510 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13511         TOKEN_STRING_INITIALIZER
13512                 (struct cmd_vf_vlan_insert_result,
13513                  vf, "vf");
13514 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13515         TOKEN_STRING_INITIALIZER
13516                 (struct cmd_vf_vlan_insert_result,
13517                  vlan, "vlan");
13518 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13519         TOKEN_STRING_INITIALIZER
13520                 (struct cmd_vf_vlan_insert_result,
13521                  insert, "insert");
13522 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13523         TOKEN_NUM_INITIALIZER
13524                 (struct cmd_vf_vlan_insert_result,
13525                  port_id, UINT16);
13526 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13527         TOKEN_NUM_INITIALIZER
13528                 (struct cmd_vf_vlan_insert_result,
13529                  vf_id, UINT16);
13530 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13531         TOKEN_NUM_INITIALIZER
13532                 (struct cmd_vf_vlan_insert_result,
13533                  vlan_id, UINT16);
13534
13535 static void
13536 cmd_set_vf_vlan_insert_parsed(
13537         void *parsed_result,
13538         __attribute__((unused)) struct cmdline *cl,
13539         __attribute__((unused)) void *data)
13540 {
13541         struct cmd_vf_vlan_insert_result *res = parsed_result;
13542         int ret = -ENOTSUP;
13543
13544         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13545                 return;
13546
13547 #ifdef RTE_LIBRTE_IXGBE_PMD
13548         if (ret == -ENOTSUP)
13549                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13550                         res->vlan_id);
13551 #endif
13552 #ifdef RTE_LIBRTE_I40E_PMD
13553         if (ret == -ENOTSUP)
13554                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13555                         res->vlan_id);
13556 #endif
13557 #ifdef RTE_LIBRTE_BNXT_PMD
13558         if (ret == -ENOTSUP)
13559                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13560                         res->vlan_id);
13561 #endif
13562
13563         switch (ret) {
13564         case 0:
13565                 break;
13566         case -EINVAL:
13567                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13568                 break;
13569         case -ENODEV:
13570                 printf("invalid port_id %d\n", res->port_id);
13571                 break;
13572         case -ENOTSUP:
13573                 printf("function not implemented\n");
13574                 break;
13575         default:
13576                 printf("programming error: (%s)\n", strerror(-ret));
13577         }
13578 }
13579
13580 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13581         .f = cmd_set_vf_vlan_insert_parsed,
13582         .data = NULL,
13583         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13584         .tokens = {
13585                 (void *)&cmd_vf_vlan_insert_set,
13586                 (void *)&cmd_vf_vlan_insert_vf,
13587                 (void *)&cmd_vf_vlan_insert_vlan,
13588                 (void *)&cmd_vf_vlan_insert_insert,
13589                 (void *)&cmd_vf_vlan_insert_port_id,
13590                 (void *)&cmd_vf_vlan_insert_vf_id,
13591                 (void *)&cmd_vf_vlan_insert_vlan_id,
13592                 NULL,
13593         },
13594 };
13595
13596 /* tx loopback configuration */
13597
13598 /* Common result structure for tx loopback */
13599 struct cmd_tx_loopback_result {
13600         cmdline_fixed_string_t set;
13601         cmdline_fixed_string_t tx;
13602         cmdline_fixed_string_t loopback;
13603         portid_t port_id;
13604         cmdline_fixed_string_t on_off;
13605 };
13606
13607 /* Common CLI fields for tx loopback enable disable */
13608 cmdline_parse_token_string_t cmd_tx_loopback_set =
13609         TOKEN_STRING_INITIALIZER
13610                 (struct cmd_tx_loopback_result,
13611                  set, "set");
13612 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13613         TOKEN_STRING_INITIALIZER
13614                 (struct cmd_tx_loopback_result,
13615                  tx, "tx");
13616 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13617         TOKEN_STRING_INITIALIZER
13618                 (struct cmd_tx_loopback_result,
13619                  loopback, "loopback");
13620 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13621         TOKEN_NUM_INITIALIZER
13622                 (struct cmd_tx_loopback_result,
13623                  port_id, UINT16);
13624 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13625         TOKEN_STRING_INITIALIZER
13626                 (struct cmd_tx_loopback_result,
13627                  on_off, "on#off");
13628
13629 static void
13630 cmd_set_tx_loopback_parsed(
13631         void *parsed_result,
13632         __attribute__((unused)) struct cmdline *cl,
13633         __attribute__((unused)) void *data)
13634 {
13635         struct cmd_tx_loopback_result *res = parsed_result;
13636         int ret = -ENOTSUP;
13637
13638         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13639
13640         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13641                 return;
13642
13643 #ifdef RTE_LIBRTE_IXGBE_PMD
13644         if (ret == -ENOTSUP)
13645                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13646 #endif
13647 #ifdef RTE_LIBRTE_I40E_PMD
13648         if (ret == -ENOTSUP)
13649                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13650 #endif
13651 #ifdef RTE_LIBRTE_BNXT_PMD
13652         if (ret == -ENOTSUP)
13653                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13654 #endif
13655 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13656         if (ret == -ENOTSUP)
13657                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13658 #endif
13659
13660         switch (ret) {
13661         case 0:
13662                 break;
13663         case -EINVAL:
13664                 printf("invalid is_on %d\n", is_on);
13665                 break;
13666         case -ENODEV:
13667                 printf("invalid port_id %d\n", res->port_id);
13668                 break;
13669         case -ENOTSUP:
13670                 printf("function not implemented\n");
13671                 break;
13672         default:
13673                 printf("programming error: (%s)\n", strerror(-ret));
13674         }
13675 }
13676
13677 cmdline_parse_inst_t cmd_set_tx_loopback = {
13678         .f = cmd_set_tx_loopback_parsed,
13679         .data = NULL,
13680         .help_str = "set tx loopback <port_id> on|off",
13681         .tokens = {
13682                 (void *)&cmd_tx_loopback_set,
13683                 (void *)&cmd_tx_loopback_tx,
13684                 (void *)&cmd_tx_loopback_loopback,
13685                 (void *)&cmd_tx_loopback_port_id,
13686                 (void *)&cmd_tx_loopback_on_off,
13687                 NULL,
13688         },
13689 };
13690
13691 /* all queues drop enable configuration */
13692
13693 /* Common result structure for all queues drop enable */
13694 struct cmd_all_queues_drop_en_result {
13695         cmdline_fixed_string_t set;
13696         cmdline_fixed_string_t all;
13697         cmdline_fixed_string_t queues;
13698         cmdline_fixed_string_t drop;
13699         portid_t port_id;
13700         cmdline_fixed_string_t on_off;
13701 };
13702
13703 /* Common CLI fields for tx loopback enable disable */
13704 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13705         TOKEN_STRING_INITIALIZER
13706                 (struct cmd_all_queues_drop_en_result,
13707                  set, "set");
13708 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13709         TOKEN_STRING_INITIALIZER
13710                 (struct cmd_all_queues_drop_en_result,
13711                  all, "all");
13712 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13713         TOKEN_STRING_INITIALIZER
13714                 (struct cmd_all_queues_drop_en_result,
13715                  queues, "queues");
13716 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13717         TOKEN_STRING_INITIALIZER
13718                 (struct cmd_all_queues_drop_en_result,
13719                  drop, "drop");
13720 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13721         TOKEN_NUM_INITIALIZER
13722                 (struct cmd_all_queues_drop_en_result,
13723                  port_id, UINT16);
13724 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13725         TOKEN_STRING_INITIALIZER
13726                 (struct cmd_all_queues_drop_en_result,
13727                  on_off, "on#off");
13728
13729 static void
13730 cmd_set_all_queues_drop_en_parsed(
13731         void *parsed_result,
13732         __attribute__((unused)) struct cmdline *cl,
13733         __attribute__((unused)) void *data)
13734 {
13735         struct cmd_all_queues_drop_en_result *res = parsed_result;
13736         int ret = -ENOTSUP;
13737         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13738
13739         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13740                 return;
13741
13742 #ifdef RTE_LIBRTE_IXGBE_PMD
13743         if (ret == -ENOTSUP)
13744                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13745 #endif
13746 #ifdef RTE_LIBRTE_BNXT_PMD
13747         if (ret == -ENOTSUP)
13748                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13749 #endif
13750         switch (ret) {
13751         case 0:
13752                 break;
13753         case -EINVAL:
13754                 printf("invalid is_on %d\n", is_on);
13755                 break;
13756         case -ENODEV:
13757                 printf("invalid port_id %d\n", res->port_id);
13758                 break;
13759         case -ENOTSUP:
13760                 printf("function not implemented\n");
13761                 break;
13762         default:
13763                 printf("programming error: (%s)\n", strerror(-ret));
13764         }
13765 }
13766
13767 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13768         .f = cmd_set_all_queues_drop_en_parsed,
13769         .data = NULL,
13770         .help_str = "set all queues drop <port_id> on|off",
13771         .tokens = {
13772                 (void *)&cmd_all_queues_drop_en_set,
13773                 (void *)&cmd_all_queues_drop_en_all,
13774                 (void *)&cmd_all_queues_drop_en_queues,
13775                 (void *)&cmd_all_queues_drop_en_drop,
13776                 (void *)&cmd_all_queues_drop_en_port_id,
13777                 (void *)&cmd_all_queues_drop_en_on_off,
13778                 NULL,
13779         },
13780 };
13781
13782 /* vf split drop enable configuration */
13783
13784 /* Common result structure for vf split drop enable */
13785 struct cmd_vf_split_drop_en_result {
13786         cmdline_fixed_string_t set;
13787         cmdline_fixed_string_t vf;
13788         cmdline_fixed_string_t split;
13789         cmdline_fixed_string_t drop;
13790         portid_t port_id;
13791         uint16_t vf_id;
13792         cmdline_fixed_string_t on_off;
13793 };
13794
13795 /* Common CLI fields for vf split drop enable disable */
13796 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13797         TOKEN_STRING_INITIALIZER
13798                 (struct cmd_vf_split_drop_en_result,
13799                  set, "set");
13800 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13801         TOKEN_STRING_INITIALIZER
13802                 (struct cmd_vf_split_drop_en_result,
13803                  vf, "vf");
13804 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13805         TOKEN_STRING_INITIALIZER
13806                 (struct cmd_vf_split_drop_en_result,
13807                  split, "split");
13808 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13809         TOKEN_STRING_INITIALIZER
13810                 (struct cmd_vf_split_drop_en_result,
13811                  drop, "drop");
13812 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13813         TOKEN_NUM_INITIALIZER
13814                 (struct cmd_vf_split_drop_en_result,
13815                  port_id, UINT16);
13816 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13817         TOKEN_NUM_INITIALIZER
13818                 (struct cmd_vf_split_drop_en_result,
13819                  vf_id, UINT16);
13820 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13821         TOKEN_STRING_INITIALIZER
13822                 (struct cmd_vf_split_drop_en_result,
13823                  on_off, "on#off");
13824
13825 static void
13826 cmd_set_vf_split_drop_en_parsed(
13827         void *parsed_result,
13828         __attribute__((unused)) struct cmdline *cl,
13829         __attribute__((unused)) void *data)
13830 {
13831         struct cmd_vf_split_drop_en_result *res = parsed_result;
13832         int ret = -ENOTSUP;
13833         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13834
13835         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13836                 return;
13837
13838 #ifdef RTE_LIBRTE_IXGBE_PMD
13839         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13840                         is_on);
13841 #endif
13842         switch (ret) {
13843         case 0:
13844                 break;
13845         case -EINVAL:
13846                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13847                 break;
13848         case -ENODEV:
13849                 printf("invalid port_id %d\n", res->port_id);
13850                 break;
13851         case -ENOTSUP:
13852                 printf("not supported on port %d\n", res->port_id);
13853                 break;
13854         default:
13855                 printf("programming error: (%s)\n", strerror(-ret));
13856         }
13857 }
13858
13859 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13860         .f = cmd_set_vf_split_drop_en_parsed,
13861         .data = NULL,
13862         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13863         .tokens = {
13864                 (void *)&cmd_vf_split_drop_en_set,
13865                 (void *)&cmd_vf_split_drop_en_vf,
13866                 (void *)&cmd_vf_split_drop_en_split,
13867                 (void *)&cmd_vf_split_drop_en_drop,
13868                 (void *)&cmd_vf_split_drop_en_port_id,
13869                 (void *)&cmd_vf_split_drop_en_vf_id,
13870                 (void *)&cmd_vf_split_drop_en_on_off,
13871                 NULL,
13872         },
13873 };
13874
13875 /* vf mac address configuration */
13876
13877 /* Common result structure for vf mac address */
13878 struct cmd_set_vf_mac_addr_result {
13879         cmdline_fixed_string_t set;
13880         cmdline_fixed_string_t vf;
13881         cmdline_fixed_string_t mac;
13882         cmdline_fixed_string_t addr;
13883         portid_t port_id;
13884         uint16_t vf_id;
13885         struct rte_ether_addr mac_addr;
13886
13887 };
13888
13889 /* Common CLI fields for vf split drop enable disable */
13890 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13891         TOKEN_STRING_INITIALIZER
13892                 (struct cmd_set_vf_mac_addr_result,
13893                  set, "set");
13894 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13895         TOKEN_STRING_INITIALIZER
13896                 (struct cmd_set_vf_mac_addr_result,
13897                  vf, "vf");
13898 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13899         TOKEN_STRING_INITIALIZER
13900                 (struct cmd_set_vf_mac_addr_result,
13901                  mac, "mac");
13902 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13903         TOKEN_STRING_INITIALIZER
13904                 (struct cmd_set_vf_mac_addr_result,
13905                  addr, "addr");
13906 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13907         TOKEN_NUM_INITIALIZER
13908                 (struct cmd_set_vf_mac_addr_result,
13909                  port_id, UINT16);
13910 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13911         TOKEN_NUM_INITIALIZER
13912                 (struct cmd_set_vf_mac_addr_result,
13913                  vf_id, UINT16);
13914 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13915         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13916                  mac_addr);
13917
13918 static void
13919 cmd_set_vf_mac_addr_parsed(
13920         void *parsed_result,
13921         __attribute__((unused)) struct cmdline *cl,
13922         __attribute__((unused)) void *data)
13923 {
13924         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13925         int ret = -ENOTSUP;
13926
13927         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13928                 return;
13929
13930 #ifdef RTE_LIBRTE_IXGBE_PMD
13931         if (ret == -ENOTSUP)
13932                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13933                                 &res->mac_addr);
13934 #endif
13935 #ifdef RTE_LIBRTE_I40E_PMD
13936         if (ret == -ENOTSUP)
13937                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13938                                 &res->mac_addr);
13939 #endif
13940 #ifdef RTE_LIBRTE_BNXT_PMD
13941         if (ret == -ENOTSUP)
13942                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13943                                 &res->mac_addr);
13944 #endif
13945
13946         switch (ret) {
13947         case 0:
13948                 break;
13949         case -EINVAL:
13950                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13951                 break;
13952         case -ENODEV:
13953                 printf("invalid port_id %d\n", res->port_id);
13954                 break;
13955         case -ENOTSUP:
13956                 printf("function not implemented\n");
13957                 break;
13958         default:
13959                 printf("programming error: (%s)\n", strerror(-ret));
13960         }
13961 }
13962
13963 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13964         .f = cmd_set_vf_mac_addr_parsed,
13965         .data = NULL,
13966         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13967         .tokens = {
13968                 (void *)&cmd_set_vf_mac_addr_set,
13969                 (void *)&cmd_set_vf_mac_addr_vf,
13970                 (void *)&cmd_set_vf_mac_addr_mac,
13971                 (void *)&cmd_set_vf_mac_addr_addr,
13972                 (void *)&cmd_set_vf_mac_addr_port_id,
13973                 (void *)&cmd_set_vf_mac_addr_vf_id,
13974                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13975                 NULL,
13976         },
13977 };
13978
13979 /* MACsec configuration */
13980
13981 /* Common result structure for MACsec offload enable */
13982 struct cmd_macsec_offload_on_result {
13983         cmdline_fixed_string_t set;
13984         cmdline_fixed_string_t macsec;
13985         cmdline_fixed_string_t offload;
13986         portid_t port_id;
13987         cmdline_fixed_string_t on;
13988         cmdline_fixed_string_t encrypt;
13989         cmdline_fixed_string_t en_on_off;
13990         cmdline_fixed_string_t replay_protect;
13991         cmdline_fixed_string_t rp_on_off;
13992 };
13993
13994 /* Common CLI fields for MACsec offload disable */
13995 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13996         TOKEN_STRING_INITIALIZER
13997                 (struct cmd_macsec_offload_on_result,
13998                  set, "set");
13999 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14000         TOKEN_STRING_INITIALIZER
14001                 (struct cmd_macsec_offload_on_result,
14002                  macsec, "macsec");
14003 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14004         TOKEN_STRING_INITIALIZER
14005                 (struct cmd_macsec_offload_on_result,
14006                  offload, "offload");
14007 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14008         TOKEN_NUM_INITIALIZER
14009                 (struct cmd_macsec_offload_on_result,
14010                  port_id, UINT16);
14011 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14012         TOKEN_STRING_INITIALIZER
14013                 (struct cmd_macsec_offload_on_result,
14014                  on, "on");
14015 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14016         TOKEN_STRING_INITIALIZER
14017                 (struct cmd_macsec_offload_on_result,
14018                  encrypt, "encrypt");
14019 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14020         TOKEN_STRING_INITIALIZER
14021                 (struct cmd_macsec_offload_on_result,
14022                  en_on_off, "on#off");
14023 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14024         TOKEN_STRING_INITIALIZER
14025                 (struct cmd_macsec_offload_on_result,
14026                  replay_protect, "replay-protect");
14027 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14028         TOKEN_STRING_INITIALIZER
14029                 (struct cmd_macsec_offload_on_result,
14030                  rp_on_off, "on#off");
14031
14032 static void
14033 cmd_set_macsec_offload_on_parsed(
14034         void *parsed_result,
14035         __attribute__((unused)) struct cmdline *cl,
14036         __attribute__((unused)) void *data)
14037 {
14038         struct cmd_macsec_offload_on_result *res = parsed_result;
14039         int ret = -ENOTSUP;
14040         portid_t port_id = res->port_id;
14041         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14042         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14043         struct rte_eth_dev_info dev_info;
14044
14045         if (port_id_is_invalid(port_id, ENABLED_WARN))
14046                 return;
14047         if (!port_is_stopped(port_id)) {
14048                 printf("Please stop port %d first\n", port_id);
14049                 return;
14050         }
14051
14052         rte_eth_dev_info_get(port_id, &dev_info);
14053         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14054 #ifdef RTE_LIBRTE_IXGBE_PMD
14055                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14056 #endif
14057         }
14058         RTE_SET_USED(en);
14059         RTE_SET_USED(rp);
14060
14061         switch (ret) {
14062         case 0:
14063                 ports[port_id].dev_conf.txmode.offloads |=
14064                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14065                 cmd_reconfig_device_queue(port_id, 1, 1);
14066                 break;
14067         case -ENODEV:
14068                 printf("invalid port_id %d\n", port_id);
14069                 break;
14070         case -ENOTSUP:
14071                 printf("not supported on port %d\n", port_id);
14072                 break;
14073         default:
14074                 printf("programming error: (%s)\n", strerror(-ret));
14075         }
14076 }
14077
14078 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14079         .f = cmd_set_macsec_offload_on_parsed,
14080         .data = NULL,
14081         .help_str = "set macsec offload <port_id> on "
14082                 "encrypt on|off replay-protect on|off",
14083         .tokens = {
14084                 (void *)&cmd_macsec_offload_on_set,
14085                 (void *)&cmd_macsec_offload_on_macsec,
14086                 (void *)&cmd_macsec_offload_on_offload,
14087                 (void *)&cmd_macsec_offload_on_port_id,
14088                 (void *)&cmd_macsec_offload_on_on,
14089                 (void *)&cmd_macsec_offload_on_encrypt,
14090                 (void *)&cmd_macsec_offload_on_en_on_off,
14091                 (void *)&cmd_macsec_offload_on_replay_protect,
14092                 (void *)&cmd_macsec_offload_on_rp_on_off,
14093                 NULL,
14094         },
14095 };
14096
14097 /* Common result structure for MACsec offload disable */
14098 struct cmd_macsec_offload_off_result {
14099         cmdline_fixed_string_t set;
14100         cmdline_fixed_string_t macsec;
14101         cmdline_fixed_string_t offload;
14102         portid_t port_id;
14103         cmdline_fixed_string_t off;
14104 };
14105
14106 /* Common CLI fields for MACsec offload disable */
14107 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14108         TOKEN_STRING_INITIALIZER
14109                 (struct cmd_macsec_offload_off_result,
14110                  set, "set");
14111 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14112         TOKEN_STRING_INITIALIZER
14113                 (struct cmd_macsec_offload_off_result,
14114                  macsec, "macsec");
14115 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14116         TOKEN_STRING_INITIALIZER
14117                 (struct cmd_macsec_offload_off_result,
14118                  offload, "offload");
14119 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14120         TOKEN_NUM_INITIALIZER
14121                 (struct cmd_macsec_offload_off_result,
14122                  port_id, UINT16);
14123 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14124         TOKEN_STRING_INITIALIZER
14125                 (struct cmd_macsec_offload_off_result,
14126                  off, "off");
14127
14128 static void
14129 cmd_set_macsec_offload_off_parsed(
14130         void *parsed_result,
14131         __attribute__((unused)) struct cmdline *cl,
14132         __attribute__((unused)) void *data)
14133 {
14134         struct cmd_macsec_offload_off_result *res = parsed_result;
14135         int ret = -ENOTSUP;
14136         struct rte_eth_dev_info dev_info;
14137         portid_t port_id = res->port_id;
14138
14139         if (port_id_is_invalid(port_id, ENABLED_WARN))
14140                 return;
14141         if (!port_is_stopped(port_id)) {
14142                 printf("Please stop port %d first\n", port_id);
14143                 return;
14144         }
14145
14146         rte_eth_dev_info_get(port_id, &dev_info);
14147         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14148 #ifdef RTE_LIBRTE_IXGBE_PMD
14149                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14150 #endif
14151         }
14152         switch (ret) {
14153         case 0:
14154                 ports[port_id].dev_conf.txmode.offloads &=
14155                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14156                 cmd_reconfig_device_queue(port_id, 1, 1);
14157                 break;
14158         case -ENODEV:
14159                 printf("invalid port_id %d\n", port_id);
14160                 break;
14161         case -ENOTSUP:
14162                 printf("not supported on port %d\n", port_id);
14163                 break;
14164         default:
14165                 printf("programming error: (%s)\n", strerror(-ret));
14166         }
14167 }
14168
14169 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14170         .f = cmd_set_macsec_offload_off_parsed,
14171         .data = NULL,
14172         .help_str = "set macsec offload <port_id> off",
14173         .tokens = {
14174                 (void *)&cmd_macsec_offload_off_set,
14175                 (void *)&cmd_macsec_offload_off_macsec,
14176                 (void *)&cmd_macsec_offload_off_offload,
14177                 (void *)&cmd_macsec_offload_off_port_id,
14178                 (void *)&cmd_macsec_offload_off_off,
14179                 NULL,
14180         },
14181 };
14182
14183 /* Common result structure for MACsec secure connection configure */
14184 struct cmd_macsec_sc_result {
14185         cmdline_fixed_string_t set;
14186         cmdline_fixed_string_t macsec;
14187         cmdline_fixed_string_t sc;
14188         cmdline_fixed_string_t tx_rx;
14189         portid_t port_id;
14190         struct rte_ether_addr mac;
14191         uint16_t pi;
14192 };
14193
14194 /* Common CLI fields for MACsec secure connection configure */
14195 cmdline_parse_token_string_t cmd_macsec_sc_set =
14196         TOKEN_STRING_INITIALIZER
14197                 (struct cmd_macsec_sc_result,
14198                  set, "set");
14199 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14200         TOKEN_STRING_INITIALIZER
14201                 (struct cmd_macsec_sc_result,
14202                  macsec, "macsec");
14203 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14204         TOKEN_STRING_INITIALIZER
14205                 (struct cmd_macsec_sc_result,
14206                  sc, "sc");
14207 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14208         TOKEN_STRING_INITIALIZER
14209                 (struct cmd_macsec_sc_result,
14210                  tx_rx, "tx#rx");
14211 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14212         TOKEN_NUM_INITIALIZER
14213                 (struct cmd_macsec_sc_result,
14214                  port_id, UINT16);
14215 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14216         TOKEN_ETHERADDR_INITIALIZER
14217                 (struct cmd_macsec_sc_result,
14218                  mac);
14219 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14220         TOKEN_NUM_INITIALIZER
14221                 (struct cmd_macsec_sc_result,
14222                  pi, UINT16);
14223
14224 static void
14225 cmd_set_macsec_sc_parsed(
14226         void *parsed_result,
14227         __attribute__((unused)) struct cmdline *cl,
14228         __attribute__((unused)) void *data)
14229 {
14230         struct cmd_macsec_sc_result *res = parsed_result;
14231         int ret = -ENOTSUP;
14232         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14233
14234 #ifdef RTE_LIBRTE_IXGBE_PMD
14235         ret = is_tx ?
14236                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14237                                 res->mac.addr_bytes) :
14238                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14239                                 res->mac.addr_bytes, res->pi);
14240 #endif
14241         RTE_SET_USED(is_tx);
14242
14243         switch (ret) {
14244         case 0:
14245                 break;
14246         case -ENODEV:
14247                 printf("invalid port_id %d\n", res->port_id);
14248                 break;
14249         case -ENOTSUP:
14250                 printf("not supported on port %d\n", res->port_id);
14251                 break;
14252         default:
14253                 printf("programming error: (%s)\n", strerror(-ret));
14254         }
14255 }
14256
14257 cmdline_parse_inst_t cmd_set_macsec_sc = {
14258         .f = cmd_set_macsec_sc_parsed,
14259         .data = NULL,
14260         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14261         .tokens = {
14262                 (void *)&cmd_macsec_sc_set,
14263                 (void *)&cmd_macsec_sc_macsec,
14264                 (void *)&cmd_macsec_sc_sc,
14265                 (void *)&cmd_macsec_sc_tx_rx,
14266                 (void *)&cmd_macsec_sc_port_id,
14267                 (void *)&cmd_macsec_sc_mac,
14268                 (void *)&cmd_macsec_sc_pi,
14269                 NULL,
14270         },
14271 };
14272
14273 /* Common result structure for MACsec secure connection configure */
14274 struct cmd_macsec_sa_result {
14275         cmdline_fixed_string_t set;
14276         cmdline_fixed_string_t macsec;
14277         cmdline_fixed_string_t sa;
14278         cmdline_fixed_string_t tx_rx;
14279         portid_t port_id;
14280         uint8_t idx;
14281         uint8_t an;
14282         uint32_t pn;
14283         cmdline_fixed_string_t key;
14284 };
14285
14286 /* Common CLI fields for MACsec secure connection configure */
14287 cmdline_parse_token_string_t cmd_macsec_sa_set =
14288         TOKEN_STRING_INITIALIZER
14289                 (struct cmd_macsec_sa_result,
14290                  set, "set");
14291 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14292         TOKEN_STRING_INITIALIZER
14293                 (struct cmd_macsec_sa_result,
14294                  macsec, "macsec");
14295 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14296         TOKEN_STRING_INITIALIZER
14297                 (struct cmd_macsec_sa_result,
14298                  sa, "sa");
14299 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14300         TOKEN_STRING_INITIALIZER
14301                 (struct cmd_macsec_sa_result,
14302                  tx_rx, "tx#rx");
14303 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14304         TOKEN_NUM_INITIALIZER
14305                 (struct cmd_macsec_sa_result,
14306                  port_id, UINT16);
14307 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14308         TOKEN_NUM_INITIALIZER
14309                 (struct cmd_macsec_sa_result,
14310                  idx, UINT8);
14311 cmdline_parse_token_num_t cmd_macsec_sa_an =
14312         TOKEN_NUM_INITIALIZER
14313                 (struct cmd_macsec_sa_result,
14314                  an, UINT8);
14315 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14316         TOKEN_NUM_INITIALIZER
14317                 (struct cmd_macsec_sa_result,
14318                  pn, UINT32);
14319 cmdline_parse_token_string_t cmd_macsec_sa_key =
14320         TOKEN_STRING_INITIALIZER
14321                 (struct cmd_macsec_sa_result,
14322                  key, NULL);
14323
14324 static void
14325 cmd_set_macsec_sa_parsed(
14326         void *parsed_result,
14327         __attribute__((unused)) struct cmdline *cl,
14328         __attribute__((unused)) void *data)
14329 {
14330         struct cmd_macsec_sa_result *res = parsed_result;
14331         int ret = -ENOTSUP;
14332         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14333         uint8_t key[16] = { 0 };
14334         uint8_t xdgt0;
14335         uint8_t xdgt1;
14336         int key_len;
14337         int i;
14338
14339         key_len = strlen(res->key) / 2;
14340         if (key_len > 16)
14341                 key_len = 16;
14342
14343         for (i = 0; i < key_len; i++) {
14344                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14345                 if (xdgt0 == 0xFF)
14346                         return;
14347                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14348                 if (xdgt1 == 0xFF)
14349                         return;
14350                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14351         }
14352
14353 #ifdef RTE_LIBRTE_IXGBE_PMD
14354         ret = is_tx ?
14355                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14356                         res->idx, res->an, res->pn, key) :
14357                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14358                         res->idx, res->an, res->pn, key);
14359 #endif
14360         RTE_SET_USED(is_tx);
14361         RTE_SET_USED(key);
14362
14363         switch (ret) {
14364         case 0:
14365                 break;
14366         case -EINVAL:
14367                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14368                 break;
14369         case -ENODEV:
14370                 printf("invalid port_id %d\n", res->port_id);
14371                 break;
14372         case -ENOTSUP:
14373                 printf("not supported on port %d\n", res->port_id);
14374                 break;
14375         default:
14376                 printf("programming error: (%s)\n", strerror(-ret));
14377         }
14378 }
14379
14380 cmdline_parse_inst_t cmd_set_macsec_sa = {
14381         .f = cmd_set_macsec_sa_parsed,
14382         .data = NULL,
14383         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14384         .tokens = {
14385                 (void *)&cmd_macsec_sa_set,
14386                 (void *)&cmd_macsec_sa_macsec,
14387                 (void *)&cmd_macsec_sa_sa,
14388                 (void *)&cmd_macsec_sa_tx_rx,
14389                 (void *)&cmd_macsec_sa_port_id,
14390                 (void *)&cmd_macsec_sa_idx,
14391                 (void *)&cmd_macsec_sa_an,
14392                 (void *)&cmd_macsec_sa_pn,
14393                 (void *)&cmd_macsec_sa_key,
14394                 NULL,
14395         },
14396 };
14397
14398 /* VF unicast promiscuous mode configuration */
14399
14400 /* Common result structure for VF unicast promiscuous mode */
14401 struct cmd_vf_promisc_result {
14402         cmdline_fixed_string_t set;
14403         cmdline_fixed_string_t vf;
14404         cmdline_fixed_string_t promisc;
14405         portid_t port_id;
14406         uint32_t vf_id;
14407         cmdline_fixed_string_t on_off;
14408 };
14409
14410 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14411 cmdline_parse_token_string_t cmd_vf_promisc_set =
14412         TOKEN_STRING_INITIALIZER
14413                 (struct cmd_vf_promisc_result,
14414                  set, "set");
14415 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14416         TOKEN_STRING_INITIALIZER
14417                 (struct cmd_vf_promisc_result,
14418                  vf, "vf");
14419 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14420         TOKEN_STRING_INITIALIZER
14421                 (struct cmd_vf_promisc_result,
14422                  promisc, "promisc");
14423 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14424         TOKEN_NUM_INITIALIZER
14425                 (struct cmd_vf_promisc_result,
14426                  port_id, UINT16);
14427 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14428         TOKEN_NUM_INITIALIZER
14429                 (struct cmd_vf_promisc_result,
14430                  vf_id, UINT32);
14431 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14432         TOKEN_STRING_INITIALIZER
14433                 (struct cmd_vf_promisc_result,
14434                  on_off, "on#off");
14435
14436 static void
14437 cmd_set_vf_promisc_parsed(
14438         void *parsed_result,
14439         __attribute__((unused)) struct cmdline *cl,
14440         __attribute__((unused)) void *data)
14441 {
14442         struct cmd_vf_promisc_result *res = parsed_result;
14443         int ret = -ENOTSUP;
14444
14445         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14446
14447         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14448                 return;
14449
14450 #ifdef RTE_LIBRTE_I40E_PMD
14451         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14452                                                   res->vf_id, is_on);
14453 #endif
14454
14455         switch (ret) {
14456         case 0:
14457                 break;
14458         case -EINVAL:
14459                 printf("invalid vf_id %d\n", res->vf_id);
14460                 break;
14461         case -ENODEV:
14462                 printf("invalid port_id %d\n", res->port_id);
14463                 break;
14464         case -ENOTSUP:
14465                 printf("function not implemented\n");
14466                 break;
14467         default:
14468                 printf("programming error: (%s)\n", strerror(-ret));
14469         }
14470 }
14471
14472 cmdline_parse_inst_t cmd_set_vf_promisc = {
14473         .f = cmd_set_vf_promisc_parsed,
14474         .data = NULL,
14475         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14476                 "Set unicast promiscuous mode for a VF from the PF",
14477         .tokens = {
14478                 (void *)&cmd_vf_promisc_set,
14479                 (void *)&cmd_vf_promisc_vf,
14480                 (void *)&cmd_vf_promisc_promisc,
14481                 (void *)&cmd_vf_promisc_port_id,
14482                 (void *)&cmd_vf_promisc_vf_id,
14483                 (void *)&cmd_vf_promisc_on_off,
14484                 NULL,
14485         },
14486 };
14487
14488 /* VF multicast promiscuous mode configuration */
14489
14490 /* Common result structure for VF multicast promiscuous mode */
14491 struct cmd_vf_allmulti_result {
14492         cmdline_fixed_string_t set;
14493         cmdline_fixed_string_t vf;
14494         cmdline_fixed_string_t allmulti;
14495         portid_t port_id;
14496         uint32_t vf_id;
14497         cmdline_fixed_string_t on_off;
14498 };
14499
14500 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14501 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14502         TOKEN_STRING_INITIALIZER
14503                 (struct cmd_vf_allmulti_result,
14504                  set, "set");
14505 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14506         TOKEN_STRING_INITIALIZER
14507                 (struct cmd_vf_allmulti_result,
14508                  vf, "vf");
14509 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14510         TOKEN_STRING_INITIALIZER
14511                 (struct cmd_vf_allmulti_result,
14512                  allmulti, "allmulti");
14513 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14514         TOKEN_NUM_INITIALIZER
14515                 (struct cmd_vf_allmulti_result,
14516                  port_id, UINT16);
14517 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14518         TOKEN_NUM_INITIALIZER
14519                 (struct cmd_vf_allmulti_result,
14520                  vf_id, UINT32);
14521 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14522         TOKEN_STRING_INITIALIZER
14523                 (struct cmd_vf_allmulti_result,
14524                  on_off, "on#off");
14525
14526 static void
14527 cmd_set_vf_allmulti_parsed(
14528         void *parsed_result,
14529         __attribute__((unused)) struct cmdline *cl,
14530         __attribute__((unused)) void *data)
14531 {
14532         struct cmd_vf_allmulti_result *res = parsed_result;
14533         int ret = -ENOTSUP;
14534
14535         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14536
14537         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14538                 return;
14539
14540 #ifdef RTE_LIBRTE_I40E_PMD
14541         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14542                                                     res->vf_id, is_on);
14543 #endif
14544
14545         switch (ret) {
14546         case 0:
14547                 break;
14548         case -EINVAL:
14549                 printf("invalid vf_id %d\n", res->vf_id);
14550                 break;
14551         case -ENODEV:
14552                 printf("invalid port_id %d\n", res->port_id);
14553                 break;
14554         case -ENOTSUP:
14555                 printf("function not implemented\n");
14556                 break;
14557         default:
14558                 printf("programming error: (%s)\n", strerror(-ret));
14559         }
14560 }
14561
14562 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14563         .f = cmd_set_vf_allmulti_parsed,
14564         .data = NULL,
14565         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14566                 "Set multicast promiscuous mode for a VF from the PF",
14567         .tokens = {
14568                 (void *)&cmd_vf_allmulti_set,
14569                 (void *)&cmd_vf_allmulti_vf,
14570                 (void *)&cmd_vf_allmulti_allmulti,
14571                 (void *)&cmd_vf_allmulti_port_id,
14572                 (void *)&cmd_vf_allmulti_vf_id,
14573                 (void *)&cmd_vf_allmulti_on_off,
14574                 NULL,
14575         },
14576 };
14577
14578 /* vf broadcast mode configuration */
14579
14580 /* Common result structure for vf broadcast */
14581 struct cmd_set_vf_broadcast_result {
14582         cmdline_fixed_string_t set;
14583         cmdline_fixed_string_t vf;
14584         cmdline_fixed_string_t broadcast;
14585         portid_t port_id;
14586         uint16_t vf_id;
14587         cmdline_fixed_string_t on_off;
14588 };
14589
14590 /* Common CLI fields for vf broadcast enable disable */
14591 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14592         TOKEN_STRING_INITIALIZER
14593                 (struct cmd_set_vf_broadcast_result,
14594                  set, "set");
14595 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14596         TOKEN_STRING_INITIALIZER
14597                 (struct cmd_set_vf_broadcast_result,
14598                  vf, "vf");
14599 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14600         TOKEN_STRING_INITIALIZER
14601                 (struct cmd_set_vf_broadcast_result,
14602                  broadcast, "broadcast");
14603 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14604         TOKEN_NUM_INITIALIZER
14605                 (struct cmd_set_vf_broadcast_result,
14606                  port_id, UINT16);
14607 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14608         TOKEN_NUM_INITIALIZER
14609                 (struct cmd_set_vf_broadcast_result,
14610                  vf_id, UINT16);
14611 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14612         TOKEN_STRING_INITIALIZER
14613                 (struct cmd_set_vf_broadcast_result,
14614                  on_off, "on#off");
14615
14616 static void
14617 cmd_set_vf_broadcast_parsed(
14618         void *parsed_result,
14619         __attribute__((unused)) struct cmdline *cl,
14620         __attribute__((unused)) void *data)
14621 {
14622         struct cmd_set_vf_broadcast_result *res = parsed_result;
14623         int ret = -ENOTSUP;
14624
14625         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14626
14627         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14628                 return;
14629
14630 #ifdef RTE_LIBRTE_I40E_PMD
14631         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14632                                             res->vf_id, is_on);
14633 #endif
14634
14635         switch (ret) {
14636         case 0:
14637                 break;
14638         case -EINVAL:
14639                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14640                 break;
14641         case -ENODEV:
14642                 printf("invalid port_id %d\n", res->port_id);
14643                 break;
14644         case -ENOTSUP:
14645                 printf("function not implemented\n");
14646                 break;
14647         default:
14648                 printf("programming error: (%s)\n", strerror(-ret));
14649         }
14650 }
14651
14652 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14653         .f = cmd_set_vf_broadcast_parsed,
14654         .data = NULL,
14655         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14656         .tokens = {
14657                 (void *)&cmd_set_vf_broadcast_set,
14658                 (void *)&cmd_set_vf_broadcast_vf,
14659                 (void *)&cmd_set_vf_broadcast_broadcast,
14660                 (void *)&cmd_set_vf_broadcast_port_id,
14661                 (void *)&cmd_set_vf_broadcast_vf_id,
14662                 (void *)&cmd_set_vf_broadcast_on_off,
14663                 NULL,
14664         },
14665 };
14666
14667 /* vf vlan tag configuration */
14668
14669 /* Common result structure for vf vlan tag */
14670 struct cmd_set_vf_vlan_tag_result {
14671         cmdline_fixed_string_t set;
14672         cmdline_fixed_string_t vf;
14673         cmdline_fixed_string_t vlan;
14674         cmdline_fixed_string_t tag;
14675         portid_t port_id;
14676         uint16_t vf_id;
14677         cmdline_fixed_string_t on_off;
14678 };
14679
14680 /* Common CLI fields for vf vlan tag enable disable */
14681 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14682         TOKEN_STRING_INITIALIZER
14683                 (struct cmd_set_vf_vlan_tag_result,
14684                  set, "set");
14685 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14686         TOKEN_STRING_INITIALIZER
14687                 (struct cmd_set_vf_vlan_tag_result,
14688                  vf, "vf");
14689 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14690         TOKEN_STRING_INITIALIZER
14691                 (struct cmd_set_vf_vlan_tag_result,
14692                  vlan, "vlan");
14693 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14694         TOKEN_STRING_INITIALIZER
14695                 (struct cmd_set_vf_vlan_tag_result,
14696                  tag, "tag");
14697 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14698         TOKEN_NUM_INITIALIZER
14699                 (struct cmd_set_vf_vlan_tag_result,
14700                  port_id, UINT16);
14701 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14702         TOKEN_NUM_INITIALIZER
14703                 (struct cmd_set_vf_vlan_tag_result,
14704                  vf_id, UINT16);
14705 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14706         TOKEN_STRING_INITIALIZER
14707                 (struct cmd_set_vf_vlan_tag_result,
14708                  on_off, "on#off");
14709
14710 static void
14711 cmd_set_vf_vlan_tag_parsed(
14712         void *parsed_result,
14713         __attribute__((unused)) struct cmdline *cl,
14714         __attribute__((unused)) void *data)
14715 {
14716         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14717         int ret = -ENOTSUP;
14718
14719         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14720
14721         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14722                 return;
14723
14724 #ifdef RTE_LIBRTE_I40E_PMD
14725         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14726                                            res->vf_id, is_on);
14727 #endif
14728
14729         switch (ret) {
14730         case 0:
14731                 break;
14732         case -EINVAL:
14733                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14734                 break;
14735         case -ENODEV:
14736                 printf("invalid port_id %d\n", res->port_id);
14737                 break;
14738         case -ENOTSUP:
14739                 printf("function not implemented\n");
14740                 break;
14741         default:
14742                 printf("programming error: (%s)\n", strerror(-ret));
14743         }
14744 }
14745
14746 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14747         .f = cmd_set_vf_vlan_tag_parsed,
14748         .data = NULL,
14749         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14750         .tokens = {
14751                 (void *)&cmd_set_vf_vlan_tag_set,
14752                 (void *)&cmd_set_vf_vlan_tag_vf,
14753                 (void *)&cmd_set_vf_vlan_tag_vlan,
14754                 (void *)&cmd_set_vf_vlan_tag_tag,
14755                 (void *)&cmd_set_vf_vlan_tag_port_id,
14756                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14757                 (void *)&cmd_set_vf_vlan_tag_on_off,
14758                 NULL,
14759         },
14760 };
14761
14762 /* Common definition of VF and TC TX bandwidth configuration */
14763 struct cmd_vf_tc_bw_result {
14764         cmdline_fixed_string_t set;
14765         cmdline_fixed_string_t vf;
14766         cmdline_fixed_string_t tc;
14767         cmdline_fixed_string_t tx;
14768         cmdline_fixed_string_t min_bw;
14769         cmdline_fixed_string_t max_bw;
14770         cmdline_fixed_string_t strict_link_prio;
14771         portid_t port_id;
14772         uint16_t vf_id;
14773         uint8_t tc_no;
14774         uint32_t bw;
14775         cmdline_fixed_string_t bw_list;
14776         uint8_t tc_map;
14777 };
14778
14779 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14780         TOKEN_STRING_INITIALIZER
14781                 (struct cmd_vf_tc_bw_result,
14782                  set, "set");
14783 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14784         TOKEN_STRING_INITIALIZER
14785                 (struct cmd_vf_tc_bw_result,
14786                  vf, "vf");
14787 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14788         TOKEN_STRING_INITIALIZER
14789                 (struct cmd_vf_tc_bw_result,
14790                  tc, "tc");
14791 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14792         TOKEN_STRING_INITIALIZER
14793                 (struct cmd_vf_tc_bw_result,
14794                  tx, "tx");
14795 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14796         TOKEN_STRING_INITIALIZER
14797                 (struct cmd_vf_tc_bw_result,
14798                  strict_link_prio, "strict-link-priority");
14799 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14800         TOKEN_STRING_INITIALIZER
14801                 (struct cmd_vf_tc_bw_result,
14802                  min_bw, "min-bandwidth");
14803 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14804         TOKEN_STRING_INITIALIZER
14805                 (struct cmd_vf_tc_bw_result,
14806                  max_bw, "max-bandwidth");
14807 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14808         TOKEN_NUM_INITIALIZER
14809                 (struct cmd_vf_tc_bw_result,
14810                  port_id, UINT16);
14811 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14812         TOKEN_NUM_INITIALIZER
14813                 (struct cmd_vf_tc_bw_result,
14814                  vf_id, UINT16);
14815 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14816         TOKEN_NUM_INITIALIZER
14817                 (struct cmd_vf_tc_bw_result,
14818                  tc_no, UINT8);
14819 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14820         TOKEN_NUM_INITIALIZER
14821                 (struct cmd_vf_tc_bw_result,
14822                  bw, UINT32);
14823 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14824         TOKEN_STRING_INITIALIZER
14825                 (struct cmd_vf_tc_bw_result,
14826                  bw_list, NULL);
14827 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14828         TOKEN_NUM_INITIALIZER
14829                 (struct cmd_vf_tc_bw_result,
14830                  tc_map, UINT8);
14831
14832 /* VF max bandwidth setting */
14833 static void
14834 cmd_vf_max_bw_parsed(
14835         void *parsed_result,
14836         __attribute__((unused)) struct cmdline *cl,
14837         __attribute__((unused)) void *data)
14838 {
14839         struct cmd_vf_tc_bw_result *res = parsed_result;
14840         int ret = -ENOTSUP;
14841
14842         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14843                 return;
14844
14845 #ifdef RTE_LIBRTE_I40E_PMD
14846         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14847                                          res->vf_id, res->bw);
14848 #endif
14849
14850         switch (ret) {
14851         case 0:
14852                 break;
14853         case -EINVAL:
14854                 printf("invalid vf_id %d or bandwidth %d\n",
14855                        res->vf_id, res->bw);
14856                 break;
14857         case -ENODEV:
14858                 printf("invalid port_id %d\n", res->port_id);
14859                 break;
14860         case -ENOTSUP:
14861                 printf("function not implemented\n");
14862                 break;
14863         default:
14864                 printf("programming error: (%s)\n", strerror(-ret));
14865         }
14866 }
14867
14868 cmdline_parse_inst_t cmd_vf_max_bw = {
14869         .f = cmd_vf_max_bw_parsed,
14870         .data = NULL,
14871         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14872         .tokens = {
14873                 (void *)&cmd_vf_tc_bw_set,
14874                 (void *)&cmd_vf_tc_bw_vf,
14875                 (void *)&cmd_vf_tc_bw_tx,
14876                 (void *)&cmd_vf_tc_bw_max_bw,
14877                 (void *)&cmd_vf_tc_bw_port_id,
14878                 (void *)&cmd_vf_tc_bw_vf_id,
14879                 (void *)&cmd_vf_tc_bw_bw,
14880                 NULL,
14881         },
14882 };
14883
14884 static int
14885 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14886                            uint8_t *tc_num,
14887                            char *str)
14888 {
14889         uint32_t size;
14890         const char *p, *p0 = str;
14891         char s[256];
14892         char *end;
14893         char *str_fld[16];
14894         uint16_t i;
14895         int ret;
14896
14897         p = strchr(p0, '(');
14898         if (p == NULL) {
14899                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14900                 return -1;
14901         }
14902         p++;
14903         p0 = strchr(p, ')');
14904         if (p0 == NULL) {
14905                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14906                 return -1;
14907         }
14908         size = p0 - p;
14909         if (size >= sizeof(s)) {
14910                 printf("The string size exceeds the internal buffer size\n");
14911                 return -1;
14912         }
14913         snprintf(s, sizeof(s), "%.*s", size, p);
14914         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14915         if (ret <= 0) {
14916                 printf("Failed to get the bandwidth list. ");
14917                 return -1;
14918         }
14919         *tc_num = ret;
14920         for (i = 0; i < ret; i++)
14921                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14922
14923         return 0;
14924 }
14925
14926 /* TC min bandwidth setting */
14927 static void
14928 cmd_vf_tc_min_bw_parsed(
14929         void *parsed_result,
14930         __attribute__((unused)) struct cmdline *cl,
14931         __attribute__((unused)) void *data)
14932 {
14933         struct cmd_vf_tc_bw_result *res = parsed_result;
14934         uint8_t tc_num;
14935         uint8_t bw[16];
14936         int ret = -ENOTSUP;
14937
14938         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14939                 return;
14940
14941         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14942         if (ret)
14943                 return;
14944
14945 #ifdef RTE_LIBRTE_I40E_PMD
14946         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14947                                               tc_num, bw);
14948 #endif
14949
14950         switch (ret) {
14951         case 0:
14952                 break;
14953         case -EINVAL:
14954                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14955                 break;
14956         case -ENODEV:
14957                 printf("invalid port_id %d\n", res->port_id);
14958                 break;
14959         case -ENOTSUP:
14960                 printf("function not implemented\n");
14961                 break;
14962         default:
14963                 printf("programming error: (%s)\n", strerror(-ret));
14964         }
14965 }
14966
14967 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14968         .f = cmd_vf_tc_min_bw_parsed,
14969         .data = NULL,
14970         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14971                     " <bw1, bw2, ...>",
14972         .tokens = {
14973                 (void *)&cmd_vf_tc_bw_set,
14974                 (void *)&cmd_vf_tc_bw_vf,
14975                 (void *)&cmd_vf_tc_bw_tc,
14976                 (void *)&cmd_vf_tc_bw_tx,
14977                 (void *)&cmd_vf_tc_bw_min_bw,
14978                 (void *)&cmd_vf_tc_bw_port_id,
14979                 (void *)&cmd_vf_tc_bw_vf_id,
14980                 (void *)&cmd_vf_tc_bw_bw_list,
14981                 NULL,
14982         },
14983 };
14984
14985 static void
14986 cmd_tc_min_bw_parsed(
14987         void *parsed_result,
14988         __attribute__((unused)) struct cmdline *cl,
14989         __attribute__((unused)) void *data)
14990 {
14991         struct cmd_vf_tc_bw_result *res = parsed_result;
14992         struct rte_port *port;
14993         uint8_t tc_num;
14994         uint8_t bw[16];
14995         int ret = -ENOTSUP;
14996
14997         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14998                 return;
14999
15000         port = &ports[res->port_id];
15001         /** Check if the port is not started **/
15002         if (port->port_status != RTE_PORT_STOPPED) {
15003                 printf("Please stop port %d first\n", res->port_id);
15004                 return;
15005         }
15006
15007         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15008         if (ret)
15009                 return;
15010
15011 #ifdef RTE_LIBRTE_IXGBE_PMD
15012         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15013 #endif
15014
15015         switch (ret) {
15016         case 0:
15017                 break;
15018         case -EINVAL:
15019                 printf("invalid bandwidth\n");
15020                 break;
15021         case -ENODEV:
15022                 printf("invalid port_id %d\n", res->port_id);
15023                 break;
15024         case -ENOTSUP:
15025                 printf("function not implemented\n");
15026                 break;
15027         default:
15028                 printf("programming error: (%s)\n", strerror(-ret));
15029         }
15030 }
15031
15032 cmdline_parse_inst_t cmd_tc_min_bw = {
15033         .f = cmd_tc_min_bw_parsed,
15034         .data = NULL,
15035         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15036         .tokens = {
15037                 (void *)&cmd_vf_tc_bw_set,
15038                 (void *)&cmd_vf_tc_bw_tc,
15039                 (void *)&cmd_vf_tc_bw_tx,
15040                 (void *)&cmd_vf_tc_bw_min_bw,
15041                 (void *)&cmd_vf_tc_bw_port_id,
15042                 (void *)&cmd_vf_tc_bw_bw_list,
15043                 NULL,
15044         },
15045 };
15046
15047 /* TC max bandwidth setting */
15048 static void
15049 cmd_vf_tc_max_bw_parsed(
15050         void *parsed_result,
15051         __attribute__((unused)) struct cmdline *cl,
15052         __attribute__((unused)) void *data)
15053 {
15054         struct cmd_vf_tc_bw_result *res = parsed_result;
15055         int ret = -ENOTSUP;
15056
15057         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15058                 return;
15059
15060 #ifdef RTE_LIBRTE_I40E_PMD
15061         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15062                                             res->tc_no, res->bw);
15063 #endif
15064
15065         switch (ret) {
15066         case 0:
15067                 break;
15068         case -EINVAL:
15069                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15070                        res->vf_id, res->tc_no, res->bw);
15071                 break;
15072         case -ENODEV:
15073                 printf("invalid port_id %d\n", res->port_id);
15074                 break;
15075         case -ENOTSUP:
15076                 printf("function not implemented\n");
15077                 break;
15078         default:
15079                 printf("programming error: (%s)\n", strerror(-ret));
15080         }
15081 }
15082
15083 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15084         .f = cmd_vf_tc_max_bw_parsed,
15085         .data = NULL,
15086         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15087                     " <bandwidth>",
15088         .tokens = {
15089                 (void *)&cmd_vf_tc_bw_set,
15090                 (void *)&cmd_vf_tc_bw_vf,
15091                 (void *)&cmd_vf_tc_bw_tc,
15092                 (void *)&cmd_vf_tc_bw_tx,
15093                 (void *)&cmd_vf_tc_bw_max_bw,
15094                 (void *)&cmd_vf_tc_bw_port_id,
15095                 (void *)&cmd_vf_tc_bw_vf_id,
15096                 (void *)&cmd_vf_tc_bw_tc_no,
15097                 (void *)&cmd_vf_tc_bw_bw,
15098                 NULL,
15099         },
15100 };
15101
15102
15103 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15104
15105 /* *** Set Port default Traffic Management Hierarchy *** */
15106 struct cmd_set_port_tm_hierarchy_default_result {
15107         cmdline_fixed_string_t set;
15108         cmdline_fixed_string_t port;
15109         cmdline_fixed_string_t tm;
15110         cmdline_fixed_string_t hierarchy;
15111         cmdline_fixed_string_t def;
15112         portid_t port_id;
15113 };
15114
15115 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15116         TOKEN_STRING_INITIALIZER(
15117                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15118 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15119         TOKEN_STRING_INITIALIZER(
15120                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15121 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15122         TOKEN_STRING_INITIALIZER(
15123                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15124 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15125         TOKEN_STRING_INITIALIZER(
15126                 struct cmd_set_port_tm_hierarchy_default_result,
15127                         hierarchy, "hierarchy");
15128 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15129         TOKEN_STRING_INITIALIZER(
15130                 struct cmd_set_port_tm_hierarchy_default_result,
15131                         def, "default");
15132 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15133         TOKEN_NUM_INITIALIZER(
15134                 struct cmd_set_port_tm_hierarchy_default_result,
15135                         port_id, UINT16);
15136
15137 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15138         __attribute__((unused)) struct cmdline *cl,
15139         __attribute__((unused)) void *data)
15140 {
15141         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15142         struct rte_port *p;
15143         portid_t port_id = res->port_id;
15144
15145         if (port_id_is_invalid(port_id, ENABLED_WARN))
15146                 return;
15147
15148         p = &ports[port_id];
15149
15150         /* Forward mode: tm */
15151         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15152                 printf("  softnicfwd mode not enabled(error)\n");
15153                 return;
15154         }
15155
15156         /* Set the default tm hierarchy */
15157         p->softport.default_tm_hierarchy_enable = 1;
15158 }
15159
15160 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15161         .f = cmd_set_port_tm_hierarchy_default_parsed,
15162         .data = NULL,
15163         .help_str = "set port tm hierarchy default <port_id>",
15164         .tokens = {
15165                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15166                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15167                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15168                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15169                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15170                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15171                 NULL,
15172         },
15173 };
15174 #endif
15175
15176 /** Set VXLAN encapsulation details */
15177 struct cmd_set_vxlan_result {
15178         cmdline_fixed_string_t set;
15179         cmdline_fixed_string_t vxlan;
15180         cmdline_fixed_string_t pos_token;
15181         cmdline_fixed_string_t ip_version;
15182         uint32_t vlan_present:1;
15183         uint32_t vni;
15184         uint16_t udp_src;
15185         uint16_t udp_dst;
15186         cmdline_ipaddr_t ip_src;
15187         cmdline_ipaddr_t ip_dst;
15188         uint16_t tci;
15189         uint8_t tos;
15190         uint8_t ttl;
15191         struct rte_ether_addr eth_src;
15192         struct rte_ether_addr eth_dst;
15193 };
15194
15195 cmdline_parse_token_string_t cmd_set_vxlan_set =
15196         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15197 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15198         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15199 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15200         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15201                                  "vxlan-tos-ttl");
15202 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15203         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15204                                  "vxlan-with-vlan");
15205 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15206         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15207                                  "ip-version");
15208 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15209         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15210                                  "ipv4#ipv6");
15211 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15212         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15213                                  "vni");
15214 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15215         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15216 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15217         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15218                                  "udp-src");
15219 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15220         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15221 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15222         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15223                                  "udp-dst");
15224 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15225         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15226 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15227         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15228                                  "ip-tos");
15229 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15230         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15231 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15232         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15233                                  "ip-ttl");
15234 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15235         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15236 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15237         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15238                                  "ip-src");
15239 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15240         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15241 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15242         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15243                                  "ip-dst");
15244 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15245         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15246 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15247         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15248                                  "vlan-tci");
15249 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15250         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15251 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15252         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15253                                  "eth-src");
15254 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15255         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15256 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15257         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15258                                  "eth-dst");
15259 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15260         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15261
15262 static void cmd_set_vxlan_parsed(void *parsed_result,
15263         __attribute__((unused)) struct cmdline *cl,
15264         __attribute__((unused)) void *data)
15265 {
15266         struct cmd_set_vxlan_result *res = parsed_result;
15267         union {
15268                 uint32_t vxlan_id;
15269                 uint8_t vni[4];
15270         } id = {
15271                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15272         };
15273
15274         vxlan_encap_conf.select_tos_ttl = 0;
15275         if (strcmp(res->vxlan, "vxlan") == 0)
15276                 vxlan_encap_conf.select_vlan = 0;
15277         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15278                 vxlan_encap_conf.select_vlan = 1;
15279         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15280                 vxlan_encap_conf.select_vlan = 0;
15281                 vxlan_encap_conf.select_tos_ttl = 1;
15282         }
15283         if (strcmp(res->ip_version, "ipv4") == 0)
15284                 vxlan_encap_conf.select_ipv4 = 1;
15285         else if (strcmp(res->ip_version, "ipv6") == 0)
15286                 vxlan_encap_conf.select_ipv4 = 0;
15287         else
15288                 return;
15289         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15290         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15291         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15292         vxlan_encap_conf.ip_tos = res->tos;
15293         vxlan_encap_conf.ip_ttl = res->ttl;
15294         if (vxlan_encap_conf.select_ipv4) {
15295                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15296                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15297         } else {
15298                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15299                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15300         }
15301         if (vxlan_encap_conf.select_vlan)
15302                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15303         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15304                    ETHER_ADDR_LEN);
15305         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15306                    ETHER_ADDR_LEN);
15307 }
15308
15309 cmdline_parse_inst_t cmd_set_vxlan = {
15310         .f = cmd_set_vxlan_parsed,
15311         .data = NULL,
15312         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15313                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15314                 " eth-src <eth-src> eth-dst <eth-dst>",
15315         .tokens = {
15316                 (void *)&cmd_set_vxlan_set,
15317                 (void *)&cmd_set_vxlan_vxlan,
15318                 (void *)&cmd_set_vxlan_ip_version,
15319                 (void *)&cmd_set_vxlan_ip_version_value,
15320                 (void *)&cmd_set_vxlan_vni,
15321                 (void *)&cmd_set_vxlan_vni_value,
15322                 (void *)&cmd_set_vxlan_udp_src,
15323                 (void *)&cmd_set_vxlan_udp_src_value,
15324                 (void *)&cmd_set_vxlan_udp_dst,
15325                 (void *)&cmd_set_vxlan_udp_dst_value,
15326                 (void *)&cmd_set_vxlan_ip_src,
15327                 (void *)&cmd_set_vxlan_ip_src_value,
15328                 (void *)&cmd_set_vxlan_ip_dst,
15329                 (void *)&cmd_set_vxlan_ip_dst_value,
15330                 (void *)&cmd_set_vxlan_eth_src,
15331                 (void *)&cmd_set_vxlan_eth_src_value,
15332                 (void *)&cmd_set_vxlan_eth_dst,
15333                 (void *)&cmd_set_vxlan_eth_dst_value,
15334                 NULL,
15335         },
15336 };
15337
15338 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15339         .f = cmd_set_vxlan_parsed,
15340         .data = NULL,
15341         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15342                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15343                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15344                 " eth-dst <eth-dst>",
15345         .tokens = {
15346                 (void *)&cmd_set_vxlan_set,
15347                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15348                 (void *)&cmd_set_vxlan_ip_version,
15349                 (void *)&cmd_set_vxlan_ip_version_value,
15350                 (void *)&cmd_set_vxlan_vni,
15351                 (void *)&cmd_set_vxlan_vni_value,
15352                 (void *)&cmd_set_vxlan_udp_src,
15353                 (void *)&cmd_set_vxlan_udp_src_value,
15354                 (void *)&cmd_set_vxlan_udp_dst,
15355                 (void *)&cmd_set_vxlan_udp_dst_value,
15356                 (void *)&cmd_set_vxlan_ip_tos,
15357                 (void *)&cmd_set_vxlan_ip_tos_value,
15358                 (void *)&cmd_set_vxlan_ip_ttl,
15359                 (void *)&cmd_set_vxlan_ip_ttl_value,
15360                 (void *)&cmd_set_vxlan_ip_src,
15361                 (void *)&cmd_set_vxlan_ip_src_value,
15362                 (void *)&cmd_set_vxlan_ip_dst,
15363                 (void *)&cmd_set_vxlan_ip_dst_value,
15364                 (void *)&cmd_set_vxlan_eth_src,
15365                 (void *)&cmd_set_vxlan_eth_src_value,
15366                 (void *)&cmd_set_vxlan_eth_dst,
15367                 (void *)&cmd_set_vxlan_eth_dst_value,
15368                 NULL,
15369         },
15370 };
15371
15372 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15373         .f = cmd_set_vxlan_parsed,
15374         .data = NULL,
15375         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15376                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15377                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15378                 " <eth-dst>",
15379         .tokens = {
15380                 (void *)&cmd_set_vxlan_set,
15381                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15382                 (void *)&cmd_set_vxlan_ip_version,
15383                 (void *)&cmd_set_vxlan_ip_version_value,
15384                 (void *)&cmd_set_vxlan_vni,
15385                 (void *)&cmd_set_vxlan_vni_value,
15386                 (void *)&cmd_set_vxlan_udp_src,
15387                 (void *)&cmd_set_vxlan_udp_src_value,
15388                 (void *)&cmd_set_vxlan_udp_dst,
15389                 (void *)&cmd_set_vxlan_udp_dst_value,
15390                 (void *)&cmd_set_vxlan_ip_src,
15391                 (void *)&cmd_set_vxlan_ip_src_value,
15392                 (void *)&cmd_set_vxlan_ip_dst,
15393                 (void *)&cmd_set_vxlan_ip_dst_value,
15394                 (void *)&cmd_set_vxlan_vlan,
15395                 (void *)&cmd_set_vxlan_vlan_value,
15396                 (void *)&cmd_set_vxlan_eth_src,
15397                 (void *)&cmd_set_vxlan_eth_src_value,
15398                 (void *)&cmd_set_vxlan_eth_dst,
15399                 (void *)&cmd_set_vxlan_eth_dst_value,
15400                 NULL,
15401         },
15402 };
15403
15404 /** Set NVGRE encapsulation details */
15405 struct cmd_set_nvgre_result {
15406         cmdline_fixed_string_t set;
15407         cmdline_fixed_string_t nvgre;
15408         cmdline_fixed_string_t pos_token;
15409         cmdline_fixed_string_t ip_version;
15410         uint32_t tni;
15411         cmdline_ipaddr_t ip_src;
15412         cmdline_ipaddr_t ip_dst;
15413         uint16_t tci;
15414         struct rte_ether_addr eth_src;
15415         struct rte_ether_addr eth_dst;
15416 };
15417
15418 cmdline_parse_token_string_t cmd_set_nvgre_set =
15419         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15420 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15421         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15422 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15423         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15424                                  "nvgre-with-vlan");
15425 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15426         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15427                                  "ip-version");
15428 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15429         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15430                                  "ipv4#ipv6");
15431 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15432         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15433                                  "tni");
15434 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15435         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15436 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15437         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15438                                  "ip-src");
15439 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15440         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15441 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15442         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15443                                  "ip-dst");
15444 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15445         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15446 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15447         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15448                                  "vlan-tci");
15449 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15450         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15451 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15452         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15453                                  "eth-src");
15454 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15455         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15456 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15457         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15458                                  "eth-dst");
15459 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15460         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15461
15462 static void cmd_set_nvgre_parsed(void *parsed_result,
15463         __attribute__((unused)) struct cmdline *cl,
15464         __attribute__((unused)) void *data)
15465 {
15466         struct cmd_set_nvgre_result *res = parsed_result;
15467         union {
15468                 uint32_t nvgre_tni;
15469                 uint8_t tni[4];
15470         } id = {
15471                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15472         };
15473
15474         if (strcmp(res->nvgre, "nvgre") == 0)
15475                 nvgre_encap_conf.select_vlan = 0;
15476         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15477                 nvgre_encap_conf.select_vlan = 1;
15478         if (strcmp(res->ip_version, "ipv4") == 0)
15479                 nvgre_encap_conf.select_ipv4 = 1;
15480         else if (strcmp(res->ip_version, "ipv6") == 0)
15481                 nvgre_encap_conf.select_ipv4 = 0;
15482         else
15483                 return;
15484         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15485         if (nvgre_encap_conf.select_ipv4) {
15486                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15487                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15488         } else {
15489                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15490                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15491         }
15492         if (nvgre_encap_conf.select_vlan)
15493                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15494         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15495                    ETHER_ADDR_LEN);
15496         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15497                    ETHER_ADDR_LEN);
15498 }
15499
15500 cmdline_parse_inst_t cmd_set_nvgre = {
15501         .f = cmd_set_nvgre_parsed,
15502         .data = NULL,
15503         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15504                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15505                 " eth-dst <eth-dst>",
15506         .tokens = {
15507                 (void *)&cmd_set_nvgre_set,
15508                 (void *)&cmd_set_nvgre_nvgre,
15509                 (void *)&cmd_set_nvgre_ip_version,
15510                 (void *)&cmd_set_nvgre_ip_version_value,
15511                 (void *)&cmd_set_nvgre_tni,
15512                 (void *)&cmd_set_nvgre_tni_value,
15513                 (void *)&cmd_set_nvgre_ip_src,
15514                 (void *)&cmd_set_nvgre_ip_src_value,
15515                 (void *)&cmd_set_nvgre_ip_dst,
15516                 (void *)&cmd_set_nvgre_ip_dst_value,
15517                 (void *)&cmd_set_nvgre_eth_src,
15518                 (void *)&cmd_set_nvgre_eth_src_value,
15519                 (void *)&cmd_set_nvgre_eth_dst,
15520                 (void *)&cmd_set_nvgre_eth_dst_value,
15521                 NULL,
15522         },
15523 };
15524
15525 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15526         .f = cmd_set_nvgre_parsed,
15527         .data = NULL,
15528         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15529                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15530                 " eth-src <eth-src> eth-dst <eth-dst>",
15531         .tokens = {
15532                 (void *)&cmd_set_nvgre_set,
15533                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15534                 (void *)&cmd_set_nvgre_ip_version,
15535                 (void *)&cmd_set_nvgre_ip_version_value,
15536                 (void *)&cmd_set_nvgre_tni,
15537                 (void *)&cmd_set_nvgre_tni_value,
15538                 (void *)&cmd_set_nvgre_ip_src,
15539                 (void *)&cmd_set_nvgre_ip_src_value,
15540                 (void *)&cmd_set_nvgre_ip_dst,
15541                 (void *)&cmd_set_nvgre_ip_dst_value,
15542                 (void *)&cmd_set_nvgre_vlan,
15543                 (void *)&cmd_set_nvgre_vlan_value,
15544                 (void *)&cmd_set_nvgre_eth_src,
15545                 (void *)&cmd_set_nvgre_eth_src_value,
15546                 (void *)&cmd_set_nvgre_eth_dst,
15547                 (void *)&cmd_set_nvgre_eth_dst_value,
15548                 NULL,
15549         },
15550 };
15551
15552 /** Set L2 encapsulation details */
15553 struct cmd_set_l2_encap_result {
15554         cmdline_fixed_string_t set;
15555         cmdline_fixed_string_t l2_encap;
15556         cmdline_fixed_string_t pos_token;
15557         cmdline_fixed_string_t ip_version;
15558         uint32_t vlan_present:1;
15559         uint16_t tci;
15560         struct rte_ether_addr eth_src;
15561         struct rte_ether_addr eth_dst;
15562 };
15563
15564 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15565         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15566 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15567         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15568 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15569         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15570                                  "l2_encap-with-vlan");
15571 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15572         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15573                                  "ip-version");
15574 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15575         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15576                                  "ipv4#ipv6");
15577 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15578         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15579                                  "vlan-tci");
15580 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15581         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15582 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15583         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15584                                  "eth-src");
15585 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15586         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15587 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15588         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15589                                  "eth-dst");
15590 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15591         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15592
15593 static void cmd_set_l2_encap_parsed(void *parsed_result,
15594         __attribute__((unused)) struct cmdline *cl,
15595         __attribute__((unused)) void *data)
15596 {
15597         struct cmd_set_l2_encap_result *res = parsed_result;
15598
15599         if (strcmp(res->l2_encap, "l2_encap") == 0)
15600                 l2_encap_conf.select_vlan = 0;
15601         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15602                 l2_encap_conf.select_vlan = 1;
15603         if (strcmp(res->ip_version, "ipv4") == 0)
15604                 l2_encap_conf.select_ipv4 = 1;
15605         else if (strcmp(res->ip_version, "ipv6") == 0)
15606                 l2_encap_conf.select_ipv4 = 0;
15607         else
15608                 return;
15609         if (l2_encap_conf.select_vlan)
15610                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15611         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15612                    ETHER_ADDR_LEN);
15613         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15614                    ETHER_ADDR_LEN);
15615 }
15616
15617 cmdline_parse_inst_t cmd_set_l2_encap = {
15618         .f = cmd_set_l2_encap_parsed,
15619         .data = NULL,
15620         .help_str = "set l2_encap ip-version ipv4|ipv6"
15621                 " eth-src <eth-src> eth-dst <eth-dst>",
15622         .tokens = {
15623                 (void *)&cmd_set_l2_encap_set,
15624                 (void *)&cmd_set_l2_encap_l2_encap,
15625                 (void *)&cmd_set_l2_encap_ip_version,
15626                 (void *)&cmd_set_l2_encap_ip_version_value,
15627                 (void *)&cmd_set_l2_encap_eth_src,
15628                 (void *)&cmd_set_l2_encap_eth_src_value,
15629                 (void *)&cmd_set_l2_encap_eth_dst,
15630                 (void *)&cmd_set_l2_encap_eth_dst_value,
15631                 NULL,
15632         },
15633 };
15634
15635 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15636         .f = cmd_set_l2_encap_parsed,
15637         .data = NULL,
15638         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15639                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15640         .tokens = {
15641                 (void *)&cmd_set_l2_encap_set,
15642                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15643                 (void *)&cmd_set_l2_encap_ip_version,
15644                 (void *)&cmd_set_l2_encap_ip_version_value,
15645                 (void *)&cmd_set_l2_encap_vlan,
15646                 (void *)&cmd_set_l2_encap_vlan_value,
15647                 (void *)&cmd_set_l2_encap_eth_src,
15648                 (void *)&cmd_set_l2_encap_eth_src_value,
15649                 (void *)&cmd_set_l2_encap_eth_dst,
15650                 (void *)&cmd_set_l2_encap_eth_dst_value,
15651                 NULL,
15652         },
15653 };
15654
15655 /** Set L2 decapsulation details */
15656 struct cmd_set_l2_decap_result {
15657         cmdline_fixed_string_t set;
15658         cmdline_fixed_string_t l2_decap;
15659         cmdline_fixed_string_t pos_token;
15660         uint32_t vlan_present:1;
15661 };
15662
15663 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15664         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15665 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15666         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15667                                  "l2_decap");
15668 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15669         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15670                                  "l2_decap-with-vlan");
15671
15672 static void cmd_set_l2_decap_parsed(void *parsed_result,
15673         __attribute__((unused)) struct cmdline *cl,
15674         __attribute__((unused)) void *data)
15675 {
15676         struct cmd_set_l2_decap_result *res = parsed_result;
15677
15678         if (strcmp(res->l2_decap, "l2_decap") == 0)
15679                 l2_decap_conf.select_vlan = 0;
15680         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15681                 l2_decap_conf.select_vlan = 1;
15682 }
15683
15684 cmdline_parse_inst_t cmd_set_l2_decap = {
15685         .f = cmd_set_l2_decap_parsed,
15686         .data = NULL,
15687         .help_str = "set l2_decap",
15688         .tokens = {
15689                 (void *)&cmd_set_l2_decap_set,
15690                 (void *)&cmd_set_l2_decap_l2_decap,
15691                 NULL,
15692         },
15693 };
15694
15695 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15696         .f = cmd_set_l2_decap_parsed,
15697         .data = NULL,
15698         .help_str = "set l2_decap-with-vlan",
15699         .tokens = {
15700                 (void *)&cmd_set_l2_decap_set,
15701                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15702                 NULL,
15703         },
15704 };
15705
15706 /** Set MPLSoGRE encapsulation details */
15707 struct cmd_set_mplsogre_encap_result {
15708         cmdline_fixed_string_t set;
15709         cmdline_fixed_string_t mplsogre;
15710         cmdline_fixed_string_t pos_token;
15711         cmdline_fixed_string_t ip_version;
15712         uint32_t vlan_present:1;
15713         uint32_t label;
15714         cmdline_ipaddr_t ip_src;
15715         cmdline_ipaddr_t ip_dst;
15716         uint16_t tci;
15717         struct rte_ether_addr eth_src;
15718         struct rte_ether_addr eth_dst;
15719 };
15720
15721 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15722         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15723                                  "set");
15724 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15725         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15726                                  "mplsogre_encap");
15727 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15728         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15729                                  mplsogre, "mplsogre_encap-with-vlan");
15730 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15731         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15732                                  pos_token, "ip-version");
15733 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15734         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15735                                  ip_version, "ipv4#ipv6");
15736 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15737         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15738                                  pos_token, "label");
15739 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15740         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15741                               UINT32);
15742 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15743         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15744                                  pos_token, "ip-src");
15745 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15746         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15747 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15748         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15749                                  pos_token, "ip-dst");
15750 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15751         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15752 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15753         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15754                                  pos_token, "vlan-tci");
15755 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15756         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15757                               UINT16);
15758 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15759         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15760                                  pos_token, "eth-src");
15761 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15762         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15763                                     eth_src);
15764 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15765         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15766                                  pos_token, "eth-dst");
15767 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15768         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15769                                     eth_dst);
15770
15771 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15772         __attribute__((unused)) struct cmdline *cl,
15773         __attribute__((unused)) void *data)
15774 {
15775         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15776         union {
15777                 uint32_t mplsogre_label;
15778                 uint8_t label[4];
15779         } id = {
15780                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15781         };
15782
15783         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15784                 mplsogre_encap_conf.select_vlan = 0;
15785         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15786                 mplsogre_encap_conf.select_vlan = 1;
15787         if (strcmp(res->ip_version, "ipv4") == 0)
15788                 mplsogre_encap_conf.select_ipv4 = 1;
15789         else if (strcmp(res->ip_version, "ipv6") == 0)
15790                 mplsogre_encap_conf.select_ipv4 = 0;
15791         else
15792                 return;
15793         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15794         if (mplsogre_encap_conf.select_ipv4) {
15795                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15796                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15797         } else {
15798                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15799                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15800         }
15801         if (mplsogre_encap_conf.select_vlan)
15802                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15803         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15804                    ETHER_ADDR_LEN);
15805         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15806                    ETHER_ADDR_LEN);
15807 }
15808
15809 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15810         .f = cmd_set_mplsogre_encap_parsed,
15811         .data = NULL,
15812         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15813                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15814                 " eth-dst <eth-dst>",
15815         .tokens = {
15816                 (void *)&cmd_set_mplsogre_encap_set,
15817                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15818                 (void *)&cmd_set_mplsogre_encap_ip_version,
15819                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15820                 (void *)&cmd_set_mplsogre_encap_label,
15821                 (void *)&cmd_set_mplsogre_encap_label_value,
15822                 (void *)&cmd_set_mplsogre_encap_ip_src,
15823                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15824                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15825                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15826                 (void *)&cmd_set_mplsogre_encap_eth_src,
15827                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15828                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15829                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15830                 NULL,
15831         },
15832 };
15833
15834 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15835         .f = cmd_set_mplsogre_encap_parsed,
15836         .data = NULL,
15837         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15838                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15839                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15840         .tokens = {
15841                 (void *)&cmd_set_mplsogre_encap_set,
15842                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15843                 (void *)&cmd_set_mplsogre_encap_ip_version,
15844                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15845                 (void *)&cmd_set_mplsogre_encap_label,
15846                 (void *)&cmd_set_mplsogre_encap_label_value,
15847                 (void *)&cmd_set_mplsogre_encap_ip_src,
15848                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15849                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15850                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15851                 (void *)&cmd_set_mplsogre_encap_vlan,
15852                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15853                 (void *)&cmd_set_mplsogre_encap_eth_src,
15854                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15855                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15856                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15857                 NULL,
15858         },
15859 };
15860
15861 /** Set MPLSoGRE decapsulation details */
15862 struct cmd_set_mplsogre_decap_result {
15863         cmdline_fixed_string_t set;
15864         cmdline_fixed_string_t mplsogre;
15865         cmdline_fixed_string_t pos_token;
15866         cmdline_fixed_string_t ip_version;
15867         uint32_t vlan_present:1;
15868 };
15869
15870 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15871         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15872                                  "set");
15873 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15874         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15875                                  "mplsogre_decap");
15876 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15877         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15878                                  mplsogre, "mplsogre_decap-with-vlan");
15879 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15880         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15881                                  pos_token, "ip-version");
15882 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15883         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15884                                  ip_version, "ipv4#ipv6");
15885
15886 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15887         __attribute__((unused)) struct cmdline *cl,
15888         __attribute__((unused)) void *data)
15889 {
15890         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15891
15892         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15893                 mplsogre_decap_conf.select_vlan = 0;
15894         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15895                 mplsogre_decap_conf.select_vlan = 1;
15896         if (strcmp(res->ip_version, "ipv4") == 0)
15897                 mplsogre_decap_conf.select_ipv4 = 1;
15898         else if (strcmp(res->ip_version, "ipv6") == 0)
15899                 mplsogre_decap_conf.select_ipv4 = 0;
15900 }
15901
15902 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15903         .f = cmd_set_mplsogre_decap_parsed,
15904         .data = NULL,
15905         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15906         .tokens = {
15907                 (void *)&cmd_set_mplsogre_decap_set,
15908                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15909                 (void *)&cmd_set_mplsogre_decap_ip_version,
15910                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15911                 NULL,
15912         },
15913 };
15914
15915 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15916         .f = cmd_set_mplsogre_decap_parsed,
15917         .data = NULL,
15918         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15919         .tokens = {
15920                 (void *)&cmd_set_mplsogre_decap_set,
15921                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15922                 (void *)&cmd_set_mplsogre_decap_ip_version,
15923                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15924                 NULL,
15925         },
15926 };
15927
15928 /** Set MPLSoUDP encapsulation details */
15929 struct cmd_set_mplsoudp_encap_result {
15930         cmdline_fixed_string_t set;
15931         cmdline_fixed_string_t mplsoudp;
15932         cmdline_fixed_string_t pos_token;
15933         cmdline_fixed_string_t ip_version;
15934         uint32_t vlan_present:1;
15935         uint32_t label;
15936         uint16_t udp_src;
15937         uint16_t udp_dst;
15938         cmdline_ipaddr_t ip_src;
15939         cmdline_ipaddr_t ip_dst;
15940         uint16_t tci;
15941         struct rte_ether_addr eth_src;
15942         struct rte_ether_addr eth_dst;
15943 };
15944
15945 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15946         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15947                                  "set");
15948 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15949         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15950                                  "mplsoudp_encap");
15951 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15952         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15953                                  mplsoudp, "mplsoudp_encap-with-vlan");
15954 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15955         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15956                                  pos_token, "ip-version");
15957 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15958         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15959                                  ip_version, "ipv4#ipv6");
15960 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15961         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15962                                  pos_token, "label");
15963 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15964         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15965                               UINT32);
15966 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15967         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15968                                  pos_token, "udp-src");
15969 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
15970         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
15971                               UINT16);
15972 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
15973         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15974                                  pos_token, "udp-dst");
15975 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
15976         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
15977                               UINT16);
15978 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
15979         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15980                                  pos_token, "ip-src");
15981 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
15982         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
15983 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
15984         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15985                                  pos_token, "ip-dst");
15986 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
15987         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
15988 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
15989         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15990                                  pos_token, "vlan-tci");
15991 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
15992         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
15993                               UINT16);
15994 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
15995         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15996                                  pos_token, "eth-src");
15997 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
15998         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15999                                     eth_src);
16000 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16001         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16002                                  pos_token, "eth-dst");
16003 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16004         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16005                                     eth_dst);
16006
16007 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16008         __attribute__((unused)) struct cmdline *cl,
16009         __attribute__((unused)) void *data)
16010 {
16011         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16012         union {
16013                 uint32_t mplsoudp_label;
16014                 uint8_t label[4];
16015         } id = {
16016                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16017         };
16018
16019         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16020                 mplsoudp_encap_conf.select_vlan = 0;
16021         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16022                 mplsoudp_encap_conf.select_vlan = 1;
16023         if (strcmp(res->ip_version, "ipv4") == 0)
16024                 mplsoudp_encap_conf.select_ipv4 = 1;
16025         else if (strcmp(res->ip_version, "ipv6") == 0)
16026                 mplsoudp_encap_conf.select_ipv4 = 0;
16027         else
16028                 return;
16029         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16030         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16031         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16032         if (mplsoudp_encap_conf.select_ipv4) {
16033                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16034                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16035         } else {
16036                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16037                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16038         }
16039         if (mplsoudp_encap_conf.select_vlan)
16040                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16041         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16042                    ETHER_ADDR_LEN);
16043         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16044                    ETHER_ADDR_LEN);
16045 }
16046
16047 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16048         .f = cmd_set_mplsoudp_encap_parsed,
16049         .data = NULL,
16050         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16051                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16052                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16053         .tokens = {
16054                 (void *)&cmd_set_mplsoudp_encap_set,
16055                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16056                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16057                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16058                 (void *)&cmd_set_mplsoudp_encap_label,
16059                 (void *)&cmd_set_mplsoudp_encap_label_value,
16060                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16061                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16062                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16063                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16064                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16065                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16066                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16067                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16068                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16069                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16070                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16071                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16072                 NULL,
16073         },
16074 };
16075
16076 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16077         .f = cmd_set_mplsoudp_encap_parsed,
16078         .data = NULL,
16079         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16080                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16081                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16082                 " eth-src <eth-src> eth-dst <eth-dst>",
16083         .tokens = {
16084                 (void *)&cmd_set_mplsoudp_encap_set,
16085                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16086                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16087                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16088                 (void *)&cmd_set_mplsoudp_encap_label,
16089                 (void *)&cmd_set_mplsoudp_encap_label_value,
16090                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16091                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16092                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16093                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16094                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16095                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16096                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16097                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16098                 (void *)&cmd_set_mplsoudp_encap_vlan,
16099                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16100                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16101                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16102                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16103                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16104                 NULL,
16105         },
16106 };
16107
16108 /** Set MPLSoUDP decapsulation details */
16109 struct cmd_set_mplsoudp_decap_result {
16110         cmdline_fixed_string_t set;
16111         cmdline_fixed_string_t mplsoudp;
16112         cmdline_fixed_string_t pos_token;
16113         cmdline_fixed_string_t ip_version;
16114         uint32_t vlan_present:1;
16115 };
16116
16117 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16118         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16119                                  "set");
16120 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16121         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16122                                  "mplsoudp_decap");
16123 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16124         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16125                                  mplsoudp, "mplsoudp_decap-with-vlan");
16126 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16127         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16128                                  pos_token, "ip-version");
16129 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16130         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16131                                  ip_version, "ipv4#ipv6");
16132
16133 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16134         __attribute__((unused)) struct cmdline *cl,
16135         __attribute__((unused)) void *data)
16136 {
16137         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16138
16139         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16140                 mplsoudp_decap_conf.select_vlan = 0;
16141         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16142                 mplsoudp_decap_conf.select_vlan = 1;
16143         if (strcmp(res->ip_version, "ipv4") == 0)
16144                 mplsoudp_decap_conf.select_ipv4 = 1;
16145         else if (strcmp(res->ip_version, "ipv6") == 0)
16146                 mplsoudp_decap_conf.select_ipv4 = 0;
16147 }
16148
16149 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16150         .f = cmd_set_mplsoudp_decap_parsed,
16151         .data = NULL,
16152         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16153         .tokens = {
16154                 (void *)&cmd_set_mplsoudp_decap_set,
16155                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16156                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16157                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16158                 NULL,
16159         },
16160 };
16161
16162 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16163         .f = cmd_set_mplsoudp_decap_parsed,
16164         .data = NULL,
16165         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16166         .tokens = {
16167                 (void *)&cmd_set_mplsoudp_decap_set,
16168                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16169                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16170                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16171                 NULL,
16172         },
16173 };
16174
16175 /* Strict link priority scheduling mode setting */
16176 static void
16177 cmd_strict_link_prio_parsed(
16178         void *parsed_result,
16179         __attribute__((unused)) struct cmdline *cl,
16180         __attribute__((unused)) void *data)
16181 {
16182         struct cmd_vf_tc_bw_result *res = parsed_result;
16183         int ret = -ENOTSUP;
16184
16185         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16186                 return;
16187
16188 #ifdef RTE_LIBRTE_I40E_PMD
16189         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16190 #endif
16191
16192         switch (ret) {
16193         case 0:
16194                 break;
16195         case -EINVAL:
16196                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16197                 break;
16198         case -ENODEV:
16199                 printf("invalid port_id %d\n", res->port_id);
16200                 break;
16201         case -ENOTSUP:
16202                 printf("function not implemented\n");
16203                 break;
16204         default:
16205                 printf("programming error: (%s)\n", strerror(-ret));
16206         }
16207 }
16208
16209 cmdline_parse_inst_t cmd_strict_link_prio = {
16210         .f = cmd_strict_link_prio_parsed,
16211         .data = NULL,
16212         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16213         .tokens = {
16214                 (void *)&cmd_vf_tc_bw_set,
16215                 (void *)&cmd_vf_tc_bw_tx,
16216                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16217                 (void *)&cmd_vf_tc_bw_port_id,
16218                 (void *)&cmd_vf_tc_bw_tc_map,
16219                 NULL,
16220         },
16221 };
16222
16223 /* Load dynamic device personalization*/
16224 struct cmd_ddp_add_result {
16225         cmdline_fixed_string_t ddp;
16226         cmdline_fixed_string_t add;
16227         portid_t port_id;
16228         char filepath[];
16229 };
16230
16231 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16232         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16233 cmdline_parse_token_string_t cmd_ddp_add_add =
16234         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16235 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16236         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16237 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16238         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16239
16240 static void
16241 cmd_ddp_add_parsed(
16242         void *parsed_result,
16243         __attribute__((unused)) struct cmdline *cl,
16244         __attribute__((unused)) void *data)
16245 {
16246         struct cmd_ddp_add_result *res = parsed_result;
16247         uint8_t *buff;
16248         uint32_t size;
16249         char *filepath;
16250         char *file_fld[2];
16251         int file_num;
16252         int ret = -ENOTSUP;
16253
16254         if (!all_ports_stopped()) {
16255                 printf("Please stop all ports first\n");
16256                 return;
16257         }
16258
16259         filepath = strdup(res->filepath);
16260         if (filepath == NULL) {
16261                 printf("Failed to allocate memory\n");
16262                 return;
16263         }
16264         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16265
16266         buff = open_file(file_fld[0], &size);
16267         if (!buff) {
16268                 free((void *)filepath);
16269                 return;
16270         }
16271
16272 #ifdef RTE_LIBRTE_I40E_PMD
16273         if (ret == -ENOTSUP)
16274                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16275                                                buff, size,
16276                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16277 #endif
16278
16279         if (ret == -EEXIST)
16280                 printf("Profile has already existed.\n");
16281         else if (ret < 0)
16282                 printf("Failed to load profile.\n");
16283         else if (file_num == 2)
16284                 save_file(file_fld[1], buff, size);
16285
16286         close_file(buff);
16287         free((void *)filepath);
16288 }
16289
16290 cmdline_parse_inst_t cmd_ddp_add = {
16291         .f = cmd_ddp_add_parsed,
16292         .data = NULL,
16293         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16294         .tokens = {
16295                 (void *)&cmd_ddp_add_ddp,
16296                 (void *)&cmd_ddp_add_add,
16297                 (void *)&cmd_ddp_add_port_id,
16298                 (void *)&cmd_ddp_add_filepath,
16299                 NULL,
16300         },
16301 };
16302
16303 /* Delete dynamic device personalization*/
16304 struct cmd_ddp_del_result {
16305         cmdline_fixed_string_t ddp;
16306         cmdline_fixed_string_t del;
16307         portid_t port_id;
16308         char filepath[];
16309 };
16310
16311 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16312         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16313 cmdline_parse_token_string_t cmd_ddp_del_del =
16314         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16315 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16316         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16317 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16318         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16319
16320 static void
16321 cmd_ddp_del_parsed(
16322         void *parsed_result,
16323         __attribute__((unused)) struct cmdline *cl,
16324         __attribute__((unused)) void *data)
16325 {
16326         struct cmd_ddp_del_result *res = parsed_result;
16327         uint8_t *buff;
16328         uint32_t size;
16329         int ret = -ENOTSUP;
16330
16331         if (!all_ports_stopped()) {
16332                 printf("Please stop all ports first\n");
16333                 return;
16334         }
16335
16336         buff = open_file(res->filepath, &size);
16337         if (!buff)
16338                 return;
16339
16340 #ifdef RTE_LIBRTE_I40E_PMD
16341         if (ret == -ENOTSUP)
16342                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16343                                                buff, size,
16344                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16345 #endif
16346
16347         if (ret == -EACCES)
16348                 printf("Profile does not exist.\n");
16349         else if (ret < 0)
16350                 printf("Failed to delete profile.\n");
16351
16352         close_file(buff);
16353 }
16354
16355 cmdline_parse_inst_t cmd_ddp_del = {
16356         .f = cmd_ddp_del_parsed,
16357         .data = NULL,
16358         .help_str = "ddp del <port_id> <backup_profile_path>",
16359         .tokens = {
16360                 (void *)&cmd_ddp_del_ddp,
16361                 (void *)&cmd_ddp_del_del,
16362                 (void *)&cmd_ddp_del_port_id,
16363                 (void *)&cmd_ddp_del_filepath,
16364                 NULL,
16365         },
16366 };
16367
16368 /* Get dynamic device personalization profile info */
16369 struct cmd_ddp_info_result {
16370         cmdline_fixed_string_t ddp;
16371         cmdline_fixed_string_t get;
16372         cmdline_fixed_string_t info;
16373         char filepath[];
16374 };
16375
16376 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16377         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16378 cmdline_parse_token_string_t cmd_ddp_info_get =
16379         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16380 cmdline_parse_token_string_t cmd_ddp_info_info =
16381         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16382 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16383         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16384
16385 static void
16386 cmd_ddp_info_parsed(
16387         void *parsed_result,
16388         __attribute__((unused)) struct cmdline *cl,
16389         __attribute__((unused)) void *data)
16390 {
16391         struct cmd_ddp_info_result *res = parsed_result;
16392         uint8_t *pkg;
16393         uint32_t pkg_size;
16394         int ret = -ENOTSUP;
16395 #ifdef RTE_LIBRTE_I40E_PMD
16396         uint32_t i, j, n;
16397         uint8_t *buff;
16398         uint32_t buff_size = 0;
16399         struct rte_pmd_i40e_profile_info info;
16400         uint32_t dev_num = 0;
16401         struct rte_pmd_i40e_ddp_device_id *devs;
16402         uint32_t proto_num = 0;
16403         struct rte_pmd_i40e_proto_info *proto = NULL;
16404         uint32_t pctype_num = 0;
16405         struct rte_pmd_i40e_ptype_info *pctype;
16406         uint32_t ptype_num = 0;
16407         struct rte_pmd_i40e_ptype_info *ptype;
16408         uint8_t proto_id;
16409
16410 #endif
16411
16412         pkg = open_file(res->filepath, &pkg_size);
16413         if (!pkg)
16414                 return;
16415
16416 #ifdef RTE_LIBRTE_I40E_PMD
16417         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16418                                 (uint8_t *)&info, sizeof(info),
16419                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16420         if (!ret) {
16421                 printf("Global Track id:       0x%x\n", info.track_id);
16422                 printf("Global Version:        %d.%d.%d.%d\n",
16423                         info.version.major,
16424                         info.version.minor,
16425                         info.version.update,
16426                         info.version.draft);
16427                 printf("Global Package name:   %s\n\n", info.name);
16428         }
16429
16430         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16431                                 (uint8_t *)&info, sizeof(info),
16432                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16433         if (!ret) {
16434                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16435                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16436                         info.version.major,
16437                         info.version.minor,
16438                         info.version.update,
16439                         info.version.draft);
16440                 printf("i40e Profile name:     %s\n\n", info.name);
16441         }
16442
16443         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16444                                 (uint8_t *)&buff_size, sizeof(buff_size),
16445                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16446         if (!ret && buff_size) {
16447                 buff = (uint8_t *)malloc(buff_size);
16448                 if (buff) {
16449                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16450                                                 buff, buff_size,
16451                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16452                         if (!ret)
16453                                 printf("Package Notes:\n%s\n\n", buff);
16454                         free(buff);
16455                 }
16456         }
16457
16458         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16459                                 (uint8_t *)&dev_num, sizeof(dev_num),
16460                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16461         if (!ret && dev_num) {
16462                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16463                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16464                 if (devs) {
16465                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16466                                                 (uint8_t *)devs, buff_size,
16467                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16468                         if (!ret) {
16469                                 printf("List of supported devices:\n");
16470                                 for (i = 0; i < dev_num; i++) {
16471                                         printf("  %04X:%04X %04X:%04X\n",
16472                                                 devs[i].vendor_dev_id >> 16,
16473                                                 devs[i].vendor_dev_id & 0xFFFF,
16474                                                 devs[i].sub_vendor_dev_id >> 16,
16475                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16476                                 }
16477                                 printf("\n");
16478                         }
16479                         free(devs);
16480                 }
16481         }
16482
16483         /* get information about protocols and packet types */
16484         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16485                 (uint8_t *)&proto_num, sizeof(proto_num),
16486                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16487         if (ret || !proto_num)
16488                 goto no_print_return;
16489
16490         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16491         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16492         if (!proto)
16493                 goto no_print_return;
16494
16495         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16496                                         buff_size,
16497                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16498         if (!ret) {
16499                 printf("List of used protocols:\n");
16500                 for (i = 0; i < proto_num; i++)
16501                         printf("  %2u: %s\n", proto[i].proto_id,
16502                                proto[i].name);
16503                 printf("\n");
16504         }
16505         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16506                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16507                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16508         if (ret || !pctype_num)
16509                 goto no_print_pctypes;
16510
16511         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16512         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16513         if (!pctype)
16514                 goto no_print_pctypes;
16515
16516         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16517                                         buff_size,
16518                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16519         if (ret) {
16520                 free(pctype);
16521                 goto no_print_pctypes;
16522         }
16523
16524         printf("List of defined packet classification types:\n");
16525         for (i = 0; i < pctype_num; i++) {
16526                 printf("  %2u:", pctype[i].ptype_id);
16527                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16528                         proto_id = pctype[i].protocols[j];
16529                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16530                                 for (n = 0; n < proto_num; n++) {
16531                                         if (proto[n].proto_id == proto_id) {
16532                                                 printf(" %s", proto[n].name);
16533                                                 break;
16534                                         }
16535                                 }
16536                         }
16537                 }
16538                 printf("\n");
16539         }
16540         printf("\n");
16541         free(pctype);
16542
16543 no_print_pctypes:
16544
16545         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16546                                         sizeof(ptype_num),
16547                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16548         if (ret || !ptype_num)
16549                 goto no_print_return;
16550
16551         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16552         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16553         if (!ptype)
16554                 goto no_print_return;
16555
16556         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16557                                         buff_size,
16558                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16559         if (ret) {
16560                 free(ptype);
16561                 goto no_print_return;
16562         }
16563         printf("List of defined packet types:\n");
16564         for (i = 0; i < ptype_num; i++) {
16565                 printf("  %2u:", ptype[i].ptype_id);
16566                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16567                         proto_id = ptype[i].protocols[j];
16568                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16569                                 for (n = 0; n < proto_num; n++) {
16570                                         if (proto[n].proto_id == proto_id) {
16571                                                 printf(" %s", proto[n].name);
16572                                                 break;
16573                                         }
16574                                 }
16575                         }
16576                 }
16577                 printf("\n");
16578         }
16579         free(ptype);
16580         printf("\n");
16581
16582         ret = 0;
16583 no_print_return:
16584         if (proto)
16585                 free(proto);
16586 #endif
16587         if (ret == -ENOTSUP)
16588                 printf("Function not supported in PMD driver\n");
16589         close_file(pkg);
16590 }
16591
16592 cmdline_parse_inst_t cmd_ddp_get_info = {
16593         .f = cmd_ddp_info_parsed,
16594         .data = NULL,
16595         .help_str = "ddp get info <profile_path>",
16596         .tokens = {
16597                 (void *)&cmd_ddp_info_ddp,
16598                 (void *)&cmd_ddp_info_get,
16599                 (void *)&cmd_ddp_info_info,
16600                 (void *)&cmd_ddp_info_filepath,
16601                 NULL,
16602         },
16603 };
16604
16605 /* Get dynamic device personalization profile info list*/
16606 #define PROFILE_INFO_SIZE 48
16607 #define MAX_PROFILE_NUM 16
16608
16609 struct cmd_ddp_get_list_result {
16610         cmdline_fixed_string_t ddp;
16611         cmdline_fixed_string_t get;
16612         cmdline_fixed_string_t list;
16613         portid_t port_id;
16614 };
16615
16616 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16617         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16618 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16619         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16620 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16621         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16622 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16623         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16624
16625 static void
16626 cmd_ddp_get_list_parsed(
16627         __attribute__((unused)) void *parsed_result,
16628         __attribute__((unused)) struct cmdline *cl,
16629         __attribute__((unused)) void *data)
16630 {
16631 #ifdef RTE_LIBRTE_I40E_PMD
16632         struct cmd_ddp_get_list_result *res = parsed_result;
16633         struct rte_pmd_i40e_profile_list *p_list;
16634         struct rte_pmd_i40e_profile_info *p_info;
16635         uint32_t p_num;
16636         uint32_t size;
16637         uint32_t i;
16638 #endif
16639         int ret = -ENOTSUP;
16640
16641 #ifdef RTE_LIBRTE_I40E_PMD
16642         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16643         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16644         if (!p_list)
16645                 printf("%s: Failed to malloc buffer\n", __func__);
16646
16647         if (ret == -ENOTSUP)
16648                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16649                                                 (uint8_t *)p_list, size);
16650
16651         if (!ret) {
16652                 p_num = p_list->p_count;
16653                 printf("Profile number is: %d\n\n", p_num);
16654
16655                 for (i = 0; i < p_num; i++) {
16656                         p_info = &p_list->p_info[i];
16657                         printf("Profile %d:\n", i);
16658                         printf("Track id:     0x%x\n", p_info->track_id);
16659                         printf("Version:      %d.%d.%d.%d\n",
16660                                p_info->version.major,
16661                                p_info->version.minor,
16662                                p_info->version.update,
16663                                p_info->version.draft);
16664                         printf("Profile name: %s\n\n", p_info->name);
16665                 }
16666         }
16667
16668         free(p_list);
16669 #endif
16670
16671         if (ret < 0)
16672                 printf("Failed to get ddp list\n");
16673 }
16674
16675 cmdline_parse_inst_t cmd_ddp_get_list = {
16676         .f = cmd_ddp_get_list_parsed,
16677         .data = NULL,
16678         .help_str = "ddp get list <port_id>",
16679         .tokens = {
16680                 (void *)&cmd_ddp_get_list_ddp,
16681                 (void *)&cmd_ddp_get_list_get,
16682                 (void *)&cmd_ddp_get_list_list,
16683                 (void *)&cmd_ddp_get_list_port_id,
16684                 NULL,
16685         },
16686 };
16687
16688 /* Configure input set */
16689 struct cmd_cfg_input_set_result {
16690         cmdline_fixed_string_t port;
16691         cmdline_fixed_string_t cfg;
16692         portid_t port_id;
16693         cmdline_fixed_string_t pctype;
16694         uint8_t pctype_id;
16695         cmdline_fixed_string_t inset_type;
16696         cmdline_fixed_string_t opt;
16697         cmdline_fixed_string_t field;
16698         uint8_t field_idx;
16699 };
16700
16701 static void
16702 cmd_cfg_input_set_parsed(
16703         __attribute__((unused)) void *parsed_result,
16704         __attribute__((unused)) struct cmdline *cl,
16705         __attribute__((unused)) void *data)
16706 {
16707 #ifdef RTE_LIBRTE_I40E_PMD
16708         struct cmd_cfg_input_set_result *res = parsed_result;
16709         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16710         struct rte_pmd_i40e_inset inset;
16711 #endif
16712         int ret = -ENOTSUP;
16713
16714         if (!all_ports_stopped()) {
16715                 printf("Please stop all ports first\n");
16716                 return;
16717         }
16718
16719 #ifdef RTE_LIBRTE_I40E_PMD
16720         if (!strcmp(res->inset_type, "hash_inset"))
16721                 inset_type = INSET_HASH;
16722         else if (!strcmp(res->inset_type, "fdir_inset"))
16723                 inset_type = INSET_FDIR;
16724         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16725                 inset_type = INSET_FDIR_FLX;
16726         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16727                                      &inset, inset_type);
16728         if (ret) {
16729                 printf("Failed to get input set.\n");
16730                 return;
16731         }
16732
16733         if (!strcmp(res->opt, "get")) {
16734                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16735                                                    res->field_idx);
16736                 if (ret)
16737                         printf("Field index %d is enabled.\n", res->field_idx);
16738                 else
16739                         printf("Field index %d is disabled.\n", res->field_idx);
16740                 return;
16741         } else if (!strcmp(res->opt, "set"))
16742                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16743                                                    res->field_idx);
16744         else if (!strcmp(res->opt, "clear"))
16745                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16746                                                      res->field_idx);
16747         if (ret) {
16748                 printf("Failed to configure input set field.\n");
16749                 return;
16750         }
16751
16752         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16753                                      &inset, inset_type);
16754         if (ret) {
16755                 printf("Failed to set input set.\n");
16756                 return;
16757         }
16758 #endif
16759
16760         if (ret == -ENOTSUP)
16761                 printf("Function not supported\n");
16762 }
16763
16764 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16765         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16766                                  port, "port");
16767 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16768         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16769                                  cfg, "config");
16770 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16771         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16772                               port_id, UINT16);
16773 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16774         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16775                                  pctype, "pctype");
16776 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16777         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16778                               pctype_id, UINT8);
16779 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16780         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16781                                  inset_type,
16782                                  "hash_inset#fdir_inset#fdir_flx_inset");
16783 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16784         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16785                                  opt, "get#set#clear");
16786 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16787         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16788                                  field, "field");
16789 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16790         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16791                               field_idx, UINT8);
16792
16793 cmdline_parse_inst_t cmd_cfg_input_set = {
16794         .f = cmd_cfg_input_set_parsed,
16795         .data = NULL,
16796         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16797                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16798         .tokens = {
16799                 (void *)&cmd_cfg_input_set_port,
16800                 (void *)&cmd_cfg_input_set_cfg,
16801                 (void *)&cmd_cfg_input_set_port_id,
16802                 (void *)&cmd_cfg_input_set_pctype,
16803                 (void *)&cmd_cfg_input_set_pctype_id,
16804                 (void *)&cmd_cfg_input_set_inset_type,
16805                 (void *)&cmd_cfg_input_set_opt,
16806                 (void *)&cmd_cfg_input_set_field,
16807                 (void *)&cmd_cfg_input_set_field_idx,
16808                 NULL,
16809         },
16810 };
16811
16812 /* Clear input set */
16813 struct cmd_clear_input_set_result {
16814         cmdline_fixed_string_t port;
16815         cmdline_fixed_string_t cfg;
16816         portid_t port_id;
16817         cmdline_fixed_string_t pctype;
16818         uint8_t pctype_id;
16819         cmdline_fixed_string_t inset_type;
16820         cmdline_fixed_string_t clear;
16821         cmdline_fixed_string_t all;
16822 };
16823
16824 static void
16825 cmd_clear_input_set_parsed(
16826         __attribute__((unused)) void *parsed_result,
16827         __attribute__((unused)) struct cmdline *cl,
16828         __attribute__((unused)) void *data)
16829 {
16830 #ifdef RTE_LIBRTE_I40E_PMD
16831         struct cmd_clear_input_set_result *res = parsed_result;
16832         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16833         struct rte_pmd_i40e_inset inset;
16834 #endif
16835         int ret = -ENOTSUP;
16836
16837         if (!all_ports_stopped()) {
16838                 printf("Please stop all ports first\n");
16839                 return;
16840         }
16841
16842 #ifdef RTE_LIBRTE_I40E_PMD
16843         if (!strcmp(res->inset_type, "hash_inset"))
16844                 inset_type = INSET_HASH;
16845         else if (!strcmp(res->inset_type, "fdir_inset"))
16846                 inset_type = INSET_FDIR;
16847         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16848                 inset_type = INSET_FDIR_FLX;
16849
16850         memset(&inset, 0, sizeof(inset));
16851
16852         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16853                                      &inset, inset_type);
16854         if (ret) {
16855                 printf("Failed to clear input set.\n");
16856                 return;
16857         }
16858
16859 #endif
16860
16861         if (ret == -ENOTSUP)
16862                 printf("Function not supported\n");
16863 }
16864
16865 cmdline_parse_token_string_t cmd_clear_input_set_port =
16866         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16867                                  port, "port");
16868 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16869         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16870                                  cfg, "config");
16871 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16872         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16873                               port_id, UINT16);
16874 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16875         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16876                                  pctype, "pctype");
16877 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16878         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16879                               pctype_id, UINT8);
16880 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16881         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16882                                  inset_type,
16883                                  "hash_inset#fdir_inset#fdir_flx_inset");
16884 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16885         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16886                                  clear, "clear");
16887 cmdline_parse_token_string_t cmd_clear_input_set_all =
16888         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16889                                  all, "all");
16890
16891 cmdline_parse_inst_t cmd_clear_input_set = {
16892         .f = cmd_clear_input_set_parsed,
16893         .data = NULL,
16894         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16895                     "fdir_inset|fdir_flx_inset clear all",
16896         .tokens = {
16897                 (void *)&cmd_clear_input_set_port,
16898                 (void *)&cmd_clear_input_set_cfg,
16899                 (void *)&cmd_clear_input_set_port_id,
16900                 (void *)&cmd_clear_input_set_pctype,
16901                 (void *)&cmd_clear_input_set_pctype_id,
16902                 (void *)&cmd_clear_input_set_inset_type,
16903                 (void *)&cmd_clear_input_set_clear,
16904                 (void *)&cmd_clear_input_set_all,
16905                 NULL,
16906         },
16907 };
16908
16909 /* show vf stats */
16910
16911 /* Common result structure for show vf stats */
16912 struct cmd_show_vf_stats_result {
16913         cmdline_fixed_string_t show;
16914         cmdline_fixed_string_t vf;
16915         cmdline_fixed_string_t stats;
16916         portid_t port_id;
16917         uint16_t vf_id;
16918 };
16919
16920 /* Common CLI fields show vf stats*/
16921 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16922         TOKEN_STRING_INITIALIZER
16923                 (struct cmd_show_vf_stats_result,
16924                  show, "show");
16925 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16926         TOKEN_STRING_INITIALIZER
16927                 (struct cmd_show_vf_stats_result,
16928                  vf, "vf");
16929 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16930         TOKEN_STRING_INITIALIZER
16931                 (struct cmd_show_vf_stats_result,
16932                  stats, "stats");
16933 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16934         TOKEN_NUM_INITIALIZER
16935                 (struct cmd_show_vf_stats_result,
16936                  port_id, UINT16);
16937 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16938         TOKEN_NUM_INITIALIZER
16939                 (struct cmd_show_vf_stats_result,
16940                  vf_id, UINT16);
16941
16942 static void
16943 cmd_show_vf_stats_parsed(
16944         void *parsed_result,
16945         __attribute__((unused)) struct cmdline *cl,
16946         __attribute__((unused)) void *data)
16947 {
16948         struct cmd_show_vf_stats_result *res = parsed_result;
16949         struct rte_eth_stats stats;
16950         int ret = -ENOTSUP;
16951         static const char *nic_stats_border = "########################";
16952
16953         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16954                 return;
16955
16956         memset(&stats, 0, sizeof(stats));
16957
16958 #ifdef RTE_LIBRTE_I40E_PMD
16959         if (ret == -ENOTSUP)
16960                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16961                                                 res->vf_id,
16962                                                 &stats);
16963 #endif
16964 #ifdef RTE_LIBRTE_BNXT_PMD
16965         if (ret == -ENOTSUP)
16966                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16967                                                 res->vf_id,
16968                                                 &stats);
16969 #endif
16970
16971         switch (ret) {
16972         case 0:
16973                 break;
16974         case -EINVAL:
16975                 printf("invalid vf_id %d\n", res->vf_id);
16976                 break;
16977         case -ENODEV:
16978                 printf("invalid port_id %d\n", res->port_id);
16979                 break;
16980         case -ENOTSUP:
16981                 printf("function not implemented\n");
16982                 break;
16983         default:
16984                 printf("programming error: (%s)\n", strerror(-ret));
16985         }
16986
16987         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
16988                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
16989
16990         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
16991                "%-"PRIu64"\n",
16992                stats.ipackets, stats.imissed, stats.ibytes);
16993         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
16994         printf("  RX-nombuf:  %-10"PRIu64"\n",
16995                stats.rx_nombuf);
16996         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
16997                "%-"PRIu64"\n",
16998                stats.opackets, stats.oerrors, stats.obytes);
16999
17000         printf("  %s############################%s\n",
17001                                nic_stats_border, nic_stats_border);
17002 }
17003
17004 cmdline_parse_inst_t cmd_show_vf_stats = {
17005         .f = cmd_show_vf_stats_parsed,
17006         .data = NULL,
17007         .help_str = "show vf stats <port_id> <vf_id>",
17008         .tokens = {
17009                 (void *)&cmd_show_vf_stats_show,
17010                 (void *)&cmd_show_vf_stats_vf,
17011                 (void *)&cmd_show_vf_stats_stats,
17012                 (void *)&cmd_show_vf_stats_port_id,
17013                 (void *)&cmd_show_vf_stats_vf_id,
17014                 NULL,
17015         },
17016 };
17017
17018 /* clear vf stats */
17019
17020 /* Common result structure for clear vf stats */
17021 struct cmd_clear_vf_stats_result {
17022         cmdline_fixed_string_t clear;
17023         cmdline_fixed_string_t vf;
17024         cmdline_fixed_string_t stats;
17025         portid_t port_id;
17026         uint16_t vf_id;
17027 };
17028
17029 /* Common CLI fields clear vf stats*/
17030 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17031         TOKEN_STRING_INITIALIZER
17032                 (struct cmd_clear_vf_stats_result,
17033                  clear, "clear");
17034 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17035         TOKEN_STRING_INITIALIZER
17036                 (struct cmd_clear_vf_stats_result,
17037                  vf, "vf");
17038 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17039         TOKEN_STRING_INITIALIZER
17040                 (struct cmd_clear_vf_stats_result,
17041                  stats, "stats");
17042 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17043         TOKEN_NUM_INITIALIZER
17044                 (struct cmd_clear_vf_stats_result,
17045                  port_id, UINT16);
17046 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17047         TOKEN_NUM_INITIALIZER
17048                 (struct cmd_clear_vf_stats_result,
17049                  vf_id, UINT16);
17050
17051 static void
17052 cmd_clear_vf_stats_parsed(
17053         void *parsed_result,
17054         __attribute__((unused)) struct cmdline *cl,
17055         __attribute__((unused)) void *data)
17056 {
17057         struct cmd_clear_vf_stats_result *res = parsed_result;
17058         int ret = -ENOTSUP;
17059
17060         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17061                 return;
17062
17063 #ifdef RTE_LIBRTE_I40E_PMD
17064         if (ret == -ENOTSUP)
17065                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17066                                                   res->vf_id);
17067 #endif
17068 #ifdef RTE_LIBRTE_BNXT_PMD
17069         if (ret == -ENOTSUP)
17070                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17071                                                   res->vf_id);
17072 #endif
17073
17074         switch (ret) {
17075         case 0:
17076                 break;
17077         case -EINVAL:
17078                 printf("invalid vf_id %d\n", res->vf_id);
17079                 break;
17080         case -ENODEV:
17081                 printf("invalid port_id %d\n", res->port_id);
17082                 break;
17083         case -ENOTSUP:
17084                 printf("function not implemented\n");
17085                 break;
17086         default:
17087                 printf("programming error: (%s)\n", strerror(-ret));
17088         }
17089 }
17090
17091 cmdline_parse_inst_t cmd_clear_vf_stats = {
17092         .f = cmd_clear_vf_stats_parsed,
17093         .data = NULL,
17094         .help_str = "clear vf stats <port_id> <vf_id>",
17095         .tokens = {
17096                 (void *)&cmd_clear_vf_stats_clear,
17097                 (void *)&cmd_clear_vf_stats_vf,
17098                 (void *)&cmd_clear_vf_stats_stats,
17099                 (void *)&cmd_clear_vf_stats_port_id,
17100                 (void *)&cmd_clear_vf_stats_vf_id,
17101                 NULL,
17102         },
17103 };
17104
17105 /* port config pctype mapping reset */
17106
17107 /* Common result structure for port config pctype mapping reset */
17108 struct cmd_pctype_mapping_reset_result {
17109         cmdline_fixed_string_t port;
17110         cmdline_fixed_string_t config;
17111         portid_t port_id;
17112         cmdline_fixed_string_t pctype;
17113         cmdline_fixed_string_t mapping;
17114         cmdline_fixed_string_t reset;
17115 };
17116
17117 /* Common CLI fields for port config pctype mapping reset*/
17118 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17119         TOKEN_STRING_INITIALIZER
17120                 (struct cmd_pctype_mapping_reset_result,
17121                  port, "port");
17122 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17123         TOKEN_STRING_INITIALIZER
17124                 (struct cmd_pctype_mapping_reset_result,
17125                  config, "config");
17126 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17127         TOKEN_NUM_INITIALIZER
17128                 (struct cmd_pctype_mapping_reset_result,
17129                  port_id, UINT16);
17130 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17131         TOKEN_STRING_INITIALIZER
17132                 (struct cmd_pctype_mapping_reset_result,
17133                  pctype, "pctype");
17134 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17135         TOKEN_STRING_INITIALIZER
17136                 (struct cmd_pctype_mapping_reset_result,
17137                  mapping, "mapping");
17138 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17139         TOKEN_STRING_INITIALIZER
17140                 (struct cmd_pctype_mapping_reset_result,
17141                  reset, "reset");
17142
17143 static void
17144 cmd_pctype_mapping_reset_parsed(
17145         void *parsed_result,
17146         __attribute__((unused)) struct cmdline *cl,
17147         __attribute__((unused)) void *data)
17148 {
17149         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17150         int ret = -ENOTSUP;
17151
17152         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17153                 return;
17154
17155 #ifdef RTE_LIBRTE_I40E_PMD
17156         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17157 #endif
17158
17159         switch (ret) {
17160         case 0:
17161                 break;
17162         case -ENODEV:
17163                 printf("invalid port_id %d\n", res->port_id);
17164                 break;
17165         case -ENOTSUP:
17166                 printf("function not implemented\n");
17167                 break;
17168         default:
17169                 printf("programming error: (%s)\n", strerror(-ret));
17170         }
17171 }
17172
17173 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17174         .f = cmd_pctype_mapping_reset_parsed,
17175         .data = NULL,
17176         .help_str = "port config <port_id> pctype mapping reset",
17177         .tokens = {
17178                 (void *)&cmd_pctype_mapping_reset_port,
17179                 (void *)&cmd_pctype_mapping_reset_config,
17180                 (void *)&cmd_pctype_mapping_reset_port_id,
17181                 (void *)&cmd_pctype_mapping_reset_pctype,
17182                 (void *)&cmd_pctype_mapping_reset_mapping,
17183                 (void *)&cmd_pctype_mapping_reset_reset,
17184                 NULL,
17185         },
17186 };
17187
17188 /* show port pctype mapping */
17189
17190 /* Common result structure for show port pctype mapping */
17191 struct cmd_pctype_mapping_get_result {
17192         cmdline_fixed_string_t show;
17193         cmdline_fixed_string_t port;
17194         portid_t port_id;
17195         cmdline_fixed_string_t pctype;
17196         cmdline_fixed_string_t mapping;
17197 };
17198
17199 /* Common CLI fields for pctype mapping get */
17200 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17201         TOKEN_STRING_INITIALIZER
17202                 (struct cmd_pctype_mapping_get_result,
17203                  show, "show");
17204 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17205         TOKEN_STRING_INITIALIZER
17206                 (struct cmd_pctype_mapping_get_result,
17207                  port, "port");
17208 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17209         TOKEN_NUM_INITIALIZER
17210                 (struct cmd_pctype_mapping_get_result,
17211                  port_id, UINT16);
17212 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17213         TOKEN_STRING_INITIALIZER
17214                 (struct cmd_pctype_mapping_get_result,
17215                  pctype, "pctype");
17216 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17217         TOKEN_STRING_INITIALIZER
17218                 (struct cmd_pctype_mapping_get_result,
17219                  mapping, "mapping");
17220
17221 static void
17222 cmd_pctype_mapping_get_parsed(
17223         void *parsed_result,
17224         __attribute__((unused)) struct cmdline *cl,
17225         __attribute__((unused)) void *data)
17226 {
17227         struct cmd_pctype_mapping_get_result *res = parsed_result;
17228         int ret = -ENOTSUP;
17229 #ifdef RTE_LIBRTE_I40E_PMD
17230         struct rte_pmd_i40e_flow_type_mapping
17231                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17232         int i, j, first_pctype;
17233 #endif
17234
17235         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17236                 return;
17237
17238 #ifdef RTE_LIBRTE_I40E_PMD
17239         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17240 #endif
17241
17242         switch (ret) {
17243         case 0:
17244                 break;
17245         case -ENODEV:
17246                 printf("invalid port_id %d\n", res->port_id);
17247                 return;
17248         case -ENOTSUP:
17249                 printf("function not implemented\n");
17250                 return;
17251         default:
17252                 printf("programming error: (%s)\n", strerror(-ret));
17253                 return;
17254         }
17255
17256 #ifdef RTE_LIBRTE_I40E_PMD
17257         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17258                 if (mapping[i].pctype != 0ULL) {
17259                         first_pctype = 1;
17260
17261                         printf("pctype: ");
17262                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17263                                 if (mapping[i].pctype & (1ULL << j)) {
17264                                         printf(first_pctype ?
17265                                                "%02d" : ",%02d", j);
17266                                         first_pctype = 0;
17267                                 }
17268                         }
17269                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17270                 }
17271         }
17272 #endif
17273 }
17274
17275 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17276         .f = cmd_pctype_mapping_get_parsed,
17277         .data = NULL,
17278         .help_str = "show port <port_id> pctype mapping",
17279         .tokens = {
17280                 (void *)&cmd_pctype_mapping_get_show,
17281                 (void *)&cmd_pctype_mapping_get_port,
17282                 (void *)&cmd_pctype_mapping_get_port_id,
17283                 (void *)&cmd_pctype_mapping_get_pctype,
17284                 (void *)&cmd_pctype_mapping_get_mapping,
17285                 NULL,
17286         },
17287 };
17288
17289 /* port config pctype mapping update */
17290
17291 /* Common result structure for port config pctype mapping update */
17292 struct cmd_pctype_mapping_update_result {
17293         cmdline_fixed_string_t port;
17294         cmdline_fixed_string_t config;
17295         portid_t port_id;
17296         cmdline_fixed_string_t pctype;
17297         cmdline_fixed_string_t mapping;
17298         cmdline_fixed_string_t update;
17299         cmdline_fixed_string_t pctype_list;
17300         uint16_t flow_type;
17301 };
17302
17303 /* Common CLI fields for pctype mapping update*/
17304 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17305         TOKEN_STRING_INITIALIZER
17306                 (struct cmd_pctype_mapping_update_result,
17307                  port, "port");
17308 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17309         TOKEN_STRING_INITIALIZER
17310                 (struct cmd_pctype_mapping_update_result,
17311                  config, "config");
17312 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17313         TOKEN_NUM_INITIALIZER
17314                 (struct cmd_pctype_mapping_update_result,
17315                  port_id, UINT16);
17316 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17317         TOKEN_STRING_INITIALIZER
17318                 (struct cmd_pctype_mapping_update_result,
17319                  pctype, "pctype");
17320 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17321         TOKEN_STRING_INITIALIZER
17322                 (struct cmd_pctype_mapping_update_result,
17323                  mapping, "mapping");
17324 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17325         TOKEN_STRING_INITIALIZER
17326                 (struct cmd_pctype_mapping_update_result,
17327                  update, "update");
17328 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17329         TOKEN_STRING_INITIALIZER
17330                 (struct cmd_pctype_mapping_update_result,
17331                  pctype_list, NULL);
17332 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17333         TOKEN_NUM_INITIALIZER
17334                 (struct cmd_pctype_mapping_update_result,
17335                  flow_type, UINT16);
17336
17337 static void
17338 cmd_pctype_mapping_update_parsed(
17339         void *parsed_result,
17340         __attribute__((unused)) struct cmdline *cl,
17341         __attribute__((unused)) void *data)
17342 {
17343         struct cmd_pctype_mapping_update_result *res = parsed_result;
17344         int ret = -ENOTSUP;
17345 #ifdef RTE_LIBRTE_I40E_PMD
17346         struct rte_pmd_i40e_flow_type_mapping mapping;
17347         unsigned int i;
17348         unsigned int nb_item;
17349         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17350 #endif
17351
17352         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17353                 return;
17354
17355 #ifdef RTE_LIBRTE_I40E_PMD
17356         nb_item = parse_item_list(res->pctype_list, "pctypes",
17357                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17358         mapping.flow_type = res->flow_type;
17359         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17360                 mapping.pctype |= (1ULL << pctype_list[i]);
17361         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17362                                                 &mapping,
17363                                                 1,
17364                                                 0);
17365 #endif
17366
17367         switch (ret) {
17368         case 0:
17369                 break;
17370         case -EINVAL:
17371                 printf("invalid pctype or flow type\n");
17372                 break;
17373         case -ENODEV:
17374                 printf("invalid port_id %d\n", res->port_id);
17375                 break;
17376         case -ENOTSUP:
17377                 printf("function not implemented\n");
17378                 break;
17379         default:
17380                 printf("programming error: (%s)\n", strerror(-ret));
17381         }
17382 }
17383
17384 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17385         .f = cmd_pctype_mapping_update_parsed,
17386         .data = NULL,
17387         .help_str = "port config <port_id> pctype mapping update"
17388         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17389         .tokens = {
17390                 (void *)&cmd_pctype_mapping_update_port,
17391                 (void *)&cmd_pctype_mapping_update_config,
17392                 (void *)&cmd_pctype_mapping_update_port_id,
17393                 (void *)&cmd_pctype_mapping_update_pctype,
17394                 (void *)&cmd_pctype_mapping_update_mapping,
17395                 (void *)&cmd_pctype_mapping_update_update,
17396                 (void *)&cmd_pctype_mapping_update_pc_type,
17397                 (void *)&cmd_pctype_mapping_update_flow_type,
17398                 NULL,
17399         },
17400 };
17401
17402 /* ptype mapping get */
17403
17404 /* Common result structure for ptype mapping get */
17405 struct cmd_ptype_mapping_get_result {
17406         cmdline_fixed_string_t ptype;
17407         cmdline_fixed_string_t mapping;
17408         cmdline_fixed_string_t get;
17409         portid_t port_id;
17410         uint8_t valid_only;
17411 };
17412
17413 /* Common CLI fields for ptype mapping get */
17414 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17415         TOKEN_STRING_INITIALIZER
17416                 (struct cmd_ptype_mapping_get_result,
17417                  ptype, "ptype");
17418 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17419         TOKEN_STRING_INITIALIZER
17420                 (struct cmd_ptype_mapping_get_result,
17421                  mapping, "mapping");
17422 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17423         TOKEN_STRING_INITIALIZER
17424                 (struct cmd_ptype_mapping_get_result,
17425                  get, "get");
17426 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17427         TOKEN_NUM_INITIALIZER
17428                 (struct cmd_ptype_mapping_get_result,
17429                  port_id, UINT16);
17430 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17431         TOKEN_NUM_INITIALIZER
17432                 (struct cmd_ptype_mapping_get_result,
17433                  valid_only, UINT8);
17434
17435 static void
17436 cmd_ptype_mapping_get_parsed(
17437         void *parsed_result,
17438         __attribute__((unused)) struct cmdline *cl,
17439         __attribute__((unused)) void *data)
17440 {
17441         struct cmd_ptype_mapping_get_result *res = parsed_result;
17442         int ret = -ENOTSUP;
17443 #ifdef RTE_LIBRTE_I40E_PMD
17444         int max_ptype_num = 256;
17445         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17446         uint16_t count;
17447         int i;
17448 #endif
17449
17450         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17451                 return;
17452
17453 #ifdef RTE_LIBRTE_I40E_PMD
17454         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17455                                         mapping,
17456                                         max_ptype_num,
17457                                         &count,
17458                                         res->valid_only);
17459 #endif
17460
17461         switch (ret) {
17462         case 0:
17463                 break;
17464         case -ENODEV:
17465                 printf("invalid port_id %d\n", res->port_id);
17466                 break;
17467         case -ENOTSUP:
17468                 printf("function not implemented\n");
17469                 break;
17470         default:
17471                 printf("programming error: (%s)\n", strerror(-ret));
17472         }
17473
17474 #ifdef RTE_LIBRTE_I40E_PMD
17475         if (!ret) {
17476                 for (i = 0; i < count; i++)
17477                         printf("%3d\t0x%08x\n",
17478                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17479         }
17480 #endif
17481 }
17482
17483 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17484         .f = cmd_ptype_mapping_get_parsed,
17485         .data = NULL,
17486         .help_str = "ptype mapping get <port_id> <valid_only>",
17487         .tokens = {
17488                 (void *)&cmd_ptype_mapping_get_ptype,
17489                 (void *)&cmd_ptype_mapping_get_mapping,
17490                 (void *)&cmd_ptype_mapping_get_get,
17491                 (void *)&cmd_ptype_mapping_get_port_id,
17492                 (void *)&cmd_ptype_mapping_get_valid_only,
17493                 NULL,
17494         },
17495 };
17496
17497 /* ptype mapping replace */
17498
17499 /* Common result structure for ptype mapping replace */
17500 struct cmd_ptype_mapping_replace_result {
17501         cmdline_fixed_string_t ptype;
17502         cmdline_fixed_string_t mapping;
17503         cmdline_fixed_string_t replace;
17504         portid_t port_id;
17505         uint32_t target;
17506         uint8_t mask;
17507         uint32_t pkt_type;
17508 };
17509
17510 /* Common CLI fields for ptype mapping replace */
17511 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17512         TOKEN_STRING_INITIALIZER
17513                 (struct cmd_ptype_mapping_replace_result,
17514                  ptype, "ptype");
17515 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17516         TOKEN_STRING_INITIALIZER
17517                 (struct cmd_ptype_mapping_replace_result,
17518                  mapping, "mapping");
17519 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17520         TOKEN_STRING_INITIALIZER
17521                 (struct cmd_ptype_mapping_replace_result,
17522                  replace, "replace");
17523 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17524         TOKEN_NUM_INITIALIZER
17525                 (struct cmd_ptype_mapping_replace_result,
17526                  port_id, UINT16);
17527 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17528         TOKEN_NUM_INITIALIZER
17529                 (struct cmd_ptype_mapping_replace_result,
17530                  target, UINT32);
17531 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17532         TOKEN_NUM_INITIALIZER
17533                 (struct cmd_ptype_mapping_replace_result,
17534                  mask, UINT8);
17535 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17536         TOKEN_NUM_INITIALIZER
17537                 (struct cmd_ptype_mapping_replace_result,
17538                  pkt_type, UINT32);
17539
17540 static void
17541 cmd_ptype_mapping_replace_parsed(
17542         void *parsed_result,
17543         __attribute__((unused)) struct cmdline *cl,
17544         __attribute__((unused)) void *data)
17545 {
17546         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17547         int ret = -ENOTSUP;
17548
17549         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17550                 return;
17551
17552 #ifdef RTE_LIBRTE_I40E_PMD
17553         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17554                                         res->target,
17555                                         res->mask,
17556                                         res->pkt_type);
17557 #endif
17558
17559         switch (ret) {
17560         case 0:
17561                 break;
17562         case -EINVAL:
17563                 printf("invalid ptype 0x%8x or 0x%8x\n",
17564                                 res->target, res->pkt_type);
17565                 break;
17566         case -ENODEV:
17567                 printf("invalid port_id %d\n", res->port_id);
17568                 break;
17569         case -ENOTSUP:
17570                 printf("function not implemented\n");
17571                 break;
17572         default:
17573                 printf("programming error: (%s)\n", strerror(-ret));
17574         }
17575 }
17576
17577 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17578         .f = cmd_ptype_mapping_replace_parsed,
17579         .data = NULL,
17580         .help_str =
17581                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17582         .tokens = {
17583                 (void *)&cmd_ptype_mapping_replace_ptype,
17584                 (void *)&cmd_ptype_mapping_replace_mapping,
17585                 (void *)&cmd_ptype_mapping_replace_replace,
17586                 (void *)&cmd_ptype_mapping_replace_port_id,
17587                 (void *)&cmd_ptype_mapping_replace_target,
17588                 (void *)&cmd_ptype_mapping_replace_mask,
17589                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17590                 NULL,
17591         },
17592 };
17593
17594 /* ptype mapping reset */
17595
17596 /* Common result structure for ptype mapping reset */
17597 struct cmd_ptype_mapping_reset_result {
17598         cmdline_fixed_string_t ptype;
17599         cmdline_fixed_string_t mapping;
17600         cmdline_fixed_string_t reset;
17601         portid_t port_id;
17602 };
17603
17604 /* Common CLI fields for ptype mapping reset*/
17605 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17606         TOKEN_STRING_INITIALIZER
17607                 (struct cmd_ptype_mapping_reset_result,
17608                  ptype, "ptype");
17609 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17610         TOKEN_STRING_INITIALIZER
17611                 (struct cmd_ptype_mapping_reset_result,
17612                  mapping, "mapping");
17613 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17614         TOKEN_STRING_INITIALIZER
17615                 (struct cmd_ptype_mapping_reset_result,
17616                  reset, "reset");
17617 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17618         TOKEN_NUM_INITIALIZER
17619                 (struct cmd_ptype_mapping_reset_result,
17620                  port_id, UINT16);
17621
17622 static void
17623 cmd_ptype_mapping_reset_parsed(
17624         void *parsed_result,
17625         __attribute__((unused)) struct cmdline *cl,
17626         __attribute__((unused)) void *data)
17627 {
17628         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17629         int ret = -ENOTSUP;
17630
17631         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17632                 return;
17633
17634 #ifdef RTE_LIBRTE_I40E_PMD
17635         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17636 #endif
17637
17638         switch (ret) {
17639         case 0:
17640                 break;
17641         case -ENODEV:
17642                 printf("invalid port_id %d\n", res->port_id);
17643                 break;
17644         case -ENOTSUP:
17645                 printf("function not implemented\n");
17646                 break;
17647         default:
17648                 printf("programming error: (%s)\n", strerror(-ret));
17649         }
17650 }
17651
17652 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17653         .f = cmd_ptype_mapping_reset_parsed,
17654         .data = NULL,
17655         .help_str = "ptype mapping reset <port_id>",
17656         .tokens = {
17657                 (void *)&cmd_ptype_mapping_reset_ptype,
17658                 (void *)&cmd_ptype_mapping_reset_mapping,
17659                 (void *)&cmd_ptype_mapping_reset_reset,
17660                 (void *)&cmd_ptype_mapping_reset_port_id,
17661                 NULL,
17662         },
17663 };
17664
17665 /* ptype mapping update */
17666
17667 /* Common result structure for ptype mapping update */
17668 struct cmd_ptype_mapping_update_result {
17669         cmdline_fixed_string_t ptype;
17670         cmdline_fixed_string_t mapping;
17671         cmdline_fixed_string_t reset;
17672         portid_t port_id;
17673         uint8_t hw_ptype;
17674         uint32_t sw_ptype;
17675 };
17676
17677 /* Common CLI fields for ptype mapping update*/
17678 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17679         TOKEN_STRING_INITIALIZER
17680                 (struct cmd_ptype_mapping_update_result,
17681                  ptype, "ptype");
17682 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17683         TOKEN_STRING_INITIALIZER
17684                 (struct cmd_ptype_mapping_update_result,
17685                  mapping, "mapping");
17686 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17687         TOKEN_STRING_INITIALIZER
17688                 (struct cmd_ptype_mapping_update_result,
17689                  reset, "update");
17690 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17691         TOKEN_NUM_INITIALIZER
17692                 (struct cmd_ptype_mapping_update_result,
17693                  port_id, UINT16);
17694 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17695         TOKEN_NUM_INITIALIZER
17696                 (struct cmd_ptype_mapping_update_result,
17697                  hw_ptype, UINT8);
17698 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17699         TOKEN_NUM_INITIALIZER
17700                 (struct cmd_ptype_mapping_update_result,
17701                  sw_ptype, UINT32);
17702
17703 static void
17704 cmd_ptype_mapping_update_parsed(
17705         void *parsed_result,
17706         __attribute__((unused)) struct cmdline *cl,
17707         __attribute__((unused)) void *data)
17708 {
17709         struct cmd_ptype_mapping_update_result *res = parsed_result;
17710         int ret = -ENOTSUP;
17711 #ifdef RTE_LIBRTE_I40E_PMD
17712         struct rte_pmd_i40e_ptype_mapping mapping;
17713 #endif
17714         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17715                 return;
17716
17717 #ifdef RTE_LIBRTE_I40E_PMD
17718         mapping.hw_ptype = res->hw_ptype;
17719         mapping.sw_ptype = res->sw_ptype;
17720         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17721                                                 &mapping,
17722                                                 1,
17723                                                 0);
17724 #endif
17725
17726         switch (ret) {
17727         case 0:
17728                 break;
17729         case -EINVAL:
17730                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17731                 break;
17732         case -ENODEV:
17733                 printf("invalid port_id %d\n", res->port_id);
17734                 break;
17735         case -ENOTSUP:
17736                 printf("function not implemented\n");
17737                 break;
17738         default:
17739                 printf("programming error: (%s)\n", strerror(-ret));
17740         }
17741 }
17742
17743 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17744         .f = cmd_ptype_mapping_update_parsed,
17745         .data = NULL,
17746         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17747         .tokens = {
17748                 (void *)&cmd_ptype_mapping_update_ptype,
17749                 (void *)&cmd_ptype_mapping_update_mapping,
17750                 (void *)&cmd_ptype_mapping_update_update,
17751                 (void *)&cmd_ptype_mapping_update_port_id,
17752                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17753                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17754                 NULL,
17755         },
17756 };
17757
17758 /* Common result structure for file commands */
17759 struct cmd_cmdfile_result {
17760         cmdline_fixed_string_t load;
17761         cmdline_fixed_string_t filename;
17762 };
17763
17764 /* Common CLI fields for file commands */
17765 cmdline_parse_token_string_t cmd_load_cmdfile =
17766         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17767 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17768         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17769
17770 static void
17771 cmd_load_from_file_parsed(
17772         void *parsed_result,
17773         __attribute__((unused)) struct cmdline *cl,
17774         __attribute__((unused)) void *data)
17775 {
17776         struct cmd_cmdfile_result *res = parsed_result;
17777
17778         cmdline_read_from_file(res->filename);
17779 }
17780
17781 cmdline_parse_inst_t cmd_load_from_file = {
17782         .f = cmd_load_from_file_parsed,
17783         .data = NULL,
17784         .help_str = "load <filename>",
17785         .tokens = {
17786                 (void *)&cmd_load_cmdfile,
17787                 (void *)&cmd_load_cmdfile_filename,
17788                 NULL,
17789         },
17790 };
17791
17792 /* Get Rx offloads capabilities */
17793 struct cmd_rx_offload_get_capa_result {
17794         cmdline_fixed_string_t show;
17795         cmdline_fixed_string_t port;
17796         portid_t port_id;
17797         cmdline_fixed_string_t rx_offload;
17798         cmdline_fixed_string_t capabilities;
17799 };
17800
17801 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17802         TOKEN_STRING_INITIALIZER
17803                 (struct cmd_rx_offload_get_capa_result,
17804                  show, "show");
17805 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17806         TOKEN_STRING_INITIALIZER
17807                 (struct cmd_rx_offload_get_capa_result,
17808                  port, "port");
17809 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17810         TOKEN_NUM_INITIALIZER
17811                 (struct cmd_rx_offload_get_capa_result,
17812                  port_id, UINT16);
17813 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17814         TOKEN_STRING_INITIALIZER
17815                 (struct cmd_rx_offload_get_capa_result,
17816                  rx_offload, "rx_offload");
17817 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17818         TOKEN_STRING_INITIALIZER
17819                 (struct cmd_rx_offload_get_capa_result,
17820                  capabilities, "capabilities");
17821
17822 static void
17823 print_rx_offloads(uint64_t offloads)
17824 {
17825         uint64_t single_offload;
17826         int begin;
17827         int end;
17828         int bit;
17829
17830         if (offloads == 0)
17831                 return;
17832
17833         begin = __builtin_ctzll(offloads);
17834         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17835
17836         single_offload = 1ULL << begin;
17837         for (bit = begin; bit < end; bit++) {
17838                 if (offloads & single_offload)
17839                         printf(" %s",
17840                                rte_eth_dev_rx_offload_name(single_offload));
17841                 single_offload <<= 1;
17842         }
17843 }
17844
17845 static void
17846 cmd_rx_offload_get_capa_parsed(
17847         void *parsed_result,
17848         __attribute__((unused)) struct cmdline *cl,
17849         __attribute__((unused)) void *data)
17850 {
17851         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17852         struct rte_eth_dev_info dev_info;
17853         portid_t port_id = res->port_id;
17854         uint64_t queue_offloads;
17855         uint64_t port_offloads;
17856
17857         rte_eth_dev_info_get(port_id, &dev_info);
17858         queue_offloads = dev_info.rx_queue_offload_capa;
17859         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17860
17861         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17862         printf("  Per Queue :");
17863         print_rx_offloads(queue_offloads);
17864
17865         printf("\n");
17866         printf("  Per Port  :");
17867         print_rx_offloads(port_offloads);
17868         printf("\n\n");
17869 }
17870
17871 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17872         .f = cmd_rx_offload_get_capa_parsed,
17873         .data = NULL,
17874         .help_str = "show port <port_id> rx_offload capabilities",
17875         .tokens = {
17876                 (void *)&cmd_rx_offload_get_capa_show,
17877                 (void *)&cmd_rx_offload_get_capa_port,
17878                 (void *)&cmd_rx_offload_get_capa_port_id,
17879                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17880                 (void *)&cmd_rx_offload_get_capa_capabilities,
17881                 NULL,
17882         }
17883 };
17884
17885 /* Get Rx offloads configuration */
17886 struct cmd_rx_offload_get_configuration_result {
17887         cmdline_fixed_string_t show;
17888         cmdline_fixed_string_t port;
17889         portid_t port_id;
17890         cmdline_fixed_string_t rx_offload;
17891         cmdline_fixed_string_t configuration;
17892 };
17893
17894 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17895         TOKEN_STRING_INITIALIZER
17896                 (struct cmd_rx_offload_get_configuration_result,
17897                  show, "show");
17898 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17899         TOKEN_STRING_INITIALIZER
17900                 (struct cmd_rx_offload_get_configuration_result,
17901                  port, "port");
17902 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17903         TOKEN_NUM_INITIALIZER
17904                 (struct cmd_rx_offload_get_configuration_result,
17905                  port_id, UINT16);
17906 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17907         TOKEN_STRING_INITIALIZER
17908                 (struct cmd_rx_offload_get_configuration_result,
17909                  rx_offload, "rx_offload");
17910 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17911         TOKEN_STRING_INITIALIZER
17912                 (struct cmd_rx_offload_get_configuration_result,
17913                  configuration, "configuration");
17914
17915 static void
17916 cmd_rx_offload_get_configuration_parsed(
17917         void *parsed_result,
17918         __attribute__((unused)) struct cmdline *cl,
17919         __attribute__((unused)) void *data)
17920 {
17921         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17922         struct rte_eth_dev_info dev_info;
17923         portid_t port_id = res->port_id;
17924         struct rte_port *port = &ports[port_id];
17925         uint64_t port_offloads;
17926         uint64_t queue_offloads;
17927         uint16_t nb_rx_queues;
17928         int q;
17929
17930         printf("Rx Offloading Configuration of port %d :\n", port_id);
17931
17932         port_offloads = port->dev_conf.rxmode.offloads;
17933         printf("  Port :");
17934         print_rx_offloads(port_offloads);
17935         printf("\n");
17936
17937         rte_eth_dev_info_get(port_id, &dev_info);
17938         nb_rx_queues = dev_info.nb_rx_queues;
17939         for (q = 0; q < nb_rx_queues; q++) {
17940                 queue_offloads = port->rx_conf[q].offloads;
17941                 printf("  Queue[%2d] :", q);
17942                 print_rx_offloads(queue_offloads);
17943                 printf("\n");
17944         }
17945         printf("\n");
17946 }
17947
17948 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17949         .f = cmd_rx_offload_get_configuration_parsed,
17950         .data = NULL,
17951         .help_str = "show port <port_id> rx_offload configuration",
17952         .tokens = {
17953                 (void *)&cmd_rx_offload_get_configuration_show,
17954                 (void *)&cmd_rx_offload_get_configuration_port,
17955                 (void *)&cmd_rx_offload_get_configuration_port_id,
17956                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17957                 (void *)&cmd_rx_offload_get_configuration_configuration,
17958                 NULL,
17959         }
17960 };
17961
17962 /* Enable/Disable a per port offloading */
17963 struct cmd_config_per_port_rx_offload_result {
17964         cmdline_fixed_string_t port;
17965         cmdline_fixed_string_t config;
17966         portid_t port_id;
17967         cmdline_fixed_string_t rx_offload;
17968         cmdline_fixed_string_t offload;
17969         cmdline_fixed_string_t on_off;
17970 };
17971
17972 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
17973         TOKEN_STRING_INITIALIZER
17974                 (struct cmd_config_per_port_rx_offload_result,
17975                  port, "port");
17976 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
17977         TOKEN_STRING_INITIALIZER
17978                 (struct cmd_config_per_port_rx_offload_result,
17979                  config, "config");
17980 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
17981         TOKEN_NUM_INITIALIZER
17982                 (struct cmd_config_per_port_rx_offload_result,
17983                  port_id, UINT16);
17984 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
17985         TOKEN_STRING_INITIALIZER
17986                 (struct cmd_config_per_port_rx_offload_result,
17987                  rx_offload, "rx_offload");
17988 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
17989         TOKEN_STRING_INITIALIZER
17990                 (struct cmd_config_per_port_rx_offload_result,
17991                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17992                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17993                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17994                            "crc_strip#scatter#timestamp#security#keep_crc");
17995 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
17996         TOKEN_STRING_INITIALIZER
17997                 (struct cmd_config_per_port_rx_offload_result,
17998                  on_off, "on#off");
17999
18000 static uint64_t
18001 search_rx_offload(const char *name)
18002 {
18003         uint64_t single_offload;
18004         const char *single_name;
18005         int found = 0;
18006         unsigned int bit;
18007
18008         single_offload = 1;
18009         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18010                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18011                 if (!strcasecmp(single_name, name)) {
18012                         found = 1;
18013                         break;
18014                 }
18015                 single_offload <<= 1;
18016         }
18017
18018         if (found)
18019                 return single_offload;
18020
18021         return 0;
18022 }
18023
18024 static void
18025 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18026                                 __attribute__((unused)) struct cmdline *cl,
18027                                 __attribute__((unused)) void *data)
18028 {
18029         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18030         portid_t port_id = res->port_id;
18031         struct rte_eth_dev_info dev_info;
18032         struct rte_port *port = &ports[port_id];
18033         uint64_t single_offload;
18034         uint16_t nb_rx_queues;
18035         int q;
18036
18037         if (port->port_status != RTE_PORT_STOPPED) {
18038                 printf("Error: Can't config offload when Port %d "
18039                        "is not stopped\n", port_id);
18040                 return;
18041         }
18042
18043         single_offload = search_rx_offload(res->offload);
18044         if (single_offload == 0) {
18045                 printf("Unknown offload name: %s\n", res->offload);
18046                 return;
18047         }
18048
18049         rte_eth_dev_info_get(port_id, &dev_info);
18050         nb_rx_queues = dev_info.nb_rx_queues;
18051         if (!strcmp(res->on_off, "on")) {
18052                 port->dev_conf.rxmode.offloads |= single_offload;
18053                 for (q = 0; q < nb_rx_queues; q++)
18054                         port->rx_conf[q].offloads |= single_offload;
18055         } else {
18056                 port->dev_conf.rxmode.offloads &= ~single_offload;
18057                 for (q = 0; q < nb_rx_queues; q++)
18058                         port->rx_conf[q].offloads &= ~single_offload;
18059         }
18060
18061         cmd_reconfig_device_queue(port_id, 1, 1);
18062 }
18063
18064 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18065         .f = cmd_config_per_port_rx_offload_parsed,
18066         .data = NULL,
18067         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18068                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18069                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18070                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18071                     "on|off",
18072         .tokens = {
18073                 (void *)&cmd_config_per_port_rx_offload_result_port,
18074                 (void *)&cmd_config_per_port_rx_offload_result_config,
18075                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18076                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18077                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18078                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18079                 NULL,
18080         }
18081 };
18082
18083 /* Enable/Disable a per queue offloading */
18084 struct cmd_config_per_queue_rx_offload_result {
18085         cmdline_fixed_string_t port;
18086         portid_t port_id;
18087         cmdline_fixed_string_t rxq;
18088         uint16_t queue_id;
18089         cmdline_fixed_string_t rx_offload;
18090         cmdline_fixed_string_t offload;
18091         cmdline_fixed_string_t on_off;
18092 };
18093
18094 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18095         TOKEN_STRING_INITIALIZER
18096                 (struct cmd_config_per_queue_rx_offload_result,
18097                  port, "port");
18098 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18099         TOKEN_NUM_INITIALIZER
18100                 (struct cmd_config_per_queue_rx_offload_result,
18101                  port_id, UINT16);
18102 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18103         TOKEN_STRING_INITIALIZER
18104                 (struct cmd_config_per_queue_rx_offload_result,
18105                  rxq, "rxq");
18106 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18107         TOKEN_NUM_INITIALIZER
18108                 (struct cmd_config_per_queue_rx_offload_result,
18109                  queue_id, UINT16);
18110 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18111         TOKEN_STRING_INITIALIZER
18112                 (struct cmd_config_per_queue_rx_offload_result,
18113                  rx_offload, "rx_offload");
18114 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18115         TOKEN_STRING_INITIALIZER
18116                 (struct cmd_config_per_queue_rx_offload_result,
18117                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18118                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18119                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18120                            "crc_strip#scatter#timestamp#security#keep_crc");
18121 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18122         TOKEN_STRING_INITIALIZER
18123                 (struct cmd_config_per_queue_rx_offload_result,
18124                  on_off, "on#off");
18125
18126 static void
18127 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18128                                 __attribute__((unused)) struct cmdline *cl,
18129                                 __attribute__((unused)) void *data)
18130 {
18131         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18132         struct rte_eth_dev_info dev_info;
18133         portid_t port_id = res->port_id;
18134         uint16_t queue_id = res->queue_id;
18135         struct rte_port *port = &ports[port_id];
18136         uint64_t single_offload;
18137
18138         if (port->port_status != RTE_PORT_STOPPED) {
18139                 printf("Error: Can't config offload when Port %d "
18140                        "is not stopped\n", port_id);
18141                 return;
18142         }
18143
18144         rte_eth_dev_info_get(port_id, &dev_info);
18145         if (queue_id >= dev_info.nb_rx_queues) {
18146                 printf("Error: input queue_id should be 0 ... "
18147                        "%d\n", dev_info.nb_rx_queues - 1);
18148                 return;
18149         }
18150
18151         single_offload = search_rx_offload(res->offload);
18152         if (single_offload == 0) {
18153                 printf("Unknown offload name: %s\n", res->offload);
18154                 return;
18155         }
18156
18157         if (!strcmp(res->on_off, "on"))
18158                 port->rx_conf[queue_id].offloads |= single_offload;
18159         else
18160                 port->rx_conf[queue_id].offloads &= ~single_offload;
18161
18162         cmd_reconfig_device_queue(port_id, 1, 1);
18163 }
18164
18165 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18166         .f = cmd_config_per_queue_rx_offload_parsed,
18167         .data = NULL,
18168         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18169                     "vlan_strip|ipv4_cksum|"
18170                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18171                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18172                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18173                     "on|off",
18174         .tokens = {
18175                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18176                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18177                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18178                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18179                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18180                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18181                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18182                 NULL,
18183         }
18184 };
18185
18186 /* Get Tx offloads capabilities */
18187 struct cmd_tx_offload_get_capa_result {
18188         cmdline_fixed_string_t show;
18189         cmdline_fixed_string_t port;
18190         portid_t port_id;
18191         cmdline_fixed_string_t tx_offload;
18192         cmdline_fixed_string_t capabilities;
18193 };
18194
18195 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18196         TOKEN_STRING_INITIALIZER
18197                 (struct cmd_tx_offload_get_capa_result,
18198                  show, "show");
18199 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18200         TOKEN_STRING_INITIALIZER
18201                 (struct cmd_tx_offload_get_capa_result,
18202                  port, "port");
18203 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18204         TOKEN_NUM_INITIALIZER
18205                 (struct cmd_tx_offload_get_capa_result,
18206                  port_id, UINT16);
18207 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18208         TOKEN_STRING_INITIALIZER
18209                 (struct cmd_tx_offload_get_capa_result,
18210                  tx_offload, "tx_offload");
18211 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18212         TOKEN_STRING_INITIALIZER
18213                 (struct cmd_tx_offload_get_capa_result,
18214                  capabilities, "capabilities");
18215
18216 static void
18217 print_tx_offloads(uint64_t offloads)
18218 {
18219         uint64_t single_offload;
18220         int begin;
18221         int end;
18222         int bit;
18223
18224         if (offloads == 0)
18225                 return;
18226
18227         begin = __builtin_ctzll(offloads);
18228         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18229
18230         single_offload = 1ULL << begin;
18231         for (bit = begin; bit < end; bit++) {
18232                 if (offloads & single_offload)
18233                         printf(" %s",
18234                                rte_eth_dev_tx_offload_name(single_offload));
18235                 single_offload <<= 1;
18236         }
18237 }
18238
18239 static void
18240 cmd_tx_offload_get_capa_parsed(
18241         void *parsed_result,
18242         __attribute__((unused)) struct cmdline *cl,
18243         __attribute__((unused)) void *data)
18244 {
18245         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18246         struct rte_eth_dev_info dev_info;
18247         portid_t port_id = res->port_id;
18248         uint64_t queue_offloads;
18249         uint64_t port_offloads;
18250
18251         rte_eth_dev_info_get(port_id, &dev_info);
18252         queue_offloads = dev_info.tx_queue_offload_capa;
18253         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18254
18255         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18256         printf("  Per Queue :");
18257         print_tx_offloads(queue_offloads);
18258
18259         printf("\n");
18260         printf("  Per Port  :");
18261         print_tx_offloads(port_offloads);
18262         printf("\n\n");
18263 }
18264
18265 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18266         .f = cmd_tx_offload_get_capa_parsed,
18267         .data = NULL,
18268         .help_str = "show port <port_id> tx_offload capabilities",
18269         .tokens = {
18270                 (void *)&cmd_tx_offload_get_capa_show,
18271                 (void *)&cmd_tx_offload_get_capa_port,
18272                 (void *)&cmd_tx_offload_get_capa_port_id,
18273                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18274                 (void *)&cmd_tx_offload_get_capa_capabilities,
18275                 NULL,
18276         }
18277 };
18278
18279 /* Get Tx offloads configuration */
18280 struct cmd_tx_offload_get_configuration_result {
18281         cmdline_fixed_string_t show;
18282         cmdline_fixed_string_t port;
18283         portid_t port_id;
18284         cmdline_fixed_string_t tx_offload;
18285         cmdline_fixed_string_t configuration;
18286 };
18287
18288 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18289         TOKEN_STRING_INITIALIZER
18290                 (struct cmd_tx_offload_get_configuration_result,
18291                  show, "show");
18292 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18293         TOKEN_STRING_INITIALIZER
18294                 (struct cmd_tx_offload_get_configuration_result,
18295                  port, "port");
18296 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18297         TOKEN_NUM_INITIALIZER
18298                 (struct cmd_tx_offload_get_configuration_result,
18299                  port_id, UINT16);
18300 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18301         TOKEN_STRING_INITIALIZER
18302                 (struct cmd_tx_offload_get_configuration_result,
18303                  tx_offload, "tx_offload");
18304 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18305         TOKEN_STRING_INITIALIZER
18306                 (struct cmd_tx_offload_get_configuration_result,
18307                  configuration, "configuration");
18308
18309 static void
18310 cmd_tx_offload_get_configuration_parsed(
18311         void *parsed_result,
18312         __attribute__((unused)) struct cmdline *cl,
18313         __attribute__((unused)) void *data)
18314 {
18315         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18316         struct rte_eth_dev_info dev_info;
18317         portid_t port_id = res->port_id;
18318         struct rte_port *port = &ports[port_id];
18319         uint64_t port_offloads;
18320         uint64_t queue_offloads;
18321         uint16_t nb_tx_queues;
18322         int q;
18323
18324         printf("Tx Offloading Configuration of port %d :\n", port_id);
18325
18326         port_offloads = port->dev_conf.txmode.offloads;
18327         printf("  Port :");
18328         print_tx_offloads(port_offloads);
18329         printf("\n");
18330
18331         rte_eth_dev_info_get(port_id, &dev_info);
18332         nb_tx_queues = dev_info.nb_tx_queues;
18333         for (q = 0; q < nb_tx_queues; q++) {
18334                 queue_offloads = port->tx_conf[q].offloads;
18335                 printf("  Queue[%2d] :", q);
18336                 print_tx_offloads(queue_offloads);
18337                 printf("\n");
18338         }
18339         printf("\n");
18340 }
18341
18342 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18343         .f = cmd_tx_offload_get_configuration_parsed,
18344         .data = NULL,
18345         .help_str = "show port <port_id> tx_offload configuration",
18346         .tokens = {
18347                 (void *)&cmd_tx_offload_get_configuration_show,
18348                 (void *)&cmd_tx_offload_get_configuration_port,
18349                 (void *)&cmd_tx_offload_get_configuration_port_id,
18350                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18351                 (void *)&cmd_tx_offload_get_configuration_configuration,
18352                 NULL,
18353         }
18354 };
18355
18356 /* Enable/Disable a per port offloading */
18357 struct cmd_config_per_port_tx_offload_result {
18358         cmdline_fixed_string_t port;
18359         cmdline_fixed_string_t config;
18360         portid_t port_id;
18361         cmdline_fixed_string_t tx_offload;
18362         cmdline_fixed_string_t offload;
18363         cmdline_fixed_string_t on_off;
18364 };
18365
18366 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18367         TOKEN_STRING_INITIALIZER
18368                 (struct cmd_config_per_port_tx_offload_result,
18369                  port, "port");
18370 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18371         TOKEN_STRING_INITIALIZER
18372                 (struct cmd_config_per_port_tx_offload_result,
18373                  config, "config");
18374 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18375         TOKEN_NUM_INITIALIZER
18376                 (struct cmd_config_per_port_tx_offload_result,
18377                  port_id, UINT16);
18378 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18379         TOKEN_STRING_INITIALIZER
18380                 (struct cmd_config_per_port_tx_offload_result,
18381                  tx_offload, "tx_offload");
18382 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18383         TOKEN_STRING_INITIALIZER
18384                 (struct cmd_config_per_port_tx_offload_result,
18385                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18386                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18387                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18388                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18389                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18390                           "match_metadata");
18391 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18392         TOKEN_STRING_INITIALIZER
18393                 (struct cmd_config_per_port_tx_offload_result,
18394                  on_off, "on#off");
18395
18396 static uint64_t
18397 search_tx_offload(const char *name)
18398 {
18399         uint64_t single_offload;
18400         const char *single_name;
18401         int found = 0;
18402         unsigned int bit;
18403
18404         single_offload = 1;
18405         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18406                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18407                 if (single_name == NULL)
18408                         break;
18409                 if (!strcasecmp(single_name, name)) {
18410                         found = 1;
18411                         break;
18412                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18413                         break;
18414                 single_offload <<= 1;
18415         }
18416
18417         if (found)
18418                 return single_offload;
18419
18420         return 0;
18421 }
18422
18423 static void
18424 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18425                                 __attribute__((unused)) struct cmdline *cl,
18426                                 __attribute__((unused)) void *data)
18427 {
18428         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18429         portid_t port_id = res->port_id;
18430         struct rte_eth_dev_info dev_info;
18431         struct rte_port *port = &ports[port_id];
18432         uint64_t single_offload;
18433         uint16_t nb_tx_queues;
18434         int q;
18435
18436         if (port->port_status != RTE_PORT_STOPPED) {
18437                 printf("Error: Can't config offload when Port %d "
18438                        "is not stopped\n", port_id);
18439                 return;
18440         }
18441
18442         single_offload = search_tx_offload(res->offload);
18443         if (single_offload == 0) {
18444                 printf("Unknown offload name: %s\n", res->offload);
18445                 return;
18446         }
18447
18448         rte_eth_dev_info_get(port_id, &dev_info);
18449         nb_tx_queues = dev_info.nb_tx_queues;
18450         if (!strcmp(res->on_off, "on")) {
18451                 port->dev_conf.txmode.offloads |= single_offload;
18452                 for (q = 0; q < nb_tx_queues; q++)
18453                         port->tx_conf[q].offloads |= single_offload;
18454         } else {
18455                 port->dev_conf.txmode.offloads &= ~single_offload;
18456                 for (q = 0; q < nb_tx_queues; q++)
18457                         port->tx_conf[q].offloads &= ~single_offload;
18458         }
18459
18460         cmd_reconfig_device_queue(port_id, 1, 1);
18461 }
18462
18463 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18464         .f = cmd_config_per_port_tx_offload_parsed,
18465         .data = NULL,
18466         .help_str = "port config <port_id> tx_offload "
18467                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18468                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18469                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18470                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18471                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18472                     "match_metadata on|off",
18473         .tokens = {
18474                 (void *)&cmd_config_per_port_tx_offload_result_port,
18475                 (void *)&cmd_config_per_port_tx_offload_result_config,
18476                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18477                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18478                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18479                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18480                 NULL,
18481         }
18482 };
18483
18484 /* Enable/Disable a per queue offloading */
18485 struct cmd_config_per_queue_tx_offload_result {
18486         cmdline_fixed_string_t port;
18487         portid_t port_id;
18488         cmdline_fixed_string_t txq;
18489         uint16_t queue_id;
18490         cmdline_fixed_string_t tx_offload;
18491         cmdline_fixed_string_t offload;
18492         cmdline_fixed_string_t on_off;
18493 };
18494
18495 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18496         TOKEN_STRING_INITIALIZER
18497                 (struct cmd_config_per_queue_tx_offload_result,
18498                  port, "port");
18499 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18500         TOKEN_NUM_INITIALIZER
18501                 (struct cmd_config_per_queue_tx_offload_result,
18502                  port_id, UINT16);
18503 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18504         TOKEN_STRING_INITIALIZER
18505                 (struct cmd_config_per_queue_tx_offload_result,
18506                  txq, "txq");
18507 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18508         TOKEN_NUM_INITIALIZER
18509                 (struct cmd_config_per_queue_tx_offload_result,
18510                  queue_id, UINT16);
18511 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18512         TOKEN_STRING_INITIALIZER
18513                 (struct cmd_config_per_queue_tx_offload_result,
18514                  tx_offload, "tx_offload");
18515 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18516         TOKEN_STRING_INITIALIZER
18517                 (struct cmd_config_per_queue_tx_offload_result,
18518                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18519                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18520                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18521                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18522                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18523 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18524         TOKEN_STRING_INITIALIZER
18525                 (struct cmd_config_per_queue_tx_offload_result,
18526                  on_off, "on#off");
18527
18528 static void
18529 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18530                                 __attribute__((unused)) struct cmdline *cl,
18531                                 __attribute__((unused)) void *data)
18532 {
18533         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18534         struct rte_eth_dev_info dev_info;
18535         portid_t port_id = res->port_id;
18536         uint16_t queue_id = res->queue_id;
18537         struct rte_port *port = &ports[port_id];
18538         uint64_t single_offload;
18539
18540         if (port->port_status != RTE_PORT_STOPPED) {
18541                 printf("Error: Can't config offload when Port %d "
18542                        "is not stopped\n", port_id);
18543                 return;
18544         }
18545
18546         rte_eth_dev_info_get(port_id, &dev_info);
18547         if (queue_id >= dev_info.nb_tx_queues) {
18548                 printf("Error: input queue_id should be 0 ... "
18549                        "%d\n", dev_info.nb_tx_queues - 1);
18550                 return;
18551         }
18552
18553         single_offload = search_tx_offload(res->offload);
18554         if (single_offload == 0) {
18555                 printf("Unknown offload name: %s\n", res->offload);
18556                 return;
18557         }
18558
18559         if (!strcmp(res->on_off, "on"))
18560                 port->tx_conf[queue_id].offloads |= single_offload;
18561         else
18562                 port->tx_conf[queue_id].offloads &= ~single_offload;
18563
18564         cmd_reconfig_device_queue(port_id, 1, 1);
18565 }
18566
18567 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18568         .f = cmd_config_per_queue_tx_offload_parsed,
18569         .data = NULL,
18570         .help_str = "port <port_id> txq <queue_id> tx_offload "
18571                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18572                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18573                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18574                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18575                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18576                     "on|off",
18577         .tokens = {
18578                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18579                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18580                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18581                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18582                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18583                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18584                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18585                 NULL,
18586         }
18587 };
18588
18589 /* *** configure tx_metadata for specific port *** */
18590 struct cmd_config_tx_metadata_specific_result {
18591         cmdline_fixed_string_t port;
18592         cmdline_fixed_string_t keyword;
18593         uint16_t port_id;
18594         cmdline_fixed_string_t item;
18595         uint32_t value;
18596 };
18597
18598 static void
18599 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18600                                 __attribute__((unused)) struct cmdline *cl,
18601                                 __attribute__((unused)) void *data)
18602 {
18603         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18604
18605         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18606                 return;
18607         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18608         /* Add/remove callback to insert valid metadata in every Tx packet. */
18609         if (ports[res->port_id].tx_metadata)
18610                 add_tx_md_callback(res->port_id);
18611         else
18612                 remove_tx_md_callback(res->port_id);
18613 }
18614
18615 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18616         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18617                         port, "port");
18618 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18619         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18620                         keyword, "config");
18621 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18622         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18623                         port_id, UINT16);
18624 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18625         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18626                         item, "tx_metadata");
18627 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18628         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18629                         value, UINT32);
18630
18631 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18632         .f = cmd_config_tx_metadata_specific_parsed,
18633         .data = NULL,
18634         .help_str = "port config <port_id> tx_metadata <value>",
18635         .tokens = {
18636                 (void *)&cmd_config_tx_metadata_specific_port,
18637                 (void *)&cmd_config_tx_metadata_specific_keyword,
18638                 (void *)&cmd_config_tx_metadata_specific_id,
18639                 (void *)&cmd_config_tx_metadata_specific_item,
18640                 (void *)&cmd_config_tx_metadata_specific_value,
18641                 NULL,
18642         },
18643 };
18644
18645 /* *** display tx_metadata per port configuration *** */
18646 struct cmd_show_tx_metadata_result {
18647         cmdline_fixed_string_t cmd_show;
18648         cmdline_fixed_string_t cmd_port;
18649         cmdline_fixed_string_t cmd_keyword;
18650         portid_t cmd_pid;
18651 };
18652
18653 static void
18654 cmd_show_tx_metadata_parsed(void *parsed_result,
18655                 __attribute__((unused)) struct cmdline *cl,
18656                 __attribute__((unused)) void *data)
18657 {
18658         struct cmd_show_tx_metadata_result *res = parsed_result;
18659
18660         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18661                 printf("invalid port id %u\n", res->cmd_pid);
18662                 return;
18663         }
18664         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18665                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18666                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18667         }
18668 }
18669
18670 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18671         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18672                         cmd_show, "show");
18673 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18674         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18675                         cmd_port, "port");
18676 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18677         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18678                         cmd_pid, UINT16);
18679 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18680         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18681                         cmd_keyword, "tx_metadata");
18682
18683 cmdline_parse_inst_t cmd_show_tx_metadata = {
18684         .f = cmd_show_tx_metadata_parsed,
18685         .data = NULL,
18686         .help_str = "show port <port_id> tx_metadata",
18687         .tokens = {
18688                 (void *)&cmd_show_tx_metadata_show,
18689                 (void *)&cmd_show_tx_metadata_port,
18690                 (void *)&cmd_show_tx_metadata_pid,
18691                 (void *)&cmd_show_tx_metadata_keyword,
18692                 NULL,
18693         },
18694 };
18695
18696 /* ******************************************************************************** */
18697
18698 /* list of instructions */
18699 cmdline_parse_ctx_t main_ctx[] = {
18700         (cmdline_parse_inst_t *)&cmd_help_brief,
18701         (cmdline_parse_inst_t *)&cmd_help_long,
18702         (cmdline_parse_inst_t *)&cmd_quit,
18703         (cmdline_parse_inst_t *)&cmd_load_from_file,
18704         (cmdline_parse_inst_t *)&cmd_showport,
18705         (cmdline_parse_inst_t *)&cmd_showqueue,
18706         (cmdline_parse_inst_t *)&cmd_showportall,
18707         (cmdline_parse_inst_t *)&cmd_showcfg,
18708         (cmdline_parse_inst_t *)&cmd_showfwdall,
18709         (cmdline_parse_inst_t *)&cmd_start,
18710         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18711         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18712         (cmdline_parse_inst_t *)&cmd_set_link_up,
18713         (cmdline_parse_inst_t *)&cmd_set_link_down,
18714         (cmdline_parse_inst_t *)&cmd_reset,
18715         (cmdline_parse_inst_t *)&cmd_set_numbers,
18716         (cmdline_parse_inst_t *)&cmd_set_log,
18717         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18718         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18719         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18720         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18721         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18722         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18723         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18724         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18725         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18726         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18727         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18728         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18729         (cmdline_parse_inst_t *)&cmd_set_link_check,
18730         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18731         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18732         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18733         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18734 #ifdef RTE_LIBRTE_PMD_BOND
18735         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18736         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18737         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18738         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18739         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18740         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18741         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18742         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18743         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18744         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18745         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18746 #endif
18747         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18748         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18749         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18750         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18751         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18752         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18753         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18754         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18755         (cmdline_parse_inst_t *)&cmd_csum_set,
18756         (cmdline_parse_inst_t *)&cmd_csum_show,
18757         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18758         (cmdline_parse_inst_t *)&cmd_tso_set,
18759         (cmdline_parse_inst_t *)&cmd_tso_show,
18760         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18761         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18762         (cmdline_parse_inst_t *)&cmd_gro_enable,
18763         (cmdline_parse_inst_t *)&cmd_gro_flush,
18764         (cmdline_parse_inst_t *)&cmd_gro_show,
18765         (cmdline_parse_inst_t *)&cmd_gso_enable,
18766         (cmdline_parse_inst_t *)&cmd_gso_size,
18767         (cmdline_parse_inst_t *)&cmd_gso_show,
18768         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18769         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18770         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18771         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18772         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18773         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18774         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18775         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18776         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18777         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18778         (cmdline_parse_inst_t *)&cmd_config_dcb,
18779         (cmdline_parse_inst_t *)&cmd_read_reg,
18780         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18781         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18782         (cmdline_parse_inst_t *)&cmd_write_reg,
18783         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18784         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18785         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18786         (cmdline_parse_inst_t *)&cmd_stop,
18787         (cmdline_parse_inst_t *)&cmd_mac_addr,
18788         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18789         (cmdline_parse_inst_t *)&cmd_set_qmap,
18790         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18791         (cmdline_parse_inst_t *)&cmd_operate_port,
18792         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18793         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18794         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18795         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18796         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18797         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18798         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18799         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18800         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18801         (cmdline_parse_inst_t *)&cmd_config_mtu,
18802         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18803         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18804         (cmdline_parse_inst_t *)&cmd_config_rss,
18805         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18806         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18807         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18808         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18809         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18810         (cmdline_parse_inst_t *)&cmd_showport_reta,
18811         (cmdline_parse_inst_t *)&cmd_config_burst,
18812         (cmdline_parse_inst_t *)&cmd_config_thresh,
18813         (cmdline_parse_inst_t *)&cmd_config_threshold,
18814         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18815         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18816         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18817         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18818         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18819         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18820         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18821         (cmdline_parse_inst_t *)&cmd_global_config,
18822         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18823         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18824         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18825         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18826         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18827         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18828         (cmdline_parse_inst_t *)&cmd_dump,
18829         (cmdline_parse_inst_t *)&cmd_dump_one,
18830         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18831         (cmdline_parse_inst_t *)&cmd_syn_filter,
18832         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18833         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18834         (cmdline_parse_inst_t *)&cmd_flex_filter,
18835         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18836         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18837         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18838         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18839         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18840         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18841         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18842         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18843         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18844         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18845         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18846         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18847         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18848         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18849         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18850         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18851         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18852         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18853         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18854         (cmdline_parse_inst_t *)&cmd_flow,
18855         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18856         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18857         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18858         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18859         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18860         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18861         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18862         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18863         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18864         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18865         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18866         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18867         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18868         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18869         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18870         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18871         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18872         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18873         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18874         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18875         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18876         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18877         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18878         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18879         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18880         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18881         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18882         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18883         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18884         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18885         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18886         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18887         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18888         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18889         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18890         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18891         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18892         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18893         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18894         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18895         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18896         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18897         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18898         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18899         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18900         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18901         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18902         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18903         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18904 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
18905         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
18906 #endif
18907         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18908         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18909         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18910         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18911         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18912         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18913         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18914         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18915         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18916         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18917         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18918         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18919         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18920         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18921         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18922         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18923         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18924         (cmdline_parse_inst_t *)&cmd_ddp_add,
18925         (cmdline_parse_inst_t *)&cmd_ddp_del,
18926         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18927         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18928         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18929         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18930         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18931         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18932         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18933         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18934         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18935         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18936
18937         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18938         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18939         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18940         (cmdline_parse_inst_t *)&cmd_queue_region,
18941         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18942         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18943         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18944         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18945         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18946         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18947         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18948         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18949         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18950         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18951         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18952         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18953         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18954         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18955         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18956         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18957         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18958         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18959         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18960         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18961         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18962         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18963         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18964         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18965         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18966         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18967         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18968         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18969         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18970         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18971         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18972         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18973         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18974         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18975         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18976 #ifdef RTE_LIBRTE_BPF
18977         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18978         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18979 #endif
18980         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18981         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18982         NULL,
18983 };
18984
18985 /* read cmdline commands from file */
18986 void
18987 cmdline_read_from_file(const char *filename)
18988 {
18989         struct cmdline *cl;
18990
18991         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18992         if (cl == NULL) {
18993                 printf("Failed to create file based cmdline context: %s\n",
18994                        filename);
18995                 return;
18996         }
18997
18998         cmdline_interact(cl);
18999         cmdline_quit(cl);
19000
19001         cmdline_free(cl);
19002
19003         printf("Read CLI commands from %s\n", filename);
19004 }
19005
19006 /* prompt function, called from main on MASTER lcore */
19007 void
19008 prompt(void)
19009 {
19010         /* initialize non-constant commands */
19011         cmd_set_fwd_mode_init();
19012         cmd_set_fwd_retry_mode_init();
19013
19014         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19015         if (testpmd_cl == NULL)
19016                 return;
19017         cmdline_interact(testpmd_cl);
19018         cmdline_stdin_exit(testpmd_cl);
19019 }
19020
19021 void
19022 prompt_exit(void)
19023 {
19024         if (testpmd_cl != NULL)
19025                 cmdline_quit(testpmd_cl);
19026 }
19027
19028 static void
19029 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19030 {
19031         if (id == (portid_t)RTE_PORT_ALL) {
19032                 portid_t pid;
19033
19034                 RTE_ETH_FOREACH_DEV(pid) {
19035                         /* check if need_reconfig has been set to 1 */
19036                         if (ports[pid].need_reconfig == 0)
19037                                 ports[pid].need_reconfig = dev;
19038                         /* check if need_reconfig_queues has been set to 1 */
19039                         if (ports[pid].need_reconfig_queues == 0)
19040                                 ports[pid].need_reconfig_queues = queue;
19041                 }
19042         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19043                 /* check if need_reconfig has been set to 1 */
19044                 if (ports[id].need_reconfig == 0)
19045                         ports[id].need_reconfig = dev;
19046                 /* check if need_reconfig_queues has been set to 1 */
19047                 if (ports[id].need_reconfig_queues == 0)
19048                         ports[id].need_reconfig_queues = queue;
19049         }
19050 }