app/testpmd: support raw encap/decap actions
[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                         , list_pkt_forwarding_modes()
737                 );
738         }
739
740         if (show_all || !strcmp(res->section, "ports")) {
741
742                 cmdline_printf(
743                         cl,
744                         "\n"
745                         "Port Operations:\n"
746                         "----------------\n\n"
747
748                         "port start (port_id|all)\n"
749                         "    Start all ports or port_id.\n\n"
750
751                         "port stop (port_id|all)\n"
752                         "    Stop all ports or port_id.\n\n"
753
754                         "port close (port_id|all)\n"
755                         "    Close all ports or port_id.\n\n"
756
757                         "port attach (ident)\n"
758                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
759
760                         "port detach (port_id)\n"
761                         "    Detach physical or virtual dev by port_id\n\n"
762
763                         "port config (port_id|all)"
764                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
765                         " duplex (half|full|auto)\n"
766                         "    Set speed and duplex for all ports or port_id\n\n"
767
768                         "port config (port_id|all) loopback (mode)\n"
769                         "    Set loopback mode for all ports or port_id\n\n"
770
771                         "port config all (rxq|txq|rxd|txd) (value)\n"
772                         "    Set number for rxq/txq/rxd/txd.\n\n"
773
774                         "port config all max-pkt-len (value)\n"
775                         "    Set the max packet length.\n\n"
776
777                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
778                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
779                         " (on|off)\n"
780                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
781                         " for ports.\n\n"
782
783                         "port config all rss (all|default|ip|tcp|udp|sctp|"
784                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
785                         "    Set the RSS mode.\n\n"
786
787                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
788                         "    Set the RSS redirection table.\n\n"
789
790                         "port config (port_id) dcb vt (on|off) (traffic_class)"
791                         " pfc (on|off)\n"
792                         "    Set the DCB mode.\n\n"
793
794                         "port config all burst (value)\n"
795                         "    Set the number of packets per burst.\n\n"
796
797                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
798                         " (value)\n"
799                         "    Set the ring prefetch/host/writeback threshold"
800                         " for tx/rx queue.\n\n"
801
802                         "port config all (txfreet|txrst|rxfreet) (value)\n"
803                         "    Set free threshold for rx/tx, or set"
804                         " tx rs bit threshold.\n\n"
805                         "port config mtu X value\n"
806                         "    Set the MTU of port X to a given value\n\n"
807
808                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
809                         "    Set a rx/tx queue's ring size configuration, the new"
810                         " value will take effect after command that (re-)start the port"
811                         " or command that setup the specific queue\n\n"
812
813                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
814                         "    Start/stop a rx/tx queue of port X. Only take effect"
815                         " when port X is started\n\n"
816
817                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
818                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
819                         " take effect when port X is stopped.\n\n"
820
821                         "port (port_id) (rxq|txq) (queue_id) setup\n"
822                         "    Setup a rx/tx queue of port X.\n\n"
823
824                         "port config (port_id|all) l2-tunnel E-tag ether-type"
825                         " (value)\n"
826                         "    Set the value of E-tag ether-type.\n\n"
827
828                         "port config (port_id|all) l2-tunnel E-tag"
829                         " (enable|disable)\n"
830                         "    Enable/disable the E-tag support.\n\n"
831
832                         "port config (port_id) pctype mapping reset\n"
833                         "    Reset flow type to pctype mapping on a port\n\n"
834
835                         "port config (port_id) pctype mapping update"
836                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
837                         "    Update a flow type to pctype mapping item on a port\n\n"
838
839                         "port config (port_id) pctype (pctype_id) hash_inset|"
840                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
841                         " (field_idx)\n"
842                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
843
844                         "port config (port_id) pctype (pctype_id) hash_inset|"
845                         "fdir_inset|fdir_flx_inset clear all"
846                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
847
848                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
849                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
850
851                         "port config <port_id> rx_offload vlan_strip|"
852                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
853                         "outer_ipv4_cksum|macsec_strip|header_split|"
854                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
855                         "scatter|timestamp|security|keep_crc on|off\n"
856                         "     Enable or disable a per port Rx offloading"
857                         " on all Rx queues of a port\n\n"
858
859                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
860                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
861                         "outer_ipv4_cksum|macsec_strip|header_split|"
862                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
863                         "scatter|timestamp|security|keep_crc on|off\n"
864                         "    Enable or disable a per queue Rx offloading"
865                         " only on a specific Rx queue\n\n"
866
867                         "port config (port_id) tx_offload vlan_insert|"
868                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
869                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
870                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
871                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
872                         "security|match_metadata on|off\n"
873                         "    Enable or disable a per port Tx offloading"
874                         " on all Tx queues of a port\n\n"
875
876                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
880                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
881                         " on|off\n"
882                         "    Enable or disable a per queue Tx offloading"
883                         " only on a specific Tx queue\n\n"
884
885                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
886                         "    Load an eBPF program as a callback"
887                         " for particular RX/TX queue\n\n"
888
889                         "bpf-unload rx|tx (port) (queue)\n"
890                         "    Unload previously loaded eBPF program"
891                         " for particular RX/TX queue\n\n"
892
893                         "port config (port_id) tx_metadata (value)\n"
894                         "    Set Tx metadata value per port. Testpmd will add this value"
895                         " to any Tx packet sent from this port\n\n"
896                 );
897         }
898
899         if (show_all || !strcmp(res->section, "registers")) {
900
901                 cmdline_printf(
902                         cl,
903                         "\n"
904                         "Registers:\n"
905                         "----------\n\n"
906
907                         "read reg (port_id) (address)\n"
908                         "    Display value of a port register.\n\n"
909
910                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
911                         "    Display a port register bit field.\n\n"
912
913                         "read regbit (port_id) (address) (bit_x)\n"
914                         "    Display a single port register bit.\n\n"
915
916                         "write reg (port_id) (address) (value)\n"
917                         "    Set value of a port register.\n\n"
918
919                         "write regfield (port_id) (address) (bit_x) (bit_y)"
920                         " (value)\n"
921                         "    Set bit field of a port register.\n\n"
922
923                         "write regbit (port_id) (address) (bit_x) (value)\n"
924                         "    Set single bit value of a port register.\n\n"
925                 );
926         }
927         if (show_all || !strcmp(res->section, "filters")) {
928
929                 cmdline_printf(
930                         cl,
931                         "\n"
932                         "filters:\n"
933                         "--------\n\n"
934
935                         "ethertype_filter (port_id) (add|del)"
936                         " (mac_addr|mac_ignr) (mac_address) ethertype"
937                         " (ether_type) (drop|fwd) queue (queue_id)\n"
938                         "    Add/Del an ethertype filter.\n\n"
939
940                         "2tuple_filter (port_id) (add|del)"
941                         " dst_port (dst_port_value) protocol (protocol_value)"
942                         " mask (mask_value) tcp_flags (tcp_flags_value)"
943                         " priority (prio_value) queue (queue_id)\n"
944                         "    Add/Del a 2tuple filter.\n\n"
945
946                         "5tuple_filter (port_id) (add|del)"
947                         " dst_ip (dst_address) src_ip (src_address)"
948                         " dst_port (dst_port_value) src_port (src_port_value)"
949                         " protocol (protocol_value)"
950                         " mask (mask_value) tcp_flags (tcp_flags_value)"
951                         " priority (prio_value) queue (queue_id)\n"
952                         "    Add/Del a 5tuple filter.\n\n"
953
954                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
955                         "    Add/Del syn filter.\n\n"
956
957                         "flex_filter (port_id) (add|del) len (len_value)"
958                         " bytes (bytes_value) mask (mask_value)"
959                         " priority (prio_value) queue (queue_id)\n"
960                         "    Add/Del a flex filter.\n\n"
961
962                         "flow_director_filter (port_id) mode IP (add|del|update)"
963                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
964                         " src (src_ip_address) dst (dst_ip_address)"
965                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
966                         " vlan (vlan_value) flexbytes (flexbytes_value)"
967                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
968                         " fd_id (fd_id_value)\n"
969                         "    Add/Del an IP type flow director filter.\n\n"
970
971                         "flow_director_filter (port_id) mode IP (add|del|update)"
972                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
973                         " src (src_ip_address) (src_port)"
974                         " dst (dst_ip_address) (dst_port)"
975                         " tos (tos_value) ttl (ttl_value)"
976                         " vlan (vlan_value) flexbytes (flexbytes_value)"
977                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
978                         " fd_id (fd_id_value)\n"
979                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
980
981                         "flow_director_filter (port_id) mode IP (add|del|update)"
982                         " flow (ipv4-sctp|ipv6-sctp)"
983                         " src (src_ip_address) (src_port)"
984                         " dst (dst_ip_address) (dst_port)"
985                         " tag (verification_tag) "
986                         " tos (tos_value) ttl (ttl_value)"
987                         " vlan (vlan_value)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a SCTP type flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode IP (add|del|update)"
993                         " flow l2_payload ether (ethertype)"
994                         " flexbytes (flexbytes_value) (drop|fwd)"
995                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
996                         "    Add/Del a l2 payload type flow director filter.\n\n"
997
998                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
999                         " mac (mac_address) vlan (vlan_value)"
1000                         " flexbytes (flexbytes_value) (drop|fwd)"
1001                         " queue (queue_id) fd_id (fd_id_value)\n"
1002                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1003
1004                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1005                         " mac (mac_address) vlan (vlan_value)"
1006                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1007                         " flexbytes (flexbytes_value) (drop|fwd)"
1008                         " queue (queue_id) fd_id (fd_id_value)\n"
1009                         "    Add/Del a Tunnel flow director filter.\n\n"
1010
1011                         "flow_director_filter (port_id) mode raw (add|del|update)"
1012                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1013                         " fd_id (fd_id_value) packet (packet file name)\n"
1014                         "    Add/Del a raw type flow director filter.\n\n"
1015
1016                         "flush_flow_director (port_id)\n"
1017                         "    Flush all flow director entries of a device.\n\n"
1018
1019                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1020                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1021                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1022                         "    Set flow director IP mask.\n\n"
1023
1024                         "flow_director_mask (port_id) mode MAC-VLAN"
1025                         " vlan (vlan_value)\n"
1026                         "    Set flow director MAC-VLAN mask.\n\n"
1027
1028                         "flow_director_mask (port_id) mode Tunnel"
1029                         " vlan (vlan_value) mac (mac_value)"
1030                         " tunnel-type (tunnel_type_value)"
1031                         " tunnel-id (tunnel_id_value)\n"
1032                         "    Set flow director Tunnel mask.\n\n"
1033
1034                         "flow_director_flex_mask (port_id)"
1035                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1036                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1037                         " (mask)\n"
1038                         "    Configure mask of flex payload.\n\n"
1039
1040                         "flow_director_flex_payload (port_id)"
1041                         " (raw|l2|l3|l4) (config)\n"
1042                         "    Configure flex payload selection.\n\n"
1043
1044                         "get_sym_hash_ena_per_port (port_id)\n"
1045                         "    get symmetric hash enable configuration per port.\n\n"
1046
1047                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1048                         "    set symmetric hash enable configuration per port"
1049                         " to enable or disable.\n\n"
1050
1051                         "get_hash_global_config (port_id)\n"
1052                         "    Get the global configurations of hash filters.\n\n"
1053
1054                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1055                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1056                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1057                         " (enable|disable)\n"
1058                         "    Set the global configurations of hash filters.\n\n"
1059
1060                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1061                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1062                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1063                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1064                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1065                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1066                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1067                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1068                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1069                         "fld-8th|none) (select|add)\n"
1070                         "    Set the input set for hash.\n\n"
1071
1072                         "set_fdir_input_set (port_id) "
1073                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1074                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1075                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1076                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1077                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1078                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1079                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1080                         " (select|add)\n"
1081                         "    Set the input set for FDir.\n\n"
1082
1083                         "flow validate {port_id}"
1084                         " [group {group_id}] [priority {level}]"
1085                         " [ingress] [egress]"
1086                         " pattern {item} [/ {item} [...]] / end"
1087                         " actions {action} [/ {action} [...]] / end\n"
1088                         "    Check whether a flow rule can be created.\n\n"
1089
1090                         "flow create {port_id}"
1091                         " [group {group_id}] [priority {level}]"
1092                         " [ingress] [egress]"
1093                         " pattern {item} [/ {item} [...]] / end"
1094                         " actions {action} [/ {action} [...]] / end\n"
1095                         "    Create a flow rule.\n\n"
1096
1097                         "flow destroy {port_id} rule {rule_id} [...]\n"
1098                         "    Destroy specific flow rules.\n\n"
1099
1100                         "flow flush {port_id}\n"
1101                         "    Destroy all flow rules.\n\n"
1102
1103                         "flow query {port_id} {rule_id} {action}\n"
1104                         "    Query an existing flow rule.\n\n"
1105
1106                         "flow list {port_id} [group {group_id}] [...]\n"
1107                         "    List existing flow rules sorted by priority,"
1108                         " filtered by group identifiers.\n\n"
1109
1110                         "flow isolate {port_id} {boolean}\n"
1111                         "    Restrict ingress traffic to the defined"
1112                         " flow rules\n\n"
1113
1114                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1115                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1116                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1117                         "       Configure the VXLAN encapsulation for flows.\n\n"
1118
1119                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1120                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1121                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1122                         " eth-dst (eth-dst)\n"
1123                         "       Configure the VXLAN encapsulation for flows.\n\n"
1124
1125                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1126                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1127                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1128                         " eth-dst (eth-dst)\n"
1129                         "       Configure the VXLAN encapsulation for flows.\n\n"
1130
1131                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1132                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1133                         " (eth-dst)\n"
1134                         "       Configure the NVGRE encapsulation for flows.\n\n"
1135
1136                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1137                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1138                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1139                         "       Configure the NVGRE encapsulation for flows.\n\n"
1140
1141                         "set raw_encap {flow items}\n"
1142                         "       Configure the encapsulation with raw data.\n\n"
1143
1144                         "set raw_decap {flow items}\n"
1145                         "       Configure the decapsulation with raw data.\n\n"
1146
1147                 );
1148         }
1149
1150         if (show_all || !strcmp(res->section, "traffic_management")) {
1151                 cmdline_printf(
1152                         cl,
1153                         "\n"
1154                         "Traffic Management:\n"
1155                         "--------------\n"
1156                         "show port tm cap (port_id)\n"
1157                         "       Display the port TM capability.\n\n"
1158
1159                         "show port tm level cap (port_id) (level_id)\n"
1160                         "       Display the port TM hierarchical level capability.\n\n"
1161
1162                         "show port tm node cap (port_id) (node_id)\n"
1163                         "       Display the port TM node capability.\n\n"
1164
1165                         "show port tm node type (port_id) (node_id)\n"
1166                         "       Display the port TM node type.\n\n"
1167
1168                         "show port tm node stats (port_id) (node_id) (clear)\n"
1169                         "       Display the port TM node stats.\n\n"
1170
1171 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1172                         "set port tm hierarchy default (port_id)\n"
1173                         "       Set default traffic Management hierarchy on a port\n\n"
1174 #endif
1175
1176                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1177                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1178                         " (packet_length_adjust)\n"
1179                         "       Add port tm node private shaper profile.\n\n"
1180
1181                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1182                         "       Delete port tm node private shaper profile.\n\n"
1183
1184                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1185                         " (shaper_profile_id)\n"
1186                         "       Add/update port tm node shared shaper.\n\n"
1187
1188                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1189                         "       Delete port tm node shared shaper.\n\n"
1190
1191                         "set port tm node shaper profile (port_id) (node_id)"
1192                         " (shaper_profile_id)\n"
1193                         "       Set port tm node shaper profile.\n\n"
1194
1195                         "add port tm node wred profile (port_id) (wred_profile_id)"
1196                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1197                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1198                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1199                         "       Add port tm node wred profile.\n\n"
1200
1201                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1202                         "       Delete port tm node wred profile.\n\n"
1203
1204                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1205                         " (priority) (weight) (level_id) (shaper_profile_id)"
1206                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1207                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1208                         "       Add port tm nonleaf node.\n\n"
1209
1210                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1211                         " (priority) (weight) (level_id) (shaper_profile_id)"
1212                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1213                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1214                         "       Add port tm leaf node.\n\n"
1215
1216                         "del port tm node (port_id) (node_id)\n"
1217                         "       Delete port tm node.\n\n"
1218
1219                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1220                         " (priority) (weight)\n"
1221                         "       Set port tm node parent.\n\n"
1222
1223                         "suspend port tm node (port_id) (node_id)"
1224                         "       Suspend tm node.\n\n"
1225
1226                         "resume port tm node (port_id) (node_id)"
1227                         "       Resume tm node.\n\n"
1228
1229                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1230                         "       Commit tm hierarchy.\n\n"
1231
1232                         "set port tm mark ip_ecn (port) (green) (yellow)"
1233                         " (red)\n"
1234                         "    Enables/Disables the traffic management marking"
1235                         " for IP ECN (Explicit Congestion Notification)"
1236                         " packets on a given port\n\n"
1237
1238                         "set port tm mark ip_dscp (port) (green) (yellow)"
1239                         " (red)\n"
1240                         "    Enables/Disables the traffic management marking"
1241                         " on the port for IP dscp packets\n\n"
1242
1243                         "set port tm mark vlan_dei (port) (green) (yellow)"
1244                         " (red)\n"
1245                         "    Enables/Disables the traffic management marking"
1246                         " on the port for VLAN packets with DEI enabled\n\n"
1247                 );
1248         }
1249
1250 }
1251
1252 cmdline_parse_token_string_t cmd_help_long_help =
1253         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1254
1255 cmdline_parse_token_string_t cmd_help_long_section =
1256         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1257                         "all#control#display#config#"
1258                         "ports#registers#filters#traffic_management");
1259
1260 cmdline_parse_inst_t cmd_help_long = {
1261         .f = cmd_help_long_parsed,
1262         .data = NULL,
1263         .help_str = "help all|control|display|config|ports|register|"
1264                 "filters|traffic_management: "
1265                 "Show help",
1266         .tokens = {
1267                 (void *)&cmd_help_long_help,
1268                 (void *)&cmd_help_long_section,
1269                 NULL,
1270         },
1271 };
1272
1273
1274 /* *** start/stop/close all ports *** */
1275 struct cmd_operate_port_result {
1276         cmdline_fixed_string_t keyword;
1277         cmdline_fixed_string_t name;
1278         cmdline_fixed_string_t value;
1279 };
1280
1281 static void cmd_operate_port_parsed(void *parsed_result,
1282                                 __attribute__((unused)) struct cmdline *cl,
1283                                 __attribute__((unused)) void *data)
1284 {
1285         struct cmd_operate_port_result *res = parsed_result;
1286
1287         if (!strcmp(res->name, "start"))
1288                 start_port(RTE_PORT_ALL);
1289         else if (!strcmp(res->name, "stop"))
1290                 stop_port(RTE_PORT_ALL);
1291         else if (!strcmp(res->name, "close"))
1292                 close_port(RTE_PORT_ALL);
1293         else if (!strcmp(res->name, "reset"))
1294                 reset_port(RTE_PORT_ALL);
1295         else
1296                 printf("Unknown parameter\n");
1297 }
1298
1299 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1300         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1301                                                                 "port");
1302 cmdline_parse_token_string_t cmd_operate_port_all_port =
1303         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1304                                                 "start#stop#close#reset");
1305 cmdline_parse_token_string_t cmd_operate_port_all_all =
1306         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1307
1308 cmdline_parse_inst_t cmd_operate_port = {
1309         .f = cmd_operate_port_parsed,
1310         .data = NULL,
1311         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1312         .tokens = {
1313                 (void *)&cmd_operate_port_all_cmd,
1314                 (void *)&cmd_operate_port_all_port,
1315                 (void *)&cmd_operate_port_all_all,
1316                 NULL,
1317         },
1318 };
1319
1320 /* *** start/stop/close specific port *** */
1321 struct cmd_operate_specific_port_result {
1322         cmdline_fixed_string_t keyword;
1323         cmdline_fixed_string_t name;
1324         uint8_t value;
1325 };
1326
1327 static void cmd_operate_specific_port_parsed(void *parsed_result,
1328                         __attribute__((unused)) struct cmdline *cl,
1329                                 __attribute__((unused)) void *data)
1330 {
1331         struct cmd_operate_specific_port_result *res = parsed_result;
1332
1333         if (!strcmp(res->name, "start"))
1334                 start_port(res->value);
1335         else if (!strcmp(res->name, "stop"))
1336                 stop_port(res->value);
1337         else if (!strcmp(res->name, "close"))
1338                 close_port(res->value);
1339         else if (!strcmp(res->name, "reset"))
1340                 reset_port(res->value);
1341         else
1342                 printf("Unknown parameter\n");
1343 }
1344
1345 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1346         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1347                                                         keyword, "port");
1348 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1349         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1350                                                 name, "start#stop#close#reset");
1351 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1352         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1353                                                         value, UINT8);
1354
1355 cmdline_parse_inst_t cmd_operate_specific_port = {
1356         .f = cmd_operate_specific_port_parsed,
1357         .data = NULL,
1358         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1359         .tokens = {
1360                 (void *)&cmd_operate_specific_port_cmd,
1361                 (void *)&cmd_operate_specific_port_port,
1362                 (void *)&cmd_operate_specific_port_id,
1363                 NULL,
1364         },
1365 };
1366
1367 /* *** enable port setup (after attach) via iterator or event *** */
1368 struct cmd_set_port_setup_on_result {
1369         cmdline_fixed_string_t set;
1370         cmdline_fixed_string_t port;
1371         cmdline_fixed_string_t setup;
1372         cmdline_fixed_string_t on;
1373         cmdline_fixed_string_t mode;
1374 };
1375
1376 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1377                                 __attribute__((unused)) struct cmdline *cl,
1378                                 __attribute__((unused)) void *data)
1379 {
1380         struct cmd_set_port_setup_on_result *res = parsed_result;
1381
1382         if (strcmp(res->mode, "event") == 0)
1383                 setup_on_probe_event = true;
1384         else if (strcmp(res->mode, "iterator") == 0)
1385                 setup_on_probe_event = false;
1386         else
1387                 printf("Unknown mode\n");
1388 }
1389
1390 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1391         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1392                         set, "set");
1393 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1394         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1395                         port, "port");
1396 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1397         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1398                         setup, "setup");
1399 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1400         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1401                         on, "on");
1402 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1403         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1404                         mode, "iterator#event");
1405
1406 cmdline_parse_inst_t cmd_set_port_setup_on = {
1407         .f = cmd_set_port_setup_on_parsed,
1408         .data = NULL,
1409         .help_str = "set port setup on iterator|event",
1410         .tokens = {
1411                 (void *)&cmd_set_port_setup_on_set,
1412                 (void *)&cmd_set_port_setup_on_port,
1413                 (void *)&cmd_set_port_setup_on_setup,
1414                 (void *)&cmd_set_port_setup_on_on,
1415                 (void *)&cmd_set_port_setup_on_mode,
1416                 NULL,
1417         },
1418 };
1419
1420 /* *** attach a specified port *** */
1421 struct cmd_operate_attach_port_result {
1422         cmdline_fixed_string_t port;
1423         cmdline_fixed_string_t keyword;
1424         cmdline_fixed_string_t identifier;
1425 };
1426
1427 static void cmd_operate_attach_port_parsed(void *parsed_result,
1428                                 __attribute__((unused)) struct cmdline *cl,
1429                                 __attribute__((unused)) void *data)
1430 {
1431         struct cmd_operate_attach_port_result *res = parsed_result;
1432
1433         if (!strcmp(res->keyword, "attach"))
1434                 attach_port(res->identifier);
1435         else
1436                 printf("Unknown parameter\n");
1437 }
1438
1439 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1440         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1441                         port, "port");
1442 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1443         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1444                         keyword, "attach");
1445 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1446         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1447                         identifier, NULL);
1448
1449 cmdline_parse_inst_t cmd_operate_attach_port = {
1450         .f = cmd_operate_attach_port_parsed,
1451         .data = NULL,
1452         .help_str = "port attach <identifier>: "
1453                 "(identifier: pci address or virtual dev name)",
1454         .tokens = {
1455                 (void *)&cmd_operate_attach_port_port,
1456                 (void *)&cmd_operate_attach_port_keyword,
1457                 (void *)&cmd_operate_attach_port_identifier,
1458                 NULL,
1459         },
1460 };
1461
1462 /* *** detach a specified port *** */
1463 struct cmd_operate_detach_port_result {
1464         cmdline_fixed_string_t port;
1465         cmdline_fixed_string_t keyword;
1466         portid_t port_id;
1467 };
1468
1469 static void cmd_operate_detach_port_parsed(void *parsed_result,
1470                                 __attribute__((unused)) struct cmdline *cl,
1471                                 __attribute__((unused)) void *data)
1472 {
1473         struct cmd_operate_detach_port_result *res = parsed_result;
1474
1475         if (!strcmp(res->keyword, "detach"))
1476                 detach_port_device(res->port_id);
1477         else
1478                 printf("Unknown parameter\n");
1479 }
1480
1481 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1482         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1483                         port, "port");
1484 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1485         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1486                         keyword, "detach");
1487 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1488         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1489                         port_id, UINT16);
1490
1491 cmdline_parse_inst_t cmd_operate_detach_port = {
1492         .f = cmd_operate_detach_port_parsed,
1493         .data = NULL,
1494         .help_str = "port detach <port_id>",
1495         .tokens = {
1496                 (void *)&cmd_operate_detach_port_port,
1497                 (void *)&cmd_operate_detach_port_keyword,
1498                 (void *)&cmd_operate_detach_port_port_id,
1499                 NULL,
1500         },
1501 };
1502
1503 /* *** configure speed for all ports *** */
1504 struct cmd_config_speed_all {
1505         cmdline_fixed_string_t port;
1506         cmdline_fixed_string_t keyword;
1507         cmdline_fixed_string_t all;
1508         cmdline_fixed_string_t item1;
1509         cmdline_fixed_string_t item2;
1510         cmdline_fixed_string_t value1;
1511         cmdline_fixed_string_t value2;
1512 };
1513
1514 static int
1515 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1516 {
1517
1518         int duplex;
1519
1520         if (!strcmp(duplexstr, "half")) {
1521                 duplex = ETH_LINK_HALF_DUPLEX;
1522         } else if (!strcmp(duplexstr, "full")) {
1523                 duplex = ETH_LINK_FULL_DUPLEX;
1524         } else if (!strcmp(duplexstr, "auto")) {
1525                 duplex = ETH_LINK_FULL_DUPLEX;
1526         } else {
1527                 printf("Unknown duplex parameter\n");
1528                 return -1;
1529         }
1530
1531         if (!strcmp(speedstr, "10")) {
1532                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1533                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1534         } else if (!strcmp(speedstr, "100")) {
1535                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1536                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1537         } else {
1538                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1539                         printf("Invalid speed/duplex parameters\n");
1540                         return -1;
1541                 }
1542                 if (!strcmp(speedstr, "1000")) {
1543                         *speed = ETH_LINK_SPEED_1G;
1544                 } else if (!strcmp(speedstr, "10000")) {
1545                         *speed = ETH_LINK_SPEED_10G;
1546                 } else if (!strcmp(speedstr, "25000")) {
1547                         *speed = ETH_LINK_SPEED_25G;
1548                 } else if (!strcmp(speedstr, "40000")) {
1549                         *speed = ETH_LINK_SPEED_40G;
1550                 } else if (!strcmp(speedstr, "50000")) {
1551                         *speed = ETH_LINK_SPEED_50G;
1552                 } else if (!strcmp(speedstr, "100000")) {
1553                         *speed = ETH_LINK_SPEED_100G;
1554                 } else if (!strcmp(speedstr, "auto")) {
1555                         *speed = ETH_LINK_SPEED_AUTONEG;
1556                 } else {
1557                         printf("Unknown speed parameter\n");
1558                         return -1;
1559                 }
1560         }
1561
1562         return 0;
1563 }
1564
1565 static void
1566 cmd_config_speed_all_parsed(void *parsed_result,
1567                         __attribute__((unused)) struct cmdline *cl,
1568                         __attribute__((unused)) void *data)
1569 {
1570         struct cmd_config_speed_all *res = parsed_result;
1571         uint32_t link_speed;
1572         portid_t pid;
1573
1574         if (!all_ports_stopped()) {
1575                 printf("Please stop all ports first\n");
1576                 return;
1577         }
1578
1579         if (parse_and_check_speed_duplex(res->value1, res->value2,
1580                         &link_speed) < 0)
1581                 return;
1582
1583         RTE_ETH_FOREACH_DEV(pid) {
1584                 ports[pid].dev_conf.link_speeds = link_speed;
1585         }
1586
1587         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1588 }
1589
1590 cmdline_parse_token_string_t cmd_config_speed_all_port =
1591         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1592 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1593         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1594                                                         "config");
1595 cmdline_parse_token_string_t cmd_config_speed_all_all =
1596         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1597 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1598         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1599 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1600         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1601                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1602 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1603         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1604 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1605         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1606                                                 "half#full#auto");
1607
1608 cmdline_parse_inst_t cmd_config_speed_all = {
1609         .f = cmd_config_speed_all_parsed,
1610         .data = NULL,
1611         .help_str = "port config all speed "
1612                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1613                                                         "half|full|auto",
1614         .tokens = {
1615                 (void *)&cmd_config_speed_all_port,
1616                 (void *)&cmd_config_speed_all_keyword,
1617                 (void *)&cmd_config_speed_all_all,
1618                 (void *)&cmd_config_speed_all_item1,
1619                 (void *)&cmd_config_speed_all_value1,
1620                 (void *)&cmd_config_speed_all_item2,
1621                 (void *)&cmd_config_speed_all_value2,
1622                 NULL,
1623         },
1624 };
1625
1626 /* *** configure speed for specific port *** */
1627 struct cmd_config_speed_specific {
1628         cmdline_fixed_string_t port;
1629         cmdline_fixed_string_t keyword;
1630         portid_t id;
1631         cmdline_fixed_string_t item1;
1632         cmdline_fixed_string_t item2;
1633         cmdline_fixed_string_t value1;
1634         cmdline_fixed_string_t value2;
1635 };
1636
1637 static void
1638 cmd_config_speed_specific_parsed(void *parsed_result,
1639                                 __attribute__((unused)) struct cmdline *cl,
1640                                 __attribute__((unused)) void *data)
1641 {
1642         struct cmd_config_speed_specific *res = parsed_result;
1643         uint32_t link_speed;
1644
1645         if (!all_ports_stopped()) {
1646                 printf("Please stop all ports first\n");
1647                 return;
1648         }
1649
1650         if (port_id_is_invalid(res->id, ENABLED_WARN))
1651                 return;
1652
1653         if (parse_and_check_speed_duplex(res->value1, res->value2,
1654                         &link_speed) < 0)
1655                 return;
1656
1657         ports[res->id].dev_conf.link_speeds = link_speed;
1658
1659         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1660 }
1661
1662
1663 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1664         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1665                                                                 "port");
1666 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1667         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1668                                                                 "config");
1669 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1670         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1671 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1672         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1673                                                                 "speed");
1674 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1675         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1676                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1677 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1679                                                                 "duplex");
1680 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1681         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1682                                                         "half#full#auto");
1683
1684 cmdline_parse_inst_t cmd_config_speed_specific = {
1685         .f = cmd_config_speed_specific_parsed,
1686         .data = NULL,
1687         .help_str = "port config <port_id> speed "
1688                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1689                                                         "half|full|auto",
1690         .tokens = {
1691                 (void *)&cmd_config_speed_specific_port,
1692                 (void *)&cmd_config_speed_specific_keyword,
1693                 (void *)&cmd_config_speed_specific_id,
1694                 (void *)&cmd_config_speed_specific_item1,
1695                 (void *)&cmd_config_speed_specific_value1,
1696                 (void *)&cmd_config_speed_specific_item2,
1697                 (void *)&cmd_config_speed_specific_value2,
1698                 NULL,
1699         },
1700 };
1701
1702 /* *** configure loopback for all ports *** */
1703 struct cmd_config_loopback_all {
1704         cmdline_fixed_string_t port;
1705         cmdline_fixed_string_t keyword;
1706         cmdline_fixed_string_t all;
1707         cmdline_fixed_string_t item;
1708         uint32_t mode;
1709 };
1710
1711 static void
1712 cmd_config_loopback_all_parsed(void *parsed_result,
1713                         __attribute__((unused)) struct cmdline *cl,
1714                         __attribute__((unused)) void *data)
1715 {
1716         struct cmd_config_loopback_all *res = parsed_result;
1717         portid_t pid;
1718
1719         if (!all_ports_stopped()) {
1720                 printf("Please stop all ports first\n");
1721                 return;
1722         }
1723
1724         RTE_ETH_FOREACH_DEV(pid) {
1725                 ports[pid].dev_conf.lpbk_mode = res->mode;
1726         }
1727
1728         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1729 }
1730
1731 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1733 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1734         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1735                                                         "config");
1736 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1737         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1738 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1739         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1740                                                         "loopback");
1741 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1742         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1743
1744 cmdline_parse_inst_t cmd_config_loopback_all = {
1745         .f = cmd_config_loopback_all_parsed,
1746         .data = NULL,
1747         .help_str = "port config all loopback <mode>",
1748         .tokens = {
1749                 (void *)&cmd_config_loopback_all_port,
1750                 (void *)&cmd_config_loopback_all_keyword,
1751                 (void *)&cmd_config_loopback_all_all,
1752                 (void *)&cmd_config_loopback_all_item,
1753                 (void *)&cmd_config_loopback_all_mode,
1754                 NULL,
1755         },
1756 };
1757
1758 /* *** configure loopback for specific port *** */
1759 struct cmd_config_loopback_specific {
1760         cmdline_fixed_string_t port;
1761         cmdline_fixed_string_t keyword;
1762         uint16_t port_id;
1763         cmdline_fixed_string_t item;
1764         uint32_t mode;
1765 };
1766
1767 static void
1768 cmd_config_loopback_specific_parsed(void *parsed_result,
1769                                 __attribute__((unused)) struct cmdline *cl,
1770                                 __attribute__((unused)) void *data)
1771 {
1772         struct cmd_config_loopback_specific *res = parsed_result;
1773
1774         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1775                 return;
1776
1777         if (!port_is_stopped(res->port_id)) {
1778                 printf("Please stop port %u first\n", res->port_id);
1779                 return;
1780         }
1781
1782         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1783
1784         cmd_reconfig_device_queue(res->port_id, 1, 1);
1785 }
1786
1787
1788 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1789         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1790                                                                 "port");
1791 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1792         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1793                                                                 "config");
1794 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1795         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1796                                                                 UINT16);
1797 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1798         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1799                                                                 "loopback");
1800 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1801         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1802                               UINT32);
1803
1804 cmdline_parse_inst_t cmd_config_loopback_specific = {
1805         .f = cmd_config_loopback_specific_parsed,
1806         .data = NULL,
1807         .help_str = "port config <port_id> loopback <mode>",
1808         .tokens = {
1809                 (void *)&cmd_config_loopback_specific_port,
1810                 (void *)&cmd_config_loopback_specific_keyword,
1811                 (void *)&cmd_config_loopback_specific_id,
1812                 (void *)&cmd_config_loopback_specific_item,
1813                 (void *)&cmd_config_loopback_specific_mode,
1814                 NULL,
1815         },
1816 };
1817
1818 /* *** configure txq/rxq, txd/rxd *** */
1819 struct cmd_config_rx_tx {
1820         cmdline_fixed_string_t port;
1821         cmdline_fixed_string_t keyword;
1822         cmdline_fixed_string_t all;
1823         cmdline_fixed_string_t name;
1824         uint16_t value;
1825 };
1826
1827 static void
1828 cmd_config_rx_tx_parsed(void *parsed_result,
1829                         __attribute__((unused)) struct cmdline *cl,
1830                         __attribute__((unused)) void *data)
1831 {
1832         struct cmd_config_rx_tx *res = parsed_result;
1833
1834         if (!all_ports_stopped()) {
1835                 printf("Please stop all ports first\n");
1836                 return;
1837         }
1838         if (!strcmp(res->name, "rxq")) {
1839                 if (!res->value && !nb_txq) {
1840                         printf("Warning: Either rx or tx queues should be non zero\n");
1841                         return;
1842                 }
1843                 if (check_nb_rxq(res->value) != 0)
1844                         return;
1845                 nb_rxq = res->value;
1846         }
1847         else if (!strcmp(res->name, "txq")) {
1848                 if (!res->value && !nb_rxq) {
1849                         printf("Warning: Either rx or tx queues should be non zero\n");
1850                         return;
1851                 }
1852                 if (check_nb_txq(res->value) != 0)
1853                         return;
1854                 nb_txq = res->value;
1855         }
1856         else if (!strcmp(res->name, "rxd")) {
1857                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1858                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1859                                         res->value, RTE_TEST_RX_DESC_MAX);
1860                         return;
1861                 }
1862                 nb_rxd = res->value;
1863         } else if (!strcmp(res->name, "txd")) {
1864                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1865                         printf("txd %d invalid - must be > 0 && <= %d\n",
1866                                         res->value, RTE_TEST_TX_DESC_MAX);
1867                         return;
1868                 }
1869                 nb_txd = res->value;
1870         } else {
1871                 printf("Unknown parameter\n");
1872                 return;
1873         }
1874
1875         fwd_config_setup();
1876
1877         init_port_config();
1878
1879         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1880 }
1881
1882 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1883         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1884 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1885         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1886 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1887         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1888 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1889         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1890                                                 "rxq#txq#rxd#txd");
1891 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1892         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1893
1894 cmdline_parse_inst_t cmd_config_rx_tx = {
1895         .f = cmd_config_rx_tx_parsed,
1896         .data = NULL,
1897         .help_str = "port config all rxq|txq|rxd|txd <value>",
1898         .tokens = {
1899                 (void *)&cmd_config_rx_tx_port,
1900                 (void *)&cmd_config_rx_tx_keyword,
1901                 (void *)&cmd_config_rx_tx_all,
1902                 (void *)&cmd_config_rx_tx_name,
1903                 (void *)&cmd_config_rx_tx_value,
1904                 NULL,
1905         },
1906 };
1907
1908 /* *** config max packet length *** */
1909 struct cmd_config_max_pkt_len_result {
1910         cmdline_fixed_string_t port;
1911         cmdline_fixed_string_t keyword;
1912         cmdline_fixed_string_t all;
1913         cmdline_fixed_string_t name;
1914         uint32_t value;
1915 };
1916
1917 static void
1918 cmd_config_max_pkt_len_parsed(void *parsed_result,
1919                                 __attribute__((unused)) struct cmdline *cl,
1920                                 __attribute__((unused)) void *data)
1921 {
1922         struct cmd_config_max_pkt_len_result *res = parsed_result;
1923         portid_t pid;
1924
1925         if (!all_ports_stopped()) {
1926                 printf("Please stop all ports first\n");
1927                 return;
1928         }
1929
1930         RTE_ETH_FOREACH_DEV(pid) {
1931                 struct rte_port *port = &ports[pid];
1932                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1933
1934                 if (!strcmp(res->name, "max-pkt-len")) {
1935                         if (res->value < RTE_ETHER_MIN_LEN) {
1936                                 printf("max-pkt-len can not be less than %d\n",
1937                                                 RTE_ETHER_MIN_LEN);
1938                                 return;
1939                         }
1940                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1941                                 return;
1942
1943                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1944                         if (res->value > RTE_ETHER_MAX_LEN)
1945                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1946                         else
1947                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1948                         port->dev_conf.rxmode.offloads = rx_offloads;
1949                 } else {
1950                         printf("Unknown parameter\n");
1951                         return;
1952                 }
1953         }
1954
1955         init_port_config();
1956
1957         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1958 }
1959
1960 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1962                                                                 "port");
1963 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1964         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1965                                                                 "config");
1966 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1967         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1968                                                                 "all");
1969 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1970         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1971                                                                 "max-pkt-len");
1972 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1973         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1974                                                                 UINT32);
1975
1976 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1977         .f = cmd_config_max_pkt_len_parsed,
1978         .data = NULL,
1979         .help_str = "port config all max-pkt-len <value>",
1980         .tokens = {
1981                 (void *)&cmd_config_max_pkt_len_port,
1982                 (void *)&cmd_config_max_pkt_len_keyword,
1983                 (void *)&cmd_config_max_pkt_len_all,
1984                 (void *)&cmd_config_max_pkt_len_name,
1985                 (void *)&cmd_config_max_pkt_len_value,
1986                 NULL,
1987         },
1988 };
1989
1990 /* *** configure port MTU *** */
1991 struct cmd_config_mtu_result {
1992         cmdline_fixed_string_t port;
1993         cmdline_fixed_string_t keyword;
1994         cmdline_fixed_string_t mtu;
1995         portid_t port_id;
1996         uint16_t value;
1997 };
1998
1999 static void
2000 cmd_config_mtu_parsed(void *parsed_result,
2001                       __attribute__((unused)) struct cmdline *cl,
2002                       __attribute__((unused)) void *data)
2003 {
2004         struct cmd_config_mtu_result *res = parsed_result;
2005
2006         if (res->value < RTE_ETHER_MIN_LEN) {
2007                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2008                 return;
2009         }
2010         port_mtu_set(res->port_id, res->value);
2011 }
2012
2013 cmdline_parse_token_string_t cmd_config_mtu_port =
2014         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2015                                  "port");
2016 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2017         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2018                                  "config");
2019 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2020         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2021                                  "mtu");
2022 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2023         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2024 cmdline_parse_token_num_t cmd_config_mtu_value =
2025         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2026
2027 cmdline_parse_inst_t cmd_config_mtu = {
2028         .f = cmd_config_mtu_parsed,
2029         .data = NULL,
2030         .help_str = "port config mtu <port_id> <value>",
2031         .tokens = {
2032                 (void *)&cmd_config_mtu_port,
2033                 (void *)&cmd_config_mtu_keyword,
2034                 (void *)&cmd_config_mtu_mtu,
2035                 (void *)&cmd_config_mtu_port_id,
2036                 (void *)&cmd_config_mtu_value,
2037                 NULL,
2038         },
2039 };
2040
2041 /* *** configure rx mode *** */
2042 struct cmd_config_rx_mode_flag {
2043         cmdline_fixed_string_t port;
2044         cmdline_fixed_string_t keyword;
2045         cmdline_fixed_string_t all;
2046         cmdline_fixed_string_t name;
2047         cmdline_fixed_string_t value;
2048 };
2049
2050 static void
2051 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2052                                 __attribute__((unused)) struct cmdline *cl,
2053                                 __attribute__((unused)) void *data)
2054 {
2055         struct cmd_config_rx_mode_flag *res = parsed_result;
2056         portid_t pid;
2057         int k;
2058
2059         if (!all_ports_stopped()) {
2060                 printf("Please stop all ports first\n");
2061                 return;
2062         }
2063
2064         RTE_ETH_FOREACH_DEV(pid) {
2065                 struct rte_port *port;
2066                 uint64_t rx_offloads;
2067
2068                 port = &ports[pid];
2069                 rx_offloads = port->dev_conf.rxmode.offloads;
2070                 if (!strcmp(res->name, "crc-strip")) {
2071                         if (!strcmp(res->value, "on")) {
2072                                 rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
2073                         } else if (!strcmp(res->value, "off")) {
2074                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
2075                         } else {
2076                                 printf("Unknown parameter\n");
2077                                 return;
2078                         }
2079                 } else if (!strcmp(res->name, "scatter")) {
2080                         if (!strcmp(res->value, "on")) {
2081                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
2082                         } else if (!strcmp(res->value, "off")) {
2083                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
2084                         } else {
2085                                 printf("Unknown parameter\n");
2086                                 return;
2087                         }
2088                 } else if (!strcmp(res->name, "rx-cksum")) {
2089                         if (!strcmp(res->value, "on"))
2090                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
2091                         else if (!strcmp(res->value, "off"))
2092                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
2093                         else {
2094                                 printf("Unknown parameter\n");
2095                                 return;
2096                         }
2097                 } else if (!strcmp(res->name, "rx-timestamp")) {
2098                         if (!strcmp(res->value, "on"))
2099                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
2100                         else if (!strcmp(res->value, "off"))
2101                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
2102                         else {
2103                                 printf("Unknown parameter\n");
2104                                 return;
2105                         }
2106                 } else if (!strcmp(res->name, "hw-vlan")) {
2107                         if (!strcmp(res->value, "on")) {
2108                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
2109                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2110                         } else if (!strcmp(res->value, "off")) {
2111                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
2112                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2113                         } else {
2114                                 printf("Unknown parameter\n");
2115                                 return;
2116                         }
2117                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
2118                         if (!strcmp(res->value, "on"))
2119                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2120                         else if (!strcmp(res->value, "off"))
2121                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2122                         else {
2123                                 printf("Unknown parameter\n");
2124                                 return;
2125                         }
2126                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
2127                         if (!strcmp(res->value, "on"))
2128                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2129                         else if (!strcmp(res->value, "off"))
2130                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2131                         else {
2132                                 printf("Unknown parameter\n");
2133                                 return;
2134                         }
2135                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
2136                         if (!strcmp(res->value, "on"))
2137                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2138                         else if (!strcmp(res->value, "off"))
2139                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2140                         else {
2141                                 printf("Unknown parameter\n");
2142                                 return;
2143                         }
2144                 } else if (!strcmp(res->name, "drop-en")) {
2145                         if (!strcmp(res->value, "on"))
2146                                 rx_drop_en = 1;
2147                         else if (!strcmp(res->value, "off"))
2148                                 rx_drop_en = 0;
2149                         else {
2150                                 printf("Unknown parameter\n");
2151                                 return;
2152                         }
2153                 } else {
2154                         printf("Unknown parameter\n");
2155                         return;
2156                 }
2157                 port->dev_conf.rxmode.offloads = rx_offloads;
2158                 /* Apply Rx offloads configuration */
2159                 for (k = 0; k < port->dev_info.max_rx_queues; k++)
2160                         port->rx_conf[k].offloads =
2161                                 port->dev_conf.rxmode.offloads;
2162         }
2163
2164         init_port_config();
2165
2166         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2167 }
2168
2169 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2170         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2171 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2172         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2173                                                                 "config");
2174 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2175         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2176 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2177         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2178                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2179                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2180 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2181         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2182                                                         "on#off");
2183
2184 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2185         .f = cmd_config_rx_mode_flag_parsed,
2186         .data = NULL,
2187         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2188                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2189         .tokens = {
2190                 (void *)&cmd_config_rx_mode_flag_port,
2191                 (void *)&cmd_config_rx_mode_flag_keyword,
2192                 (void *)&cmd_config_rx_mode_flag_all,
2193                 (void *)&cmd_config_rx_mode_flag_name,
2194                 (void *)&cmd_config_rx_mode_flag_value,
2195                 NULL,
2196         },
2197 };
2198
2199 /* *** configure rss *** */
2200 struct cmd_config_rss {
2201         cmdline_fixed_string_t port;
2202         cmdline_fixed_string_t keyword;
2203         cmdline_fixed_string_t all;
2204         cmdline_fixed_string_t name;
2205         cmdline_fixed_string_t value;
2206 };
2207
2208 static void
2209 cmd_config_rss_parsed(void *parsed_result,
2210                         __attribute__((unused)) struct cmdline *cl,
2211                         __attribute__((unused)) void *data)
2212 {
2213         struct cmd_config_rss *res = parsed_result;
2214         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2215         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2216         int use_default = 0;
2217         int all_updated = 1;
2218         int diag;
2219         uint16_t i;
2220
2221         if (!strcmp(res->value, "all"))
2222                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2223                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2224                                         ETH_RSS_L2_PAYLOAD;
2225         else if (!strcmp(res->value, "ip"))
2226                 rss_conf.rss_hf = ETH_RSS_IP;
2227         else if (!strcmp(res->value, "udp"))
2228                 rss_conf.rss_hf = ETH_RSS_UDP;
2229         else if (!strcmp(res->value, "tcp"))
2230                 rss_conf.rss_hf = ETH_RSS_TCP;
2231         else if (!strcmp(res->value, "sctp"))
2232                 rss_conf.rss_hf = ETH_RSS_SCTP;
2233         else if (!strcmp(res->value, "ether"))
2234                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2235         else if (!strcmp(res->value, "port"))
2236                 rss_conf.rss_hf = ETH_RSS_PORT;
2237         else if (!strcmp(res->value, "vxlan"))
2238                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2239         else if (!strcmp(res->value, "geneve"))
2240                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2241         else if (!strcmp(res->value, "nvgre"))
2242                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2243         else if (!strcmp(res->value, "none"))
2244                 rss_conf.rss_hf = 0;
2245         else if (!strcmp(res->value, "default"))
2246                 use_default = 1;
2247         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2248                                                 atoi(res->value) < 64)
2249                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2250         else {
2251                 printf("Unknown parameter\n");
2252                 return;
2253         }
2254         rss_conf.rss_key = NULL;
2255         /* Update global configuration for RSS types. */
2256         RTE_ETH_FOREACH_DEV(i) {
2257                 struct rte_eth_rss_conf local_rss_conf;
2258
2259                 rte_eth_dev_info_get(i, &dev_info);
2260                 if (use_default)
2261                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2262
2263                 local_rss_conf = rss_conf;
2264                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2265                         dev_info.flow_type_rss_offloads;
2266                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2267                         printf("Port %u modified RSS hash function based on hardware support,"
2268                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2269                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2270                 }
2271                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2272                 if (diag < 0) {
2273                         all_updated = 0;
2274                         printf("Configuration of RSS hash at ethernet port %d "
2275                                 "failed with error (%d): %s.\n",
2276                                 i, -diag, strerror(-diag));
2277                 }
2278         }
2279         if (all_updated && !use_default)
2280                 rss_hf = rss_conf.rss_hf;
2281 }
2282
2283 cmdline_parse_token_string_t cmd_config_rss_port =
2284         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2285 cmdline_parse_token_string_t cmd_config_rss_keyword =
2286         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2287 cmdline_parse_token_string_t cmd_config_rss_all =
2288         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2289 cmdline_parse_token_string_t cmd_config_rss_name =
2290         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2291 cmdline_parse_token_string_t cmd_config_rss_value =
2292         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2293
2294 cmdline_parse_inst_t cmd_config_rss = {
2295         .f = cmd_config_rss_parsed,
2296         .data = NULL,
2297         .help_str = "port config all rss "
2298                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2299         .tokens = {
2300                 (void *)&cmd_config_rss_port,
2301                 (void *)&cmd_config_rss_keyword,
2302                 (void *)&cmd_config_rss_all,
2303                 (void *)&cmd_config_rss_name,
2304                 (void *)&cmd_config_rss_value,
2305                 NULL,
2306         },
2307 };
2308
2309 /* *** configure rss hash key *** */
2310 struct cmd_config_rss_hash_key {
2311         cmdline_fixed_string_t port;
2312         cmdline_fixed_string_t config;
2313         portid_t port_id;
2314         cmdline_fixed_string_t rss_hash_key;
2315         cmdline_fixed_string_t rss_type;
2316         cmdline_fixed_string_t key;
2317 };
2318
2319 static uint8_t
2320 hexa_digit_to_value(char hexa_digit)
2321 {
2322         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2323                 return (uint8_t) (hexa_digit - '0');
2324         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2325                 return (uint8_t) ((hexa_digit - 'a') + 10);
2326         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2327                 return (uint8_t) ((hexa_digit - 'A') + 10);
2328         /* Invalid hexa digit */
2329         return 0xFF;
2330 }
2331
2332 static uint8_t
2333 parse_and_check_key_hexa_digit(char *key, int idx)
2334 {
2335         uint8_t hexa_v;
2336
2337         hexa_v = hexa_digit_to_value(key[idx]);
2338         if (hexa_v == 0xFF)
2339                 printf("invalid key: character %c at position %d is not a "
2340                        "valid hexa digit\n", key[idx], idx);
2341         return hexa_v;
2342 }
2343
2344 static void
2345 cmd_config_rss_hash_key_parsed(void *parsed_result,
2346                                __attribute__((unused)) struct cmdline *cl,
2347                                __attribute__((unused)) void *data)
2348 {
2349         struct cmd_config_rss_hash_key *res = parsed_result;
2350         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2351         uint8_t xdgt0;
2352         uint8_t xdgt1;
2353         int i;
2354         struct rte_eth_dev_info dev_info;
2355         uint8_t hash_key_size;
2356         uint32_t key_len;
2357
2358         memset(&dev_info, 0, sizeof(dev_info));
2359         rte_eth_dev_info_get(res->port_id, &dev_info);
2360         if (dev_info.hash_key_size > 0 &&
2361                         dev_info.hash_key_size <= sizeof(hash_key))
2362                 hash_key_size = dev_info.hash_key_size;
2363         else {
2364                 printf("dev_info did not provide a valid hash key size\n");
2365                 return;
2366         }
2367         /* Check the length of the RSS hash key */
2368         key_len = strlen(res->key);
2369         if (key_len != (hash_key_size * 2)) {
2370                 printf("key length: %d invalid - key must be a string of %d"
2371                            " hexa-decimal numbers\n",
2372                            (int) key_len, hash_key_size * 2);
2373                 return;
2374         }
2375         /* Translate RSS hash key into binary representation */
2376         for (i = 0; i < hash_key_size; i++) {
2377                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2378                 if (xdgt0 == 0xFF)
2379                         return;
2380                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2381                 if (xdgt1 == 0xFF)
2382                         return;
2383                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2384         }
2385         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2386                         hash_key_size);
2387 }
2388
2389 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2390         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2391 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2392         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2393                                  "config");
2394 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2395         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2396 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2397         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2398                                  rss_hash_key, "rss-hash-key");
2399 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2400         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2401                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2402                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2403                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2404                                  "ipv6-tcp-ex#ipv6-udp-ex");
2405 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2406         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2407
2408 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2409         .f = cmd_config_rss_hash_key_parsed,
2410         .data = NULL,
2411         .help_str = "port config <port_id> rss-hash-key "
2412                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2413                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2414                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2415                 "<string of hex digits (variable length, NIC dependent)>",
2416         .tokens = {
2417                 (void *)&cmd_config_rss_hash_key_port,
2418                 (void *)&cmd_config_rss_hash_key_config,
2419                 (void *)&cmd_config_rss_hash_key_port_id,
2420                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2421                 (void *)&cmd_config_rss_hash_key_rss_type,
2422                 (void *)&cmd_config_rss_hash_key_value,
2423                 NULL,
2424         },
2425 };
2426
2427 /* *** configure port rxq/txq ring size *** */
2428 struct cmd_config_rxtx_ring_size {
2429         cmdline_fixed_string_t port;
2430         cmdline_fixed_string_t config;
2431         portid_t portid;
2432         cmdline_fixed_string_t rxtxq;
2433         uint16_t qid;
2434         cmdline_fixed_string_t rsize;
2435         uint16_t size;
2436 };
2437
2438 static void
2439 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2440                                  __attribute__((unused)) struct cmdline *cl,
2441                                  __attribute__((unused)) void *data)
2442 {
2443         struct cmd_config_rxtx_ring_size *res = parsed_result;
2444         struct rte_port *port;
2445         uint8_t isrx;
2446
2447         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2448                 return;
2449
2450         if (res->portid == (portid_t)RTE_PORT_ALL) {
2451                 printf("Invalid port id\n");
2452                 return;
2453         }
2454
2455         port = &ports[res->portid];
2456
2457         if (!strcmp(res->rxtxq, "rxq"))
2458                 isrx = 1;
2459         else if (!strcmp(res->rxtxq, "txq"))
2460                 isrx = 0;
2461         else {
2462                 printf("Unknown parameter\n");
2463                 return;
2464         }
2465
2466         if (isrx && rx_queue_id_is_invalid(res->qid))
2467                 return;
2468         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2469                 return;
2470
2471         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2472                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2473                        rx_free_thresh);
2474                 return;
2475         }
2476
2477         if (isrx)
2478                 port->nb_rx_desc[res->qid] = res->size;
2479         else
2480                 port->nb_tx_desc[res->qid] = res->size;
2481
2482         cmd_reconfig_device_queue(res->portid, 0, 1);
2483 }
2484
2485 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2486         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2487                                  port, "port");
2488 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2489         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2490                                  config, "config");
2491 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2492         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2493                                  portid, UINT16);
2494 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2495         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2496                                  rxtxq, "rxq#txq");
2497 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2498         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2499                               qid, UINT16);
2500 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2501         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2502                                  rsize, "ring_size");
2503 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2504         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2505                               size, UINT16);
2506
2507 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2508         .f = cmd_config_rxtx_ring_size_parsed,
2509         .data = NULL,
2510         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2511         .tokens = {
2512                 (void *)&cmd_config_rxtx_ring_size_port,
2513                 (void *)&cmd_config_rxtx_ring_size_config,
2514                 (void *)&cmd_config_rxtx_ring_size_portid,
2515                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2516                 (void *)&cmd_config_rxtx_ring_size_qid,
2517                 (void *)&cmd_config_rxtx_ring_size_rsize,
2518                 (void *)&cmd_config_rxtx_ring_size_size,
2519                 NULL,
2520         },
2521 };
2522
2523 /* *** configure port rxq/txq start/stop *** */
2524 struct cmd_config_rxtx_queue {
2525         cmdline_fixed_string_t port;
2526         portid_t portid;
2527         cmdline_fixed_string_t rxtxq;
2528         uint16_t qid;
2529         cmdline_fixed_string_t opname;
2530 };
2531
2532 static void
2533 cmd_config_rxtx_queue_parsed(void *parsed_result,
2534                         __attribute__((unused)) struct cmdline *cl,
2535                         __attribute__((unused)) void *data)
2536 {
2537         struct cmd_config_rxtx_queue *res = parsed_result;
2538         uint8_t isrx;
2539         uint8_t isstart;
2540         int ret = 0;
2541
2542         if (test_done == 0) {
2543                 printf("Please stop forwarding first\n");
2544                 return;
2545         }
2546
2547         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2548                 return;
2549
2550         if (port_is_started(res->portid) != 1) {
2551                 printf("Please start port %u first\n", res->portid);
2552                 return;
2553         }
2554
2555         if (!strcmp(res->rxtxq, "rxq"))
2556                 isrx = 1;
2557         else if (!strcmp(res->rxtxq, "txq"))
2558                 isrx = 0;
2559         else {
2560                 printf("Unknown parameter\n");
2561                 return;
2562         }
2563
2564         if (isrx && rx_queue_id_is_invalid(res->qid))
2565                 return;
2566         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2567                 return;
2568
2569         if (!strcmp(res->opname, "start"))
2570                 isstart = 1;
2571         else if (!strcmp(res->opname, "stop"))
2572                 isstart = 0;
2573         else {
2574                 printf("Unknown parameter\n");
2575                 return;
2576         }
2577
2578         if (isstart && isrx)
2579                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2580         else if (!isstart && isrx)
2581                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2582         else if (isstart && !isrx)
2583                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2584         else
2585                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2586
2587         if (ret == -ENOTSUP)
2588                 printf("Function not supported in PMD driver\n");
2589 }
2590
2591 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2592         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2593 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2594         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2595 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2596         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2597 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2598         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2599 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2600         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2601                                                 "start#stop");
2602
2603 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2604         .f = cmd_config_rxtx_queue_parsed,
2605         .data = NULL,
2606         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2607         .tokens = {
2608                 (void *)&cmd_config_rxtx_queue_port,
2609                 (void *)&cmd_config_rxtx_queue_portid,
2610                 (void *)&cmd_config_rxtx_queue_rxtxq,
2611                 (void *)&cmd_config_rxtx_queue_qid,
2612                 (void *)&cmd_config_rxtx_queue_opname,
2613                 NULL,
2614         },
2615 };
2616
2617 /* *** configure port rxq/txq deferred start on/off *** */
2618 struct cmd_config_deferred_start_rxtx_queue {
2619         cmdline_fixed_string_t port;
2620         portid_t port_id;
2621         cmdline_fixed_string_t rxtxq;
2622         uint16_t qid;
2623         cmdline_fixed_string_t opname;
2624         cmdline_fixed_string_t state;
2625 };
2626
2627 static void
2628 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2629                         __attribute__((unused)) struct cmdline *cl,
2630                         __attribute__((unused)) void *data)
2631 {
2632         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2633         struct rte_port *port;
2634         uint8_t isrx;
2635         uint8_t ison;
2636         uint8_t needreconfig = 0;
2637
2638         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2639                 return;
2640
2641         if (port_is_started(res->port_id) != 0) {
2642                 printf("Please stop port %u first\n", res->port_id);
2643                 return;
2644         }
2645
2646         port = &ports[res->port_id];
2647
2648         isrx = !strcmp(res->rxtxq, "rxq");
2649
2650         if (isrx && rx_queue_id_is_invalid(res->qid))
2651                 return;
2652         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2653                 return;
2654
2655         ison = !strcmp(res->state, "on");
2656
2657         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2658                 port->rx_conf[res->qid].rx_deferred_start = ison;
2659                 needreconfig = 1;
2660         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2661                 port->tx_conf[res->qid].tx_deferred_start = ison;
2662                 needreconfig = 1;
2663         }
2664
2665         if (needreconfig)
2666                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2667 }
2668
2669 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2670         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2671                                                 port, "port");
2672 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2673         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2674                                                 port_id, UINT16);
2675 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2676         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2677                                                 rxtxq, "rxq#txq");
2678 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2679         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2680                                                 qid, UINT16);
2681 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2682         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2683                                                 opname, "deferred_start");
2684 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2685         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2686                                                 state, "on#off");
2687
2688 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2689         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2690         .data = NULL,
2691         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2692         .tokens = {
2693                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2694                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2695                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2696                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2697                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2698                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2699                 NULL,
2700         },
2701 };
2702
2703 /* *** configure port rxq/txq setup *** */
2704 struct cmd_setup_rxtx_queue {
2705         cmdline_fixed_string_t port;
2706         portid_t portid;
2707         cmdline_fixed_string_t rxtxq;
2708         uint16_t qid;
2709         cmdline_fixed_string_t setup;
2710 };
2711
2712 /* Common CLI fields for queue setup */
2713 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2714         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2715 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2716         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2717 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2718         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2719 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2720         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2721 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2722         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2723
2724 static void
2725 cmd_setup_rxtx_queue_parsed(
2726         void *parsed_result,
2727         __attribute__((unused)) struct cmdline *cl,
2728         __attribute__((unused)) void *data)
2729 {
2730         struct cmd_setup_rxtx_queue *res = parsed_result;
2731         struct rte_port *port;
2732         struct rte_mempool *mp;
2733         unsigned int socket_id;
2734         uint8_t isrx = 0;
2735         int ret;
2736
2737         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2738                 return;
2739
2740         if (res->portid == (portid_t)RTE_PORT_ALL) {
2741                 printf("Invalid port id\n");
2742                 return;
2743         }
2744
2745         if (!strcmp(res->rxtxq, "rxq"))
2746                 isrx = 1;
2747         else if (!strcmp(res->rxtxq, "txq"))
2748                 isrx = 0;
2749         else {
2750                 printf("Unknown parameter\n");
2751                 return;
2752         }
2753
2754         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2755                 printf("Invalid rx queue\n");
2756                 return;
2757         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2758                 printf("Invalid tx queue\n");
2759                 return;
2760         }
2761
2762         port = &ports[res->portid];
2763         if (isrx) {
2764                 socket_id = rxring_numa[res->portid];
2765                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2766                         socket_id = port->socket_id;
2767
2768                 mp = mbuf_pool_find(socket_id);
2769                 if (mp == NULL) {
2770                         printf("Failed to setup RX queue: "
2771                                 "No mempool allocation"
2772                                 " on the socket %d\n",
2773                                 rxring_numa[res->portid]);
2774                         return;
2775                 }
2776                 ret = rte_eth_rx_queue_setup(res->portid,
2777                                              res->qid,
2778                                              port->nb_rx_desc[res->qid],
2779                                              socket_id,
2780                                              &port->rx_conf[res->qid],
2781                                              mp);
2782                 if (ret)
2783                         printf("Failed to setup RX queue\n");
2784         } else {
2785                 socket_id = txring_numa[res->portid];
2786                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2787                         socket_id = port->socket_id;
2788
2789                 ret = rte_eth_tx_queue_setup(res->portid,
2790                                              res->qid,
2791                                              port->nb_tx_desc[res->qid],
2792                                              socket_id,
2793                                              &port->tx_conf[res->qid]);
2794                 if (ret)
2795                         printf("Failed to setup TX queue\n");
2796         }
2797 }
2798
2799 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2800         .f = cmd_setup_rxtx_queue_parsed,
2801         .data = NULL,
2802         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2803         .tokens = {
2804                 (void *)&cmd_setup_rxtx_queue_port,
2805                 (void *)&cmd_setup_rxtx_queue_portid,
2806                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2807                 (void *)&cmd_setup_rxtx_queue_qid,
2808                 (void *)&cmd_setup_rxtx_queue_setup,
2809                 NULL,
2810         },
2811 };
2812
2813
2814 /* *** Configure RSS RETA *** */
2815 struct cmd_config_rss_reta {
2816         cmdline_fixed_string_t port;
2817         cmdline_fixed_string_t keyword;
2818         portid_t port_id;
2819         cmdline_fixed_string_t name;
2820         cmdline_fixed_string_t list_name;
2821         cmdline_fixed_string_t list_of_items;
2822 };
2823
2824 static int
2825 parse_reta_config(const char *str,
2826                   struct rte_eth_rss_reta_entry64 *reta_conf,
2827                   uint16_t nb_entries)
2828 {
2829         int i;
2830         unsigned size;
2831         uint16_t hash_index, idx, shift;
2832         uint16_t nb_queue;
2833         char s[256];
2834         const char *p, *p0 = str;
2835         char *end;
2836         enum fieldnames {
2837                 FLD_HASH_INDEX = 0,
2838                 FLD_QUEUE,
2839                 _NUM_FLD
2840         };
2841         unsigned long int_fld[_NUM_FLD];
2842         char *str_fld[_NUM_FLD];
2843
2844         while ((p = strchr(p0,'(')) != NULL) {
2845                 ++p;
2846                 if((p0 = strchr(p,')')) == NULL)
2847                         return -1;
2848
2849                 size = p0 - p;
2850                 if(size >= sizeof(s))
2851                         return -1;
2852
2853                 snprintf(s, sizeof(s), "%.*s", size, p);
2854                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2855                         return -1;
2856                 for (i = 0; i < _NUM_FLD; i++) {
2857                         errno = 0;
2858                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2859                         if (errno != 0 || end == str_fld[i] ||
2860                                         int_fld[i] > 65535)
2861                                 return -1;
2862                 }
2863
2864                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2865                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2866
2867                 if (hash_index >= nb_entries) {
2868                         printf("Invalid RETA hash index=%d\n", hash_index);
2869                         return -1;
2870                 }
2871
2872                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2873                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2874                 reta_conf[idx].mask |= (1ULL << shift);
2875                 reta_conf[idx].reta[shift] = nb_queue;
2876         }
2877
2878         return 0;
2879 }
2880
2881 static void
2882 cmd_set_rss_reta_parsed(void *parsed_result,
2883                         __attribute__((unused)) struct cmdline *cl,
2884                         __attribute__((unused)) void *data)
2885 {
2886         int ret;
2887         struct rte_eth_dev_info dev_info;
2888         struct rte_eth_rss_reta_entry64 reta_conf[8];
2889         struct cmd_config_rss_reta *res = parsed_result;
2890
2891         memset(&dev_info, 0, sizeof(dev_info));
2892         rte_eth_dev_info_get(res->port_id, &dev_info);
2893         if (dev_info.reta_size == 0) {
2894                 printf("Redirection table size is 0 which is "
2895                                         "invalid for RSS\n");
2896                 return;
2897         } else
2898                 printf("The reta size of port %d is %u\n",
2899                         res->port_id, dev_info.reta_size);
2900         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2901                 printf("Currently do not support more than %u entries of "
2902                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2903                 return;
2904         }
2905
2906         memset(reta_conf, 0, sizeof(reta_conf));
2907         if (!strcmp(res->list_name, "reta")) {
2908                 if (parse_reta_config(res->list_of_items, reta_conf,
2909                                                 dev_info.reta_size)) {
2910                         printf("Invalid RSS Redirection Table "
2911                                         "config entered\n");
2912                         return;
2913                 }
2914                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2915                                 reta_conf, dev_info.reta_size);
2916                 if (ret != 0)
2917                         printf("Bad redirection table parameter, "
2918                                         "return code = %d \n", ret);
2919         }
2920 }
2921
2922 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2923         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2924 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2925         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2926 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2927         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2928 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2929         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2930 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2931         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2932 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2933         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2934                                  NULL);
2935 cmdline_parse_inst_t cmd_config_rss_reta = {
2936         .f = cmd_set_rss_reta_parsed,
2937         .data = NULL,
2938         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2939         .tokens = {
2940                 (void *)&cmd_config_rss_reta_port,
2941                 (void *)&cmd_config_rss_reta_keyword,
2942                 (void *)&cmd_config_rss_reta_port_id,
2943                 (void *)&cmd_config_rss_reta_name,
2944                 (void *)&cmd_config_rss_reta_list_name,
2945                 (void *)&cmd_config_rss_reta_list_of_items,
2946                 NULL,
2947         },
2948 };
2949
2950 /* *** SHOW PORT RETA INFO *** */
2951 struct cmd_showport_reta {
2952         cmdline_fixed_string_t show;
2953         cmdline_fixed_string_t port;
2954         portid_t port_id;
2955         cmdline_fixed_string_t rss;
2956         cmdline_fixed_string_t reta;
2957         uint16_t size;
2958         cmdline_fixed_string_t list_of_items;
2959 };
2960
2961 static int
2962 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2963                            uint16_t nb_entries,
2964                            char *str)
2965 {
2966         uint32_t size;
2967         const char *p, *p0 = str;
2968         char s[256];
2969         char *end;
2970         char *str_fld[8];
2971         uint16_t i;
2972         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2973                         RTE_RETA_GROUP_SIZE;
2974         int ret;
2975
2976         p = strchr(p0, '(');
2977         if (p == NULL)
2978                 return -1;
2979         p++;
2980         p0 = strchr(p, ')');
2981         if (p0 == NULL)
2982                 return -1;
2983         size = p0 - p;
2984         if (size >= sizeof(s)) {
2985                 printf("The string size exceeds the internal buffer size\n");
2986                 return -1;
2987         }
2988         snprintf(s, sizeof(s), "%.*s", size, p);
2989         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2990         if (ret <= 0 || ret != num) {
2991                 printf("The bits of masks do not match the number of "
2992                                         "reta entries: %u\n", num);
2993                 return -1;
2994         }
2995         for (i = 0; i < ret; i++)
2996                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2997
2998         return 0;
2999 }
3000
3001 static void
3002 cmd_showport_reta_parsed(void *parsed_result,
3003                          __attribute__((unused)) struct cmdline *cl,
3004                          __attribute__((unused)) void *data)
3005 {
3006         struct cmd_showport_reta *res = parsed_result;
3007         struct rte_eth_rss_reta_entry64 reta_conf[8];
3008         struct rte_eth_dev_info dev_info;
3009         uint16_t max_reta_size;
3010
3011         memset(&dev_info, 0, sizeof(dev_info));
3012         rte_eth_dev_info_get(res->port_id, &dev_info);
3013         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3014         if (res->size == 0 || res->size > max_reta_size) {
3015                 printf("Invalid redirection table size: %u (1-%u)\n",
3016                         res->size, max_reta_size);
3017                 return;
3018         }
3019
3020         memset(reta_conf, 0, sizeof(reta_conf));
3021         if (showport_parse_reta_config(reta_conf, res->size,
3022                                 res->list_of_items) < 0) {
3023                 printf("Invalid string: %s for reta masks\n",
3024                                         res->list_of_items);
3025                 return;
3026         }
3027         port_rss_reta_info(res->port_id, reta_conf, res->size);
3028 }
3029
3030 cmdline_parse_token_string_t cmd_showport_reta_show =
3031         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3032 cmdline_parse_token_string_t cmd_showport_reta_port =
3033         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3034 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3035         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3036 cmdline_parse_token_string_t cmd_showport_reta_rss =
3037         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3038 cmdline_parse_token_string_t cmd_showport_reta_reta =
3039         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3040 cmdline_parse_token_num_t cmd_showport_reta_size =
3041         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3042 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3043         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3044                                         list_of_items, NULL);
3045
3046 cmdline_parse_inst_t cmd_showport_reta = {
3047         .f = cmd_showport_reta_parsed,
3048         .data = NULL,
3049         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3050         .tokens = {
3051                 (void *)&cmd_showport_reta_show,
3052                 (void *)&cmd_showport_reta_port,
3053                 (void *)&cmd_showport_reta_port_id,
3054                 (void *)&cmd_showport_reta_rss,
3055                 (void *)&cmd_showport_reta_reta,
3056                 (void *)&cmd_showport_reta_size,
3057                 (void *)&cmd_showport_reta_list_of_items,
3058                 NULL,
3059         },
3060 };
3061
3062 /* *** Show RSS hash configuration *** */
3063 struct cmd_showport_rss_hash {
3064         cmdline_fixed_string_t show;
3065         cmdline_fixed_string_t port;
3066         portid_t port_id;
3067         cmdline_fixed_string_t rss_hash;
3068         cmdline_fixed_string_t rss_type;
3069         cmdline_fixed_string_t key; /* optional argument */
3070 };
3071
3072 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3073                                 __attribute__((unused)) struct cmdline *cl,
3074                                 void *show_rss_key)
3075 {
3076         struct cmd_showport_rss_hash *res = parsed_result;
3077
3078         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3079 }
3080
3081 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3082         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3083 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3084         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3085 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3086         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3087 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3088         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3089                                  "rss-hash");
3090 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3091         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3092
3093 cmdline_parse_inst_t cmd_showport_rss_hash = {
3094         .f = cmd_showport_rss_hash_parsed,
3095         .data = NULL,
3096         .help_str = "show port <port_id> rss-hash",
3097         .tokens = {
3098                 (void *)&cmd_showport_rss_hash_show,
3099                 (void *)&cmd_showport_rss_hash_port,
3100                 (void *)&cmd_showport_rss_hash_port_id,
3101                 (void *)&cmd_showport_rss_hash_rss_hash,
3102                 NULL,
3103         },
3104 };
3105
3106 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3107         .f = cmd_showport_rss_hash_parsed,
3108         .data = (void *)1,
3109         .help_str = "show port <port_id> rss-hash key",
3110         .tokens = {
3111                 (void *)&cmd_showport_rss_hash_show,
3112                 (void *)&cmd_showport_rss_hash_port,
3113                 (void *)&cmd_showport_rss_hash_port_id,
3114                 (void *)&cmd_showport_rss_hash_rss_hash,
3115                 (void *)&cmd_showport_rss_hash_rss_key,
3116                 NULL,
3117         },
3118 };
3119
3120 /* *** Configure DCB *** */
3121 struct cmd_config_dcb {
3122         cmdline_fixed_string_t port;
3123         cmdline_fixed_string_t config;
3124         portid_t port_id;
3125         cmdline_fixed_string_t dcb;
3126         cmdline_fixed_string_t vt;
3127         cmdline_fixed_string_t vt_en;
3128         uint8_t num_tcs;
3129         cmdline_fixed_string_t pfc;
3130         cmdline_fixed_string_t pfc_en;
3131 };
3132
3133 static void
3134 cmd_config_dcb_parsed(void *parsed_result,
3135                         __attribute__((unused)) struct cmdline *cl,
3136                         __attribute__((unused)) void *data)
3137 {
3138         struct cmd_config_dcb *res = parsed_result;
3139         portid_t port_id = res->port_id;
3140         struct rte_port *port;
3141         uint8_t pfc_en;
3142         int ret;
3143
3144         port = &ports[port_id];
3145         /** Check if the port is not started **/
3146         if (port->port_status != RTE_PORT_STOPPED) {
3147                 printf("Please stop port %d first\n", port_id);
3148                 return;
3149         }
3150
3151         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3152                 printf("The invalid number of traffic class,"
3153                         " only 4 or 8 allowed.\n");
3154                 return;
3155         }
3156
3157         if (nb_fwd_lcores < res->num_tcs) {
3158                 printf("nb_cores shouldn't be less than number of TCs.\n");
3159                 return;
3160         }
3161         if (!strncmp(res->pfc_en, "on", 2))
3162                 pfc_en = 1;
3163         else
3164                 pfc_en = 0;
3165
3166         /* DCB in VT mode */
3167         if (!strncmp(res->vt_en, "on", 2))
3168                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3169                                 (enum rte_eth_nb_tcs)res->num_tcs,
3170                                 pfc_en);
3171         else
3172                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3173                                 (enum rte_eth_nb_tcs)res->num_tcs,
3174                                 pfc_en);
3175
3176
3177         if (ret != 0) {
3178                 printf("Cannot initialize network ports.\n");
3179                 return;
3180         }
3181
3182         cmd_reconfig_device_queue(port_id, 1, 1);
3183 }
3184
3185 cmdline_parse_token_string_t cmd_config_dcb_port =
3186         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3187 cmdline_parse_token_string_t cmd_config_dcb_config =
3188         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3189 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3190         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3191 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3192         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3193 cmdline_parse_token_string_t cmd_config_dcb_vt =
3194         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3195 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3196         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3197 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3198         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3199 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3200         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3201 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3202         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3203
3204 cmdline_parse_inst_t cmd_config_dcb = {
3205         .f = cmd_config_dcb_parsed,
3206         .data = NULL,
3207         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3208         .tokens = {
3209                 (void *)&cmd_config_dcb_port,
3210                 (void *)&cmd_config_dcb_config,
3211                 (void *)&cmd_config_dcb_port_id,
3212                 (void *)&cmd_config_dcb_dcb,
3213                 (void *)&cmd_config_dcb_vt,
3214                 (void *)&cmd_config_dcb_vt_en,
3215                 (void *)&cmd_config_dcb_num_tcs,
3216                 (void *)&cmd_config_dcb_pfc,
3217                 (void *)&cmd_config_dcb_pfc_en,
3218                 NULL,
3219         },
3220 };
3221
3222 /* *** configure number of packets per burst *** */
3223 struct cmd_config_burst {
3224         cmdline_fixed_string_t port;
3225         cmdline_fixed_string_t keyword;
3226         cmdline_fixed_string_t all;
3227         cmdline_fixed_string_t name;
3228         uint16_t value;
3229 };
3230
3231 static void
3232 cmd_config_burst_parsed(void *parsed_result,
3233                         __attribute__((unused)) struct cmdline *cl,
3234                         __attribute__((unused)) void *data)
3235 {
3236         struct cmd_config_burst *res = parsed_result;
3237         struct rte_eth_dev_info dev_info;
3238         uint16_t rec_nb_pkts;
3239
3240         if (!all_ports_stopped()) {
3241                 printf("Please stop all ports first\n");
3242                 return;
3243         }
3244
3245         if (!strcmp(res->name, "burst")) {
3246                 if (res->value == 0) {
3247                         /* If user gives a value of zero, query the PMD for
3248                          * its recommended Rx burst size. Testpmd uses a single
3249                          * size for all ports, so assume all ports are the same
3250                          * NIC model and use the values from Port 0.
3251                          */
3252                         rte_eth_dev_info_get(0, &dev_info);
3253                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3254
3255                         if (rec_nb_pkts == 0) {
3256                                 printf("PMD does not recommend a burst size.\n"
3257                                         "User provided value must be between"
3258                                         " 1 and %d\n", MAX_PKT_BURST);
3259                                 return;
3260                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3261                                 printf("PMD recommended burst size of %d"
3262                                         " exceeds maximum value of %d\n",
3263                                         rec_nb_pkts, MAX_PKT_BURST);
3264                                 return;
3265                         }
3266                         printf("Using PMD-provided burst value of %d\n",
3267                                 rec_nb_pkts);
3268                         nb_pkt_per_burst = rec_nb_pkts;
3269                 } else if (res->value > MAX_PKT_BURST) {
3270                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3271                         return;
3272                 } else
3273                         nb_pkt_per_burst = res->value;
3274         } else {
3275                 printf("Unknown parameter\n");
3276                 return;
3277         }
3278
3279         init_port_config();
3280
3281         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3282 }
3283
3284 cmdline_parse_token_string_t cmd_config_burst_port =
3285         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3286 cmdline_parse_token_string_t cmd_config_burst_keyword =
3287         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3288 cmdline_parse_token_string_t cmd_config_burst_all =
3289         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3290 cmdline_parse_token_string_t cmd_config_burst_name =
3291         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3292 cmdline_parse_token_num_t cmd_config_burst_value =
3293         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3294
3295 cmdline_parse_inst_t cmd_config_burst = {
3296         .f = cmd_config_burst_parsed,
3297         .data = NULL,
3298         .help_str = "port config all burst <value>",
3299         .tokens = {
3300                 (void *)&cmd_config_burst_port,
3301                 (void *)&cmd_config_burst_keyword,
3302                 (void *)&cmd_config_burst_all,
3303                 (void *)&cmd_config_burst_name,
3304                 (void *)&cmd_config_burst_value,
3305                 NULL,
3306         },
3307 };
3308
3309 /* *** configure rx/tx queues *** */
3310 struct cmd_config_thresh {
3311         cmdline_fixed_string_t port;
3312         cmdline_fixed_string_t keyword;
3313         cmdline_fixed_string_t all;
3314         cmdline_fixed_string_t name;
3315         uint8_t value;
3316 };
3317
3318 static void
3319 cmd_config_thresh_parsed(void *parsed_result,
3320                         __attribute__((unused)) struct cmdline *cl,
3321                         __attribute__((unused)) void *data)
3322 {
3323         struct cmd_config_thresh *res = parsed_result;
3324
3325         if (!all_ports_stopped()) {
3326                 printf("Please stop all ports first\n");
3327                 return;
3328         }
3329
3330         if (!strcmp(res->name, "txpt"))
3331                 tx_pthresh = res->value;
3332         else if(!strcmp(res->name, "txht"))
3333                 tx_hthresh = res->value;
3334         else if(!strcmp(res->name, "txwt"))
3335                 tx_wthresh = res->value;
3336         else if(!strcmp(res->name, "rxpt"))
3337                 rx_pthresh = res->value;
3338         else if(!strcmp(res->name, "rxht"))
3339                 rx_hthresh = res->value;
3340         else if(!strcmp(res->name, "rxwt"))
3341                 rx_wthresh = res->value;
3342         else {
3343                 printf("Unknown parameter\n");
3344                 return;
3345         }
3346
3347         init_port_config();
3348
3349         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3350 }
3351
3352 cmdline_parse_token_string_t cmd_config_thresh_port =
3353         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3354 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3355         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3356 cmdline_parse_token_string_t cmd_config_thresh_all =
3357         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3358 cmdline_parse_token_string_t cmd_config_thresh_name =
3359         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3360                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3361 cmdline_parse_token_num_t cmd_config_thresh_value =
3362         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3363
3364 cmdline_parse_inst_t cmd_config_thresh = {
3365         .f = cmd_config_thresh_parsed,
3366         .data = NULL,
3367         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3368         .tokens = {
3369                 (void *)&cmd_config_thresh_port,
3370                 (void *)&cmd_config_thresh_keyword,
3371                 (void *)&cmd_config_thresh_all,
3372                 (void *)&cmd_config_thresh_name,
3373                 (void *)&cmd_config_thresh_value,
3374                 NULL,
3375         },
3376 };
3377
3378 /* *** configure free/rs threshold *** */
3379 struct cmd_config_threshold {
3380         cmdline_fixed_string_t port;
3381         cmdline_fixed_string_t keyword;
3382         cmdline_fixed_string_t all;
3383         cmdline_fixed_string_t name;
3384         uint16_t value;
3385 };
3386
3387 static void
3388 cmd_config_threshold_parsed(void *parsed_result,
3389                         __attribute__((unused)) struct cmdline *cl,
3390                         __attribute__((unused)) void *data)
3391 {
3392         struct cmd_config_threshold *res = parsed_result;
3393
3394         if (!all_ports_stopped()) {
3395                 printf("Please stop all ports first\n");
3396                 return;
3397         }
3398
3399         if (!strcmp(res->name, "txfreet"))
3400                 tx_free_thresh = res->value;
3401         else if (!strcmp(res->name, "txrst"))
3402                 tx_rs_thresh = res->value;
3403         else if (!strcmp(res->name, "rxfreet"))
3404                 rx_free_thresh = res->value;
3405         else {
3406                 printf("Unknown parameter\n");
3407                 return;
3408         }
3409
3410         init_port_config();
3411
3412         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3413 }
3414
3415 cmdline_parse_token_string_t cmd_config_threshold_port =
3416         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3417 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3418         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3419                                                                 "config");
3420 cmdline_parse_token_string_t cmd_config_threshold_all =
3421         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3422 cmdline_parse_token_string_t cmd_config_threshold_name =
3423         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3424                                                 "txfreet#txrst#rxfreet");
3425 cmdline_parse_token_num_t cmd_config_threshold_value =
3426         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3427
3428 cmdline_parse_inst_t cmd_config_threshold = {
3429         .f = cmd_config_threshold_parsed,
3430         .data = NULL,
3431         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3432         .tokens = {
3433                 (void *)&cmd_config_threshold_port,
3434                 (void *)&cmd_config_threshold_keyword,
3435                 (void *)&cmd_config_threshold_all,
3436                 (void *)&cmd_config_threshold_name,
3437                 (void *)&cmd_config_threshold_value,
3438                 NULL,
3439         },
3440 };
3441
3442 /* *** stop *** */
3443 struct cmd_stop_result {
3444         cmdline_fixed_string_t stop;
3445 };
3446
3447 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3448                             __attribute__((unused)) struct cmdline *cl,
3449                             __attribute__((unused)) void *data)
3450 {
3451         stop_packet_forwarding();
3452 }
3453
3454 cmdline_parse_token_string_t cmd_stop_stop =
3455         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3456
3457 cmdline_parse_inst_t cmd_stop = {
3458         .f = cmd_stop_parsed,
3459         .data = NULL,
3460         .help_str = "stop: Stop packet forwarding",
3461         .tokens = {
3462                 (void *)&cmd_stop_stop,
3463                 NULL,
3464         },
3465 };
3466
3467 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3468
3469 unsigned int
3470 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3471                 unsigned int *parsed_items, int check_unique_values)
3472 {
3473         unsigned int nb_item;
3474         unsigned int value;
3475         unsigned int i;
3476         unsigned int j;
3477         int value_ok;
3478         char c;
3479
3480         /*
3481          * First parse all items in the list and store their value.
3482          */
3483         value = 0;
3484         nb_item = 0;
3485         value_ok = 0;
3486         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3487                 c = str[i];
3488                 if ((c >= '0') && (c <= '9')) {
3489                         value = (unsigned int) (value * 10 + (c - '0'));
3490                         value_ok = 1;
3491                         continue;
3492                 }
3493                 if (c != ',') {
3494                         printf("character %c is not a decimal digit\n", c);
3495                         return 0;
3496                 }
3497                 if (! value_ok) {
3498                         printf("No valid value before comma\n");
3499                         return 0;
3500                 }
3501                 if (nb_item < max_items) {
3502                         parsed_items[nb_item] = value;
3503                         value_ok = 0;
3504                         value = 0;
3505                 }
3506                 nb_item++;
3507         }
3508         if (nb_item >= max_items) {
3509                 printf("Number of %s = %u > %u (maximum items)\n",
3510                        item_name, nb_item + 1, max_items);
3511                 return 0;
3512         }
3513         parsed_items[nb_item++] = value;
3514         if (! check_unique_values)
3515                 return nb_item;
3516
3517         /*
3518          * Then, check that all values in the list are differents.
3519          * No optimization here...
3520          */
3521         for (i = 0; i < nb_item; i++) {
3522                 for (j = i + 1; j < nb_item; j++) {
3523                         if (parsed_items[j] == parsed_items[i]) {
3524                                 printf("duplicated %s %u at index %u and %u\n",
3525                                        item_name, parsed_items[i], i, j);
3526                                 return 0;
3527                         }
3528                 }
3529         }
3530         return nb_item;
3531 }
3532
3533 struct cmd_set_list_result {
3534         cmdline_fixed_string_t cmd_keyword;
3535         cmdline_fixed_string_t list_name;
3536         cmdline_fixed_string_t list_of_items;
3537 };
3538
3539 static void cmd_set_list_parsed(void *parsed_result,
3540                                 __attribute__((unused)) struct cmdline *cl,
3541                                 __attribute__((unused)) void *data)
3542 {
3543         struct cmd_set_list_result *res;
3544         union {
3545                 unsigned int lcorelist[RTE_MAX_LCORE];
3546                 unsigned int portlist[RTE_MAX_ETHPORTS];
3547         } parsed_items;
3548         unsigned int nb_item;
3549
3550         if (test_done == 0) {
3551                 printf("Please stop forwarding first\n");
3552                 return;
3553         }
3554
3555         res = parsed_result;
3556         if (!strcmp(res->list_name, "corelist")) {
3557                 nb_item = parse_item_list(res->list_of_items, "core",
3558                                           RTE_MAX_LCORE,
3559                                           parsed_items.lcorelist, 1);
3560                 if (nb_item > 0) {
3561                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3562                         fwd_config_setup();
3563                 }
3564                 return;
3565         }
3566         if (!strcmp(res->list_name, "portlist")) {
3567                 nb_item = parse_item_list(res->list_of_items, "port",
3568                                           RTE_MAX_ETHPORTS,
3569                                           parsed_items.portlist, 1);
3570                 if (nb_item > 0) {
3571                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3572                         fwd_config_setup();
3573                 }
3574         }
3575 }
3576
3577 cmdline_parse_token_string_t cmd_set_list_keyword =
3578         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3579                                  "set");
3580 cmdline_parse_token_string_t cmd_set_list_name =
3581         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3582                                  "corelist#portlist");
3583 cmdline_parse_token_string_t cmd_set_list_of_items =
3584         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3585                                  NULL);
3586
3587 cmdline_parse_inst_t cmd_set_fwd_list = {
3588         .f = cmd_set_list_parsed,
3589         .data = NULL,
3590         .help_str = "set corelist|portlist <list0[,list1]*>",
3591         .tokens = {
3592                 (void *)&cmd_set_list_keyword,
3593                 (void *)&cmd_set_list_name,
3594                 (void *)&cmd_set_list_of_items,
3595                 NULL,
3596         },
3597 };
3598
3599 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3600
3601 struct cmd_setmask_result {
3602         cmdline_fixed_string_t set;
3603         cmdline_fixed_string_t mask;
3604         uint64_t hexavalue;
3605 };
3606
3607 static void cmd_set_mask_parsed(void *parsed_result,
3608                                 __attribute__((unused)) struct cmdline *cl,
3609                                 __attribute__((unused)) void *data)
3610 {
3611         struct cmd_setmask_result *res = parsed_result;
3612
3613         if (test_done == 0) {
3614                 printf("Please stop forwarding first\n");
3615                 return;
3616         }
3617         if (!strcmp(res->mask, "coremask")) {
3618                 set_fwd_lcores_mask(res->hexavalue);
3619                 fwd_config_setup();
3620         } else if (!strcmp(res->mask, "portmask")) {
3621                 set_fwd_ports_mask(res->hexavalue);
3622                 fwd_config_setup();
3623         }
3624 }
3625
3626 cmdline_parse_token_string_t cmd_setmask_set =
3627         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3628 cmdline_parse_token_string_t cmd_setmask_mask =
3629         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3630                                  "coremask#portmask");
3631 cmdline_parse_token_num_t cmd_setmask_value =
3632         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3633
3634 cmdline_parse_inst_t cmd_set_fwd_mask = {
3635         .f = cmd_set_mask_parsed,
3636         .data = NULL,
3637         .help_str = "set coremask|portmask <hexadecimal value>",
3638         .tokens = {
3639                 (void *)&cmd_setmask_set,
3640                 (void *)&cmd_setmask_mask,
3641                 (void *)&cmd_setmask_value,
3642                 NULL,
3643         },
3644 };
3645
3646 /*
3647  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3648  */
3649 struct cmd_set_result {
3650         cmdline_fixed_string_t set;
3651         cmdline_fixed_string_t what;
3652         uint16_t value;
3653 };
3654
3655 static void cmd_set_parsed(void *parsed_result,
3656                            __attribute__((unused)) struct cmdline *cl,
3657                            __attribute__((unused)) void *data)
3658 {
3659         struct cmd_set_result *res = parsed_result;
3660         if (!strcmp(res->what, "nbport")) {
3661                 set_fwd_ports_number(res->value);
3662                 fwd_config_setup();
3663         } else if (!strcmp(res->what, "nbcore")) {
3664                 set_fwd_lcores_number(res->value);
3665                 fwd_config_setup();
3666         } else if (!strcmp(res->what, "burst"))
3667                 set_nb_pkt_per_burst(res->value);
3668         else if (!strcmp(res->what, "verbose"))
3669                 set_verbose_level(res->value);
3670 }
3671
3672 cmdline_parse_token_string_t cmd_set_set =
3673         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3674 cmdline_parse_token_string_t cmd_set_what =
3675         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3676                                  "nbport#nbcore#burst#verbose");
3677 cmdline_parse_token_num_t cmd_set_value =
3678         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3679
3680 cmdline_parse_inst_t cmd_set_numbers = {
3681         .f = cmd_set_parsed,
3682         .data = NULL,
3683         .help_str = "set nbport|nbcore|burst|verbose <value>",
3684         .tokens = {
3685                 (void *)&cmd_set_set,
3686                 (void *)&cmd_set_what,
3687                 (void *)&cmd_set_value,
3688                 NULL,
3689         },
3690 };
3691
3692 /* *** SET LOG LEVEL CONFIGURATION *** */
3693
3694 struct cmd_set_log_result {
3695         cmdline_fixed_string_t set;
3696         cmdline_fixed_string_t log;
3697         cmdline_fixed_string_t type;
3698         uint32_t level;
3699 };
3700
3701 static void
3702 cmd_set_log_parsed(void *parsed_result,
3703                    __attribute__((unused)) struct cmdline *cl,
3704                    __attribute__((unused)) void *data)
3705 {
3706         struct cmd_set_log_result *res;
3707         int ret;
3708
3709         res = parsed_result;
3710         if (!strcmp(res->type, "global"))
3711                 rte_log_set_global_level(res->level);
3712         else {
3713                 ret = rte_log_set_level_regexp(res->type, res->level);
3714                 if (ret < 0)
3715                         printf("Unable to set log level\n");
3716         }
3717 }
3718
3719 cmdline_parse_token_string_t cmd_set_log_set =
3720         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3721 cmdline_parse_token_string_t cmd_set_log_log =
3722         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3723 cmdline_parse_token_string_t cmd_set_log_type =
3724         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3725 cmdline_parse_token_num_t cmd_set_log_level =
3726         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3727
3728 cmdline_parse_inst_t cmd_set_log = {
3729         .f = cmd_set_log_parsed,
3730         .data = NULL,
3731         .help_str = "set log global|<type> <level>",
3732         .tokens = {
3733                 (void *)&cmd_set_log_set,
3734                 (void *)&cmd_set_log_log,
3735                 (void *)&cmd_set_log_type,
3736                 (void *)&cmd_set_log_level,
3737                 NULL,
3738         },
3739 };
3740
3741 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3742
3743 struct cmd_set_txpkts_result {
3744         cmdline_fixed_string_t cmd_keyword;
3745         cmdline_fixed_string_t txpkts;
3746         cmdline_fixed_string_t seg_lengths;
3747 };
3748
3749 static void
3750 cmd_set_txpkts_parsed(void *parsed_result,
3751                       __attribute__((unused)) struct cmdline *cl,
3752                       __attribute__((unused)) void *data)
3753 {
3754         struct cmd_set_txpkts_result *res;
3755         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3756         unsigned int nb_segs;
3757
3758         res = parsed_result;
3759         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3760                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3761         if (nb_segs > 0)
3762                 set_tx_pkt_segments(seg_lengths, nb_segs);
3763 }
3764
3765 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3766         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3767                                  cmd_keyword, "set");
3768 cmdline_parse_token_string_t cmd_set_txpkts_name =
3769         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3770                                  txpkts, "txpkts");
3771 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3772         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3773                                  seg_lengths, NULL);
3774
3775 cmdline_parse_inst_t cmd_set_txpkts = {
3776         .f = cmd_set_txpkts_parsed,
3777         .data = NULL,
3778         .help_str = "set txpkts <len0[,len1]*>",
3779         .tokens = {
3780                 (void *)&cmd_set_txpkts_keyword,
3781                 (void *)&cmd_set_txpkts_name,
3782                 (void *)&cmd_set_txpkts_lengths,
3783                 NULL,
3784         },
3785 };
3786
3787 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3788
3789 struct cmd_set_txsplit_result {
3790         cmdline_fixed_string_t cmd_keyword;
3791         cmdline_fixed_string_t txsplit;
3792         cmdline_fixed_string_t mode;
3793 };
3794
3795 static void
3796 cmd_set_txsplit_parsed(void *parsed_result,
3797                       __attribute__((unused)) struct cmdline *cl,
3798                       __attribute__((unused)) void *data)
3799 {
3800         struct cmd_set_txsplit_result *res;
3801
3802         res = parsed_result;
3803         set_tx_pkt_split(res->mode);
3804 }
3805
3806 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3807         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3808                                  cmd_keyword, "set");
3809 cmdline_parse_token_string_t cmd_set_txsplit_name =
3810         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3811                                  txsplit, "txsplit");
3812 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3813         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3814                                  mode, NULL);
3815
3816 cmdline_parse_inst_t cmd_set_txsplit = {
3817         .f = cmd_set_txsplit_parsed,
3818         .data = NULL,
3819         .help_str = "set txsplit on|off|rand",
3820         .tokens = {
3821                 (void *)&cmd_set_txsplit_keyword,
3822                 (void *)&cmd_set_txsplit_name,
3823                 (void *)&cmd_set_txsplit_mode,
3824                 NULL,
3825         },
3826 };
3827
3828 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3829 struct cmd_rx_vlan_filter_all_result {
3830         cmdline_fixed_string_t rx_vlan;
3831         cmdline_fixed_string_t what;
3832         cmdline_fixed_string_t all;
3833         portid_t port_id;
3834 };
3835
3836 static void
3837 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3838                               __attribute__((unused)) struct cmdline *cl,
3839                               __attribute__((unused)) void *data)
3840 {
3841         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3842
3843         if (!strcmp(res->what, "add"))
3844                 rx_vlan_all_filter_set(res->port_id, 1);
3845         else
3846                 rx_vlan_all_filter_set(res->port_id, 0);
3847 }
3848
3849 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3850         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3851                                  rx_vlan, "rx_vlan");
3852 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3853         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3854                                  what, "add#rm");
3855 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3856         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3857                                  all, "all");
3858 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3859         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3860                               port_id, UINT16);
3861
3862 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3863         .f = cmd_rx_vlan_filter_all_parsed,
3864         .data = NULL,
3865         .help_str = "rx_vlan add|rm all <port_id>: "
3866                 "Add/Remove all identifiers to/from the set of VLAN "
3867                 "identifiers filtered by a port",
3868         .tokens = {
3869                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3870                 (void *)&cmd_rx_vlan_filter_all_what,
3871                 (void *)&cmd_rx_vlan_filter_all_all,
3872                 (void *)&cmd_rx_vlan_filter_all_portid,
3873                 NULL,
3874         },
3875 };
3876
3877 /* *** VLAN OFFLOAD SET ON A PORT *** */
3878 struct cmd_vlan_offload_result {
3879         cmdline_fixed_string_t vlan;
3880         cmdline_fixed_string_t set;
3881         cmdline_fixed_string_t vlan_type;
3882         cmdline_fixed_string_t what;
3883         cmdline_fixed_string_t on;
3884         cmdline_fixed_string_t port_id;
3885 };
3886
3887 static void
3888 cmd_vlan_offload_parsed(void *parsed_result,
3889                           __attribute__((unused)) struct cmdline *cl,
3890                           __attribute__((unused)) void *data)
3891 {
3892         int on;
3893         struct cmd_vlan_offload_result *res = parsed_result;
3894         char *str;
3895         int i, len = 0;
3896         portid_t port_id = 0;
3897         unsigned int tmp;
3898
3899         str = res->port_id;
3900         len = strnlen(str, STR_TOKEN_SIZE);
3901         i = 0;
3902         /* Get port_id first */
3903         while(i < len){
3904                 if(str[i] == ',')
3905                         break;
3906
3907                 i++;
3908         }
3909         str[i]='\0';
3910         tmp = strtoul(str, NULL, 0);
3911         /* If port_id greater that what portid_t can represent, return */
3912         if(tmp >= RTE_MAX_ETHPORTS)
3913                 return;
3914         port_id = (portid_t)tmp;
3915
3916         if (!strcmp(res->on, "on"))
3917                 on = 1;
3918         else
3919                 on = 0;
3920
3921         if (!strcmp(res->what, "strip"))
3922                 rx_vlan_strip_set(port_id,  on);
3923         else if(!strcmp(res->what, "stripq")){
3924                 uint16_t queue_id = 0;
3925
3926                 /* No queue_id, return */
3927                 if(i + 1 >= len) {
3928                         printf("must specify (port,queue_id)\n");
3929                         return;
3930                 }
3931                 tmp = strtoul(str + i + 1, NULL, 0);
3932                 /* If queue_id greater that what 16-bits can represent, return */
3933                 if(tmp > 0xffff)
3934                         return;
3935
3936                 queue_id = (uint16_t)tmp;
3937                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3938         }
3939         else if (!strcmp(res->what, "filter"))
3940                 rx_vlan_filter_set(port_id, on);
3941         else
3942                 vlan_extend_set(port_id, on);
3943
3944         return;
3945 }
3946
3947 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3948         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3949                                  vlan, "vlan");
3950 cmdline_parse_token_string_t cmd_vlan_offload_set =
3951         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3952                                  set, "set");
3953 cmdline_parse_token_string_t cmd_vlan_offload_what =
3954         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3955                                  what, "strip#filter#qinq#stripq");
3956 cmdline_parse_token_string_t cmd_vlan_offload_on =
3957         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3958                               on, "on#off");
3959 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3960         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3961                               port_id, NULL);
3962
3963 cmdline_parse_inst_t cmd_vlan_offload = {
3964         .f = cmd_vlan_offload_parsed,
3965         .data = NULL,
3966         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3967                 "<port_id[,queue_id]>: "
3968                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3969         .tokens = {
3970                 (void *)&cmd_vlan_offload_vlan,
3971                 (void *)&cmd_vlan_offload_set,
3972                 (void *)&cmd_vlan_offload_what,
3973                 (void *)&cmd_vlan_offload_on,
3974                 (void *)&cmd_vlan_offload_portid,
3975                 NULL,
3976         },
3977 };
3978
3979 /* *** VLAN TPID SET ON A PORT *** */
3980 struct cmd_vlan_tpid_result {
3981         cmdline_fixed_string_t vlan;
3982         cmdline_fixed_string_t set;
3983         cmdline_fixed_string_t vlan_type;
3984         cmdline_fixed_string_t what;
3985         uint16_t tp_id;
3986         portid_t port_id;
3987 };
3988
3989 static void
3990 cmd_vlan_tpid_parsed(void *parsed_result,
3991                           __attribute__((unused)) struct cmdline *cl,
3992                           __attribute__((unused)) void *data)
3993 {
3994         struct cmd_vlan_tpid_result *res = parsed_result;
3995         enum rte_vlan_type vlan_type;
3996
3997         if (!strcmp(res->vlan_type, "inner"))
3998                 vlan_type = ETH_VLAN_TYPE_INNER;
3999         else if (!strcmp(res->vlan_type, "outer"))
4000                 vlan_type = ETH_VLAN_TYPE_OUTER;
4001         else {
4002                 printf("Unknown vlan type\n");
4003                 return;
4004         }
4005         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4006 }
4007
4008 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4009         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4010                                  vlan, "vlan");
4011 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4012         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4013                                  set, "set");
4014 cmdline_parse_token_string_t cmd_vlan_type =
4015         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4016                                  vlan_type, "inner#outer");
4017 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4018         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4019                                  what, "tpid");
4020 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4021         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4022                               tp_id, UINT16);
4023 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4024         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4025                               port_id, UINT16);
4026
4027 cmdline_parse_inst_t cmd_vlan_tpid = {
4028         .f = cmd_vlan_tpid_parsed,
4029         .data = NULL,
4030         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4031                 "Set the VLAN Ether type",
4032         .tokens = {
4033                 (void *)&cmd_vlan_tpid_vlan,
4034                 (void *)&cmd_vlan_tpid_set,
4035                 (void *)&cmd_vlan_type,
4036                 (void *)&cmd_vlan_tpid_what,
4037                 (void *)&cmd_vlan_tpid_tpid,
4038                 (void *)&cmd_vlan_tpid_portid,
4039                 NULL,
4040         },
4041 };
4042
4043 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4044 struct cmd_rx_vlan_filter_result {
4045         cmdline_fixed_string_t rx_vlan;
4046         cmdline_fixed_string_t what;
4047         uint16_t vlan_id;
4048         portid_t port_id;
4049 };
4050
4051 static void
4052 cmd_rx_vlan_filter_parsed(void *parsed_result,
4053                           __attribute__((unused)) struct cmdline *cl,
4054                           __attribute__((unused)) void *data)
4055 {
4056         struct cmd_rx_vlan_filter_result *res = parsed_result;
4057
4058         if (!strcmp(res->what, "add"))
4059                 rx_vft_set(res->port_id, res->vlan_id, 1);
4060         else
4061                 rx_vft_set(res->port_id, res->vlan_id, 0);
4062 }
4063
4064 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4065         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4066                                  rx_vlan, "rx_vlan");
4067 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4068         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4069                                  what, "add#rm");
4070 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4071         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4072                               vlan_id, UINT16);
4073 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4074         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4075                               port_id, UINT16);
4076
4077 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4078         .f = cmd_rx_vlan_filter_parsed,
4079         .data = NULL,
4080         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4081                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4082                 "identifiers filtered by a port",
4083         .tokens = {
4084                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4085                 (void *)&cmd_rx_vlan_filter_what,
4086                 (void *)&cmd_rx_vlan_filter_vlanid,
4087                 (void *)&cmd_rx_vlan_filter_portid,
4088                 NULL,
4089         },
4090 };
4091
4092 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4093 struct cmd_tx_vlan_set_result {
4094         cmdline_fixed_string_t tx_vlan;
4095         cmdline_fixed_string_t set;
4096         portid_t port_id;
4097         uint16_t vlan_id;
4098 };
4099
4100 static void
4101 cmd_tx_vlan_set_parsed(void *parsed_result,
4102                        __attribute__((unused)) struct cmdline *cl,
4103                        __attribute__((unused)) void *data)
4104 {
4105         struct cmd_tx_vlan_set_result *res = parsed_result;
4106
4107         if (!port_is_stopped(res->port_id)) {
4108                 printf("Please stop port %d first\n", res->port_id);
4109                 return;
4110         }
4111
4112         tx_vlan_set(res->port_id, res->vlan_id);
4113
4114         cmd_reconfig_device_queue(res->port_id, 1, 1);
4115 }
4116
4117 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4118         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4119                                  tx_vlan, "tx_vlan");
4120 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4121         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4122                                  set, "set");
4123 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4124         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4125                               port_id, UINT16);
4126 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4127         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4128                               vlan_id, UINT16);
4129
4130 cmdline_parse_inst_t cmd_tx_vlan_set = {
4131         .f = cmd_tx_vlan_set_parsed,
4132         .data = NULL,
4133         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4134                 "Enable hardware insertion of a single VLAN header "
4135                 "with a given TAG Identifier in packets sent on a port",
4136         .tokens = {
4137                 (void *)&cmd_tx_vlan_set_tx_vlan,
4138                 (void *)&cmd_tx_vlan_set_set,
4139                 (void *)&cmd_tx_vlan_set_portid,
4140                 (void *)&cmd_tx_vlan_set_vlanid,
4141                 NULL,
4142         },
4143 };
4144
4145 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4146 struct cmd_tx_vlan_set_qinq_result {
4147         cmdline_fixed_string_t tx_vlan;
4148         cmdline_fixed_string_t set;
4149         portid_t port_id;
4150         uint16_t vlan_id;
4151         uint16_t vlan_id_outer;
4152 };
4153
4154 static void
4155 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4156                             __attribute__((unused)) struct cmdline *cl,
4157                             __attribute__((unused)) void *data)
4158 {
4159         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4160
4161         if (!port_is_stopped(res->port_id)) {
4162                 printf("Please stop port %d first\n", res->port_id);
4163                 return;
4164         }
4165
4166         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4167
4168         cmd_reconfig_device_queue(res->port_id, 1, 1);
4169 }
4170
4171 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4172         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4173                 tx_vlan, "tx_vlan");
4174 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4175         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4176                 set, "set");
4177 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4178         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4179                 port_id, UINT16);
4180 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4181         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4182                 vlan_id, UINT16);
4183 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4184         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4185                 vlan_id_outer, UINT16);
4186
4187 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4188         .f = cmd_tx_vlan_set_qinq_parsed,
4189         .data = NULL,
4190         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4191                 "Enable hardware insertion of double VLAN header "
4192                 "with given TAG Identifiers in packets sent on a port",
4193         .tokens = {
4194                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4195                 (void *)&cmd_tx_vlan_set_qinq_set,
4196                 (void *)&cmd_tx_vlan_set_qinq_portid,
4197                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4198                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4199                 NULL,
4200         },
4201 };
4202
4203 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4204 struct cmd_tx_vlan_set_pvid_result {
4205         cmdline_fixed_string_t tx_vlan;
4206         cmdline_fixed_string_t set;
4207         cmdline_fixed_string_t pvid;
4208         portid_t port_id;
4209         uint16_t vlan_id;
4210         cmdline_fixed_string_t mode;
4211 };
4212
4213 static void
4214 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4215                             __attribute__((unused)) struct cmdline *cl,
4216                             __attribute__((unused)) void *data)
4217 {
4218         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4219
4220         if (strcmp(res->mode, "on") == 0)
4221                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4222         else
4223                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4224 }
4225
4226 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4227         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4228                                  tx_vlan, "tx_vlan");
4229 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4230         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4231                                  set, "set");
4232 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4233         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4234                                  pvid, "pvid");
4235 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4236         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4237                              port_id, UINT16);
4238 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4239         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4240                               vlan_id, UINT16);
4241 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4242         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4243                                  mode, "on#off");
4244
4245 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4246         .f = cmd_tx_vlan_set_pvid_parsed,
4247         .data = NULL,
4248         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4249         .tokens = {
4250                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4251                 (void *)&cmd_tx_vlan_set_pvid_set,
4252                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4253                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4254                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4255                 (void *)&cmd_tx_vlan_set_pvid_mode,
4256                 NULL,
4257         },
4258 };
4259
4260 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4261 struct cmd_tx_vlan_reset_result {
4262         cmdline_fixed_string_t tx_vlan;
4263         cmdline_fixed_string_t reset;
4264         portid_t port_id;
4265 };
4266
4267 static void
4268 cmd_tx_vlan_reset_parsed(void *parsed_result,
4269                          __attribute__((unused)) struct cmdline *cl,
4270                          __attribute__((unused)) void *data)
4271 {
4272         struct cmd_tx_vlan_reset_result *res = parsed_result;
4273
4274         if (!port_is_stopped(res->port_id)) {
4275                 printf("Please stop port %d first\n", res->port_id);
4276                 return;
4277         }
4278
4279         tx_vlan_reset(res->port_id);
4280
4281         cmd_reconfig_device_queue(res->port_id, 1, 1);
4282 }
4283
4284 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4285         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4286                                  tx_vlan, "tx_vlan");
4287 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4288         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4289                                  reset, "reset");
4290 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4291         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4292                               port_id, UINT16);
4293
4294 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4295         .f = cmd_tx_vlan_reset_parsed,
4296         .data = NULL,
4297         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4298                 "VLAN header in packets sent on a port",
4299         .tokens = {
4300                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4301                 (void *)&cmd_tx_vlan_reset_reset,
4302                 (void *)&cmd_tx_vlan_reset_portid,
4303                 NULL,
4304         },
4305 };
4306
4307
4308 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4309 struct cmd_csum_result {
4310         cmdline_fixed_string_t csum;
4311         cmdline_fixed_string_t mode;
4312         cmdline_fixed_string_t proto;
4313         cmdline_fixed_string_t hwsw;
4314         portid_t port_id;
4315 };
4316
4317 static void
4318 csum_show(int port_id)
4319 {
4320         struct rte_eth_dev_info dev_info;
4321         uint64_t tx_offloads;
4322
4323         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4324         printf("Parse tunnel is %s\n",
4325                 (ports[port_id].parse_tunnel) ? "on" : "off");
4326         printf("IP checksum offload is %s\n",
4327                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4328         printf("UDP checksum offload is %s\n",
4329                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4330         printf("TCP checksum offload is %s\n",
4331                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4332         printf("SCTP checksum offload is %s\n",
4333                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4334         printf("Outer-Ip checksum offload is %s\n",
4335                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4336         printf("Outer-Udp checksum offload is %s\n",
4337                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4338
4339         /* display warnings if configuration is not supported by the NIC */
4340         rte_eth_dev_info_get(port_id, &dev_info);
4341         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4342                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4343                 printf("Warning: hardware IP checksum enabled but not "
4344                         "supported by port %d\n", port_id);
4345         }
4346         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4347                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4348                 printf("Warning: hardware UDP checksum enabled but not "
4349                         "supported by port %d\n", port_id);
4350         }
4351         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4352                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4353                 printf("Warning: hardware TCP checksum enabled but not "
4354                         "supported by port %d\n", port_id);
4355         }
4356         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4357                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4358                 printf("Warning: hardware SCTP checksum enabled but not "
4359                         "supported by port %d\n", port_id);
4360         }
4361         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4362                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4363                 printf("Warning: hardware outer IP checksum enabled but not "
4364                         "supported by port %d\n", port_id);
4365         }
4366         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4367                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4368                         == 0) {
4369                 printf("Warning: hardware outer UDP checksum enabled but not "
4370                         "supported by port %d\n", port_id);
4371         }
4372 }
4373
4374 static void
4375 cmd_config_queue_tx_offloads(struct rte_port *port)
4376 {
4377         int k;
4378
4379         /* Apply queue tx offloads configuration */
4380         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4381                 port->tx_conf[k].offloads =
4382                         port->dev_conf.txmode.offloads;
4383 }
4384
4385 static void
4386 cmd_csum_parsed(void *parsed_result,
4387                        __attribute__((unused)) struct cmdline *cl,
4388                        __attribute__((unused)) void *data)
4389 {
4390         struct cmd_csum_result *res = parsed_result;
4391         int hw = 0;
4392         uint64_t csum_offloads = 0;
4393         struct rte_eth_dev_info dev_info;
4394
4395         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4396                 printf("invalid port %d\n", res->port_id);
4397                 return;
4398         }
4399         if (!port_is_stopped(res->port_id)) {
4400                 printf("Please stop port %d first\n", res->port_id);
4401                 return;
4402         }
4403
4404         rte_eth_dev_info_get(res->port_id, &dev_info);
4405         if (!strcmp(res->mode, "set")) {
4406
4407                 if (!strcmp(res->hwsw, "hw"))
4408                         hw = 1;
4409
4410                 if (!strcmp(res->proto, "ip")) {
4411                         if (hw == 0 || (dev_info.tx_offload_capa &
4412                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4413                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4414                         } else {
4415                                 printf("IP checksum offload is not supported "
4416                                        "by port %u\n", res->port_id);
4417                         }
4418                 } else if (!strcmp(res->proto, "udp")) {
4419                         if (hw == 0 || (dev_info.tx_offload_capa &
4420                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4421                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4422                         } else {
4423                                 printf("UDP checksum offload is not supported "
4424                                        "by port %u\n", res->port_id);
4425                         }
4426                 } else if (!strcmp(res->proto, "tcp")) {
4427                         if (hw == 0 || (dev_info.tx_offload_capa &
4428                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4429                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4430                         } else {
4431                                 printf("TCP checksum offload is not supported "
4432                                        "by port %u\n", res->port_id);
4433                         }
4434                 } else if (!strcmp(res->proto, "sctp")) {
4435                         if (hw == 0 || (dev_info.tx_offload_capa &
4436                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4437                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4438                         } else {
4439                                 printf("SCTP checksum offload is not supported "
4440                                        "by port %u\n", res->port_id);
4441                         }
4442                 } else if (!strcmp(res->proto, "outer-ip")) {
4443                         if (hw == 0 || (dev_info.tx_offload_capa &
4444                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4445                                 csum_offloads |=
4446                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4447                         } else {
4448                                 printf("Outer IP checksum offload is not "
4449                                        "supported by port %u\n", res->port_id);
4450                         }
4451                 } else if (!strcmp(res->proto, "outer-udp")) {
4452                         if (hw == 0 || (dev_info.tx_offload_capa &
4453                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4454                                 csum_offloads |=
4455                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4456                         } else {
4457                                 printf("Outer UDP checksum offload is not "
4458                                        "supported by port %u\n", res->port_id);
4459                         }
4460                 }
4461
4462                 if (hw) {
4463                         ports[res->port_id].dev_conf.txmode.offloads |=
4464                                                         csum_offloads;
4465                 } else {
4466                         ports[res->port_id].dev_conf.txmode.offloads &=
4467                                                         (~csum_offloads);
4468                 }
4469                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4470         }
4471         csum_show(res->port_id);
4472
4473         cmd_reconfig_device_queue(res->port_id, 1, 1);
4474 }
4475
4476 cmdline_parse_token_string_t cmd_csum_csum =
4477         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4478                                 csum, "csum");
4479 cmdline_parse_token_string_t cmd_csum_mode =
4480         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4481                                 mode, "set");
4482 cmdline_parse_token_string_t cmd_csum_proto =
4483         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4484                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4485 cmdline_parse_token_string_t cmd_csum_hwsw =
4486         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4487                                 hwsw, "hw#sw");
4488 cmdline_parse_token_num_t cmd_csum_portid =
4489         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4490                                 port_id, UINT16);
4491
4492 cmdline_parse_inst_t cmd_csum_set = {
4493         .f = cmd_csum_parsed,
4494         .data = NULL,
4495         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4496                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4497                 "using csum forward engine",
4498         .tokens = {
4499                 (void *)&cmd_csum_csum,
4500                 (void *)&cmd_csum_mode,
4501                 (void *)&cmd_csum_proto,
4502                 (void *)&cmd_csum_hwsw,
4503                 (void *)&cmd_csum_portid,
4504                 NULL,
4505         },
4506 };
4507
4508 cmdline_parse_token_string_t cmd_csum_mode_show =
4509         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4510                                 mode, "show");
4511
4512 cmdline_parse_inst_t cmd_csum_show = {
4513         .f = cmd_csum_parsed,
4514         .data = NULL,
4515         .help_str = "csum show <port_id>: Show checksum offload configuration",
4516         .tokens = {
4517                 (void *)&cmd_csum_csum,
4518                 (void *)&cmd_csum_mode_show,
4519                 (void *)&cmd_csum_portid,
4520                 NULL,
4521         },
4522 };
4523
4524 /* Enable/disable tunnel parsing */
4525 struct cmd_csum_tunnel_result {
4526         cmdline_fixed_string_t csum;
4527         cmdline_fixed_string_t parse;
4528         cmdline_fixed_string_t onoff;
4529         portid_t port_id;
4530 };
4531
4532 static void
4533 cmd_csum_tunnel_parsed(void *parsed_result,
4534                        __attribute__((unused)) struct cmdline *cl,
4535                        __attribute__((unused)) void *data)
4536 {
4537         struct cmd_csum_tunnel_result *res = parsed_result;
4538
4539         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4540                 return;
4541
4542         if (!strcmp(res->onoff, "on"))
4543                 ports[res->port_id].parse_tunnel = 1;
4544         else
4545                 ports[res->port_id].parse_tunnel = 0;
4546
4547         csum_show(res->port_id);
4548 }
4549
4550 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4551         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4552                                 csum, "csum");
4553 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4554         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4555                                 parse, "parse-tunnel");
4556 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4557         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4558                                 onoff, "on#off");
4559 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4560         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4561                                 port_id, UINT16);
4562
4563 cmdline_parse_inst_t cmd_csum_tunnel = {
4564         .f = cmd_csum_tunnel_parsed,
4565         .data = NULL,
4566         .help_str = "csum parse-tunnel on|off <port_id>: "
4567                 "Enable/Disable parsing of tunnels for csum engine",
4568         .tokens = {
4569                 (void *)&cmd_csum_tunnel_csum,
4570                 (void *)&cmd_csum_tunnel_parse,
4571                 (void *)&cmd_csum_tunnel_onoff,
4572                 (void *)&cmd_csum_tunnel_portid,
4573                 NULL,
4574         },
4575 };
4576
4577 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4578 struct cmd_tso_set_result {
4579         cmdline_fixed_string_t tso;
4580         cmdline_fixed_string_t mode;
4581         uint16_t tso_segsz;
4582         portid_t port_id;
4583 };
4584
4585 static void
4586 cmd_tso_set_parsed(void *parsed_result,
4587                        __attribute__((unused)) struct cmdline *cl,
4588                        __attribute__((unused)) void *data)
4589 {
4590         struct cmd_tso_set_result *res = parsed_result;
4591         struct rte_eth_dev_info dev_info;
4592
4593         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4594                 return;
4595         if (!port_is_stopped(res->port_id)) {
4596                 printf("Please stop port %d first\n", res->port_id);
4597                 return;
4598         }
4599
4600         if (!strcmp(res->mode, "set"))
4601                 ports[res->port_id].tso_segsz = res->tso_segsz;
4602
4603         rte_eth_dev_info_get(res->port_id, &dev_info);
4604         if ((ports[res->port_id].tso_segsz != 0) &&
4605                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4606                 printf("Error: TSO is not supported by port %d\n",
4607                        res->port_id);
4608                 return;
4609         }
4610
4611         if (ports[res->port_id].tso_segsz == 0) {
4612                 ports[res->port_id].dev_conf.txmode.offloads &=
4613                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4614                 printf("TSO for non-tunneled packets is disabled\n");
4615         } else {
4616                 ports[res->port_id].dev_conf.txmode.offloads |=
4617                                                 DEV_TX_OFFLOAD_TCP_TSO;
4618                 printf("TSO segment size for non-tunneled packets is %d\n",
4619                         ports[res->port_id].tso_segsz);
4620         }
4621         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4622
4623         /* display warnings if configuration is not supported by the NIC */
4624         rte_eth_dev_info_get(res->port_id, &dev_info);
4625         if ((ports[res->port_id].tso_segsz != 0) &&
4626                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4627                 printf("Warning: TSO enabled but not "
4628                         "supported by port %d\n", res->port_id);
4629         }
4630
4631         cmd_reconfig_device_queue(res->port_id, 1, 1);
4632 }
4633
4634 cmdline_parse_token_string_t cmd_tso_set_tso =
4635         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4636                                 tso, "tso");
4637 cmdline_parse_token_string_t cmd_tso_set_mode =
4638         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4639                                 mode, "set");
4640 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4641         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4642                                 tso_segsz, UINT16);
4643 cmdline_parse_token_num_t cmd_tso_set_portid =
4644         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4645                                 port_id, UINT16);
4646
4647 cmdline_parse_inst_t cmd_tso_set = {
4648         .f = cmd_tso_set_parsed,
4649         .data = NULL,
4650         .help_str = "tso set <tso_segsz> <port_id>: "
4651                 "Set TSO segment size of non-tunneled packets for csum engine "
4652                 "(0 to disable)",
4653         .tokens = {
4654                 (void *)&cmd_tso_set_tso,
4655                 (void *)&cmd_tso_set_mode,
4656                 (void *)&cmd_tso_set_tso_segsz,
4657                 (void *)&cmd_tso_set_portid,
4658                 NULL,
4659         },
4660 };
4661
4662 cmdline_parse_token_string_t cmd_tso_show_mode =
4663         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4664                                 mode, "show");
4665
4666
4667 cmdline_parse_inst_t cmd_tso_show = {
4668         .f = cmd_tso_set_parsed,
4669         .data = NULL,
4670         .help_str = "tso show <port_id>: "
4671                 "Show TSO segment size of non-tunneled packets for csum engine",
4672         .tokens = {
4673                 (void *)&cmd_tso_set_tso,
4674                 (void *)&cmd_tso_show_mode,
4675                 (void *)&cmd_tso_set_portid,
4676                 NULL,
4677         },
4678 };
4679
4680 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4681 struct cmd_tunnel_tso_set_result {
4682         cmdline_fixed_string_t tso;
4683         cmdline_fixed_string_t mode;
4684         uint16_t tso_segsz;
4685         portid_t port_id;
4686 };
4687
4688 static struct rte_eth_dev_info
4689 check_tunnel_tso_nic_support(portid_t port_id)
4690 {
4691         struct rte_eth_dev_info dev_info;
4692
4693         rte_eth_dev_info_get(port_id, &dev_info);
4694         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4695                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4696                        "not enabled for port %d\n", port_id);
4697         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4698                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4699                        "not enabled for port %d\n", port_id);
4700         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4701                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4702                        "not enabled for port %d\n", port_id);
4703         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4704                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4705                        "not enabled for port %d\n", port_id);
4706         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4707                 printf("Warning: IP TUNNEL TSO not supported therefore "
4708                        "not enabled for port %d\n", port_id);
4709         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4710                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4711                        "not enabled for port %d\n", port_id);
4712         return dev_info;
4713 }
4714
4715 static void
4716 cmd_tunnel_tso_set_parsed(void *parsed_result,
4717                           __attribute__((unused)) struct cmdline *cl,
4718                           __attribute__((unused)) void *data)
4719 {
4720         struct cmd_tunnel_tso_set_result *res = parsed_result;
4721         struct rte_eth_dev_info dev_info;
4722
4723         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4724                 return;
4725         if (!port_is_stopped(res->port_id)) {
4726                 printf("Please stop port %d first\n", res->port_id);
4727                 return;
4728         }
4729
4730         if (!strcmp(res->mode, "set"))
4731                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4732
4733         dev_info = check_tunnel_tso_nic_support(res->port_id);
4734         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4735                 ports[res->port_id].dev_conf.txmode.offloads &=
4736                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4737                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4738                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4739                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4740                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4741                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4742                 printf("TSO for tunneled packets is disabled\n");
4743         } else {
4744                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4745                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4746                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4747                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4748                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4749                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4750
4751                 ports[res->port_id].dev_conf.txmode.offloads |=
4752                         (tso_offloads & dev_info.tx_offload_capa);
4753                 printf("TSO segment size for tunneled packets is %d\n",
4754                         ports[res->port_id].tunnel_tso_segsz);
4755
4756                 /* Below conditions are needed to make it work:
4757                  * (1) tunnel TSO is supported by the NIC;
4758                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4759                  * are recognized;
4760                  * (3) for tunneled pkts with outer L3 of IPv4,
4761                  * "csum set outer-ip" must be set to hw, because after tso,
4762                  * total_len of outer IP header is changed, and the checksum
4763                  * of outer IP header calculated by sw should be wrong; that
4764                  * is not necessary for IPv6 tunneled pkts because there's no
4765                  * checksum in IP header anymore.
4766                  */
4767
4768                 if (!ports[res->port_id].parse_tunnel)
4769                         printf("Warning: csum parse_tunnel must be set "
4770                                 "so that tunneled packets are recognized\n");
4771                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4772                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4773                         printf("Warning: csum set outer-ip must be set to hw "
4774                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4775         }
4776
4777         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4778         cmd_reconfig_device_queue(res->port_id, 1, 1);
4779 }
4780
4781 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4782         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4783                                 tso, "tunnel_tso");
4784 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4785         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4786                                 mode, "set");
4787 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4788         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4789                                 tso_segsz, UINT16);
4790 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4791         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4792                                 port_id, UINT16);
4793
4794 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4795         .f = cmd_tunnel_tso_set_parsed,
4796         .data = NULL,
4797         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4798                 "Set TSO segment size of tunneled packets for csum engine "
4799                 "(0 to disable)",
4800         .tokens = {
4801                 (void *)&cmd_tunnel_tso_set_tso,
4802                 (void *)&cmd_tunnel_tso_set_mode,
4803                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4804                 (void *)&cmd_tunnel_tso_set_portid,
4805                 NULL,
4806         },
4807 };
4808
4809 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4810         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4811                                 mode, "show");
4812
4813
4814 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4815         .f = cmd_tunnel_tso_set_parsed,
4816         .data = NULL,
4817         .help_str = "tunnel_tso show <port_id> "
4818                 "Show TSO segment size of tunneled packets for csum engine",
4819         .tokens = {
4820                 (void *)&cmd_tunnel_tso_set_tso,
4821                 (void *)&cmd_tunnel_tso_show_mode,
4822                 (void *)&cmd_tunnel_tso_set_portid,
4823                 NULL,
4824         },
4825 };
4826
4827 /* *** SET GRO FOR A PORT *** */
4828 struct cmd_gro_enable_result {
4829         cmdline_fixed_string_t cmd_set;
4830         cmdline_fixed_string_t cmd_port;
4831         cmdline_fixed_string_t cmd_keyword;
4832         cmdline_fixed_string_t cmd_onoff;
4833         portid_t cmd_pid;
4834 };
4835
4836 static void
4837 cmd_gro_enable_parsed(void *parsed_result,
4838                 __attribute__((unused)) struct cmdline *cl,
4839                 __attribute__((unused)) void *data)
4840 {
4841         struct cmd_gro_enable_result *res;
4842
4843         res = parsed_result;
4844         if (!strcmp(res->cmd_keyword, "gro"))
4845                 setup_gro(res->cmd_onoff, res->cmd_pid);
4846 }
4847
4848 cmdline_parse_token_string_t cmd_gro_enable_set =
4849         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4850                         cmd_set, "set");
4851 cmdline_parse_token_string_t cmd_gro_enable_port =
4852         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4853                         cmd_keyword, "port");
4854 cmdline_parse_token_num_t cmd_gro_enable_pid =
4855         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4856                         cmd_pid, UINT16);
4857 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4858         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4859                         cmd_keyword, "gro");
4860 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4861         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4862                         cmd_onoff, "on#off");
4863
4864 cmdline_parse_inst_t cmd_gro_enable = {
4865         .f = cmd_gro_enable_parsed,
4866         .data = NULL,
4867         .help_str = "set port <port_id> gro on|off",
4868         .tokens = {
4869                 (void *)&cmd_gro_enable_set,
4870                 (void *)&cmd_gro_enable_port,
4871                 (void *)&cmd_gro_enable_pid,
4872                 (void *)&cmd_gro_enable_keyword,
4873                 (void *)&cmd_gro_enable_onoff,
4874                 NULL,
4875         },
4876 };
4877
4878 /* *** DISPLAY GRO CONFIGURATION *** */
4879 struct cmd_gro_show_result {
4880         cmdline_fixed_string_t cmd_show;
4881         cmdline_fixed_string_t cmd_port;
4882         cmdline_fixed_string_t cmd_keyword;
4883         portid_t cmd_pid;
4884 };
4885
4886 static void
4887 cmd_gro_show_parsed(void *parsed_result,
4888                 __attribute__((unused)) struct cmdline *cl,
4889                 __attribute__((unused)) void *data)
4890 {
4891         struct cmd_gro_show_result *res;
4892
4893         res = parsed_result;
4894         if (!strcmp(res->cmd_keyword, "gro"))
4895                 show_gro(res->cmd_pid);
4896 }
4897
4898 cmdline_parse_token_string_t cmd_gro_show_show =
4899         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4900                         cmd_show, "show");
4901 cmdline_parse_token_string_t cmd_gro_show_port =
4902         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4903                         cmd_port, "port");
4904 cmdline_parse_token_num_t cmd_gro_show_pid =
4905         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4906                         cmd_pid, UINT16);
4907 cmdline_parse_token_string_t cmd_gro_show_keyword =
4908         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4909                         cmd_keyword, "gro");
4910
4911 cmdline_parse_inst_t cmd_gro_show = {
4912         .f = cmd_gro_show_parsed,
4913         .data = NULL,
4914         .help_str = "show port <port_id> gro",
4915         .tokens = {
4916                 (void *)&cmd_gro_show_show,
4917                 (void *)&cmd_gro_show_port,
4918                 (void *)&cmd_gro_show_pid,
4919                 (void *)&cmd_gro_show_keyword,
4920                 NULL,
4921         },
4922 };
4923
4924 /* *** SET FLUSH CYCLES FOR GRO *** */
4925 struct cmd_gro_flush_result {
4926         cmdline_fixed_string_t cmd_set;
4927         cmdline_fixed_string_t cmd_keyword;
4928         cmdline_fixed_string_t cmd_flush;
4929         uint8_t cmd_cycles;
4930 };
4931
4932 static void
4933 cmd_gro_flush_parsed(void *parsed_result,
4934                 __attribute__((unused)) struct cmdline *cl,
4935                 __attribute__((unused)) void *data)
4936 {
4937         struct cmd_gro_flush_result *res;
4938
4939         res = parsed_result;
4940         if ((!strcmp(res->cmd_keyword, "gro")) &&
4941                         (!strcmp(res->cmd_flush, "flush")))
4942                 setup_gro_flush_cycles(res->cmd_cycles);
4943 }
4944
4945 cmdline_parse_token_string_t cmd_gro_flush_set =
4946         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4947                         cmd_set, "set");
4948 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4949         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4950                         cmd_keyword, "gro");
4951 cmdline_parse_token_string_t cmd_gro_flush_flush =
4952         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4953                         cmd_flush, "flush");
4954 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4955         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4956                         cmd_cycles, UINT8);
4957
4958 cmdline_parse_inst_t cmd_gro_flush = {
4959         .f = cmd_gro_flush_parsed,
4960         .data = NULL,
4961         .help_str = "set gro flush <cycles>",
4962         .tokens = {
4963                 (void *)&cmd_gro_flush_set,
4964                 (void *)&cmd_gro_flush_keyword,
4965                 (void *)&cmd_gro_flush_flush,
4966                 (void *)&cmd_gro_flush_cycles,
4967                 NULL,
4968         },
4969 };
4970
4971 /* *** ENABLE/DISABLE GSO *** */
4972 struct cmd_gso_enable_result {
4973         cmdline_fixed_string_t cmd_set;
4974         cmdline_fixed_string_t cmd_port;
4975         cmdline_fixed_string_t cmd_keyword;
4976         cmdline_fixed_string_t cmd_mode;
4977         portid_t cmd_pid;
4978 };
4979
4980 static void
4981 cmd_gso_enable_parsed(void *parsed_result,
4982                 __attribute__((unused)) struct cmdline *cl,
4983                 __attribute__((unused)) void *data)
4984 {
4985         struct cmd_gso_enable_result *res;
4986
4987         res = parsed_result;
4988         if (!strcmp(res->cmd_keyword, "gso"))
4989                 setup_gso(res->cmd_mode, res->cmd_pid);
4990 }
4991
4992 cmdline_parse_token_string_t cmd_gso_enable_set =
4993         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4994                         cmd_set, "set");
4995 cmdline_parse_token_string_t cmd_gso_enable_port =
4996         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4997                         cmd_port, "port");
4998 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4999         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5000                         cmd_keyword, "gso");
5001 cmdline_parse_token_string_t cmd_gso_enable_mode =
5002         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5003                         cmd_mode, "on#off");
5004 cmdline_parse_token_num_t cmd_gso_enable_pid =
5005         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5006                         cmd_pid, UINT16);
5007
5008 cmdline_parse_inst_t cmd_gso_enable = {
5009         .f = cmd_gso_enable_parsed,
5010         .data = NULL,
5011         .help_str = "set port <port_id> gso on|off",
5012         .tokens = {
5013                 (void *)&cmd_gso_enable_set,
5014                 (void *)&cmd_gso_enable_port,
5015                 (void *)&cmd_gso_enable_pid,
5016                 (void *)&cmd_gso_enable_keyword,
5017                 (void *)&cmd_gso_enable_mode,
5018                 NULL,
5019         },
5020 };
5021
5022 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5023 struct cmd_gso_size_result {
5024         cmdline_fixed_string_t cmd_set;
5025         cmdline_fixed_string_t cmd_keyword;
5026         cmdline_fixed_string_t cmd_segsz;
5027         uint16_t cmd_size;
5028 };
5029
5030 static void
5031 cmd_gso_size_parsed(void *parsed_result,
5032                        __attribute__((unused)) struct cmdline *cl,
5033                        __attribute__((unused)) void *data)
5034 {
5035         struct cmd_gso_size_result *res = parsed_result;
5036
5037         if (test_done == 0) {
5038                 printf("Before setting GSO segsz, please first"
5039                                 " stop fowarding\n");
5040                 return;
5041         }
5042
5043         if (!strcmp(res->cmd_keyword, "gso") &&
5044                         !strcmp(res->cmd_segsz, "segsz")) {
5045                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5046                         printf("gso_size should be larger than %zu."
5047                                         " Please input a legal value\n",
5048                                         RTE_GSO_SEG_SIZE_MIN);
5049                 else
5050                         gso_max_segment_size = res->cmd_size;
5051         }
5052 }
5053
5054 cmdline_parse_token_string_t cmd_gso_size_set =
5055         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5056                                 cmd_set, "set");
5057 cmdline_parse_token_string_t cmd_gso_size_keyword =
5058         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5059                                 cmd_keyword, "gso");
5060 cmdline_parse_token_string_t cmd_gso_size_segsz =
5061         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5062                                 cmd_segsz, "segsz");
5063 cmdline_parse_token_num_t cmd_gso_size_size =
5064         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5065                                 cmd_size, UINT16);
5066
5067 cmdline_parse_inst_t cmd_gso_size = {
5068         .f = cmd_gso_size_parsed,
5069         .data = NULL,
5070         .help_str = "set gso segsz <length>",
5071         .tokens = {
5072                 (void *)&cmd_gso_size_set,
5073                 (void *)&cmd_gso_size_keyword,
5074                 (void *)&cmd_gso_size_segsz,
5075                 (void *)&cmd_gso_size_size,
5076                 NULL,
5077         },
5078 };
5079
5080 /* *** SHOW GSO CONFIGURATION *** */
5081 struct cmd_gso_show_result {
5082         cmdline_fixed_string_t cmd_show;
5083         cmdline_fixed_string_t cmd_port;
5084         cmdline_fixed_string_t cmd_keyword;
5085         portid_t cmd_pid;
5086 };
5087
5088 static void
5089 cmd_gso_show_parsed(void *parsed_result,
5090                        __attribute__((unused)) struct cmdline *cl,
5091                        __attribute__((unused)) void *data)
5092 {
5093         struct cmd_gso_show_result *res = parsed_result;
5094
5095         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5096                 printf("invalid port id %u\n", res->cmd_pid);
5097                 return;
5098         }
5099         if (!strcmp(res->cmd_keyword, "gso")) {
5100                 if (gso_ports[res->cmd_pid].enable) {
5101                         printf("Max GSO'd packet size: %uB\n"
5102                                         "Supported GSO types: TCP/IPv4, "
5103                                         "UDP/IPv4, VxLAN with inner "
5104                                         "TCP/IPv4 packet, GRE with inner "
5105                                         "TCP/IPv4 packet\n",
5106                                         gso_max_segment_size);
5107                 } else
5108                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5109         }
5110 }
5111
5112 cmdline_parse_token_string_t cmd_gso_show_show =
5113 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5114                 cmd_show, "show");
5115 cmdline_parse_token_string_t cmd_gso_show_port =
5116 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5117                 cmd_port, "port");
5118 cmdline_parse_token_string_t cmd_gso_show_keyword =
5119         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5120                                 cmd_keyword, "gso");
5121 cmdline_parse_token_num_t cmd_gso_show_pid =
5122         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5123                                 cmd_pid, UINT16);
5124
5125 cmdline_parse_inst_t cmd_gso_show = {
5126         .f = cmd_gso_show_parsed,
5127         .data = NULL,
5128         .help_str = "show port <port_id> gso",
5129         .tokens = {
5130                 (void *)&cmd_gso_show_show,
5131                 (void *)&cmd_gso_show_port,
5132                 (void *)&cmd_gso_show_pid,
5133                 (void *)&cmd_gso_show_keyword,
5134                 NULL,
5135         },
5136 };
5137
5138 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5139 struct cmd_set_flush_rx {
5140         cmdline_fixed_string_t set;
5141         cmdline_fixed_string_t flush_rx;
5142         cmdline_fixed_string_t mode;
5143 };
5144
5145 static void
5146 cmd_set_flush_rx_parsed(void *parsed_result,
5147                 __attribute__((unused)) struct cmdline *cl,
5148                 __attribute__((unused)) void *data)
5149 {
5150         struct cmd_set_flush_rx *res = parsed_result;
5151         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5152 }
5153
5154 cmdline_parse_token_string_t cmd_setflushrx_set =
5155         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5156                         set, "set");
5157 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5158         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5159                         flush_rx, "flush_rx");
5160 cmdline_parse_token_string_t cmd_setflushrx_mode =
5161         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5162                         mode, "on#off");
5163
5164
5165 cmdline_parse_inst_t cmd_set_flush_rx = {
5166         .f = cmd_set_flush_rx_parsed,
5167         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5168         .data = NULL,
5169         .tokens = {
5170                 (void *)&cmd_setflushrx_set,
5171                 (void *)&cmd_setflushrx_flush_rx,
5172                 (void *)&cmd_setflushrx_mode,
5173                 NULL,
5174         },
5175 };
5176
5177 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5178 struct cmd_set_link_check {
5179         cmdline_fixed_string_t set;
5180         cmdline_fixed_string_t link_check;
5181         cmdline_fixed_string_t mode;
5182 };
5183
5184 static void
5185 cmd_set_link_check_parsed(void *parsed_result,
5186                 __attribute__((unused)) struct cmdline *cl,
5187                 __attribute__((unused)) void *data)
5188 {
5189         struct cmd_set_link_check *res = parsed_result;
5190         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5191 }
5192
5193 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5194         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5195                         set, "set");
5196 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5197         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5198                         link_check, "link_check");
5199 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5200         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5201                         mode, "on#off");
5202
5203
5204 cmdline_parse_inst_t cmd_set_link_check = {
5205         .f = cmd_set_link_check_parsed,
5206         .help_str = "set link_check on|off: Enable/Disable link status check "
5207                     "when starting/stopping a port",
5208         .data = NULL,
5209         .tokens = {
5210                 (void *)&cmd_setlinkcheck_set,
5211                 (void *)&cmd_setlinkcheck_link_check,
5212                 (void *)&cmd_setlinkcheck_mode,
5213                 NULL,
5214         },
5215 };
5216
5217 /* *** SET NIC BYPASS MODE *** */
5218 struct cmd_set_bypass_mode_result {
5219         cmdline_fixed_string_t set;
5220         cmdline_fixed_string_t bypass;
5221         cmdline_fixed_string_t mode;
5222         cmdline_fixed_string_t value;
5223         portid_t port_id;
5224 };
5225
5226 static void
5227 cmd_set_bypass_mode_parsed(void *parsed_result,
5228                 __attribute__((unused)) struct cmdline *cl,
5229                 __attribute__((unused)) void *data)
5230 {
5231         struct cmd_set_bypass_mode_result *res = parsed_result;
5232         portid_t port_id = res->port_id;
5233         int32_t rc = -EINVAL;
5234
5235 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5236         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5237
5238         if (!strcmp(res->value, "bypass"))
5239                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5240         else if (!strcmp(res->value, "isolate"))
5241                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5242         else
5243                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5244
5245         /* Set the bypass mode for the relevant port. */
5246         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5247 #endif
5248         if (rc != 0)
5249                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5250 }
5251
5252 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5253         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5254                         set, "set");
5255 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5256         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5257                         bypass, "bypass");
5258 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5259         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5260                         mode, "mode");
5261 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5262         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5263                         value, "normal#bypass#isolate");
5264 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5265         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5266                                 port_id, UINT16);
5267
5268 cmdline_parse_inst_t cmd_set_bypass_mode = {
5269         .f = cmd_set_bypass_mode_parsed,
5270         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5271                     "Set the NIC bypass mode for port_id",
5272         .data = NULL,
5273         .tokens = {
5274                 (void *)&cmd_setbypass_mode_set,
5275                 (void *)&cmd_setbypass_mode_bypass,
5276                 (void *)&cmd_setbypass_mode_mode,
5277                 (void *)&cmd_setbypass_mode_value,
5278                 (void *)&cmd_setbypass_mode_port,
5279                 NULL,
5280         },
5281 };
5282
5283 /* *** SET NIC BYPASS EVENT *** */
5284 struct cmd_set_bypass_event_result {
5285         cmdline_fixed_string_t set;
5286         cmdline_fixed_string_t bypass;
5287         cmdline_fixed_string_t event;
5288         cmdline_fixed_string_t event_value;
5289         cmdline_fixed_string_t mode;
5290         cmdline_fixed_string_t mode_value;
5291         portid_t port_id;
5292 };
5293
5294 static void
5295 cmd_set_bypass_event_parsed(void *parsed_result,
5296                 __attribute__((unused)) struct cmdline *cl,
5297                 __attribute__((unused)) void *data)
5298 {
5299         int32_t rc = -EINVAL;
5300         struct cmd_set_bypass_event_result *res = parsed_result;
5301         portid_t port_id = res->port_id;
5302
5303 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5304         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5305         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5306
5307         if (!strcmp(res->event_value, "timeout"))
5308                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5309         else if (!strcmp(res->event_value, "os_on"))
5310                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5311         else if (!strcmp(res->event_value, "os_off"))
5312                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5313         else if (!strcmp(res->event_value, "power_on"))
5314                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5315         else if (!strcmp(res->event_value, "power_off"))
5316                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5317         else
5318                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5319
5320         if (!strcmp(res->mode_value, "bypass"))
5321                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5322         else if (!strcmp(res->mode_value, "isolate"))
5323                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5324         else
5325                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5326
5327         /* Set the watchdog timeout. */
5328         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5329
5330                 rc = -EINVAL;
5331                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5332                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5333                                                            bypass_timeout);
5334                 }
5335                 if (rc != 0) {
5336                         printf("Failed to set timeout value %u "
5337                         "for port %d, errto code: %d.\n",
5338                         bypass_timeout, port_id, rc);
5339                 }
5340         }
5341
5342         /* Set the bypass event to transition to bypass mode. */
5343         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5344                                               bypass_mode);
5345 #endif
5346
5347         if (rc != 0)
5348                 printf("\t Failed to set bypass event for port = %d.\n",
5349                        port_id);
5350 }
5351
5352 cmdline_parse_token_string_t cmd_setbypass_event_set =
5353         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5354                         set, "set");
5355 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5356         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5357                         bypass, "bypass");
5358 cmdline_parse_token_string_t cmd_setbypass_event_event =
5359         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5360                         event, "event");
5361 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5362         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5363                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5364 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5365         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5366                         mode, "mode");
5367 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5368         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5369                         mode_value, "normal#bypass#isolate");
5370 cmdline_parse_token_num_t cmd_setbypass_event_port =
5371         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5372                                 port_id, UINT16);
5373
5374 cmdline_parse_inst_t cmd_set_bypass_event = {
5375         .f = cmd_set_bypass_event_parsed,
5376         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5377                 "power_off mode normal|bypass|isolate <port_id>: "
5378                 "Set the NIC bypass event mode for port_id",
5379         .data = NULL,
5380         .tokens = {
5381                 (void *)&cmd_setbypass_event_set,
5382                 (void *)&cmd_setbypass_event_bypass,
5383                 (void *)&cmd_setbypass_event_event,
5384                 (void *)&cmd_setbypass_event_event_value,
5385                 (void *)&cmd_setbypass_event_mode,
5386                 (void *)&cmd_setbypass_event_mode_value,
5387                 (void *)&cmd_setbypass_event_port,
5388                 NULL,
5389         },
5390 };
5391
5392
5393 /* *** SET NIC BYPASS TIMEOUT *** */
5394 struct cmd_set_bypass_timeout_result {
5395         cmdline_fixed_string_t set;
5396         cmdline_fixed_string_t bypass;
5397         cmdline_fixed_string_t timeout;
5398         cmdline_fixed_string_t value;
5399 };
5400
5401 static void
5402 cmd_set_bypass_timeout_parsed(void *parsed_result,
5403                 __attribute__((unused)) struct cmdline *cl,
5404                 __attribute__((unused)) void *data)
5405 {
5406         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5407
5408 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5409         if (!strcmp(res->value, "1.5"))
5410                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5411         else if (!strcmp(res->value, "2"))
5412                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5413         else if (!strcmp(res->value, "3"))
5414                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5415         else if (!strcmp(res->value, "4"))
5416                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5417         else if (!strcmp(res->value, "8"))
5418                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5419         else if (!strcmp(res->value, "16"))
5420                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5421         else if (!strcmp(res->value, "32"))
5422                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5423         else
5424                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5425 #endif
5426 }
5427
5428 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5429         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5430                         set, "set");
5431 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5432         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5433                         bypass, "bypass");
5434 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5435         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5436                         timeout, "timeout");
5437 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5438         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5439                         value, "0#1.5#2#3#4#8#16#32");
5440
5441 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5442         .f = cmd_set_bypass_timeout_parsed,
5443         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5444                 "Set the NIC bypass watchdog timeout in seconds",
5445         .data = NULL,
5446         .tokens = {
5447                 (void *)&cmd_setbypass_timeout_set,
5448                 (void *)&cmd_setbypass_timeout_bypass,
5449                 (void *)&cmd_setbypass_timeout_timeout,
5450                 (void *)&cmd_setbypass_timeout_value,
5451                 NULL,
5452         },
5453 };
5454
5455 /* *** SHOW NIC BYPASS MODE *** */
5456 struct cmd_show_bypass_config_result {
5457         cmdline_fixed_string_t show;
5458         cmdline_fixed_string_t bypass;
5459         cmdline_fixed_string_t config;
5460         portid_t port_id;
5461 };
5462
5463 static void
5464 cmd_show_bypass_config_parsed(void *parsed_result,
5465                 __attribute__((unused)) struct cmdline *cl,
5466                 __attribute__((unused)) void *data)
5467 {
5468         struct cmd_show_bypass_config_result *res = parsed_result;
5469         portid_t port_id = res->port_id;
5470         int rc = -EINVAL;
5471 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5472         uint32_t event_mode;
5473         uint32_t bypass_mode;
5474         uint32_t timeout = bypass_timeout;
5475         int i;
5476
5477         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5478                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5479         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5480                 {"UNKNOWN", "normal", "bypass", "isolate"};
5481         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5482                 "NONE",
5483                 "OS/board on",
5484                 "power supply on",
5485                 "OS/board off",
5486                 "power supply off",
5487                 "timeout"};
5488         int num_events = (sizeof events) / (sizeof events[0]);
5489
5490         /* Display the bypass mode.*/
5491         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5492                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5493                 return;
5494         }
5495         else {
5496                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5497                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5498
5499                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5500         }
5501
5502         /* Display the bypass timeout.*/
5503         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5504                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5505
5506         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5507
5508         /* Display the bypass events and associated modes. */
5509         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5510
5511                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5512                         printf("\tFailed to get bypass mode for event = %s\n",
5513                                 events[i]);
5514                 } else {
5515                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5516                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5517
5518                         printf("\tbypass event: %-16s = %s\n", events[i],
5519                                 modes[event_mode]);
5520                 }
5521         }
5522 #endif
5523         if (rc != 0)
5524                 printf("\tFailed to get bypass configuration for port = %d\n",
5525                        port_id);
5526 }
5527
5528 cmdline_parse_token_string_t cmd_showbypass_config_show =
5529         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5530                         show, "show");
5531 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5532         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5533                         bypass, "bypass");
5534 cmdline_parse_token_string_t cmd_showbypass_config_config =
5535         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5536                         config, "config");
5537 cmdline_parse_token_num_t cmd_showbypass_config_port =
5538         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5539                                 port_id, UINT16);
5540
5541 cmdline_parse_inst_t cmd_show_bypass_config = {
5542         .f = cmd_show_bypass_config_parsed,
5543         .help_str = "show bypass config <port_id>: "
5544                     "Show the NIC bypass config for port_id",
5545         .data = NULL,
5546         .tokens = {
5547                 (void *)&cmd_showbypass_config_show,
5548                 (void *)&cmd_showbypass_config_bypass,
5549                 (void *)&cmd_showbypass_config_config,
5550                 (void *)&cmd_showbypass_config_port,
5551                 NULL,
5552         },
5553 };
5554
5555 #ifdef RTE_LIBRTE_PMD_BOND
5556 /* *** SET BONDING MODE *** */
5557 struct cmd_set_bonding_mode_result {
5558         cmdline_fixed_string_t set;
5559         cmdline_fixed_string_t bonding;
5560         cmdline_fixed_string_t mode;
5561         uint8_t value;
5562         portid_t port_id;
5563 };
5564
5565 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5566                 __attribute__((unused))  struct cmdline *cl,
5567                 __attribute__((unused)) void *data)
5568 {
5569         struct cmd_set_bonding_mode_result *res = parsed_result;
5570         portid_t port_id = res->port_id;
5571
5572         /* Set the bonding mode for the relevant port. */
5573         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5574                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5575 }
5576
5577 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5578 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5579                 set, "set");
5580 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5581 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5582                 bonding, "bonding");
5583 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5584 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5585                 mode, "mode");
5586 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5587 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5588                 value, UINT8);
5589 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5590 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5591                 port_id, UINT16);
5592
5593 cmdline_parse_inst_t cmd_set_bonding_mode = {
5594                 .f = cmd_set_bonding_mode_parsed,
5595                 .help_str = "set bonding mode <mode_value> <port_id>: "
5596                         "Set the bonding mode for port_id",
5597                 .data = NULL,
5598                 .tokens = {
5599                                 (void *) &cmd_setbonding_mode_set,
5600                                 (void *) &cmd_setbonding_mode_bonding,
5601                                 (void *) &cmd_setbonding_mode_mode,
5602                                 (void *) &cmd_setbonding_mode_value,
5603                                 (void *) &cmd_setbonding_mode_port,
5604                                 NULL
5605                 }
5606 };
5607
5608 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5609 struct cmd_set_bonding_lacp_dedicated_queues_result {
5610         cmdline_fixed_string_t set;
5611         cmdline_fixed_string_t bonding;
5612         cmdline_fixed_string_t lacp;
5613         cmdline_fixed_string_t dedicated_queues;
5614         portid_t port_id;
5615         cmdline_fixed_string_t mode;
5616 };
5617
5618 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5619                 __attribute__((unused))  struct cmdline *cl,
5620                 __attribute__((unused)) void *data)
5621 {
5622         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5623         portid_t port_id = res->port_id;
5624         struct rte_port *port;
5625
5626         port = &ports[port_id];
5627
5628         /** Check if the port is not started **/
5629         if (port->port_status != RTE_PORT_STOPPED) {
5630                 printf("Please stop port %d first\n", port_id);
5631                 return;
5632         }
5633
5634         if (!strcmp(res->mode, "enable")) {
5635                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5636                         printf("Dedicate queues for LACP control packets"
5637                                         " enabled\n");
5638                 else
5639                         printf("Enabling dedicate queues for LACP control "
5640                                         "packets on port %d failed\n", port_id);
5641         } else if (!strcmp(res->mode, "disable")) {
5642                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5643                         printf("Dedicated queues for LACP control packets "
5644                                         "disabled\n");
5645                 else
5646                         printf("Disabling dedicated queues for LACP control "
5647                                         "traffic on port %d failed\n", port_id);
5648         }
5649 }
5650
5651 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5652 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5653                 set, "set");
5654 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5655 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5656                 bonding, "bonding");
5657 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5658 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5659                 lacp, "lacp");
5660 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5661 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5662                 dedicated_queues, "dedicated_queues");
5663 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5664 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5665                 port_id, UINT16);
5666 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5667 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5668                 mode, "enable#disable");
5669
5670 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5671                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5672                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5673                         "enable|disable: "
5674                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5675                 .data = NULL,
5676                 .tokens = {
5677                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5678                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5679                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5680                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5681                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5682                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5683                         NULL
5684                 }
5685 };
5686
5687 /* *** SET BALANCE XMIT POLICY *** */
5688 struct cmd_set_bonding_balance_xmit_policy_result {
5689         cmdline_fixed_string_t set;
5690         cmdline_fixed_string_t bonding;
5691         cmdline_fixed_string_t balance_xmit_policy;
5692         portid_t port_id;
5693         cmdline_fixed_string_t policy;
5694 };
5695
5696 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5697                 __attribute__((unused))  struct cmdline *cl,
5698                 __attribute__((unused)) void *data)
5699 {
5700         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5701         portid_t port_id = res->port_id;
5702         uint8_t policy;
5703
5704         if (!strcmp(res->policy, "l2")) {
5705                 policy = BALANCE_XMIT_POLICY_LAYER2;
5706         } else if (!strcmp(res->policy, "l23")) {
5707                 policy = BALANCE_XMIT_POLICY_LAYER23;
5708         } else if (!strcmp(res->policy, "l34")) {
5709                 policy = BALANCE_XMIT_POLICY_LAYER34;
5710         } else {
5711                 printf("\t Invalid xmit policy selection");
5712                 return;
5713         }
5714
5715         /* Set the bonding mode for the relevant port. */
5716         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5717                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5718                                 port_id);
5719         }
5720 }
5721
5722 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5723 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5724                 set, "set");
5725 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5726 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5727                 bonding, "bonding");
5728 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5729 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5730                 balance_xmit_policy, "balance_xmit_policy");
5731 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5732 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5733                 port_id, UINT16);
5734 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5735 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5736                 policy, "l2#l23#l34");
5737
5738 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5739                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5740                 .help_str = "set bonding balance_xmit_policy <port_id> "
5741                         "l2|l23|l34: "
5742                         "Set the bonding balance_xmit_policy for port_id",
5743                 .data = NULL,
5744                 .tokens = {
5745                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5746                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5747                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5748                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5749                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5750                                 NULL
5751                 }
5752 };
5753
5754 /* *** SHOW NIC BONDING CONFIGURATION *** */
5755 struct cmd_show_bonding_config_result {
5756         cmdline_fixed_string_t show;
5757         cmdline_fixed_string_t bonding;
5758         cmdline_fixed_string_t config;
5759         portid_t port_id;
5760 };
5761
5762 static void cmd_show_bonding_config_parsed(void *parsed_result,
5763                 __attribute__((unused))  struct cmdline *cl,
5764                 __attribute__((unused)) void *data)
5765 {
5766         struct cmd_show_bonding_config_result *res = parsed_result;
5767         int bonding_mode, agg_mode;
5768         portid_t slaves[RTE_MAX_ETHPORTS];
5769         int num_slaves, num_active_slaves;
5770         int primary_id;
5771         int i;
5772         portid_t port_id = res->port_id;
5773
5774         /* Display the bonding mode.*/
5775         bonding_mode = rte_eth_bond_mode_get(port_id);
5776         if (bonding_mode < 0) {
5777                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5778                 return;
5779         } else
5780                 printf("\tBonding mode: %d\n", bonding_mode);
5781
5782         if (bonding_mode == BONDING_MODE_BALANCE) {
5783                 int balance_xmit_policy;
5784
5785                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5786                 if (balance_xmit_policy < 0) {
5787                         printf("\tFailed to get balance xmit policy for port = %d\n",
5788                                         port_id);
5789                         return;
5790                 } else {
5791                         printf("\tBalance Xmit Policy: ");
5792
5793                         switch (balance_xmit_policy) {
5794                         case BALANCE_XMIT_POLICY_LAYER2:
5795                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5796                                 break;
5797                         case BALANCE_XMIT_POLICY_LAYER23:
5798                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5799                                 break;
5800                         case BALANCE_XMIT_POLICY_LAYER34:
5801                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5802                                 break;
5803                         }
5804                         printf("\n");
5805                 }
5806         }
5807
5808         if (bonding_mode == BONDING_MODE_8023AD) {
5809                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5810                 printf("\tIEEE802.3AD Aggregator Mode: ");
5811                 switch (agg_mode) {
5812                 case AGG_BANDWIDTH:
5813                         printf("bandwidth");
5814                         break;
5815                 case AGG_STABLE:
5816                         printf("stable");
5817                         break;
5818                 case AGG_COUNT:
5819                         printf("count");
5820                         break;
5821                 }
5822                 printf("\n");
5823         }
5824
5825         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5826
5827         if (num_slaves < 0) {
5828                 printf("\tFailed to get slave list for port = %d\n", port_id);
5829                 return;
5830         }
5831         if (num_slaves > 0) {
5832                 printf("\tSlaves (%d): [", num_slaves);
5833                 for (i = 0; i < num_slaves - 1; i++)
5834                         printf("%d ", slaves[i]);
5835
5836                 printf("%d]\n", slaves[num_slaves - 1]);
5837         } else {
5838                 printf("\tSlaves: []\n");
5839
5840         }
5841
5842         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5843                         RTE_MAX_ETHPORTS);
5844
5845         if (num_active_slaves < 0) {
5846                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5847                 return;
5848         }
5849         if (num_active_slaves > 0) {
5850                 printf("\tActive Slaves (%d): [", num_active_slaves);
5851                 for (i = 0; i < num_active_slaves - 1; i++)
5852                         printf("%d ", slaves[i]);
5853
5854                 printf("%d]\n", slaves[num_active_slaves - 1]);
5855
5856         } else {
5857                 printf("\tActive Slaves: []\n");
5858
5859         }
5860
5861         primary_id = rte_eth_bond_primary_get(port_id);
5862         if (primary_id < 0) {
5863                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5864                 return;
5865         } else
5866                 printf("\tPrimary: [%d]\n", primary_id);
5867
5868 }
5869
5870 cmdline_parse_token_string_t cmd_showbonding_config_show =
5871 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5872                 show, "show");
5873 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5874 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5875                 bonding, "bonding");
5876 cmdline_parse_token_string_t cmd_showbonding_config_config =
5877 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5878                 config, "config");
5879 cmdline_parse_token_num_t cmd_showbonding_config_port =
5880 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5881                 port_id, UINT16);
5882
5883 cmdline_parse_inst_t cmd_show_bonding_config = {
5884                 .f = cmd_show_bonding_config_parsed,
5885                 .help_str = "show bonding config <port_id>: "
5886                         "Show the bonding config for port_id",
5887                 .data = NULL,
5888                 .tokens = {
5889                                 (void *)&cmd_showbonding_config_show,
5890                                 (void *)&cmd_showbonding_config_bonding,
5891                                 (void *)&cmd_showbonding_config_config,
5892                                 (void *)&cmd_showbonding_config_port,
5893                                 NULL
5894                 }
5895 };
5896
5897 /* *** SET BONDING PRIMARY *** */
5898 struct cmd_set_bonding_primary_result {
5899         cmdline_fixed_string_t set;
5900         cmdline_fixed_string_t bonding;
5901         cmdline_fixed_string_t primary;
5902         portid_t slave_id;
5903         portid_t port_id;
5904 };
5905
5906 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5907                 __attribute__((unused))  struct cmdline *cl,
5908                 __attribute__((unused)) void *data)
5909 {
5910         struct cmd_set_bonding_primary_result *res = parsed_result;
5911         portid_t master_port_id = res->port_id;
5912         portid_t slave_port_id = res->slave_id;
5913
5914         /* Set the primary slave for a bonded device. */
5915         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5916                 printf("\t Failed to set primary slave for port = %d.\n",
5917                                 master_port_id);
5918                 return;
5919         }
5920         init_port_config();
5921 }
5922
5923 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5924 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5925                 set, "set");
5926 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5928                 bonding, "bonding");
5929 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5930 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5931                 primary, "primary");
5932 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5933 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5934                 slave_id, UINT16);
5935 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5936 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5937                 port_id, UINT16);
5938
5939 cmdline_parse_inst_t cmd_set_bonding_primary = {
5940                 .f = cmd_set_bonding_primary_parsed,
5941                 .help_str = "set bonding primary <slave_id> <port_id>: "
5942                         "Set the primary slave for port_id",
5943                 .data = NULL,
5944                 .tokens = {
5945                                 (void *)&cmd_setbonding_primary_set,
5946                                 (void *)&cmd_setbonding_primary_bonding,
5947                                 (void *)&cmd_setbonding_primary_primary,
5948                                 (void *)&cmd_setbonding_primary_slave,
5949                                 (void *)&cmd_setbonding_primary_port,
5950                                 NULL
5951                 }
5952 };
5953
5954 /* *** ADD SLAVE *** */
5955 struct cmd_add_bonding_slave_result {
5956         cmdline_fixed_string_t add;
5957         cmdline_fixed_string_t bonding;
5958         cmdline_fixed_string_t slave;
5959         portid_t slave_id;
5960         portid_t port_id;
5961 };
5962
5963 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5964                 __attribute__((unused))  struct cmdline *cl,
5965                 __attribute__((unused)) void *data)
5966 {
5967         struct cmd_add_bonding_slave_result *res = parsed_result;
5968         portid_t master_port_id = res->port_id;
5969         portid_t slave_port_id = res->slave_id;
5970
5971         /* add the slave for a bonded device. */
5972         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5973                 printf("\t Failed to add slave %d to master port = %d.\n",
5974                                 slave_port_id, master_port_id);
5975                 return;
5976         }
5977         init_port_config();
5978         set_port_slave_flag(slave_port_id);
5979 }
5980
5981 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5982 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5983                 add, "add");
5984 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5985 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5986                 bonding, "bonding");
5987 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5988 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5989                 slave, "slave");
5990 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5991 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5992                 slave_id, UINT16);
5993 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5994 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5995                 port_id, UINT16);
5996
5997 cmdline_parse_inst_t cmd_add_bonding_slave = {
5998                 .f = cmd_add_bonding_slave_parsed,
5999                 .help_str = "add bonding slave <slave_id> <port_id>: "
6000                         "Add a slave device to a bonded device",
6001                 .data = NULL,
6002                 .tokens = {
6003                                 (void *)&cmd_addbonding_slave_add,
6004                                 (void *)&cmd_addbonding_slave_bonding,
6005                                 (void *)&cmd_addbonding_slave_slave,
6006                                 (void *)&cmd_addbonding_slave_slaveid,
6007                                 (void *)&cmd_addbonding_slave_port,
6008                                 NULL
6009                 }
6010 };
6011
6012 /* *** REMOVE SLAVE *** */
6013 struct cmd_remove_bonding_slave_result {
6014         cmdline_fixed_string_t remove;
6015         cmdline_fixed_string_t bonding;
6016         cmdline_fixed_string_t slave;
6017         portid_t slave_id;
6018         portid_t port_id;
6019 };
6020
6021 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6022                 __attribute__((unused))  struct cmdline *cl,
6023                 __attribute__((unused)) void *data)
6024 {
6025         struct cmd_remove_bonding_slave_result *res = parsed_result;
6026         portid_t master_port_id = res->port_id;
6027         portid_t slave_port_id = res->slave_id;
6028
6029         /* remove the slave from a bonded device. */
6030         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6031                 printf("\t Failed to remove slave %d from master port = %d.\n",
6032                                 slave_port_id, master_port_id);
6033                 return;
6034         }
6035         init_port_config();
6036         clear_port_slave_flag(slave_port_id);
6037 }
6038
6039 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6040                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6041                                 remove, "remove");
6042 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6043                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6044                                 bonding, "bonding");
6045 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6046                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6047                                 slave, "slave");
6048 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6049                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6050                                 slave_id, UINT16);
6051 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6052                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6053                                 port_id, UINT16);
6054
6055 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6056                 .f = cmd_remove_bonding_slave_parsed,
6057                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6058                         "Remove a slave device from a bonded device",
6059                 .data = NULL,
6060                 .tokens = {
6061                                 (void *)&cmd_removebonding_slave_remove,
6062                                 (void *)&cmd_removebonding_slave_bonding,
6063                                 (void *)&cmd_removebonding_slave_slave,
6064                                 (void *)&cmd_removebonding_slave_slaveid,
6065                                 (void *)&cmd_removebonding_slave_port,
6066                                 NULL
6067                 }
6068 };
6069
6070 /* *** CREATE BONDED DEVICE *** */
6071 struct cmd_create_bonded_device_result {
6072         cmdline_fixed_string_t create;
6073         cmdline_fixed_string_t bonded;
6074         cmdline_fixed_string_t device;
6075         uint8_t mode;
6076         uint8_t socket;
6077 };
6078
6079 static int bond_dev_num = 0;
6080
6081 static void cmd_create_bonded_device_parsed(void *parsed_result,
6082                 __attribute__((unused))  struct cmdline *cl,
6083                 __attribute__((unused)) void *data)
6084 {
6085         struct cmd_create_bonded_device_result *res = parsed_result;
6086         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6087         int port_id;
6088
6089         if (test_done == 0) {
6090                 printf("Please stop forwarding first\n");
6091                 return;
6092         }
6093
6094         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6095                         bond_dev_num++);
6096
6097         /* Create a new bonded device. */
6098         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6099         if (port_id < 0) {
6100                 printf("\t Failed to create bonded device.\n");
6101                 return;
6102         } else {
6103                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6104                                 port_id);
6105
6106                 /* Update number of ports */
6107                 nb_ports = rte_eth_dev_count_avail();
6108                 reconfig(port_id, res->socket);
6109                 rte_eth_promiscuous_enable(port_id);
6110                 ports[port_id].need_setup = 0;
6111                 ports[port_id].port_status = RTE_PORT_STOPPED;
6112         }
6113
6114 }
6115
6116 cmdline_parse_token_string_t cmd_createbonded_device_create =
6117                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6118                                 create, "create");
6119 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6120                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6121                                 bonded, "bonded");
6122 cmdline_parse_token_string_t cmd_createbonded_device_device =
6123                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6124                                 device, "device");
6125 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6126                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6127                                 mode, UINT8);
6128 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6129                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6130                                 socket, UINT8);
6131
6132 cmdline_parse_inst_t cmd_create_bonded_device = {
6133                 .f = cmd_create_bonded_device_parsed,
6134                 .help_str = "create bonded device <mode> <socket>: "
6135                         "Create a new bonded device with specific bonding mode and socket",
6136                 .data = NULL,
6137                 .tokens = {
6138                                 (void *)&cmd_createbonded_device_create,
6139                                 (void *)&cmd_createbonded_device_bonded,
6140                                 (void *)&cmd_createbonded_device_device,
6141                                 (void *)&cmd_createbonded_device_mode,
6142                                 (void *)&cmd_createbonded_device_socket,
6143                                 NULL
6144                 }
6145 };
6146
6147 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6148 struct cmd_set_bond_mac_addr_result {
6149         cmdline_fixed_string_t set;
6150         cmdline_fixed_string_t bonding;
6151         cmdline_fixed_string_t mac_addr;
6152         uint16_t port_num;
6153         struct rte_ether_addr address;
6154 };
6155
6156 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6157                 __attribute__((unused))  struct cmdline *cl,
6158                 __attribute__((unused)) void *data)
6159 {
6160         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6161         int ret;
6162
6163         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6164                 return;
6165
6166         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6167
6168         /* check the return value and print it if is < 0 */
6169         if (ret < 0)
6170                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6171 }
6172
6173 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6174                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6175 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6176                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6177                                 "bonding");
6178 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6179                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6180                                 "mac_addr");
6181 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6182                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6183                                 port_num, UINT16);
6184 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6185                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6186
6187 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6188                 .f = cmd_set_bond_mac_addr_parsed,
6189                 .data = (void *) 0,
6190                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6191                 .tokens = {
6192                                 (void *)&cmd_set_bond_mac_addr_set,
6193                                 (void *)&cmd_set_bond_mac_addr_bonding,
6194                                 (void *)&cmd_set_bond_mac_addr_mac,
6195                                 (void *)&cmd_set_bond_mac_addr_portnum,
6196                                 (void *)&cmd_set_bond_mac_addr_addr,
6197                                 NULL
6198                 }
6199 };
6200
6201
6202 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6203 struct cmd_set_bond_mon_period_result {
6204         cmdline_fixed_string_t set;
6205         cmdline_fixed_string_t bonding;
6206         cmdline_fixed_string_t mon_period;
6207         uint16_t port_num;
6208         uint32_t period_ms;
6209 };
6210
6211 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6212                 __attribute__((unused))  struct cmdline *cl,
6213                 __attribute__((unused)) void *data)
6214 {
6215         struct cmd_set_bond_mon_period_result *res = parsed_result;
6216         int ret;
6217
6218         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6219
6220         /* check the return value and print it if is < 0 */
6221         if (ret < 0)
6222                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6223 }
6224
6225 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6226                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6227                                 set, "set");
6228 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6229                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6230                                 bonding, "bonding");
6231 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6232                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6233                                 mon_period,     "mon_period");
6234 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6235                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6236                                 port_num, UINT16);
6237 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6238                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6239                                 period_ms, UINT32);
6240
6241 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6242                 .f = cmd_set_bond_mon_period_parsed,
6243                 .data = (void *) 0,
6244                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6245                 .tokens = {
6246                                 (void *)&cmd_set_bond_mon_period_set,
6247                                 (void *)&cmd_set_bond_mon_period_bonding,
6248                                 (void *)&cmd_set_bond_mon_period_mon_period,
6249                                 (void *)&cmd_set_bond_mon_period_portnum,
6250                                 (void *)&cmd_set_bond_mon_period_period_ms,
6251                                 NULL
6252                 }
6253 };
6254
6255
6256
6257 struct cmd_set_bonding_agg_mode_policy_result {
6258         cmdline_fixed_string_t set;
6259         cmdline_fixed_string_t bonding;
6260         cmdline_fixed_string_t agg_mode;
6261         uint16_t port_num;
6262         cmdline_fixed_string_t policy;
6263 };
6264
6265
6266 static void
6267 cmd_set_bonding_agg_mode(void *parsed_result,
6268                 __attribute__((unused)) struct cmdline *cl,
6269                 __attribute__((unused)) void *data)
6270 {
6271         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6272         uint8_t policy = AGG_BANDWIDTH;
6273
6274         if (!strcmp(res->policy, "bandwidth"))
6275                 policy = AGG_BANDWIDTH;
6276         else if (!strcmp(res->policy, "stable"))
6277                 policy = AGG_STABLE;
6278         else if (!strcmp(res->policy, "count"))
6279                 policy = AGG_COUNT;
6280
6281         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6282 }
6283
6284
6285 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6286         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6287                                 set, "set");
6288 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6289         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6290                                 bonding, "bonding");
6291
6292 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6293         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6294                                 agg_mode, "agg_mode");
6295
6296 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6297         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6298                                 port_num, UINT16);
6299
6300 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6301         TOKEN_STRING_INITIALIZER(
6302                         struct cmd_set_bonding_balance_xmit_policy_result,
6303                 policy, "stable#bandwidth#count");
6304
6305 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6306         .f = cmd_set_bonding_agg_mode,
6307         .data = (void *) 0,
6308         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6309         .tokens = {
6310                         (void *)&cmd_set_bonding_agg_mode_set,
6311                         (void *)&cmd_set_bonding_agg_mode_bonding,
6312                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6313                         (void *)&cmd_set_bonding_agg_mode_portnum,
6314                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6315                         NULL
6316                 }
6317 };
6318
6319
6320 #endif /* RTE_LIBRTE_PMD_BOND */
6321
6322 /* *** SET FORWARDING MODE *** */
6323 struct cmd_set_fwd_mode_result {
6324         cmdline_fixed_string_t set;
6325         cmdline_fixed_string_t fwd;
6326         cmdline_fixed_string_t mode;
6327 };
6328
6329 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6330                                     __attribute__((unused)) struct cmdline *cl,
6331                                     __attribute__((unused)) void *data)
6332 {
6333         struct cmd_set_fwd_mode_result *res = parsed_result;
6334
6335         retry_enabled = 0;
6336         set_pkt_forwarding_mode(res->mode);
6337 }
6338
6339 cmdline_parse_token_string_t cmd_setfwd_set =
6340         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6341 cmdline_parse_token_string_t cmd_setfwd_fwd =
6342         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6343 cmdline_parse_token_string_t cmd_setfwd_mode =
6344         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6345                 "" /* defined at init */);
6346
6347 cmdline_parse_inst_t cmd_set_fwd_mode = {
6348         .f = cmd_set_fwd_mode_parsed,
6349         .data = NULL,
6350         .help_str = NULL, /* defined at init */
6351         .tokens = {
6352                 (void *)&cmd_setfwd_set,
6353                 (void *)&cmd_setfwd_fwd,
6354                 (void *)&cmd_setfwd_mode,
6355                 NULL,
6356         },
6357 };
6358
6359 static void cmd_set_fwd_mode_init(void)
6360 {
6361         char *modes, *c;
6362         static char token[128];
6363         static char help[256];
6364         cmdline_parse_token_string_t *token_struct;
6365
6366         modes = list_pkt_forwarding_modes();
6367         snprintf(help, sizeof(help), "set fwd %s: "
6368                 "Set packet forwarding mode", modes);
6369         cmd_set_fwd_mode.help_str = help;
6370
6371         /* string token separator is # */
6372         for (c = token; *modes != '\0'; modes++)
6373                 if (*modes == '|')
6374                         *c++ = '#';
6375                 else
6376                         *c++ = *modes;
6377         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6378         token_struct->string_data.str = token;
6379 }
6380
6381 /* *** SET RETRY FORWARDING MODE *** */
6382 struct cmd_set_fwd_retry_mode_result {
6383         cmdline_fixed_string_t set;
6384         cmdline_fixed_string_t fwd;
6385         cmdline_fixed_string_t mode;
6386         cmdline_fixed_string_t retry;
6387 };
6388
6389 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6390                             __attribute__((unused)) struct cmdline *cl,
6391                             __attribute__((unused)) void *data)
6392 {
6393         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6394
6395         retry_enabled = 1;
6396         set_pkt_forwarding_mode(res->mode);
6397 }
6398
6399 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6400         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6401                         set, "set");
6402 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6403         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6404                         fwd, "fwd");
6405 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6406         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6407                         mode,
6408                 "" /* defined at init */);
6409 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6410         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6411                         retry, "retry");
6412
6413 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6414         .f = cmd_set_fwd_retry_mode_parsed,
6415         .data = NULL,
6416         .help_str = NULL, /* defined at init */
6417         .tokens = {
6418                 (void *)&cmd_setfwd_retry_set,
6419                 (void *)&cmd_setfwd_retry_fwd,
6420                 (void *)&cmd_setfwd_retry_mode,
6421                 (void *)&cmd_setfwd_retry_retry,
6422                 NULL,
6423         },
6424 };
6425
6426 static void cmd_set_fwd_retry_mode_init(void)
6427 {
6428         char *modes, *c;
6429         static char token[128];
6430         static char help[256];
6431         cmdline_parse_token_string_t *token_struct;
6432
6433         modes = list_pkt_forwarding_retry_modes();
6434         snprintf(help, sizeof(help), "set fwd %s retry: "
6435                 "Set packet forwarding mode with retry", modes);
6436         cmd_set_fwd_retry_mode.help_str = help;
6437
6438         /* string token separator is # */
6439         for (c = token; *modes != '\0'; modes++)
6440                 if (*modes == '|')
6441                         *c++ = '#';
6442                 else
6443                         *c++ = *modes;
6444         token_struct = (cmdline_parse_token_string_t *)
6445                 cmd_set_fwd_retry_mode.tokens[2];
6446         token_struct->string_data.str = token;
6447 }
6448
6449 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6450 struct cmd_set_burst_tx_retry_result {
6451         cmdline_fixed_string_t set;
6452         cmdline_fixed_string_t burst;
6453         cmdline_fixed_string_t tx;
6454         cmdline_fixed_string_t delay;
6455         uint32_t time;
6456         cmdline_fixed_string_t retry;
6457         uint32_t retry_num;
6458 };
6459
6460 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6461                                         __attribute__((unused)) struct cmdline *cl,
6462                                         __attribute__((unused)) void *data)
6463 {
6464         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6465
6466         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6467                 && !strcmp(res->tx, "tx")) {
6468                 if (!strcmp(res->delay, "delay"))
6469                         burst_tx_delay_time = res->time;
6470                 if (!strcmp(res->retry, "retry"))
6471                         burst_tx_retry_num = res->retry_num;
6472         }
6473
6474 }
6475
6476 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6477         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6478 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6479         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6480                                  "burst");
6481 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6482         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6483 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6484         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6485 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6486         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6487 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6488         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6489 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6490         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6491
6492 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6493         .f = cmd_set_burst_tx_retry_parsed,
6494         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6495         .tokens = {
6496                 (void *)&cmd_set_burst_tx_retry_set,
6497                 (void *)&cmd_set_burst_tx_retry_burst,
6498                 (void *)&cmd_set_burst_tx_retry_tx,
6499                 (void *)&cmd_set_burst_tx_retry_delay,
6500                 (void *)&cmd_set_burst_tx_retry_time,
6501                 (void *)&cmd_set_burst_tx_retry_retry,
6502                 (void *)&cmd_set_burst_tx_retry_retry_num,
6503                 NULL,
6504         },
6505 };
6506
6507 /* *** SET PROMISC MODE *** */
6508 struct cmd_set_promisc_mode_result {
6509         cmdline_fixed_string_t set;
6510         cmdline_fixed_string_t promisc;
6511         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6512         uint16_t port_num;               /* valid if "allports" argument == 0 */
6513         cmdline_fixed_string_t mode;
6514 };
6515
6516 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6517                                         __attribute__((unused)) struct cmdline *cl,
6518                                         void *allports)
6519 {
6520         struct cmd_set_promisc_mode_result *res = parsed_result;
6521         int enable;
6522         portid_t i;
6523
6524         if (!strcmp(res->mode, "on"))
6525                 enable = 1;
6526         else
6527                 enable = 0;
6528
6529         /* all ports */
6530         if (allports) {
6531                 RTE_ETH_FOREACH_DEV(i) {
6532                         if (enable)
6533                                 rte_eth_promiscuous_enable(i);
6534                         else
6535                                 rte_eth_promiscuous_disable(i);
6536                 }
6537         }
6538         else {
6539                 if (enable)
6540                         rte_eth_promiscuous_enable(res->port_num);
6541                 else
6542                         rte_eth_promiscuous_disable(res->port_num);
6543         }
6544 }
6545
6546 cmdline_parse_token_string_t cmd_setpromisc_set =
6547         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6548 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6549         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6550                                  "promisc");
6551 cmdline_parse_token_string_t cmd_setpromisc_portall =
6552         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6553                                  "all");
6554 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6555         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6556                               UINT16);
6557 cmdline_parse_token_string_t cmd_setpromisc_mode =
6558         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6559                                  "on#off");
6560
6561 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6562         .f = cmd_set_promisc_mode_parsed,
6563         .data = (void *)1,
6564         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6565         .tokens = {
6566                 (void *)&cmd_setpromisc_set,
6567                 (void *)&cmd_setpromisc_promisc,
6568                 (void *)&cmd_setpromisc_portall,
6569                 (void *)&cmd_setpromisc_mode,
6570                 NULL,
6571         },
6572 };
6573
6574 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6575         .f = cmd_set_promisc_mode_parsed,
6576         .data = (void *)0,
6577         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6578         .tokens = {
6579                 (void *)&cmd_setpromisc_set,
6580                 (void *)&cmd_setpromisc_promisc,
6581                 (void *)&cmd_setpromisc_portnum,
6582                 (void *)&cmd_setpromisc_mode,
6583                 NULL,
6584         },
6585 };
6586
6587 /* *** SET ALLMULTI MODE *** */
6588 struct cmd_set_allmulti_mode_result {
6589         cmdline_fixed_string_t set;
6590         cmdline_fixed_string_t allmulti;
6591         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6592         uint16_t port_num;               /* valid if "allports" argument == 0 */
6593         cmdline_fixed_string_t mode;
6594 };
6595
6596 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6597                                         __attribute__((unused)) struct cmdline *cl,
6598                                         void *allports)
6599 {
6600         struct cmd_set_allmulti_mode_result *res = parsed_result;
6601         int enable;
6602         portid_t i;
6603
6604         if (!strcmp(res->mode, "on"))
6605                 enable = 1;
6606         else
6607                 enable = 0;
6608
6609         /* all ports */
6610         if (allports) {
6611                 RTE_ETH_FOREACH_DEV(i) {
6612                         if (enable)
6613                                 rte_eth_allmulticast_enable(i);
6614                         else
6615                                 rte_eth_allmulticast_disable(i);
6616                 }
6617         }
6618         else {
6619                 if (enable)
6620                         rte_eth_allmulticast_enable(res->port_num);
6621                 else
6622                         rte_eth_allmulticast_disable(res->port_num);
6623         }
6624 }
6625
6626 cmdline_parse_token_string_t cmd_setallmulti_set =
6627         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6628 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6629         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6630                                  "allmulti");
6631 cmdline_parse_token_string_t cmd_setallmulti_portall =
6632         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6633                                  "all");
6634 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6635         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6636                               UINT16);
6637 cmdline_parse_token_string_t cmd_setallmulti_mode =
6638         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6639                                  "on#off");
6640
6641 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6642         .f = cmd_set_allmulti_mode_parsed,
6643         .data = (void *)1,
6644         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6645         .tokens = {
6646                 (void *)&cmd_setallmulti_set,
6647                 (void *)&cmd_setallmulti_allmulti,
6648                 (void *)&cmd_setallmulti_portall,
6649                 (void *)&cmd_setallmulti_mode,
6650                 NULL,
6651         },
6652 };
6653
6654 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6655         .f = cmd_set_allmulti_mode_parsed,
6656         .data = (void *)0,
6657         .help_str = "set allmulti <port_id> on|off: "
6658                 "Set allmulti mode on port_id",
6659         .tokens = {
6660                 (void *)&cmd_setallmulti_set,
6661                 (void *)&cmd_setallmulti_allmulti,
6662                 (void *)&cmd_setallmulti_portnum,
6663                 (void *)&cmd_setallmulti_mode,
6664                 NULL,
6665         },
6666 };
6667
6668 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6669 struct cmd_link_flow_ctrl_set_result {
6670         cmdline_fixed_string_t set;
6671         cmdline_fixed_string_t flow_ctrl;
6672         cmdline_fixed_string_t rx;
6673         cmdline_fixed_string_t rx_lfc_mode;
6674         cmdline_fixed_string_t tx;
6675         cmdline_fixed_string_t tx_lfc_mode;
6676         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6677         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6678         cmdline_fixed_string_t autoneg_str;
6679         cmdline_fixed_string_t autoneg;
6680         cmdline_fixed_string_t hw_str;
6681         uint32_t high_water;
6682         cmdline_fixed_string_t lw_str;
6683         uint32_t low_water;
6684         cmdline_fixed_string_t pt_str;
6685         uint16_t pause_time;
6686         cmdline_fixed_string_t xon_str;
6687         uint16_t send_xon;
6688         portid_t port_id;
6689 };
6690
6691 cmdline_parse_token_string_t cmd_lfc_set_set =
6692         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6693                                 set, "set");
6694 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6695         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6696                                 flow_ctrl, "flow_ctrl");
6697 cmdline_parse_token_string_t cmd_lfc_set_rx =
6698         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6699                                 rx, "rx");
6700 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6701         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6702                                 rx_lfc_mode, "on#off");
6703 cmdline_parse_token_string_t cmd_lfc_set_tx =
6704         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6705                                 tx, "tx");
6706 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6707         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6708                                 tx_lfc_mode, "on#off");
6709 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6710         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6711                                 hw_str, "high_water");
6712 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6713         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6714                                 high_water, UINT32);
6715 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6716         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6717                                 lw_str, "low_water");
6718 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6719         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6720                                 low_water, UINT32);
6721 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6722         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6723                                 pt_str, "pause_time");
6724 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6725         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6726                                 pause_time, UINT16);
6727 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6728         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6729                                 xon_str, "send_xon");
6730 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6731         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6732                                 send_xon, UINT16);
6733 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6734         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6735                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6736 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6737         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6738                                 mac_ctrl_frame_fwd_mode, "on#off");
6739 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6740         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6741                                 autoneg_str, "autoneg");
6742 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6743         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6744                                 autoneg, "on#off");
6745 cmdline_parse_token_num_t cmd_lfc_set_portid =
6746         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6747                                 port_id, UINT16);
6748
6749 /* forward declaration */
6750 static void
6751 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6752                               void *data);
6753
6754 cmdline_parse_inst_t cmd_link_flow_control_set = {
6755         .f = cmd_link_flow_ctrl_set_parsed,
6756         .data = NULL,
6757         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6758                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6759                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6760         .tokens = {
6761                 (void *)&cmd_lfc_set_set,
6762                 (void *)&cmd_lfc_set_flow_ctrl,
6763                 (void *)&cmd_lfc_set_rx,
6764                 (void *)&cmd_lfc_set_rx_mode,
6765                 (void *)&cmd_lfc_set_tx,
6766                 (void *)&cmd_lfc_set_tx_mode,
6767                 (void *)&cmd_lfc_set_high_water,
6768                 (void *)&cmd_lfc_set_low_water,
6769                 (void *)&cmd_lfc_set_pause_time,
6770                 (void *)&cmd_lfc_set_send_xon,
6771                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6772                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6773                 (void *)&cmd_lfc_set_autoneg_str,
6774                 (void *)&cmd_lfc_set_autoneg,
6775                 (void *)&cmd_lfc_set_portid,
6776                 NULL,
6777         },
6778 };
6779
6780 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6781         .f = cmd_link_flow_ctrl_set_parsed,
6782         .data = (void *)&cmd_link_flow_control_set_rx,
6783         .help_str = "set flow_ctrl rx on|off <port_id>: "
6784                 "Change rx flow control parameter",
6785         .tokens = {
6786                 (void *)&cmd_lfc_set_set,
6787                 (void *)&cmd_lfc_set_flow_ctrl,
6788                 (void *)&cmd_lfc_set_rx,
6789                 (void *)&cmd_lfc_set_rx_mode,
6790                 (void *)&cmd_lfc_set_portid,
6791                 NULL,
6792         },
6793 };
6794
6795 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6796         .f = cmd_link_flow_ctrl_set_parsed,
6797         .data = (void *)&cmd_link_flow_control_set_tx,
6798         .help_str = "set flow_ctrl tx on|off <port_id>: "
6799                 "Change tx flow control parameter",
6800         .tokens = {
6801                 (void *)&cmd_lfc_set_set,
6802                 (void *)&cmd_lfc_set_flow_ctrl,
6803                 (void *)&cmd_lfc_set_tx,
6804                 (void *)&cmd_lfc_set_tx_mode,
6805                 (void *)&cmd_lfc_set_portid,
6806                 NULL,
6807         },
6808 };
6809
6810 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6811         .f = cmd_link_flow_ctrl_set_parsed,
6812         .data = (void *)&cmd_link_flow_control_set_hw,
6813         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6814                 "Change high water flow control parameter",
6815         .tokens = {
6816                 (void *)&cmd_lfc_set_set,
6817                 (void *)&cmd_lfc_set_flow_ctrl,
6818                 (void *)&cmd_lfc_set_high_water_str,
6819                 (void *)&cmd_lfc_set_high_water,
6820                 (void *)&cmd_lfc_set_portid,
6821                 NULL,
6822         },
6823 };
6824
6825 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6826         .f = cmd_link_flow_ctrl_set_parsed,
6827         .data = (void *)&cmd_link_flow_control_set_lw,
6828         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6829                 "Change low water flow control parameter",
6830         .tokens = {
6831                 (void *)&cmd_lfc_set_set,
6832                 (void *)&cmd_lfc_set_flow_ctrl,
6833                 (void *)&cmd_lfc_set_low_water_str,
6834                 (void *)&cmd_lfc_set_low_water,
6835                 (void *)&cmd_lfc_set_portid,
6836                 NULL,
6837         },
6838 };
6839
6840 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6841         .f = cmd_link_flow_ctrl_set_parsed,
6842         .data = (void *)&cmd_link_flow_control_set_pt,
6843         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6844                 "Change pause time flow control parameter",
6845         .tokens = {
6846                 (void *)&cmd_lfc_set_set,
6847                 (void *)&cmd_lfc_set_flow_ctrl,
6848                 (void *)&cmd_lfc_set_pause_time_str,
6849                 (void *)&cmd_lfc_set_pause_time,
6850                 (void *)&cmd_lfc_set_portid,
6851                 NULL,
6852         },
6853 };
6854
6855 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6856         .f = cmd_link_flow_ctrl_set_parsed,
6857         .data = (void *)&cmd_link_flow_control_set_xon,
6858         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6859                 "Change send_xon flow control parameter",
6860         .tokens = {
6861                 (void *)&cmd_lfc_set_set,
6862                 (void *)&cmd_lfc_set_flow_ctrl,
6863                 (void *)&cmd_lfc_set_send_xon_str,
6864                 (void *)&cmd_lfc_set_send_xon,
6865                 (void *)&cmd_lfc_set_portid,
6866                 NULL,
6867         },
6868 };
6869
6870 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6871         .f = cmd_link_flow_ctrl_set_parsed,
6872         .data = (void *)&cmd_link_flow_control_set_macfwd,
6873         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6874                 "Change mac ctrl fwd flow control parameter",
6875         .tokens = {
6876                 (void *)&cmd_lfc_set_set,
6877                 (void *)&cmd_lfc_set_flow_ctrl,
6878                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6879                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6880                 (void *)&cmd_lfc_set_portid,
6881                 NULL,
6882         },
6883 };
6884
6885 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6886         .f = cmd_link_flow_ctrl_set_parsed,
6887         .data = (void *)&cmd_link_flow_control_set_autoneg,
6888         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6889                 "Change autoneg flow control parameter",
6890         .tokens = {
6891                 (void *)&cmd_lfc_set_set,
6892                 (void *)&cmd_lfc_set_flow_ctrl,
6893                 (void *)&cmd_lfc_set_autoneg_str,
6894                 (void *)&cmd_lfc_set_autoneg,
6895                 (void *)&cmd_lfc_set_portid,
6896                 NULL,
6897         },
6898 };
6899
6900 static void
6901 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6902                               __attribute__((unused)) struct cmdline *cl,
6903                               void *data)
6904 {
6905         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6906         cmdline_parse_inst_t *cmd = data;
6907         struct rte_eth_fc_conf fc_conf;
6908         int rx_fc_en = 0;
6909         int tx_fc_en = 0;
6910         int ret;
6911
6912         /*
6913          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6914          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6915          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6916          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6917          */
6918         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6919                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6920         };
6921
6922         /* Partial command line, retrieve current configuration */
6923         if (cmd) {
6924                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6925                 if (ret != 0) {
6926                         printf("cannot get current flow ctrl parameters, return"
6927                                "code = %d\n", ret);
6928                         return;
6929                 }
6930
6931                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6932                     (fc_conf.mode == RTE_FC_FULL))
6933                         rx_fc_en = 1;
6934                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6935                     (fc_conf.mode == RTE_FC_FULL))
6936                         tx_fc_en = 1;
6937         }
6938
6939         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6940                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6941
6942         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6943                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6944
6945         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6946
6947         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6948                 fc_conf.high_water = res->high_water;
6949
6950         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6951                 fc_conf.low_water = res->low_water;
6952
6953         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6954                 fc_conf.pause_time = res->pause_time;
6955
6956         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6957                 fc_conf.send_xon = res->send_xon;
6958
6959         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6960                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6961                         fc_conf.mac_ctrl_frame_fwd = 1;
6962                 else
6963                         fc_conf.mac_ctrl_frame_fwd = 0;
6964         }
6965
6966         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6967                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6968
6969         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6970         if (ret != 0)
6971                 printf("bad flow contrl parameter, return code = %d \n", ret);
6972 }
6973
6974 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6975 struct cmd_priority_flow_ctrl_set_result {
6976         cmdline_fixed_string_t set;
6977         cmdline_fixed_string_t pfc_ctrl;
6978         cmdline_fixed_string_t rx;
6979         cmdline_fixed_string_t rx_pfc_mode;
6980         cmdline_fixed_string_t tx;
6981         cmdline_fixed_string_t tx_pfc_mode;
6982         uint32_t high_water;
6983         uint32_t low_water;
6984         uint16_t pause_time;
6985         uint8_t  priority;
6986         portid_t port_id;
6987 };
6988
6989 static void
6990 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6991                        __attribute__((unused)) struct cmdline *cl,
6992                        __attribute__((unused)) void *data)
6993 {
6994         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6995         struct rte_eth_pfc_conf pfc_conf;
6996         int rx_fc_enable, tx_fc_enable;
6997         int ret;
6998
6999         /*
7000          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7001          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7002          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7003          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7004          */
7005         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7006                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
7007         };
7008
7009         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7010         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7011         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7012         pfc_conf.fc.high_water = res->high_water;
7013         pfc_conf.fc.low_water  = res->low_water;
7014         pfc_conf.fc.pause_time = res->pause_time;
7015         pfc_conf.priority      = res->priority;
7016
7017         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7018         if (ret != 0)
7019                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7020 }
7021
7022 cmdline_parse_token_string_t cmd_pfc_set_set =
7023         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7024                                 set, "set");
7025 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7026         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7027                                 pfc_ctrl, "pfc_ctrl");
7028 cmdline_parse_token_string_t cmd_pfc_set_rx =
7029         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7030                                 rx, "rx");
7031 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7032         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7033                                 rx_pfc_mode, "on#off");
7034 cmdline_parse_token_string_t cmd_pfc_set_tx =
7035         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7036                                 tx, "tx");
7037 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7038         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7039                                 tx_pfc_mode, "on#off");
7040 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7041         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7042                                 high_water, UINT32);
7043 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7044         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7045                                 low_water, UINT32);
7046 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7047         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7048                                 pause_time, UINT16);
7049 cmdline_parse_token_num_t cmd_pfc_set_priority =
7050         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7051                                 priority, UINT8);
7052 cmdline_parse_token_num_t cmd_pfc_set_portid =
7053         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7054                                 port_id, UINT16);
7055
7056 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7057         .f = cmd_priority_flow_ctrl_set_parsed,
7058         .data = NULL,
7059         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7060                 "<pause_time> <priority> <port_id>: "
7061                 "Configure the Ethernet priority flow control",
7062         .tokens = {
7063                 (void *)&cmd_pfc_set_set,
7064                 (void *)&cmd_pfc_set_flow_ctrl,
7065                 (void *)&cmd_pfc_set_rx,
7066                 (void *)&cmd_pfc_set_rx_mode,
7067                 (void *)&cmd_pfc_set_tx,
7068                 (void *)&cmd_pfc_set_tx_mode,
7069                 (void *)&cmd_pfc_set_high_water,
7070                 (void *)&cmd_pfc_set_low_water,
7071                 (void *)&cmd_pfc_set_pause_time,
7072                 (void *)&cmd_pfc_set_priority,
7073                 (void *)&cmd_pfc_set_portid,
7074                 NULL,
7075         },
7076 };
7077
7078 /* *** RESET CONFIGURATION *** */
7079 struct cmd_reset_result {
7080         cmdline_fixed_string_t reset;
7081         cmdline_fixed_string_t def;
7082 };
7083
7084 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7085                              struct cmdline *cl,
7086                              __attribute__((unused)) void *data)
7087 {
7088         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7089         set_def_fwd_config();
7090 }
7091
7092 cmdline_parse_token_string_t cmd_reset_set =
7093         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7094 cmdline_parse_token_string_t cmd_reset_def =
7095         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7096                                  "default");
7097
7098 cmdline_parse_inst_t cmd_reset = {
7099         .f = cmd_reset_parsed,
7100         .data = NULL,
7101         .help_str = "set default: Reset default forwarding configuration",
7102         .tokens = {
7103                 (void *)&cmd_reset_set,
7104                 (void *)&cmd_reset_def,
7105                 NULL,
7106         },
7107 };
7108
7109 /* *** START FORWARDING *** */
7110 struct cmd_start_result {
7111         cmdline_fixed_string_t start;
7112 };
7113
7114 cmdline_parse_token_string_t cmd_start_start =
7115         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7116
7117 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7118                              __attribute__((unused)) struct cmdline *cl,
7119                              __attribute__((unused)) void *data)
7120 {
7121         start_packet_forwarding(0);
7122 }
7123
7124 cmdline_parse_inst_t cmd_start = {
7125         .f = cmd_start_parsed,
7126         .data = NULL,
7127         .help_str = "start: Start packet forwarding",
7128         .tokens = {
7129                 (void *)&cmd_start_start,
7130                 NULL,
7131         },
7132 };
7133
7134 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7135 struct cmd_start_tx_first_result {
7136         cmdline_fixed_string_t start;
7137         cmdline_fixed_string_t tx_first;
7138 };
7139
7140 static void
7141 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7142                           __attribute__((unused)) struct cmdline *cl,
7143                           __attribute__((unused)) void *data)
7144 {
7145         start_packet_forwarding(1);
7146 }
7147
7148 cmdline_parse_token_string_t cmd_start_tx_first_start =
7149         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7150                                  "start");
7151 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7152         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7153                                  tx_first, "tx_first");
7154
7155 cmdline_parse_inst_t cmd_start_tx_first = {
7156         .f = cmd_start_tx_first_parsed,
7157         .data = NULL,
7158         .help_str = "start tx_first: Start packet forwarding, "
7159                 "after sending 1 burst of packets",
7160         .tokens = {
7161                 (void *)&cmd_start_tx_first_start,
7162                 (void *)&cmd_start_tx_first_tx_first,
7163                 NULL,
7164         },
7165 };
7166
7167 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7168 struct cmd_start_tx_first_n_result {
7169         cmdline_fixed_string_t start;
7170         cmdline_fixed_string_t tx_first;
7171         uint32_t tx_num;
7172 };
7173
7174 static void
7175 cmd_start_tx_first_n_parsed(void *parsed_result,
7176                           __attribute__((unused)) struct cmdline *cl,
7177                           __attribute__((unused)) void *data)
7178 {
7179         struct cmd_start_tx_first_n_result *res = parsed_result;
7180
7181         start_packet_forwarding(res->tx_num);
7182 }
7183
7184 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7185         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7186                         start, "start");
7187 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7188         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7189                         tx_first, "tx_first");
7190 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7191         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7192                         tx_num, UINT32);
7193
7194 cmdline_parse_inst_t cmd_start_tx_first_n = {
7195         .f = cmd_start_tx_first_n_parsed,
7196         .data = NULL,
7197         .help_str = "start tx_first <num>: "
7198                 "packet forwarding, after sending <num> bursts of packets",
7199         .tokens = {
7200                 (void *)&cmd_start_tx_first_n_start,
7201                 (void *)&cmd_start_tx_first_n_tx_first,
7202                 (void *)&cmd_start_tx_first_n_tx_num,
7203                 NULL,
7204         },
7205 };
7206
7207 /* *** SET LINK UP *** */
7208 struct cmd_set_link_up_result {
7209         cmdline_fixed_string_t set;
7210         cmdline_fixed_string_t link_up;
7211         cmdline_fixed_string_t port;
7212         portid_t port_id;
7213 };
7214
7215 cmdline_parse_token_string_t cmd_set_link_up_set =
7216         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7217 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7218         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7219                                 "link-up");
7220 cmdline_parse_token_string_t cmd_set_link_up_port =
7221         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7222 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7223         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7224
7225 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7226                              __attribute__((unused)) struct cmdline *cl,
7227                              __attribute__((unused)) void *data)
7228 {
7229         struct cmd_set_link_up_result *res = parsed_result;
7230         dev_set_link_up(res->port_id);
7231 }
7232
7233 cmdline_parse_inst_t cmd_set_link_up = {
7234         .f = cmd_set_link_up_parsed,
7235         .data = NULL,
7236         .help_str = "set link-up port <port id>",
7237         .tokens = {
7238                 (void *)&cmd_set_link_up_set,
7239                 (void *)&cmd_set_link_up_link_up,
7240                 (void *)&cmd_set_link_up_port,
7241                 (void *)&cmd_set_link_up_port_id,
7242                 NULL,
7243         },
7244 };
7245
7246 /* *** SET LINK DOWN *** */
7247 struct cmd_set_link_down_result {
7248         cmdline_fixed_string_t set;
7249         cmdline_fixed_string_t link_down;
7250         cmdline_fixed_string_t port;
7251         portid_t port_id;
7252 };
7253
7254 cmdline_parse_token_string_t cmd_set_link_down_set =
7255         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7256 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7257         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7258                                 "link-down");
7259 cmdline_parse_token_string_t cmd_set_link_down_port =
7260         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7261 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7262         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7263
7264 static void cmd_set_link_down_parsed(
7265                                 __attribute__((unused)) void *parsed_result,
7266                                 __attribute__((unused)) struct cmdline *cl,
7267                                 __attribute__((unused)) void *data)
7268 {
7269         struct cmd_set_link_down_result *res = parsed_result;
7270         dev_set_link_down(res->port_id);
7271 }
7272
7273 cmdline_parse_inst_t cmd_set_link_down = {
7274         .f = cmd_set_link_down_parsed,
7275         .data = NULL,
7276         .help_str = "set link-down port <port id>",
7277         .tokens = {
7278                 (void *)&cmd_set_link_down_set,
7279                 (void *)&cmd_set_link_down_link_down,
7280                 (void *)&cmd_set_link_down_port,
7281                 (void *)&cmd_set_link_down_port_id,
7282                 NULL,
7283         },
7284 };
7285
7286 /* *** SHOW CFG *** */
7287 struct cmd_showcfg_result {
7288         cmdline_fixed_string_t show;
7289         cmdline_fixed_string_t cfg;
7290         cmdline_fixed_string_t what;
7291 };
7292
7293 static void cmd_showcfg_parsed(void *parsed_result,
7294                                __attribute__((unused)) struct cmdline *cl,
7295                                __attribute__((unused)) void *data)
7296 {
7297         struct cmd_showcfg_result *res = parsed_result;
7298         if (!strcmp(res->what, "rxtx"))
7299                 rxtx_config_display();
7300         else if (!strcmp(res->what, "cores"))
7301                 fwd_lcores_config_display();
7302         else if (!strcmp(res->what, "fwd"))
7303                 pkt_fwd_config_display(&cur_fwd_config);
7304         else if (!strcmp(res->what, "txpkts"))
7305                 show_tx_pkt_segments();
7306 }
7307
7308 cmdline_parse_token_string_t cmd_showcfg_show =
7309         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7310 cmdline_parse_token_string_t cmd_showcfg_port =
7311         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7312 cmdline_parse_token_string_t cmd_showcfg_what =
7313         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7314                                  "rxtx#cores#fwd#txpkts");
7315
7316 cmdline_parse_inst_t cmd_showcfg = {
7317         .f = cmd_showcfg_parsed,
7318         .data = NULL,
7319         .help_str = "show config rxtx|cores|fwd|txpkts",
7320         .tokens = {
7321                 (void *)&cmd_showcfg_show,
7322                 (void *)&cmd_showcfg_port,
7323                 (void *)&cmd_showcfg_what,
7324                 NULL,
7325         },
7326 };
7327
7328 /* *** SHOW ALL PORT INFO *** */
7329 struct cmd_showportall_result {
7330         cmdline_fixed_string_t show;
7331         cmdline_fixed_string_t port;
7332         cmdline_fixed_string_t what;
7333         cmdline_fixed_string_t all;
7334 };
7335
7336 static void cmd_showportall_parsed(void *parsed_result,
7337                                 __attribute__((unused)) struct cmdline *cl,
7338                                 __attribute__((unused)) void *data)
7339 {
7340         portid_t i;
7341
7342         struct cmd_showportall_result *res = parsed_result;
7343         if (!strcmp(res->show, "clear")) {
7344                 if (!strcmp(res->what, "stats"))
7345                         RTE_ETH_FOREACH_DEV(i)
7346                                 nic_stats_clear(i);
7347                 else if (!strcmp(res->what, "xstats"))
7348                         RTE_ETH_FOREACH_DEV(i)
7349                                 nic_xstats_clear(i);
7350         } else if (!strcmp(res->what, "info"))
7351                 RTE_ETH_FOREACH_DEV(i)
7352                         port_infos_display(i);
7353         else if (!strcmp(res->what, "summary")) {
7354                 port_summary_header_display();
7355                 RTE_ETH_FOREACH_DEV(i)
7356                         port_summary_display(i);
7357         }
7358         else if (!strcmp(res->what, "stats"))
7359                 RTE_ETH_FOREACH_DEV(i)
7360                         nic_stats_display(i);
7361         else if (!strcmp(res->what, "xstats"))
7362                 RTE_ETH_FOREACH_DEV(i)
7363                         nic_xstats_display(i);
7364         else if (!strcmp(res->what, "fdir"))
7365                 RTE_ETH_FOREACH_DEV(i)
7366                         fdir_get_infos(i);
7367         else if (!strcmp(res->what, "stat_qmap"))
7368                 RTE_ETH_FOREACH_DEV(i)
7369                         nic_stats_mapping_display(i);
7370         else if (!strcmp(res->what, "dcb_tc"))
7371                 RTE_ETH_FOREACH_DEV(i)
7372                         port_dcb_info_display(i);
7373         else if (!strcmp(res->what, "cap"))
7374                 RTE_ETH_FOREACH_DEV(i)
7375                         port_offload_cap_display(i);
7376 }
7377
7378 cmdline_parse_token_string_t cmd_showportall_show =
7379         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7380                                  "show#clear");
7381 cmdline_parse_token_string_t cmd_showportall_port =
7382         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7383 cmdline_parse_token_string_t cmd_showportall_what =
7384         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7385                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7386 cmdline_parse_token_string_t cmd_showportall_all =
7387         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7388 cmdline_parse_inst_t cmd_showportall = {
7389         .f = cmd_showportall_parsed,
7390         .data = NULL,
7391         .help_str = "show|clear port "
7392                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7393         .tokens = {
7394                 (void *)&cmd_showportall_show,
7395                 (void *)&cmd_showportall_port,
7396                 (void *)&cmd_showportall_what,
7397                 (void *)&cmd_showportall_all,
7398                 NULL,
7399         },
7400 };
7401
7402 /* *** SHOW PORT INFO *** */
7403 struct cmd_showport_result {
7404         cmdline_fixed_string_t show;
7405         cmdline_fixed_string_t port;
7406         cmdline_fixed_string_t what;
7407         uint16_t portnum;
7408 };
7409
7410 static void cmd_showport_parsed(void *parsed_result,
7411                                 __attribute__((unused)) struct cmdline *cl,
7412                                 __attribute__((unused)) void *data)
7413 {
7414         struct cmd_showport_result *res = parsed_result;
7415         if (!strcmp(res->show, "clear")) {
7416                 if (!strcmp(res->what, "stats"))
7417                         nic_stats_clear(res->portnum);
7418                 else if (!strcmp(res->what, "xstats"))
7419                         nic_xstats_clear(res->portnum);
7420         } else if (!strcmp(res->what, "info"))
7421                 port_infos_display(res->portnum);
7422         else if (!strcmp(res->what, "summary")) {
7423                 port_summary_header_display();
7424                 port_summary_display(res->portnum);
7425         }
7426         else if (!strcmp(res->what, "stats"))
7427                 nic_stats_display(res->portnum);
7428         else if (!strcmp(res->what, "xstats"))
7429                 nic_xstats_display(res->portnum);
7430         else if (!strcmp(res->what, "fdir"))
7431                  fdir_get_infos(res->portnum);
7432         else if (!strcmp(res->what, "stat_qmap"))
7433                 nic_stats_mapping_display(res->portnum);
7434         else if (!strcmp(res->what, "dcb_tc"))
7435                 port_dcb_info_display(res->portnum);
7436         else if (!strcmp(res->what, "cap"))
7437                 port_offload_cap_display(res->portnum);
7438 }
7439
7440 cmdline_parse_token_string_t cmd_showport_show =
7441         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7442                                  "show#clear");
7443 cmdline_parse_token_string_t cmd_showport_port =
7444         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7445 cmdline_parse_token_string_t cmd_showport_what =
7446         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7447                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7448 cmdline_parse_token_num_t cmd_showport_portnum =
7449         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7450
7451 cmdline_parse_inst_t cmd_showport = {
7452         .f = cmd_showport_parsed,
7453         .data = NULL,
7454         .help_str = "show|clear port "
7455                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7456                 "<port_id>",
7457         .tokens = {
7458                 (void *)&cmd_showport_show,
7459                 (void *)&cmd_showport_port,
7460                 (void *)&cmd_showport_what,
7461                 (void *)&cmd_showport_portnum,
7462                 NULL,
7463         },
7464 };
7465
7466 /* *** SHOW QUEUE INFO *** */
7467 struct cmd_showqueue_result {
7468         cmdline_fixed_string_t show;
7469         cmdline_fixed_string_t type;
7470         cmdline_fixed_string_t what;
7471         uint16_t portnum;
7472         uint16_t queuenum;
7473 };
7474
7475 static void
7476 cmd_showqueue_parsed(void *parsed_result,
7477         __attribute__((unused)) struct cmdline *cl,
7478         __attribute__((unused)) void *data)
7479 {
7480         struct cmd_showqueue_result *res = parsed_result;
7481
7482         if (!strcmp(res->type, "rxq"))
7483                 rx_queue_infos_display(res->portnum, res->queuenum);
7484         else if (!strcmp(res->type, "txq"))
7485                 tx_queue_infos_display(res->portnum, res->queuenum);
7486 }
7487
7488 cmdline_parse_token_string_t cmd_showqueue_show =
7489         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7490 cmdline_parse_token_string_t cmd_showqueue_type =
7491         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7492 cmdline_parse_token_string_t cmd_showqueue_what =
7493         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7494 cmdline_parse_token_num_t cmd_showqueue_portnum =
7495         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7496 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7497         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7498
7499 cmdline_parse_inst_t cmd_showqueue = {
7500         .f = cmd_showqueue_parsed,
7501         .data = NULL,
7502         .help_str = "show rxq|txq info <port_id> <queue_id>",
7503         .tokens = {
7504                 (void *)&cmd_showqueue_show,
7505                 (void *)&cmd_showqueue_type,
7506                 (void *)&cmd_showqueue_what,
7507                 (void *)&cmd_showqueue_portnum,
7508                 (void *)&cmd_showqueue_queuenum,
7509                 NULL,
7510         },
7511 };
7512
7513 /* show/clear fwd engine statistics */
7514 struct fwd_result {
7515         cmdline_fixed_string_t action;
7516         cmdline_fixed_string_t fwd;
7517         cmdline_fixed_string_t stats;
7518         cmdline_fixed_string_t all;
7519 };
7520
7521 cmdline_parse_token_string_t cmd_fwd_action =
7522         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7523 cmdline_parse_token_string_t cmd_fwd_fwd =
7524         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7525 cmdline_parse_token_string_t cmd_fwd_stats =
7526         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7527 cmdline_parse_token_string_t cmd_fwd_all =
7528         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7529
7530 static void
7531 cmd_showfwdall_parsed(void *parsed_result,
7532                       __rte_unused struct cmdline *cl,
7533                       __rte_unused void *data)
7534 {
7535         struct fwd_result *res = parsed_result;
7536
7537         if (!strcmp(res->action, "show"))
7538                 fwd_stats_display();
7539         else
7540                 fwd_stats_reset();
7541 }
7542
7543 static cmdline_parse_inst_t cmd_showfwdall = {
7544         .f = cmd_showfwdall_parsed,
7545         .data = NULL,
7546         .help_str = "show|clear fwd stats all",
7547         .tokens = {
7548                 (void *)&cmd_fwd_action,
7549                 (void *)&cmd_fwd_fwd,
7550                 (void *)&cmd_fwd_stats,
7551                 (void *)&cmd_fwd_all,
7552                 NULL,
7553         },
7554 };
7555
7556 /* *** READ PORT REGISTER *** */
7557 struct cmd_read_reg_result {
7558         cmdline_fixed_string_t read;
7559         cmdline_fixed_string_t reg;
7560         portid_t port_id;
7561         uint32_t reg_off;
7562 };
7563
7564 static void
7565 cmd_read_reg_parsed(void *parsed_result,
7566                     __attribute__((unused)) struct cmdline *cl,
7567                     __attribute__((unused)) void *data)
7568 {
7569         struct cmd_read_reg_result *res = parsed_result;
7570         port_reg_display(res->port_id, res->reg_off);
7571 }
7572
7573 cmdline_parse_token_string_t cmd_read_reg_read =
7574         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7575 cmdline_parse_token_string_t cmd_read_reg_reg =
7576         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7577 cmdline_parse_token_num_t cmd_read_reg_port_id =
7578         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7579 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7580         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7581
7582 cmdline_parse_inst_t cmd_read_reg = {
7583         .f = cmd_read_reg_parsed,
7584         .data = NULL,
7585         .help_str = "read reg <port_id> <reg_off>",
7586         .tokens = {
7587                 (void *)&cmd_read_reg_read,
7588                 (void *)&cmd_read_reg_reg,
7589                 (void *)&cmd_read_reg_port_id,
7590                 (void *)&cmd_read_reg_reg_off,
7591                 NULL,
7592         },
7593 };
7594
7595 /* *** READ PORT REGISTER BIT FIELD *** */
7596 struct cmd_read_reg_bit_field_result {
7597         cmdline_fixed_string_t read;
7598         cmdline_fixed_string_t regfield;
7599         portid_t port_id;
7600         uint32_t reg_off;
7601         uint8_t bit1_pos;
7602         uint8_t bit2_pos;
7603 };
7604
7605 static void
7606 cmd_read_reg_bit_field_parsed(void *parsed_result,
7607                               __attribute__((unused)) struct cmdline *cl,
7608                               __attribute__((unused)) void *data)
7609 {
7610         struct cmd_read_reg_bit_field_result *res = parsed_result;
7611         port_reg_bit_field_display(res->port_id, res->reg_off,
7612                                    res->bit1_pos, res->bit2_pos);
7613 }
7614
7615 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7616         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7617                                  "read");
7618 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7619         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7620                                  regfield, "regfield");
7621 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7622         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7623                               UINT16);
7624 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7625         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7626                               UINT32);
7627 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7628         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7629                               UINT8);
7630 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7631         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7632                               UINT8);
7633
7634 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7635         .f = cmd_read_reg_bit_field_parsed,
7636         .data = NULL,
7637         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7638         "Read register bit field between bit_x and bit_y included",
7639         .tokens = {
7640                 (void *)&cmd_read_reg_bit_field_read,
7641                 (void *)&cmd_read_reg_bit_field_regfield,
7642                 (void *)&cmd_read_reg_bit_field_port_id,
7643                 (void *)&cmd_read_reg_bit_field_reg_off,
7644                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7645                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7646                 NULL,
7647         },
7648 };
7649
7650 /* *** READ PORT REGISTER BIT *** */
7651 struct cmd_read_reg_bit_result {
7652         cmdline_fixed_string_t read;
7653         cmdline_fixed_string_t regbit;
7654         portid_t port_id;
7655         uint32_t reg_off;
7656         uint8_t bit_pos;
7657 };
7658
7659 static void
7660 cmd_read_reg_bit_parsed(void *parsed_result,
7661                         __attribute__((unused)) struct cmdline *cl,
7662                         __attribute__((unused)) void *data)
7663 {
7664         struct cmd_read_reg_bit_result *res = parsed_result;
7665         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7666 }
7667
7668 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7669         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7670 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7671         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7672                                  regbit, "regbit");
7673 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7674         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7675 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7676         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7677 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7678         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7679
7680 cmdline_parse_inst_t cmd_read_reg_bit = {
7681         .f = cmd_read_reg_bit_parsed,
7682         .data = NULL,
7683         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7684         .tokens = {
7685                 (void *)&cmd_read_reg_bit_read,
7686                 (void *)&cmd_read_reg_bit_regbit,
7687                 (void *)&cmd_read_reg_bit_port_id,
7688                 (void *)&cmd_read_reg_bit_reg_off,
7689                 (void *)&cmd_read_reg_bit_bit_pos,
7690                 NULL,
7691         },
7692 };
7693
7694 /* *** WRITE PORT REGISTER *** */
7695 struct cmd_write_reg_result {
7696         cmdline_fixed_string_t write;
7697         cmdline_fixed_string_t reg;
7698         portid_t port_id;
7699         uint32_t reg_off;
7700         uint32_t value;
7701 };
7702
7703 static void
7704 cmd_write_reg_parsed(void *parsed_result,
7705                      __attribute__((unused)) struct cmdline *cl,
7706                      __attribute__((unused)) void *data)
7707 {
7708         struct cmd_write_reg_result *res = parsed_result;
7709         port_reg_set(res->port_id, res->reg_off, res->value);
7710 }
7711
7712 cmdline_parse_token_string_t cmd_write_reg_write =
7713         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7714 cmdline_parse_token_string_t cmd_write_reg_reg =
7715         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7716 cmdline_parse_token_num_t cmd_write_reg_port_id =
7717         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7718 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7719         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7720 cmdline_parse_token_num_t cmd_write_reg_value =
7721         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7722
7723 cmdline_parse_inst_t cmd_write_reg = {
7724         .f = cmd_write_reg_parsed,
7725         .data = NULL,
7726         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7727         .tokens = {
7728                 (void *)&cmd_write_reg_write,
7729                 (void *)&cmd_write_reg_reg,
7730                 (void *)&cmd_write_reg_port_id,
7731                 (void *)&cmd_write_reg_reg_off,
7732                 (void *)&cmd_write_reg_value,
7733                 NULL,
7734         },
7735 };
7736
7737 /* *** WRITE PORT REGISTER BIT FIELD *** */
7738 struct cmd_write_reg_bit_field_result {
7739         cmdline_fixed_string_t write;
7740         cmdline_fixed_string_t regfield;
7741         portid_t port_id;
7742         uint32_t reg_off;
7743         uint8_t bit1_pos;
7744         uint8_t bit2_pos;
7745         uint32_t value;
7746 };
7747
7748 static void
7749 cmd_write_reg_bit_field_parsed(void *parsed_result,
7750                                __attribute__((unused)) struct cmdline *cl,
7751                                __attribute__((unused)) void *data)
7752 {
7753         struct cmd_write_reg_bit_field_result *res = parsed_result;
7754         port_reg_bit_field_set(res->port_id, res->reg_off,
7755                           res->bit1_pos, res->bit2_pos, res->value);
7756 }
7757
7758 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7759         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7760                                  "write");
7761 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7762         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7763                                  regfield, "regfield");
7764 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7765         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7766                               UINT16);
7767 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7768         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7769                               UINT32);
7770 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7771         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7772                               UINT8);
7773 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7774         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7775                               UINT8);
7776 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7777         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7778                               UINT32);
7779
7780 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7781         .f = cmd_write_reg_bit_field_parsed,
7782         .data = NULL,
7783         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7784                 "<reg_value>: "
7785                 "Set register bit field between bit_x and bit_y included",
7786         .tokens = {
7787                 (void *)&cmd_write_reg_bit_field_write,
7788                 (void *)&cmd_write_reg_bit_field_regfield,
7789                 (void *)&cmd_write_reg_bit_field_port_id,
7790                 (void *)&cmd_write_reg_bit_field_reg_off,
7791                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7792                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7793                 (void *)&cmd_write_reg_bit_field_value,
7794                 NULL,
7795         },
7796 };
7797
7798 /* *** WRITE PORT REGISTER BIT *** */
7799 struct cmd_write_reg_bit_result {
7800         cmdline_fixed_string_t write;
7801         cmdline_fixed_string_t regbit;
7802         portid_t port_id;
7803         uint32_t reg_off;
7804         uint8_t bit_pos;
7805         uint8_t value;
7806 };
7807
7808 static void
7809 cmd_write_reg_bit_parsed(void *parsed_result,
7810                          __attribute__((unused)) struct cmdline *cl,
7811                          __attribute__((unused)) void *data)
7812 {
7813         struct cmd_write_reg_bit_result *res = parsed_result;
7814         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7815 }
7816
7817 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7818         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7819                                  "write");
7820 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7821         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7822                                  regbit, "regbit");
7823 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7824         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7825 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7826         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7827 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7828         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7829 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7830         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7831
7832 cmdline_parse_inst_t cmd_write_reg_bit = {
7833         .f = cmd_write_reg_bit_parsed,
7834         .data = NULL,
7835         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7836                 "0 <= bit_x <= 31",
7837         .tokens = {
7838                 (void *)&cmd_write_reg_bit_write,
7839                 (void *)&cmd_write_reg_bit_regbit,
7840                 (void *)&cmd_write_reg_bit_port_id,
7841                 (void *)&cmd_write_reg_bit_reg_off,
7842                 (void *)&cmd_write_reg_bit_bit_pos,
7843                 (void *)&cmd_write_reg_bit_value,
7844                 NULL,
7845         },
7846 };
7847
7848 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7849 struct cmd_read_rxd_txd_result {
7850         cmdline_fixed_string_t read;
7851         cmdline_fixed_string_t rxd_txd;
7852         portid_t port_id;
7853         uint16_t queue_id;
7854         uint16_t desc_id;
7855 };
7856
7857 static void
7858 cmd_read_rxd_txd_parsed(void *parsed_result,
7859                         __attribute__((unused)) struct cmdline *cl,
7860                         __attribute__((unused)) void *data)
7861 {
7862         struct cmd_read_rxd_txd_result *res = parsed_result;
7863
7864         if (!strcmp(res->rxd_txd, "rxd"))
7865                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7866         else if (!strcmp(res->rxd_txd, "txd"))
7867                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7868 }
7869
7870 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7871         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7872 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7873         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7874                                  "rxd#txd");
7875 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7876         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7877 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7878         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7879 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7880         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7881
7882 cmdline_parse_inst_t cmd_read_rxd_txd = {
7883         .f = cmd_read_rxd_txd_parsed,
7884         .data = NULL,
7885         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7886         .tokens = {
7887                 (void *)&cmd_read_rxd_txd_read,
7888                 (void *)&cmd_read_rxd_txd_rxd_txd,
7889                 (void *)&cmd_read_rxd_txd_port_id,
7890                 (void *)&cmd_read_rxd_txd_queue_id,
7891                 (void *)&cmd_read_rxd_txd_desc_id,
7892                 NULL,
7893         },
7894 };
7895
7896 /* *** QUIT *** */
7897 struct cmd_quit_result {
7898         cmdline_fixed_string_t quit;
7899 };
7900
7901 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7902                             struct cmdline *cl,
7903                             __attribute__((unused)) void *data)
7904 {
7905         cmdline_quit(cl);
7906 }
7907
7908 cmdline_parse_token_string_t cmd_quit_quit =
7909         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7910
7911 cmdline_parse_inst_t cmd_quit = {
7912         .f = cmd_quit_parsed,
7913         .data = NULL,
7914         .help_str = "quit: Exit application",
7915         .tokens = {
7916                 (void *)&cmd_quit_quit,
7917                 NULL,
7918         },
7919 };
7920
7921 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7922 struct cmd_mac_addr_result {
7923         cmdline_fixed_string_t mac_addr_cmd;
7924         cmdline_fixed_string_t what;
7925         uint16_t port_num;
7926         struct rte_ether_addr address;
7927 };
7928
7929 static void cmd_mac_addr_parsed(void *parsed_result,
7930                 __attribute__((unused)) struct cmdline *cl,
7931                 __attribute__((unused)) void *data)
7932 {
7933         struct cmd_mac_addr_result *res = parsed_result;
7934         int ret;
7935
7936         if (strcmp(res->what, "add") == 0)
7937                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7938         else if (strcmp(res->what, "set") == 0)
7939                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7940                                                        &res->address);
7941         else
7942                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7943
7944         /* check the return value and print it if is < 0 */
7945         if(ret < 0)
7946                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7947
7948 }
7949
7950 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7951         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7952                                 "mac_addr");
7953 cmdline_parse_token_string_t cmd_mac_addr_what =
7954         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7955                                 "add#remove#set");
7956 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7957                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7958                                         UINT16);
7959 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7960                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7961
7962 cmdline_parse_inst_t cmd_mac_addr = {
7963         .f = cmd_mac_addr_parsed,
7964         .data = (void *)0,
7965         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7966                         "Add/Remove/Set MAC address on port_id",
7967         .tokens = {
7968                 (void *)&cmd_mac_addr_cmd,
7969                 (void *)&cmd_mac_addr_what,
7970                 (void *)&cmd_mac_addr_portnum,
7971                 (void *)&cmd_mac_addr_addr,
7972                 NULL,
7973         },
7974 };
7975
7976 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7977 struct cmd_eth_peer_result {
7978         cmdline_fixed_string_t set;
7979         cmdline_fixed_string_t eth_peer;
7980         portid_t port_id;
7981         cmdline_fixed_string_t peer_addr;
7982 };
7983
7984 static void cmd_set_eth_peer_parsed(void *parsed_result,
7985                         __attribute__((unused)) struct cmdline *cl,
7986                         __attribute__((unused)) void *data)
7987 {
7988                 struct cmd_eth_peer_result *res = parsed_result;
7989
7990                 if (test_done == 0) {
7991                         printf("Please stop forwarding first\n");
7992                         return;
7993                 }
7994                 if (!strcmp(res->eth_peer, "eth-peer")) {
7995                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7996                         fwd_config_setup();
7997                 }
7998 }
7999 cmdline_parse_token_string_t cmd_eth_peer_set =
8000         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8001 cmdline_parse_token_string_t cmd_eth_peer =
8002         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8003 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8004         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8005 cmdline_parse_token_string_t cmd_eth_peer_addr =
8006         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8007
8008 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8009         .f = cmd_set_eth_peer_parsed,
8010         .data = NULL,
8011         .help_str = "set eth-peer <port_id> <peer_mac>",
8012         .tokens = {
8013                 (void *)&cmd_eth_peer_set,
8014                 (void *)&cmd_eth_peer,
8015                 (void *)&cmd_eth_peer_port_id,
8016                 (void *)&cmd_eth_peer_addr,
8017                 NULL,
8018         },
8019 };
8020
8021 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8022 struct cmd_set_qmap_result {
8023         cmdline_fixed_string_t set;
8024         cmdline_fixed_string_t qmap;
8025         cmdline_fixed_string_t what;
8026         portid_t port_id;
8027         uint16_t queue_id;
8028         uint8_t map_value;
8029 };
8030
8031 static void
8032 cmd_set_qmap_parsed(void *parsed_result,
8033                        __attribute__((unused)) struct cmdline *cl,
8034                        __attribute__((unused)) void *data)
8035 {
8036         struct cmd_set_qmap_result *res = parsed_result;
8037         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8038
8039         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8040 }
8041
8042 cmdline_parse_token_string_t cmd_setqmap_set =
8043         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8044                                  set, "set");
8045 cmdline_parse_token_string_t cmd_setqmap_qmap =
8046         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8047                                  qmap, "stat_qmap");
8048 cmdline_parse_token_string_t cmd_setqmap_what =
8049         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8050                                  what, "tx#rx");
8051 cmdline_parse_token_num_t cmd_setqmap_portid =
8052         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8053                               port_id, UINT16);
8054 cmdline_parse_token_num_t cmd_setqmap_queueid =
8055         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8056                               queue_id, UINT16);
8057 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8058         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8059                               map_value, UINT8);
8060
8061 cmdline_parse_inst_t cmd_set_qmap = {
8062         .f = cmd_set_qmap_parsed,
8063         .data = NULL,
8064         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8065                 "Set statistics mapping value on tx|rx queue_id of port_id",
8066         .tokens = {
8067                 (void *)&cmd_setqmap_set,
8068                 (void *)&cmd_setqmap_qmap,
8069                 (void *)&cmd_setqmap_what,
8070                 (void *)&cmd_setqmap_portid,
8071                 (void *)&cmd_setqmap_queueid,
8072                 (void *)&cmd_setqmap_mapvalue,
8073                 NULL,
8074         },
8075 };
8076
8077 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8078 struct cmd_set_xstats_hide_zero_result {
8079         cmdline_fixed_string_t keyword;
8080         cmdline_fixed_string_t name;
8081         cmdline_fixed_string_t on_off;
8082 };
8083
8084 static void
8085 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8086                         __attribute__((unused)) struct cmdline *cl,
8087                         __attribute__((unused)) void *data)
8088 {
8089         struct cmd_set_xstats_hide_zero_result *res;
8090         uint16_t on_off = 0;
8091
8092         res = parsed_result;
8093         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8094         set_xstats_hide_zero(on_off);
8095 }
8096
8097 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8098         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8099                                  keyword, "set");
8100 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8101         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8102                                  name, "xstats-hide-zero");
8103 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8104         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8105                                  on_off, "on#off");
8106
8107 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8108         .f = cmd_set_xstats_hide_zero_parsed,
8109         .data = NULL,
8110         .help_str = "set xstats-hide-zero on|off",
8111         .tokens = {
8112                 (void *)&cmd_set_xstats_hide_zero_keyword,
8113                 (void *)&cmd_set_xstats_hide_zero_name,
8114                 (void *)&cmd_set_xstats_hide_zero_on_off,
8115                 NULL,
8116         },
8117 };
8118
8119 /* *** CONFIGURE UNICAST HASH TABLE *** */
8120 struct cmd_set_uc_hash_table {
8121         cmdline_fixed_string_t set;
8122         cmdline_fixed_string_t port;
8123         portid_t port_id;
8124         cmdline_fixed_string_t what;
8125         struct rte_ether_addr address;
8126         cmdline_fixed_string_t mode;
8127 };
8128
8129 static void
8130 cmd_set_uc_hash_parsed(void *parsed_result,
8131                        __attribute__((unused)) struct cmdline *cl,
8132                        __attribute__((unused)) void *data)
8133 {
8134         int ret=0;
8135         struct cmd_set_uc_hash_table *res = parsed_result;
8136
8137         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8138
8139         if (strcmp(res->what, "uta") == 0)
8140                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8141                                                 &res->address,(uint8_t)is_on);
8142         if (ret < 0)
8143                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8144
8145 }
8146
8147 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8148         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8149                                  set, "set");
8150 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8151         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8152                                  port, "port");
8153 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8154         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8155                               port_id, UINT16);
8156 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8157         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8158                                  what, "uta");
8159 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8160         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8161                                 address);
8162 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8163         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8164                                  mode, "on#off");
8165
8166 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8167         .f = cmd_set_uc_hash_parsed,
8168         .data = NULL,
8169         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8170         .tokens = {
8171                 (void *)&cmd_set_uc_hash_set,
8172                 (void *)&cmd_set_uc_hash_port,
8173                 (void *)&cmd_set_uc_hash_portid,
8174                 (void *)&cmd_set_uc_hash_what,
8175                 (void *)&cmd_set_uc_hash_mac,
8176                 (void *)&cmd_set_uc_hash_mode,
8177                 NULL,
8178         },
8179 };
8180
8181 struct cmd_set_uc_all_hash_table {
8182         cmdline_fixed_string_t set;
8183         cmdline_fixed_string_t port;
8184         portid_t port_id;
8185         cmdline_fixed_string_t what;
8186         cmdline_fixed_string_t value;
8187         cmdline_fixed_string_t mode;
8188 };
8189
8190 static void
8191 cmd_set_uc_all_hash_parsed(void *parsed_result,
8192                        __attribute__((unused)) struct cmdline *cl,
8193                        __attribute__((unused)) void *data)
8194 {
8195         int ret=0;
8196         struct cmd_set_uc_all_hash_table *res = parsed_result;
8197
8198         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8199
8200         if ((strcmp(res->what, "uta") == 0) &&
8201                 (strcmp(res->value, "all") == 0))
8202                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8203         if (ret < 0)
8204                 printf("bad unicast hash table parameter,"
8205                         "return code = %d \n", ret);
8206 }
8207
8208 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8209         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8210                                  set, "set");
8211 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8212         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8213                                  port, "port");
8214 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8215         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8216                               port_id, UINT16);
8217 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8218         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8219                                  what, "uta");
8220 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8221         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8222                                 value,"all");
8223 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8224         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8225                                  mode, "on#off");
8226
8227 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8228         .f = cmd_set_uc_all_hash_parsed,
8229         .data = NULL,
8230         .help_str = "set port <port_id> uta all on|off",
8231         .tokens = {
8232                 (void *)&cmd_set_uc_all_hash_set,
8233                 (void *)&cmd_set_uc_all_hash_port,
8234                 (void *)&cmd_set_uc_all_hash_portid,
8235                 (void *)&cmd_set_uc_all_hash_what,
8236                 (void *)&cmd_set_uc_all_hash_value,
8237                 (void *)&cmd_set_uc_all_hash_mode,
8238                 NULL,
8239         },
8240 };
8241
8242 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8243 struct cmd_set_vf_macvlan_filter {
8244         cmdline_fixed_string_t set;
8245         cmdline_fixed_string_t port;
8246         portid_t port_id;
8247         cmdline_fixed_string_t vf;
8248         uint8_t vf_id;
8249         struct rte_ether_addr address;
8250         cmdline_fixed_string_t filter_type;
8251         cmdline_fixed_string_t mode;
8252 };
8253
8254 static void
8255 cmd_set_vf_macvlan_parsed(void *parsed_result,
8256                        __attribute__((unused)) struct cmdline *cl,
8257                        __attribute__((unused)) void *data)
8258 {
8259         int is_on, ret = 0;
8260         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8261         struct rte_eth_mac_filter filter;
8262
8263         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8264
8265         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8266
8267         /* set VF MAC filter */
8268         filter.is_vf = 1;
8269
8270         /* set VF ID */
8271         filter.dst_id = res->vf_id;
8272
8273         if (!strcmp(res->filter_type, "exact-mac"))
8274                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8275         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8276                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8277         else if (!strcmp(res->filter_type, "hashmac"))
8278                 filter.filter_type = RTE_MAC_HASH_MATCH;
8279         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8280                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8281
8282         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8283
8284         if (is_on)
8285                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8286                                         RTE_ETH_FILTER_MACVLAN,
8287                                         RTE_ETH_FILTER_ADD,
8288                                          &filter);
8289         else
8290                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8291                                         RTE_ETH_FILTER_MACVLAN,
8292                                         RTE_ETH_FILTER_DELETE,
8293                                         &filter);
8294
8295         if (ret < 0)
8296                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8297
8298 }
8299
8300 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8301         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8302                                  set, "set");
8303 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8304         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8305                                  port, "port");
8306 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8307         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8308                               port_id, UINT16);
8309 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8310         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8311                                  vf, "vf");
8312 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8313         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8314                                 vf_id, UINT8);
8315 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8316         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8317                                 address);
8318 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8319         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8320                                 filter_type, "exact-mac#exact-mac-vlan"
8321                                 "#hashmac#hashmac-vlan");
8322 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8323         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8324                                  mode, "on#off");
8325
8326 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8327         .f = cmd_set_vf_macvlan_parsed,
8328         .data = NULL,
8329         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8330                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8331                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8332                 "hash match rule: hash match of MAC and exact match of VLAN",
8333         .tokens = {
8334                 (void *)&cmd_set_vf_macvlan_set,
8335                 (void *)&cmd_set_vf_macvlan_port,
8336                 (void *)&cmd_set_vf_macvlan_portid,
8337                 (void *)&cmd_set_vf_macvlan_vf,
8338                 (void *)&cmd_set_vf_macvlan_vf_id,
8339                 (void *)&cmd_set_vf_macvlan_mac,
8340                 (void *)&cmd_set_vf_macvlan_filter_type,
8341                 (void *)&cmd_set_vf_macvlan_mode,
8342                 NULL,
8343         },
8344 };
8345
8346 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8347 struct cmd_set_vf_traffic {
8348         cmdline_fixed_string_t set;
8349         cmdline_fixed_string_t port;
8350         portid_t port_id;
8351         cmdline_fixed_string_t vf;
8352         uint8_t vf_id;
8353         cmdline_fixed_string_t what;
8354         cmdline_fixed_string_t mode;
8355 };
8356
8357 static void
8358 cmd_set_vf_traffic_parsed(void *parsed_result,
8359                        __attribute__((unused)) struct cmdline *cl,
8360                        __attribute__((unused)) void *data)
8361 {
8362         struct cmd_set_vf_traffic *res = parsed_result;
8363         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8364         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8365
8366         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8367 }
8368
8369 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8370         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8371                                  set, "set");
8372 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8373         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8374                                  port, "port");
8375 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8376         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8377                               port_id, UINT16);
8378 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8379         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8380                                  vf, "vf");
8381 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8382         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8383                               vf_id, UINT8);
8384 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8385         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8386                                  what, "tx#rx");
8387 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8388         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8389                                  mode, "on#off");
8390
8391 cmdline_parse_inst_t cmd_set_vf_traffic = {
8392         .f = cmd_set_vf_traffic_parsed,
8393         .data = NULL,
8394         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8395         .tokens = {
8396                 (void *)&cmd_setvf_traffic_set,
8397                 (void *)&cmd_setvf_traffic_port,
8398                 (void *)&cmd_setvf_traffic_portid,
8399                 (void *)&cmd_setvf_traffic_vf,
8400                 (void *)&cmd_setvf_traffic_vfid,
8401                 (void *)&cmd_setvf_traffic_what,
8402                 (void *)&cmd_setvf_traffic_mode,
8403                 NULL,
8404         },
8405 };
8406
8407 /* *** CONFIGURE VF RECEIVE MODE *** */
8408 struct cmd_set_vf_rxmode {
8409         cmdline_fixed_string_t set;
8410         cmdline_fixed_string_t port;
8411         portid_t port_id;
8412         cmdline_fixed_string_t vf;
8413         uint8_t vf_id;
8414         cmdline_fixed_string_t what;
8415         cmdline_fixed_string_t mode;
8416         cmdline_fixed_string_t on;
8417 };
8418
8419 static void
8420 cmd_set_vf_rxmode_parsed(void *parsed_result,
8421                        __attribute__((unused)) struct cmdline *cl,
8422                        __attribute__((unused)) void *data)
8423 {
8424         int ret = -ENOTSUP;
8425         uint16_t rx_mode = 0;
8426         struct cmd_set_vf_rxmode *res = parsed_result;
8427
8428         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8429         if (!strcmp(res->what,"rxmode")) {
8430                 if (!strcmp(res->mode, "AUPE"))
8431                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8432                 else if (!strcmp(res->mode, "ROPE"))
8433                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8434                 else if (!strcmp(res->mode, "BAM"))
8435                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8436                 else if (!strncmp(res->mode, "MPE",3))
8437                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8438         }
8439
8440         RTE_SET_USED(is_on);
8441
8442 #ifdef RTE_LIBRTE_IXGBE_PMD
8443         if (ret == -ENOTSUP)
8444                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8445                                                   rx_mode, (uint8_t)is_on);
8446 #endif
8447 #ifdef RTE_LIBRTE_BNXT_PMD
8448         if (ret == -ENOTSUP)
8449                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8450                                                  rx_mode, (uint8_t)is_on);
8451 #endif
8452         if (ret < 0)
8453                 printf("bad VF receive mode parameter, return code = %d \n",
8454                 ret);
8455 }
8456
8457 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8458         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8459                                  set, "set");
8460 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8461         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8462                                  port, "port");
8463 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8464         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8465                               port_id, UINT16);
8466 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8467         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8468                                  vf, "vf");
8469 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8470         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8471                               vf_id, UINT8);
8472 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8473         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8474                                  what, "rxmode");
8475 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8476         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8477                                  mode, "AUPE#ROPE#BAM#MPE");
8478 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8479         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8480                                  on, "on#off");
8481
8482 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8483         .f = cmd_set_vf_rxmode_parsed,
8484         .data = NULL,
8485         .help_str = "set port <port_id> vf <vf_id> rxmode "
8486                 "AUPE|ROPE|BAM|MPE on|off",
8487         .tokens = {
8488                 (void *)&cmd_set_vf_rxmode_set,
8489                 (void *)&cmd_set_vf_rxmode_port,
8490                 (void *)&cmd_set_vf_rxmode_portid,
8491                 (void *)&cmd_set_vf_rxmode_vf,
8492                 (void *)&cmd_set_vf_rxmode_vfid,
8493                 (void *)&cmd_set_vf_rxmode_what,
8494                 (void *)&cmd_set_vf_rxmode_mode,
8495                 (void *)&cmd_set_vf_rxmode_on,
8496                 NULL,
8497         },
8498 };
8499
8500 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8501 struct cmd_vf_mac_addr_result {
8502         cmdline_fixed_string_t mac_addr_cmd;
8503         cmdline_fixed_string_t what;
8504         cmdline_fixed_string_t port;
8505         uint16_t port_num;
8506         cmdline_fixed_string_t vf;
8507         uint8_t vf_num;
8508         struct rte_ether_addr address;
8509 };
8510
8511 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8512                 __attribute__((unused)) struct cmdline *cl,
8513                 __attribute__((unused)) void *data)
8514 {
8515         struct cmd_vf_mac_addr_result *res = parsed_result;
8516         int ret = -ENOTSUP;
8517
8518         if (strcmp(res->what, "add") != 0)
8519                 return;
8520
8521 #ifdef RTE_LIBRTE_I40E_PMD
8522         if (ret == -ENOTSUP)
8523                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8524                                                    &res->address);
8525 #endif
8526 #ifdef RTE_LIBRTE_BNXT_PMD
8527         if (ret == -ENOTSUP)
8528                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8529                                                 res->vf_num);
8530 #endif
8531
8532         if(ret < 0)
8533                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8534
8535 }
8536
8537 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8538         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8539                                 mac_addr_cmd,"mac_addr");
8540 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8541         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8542                                 what,"add");
8543 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8544         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8545                                 port,"port");
8546 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8547         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8548                                 port_num, UINT16);
8549 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8550         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8551                                 vf,"vf");
8552 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8553         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8554                                 vf_num, UINT8);
8555 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8556         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8557                                 address);
8558
8559 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8560         .f = cmd_vf_mac_addr_parsed,
8561         .data = (void *)0,
8562         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8563                 "Add MAC address filtering for a VF on port_id",
8564         .tokens = {
8565                 (void *)&cmd_vf_mac_addr_cmd,
8566                 (void *)&cmd_vf_mac_addr_what,
8567                 (void *)&cmd_vf_mac_addr_port,
8568                 (void *)&cmd_vf_mac_addr_portnum,
8569                 (void *)&cmd_vf_mac_addr_vf,
8570                 (void *)&cmd_vf_mac_addr_vfnum,
8571                 (void *)&cmd_vf_mac_addr_addr,
8572                 NULL,
8573         },
8574 };
8575
8576 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8577 struct cmd_vf_rx_vlan_filter {
8578         cmdline_fixed_string_t rx_vlan;
8579         cmdline_fixed_string_t what;
8580         uint16_t vlan_id;
8581         cmdline_fixed_string_t port;
8582         portid_t port_id;
8583         cmdline_fixed_string_t vf;
8584         uint64_t vf_mask;
8585 };
8586
8587 static void
8588 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8589                           __attribute__((unused)) struct cmdline *cl,
8590                           __attribute__((unused)) void *data)
8591 {
8592         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8593         int ret = -ENOTSUP;
8594
8595         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8596
8597 #ifdef RTE_LIBRTE_IXGBE_PMD
8598         if (ret == -ENOTSUP)
8599                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8600                                 res->vlan_id, res->vf_mask, is_add);
8601 #endif
8602 #ifdef RTE_LIBRTE_I40E_PMD
8603         if (ret == -ENOTSUP)
8604                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8605                                 res->vlan_id, res->vf_mask, is_add);
8606 #endif
8607 #ifdef RTE_LIBRTE_BNXT_PMD
8608         if (ret == -ENOTSUP)
8609                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8610                                 res->vlan_id, res->vf_mask, is_add);
8611 #endif
8612
8613         switch (ret) {
8614         case 0:
8615                 break;
8616         case -EINVAL:
8617                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8618                                 res->vlan_id, res->vf_mask);
8619                 break;
8620         case -ENODEV:
8621                 printf("invalid port_id %d\n", res->port_id);
8622                 break;
8623         case -ENOTSUP:
8624                 printf("function not implemented or supported\n");
8625                 break;
8626         default:
8627                 printf("programming error: (%s)\n", strerror(-ret));
8628         }
8629 }
8630
8631 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8632         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8633                                  rx_vlan, "rx_vlan");
8634 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8635         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8636                                  what, "add#rm");
8637 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8638         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8639                               vlan_id, UINT16);
8640 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8641         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8642                                  port, "port");
8643 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8644         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8645                               port_id, UINT16);
8646 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8647         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8648                                  vf, "vf");
8649 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8650         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8651                               vf_mask, UINT64);
8652
8653 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8654         .f = cmd_vf_rx_vlan_filter_parsed,
8655         .data = NULL,
8656         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8657                 "(vf_mask = hexadecimal VF mask)",
8658         .tokens = {
8659                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8660                 (void *)&cmd_vf_rx_vlan_filter_what,
8661                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8662                 (void *)&cmd_vf_rx_vlan_filter_port,
8663                 (void *)&cmd_vf_rx_vlan_filter_portid,
8664                 (void *)&cmd_vf_rx_vlan_filter_vf,
8665                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8666                 NULL,
8667         },
8668 };
8669
8670 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8671 struct cmd_queue_rate_limit_result {
8672         cmdline_fixed_string_t set;
8673         cmdline_fixed_string_t port;
8674         uint16_t port_num;
8675         cmdline_fixed_string_t queue;
8676         uint8_t queue_num;
8677         cmdline_fixed_string_t rate;
8678         uint16_t rate_num;
8679 };
8680
8681 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8682                 __attribute__((unused)) struct cmdline *cl,
8683                 __attribute__((unused)) void *data)
8684 {
8685         struct cmd_queue_rate_limit_result *res = parsed_result;
8686         int ret = 0;
8687
8688         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8689                 && (strcmp(res->queue, "queue") == 0)
8690                 && (strcmp(res->rate, "rate") == 0))
8691                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8692                                         res->rate_num);
8693         if (ret < 0)
8694                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8695
8696 }
8697
8698 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8699         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8700                                 set, "set");
8701 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8702         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8703                                 port, "port");
8704 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8705         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8706                                 port_num, UINT16);
8707 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8708         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8709                                 queue, "queue");
8710 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8711         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8712                                 queue_num, UINT8);
8713 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8714         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8715                                 rate, "rate");
8716 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8717         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8718                                 rate_num, UINT16);
8719
8720 cmdline_parse_inst_t cmd_queue_rate_limit = {
8721         .f = cmd_queue_rate_limit_parsed,
8722         .data = (void *)0,
8723         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8724                 "Set rate limit for a queue on port_id",
8725         .tokens = {
8726                 (void *)&cmd_queue_rate_limit_set,
8727                 (void *)&cmd_queue_rate_limit_port,
8728                 (void *)&cmd_queue_rate_limit_portnum,
8729                 (void *)&cmd_queue_rate_limit_queue,
8730                 (void *)&cmd_queue_rate_limit_queuenum,
8731                 (void *)&cmd_queue_rate_limit_rate,
8732                 (void *)&cmd_queue_rate_limit_ratenum,
8733                 NULL,
8734         },
8735 };
8736
8737 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8738 struct cmd_vf_rate_limit_result {
8739         cmdline_fixed_string_t set;
8740         cmdline_fixed_string_t port;
8741         uint16_t port_num;
8742         cmdline_fixed_string_t vf;
8743         uint8_t vf_num;
8744         cmdline_fixed_string_t rate;
8745         uint16_t rate_num;
8746         cmdline_fixed_string_t q_msk;
8747         uint64_t q_msk_val;
8748 };
8749
8750 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8751                 __attribute__((unused)) struct cmdline *cl,
8752                 __attribute__((unused)) void *data)
8753 {
8754         struct cmd_vf_rate_limit_result *res = parsed_result;
8755         int ret = 0;
8756
8757         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8758                 && (strcmp(res->vf, "vf") == 0)
8759                 && (strcmp(res->rate, "rate") == 0)
8760                 && (strcmp(res->q_msk, "queue_mask") == 0))
8761                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8762                                         res->rate_num, res->q_msk_val);
8763         if (ret < 0)
8764                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8765
8766 }
8767
8768 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8769         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8770                                 set, "set");
8771 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8772         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8773                                 port, "port");
8774 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8775         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8776                                 port_num, UINT16);
8777 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8778         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8779                                 vf, "vf");
8780 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8781         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8782                                 vf_num, UINT8);
8783 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8784         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8785                                 rate, "rate");
8786 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8787         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8788                                 rate_num, UINT16);
8789 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8790         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8791                                 q_msk, "queue_mask");
8792 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8793         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8794                                 q_msk_val, UINT64);
8795
8796 cmdline_parse_inst_t cmd_vf_rate_limit = {
8797         .f = cmd_vf_rate_limit_parsed,
8798         .data = (void *)0,
8799         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8800                 "queue_mask <queue_mask_value>: "
8801                 "Set rate limit for queues of VF on port_id",
8802         .tokens = {
8803                 (void *)&cmd_vf_rate_limit_set,
8804                 (void *)&cmd_vf_rate_limit_port,
8805                 (void *)&cmd_vf_rate_limit_portnum,
8806                 (void *)&cmd_vf_rate_limit_vf,
8807                 (void *)&cmd_vf_rate_limit_vfnum,
8808                 (void *)&cmd_vf_rate_limit_rate,
8809                 (void *)&cmd_vf_rate_limit_ratenum,
8810                 (void *)&cmd_vf_rate_limit_q_msk,
8811                 (void *)&cmd_vf_rate_limit_q_msk_val,
8812                 NULL,
8813         },
8814 };
8815
8816 /* *** ADD TUNNEL FILTER OF A PORT *** */
8817 struct cmd_tunnel_filter_result {
8818         cmdline_fixed_string_t cmd;
8819         cmdline_fixed_string_t what;
8820         portid_t port_id;
8821         struct rte_ether_addr outer_mac;
8822         struct rte_ether_addr inner_mac;
8823         cmdline_ipaddr_t ip_value;
8824         uint16_t inner_vlan;
8825         cmdline_fixed_string_t tunnel_type;
8826         cmdline_fixed_string_t filter_type;
8827         uint32_t tenant_id;
8828         uint16_t queue_num;
8829 };
8830
8831 static void
8832 cmd_tunnel_filter_parsed(void *parsed_result,
8833                           __attribute__((unused)) struct cmdline *cl,
8834                           __attribute__((unused)) void *data)
8835 {
8836         struct cmd_tunnel_filter_result *res = parsed_result;
8837         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8838         int ret = 0;
8839
8840         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8841
8842         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8843         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8844         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8845
8846         if (res->ip_value.family == AF_INET) {
8847                 tunnel_filter_conf.ip_addr.ipv4_addr =
8848                         res->ip_value.addr.ipv4.s_addr;
8849                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8850         } else {
8851                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8852                         &(res->ip_value.addr.ipv6),
8853                         sizeof(struct in6_addr));
8854                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8855         }
8856
8857         if (!strcmp(res->filter_type, "imac-ivlan"))
8858                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8859         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8860                 tunnel_filter_conf.filter_type =
8861                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8862         else if (!strcmp(res->filter_type, "imac-tenid"))
8863                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8864         else if (!strcmp(res->filter_type, "imac"))
8865                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8866         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8867                 tunnel_filter_conf.filter_type =
8868                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8869         else if (!strcmp(res->filter_type, "oip"))
8870                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8871         else if (!strcmp(res->filter_type, "iip"))
8872                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8873         else {
8874                 printf("The filter type is not supported");
8875                 return;
8876         }
8877
8878         if (!strcmp(res->tunnel_type, "vxlan"))
8879                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8880         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8881                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8882         else if (!strcmp(res->tunnel_type, "nvgre"))
8883                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8884         else if (!strcmp(res->tunnel_type, "ipingre"))
8885                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8886         else {
8887                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8888                 return;
8889         }
8890
8891         tunnel_filter_conf.tenant_id = res->tenant_id;
8892         tunnel_filter_conf.queue_id = res->queue_num;
8893         if (!strcmp(res->what, "add"))
8894                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8895                                         RTE_ETH_FILTER_TUNNEL,
8896                                         RTE_ETH_FILTER_ADD,
8897                                         &tunnel_filter_conf);
8898         else
8899                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8900                                         RTE_ETH_FILTER_TUNNEL,
8901                                         RTE_ETH_FILTER_DELETE,
8902                                         &tunnel_filter_conf);
8903         if (ret < 0)
8904                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8905                                 strerror(-ret));
8906
8907 }
8908 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8909         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8910         cmd, "tunnel_filter");
8911 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8912         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8913         what, "add#rm");
8914 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8915         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8916         port_id, UINT16);
8917 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8918         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8919         outer_mac);
8920 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8921         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8922         inner_mac);
8923 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8924         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8925         inner_vlan, UINT16);
8926 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8927         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8928         ip_value);
8929 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8930         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8931         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8932
8933 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8934         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8935         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8936                 "imac#omac-imac-tenid");
8937 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8938         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8939         tenant_id, UINT32);
8940 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8941         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8942         queue_num, UINT16);
8943
8944 cmdline_parse_inst_t cmd_tunnel_filter = {
8945         .f = cmd_tunnel_filter_parsed,
8946         .data = (void *)0,
8947         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8948                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8949                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8950                 "<queue_id>: Add/Rm tunnel filter of a port",
8951         .tokens = {
8952                 (void *)&cmd_tunnel_filter_cmd,
8953                 (void *)&cmd_tunnel_filter_what,
8954                 (void *)&cmd_tunnel_filter_port_id,
8955                 (void *)&cmd_tunnel_filter_outer_mac,
8956                 (void *)&cmd_tunnel_filter_inner_mac,
8957                 (void *)&cmd_tunnel_filter_ip_value,
8958                 (void *)&cmd_tunnel_filter_innner_vlan,
8959                 (void *)&cmd_tunnel_filter_tunnel_type,
8960                 (void *)&cmd_tunnel_filter_filter_type,
8961                 (void *)&cmd_tunnel_filter_tenant_id,
8962                 (void *)&cmd_tunnel_filter_queue_num,
8963                 NULL,
8964         },
8965 };
8966
8967 /* *** CONFIGURE TUNNEL UDP PORT *** */
8968 struct cmd_tunnel_udp_config {
8969         cmdline_fixed_string_t cmd;
8970         cmdline_fixed_string_t what;
8971         uint16_t udp_port;
8972         portid_t port_id;
8973 };
8974
8975 static void
8976 cmd_tunnel_udp_config_parsed(void *parsed_result,
8977                           __attribute__((unused)) struct cmdline *cl,
8978                           __attribute__((unused)) void *data)
8979 {
8980         struct cmd_tunnel_udp_config *res = parsed_result;
8981         struct rte_eth_udp_tunnel tunnel_udp;
8982         int ret;
8983
8984         tunnel_udp.udp_port = res->udp_port;
8985
8986         if (!strcmp(res->cmd, "rx_vxlan_port"))
8987                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8988
8989         if (!strcmp(res->what, "add"))
8990                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8991                                                       &tunnel_udp);
8992         else
8993                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8994                                                          &tunnel_udp);
8995
8996         if (ret < 0)
8997                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8998 }
8999
9000 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9001         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9002                                 cmd, "rx_vxlan_port");
9003 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9004         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9005                                 what, "add#rm");
9006 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9007         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9008                                 udp_port, UINT16);
9009 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9010         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9011                                 port_id, UINT16);
9012
9013 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9014         .f = cmd_tunnel_udp_config_parsed,
9015         .data = (void *)0,
9016         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9017                 "Add/Remove a tunneling UDP port filter",
9018         .tokens = {
9019                 (void *)&cmd_tunnel_udp_config_cmd,
9020                 (void *)&cmd_tunnel_udp_config_what,
9021                 (void *)&cmd_tunnel_udp_config_udp_port,
9022                 (void *)&cmd_tunnel_udp_config_port_id,
9023                 NULL,
9024         },
9025 };
9026
9027 struct cmd_config_tunnel_udp_port {
9028         cmdline_fixed_string_t port;
9029         cmdline_fixed_string_t config;
9030         portid_t port_id;
9031         cmdline_fixed_string_t udp_tunnel_port;
9032         cmdline_fixed_string_t action;
9033         cmdline_fixed_string_t tunnel_type;
9034         uint16_t udp_port;
9035 };
9036
9037 static void
9038 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9039                                __attribute__((unused)) struct cmdline *cl,
9040                                __attribute__((unused)) void *data)
9041 {
9042         struct cmd_config_tunnel_udp_port *res = parsed_result;
9043         struct rte_eth_udp_tunnel tunnel_udp;
9044         int ret = 0;
9045
9046         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9047                 return;
9048
9049         tunnel_udp.udp_port = res->udp_port;
9050
9051         if (!strcmp(res->tunnel_type, "vxlan")) {
9052                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9053         } else if (!strcmp(res->tunnel_type, "geneve")) {
9054                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9055         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9056                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9057         } else {
9058                 printf("Invalid tunnel type\n");
9059                 return;
9060         }
9061
9062         if (!strcmp(res->action, "add"))
9063                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9064                                                       &tunnel_udp);
9065         else
9066                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9067                                                          &tunnel_udp);
9068
9069         if (ret < 0)
9070                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9071 }
9072
9073 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9074         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9075                                  "port");
9076 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9077         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9078                                  "config");
9079 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9080         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9081                               UINT16);
9082 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9083         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9084                                  udp_tunnel_port,
9085                                  "udp_tunnel_port");
9086 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9087         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9088                                  "add#rm");
9089 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9090         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9091                                  "vxlan#geneve#vxlan-gpe");
9092 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9093         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9094                               UINT16);
9095
9096 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9097         .f = cmd_cfg_tunnel_udp_port_parsed,
9098         .data = NULL,
9099         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9100         .tokens = {
9101                 (void *)&cmd_config_tunnel_udp_port_port,
9102                 (void *)&cmd_config_tunnel_udp_port_config,
9103                 (void *)&cmd_config_tunnel_udp_port_port_id,
9104                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9105                 (void *)&cmd_config_tunnel_udp_port_action,
9106                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9107                 (void *)&cmd_config_tunnel_udp_port_value,
9108                 NULL,
9109         },
9110 };
9111
9112 /* *** GLOBAL CONFIG *** */
9113 struct cmd_global_config_result {
9114         cmdline_fixed_string_t cmd;
9115         portid_t port_id;
9116         cmdline_fixed_string_t cfg_type;
9117         uint8_t len;
9118 };
9119
9120 static void
9121 cmd_global_config_parsed(void *parsed_result,
9122                          __attribute__((unused)) struct cmdline *cl,
9123                          __attribute__((unused)) void *data)
9124 {
9125         struct cmd_global_config_result *res = parsed_result;
9126         struct rte_eth_global_cfg conf;
9127         int ret;
9128
9129         memset(&conf, 0, sizeof(conf));
9130         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9131         conf.cfg.gre_key_len = res->len;
9132         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9133                                       RTE_ETH_FILTER_SET, &conf);
9134         if (ret != 0)
9135                 printf("Global config error\n");
9136 }
9137
9138 cmdline_parse_token_string_t cmd_global_config_cmd =
9139         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9140                 "global_config");
9141 cmdline_parse_token_num_t cmd_global_config_port_id =
9142         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9143                                UINT16);
9144 cmdline_parse_token_string_t cmd_global_config_type =
9145         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9146                 cfg_type, "gre-key-len");
9147 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9148         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9149                 len, UINT8);
9150
9151 cmdline_parse_inst_t cmd_global_config = {
9152         .f = cmd_global_config_parsed,
9153         .data = (void *)NULL,
9154         .help_str = "global_config <port_id> gre-key-len <key_len>",
9155         .tokens = {
9156                 (void *)&cmd_global_config_cmd,
9157                 (void *)&cmd_global_config_port_id,
9158                 (void *)&cmd_global_config_type,
9159                 (void *)&cmd_global_config_gre_key_len,
9160                 NULL,
9161         },
9162 };
9163
9164 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9165 struct cmd_set_mirror_mask_result {
9166         cmdline_fixed_string_t set;
9167         cmdline_fixed_string_t port;
9168         portid_t port_id;
9169         cmdline_fixed_string_t mirror;
9170         uint8_t rule_id;
9171         cmdline_fixed_string_t what;
9172         cmdline_fixed_string_t value;
9173         cmdline_fixed_string_t dstpool;
9174         uint8_t dstpool_id;
9175         cmdline_fixed_string_t on;
9176 };
9177
9178 cmdline_parse_token_string_t cmd_mirror_mask_set =
9179         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9180                                 set, "set");
9181 cmdline_parse_token_string_t cmd_mirror_mask_port =
9182         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9183                                 port, "port");
9184 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9185         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9186                                 port_id, UINT16);
9187 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9188         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9189                                 mirror, "mirror-rule");
9190 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9191         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9192                                 rule_id, UINT8);
9193 cmdline_parse_token_string_t cmd_mirror_mask_what =
9194         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9195                                 what, "pool-mirror-up#pool-mirror-down"
9196                                       "#vlan-mirror");
9197 cmdline_parse_token_string_t cmd_mirror_mask_value =
9198         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9199                                 value, NULL);
9200 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9201         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9202                                 dstpool, "dst-pool");
9203 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9204         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9205                                 dstpool_id, UINT8);
9206 cmdline_parse_token_string_t cmd_mirror_mask_on =
9207         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9208                                 on, "on#off");
9209
9210 static void
9211 cmd_set_mirror_mask_parsed(void *parsed_result,
9212                        __attribute__((unused)) struct cmdline *cl,
9213                        __attribute__((unused)) void *data)
9214 {
9215         int ret,nb_item,i;
9216         struct cmd_set_mirror_mask_result *res = parsed_result;
9217         struct rte_eth_mirror_conf mr_conf;
9218
9219         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9220
9221         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9222
9223         mr_conf.dst_pool = res->dstpool_id;
9224
9225         if (!strcmp(res->what, "pool-mirror-up")) {
9226                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9227                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9228         } else if (!strcmp(res->what, "pool-mirror-down")) {
9229                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9230                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9231         } else if (!strcmp(res->what, "vlan-mirror")) {
9232                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9233                 nb_item = parse_item_list(res->value, "vlan",
9234                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9235                 if (nb_item <= 0)
9236                         return;
9237
9238                 for (i = 0; i < nb_item; i++) {
9239                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9240                                 printf("Invalid vlan_id: must be < 4096\n");
9241                                 return;
9242                         }
9243
9244                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9245                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9246                 }
9247         }
9248
9249         if (!strcmp(res->on, "on"))
9250                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9251                                                 res->rule_id, 1);
9252         else
9253                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9254                                                 res->rule_id, 0);
9255         if (ret < 0)
9256                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9257 }
9258
9259 cmdline_parse_inst_t cmd_set_mirror_mask = {
9260                 .f = cmd_set_mirror_mask_parsed,
9261                 .data = NULL,
9262                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9263                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9264                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9265                 .tokens = {
9266                         (void *)&cmd_mirror_mask_set,
9267                         (void *)&cmd_mirror_mask_port,
9268                         (void *)&cmd_mirror_mask_portid,
9269                         (void *)&cmd_mirror_mask_mirror,
9270                         (void *)&cmd_mirror_mask_ruleid,
9271                         (void *)&cmd_mirror_mask_what,
9272                         (void *)&cmd_mirror_mask_value,
9273                         (void *)&cmd_mirror_mask_dstpool,
9274                         (void *)&cmd_mirror_mask_poolid,
9275                         (void *)&cmd_mirror_mask_on,
9276                         NULL,
9277                 },
9278 };
9279
9280 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9281 struct cmd_set_mirror_link_result {
9282         cmdline_fixed_string_t set;
9283         cmdline_fixed_string_t port;
9284         portid_t port_id;
9285         cmdline_fixed_string_t mirror;
9286         uint8_t rule_id;
9287         cmdline_fixed_string_t what;
9288         cmdline_fixed_string_t dstpool;
9289         uint8_t dstpool_id;
9290         cmdline_fixed_string_t on;
9291 };
9292
9293 cmdline_parse_token_string_t cmd_mirror_link_set =
9294         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9295                                  set, "set");
9296 cmdline_parse_token_string_t cmd_mirror_link_port =
9297         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9298                                 port, "port");
9299 cmdline_parse_token_num_t cmd_mirror_link_portid =
9300         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9301                                 port_id, UINT16);
9302 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9303         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9304                                 mirror, "mirror-rule");
9305 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9306         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9307                             rule_id, UINT8);
9308 cmdline_parse_token_string_t cmd_mirror_link_what =
9309         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9310                                 what, "uplink-mirror#downlink-mirror");
9311 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9312         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9313                                 dstpool, "dst-pool");
9314 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9315         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9316                                 dstpool_id, UINT8);
9317 cmdline_parse_token_string_t cmd_mirror_link_on =
9318         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9319                                 on, "on#off");
9320
9321 static void
9322 cmd_set_mirror_link_parsed(void *parsed_result,
9323                        __attribute__((unused)) struct cmdline *cl,
9324                        __attribute__((unused)) void *data)
9325 {
9326         int ret;
9327         struct cmd_set_mirror_link_result *res = parsed_result;
9328         struct rte_eth_mirror_conf mr_conf;
9329
9330         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9331         if (!strcmp(res->what, "uplink-mirror"))
9332                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9333         else
9334                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9335
9336         mr_conf.dst_pool = res->dstpool_id;
9337
9338         if (!strcmp(res->on, "on"))
9339                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9340                                                 res->rule_id, 1);
9341         else
9342                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9343                                                 res->rule_id, 0);
9344
9345         /* check the return value and print it if is < 0 */
9346         if (ret < 0)
9347                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9348
9349 }
9350
9351 cmdline_parse_inst_t cmd_set_mirror_link = {
9352                 .f = cmd_set_mirror_link_parsed,
9353                 .data = NULL,
9354                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9355                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9356                 .tokens = {
9357                         (void *)&cmd_mirror_link_set,
9358                         (void *)&cmd_mirror_link_port,
9359                         (void *)&cmd_mirror_link_portid,
9360                         (void *)&cmd_mirror_link_mirror,
9361                         (void *)&cmd_mirror_link_ruleid,
9362                         (void *)&cmd_mirror_link_what,
9363                         (void *)&cmd_mirror_link_dstpool,
9364                         (void *)&cmd_mirror_link_poolid,
9365                         (void *)&cmd_mirror_link_on,
9366                         NULL,
9367                 },
9368 };
9369
9370 /* *** RESET VM MIRROR RULE *** */
9371 struct cmd_rm_mirror_rule_result {
9372         cmdline_fixed_string_t reset;
9373         cmdline_fixed_string_t port;
9374         portid_t port_id;
9375         cmdline_fixed_string_t mirror;
9376         uint8_t rule_id;
9377 };
9378
9379 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9380         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9381                                  reset, "reset");
9382 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9383         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9384                                 port, "port");
9385 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9386         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9387                                 port_id, UINT16);
9388 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9389         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9390                                 mirror, "mirror-rule");
9391 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9392         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9393                                 rule_id, UINT8);
9394
9395 static void
9396 cmd_reset_mirror_rule_parsed(void *parsed_result,
9397                        __attribute__((unused)) struct cmdline *cl,
9398                        __attribute__((unused)) void *data)
9399 {
9400         int ret;
9401         struct cmd_set_mirror_link_result *res = parsed_result;
9402         /* check rule_id */
9403         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9404         if(ret < 0)
9405                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9406 }
9407
9408 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9409                 .f = cmd_reset_mirror_rule_parsed,
9410                 .data = NULL,
9411                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9412                 .tokens = {
9413                         (void *)&cmd_rm_mirror_rule_reset,
9414                         (void *)&cmd_rm_mirror_rule_port,
9415                         (void *)&cmd_rm_mirror_rule_portid,
9416                         (void *)&cmd_rm_mirror_rule_mirror,
9417                         (void *)&cmd_rm_mirror_rule_ruleid,
9418                         NULL,
9419                 },
9420 };
9421
9422 /* ******************************************************************************** */
9423
9424 struct cmd_dump_result {
9425         cmdline_fixed_string_t dump;
9426 };
9427
9428 static void
9429 dump_struct_sizes(void)
9430 {
9431 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9432         DUMP_SIZE(struct rte_mbuf);
9433         DUMP_SIZE(struct rte_mempool);
9434         DUMP_SIZE(struct rte_ring);
9435 #undef DUMP_SIZE
9436 }
9437
9438 static void cmd_dump_parsed(void *parsed_result,
9439                             __attribute__((unused)) struct cmdline *cl,
9440                             __attribute__((unused)) void *data)
9441 {
9442         struct cmd_dump_result *res = parsed_result;
9443
9444         if (!strcmp(res->dump, "dump_physmem"))
9445                 rte_dump_physmem_layout(stdout);
9446         else if (!strcmp(res->dump, "dump_memzone"))
9447                 rte_memzone_dump(stdout);
9448         else if (!strcmp(res->dump, "dump_struct_sizes"))
9449                 dump_struct_sizes();
9450         else if (!strcmp(res->dump, "dump_ring"))
9451                 rte_ring_list_dump(stdout);
9452         else if (!strcmp(res->dump, "dump_mempool"))
9453                 rte_mempool_list_dump(stdout);
9454         else if (!strcmp(res->dump, "dump_devargs"))
9455                 rte_devargs_dump(stdout);
9456         else if (!strcmp(res->dump, "dump_log_types"))
9457                 rte_log_dump(stdout);
9458 }
9459
9460 cmdline_parse_token_string_t cmd_dump_dump =
9461         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9462                 "dump_physmem#"
9463                 "dump_memzone#"
9464                 "dump_struct_sizes#"
9465                 "dump_ring#"
9466                 "dump_mempool#"
9467                 "dump_devargs#"
9468                 "dump_log_types");
9469
9470 cmdline_parse_inst_t cmd_dump = {
9471         .f = cmd_dump_parsed,  /* function to call */
9472         .data = NULL,      /* 2nd arg of func */
9473         .help_str = "Dump status",
9474         .tokens = {        /* token list, NULL terminated */
9475                 (void *)&cmd_dump_dump,
9476                 NULL,
9477         },
9478 };
9479
9480 /* ******************************************************************************** */
9481
9482 struct cmd_dump_one_result {
9483         cmdline_fixed_string_t dump;
9484         cmdline_fixed_string_t name;
9485 };
9486
9487 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9488                                 __attribute__((unused)) void *data)
9489 {
9490         struct cmd_dump_one_result *res = parsed_result;
9491
9492         if (!strcmp(res->dump, "dump_ring")) {
9493                 struct rte_ring *r;
9494                 r = rte_ring_lookup(res->name);
9495                 if (r == NULL) {
9496                         cmdline_printf(cl, "Cannot find ring\n");
9497                         return;
9498                 }
9499                 rte_ring_dump(stdout, r);
9500         } else if (!strcmp(res->dump, "dump_mempool")) {
9501                 struct rte_mempool *mp;
9502                 mp = rte_mempool_lookup(res->name);
9503                 if (mp == NULL) {
9504                         cmdline_printf(cl, "Cannot find mempool\n");
9505                         return;
9506                 }
9507                 rte_mempool_dump(stdout, mp);
9508         }
9509 }
9510
9511 cmdline_parse_token_string_t cmd_dump_one_dump =
9512         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9513                                  "dump_ring#dump_mempool");
9514
9515 cmdline_parse_token_string_t cmd_dump_one_name =
9516         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9517
9518 cmdline_parse_inst_t cmd_dump_one = {
9519         .f = cmd_dump_one_parsed,  /* function to call */
9520         .data = NULL,      /* 2nd arg of func */
9521         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9522         .tokens = {        /* token list, NULL terminated */
9523                 (void *)&cmd_dump_one_dump,
9524                 (void *)&cmd_dump_one_name,
9525                 NULL,
9526         },
9527 };
9528
9529 /* *** Add/Del syn filter *** */
9530 struct cmd_syn_filter_result {
9531         cmdline_fixed_string_t filter;
9532         portid_t port_id;
9533         cmdline_fixed_string_t ops;
9534         cmdline_fixed_string_t priority;
9535         cmdline_fixed_string_t high;
9536         cmdline_fixed_string_t queue;
9537         uint16_t queue_id;
9538 };
9539
9540 static void
9541 cmd_syn_filter_parsed(void *parsed_result,
9542                         __attribute__((unused)) struct cmdline *cl,
9543                         __attribute__((unused)) void *data)
9544 {
9545         struct cmd_syn_filter_result *res = parsed_result;
9546         struct rte_eth_syn_filter syn_filter;
9547         int ret = 0;
9548
9549         ret = rte_eth_dev_filter_supported(res->port_id,
9550                                         RTE_ETH_FILTER_SYN);
9551         if (ret < 0) {
9552                 printf("syn filter is not supported on port %u.\n",
9553                                 res->port_id);
9554                 return;
9555         }
9556
9557         memset(&syn_filter, 0, sizeof(syn_filter));
9558
9559         if (!strcmp(res->ops, "add")) {
9560                 if (!strcmp(res->high, "high"))
9561                         syn_filter.hig_pri = 1;
9562                 else
9563                         syn_filter.hig_pri = 0;
9564
9565                 syn_filter.queue = res->queue_id;
9566                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9567                                                 RTE_ETH_FILTER_SYN,
9568                                                 RTE_ETH_FILTER_ADD,
9569                                                 &syn_filter);
9570         } else
9571                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9572                                                 RTE_ETH_FILTER_SYN,
9573                                                 RTE_ETH_FILTER_DELETE,
9574                                                 &syn_filter);
9575
9576         if (ret < 0)
9577                 printf("syn filter programming error: (%s)\n",
9578                                 strerror(-ret));
9579 }
9580
9581 cmdline_parse_token_string_t cmd_syn_filter_filter =
9582         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9583         filter, "syn_filter");
9584 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9585         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9586         port_id, UINT16);
9587 cmdline_parse_token_string_t cmd_syn_filter_ops =
9588         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9589         ops, "add#del");
9590 cmdline_parse_token_string_t cmd_syn_filter_priority =
9591         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9592                                 priority, "priority");
9593 cmdline_parse_token_string_t cmd_syn_filter_high =
9594         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9595                                 high, "high#low");
9596 cmdline_parse_token_string_t cmd_syn_filter_queue =
9597         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9598                                 queue, "queue");
9599 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9600         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9601                                 queue_id, UINT16);
9602
9603 cmdline_parse_inst_t cmd_syn_filter = {
9604         .f = cmd_syn_filter_parsed,
9605         .data = NULL,
9606         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9607                 "<queue_id>: Add/Delete syn filter",
9608         .tokens = {
9609                 (void *)&cmd_syn_filter_filter,
9610                 (void *)&cmd_syn_filter_port_id,
9611                 (void *)&cmd_syn_filter_ops,
9612                 (void *)&cmd_syn_filter_priority,
9613                 (void *)&cmd_syn_filter_high,
9614                 (void *)&cmd_syn_filter_queue,
9615                 (void *)&cmd_syn_filter_queue_id,
9616                 NULL,
9617         },
9618 };
9619
9620 /* *** queue region set *** */
9621 struct cmd_queue_region_result {
9622         cmdline_fixed_string_t set;
9623         cmdline_fixed_string_t port;
9624         portid_t port_id;
9625         cmdline_fixed_string_t cmd;
9626         cmdline_fixed_string_t region;
9627         uint8_t  region_id;
9628         cmdline_fixed_string_t queue_start_index;
9629         uint8_t  queue_id;
9630         cmdline_fixed_string_t queue_num;
9631         uint8_t  queue_num_value;
9632 };
9633
9634 static void
9635 cmd_queue_region_parsed(void *parsed_result,
9636                         __attribute__((unused)) struct cmdline *cl,
9637                         __attribute__((unused)) void *data)
9638 {
9639         struct cmd_queue_region_result *res = parsed_result;
9640         int ret = -ENOTSUP;
9641 #ifdef RTE_LIBRTE_I40E_PMD
9642         struct rte_pmd_i40e_queue_region_conf region_conf;
9643         enum rte_pmd_i40e_queue_region_op op_type;
9644 #endif
9645
9646         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9647                 return;
9648
9649 #ifdef RTE_LIBRTE_I40E_PMD
9650         memset(&region_conf, 0, sizeof(region_conf));
9651         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9652         region_conf.region_id = res->region_id;
9653         region_conf.queue_num = res->queue_num_value;
9654         region_conf.queue_start_index = res->queue_id;
9655
9656         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9657                                 op_type, &region_conf);
9658 #endif
9659
9660         switch (ret) {
9661         case 0:
9662                 break;
9663         case -ENOTSUP:
9664                 printf("function not implemented or supported\n");
9665                 break;
9666         default:
9667                 printf("queue region config error: (%s)\n", strerror(-ret));
9668         }
9669 }
9670
9671 cmdline_parse_token_string_t cmd_queue_region_set =
9672 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9673                 set, "set");
9674 cmdline_parse_token_string_t cmd_queue_region_port =
9675         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9676 cmdline_parse_token_num_t cmd_queue_region_port_id =
9677         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9678                                 port_id, UINT16);
9679 cmdline_parse_token_string_t cmd_queue_region_cmd =
9680         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9681                                  cmd, "queue-region");
9682 cmdline_parse_token_string_t cmd_queue_region_id =
9683         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9684                                 region, "region_id");
9685 cmdline_parse_token_num_t cmd_queue_region_index =
9686         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9687                                 region_id, UINT8);
9688 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9689         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9690                                 queue_start_index, "queue_start_index");
9691 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9692         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9693                                 queue_id, UINT8);
9694 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9695         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9696                                 queue_num, "queue_num");
9697 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9698         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9699                                 queue_num_value, UINT8);
9700
9701 cmdline_parse_inst_t cmd_queue_region = {
9702         .f = cmd_queue_region_parsed,
9703         .data = NULL,
9704         .help_str = "set port <port_id> queue-region region_id <value> "
9705                 "queue_start_index <value> queue_num <value>: Set a queue region",
9706         .tokens = {
9707                 (void *)&cmd_queue_region_set,
9708                 (void *)&cmd_queue_region_port,
9709                 (void *)&cmd_queue_region_port_id,
9710                 (void *)&cmd_queue_region_cmd,
9711                 (void *)&cmd_queue_region_id,
9712                 (void *)&cmd_queue_region_index,
9713                 (void *)&cmd_queue_region_queue_start_index,
9714                 (void *)&cmd_queue_region_queue_id,
9715                 (void *)&cmd_queue_region_queue_num,
9716                 (void *)&cmd_queue_region_queue_num_value,
9717                 NULL,
9718         },
9719 };
9720
9721 /* *** queue region and flowtype set *** */
9722 struct cmd_region_flowtype_result {
9723         cmdline_fixed_string_t set;
9724         cmdline_fixed_string_t port;
9725         portid_t port_id;
9726         cmdline_fixed_string_t cmd;
9727         cmdline_fixed_string_t region;
9728         uint8_t  region_id;
9729         cmdline_fixed_string_t flowtype;
9730         uint8_t  flowtype_id;
9731 };
9732
9733 static void
9734 cmd_region_flowtype_parsed(void *parsed_result,
9735                         __attribute__((unused)) struct cmdline *cl,
9736                         __attribute__((unused)) void *data)
9737 {
9738         struct cmd_region_flowtype_result *res = parsed_result;
9739         int ret = -ENOTSUP;
9740 #ifdef RTE_LIBRTE_I40E_PMD
9741         struct rte_pmd_i40e_queue_region_conf region_conf;
9742         enum rte_pmd_i40e_queue_region_op op_type;
9743 #endif
9744
9745         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9746                 return;
9747
9748 #ifdef RTE_LIBRTE_I40E_PMD
9749         memset(&region_conf, 0, sizeof(region_conf));
9750
9751         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9752         region_conf.region_id = res->region_id;
9753         region_conf.hw_flowtype = res->flowtype_id;
9754
9755         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9756                         op_type, &region_conf);
9757 #endif
9758
9759         switch (ret) {
9760         case 0:
9761                 break;
9762         case -ENOTSUP:
9763                 printf("function not implemented or supported\n");
9764                 break;
9765         default:
9766                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9767         }
9768 }
9769
9770 cmdline_parse_token_string_t cmd_region_flowtype_set =
9771 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9772                                 set, "set");
9773 cmdline_parse_token_string_t cmd_region_flowtype_port =
9774         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9775                                 port, "port");
9776 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9777         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9778                                 port_id, UINT16);
9779 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9780         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9781                                 cmd, "queue-region");
9782 cmdline_parse_token_string_t cmd_region_flowtype_index =
9783         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9784                                 region, "region_id");
9785 cmdline_parse_token_num_t cmd_region_flowtype_id =
9786         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9787                                 region_id, UINT8);
9788 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9789         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9790                                 flowtype, "flowtype");
9791 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9792         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9793                                 flowtype_id, UINT8);
9794 cmdline_parse_inst_t cmd_region_flowtype = {
9795         .f = cmd_region_flowtype_parsed,
9796         .data = NULL,
9797         .help_str = "set port <port_id> queue-region region_id <value> "
9798                 "flowtype <value>: Set a flowtype region index",
9799         .tokens = {
9800                 (void *)&cmd_region_flowtype_set,
9801                 (void *)&cmd_region_flowtype_port,
9802                 (void *)&cmd_region_flowtype_port_index,
9803                 (void *)&cmd_region_flowtype_cmd,
9804                 (void *)&cmd_region_flowtype_index,
9805                 (void *)&cmd_region_flowtype_id,
9806                 (void *)&cmd_region_flowtype_flow_index,
9807                 (void *)&cmd_region_flowtype_flow_id,
9808                 NULL,
9809         },
9810 };
9811
9812 /* *** User Priority (UP) to queue region (region_id) set *** */
9813 struct cmd_user_priority_region_result {
9814         cmdline_fixed_string_t set;
9815         cmdline_fixed_string_t port;
9816         portid_t port_id;
9817         cmdline_fixed_string_t cmd;
9818         cmdline_fixed_string_t user_priority;
9819         uint8_t  user_priority_id;
9820         cmdline_fixed_string_t region;
9821         uint8_t  region_id;
9822 };
9823
9824 static void
9825 cmd_user_priority_region_parsed(void *parsed_result,
9826                         __attribute__((unused)) struct cmdline *cl,
9827                         __attribute__((unused)) void *data)
9828 {
9829         struct cmd_user_priority_region_result *res = parsed_result;
9830         int ret = -ENOTSUP;
9831 #ifdef RTE_LIBRTE_I40E_PMD
9832         struct rte_pmd_i40e_queue_region_conf region_conf;
9833         enum rte_pmd_i40e_queue_region_op op_type;
9834 #endif
9835
9836         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9837                 return;
9838
9839 #ifdef RTE_LIBRTE_I40E_PMD
9840         memset(&region_conf, 0, sizeof(region_conf));
9841         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9842         region_conf.user_priority = res->user_priority_id;
9843         region_conf.region_id = res->region_id;
9844
9845         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9846                                 op_type, &region_conf);
9847 #endif
9848
9849         switch (ret) {
9850         case 0:
9851                 break;
9852         case -ENOTSUP:
9853                 printf("function not implemented or supported\n");
9854                 break;
9855         default:
9856                 printf("user_priority region config error: (%s)\n",
9857                                 strerror(-ret));
9858         }
9859 }
9860
9861 cmdline_parse_token_string_t cmd_user_priority_region_set =
9862         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9863                                 set, "set");
9864 cmdline_parse_token_string_t cmd_user_priority_region_port =
9865         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9866                                 port, "port");
9867 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9868         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9869                                 port_id, UINT16);
9870 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9871         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9872                                 cmd, "queue-region");
9873 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9874         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9875                                 user_priority, "UP");
9876 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9877         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9878                                 user_priority_id, UINT8);
9879 cmdline_parse_token_string_t cmd_user_priority_region_region =
9880         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9881                                 region, "region_id");
9882 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9883         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9884                                 region_id, UINT8);
9885
9886 cmdline_parse_inst_t cmd_user_priority_region = {
9887         .f = cmd_user_priority_region_parsed,
9888         .data = NULL,
9889         .help_str = "set port <port_id> queue-region UP <value> "
9890                 "region_id <value>: Set the mapping of User Priority (UP) "
9891                 "to queue region (region_id) ",
9892         .tokens = {
9893                 (void *)&cmd_user_priority_region_set,
9894                 (void *)&cmd_user_priority_region_port,
9895                 (void *)&cmd_user_priority_region_port_index,
9896                 (void *)&cmd_user_priority_region_cmd,
9897                 (void *)&cmd_user_priority_region_UP,
9898                 (void *)&cmd_user_priority_region_UP_id,
9899                 (void *)&cmd_user_priority_region_region,
9900                 (void *)&cmd_user_priority_region_region_id,
9901                 NULL,
9902         },
9903 };
9904
9905 /* *** flush all queue region related configuration *** */
9906 struct cmd_flush_queue_region_result {
9907         cmdline_fixed_string_t set;
9908         cmdline_fixed_string_t port;
9909         portid_t port_id;
9910         cmdline_fixed_string_t cmd;
9911         cmdline_fixed_string_t flush;
9912         cmdline_fixed_string_t what;
9913 };
9914
9915 static void
9916 cmd_flush_queue_region_parsed(void *parsed_result,
9917                         __attribute__((unused)) struct cmdline *cl,
9918                         __attribute__((unused)) void *data)
9919 {
9920         struct cmd_flush_queue_region_result *res = parsed_result;
9921         int ret = -ENOTSUP;
9922 #ifdef RTE_LIBRTE_I40E_PMD
9923         struct rte_pmd_i40e_queue_region_conf region_conf;
9924         enum rte_pmd_i40e_queue_region_op op_type;
9925 #endif
9926
9927         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9928                 return;
9929
9930 #ifdef RTE_LIBRTE_I40E_PMD
9931         memset(&region_conf, 0, sizeof(region_conf));
9932
9933         if (strcmp(res->what, "on") == 0)
9934                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9935         else
9936                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9937
9938         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9939                                 op_type, &region_conf);
9940 #endif
9941
9942         switch (ret) {
9943         case 0:
9944                 break;
9945         case -ENOTSUP:
9946                 printf("function not implemented or supported\n");
9947                 break;
9948         default:
9949                 printf("queue region config flush error: (%s)\n",
9950                                 strerror(-ret));
9951         }
9952 }
9953
9954 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9955         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9956                                 set, "set");
9957 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9958         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9959                                 port, "port");
9960 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9961         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9962                                 port_id, UINT16);
9963 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9964         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9965                                 cmd, "queue-region");
9966 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9967         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9968                                 flush, "flush");
9969 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9970         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9971                                 what, "on#off");
9972
9973 cmdline_parse_inst_t cmd_flush_queue_region = {
9974         .f = cmd_flush_queue_region_parsed,
9975         .data = NULL,
9976         .help_str = "set port <port_id> queue-region flush on|off"
9977                 ": flush all queue region related configuration",
9978         .tokens = {
9979                 (void *)&cmd_flush_queue_region_set,
9980                 (void *)&cmd_flush_queue_region_port,
9981                 (void *)&cmd_flush_queue_region_port_index,
9982                 (void *)&cmd_flush_queue_region_cmd,
9983                 (void *)&cmd_flush_queue_region_flush,
9984                 (void *)&cmd_flush_queue_region_what,
9985                 NULL,
9986         },
9987 };
9988
9989 /* *** get all queue region related configuration info *** */
9990 struct cmd_show_queue_region_info {
9991         cmdline_fixed_string_t show;
9992         cmdline_fixed_string_t port;
9993         portid_t port_id;
9994         cmdline_fixed_string_t cmd;
9995 };
9996
9997 static void
9998 cmd_show_queue_region_info_parsed(void *parsed_result,
9999                         __attribute__((unused)) struct cmdline *cl,
10000                         __attribute__((unused)) void *data)
10001 {
10002         struct cmd_show_queue_region_info *res = parsed_result;
10003         int ret = -ENOTSUP;
10004 #ifdef RTE_LIBRTE_I40E_PMD
10005         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10006         enum rte_pmd_i40e_queue_region_op op_type;
10007 #endif
10008
10009         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10010                 return;
10011
10012 #ifdef RTE_LIBRTE_I40E_PMD
10013         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10014
10015         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10016
10017         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10018                                         op_type, &rte_pmd_regions);
10019
10020         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10021 #endif
10022
10023         switch (ret) {
10024         case 0:
10025                 break;
10026         case -ENOTSUP:
10027                 printf("function not implemented or supported\n");
10028                 break;
10029         default:
10030                 printf("queue region config info show error: (%s)\n",
10031                                 strerror(-ret));
10032         }
10033 }
10034
10035 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10036 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10037                                 show, "show");
10038 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10039         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10040                                 port, "port");
10041 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10042         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10043                                 port_id, UINT16);
10044 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10045         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10046                                 cmd, "queue-region");
10047
10048 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10049         .f = cmd_show_queue_region_info_parsed,
10050         .data = NULL,
10051         .help_str = "show port <port_id> queue-region"
10052                 ": show all queue region related configuration info",
10053         .tokens = {
10054                 (void *)&cmd_show_queue_region_info_get,
10055                 (void *)&cmd_show_queue_region_info_port,
10056                 (void *)&cmd_show_queue_region_info_port_index,
10057                 (void *)&cmd_show_queue_region_info_cmd,
10058                 NULL,
10059         },
10060 };
10061
10062 /* *** ADD/REMOVE A 2tuple FILTER *** */
10063 struct cmd_2tuple_filter_result {
10064         cmdline_fixed_string_t filter;
10065         portid_t port_id;
10066         cmdline_fixed_string_t ops;
10067         cmdline_fixed_string_t dst_port;
10068         uint16_t dst_port_value;
10069         cmdline_fixed_string_t protocol;
10070         uint8_t protocol_value;
10071         cmdline_fixed_string_t mask;
10072         uint8_t  mask_value;
10073         cmdline_fixed_string_t tcp_flags;
10074         uint8_t tcp_flags_value;
10075         cmdline_fixed_string_t priority;
10076         uint8_t  priority_value;
10077         cmdline_fixed_string_t queue;
10078         uint16_t  queue_id;
10079 };
10080
10081 static void
10082 cmd_2tuple_filter_parsed(void *parsed_result,
10083                         __attribute__((unused)) struct cmdline *cl,
10084                         __attribute__((unused)) void *data)
10085 {
10086         struct rte_eth_ntuple_filter filter;
10087         struct cmd_2tuple_filter_result *res = parsed_result;
10088         int ret = 0;
10089
10090         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10091         if (ret < 0) {
10092                 printf("ntuple filter is not supported on port %u.\n",
10093                         res->port_id);
10094                 return;
10095         }
10096
10097         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10098
10099         filter.flags = RTE_2TUPLE_FLAGS;
10100         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10101         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10102         filter.proto = res->protocol_value;
10103         filter.priority = res->priority_value;
10104         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10105                 printf("nonzero tcp_flags is only meaningful"
10106                         " when protocol is TCP.\n");
10107                 return;
10108         }
10109         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10110                 printf("invalid TCP flags.\n");
10111                 return;
10112         }
10113
10114         if (res->tcp_flags_value != 0) {
10115                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10116                 filter.tcp_flags = res->tcp_flags_value;
10117         }
10118
10119         /* need convert to big endian. */
10120         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10121         filter.queue = res->queue_id;
10122
10123         if (!strcmp(res->ops, "add"))
10124                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10125                                 RTE_ETH_FILTER_NTUPLE,
10126                                 RTE_ETH_FILTER_ADD,
10127                                 &filter);
10128         else
10129                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10130                                 RTE_ETH_FILTER_NTUPLE,
10131                                 RTE_ETH_FILTER_DELETE,
10132                                 &filter);
10133         if (ret < 0)
10134                 printf("2tuple filter programming error: (%s)\n",
10135                         strerror(-ret));
10136
10137 }
10138
10139 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10140         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10141                                  filter, "2tuple_filter");
10142 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10143         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10144                                 port_id, UINT16);
10145 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10146         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10147                                  ops, "add#del");
10148 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10149         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10150                                 dst_port, "dst_port");
10151 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10152         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10153                                 dst_port_value, UINT16);
10154 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10155         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10156                                 protocol, "protocol");
10157 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10158         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10159                                 protocol_value, UINT8);
10160 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10161         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10162                                 mask, "mask");
10163 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10164         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10165                                 mask_value, INT8);
10166 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10167         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10168                                 tcp_flags, "tcp_flags");
10169 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10170         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10171                                 tcp_flags_value, UINT8);
10172 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10173         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10174                                 priority, "priority");
10175 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10176         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10177                                 priority_value, UINT8);
10178 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10179         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10180                                 queue, "queue");
10181 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10182         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10183                                 queue_id, UINT16);
10184
10185 cmdline_parse_inst_t cmd_2tuple_filter = {
10186         .f = cmd_2tuple_filter_parsed,
10187         .data = NULL,
10188         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10189                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10190                 "<queue_id>: Add a 2tuple filter",
10191         .tokens = {
10192                 (void *)&cmd_2tuple_filter_filter,
10193                 (void *)&cmd_2tuple_filter_port_id,
10194                 (void *)&cmd_2tuple_filter_ops,
10195                 (void *)&cmd_2tuple_filter_dst_port,
10196                 (void *)&cmd_2tuple_filter_dst_port_value,
10197                 (void *)&cmd_2tuple_filter_protocol,
10198                 (void *)&cmd_2tuple_filter_protocol_value,
10199                 (void *)&cmd_2tuple_filter_mask,
10200                 (void *)&cmd_2tuple_filter_mask_value,
10201                 (void *)&cmd_2tuple_filter_tcp_flags,
10202                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10203                 (void *)&cmd_2tuple_filter_priority,
10204                 (void *)&cmd_2tuple_filter_priority_value,
10205                 (void *)&cmd_2tuple_filter_queue,
10206                 (void *)&cmd_2tuple_filter_queue_id,
10207                 NULL,
10208         },
10209 };
10210
10211 /* *** ADD/REMOVE A 5tuple FILTER *** */
10212 struct cmd_5tuple_filter_result {
10213         cmdline_fixed_string_t filter;
10214         portid_t port_id;
10215         cmdline_fixed_string_t ops;
10216         cmdline_fixed_string_t dst_ip;
10217         cmdline_ipaddr_t dst_ip_value;
10218         cmdline_fixed_string_t src_ip;
10219         cmdline_ipaddr_t src_ip_value;
10220         cmdline_fixed_string_t dst_port;
10221         uint16_t dst_port_value;
10222         cmdline_fixed_string_t src_port;
10223         uint16_t src_port_value;
10224         cmdline_fixed_string_t protocol;
10225         uint8_t protocol_value;
10226         cmdline_fixed_string_t mask;
10227         uint8_t  mask_value;
10228         cmdline_fixed_string_t tcp_flags;
10229         uint8_t tcp_flags_value;
10230         cmdline_fixed_string_t priority;
10231         uint8_t  priority_value;
10232         cmdline_fixed_string_t queue;
10233         uint16_t  queue_id;
10234 };
10235
10236 static void
10237 cmd_5tuple_filter_parsed(void *parsed_result,
10238                         __attribute__((unused)) struct cmdline *cl,
10239                         __attribute__((unused)) void *data)
10240 {
10241         struct rte_eth_ntuple_filter filter;
10242         struct cmd_5tuple_filter_result *res = parsed_result;
10243         int ret = 0;
10244
10245         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10246         if (ret < 0) {
10247                 printf("ntuple filter is not supported on port %u.\n",
10248                         res->port_id);
10249                 return;
10250         }
10251
10252         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10253
10254         filter.flags = RTE_5TUPLE_FLAGS;
10255         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10256         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10257         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10258         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10259         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10260         filter.proto = res->protocol_value;
10261         filter.priority = res->priority_value;
10262         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10263                 printf("nonzero tcp_flags is only meaningful"
10264                         " when protocol is TCP.\n");
10265                 return;
10266         }
10267         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10268                 printf("invalid TCP flags.\n");
10269                 return;
10270         }
10271
10272         if (res->tcp_flags_value != 0) {
10273                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10274                 filter.tcp_flags = res->tcp_flags_value;
10275         }
10276
10277         if (res->dst_ip_value.family == AF_INET)
10278                 /* no need to convert, already big endian. */
10279                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10280         else {
10281                 if (filter.dst_ip_mask == 0) {
10282                         printf("can not support ipv6 involved compare.\n");
10283                         return;
10284                 }
10285                 filter.dst_ip = 0;
10286         }
10287
10288         if (res->src_ip_value.family == AF_INET)
10289                 /* no need to convert, already big endian. */
10290                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10291         else {
10292                 if (filter.src_ip_mask == 0) {
10293                         printf("can not support ipv6 involved compare.\n");
10294                         return;
10295                 }
10296                 filter.src_ip = 0;
10297         }
10298         /* need convert to big endian. */
10299         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10300         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10301         filter.queue = res->queue_id;
10302
10303         if (!strcmp(res->ops, "add"))
10304                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10305                                 RTE_ETH_FILTER_NTUPLE,
10306                                 RTE_ETH_FILTER_ADD,
10307                                 &filter);
10308         else
10309                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10310                                 RTE_ETH_FILTER_NTUPLE,
10311                                 RTE_ETH_FILTER_DELETE,
10312                                 &filter);
10313         if (ret < 0)
10314                 printf("5tuple filter programming error: (%s)\n",
10315                         strerror(-ret));
10316 }
10317
10318 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10319         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10320                                  filter, "5tuple_filter");
10321 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10322         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10323                                 port_id, UINT16);
10324 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10325         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10326                                  ops, "add#del");
10327 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10328         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10329                                 dst_ip, "dst_ip");
10330 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10331         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10332                                 dst_ip_value);
10333 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10334         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10335                                 src_ip, "src_ip");
10336 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10337         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10338                                 src_ip_value);
10339 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10340         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10341                                 dst_port, "dst_port");
10342 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10343         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10344                                 dst_port_value, UINT16);
10345 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10346         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10347                                 src_port, "src_port");
10348 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10349         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10350                                 src_port_value, UINT16);
10351 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10352         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10353                                 protocol, "protocol");
10354 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10355         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10356                                 protocol_value, UINT8);
10357 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10358         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10359                                 mask, "mask");
10360 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10361         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10362                                 mask_value, INT8);
10363 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10364         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10365                                 tcp_flags, "tcp_flags");
10366 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10367         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10368                                 tcp_flags_value, UINT8);
10369 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10370         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10371                                 priority, "priority");
10372 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10373         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10374                                 priority_value, UINT8);
10375 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10376         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10377                                 queue, "queue");
10378 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10379         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10380                                 queue_id, UINT16);
10381
10382 cmdline_parse_inst_t cmd_5tuple_filter = {
10383         .f = cmd_5tuple_filter_parsed,
10384         .data = NULL,
10385         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10386                 "src_ip <value> dst_port <value> src_port <value> "
10387                 "protocol <value>  mask <value> tcp_flags <value> "
10388                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10389         .tokens = {
10390                 (void *)&cmd_5tuple_filter_filter,
10391                 (void *)&cmd_5tuple_filter_port_id,
10392                 (void *)&cmd_5tuple_filter_ops,
10393                 (void *)&cmd_5tuple_filter_dst_ip,
10394                 (void *)&cmd_5tuple_filter_dst_ip_value,
10395                 (void *)&cmd_5tuple_filter_src_ip,
10396                 (void *)&cmd_5tuple_filter_src_ip_value,
10397                 (void *)&cmd_5tuple_filter_dst_port,
10398                 (void *)&cmd_5tuple_filter_dst_port_value,
10399                 (void *)&cmd_5tuple_filter_src_port,
10400                 (void *)&cmd_5tuple_filter_src_port_value,
10401                 (void *)&cmd_5tuple_filter_protocol,
10402                 (void *)&cmd_5tuple_filter_protocol_value,
10403                 (void *)&cmd_5tuple_filter_mask,
10404                 (void *)&cmd_5tuple_filter_mask_value,
10405                 (void *)&cmd_5tuple_filter_tcp_flags,
10406                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10407                 (void *)&cmd_5tuple_filter_priority,
10408                 (void *)&cmd_5tuple_filter_priority_value,
10409                 (void *)&cmd_5tuple_filter_queue,
10410                 (void *)&cmd_5tuple_filter_queue_id,
10411                 NULL,
10412         },
10413 };
10414
10415 /* *** ADD/REMOVE A flex FILTER *** */
10416 struct cmd_flex_filter_result {
10417         cmdline_fixed_string_t filter;
10418         cmdline_fixed_string_t ops;
10419         portid_t port_id;
10420         cmdline_fixed_string_t len;
10421         uint8_t len_value;
10422         cmdline_fixed_string_t bytes;
10423         cmdline_fixed_string_t bytes_value;
10424         cmdline_fixed_string_t mask;
10425         cmdline_fixed_string_t mask_value;
10426         cmdline_fixed_string_t priority;
10427         uint8_t priority_value;
10428         cmdline_fixed_string_t queue;
10429         uint16_t queue_id;
10430 };
10431
10432 static int xdigit2val(unsigned char c)
10433 {
10434         int val;
10435         if (isdigit(c))
10436                 val = c - '0';
10437         else if (isupper(c))
10438                 val = c - 'A' + 10;
10439         else
10440                 val = c - 'a' + 10;
10441         return val;
10442 }
10443
10444 static void
10445 cmd_flex_filter_parsed(void *parsed_result,
10446                           __attribute__((unused)) struct cmdline *cl,
10447                           __attribute__((unused)) void *data)
10448 {
10449         int ret = 0;
10450         struct rte_eth_flex_filter filter;
10451         struct cmd_flex_filter_result *res = parsed_result;
10452         char *bytes_ptr, *mask_ptr;
10453         uint16_t len, i, j = 0;
10454         char c;
10455         int val;
10456         uint8_t byte = 0;
10457
10458         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10459                 printf("the len exceed the max length 128\n");
10460                 return;
10461         }
10462         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10463         filter.len = res->len_value;
10464         filter.priority = res->priority_value;
10465         filter.queue = res->queue_id;
10466         bytes_ptr = res->bytes_value;
10467         mask_ptr = res->mask_value;
10468
10469          /* translate bytes string to array. */
10470         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10471                 (bytes_ptr[1] == 'X')))
10472                 bytes_ptr += 2;
10473         len = strnlen(bytes_ptr, res->len_value * 2);
10474         if (len == 0 || (len % 8 != 0)) {
10475                 printf("please check len and bytes input\n");
10476                 return;
10477         }
10478         for (i = 0; i < len; i++) {
10479                 c = bytes_ptr[i];
10480                 if (isxdigit(c) == 0) {
10481                         /* invalid characters. */
10482                         printf("invalid input\n");
10483                         return;
10484                 }
10485                 val = xdigit2val(c);
10486                 if (i % 2) {
10487                         byte |= val;
10488                         filter.bytes[j] = byte;
10489                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10490                         j++;
10491                         byte = 0;
10492                 } else
10493                         byte |= val << 4;
10494         }
10495         printf("\n");
10496          /* translate mask string to uint8_t array. */
10497         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10498                 (mask_ptr[1] == 'X')))
10499                 mask_ptr += 2;
10500         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10501         if (len == 0) {
10502                 printf("invalid input\n");
10503                 return;
10504         }
10505         j = 0;
10506         byte = 0;
10507         for (i = 0; i < len; i++) {
10508                 c = mask_ptr[i];
10509                 if (isxdigit(c) == 0) {
10510                         /* invalid characters. */
10511                         printf("invalid input\n");
10512                         return;
10513                 }
10514                 val = xdigit2val(c);
10515                 if (i % 2) {
10516                         byte |= val;
10517                         filter.mask[j] = byte;
10518                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10519                         j++;
10520                         byte = 0;
10521                 } else
10522                         byte |= val << 4;
10523         }
10524         printf("\n");
10525
10526         if (!strcmp(res->ops, "add"))
10527                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10528                                 RTE_ETH_FILTER_FLEXIBLE,
10529                                 RTE_ETH_FILTER_ADD,
10530                                 &filter);
10531         else
10532                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10533                                 RTE_ETH_FILTER_FLEXIBLE,
10534                                 RTE_ETH_FILTER_DELETE,
10535                                 &filter);
10536
10537         if (ret < 0)
10538                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10539 }
10540
10541 cmdline_parse_token_string_t cmd_flex_filter_filter =
10542         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10543                                 filter, "flex_filter");
10544 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10545         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10546                                 port_id, UINT16);
10547 cmdline_parse_token_string_t cmd_flex_filter_ops =
10548         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10549                                 ops, "add#del");
10550 cmdline_parse_token_string_t cmd_flex_filter_len =
10551         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10552                                 len, "len");
10553 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10554         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10555                                 len_value, UINT8);
10556 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10557         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10558                                 bytes, "bytes");
10559 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10560         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10561                                 bytes_value, NULL);
10562 cmdline_parse_token_string_t cmd_flex_filter_mask =
10563         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10564                                 mask, "mask");
10565 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10566         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10567                                 mask_value, NULL);
10568 cmdline_parse_token_string_t cmd_flex_filter_priority =
10569         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10570                                 priority, "priority");
10571 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10572         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10573                                 priority_value, UINT8);
10574 cmdline_parse_token_string_t cmd_flex_filter_queue =
10575         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10576                                 queue, "queue");
10577 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10578         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10579                                 queue_id, UINT16);
10580 cmdline_parse_inst_t cmd_flex_filter = {
10581         .f = cmd_flex_filter_parsed,
10582         .data = NULL,
10583         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10584                 "<value> mask <value> priority <value> queue <queue_id>: "
10585                 "Add/Del a flex filter",
10586         .tokens = {
10587                 (void *)&cmd_flex_filter_filter,
10588                 (void *)&cmd_flex_filter_port_id,
10589                 (void *)&cmd_flex_filter_ops,
10590                 (void *)&cmd_flex_filter_len,
10591                 (void *)&cmd_flex_filter_len_value,
10592                 (void *)&cmd_flex_filter_bytes,
10593                 (void *)&cmd_flex_filter_bytes_value,
10594                 (void *)&cmd_flex_filter_mask,
10595                 (void *)&cmd_flex_filter_mask_value,
10596                 (void *)&cmd_flex_filter_priority,
10597                 (void *)&cmd_flex_filter_priority_value,
10598                 (void *)&cmd_flex_filter_queue,
10599                 (void *)&cmd_flex_filter_queue_id,
10600                 NULL,
10601         },
10602 };
10603
10604 /* *** Filters Control *** */
10605
10606 /* *** deal with ethertype filter *** */
10607 struct cmd_ethertype_filter_result {
10608         cmdline_fixed_string_t filter;
10609         portid_t port_id;
10610         cmdline_fixed_string_t ops;
10611         cmdline_fixed_string_t mac;
10612         struct rte_ether_addr mac_addr;
10613         cmdline_fixed_string_t ethertype;
10614         uint16_t ethertype_value;
10615         cmdline_fixed_string_t drop;
10616         cmdline_fixed_string_t queue;
10617         uint16_t  queue_id;
10618 };
10619
10620 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10621         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10622                                  filter, "ethertype_filter");
10623 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10624         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10625                               port_id, UINT16);
10626 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10627         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10628                                  ops, "add#del");
10629 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10630         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10631                                  mac, "mac_addr#mac_ignr");
10632 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10633         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10634                                      mac_addr);
10635 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10636         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10637                                  ethertype, "ethertype");
10638 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10639         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10640                               ethertype_value, UINT16);
10641 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10642         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10643                                  drop, "drop#fwd");
10644 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10645         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10646                                  queue, "queue");
10647 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10648         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10649                               queue_id, UINT16);
10650
10651 static void
10652 cmd_ethertype_filter_parsed(void *parsed_result,
10653                           __attribute__((unused)) struct cmdline *cl,
10654                           __attribute__((unused)) void *data)
10655 {
10656         struct cmd_ethertype_filter_result *res = parsed_result;
10657         struct rte_eth_ethertype_filter filter;
10658         int ret = 0;
10659
10660         ret = rte_eth_dev_filter_supported(res->port_id,
10661                         RTE_ETH_FILTER_ETHERTYPE);
10662         if (ret < 0) {
10663                 printf("ethertype filter is not supported on port %u.\n",
10664                         res->port_id);
10665                 return;
10666         }
10667
10668         memset(&filter, 0, sizeof(filter));
10669         if (!strcmp(res->mac, "mac_addr")) {
10670                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10671                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10672                         sizeof(struct rte_ether_addr));
10673         }
10674         if (!strcmp(res->drop, "drop"))
10675                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10676         filter.ether_type = res->ethertype_value;
10677         filter.queue = res->queue_id;
10678
10679         if (!strcmp(res->ops, "add"))
10680                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10681                                 RTE_ETH_FILTER_ETHERTYPE,
10682                                 RTE_ETH_FILTER_ADD,
10683                                 &filter);
10684         else
10685                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10686                                 RTE_ETH_FILTER_ETHERTYPE,
10687                                 RTE_ETH_FILTER_DELETE,
10688                                 &filter);
10689         if (ret < 0)
10690                 printf("ethertype filter programming error: (%s)\n",
10691                         strerror(-ret));
10692 }
10693
10694 cmdline_parse_inst_t cmd_ethertype_filter = {
10695         .f = cmd_ethertype_filter_parsed,
10696         .data = NULL,
10697         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10698                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10699                 "Add or delete an ethertype filter entry",
10700         .tokens = {
10701                 (void *)&cmd_ethertype_filter_filter,
10702                 (void *)&cmd_ethertype_filter_port_id,
10703                 (void *)&cmd_ethertype_filter_ops,
10704                 (void *)&cmd_ethertype_filter_mac,
10705                 (void *)&cmd_ethertype_filter_mac_addr,
10706                 (void *)&cmd_ethertype_filter_ethertype,
10707                 (void *)&cmd_ethertype_filter_ethertype_value,
10708                 (void *)&cmd_ethertype_filter_drop,
10709                 (void *)&cmd_ethertype_filter_queue,
10710                 (void *)&cmd_ethertype_filter_queue_id,
10711                 NULL,
10712         },
10713 };
10714
10715 /* *** deal with flow director filter *** */
10716 struct cmd_flow_director_result {
10717         cmdline_fixed_string_t flow_director_filter;
10718         portid_t port_id;
10719         cmdline_fixed_string_t mode;
10720         cmdline_fixed_string_t mode_value;
10721         cmdline_fixed_string_t ops;
10722         cmdline_fixed_string_t flow;
10723         cmdline_fixed_string_t flow_type;
10724         cmdline_fixed_string_t ether;
10725         uint16_t ether_type;
10726         cmdline_fixed_string_t src;
10727         cmdline_ipaddr_t ip_src;
10728         uint16_t port_src;
10729         cmdline_fixed_string_t dst;
10730         cmdline_ipaddr_t ip_dst;
10731         uint16_t port_dst;
10732         cmdline_fixed_string_t verify_tag;
10733         uint32_t verify_tag_value;
10734         cmdline_fixed_string_t tos;
10735         uint8_t tos_value;
10736         cmdline_fixed_string_t proto;
10737         uint8_t proto_value;
10738         cmdline_fixed_string_t ttl;
10739         uint8_t ttl_value;
10740         cmdline_fixed_string_t vlan;
10741         uint16_t vlan_value;
10742         cmdline_fixed_string_t flexbytes;
10743         cmdline_fixed_string_t flexbytes_value;
10744         cmdline_fixed_string_t pf_vf;
10745         cmdline_fixed_string_t drop;
10746         cmdline_fixed_string_t queue;
10747         uint16_t  queue_id;
10748         cmdline_fixed_string_t fd_id;
10749         uint32_t  fd_id_value;
10750         cmdline_fixed_string_t mac;
10751         struct rte_ether_addr mac_addr;
10752         cmdline_fixed_string_t tunnel;
10753         cmdline_fixed_string_t tunnel_type;
10754         cmdline_fixed_string_t tunnel_id;
10755         uint32_t tunnel_id_value;
10756         cmdline_fixed_string_t packet;
10757         char filepath[];
10758 };
10759
10760 static inline int
10761 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10762 {
10763         char s[256];
10764         const char *p, *p0 = q_arg;
10765         char *end;
10766         unsigned long int_fld;
10767         char *str_fld[max_num];
10768         int i;
10769         unsigned size;
10770         int ret = -1;
10771
10772         p = strchr(p0, '(');
10773         if (p == NULL)
10774                 return -1;
10775         ++p;
10776         p0 = strchr(p, ')');
10777         if (p0 == NULL)
10778                 return -1;
10779
10780         size = p0 - p;
10781         if (size >= sizeof(s))
10782                 return -1;
10783
10784         snprintf(s, sizeof(s), "%.*s", size, p);
10785         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10786         if (ret < 0 || ret > max_num)
10787                 return -1;
10788         for (i = 0; i < ret; i++) {
10789                 errno = 0;
10790                 int_fld = strtoul(str_fld[i], &end, 0);
10791                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10792                         return -1;
10793                 flexbytes[i] = (uint8_t)int_fld;
10794         }
10795         return ret;
10796 }
10797
10798 static uint16_t
10799 str2flowtype(char *string)
10800 {
10801         uint8_t i = 0;
10802         static const struct {
10803                 char str[32];
10804                 uint16_t type;
10805         } flowtype_str[] = {
10806                 {"raw", RTE_ETH_FLOW_RAW},
10807                 {"ipv4", RTE_ETH_FLOW_IPV4},
10808                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10809                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10810                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10811                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10812                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10813                 {"ipv6", RTE_ETH_FLOW_IPV6},
10814                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10815                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10816                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10817                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10818                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10819                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10820         };
10821
10822         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10823                 if (!strcmp(flowtype_str[i].str, string))
10824                         return flowtype_str[i].type;
10825         }
10826
10827         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10828                 return (uint16_t)atoi(string);
10829
10830         return RTE_ETH_FLOW_UNKNOWN;
10831 }
10832
10833 static enum rte_eth_fdir_tunnel_type
10834 str2fdir_tunneltype(char *string)
10835 {
10836         uint8_t i = 0;
10837
10838         static const struct {
10839                 char str[32];
10840                 enum rte_eth_fdir_tunnel_type type;
10841         } tunneltype_str[] = {
10842                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10843                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10844         };
10845
10846         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10847                 if (!strcmp(tunneltype_str[i].str, string))
10848                         return tunneltype_str[i].type;
10849         }
10850         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10851 }
10852
10853 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10854 do { \
10855         if ((ip_addr).family == AF_INET) \
10856                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10857         else { \
10858                 printf("invalid parameter.\n"); \
10859                 return; \
10860         } \
10861 } while (0)
10862
10863 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10864 do { \
10865         if ((ip_addr).family == AF_INET6) \
10866                 rte_memcpy(&(ip), \
10867                                  &((ip_addr).addr.ipv6), \
10868                                  sizeof(struct in6_addr)); \
10869         else { \
10870                 printf("invalid parameter.\n"); \
10871                 return; \
10872         } \
10873 } while (0)
10874
10875 static void
10876 cmd_flow_director_filter_parsed(void *parsed_result,
10877                           __attribute__((unused)) struct cmdline *cl,
10878                           __attribute__((unused)) void *data)
10879 {
10880         struct cmd_flow_director_result *res = parsed_result;
10881         struct rte_eth_fdir_filter entry;
10882         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10883         char *end;
10884         unsigned long vf_id;
10885         int ret = 0;
10886
10887         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10888         if (ret < 0) {
10889                 printf("flow director is not supported on port %u.\n",
10890                         res->port_id);
10891                 return;
10892         }
10893         memset(flexbytes, 0, sizeof(flexbytes));
10894         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10895
10896         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10897                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10898                         printf("Please set mode to MAC-VLAN.\n");
10899                         return;
10900                 }
10901         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10902                 if (strcmp(res->mode_value, "Tunnel")) {
10903                         printf("Please set mode to Tunnel.\n");
10904                         return;
10905                 }
10906         } else {
10907                 if (!strcmp(res->mode_value, "raw")) {
10908 #ifdef RTE_LIBRTE_I40E_PMD
10909                         struct rte_pmd_i40e_flow_type_mapping
10910                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10911                         struct rte_pmd_i40e_pkt_template_conf conf;
10912                         uint16_t flow_type = str2flowtype(res->flow_type);
10913                         uint16_t i, port = res->port_id;
10914                         uint8_t add;
10915
10916                         memset(&conf, 0, sizeof(conf));
10917
10918                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10919                                 printf("Invalid flow type specified.\n");
10920                                 return;
10921                         }
10922                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10923                                                                  mapping);
10924                         if (ret)
10925                                 return;
10926                         if (mapping[flow_type].pctype == 0ULL) {
10927                                 printf("Invalid flow type specified.\n");
10928                                 return;
10929                         }
10930                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10931                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10932                                         conf.input.pctype = i;
10933                                         break;
10934                                 }
10935                         }
10936
10937                         conf.input.packet = open_file(res->filepath,
10938                                                 &conf.input.length);
10939                         if (!conf.input.packet)
10940                                 return;
10941                         if (!strcmp(res->drop, "drop"))
10942                                 conf.action.behavior =
10943                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10944                         else
10945                                 conf.action.behavior =
10946                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10947                         conf.action.report_status =
10948                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10949                         conf.action.rx_queue = res->queue_id;
10950                         conf.soft_id = res->fd_id_value;
10951                         add  = strcmp(res->ops, "del") ? 1 : 0;
10952                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10953                                                                         &conf,
10954                                                                         add);
10955                         if (ret < 0)
10956                                 printf("flow director config error: (%s)\n",
10957                                        strerror(-ret));
10958                         close_file(conf.input.packet);
10959 #endif
10960                         return;
10961                 } else if (strcmp(res->mode_value, "IP")) {
10962                         printf("Please set mode to IP or raw.\n");
10963                         return;
10964                 }
10965                 entry.input.flow_type = str2flowtype(res->flow_type);
10966         }
10967
10968         ret = parse_flexbytes(res->flexbytes_value,
10969                                         flexbytes,
10970                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10971         if (ret < 0) {
10972                 printf("error: Cannot parse flexbytes input.\n");
10973                 return;
10974         }
10975
10976         switch (entry.input.flow_type) {
10977         case RTE_ETH_FLOW_FRAG_IPV4:
10978         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10979                 entry.input.flow.ip4_flow.proto = res->proto_value;
10980                 /* fall-through */
10981         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10982         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10983                 IPV4_ADDR_TO_UINT(res->ip_dst,
10984                         entry.input.flow.ip4_flow.dst_ip);
10985                 IPV4_ADDR_TO_UINT(res->ip_src,
10986                         entry.input.flow.ip4_flow.src_ip);
10987                 entry.input.flow.ip4_flow.tos = res->tos_value;
10988                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10989                 /* need convert to big endian. */
10990                 entry.input.flow.udp4_flow.dst_port =
10991                                 rte_cpu_to_be_16(res->port_dst);
10992                 entry.input.flow.udp4_flow.src_port =
10993                                 rte_cpu_to_be_16(res->port_src);
10994                 break;
10995         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10996                 IPV4_ADDR_TO_UINT(res->ip_dst,
10997                         entry.input.flow.sctp4_flow.ip.dst_ip);
10998                 IPV4_ADDR_TO_UINT(res->ip_src,
10999                         entry.input.flow.sctp4_flow.ip.src_ip);
11000                 entry.input.flow.ip4_flow.tos = res->tos_value;
11001                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11002                 /* need convert to big endian. */
11003                 entry.input.flow.sctp4_flow.dst_port =
11004                                 rte_cpu_to_be_16(res->port_dst);
11005                 entry.input.flow.sctp4_flow.src_port =
11006                                 rte_cpu_to_be_16(res->port_src);
11007                 entry.input.flow.sctp4_flow.verify_tag =
11008                                 rte_cpu_to_be_32(res->verify_tag_value);
11009                 break;
11010         case RTE_ETH_FLOW_FRAG_IPV6:
11011         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11012                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11013                 /* fall-through */
11014         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11015         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11016                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11017                         entry.input.flow.ipv6_flow.dst_ip);
11018                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11019                         entry.input.flow.ipv6_flow.src_ip);
11020                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11021                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11022                 /* need convert to big endian. */
11023                 entry.input.flow.udp6_flow.dst_port =
11024                                 rte_cpu_to_be_16(res->port_dst);
11025                 entry.input.flow.udp6_flow.src_port =
11026                                 rte_cpu_to_be_16(res->port_src);
11027                 break;
11028         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11029                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11030                         entry.input.flow.sctp6_flow.ip.dst_ip);
11031                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11032                         entry.input.flow.sctp6_flow.ip.src_ip);
11033                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11034                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11035                 /* need convert to big endian. */
11036                 entry.input.flow.sctp6_flow.dst_port =
11037                                 rte_cpu_to_be_16(res->port_dst);
11038                 entry.input.flow.sctp6_flow.src_port =
11039                                 rte_cpu_to_be_16(res->port_src);
11040                 entry.input.flow.sctp6_flow.verify_tag =
11041                                 rte_cpu_to_be_32(res->verify_tag_value);
11042                 break;
11043         case RTE_ETH_FLOW_L2_PAYLOAD:
11044                 entry.input.flow.l2_flow.ether_type =
11045                         rte_cpu_to_be_16(res->ether_type);
11046                 break;
11047         default:
11048                 break;
11049         }
11050
11051         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11052                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11053                                  &res->mac_addr,
11054                                  sizeof(struct rte_ether_addr));
11055
11056         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11057                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11058                                  &res->mac_addr,
11059                                  sizeof(struct rte_ether_addr));
11060                 entry.input.flow.tunnel_flow.tunnel_type =
11061                         str2fdir_tunneltype(res->tunnel_type);
11062                 entry.input.flow.tunnel_flow.tunnel_id =
11063                         rte_cpu_to_be_32(res->tunnel_id_value);
11064         }
11065
11066         rte_memcpy(entry.input.flow_ext.flexbytes,
11067                    flexbytes,
11068                    RTE_ETH_FDIR_MAX_FLEXLEN);
11069
11070         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11071
11072         entry.action.flex_off = 0;  /*use 0 by default */
11073         if (!strcmp(res->drop, "drop"))
11074                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11075         else
11076                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11077
11078         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11079             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11080                 if (!strcmp(res->pf_vf, "pf"))
11081                         entry.input.flow_ext.is_vf = 0;
11082                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11083                         struct rte_eth_dev_info dev_info;
11084
11085                         memset(&dev_info, 0, sizeof(dev_info));
11086                         rte_eth_dev_info_get(res->port_id, &dev_info);
11087                         errno = 0;
11088                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11089                         if (errno != 0 || *end != '\0' ||
11090                             vf_id >= dev_info.max_vfs) {
11091                                 printf("invalid parameter %s.\n", res->pf_vf);
11092                                 return;
11093                         }
11094                         entry.input.flow_ext.is_vf = 1;
11095                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11096                 } else {
11097                         printf("invalid parameter %s.\n", res->pf_vf);
11098                         return;
11099                 }
11100         }
11101
11102         /* set to report FD ID by default */
11103         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11104         entry.action.rx_queue = res->queue_id;
11105         entry.soft_id = res->fd_id_value;
11106         if (!strcmp(res->ops, "add"))
11107                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11108                                              RTE_ETH_FILTER_ADD, &entry);
11109         else if (!strcmp(res->ops, "del"))
11110                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11111                                              RTE_ETH_FILTER_DELETE, &entry);
11112         else
11113                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11114                                              RTE_ETH_FILTER_UPDATE, &entry);
11115         if (ret < 0)
11116                 printf("flow director programming error: (%s)\n",
11117                         strerror(-ret));
11118 }
11119
11120 cmdline_parse_token_string_t cmd_flow_director_filter =
11121         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11122                                  flow_director_filter, "flow_director_filter");
11123 cmdline_parse_token_num_t cmd_flow_director_port_id =
11124         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11125                               port_id, UINT16);
11126 cmdline_parse_token_string_t cmd_flow_director_ops =
11127         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11128                                  ops, "add#del#update");
11129 cmdline_parse_token_string_t cmd_flow_director_flow =
11130         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11131                                  flow, "flow");
11132 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11133         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11134                 flow_type, NULL);
11135 cmdline_parse_token_string_t cmd_flow_director_ether =
11136         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11137                                  ether, "ether");
11138 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11139         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11140                               ether_type, UINT16);
11141 cmdline_parse_token_string_t cmd_flow_director_src =
11142         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11143                                  src, "src");
11144 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11145         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11146                                  ip_src);
11147 cmdline_parse_token_num_t cmd_flow_director_port_src =
11148         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11149                               port_src, UINT16);
11150 cmdline_parse_token_string_t cmd_flow_director_dst =
11151         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11152                                  dst, "dst");
11153 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11154         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11155                                  ip_dst);
11156 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11157         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11158                               port_dst, UINT16);
11159 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11160         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11161                                   verify_tag, "verify_tag");
11162 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11163         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11164                               verify_tag_value, UINT32);
11165 cmdline_parse_token_string_t cmd_flow_director_tos =
11166         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11167                                  tos, "tos");
11168 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11169         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11170                               tos_value, UINT8);
11171 cmdline_parse_token_string_t cmd_flow_director_proto =
11172         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11173                                  proto, "proto");
11174 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11175         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11176                               proto_value, UINT8);
11177 cmdline_parse_token_string_t cmd_flow_director_ttl =
11178         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11179                                  ttl, "ttl");
11180 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11181         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11182                               ttl_value, UINT8);
11183 cmdline_parse_token_string_t cmd_flow_director_vlan =
11184         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11185                                  vlan, "vlan");
11186 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11187         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11188                               vlan_value, UINT16);
11189 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11190         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11191                                  flexbytes, "flexbytes");
11192 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11193         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11194                               flexbytes_value, NULL);
11195 cmdline_parse_token_string_t cmd_flow_director_drop =
11196         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11197                                  drop, "drop#fwd");
11198 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11199         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11200                               pf_vf, NULL);
11201 cmdline_parse_token_string_t cmd_flow_director_queue =
11202         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11203                                  queue, "queue");
11204 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11205         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11206                               queue_id, UINT16);
11207 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11208         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11209                                  fd_id, "fd_id");
11210 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11211         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11212                               fd_id_value, UINT32);
11213
11214 cmdline_parse_token_string_t cmd_flow_director_mode =
11215         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11216                                  mode, "mode");
11217 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11218         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11219                                  mode_value, "IP");
11220 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11221         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11222                                  mode_value, "MAC-VLAN");
11223 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11224         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11225                                  mode_value, "Tunnel");
11226 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11227         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11228                                  mode_value, "raw");
11229 cmdline_parse_token_string_t cmd_flow_director_mac =
11230         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11231                                  mac, "mac");
11232 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11233         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11234                                     mac_addr);
11235 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11236         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11237                                  tunnel, "tunnel");
11238 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11239         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11240                                  tunnel_type, "NVGRE#VxLAN");
11241 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11242         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11243                                  tunnel_id, "tunnel-id");
11244 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11245         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11246                               tunnel_id_value, UINT32);
11247 cmdline_parse_token_string_t cmd_flow_director_packet =
11248         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11249                                  packet, "packet");
11250 cmdline_parse_token_string_t cmd_flow_director_filepath =
11251         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11252                                  filepath, NULL);
11253
11254 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11255         .f = cmd_flow_director_filter_parsed,
11256         .data = NULL,
11257         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11258                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11259                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11260                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11261                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11262                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11263                 "fd_id <fd_id_value>: "
11264                 "Add or delete an ip flow director entry on NIC",
11265         .tokens = {
11266                 (void *)&cmd_flow_director_filter,
11267                 (void *)&cmd_flow_director_port_id,
11268                 (void *)&cmd_flow_director_mode,
11269                 (void *)&cmd_flow_director_mode_ip,
11270                 (void *)&cmd_flow_director_ops,
11271                 (void *)&cmd_flow_director_flow,
11272                 (void *)&cmd_flow_director_flow_type,
11273                 (void *)&cmd_flow_director_src,
11274                 (void *)&cmd_flow_director_ip_src,
11275                 (void *)&cmd_flow_director_dst,
11276                 (void *)&cmd_flow_director_ip_dst,
11277                 (void *)&cmd_flow_director_tos,
11278                 (void *)&cmd_flow_director_tos_value,
11279                 (void *)&cmd_flow_director_proto,
11280                 (void *)&cmd_flow_director_proto_value,
11281                 (void *)&cmd_flow_director_ttl,
11282                 (void *)&cmd_flow_director_ttl_value,
11283                 (void *)&cmd_flow_director_vlan,
11284                 (void *)&cmd_flow_director_vlan_value,
11285                 (void *)&cmd_flow_director_flexbytes,
11286                 (void *)&cmd_flow_director_flexbytes_value,
11287                 (void *)&cmd_flow_director_drop,
11288                 (void *)&cmd_flow_director_pf_vf,
11289                 (void *)&cmd_flow_director_queue,
11290                 (void *)&cmd_flow_director_queue_id,
11291                 (void *)&cmd_flow_director_fd_id,
11292                 (void *)&cmd_flow_director_fd_id_value,
11293                 NULL,
11294         },
11295 };
11296
11297 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11298         .f = cmd_flow_director_filter_parsed,
11299         .data = NULL,
11300         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11301                 "director entry on NIC",
11302         .tokens = {
11303                 (void *)&cmd_flow_director_filter,
11304                 (void *)&cmd_flow_director_port_id,
11305                 (void *)&cmd_flow_director_mode,
11306                 (void *)&cmd_flow_director_mode_ip,
11307                 (void *)&cmd_flow_director_ops,
11308                 (void *)&cmd_flow_director_flow,
11309                 (void *)&cmd_flow_director_flow_type,
11310                 (void *)&cmd_flow_director_src,
11311                 (void *)&cmd_flow_director_ip_src,
11312                 (void *)&cmd_flow_director_port_src,
11313                 (void *)&cmd_flow_director_dst,
11314                 (void *)&cmd_flow_director_ip_dst,
11315                 (void *)&cmd_flow_director_port_dst,
11316                 (void *)&cmd_flow_director_tos,
11317                 (void *)&cmd_flow_director_tos_value,
11318                 (void *)&cmd_flow_director_ttl,
11319                 (void *)&cmd_flow_director_ttl_value,
11320                 (void *)&cmd_flow_director_vlan,
11321                 (void *)&cmd_flow_director_vlan_value,
11322                 (void *)&cmd_flow_director_flexbytes,
11323                 (void *)&cmd_flow_director_flexbytes_value,
11324                 (void *)&cmd_flow_director_drop,
11325                 (void *)&cmd_flow_director_pf_vf,
11326                 (void *)&cmd_flow_director_queue,
11327                 (void *)&cmd_flow_director_queue_id,
11328                 (void *)&cmd_flow_director_fd_id,
11329                 (void *)&cmd_flow_director_fd_id_value,
11330                 NULL,
11331         },
11332 };
11333
11334 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11335         .f = cmd_flow_director_filter_parsed,
11336         .data = NULL,
11337         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11338                 "director entry on NIC",
11339         .tokens = {
11340                 (void *)&cmd_flow_director_filter,
11341                 (void *)&cmd_flow_director_port_id,
11342                 (void *)&cmd_flow_director_mode,
11343                 (void *)&cmd_flow_director_mode_ip,
11344                 (void *)&cmd_flow_director_ops,
11345                 (void *)&cmd_flow_director_flow,
11346                 (void *)&cmd_flow_director_flow_type,
11347                 (void *)&cmd_flow_director_src,
11348                 (void *)&cmd_flow_director_ip_src,
11349                 (void *)&cmd_flow_director_port_src,
11350                 (void *)&cmd_flow_director_dst,
11351                 (void *)&cmd_flow_director_ip_dst,
11352                 (void *)&cmd_flow_director_port_dst,
11353                 (void *)&cmd_flow_director_verify_tag,
11354                 (void *)&cmd_flow_director_verify_tag_value,
11355                 (void *)&cmd_flow_director_tos,
11356                 (void *)&cmd_flow_director_tos_value,
11357                 (void *)&cmd_flow_director_ttl,
11358                 (void *)&cmd_flow_director_ttl_value,
11359                 (void *)&cmd_flow_director_vlan,
11360                 (void *)&cmd_flow_director_vlan_value,
11361                 (void *)&cmd_flow_director_flexbytes,
11362                 (void *)&cmd_flow_director_flexbytes_value,
11363                 (void *)&cmd_flow_director_drop,
11364                 (void *)&cmd_flow_director_pf_vf,
11365                 (void *)&cmd_flow_director_queue,
11366                 (void *)&cmd_flow_director_queue_id,
11367                 (void *)&cmd_flow_director_fd_id,
11368                 (void *)&cmd_flow_director_fd_id_value,
11369                 NULL,
11370         },
11371 };
11372
11373 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11374         .f = cmd_flow_director_filter_parsed,
11375         .data = NULL,
11376         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11377                 "director entry on NIC",
11378         .tokens = {
11379                 (void *)&cmd_flow_director_filter,
11380                 (void *)&cmd_flow_director_port_id,
11381                 (void *)&cmd_flow_director_mode,
11382                 (void *)&cmd_flow_director_mode_ip,
11383                 (void *)&cmd_flow_director_ops,
11384                 (void *)&cmd_flow_director_flow,
11385                 (void *)&cmd_flow_director_flow_type,
11386                 (void *)&cmd_flow_director_ether,
11387                 (void *)&cmd_flow_director_ether_type,
11388                 (void *)&cmd_flow_director_flexbytes,
11389                 (void *)&cmd_flow_director_flexbytes_value,
11390                 (void *)&cmd_flow_director_drop,
11391                 (void *)&cmd_flow_director_pf_vf,
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_mac_vlan_flow_director = {
11401         .f = cmd_flow_director_filter_parsed,
11402         .data = NULL,
11403         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN 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_mac_vlan,
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_flexbytes,
11416                 (void *)&cmd_flow_director_flexbytes_value,
11417                 (void *)&cmd_flow_director_drop,
11418                 (void *)&cmd_flow_director_queue,
11419                 (void *)&cmd_flow_director_queue_id,
11420                 (void *)&cmd_flow_director_fd_id,
11421                 (void *)&cmd_flow_director_fd_id_value,
11422                 NULL,
11423         },
11424 };
11425
11426 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11427         .f = cmd_flow_director_filter_parsed,
11428         .data = NULL,
11429         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11430                 "director entry on NIC",
11431         .tokens = {
11432                 (void *)&cmd_flow_director_filter,
11433                 (void *)&cmd_flow_director_port_id,
11434                 (void *)&cmd_flow_director_mode,
11435                 (void *)&cmd_flow_director_mode_tunnel,
11436                 (void *)&cmd_flow_director_ops,
11437                 (void *)&cmd_flow_director_mac,
11438                 (void *)&cmd_flow_director_mac_addr,
11439                 (void *)&cmd_flow_director_vlan,
11440                 (void *)&cmd_flow_director_vlan_value,
11441                 (void *)&cmd_flow_director_tunnel,
11442                 (void *)&cmd_flow_director_tunnel_type,
11443                 (void *)&cmd_flow_director_tunnel_id,
11444                 (void *)&cmd_flow_director_tunnel_id_value,
11445                 (void *)&cmd_flow_director_flexbytes,
11446                 (void *)&cmd_flow_director_flexbytes_value,
11447                 (void *)&cmd_flow_director_drop,
11448                 (void *)&cmd_flow_director_queue,
11449                 (void *)&cmd_flow_director_queue_id,
11450                 (void *)&cmd_flow_director_fd_id,
11451                 (void *)&cmd_flow_director_fd_id_value,
11452                 NULL,
11453         },
11454 };
11455
11456 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11457         .f = cmd_flow_director_filter_parsed,
11458         .data = NULL,
11459         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11460                 "director entry on NIC",
11461         .tokens = {
11462                 (void *)&cmd_flow_director_filter,
11463                 (void *)&cmd_flow_director_port_id,
11464                 (void *)&cmd_flow_director_mode,
11465                 (void *)&cmd_flow_director_mode_raw,
11466                 (void *)&cmd_flow_director_ops,
11467                 (void *)&cmd_flow_director_flow,
11468                 (void *)&cmd_flow_director_flow_type,
11469                 (void *)&cmd_flow_director_drop,
11470                 (void *)&cmd_flow_director_queue,
11471                 (void *)&cmd_flow_director_queue_id,
11472                 (void *)&cmd_flow_director_fd_id,
11473                 (void *)&cmd_flow_director_fd_id_value,
11474                 (void *)&cmd_flow_director_packet,
11475                 (void *)&cmd_flow_director_filepath,
11476                 NULL,
11477         },
11478 };
11479
11480 struct cmd_flush_flow_director_result {
11481         cmdline_fixed_string_t flush_flow_director;
11482         portid_t port_id;
11483 };
11484
11485 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11486         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11487                                  flush_flow_director, "flush_flow_director");
11488 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11489         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11490                               port_id, UINT16);
11491
11492 static void
11493 cmd_flush_flow_director_parsed(void *parsed_result,
11494                           __attribute__((unused)) struct cmdline *cl,
11495                           __attribute__((unused)) void *data)
11496 {
11497         struct cmd_flow_director_result *res = parsed_result;
11498         int ret = 0;
11499
11500         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11501         if (ret < 0) {
11502                 printf("flow director is not supported on port %u.\n",
11503                         res->port_id);
11504                 return;
11505         }
11506
11507         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11508                         RTE_ETH_FILTER_FLUSH, NULL);
11509         if (ret < 0)
11510                 printf("flow director table flushing error: (%s)\n",
11511                         strerror(-ret));
11512 }
11513
11514 cmdline_parse_inst_t cmd_flush_flow_director = {
11515         .f = cmd_flush_flow_director_parsed,
11516         .data = NULL,
11517         .help_str = "flush_flow_director <port_id>: "
11518                 "Flush all flow director entries of a device on NIC",
11519         .tokens = {
11520                 (void *)&cmd_flush_flow_director_flush,
11521                 (void *)&cmd_flush_flow_director_port_id,
11522                 NULL,
11523         },
11524 };
11525
11526 /* *** deal with flow director mask *** */
11527 struct cmd_flow_director_mask_result {
11528         cmdline_fixed_string_t flow_director_mask;
11529         portid_t port_id;
11530         cmdline_fixed_string_t mode;
11531         cmdline_fixed_string_t mode_value;
11532         cmdline_fixed_string_t vlan;
11533         uint16_t vlan_mask;
11534         cmdline_fixed_string_t src_mask;
11535         cmdline_ipaddr_t ipv4_src;
11536         cmdline_ipaddr_t ipv6_src;
11537         uint16_t port_src;
11538         cmdline_fixed_string_t dst_mask;
11539         cmdline_ipaddr_t ipv4_dst;
11540         cmdline_ipaddr_t ipv6_dst;
11541         uint16_t port_dst;
11542         cmdline_fixed_string_t mac;
11543         uint8_t mac_addr_byte_mask;
11544         cmdline_fixed_string_t tunnel_id;
11545         uint32_t tunnel_id_mask;
11546         cmdline_fixed_string_t tunnel_type;
11547         uint8_t tunnel_type_mask;
11548 };
11549
11550 static void
11551 cmd_flow_director_mask_parsed(void *parsed_result,
11552                           __attribute__((unused)) struct cmdline *cl,
11553                           __attribute__((unused)) void *data)
11554 {
11555         struct cmd_flow_director_mask_result *res = parsed_result;
11556         struct rte_eth_fdir_masks *mask;
11557         struct rte_port *port;
11558
11559         port = &ports[res->port_id];
11560         /** Check if the port is not started **/
11561         if (port->port_status != RTE_PORT_STOPPED) {
11562                 printf("Please stop port %d first\n", res->port_id);
11563                 return;
11564         }
11565
11566         mask = &port->dev_conf.fdir_conf.mask;
11567
11568         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11569                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11570                         printf("Please set mode to MAC-VLAN.\n");
11571                         return;
11572                 }
11573
11574                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11575         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11576                 if (strcmp(res->mode_value, "Tunnel")) {
11577                         printf("Please set mode to Tunnel.\n");
11578                         return;
11579                 }
11580
11581                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11582                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11583                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11584                 mask->tunnel_type_mask = res->tunnel_type_mask;
11585         } else {
11586                 if (strcmp(res->mode_value, "IP")) {
11587                         printf("Please set mode to IP.\n");
11588                         return;
11589                 }
11590
11591                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11592                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11593                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11594                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11595                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11596                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11597                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11598         }
11599
11600         cmd_reconfig_device_queue(res->port_id, 1, 1);
11601 }
11602
11603 cmdline_parse_token_string_t cmd_flow_director_mask =
11604         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11605                                  flow_director_mask, "flow_director_mask");
11606 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11607         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11608                               port_id, UINT16);
11609 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11610         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11611                                  vlan, "vlan");
11612 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11613         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11614                               vlan_mask, UINT16);
11615 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11616         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11617                                  src_mask, "src_mask");
11618 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11619         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11620                                  ipv4_src);
11621 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11622         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11623                                  ipv6_src);
11624 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11625         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11626                               port_src, UINT16);
11627 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11628         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11629                                  dst_mask, "dst_mask");
11630 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11631         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11632                                  ipv4_dst);
11633 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11634         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11635                                  ipv6_dst);
11636 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11637         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11638                               port_dst, UINT16);
11639
11640 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11641         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11642                                  mode, "mode");
11643 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11644         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11645                                  mode_value, "IP");
11646 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11647         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11648                                  mode_value, "MAC-VLAN");
11649 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11650         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11651                                  mode_value, "Tunnel");
11652 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11653         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11654                                  mac, "mac");
11655 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11656         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11657                               mac_addr_byte_mask, UINT8);
11658 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11659         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11660                                  tunnel_type, "tunnel-type");
11661 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11662         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11663                               tunnel_type_mask, UINT8);
11664 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11665         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11666                                  tunnel_id, "tunnel-id");
11667 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11668         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11669                               tunnel_id_mask, UINT32);
11670
11671 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11672         .f = cmd_flow_director_mask_parsed,
11673         .data = NULL,
11674         .help_str = "flow_director_mask ... : "
11675                 "Set IP mode flow director's mask on NIC",
11676         .tokens = {
11677                 (void *)&cmd_flow_director_mask,
11678                 (void *)&cmd_flow_director_mask_port_id,
11679                 (void *)&cmd_flow_director_mask_mode,
11680                 (void *)&cmd_flow_director_mask_mode_ip,
11681                 (void *)&cmd_flow_director_mask_vlan,
11682                 (void *)&cmd_flow_director_mask_vlan_value,
11683                 (void *)&cmd_flow_director_mask_src,
11684                 (void *)&cmd_flow_director_mask_ipv4_src,
11685                 (void *)&cmd_flow_director_mask_ipv6_src,
11686                 (void *)&cmd_flow_director_mask_port_src,
11687                 (void *)&cmd_flow_director_mask_dst,
11688                 (void *)&cmd_flow_director_mask_ipv4_dst,
11689                 (void *)&cmd_flow_director_mask_ipv6_dst,
11690                 (void *)&cmd_flow_director_mask_port_dst,
11691                 NULL,
11692         },
11693 };
11694
11695 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11696         .f = cmd_flow_director_mask_parsed,
11697         .data = NULL,
11698         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11699                 "flow director's mask on NIC",
11700         .tokens = {
11701                 (void *)&cmd_flow_director_mask,
11702                 (void *)&cmd_flow_director_mask_port_id,
11703                 (void *)&cmd_flow_director_mask_mode,
11704                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11705                 (void *)&cmd_flow_director_mask_vlan,
11706                 (void *)&cmd_flow_director_mask_vlan_value,
11707                 NULL,
11708         },
11709 };
11710
11711 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11712         .f = cmd_flow_director_mask_parsed,
11713         .data = NULL,
11714         .help_str = "flow_director_mask ... : Set tunnel mode "
11715                 "flow director's mask on NIC",
11716         .tokens = {
11717                 (void *)&cmd_flow_director_mask,
11718                 (void *)&cmd_flow_director_mask_port_id,
11719                 (void *)&cmd_flow_director_mask_mode,
11720                 (void *)&cmd_flow_director_mask_mode_tunnel,
11721                 (void *)&cmd_flow_director_mask_vlan,
11722                 (void *)&cmd_flow_director_mask_vlan_value,
11723                 (void *)&cmd_flow_director_mask_mac,
11724                 (void *)&cmd_flow_director_mask_mac_value,
11725                 (void *)&cmd_flow_director_mask_tunnel_type,
11726                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11727                 (void *)&cmd_flow_director_mask_tunnel_id,
11728                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11729                 NULL,
11730         },
11731 };
11732
11733 /* *** deal with flow director mask on flexible payload *** */
11734 struct cmd_flow_director_flex_mask_result {
11735         cmdline_fixed_string_t flow_director_flexmask;
11736         portid_t port_id;
11737         cmdline_fixed_string_t flow;
11738         cmdline_fixed_string_t flow_type;
11739         cmdline_fixed_string_t mask;
11740 };
11741
11742 static void
11743 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11744                           __attribute__((unused)) struct cmdline *cl,
11745                           __attribute__((unused)) void *data)
11746 {
11747         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11748         struct rte_eth_fdir_info fdir_info;
11749         struct rte_eth_fdir_flex_mask flex_mask;
11750         struct rte_port *port;
11751         uint64_t flow_type_mask;
11752         uint16_t i;
11753         int ret;
11754
11755         port = &ports[res->port_id];
11756         /** Check if the port is not started **/
11757         if (port->port_status != RTE_PORT_STOPPED) {
11758                 printf("Please stop port %d first\n", res->port_id);
11759                 return;
11760         }
11761
11762         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11763         ret = parse_flexbytes(res->mask,
11764                         flex_mask.mask,
11765                         RTE_ETH_FDIR_MAX_FLEXLEN);
11766         if (ret < 0) {
11767                 printf("error: Cannot parse mask input.\n");
11768                 return;
11769         }
11770
11771         memset(&fdir_info, 0, sizeof(fdir_info));
11772         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11773                                 RTE_ETH_FILTER_INFO, &fdir_info);
11774         if (ret < 0) {
11775                 printf("Cannot get FDir filter info\n");
11776                 return;
11777         }
11778
11779         if (!strcmp(res->flow_type, "none")) {
11780                 /* means don't specify the flow type */
11781                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11782                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11783                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11784                                0, sizeof(struct rte_eth_fdir_flex_mask));
11785                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11786                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11787                                  &flex_mask,
11788                                  sizeof(struct rte_eth_fdir_flex_mask));
11789                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11790                 return;
11791         }
11792         flow_type_mask = fdir_info.flow_types_mask[0];
11793         if (!strcmp(res->flow_type, "all")) {
11794                 if (!flow_type_mask) {
11795                         printf("No flow type supported\n");
11796                         return;
11797                 }
11798                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11799                         if (flow_type_mask & (1ULL << i)) {
11800                                 flex_mask.flow_type = i;
11801                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11802                         }
11803                 }
11804                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11805                 return;
11806         }
11807         flex_mask.flow_type = str2flowtype(res->flow_type);
11808         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11809                 printf("Flow type %s not supported on port %d\n",
11810                                 res->flow_type, res->port_id);
11811                 return;
11812         }
11813         fdir_set_flex_mask(res->port_id, &flex_mask);
11814         cmd_reconfig_device_queue(res->port_id, 1, 1);
11815 }
11816
11817 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11818         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11819                                  flow_director_flexmask,
11820                                  "flow_director_flex_mask");
11821 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11822         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11823                               port_id, UINT16);
11824 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11825         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11826                                  flow, "flow");
11827 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11828         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11829                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11830                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11831 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11832         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11833                                  mask, NULL);
11834
11835 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11836         .f = cmd_flow_director_flex_mask_parsed,
11837         .data = NULL,
11838         .help_str = "flow_director_flex_mask ... : "
11839                 "Set flow director's flex mask on NIC",
11840         .tokens = {
11841                 (void *)&cmd_flow_director_flexmask,
11842                 (void *)&cmd_flow_director_flexmask_port_id,
11843                 (void *)&cmd_flow_director_flexmask_flow,
11844                 (void *)&cmd_flow_director_flexmask_flow_type,
11845                 (void *)&cmd_flow_director_flexmask_mask,
11846                 NULL,
11847         },
11848 };
11849
11850 /* *** deal with flow director flexible payload configuration *** */
11851 struct cmd_flow_director_flexpayload_result {
11852         cmdline_fixed_string_t flow_director_flexpayload;
11853         portid_t port_id;
11854         cmdline_fixed_string_t payload_layer;
11855         cmdline_fixed_string_t payload_cfg;
11856 };
11857
11858 static inline int
11859 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11860 {
11861         char s[256];
11862         const char *p, *p0 = q_arg;
11863         char *end;
11864         unsigned long int_fld;
11865         char *str_fld[max_num];
11866         int i;
11867         unsigned size;
11868         int ret = -1;
11869
11870         p = strchr(p0, '(');
11871         if (p == NULL)
11872                 return -1;
11873         ++p;
11874         p0 = strchr(p, ')');
11875         if (p0 == NULL)
11876                 return -1;
11877
11878         size = p0 - p;
11879         if (size >= sizeof(s))
11880                 return -1;
11881
11882         snprintf(s, sizeof(s), "%.*s", size, p);
11883         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11884         if (ret < 0 || ret > max_num)
11885                 return -1;
11886         for (i = 0; i < ret; i++) {
11887                 errno = 0;
11888                 int_fld = strtoul(str_fld[i], &end, 0);
11889                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11890                         return -1;
11891                 offsets[i] = (uint16_t)int_fld;
11892         }
11893         return ret;
11894 }
11895
11896 static void
11897 cmd_flow_director_flxpld_parsed(void *parsed_result,
11898                           __attribute__((unused)) struct cmdline *cl,
11899                           __attribute__((unused)) void *data)
11900 {
11901         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11902         struct rte_eth_flex_payload_cfg flex_cfg;
11903         struct rte_port *port;
11904         int ret = 0;
11905
11906         port = &ports[res->port_id];
11907         /** Check if the port is not started **/
11908         if (port->port_status != RTE_PORT_STOPPED) {
11909                 printf("Please stop port %d first\n", res->port_id);
11910                 return;
11911         }
11912
11913         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11914
11915         if (!strcmp(res->payload_layer, "raw"))
11916                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11917         else if (!strcmp(res->payload_layer, "l2"))
11918                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11919         else if (!strcmp(res->payload_layer, "l3"))
11920                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11921         else if (!strcmp(res->payload_layer, "l4"))
11922                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11923
11924         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11925                             RTE_ETH_FDIR_MAX_FLEXLEN);
11926         if (ret < 0) {
11927                 printf("error: Cannot parse flex payload input.\n");
11928                 return;
11929         }
11930
11931         fdir_set_flex_payload(res->port_id, &flex_cfg);
11932         cmd_reconfig_device_queue(res->port_id, 1, 1);
11933 }
11934
11935 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11936         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11937                                  flow_director_flexpayload,
11938                                  "flow_director_flex_payload");
11939 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11940         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11941                               port_id, UINT16);
11942 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11943         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11944                                  payload_layer, "raw#l2#l3#l4");
11945 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11946         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11947                                  payload_cfg, NULL);
11948
11949 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11950         .f = cmd_flow_director_flxpld_parsed,
11951         .data = NULL,
11952         .help_str = "flow_director_flexpayload ... : "
11953                 "Set flow director's flex payload on NIC",
11954         .tokens = {
11955                 (void *)&cmd_flow_director_flexpayload,
11956                 (void *)&cmd_flow_director_flexpayload_port_id,
11957                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11958                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11959                 NULL,
11960         },
11961 };
11962
11963 /* Generic flow interface command. */
11964 extern cmdline_parse_inst_t cmd_flow;
11965
11966 /* *** Classification Filters Control *** */
11967 /* *** Get symmetric hash enable per port *** */
11968 struct cmd_get_sym_hash_ena_per_port_result {
11969         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11970         portid_t port_id;
11971 };
11972
11973 static void
11974 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11975                                  __rte_unused struct cmdline *cl,
11976                                  __rte_unused void *data)
11977 {
11978         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11979         struct rte_eth_hash_filter_info info;
11980         int ret;
11981
11982         if (rte_eth_dev_filter_supported(res->port_id,
11983                                 RTE_ETH_FILTER_HASH) < 0) {
11984                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11985                                                         res->port_id);
11986                 return;
11987         }
11988
11989         memset(&info, 0, sizeof(info));
11990         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11991         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11992                                                 RTE_ETH_FILTER_GET, &info);
11993
11994         if (ret < 0) {
11995                 printf("Cannot get symmetric hash enable per port "
11996                                         "on port %u\n", res->port_id);
11997                 return;
11998         }
11999
12000         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12001                                 "enabled" : "disabled", res->port_id);
12002 }
12003
12004 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12005         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12006                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12007 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12008         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12009                 port_id, UINT16);
12010
12011 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12012         .f = cmd_get_sym_hash_per_port_parsed,
12013         .data = NULL,
12014         .help_str = "get_sym_hash_ena_per_port <port_id>",
12015         .tokens = {
12016                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12017                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12018                 NULL,
12019         },
12020 };
12021
12022 /* *** Set symmetric hash enable per port *** */
12023 struct cmd_set_sym_hash_ena_per_port_result {
12024         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12025         cmdline_fixed_string_t enable;
12026         portid_t port_id;
12027 };
12028
12029 static void
12030 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12031                                  __rte_unused struct cmdline *cl,
12032                                  __rte_unused void *data)
12033 {
12034         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12035         struct rte_eth_hash_filter_info info;
12036         int ret;
12037
12038         if (rte_eth_dev_filter_supported(res->port_id,
12039                                 RTE_ETH_FILTER_HASH) < 0) {
12040                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12041                                                         res->port_id);
12042                 return;
12043         }
12044
12045         memset(&info, 0, sizeof(info));
12046         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12047         if (!strcmp(res->enable, "enable"))
12048                 info.info.enable = 1;
12049         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12050                                         RTE_ETH_FILTER_SET, &info);
12051         if (ret < 0) {
12052                 printf("Cannot set symmetric hash enable per port on "
12053                                         "port %u\n", res->port_id);
12054                 return;
12055         }
12056         printf("Symmetric hash has been set to %s on port %u\n",
12057                                         res->enable, res->port_id);
12058 }
12059
12060 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12061         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12062                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12063 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12064         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12065                 port_id, UINT16);
12066 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12067         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12068                 enable, "enable#disable");
12069
12070 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12071         .f = cmd_set_sym_hash_per_port_parsed,
12072         .data = NULL,
12073         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12074         .tokens = {
12075                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12076                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12077                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12078                 NULL,
12079         },
12080 };
12081
12082 /* Get global config of hash function */
12083 struct cmd_get_hash_global_config_result {
12084         cmdline_fixed_string_t get_hash_global_config;
12085         portid_t port_id;
12086 };
12087
12088 static char *
12089 flowtype_to_str(uint16_t ftype)
12090 {
12091         uint16_t i;
12092         static struct {
12093                 char str[16];
12094                 uint16_t ftype;
12095         } ftype_table[] = {
12096                 {"ipv4", RTE_ETH_FLOW_IPV4},
12097                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12098                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12099                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12100                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12101                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12102                 {"ipv6", RTE_ETH_FLOW_IPV6},
12103                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12104                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12105                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12106                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12107                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12108                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12109                 {"port", RTE_ETH_FLOW_PORT},
12110                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12111                 {"geneve", RTE_ETH_FLOW_GENEVE},
12112                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12113                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12114         };
12115
12116         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12117                 if (ftype_table[i].ftype == ftype)
12118                         return ftype_table[i].str;
12119         }
12120
12121         return NULL;
12122 }
12123
12124 static void
12125 cmd_get_hash_global_config_parsed(void *parsed_result,
12126                                   __rte_unused struct cmdline *cl,
12127                                   __rte_unused void *data)
12128 {
12129         struct cmd_get_hash_global_config_result *res = parsed_result;
12130         struct rte_eth_hash_filter_info info;
12131         uint32_t idx, offset;
12132         uint16_t i;
12133         char *str;
12134         int ret;
12135
12136         if (rte_eth_dev_filter_supported(res->port_id,
12137                         RTE_ETH_FILTER_HASH) < 0) {
12138                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12139                                                         res->port_id);
12140                 return;
12141         }
12142
12143         memset(&info, 0, sizeof(info));
12144         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12145         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12146                                         RTE_ETH_FILTER_GET, &info);
12147         if (ret < 0) {
12148                 printf("Cannot get hash global configurations by port %d\n",
12149                                                         res->port_id);
12150                 return;
12151         }
12152
12153         switch (info.info.global_conf.hash_func) {
12154         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12155                 printf("Hash function is Toeplitz\n");
12156                 break;
12157         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12158                 printf("Hash function is Simple XOR\n");
12159                 break;
12160         default:
12161                 printf("Unknown hash function\n");
12162                 break;
12163         }
12164
12165         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12166                 idx = i / UINT64_BIT;
12167                 offset = i % UINT64_BIT;
12168                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12169                                                 (1ULL << offset)))
12170                         continue;
12171                 str = flowtype_to_str(i);
12172                 if (!str)
12173                         continue;
12174                 printf("Symmetric hash is %s globally for flow type %s "
12175                                                         "by port %d\n",
12176                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12177                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12178                                                         res->port_id);
12179         }
12180 }
12181
12182 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12183         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12184                 get_hash_global_config, "get_hash_global_config");
12185 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12186         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12187                 port_id, UINT16);
12188
12189 cmdline_parse_inst_t cmd_get_hash_global_config = {
12190         .f = cmd_get_hash_global_config_parsed,
12191         .data = NULL,
12192         .help_str = "get_hash_global_config <port_id>",
12193         .tokens = {
12194                 (void *)&cmd_get_hash_global_config_all,
12195                 (void *)&cmd_get_hash_global_config_port_id,
12196                 NULL,
12197         },
12198 };
12199
12200 /* Set global config of hash function */
12201 struct cmd_set_hash_global_config_result {
12202         cmdline_fixed_string_t set_hash_global_config;
12203         portid_t port_id;
12204         cmdline_fixed_string_t hash_func;
12205         cmdline_fixed_string_t flow_type;
12206         cmdline_fixed_string_t enable;
12207 };
12208
12209 static void
12210 cmd_set_hash_global_config_parsed(void *parsed_result,
12211                                   __rte_unused struct cmdline *cl,
12212                                   __rte_unused void *data)
12213 {
12214         struct cmd_set_hash_global_config_result *res = parsed_result;
12215         struct rte_eth_hash_filter_info info;
12216         uint32_t ftype, idx, offset;
12217         int ret;
12218
12219         if (rte_eth_dev_filter_supported(res->port_id,
12220                                 RTE_ETH_FILTER_HASH) < 0) {
12221                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12222                                                         res->port_id);
12223                 return;
12224         }
12225         memset(&info, 0, sizeof(info));
12226         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12227         if (!strcmp(res->hash_func, "toeplitz"))
12228                 info.info.global_conf.hash_func =
12229                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12230         else if (!strcmp(res->hash_func, "simple_xor"))
12231                 info.info.global_conf.hash_func =
12232                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12233         else if (!strcmp(res->hash_func, "default"))
12234                 info.info.global_conf.hash_func =
12235                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12236
12237         ftype = str2flowtype(res->flow_type);
12238         idx = ftype / UINT64_BIT;
12239         offset = ftype % UINT64_BIT;
12240         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12241         if (!strcmp(res->enable, "enable"))
12242                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12243                                                 (1ULL << offset);
12244         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12245                                         RTE_ETH_FILTER_SET, &info);
12246         if (ret < 0)
12247                 printf("Cannot set global hash configurations by port %d\n",
12248                                                         res->port_id);
12249         else
12250                 printf("Global hash configurations have been set "
12251                         "successfully by port %d\n", res->port_id);
12252 }
12253
12254 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12255         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12256                 set_hash_global_config, "set_hash_global_config");
12257 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12258         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12259                 port_id, UINT16);
12260 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12261         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12262                 hash_func, "toeplitz#simple_xor#default");
12263 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12264         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12265                 flow_type,
12266                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12267                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12268 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12269         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12270                 enable, "enable#disable");
12271
12272 cmdline_parse_inst_t cmd_set_hash_global_config = {
12273         .f = cmd_set_hash_global_config_parsed,
12274         .data = NULL,
12275         .help_str = "set_hash_global_config <port_id> "
12276                 "toeplitz|simple_xor|default "
12277                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12278                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12279                 "l2_payload enable|disable",
12280         .tokens = {
12281                 (void *)&cmd_set_hash_global_config_all,
12282                 (void *)&cmd_set_hash_global_config_port_id,
12283                 (void *)&cmd_set_hash_global_config_hash_func,
12284                 (void *)&cmd_set_hash_global_config_flow_type,
12285                 (void *)&cmd_set_hash_global_config_enable,
12286                 NULL,
12287         },
12288 };
12289
12290 /* Set hash input set */
12291 struct cmd_set_hash_input_set_result {
12292         cmdline_fixed_string_t set_hash_input_set;
12293         portid_t port_id;
12294         cmdline_fixed_string_t flow_type;
12295         cmdline_fixed_string_t inset_field;
12296         cmdline_fixed_string_t select;
12297 };
12298
12299 static enum rte_eth_input_set_field
12300 str2inset(char *string)
12301 {
12302         uint16_t i;
12303
12304         static const struct {
12305                 char str[32];
12306                 enum rte_eth_input_set_field inset;
12307         } inset_table[] = {
12308                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12309                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12310                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12311                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12312                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12313                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12314                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12315                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12316                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12317                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12318                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12319                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12320                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12321                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12322                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12323                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12324                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12325                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12326                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12327                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12328                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12329                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12330                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12331                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12332                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12333                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12334                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12335                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12336                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12337                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12338                 {"none", RTE_ETH_INPUT_SET_NONE},
12339         };
12340
12341         for (i = 0; i < RTE_DIM(inset_table); i++) {
12342                 if (!strcmp(string, inset_table[i].str))
12343                         return inset_table[i].inset;
12344         }
12345
12346         return RTE_ETH_INPUT_SET_UNKNOWN;
12347 }
12348
12349 static void
12350 cmd_set_hash_input_set_parsed(void *parsed_result,
12351                               __rte_unused struct cmdline *cl,
12352                               __rte_unused void *data)
12353 {
12354         struct cmd_set_hash_input_set_result *res = parsed_result;
12355         struct rte_eth_hash_filter_info info;
12356
12357         memset(&info, 0, sizeof(info));
12358         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12359         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12360         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12361         info.info.input_set_conf.inset_size = 1;
12362         if (!strcmp(res->select, "select"))
12363                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12364         else if (!strcmp(res->select, "add"))
12365                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12366         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12367                                 RTE_ETH_FILTER_SET, &info);
12368 }
12369
12370 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12371         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12372                 set_hash_input_set, "set_hash_input_set");
12373 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12374         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12375                 port_id, UINT16);
12376 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12377         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12378                 flow_type, NULL);
12379 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12380         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12381                 inset_field,
12382                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12383                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12384                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12385                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12386                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12387                 "fld-8th#none");
12388 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12389         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12390                 select, "select#add");
12391
12392 cmdline_parse_inst_t cmd_set_hash_input_set = {
12393         .f = cmd_set_hash_input_set_parsed,
12394         .data = NULL,
12395         .help_str = "set_hash_input_set <port_id> "
12396         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12397         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12398         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12399         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12400         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12401         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12402         "fld-7th|fld-8th|none select|add",
12403         .tokens = {
12404                 (void *)&cmd_set_hash_input_set_cmd,
12405                 (void *)&cmd_set_hash_input_set_port_id,
12406                 (void *)&cmd_set_hash_input_set_flow_type,
12407                 (void *)&cmd_set_hash_input_set_field,
12408                 (void *)&cmd_set_hash_input_set_select,
12409                 NULL,
12410         },
12411 };
12412
12413 /* Set flow director input set */
12414 struct cmd_set_fdir_input_set_result {
12415         cmdline_fixed_string_t set_fdir_input_set;
12416         portid_t port_id;
12417         cmdline_fixed_string_t flow_type;
12418         cmdline_fixed_string_t inset_field;
12419         cmdline_fixed_string_t select;
12420 };
12421
12422 static void
12423 cmd_set_fdir_input_set_parsed(void *parsed_result,
12424         __rte_unused struct cmdline *cl,
12425         __rte_unused void *data)
12426 {
12427         struct cmd_set_fdir_input_set_result *res = parsed_result;
12428         struct rte_eth_fdir_filter_info info;
12429
12430         memset(&info, 0, sizeof(info));
12431         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12432         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12433         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12434         info.info.input_set_conf.inset_size = 1;
12435         if (!strcmp(res->select, "select"))
12436                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12437         else if (!strcmp(res->select, "add"))
12438                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12439         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12440                 RTE_ETH_FILTER_SET, &info);
12441 }
12442
12443 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12444         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12445         set_fdir_input_set, "set_fdir_input_set");
12446 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12447         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12448         port_id, UINT16);
12449 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12450         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12451         flow_type,
12452         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12453         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12454 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12455         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12456         inset_field,
12457         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12458         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12459         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12460         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12461         "sctp-veri-tag#none");
12462 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12463         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12464         select, "select#add");
12465
12466 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12467         .f = cmd_set_fdir_input_set_parsed,
12468         .data = NULL,
12469         .help_str = "set_fdir_input_set <port_id> "
12470         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12471         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12472         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12473         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12474         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12475         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12476         "sctp-veri-tag|none select|add",
12477         .tokens = {
12478                 (void *)&cmd_set_fdir_input_set_cmd,
12479                 (void *)&cmd_set_fdir_input_set_port_id,
12480                 (void *)&cmd_set_fdir_input_set_flow_type,
12481                 (void *)&cmd_set_fdir_input_set_field,
12482                 (void *)&cmd_set_fdir_input_set_select,
12483                 NULL,
12484         },
12485 };
12486
12487 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12488 struct cmd_mcast_addr_result {
12489         cmdline_fixed_string_t mcast_addr_cmd;
12490         cmdline_fixed_string_t what;
12491         uint16_t port_num;
12492         struct rte_ether_addr mc_addr;
12493 };
12494
12495 static void cmd_mcast_addr_parsed(void *parsed_result,
12496                 __attribute__((unused)) struct cmdline *cl,
12497                 __attribute__((unused)) void *data)
12498 {
12499         struct cmd_mcast_addr_result *res = parsed_result;
12500
12501         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12502                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12503                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12504                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12505                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12506                 return;
12507         }
12508         if (strcmp(res->what, "add") == 0)
12509                 mcast_addr_add(res->port_num, &res->mc_addr);
12510         else
12511                 mcast_addr_remove(res->port_num, &res->mc_addr);
12512 }
12513
12514 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12515         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12516                                  mcast_addr_cmd, "mcast_addr");
12517 cmdline_parse_token_string_t cmd_mcast_addr_what =
12518         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12519                                  "add#remove");
12520 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12521         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12522 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12523         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12524
12525 cmdline_parse_inst_t cmd_mcast_addr = {
12526         .f = cmd_mcast_addr_parsed,
12527         .data = (void *)0,
12528         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12529                 "Add/Remove multicast MAC address on port_id",
12530         .tokens = {
12531                 (void *)&cmd_mcast_addr_cmd,
12532                 (void *)&cmd_mcast_addr_what,
12533                 (void *)&cmd_mcast_addr_portnum,
12534                 (void *)&cmd_mcast_addr_addr,
12535                 NULL,
12536         },
12537 };
12538
12539 /* l2 tunnel config
12540  * only support E-tag now.
12541  */
12542
12543 /* Ether type config */
12544 struct cmd_config_l2_tunnel_eth_type_result {
12545         cmdline_fixed_string_t port;
12546         cmdline_fixed_string_t config;
12547         cmdline_fixed_string_t all;
12548         portid_t id;
12549         cmdline_fixed_string_t l2_tunnel;
12550         cmdline_fixed_string_t l2_tunnel_type;
12551         cmdline_fixed_string_t eth_type;
12552         uint16_t eth_type_val;
12553 };
12554
12555 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12556         TOKEN_STRING_INITIALIZER
12557                 (struct cmd_config_l2_tunnel_eth_type_result,
12558                  port, "port");
12559 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12560         TOKEN_STRING_INITIALIZER
12561                 (struct cmd_config_l2_tunnel_eth_type_result,
12562                  config, "config");
12563 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12564         TOKEN_STRING_INITIALIZER
12565                 (struct cmd_config_l2_tunnel_eth_type_result,
12566                  all, "all");
12567 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12568         TOKEN_NUM_INITIALIZER
12569                 (struct cmd_config_l2_tunnel_eth_type_result,
12570                  id, UINT16);
12571 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12572         TOKEN_STRING_INITIALIZER
12573                 (struct cmd_config_l2_tunnel_eth_type_result,
12574                  l2_tunnel, "l2-tunnel");
12575 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12576         TOKEN_STRING_INITIALIZER
12577                 (struct cmd_config_l2_tunnel_eth_type_result,
12578                  l2_tunnel_type, "E-tag");
12579 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12580         TOKEN_STRING_INITIALIZER
12581                 (struct cmd_config_l2_tunnel_eth_type_result,
12582                  eth_type, "ether-type");
12583 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12584         TOKEN_NUM_INITIALIZER
12585                 (struct cmd_config_l2_tunnel_eth_type_result,
12586                  eth_type_val, UINT16);
12587
12588 static enum rte_eth_tunnel_type
12589 str2fdir_l2_tunnel_type(char *string)
12590 {
12591         uint32_t i = 0;
12592
12593         static const struct {
12594                 char str[32];
12595                 enum rte_eth_tunnel_type type;
12596         } l2_tunnel_type_str[] = {
12597                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12598         };
12599
12600         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12601                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12602                         return l2_tunnel_type_str[i].type;
12603         }
12604         return RTE_TUNNEL_TYPE_NONE;
12605 }
12606
12607 /* ether type config for all ports */
12608 static void
12609 cmd_config_l2_tunnel_eth_type_all_parsed
12610         (void *parsed_result,
12611          __attribute__((unused)) struct cmdline *cl,
12612          __attribute__((unused)) void *data)
12613 {
12614         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12615         struct rte_eth_l2_tunnel_conf entry;
12616         portid_t pid;
12617
12618         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12619         entry.ether_type = res->eth_type_val;
12620
12621         RTE_ETH_FOREACH_DEV(pid) {
12622                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12623         }
12624 }
12625
12626 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12627         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12628         .data = NULL,
12629         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12630         .tokens = {
12631                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12632                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12633                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12634                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12635                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12636                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12637                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12638                 NULL,
12639         },
12640 };
12641
12642 /* ether type config for a specific port */
12643 static void
12644 cmd_config_l2_tunnel_eth_type_specific_parsed(
12645         void *parsed_result,
12646         __attribute__((unused)) struct cmdline *cl,
12647         __attribute__((unused)) void *data)
12648 {
12649         struct cmd_config_l2_tunnel_eth_type_result *res =
12650                  parsed_result;
12651         struct rte_eth_l2_tunnel_conf entry;
12652
12653         if (port_id_is_invalid(res->id, ENABLED_WARN))
12654                 return;
12655
12656         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12657         entry.ether_type = res->eth_type_val;
12658
12659         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12660 }
12661
12662 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12663         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12664         .data = NULL,
12665         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12666         .tokens = {
12667                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12668                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12669                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12670                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12671                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12672                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12673                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12674                 NULL,
12675         },
12676 };
12677
12678 /* Enable/disable l2 tunnel */
12679 struct cmd_config_l2_tunnel_en_dis_result {
12680         cmdline_fixed_string_t port;
12681         cmdline_fixed_string_t config;
12682         cmdline_fixed_string_t all;
12683         portid_t id;
12684         cmdline_fixed_string_t l2_tunnel;
12685         cmdline_fixed_string_t l2_tunnel_type;
12686         cmdline_fixed_string_t en_dis;
12687 };
12688
12689 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12690         TOKEN_STRING_INITIALIZER
12691                 (struct cmd_config_l2_tunnel_en_dis_result,
12692                  port, "port");
12693 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12694         TOKEN_STRING_INITIALIZER
12695                 (struct cmd_config_l2_tunnel_en_dis_result,
12696                  config, "config");
12697 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12698         TOKEN_STRING_INITIALIZER
12699                 (struct cmd_config_l2_tunnel_en_dis_result,
12700                  all, "all");
12701 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12702         TOKEN_NUM_INITIALIZER
12703                 (struct cmd_config_l2_tunnel_en_dis_result,
12704                  id, UINT16);
12705 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12706         TOKEN_STRING_INITIALIZER
12707                 (struct cmd_config_l2_tunnel_en_dis_result,
12708                  l2_tunnel, "l2-tunnel");
12709 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12710         TOKEN_STRING_INITIALIZER
12711                 (struct cmd_config_l2_tunnel_en_dis_result,
12712                  l2_tunnel_type, "E-tag");
12713 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12714         TOKEN_STRING_INITIALIZER
12715                 (struct cmd_config_l2_tunnel_en_dis_result,
12716                  en_dis, "enable#disable");
12717
12718 /* enable/disable l2 tunnel for all ports */
12719 static void
12720 cmd_config_l2_tunnel_en_dis_all_parsed(
12721         void *parsed_result,
12722         __attribute__((unused)) struct cmdline *cl,
12723         __attribute__((unused)) void *data)
12724 {
12725         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12726         struct rte_eth_l2_tunnel_conf entry;
12727         portid_t pid;
12728         uint8_t en;
12729
12730         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12731
12732         if (!strcmp("enable", res->en_dis))
12733                 en = 1;
12734         else
12735                 en = 0;
12736
12737         RTE_ETH_FOREACH_DEV(pid) {
12738                 rte_eth_dev_l2_tunnel_offload_set(pid,
12739                                                   &entry,
12740                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12741                                                   en);
12742         }
12743 }
12744
12745 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12746         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12747         .data = NULL,
12748         .help_str = "port config all l2-tunnel E-tag enable|disable",
12749         .tokens = {
12750                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12751                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12752                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12753                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12754                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12755                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12756                 NULL,
12757         },
12758 };
12759
12760 /* enable/disable l2 tunnel for a port */
12761 static void
12762 cmd_config_l2_tunnel_en_dis_specific_parsed(
12763         void *parsed_result,
12764         __attribute__((unused)) struct cmdline *cl,
12765         __attribute__((unused)) void *data)
12766 {
12767         struct cmd_config_l2_tunnel_en_dis_result *res =
12768                 parsed_result;
12769         struct rte_eth_l2_tunnel_conf entry;
12770
12771         if (port_id_is_invalid(res->id, ENABLED_WARN))
12772                 return;
12773
12774         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12775
12776         if (!strcmp("enable", res->en_dis))
12777                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12778                                                   &entry,
12779                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12780                                                   1);
12781         else
12782                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12783                                                   &entry,
12784                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12785                                                   0);
12786 }
12787
12788 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12789         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12790         .data = NULL,
12791         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12792         .tokens = {
12793                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12794                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12795                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12796                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12797                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12798                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12799                 NULL,
12800         },
12801 };
12802
12803 /* E-tag configuration */
12804
12805 /* Common result structure for all E-tag configuration */
12806 struct cmd_config_e_tag_result {
12807         cmdline_fixed_string_t e_tag;
12808         cmdline_fixed_string_t set;
12809         cmdline_fixed_string_t insertion;
12810         cmdline_fixed_string_t stripping;
12811         cmdline_fixed_string_t forwarding;
12812         cmdline_fixed_string_t filter;
12813         cmdline_fixed_string_t add;
12814         cmdline_fixed_string_t del;
12815         cmdline_fixed_string_t on;
12816         cmdline_fixed_string_t off;
12817         cmdline_fixed_string_t on_off;
12818         cmdline_fixed_string_t port_tag_id;
12819         uint32_t port_tag_id_val;
12820         cmdline_fixed_string_t e_tag_id;
12821         uint16_t e_tag_id_val;
12822         cmdline_fixed_string_t dst_pool;
12823         uint8_t dst_pool_val;
12824         cmdline_fixed_string_t port;
12825         portid_t port_id;
12826         cmdline_fixed_string_t vf;
12827         uint8_t vf_id;
12828 };
12829
12830 /* Common CLI fields for all E-tag configuration */
12831 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12832         TOKEN_STRING_INITIALIZER
12833                 (struct cmd_config_e_tag_result,
12834                  e_tag, "E-tag");
12835 cmdline_parse_token_string_t cmd_config_e_tag_set =
12836         TOKEN_STRING_INITIALIZER
12837                 (struct cmd_config_e_tag_result,
12838                  set, "set");
12839 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12840         TOKEN_STRING_INITIALIZER
12841                 (struct cmd_config_e_tag_result,
12842                  insertion, "insertion");
12843 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12844         TOKEN_STRING_INITIALIZER
12845                 (struct cmd_config_e_tag_result,
12846                  stripping, "stripping");
12847 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12848         TOKEN_STRING_INITIALIZER
12849                 (struct cmd_config_e_tag_result,
12850                  forwarding, "forwarding");
12851 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12852         TOKEN_STRING_INITIALIZER
12853                 (struct cmd_config_e_tag_result,
12854                  filter, "filter");
12855 cmdline_parse_token_string_t cmd_config_e_tag_add =
12856         TOKEN_STRING_INITIALIZER
12857                 (struct cmd_config_e_tag_result,
12858                  add, "add");
12859 cmdline_parse_token_string_t cmd_config_e_tag_del =
12860         TOKEN_STRING_INITIALIZER
12861                 (struct cmd_config_e_tag_result,
12862                  del, "del");
12863 cmdline_parse_token_string_t cmd_config_e_tag_on =
12864         TOKEN_STRING_INITIALIZER
12865                 (struct cmd_config_e_tag_result,
12866                  on, "on");
12867 cmdline_parse_token_string_t cmd_config_e_tag_off =
12868         TOKEN_STRING_INITIALIZER
12869                 (struct cmd_config_e_tag_result,
12870                  off, "off");
12871 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12872         TOKEN_STRING_INITIALIZER
12873                 (struct cmd_config_e_tag_result,
12874                  on_off, "on#off");
12875 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12876         TOKEN_STRING_INITIALIZER
12877                 (struct cmd_config_e_tag_result,
12878                  port_tag_id, "port-tag-id");
12879 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12880         TOKEN_NUM_INITIALIZER
12881                 (struct cmd_config_e_tag_result,
12882                  port_tag_id_val, UINT32);
12883 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12884         TOKEN_STRING_INITIALIZER
12885                 (struct cmd_config_e_tag_result,
12886                  e_tag_id, "e-tag-id");
12887 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12888         TOKEN_NUM_INITIALIZER
12889                 (struct cmd_config_e_tag_result,
12890                  e_tag_id_val, UINT16);
12891 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12892         TOKEN_STRING_INITIALIZER
12893                 (struct cmd_config_e_tag_result,
12894                  dst_pool, "dst-pool");
12895 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12896         TOKEN_NUM_INITIALIZER
12897                 (struct cmd_config_e_tag_result,
12898                  dst_pool_val, UINT8);
12899 cmdline_parse_token_string_t cmd_config_e_tag_port =
12900         TOKEN_STRING_INITIALIZER
12901                 (struct cmd_config_e_tag_result,
12902                  port, "port");
12903 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12904         TOKEN_NUM_INITIALIZER
12905                 (struct cmd_config_e_tag_result,
12906                  port_id, UINT16);
12907 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12908         TOKEN_STRING_INITIALIZER
12909                 (struct cmd_config_e_tag_result,
12910                  vf, "vf");
12911 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12912         TOKEN_NUM_INITIALIZER
12913                 (struct cmd_config_e_tag_result,
12914                  vf_id, UINT8);
12915
12916 /* E-tag insertion configuration */
12917 static void
12918 cmd_config_e_tag_insertion_en_parsed(
12919         void *parsed_result,
12920         __attribute__((unused)) struct cmdline *cl,
12921         __attribute__((unused)) void *data)
12922 {
12923         struct cmd_config_e_tag_result *res =
12924                 parsed_result;
12925         struct rte_eth_l2_tunnel_conf entry;
12926
12927         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12928                 return;
12929
12930         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12931         entry.tunnel_id = res->port_tag_id_val;
12932         entry.vf_id = res->vf_id;
12933         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12934                                           &entry,
12935                                           ETH_L2_TUNNEL_INSERTION_MASK,
12936                                           1);
12937 }
12938
12939 static void
12940 cmd_config_e_tag_insertion_dis_parsed(
12941         void *parsed_result,
12942         __attribute__((unused)) struct cmdline *cl,
12943         __attribute__((unused)) void *data)
12944 {
12945         struct cmd_config_e_tag_result *res =
12946                 parsed_result;
12947         struct rte_eth_l2_tunnel_conf entry;
12948
12949         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12950                 return;
12951
12952         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12953         entry.vf_id = res->vf_id;
12954
12955         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12956                                           &entry,
12957                                           ETH_L2_TUNNEL_INSERTION_MASK,
12958                                           0);
12959 }
12960
12961 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12962         .f = cmd_config_e_tag_insertion_en_parsed,
12963         .data = NULL,
12964         .help_str = "E-tag ... : E-tag insertion enable",
12965         .tokens = {
12966                 (void *)&cmd_config_e_tag_e_tag,
12967                 (void *)&cmd_config_e_tag_set,
12968                 (void *)&cmd_config_e_tag_insertion,
12969                 (void *)&cmd_config_e_tag_on,
12970                 (void *)&cmd_config_e_tag_port_tag_id,
12971                 (void *)&cmd_config_e_tag_port_tag_id_val,
12972                 (void *)&cmd_config_e_tag_port,
12973                 (void *)&cmd_config_e_tag_port_id,
12974                 (void *)&cmd_config_e_tag_vf,
12975                 (void *)&cmd_config_e_tag_vf_id,
12976                 NULL,
12977         },
12978 };
12979
12980 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12981         .f = cmd_config_e_tag_insertion_dis_parsed,
12982         .data = NULL,
12983         .help_str = "E-tag ... : E-tag insertion disable",
12984         .tokens = {
12985                 (void *)&cmd_config_e_tag_e_tag,
12986                 (void *)&cmd_config_e_tag_set,
12987                 (void *)&cmd_config_e_tag_insertion,
12988                 (void *)&cmd_config_e_tag_off,
12989                 (void *)&cmd_config_e_tag_port,
12990                 (void *)&cmd_config_e_tag_port_id,
12991                 (void *)&cmd_config_e_tag_vf,
12992                 (void *)&cmd_config_e_tag_vf_id,
12993                 NULL,
12994         },
12995 };
12996
12997 /* E-tag stripping configuration */
12998 static void
12999 cmd_config_e_tag_stripping_parsed(
13000         void *parsed_result,
13001         __attribute__((unused)) struct cmdline *cl,
13002         __attribute__((unused)) void *data)
13003 {
13004         struct cmd_config_e_tag_result *res =
13005                 parsed_result;
13006         struct rte_eth_l2_tunnel_conf entry;
13007
13008         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13009                 return;
13010
13011         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13012
13013         if (!strcmp(res->on_off, "on"))
13014                 rte_eth_dev_l2_tunnel_offload_set
13015                         (res->port_id,
13016                          &entry,
13017                          ETH_L2_TUNNEL_STRIPPING_MASK,
13018                          1);
13019         else
13020                 rte_eth_dev_l2_tunnel_offload_set
13021                         (res->port_id,
13022                          &entry,
13023                          ETH_L2_TUNNEL_STRIPPING_MASK,
13024                          0);
13025 }
13026
13027 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13028         .f = cmd_config_e_tag_stripping_parsed,
13029         .data = NULL,
13030         .help_str = "E-tag ... : E-tag stripping enable/disable",
13031         .tokens = {
13032                 (void *)&cmd_config_e_tag_e_tag,
13033                 (void *)&cmd_config_e_tag_set,
13034                 (void *)&cmd_config_e_tag_stripping,
13035                 (void *)&cmd_config_e_tag_on_off,
13036                 (void *)&cmd_config_e_tag_port,
13037                 (void *)&cmd_config_e_tag_port_id,
13038                 NULL,
13039         },
13040 };
13041
13042 /* E-tag forwarding configuration */
13043 static void
13044 cmd_config_e_tag_forwarding_parsed(
13045         void *parsed_result,
13046         __attribute__((unused)) struct cmdline *cl,
13047         __attribute__((unused)) void *data)
13048 {
13049         struct cmd_config_e_tag_result *res = parsed_result;
13050         struct rte_eth_l2_tunnel_conf entry;
13051
13052         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13053                 return;
13054
13055         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13056
13057         if (!strcmp(res->on_off, "on"))
13058                 rte_eth_dev_l2_tunnel_offload_set
13059                         (res->port_id,
13060                          &entry,
13061                          ETH_L2_TUNNEL_FORWARDING_MASK,
13062                          1);
13063         else
13064                 rte_eth_dev_l2_tunnel_offload_set
13065                         (res->port_id,
13066                          &entry,
13067                          ETH_L2_TUNNEL_FORWARDING_MASK,
13068                          0);
13069 }
13070
13071 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13072         .f = cmd_config_e_tag_forwarding_parsed,
13073         .data = NULL,
13074         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13075         .tokens = {
13076                 (void *)&cmd_config_e_tag_e_tag,
13077                 (void *)&cmd_config_e_tag_set,
13078                 (void *)&cmd_config_e_tag_forwarding,
13079                 (void *)&cmd_config_e_tag_on_off,
13080                 (void *)&cmd_config_e_tag_port,
13081                 (void *)&cmd_config_e_tag_port_id,
13082                 NULL,
13083         },
13084 };
13085
13086 /* E-tag filter configuration */
13087 static void
13088 cmd_config_e_tag_filter_add_parsed(
13089         void *parsed_result,
13090         __attribute__((unused)) struct cmdline *cl,
13091         __attribute__((unused)) void *data)
13092 {
13093         struct cmd_config_e_tag_result *res = parsed_result;
13094         struct rte_eth_l2_tunnel_conf entry;
13095         int ret = 0;
13096
13097         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13098                 return;
13099
13100         if (res->e_tag_id_val > 0x3fff) {
13101                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13102                 return;
13103         }
13104
13105         ret = rte_eth_dev_filter_supported(res->port_id,
13106                                            RTE_ETH_FILTER_L2_TUNNEL);
13107         if (ret < 0) {
13108                 printf("E-tag filter is not supported on port %u.\n",
13109                        res->port_id);
13110                 return;
13111         }
13112
13113         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13114         entry.tunnel_id = res->e_tag_id_val;
13115         entry.pool = res->dst_pool_val;
13116
13117         ret = rte_eth_dev_filter_ctrl(res->port_id,
13118                                       RTE_ETH_FILTER_L2_TUNNEL,
13119                                       RTE_ETH_FILTER_ADD,
13120                                       &entry);
13121         if (ret < 0)
13122                 printf("E-tag filter programming error: (%s)\n",
13123                        strerror(-ret));
13124 }
13125
13126 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13127         .f = cmd_config_e_tag_filter_add_parsed,
13128         .data = NULL,
13129         .help_str = "E-tag ... : E-tag filter add",
13130         .tokens = {
13131                 (void *)&cmd_config_e_tag_e_tag,
13132                 (void *)&cmd_config_e_tag_set,
13133                 (void *)&cmd_config_e_tag_filter,
13134                 (void *)&cmd_config_e_tag_add,
13135                 (void *)&cmd_config_e_tag_e_tag_id,
13136                 (void *)&cmd_config_e_tag_e_tag_id_val,
13137                 (void *)&cmd_config_e_tag_dst_pool,
13138                 (void *)&cmd_config_e_tag_dst_pool_val,
13139                 (void *)&cmd_config_e_tag_port,
13140                 (void *)&cmd_config_e_tag_port_id,
13141                 NULL,
13142         },
13143 };
13144
13145 static void
13146 cmd_config_e_tag_filter_del_parsed(
13147         void *parsed_result,
13148         __attribute__((unused)) struct cmdline *cl,
13149         __attribute__((unused)) void *data)
13150 {
13151         struct cmd_config_e_tag_result *res = parsed_result;
13152         struct rte_eth_l2_tunnel_conf entry;
13153         int ret = 0;
13154
13155         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13156                 return;
13157
13158         if (res->e_tag_id_val > 0x3fff) {
13159                 printf("e-tag-id must be less than 0x3fff.\n");
13160                 return;
13161         }
13162
13163         ret = rte_eth_dev_filter_supported(res->port_id,
13164                                            RTE_ETH_FILTER_L2_TUNNEL);
13165         if (ret < 0) {
13166                 printf("E-tag filter is not supported on port %u.\n",
13167                        res->port_id);
13168                 return;
13169         }
13170
13171         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13172         entry.tunnel_id = res->e_tag_id_val;
13173
13174         ret = rte_eth_dev_filter_ctrl(res->port_id,
13175                                       RTE_ETH_FILTER_L2_TUNNEL,
13176                                       RTE_ETH_FILTER_DELETE,
13177                                       &entry);
13178         if (ret < 0)
13179                 printf("E-tag filter programming error: (%s)\n",
13180                        strerror(-ret));
13181 }
13182
13183 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13184         .f = cmd_config_e_tag_filter_del_parsed,
13185         .data = NULL,
13186         .help_str = "E-tag ... : E-tag filter delete",
13187         .tokens = {
13188                 (void *)&cmd_config_e_tag_e_tag,
13189                 (void *)&cmd_config_e_tag_set,
13190                 (void *)&cmd_config_e_tag_filter,
13191                 (void *)&cmd_config_e_tag_del,
13192                 (void *)&cmd_config_e_tag_e_tag_id,
13193                 (void *)&cmd_config_e_tag_e_tag_id_val,
13194                 (void *)&cmd_config_e_tag_port,
13195                 (void *)&cmd_config_e_tag_port_id,
13196                 NULL,
13197         },
13198 };
13199
13200 /* vf vlan anti spoof configuration */
13201
13202 /* Common result structure for vf vlan anti spoof */
13203 struct cmd_vf_vlan_anti_spoof_result {
13204         cmdline_fixed_string_t set;
13205         cmdline_fixed_string_t vf;
13206         cmdline_fixed_string_t vlan;
13207         cmdline_fixed_string_t antispoof;
13208         portid_t port_id;
13209         uint32_t vf_id;
13210         cmdline_fixed_string_t on_off;
13211 };
13212
13213 /* Common CLI fields for vf vlan anti spoof enable disable */
13214 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13215         TOKEN_STRING_INITIALIZER
13216                 (struct cmd_vf_vlan_anti_spoof_result,
13217                  set, "set");
13218 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13219         TOKEN_STRING_INITIALIZER
13220                 (struct cmd_vf_vlan_anti_spoof_result,
13221                  vf, "vf");
13222 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13223         TOKEN_STRING_INITIALIZER
13224                 (struct cmd_vf_vlan_anti_spoof_result,
13225                  vlan, "vlan");
13226 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13227         TOKEN_STRING_INITIALIZER
13228                 (struct cmd_vf_vlan_anti_spoof_result,
13229                  antispoof, "antispoof");
13230 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13231         TOKEN_NUM_INITIALIZER
13232                 (struct cmd_vf_vlan_anti_spoof_result,
13233                  port_id, UINT16);
13234 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13235         TOKEN_NUM_INITIALIZER
13236                 (struct cmd_vf_vlan_anti_spoof_result,
13237                  vf_id, UINT32);
13238 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13239         TOKEN_STRING_INITIALIZER
13240                 (struct cmd_vf_vlan_anti_spoof_result,
13241                  on_off, "on#off");
13242
13243 static void
13244 cmd_set_vf_vlan_anti_spoof_parsed(
13245         void *parsed_result,
13246         __attribute__((unused)) struct cmdline *cl,
13247         __attribute__((unused)) void *data)
13248 {
13249         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13250         int ret = -ENOTSUP;
13251
13252         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13253
13254         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13255                 return;
13256
13257 #ifdef RTE_LIBRTE_IXGBE_PMD
13258         if (ret == -ENOTSUP)
13259                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13260                                 res->vf_id, is_on);
13261 #endif
13262 #ifdef RTE_LIBRTE_I40E_PMD
13263         if (ret == -ENOTSUP)
13264                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13265                                 res->vf_id, is_on);
13266 #endif
13267 #ifdef RTE_LIBRTE_BNXT_PMD
13268         if (ret == -ENOTSUP)
13269                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13270                                 res->vf_id, is_on);
13271 #endif
13272
13273         switch (ret) {
13274         case 0:
13275                 break;
13276         case -EINVAL:
13277                 printf("invalid vf_id %d\n", res->vf_id);
13278                 break;
13279         case -ENODEV:
13280                 printf("invalid port_id %d\n", res->port_id);
13281                 break;
13282         case -ENOTSUP:
13283                 printf("function not implemented\n");
13284                 break;
13285         default:
13286                 printf("programming error: (%s)\n", strerror(-ret));
13287         }
13288 }
13289
13290 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13291         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13292         .data = NULL,
13293         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13294         .tokens = {
13295                 (void *)&cmd_vf_vlan_anti_spoof_set,
13296                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13297                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13298                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13299                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13300                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13301                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13302                 NULL,
13303         },
13304 };
13305
13306 /* vf mac anti spoof configuration */
13307
13308 /* Common result structure for vf mac anti spoof */
13309 struct cmd_vf_mac_anti_spoof_result {
13310         cmdline_fixed_string_t set;
13311         cmdline_fixed_string_t vf;
13312         cmdline_fixed_string_t mac;
13313         cmdline_fixed_string_t antispoof;
13314         portid_t port_id;
13315         uint32_t vf_id;
13316         cmdline_fixed_string_t on_off;
13317 };
13318
13319 /* Common CLI fields for vf mac anti spoof enable disable */
13320 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13321         TOKEN_STRING_INITIALIZER
13322                 (struct cmd_vf_mac_anti_spoof_result,
13323                  set, "set");
13324 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13325         TOKEN_STRING_INITIALIZER
13326                 (struct cmd_vf_mac_anti_spoof_result,
13327                  vf, "vf");
13328 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13329         TOKEN_STRING_INITIALIZER
13330                 (struct cmd_vf_mac_anti_spoof_result,
13331                  mac, "mac");
13332 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13333         TOKEN_STRING_INITIALIZER
13334                 (struct cmd_vf_mac_anti_spoof_result,
13335                  antispoof, "antispoof");
13336 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13337         TOKEN_NUM_INITIALIZER
13338                 (struct cmd_vf_mac_anti_spoof_result,
13339                  port_id, UINT16);
13340 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13341         TOKEN_NUM_INITIALIZER
13342                 (struct cmd_vf_mac_anti_spoof_result,
13343                  vf_id, UINT32);
13344 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13345         TOKEN_STRING_INITIALIZER
13346                 (struct cmd_vf_mac_anti_spoof_result,
13347                  on_off, "on#off");
13348
13349 static void
13350 cmd_set_vf_mac_anti_spoof_parsed(
13351         void *parsed_result,
13352         __attribute__((unused)) struct cmdline *cl,
13353         __attribute__((unused)) void *data)
13354 {
13355         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13356         int ret = -ENOTSUP;
13357
13358         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13359
13360         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13361                 return;
13362
13363 #ifdef RTE_LIBRTE_IXGBE_PMD
13364         if (ret == -ENOTSUP)
13365                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13366                         res->vf_id, is_on);
13367 #endif
13368 #ifdef RTE_LIBRTE_I40E_PMD
13369         if (ret == -ENOTSUP)
13370                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13371                         res->vf_id, is_on);
13372 #endif
13373 #ifdef RTE_LIBRTE_BNXT_PMD
13374         if (ret == -ENOTSUP)
13375                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13376                         res->vf_id, is_on);
13377 #endif
13378
13379         switch (ret) {
13380         case 0:
13381                 break;
13382         case -EINVAL:
13383                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13384                 break;
13385         case -ENODEV:
13386                 printf("invalid port_id %d\n", res->port_id);
13387                 break;
13388         case -ENOTSUP:
13389                 printf("function not implemented\n");
13390                 break;
13391         default:
13392                 printf("programming error: (%s)\n", strerror(-ret));
13393         }
13394 }
13395
13396 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13397         .f = cmd_set_vf_mac_anti_spoof_parsed,
13398         .data = NULL,
13399         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13400         .tokens = {
13401                 (void *)&cmd_vf_mac_anti_spoof_set,
13402                 (void *)&cmd_vf_mac_anti_spoof_vf,
13403                 (void *)&cmd_vf_mac_anti_spoof_mac,
13404                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13405                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13406                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13407                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13408                 NULL,
13409         },
13410 };
13411
13412 /* vf vlan strip queue configuration */
13413
13414 /* Common result structure for vf mac anti spoof */
13415 struct cmd_vf_vlan_stripq_result {
13416         cmdline_fixed_string_t set;
13417         cmdline_fixed_string_t vf;
13418         cmdline_fixed_string_t vlan;
13419         cmdline_fixed_string_t stripq;
13420         portid_t port_id;
13421         uint16_t vf_id;
13422         cmdline_fixed_string_t on_off;
13423 };
13424
13425 /* Common CLI fields for vf vlan strip enable disable */
13426 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13427         TOKEN_STRING_INITIALIZER
13428                 (struct cmd_vf_vlan_stripq_result,
13429                  set, "set");
13430 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13431         TOKEN_STRING_INITIALIZER
13432                 (struct cmd_vf_vlan_stripq_result,
13433                  vf, "vf");
13434 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13435         TOKEN_STRING_INITIALIZER
13436                 (struct cmd_vf_vlan_stripq_result,
13437                  vlan, "vlan");
13438 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13439         TOKEN_STRING_INITIALIZER
13440                 (struct cmd_vf_vlan_stripq_result,
13441                  stripq, "stripq");
13442 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13443         TOKEN_NUM_INITIALIZER
13444                 (struct cmd_vf_vlan_stripq_result,
13445                  port_id, UINT16);
13446 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13447         TOKEN_NUM_INITIALIZER
13448                 (struct cmd_vf_vlan_stripq_result,
13449                  vf_id, UINT16);
13450 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13451         TOKEN_STRING_INITIALIZER
13452                 (struct cmd_vf_vlan_stripq_result,
13453                  on_off, "on#off");
13454
13455 static void
13456 cmd_set_vf_vlan_stripq_parsed(
13457         void *parsed_result,
13458         __attribute__((unused)) struct cmdline *cl,
13459         __attribute__((unused)) void *data)
13460 {
13461         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13462         int ret = -ENOTSUP;
13463
13464         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13465
13466         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13467                 return;
13468
13469 #ifdef RTE_LIBRTE_IXGBE_PMD
13470         if (ret == -ENOTSUP)
13471                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13472                         res->vf_id, is_on);
13473 #endif
13474 #ifdef RTE_LIBRTE_I40E_PMD
13475         if (ret == -ENOTSUP)
13476                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13477                         res->vf_id, is_on);
13478 #endif
13479 #ifdef RTE_LIBRTE_BNXT_PMD
13480         if (ret == -ENOTSUP)
13481                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13482                         res->vf_id, is_on);
13483 #endif
13484
13485         switch (ret) {
13486         case 0:
13487                 break;
13488         case -EINVAL:
13489                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13490                 break;
13491         case -ENODEV:
13492                 printf("invalid port_id %d\n", res->port_id);
13493                 break;
13494         case -ENOTSUP:
13495                 printf("function not implemented\n");
13496                 break;
13497         default:
13498                 printf("programming error: (%s)\n", strerror(-ret));
13499         }
13500 }
13501
13502 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13503         .f = cmd_set_vf_vlan_stripq_parsed,
13504         .data = NULL,
13505         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13506         .tokens = {
13507                 (void *)&cmd_vf_vlan_stripq_set,
13508                 (void *)&cmd_vf_vlan_stripq_vf,
13509                 (void *)&cmd_vf_vlan_stripq_vlan,
13510                 (void *)&cmd_vf_vlan_stripq_stripq,
13511                 (void *)&cmd_vf_vlan_stripq_port_id,
13512                 (void *)&cmd_vf_vlan_stripq_vf_id,
13513                 (void *)&cmd_vf_vlan_stripq_on_off,
13514                 NULL,
13515         },
13516 };
13517
13518 /* vf vlan insert configuration */
13519
13520 /* Common result structure for vf vlan insert */
13521 struct cmd_vf_vlan_insert_result {
13522         cmdline_fixed_string_t set;
13523         cmdline_fixed_string_t vf;
13524         cmdline_fixed_string_t vlan;
13525         cmdline_fixed_string_t insert;
13526         portid_t port_id;
13527         uint16_t vf_id;
13528         uint16_t vlan_id;
13529 };
13530
13531 /* Common CLI fields for vf vlan insert enable disable */
13532 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13533         TOKEN_STRING_INITIALIZER
13534                 (struct cmd_vf_vlan_insert_result,
13535                  set, "set");
13536 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13537         TOKEN_STRING_INITIALIZER
13538                 (struct cmd_vf_vlan_insert_result,
13539                  vf, "vf");
13540 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13541         TOKEN_STRING_INITIALIZER
13542                 (struct cmd_vf_vlan_insert_result,
13543                  vlan, "vlan");
13544 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13545         TOKEN_STRING_INITIALIZER
13546                 (struct cmd_vf_vlan_insert_result,
13547                  insert, "insert");
13548 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13549         TOKEN_NUM_INITIALIZER
13550                 (struct cmd_vf_vlan_insert_result,
13551                  port_id, UINT16);
13552 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13553         TOKEN_NUM_INITIALIZER
13554                 (struct cmd_vf_vlan_insert_result,
13555                  vf_id, UINT16);
13556 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13557         TOKEN_NUM_INITIALIZER
13558                 (struct cmd_vf_vlan_insert_result,
13559                  vlan_id, UINT16);
13560
13561 static void
13562 cmd_set_vf_vlan_insert_parsed(
13563         void *parsed_result,
13564         __attribute__((unused)) struct cmdline *cl,
13565         __attribute__((unused)) void *data)
13566 {
13567         struct cmd_vf_vlan_insert_result *res = parsed_result;
13568         int ret = -ENOTSUP;
13569
13570         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13571                 return;
13572
13573 #ifdef RTE_LIBRTE_IXGBE_PMD
13574         if (ret == -ENOTSUP)
13575                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13576                         res->vlan_id);
13577 #endif
13578 #ifdef RTE_LIBRTE_I40E_PMD
13579         if (ret == -ENOTSUP)
13580                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13581                         res->vlan_id);
13582 #endif
13583 #ifdef RTE_LIBRTE_BNXT_PMD
13584         if (ret == -ENOTSUP)
13585                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13586                         res->vlan_id);
13587 #endif
13588
13589         switch (ret) {
13590         case 0:
13591                 break;
13592         case -EINVAL:
13593                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13594                 break;
13595         case -ENODEV:
13596                 printf("invalid port_id %d\n", res->port_id);
13597                 break;
13598         case -ENOTSUP:
13599                 printf("function not implemented\n");
13600                 break;
13601         default:
13602                 printf("programming error: (%s)\n", strerror(-ret));
13603         }
13604 }
13605
13606 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13607         .f = cmd_set_vf_vlan_insert_parsed,
13608         .data = NULL,
13609         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13610         .tokens = {
13611                 (void *)&cmd_vf_vlan_insert_set,
13612                 (void *)&cmd_vf_vlan_insert_vf,
13613                 (void *)&cmd_vf_vlan_insert_vlan,
13614                 (void *)&cmd_vf_vlan_insert_insert,
13615                 (void *)&cmd_vf_vlan_insert_port_id,
13616                 (void *)&cmd_vf_vlan_insert_vf_id,
13617                 (void *)&cmd_vf_vlan_insert_vlan_id,
13618                 NULL,
13619         },
13620 };
13621
13622 /* tx loopback configuration */
13623
13624 /* Common result structure for tx loopback */
13625 struct cmd_tx_loopback_result {
13626         cmdline_fixed_string_t set;
13627         cmdline_fixed_string_t tx;
13628         cmdline_fixed_string_t loopback;
13629         portid_t port_id;
13630         cmdline_fixed_string_t on_off;
13631 };
13632
13633 /* Common CLI fields for tx loopback enable disable */
13634 cmdline_parse_token_string_t cmd_tx_loopback_set =
13635         TOKEN_STRING_INITIALIZER
13636                 (struct cmd_tx_loopback_result,
13637                  set, "set");
13638 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13639         TOKEN_STRING_INITIALIZER
13640                 (struct cmd_tx_loopback_result,
13641                  tx, "tx");
13642 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13643         TOKEN_STRING_INITIALIZER
13644                 (struct cmd_tx_loopback_result,
13645                  loopback, "loopback");
13646 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13647         TOKEN_NUM_INITIALIZER
13648                 (struct cmd_tx_loopback_result,
13649                  port_id, UINT16);
13650 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13651         TOKEN_STRING_INITIALIZER
13652                 (struct cmd_tx_loopback_result,
13653                  on_off, "on#off");
13654
13655 static void
13656 cmd_set_tx_loopback_parsed(
13657         void *parsed_result,
13658         __attribute__((unused)) struct cmdline *cl,
13659         __attribute__((unused)) void *data)
13660 {
13661         struct cmd_tx_loopback_result *res = parsed_result;
13662         int ret = -ENOTSUP;
13663
13664         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13665
13666         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13667                 return;
13668
13669 #ifdef RTE_LIBRTE_IXGBE_PMD
13670         if (ret == -ENOTSUP)
13671                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13672 #endif
13673 #ifdef RTE_LIBRTE_I40E_PMD
13674         if (ret == -ENOTSUP)
13675                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13676 #endif
13677 #ifdef RTE_LIBRTE_BNXT_PMD
13678         if (ret == -ENOTSUP)
13679                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13680 #endif
13681 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13682         if (ret == -ENOTSUP)
13683                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13684 #endif
13685
13686         switch (ret) {
13687         case 0:
13688                 break;
13689         case -EINVAL:
13690                 printf("invalid is_on %d\n", is_on);
13691                 break;
13692         case -ENODEV:
13693                 printf("invalid port_id %d\n", res->port_id);
13694                 break;
13695         case -ENOTSUP:
13696                 printf("function not implemented\n");
13697                 break;
13698         default:
13699                 printf("programming error: (%s)\n", strerror(-ret));
13700         }
13701 }
13702
13703 cmdline_parse_inst_t cmd_set_tx_loopback = {
13704         .f = cmd_set_tx_loopback_parsed,
13705         .data = NULL,
13706         .help_str = "set tx loopback <port_id> on|off",
13707         .tokens = {
13708                 (void *)&cmd_tx_loopback_set,
13709                 (void *)&cmd_tx_loopback_tx,
13710                 (void *)&cmd_tx_loopback_loopback,
13711                 (void *)&cmd_tx_loopback_port_id,
13712                 (void *)&cmd_tx_loopback_on_off,
13713                 NULL,
13714         },
13715 };
13716
13717 /* all queues drop enable configuration */
13718
13719 /* Common result structure for all queues drop enable */
13720 struct cmd_all_queues_drop_en_result {
13721         cmdline_fixed_string_t set;
13722         cmdline_fixed_string_t all;
13723         cmdline_fixed_string_t queues;
13724         cmdline_fixed_string_t drop;
13725         portid_t port_id;
13726         cmdline_fixed_string_t on_off;
13727 };
13728
13729 /* Common CLI fields for tx loopback enable disable */
13730 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13731         TOKEN_STRING_INITIALIZER
13732                 (struct cmd_all_queues_drop_en_result,
13733                  set, "set");
13734 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13735         TOKEN_STRING_INITIALIZER
13736                 (struct cmd_all_queues_drop_en_result,
13737                  all, "all");
13738 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13739         TOKEN_STRING_INITIALIZER
13740                 (struct cmd_all_queues_drop_en_result,
13741                  queues, "queues");
13742 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13743         TOKEN_STRING_INITIALIZER
13744                 (struct cmd_all_queues_drop_en_result,
13745                  drop, "drop");
13746 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13747         TOKEN_NUM_INITIALIZER
13748                 (struct cmd_all_queues_drop_en_result,
13749                  port_id, UINT16);
13750 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13751         TOKEN_STRING_INITIALIZER
13752                 (struct cmd_all_queues_drop_en_result,
13753                  on_off, "on#off");
13754
13755 static void
13756 cmd_set_all_queues_drop_en_parsed(
13757         void *parsed_result,
13758         __attribute__((unused)) struct cmdline *cl,
13759         __attribute__((unused)) void *data)
13760 {
13761         struct cmd_all_queues_drop_en_result *res = parsed_result;
13762         int ret = -ENOTSUP;
13763         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13764
13765         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13766                 return;
13767
13768 #ifdef RTE_LIBRTE_IXGBE_PMD
13769         if (ret == -ENOTSUP)
13770                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13771 #endif
13772 #ifdef RTE_LIBRTE_BNXT_PMD
13773         if (ret == -ENOTSUP)
13774                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13775 #endif
13776         switch (ret) {
13777         case 0:
13778                 break;
13779         case -EINVAL:
13780                 printf("invalid is_on %d\n", is_on);
13781                 break;
13782         case -ENODEV:
13783                 printf("invalid port_id %d\n", res->port_id);
13784                 break;
13785         case -ENOTSUP:
13786                 printf("function not implemented\n");
13787                 break;
13788         default:
13789                 printf("programming error: (%s)\n", strerror(-ret));
13790         }
13791 }
13792
13793 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13794         .f = cmd_set_all_queues_drop_en_parsed,
13795         .data = NULL,
13796         .help_str = "set all queues drop <port_id> on|off",
13797         .tokens = {
13798                 (void *)&cmd_all_queues_drop_en_set,
13799                 (void *)&cmd_all_queues_drop_en_all,
13800                 (void *)&cmd_all_queues_drop_en_queues,
13801                 (void *)&cmd_all_queues_drop_en_drop,
13802                 (void *)&cmd_all_queues_drop_en_port_id,
13803                 (void *)&cmd_all_queues_drop_en_on_off,
13804                 NULL,
13805         },
13806 };
13807
13808 /* vf split drop enable configuration */
13809
13810 /* Common result structure for vf split drop enable */
13811 struct cmd_vf_split_drop_en_result {
13812         cmdline_fixed_string_t set;
13813         cmdline_fixed_string_t vf;
13814         cmdline_fixed_string_t split;
13815         cmdline_fixed_string_t drop;
13816         portid_t port_id;
13817         uint16_t vf_id;
13818         cmdline_fixed_string_t on_off;
13819 };
13820
13821 /* Common CLI fields for vf split drop enable disable */
13822 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13823         TOKEN_STRING_INITIALIZER
13824                 (struct cmd_vf_split_drop_en_result,
13825                  set, "set");
13826 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13827         TOKEN_STRING_INITIALIZER
13828                 (struct cmd_vf_split_drop_en_result,
13829                  vf, "vf");
13830 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13831         TOKEN_STRING_INITIALIZER
13832                 (struct cmd_vf_split_drop_en_result,
13833                  split, "split");
13834 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13835         TOKEN_STRING_INITIALIZER
13836                 (struct cmd_vf_split_drop_en_result,
13837                  drop, "drop");
13838 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13839         TOKEN_NUM_INITIALIZER
13840                 (struct cmd_vf_split_drop_en_result,
13841                  port_id, UINT16);
13842 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13843         TOKEN_NUM_INITIALIZER
13844                 (struct cmd_vf_split_drop_en_result,
13845                  vf_id, UINT16);
13846 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13847         TOKEN_STRING_INITIALIZER
13848                 (struct cmd_vf_split_drop_en_result,
13849                  on_off, "on#off");
13850
13851 static void
13852 cmd_set_vf_split_drop_en_parsed(
13853         void *parsed_result,
13854         __attribute__((unused)) struct cmdline *cl,
13855         __attribute__((unused)) void *data)
13856 {
13857         struct cmd_vf_split_drop_en_result *res = parsed_result;
13858         int ret = -ENOTSUP;
13859         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13860
13861         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13862                 return;
13863
13864 #ifdef RTE_LIBRTE_IXGBE_PMD
13865         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13866                         is_on);
13867 #endif
13868         switch (ret) {
13869         case 0:
13870                 break;
13871         case -EINVAL:
13872                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13873                 break;
13874         case -ENODEV:
13875                 printf("invalid port_id %d\n", res->port_id);
13876                 break;
13877         case -ENOTSUP:
13878                 printf("not supported on port %d\n", res->port_id);
13879                 break;
13880         default:
13881                 printf("programming error: (%s)\n", strerror(-ret));
13882         }
13883 }
13884
13885 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13886         .f = cmd_set_vf_split_drop_en_parsed,
13887         .data = NULL,
13888         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13889         .tokens = {
13890                 (void *)&cmd_vf_split_drop_en_set,
13891                 (void *)&cmd_vf_split_drop_en_vf,
13892                 (void *)&cmd_vf_split_drop_en_split,
13893                 (void *)&cmd_vf_split_drop_en_drop,
13894                 (void *)&cmd_vf_split_drop_en_port_id,
13895                 (void *)&cmd_vf_split_drop_en_vf_id,
13896                 (void *)&cmd_vf_split_drop_en_on_off,
13897                 NULL,
13898         },
13899 };
13900
13901 /* vf mac address configuration */
13902
13903 /* Common result structure for vf mac address */
13904 struct cmd_set_vf_mac_addr_result {
13905         cmdline_fixed_string_t set;
13906         cmdline_fixed_string_t vf;
13907         cmdline_fixed_string_t mac;
13908         cmdline_fixed_string_t addr;
13909         portid_t port_id;
13910         uint16_t vf_id;
13911         struct rte_ether_addr mac_addr;
13912
13913 };
13914
13915 /* Common CLI fields for vf split drop enable disable */
13916 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13917         TOKEN_STRING_INITIALIZER
13918                 (struct cmd_set_vf_mac_addr_result,
13919                  set, "set");
13920 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13921         TOKEN_STRING_INITIALIZER
13922                 (struct cmd_set_vf_mac_addr_result,
13923                  vf, "vf");
13924 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13925         TOKEN_STRING_INITIALIZER
13926                 (struct cmd_set_vf_mac_addr_result,
13927                  mac, "mac");
13928 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13929         TOKEN_STRING_INITIALIZER
13930                 (struct cmd_set_vf_mac_addr_result,
13931                  addr, "addr");
13932 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13933         TOKEN_NUM_INITIALIZER
13934                 (struct cmd_set_vf_mac_addr_result,
13935                  port_id, UINT16);
13936 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13937         TOKEN_NUM_INITIALIZER
13938                 (struct cmd_set_vf_mac_addr_result,
13939                  vf_id, UINT16);
13940 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13941         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13942                  mac_addr);
13943
13944 static void
13945 cmd_set_vf_mac_addr_parsed(
13946         void *parsed_result,
13947         __attribute__((unused)) struct cmdline *cl,
13948         __attribute__((unused)) void *data)
13949 {
13950         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13951         int ret = -ENOTSUP;
13952
13953         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13954                 return;
13955
13956 #ifdef RTE_LIBRTE_IXGBE_PMD
13957         if (ret == -ENOTSUP)
13958                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13959                                 &res->mac_addr);
13960 #endif
13961 #ifdef RTE_LIBRTE_I40E_PMD
13962         if (ret == -ENOTSUP)
13963                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13964                                 &res->mac_addr);
13965 #endif
13966 #ifdef RTE_LIBRTE_BNXT_PMD
13967         if (ret == -ENOTSUP)
13968                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13969                                 &res->mac_addr);
13970 #endif
13971
13972         switch (ret) {
13973         case 0:
13974                 break;
13975         case -EINVAL:
13976                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13977                 break;
13978         case -ENODEV:
13979                 printf("invalid port_id %d\n", res->port_id);
13980                 break;
13981         case -ENOTSUP:
13982                 printf("function not implemented\n");
13983                 break;
13984         default:
13985                 printf("programming error: (%s)\n", strerror(-ret));
13986         }
13987 }
13988
13989 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13990         .f = cmd_set_vf_mac_addr_parsed,
13991         .data = NULL,
13992         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13993         .tokens = {
13994                 (void *)&cmd_set_vf_mac_addr_set,
13995                 (void *)&cmd_set_vf_mac_addr_vf,
13996                 (void *)&cmd_set_vf_mac_addr_mac,
13997                 (void *)&cmd_set_vf_mac_addr_addr,
13998                 (void *)&cmd_set_vf_mac_addr_port_id,
13999                 (void *)&cmd_set_vf_mac_addr_vf_id,
14000                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14001                 NULL,
14002         },
14003 };
14004
14005 /* MACsec configuration */
14006
14007 /* Common result structure for MACsec offload enable */
14008 struct cmd_macsec_offload_on_result {
14009         cmdline_fixed_string_t set;
14010         cmdline_fixed_string_t macsec;
14011         cmdline_fixed_string_t offload;
14012         portid_t port_id;
14013         cmdline_fixed_string_t on;
14014         cmdline_fixed_string_t encrypt;
14015         cmdline_fixed_string_t en_on_off;
14016         cmdline_fixed_string_t replay_protect;
14017         cmdline_fixed_string_t rp_on_off;
14018 };
14019
14020 /* Common CLI fields for MACsec offload disable */
14021 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14022         TOKEN_STRING_INITIALIZER
14023                 (struct cmd_macsec_offload_on_result,
14024                  set, "set");
14025 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14026         TOKEN_STRING_INITIALIZER
14027                 (struct cmd_macsec_offload_on_result,
14028                  macsec, "macsec");
14029 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14030         TOKEN_STRING_INITIALIZER
14031                 (struct cmd_macsec_offload_on_result,
14032                  offload, "offload");
14033 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14034         TOKEN_NUM_INITIALIZER
14035                 (struct cmd_macsec_offload_on_result,
14036                  port_id, UINT16);
14037 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14038         TOKEN_STRING_INITIALIZER
14039                 (struct cmd_macsec_offload_on_result,
14040                  on, "on");
14041 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14042         TOKEN_STRING_INITIALIZER
14043                 (struct cmd_macsec_offload_on_result,
14044                  encrypt, "encrypt");
14045 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14046         TOKEN_STRING_INITIALIZER
14047                 (struct cmd_macsec_offload_on_result,
14048                  en_on_off, "on#off");
14049 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14050         TOKEN_STRING_INITIALIZER
14051                 (struct cmd_macsec_offload_on_result,
14052                  replay_protect, "replay-protect");
14053 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14054         TOKEN_STRING_INITIALIZER
14055                 (struct cmd_macsec_offload_on_result,
14056                  rp_on_off, "on#off");
14057
14058 static void
14059 cmd_set_macsec_offload_on_parsed(
14060         void *parsed_result,
14061         __attribute__((unused)) struct cmdline *cl,
14062         __attribute__((unused)) void *data)
14063 {
14064         struct cmd_macsec_offload_on_result *res = parsed_result;
14065         int ret = -ENOTSUP;
14066         portid_t port_id = res->port_id;
14067         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14068         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14069         struct rte_eth_dev_info dev_info;
14070
14071         if (port_id_is_invalid(port_id, ENABLED_WARN))
14072                 return;
14073         if (!port_is_stopped(port_id)) {
14074                 printf("Please stop port %d first\n", port_id);
14075                 return;
14076         }
14077
14078         rte_eth_dev_info_get(port_id, &dev_info);
14079         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14080 #ifdef RTE_LIBRTE_IXGBE_PMD
14081                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14082 #endif
14083         }
14084         RTE_SET_USED(en);
14085         RTE_SET_USED(rp);
14086
14087         switch (ret) {
14088         case 0:
14089                 ports[port_id].dev_conf.txmode.offloads |=
14090                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14091                 cmd_reconfig_device_queue(port_id, 1, 1);
14092                 break;
14093         case -ENODEV:
14094                 printf("invalid port_id %d\n", port_id);
14095                 break;
14096         case -ENOTSUP:
14097                 printf("not supported on port %d\n", port_id);
14098                 break;
14099         default:
14100                 printf("programming error: (%s)\n", strerror(-ret));
14101         }
14102 }
14103
14104 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14105         .f = cmd_set_macsec_offload_on_parsed,
14106         .data = NULL,
14107         .help_str = "set macsec offload <port_id> on "
14108                 "encrypt on|off replay-protect on|off",
14109         .tokens = {
14110                 (void *)&cmd_macsec_offload_on_set,
14111                 (void *)&cmd_macsec_offload_on_macsec,
14112                 (void *)&cmd_macsec_offload_on_offload,
14113                 (void *)&cmd_macsec_offload_on_port_id,
14114                 (void *)&cmd_macsec_offload_on_on,
14115                 (void *)&cmd_macsec_offload_on_encrypt,
14116                 (void *)&cmd_macsec_offload_on_en_on_off,
14117                 (void *)&cmd_macsec_offload_on_replay_protect,
14118                 (void *)&cmd_macsec_offload_on_rp_on_off,
14119                 NULL,
14120         },
14121 };
14122
14123 /* Common result structure for MACsec offload disable */
14124 struct cmd_macsec_offload_off_result {
14125         cmdline_fixed_string_t set;
14126         cmdline_fixed_string_t macsec;
14127         cmdline_fixed_string_t offload;
14128         portid_t port_id;
14129         cmdline_fixed_string_t off;
14130 };
14131
14132 /* Common CLI fields for MACsec offload disable */
14133 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14134         TOKEN_STRING_INITIALIZER
14135                 (struct cmd_macsec_offload_off_result,
14136                  set, "set");
14137 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14138         TOKEN_STRING_INITIALIZER
14139                 (struct cmd_macsec_offload_off_result,
14140                  macsec, "macsec");
14141 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14142         TOKEN_STRING_INITIALIZER
14143                 (struct cmd_macsec_offload_off_result,
14144                  offload, "offload");
14145 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14146         TOKEN_NUM_INITIALIZER
14147                 (struct cmd_macsec_offload_off_result,
14148                  port_id, UINT16);
14149 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14150         TOKEN_STRING_INITIALIZER
14151                 (struct cmd_macsec_offload_off_result,
14152                  off, "off");
14153
14154 static void
14155 cmd_set_macsec_offload_off_parsed(
14156         void *parsed_result,
14157         __attribute__((unused)) struct cmdline *cl,
14158         __attribute__((unused)) void *data)
14159 {
14160         struct cmd_macsec_offload_off_result *res = parsed_result;
14161         int ret = -ENOTSUP;
14162         struct rte_eth_dev_info dev_info;
14163         portid_t port_id = res->port_id;
14164
14165         if (port_id_is_invalid(port_id, ENABLED_WARN))
14166                 return;
14167         if (!port_is_stopped(port_id)) {
14168                 printf("Please stop port %d first\n", port_id);
14169                 return;
14170         }
14171
14172         rte_eth_dev_info_get(port_id, &dev_info);
14173         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14174 #ifdef RTE_LIBRTE_IXGBE_PMD
14175                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14176 #endif
14177         }
14178         switch (ret) {
14179         case 0:
14180                 ports[port_id].dev_conf.txmode.offloads &=
14181                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14182                 cmd_reconfig_device_queue(port_id, 1, 1);
14183                 break;
14184         case -ENODEV:
14185                 printf("invalid port_id %d\n", port_id);
14186                 break;
14187         case -ENOTSUP:
14188                 printf("not supported on port %d\n", port_id);
14189                 break;
14190         default:
14191                 printf("programming error: (%s)\n", strerror(-ret));
14192         }
14193 }
14194
14195 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14196         .f = cmd_set_macsec_offload_off_parsed,
14197         .data = NULL,
14198         .help_str = "set macsec offload <port_id> off",
14199         .tokens = {
14200                 (void *)&cmd_macsec_offload_off_set,
14201                 (void *)&cmd_macsec_offload_off_macsec,
14202                 (void *)&cmd_macsec_offload_off_offload,
14203                 (void *)&cmd_macsec_offload_off_port_id,
14204                 (void *)&cmd_macsec_offload_off_off,
14205                 NULL,
14206         },
14207 };
14208
14209 /* Common result structure for MACsec secure connection configure */
14210 struct cmd_macsec_sc_result {
14211         cmdline_fixed_string_t set;
14212         cmdline_fixed_string_t macsec;
14213         cmdline_fixed_string_t sc;
14214         cmdline_fixed_string_t tx_rx;
14215         portid_t port_id;
14216         struct rte_ether_addr mac;
14217         uint16_t pi;
14218 };
14219
14220 /* Common CLI fields for MACsec secure connection configure */
14221 cmdline_parse_token_string_t cmd_macsec_sc_set =
14222         TOKEN_STRING_INITIALIZER
14223                 (struct cmd_macsec_sc_result,
14224                  set, "set");
14225 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14226         TOKEN_STRING_INITIALIZER
14227                 (struct cmd_macsec_sc_result,
14228                  macsec, "macsec");
14229 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14230         TOKEN_STRING_INITIALIZER
14231                 (struct cmd_macsec_sc_result,
14232                  sc, "sc");
14233 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14234         TOKEN_STRING_INITIALIZER
14235                 (struct cmd_macsec_sc_result,
14236                  tx_rx, "tx#rx");
14237 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14238         TOKEN_NUM_INITIALIZER
14239                 (struct cmd_macsec_sc_result,
14240                  port_id, UINT16);
14241 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14242         TOKEN_ETHERADDR_INITIALIZER
14243                 (struct cmd_macsec_sc_result,
14244                  mac);
14245 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14246         TOKEN_NUM_INITIALIZER
14247                 (struct cmd_macsec_sc_result,
14248                  pi, UINT16);
14249
14250 static void
14251 cmd_set_macsec_sc_parsed(
14252         void *parsed_result,
14253         __attribute__((unused)) struct cmdline *cl,
14254         __attribute__((unused)) void *data)
14255 {
14256         struct cmd_macsec_sc_result *res = parsed_result;
14257         int ret = -ENOTSUP;
14258         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14259
14260 #ifdef RTE_LIBRTE_IXGBE_PMD
14261         ret = is_tx ?
14262                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14263                                 res->mac.addr_bytes) :
14264                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14265                                 res->mac.addr_bytes, res->pi);
14266 #endif
14267         RTE_SET_USED(is_tx);
14268
14269         switch (ret) {
14270         case 0:
14271                 break;
14272         case -ENODEV:
14273                 printf("invalid port_id %d\n", res->port_id);
14274                 break;
14275         case -ENOTSUP:
14276                 printf("not supported on port %d\n", res->port_id);
14277                 break;
14278         default:
14279                 printf("programming error: (%s)\n", strerror(-ret));
14280         }
14281 }
14282
14283 cmdline_parse_inst_t cmd_set_macsec_sc = {
14284         .f = cmd_set_macsec_sc_parsed,
14285         .data = NULL,
14286         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14287         .tokens = {
14288                 (void *)&cmd_macsec_sc_set,
14289                 (void *)&cmd_macsec_sc_macsec,
14290                 (void *)&cmd_macsec_sc_sc,
14291                 (void *)&cmd_macsec_sc_tx_rx,
14292                 (void *)&cmd_macsec_sc_port_id,
14293                 (void *)&cmd_macsec_sc_mac,
14294                 (void *)&cmd_macsec_sc_pi,
14295                 NULL,
14296         },
14297 };
14298
14299 /* Common result structure for MACsec secure connection configure */
14300 struct cmd_macsec_sa_result {
14301         cmdline_fixed_string_t set;
14302         cmdline_fixed_string_t macsec;
14303         cmdline_fixed_string_t sa;
14304         cmdline_fixed_string_t tx_rx;
14305         portid_t port_id;
14306         uint8_t idx;
14307         uint8_t an;
14308         uint32_t pn;
14309         cmdline_fixed_string_t key;
14310 };
14311
14312 /* Common CLI fields for MACsec secure connection configure */
14313 cmdline_parse_token_string_t cmd_macsec_sa_set =
14314         TOKEN_STRING_INITIALIZER
14315                 (struct cmd_macsec_sa_result,
14316                  set, "set");
14317 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14318         TOKEN_STRING_INITIALIZER
14319                 (struct cmd_macsec_sa_result,
14320                  macsec, "macsec");
14321 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14322         TOKEN_STRING_INITIALIZER
14323                 (struct cmd_macsec_sa_result,
14324                  sa, "sa");
14325 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14326         TOKEN_STRING_INITIALIZER
14327                 (struct cmd_macsec_sa_result,
14328                  tx_rx, "tx#rx");
14329 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14330         TOKEN_NUM_INITIALIZER
14331                 (struct cmd_macsec_sa_result,
14332                  port_id, UINT16);
14333 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14334         TOKEN_NUM_INITIALIZER
14335                 (struct cmd_macsec_sa_result,
14336                  idx, UINT8);
14337 cmdline_parse_token_num_t cmd_macsec_sa_an =
14338         TOKEN_NUM_INITIALIZER
14339                 (struct cmd_macsec_sa_result,
14340                  an, UINT8);
14341 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14342         TOKEN_NUM_INITIALIZER
14343                 (struct cmd_macsec_sa_result,
14344                  pn, UINT32);
14345 cmdline_parse_token_string_t cmd_macsec_sa_key =
14346         TOKEN_STRING_INITIALIZER
14347                 (struct cmd_macsec_sa_result,
14348                  key, NULL);
14349
14350 static void
14351 cmd_set_macsec_sa_parsed(
14352         void *parsed_result,
14353         __attribute__((unused)) struct cmdline *cl,
14354         __attribute__((unused)) void *data)
14355 {
14356         struct cmd_macsec_sa_result *res = parsed_result;
14357         int ret = -ENOTSUP;
14358         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14359         uint8_t key[16] = { 0 };
14360         uint8_t xdgt0;
14361         uint8_t xdgt1;
14362         int key_len;
14363         int i;
14364
14365         key_len = strlen(res->key) / 2;
14366         if (key_len > 16)
14367                 key_len = 16;
14368
14369         for (i = 0; i < key_len; i++) {
14370                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14371                 if (xdgt0 == 0xFF)
14372                         return;
14373                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14374                 if (xdgt1 == 0xFF)
14375                         return;
14376                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14377         }
14378
14379 #ifdef RTE_LIBRTE_IXGBE_PMD
14380         ret = is_tx ?
14381                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14382                         res->idx, res->an, res->pn, key) :
14383                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14384                         res->idx, res->an, res->pn, key);
14385 #endif
14386         RTE_SET_USED(is_tx);
14387         RTE_SET_USED(key);
14388
14389         switch (ret) {
14390         case 0:
14391                 break;
14392         case -EINVAL:
14393                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14394                 break;
14395         case -ENODEV:
14396                 printf("invalid port_id %d\n", res->port_id);
14397                 break;
14398         case -ENOTSUP:
14399                 printf("not supported on port %d\n", res->port_id);
14400                 break;
14401         default:
14402                 printf("programming error: (%s)\n", strerror(-ret));
14403         }
14404 }
14405
14406 cmdline_parse_inst_t cmd_set_macsec_sa = {
14407         .f = cmd_set_macsec_sa_parsed,
14408         .data = NULL,
14409         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14410         .tokens = {
14411                 (void *)&cmd_macsec_sa_set,
14412                 (void *)&cmd_macsec_sa_macsec,
14413                 (void *)&cmd_macsec_sa_sa,
14414                 (void *)&cmd_macsec_sa_tx_rx,
14415                 (void *)&cmd_macsec_sa_port_id,
14416                 (void *)&cmd_macsec_sa_idx,
14417                 (void *)&cmd_macsec_sa_an,
14418                 (void *)&cmd_macsec_sa_pn,
14419                 (void *)&cmd_macsec_sa_key,
14420                 NULL,
14421         },
14422 };
14423
14424 /* VF unicast promiscuous mode configuration */
14425
14426 /* Common result structure for VF unicast promiscuous mode */
14427 struct cmd_vf_promisc_result {
14428         cmdline_fixed_string_t set;
14429         cmdline_fixed_string_t vf;
14430         cmdline_fixed_string_t promisc;
14431         portid_t port_id;
14432         uint32_t vf_id;
14433         cmdline_fixed_string_t on_off;
14434 };
14435
14436 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14437 cmdline_parse_token_string_t cmd_vf_promisc_set =
14438         TOKEN_STRING_INITIALIZER
14439                 (struct cmd_vf_promisc_result,
14440                  set, "set");
14441 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14442         TOKEN_STRING_INITIALIZER
14443                 (struct cmd_vf_promisc_result,
14444                  vf, "vf");
14445 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14446         TOKEN_STRING_INITIALIZER
14447                 (struct cmd_vf_promisc_result,
14448                  promisc, "promisc");
14449 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14450         TOKEN_NUM_INITIALIZER
14451                 (struct cmd_vf_promisc_result,
14452                  port_id, UINT16);
14453 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14454         TOKEN_NUM_INITIALIZER
14455                 (struct cmd_vf_promisc_result,
14456                  vf_id, UINT32);
14457 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14458         TOKEN_STRING_INITIALIZER
14459                 (struct cmd_vf_promisc_result,
14460                  on_off, "on#off");
14461
14462 static void
14463 cmd_set_vf_promisc_parsed(
14464         void *parsed_result,
14465         __attribute__((unused)) struct cmdline *cl,
14466         __attribute__((unused)) void *data)
14467 {
14468         struct cmd_vf_promisc_result *res = parsed_result;
14469         int ret = -ENOTSUP;
14470
14471         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14472
14473         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14474                 return;
14475
14476 #ifdef RTE_LIBRTE_I40E_PMD
14477         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14478                                                   res->vf_id, is_on);
14479 #endif
14480
14481         switch (ret) {
14482         case 0:
14483                 break;
14484         case -EINVAL:
14485                 printf("invalid vf_id %d\n", res->vf_id);
14486                 break;
14487         case -ENODEV:
14488                 printf("invalid port_id %d\n", res->port_id);
14489                 break;
14490         case -ENOTSUP:
14491                 printf("function not implemented\n");
14492                 break;
14493         default:
14494                 printf("programming error: (%s)\n", strerror(-ret));
14495         }
14496 }
14497
14498 cmdline_parse_inst_t cmd_set_vf_promisc = {
14499         .f = cmd_set_vf_promisc_parsed,
14500         .data = NULL,
14501         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14502                 "Set unicast promiscuous mode for a VF from the PF",
14503         .tokens = {
14504                 (void *)&cmd_vf_promisc_set,
14505                 (void *)&cmd_vf_promisc_vf,
14506                 (void *)&cmd_vf_promisc_promisc,
14507                 (void *)&cmd_vf_promisc_port_id,
14508                 (void *)&cmd_vf_promisc_vf_id,
14509                 (void *)&cmd_vf_promisc_on_off,
14510                 NULL,
14511         },
14512 };
14513
14514 /* VF multicast promiscuous mode configuration */
14515
14516 /* Common result structure for VF multicast promiscuous mode */
14517 struct cmd_vf_allmulti_result {
14518         cmdline_fixed_string_t set;
14519         cmdline_fixed_string_t vf;
14520         cmdline_fixed_string_t allmulti;
14521         portid_t port_id;
14522         uint32_t vf_id;
14523         cmdline_fixed_string_t on_off;
14524 };
14525
14526 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14527 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14528         TOKEN_STRING_INITIALIZER
14529                 (struct cmd_vf_allmulti_result,
14530                  set, "set");
14531 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14532         TOKEN_STRING_INITIALIZER
14533                 (struct cmd_vf_allmulti_result,
14534                  vf, "vf");
14535 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14536         TOKEN_STRING_INITIALIZER
14537                 (struct cmd_vf_allmulti_result,
14538                  allmulti, "allmulti");
14539 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14540         TOKEN_NUM_INITIALIZER
14541                 (struct cmd_vf_allmulti_result,
14542                  port_id, UINT16);
14543 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14544         TOKEN_NUM_INITIALIZER
14545                 (struct cmd_vf_allmulti_result,
14546                  vf_id, UINT32);
14547 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14548         TOKEN_STRING_INITIALIZER
14549                 (struct cmd_vf_allmulti_result,
14550                  on_off, "on#off");
14551
14552 static void
14553 cmd_set_vf_allmulti_parsed(
14554         void *parsed_result,
14555         __attribute__((unused)) struct cmdline *cl,
14556         __attribute__((unused)) void *data)
14557 {
14558         struct cmd_vf_allmulti_result *res = parsed_result;
14559         int ret = -ENOTSUP;
14560
14561         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14562
14563         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14564                 return;
14565
14566 #ifdef RTE_LIBRTE_I40E_PMD
14567         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14568                                                     res->vf_id, is_on);
14569 #endif
14570
14571         switch (ret) {
14572         case 0:
14573                 break;
14574         case -EINVAL:
14575                 printf("invalid vf_id %d\n", res->vf_id);
14576                 break;
14577         case -ENODEV:
14578                 printf("invalid port_id %d\n", res->port_id);
14579                 break;
14580         case -ENOTSUP:
14581                 printf("function not implemented\n");
14582                 break;
14583         default:
14584                 printf("programming error: (%s)\n", strerror(-ret));
14585         }
14586 }
14587
14588 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14589         .f = cmd_set_vf_allmulti_parsed,
14590         .data = NULL,
14591         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14592                 "Set multicast promiscuous mode for a VF from the PF",
14593         .tokens = {
14594                 (void *)&cmd_vf_allmulti_set,
14595                 (void *)&cmd_vf_allmulti_vf,
14596                 (void *)&cmd_vf_allmulti_allmulti,
14597                 (void *)&cmd_vf_allmulti_port_id,
14598                 (void *)&cmd_vf_allmulti_vf_id,
14599                 (void *)&cmd_vf_allmulti_on_off,
14600                 NULL,
14601         },
14602 };
14603
14604 /* vf broadcast mode configuration */
14605
14606 /* Common result structure for vf broadcast */
14607 struct cmd_set_vf_broadcast_result {
14608         cmdline_fixed_string_t set;
14609         cmdline_fixed_string_t vf;
14610         cmdline_fixed_string_t broadcast;
14611         portid_t port_id;
14612         uint16_t vf_id;
14613         cmdline_fixed_string_t on_off;
14614 };
14615
14616 /* Common CLI fields for vf broadcast enable disable */
14617 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14618         TOKEN_STRING_INITIALIZER
14619                 (struct cmd_set_vf_broadcast_result,
14620                  set, "set");
14621 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14622         TOKEN_STRING_INITIALIZER
14623                 (struct cmd_set_vf_broadcast_result,
14624                  vf, "vf");
14625 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14626         TOKEN_STRING_INITIALIZER
14627                 (struct cmd_set_vf_broadcast_result,
14628                  broadcast, "broadcast");
14629 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14630         TOKEN_NUM_INITIALIZER
14631                 (struct cmd_set_vf_broadcast_result,
14632                  port_id, UINT16);
14633 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14634         TOKEN_NUM_INITIALIZER
14635                 (struct cmd_set_vf_broadcast_result,
14636                  vf_id, UINT16);
14637 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14638         TOKEN_STRING_INITIALIZER
14639                 (struct cmd_set_vf_broadcast_result,
14640                  on_off, "on#off");
14641
14642 static void
14643 cmd_set_vf_broadcast_parsed(
14644         void *parsed_result,
14645         __attribute__((unused)) struct cmdline *cl,
14646         __attribute__((unused)) void *data)
14647 {
14648         struct cmd_set_vf_broadcast_result *res = parsed_result;
14649         int ret = -ENOTSUP;
14650
14651         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14652
14653         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14654                 return;
14655
14656 #ifdef RTE_LIBRTE_I40E_PMD
14657         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14658                                             res->vf_id, is_on);
14659 #endif
14660
14661         switch (ret) {
14662         case 0:
14663                 break;
14664         case -EINVAL:
14665                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14666                 break;
14667         case -ENODEV:
14668                 printf("invalid port_id %d\n", res->port_id);
14669                 break;
14670         case -ENOTSUP:
14671                 printf("function not implemented\n");
14672                 break;
14673         default:
14674                 printf("programming error: (%s)\n", strerror(-ret));
14675         }
14676 }
14677
14678 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14679         .f = cmd_set_vf_broadcast_parsed,
14680         .data = NULL,
14681         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14682         .tokens = {
14683                 (void *)&cmd_set_vf_broadcast_set,
14684                 (void *)&cmd_set_vf_broadcast_vf,
14685                 (void *)&cmd_set_vf_broadcast_broadcast,
14686                 (void *)&cmd_set_vf_broadcast_port_id,
14687                 (void *)&cmd_set_vf_broadcast_vf_id,
14688                 (void *)&cmd_set_vf_broadcast_on_off,
14689                 NULL,
14690         },
14691 };
14692
14693 /* vf vlan tag configuration */
14694
14695 /* Common result structure for vf vlan tag */
14696 struct cmd_set_vf_vlan_tag_result {
14697         cmdline_fixed_string_t set;
14698         cmdline_fixed_string_t vf;
14699         cmdline_fixed_string_t vlan;
14700         cmdline_fixed_string_t tag;
14701         portid_t port_id;
14702         uint16_t vf_id;
14703         cmdline_fixed_string_t on_off;
14704 };
14705
14706 /* Common CLI fields for vf vlan tag enable disable */
14707 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14708         TOKEN_STRING_INITIALIZER
14709                 (struct cmd_set_vf_vlan_tag_result,
14710                  set, "set");
14711 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14712         TOKEN_STRING_INITIALIZER
14713                 (struct cmd_set_vf_vlan_tag_result,
14714                  vf, "vf");
14715 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14716         TOKEN_STRING_INITIALIZER
14717                 (struct cmd_set_vf_vlan_tag_result,
14718                  vlan, "vlan");
14719 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14720         TOKEN_STRING_INITIALIZER
14721                 (struct cmd_set_vf_vlan_tag_result,
14722                  tag, "tag");
14723 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14724         TOKEN_NUM_INITIALIZER
14725                 (struct cmd_set_vf_vlan_tag_result,
14726                  port_id, UINT16);
14727 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14728         TOKEN_NUM_INITIALIZER
14729                 (struct cmd_set_vf_vlan_tag_result,
14730                  vf_id, UINT16);
14731 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14732         TOKEN_STRING_INITIALIZER
14733                 (struct cmd_set_vf_vlan_tag_result,
14734                  on_off, "on#off");
14735
14736 static void
14737 cmd_set_vf_vlan_tag_parsed(
14738         void *parsed_result,
14739         __attribute__((unused)) struct cmdline *cl,
14740         __attribute__((unused)) void *data)
14741 {
14742         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14743         int ret = -ENOTSUP;
14744
14745         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14746
14747         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14748                 return;
14749
14750 #ifdef RTE_LIBRTE_I40E_PMD
14751         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14752                                            res->vf_id, is_on);
14753 #endif
14754
14755         switch (ret) {
14756         case 0:
14757                 break;
14758         case -EINVAL:
14759                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14760                 break;
14761         case -ENODEV:
14762                 printf("invalid port_id %d\n", res->port_id);
14763                 break;
14764         case -ENOTSUP:
14765                 printf("function not implemented\n");
14766                 break;
14767         default:
14768                 printf("programming error: (%s)\n", strerror(-ret));
14769         }
14770 }
14771
14772 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14773         .f = cmd_set_vf_vlan_tag_parsed,
14774         .data = NULL,
14775         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14776         .tokens = {
14777                 (void *)&cmd_set_vf_vlan_tag_set,
14778                 (void *)&cmd_set_vf_vlan_tag_vf,
14779                 (void *)&cmd_set_vf_vlan_tag_vlan,
14780                 (void *)&cmd_set_vf_vlan_tag_tag,
14781                 (void *)&cmd_set_vf_vlan_tag_port_id,
14782                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14783                 (void *)&cmd_set_vf_vlan_tag_on_off,
14784                 NULL,
14785         },
14786 };
14787
14788 /* Common definition of VF and TC TX bandwidth configuration */
14789 struct cmd_vf_tc_bw_result {
14790         cmdline_fixed_string_t set;
14791         cmdline_fixed_string_t vf;
14792         cmdline_fixed_string_t tc;
14793         cmdline_fixed_string_t tx;
14794         cmdline_fixed_string_t min_bw;
14795         cmdline_fixed_string_t max_bw;
14796         cmdline_fixed_string_t strict_link_prio;
14797         portid_t port_id;
14798         uint16_t vf_id;
14799         uint8_t tc_no;
14800         uint32_t bw;
14801         cmdline_fixed_string_t bw_list;
14802         uint8_t tc_map;
14803 };
14804
14805 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14806         TOKEN_STRING_INITIALIZER
14807                 (struct cmd_vf_tc_bw_result,
14808                  set, "set");
14809 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14810         TOKEN_STRING_INITIALIZER
14811                 (struct cmd_vf_tc_bw_result,
14812                  vf, "vf");
14813 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14814         TOKEN_STRING_INITIALIZER
14815                 (struct cmd_vf_tc_bw_result,
14816                  tc, "tc");
14817 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14818         TOKEN_STRING_INITIALIZER
14819                 (struct cmd_vf_tc_bw_result,
14820                  tx, "tx");
14821 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14822         TOKEN_STRING_INITIALIZER
14823                 (struct cmd_vf_tc_bw_result,
14824                  strict_link_prio, "strict-link-priority");
14825 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14826         TOKEN_STRING_INITIALIZER
14827                 (struct cmd_vf_tc_bw_result,
14828                  min_bw, "min-bandwidth");
14829 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14830         TOKEN_STRING_INITIALIZER
14831                 (struct cmd_vf_tc_bw_result,
14832                  max_bw, "max-bandwidth");
14833 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14834         TOKEN_NUM_INITIALIZER
14835                 (struct cmd_vf_tc_bw_result,
14836                  port_id, UINT16);
14837 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14838         TOKEN_NUM_INITIALIZER
14839                 (struct cmd_vf_tc_bw_result,
14840                  vf_id, UINT16);
14841 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14842         TOKEN_NUM_INITIALIZER
14843                 (struct cmd_vf_tc_bw_result,
14844                  tc_no, UINT8);
14845 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14846         TOKEN_NUM_INITIALIZER
14847                 (struct cmd_vf_tc_bw_result,
14848                  bw, UINT32);
14849 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14850         TOKEN_STRING_INITIALIZER
14851                 (struct cmd_vf_tc_bw_result,
14852                  bw_list, NULL);
14853 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14854         TOKEN_NUM_INITIALIZER
14855                 (struct cmd_vf_tc_bw_result,
14856                  tc_map, UINT8);
14857
14858 /* VF max bandwidth setting */
14859 static void
14860 cmd_vf_max_bw_parsed(
14861         void *parsed_result,
14862         __attribute__((unused)) struct cmdline *cl,
14863         __attribute__((unused)) void *data)
14864 {
14865         struct cmd_vf_tc_bw_result *res = parsed_result;
14866         int ret = -ENOTSUP;
14867
14868         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14869                 return;
14870
14871 #ifdef RTE_LIBRTE_I40E_PMD
14872         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14873                                          res->vf_id, res->bw);
14874 #endif
14875
14876         switch (ret) {
14877         case 0:
14878                 break;
14879         case -EINVAL:
14880                 printf("invalid vf_id %d or bandwidth %d\n",
14881                        res->vf_id, res->bw);
14882                 break;
14883         case -ENODEV:
14884                 printf("invalid port_id %d\n", res->port_id);
14885                 break;
14886         case -ENOTSUP:
14887                 printf("function not implemented\n");
14888                 break;
14889         default:
14890                 printf("programming error: (%s)\n", strerror(-ret));
14891         }
14892 }
14893
14894 cmdline_parse_inst_t cmd_vf_max_bw = {
14895         .f = cmd_vf_max_bw_parsed,
14896         .data = NULL,
14897         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14898         .tokens = {
14899                 (void *)&cmd_vf_tc_bw_set,
14900                 (void *)&cmd_vf_tc_bw_vf,
14901                 (void *)&cmd_vf_tc_bw_tx,
14902                 (void *)&cmd_vf_tc_bw_max_bw,
14903                 (void *)&cmd_vf_tc_bw_port_id,
14904                 (void *)&cmd_vf_tc_bw_vf_id,
14905                 (void *)&cmd_vf_tc_bw_bw,
14906                 NULL,
14907         },
14908 };
14909
14910 static int
14911 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14912                            uint8_t *tc_num,
14913                            char *str)
14914 {
14915         uint32_t size;
14916         const char *p, *p0 = str;
14917         char s[256];
14918         char *end;
14919         char *str_fld[16];
14920         uint16_t i;
14921         int ret;
14922
14923         p = strchr(p0, '(');
14924         if (p == NULL) {
14925                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14926                 return -1;
14927         }
14928         p++;
14929         p0 = strchr(p, ')');
14930         if (p0 == NULL) {
14931                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14932                 return -1;
14933         }
14934         size = p0 - p;
14935         if (size >= sizeof(s)) {
14936                 printf("The string size exceeds the internal buffer size\n");
14937                 return -1;
14938         }
14939         snprintf(s, sizeof(s), "%.*s", size, p);
14940         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14941         if (ret <= 0) {
14942                 printf("Failed to get the bandwidth list. ");
14943                 return -1;
14944         }
14945         *tc_num = ret;
14946         for (i = 0; i < ret; i++)
14947                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14948
14949         return 0;
14950 }
14951
14952 /* TC min bandwidth setting */
14953 static void
14954 cmd_vf_tc_min_bw_parsed(
14955         void *parsed_result,
14956         __attribute__((unused)) struct cmdline *cl,
14957         __attribute__((unused)) void *data)
14958 {
14959         struct cmd_vf_tc_bw_result *res = parsed_result;
14960         uint8_t tc_num;
14961         uint8_t bw[16];
14962         int ret = -ENOTSUP;
14963
14964         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14965                 return;
14966
14967         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14968         if (ret)
14969                 return;
14970
14971 #ifdef RTE_LIBRTE_I40E_PMD
14972         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14973                                               tc_num, bw);
14974 #endif
14975
14976         switch (ret) {
14977         case 0:
14978                 break;
14979         case -EINVAL:
14980                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14981                 break;
14982         case -ENODEV:
14983                 printf("invalid port_id %d\n", res->port_id);
14984                 break;
14985         case -ENOTSUP:
14986                 printf("function not implemented\n");
14987                 break;
14988         default:
14989                 printf("programming error: (%s)\n", strerror(-ret));
14990         }
14991 }
14992
14993 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14994         .f = cmd_vf_tc_min_bw_parsed,
14995         .data = NULL,
14996         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14997                     " <bw1, bw2, ...>",
14998         .tokens = {
14999                 (void *)&cmd_vf_tc_bw_set,
15000                 (void *)&cmd_vf_tc_bw_vf,
15001                 (void *)&cmd_vf_tc_bw_tc,
15002                 (void *)&cmd_vf_tc_bw_tx,
15003                 (void *)&cmd_vf_tc_bw_min_bw,
15004                 (void *)&cmd_vf_tc_bw_port_id,
15005                 (void *)&cmd_vf_tc_bw_vf_id,
15006                 (void *)&cmd_vf_tc_bw_bw_list,
15007                 NULL,
15008         },
15009 };
15010
15011 static void
15012 cmd_tc_min_bw_parsed(
15013         void *parsed_result,
15014         __attribute__((unused)) struct cmdline *cl,
15015         __attribute__((unused)) void *data)
15016 {
15017         struct cmd_vf_tc_bw_result *res = parsed_result;
15018         struct rte_port *port;
15019         uint8_t tc_num;
15020         uint8_t bw[16];
15021         int ret = -ENOTSUP;
15022
15023         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15024                 return;
15025
15026         port = &ports[res->port_id];
15027         /** Check if the port is not started **/
15028         if (port->port_status != RTE_PORT_STOPPED) {
15029                 printf("Please stop port %d first\n", res->port_id);
15030                 return;
15031         }
15032
15033         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15034         if (ret)
15035                 return;
15036
15037 #ifdef RTE_LIBRTE_IXGBE_PMD
15038         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15039 #endif
15040
15041         switch (ret) {
15042         case 0:
15043                 break;
15044         case -EINVAL:
15045                 printf("invalid bandwidth\n");
15046                 break;
15047         case -ENODEV:
15048                 printf("invalid port_id %d\n", res->port_id);
15049                 break;
15050         case -ENOTSUP:
15051                 printf("function not implemented\n");
15052                 break;
15053         default:
15054                 printf("programming error: (%s)\n", strerror(-ret));
15055         }
15056 }
15057
15058 cmdline_parse_inst_t cmd_tc_min_bw = {
15059         .f = cmd_tc_min_bw_parsed,
15060         .data = NULL,
15061         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15062         .tokens = {
15063                 (void *)&cmd_vf_tc_bw_set,
15064                 (void *)&cmd_vf_tc_bw_tc,
15065                 (void *)&cmd_vf_tc_bw_tx,
15066                 (void *)&cmd_vf_tc_bw_min_bw,
15067                 (void *)&cmd_vf_tc_bw_port_id,
15068                 (void *)&cmd_vf_tc_bw_bw_list,
15069                 NULL,
15070         },
15071 };
15072
15073 /* TC max bandwidth setting */
15074 static void
15075 cmd_vf_tc_max_bw_parsed(
15076         void *parsed_result,
15077         __attribute__((unused)) struct cmdline *cl,
15078         __attribute__((unused)) void *data)
15079 {
15080         struct cmd_vf_tc_bw_result *res = parsed_result;
15081         int ret = -ENOTSUP;
15082
15083         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15084                 return;
15085
15086 #ifdef RTE_LIBRTE_I40E_PMD
15087         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15088                                             res->tc_no, res->bw);
15089 #endif
15090
15091         switch (ret) {
15092         case 0:
15093                 break;
15094         case -EINVAL:
15095                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15096                        res->vf_id, res->tc_no, res->bw);
15097                 break;
15098         case -ENODEV:
15099                 printf("invalid port_id %d\n", res->port_id);
15100                 break;
15101         case -ENOTSUP:
15102                 printf("function not implemented\n");
15103                 break;
15104         default:
15105                 printf("programming error: (%s)\n", strerror(-ret));
15106         }
15107 }
15108
15109 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15110         .f = cmd_vf_tc_max_bw_parsed,
15111         .data = NULL,
15112         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15113                     " <bandwidth>",
15114         .tokens = {
15115                 (void *)&cmd_vf_tc_bw_set,
15116                 (void *)&cmd_vf_tc_bw_vf,
15117                 (void *)&cmd_vf_tc_bw_tc,
15118                 (void *)&cmd_vf_tc_bw_tx,
15119                 (void *)&cmd_vf_tc_bw_max_bw,
15120                 (void *)&cmd_vf_tc_bw_port_id,
15121                 (void *)&cmd_vf_tc_bw_vf_id,
15122                 (void *)&cmd_vf_tc_bw_tc_no,
15123                 (void *)&cmd_vf_tc_bw_bw,
15124                 NULL,
15125         },
15126 };
15127
15128
15129 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15130
15131 /* *** Set Port default Traffic Management Hierarchy *** */
15132 struct cmd_set_port_tm_hierarchy_default_result {
15133         cmdline_fixed_string_t set;
15134         cmdline_fixed_string_t port;
15135         cmdline_fixed_string_t tm;
15136         cmdline_fixed_string_t hierarchy;
15137         cmdline_fixed_string_t def;
15138         portid_t port_id;
15139 };
15140
15141 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15142         TOKEN_STRING_INITIALIZER(
15143                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15144 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15145         TOKEN_STRING_INITIALIZER(
15146                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15147 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15148         TOKEN_STRING_INITIALIZER(
15149                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15150 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15151         TOKEN_STRING_INITIALIZER(
15152                 struct cmd_set_port_tm_hierarchy_default_result,
15153                         hierarchy, "hierarchy");
15154 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15155         TOKEN_STRING_INITIALIZER(
15156                 struct cmd_set_port_tm_hierarchy_default_result,
15157                         def, "default");
15158 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15159         TOKEN_NUM_INITIALIZER(
15160                 struct cmd_set_port_tm_hierarchy_default_result,
15161                         port_id, UINT16);
15162
15163 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15164         __attribute__((unused)) struct cmdline *cl,
15165         __attribute__((unused)) void *data)
15166 {
15167         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15168         struct rte_port *p;
15169         portid_t port_id = res->port_id;
15170
15171         if (port_id_is_invalid(port_id, ENABLED_WARN))
15172                 return;
15173
15174         p = &ports[port_id];
15175
15176         /* Forward mode: tm */
15177         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15178                 printf("  softnicfwd mode not enabled(error)\n");
15179                 return;
15180         }
15181
15182         /* Set the default tm hierarchy */
15183         p->softport.default_tm_hierarchy_enable = 1;
15184 }
15185
15186 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15187         .f = cmd_set_port_tm_hierarchy_default_parsed,
15188         .data = NULL,
15189         .help_str = "set port tm hierarchy default <port_id>",
15190         .tokens = {
15191                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15192                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15193                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15194                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15195                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15196                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15197                 NULL,
15198         },
15199 };
15200 #endif
15201
15202 /** Set VXLAN encapsulation details */
15203 struct cmd_set_vxlan_result {
15204         cmdline_fixed_string_t set;
15205         cmdline_fixed_string_t vxlan;
15206         cmdline_fixed_string_t pos_token;
15207         cmdline_fixed_string_t ip_version;
15208         uint32_t vlan_present:1;
15209         uint32_t vni;
15210         uint16_t udp_src;
15211         uint16_t udp_dst;
15212         cmdline_ipaddr_t ip_src;
15213         cmdline_ipaddr_t ip_dst;
15214         uint16_t tci;
15215         uint8_t tos;
15216         uint8_t ttl;
15217         struct rte_ether_addr eth_src;
15218         struct rte_ether_addr eth_dst;
15219 };
15220
15221 cmdline_parse_token_string_t cmd_set_vxlan_set =
15222         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15223 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15224         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15225 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15226         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15227                                  "vxlan-tos-ttl");
15228 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15229         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15230                                  "vxlan-with-vlan");
15231 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15232         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15233                                  "ip-version");
15234 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15235         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15236                                  "ipv4#ipv6");
15237 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15238         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15239                                  "vni");
15240 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15241         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15242 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15243         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15244                                  "udp-src");
15245 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15246         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15247 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15248         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15249                                  "udp-dst");
15250 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15251         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15252 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15253         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15254                                  "ip-tos");
15255 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15256         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15257 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15258         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15259                                  "ip-ttl");
15260 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15261         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15262 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15263         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15264                                  "ip-src");
15265 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15266         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15267 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15268         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15269                                  "ip-dst");
15270 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15271         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15272 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15273         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15274                                  "vlan-tci");
15275 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15276         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15277 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15278         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15279                                  "eth-src");
15280 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15281         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15282 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15283         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15284                                  "eth-dst");
15285 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15286         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15287
15288 static void cmd_set_vxlan_parsed(void *parsed_result,
15289         __attribute__((unused)) struct cmdline *cl,
15290         __attribute__((unused)) void *data)
15291 {
15292         struct cmd_set_vxlan_result *res = parsed_result;
15293         union {
15294                 uint32_t vxlan_id;
15295                 uint8_t vni[4];
15296         } id = {
15297                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15298         };
15299
15300         vxlan_encap_conf.select_tos_ttl = 0;
15301         if (strcmp(res->vxlan, "vxlan") == 0)
15302                 vxlan_encap_conf.select_vlan = 0;
15303         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15304                 vxlan_encap_conf.select_vlan = 1;
15305         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15306                 vxlan_encap_conf.select_vlan = 0;
15307                 vxlan_encap_conf.select_tos_ttl = 1;
15308         }
15309         if (strcmp(res->ip_version, "ipv4") == 0)
15310                 vxlan_encap_conf.select_ipv4 = 1;
15311         else if (strcmp(res->ip_version, "ipv6") == 0)
15312                 vxlan_encap_conf.select_ipv4 = 0;
15313         else
15314                 return;
15315         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15316         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15317         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15318         vxlan_encap_conf.ip_tos = res->tos;
15319         vxlan_encap_conf.ip_ttl = res->ttl;
15320         if (vxlan_encap_conf.select_ipv4) {
15321                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15322                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15323         } else {
15324                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15325                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15326         }
15327         if (vxlan_encap_conf.select_vlan)
15328                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15329         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15330                    RTE_ETHER_ADDR_LEN);
15331         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15332                    RTE_ETHER_ADDR_LEN);
15333 }
15334
15335 cmdline_parse_inst_t cmd_set_vxlan = {
15336         .f = cmd_set_vxlan_parsed,
15337         .data = NULL,
15338         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15339                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15340                 " eth-src <eth-src> eth-dst <eth-dst>",
15341         .tokens = {
15342                 (void *)&cmd_set_vxlan_set,
15343                 (void *)&cmd_set_vxlan_vxlan,
15344                 (void *)&cmd_set_vxlan_ip_version,
15345                 (void *)&cmd_set_vxlan_ip_version_value,
15346                 (void *)&cmd_set_vxlan_vni,
15347                 (void *)&cmd_set_vxlan_vni_value,
15348                 (void *)&cmd_set_vxlan_udp_src,
15349                 (void *)&cmd_set_vxlan_udp_src_value,
15350                 (void *)&cmd_set_vxlan_udp_dst,
15351                 (void *)&cmd_set_vxlan_udp_dst_value,
15352                 (void *)&cmd_set_vxlan_ip_src,
15353                 (void *)&cmd_set_vxlan_ip_src_value,
15354                 (void *)&cmd_set_vxlan_ip_dst,
15355                 (void *)&cmd_set_vxlan_ip_dst_value,
15356                 (void *)&cmd_set_vxlan_eth_src,
15357                 (void *)&cmd_set_vxlan_eth_src_value,
15358                 (void *)&cmd_set_vxlan_eth_dst,
15359                 (void *)&cmd_set_vxlan_eth_dst_value,
15360                 NULL,
15361         },
15362 };
15363
15364 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15365         .f = cmd_set_vxlan_parsed,
15366         .data = NULL,
15367         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15368                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15369                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15370                 " eth-dst <eth-dst>",
15371         .tokens = {
15372                 (void *)&cmd_set_vxlan_set,
15373                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15374                 (void *)&cmd_set_vxlan_ip_version,
15375                 (void *)&cmd_set_vxlan_ip_version_value,
15376                 (void *)&cmd_set_vxlan_vni,
15377                 (void *)&cmd_set_vxlan_vni_value,
15378                 (void *)&cmd_set_vxlan_udp_src,
15379                 (void *)&cmd_set_vxlan_udp_src_value,
15380                 (void *)&cmd_set_vxlan_udp_dst,
15381                 (void *)&cmd_set_vxlan_udp_dst_value,
15382                 (void *)&cmd_set_vxlan_ip_tos,
15383                 (void *)&cmd_set_vxlan_ip_tos_value,
15384                 (void *)&cmd_set_vxlan_ip_ttl,
15385                 (void *)&cmd_set_vxlan_ip_ttl_value,
15386                 (void *)&cmd_set_vxlan_ip_src,
15387                 (void *)&cmd_set_vxlan_ip_src_value,
15388                 (void *)&cmd_set_vxlan_ip_dst,
15389                 (void *)&cmd_set_vxlan_ip_dst_value,
15390                 (void *)&cmd_set_vxlan_eth_src,
15391                 (void *)&cmd_set_vxlan_eth_src_value,
15392                 (void *)&cmd_set_vxlan_eth_dst,
15393                 (void *)&cmd_set_vxlan_eth_dst_value,
15394                 NULL,
15395         },
15396 };
15397
15398 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15399         .f = cmd_set_vxlan_parsed,
15400         .data = NULL,
15401         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15402                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15403                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15404                 " <eth-dst>",
15405         .tokens = {
15406                 (void *)&cmd_set_vxlan_set,
15407                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15408                 (void *)&cmd_set_vxlan_ip_version,
15409                 (void *)&cmd_set_vxlan_ip_version_value,
15410                 (void *)&cmd_set_vxlan_vni,
15411                 (void *)&cmd_set_vxlan_vni_value,
15412                 (void *)&cmd_set_vxlan_udp_src,
15413                 (void *)&cmd_set_vxlan_udp_src_value,
15414                 (void *)&cmd_set_vxlan_udp_dst,
15415                 (void *)&cmd_set_vxlan_udp_dst_value,
15416                 (void *)&cmd_set_vxlan_ip_src,
15417                 (void *)&cmd_set_vxlan_ip_src_value,
15418                 (void *)&cmd_set_vxlan_ip_dst,
15419                 (void *)&cmd_set_vxlan_ip_dst_value,
15420                 (void *)&cmd_set_vxlan_vlan,
15421                 (void *)&cmd_set_vxlan_vlan_value,
15422                 (void *)&cmd_set_vxlan_eth_src,
15423                 (void *)&cmd_set_vxlan_eth_src_value,
15424                 (void *)&cmd_set_vxlan_eth_dst,
15425                 (void *)&cmd_set_vxlan_eth_dst_value,
15426                 NULL,
15427         },
15428 };
15429
15430 /** Set NVGRE encapsulation details */
15431 struct cmd_set_nvgre_result {
15432         cmdline_fixed_string_t set;
15433         cmdline_fixed_string_t nvgre;
15434         cmdline_fixed_string_t pos_token;
15435         cmdline_fixed_string_t ip_version;
15436         uint32_t tni;
15437         cmdline_ipaddr_t ip_src;
15438         cmdline_ipaddr_t ip_dst;
15439         uint16_t tci;
15440         struct rte_ether_addr eth_src;
15441         struct rte_ether_addr eth_dst;
15442 };
15443
15444 cmdline_parse_token_string_t cmd_set_nvgre_set =
15445         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15446 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15447         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15448 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15449         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15450                                  "nvgre-with-vlan");
15451 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15452         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15453                                  "ip-version");
15454 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15455         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15456                                  "ipv4#ipv6");
15457 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15458         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15459                                  "tni");
15460 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15461         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15462 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15463         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15464                                  "ip-src");
15465 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15466         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15467 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15468         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15469                                  "ip-dst");
15470 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15471         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15472 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15473         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15474                                  "vlan-tci");
15475 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15476         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15477 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15478         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15479                                  "eth-src");
15480 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15481         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15482 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15483         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15484                                  "eth-dst");
15485 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15486         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15487
15488 static void cmd_set_nvgre_parsed(void *parsed_result,
15489         __attribute__((unused)) struct cmdline *cl,
15490         __attribute__((unused)) void *data)
15491 {
15492         struct cmd_set_nvgre_result *res = parsed_result;
15493         union {
15494                 uint32_t nvgre_tni;
15495                 uint8_t tni[4];
15496         } id = {
15497                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15498         };
15499
15500         if (strcmp(res->nvgre, "nvgre") == 0)
15501                 nvgre_encap_conf.select_vlan = 0;
15502         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15503                 nvgre_encap_conf.select_vlan = 1;
15504         if (strcmp(res->ip_version, "ipv4") == 0)
15505                 nvgre_encap_conf.select_ipv4 = 1;
15506         else if (strcmp(res->ip_version, "ipv6") == 0)
15507                 nvgre_encap_conf.select_ipv4 = 0;
15508         else
15509                 return;
15510         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15511         if (nvgre_encap_conf.select_ipv4) {
15512                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15513                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15514         } else {
15515                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15516                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15517         }
15518         if (nvgre_encap_conf.select_vlan)
15519                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15520         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15521                    RTE_ETHER_ADDR_LEN);
15522         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15523                    RTE_ETHER_ADDR_LEN);
15524 }
15525
15526 cmdline_parse_inst_t cmd_set_nvgre = {
15527         .f = cmd_set_nvgre_parsed,
15528         .data = NULL,
15529         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15530                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15531                 " eth-dst <eth-dst>",
15532         .tokens = {
15533                 (void *)&cmd_set_nvgre_set,
15534                 (void *)&cmd_set_nvgre_nvgre,
15535                 (void *)&cmd_set_nvgre_ip_version,
15536                 (void *)&cmd_set_nvgre_ip_version_value,
15537                 (void *)&cmd_set_nvgre_tni,
15538                 (void *)&cmd_set_nvgre_tni_value,
15539                 (void *)&cmd_set_nvgre_ip_src,
15540                 (void *)&cmd_set_nvgre_ip_src_value,
15541                 (void *)&cmd_set_nvgre_ip_dst,
15542                 (void *)&cmd_set_nvgre_ip_dst_value,
15543                 (void *)&cmd_set_nvgre_eth_src,
15544                 (void *)&cmd_set_nvgre_eth_src_value,
15545                 (void *)&cmd_set_nvgre_eth_dst,
15546                 (void *)&cmd_set_nvgre_eth_dst_value,
15547                 NULL,
15548         },
15549 };
15550
15551 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15552         .f = cmd_set_nvgre_parsed,
15553         .data = NULL,
15554         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15555                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15556                 " eth-src <eth-src> eth-dst <eth-dst>",
15557         .tokens = {
15558                 (void *)&cmd_set_nvgre_set,
15559                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15560                 (void *)&cmd_set_nvgre_ip_version,
15561                 (void *)&cmd_set_nvgre_ip_version_value,
15562                 (void *)&cmd_set_nvgre_tni,
15563                 (void *)&cmd_set_nvgre_tni_value,
15564                 (void *)&cmd_set_nvgre_ip_src,
15565                 (void *)&cmd_set_nvgre_ip_src_value,
15566                 (void *)&cmd_set_nvgre_ip_dst,
15567                 (void *)&cmd_set_nvgre_ip_dst_value,
15568                 (void *)&cmd_set_nvgre_vlan,
15569                 (void *)&cmd_set_nvgre_vlan_value,
15570                 (void *)&cmd_set_nvgre_eth_src,
15571                 (void *)&cmd_set_nvgre_eth_src_value,
15572                 (void *)&cmd_set_nvgre_eth_dst,
15573                 (void *)&cmd_set_nvgre_eth_dst_value,
15574                 NULL,
15575         },
15576 };
15577
15578 /** Set L2 encapsulation details */
15579 struct cmd_set_l2_encap_result {
15580         cmdline_fixed_string_t set;
15581         cmdline_fixed_string_t l2_encap;
15582         cmdline_fixed_string_t pos_token;
15583         cmdline_fixed_string_t ip_version;
15584         uint32_t vlan_present:1;
15585         uint16_t tci;
15586         struct rte_ether_addr eth_src;
15587         struct rte_ether_addr eth_dst;
15588 };
15589
15590 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15591         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15592 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15593         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15594 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15595         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15596                                  "l2_encap-with-vlan");
15597 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15598         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15599                                  "ip-version");
15600 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15601         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15602                                  "ipv4#ipv6");
15603 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15604         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15605                                  "vlan-tci");
15606 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15607         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15608 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15609         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15610                                  "eth-src");
15611 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15612         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15613 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15614         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15615                                  "eth-dst");
15616 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15617         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15618
15619 static void cmd_set_l2_encap_parsed(void *parsed_result,
15620         __attribute__((unused)) struct cmdline *cl,
15621         __attribute__((unused)) void *data)
15622 {
15623         struct cmd_set_l2_encap_result *res = parsed_result;
15624
15625         if (strcmp(res->l2_encap, "l2_encap") == 0)
15626                 l2_encap_conf.select_vlan = 0;
15627         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15628                 l2_encap_conf.select_vlan = 1;
15629         if (strcmp(res->ip_version, "ipv4") == 0)
15630                 l2_encap_conf.select_ipv4 = 1;
15631         else if (strcmp(res->ip_version, "ipv6") == 0)
15632                 l2_encap_conf.select_ipv4 = 0;
15633         else
15634                 return;
15635         if (l2_encap_conf.select_vlan)
15636                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15637         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15638                    RTE_ETHER_ADDR_LEN);
15639         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15640                    RTE_ETHER_ADDR_LEN);
15641 }
15642
15643 cmdline_parse_inst_t cmd_set_l2_encap = {
15644         .f = cmd_set_l2_encap_parsed,
15645         .data = NULL,
15646         .help_str = "set l2_encap ip-version ipv4|ipv6"
15647                 " eth-src <eth-src> eth-dst <eth-dst>",
15648         .tokens = {
15649                 (void *)&cmd_set_l2_encap_set,
15650                 (void *)&cmd_set_l2_encap_l2_encap,
15651                 (void *)&cmd_set_l2_encap_ip_version,
15652                 (void *)&cmd_set_l2_encap_ip_version_value,
15653                 (void *)&cmd_set_l2_encap_eth_src,
15654                 (void *)&cmd_set_l2_encap_eth_src_value,
15655                 (void *)&cmd_set_l2_encap_eth_dst,
15656                 (void *)&cmd_set_l2_encap_eth_dst_value,
15657                 NULL,
15658         },
15659 };
15660
15661 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15662         .f = cmd_set_l2_encap_parsed,
15663         .data = NULL,
15664         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15665                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15666         .tokens = {
15667                 (void *)&cmd_set_l2_encap_set,
15668                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15669                 (void *)&cmd_set_l2_encap_ip_version,
15670                 (void *)&cmd_set_l2_encap_ip_version_value,
15671                 (void *)&cmd_set_l2_encap_vlan,
15672                 (void *)&cmd_set_l2_encap_vlan_value,
15673                 (void *)&cmd_set_l2_encap_eth_src,
15674                 (void *)&cmd_set_l2_encap_eth_src_value,
15675                 (void *)&cmd_set_l2_encap_eth_dst,
15676                 (void *)&cmd_set_l2_encap_eth_dst_value,
15677                 NULL,
15678         },
15679 };
15680
15681 /** Set L2 decapsulation details */
15682 struct cmd_set_l2_decap_result {
15683         cmdline_fixed_string_t set;
15684         cmdline_fixed_string_t l2_decap;
15685         cmdline_fixed_string_t pos_token;
15686         uint32_t vlan_present:1;
15687 };
15688
15689 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15690         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15691 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15692         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15693                                  "l2_decap");
15694 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15695         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15696                                  "l2_decap-with-vlan");
15697
15698 static void cmd_set_l2_decap_parsed(void *parsed_result,
15699         __attribute__((unused)) struct cmdline *cl,
15700         __attribute__((unused)) void *data)
15701 {
15702         struct cmd_set_l2_decap_result *res = parsed_result;
15703
15704         if (strcmp(res->l2_decap, "l2_decap") == 0)
15705                 l2_decap_conf.select_vlan = 0;
15706         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15707                 l2_decap_conf.select_vlan = 1;
15708 }
15709
15710 cmdline_parse_inst_t cmd_set_l2_decap = {
15711         .f = cmd_set_l2_decap_parsed,
15712         .data = NULL,
15713         .help_str = "set l2_decap",
15714         .tokens = {
15715                 (void *)&cmd_set_l2_decap_set,
15716                 (void *)&cmd_set_l2_decap_l2_decap,
15717                 NULL,
15718         },
15719 };
15720
15721 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15722         .f = cmd_set_l2_decap_parsed,
15723         .data = NULL,
15724         .help_str = "set l2_decap-with-vlan",
15725         .tokens = {
15726                 (void *)&cmd_set_l2_decap_set,
15727                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15728                 NULL,
15729         },
15730 };
15731
15732 /** Set MPLSoGRE encapsulation details */
15733 struct cmd_set_mplsogre_encap_result {
15734         cmdline_fixed_string_t set;
15735         cmdline_fixed_string_t mplsogre;
15736         cmdline_fixed_string_t pos_token;
15737         cmdline_fixed_string_t ip_version;
15738         uint32_t vlan_present:1;
15739         uint32_t label;
15740         cmdline_ipaddr_t ip_src;
15741         cmdline_ipaddr_t ip_dst;
15742         uint16_t tci;
15743         struct rte_ether_addr eth_src;
15744         struct rte_ether_addr eth_dst;
15745 };
15746
15747 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15748         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15749                                  "set");
15750 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15751         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15752                                  "mplsogre_encap");
15753 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15754         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15755                                  mplsogre, "mplsogre_encap-with-vlan");
15756 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15757         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15758                                  pos_token, "ip-version");
15759 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15760         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15761                                  ip_version, "ipv4#ipv6");
15762 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15763         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15764                                  pos_token, "label");
15765 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15766         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15767                               UINT32);
15768 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15769         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15770                                  pos_token, "ip-src");
15771 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15772         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15773 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15774         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15775                                  pos_token, "ip-dst");
15776 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15777         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15778 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15779         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15780                                  pos_token, "vlan-tci");
15781 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15782         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15783                               UINT16);
15784 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15785         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15786                                  pos_token, "eth-src");
15787 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15788         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15789                                     eth_src);
15790 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15791         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15792                                  pos_token, "eth-dst");
15793 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15794         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15795                                     eth_dst);
15796
15797 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15798         __attribute__((unused)) struct cmdline *cl,
15799         __attribute__((unused)) void *data)
15800 {
15801         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15802         union {
15803                 uint32_t mplsogre_label;
15804                 uint8_t label[4];
15805         } id = {
15806                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15807         };
15808
15809         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15810                 mplsogre_encap_conf.select_vlan = 0;
15811         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15812                 mplsogre_encap_conf.select_vlan = 1;
15813         if (strcmp(res->ip_version, "ipv4") == 0)
15814                 mplsogre_encap_conf.select_ipv4 = 1;
15815         else if (strcmp(res->ip_version, "ipv6") == 0)
15816                 mplsogre_encap_conf.select_ipv4 = 0;
15817         else
15818                 return;
15819         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15820         if (mplsogre_encap_conf.select_ipv4) {
15821                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15822                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15823         } else {
15824                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15825                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15826         }
15827         if (mplsogre_encap_conf.select_vlan)
15828                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15829         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15830                    RTE_ETHER_ADDR_LEN);
15831         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15832                    RTE_ETHER_ADDR_LEN);
15833 }
15834
15835 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15836         .f = cmd_set_mplsogre_encap_parsed,
15837         .data = NULL,
15838         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15839                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15840                 " eth-dst <eth-dst>",
15841         .tokens = {
15842                 (void *)&cmd_set_mplsogre_encap_set,
15843                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15844                 (void *)&cmd_set_mplsogre_encap_ip_version,
15845                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15846                 (void *)&cmd_set_mplsogre_encap_label,
15847                 (void *)&cmd_set_mplsogre_encap_label_value,
15848                 (void *)&cmd_set_mplsogre_encap_ip_src,
15849                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15850                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15851                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15852                 (void *)&cmd_set_mplsogre_encap_eth_src,
15853                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15854                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15855                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15856                 NULL,
15857         },
15858 };
15859
15860 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15861         .f = cmd_set_mplsogre_encap_parsed,
15862         .data = NULL,
15863         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15864                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15865                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15866         .tokens = {
15867                 (void *)&cmd_set_mplsogre_encap_set,
15868                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15869                 (void *)&cmd_set_mplsogre_encap_ip_version,
15870                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15871                 (void *)&cmd_set_mplsogre_encap_label,
15872                 (void *)&cmd_set_mplsogre_encap_label_value,
15873                 (void *)&cmd_set_mplsogre_encap_ip_src,
15874                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15875                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15876                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15877                 (void *)&cmd_set_mplsogre_encap_vlan,
15878                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15879                 (void *)&cmd_set_mplsogre_encap_eth_src,
15880                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15881                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15882                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15883                 NULL,
15884         },
15885 };
15886
15887 /** Set MPLSoGRE decapsulation details */
15888 struct cmd_set_mplsogre_decap_result {
15889         cmdline_fixed_string_t set;
15890         cmdline_fixed_string_t mplsogre;
15891         cmdline_fixed_string_t pos_token;
15892         cmdline_fixed_string_t ip_version;
15893         uint32_t vlan_present:1;
15894 };
15895
15896 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15897         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15898                                  "set");
15899 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15900         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15901                                  "mplsogre_decap");
15902 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15903         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15904                                  mplsogre, "mplsogre_decap-with-vlan");
15905 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15906         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15907                                  pos_token, "ip-version");
15908 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15909         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15910                                  ip_version, "ipv4#ipv6");
15911
15912 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15913         __attribute__((unused)) struct cmdline *cl,
15914         __attribute__((unused)) void *data)
15915 {
15916         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15917
15918         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15919                 mplsogre_decap_conf.select_vlan = 0;
15920         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15921                 mplsogre_decap_conf.select_vlan = 1;
15922         if (strcmp(res->ip_version, "ipv4") == 0)
15923                 mplsogre_decap_conf.select_ipv4 = 1;
15924         else if (strcmp(res->ip_version, "ipv6") == 0)
15925                 mplsogre_decap_conf.select_ipv4 = 0;
15926 }
15927
15928 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15929         .f = cmd_set_mplsogre_decap_parsed,
15930         .data = NULL,
15931         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15932         .tokens = {
15933                 (void *)&cmd_set_mplsogre_decap_set,
15934                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15935                 (void *)&cmd_set_mplsogre_decap_ip_version,
15936                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15937                 NULL,
15938         },
15939 };
15940
15941 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15942         .f = cmd_set_mplsogre_decap_parsed,
15943         .data = NULL,
15944         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15945         .tokens = {
15946                 (void *)&cmd_set_mplsogre_decap_set,
15947                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15948                 (void *)&cmd_set_mplsogre_decap_ip_version,
15949                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15950                 NULL,
15951         },
15952 };
15953
15954 /** Set MPLSoUDP encapsulation details */
15955 struct cmd_set_mplsoudp_encap_result {
15956         cmdline_fixed_string_t set;
15957         cmdline_fixed_string_t mplsoudp;
15958         cmdline_fixed_string_t pos_token;
15959         cmdline_fixed_string_t ip_version;
15960         uint32_t vlan_present:1;
15961         uint32_t label;
15962         uint16_t udp_src;
15963         uint16_t udp_dst;
15964         cmdline_ipaddr_t ip_src;
15965         cmdline_ipaddr_t ip_dst;
15966         uint16_t tci;
15967         struct rte_ether_addr eth_src;
15968         struct rte_ether_addr eth_dst;
15969 };
15970
15971 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15972         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15973                                  "set");
15974 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15975         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15976                                  "mplsoudp_encap");
15977 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15978         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15979                                  mplsoudp, "mplsoudp_encap-with-vlan");
15980 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15981         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15982                                  pos_token, "ip-version");
15983 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15984         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15985                                  ip_version, "ipv4#ipv6");
15986 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15987         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15988                                  pos_token, "label");
15989 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15990         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15991                               UINT32);
15992 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15993         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15994                                  pos_token, "udp-src");
15995 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
15996         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
15997                               UINT16);
15998 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
15999         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16000                                  pos_token, "udp-dst");
16001 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16002         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16003                               UINT16);
16004 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16005         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16006                                  pos_token, "ip-src");
16007 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16008         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16009 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16010         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16011                                  pos_token, "ip-dst");
16012 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16013         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16014 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16015         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16016                                  pos_token, "vlan-tci");
16017 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16018         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16019                               UINT16);
16020 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16021         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16022                                  pos_token, "eth-src");
16023 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16024         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16025                                     eth_src);
16026 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16027         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16028                                  pos_token, "eth-dst");
16029 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16030         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16031                                     eth_dst);
16032
16033 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16034         __attribute__((unused)) struct cmdline *cl,
16035         __attribute__((unused)) void *data)
16036 {
16037         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16038         union {
16039                 uint32_t mplsoudp_label;
16040                 uint8_t label[4];
16041         } id = {
16042                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16043         };
16044
16045         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16046                 mplsoudp_encap_conf.select_vlan = 0;
16047         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16048                 mplsoudp_encap_conf.select_vlan = 1;
16049         if (strcmp(res->ip_version, "ipv4") == 0)
16050                 mplsoudp_encap_conf.select_ipv4 = 1;
16051         else if (strcmp(res->ip_version, "ipv6") == 0)
16052                 mplsoudp_encap_conf.select_ipv4 = 0;
16053         else
16054                 return;
16055         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16056         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16057         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16058         if (mplsoudp_encap_conf.select_ipv4) {
16059                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16060                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16061         } else {
16062                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16063                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16064         }
16065         if (mplsoudp_encap_conf.select_vlan)
16066                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16067         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16068                    RTE_ETHER_ADDR_LEN);
16069         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16070                    RTE_ETHER_ADDR_LEN);
16071 }
16072
16073 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16074         .f = cmd_set_mplsoudp_encap_parsed,
16075         .data = NULL,
16076         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16077                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16078                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16079         .tokens = {
16080                 (void *)&cmd_set_mplsoudp_encap_set,
16081                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16082                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16083                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16084                 (void *)&cmd_set_mplsoudp_encap_label,
16085                 (void *)&cmd_set_mplsoudp_encap_label_value,
16086                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16087                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16088                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16089                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16090                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16091                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16092                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16093                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16094                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16095                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16096                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16097                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16098                 NULL,
16099         },
16100 };
16101
16102 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16103         .f = cmd_set_mplsoudp_encap_parsed,
16104         .data = NULL,
16105         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16106                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16107                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16108                 " eth-src <eth-src> eth-dst <eth-dst>",
16109         .tokens = {
16110                 (void *)&cmd_set_mplsoudp_encap_set,
16111                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16112                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16113                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16114                 (void *)&cmd_set_mplsoudp_encap_label,
16115                 (void *)&cmd_set_mplsoudp_encap_label_value,
16116                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16117                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16118                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16119                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16120                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16121                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16122                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16123                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16124                 (void *)&cmd_set_mplsoudp_encap_vlan,
16125                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16126                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16127                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16128                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16129                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16130                 NULL,
16131         },
16132 };
16133
16134 /** Set MPLSoUDP decapsulation details */
16135 struct cmd_set_mplsoudp_decap_result {
16136         cmdline_fixed_string_t set;
16137         cmdline_fixed_string_t mplsoudp;
16138         cmdline_fixed_string_t pos_token;
16139         cmdline_fixed_string_t ip_version;
16140         uint32_t vlan_present:1;
16141 };
16142
16143 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16144         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16145                                  "set");
16146 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16147         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16148                                  "mplsoudp_decap");
16149 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16150         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16151                                  mplsoudp, "mplsoudp_decap-with-vlan");
16152 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16153         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16154                                  pos_token, "ip-version");
16155 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16156         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16157                                  ip_version, "ipv4#ipv6");
16158
16159 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16160         __attribute__((unused)) struct cmdline *cl,
16161         __attribute__((unused)) void *data)
16162 {
16163         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16164
16165         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16166                 mplsoudp_decap_conf.select_vlan = 0;
16167         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16168                 mplsoudp_decap_conf.select_vlan = 1;
16169         if (strcmp(res->ip_version, "ipv4") == 0)
16170                 mplsoudp_decap_conf.select_ipv4 = 1;
16171         else if (strcmp(res->ip_version, "ipv6") == 0)
16172                 mplsoudp_decap_conf.select_ipv4 = 0;
16173 }
16174
16175 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16176         .f = cmd_set_mplsoudp_decap_parsed,
16177         .data = NULL,
16178         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16179         .tokens = {
16180                 (void *)&cmd_set_mplsoudp_decap_set,
16181                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16182                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16183                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16184                 NULL,
16185         },
16186 };
16187
16188 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16189         .f = cmd_set_mplsoudp_decap_parsed,
16190         .data = NULL,
16191         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16192         .tokens = {
16193                 (void *)&cmd_set_mplsoudp_decap_set,
16194                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16195                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16196                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16197                 NULL,
16198         },
16199 };
16200
16201 /* Strict link priority scheduling mode setting */
16202 static void
16203 cmd_strict_link_prio_parsed(
16204         void *parsed_result,
16205         __attribute__((unused)) struct cmdline *cl,
16206         __attribute__((unused)) void *data)
16207 {
16208         struct cmd_vf_tc_bw_result *res = parsed_result;
16209         int ret = -ENOTSUP;
16210
16211         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16212                 return;
16213
16214 #ifdef RTE_LIBRTE_I40E_PMD
16215         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16216 #endif
16217
16218         switch (ret) {
16219         case 0:
16220                 break;
16221         case -EINVAL:
16222                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16223                 break;
16224         case -ENODEV:
16225                 printf("invalid port_id %d\n", res->port_id);
16226                 break;
16227         case -ENOTSUP:
16228                 printf("function not implemented\n");
16229                 break;
16230         default:
16231                 printf("programming error: (%s)\n", strerror(-ret));
16232         }
16233 }
16234
16235 cmdline_parse_inst_t cmd_strict_link_prio = {
16236         .f = cmd_strict_link_prio_parsed,
16237         .data = NULL,
16238         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16239         .tokens = {
16240                 (void *)&cmd_vf_tc_bw_set,
16241                 (void *)&cmd_vf_tc_bw_tx,
16242                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16243                 (void *)&cmd_vf_tc_bw_port_id,
16244                 (void *)&cmd_vf_tc_bw_tc_map,
16245                 NULL,
16246         },
16247 };
16248
16249 /* Load dynamic device personalization*/
16250 struct cmd_ddp_add_result {
16251         cmdline_fixed_string_t ddp;
16252         cmdline_fixed_string_t add;
16253         portid_t port_id;
16254         char filepath[];
16255 };
16256
16257 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16258         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16259 cmdline_parse_token_string_t cmd_ddp_add_add =
16260         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16261 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16262         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16263 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16264         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16265
16266 static void
16267 cmd_ddp_add_parsed(
16268         void *parsed_result,
16269         __attribute__((unused)) struct cmdline *cl,
16270         __attribute__((unused)) void *data)
16271 {
16272         struct cmd_ddp_add_result *res = parsed_result;
16273         uint8_t *buff;
16274         uint32_t size;
16275         char *filepath;
16276         char *file_fld[2];
16277         int file_num;
16278         int ret = -ENOTSUP;
16279
16280         if (!all_ports_stopped()) {
16281                 printf("Please stop all ports first\n");
16282                 return;
16283         }
16284
16285         filepath = strdup(res->filepath);
16286         if (filepath == NULL) {
16287                 printf("Failed to allocate memory\n");
16288                 return;
16289         }
16290         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16291
16292         buff = open_file(file_fld[0], &size);
16293         if (!buff) {
16294                 free((void *)filepath);
16295                 return;
16296         }
16297
16298 #ifdef RTE_LIBRTE_I40E_PMD
16299         if (ret == -ENOTSUP)
16300                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16301                                                buff, size,
16302                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16303 #endif
16304
16305         if (ret == -EEXIST)
16306                 printf("Profile has already existed.\n");
16307         else if (ret < 0)
16308                 printf("Failed to load profile.\n");
16309         else if (file_num == 2)
16310                 save_file(file_fld[1], buff, size);
16311
16312         close_file(buff);
16313         free((void *)filepath);
16314 }
16315
16316 cmdline_parse_inst_t cmd_ddp_add = {
16317         .f = cmd_ddp_add_parsed,
16318         .data = NULL,
16319         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16320         .tokens = {
16321                 (void *)&cmd_ddp_add_ddp,
16322                 (void *)&cmd_ddp_add_add,
16323                 (void *)&cmd_ddp_add_port_id,
16324                 (void *)&cmd_ddp_add_filepath,
16325                 NULL,
16326         },
16327 };
16328
16329 /* Delete dynamic device personalization*/
16330 struct cmd_ddp_del_result {
16331         cmdline_fixed_string_t ddp;
16332         cmdline_fixed_string_t del;
16333         portid_t port_id;
16334         char filepath[];
16335 };
16336
16337 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16338         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16339 cmdline_parse_token_string_t cmd_ddp_del_del =
16340         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16341 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16342         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16343 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16344         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16345
16346 static void
16347 cmd_ddp_del_parsed(
16348         void *parsed_result,
16349         __attribute__((unused)) struct cmdline *cl,
16350         __attribute__((unused)) void *data)
16351 {
16352         struct cmd_ddp_del_result *res = parsed_result;
16353         uint8_t *buff;
16354         uint32_t size;
16355         int ret = -ENOTSUP;
16356
16357         if (!all_ports_stopped()) {
16358                 printf("Please stop all ports first\n");
16359                 return;
16360         }
16361
16362         buff = open_file(res->filepath, &size);
16363         if (!buff)
16364                 return;
16365
16366 #ifdef RTE_LIBRTE_I40E_PMD
16367         if (ret == -ENOTSUP)
16368                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16369                                                buff, size,
16370                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16371 #endif
16372
16373         if (ret == -EACCES)
16374                 printf("Profile does not exist.\n");
16375         else if (ret < 0)
16376                 printf("Failed to delete profile.\n");
16377
16378         close_file(buff);
16379 }
16380
16381 cmdline_parse_inst_t cmd_ddp_del = {
16382         .f = cmd_ddp_del_parsed,
16383         .data = NULL,
16384         .help_str = "ddp del <port_id> <backup_profile_path>",
16385         .tokens = {
16386                 (void *)&cmd_ddp_del_ddp,
16387                 (void *)&cmd_ddp_del_del,
16388                 (void *)&cmd_ddp_del_port_id,
16389                 (void *)&cmd_ddp_del_filepath,
16390                 NULL,
16391         },
16392 };
16393
16394 /* Get dynamic device personalization profile info */
16395 struct cmd_ddp_info_result {
16396         cmdline_fixed_string_t ddp;
16397         cmdline_fixed_string_t get;
16398         cmdline_fixed_string_t info;
16399         char filepath[];
16400 };
16401
16402 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16403         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16404 cmdline_parse_token_string_t cmd_ddp_info_get =
16405         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16406 cmdline_parse_token_string_t cmd_ddp_info_info =
16407         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16408 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16409         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16410
16411 static void
16412 cmd_ddp_info_parsed(
16413         void *parsed_result,
16414         __attribute__((unused)) struct cmdline *cl,
16415         __attribute__((unused)) void *data)
16416 {
16417         struct cmd_ddp_info_result *res = parsed_result;
16418         uint8_t *pkg;
16419         uint32_t pkg_size;
16420         int ret = -ENOTSUP;
16421 #ifdef RTE_LIBRTE_I40E_PMD
16422         uint32_t i, j, n;
16423         uint8_t *buff;
16424         uint32_t buff_size = 0;
16425         struct rte_pmd_i40e_profile_info info;
16426         uint32_t dev_num = 0;
16427         struct rte_pmd_i40e_ddp_device_id *devs;
16428         uint32_t proto_num = 0;
16429         struct rte_pmd_i40e_proto_info *proto = NULL;
16430         uint32_t pctype_num = 0;
16431         struct rte_pmd_i40e_ptype_info *pctype;
16432         uint32_t ptype_num = 0;
16433         struct rte_pmd_i40e_ptype_info *ptype;
16434         uint8_t proto_id;
16435
16436 #endif
16437
16438         pkg = open_file(res->filepath, &pkg_size);
16439         if (!pkg)
16440                 return;
16441
16442 #ifdef RTE_LIBRTE_I40E_PMD
16443         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16444                                 (uint8_t *)&info, sizeof(info),
16445                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16446         if (!ret) {
16447                 printf("Global Track id:       0x%x\n", info.track_id);
16448                 printf("Global Version:        %d.%d.%d.%d\n",
16449                         info.version.major,
16450                         info.version.minor,
16451                         info.version.update,
16452                         info.version.draft);
16453                 printf("Global Package name:   %s\n\n", info.name);
16454         }
16455
16456         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16457                                 (uint8_t *)&info, sizeof(info),
16458                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16459         if (!ret) {
16460                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16461                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16462                         info.version.major,
16463                         info.version.minor,
16464                         info.version.update,
16465                         info.version.draft);
16466                 printf("i40e Profile name:     %s\n\n", info.name);
16467         }
16468
16469         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16470                                 (uint8_t *)&buff_size, sizeof(buff_size),
16471                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16472         if (!ret && buff_size) {
16473                 buff = (uint8_t *)malloc(buff_size);
16474                 if (buff) {
16475                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16476                                                 buff, buff_size,
16477                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16478                         if (!ret)
16479                                 printf("Package Notes:\n%s\n\n", buff);
16480                         free(buff);
16481                 }
16482         }
16483
16484         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16485                                 (uint8_t *)&dev_num, sizeof(dev_num),
16486                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16487         if (!ret && dev_num) {
16488                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16489                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16490                 if (devs) {
16491                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16492                                                 (uint8_t *)devs, buff_size,
16493                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16494                         if (!ret) {
16495                                 printf("List of supported devices:\n");
16496                                 for (i = 0; i < dev_num; i++) {
16497                                         printf("  %04X:%04X %04X:%04X\n",
16498                                                 devs[i].vendor_dev_id >> 16,
16499                                                 devs[i].vendor_dev_id & 0xFFFF,
16500                                                 devs[i].sub_vendor_dev_id >> 16,
16501                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16502                                 }
16503                                 printf("\n");
16504                         }
16505                         free(devs);
16506                 }
16507         }
16508
16509         /* get information about protocols and packet types */
16510         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16511                 (uint8_t *)&proto_num, sizeof(proto_num),
16512                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16513         if (ret || !proto_num)
16514                 goto no_print_return;
16515
16516         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16517         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16518         if (!proto)
16519                 goto no_print_return;
16520
16521         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16522                                         buff_size,
16523                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16524         if (!ret) {
16525                 printf("List of used protocols:\n");
16526                 for (i = 0; i < proto_num; i++)
16527                         printf("  %2u: %s\n", proto[i].proto_id,
16528                                proto[i].name);
16529                 printf("\n");
16530         }
16531         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16532                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16533                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16534         if (ret || !pctype_num)
16535                 goto no_print_pctypes;
16536
16537         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16538         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16539         if (!pctype)
16540                 goto no_print_pctypes;
16541
16542         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16543                                         buff_size,
16544                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16545         if (ret) {
16546                 free(pctype);
16547                 goto no_print_pctypes;
16548         }
16549
16550         printf("List of defined packet classification types:\n");
16551         for (i = 0; i < pctype_num; i++) {
16552                 printf("  %2u:", pctype[i].ptype_id);
16553                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16554                         proto_id = pctype[i].protocols[j];
16555                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16556                                 for (n = 0; n < proto_num; n++) {
16557                                         if (proto[n].proto_id == proto_id) {
16558                                                 printf(" %s", proto[n].name);
16559                                                 break;
16560                                         }
16561                                 }
16562                         }
16563                 }
16564                 printf("\n");
16565         }
16566         printf("\n");
16567         free(pctype);
16568
16569 no_print_pctypes:
16570
16571         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16572                                         sizeof(ptype_num),
16573                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16574         if (ret || !ptype_num)
16575                 goto no_print_return;
16576
16577         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16578         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16579         if (!ptype)
16580                 goto no_print_return;
16581
16582         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16583                                         buff_size,
16584                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16585         if (ret) {
16586                 free(ptype);
16587                 goto no_print_return;
16588         }
16589         printf("List of defined packet types:\n");
16590         for (i = 0; i < ptype_num; i++) {
16591                 printf("  %2u:", ptype[i].ptype_id);
16592                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16593                         proto_id = ptype[i].protocols[j];
16594                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16595                                 for (n = 0; n < proto_num; n++) {
16596                                         if (proto[n].proto_id == proto_id) {
16597                                                 printf(" %s", proto[n].name);
16598                                                 break;
16599                                         }
16600                                 }
16601                         }
16602                 }
16603                 printf("\n");
16604         }
16605         free(ptype);
16606         printf("\n");
16607
16608         ret = 0;
16609 no_print_return:
16610         if (proto)
16611                 free(proto);
16612 #endif
16613         if (ret == -ENOTSUP)
16614                 printf("Function not supported in PMD driver\n");
16615         close_file(pkg);
16616 }
16617
16618 cmdline_parse_inst_t cmd_ddp_get_info = {
16619         .f = cmd_ddp_info_parsed,
16620         .data = NULL,
16621         .help_str = "ddp get info <profile_path>",
16622         .tokens = {
16623                 (void *)&cmd_ddp_info_ddp,
16624                 (void *)&cmd_ddp_info_get,
16625                 (void *)&cmd_ddp_info_info,
16626                 (void *)&cmd_ddp_info_filepath,
16627                 NULL,
16628         },
16629 };
16630
16631 /* Get dynamic device personalization profile info list*/
16632 #define PROFILE_INFO_SIZE 48
16633 #define MAX_PROFILE_NUM 16
16634
16635 struct cmd_ddp_get_list_result {
16636         cmdline_fixed_string_t ddp;
16637         cmdline_fixed_string_t get;
16638         cmdline_fixed_string_t list;
16639         portid_t port_id;
16640 };
16641
16642 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16643         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16644 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16645         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16646 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16647         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16648 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16649         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16650
16651 static void
16652 cmd_ddp_get_list_parsed(
16653         __attribute__((unused)) void *parsed_result,
16654         __attribute__((unused)) struct cmdline *cl,
16655         __attribute__((unused)) void *data)
16656 {
16657 #ifdef RTE_LIBRTE_I40E_PMD
16658         struct cmd_ddp_get_list_result *res = parsed_result;
16659         struct rte_pmd_i40e_profile_list *p_list;
16660         struct rte_pmd_i40e_profile_info *p_info;
16661         uint32_t p_num;
16662         uint32_t size;
16663         uint32_t i;
16664 #endif
16665         int ret = -ENOTSUP;
16666
16667 #ifdef RTE_LIBRTE_I40E_PMD
16668         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16669         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16670         if (!p_list)
16671                 printf("%s: Failed to malloc buffer\n", __func__);
16672
16673         if (ret == -ENOTSUP)
16674                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16675                                                 (uint8_t *)p_list, size);
16676
16677         if (!ret) {
16678                 p_num = p_list->p_count;
16679                 printf("Profile number is: %d\n\n", p_num);
16680
16681                 for (i = 0; i < p_num; i++) {
16682                         p_info = &p_list->p_info[i];
16683                         printf("Profile %d:\n", i);
16684                         printf("Track id:     0x%x\n", p_info->track_id);
16685                         printf("Version:      %d.%d.%d.%d\n",
16686                                p_info->version.major,
16687                                p_info->version.minor,
16688                                p_info->version.update,
16689                                p_info->version.draft);
16690                         printf("Profile name: %s\n\n", p_info->name);
16691                 }
16692         }
16693
16694         free(p_list);
16695 #endif
16696
16697         if (ret < 0)
16698                 printf("Failed to get ddp list\n");
16699 }
16700
16701 cmdline_parse_inst_t cmd_ddp_get_list = {
16702         .f = cmd_ddp_get_list_parsed,
16703         .data = NULL,
16704         .help_str = "ddp get list <port_id>",
16705         .tokens = {
16706                 (void *)&cmd_ddp_get_list_ddp,
16707                 (void *)&cmd_ddp_get_list_get,
16708                 (void *)&cmd_ddp_get_list_list,
16709                 (void *)&cmd_ddp_get_list_port_id,
16710                 NULL,
16711         },
16712 };
16713
16714 /* Configure input set */
16715 struct cmd_cfg_input_set_result {
16716         cmdline_fixed_string_t port;
16717         cmdline_fixed_string_t cfg;
16718         portid_t port_id;
16719         cmdline_fixed_string_t pctype;
16720         uint8_t pctype_id;
16721         cmdline_fixed_string_t inset_type;
16722         cmdline_fixed_string_t opt;
16723         cmdline_fixed_string_t field;
16724         uint8_t field_idx;
16725 };
16726
16727 static void
16728 cmd_cfg_input_set_parsed(
16729         __attribute__((unused)) void *parsed_result,
16730         __attribute__((unused)) struct cmdline *cl,
16731         __attribute__((unused)) void *data)
16732 {
16733 #ifdef RTE_LIBRTE_I40E_PMD
16734         struct cmd_cfg_input_set_result *res = parsed_result;
16735         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16736         struct rte_pmd_i40e_inset inset;
16737 #endif
16738         int ret = -ENOTSUP;
16739
16740         if (!all_ports_stopped()) {
16741                 printf("Please stop all ports first\n");
16742                 return;
16743         }
16744
16745 #ifdef RTE_LIBRTE_I40E_PMD
16746         if (!strcmp(res->inset_type, "hash_inset"))
16747                 inset_type = INSET_HASH;
16748         else if (!strcmp(res->inset_type, "fdir_inset"))
16749                 inset_type = INSET_FDIR;
16750         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16751                 inset_type = INSET_FDIR_FLX;
16752         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16753                                      &inset, inset_type);
16754         if (ret) {
16755                 printf("Failed to get input set.\n");
16756                 return;
16757         }
16758
16759         if (!strcmp(res->opt, "get")) {
16760                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16761                                                    res->field_idx);
16762                 if (ret)
16763                         printf("Field index %d is enabled.\n", res->field_idx);
16764                 else
16765                         printf("Field index %d is disabled.\n", res->field_idx);
16766                 return;
16767         } else if (!strcmp(res->opt, "set"))
16768                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16769                                                    res->field_idx);
16770         else if (!strcmp(res->opt, "clear"))
16771                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16772                                                      res->field_idx);
16773         if (ret) {
16774                 printf("Failed to configure input set field.\n");
16775                 return;
16776         }
16777
16778         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16779                                      &inset, inset_type);
16780         if (ret) {
16781                 printf("Failed to set input set.\n");
16782                 return;
16783         }
16784 #endif
16785
16786         if (ret == -ENOTSUP)
16787                 printf("Function not supported\n");
16788 }
16789
16790 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16791         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16792                                  port, "port");
16793 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16794         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16795                                  cfg, "config");
16796 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16797         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16798                               port_id, UINT16);
16799 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16800         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16801                                  pctype, "pctype");
16802 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16803         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16804                               pctype_id, UINT8);
16805 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16806         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16807                                  inset_type,
16808                                  "hash_inset#fdir_inset#fdir_flx_inset");
16809 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16810         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16811                                  opt, "get#set#clear");
16812 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16813         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16814                                  field, "field");
16815 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16816         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16817                               field_idx, UINT8);
16818
16819 cmdline_parse_inst_t cmd_cfg_input_set = {
16820         .f = cmd_cfg_input_set_parsed,
16821         .data = NULL,
16822         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16823                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16824         .tokens = {
16825                 (void *)&cmd_cfg_input_set_port,
16826                 (void *)&cmd_cfg_input_set_cfg,
16827                 (void *)&cmd_cfg_input_set_port_id,
16828                 (void *)&cmd_cfg_input_set_pctype,
16829                 (void *)&cmd_cfg_input_set_pctype_id,
16830                 (void *)&cmd_cfg_input_set_inset_type,
16831                 (void *)&cmd_cfg_input_set_opt,
16832                 (void *)&cmd_cfg_input_set_field,
16833                 (void *)&cmd_cfg_input_set_field_idx,
16834                 NULL,
16835         },
16836 };
16837
16838 /* Clear input set */
16839 struct cmd_clear_input_set_result {
16840         cmdline_fixed_string_t port;
16841         cmdline_fixed_string_t cfg;
16842         portid_t port_id;
16843         cmdline_fixed_string_t pctype;
16844         uint8_t pctype_id;
16845         cmdline_fixed_string_t inset_type;
16846         cmdline_fixed_string_t clear;
16847         cmdline_fixed_string_t all;
16848 };
16849
16850 static void
16851 cmd_clear_input_set_parsed(
16852         __attribute__((unused)) void *parsed_result,
16853         __attribute__((unused)) struct cmdline *cl,
16854         __attribute__((unused)) void *data)
16855 {
16856 #ifdef RTE_LIBRTE_I40E_PMD
16857         struct cmd_clear_input_set_result *res = parsed_result;
16858         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16859         struct rte_pmd_i40e_inset inset;
16860 #endif
16861         int ret = -ENOTSUP;
16862
16863         if (!all_ports_stopped()) {
16864                 printf("Please stop all ports first\n");
16865                 return;
16866         }
16867
16868 #ifdef RTE_LIBRTE_I40E_PMD
16869         if (!strcmp(res->inset_type, "hash_inset"))
16870                 inset_type = INSET_HASH;
16871         else if (!strcmp(res->inset_type, "fdir_inset"))
16872                 inset_type = INSET_FDIR;
16873         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16874                 inset_type = INSET_FDIR_FLX;
16875
16876         memset(&inset, 0, sizeof(inset));
16877
16878         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16879                                      &inset, inset_type);
16880         if (ret) {
16881                 printf("Failed to clear input set.\n");
16882                 return;
16883         }
16884
16885 #endif
16886
16887         if (ret == -ENOTSUP)
16888                 printf("Function not supported\n");
16889 }
16890
16891 cmdline_parse_token_string_t cmd_clear_input_set_port =
16892         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16893                                  port, "port");
16894 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16895         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16896                                  cfg, "config");
16897 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16898         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16899                               port_id, UINT16);
16900 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16901         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16902                                  pctype, "pctype");
16903 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16904         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16905                               pctype_id, UINT8);
16906 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16907         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16908                                  inset_type,
16909                                  "hash_inset#fdir_inset#fdir_flx_inset");
16910 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16911         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16912                                  clear, "clear");
16913 cmdline_parse_token_string_t cmd_clear_input_set_all =
16914         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16915                                  all, "all");
16916
16917 cmdline_parse_inst_t cmd_clear_input_set = {
16918         .f = cmd_clear_input_set_parsed,
16919         .data = NULL,
16920         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16921                     "fdir_inset|fdir_flx_inset clear all",
16922         .tokens = {
16923                 (void *)&cmd_clear_input_set_port,
16924                 (void *)&cmd_clear_input_set_cfg,
16925                 (void *)&cmd_clear_input_set_port_id,
16926                 (void *)&cmd_clear_input_set_pctype,
16927                 (void *)&cmd_clear_input_set_pctype_id,
16928                 (void *)&cmd_clear_input_set_inset_type,
16929                 (void *)&cmd_clear_input_set_clear,
16930                 (void *)&cmd_clear_input_set_all,
16931                 NULL,
16932         },
16933 };
16934
16935 /* show vf stats */
16936
16937 /* Common result structure for show vf stats */
16938 struct cmd_show_vf_stats_result {
16939         cmdline_fixed_string_t show;
16940         cmdline_fixed_string_t vf;
16941         cmdline_fixed_string_t stats;
16942         portid_t port_id;
16943         uint16_t vf_id;
16944 };
16945
16946 /* Common CLI fields show vf stats*/
16947 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16948         TOKEN_STRING_INITIALIZER
16949                 (struct cmd_show_vf_stats_result,
16950                  show, "show");
16951 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16952         TOKEN_STRING_INITIALIZER
16953                 (struct cmd_show_vf_stats_result,
16954                  vf, "vf");
16955 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16956         TOKEN_STRING_INITIALIZER
16957                 (struct cmd_show_vf_stats_result,
16958                  stats, "stats");
16959 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16960         TOKEN_NUM_INITIALIZER
16961                 (struct cmd_show_vf_stats_result,
16962                  port_id, UINT16);
16963 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16964         TOKEN_NUM_INITIALIZER
16965                 (struct cmd_show_vf_stats_result,
16966                  vf_id, UINT16);
16967
16968 static void
16969 cmd_show_vf_stats_parsed(
16970         void *parsed_result,
16971         __attribute__((unused)) struct cmdline *cl,
16972         __attribute__((unused)) void *data)
16973 {
16974         struct cmd_show_vf_stats_result *res = parsed_result;
16975         struct rte_eth_stats stats;
16976         int ret = -ENOTSUP;
16977         static const char *nic_stats_border = "########################";
16978
16979         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16980                 return;
16981
16982         memset(&stats, 0, sizeof(stats));
16983
16984 #ifdef RTE_LIBRTE_I40E_PMD
16985         if (ret == -ENOTSUP)
16986                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16987                                                 res->vf_id,
16988                                                 &stats);
16989 #endif
16990 #ifdef RTE_LIBRTE_BNXT_PMD
16991         if (ret == -ENOTSUP)
16992                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16993                                                 res->vf_id,
16994                                                 &stats);
16995 #endif
16996
16997         switch (ret) {
16998         case 0:
16999                 break;
17000         case -EINVAL:
17001                 printf("invalid vf_id %d\n", res->vf_id);
17002                 break;
17003         case -ENODEV:
17004                 printf("invalid port_id %d\n", res->port_id);
17005                 break;
17006         case -ENOTSUP:
17007                 printf("function not implemented\n");
17008                 break;
17009         default:
17010                 printf("programming error: (%s)\n", strerror(-ret));
17011         }
17012
17013         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17014                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17015
17016         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17017                "%-"PRIu64"\n",
17018                stats.ipackets, stats.imissed, stats.ibytes);
17019         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17020         printf("  RX-nombuf:  %-10"PRIu64"\n",
17021                stats.rx_nombuf);
17022         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17023                "%-"PRIu64"\n",
17024                stats.opackets, stats.oerrors, stats.obytes);
17025
17026         printf("  %s############################%s\n",
17027                                nic_stats_border, nic_stats_border);
17028 }
17029
17030 cmdline_parse_inst_t cmd_show_vf_stats = {
17031         .f = cmd_show_vf_stats_parsed,
17032         .data = NULL,
17033         .help_str = "show vf stats <port_id> <vf_id>",
17034         .tokens = {
17035                 (void *)&cmd_show_vf_stats_show,
17036                 (void *)&cmd_show_vf_stats_vf,
17037                 (void *)&cmd_show_vf_stats_stats,
17038                 (void *)&cmd_show_vf_stats_port_id,
17039                 (void *)&cmd_show_vf_stats_vf_id,
17040                 NULL,
17041         },
17042 };
17043
17044 /* clear vf stats */
17045
17046 /* Common result structure for clear vf stats */
17047 struct cmd_clear_vf_stats_result {
17048         cmdline_fixed_string_t clear;
17049         cmdline_fixed_string_t vf;
17050         cmdline_fixed_string_t stats;
17051         portid_t port_id;
17052         uint16_t vf_id;
17053 };
17054
17055 /* Common CLI fields clear vf stats*/
17056 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17057         TOKEN_STRING_INITIALIZER
17058                 (struct cmd_clear_vf_stats_result,
17059                  clear, "clear");
17060 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17061         TOKEN_STRING_INITIALIZER
17062                 (struct cmd_clear_vf_stats_result,
17063                  vf, "vf");
17064 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17065         TOKEN_STRING_INITIALIZER
17066                 (struct cmd_clear_vf_stats_result,
17067                  stats, "stats");
17068 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17069         TOKEN_NUM_INITIALIZER
17070                 (struct cmd_clear_vf_stats_result,
17071                  port_id, UINT16);
17072 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17073         TOKEN_NUM_INITIALIZER
17074                 (struct cmd_clear_vf_stats_result,
17075                  vf_id, UINT16);
17076
17077 static void
17078 cmd_clear_vf_stats_parsed(
17079         void *parsed_result,
17080         __attribute__((unused)) struct cmdline *cl,
17081         __attribute__((unused)) void *data)
17082 {
17083         struct cmd_clear_vf_stats_result *res = parsed_result;
17084         int ret = -ENOTSUP;
17085
17086         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17087                 return;
17088
17089 #ifdef RTE_LIBRTE_I40E_PMD
17090         if (ret == -ENOTSUP)
17091                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17092                                                   res->vf_id);
17093 #endif
17094 #ifdef RTE_LIBRTE_BNXT_PMD
17095         if (ret == -ENOTSUP)
17096                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17097                                                   res->vf_id);
17098 #endif
17099
17100         switch (ret) {
17101         case 0:
17102                 break;
17103         case -EINVAL:
17104                 printf("invalid vf_id %d\n", res->vf_id);
17105                 break;
17106         case -ENODEV:
17107                 printf("invalid port_id %d\n", res->port_id);
17108                 break;
17109         case -ENOTSUP:
17110                 printf("function not implemented\n");
17111                 break;
17112         default:
17113                 printf("programming error: (%s)\n", strerror(-ret));
17114         }
17115 }
17116
17117 cmdline_parse_inst_t cmd_clear_vf_stats = {
17118         .f = cmd_clear_vf_stats_parsed,
17119         .data = NULL,
17120         .help_str = "clear vf stats <port_id> <vf_id>",
17121         .tokens = {
17122                 (void *)&cmd_clear_vf_stats_clear,
17123                 (void *)&cmd_clear_vf_stats_vf,
17124                 (void *)&cmd_clear_vf_stats_stats,
17125                 (void *)&cmd_clear_vf_stats_port_id,
17126                 (void *)&cmd_clear_vf_stats_vf_id,
17127                 NULL,
17128         },
17129 };
17130
17131 /* port config pctype mapping reset */
17132
17133 /* Common result structure for port config pctype mapping reset */
17134 struct cmd_pctype_mapping_reset_result {
17135         cmdline_fixed_string_t port;
17136         cmdline_fixed_string_t config;
17137         portid_t port_id;
17138         cmdline_fixed_string_t pctype;
17139         cmdline_fixed_string_t mapping;
17140         cmdline_fixed_string_t reset;
17141 };
17142
17143 /* Common CLI fields for port config pctype mapping reset*/
17144 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17145         TOKEN_STRING_INITIALIZER
17146                 (struct cmd_pctype_mapping_reset_result,
17147                  port, "port");
17148 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17149         TOKEN_STRING_INITIALIZER
17150                 (struct cmd_pctype_mapping_reset_result,
17151                  config, "config");
17152 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17153         TOKEN_NUM_INITIALIZER
17154                 (struct cmd_pctype_mapping_reset_result,
17155                  port_id, UINT16);
17156 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17157         TOKEN_STRING_INITIALIZER
17158                 (struct cmd_pctype_mapping_reset_result,
17159                  pctype, "pctype");
17160 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17161         TOKEN_STRING_INITIALIZER
17162                 (struct cmd_pctype_mapping_reset_result,
17163                  mapping, "mapping");
17164 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17165         TOKEN_STRING_INITIALIZER
17166                 (struct cmd_pctype_mapping_reset_result,
17167                  reset, "reset");
17168
17169 static void
17170 cmd_pctype_mapping_reset_parsed(
17171         void *parsed_result,
17172         __attribute__((unused)) struct cmdline *cl,
17173         __attribute__((unused)) void *data)
17174 {
17175         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17176         int ret = -ENOTSUP;
17177
17178         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17179                 return;
17180
17181 #ifdef RTE_LIBRTE_I40E_PMD
17182         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17183 #endif
17184
17185         switch (ret) {
17186         case 0:
17187                 break;
17188         case -ENODEV:
17189                 printf("invalid port_id %d\n", res->port_id);
17190                 break;
17191         case -ENOTSUP:
17192                 printf("function not implemented\n");
17193                 break;
17194         default:
17195                 printf("programming error: (%s)\n", strerror(-ret));
17196         }
17197 }
17198
17199 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17200         .f = cmd_pctype_mapping_reset_parsed,
17201         .data = NULL,
17202         .help_str = "port config <port_id> pctype mapping reset",
17203         .tokens = {
17204                 (void *)&cmd_pctype_mapping_reset_port,
17205                 (void *)&cmd_pctype_mapping_reset_config,
17206                 (void *)&cmd_pctype_mapping_reset_port_id,
17207                 (void *)&cmd_pctype_mapping_reset_pctype,
17208                 (void *)&cmd_pctype_mapping_reset_mapping,
17209                 (void *)&cmd_pctype_mapping_reset_reset,
17210                 NULL,
17211         },
17212 };
17213
17214 /* show port pctype mapping */
17215
17216 /* Common result structure for show port pctype mapping */
17217 struct cmd_pctype_mapping_get_result {
17218         cmdline_fixed_string_t show;
17219         cmdline_fixed_string_t port;
17220         portid_t port_id;
17221         cmdline_fixed_string_t pctype;
17222         cmdline_fixed_string_t mapping;
17223 };
17224
17225 /* Common CLI fields for pctype mapping get */
17226 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17227         TOKEN_STRING_INITIALIZER
17228                 (struct cmd_pctype_mapping_get_result,
17229                  show, "show");
17230 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17231         TOKEN_STRING_INITIALIZER
17232                 (struct cmd_pctype_mapping_get_result,
17233                  port, "port");
17234 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17235         TOKEN_NUM_INITIALIZER
17236                 (struct cmd_pctype_mapping_get_result,
17237                  port_id, UINT16);
17238 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17239         TOKEN_STRING_INITIALIZER
17240                 (struct cmd_pctype_mapping_get_result,
17241                  pctype, "pctype");
17242 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17243         TOKEN_STRING_INITIALIZER
17244                 (struct cmd_pctype_mapping_get_result,
17245                  mapping, "mapping");
17246
17247 static void
17248 cmd_pctype_mapping_get_parsed(
17249         void *parsed_result,
17250         __attribute__((unused)) struct cmdline *cl,
17251         __attribute__((unused)) void *data)
17252 {
17253         struct cmd_pctype_mapping_get_result *res = parsed_result;
17254         int ret = -ENOTSUP;
17255 #ifdef RTE_LIBRTE_I40E_PMD
17256         struct rte_pmd_i40e_flow_type_mapping
17257                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17258         int i, j, first_pctype;
17259 #endif
17260
17261         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17262                 return;
17263
17264 #ifdef RTE_LIBRTE_I40E_PMD
17265         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17266 #endif
17267
17268         switch (ret) {
17269         case 0:
17270                 break;
17271         case -ENODEV:
17272                 printf("invalid port_id %d\n", res->port_id);
17273                 return;
17274         case -ENOTSUP:
17275                 printf("function not implemented\n");
17276                 return;
17277         default:
17278                 printf("programming error: (%s)\n", strerror(-ret));
17279                 return;
17280         }
17281
17282 #ifdef RTE_LIBRTE_I40E_PMD
17283         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17284                 if (mapping[i].pctype != 0ULL) {
17285                         first_pctype = 1;
17286
17287                         printf("pctype: ");
17288                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17289                                 if (mapping[i].pctype & (1ULL << j)) {
17290                                         printf(first_pctype ?
17291                                                "%02d" : ",%02d", j);
17292                                         first_pctype = 0;
17293                                 }
17294                         }
17295                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17296                 }
17297         }
17298 #endif
17299 }
17300
17301 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17302         .f = cmd_pctype_mapping_get_parsed,
17303         .data = NULL,
17304         .help_str = "show port <port_id> pctype mapping",
17305         .tokens = {
17306                 (void *)&cmd_pctype_mapping_get_show,
17307                 (void *)&cmd_pctype_mapping_get_port,
17308                 (void *)&cmd_pctype_mapping_get_port_id,
17309                 (void *)&cmd_pctype_mapping_get_pctype,
17310                 (void *)&cmd_pctype_mapping_get_mapping,
17311                 NULL,
17312         },
17313 };
17314
17315 /* port config pctype mapping update */
17316
17317 /* Common result structure for port config pctype mapping update */
17318 struct cmd_pctype_mapping_update_result {
17319         cmdline_fixed_string_t port;
17320         cmdline_fixed_string_t config;
17321         portid_t port_id;
17322         cmdline_fixed_string_t pctype;
17323         cmdline_fixed_string_t mapping;
17324         cmdline_fixed_string_t update;
17325         cmdline_fixed_string_t pctype_list;
17326         uint16_t flow_type;
17327 };
17328
17329 /* Common CLI fields for pctype mapping update*/
17330 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17331         TOKEN_STRING_INITIALIZER
17332                 (struct cmd_pctype_mapping_update_result,
17333                  port, "port");
17334 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17335         TOKEN_STRING_INITIALIZER
17336                 (struct cmd_pctype_mapping_update_result,
17337                  config, "config");
17338 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17339         TOKEN_NUM_INITIALIZER
17340                 (struct cmd_pctype_mapping_update_result,
17341                  port_id, UINT16);
17342 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17343         TOKEN_STRING_INITIALIZER
17344                 (struct cmd_pctype_mapping_update_result,
17345                  pctype, "pctype");
17346 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17347         TOKEN_STRING_INITIALIZER
17348                 (struct cmd_pctype_mapping_update_result,
17349                  mapping, "mapping");
17350 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17351         TOKEN_STRING_INITIALIZER
17352                 (struct cmd_pctype_mapping_update_result,
17353                  update, "update");
17354 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17355         TOKEN_STRING_INITIALIZER
17356                 (struct cmd_pctype_mapping_update_result,
17357                  pctype_list, NULL);
17358 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17359         TOKEN_NUM_INITIALIZER
17360                 (struct cmd_pctype_mapping_update_result,
17361                  flow_type, UINT16);
17362
17363 static void
17364 cmd_pctype_mapping_update_parsed(
17365         void *parsed_result,
17366         __attribute__((unused)) struct cmdline *cl,
17367         __attribute__((unused)) void *data)
17368 {
17369         struct cmd_pctype_mapping_update_result *res = parsed_result;
17370         int ret = -ENOTSUP;
17371 #ifdef RTE_LIBRTE_I40E_PMD
17372         struct rte_pmd_i40e_flow_type_mapping mapping;
17373         unsigned int i;
17374         unsigned int nb_item;
17375         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17376 #endif
17377
17378         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17379                 return;
17380
17381 #ifdef RTE_LIBRTE_I40E_PMD
17382         nb_item = parse_item_list(res->pctype_list, "pctypes",
17383                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17384         mapping.flow_type = res->flow_type;
17385         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17386                 mapping.pctype |= (1ULL << pctype_list[i]);
17387         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17388                                                 &mapping,
17389                                                 1,
17390                                                 0);
17391 #endif
17392
17393         switch (ret) {
17394         case 0:
17395                 break;
17396         case -EINVAL:
17397                 printf("invalid pctype or flow type\n");
17398                 break;
17399         case -ENODEV:
17400                 printf("invalid port_id %d\n", res->port_id);
17401                 break;
17402         case -ENOTSUP:
17403                 printf("function not implemented\n");
17404                 break;
17405         default:
17406                 printf("programming error: (%s)\n", strerror(-ret));
17407         }
17408 }
17409
17410 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17411         .f = cmd_pctype_mapping_update_parsed,
17412         .data = NULL,
17413         .help_str = "port config <port_id> pctype mapping update"
17414         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17415         .tokens = {
17416                 (void *)&cmd_pctype_mapping_update_port,
17417                 (void *)&cmd_pctype_mapping_update_config,
17418                 (void *)&cmd_pctype_mapping_update_port_id,
17419                 (void *)&cmd_pctype_mapping_update_pctype,
17420                 (void *)&cmd_pctype_mapping_update_mapping,
17421                 (void *)&cmd_pctype_mapping_update_update,
17422                 (void *)&cmd_pctype_mapping_update_pc_type,
17423                 (void *)&cmd_pctype_mapping_update_flow_type,
17424                 NULL,
17425         },
17426 };
17427
17428 /* ptype mapping get */
17429
17430 /* Common result structure for ptype mapping get */
17431 struct cmd_ptype_mapping_get_result {
17432         cmdline_fixed_string_t ptype;
17433         cmdline_fixed_string_t mapping;
17434         cmdline_fixed_string_t get;
17435         portid_t port_id;
17436         uint8_t valid_only;
17437 };
17438
17439 /* Common CLI fields for ptype mapping get */
17440 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17441         TOKEN_STRING_INITIALIZER
17442                 (struct cmd_ptype_mapping_get_result,
17443                  ptype, "ptype");
17444 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17445         TOKEN_STRING_INITIALIZER
17446                 (struct cmd_ptype_mapping_get_result,
17447                  mapping, "mapping");
17448 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17449         TOKEN_STRING_INITIALIZER
17450                 (struct cmd_ptype_mapping_get_result,
17451                  get, "get");
17452 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17453         TOKEN_NUM_INITIALIZER
17454                 (struct cmd_ptype_mapping_get_result,
17455                  port_id, UINT16);
17456 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17457         TOKEN_NUM_INITIALIZER
17458                 (struct cmd_ptype_mapping_get_result,
17459                  valid_only, UINT8);
17460
17461 static void
17462 cmd_ptype_mapping_get_parsed(
17463         void *parsed_result,
17464         __attribute__((unused)) struct cmdline *cl,
17465         __attribute__((unused)) void *data)
17466 {
17467         struct cmd_ptype_mapping_get_result *res = parsed_result;
17468         int ret = -ENOTSUP;
17469 #ifdef RTE_LIBRTE_I40E_PMD
17470         int max_ptype_num = 256;
17471         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17472         uint16_t count;
17473         int i;
17474 #endif
17475
17476         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17477                 return;
17478
17479 #ifdef RTE_LIBRTE_I40E_PMD
17480         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17481                                         mapping,
17482                                         max_ptype_num,
17483                                         &count,
17484                                         res->valid_only);
17485 #endif
17486
17487         switch (ret) {
17488         case 0:
17489                 break;
17490         case -ENODEV:
17491                 printf("invalid port_id %d\n", res->port_id);
17492                 break;
17493         case -ENOTSUP:
17494                 printf("function not implemented\n");
17495                 break;
17496         default:
17497                 printf("programming error: (%s)\n", strerror(-ret));
17498         }
17499
17500 #ifdef RTE_LIBRTE_I40E_PMD
17501         if (!ret) {
17502                 for (i = 0; i < count; i++)
17503                         printf("%3d\t0x%08x\n",
17504                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17505         }
17506 #endif
17507 }
17508
17509 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17510         .f = cmd_ptype_mapping_get_parsed,
17511         .data = NULL,
17512         .help_str = "ptype mapping get <port_id> <valid_only>",
17513         .tokens = {
17514                 (void *)&cmd_ptype_mapping_get_ptype,
17515                 (void *)&cmd_ptype_mapping_get_mapping,
17516                 (void *)&cmd_ptype_mapping_get_get,
17517                 (void *)&cmd_ptype_mapping_get_port_id,
17518                 (void *)&cmd_ptype_mapping_get_valid_only,
17519                 NULL,
17520         },
17521 };
17522
17523 /* ptype mapping replace */
17524
17525 /* Common result structure for ptype mapping replace */
17526 struct cmd_ptype_mapping_replace_result {
17527         cmdline_fixed_string_t ptype;
17528         cmdline_fixed_string_t mapping;
17529         cmdline_fixed_string_t replace;
17530         portid_t port_id;
17531         uint32_t target;
17532         uint8_t mask;
17533         uint32_t pkt_type;
17534 };
17535
17536 /* Common CLI fields for ptype mapping replace */
17537 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17538         TOKEN_STRING_INITIALIZER
17539                 (struct cmd_ptype_mapping_replace_result,
17540                  ptype, "ptype");
17541 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17542         TOKEN_STRING_INITIALIZER
17543                 (struct cmd_ptype_mapping_replace_result,
17544                  mapping, "mapping");
17545 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17546         TOKEN_STRING_INITIALIZER
17547                 (struct cmd_ptype_mapping_replace_result,
17548                  replace, "replace");
17549 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17550         TOKEN_NUM_INITIALIZER
17551                 (struct cmd_ptype_mapping_replace_result,
17552                  port_id, UINT16);
17553 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17554         TOKEN_NUM_INITIALIZER
17555                 (struct cmd_ptype_mapping_replace_result,
17556                  target, UINT32);
17557 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17558         TOKEN_NUM_INITIALIZER
17559                 (struct cmd_ptype_mapping_replace_result,
17560                  mask, UINT8);
17561 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17562         TOKEN_NUM_INITIALIZER
17563                 (struct cmd_ptype_mapping_replace_result,
17564                  pkt_type, UINT32);
17565
17566 static void
17567 cmd_ptype_mapping_replace_parsed(
17568         void *parsed_result,
17569         __attribute__((unused)) struct cmdline *cl,
17570         __attribute__((unused)) void *data)
17571 {
17572         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17573         int ret = -ENOTSUP;
17574
17575         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17576                 return;
17577
17578 #ifdef RTE_LIBRTE_I40E_PMD
17579         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17580                                         res->target,
17581                                         res->mask,
17582                                         res->pkt_type);
17583 #endif
17584
17585         switch (ret) {
17586         case 0:
17587                 break;
17588         case -EINVAL:
17589                 printf("invalid ptype 0x%8x or 0x%8x\n",
17590                                 res->target, res->pkt_type);
17591                 break;
17592         case -ENODEV:
17593                 printf("invalid port_id %d\n", res->port_id);
17594                 break;
17595         case -ENOTSUP:
17596                 printf("function not implemented\n");
17597                 break;
17598         default:
17599                 printf("programming error: (%s)\n", strerror(-ret));
17600         }
17601 }
17602
17603 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17604         .f = cmd_ptype_mapping_replace_parsed,
17605         .data = NULL,
17606         .help_str =
17607                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17608         .tokens = {
17609                 (void *)&cmd_ptype_mapping_replace_ptype,
17610                 (void *)&cmd_ptype_mapping_replace_mapping,
17611                 (void *)&cmd_ptype_mapping_replace_replace,
17612                 (void *)&cmd_ptype_mapping_replace_port_id,
17613                 (void *)&cmd_ptype_mapping_replace_target,
17614                 (void *)&cmd_ptype_mapping_replace_mask,
17615                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17616                 NULL,
17617         },
17618 };
17619
17620 /* ptype mapping reset */
17621
17622 /* Common result structure for ptype mapping reset */
17623 struct cmd_ptype_mapping_reset_result {
17624         cmdline_fixed_string_t ptype;
17625         cmdline_fixed_string_t mapping;
17626         cmdline_fixed_string_t reset;
17627         portid_t port_id;
17628 };
17629
17630 /* Common CLI fields for ptype mapping reset*/
17631 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17632         TOKEN_STRING_INITIALIZER
17633                 (struct cmd_ptype_mapping_reset_result,
17634                  ptype, "ptype");
17635 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17636         TOKEN_STRING_INITIALIZER
17637                 (struct cmd_ptype_mapping_reset_result,
17638                  mapping, "mapping");
17639 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17640         TOKEN_STRING_INITIALIZER
17641                 (struct cmd_ptype_mapping_reset_result,
17642                  reset, "reset");
17643 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17644         TOKEN_NUM_INITIALIZER
17645                 (struct cmd_ptype_mapping_reset_result,
17646                  port_id, UINT16);
17647
17648 static void
17649 cmd_ptype_mapping_reset_parsed(
17650         void *parsed_result,
17651         __attribute__((unused)) struct cmdline *cl,
17652         __attribute__((unused)) void *data)
17653 {
17654         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17655         int ret = -ENOTSUP;
17656
17657         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17658                 return;
17659
17660 #ifdef RTE_LIBRTE_I40E_PMD
17661         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17662 #endif
17663
17664         switch (ret) {
17665         case 0:
17666                 break;
17667         case -ENODEV:
17668                 printf("invalid port_id %d\n", res->port_id);
17669                 break;
17670         case -ENOTSUP:
17671                 printf("function not implemented\n");
17672                 break;
17673         default:
17674                 printf("programming error: (%s)\n", strerror(-ret));
17675         }
17676 }
17677
17678 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17679         .f = cmd_ptype_mapping_reset_parsed,
17680         .data = NULL,
17681         .help_str = "ptype mapping reset <port_id>",
17682         .tokens = {
17683                 (void *)&cmd_ptype_mapping_reset_ptype,
17684                 (void *)&cmd_ptype_mapping_reset_mapping,
17685                 (void *)&cmd_ptype_mapping_reset_reset,
17686                 (void *)&cmd_ptype_mapping_reset_port_id,
17687                 NULL,
17688         },
17689 };
17690
17691 /* ptype mapping update */
17692
17693 /* Common result structure for ptype mapping update */
17694 struct cmd_ptype_mapping_update_result {
17695         cmdline_fixed_string_t ptype;
17696         cmdline_fixed_string_t mapping;
17697         cmdline_fixed_string_t reset;
17698         portid_t port_id;
17699         uint8_t hw_ptype;
17700         uint32_t sw_ptype;
17701 };
17702
17703 /* Common CLI fields for ptype mapping update*/
17704 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17705         TOKEN_STRING_INITIALIZER
17706                 (struct cmd_ptype_mapping_update_result,
17707                  ptype, "ptype");
17708 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17709         TOKEN_STRING_INITIALIZER
17710                 (struct cmd_ptype_mapping_update_result,
17711                  mapping, "mapping");
17712 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17713         TOKEN_STRING_INITIALIZER
17714                 (struct cmd_ptype_mapping_update_result,
17715                  reset, "update");
17716 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17717         TOKEN_NUM_INITIALIZER
17718                 (struct cmd_ptype_mapping_update_result,
17719                  port_id, UINT16);
17720 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17721         TOKEN_NUM_INITIALIZER
17722                 (struct cmd_ptype_mapping_update_result,
17723                  hw_ptype, UINT8);
17724 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17725         TOKEN_NUM_INITIALIZER
17726                 (struct cmd_ptype_mapping_update_result,
17727                  sw_ptype, UINT32);
17728
17729 static void
17730 cmd_ptype_mapping_update_parsed(
17731         void *parsed_result,
17732         __attribute__((unused)) struct cmdline *cl,
17733         __attribute__((unused)) void *data)
17734 {
17735         struct cmd_ptype_mapping_update_result *res = parsed_result;
17736         int ret = -ENOTSUP;
17737 #ifdef RTE_LIBRTE_I40E_PMD
17738         struct rte_pmd_i40e_ptype_mapping mapping;
17739 #endif
17740         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17741                 return;
17742
17743 #ifdef RTE_LIBRTE_I40E_PMD
17744         mapping.hw_ptype = res->hw_ptype;
17745         mapping.sw_ptype = res->sw_ptype;
17746         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17747                                                 &mapping,
17748                                                 1,
17749                                                 0);
17750 #endif
17751
17752         switch (ret) {
17753         case 0:
17754                 break;
17755         case -EINVAL:
17756                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17757                 break;
17758         case -ENODEV:
17759                 printf("invalid port_id %d\n", res->port_id);
17760                 break;
17761         case -ENOTSUP:
17762                 printf("function not implemented\n");
17763                 break;
17764         default:
17765                 printf("programming error: (%s)\n", strerror(-ret));
17766         }
17767 }
17768
17769 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17770         .f = cmd_ptype_mapping_update_parsed,
17771         .data = NULL,
17772         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17773         .tokens = {
17774                 (void *)&cmd_ptype_mapping_update_ptype,
17775                 (void *)&cmd_ptype_mapping_update_mapping,
17776                 (void *)&cmd_ptype_mapping_update_update,
17777                 (void *)&cmd_ptype_mapping_update_port_id,
17778                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17779                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17780                 NULL,
17781         },
17782 };
17783
17784 /* Common result structure for file commands */
17785 struct cmd_cmdfile_result {
17786         cmdline_fixed_string_t load;
17787         cmdline_fixed_string_t filename;
17788 };
17789
17790 /* Common CLI fields for file commands */
17791 cmdline_parse_token_string_t cmd_load_cmdfile =
17792         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17793 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17794         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17795
17796 static void
17797 cmd_load_from_file_parsed(
17798         void *parsed_result,
17799         __attribute__((unused)) struct cmdline *cl,
17800         __attribute__((unused)) void *data)
17801 {
17802         struct cmd_cmdfile_result *res = parsed_result;
17803
17804         cmdline_read_from_file(res->filename);
17805 }
17806
17807 cmdline_parse_inst_t cmd_load_from_file = {
17808         .f = cmd_load_from_file_parsed,
17809         .data = NULL,
17810         .help_str = "load <filename>",
17811         .tokens = {
17812                 (void *)&cmd_load_cmdfile,
17813                 (void *)&cmd_load_cmdfile_filename,
17814                 NULL,
17815         },
17816 };
17817
17818 /* Get Rx offloads capabilities */
17819 struct cmd_rx_offload_get_capa_result {
17820         cmdline_fixed_string_t show;
17821         cmdline_fixed_string_t port;
17822         portid_t port_id;
17823         cmdline_fixed_string_t rx_offload;
17824         cmdline_fixed_string_t capabilities;
17825 };
17826
17827 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17828         TOKEN_STRING_INITIALIZER
17829                 (struct cmd_rx_offload_get_capa_result,
17830                  show, "show");
17831 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17832         TOKEN_STRING_INITIALIZER
17833                 (struct cmd_rx_offload_get_capa_result,
17834                  port, "port");
17835 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17836         TOKEN_NUM_INITIALIZER
17837                 (struct cmd_rx_offload_get_capa_result,
17838                  port_id, UINT16);
17839 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17840         TOKEN_STRING_INITIALIZER
17841                 (struct cmd_rx_offload_get_capa_result,
17842                  rx_offload, "rx_offload");
17843 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17844         TOKEN_STRING_INITIALIZER
17845                 (struct cmd_rx_offload_get_capa_result,
17846                  capabilities, "capabilities");
17847
17848 static void
17849 print_rx_offloads(uint64_t offloads)
17850 {
17851         uint64_t single_offload;
17852         int begin;
17853         int end;
17854         int bit;
17855
17856         if (offloads == 0)
17857                 return;
17858
17859         begin = __builtin_ctzll(offloads);
17860         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17861
17862         single_offload = 1ULL << begin;
17863         for (bit = begin; bit < end; bit++) {
17864                 if (offloads & single_offload)
17865                         printf(" %s",
17866                                rte_eth_dev_rx_offload_name(single_offload));
17867                 single_offload <<= 1;
17868         }
17869 }
17870
17871 static void
17872 cmd_rx_offload_get_capa_parsed(
17873         void *parsed_result,
17874         __attribute__((unused)) struct cmdline *cl,
17875         __attribute__((unused)) void *data)
17876 {
17877         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17878         struct rte_eth_dev_info dev_info;
17879         portid_t port_id = res->port_id;
17880         uint64_t queue_offloads;
17881         uint64_t port_offloads;
17882
17883         rte_eth_dev_info_get(port_id, &dev_info);
17884         queue_offloads = dev_info.rx_queue_offload_capa;
17885         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17886
17887         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17888         printf("  Per Queue :");
17889         print_rx_offloads(queue_offloads);
17890
17891         printf("\n");
17892         printf("  Per Port  :");
17893         print_rx_offloads(port_offloads);
17894         printf("\n\n");
17895 }
17896
17897 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17898         .f = cmd_rx_offload_get_capa_parsed,
17899         .data = NULL,
17900         .help_str = "show port <port_id> rx_offload capabilities",
17901         .tokens = {
17902                 (void *)&cmd_rx_offload_get_capa_show,
17903                 (void *)&cmd_rx_offload_get_capa_port,
17904                 (void *)&cmd_rx_offload_get_capa_port_id,
17905                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17906                 (void *)&cmd_rx_offload_get_capa_capabilities,
17907                 NULL,
17908         }
17909 };
17910
17911 /* Get Rx offloads configuration */
17912 struct cmd_rx_offload_get_configuration_result {
17913         cmdline_fixed_string_t show;
17914         cmdline_fixed_string_t port;
17915         portid_t port_id;
17916         cmdline_fixed_string_t rx_offload;
17917         cmdline_fixed_string_t configuration;
17918 };
17919
17920 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17921         TOKEN_STRING_INITIALIZER
17922                 (struct cmd_rx_offload_get_configuration_result,
17923                  show, "show");
17924 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17925         TOKEN_STRING_INITIALIZER
17926                 (struct cmd_rx_offload_get_configuration_result,
17927                  port, "port");
17928 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17929         TOKEN_NUM_INITIALIZER
17930                 (struct cmd_rx_offload_get_configuration_result,
17931                  port_id, UINT16);
17932 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17933         TOKEN_STRING_INITIALIZER
17934                 (struct cmd_rx_offload_get_configuration_result,
17935                  rx_offload, "rx_offload");
17936 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17937         TOKEN_STRING_INITIALIZER
17938                 (struct cmd_rx_offload_get_configuration_result,
17939                  configuration, "configuration");
17940
17941 static void
17942 cmd_rx_offload_get_configuration_parsed(
17943         void *parsed_result,
17944         __attribute__((unused)) struct cmdline *cl,
17945         __attribute__((unused)) void *data)
17946 {
17947         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17948         struct rte_eth_dev_info dev_info;
17949         portid_t port_id = res->port_id;
17950         struct rte_port *port = &ports[port_id];
17951         uint64_t port_offloads;
17952         uint64_t queue_offloads;
17953         uint16_t nb_rx_queues;
17954         int q;
17955
17956         printf("Rx Offloading Configuration of port %d :\n", port_id);
17957
17958         port_offloads = port->dev_conf.rxmode.offloads;
17959         printf("  Port :");
17960         print_rx_offloads(port_offloads);
17961         printf("\n");
17962
17963         rte_eth_dev_info_get(port_id, &dev_info);
17964         nb_rx_queues = dev_info.nb_rx_queues;
17965         for (q = 0; q < nb_rx_queues; q++) {
17966                 queue_offloads = port->rx_conf[q].offloads;
17967                 printf("  Queue[%2d] :", q);
17968                 print_rx_offloads(queue_offloads);
17969                 printf("\n");
17970         }
17971         printf("\n");
17972 }
17973
17974 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17975         .f = cmd_rx_offload_get_configuration_parsed,
17976         .data = NULL,
17977         .help_str = "show port <port_id> rx_offload configuration",
17978         .tokens = {
17979                 (void *)&cmd_rx_offload_get_configuration_show,
17980                 (void *)&cmd_rx_offload_get_configuration_port,
17981                 (void *)&cmd_rx_offload_get_configuration_port_id,
17982                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17983                 (void *)&cmd_rx_offload_get_configuration_configuration,
17984                 NULL,
17985         }
17986 };
17987
17988 /* Enable/Disable a per port offloading */
17989 struct cmd_config_per_port_rx_offload_result {
17990         cmdline_fixed_string_t port;
17991         cmdline_fixed_string_t config;
17992         portid_t port_id;
17993         cmdline_fixed_string_t rx_offload;
17994         cmdline_fixed_string_t offload;
17995         cmdline_fixed_string_t on_off;
17996 };
17997
17998 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
17999         TOKEN_STRING_INITIALIZER
18000                 (struct cmd_config_per_port_rx_offload_result,
18001                  port, "port");
18002 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18003         TOKEN_STRING_INITIALIZER
18004                 (struct cmd_config_per_port_rx_offload_result,
18005                  config, "config");
18006 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18007         TOKEN_NUM_INITIALIZER
18008                 (struct cmd_config_per_port_rx_offload_result,
18009                  port_id, UINT16);
18010 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18011         TOKEN_STRING_INITIALIZER
18012                 (struct cmd_config_per_port_rx_offload_result,
18013                  rx_offload, "rx_offload");
18014 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18015         TOKEN_STRING_INITIALIZER
18016                 (struct cmd_config_per_port_rx_offload_result,
18017                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18018                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18019                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18020                            "crc_strip#scatter#timestamp#security#keep_crc");
18021 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18022         TOKEN_STRING_INITIALIZER
18023                 (struct cmd_config_per_port_rx_offload_result,
18024                  on_off, "on#off");
18025
18026 static uint64_t
18027 search_rx_offload(const char *name)
18028 {
18029         uint64_t single_offload;
18030         const char *single_name;
18031         int found = 0;
18032         unsigned int bit;
18033
18034         single_offload = 1;
18035         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18036                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18037                 if (!strcasecmp(single_name, name)) {
18038                         found = 1;
18039                         break;
18040                 }
18041                 single_offload <<= 1;
18042         }
18043
18044         if (found)
18045                 return single_offload;
18046
18047         return 0;
18048 }
18049
18050 static void
18051 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18052                                 __attribute__((unused)) struct cmdline *cl,
18053                                 __attribute__((unused)) void *data)
18054 {
18055         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18056         portid_t port_id = res->port_id;
18057         struct rte_eth_dev_info dev_info;
18058         struct rte_port *port = &ports[port_id];
18059         uint64_t single_offload;
18060         uint16_t nb_rx_queues;
18061         int q;
18062
18063         if (port->port_status != RTE_PORT_STOPPED) {
18064                 printf("Error: Can't config offload when Port %d "
18065                        "is not stopped\n", port_id);
18066                 return;
18067         }
18068
18069         single_offload = search_rx_offload(res->offload);
18070         if (single_offload == 0) {
18071                 printf("Unknown offload name: %s\n", res->offload);
18072                 return;
18073         }
18074
18075         rte_eth_dev_info_get(port_id, &dev_info);
18076         nb_rx_queues = dev_info.nb_rx_queues;
18077         if (!strcmp(res->on_off, "on")) {
18078                 port->dev_conf.rxmode.offloads |= single_offload;
18079                 for (q = 0; q < nb_rx_queues; q++)
18080                         port->rx_conf[q].offloads |= single_offload;
18081         } else {
18082                 port->dev_conf.rxmode.offloads &= ~single_offload;
18083                 for (q = 0; q < nb_rx_queues; q++)
18084                         port->rx_conf[q].offloads &= ~single_offload;
18085         }
18086
18087         cmd_reconfig_device_queue(port_id, 1, 1);
18088 }
18089
18090 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18091         .f = cmd_config_per_port_rx_offload_parsed,
18092         .data = NULL,
18093         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18094                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18095                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18096                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18097                     "on|off",
18098         .tokens = {
18099                 (void *)&cmd_config_per_port_rx_offload_result_port,
18100                 (void *)&cmd_config_per_port_rx_offload_result_config,
18101                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18102                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18103                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18104                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18105                 NULL,
18106         }
18107 };
18108
18109 /* Enable/Disable a per queue offloading */
18110 struct cmd_config_per_queue_rx_offload_result {
18111         cmdline_fixed_string_t port;
18112         portid_t port_id;
18113         cmdline_fixed_string_t rxq;
18114         uint16_t queue_id;
18115         cmdline_fixed_string_t rx_offload;
18116         cmdline_fixed_string_t offload;
18117         cmdline_fixed_string_t on_off;
18118 };
18119
18120 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18121         TOKEN_STRING_INITIALIZER
18122                 (struct cmd_config_per_queue_rx_offload_result,
18123                  port, "port");
18124 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18125         TOKEN_NUM_INITIALIZER
18126                 (struct cmd_config_per_queue_rx_offload_result,
18127                  port_id, UINT16);
18128 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18129         TOKEN_STRING_INITIALIZER
18130                 (struct cmd_config_per_queue_rx_offload_result,
18131                  rxq, "rxq");
18132 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18133         TOKEN_NUM_INITIALIZER
18134                 (struct cmd_config_per_queue_rx_offload_result,
18135                  queue_id, UINT16);
18136 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18137         TOKEN_STRING_INITIALIZER
18138                 (struct cmd_config_per_queue_rx_offload_result,
18139                  rx_offload, "rx_offload");
18140 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18141         TOKEN_STRING_INITIALIZER
18142                 (struct cmd_config_per_queue_rx_offload_result,
18143                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18144                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18145                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18146                            "crc_strip#scatter#timestamp#security#keep_crc");
18147 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18148         TOKEN_STRING_INITIALIZER
18149                 (struct cmd_config_per_queue_rx_offload_result,
18150                  on_off, "on#off");
18151
18152 static void
18153 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18154                                 __attribute__((unused)) struct cmdline *cl,
18155                                 __attribute__((unused)) void *data)
18156 {
18157         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18158         struct rte_eth_dev_info dev_info;
18159         portid_t port_id = res->port_id;
18160         uint16_t queue_id = res->queue_id;
18161         struct rte_port *port = &ports[port_id];
18162         uint64_t single_offload;
18163
18164         if (port->port_status != RTE_PORT_STOPPED) {
18165                 printf("Error: Can't config offload when Port %d "
18166                        "is not stopped\n", port_id);
18167                 return;
18168         }
18169
18170         rte_eth_dev_info_get(port_id, &dev_info);
18171         if (queue_id >= dev_info.nb_rx_queues) {
18172                 printf("Error: input queue_id should be 0 ... "
18173                        "%d\n", dev_info.nb_rx_queues - 1);
18174                 return;
18175         }
18176
18177         single_offload = search_rx_offload(res->offload);
18178         if (single_offload == 0) {
18179                 printf("Unknown offload name: %s\n", res->offload);
18180                 return;
18181         }
18182
18183         if (!strcmp(res->on_off, "on"))
18184                 port->rx_conf[queue_id].offloads |= single_offload;
18185         else
18186                 port->rx_conf[queue_id].offloads &= ~single_offload;
18187
18188         cmd_reconfig_device_queue(port_id, 1, 1);
18189 }
18190
18191 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18192         .f = cmd_config_per_queue_rx_offload_parsed,
18193         .data = NULL,
18194         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18195                     "vlan_strip|ipv4_cksum|"
18196                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18197                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18198                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18199                     "on|off",
18200         .tokens = {
18201                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18202                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18203                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18204                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18205                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18206                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18207                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18208                 NULL,
18209         }
18210 };
18211
18212 /* Get Tx offloads capabilities */
18213 struct cmd_tx_offload_get_capa_result {
18214         cmdline_fixed_string_t show;
18215         cmdline_fixed_string_t port;
18216         portid_t port_id;
18217         cmdline_fixed_string_t tx_offload;
18218         cmdline_fixed_string_t capabilities;
18219 };
18220
18221 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18222         TOKEN_STRING_INITIALIZER
18223                 (struct cmd_tx_offload_get_capa_result,
18224                  show, "show");
18225 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18226         TOKEN_STRING_INITIALIZER
18227                 (struct cmd_tx_offload_get_capa_result,
18228                  port, "port");
18229 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18230         TOKEN_NUM_INITIALIZER
18231                 (struct cmd_tx_offload_get_capa_result,
18232                  port_id, UINT16);
18233 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18234         TOKEN_STRING_INITIALIZER
18235                 (struct cmd_tx_offload_get_capa_result,
18236                  tx_offload, "tx_offload");
18237 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18238         TOKEN_STRING_INITIALIZER
18239                 (struct cmd_tx_offload_get_capa_result,
18240                  capabilities, "capabilities");
18241
18242 static void
18243 print_tx_offloads(uint64_t offloads)
18244 {
18245         uint64_t single_offload;
18246         int begin;
18247         int end;
18248         int bit;
18249
18250         if (offloads == 0)
18251                 return;
18252
18253         begin = __builtin_ctzll(offloads);
18254         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18255
18256         single_offload = 1ULL << begin;
18257         for (bit = begin; bit < end; bit++) {
18258                 if (offloads & single_offload)
18259                         printf(" %s",
18260                                rte_eth_dev_tx_offload_name(single_offload));
18261                 single_offload <<= 1;
18262         }
18263 }
18264
18265 static void
18266 cmd_tx_offload_get_capa_parsed(
18267         void *parsed_result,
18268         __attribute__((unused)) struct cmdline *cl,
18269         __attribute__((unused)) void *data)
18270 {
18271         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18272         struct rte_eth_dev_info dev_info;
18273         portid_t port_id = res->port_id;
18274         uint64_t queue_offloads;
18275         uint64_t port_offloads;
18276
18277         rte_eth_dev_info_get(port_id, &dev_info);
18278         queue_offloads = dev_info.tx_queue_offload_capa;
18279         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18280
18281         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18282         printf("  Per Queue :");
18283         print_tx_offloads(queue_offloads);
18284
18285         printf("\n");
18286         printf("  Per Port  :");
18287         print_tx_offloads(port_offloads);
18288         printf("\n\n");
18289 }
18290
18291 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18292         .f = cmd_tx_offload_get_capa_parsed,
18293         .data = NULL,
18294         .help_str = "show port <port_id> tx_offload capabilities",
18295         .tokens = {
18296                 (void *)&cmd_tx_offload_get_capa_show,
18297                 (void *)&cmd_tx_offload_get_capa_port,
18298                 (void *)&cmd_tx_offload_get_capa_port_id,
18299                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18300                 (void *)&cmd_tx_offload_get_capa_capabilities,
18301                 NULL,
18302         }
18303 };
18304
18305 /* Get Tx offloads configuration */
18306 struct cmd_tx_offload_get_configuration_result {
18307         cmdline_fixed_string_t show;
18308         cmdline_fixed_string_t port;
18309         portid_t port_id;
18310         cmdline_fixed_string_t tx_offload;
18311         cmdline_fixed_string_t configuration;
18312 };
18313
18314 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18315         TOKEN_STRING_INITIALIZER
18316                 (struct cmd_tx_offload_get_configuration_result,
18317                  show, "show");
18318 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18319         TOKEN_STRING_INITIALIZER
18320                 (struct cmd_tx_offload_get_configuration_result,
18321                  port, "port");
18322 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18323         TOKEN_NUM_INITIALIZER
18324                 (struct cmd_tx_offload_get_configuration_result,
18325                  port_id, UINT16);
18326 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18327         TOKEN_STRING_INITIALIZER
18328                 (struct cmd_tx_offload_get_configuration_result,
18329                  tx_offload, "tx_offload");
18330 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18331         TOKEN_STRING_INITIALIZER
18332                 (struct cmd_tx_offload_get_configuration_result,
18333                  configuration, "configuration");
18334
18335 static void
18336 cmd_tx_offload_get_configuration_parsed(
18337         void *parsed_result,
18338         __attribute__((unused)) struct cmdline *cl,
18339         __attribute__((unused)) void *data)
18340 {
18341         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18342         struct rte_eth_dev_info dev_info;
18343         portid_t port_id = res->port_id;
18344         struct rte_port *port = &ports[port_id];
18345         uint64_t port_offloads;
18346         uint64_t queue_offloads;
18347         uint16_t nb_tx_queues;
18348         int q;
18349
18350         printf("Tx Offloading Configuration of port %d :\n", port_id);
18351
18352         port_offloads = port->dev_conf.txmode.offloads;
18353         printf("  Port :");
18354         print_tx_offloads(port_offloads);
18355         printf("\n");
18356
18357         rte_eth_dev_info_get(port_id, &dev_info);
18358         nb_tx_queues = dev_info.nb_tx_queues;
18359         for (q = 0; q < nb_tx_queues; q++) {
18360                 queue_offloads = port->tx_conf[q].offloads;
18361                 printf("  Queue[%2d] :", q);
18362                 print_tx_offloads(queue_offloads);
18363                 printf("\n");
18364         }
18365         printf("\n");
18366 }
18367
18368 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18369         .f = cmd_tx_offload_get_configuration_parsed,
18370         .data = NULL,
18371         .help_str = "show port <port_id> tx_offload configuration",
18372         .tokens = {
18373                 (void *)&cmd_tx_offload_get_configuration_show,
18374                 (void *)&cmd_tx_offload_get_configuration_port,
18375                 (void *)&cmd_tx_offload_get_configuration_port_id,
18376                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18377                 (void *)&cmd_tx_offload_get_configuration_configuration,
18378                 NULL,
18379         }
18380 };
18381
18382 /* Enable/Disable a per port offloading */
18383 struct cmd_config_per_port_tx_offload_result {
18384         cmdline_fixed_string_t port;
18385         cmdline_fixed_string_t config;
18386         portid_t port_id;
18387         cmdline_fixed_string_t tx_offload;
18388         cmdline_fixed_string_t offload;
18389         cmdline_fixed_string_t on_off;
18390 };
18391
18392 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18393         TOKEN_STRING_INITIALIZER
18394                 (struct cmd_config_per_port_tx_offload_result,
18395                  port, "port");
18396 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18397         TOKEN_STRING_INITIALIZER
18398                 (struct cmd_config_per_port_tx_offload_result,
18399                  config, "config");
18400 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18401         TOKEN_NUM_INITIALIZER
18402                 (struct cmd_config_per_port_tx_offload_result,
18403                  port_id, UINT16);
18404 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18405         TOKEN_STRING_INITIALIZER
18406                 (struct cmd_config_per_port_tx_offload_result,
18407                  tx_offload, "tx_offload");
18408 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18409         TOKEN_STRING_INITIALIZER
18410                 (struct cmd_config_per_port_tx_offload_result,
18411                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18412                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18413                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18414                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18415                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18416                           "match_metadata");
18417 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18418         TOKEN_STRING_INITIALIZER
18419                 (struct cmd_config_per_port_tx_offload_result,
18420                  on_off, "on#off");
18421
18422 static uint64_t
18423 search_tx_offload(const char *name)
18424 {
18425         uint64_t single_offload;
18426         const char *single_name;
18427         int found = 0;
18428         unsigned int bit;
18429
18430         single_offload = 1;
18431         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18432                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18433                 if (single_name == NULL)
18434                         break;
18435                 if (!strcasecmp(single_name, name)) {
18436                         found = 1;
18437                         break;
18438                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18439                         break;
18440                 single_offload <<= 1;
18441         }
18442
18443         if (found)
18444                 return single_offload;
18445
18446         return 0;
18447 }
18448
18449 static void
18450 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18451                                 __attribute__((unused)) struct cmdline *cl,
18452                                 __attribute__((unused)) void *data)
18453 {
18454         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18455         portid_t port_id = res->port_id;
18456         struct rte_eth_dev_info dev_info;
18457         struct rte_port *port = &ports[port_id];
18458         uint64_t single_offload;
18459         uint16_t nb_tx_queues;
18460         int q;
18461
18462         if (port->port_status != RTE_PORT_STOPPED) {
18463                 printf("Error: Can't config offload when Port %d "
18464                        "is not stopped\n", port_id);
18465                 return;
18466         }
18467
18468         single_offload = search_tx_offload(res->offload);
18469         if (single_offload == 0) {
18470                 printf("Unknown offload name: %s\n", res->offload);
18471                 return;
18472         }
18473
18474         rte_eth_dev_info_get(port_id, &dev_info);
18475         nb_tx_queues = dev_info.nb_tx_queues;
18476         if (!strcmp(res->on_off, "on")) {
18477                 port->dev_conf.txmode.offloads |= single_offload;
18478                 for (q = 0; q < nb_tx_queues; q++)
18479                         port->tx_conf[q].offloads |= single_offload;
18480         } else {
18481                 port->dev_conf.txmode.offloads &= ~single_offload;
18482                 for (q = 0; q < nb_tx_queues; q++)
18483                         port->tx_conf[q].offloads &= ~single_offload;
18484         }
18485
18486         cmd_reconfig_device_queue(port_id, 1, 1);
18487 }
18488
18489 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18490         .f = cmd_config_per_port_tx_offload_parsed,
18491         .data = NULL,
18492         .help_str = "port config <port_id> tx_offload "
18493                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18494                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18495                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18496                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18497                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18498                     "match_metadata on|off",
18499         .tokens = {
18500                 (void *)&cmd_config_per_port_tx_offload_result_port,
18501                 (void *)&cmd_config_per_port_tx_offload_result_config,
18502                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18503                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18504                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18505                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18506                 NULL,
18507         }
18508 };
18509
18510 /* Enable/Disable a per queue offloading */
18511 struct cmd_config_per_queue_tx_offload_result {
18512         cmdline_fixed_string_t port;
18513         portid_t port_id;
18514         cmdline_fixed_string_t txq;
18515         uint16_t queue_id;
18516         cmdline_fixed_string_t tx_offload;
18517         cmdline_fixed_string_t offload;
18518         cmdline_fixed_string_t on_off;
18519 };
18520
18521 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18522         TOKEN_STRING_INITIALIZER
18523                 (struct cmd_config_per_queue_tx_offload_result,
18524                  port, "port");
18525 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18526         TOKEN_NUM_INITIALIZER
18527                 (struct cmd_config_per_queue_tx_offload_result,
18528                  port_id, UINT16);
18529 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18530         TOKEN_STRING_INITIALIZER
18531                 (struct cmd_config_per_queue_tx_offload_result,
18532                  txq, "txq");
18533 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18534         TOKEN_NUM_INITIALIZER
18535                 (struct cmd_config_per_queue_tx_offload_result,
18536                  queue_id, UINT16);
18537 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18538         TOKEN_STRING_INITIALIZER
18539                 (struct cmd_config_per_queue_tx_offload_result,
18540                  tx_offload, "tx_offload");
18541 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18542         TOKEN_STRING_INITIALIZER
18543                 (struct cmd_config_per_queue_tx_offload_result,
18544                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18545                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18546                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18547                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18548                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18549 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18550         TOKEN_STRING_INITIALIZER
18551                 (struct cmd_config_per_queue_tx_offload_result,
18552                  on_off, "on#off");
18553
18554 static void
18555 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18556                                 __attribute__((unused)) struct cmdline *cl,
18557                                 __attribute__((unused)) void *data)
18558 {
18559         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18560         struct rte_eth_dev_info dev_info;
18561         portid_t port_id = res->port_id;
18562         uint16_t queue_id = res->queue_id;
18563         struct rte_port *port = &ports[port_id];
18564         uint64_t single_offload;
18565
18566         if (port->port_status != RTE_PORT_STOPPED) {
18567                 printf("Error: Can't config offload when Port %d "
18568                        "is not stopped\n", port_id);
18569                 return;
18570         }
18571
18572         rte_eth_dev_info_get(port_id, &dev_info);
18573         if (queue_id >= dev_info.nb_tx_queues) {
18574                 printf("Error: input queue_id should be 0 ... "
18575                        "%d\n", dev_info.nb_tx_queues - 1);
18576                 return;
18577         }
18578
18579         single_offload = search_tx_offload(res->offload);
18580         if (single_offload == 0) {
18581                 printf("Unknown offload name: %s\n", res->offload);
18582                 return;
18583         }
18584
18585         if (!strcmp(res->on_off, "on"))
18586                 port->tx_conf[queue_id].offloads |= single_offload;
18587         else
18588                 port->tx_conf[queue_id].offloads &= ~single_offload;
18589
18590         cmd_reconfig_device_queue(port_id, 1, 1);
18591 }
18592
18593 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18594         .f = cmd_config_per_queue_tx_offload_parsed,
18595         .data = NULL,
18596         .help_str = "port <port_id> txq <queue_id> tx_offload "
18597                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18598                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18599                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18600                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18601                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18602                     "on|off",
18603         .tokens = {
18604                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18605                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18606                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18607                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18608                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18609                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18610                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18611                 NULL,
18612         }
18613 };
18614
18615 /* *** configure tx_metadata for specific port *** */
18616 struct cmd_config_tx_metadata_specific_result {
18617         cmdline_fixed_string_t port;
18618         cmdline_fixed_string_t keyword;
18619         uint16_t port_id;
18620         cmdline_fixed_string_t item;
18621         uint32_t value;
18622 };
18623
18624 static void
18625 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18626                                 __attribute__((unused)) struct cmdline *cl,
18627                                 __attribute__((unused)) void *data)
18628 {
18629         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18630
18631         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18632                 return;
18633         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18634         /* Add/remove callback to insert valid metadata in every Tx packet. */
18635         if (ports[res->port_id].tx_metadata)
18636                 add_tx_md_callback(res->port_id);
18637         else
18638                 remove_tx_md_callback(res->port_id);
18639 }
18640
18641 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18642         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18643                         port, "port");
18644 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18645         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18646                         keyword, "config");
18647 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18648         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18649                         port_id, UINT16);
18650 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18651         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18652                         item, "tx_metadata");
18653 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18654         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18655                         value, UINT32);
18656
18657 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18658         .f = cmd_config_tx_metadata_specific_parsed,
18659         .data = NULL,
18660         .help_str = "port config <port_id> tx_metadata <value>",
18661         .tokens = {
18662                 (void *)&cmd_config_tx_metadata_specific_port,
18663                 (void *)&cmd_config_tx_metadata_specific_keyword,
18664                 (void *)&cmd_config_tx_metadata_specific_id,
18665                 (void *)&cmd_config_tx_metadata_specific_item,
18666                 (void *)&cmd_config_tx_metadata_specific_value,
18667                 NULL,
18668         },
18669 };
18670
18671 /* *** display tx_metadata per port configuration *** */
18672 struct cmd_show_tx_metadata_result {
18673         cmdline_fixed_string_t cmd_show;
18674         cmdline_fixed_string_t cmd_port;
18675         cmdline_fixed_string_t cmd_keyword;
18676         portid_t cmd_pid;
18677 };
18678
18679 static void
18680 cmd_show_tx_metadata_parsed(void *parsed_result,
18681                 __attribute__((unused)) struct cmdline *cl,
18682                 __attribute__((unused)) void *data)
18683 {
18684         struct cmd_show_tx_metadata_result *res = parsed_result;
18685
18686         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18687                 printf("invalid port id %u\n", res->cmd_pid);
18688                 return;
18689         }
18690         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18691                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18692                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18693         }
18694 }
18695
18696 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18697         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18698                         cmd_show, "show");
18699 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18700         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18701                         cmd_port, "port");
18702 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18703         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18704                         cmd_pid, UINT16);
18705 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18706         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18707                         cmd_keyword, "tx_metadata");
18708
18709 cmdline_parse_inst_t cmd_show_tx_metadata = {
18710         .f = cmd_show_tx_metadata_parsed,
18711         .data = NULL,
18712         .help_str = "show port <port_id> tx_metadata",
18713         .tokens = {
18714                 (void *)&cmd_show_tx_metadata_show,
18715                 (void *)&cmd_show_tx_metadata_port,
18716                 (void *)&cmd_show_tx_metadata_pid,
18717                 (void *)&cmd_show_tx_metadata_keyword,
18718                 NULL,
18719         },
18720 };
18721
18722 /* ******************************************************************************** */
18723
18724 /* list of instructions */
18725 cmdline_parse_ctx_t main_ctx[] = {
18726         (cmdline_parse_inst_t *)&cmd_help_brief,
18727         (cmdline_parse_inst_t *)&cmd_help_long,
18728         (cmdline_parse_inst_t *)&cmd_quit,
18729         (cmdline_parse_inst_t *)&cmd_load_from_file,
18730         (cmdline_parse_inst_t *)&cmd_showport,
18731         (cmdline_parse_inst_t *)&cmd_showqueue,
18732         (cmdline_parse_inst_t *)&cmd_showportall,
18733         (cmdline_parse_inst_t *)&cmd_showcfg,
18734         (cmdline_parse_inst_t *)&cmd_showfwdall,
18735         (cmdline_parse_inst_t *)&cmd_start,
18736         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18737         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18738         (cmdline_parse_inst_t *)&cmd_set_link_up,
18739         (cmdline_parse_inst_t *)&cmd_set_link_down,
18740         (cmdline_parse_inst_t *)&cmd_reset,
18741         (cmdline_parse_inst_t *)&cmd_set_numbers,
18742         (cmdline_parse_inst_t *)&cmd_set_log,
18743         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18744         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18745         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18746         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18747         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18748         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18749         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18750         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18751         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18752         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18753         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18754         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18755         (cmdline_parse_inst_t *)&cmd_set_link_check,
18756         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18757         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18758         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18759         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18760 #ifdef RTE_LIBRTE_PMD_BOND
18761         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18762         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18763         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18764         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18765         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18766         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18767         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18768         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18769         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18770         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18771         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18772 #endif
18773         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18774         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18775         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18776         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18777         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18778         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18779         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18780         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18781         (cmdline_parse_inst_t *)&cmd_csum_set,
18782         (cmdline_parse_inst_t *)&cmd_csum_show,
18783         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18784         (cmdline_parse_inst_t *)&cmd_tso_set,
18785         (cmdline_parse_inst_t *)&cmd_tso_show,
18786         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18787         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18788         (cmdline_parse_inst_t *)&cmd_gro_enable,
18789         (cmdline_parse_inst_t *)&cmd_gro_flush,
18790         (cmdline_parse_inst_t *)&cmd_gro_show,
18791         (cmdline_parse_inst_t *)&cmd_gso_enable,
18792         (cmdline_parse_inst_t *)&cmd_gso_size,
18793         (cmdline_parse_inst_t *)&cmd_gso_show,
18794         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18795         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18796         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18797         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18798         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18799         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18800         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18801         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18802         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18803         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18804         (cmdline_parse_inst_t *)&cmd_config_dcb,
18805         (cmdline_parse_inst_t *)&cmd_read_reg,
18806         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18807         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18808         (cmdline_parse_inst_t *)&cmd_write_reg,
18809         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18810         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18811         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18812         (cmdline_parse_inst_t *)&cmd_stop,
18813         (cmdline_parse_inst_t *)&cmd_mac_addr,
18814         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18815         (cmdline_parse_inst_t *)&cmd_set_qmap,
18816         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18817         (cmdline_parse_inst_t *)&cmd_operate_port,
18818         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18819         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18820         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18821         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18822         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18823         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18824         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18825         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18826         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18827         (cmdline_parse_inst_t *)&cmd_config_mtu,
18828         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18829         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18830         (cmdline_parse_inst_t *)&cmd_config_rss,
18831         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18832         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18833         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18834         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18835         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18836         (cmdline_parse_inst_t *)&cmd_showport_reta,
18837         (cmdline_parse_inst_t *)&cmd_config_burst,
18838         (cmdline_parse_inst_t *)&cmd_config_thresh,
18839         (cmdline_parse_inst_t *)&cmd_config_threshold,
18840         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18841         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18842         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18843         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18844         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18845         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18846         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18847         (cmdline_parse_inst_t *)&cmd_global_config,
18848         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18849         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18850         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18851         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18852         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18853         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18854         (cmdline_parse_inst_t *)&cmd_dump,
18855         (cmdline_parse_inst_t *)&cmd_dump_one,
18856         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18857         (cmdline_parse_inst_t *)&cmd_syn_filter,
18858         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18859         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18860         (cmdline_parse_inst_t *)&cmd_flex_filter,
18861         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18862         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18863         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18864         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18865         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18866         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18867         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18868         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18869         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18870         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18871         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18872         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18873         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18874         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18875         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18876         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18877         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18878         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18879         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18880         (cmdline_parse_inst_t *)&cmd_flow,
18881         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18882         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18883         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18884         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18885         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18886         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18887         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18888         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18889         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18890         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18891         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18892         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18893         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18894         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18895         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18896         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18897         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18898         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18899         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18900         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18901         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18902         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18903         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18904         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18905         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18906         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18907         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18908         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18909         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18910         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18911         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18912         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18913         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18914         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18915         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18916         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18917         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18918         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18919         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18920         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18921         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18922         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18923         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18924         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18925         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18926         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18927         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18928         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18929         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18930 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
18931         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
18932 #endif
18933         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18934         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18935         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18936         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18937         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18938         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18939         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18940         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18941         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18942         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18943         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18944         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18945         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18946         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18947         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18948         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18949         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18950         (cmdline_parse_inst_t *)&cmd_ddp_add,
18951         (cmdline_parse_inst_t *)&cmd_ddp_del,
18952         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18953         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18954         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18955         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18956         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18957         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18958         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18959         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18960         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18961         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18962
18963         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18964         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18965         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18966         (cmdline_parse_inst_t *)&cmd_queue_region,
18967         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18968         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18969         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18970         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18971         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18972         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18973         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18974         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18975         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18976         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18977         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18978         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18979         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18980         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18981         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18982         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18983         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18984         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18985         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18986         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18987         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18988         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18989         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18990         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18991         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18992         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18993         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18994         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18995         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18996         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18997         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18998         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18999         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19000         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19001         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19002 #ifdef RTE_LIBRTE_BPF
19003         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19004         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19005 #endif
19006         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19007         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19008         (cmdline_parse_inst_t *)&cmd_set_raw,
19009         NULL,
19010 };
19011
19012 /* read cmdline commands from file */
19013 void
19014 cmdline_read_from_file(const char *filename)
19015 {
19016         struct cmdline *cl;
19017
19018         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19019         if (cl == NULL) {
19020                 printf("Failed to create file based cmdline context: %s\n",
19021                        filename);
19022                 return;
19023         }
19024
19025         cmdline_interact(cl);
19026         cmdline_quit(cl);
19027
19028         cmdline_free(cl);
19029
19030         printf("Read CLI commands from %s\n", filename);
19031 }
19032
19033 /* prompt function, called from main on MASTER lcore */
19034 void
19035 prompt(void)
19036 {
19037         /* initialize non-constant commands */
19038         cmd_set_fwd_mode_init();
19039         cmd_set_fwd_retry_mode_init();
19040
19041         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19042         if (testpmd_cl == NULL)
19043                 return;
19044         cmdline_interact(testpmd_cl);
19045         cmdline_stdin_exit(testpmd_cl);
19046 }
19047
19048 void
19049 prompt_exit(void)
19050 {
19051         if (testpmd_cl != NULL)
19052                 cmdline_quit(testpmd_cl);
19053 }
19054
19055 static void
19056 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19057 {
19058         if (id == (portid_t)RTE_PORT_ALL) {
19059                 portid_t pid;
19060
19061                 RTE_ETH_FOREACH_DEV(pid) {
19062                         /* check if need_reconfig has been set to 1 */
19063                         if (ports[pid].need_reconfig == 0)
19064                                 ports[pid].need_reconfig = dev;
19065                         /* check if need_reconfig_queues has been set to 1 */
19066                         if (ports[pid].need_reconfig_queues == 0)
19067                                 ports[pid].need_reconfig_queues = queue;
19068                 }
19069         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19070                 /* check if need_reconfig has been set to 1 */
19071                 if (ports[id].need_reconfig == 0)
19072                         ports[id].need_reconfig = dev;
19073                 /* check if need_reconfig_queues has been set to 1 */
19074                 if (ports[id].need_reconfig_queues == 0)
19075                         ports[id].need_reconfig_queues = queue;
19076         }
19077 }