2a1027828e98fbeb35de6f0c487d93de050a1099
[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_eth_ctrl.h>
48 #include <rte_flow.h>
49 #include <rte_gro.h>
50
51 #include <cmdline_rdline.h>
52 #include <cmdline_parse.h>
53 #include <cmdline_parse_num.h>
54 #include <cmdline_parse_string.h>
55 #include <cmdline_parse_ipaddr.h>
56 #include <cmdline_parse_etheraddr.h>
57 #include <cmdline_socket.h>
58 #include <cmdline.h>
59 #ifdef RTE_LIBRTE_PMD_BOND
60 #include <rte_eth_bond.h>
61 #include <rte_eth_bond_8023ad.h>
62 #endif
63 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
64 #include <rte_pmd_dpaa.h>
65 #endif
66 #ifdef RTE_LIBRTE_IXGBE_PMD
67 #include <rte_pmd_ixgbe.h>
68 #endif
69 #ifdef RTE_LIBRTE_I40E_PMD
70 #include <rte_pmd_i40e.h>
71 #endif
72 #ifdef RTE_LIBRTE_BNXT_PMD
73 #include <rte_pmd_bnxt.h>
74 #endif
75 #include "testpmd.h"
76 #include "cmdline_mtr.h"
77 #include "cmdline_tm.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 all        : All of the above sections.\n\n"
104         );
105
106 }
107
108 cmdline_parse_token_string_t cmd_help_brief_help =
109         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
110
111 cmdline_parse_inst_t cmd_help_brief = {
112         .f = cmd_help_brief_parsed,
113         .data = NULL,
114         .help_str = "help: Show help",
115         .tokens = {
116                 (void *)&cmd_help_brief_help,
117                 NULL,
118         },
119 };
120
121 /* *** Help command with help sections. *** */
122 struct cmd_help_long_result {
123         cmdline_fixed_string_t help;
124         cmdline_fixed_string_t section;
125 };
126
127 static void cmd_help_long_parsed(void *parsed_result,
128                                  struct cmdline *cl,
129                                  __attribute__((unused)) void *data)
130 {
131         int show_all = 0;
132         struct cmd_help_long_result *res = parsed_result;
133
134         if (!strcmp(res->section, "all"))
135                 show_all = 1;
136
137         if (show_all || !strcmp(res->section, "control")) {
138
139                 cmdline_printf(
140                         cl,
141                         "\n"
142                         "Control forwarding:\n"
143                         "-------------------\n\n"
144
145                         "start\n"
146                         "    Start packet forwarding with current configuration.\n\n"
147
148                         "start tx_first\n"
149                         "    Start packet forwarding with current config"
150                         " after sending one burst of packets.\n\n"
151
152                         "stop\n"
153                         "    Stop packet forwarding, and display accumulated"
154                         " statistics.\n\n"
155
156                         "quit\n"
157                         "    Quit to prompt.\n\n"
158                 );
159         }
160
161         if (show_all || !strcmp(res->section, "display")) {
162
163                 cmdline_printf(
164                         cl,
165                         "\n"
166                         "Display:\n"
167                         "--------\n\n"
168
169                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
170                         "    Display information for port_id, or all.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
178                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
179                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
180                         "    Display the RSS hash functions and RSS hash key"
181                         " of port X\n\n"
182
183                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
184                         "    Clear information for port_id, or all.\n\n"
185
186                         "show (rxq|txq) info (port_id) (queue_id)\n"
187                         "    Display information for configured RX/TX queue.\n\n"
188
189                         "show config (rxtx|cores|fwd|txpkts)\n"
190                         "    Display the given configuration.\n\n"
191
192                         "read rxd (port_id) (queue_id) (rxd_id)\n"
193                         "    Display an RX descriptor of a port RX queue.\n\n"
194
195                         "read txd (port_id) (queue_id) (txd_id)\n"
196                         "    Display a TX descriptor of a port TX queue.\n\n"
197
198                         "ddp get list (port_id)\n"
199                         "    Get ddp profile info list\n\n"
200
201                         "ddp get info (profile_path)\n"
202                         "    Get ddp profile information.\n\n"
203
204                         "show vf stats (port_id) (vf_id)\n"
205                         "    Display a VF's statistics.\n\n"
206
207                         "clear vf stats (port_id) (vf_id)\n"
208                         "    Reset a VF's statistics.\n\n"
209
210                         "show port (port_id) pctype mapping\n"
211                         "    Get flow ptype to pctype mapping on a port\n\n"
212
213                         "show port meter stats (port_id) (meter_id) (clear)\n"
214                         "    Get meter stats on a port\n\n"
215                         "show port tm cap (port_id)\n"
216                         "       Display the port TM capability.\n\n"
217
218                         "show port tm level cap (port_id) (level_id)\n"
219                         "       Display the port TM hierarchical level capability.\n\n"
220
221                         "show port tm node cap (port_id) (node_id)\n"
222                         "       Display the port TM node capability.\n\n"
223
224                         "show port tm node type (port_id) (node_id)\n"
225                         "       Display the port TM node type.\n\n"
226
227                         "show port tm node stats (port_id) (node_id) (clear)\n"
228                         "       Display the port TM node stats.\n\n"
229
230                 );
231         }
232
233         if (show_all || !strcmp(res->section, "config")) {
234                 cmdline_printf(
235                         cl,
236                         "\n"
237                         "Configuration:\n"
238                         "--------------\n"
239                         "Configuration changes only become active when"
240                         " forwarding is started/restarted.\n\n"
241
242                         "set default\n"
243                         "    Reset forwarding to the default configuration.\n\n"
244
245                         "set verbose (level)\n"
246                         "    Set the debug verbosity level X.\n\n"
247
248                         "set log global|(type) (level)\n"
249                         "    Set the log level.\n\n"
250
251                         "set nbport (num)\n"
252                         "    Set number of ports.\n\n"
253
254                         "set nbcore (num)\n"
255                         "    Set number of cores.\n\n"
256
257                         "set coremask (mask)\n"
258                         "    Set the forwarding cores hexadecimal mask.\n\n"
259
260                         "set portmask (mask)\n"
261                         "    Set the forwarding ports hexadecimal mask.\n\n"
262
263                         "set burst (num)\n"
264                         "    Set number of packets per burst.\n\n"
265
266                         "set burst tx delay (microseconds) retry (num)\n"
267                         "    Set the transmit delay time and number of retries,"
268                         " effective when retry is enabled.\n\n"
269
270                         "set txpkts (x[,y]*)\n"
271                         "    Set the length of each segment of TXONLY"
272                         " and optionally CSUM packets.\n\n"
273
274                         "set txsplit (off|on|rand)\n"
275                         "    Set the split policy for the TX packets."
276                         " Right now only applicable for CSUM and TXONLY"
277                         " modes\n\n"
278
279                         "set corelist (x[,y]*)\n"
280                         "    Set the list of forwarding cores.\n\n"
281
282                         "set portlist (x[,y]*)\n"
283                         "    Set the list of forwarding ports.\n\n"
284
285                         "set tx loopback (port_id) (on|off)\n"
286                         "    Enable or disable tx loopback.\n\n"
287
288                         "set all queues drop (port_id) (on|off)\n"
289                         "    Set drop enable bit for all queues.\n\n"
290
291                         "set vf split drop (port_id) (vf_id) (on|off)\n"
292                         "    Set split drop enable bit for a VF from the PF.\n\n"
293
294                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
295                         "    Set MAC antispoof for a VF from the PF.\n\n"
296
297                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
298                         "    Enable MACsec offload.\n\n"
299
300                         "set macsec offload (port_id) off\n"
301                         "    Disable MACsec offload.\n\n"
302
303                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
304                         "    Configure MACsec secure connection (SC).\n\n"
305
306                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
307                         "    Configure MACsec secure association (SA).\n\n"
308
309                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
310                         "    Set VF broadcast for a VF from the PF.\n\n"
311
312                         "vlan set strip (on|off) (port_id)\n"
313                         "    Set the VLAN strip on a port.\n\n"
314
315                         "vlan set stripq (on|off) (port_id,queue_id)\n"
316                         "    Set the VLAN strip for a queue on a port.\n\n"
317
318                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
319                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
320
321                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
322                         "    Set VLAN insert for a VF from the PF.\n\n"
323
324                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
325                         "    Set VLAN antispoof for a VF from the PF.\n\n"
326
327                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
328                         "    Set VLAN tag for a VF from the PF.\n\n"
329
330                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
331                         "    Set a VF's max bandwidth(Mbps).\n\n"
332
333                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
334                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
335
336                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
337                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
338
339                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
340                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
341
342                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
343                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
344
345                         "vlan set filter (on|off) (port_id)\n"
346                         "    Set the VLAN filter on a port.\n\n"
347
348                         "vlan set qinq (on|off) (port_id)\n"
349                         "    Set the VLAN QinQ (extended queue in queue)"
350                         " on a port.\n\n"
351
352                         "vlan set (inner|outer) tpid (value) (port_id)\n"
353                         "    Set the VLAN TPID for Packet Filtering on"
354                         " a port\n\n"
355
356                         "rx_vlan add (vlan_id|all) (port_id)\n"
357                         "    Add a vlan_id, or all identifiers, to the set"
358                         " of VLAN identifiers filtered by port_id.\n\n"
359
360                         "rx_vlan rm (vlan_id|all) (port_id)\n"
361                         "    Remove a vlan_id, or all identifiers, from the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
365                         "    Add a vlan_id, to the set of VLAN identifiers"
366                         "filtered for VF(s) from port_id.\n\n"
367
368                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Remove a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
373                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
374                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
375                         "   add a tunnel filter of a port.\n\n"
376
377                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
378                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
379                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
380                         "   remove a tunnel filter of a port.\n\n"
381
382                         "rx_vxlan_port add (udp_port) (port_id)\n"
383                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
384
385                         "rx_vxlan_port rm (udp_port) (port_id)\n"
386                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
387
388                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
389                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
390                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
391
392                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
393                         "    Set port based TX VLAN insertion.\n\n"
394
395                         "tx_vlan reset (port_id)\n"
396                         "    Disable hardware insertion of a VLAN header in"
397                         " packets sent on a port.\n\n"
398
399                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
400                         "    Select hardware or software calculation of the"
401                         " checksum when transmitting a packet using the"
402                         " csum forward engine.\n"
403                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
404                         "    outer-ip concerns the outer IP layer in"
405                         " case the packet is recognized as a tunnel packet by"
406                         " the forward engine (vxlan, gre and ipip are supported)\n"
407                         "    Please check the NIC datasheet for HW limits.\n\n"
408
409                         "csum parse-tunnel (on|off) (tx_port_id)\n"
410                         "    If disabled, treat tunnel packets as non-tunneled"
411                         " packets (treat inner headers as payload). The port\n"
412                         "    argument is the port used for TX in csum forward"
413                         " engine.\n\n"
414
415                         "csum show (port_id)\n"
416                         "    Display tx checksum offload configuration\n\n"
417
418                         "tso set (segsize) (portid)\n"
419                         "    Enable TCP Segmentation Offload in csum forward"
420                         " engine.\n"
421                         "    Please check the NIC datasheet for HW limits.\n\n"
422
423                         "tso show (portid)"
424                         "    Display the status of TCP Segmentation Offload.\n\n"
425
426                         "set port (port_id) gro on|off\n"
427                         "    Enable or disable Generic Receive Offload in"
428                         " csum forwarding engine.\n\n"
429
430                         "show port (port_id) gro\n"
431                         "    Display GRO configuration.\n\n"
432
433                         "set gro flush (cycles)\n"
434                         "    Set the cycle to flush GROed packets from"
435                         " reassembly tables.\n\n"
436
437                         "set port (port_id) gso (on|off)"
438                         "    Enable or disable Generic Segmentation Offload in"
439                         " csum forwarding engine.\n\n"
440
441                         "set gso segsz (length)\n"
442                         "    Set max packet length for output GSO segments,"
443                         " including packet header and payload.\n\n"
444
445                         "show port (port_id) gso\n"
446                         "    Show GSO configuration.\n\n"
447
448                         "set fwd (%s)\n"
449                         "    Set packet forwarding mode.\n\n"
450
451                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
452                         "    Add a MAC address on port_id.\n\n"
453
454                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
455                         "    Remove a MAC address from port_id.\n\n"
456
457                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
458                         "    Set the default MAC address for port_id.\n\n"
459
460                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
461                         "    Add a MAC address for a VF on the port.\n\n"
462
463                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
464                         "    Set the MAC address for a VF from the PF.\n\n"
465
466                         "set eth-peer (port_id) (peer_addr)\n"
467                         "    set the peer address for certain port.\n\n"
468
469                         "set port (port_id) uta (mac_address|all) (on|off)\n"
470                         "    Add/Remove a or all unicast hash filter(s)"
471                         "from port X.\n\n"
472
473                         "set promisc (port_id|all) (on|off)\n"
474                         "    Set the promiscuous mode on port_id, or all.\n\n"
475
476                         "set allmulti (port_id|all) (on|off)\n"
477                         "    Set the allmulti mode on port_id, or all.\n\n"
478
479                         "set vf promisc (port_id) (vf_id) (on|off)\n"
480                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
481
482                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
483                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
484
485                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
486                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
487                         " (on|off) autoneg (on|off) (port_id)\n"
488                         "set flow_ctrl rx (on|off) (portid)\n"
489                         "set flow_ctrl tx (on|off) (portid)\n"
490                         "set flow_ctrl high_water (high_water) (portid)\n"
491                         "set flow_ctrl low_water (low_water) (portid)\n"
492                         "set flow_ctrl pause_time (pause_time) (portid)\n"
493                         "set flow_ctrl send_xon (send_xon) (portid)\n"
494                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
495                         "set flow_ctrl autoneg (on|off) (port_id)\n"
496                         "    Set the link flow control parameter on a port.\n\n"
497
498                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
499                         " (low_water) (pause_time) (priority) (port_id)\n"
500                         "    Set the priority flow control parameter on a"
501                         " port.\n\n"
502
503                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
504                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
505                         " queue on port.\n"
506                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
507                         " on port 0 to mapping 5.\n\n"
508
509                         "set xstats-hide-zero on|off\n"
510                         "    Set the option to hide the zero values"
511                         " for xstats display.\n"
512
513                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
514                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
515
516                         "set port (port_id) vf (vf_id) (mac_addr)"
517                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
518                         "   Add/Remove unicast or multicast MAC addr filter"
519                         " for a VF.\n\n"
520
521                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
522                         "|MPE) (on|off)\n"
523                         "    AUPE:accepts untagged VLAN;"
524                         "ROPE:accept unicast hash\n\n"
525                         "    BAM:accepts broadcast packets;"
526                         "MPE:accepts all multicast packets\n\n"
527                         "    Enable/Disable a VF receive mode of a port\n\n"
528
529                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
530                         "    Set rate limit for a queue of a port\n\n"
531
532                         "set port (port_id) vf (vf_id) rate (rate_num) "
533                         "queue_mask (queue_mask_value)\n"
534                         "    Set rate limit for queues in VF of a port\n\n"
535
536                         "set port (port_id) mirror-rule (rule_id)"
537                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
538                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
539                         "   Set pool or vlan type mirror rule on a port.\n"
540                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
541                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
542                         " to pool 0.\n\n"
543
544                         "set port (port_id) mirror-rule (rule_id)"
545                         " (uplink-mirror|downlink-mirror) dst-pool"
546                         " (pool_id) (on|off)\n"
547                         "   Set uplink or downlink type mirror rule on a port.\n"
548                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
549                         " 0 on' enable mirror income traffic to pool 0.\n\n"
550
551                         "reset port (port_id) mirror-rule (rule_id)\n"
552                         "   Reset a mirror rule.\n\n"
553
554                         "set flush_rx (on|off)\n"
555                         "   Flush (default) or don't flush RX streams before"
556                         " forwarding. Mainly used with PCAP drivers.\n\n"
557
558                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
559                         "   Set the bypass mode for the lowest port on bypass enabled"
560                         " NIC.\n\n"
561
562                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
563                         "mode (normal|bypass|isolate) (port_id)\n"
564                         "   Set the event required to initiate specified bypass mode for"
565                         " the lowest port on a bypass enabled NIC where:\n"
566                         "       timeout   = enable bypass after watchdog timeout.\n"
567                         "       os_on     = enable bypass when OS/board is powered on.\n"
568                         "       os_off    = enable bypass when OS/board is powered off.\n"
569                         "       power_on  = enable bypass when power supply is turned on.\n"
570                         "       power_off = enable bypass when power supply is turned off."
571                         "\n\n"
572
573                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
574                         "   Set the bypass watchdog timeout to 'n' seconds"
575                         " where 0 = instant.\n\n"
576
577                         "show bypass config (port_id)\n"
578                         "   Show the bypass configuration for a bypass enabled NIC"
579                         " using the lowest port on the NIC.\n\n"
580
581 #ifdef RTE_LIBRTE_PMD_BOND
582                         "create bonded device (mode) (socket)\n"
583                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
584
585                         "add bonding slave (slave_id) (port_id)\n"
586                         "       Add a slave device to a bonded device.\n\n"
587
588                         "remove bonding slave (slave_id) (port_id)\n"
589                         "       Remove a slave device from a bonded device.\n\n"
590
591                         "set bonding mode (value) (port_id)\n"
592                         "       Set the bonding mode on a bonded device.\n\n"
593
594                         "set bonding primary (slave_id) (port_id)\n"
595                         "       Set the primary slave for a bonded device.\n\n"
596
597                         "show bonding config (port_id)\n"
598                         "       Show the bonding config for port_id.\n\n"
599
600                         "set bonding mac_addr (port_id) (address)\n"
601                         "       Set the MAC address of a bonded device.\n\n"
602
603                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
604                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
605
606                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
607                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
608
609                         "set bonding mon_period (port_id) (value)\n"
610                         "       Set the bonding link status monitoring polling period in ms.\n\n"
611
612                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
613                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
614
615 #endif
616                         "set link-up port (port_id)\n"
617                         "       Set link up for a port.\n\n"
618
619                         "set link-down port (port_id)\n"
620                         "       Set link down for a port.\n\n"
621
622                         "E-tag set insertion on port-tag-id (value)"
623                         " port (port_id) vf (vf_id)\n"
624                         "    Enable E-tag insertion for a VF on a port\n\n"
625
626                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
627                         "    Disable E-tag insertion for a VF on a port\n\n"
628
629                         "E-tag set stripping (on|off) port (port_id)\n"
630                         "    Enable/disable E-tag stripping on a port\n\n"
631
632                         "E-tag set forwarding (on|off) port (port_id)\n"
633                         "    Enable/disable E-tag based forwarding"
634                         " on a port\n\n"
635
636                         "E-tag set filter add e-tag-id (value) dst-pool"
637                         " (pool_id) port (port_id)\n"
638                         "    Add an E-tag forwarding filter on a port\n\n"
639
640                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
641                         "    Delete an E-tag forwarding filter on a port\n\n"
642
643 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
644                         "set port tm hierarchy default (port_id)\n"
645                         "       Set default traffic Management hierarchy on a port\n\n"
646
647 #endif
648                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
649                         "    Load a profile package on a port\n\n"
650
651                         "ddp del (port_id) (backup_profile_path)\n"
652                         "    Delete a profile package from a port\n\n"
653
654                         "ptype mapping get (port_id) (valid_only)\n"
655                         "    Get ptype mapping on a port\n\n"
656
657                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
658                         "    Replace target with the pkt_type in ptype mapping\n\n"
659
660                         "ptype mapping reset (port_id)\n"
661                         "    Reset ptype mapping on a port\n\n"
662
663                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
664                         "    Update a ptype mapping item on a port\n\n"
665
666                         "set port (port_id) queue-region region_id (value) "
667                         "queue_start_index (value) queue_num (value)\n"
668                         "    Set a queue region on a port\n\n"
669
670                         "set port (port_id) queue-region region_id (value) "
671                         "flowtype (value)\n"
672                         "    Set a flowtype region index on a port\n\n"
673
674                         "set port (port_id) queue-region UP (value) region_id (value)\n"
675                         "    Set the mapping of User Priority to "
676                         "queue region on a port\n\n"
677
678                         "set port (port_id) queue-region flush (on|off)\n"
679                         "    flush all queue region related configuration\n\n"
680
681                         "show port meter cap (port_id)\n"
682                         "    Show port meter capability information\n\n"
683
684                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
685                         "    meter profile add - srtcm rfc 2697\n\n"
686
687                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
688                         "    meter profile add - trtcm rfc 2698\n\n"
689
690                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
691                         "    meter profile add - trtcm rfc 4115\n\n"
692
693                         "del port meter profile (port_id) (profile_id)\n"
694                         "    meter profile delete\n\n"
695
696                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
697                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
698                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
699                         "(dscp_tbl_entry63)]\n"
700                         "    meter create\n\n"
701
702                         "enable port meter (port_id) (mtr_id)\n"
703                         "    meter enable\n\n"
704
705                         "disable port meter (port_id) (mtr_id)\n"
706                         "    meter disable\n\n"
707
708                         "del port meter (port_id) (mtr_id)\n"
709                         "    meter delete\n\n"
710
711                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
712                         "    meter update meter profile\n\n"
713
714                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
715                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
716                         "    update meter dscp table entries\n\n"
717
718                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
719                         "(action0) [(action1) (action2)]\n"
720                         "    meter update policer action\n\n"
721
722                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
723                         "    meter update stats\n\n"
724
725                         "show port (port_id) queue-region\n"
726                         "    show all queue region related configuration info\n\n"
727
728                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
729                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
730                         "       Add port tm node private shaper profile.\n\n"
731
732                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
733                         "       Delete port tm node private shaper profile.\n\n"
734
735                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
736                         " (shaper_profile_id)\n"
737                         "       Add/update port tm node shared shaper.\n\n"
738
739                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
740                         "       Delete port tm node shared shaper.\n\n"
741
742                         "set port tm node shaper profile (port_id) (node_id)"
743                         " (shaper_profile_id)\n"
744                         "       Set port tm node shaper profile.\n\n"
745
746                         "add port tm node wred profile (port_id) (wred_profile_id)"
747                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
748                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
749                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
750                         "       Add port tm node wred profile.\n\n"
751
752                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
753                         "       Delete port tm node wred profile.\n\n"
754
755                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
756                         " (priority) (weight) (level_id) (shaper_profile_id)"
757                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
758                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
759                         "       Add port tm nonleaf node.\n\n"
760
761                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
762                         " (priority) (weight) (level_id) (shaper_profile_id)"
763                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
764                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
765                         "       Add port tm leaf node.\n\n"
766
767                         "del port tm node (port_id) (node_id)\n"
768                         "       Delete port tm node.\n\n"
769
770                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
771                         " (priority) (weight)\n"
772                         "       Set port tm node parent.\n\n"
773
774                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
775                         "       Commit tm hierarchy.\n\n"
776
777                         , list_pkt_forwarding_modes()
778                 );
779         }
780
781         if (show_all || !strcmp(res->section, "ports")) {
782
783                 cmdline_printf(
784                         cl,
785                         "\n"
786                         "Port Operations:\n"
787                         "----------------\n\n"
788
789                         "port start (port_id|all)\n"
790                         "    Start all ports or port_id.\n\n"
791
792                         "port stop (port_id|all)\n"
793                         "    Stop all ports or port_id.\n\n"
794
795                         "port close (port_id|all)\n"
796                         "    Close all ports or port_id.\n\n"
797
798                         "port attach (ident)\n"
799                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
800
801                         "port detach (port_id)\n"
802                         "    Detach physical or virtual dev by port_id\n\n"
803
804                         "port config (port_id|all)"
805                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
806                         " duplex (half|full|auto)\n"
807                         "    Set speed and duplex for all ports or port_id\n\n"
808
809                         "port config (port_id|all) loopback (mode)\n"
810                         "    Set loopback mode for all ports or port_id\n\n"
811
812                         "port config all (rxq|txq|rxd|txd) (value)\n"
813                         "    Set number for rxq/txq/rxd/txd.\n\n"
814
815                         "port config all max-pkt-len (value)\n"
816                         "    Set the max packet length.\n\n"
817
818                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
819                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
820                         " (on|off)\n"
821                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
822                         " for ports.\n\n"
823
824                         "port config all rss (all|default|ip|tcp|udp|sctp|"
825                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
826                         "    Set the RSS mode.\n\n"
827
828                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
829                         "    Set the RSS redirection table.\n\n"
830
831                         "port config (port_id) dcb vt (on|off) (traffic_class)"
832                         " pfc (on|off)\n"
833                         "    Set the DCB mode.\n\n"
834
835                         "port config all burst (value)\n"
836                         "    Set the number of packets per burst.\n\n"
837
838                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
839                         " (value)\n"
840                         "    Set the ring prefetch/host/writeback threshold"
841                         " for tx/rx queue.\n\n"
842
843                         "port config all (txfreet|txrst|rxfreet) (value)\n"
844                         "    Set free threshold for rx/tx, or set"
845                         " tx rs bit threshold.\n\n"
846                         "port config mtu X value\n"
847                         "    Set the MTU of port X to a given value\n\n"
848
849                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
850                         "    Start/stop a rx/tx queue of port X. Only take effect"
851                         " when port X is started\n\n"
852
853                         "port config (port_id|all) l2-tunnel E-tag ether-type"
854                         " (value)\n"
855                         "    Set the value of E-tag ether-type.\n\n"
856
857                         "port config (port_id|all) l2-tunnel E-tag"
858                         " (enable|disable)\n"
859                         "    Enable/disable the E-tag support.\n\n"
860
861                         "port config (port_id) pctype mapping reset\n"
862                         "    Reset flow type to pctype mapping on a port\n\n"
863
864                         "port config (port_id) pctype mapping update"
865                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
866                         "    Update a flow type to pctype mapping item on a port\n\n"
867
868                         "port config (port_id) pctype (pctype_id) hash_inset|"
869                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
870                         " (field_idx)\n"
871                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
872
873                         "port config (port_id) pctype (pctype_id) hash_inset|"
874                         "fdir_inset|fdir_flx_inset clear all"
875                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
876                 );
877         }
878
879         if (show_all || !strcmp(res->section, "registers")) {
880
881                 cmdline_printf(
882                         cl,
883                         "\n"
884                         "Registers:\n"
885                         "----------\n\n"
886
887                         "read reg (port_id) (address)\n"
888                         "    Display value of a port register.\n\n"
889
890                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
891                         "    Display a port register bit field.\n\n"
892
893                         "read regbit (port_id) (address) (bit_x)\n"
894                         "    Display a single port register bit.\n\n"
895
896                         "write reg (port_id) (address) (value)\n"
897                         "    Set value of a port register.\n\n"
898
899                         "write regfield (port_id) (address) (bit_x) (bit_y)"
900                         " (value)\n"
901                         "    Set bit field of a port register.\n\n"
902
903                         "write regbit (port_id) (address) (bit_x) (value)\n"
904                         "    Set single bit value of a port register.\n\n"
905                 );
906         }
907         if (show_all || !strcmp(res->section, "filters")) {
908
909                 cmdline_printf(
910                         cl,
911                         "\n"
912                         "filters:\n"
913                         "--------\n\n"
914
915                         "ethertype_filter (port_id) (add|del)"
916                         " (mac_addr|mac_ignr) (mac_address) ethertype"
917                         " (ether_type) (drop|fwd) queue (queue_id)\n"
918                         "    Add/Del an ethertype filter.\n\n"
919
920                         "2tuple_filter (port_id) (add|del)"
921                         " dst_port (dst_port_value) protocol (protocol_value)"
922                         " mask (mask_value) tcp_flags (tcp_flags_value)"
923                         " priority (prio_value) queue (queue_id)\n"
924                         "    Add/Del a 2tuple filter.\n\n"
925
926                         "5tuple_filter (port_id) (add|del)"
927                         " dst_ip (dst_address) src_ip (src_address)"
928                         " dst_port (dst_port_value) src_port (src_port_value)"
929                         " protocol (protocol_value)"
930                         " mask (mask_value) tcp_flags (tcp_flags_value)"
931                         " priority (prio_value) queue (queue_id)\n"
932                         "    Add/Del a 5tuple filter.\n\n"
933
934                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
935                         "    Add/Del syn filter.\n\n"
936
937                         "flex_filter (port_id) (add|del) len (len_value)"
938                         " bytes (bytes_value) mask (mask_value)"
939                         " priority (prio_value) queue (queue_id)\n"
940                         "    Add/Del a flex filter.\n\n"
941
942                         "flow_director_filter (port_id) mode IP (add|del|update)"
943                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
944                         " src (src_ip_address) dst (dst_ip_address)"
945                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
946                         " vlan (vlan_value) flexbytes (flexbytes_value)"
947                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
948                         " fd_id (fd_id_value)\n"
949                         "    Add/Del an IP type flow director filter.\n\n"
950
951                         "flow_director_filter (port_id) mode IP (add|del|update)"
952                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
953                         " src (src_ip_address) (src_port)"
954                         " dst (dst_ip_address) (dst_port)"
955                         " tos (tos_value) ttl (ttl_value)"
956                         " vlan (vlan_value) flexbytes (flexbytes_value)"
957                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
958                         " fd_id (fd_id_value)\n"
959                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
960
961                         "flow_director_filter (port_id) mode IP (add|del|update)"
962                         " flow (ipv4-sctp|ipv6-sctp)"
963                         " src (src_ip_address) (src_port)"
964                         " dst (dst_ip_address) (dst_port)"
965                         " tag (verification_tag) "
966                         " tos (tos_value) ttl (ttl_value)"
967                         " vlan (vlan_value)"
968                         " flexbytes (flexbytes_value) (drop|fwd)"
969                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
970                         "    Add/Del a SCTP type flow director filter.\n\n"
971
972                         "flow_director_filter (port_id) mode IP (add|del|update)"
973                         " flow l2_payload ether (ethertype)"
974                         " flexbytes (flexbytes_value) (drop|fwd)"
975                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
976                         "    Add/Del a l2 payload type flow director filter.\n\n"
977
978                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
979                         " mac (mac_address) vlan (vlan_value)"
980                         " flexbytes (flexbytes_value) (drop|fwd)"
981                         " queue (queue_id) fd_id (fd_id_value)\n"
982                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
983
984                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
985                         " mac (mac_address) vlan (vlan_value)"
986                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
987                         " flexbytes (flexbytes_value) (drop|fwd)"
988                         " queue (queue_id) fd_id (fd_id_value)\n"
989                         "    Add/Del a Tunnel flow director filter.\n\n"
990
991                         "flow_director_filter (port_id) mode raw (add|del|update)"
992                         " flow (flow_id) (drop|fwd) queue (queue_id)"
993                         " fd_id (fd_id_value) packet (packet file name)\n"
994                         "    Add/Del a raw type flow director filter.\n\n"
995
996                         "flush_flow_director (port_id)\n"
997                         "    Flush all flow director entries of a device.\n\n"
998
999                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1000                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1001                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1002                         "    Set flow director IP mask.\n\n"
1003
1004                         "flow_director_mask (port_id) mode MAC-VLAN"
1005                         " vlan (vlan_value)\n"
1006                         "    Set flow director MAC-VLAN mask.\n\n"
1007
1008                         "flow_director_mask (port_id) mode Tunnel"
1009                         " vlan (vlan_value) mac (mac_value)"
1010                         " tunnel-type (tunnel_type_value)"
1011                         " tunnel-id (tunnel_id_value)\n"
1012                         "    Set flow director Tunnel mask.\n\n"
1013
1014                         "flow_director_flex_mask (port_id)"
1015                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1016                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1017                         " (mask)\n"
1018                         "    Configure mask of flex payload.\n\n"
1019
1020                         "flow_director_flex_payload (port_id)"
1021                         " (raw|l2|l3|l4) (config)\n"
1022                         "    Configure flex payload selection.\n\n"
1023
1024                         "get_sym_hash_ena_per_port (port_id)\n"
1025                         "    get symmetric hash enable configuration per port.\n\n"
1026
1027                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1028                         "    set symmetric hash enable configuration per port"
1029                         " to enable or disable.\n\n"
1030
1031                         "get_hash_global_config (port_id)\n"
1032                         "    Get the global configurations of hash filters.\n\n"
1033
1034                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1035                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1036                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1037                         " (enable|disable)\n"
1038                         "    Set the global configurations of hash filters.\n\n"
1039
1040                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1041                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1042                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1043                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1044                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1045                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1046                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1047                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1048                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1049                         "fld-8th|none) (select|add)\n"
1050                         "    Set the input set for hash.\n\n"
1051
1052                         "set_fdir_input_set (port_id) "
1053                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1054                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1055                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1056                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1057                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1058                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1059                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1060                         " (select|add)\n"
1061                         "    Set the input set for FDir.\n\n"
1062
1063                         "flow validate {port_id}"
1064                         " [group {group_id}] [priority {level}]"
1065                         " [ingress] [egress]"
1066                         " pattern {item} [/ {item} [...]] / end"
1067                         " actions {action} [/ {action} [...]] / end\n"
1068                         "    Check whether a flow rule can be created.\n\n"
1069
1070                         "flow create {port_id}"
1071                         " [group {group_id}] [priority {level}]"
1072                         " [ingress] [egress]"
1073                         " pattern {item} [/ {item} [...]] / end"
1074                         " actions {action} [/ {action} [...]] / end\n"
1075                         "    Create a flow rule.\n\n"
1076
1077                         "flow destroy {port_id} rule {rule_id} [...]\n"
1078                         "    Destroy specific flow rules.\n\n"
1079
1080                         "flow flush {port_id}\n"
1081                         "    Destroy all flow rules.\n\n"
1082
1083                         "flow query {port_id} {rule_id} {action}\n"
1084                         "    Query an existing flow rule.\n\n"
1085
1086                         "flow list {port_id} [group {group_id}] [...]\n"
1087                         "    List existing flow rules sorted by priority,"
1088                         " filtered by group identifiers.\n\n"
1089
1090                         "flow isolate {port_id} {boolean}\n"
1091                         "    Restrict ingress traffic to the defined"
1092                         " flow rules\n\n"
1093                 );
1094         }
1095 }
1096
1097 cmdline_parse_token_string_t cmd_help_long_help =
1098         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1099
1100 cmdline_parse_token_string_t cmd_help_long_section =
1101         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1102                         "all#control#display#config#"
1103                         "ports#registers#filters");
1104
1105 cmdline_parse_inst_t cmd_help_long = {
1106         .f = cmd_help_long_parsed,
1107         .data = NULL,
1108         .help_str = "help all|control|display|config|ports|register|filters: "
1109                 "Show help",
1110         .tokens = {
1111                 (void *)&cmd_help_long_help,
1112                 (void *)&cmd_help_long_section,
1113                 NULL,
1114         },
1115 };
1116
1117
1118 /* *** start/stop/close all ports *** */
1119 struct cmd_operate_port_result {
1120         cmdline_fixed_string_t keyword;
1121         cmdline_fixed_string_t name;
1122         cmdline_fixed_string_t value;
1123 };
1124
1125 static void cmd_operate_port_parsed(void *parsed_result,
1126                                 __attribute__((unused)) struct cmdline *cl,
1127                                 __attribute__((unused)) void *data)
1128 {
1129         struct cmd_operate_port_result *res = parsed_result;
1130
1131         if (!strcmp(res->name, "start"))
1132                 start_port(RTE_PORT_ALL);
1133         else if (!strcmp(res->name, "stop"))
1134                 stop_port(RTE_PORT_ALL);
1135         else if (!strcmp(res->name, "close"))
1136                 close_port(RTE_PORT_ALL);
1137         else if (!strcmp(res->name, "reset"))
1138                 reset_port(RTE_PORT_ALL);
1139         else
1140                 printf("Unknown parameter\n");
1141 }
1142
1143 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1144         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1145                                                                 "port");
1146 cmdline_parse_token_string_t cmd_operate_port_all_port =
1147         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1148                                                 "start#stop#close#reset");
1149 cmdline_parse_token_string_t cmd_operate_port_all_all =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1151
1152 cmdline_parse_inst_t cmd_operate_port = {
1153         .f = cmd_operate_port_parsed,
1154         .data = NULL,
1155         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1156         .tokens = {
1157                 (void *)&cmd_operate_port_all_cmd,
1158                 (void *)&cmd_operate_port_all_port,
1159                 (void *)&cmd_operate_port_all_all,
1160                 NULL,
1161         },
1162 };
1163
1164 /* *** start/stop/close specific port *** */
1165 struct cmd_operate_specific_port_result {
1166         cmdline_fixed_string_t keyword;
1167         cmdline_fixed_string_t name;
1168         uint8_t value;
1169 };
1170
1171 static void cmd_operate_specific_port_parsed(void *parsed_result,
1172                         __attribute__((unused)) struct cmdline *cl,
1173                                 __attribute__((unused)) void *data)
1174 {
1175         struct cmd_operate_specific_port_result *res = parsed_result;
1176
1177         if (!strcmp(res->name, "start"))
1178                 start_port(res->value);
1179         else if (!strcmp(res->name, "stop"))
1180                 stop_port(res->value);
1181         else if (!strcmp(res->name, "close"))
1182                 close_port(res->value);
1183         else if (!strcmp(res->name, "reset"))
1184                 reset_port(res->value);
1185         else
1186                 printf("Unknown parameter\n");
1187 }
1188
1189 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1190         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1191                                                         keyword, "port");
1192 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1193         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1194                                                 name, "start#stop#close#reset");
1195 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1196         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1197                                                         value, UINT8);
1198
1199 cmdline_parse_inst_t cmd_operate_specific_port = {
1200         .f = cmd_operate_specific_port_parsed,
1201         .data = NULL,
1202         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1203         .tokens = {
1204                 (void *)&cmd_operate_specific_port_cmd,
1205                 (void *)&cmd_operate_specific_port_port,
1206                 (void *)&cmd_operate_specific_port_id,
1207                 NULL,
1208         },
1209 };
1210
1211 /* *** attach a specified port *** */
1212 struct cmd_operate_attach_port_result {
1213         cmdline_fixed_string_t port;
1214         cmdline_fixed_string_t keyword;
1215         cmdline_fixed_string_t identifier;
1216 };
1217
1218 static void cmd_operate_attach_port_parsed(void *parsed_result,
1219                                 __attribute__((unused)) struct cmdline *cl,
1220                                 __attribute__((unused)) void *data)
1221 {
1222         struct cmd_operate_attach_port_result *res = parsed_result;
1223
1224         if (!strcmp(res->keyword, "attach"))
1225                 attach_port(res->identifier);
1226         else
1227                 printf("Unknown parameter\n");
1228 }
1229
1230 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1231         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1232                         port, "port");
1233 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1235                         keyword, "attach");
1236 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1238                         identifier, NULL);
1239
1240 cmdline_parse_inst_t cmd_operate_attach_port = {
1241         .f = cmd_operate_attach_port_parsed,
1242         .data = NULL,
1243         .help_str = "port attach <identifier>: "
1244                 "(identifier: pci address or virtual dev name)",
1245         .tokens = {
1246                 (void *)&cmd_operate_attach_port_port,
1247                 (void *)&cmd_operate_attach_port_keyword,
1248                 (void *)&cmd_operate_attach_port_identifier,
1249                 NULL,
1250         },
1251 };
1252
1253 /* *** detach a specified port *** */
1254 struct cmd_operate_detach_port_result {
1255         cmdline_fixed_string_t port;
1256         cmdline_fixed_string_t keyword;
1257         portid_t port_id;
1258 };
1259
1260 static void cmd_operate_detach_port_parsed(void *parsed_result,
1261                                 __attribute__((unused)) struct cmdline *cl,
1262                                 __attribute__((unused)) void *data)
1263 {
1264         struct cmd_operate_detach_port_result *res = parsed_result;
1265
1266         if (!strcmp(res->keyword, "detach"))
1267                 detach_port(res->port_id);
1268         else
1269                 printf("Unknown parameter\n");
1270 }
1271
1272 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1273         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1274                         port, "port");
1275 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1277                         keyword, "detach");
1278 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1279         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1280                         port_id, UINT16);
1281
1282 cmdline_parse_inst_t cmd_operate_detach_port = {
1283         .f = cmd_operate_detach_port_parsed,
1284         .data = NULL,
1285         .help_str = "port detach <port_id>",
1286         .tokens = {
1287                 (void *)&cmd_operate_detach_port_port,
1288                 (void *)&cmd_operate_detach_port_keyword,
1289                 (void *)&cmd_operate_detach_port_port_id,
1290                 NULL,
1291         },
1292 };
1293
1294 /* *** configure speed for all ports *** */
1295 struct cmd_config_speed_all {
1296         cmdline_fixed_string_t port;
1297         cmdline_fixed_string_t keyword;
1298         cmdline_fixed_string_t all;
1299         cmdline_fixed_string_t item1;
1300         cmdline_fixed_string_t item2;
1301         cmdline_fixed_string_t value1;
1302         cmdline_fixed_string_t value2;
1303 };
1304
1305 static int
1306 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1307 {
1308
1309         int duplex;
1310
1311         if (!strcmp(duplexstr, "half")) {
1312                 duplex = ETH_LINK_HALF_DUPLEX;
1313         } else if (!strcmp(duplexstr, "full")) {
1314                 duplex = ETH_LINK_FULL_DUPLEX;
1315         } else if (!strcmp(duplexstr, "auto")) {
1316                 duplex = ETH_LINK_FULL_DUPLEX;
1317         } else {
1318                 printf("Unknown duplex parameter\n");
1319                 return -1;
1320         }
1321
1322         if (!strcmp(speedstr, "10")) {
1323                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1324                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1325         } else if (!strcmp(speedstr, "100")) {
1326                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1327                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1328         } else {
1329                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1330                         printf("Invalid speed/duplex parameters\n");
1331                         return -1;
1332                 }
1333                 if (!strcmp(speedstr, "1000")) {
1334                         *speed = ETH_LINK_SPEED_1G;
1335                 } else if (!strcmp(speedstr, "10000")) {
1336                         *speed = ETH_LINK_SPEED_10G;
1337                 } else if (!strcmp(speedstr, "25000")) {
1338                         *speed = ETH_LINK_SPEED_25G;
1339                 } else if (!strcmp(speedstr, "40000")) {
1340                         *speed = ETH_LINK_SPEED_40G;
1341                 } else if (!strcmp(speedstr, "50000")) {
1342                         *speed = ETH_LINK_SPEED_50G;
1343                 } else if (!strcmp(speedstr, "100000")) {
1344                         *speed = ETH_LINK_SPEED_100G;
1345                 } else if (!strcmp(speedstr, "auto")) {
1346                         *speed = ETH_LINK_SPEED_AUTONEG;
1347                 } else {
1348                         printf("Unknown speed parameter\n");
1349                         return -1;
1350                 }
1351         }
1352
1353         return 0;
1354 }
1355
1356 static void
1357 cmd_config_speed_all_parsed(void *parsed_result,
1358                         __attribute__((unused)) struct cmdline *cl,
1359                         __attribute__((unused)) void *data)
1360 {
1361         struct cmd_config_speed_all *res = parsed_result;
1362         uint32_t link_speed;
1363         portid_t pid;
1364
1365         if (!all_ports_stopped()) {
1366                 printf("Please stop all ports first\n");
1367                 return;
1368         }
1369
1370         if (parse_and_check_speed_duplex(res->value1, res->value2,
1371                         &link_speed) < 0)
1372                 return;
1373
1374         RTE_ETH_FOREACH_DEV(pid) {
1375                 ports[pid].dev_conf.link_speeds = link_speed;
1376         }
1377
1378         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1379 }
1380
1381 cmdline_parse_token_string_t cmd_config_speed_all_port =
1382         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1383 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1384         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1385                                                         "config");
1386 cmdline_parse_token_string_t cmd_config_speed_all_all =
1387         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1388 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1389         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1390 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1391         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1392                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1393 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1395 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1396         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1397                                                 "half#full#auto");
1398
1399 cmdline_parse_inst_t cmd_config_speed_all = {
1400         .f = cmd_config_speed_all_parsed,
1401         .data = NULL,
1402         .help_str = "port config all speed "
1403                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1404                                                         "half|full|auto",
1405         .tokens = {
1406                 (void *)&cmd_config_speed_all_port,
1407                 (void *)&cmd_config_speed_all_keyword,
1408                 (void *)&cmd_config_speed_all_all,
1409                 (void *)&cmd_config_speed_all_item1,
1410                 (void *)&cmd_config_speed_all_value1,
1411                 (void *)&cmd_config_speed_all_item2,
1412                 (void *)&cmd_config_speed_all_value2,
1413                 NULL,
1414         },
1415 };
1416
1417 /* *** configure speed for specific port *** */
1418 struct cmd_config_speed_specific {
1419         cmdline_fixed_string_t port;
1420         cmdline_fixed_string_t keyword;
1421         uint8_t id;
1422         cmdline_fixed_string_t item1;
1423         cmdline_fixed_string_t item2;
1424         cmdline_fixed_string_t value1;
1425         cmdline_fixed_string_t value2;
1426 };
1427
1428 static void
1429 cmd_config_speed_specific_parsed(void *parsed_result,
1430                                 __attribute__((unused)) struct cmdline *cl,
1431                                 __attribute__((unused)) void *data)
1432 {
1433         struct cmd_config_speed_specific *res = parsed_result;
1434         uint32_t link_speed;
1435
1436         if (!all_ports_stopped()) {
1437                 printf("Please stop all ports first\n");
1438                 return;
1439         }
1440
1441         if (port_id_is_invalid(res->id, ENABLED_WARN))
1442                 return;
1443
1444         if (parse_and_check_speed_duplex(res->value1, res->value2,
1445                         &link_speed) < 0)
1446                 return;
1447
1448         ports[res->id].dev_conf.link_speeds = link_speed;
1449
1450         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1451 }
1452
1453
1454 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1455         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1456                                                                 "port");
1457 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1459                                                                 "config");
1460 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1461         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1462 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1463         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1464                                                                 "speed");
1465 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1467                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1468 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1470                                                                 "duplex");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1473                                                         "half#full#auto");
1474
1475 cmdline_parse_inst_t cmd_config_speed_specific = {
1476         .f = cmd_config_speed_specific_parsed,
1477         .data = NULL,
1478         .help_str = "port config <port_id> speed "
1479                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1480                                                         "half|full|auto",
1481         .tokens = {
1482                 (void *)&cmd_config_speed_specific_port,
1483                 (void *)&cmd_config_speed_specific_keyword,
1484                 (void *)&cmd_config_speed_specific_id,
1485                 (void *)&cmd_config_speed_specific_item1,
1486                 (void *)&cmd_config_speed_specific_value1,
1487                 (void *)&cmd_config_speed_specific_item2,
1488                 (void *)&cmd_config_speed_specific_value2,
1489                 NULL,
1490         },
1491 };
1492
1493 /* *** configure loopback for all ports *** */
1494 struct cmd_config_loopback_all {
1495         cmdline_fixed_string_t port;
1496         cmdline_fixed_string_t keyword;
1497         cmdline_fixed_string_t all;
1498         cmdline_fixed_string_t item;
1499         uint32_t mode;
1500 };
1501
1502 static void
1503 cmd_config_loopback_all_parsed(void *parsed_result,
1504                         __attribute__((unused)) struct cmdline *cl,
1505                         __attribute__((unused)) void *data)
1506 {
1507         struct cmd_config_loopback_all *res = parsed_result;
1508         portid_t pid;
1509
1510         if (!all_ports_stopped()) {
1511                 printf("Please stop all ports first\n");
1512                 return;
1513         }
1514
1515         RTE_ETH_FOREACH_DEV(pid) {
1516                 ports[pid].dev_conf.lpbk_mode = res->mode;
1517         }
1518
1519         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1520 }
1521
1522 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1523         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1524 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1525         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1526                                                         "config");
1527 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1528         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1529 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1530         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1531                                                         "loopback");
1532 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1533         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1534
1535 cmdline_parse_inst_t cmd_config_loopback_all = {
1536         .f = cmd_config_loopback_all_parsed,
1537         .data = NULL,
1538         .help_str = "port config all loopback <mode>",
1539         .tokens = {
1540                 (void *)&cmd_config_loopback_all_port,
1541                 (void *)&cmd_config_loopback_all_keyword,
1542                 (void *)&cmd_config_loopback_all_all,
1543                 (void *)&cmd_config_loopback_all_item,
1544                 (void *)&cmd_config_loopback_all_mode,
1545                 NULL,
1546         },
1547 };
1548
1549 /* *** configure loopback for specific port *** */
1550 struct cmd_config_loopback_specific {
1551         cmdline_fixed_string_t port;
1552         cmdline_fixed_string_t keyword;
1553         uint16_t port_id;
1554         cmdline_fixed_string_t item;
1555         uint32_t mode;
1556 };
1557
1558 static void
1559 cmd_config_loopback_specific_parsed(void *parsed_result,
1560                                 __attribute__((unused)) struct cmdline *cl,
1561                                 __attribute__((unused)) void *data)
1562 {
1563         struct cmd_config_loopback_specific *res = parsed_result;
1564
1565         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1566                 return;
1567
1568         if (!port_is_stopped(res->port_id)) {
1569                 printf("Please stop port %u first\n", res->port_id);
1570                 return;
1571         }
1572
1573         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1574
1575         cmd_reconfig_device_queue(res->port_id, 1, 1);
1576 }
1577
1578
1579 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1580         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1581                                                                 "port");
1582 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1583         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1584                                                                 "config");
1585 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1586         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1587                                                                 UINT16);
1588 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1589         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1590                                                                 "loopback");
1591 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1592         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1593                               UINT32);
1594
1595 cmdline_parse_inst_t cmd_config_loopback_specific = {
1596         .f = cmd_config_loopback_specific_parsed,
1597         .data = NULL,
1598         .help_str = "port config <port_id> loopback <mode>",
1599         .tokens = {
1600                 (void *)&cmd_config_loopback_specific_port,
1601                 (void *)&cmd_config_loopback_specific_keyword,
1602                 (void *)&cmd_config_loopback_specific_id,
1603                 (void *)&cmd_config_loopback_specific_item,
1604                 (void *)&cmd_config_loopback_specific_mode,
1605                 NULL,
1606         },
1607 };
1608
1609 /* *** configure txq/rxq, txd/rxd *** */
1610 struct cmd_config_rx_tx {
1611         cmdline_fixed_string_t port;
1612         cmdline_fixed_string_t keyword;
1613         cmdline_fixed_string_t all;
1614         cmdline_fixed_string_t name;
1615         uint16_t value;
1616 };
1617
1618 static void
1619 cmd_config_rx_tx_parsed(void *parsed_result,
1620                         __attribute__((unused)) struct cmdline *cl,
1621                         __attribute__((unused)) void *data)
1622 {
1623         struct cmd_config_rx_tx *res = parsed_result;
1624
1625         if (!all_ports_stopped()) {
1626                 printf("Please stop all ports first\n");
1627                 return;
1628         }
1629         if (!strcmp(res->name, "rxq")) {
1630                 if (!res->value && !nb_txq) {
1631                         printf("Warning: Either rx or tx queues should be non zero\n");
1632                         return;
1633                 }
1634                 if (check_nb_rxq(res->value) != 0)
1635                         return;
1636                 nb_rxq = res->value;
1637         }
1638         else if (!strcmp(res->name, "txq")) {
1639                 if (!res->value && !nb_rxq) {
1640                         printf("Warning: Either rx or tx queues should be non zero\n");
1641                         return;
1642                 }
1643                 if (check_nb_txq(res->value) != 0)
1644                         return;
1645                 nb_txq = res->value;
1646         }
1647         else if (!strcmp(res->name, "rxd")) {
1648                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1649                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1650                                         res->value, RTE_TEST_RX_DESC_MAX);
1651                         return;
1652                 }
1653                 nb_rxd = res->value;
1654         } else if (!strcmp(res->name, "txd")) {
1655                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1656                         printf("txd %d invalid - must be > 0 && <= %d\n",
1657                                         res->value, RTE_TEST_TX_DESC_MAX);
1658                         return;
1659                 }
1660                 nb_txd = res->value;
1661         } else {
1662                 printf("Unknown parameter\n");
1663                 return;
1664         }
1665
1666         fwd_config_setup();
1667
1668         init_port_config();
1669
1670         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1671 }
1672
1673 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1675 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1676         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1677 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1679 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1680         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1681                                                 "rxq#txq#rxd#txd");
1682 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1683         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1684
1685 cmdline_parse_inst_t cmd_config_rx_tx = {
1686         .f = cmd_config_rx_tx_parsed,
1687         .data = NULL,
1688         .help_str = "port config all rxq|txq|rxd|txd <value>",
1689         .tokens = {
1690                 (void *)&cmd_config_rx_tx_port,
1691                 (void *)&cmd_config_rx_tx_keyword,
1692                 (void *)&cmd_config_rx_tx_all,
1693                 (void *)&cmd_config_rx_tx_name,
1694                 (void *)&cmd_config_rx_tx_value,
1695                 NULL,
1696         },
1697 };
1698
1699 /* *** config max packet length *** */
1700 struct cmd_config_max_pkt_len_result {
1701         cmdline_fixed_string_t port;
1702         cmdline_fixed_string_t keyword;
1703         cmdline_fixed_string_t all;
1704         cmdline_fixed_string_t name;
1705         uint32_t value;
1706 };
1707
1708 static void
1709 cmd_config_max_pkt_len_parsed(void *parsed_result,
1710                                 __attribute__((unused)) struct cmdline *cl,
1711                                 __attribute__((unused)) void *data)
1712 {
1713         struct cmd_config_max_pkt_len_result *res = parsed_result;
1714         portid_t pid;
1715
1716         if (!all_ports_stopped()) {
1717                 printf("Please stop all ports first\n");
1718                 return;
1719         }
1720
1721         RTE_ETH_FOREACH_DEV(pid) {
1722                 struct rte_port *port = &ports[pid];
1723                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1724
1725                 if (!strcmp(res->name, "max-pkt-len")) {
1726                         if (res->value < ETHER_MIN_LEN) {
1727                                 printf("max-pkt-len can not be less than %d\n",
1728                                                 ETHER_MIN_LEN);
1729                                 return;
1730                         }
1731                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1732                                 return;
1733
1734                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1735                         if (res->value > ETHER_MAX_LEN)
1736                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1737                         else
1738                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1739                         port->dev_conf.rxmode.offloads = rx_offloads;
1740                 } else {
1741                         printf("Unknown parameter\n");
1742                         return;
1743                 }
1744         }
1745
1746         init_port_config();
1747
1748         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1749 }
1750
1751 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1752         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1753                                                                 "port");
1754 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1755         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1756                                                                 "config");
1757 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1758         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1759                                                                 "all");
1760 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1761         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1762                                                                 "max-pkt-len");
1763 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1764         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1765                                                                 UINT32);
1766
1767 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1768         .f = cmd_config_max_pkt_len_parsed,
1769         .data = NULL,
1770         .help_str = "port config all max-pkt-len <value>",
1771         .tokens = {
1772                 (void *)&cmd_config_max_pkt_len_port,
1773                 (void *)&cmd_config_max_pkt_len_keyword,
1774                 (void *)&cmd_config_max_pkt_len_all,
1775                 (void *)&cmd_config_max_pkt_len_name,
1776                 (void *)&cmd_config_max_pkt_len_value,
1777                 NULL,
1778         },
1779 };
1780
1781 /* *** configure port MTU *** */
1782 struct cmd_config_mtu_result {
1783         cmdline_fixed_string_t port;
1784         cmdline_fixed_string_t keyword;
1785         cmdline_fixed_string_t mtu;
1786         portid_t port_id;
1787         uint16_t value;
1788 };
1789
1790 static void
1791 cmd_config_mtu_parsed(void *parsed_result,
1792                       __attribute__((unused)) struct cmdline *cl,
1793                       __attribute__((unused)) void *data)
1794 {
1795         struct cmd_config_mtu_result *res = parsed_result;
1796
1797         if (res->value < ETHER_MIN_LEN) {
1798                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1799                 return;
1800         }
1801         port_mtu_set(res->port_id, res->value);
1802 }
1803
1804 cmdline_parse_token_string_t cmd_config_mtu_port =
1805         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1806                                  "port");
1807 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1808         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1809                                  "config");
1810 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1811         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1812                                  "mtu");
1813 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1814         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1815 cmdline_parse_token_num_t cmd_config_mtu_value =
1816         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1817
1818 cmdline_parse_inst_t cmd_config_mtu = {
1819         .f = cmd_config_mtu_parsed,
1820         .data = NULL,
1821         .help_str = "port config mtu <port_id> <value>",
1822         .tokens = {
1823                 (void *)&cmd_config_mtu_port,
1824                 (void *)&cmd_config_mtu_keyword,
1825                 (void *)&cmd_config_mtu_mtu,
1826                 (void *)&cmd_config_mtu_port_id,
1827                 (void *)&cmd_config_mtu_value,
1828                 NULL,
1829         },
1830 };
1831
1832 /* *** configure rx mode *** */
1833 struct cmd_config_rx_mode_flag {
1834         cmdline_fixed_string_t port;
1835         cmdline_fixed_string_t keyword;
1836         cmdline_fixed_string_t all;
1837         cmdline_fixed_string_t name;
1838         cmdline_fixed_string_t value;
1839 };
1840
1841 static void
1842 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1843                                 __attribute__((unused)) struct cmdline *cl,
1844                                 __attribute__((unused)) void *data)
1845 {
1846         struct cmd_config_rx_mode_flag *res = parsed_result;
1847         portid_t pid;
1848
1849         if (!all_ports_stopped()) {
1850                 printf("Please stop all ports first\n");
1851                 return;
1852         }
1853
1854         RTE_ETH_FOREACH_DEV(pid) {
1855                 struct rte_port *port;
1856                 uint64_t rx_offloads;
1857
1858                 port = &ports[pid];
1859                 rx_offloads = port->dev_conf.rxmode.offloads;
1860                 if (!strcmp(res->name, "crc-strip")) {
1861                         if (!strcmp(res->value, "on"))
1862                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1863                         else if (!strcmp(res->value, "off"))
1864                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1865                         else {
1866                                 printf("Unknown parameter\n");
1867                                 return;
1868                         }
1869                 } else if (!strcmp(res->name, "scatter")) {
1870                         if (!strcmp(res->value, "on")) {
1871                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1872                         } else if (!strcmp(res->value, "off")) {
1873                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1874                         } else {
1875                                 printf("Unknown parameter\n");
1876                                 return;
1877                         }
1878                 } else if (!strcmp(res->name, "rx-cksum")) {
1879                         if (!strcmp(res->value, "on"))
1880                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1881                         else if (!strcmp(res->value, "off"))
1882                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1883                         else {
1884                                 printf("Unknown parameter\n");
1885                                 return;
1886                         }
1887                 } else if (!strcmp(res->name, "rx-timestamp")) {
1888                         if (!strcmp(res->value, "on"))
1889                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1890                         else if (!strcmp(res->value, "off"))
1891                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1892                         else {
1893                                 printf("Unknown parameter\n");
1894                                 return;
1895                         }
1896                 } else if (!strcmp(res->name, "hw-vlan")) {
1897                         if (!strcmp(res->value, "on")) {
1898                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1899                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1900                         } else if (!strcmp(res->value, "off")) {
1901                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1902                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1903                         } else {
1904                                 printf("Unknown parameter\n");
1905                                 return;
1906                         }
1907                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1908                         if (!strcmp(res->value, "on"))
1909                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1910                         else if (!strcmp(res->value, "off"))
1911                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1912                         else {
1913                                 printf("Unknown parameter\n");
1914                                 return;
1915                         }
1916                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1917                         if (!strcmp(res->value, "on"))
1918                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1919                         else if (!strcmp(res->value, "off"))
1920                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1921                         else {
1922                                 printf("Unknown parameter\n");
1923                                 return;
1924                         }
1925                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1926                         if (!strcmp(res->value, "on"))
1927                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1928                         else if (!strcmp(res->value, "off"))
1929                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1930                         else {
1931                                 printf("Unknown parameter\n");
1932                                 return;
1933                         }
1934                 } else if (!strcmp(res->name, "drop-en")) {
1935                         if (!strcmp(res->value, "on"))
1936                                 rx_drop_en = 1;
1937                         else if (!strcmp(res->value, "off"))
1938                                 rx_drop_en = 0;
1939                         else {
1940                                 printf("Unknown parameter\n");
1941                                 return;
1942                         }
1943                 } else {
1944                         printf("Unknown parameter\n");
1945                         return;
1946                 }
1947                 port->dev_conf.rxmode.offloads = rx_offloads;
1948         }
1949
1950         init_port_config();
1951
1952         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1953 }
1954
1955 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1956         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1957 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1959                                                                 "config");
1960 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1962 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1963         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1964                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1965                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1966 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1967         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1968                                                         "on#off");
1969
1970 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1971         .f = cmd_config_rx_mode_flag_parsed,
1972         .data = NULL,
1973         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1974                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1975         .tokens = {
1976                 (void *)&cmd_config_rx_mode_flag_port,
1977                 (void *)&cmd_config_rx_mode_flag_keyword,
1978                 (void *)&cmd_config_rx_mode_flag_all,
1979                 (void *)&cmd_config_rx_mode_flag_name,
1980                 (void *)&cmd_config_rx_mode_flag_value,
1981                 NULL,
1982         },
1983 };
1984
1985 /* *** configure rss *** */
1986 struct cmd_config_rss {
1987         cmdline_fixed_string_t port;
1988         cmdline_fixed_string_t keyword;
1989         cmdline_fixed_string_t all;
1990         cmdline_fixed_string_t name;
1991         cmdline_fixed_string_t value;
1992 };
1993
1994 static void
1995 cmd_config_rss_parsed(void *parsed_result,
1996                         __attribute__((unused)) struct cmdline *cl,
1997                         __attribute__((unused)) void *data)
1998 {
1999         struct cmd_config_rss *res = parsed_result;
2000         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2001         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2002         int diag;
2003         uint16_t i;
2004
2005         if (!strcmp(res->value, "all"))
2006                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2007                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2008                                         ETH_RSS_L2_PAYLOAD;
2009         else if (!strcmp(res->value, "ip"))
2010                 rss_conf.rss_hf = ETH_RSS_IP;
2011         else if (!strcmp(res->value, "udp"))
2012                 rss_conf.rss_hf = ETH_RSS_UDP;
2013         else if (!strcmp(res->value, "tcp"))
2014                 rss_conf.rss_hf = ETH_RSS_TCP;
2015         else if (!strcmp(res->value, "sctp"))
2016                 rss_conf.rss_hf = ETH_RSS_SCTP;
2017         else if (!strcmp(res->value, "ether"))
2018                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2019         else if (!strcmp(res->value, "port"))
2020                 rss_conf.rss_hf = ETH_RSS_PORT;
2021         else if (!strcmp(res->value, "vxlan"))
2022                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2023         else if (!strcmp(res->value, "geneve"))
2024                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2025         else if (!strcmp(res->value, "nvgre"))
2026                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2027         else if (!strcmp(res->value, "none") || !strcmp(res->value, "default"))
2028                 rss_conf.rss_hf = 0;
2029         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2030                                                 atoi(res->value) < 64)
2031                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2032         else {
2033                 printf("Unknown parameter\n");
2034                 return;
2035         }
2036         rss_conf.rss_key = NULL;
2037         /* Update global configuration for RSS types. */
2038         rss_hf = rss_conf.rss_hf;
2039         RTE_ETH_FOREACH_DEV(i) {
2040                 if (!strcmp(res->value, "default")) {
2041                         rte_eth_dev_info_get(i, &dev_info);
2042                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2043                 }
2044                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
2045                 if (diag < 0)
2046                         printf("Configuration of RSS hash at ethernet port %d "
2047                                 "failed with error (%d): %s.\n",
2048                                 i, -diag, strerror(-diag));
2049         }
2050 }
2051
2052 cmdline_parse_token_string_t cmd_config_rss_port =
2053         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2054 cmdline_parse_token_string_t cmd_config_rss_keyword =
2055         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2056 cmdline_parse_token_string_t cmd_config_rss_all =
2057         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2058 cmdline_parse_token_string_t cmd_config_rss_name =
2059         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2060 cmdline_parse_token_string_t cmd_config_rss_value =
2061         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2062
2063 cmdline_parse_inst_t cmd_config_rss = {
2064         .f = cmd_config_rss_parsed,
2065         .data = NULL,
2066         .help_str = "port config all rss "
2067                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2068         .tokens = {
2069                 (void *)&cmd_config_rss_port,
2070                 (void *)&cmd_config_rss_keyword,
2071                 (void *)&cmd_config_rss_all,
2072                 (void *)&cmd_config_rss_name,
2073                 (void *)&cmd_config_rss_value,
2074                 NULL,
2075         },
2076 };
2077
2078 /* *** configure rss hash key *** */
2079 struct cmd_config_rss_hash_key {
2080         cmdline_fixed_string_t port;
2081         cmdline_fixed_string_t config;
2082         portid_t port_id;
2083         cmdline_fixed_string_t rss_hash_key;
2084         cmdline_fixed_string_t rss_type;
2085         cmdline_fixed_string_t key;
2086 };
2087
2088 static uint8_t
2089 hexa_digit_to_value(char hexa_digit)
2090 {
2091         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2092                 return (uint8_t) (hexa_digit - '0');
2093         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2094                 return (uint8_t) ((hexa_digit - 'a') + 10);
2095         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2096                 return (uint8_t) ((hexa_digit - 'A') + 10);
2097         /* Invalid hexa digit */
2098         return 0xFF;
2099 }
2100
2101 static uint8_t
2102 parse_and_check_key_hexa_digit(char *key, int idx)
2103 {
2104         uint8_t hexa_v;
2105
2106         hexa_v = hexa_digit_to_value(key[idx]);
2107         if (hexa_v == 0xFF)
2108                 printf("invalid key: character %c at position %d is not a "
2109                        "valid hexa digit\n", key[idx], idx);
2110         return hexa_v;
2111 }
2112
2113 static void
2114 cmd_config_rss_hash_key_parsed(void *parsed_result,
2115                                __attribute__((unused)) struct cmdline *cl,
2116                                __attribute__((unused)) void *data)
2117 {
2118         struct cmd_config_rss_hash_key *res = parsed_result;
2119         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2120         uint8_t xdgt0;
2121         uint8_t xdgt1;
2122         int i;
2123         struct rte_eth_dev_info dev_info;
2124         uint8_t hash_key_size;
2125         uint32_t key_len;
2126
2127         memset(&dev_info, 0, sizeof(dev_info));
2128         rte_eth_dev_info_get(res->port_id, &dev_info);
2129         if (dev_info.hash_key_size > 0 &&
2130                         dev_info.hash_key_size <= sizeof(hash_key))
2131                 hash_key_size = dev_info.hash_key_size;
2132         else {
2133                 printf("dev_info did not provide a valid hash key size\n");
2134                 return;
2135         }
2136         /* Check the length of the RSS hash key */
2137         key_len = strlen(res->key);
2138         if (key_len != (hash_key_size * 2)) {
2139                 printf("key length: %d invalid - key must be a string of %d"
2140                            " hexa-decimal numbers\n",
2141                            (int) key_len, hash_key_size * 2);
2142                 return;
2143         }
2144         /* Translate RSS hash key into binary representation */
2145         for (i = 0; i < hash_key_size; i++) {
2146                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2147                 if (xdgt0 == 0xFF)
2148                         return;
2149                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2150                 if (xdgt1 == 0xFF)
2151                         return;
2152                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2153         }
2154         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2155                         hash_key_size);
2156 }
2157
2158 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2159         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2160 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2161         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2162                                  "config");
2163 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2164         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2165 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2166         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2167                                  rss_hash_key, "rss-hash-key");
2168 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2169         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2170                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2171                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2172                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2173                                  "ipv6-tcp-ex#ipv6-udp-ex");
2174 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2175         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2176
2177 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2178         .f = cmd_config_rss_hash_key_parsed,
2179         .data = NULL,
2180         .help_str = "port config <port_id> rss-hash-key "
2181                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2182                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2183                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2184                 "<string of hex digits (variable length, NIC dependent)>",
2185         .tokens = {
2186                 (void *)&cmd_config_rss_hash_key_port,
2187                 (void *)&cmd_config_rss_hash_key_config,
2188                 (void *)&cmd_config_rss_hash_key_port_id,
2189                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2190                 (void *)&cmd_config_rss_hash_key_rss_type,
2191                 (void *)&cmd_config_rss_hash_key_value,
2192                 NULL,
2193         },
2194 };
2195
2196 /* *** configure port rxq/txq start/stop *** */
2197 struct cmd_config_rxtx_queue {
2198         cmdline_fixed_string_t port;
2199         portid_t portid;
2200         cmdline_fixed_string_t rxtxq;
2201         uint16_t qid;
2202         cmdline_fixed_string_t opname;
2203 };
2204
2205 static void
2206 cmd_config_rxtx_queue_parsed(void *parsed_result,
2207                         __attribute__((unused)) struct cmdline *cl,
2208                         __attribute__((unused)) void *data)
2209 {
2210         struct cmd_config_rxtx_queue *res = parsed_result;
2211         uint8_t isrx;
2212         uint8_t isstart;
2213         int ret = 0;
2214
2215         if (test_done == 0) {
2216                 printf("Please stop forwarding first\n");
2217                 return;
2218         }
2219
2220         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2221                 return;
2222
2223         if (port_is_started(res->portid) != 1) {
2224                 printf("Please start port %u first\n", res->portid);
2225                 return;
2226         }
2227
2228         if (!strcmp(res->rxtxq, "rxq"))
2229                 isrx = 1;
2230         else if (!strcmp(res->rxtxq, "txq"))
2231                 isrx = 0;
2232         else {
2233                 printf("Unknown parameter\n");
2234                 return;
2235         }
2236
2237         if (isrx && rx_queue_id_is_invalid(res->qid))
2238                 return;
2239         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2240                 return;
2241
2242         if (!strcmp(res->opname, "start"))
2243                 isstart = 1;
2244         else if (!strcmp(res->opname, "stop"))
2245                 isstart = 0;
2246         else {
2247                 printf("Unknown parameter\n");
2248                 return;
2249         }
2250
2251         if (isstart && isrx)
2252                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2253         else if (!isstart && isrx)
2254                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2255         else if (isstart && !isrx)
2256                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2257         else
2258                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2259
2260         if (ret == -ENOTSUP)
2261                 printf("Function not supported in PMD driver\n");
2262 }
2263
2264 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2265         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2266 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2267         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2268 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2269         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2270 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2271         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2272 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2273         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2274                                                 "start#stop");
2275
2276 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2277         .f = cmd_config_rxtx_queue_parsed,
2278         .data = NULL,
2279         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2280         .tokens = {
2281                 (void *)&cmd_config_speed_all_port,
2282                 (void *)&cmd_config_rxtx_queue_portid,
2283                 (void *)&cmd_config_rxtx_queue_rxtxq,
2284                 (void *)&cmd_config_rxtx_queue_qid,
2285                 (void *)&cmd_config_rxtx_queue_opname,
2286                 NULL,
2287         },
2288 };
2289
2290 /* *** Configure RSS RETA *** */
2291 struct cmd_config_rss_reta {
2292         cmdline_fixed_string_t port;
2293         cmdline_fixed_string_t keyword;
2294         portid_t port_id;
2295         cmdline_fixed_string_t name;
2296         cmdline_fixed_string_t list_name;
2297         cmdline_fixed_string_t list_of_items;
2298 };
2299
2300 static int
2301 parse_reta_config(const char *str,
2302                   struct rte_eth_rss_reta_entry64 *reta_conf,
2303                   uint16_t nb_entries)
2304 {
2305         int i;
2306         unsigned size;
2307         uint16_t hash_index, idx, shift;
2308         uint16_t nb_queue;
2309         char s[256];
2310         const char *p, *p0 = str;
2311         char *end;
2312         enum fieldnames {
2313                 FLD_HASH_INDEX = 0,
2314                 FLD_QUEUE,
2315                 _NUM_FLD
2316         };
2317         unsigned long int_fld[_NUM_FLD];
2318         char *str_fld[_NUM_FLD];
2319
2320         while ((p = strchr(p0,'(')) != NULL) {
2321                 ++p;
2322                 if((p0 = strchr(p,')')) == NULL)
2323                         return -1;
2324
2325                 size = p0 - p;
2326                 if(size >= sizeof(s))
2327                         return -1;
2328
2329                 snprintf(s, sizeof(s), "%.*s", size, p);
2330                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2331                         return -1;
2332                 for (i = 0; i < _NUM_FLD; i++) {
2333                         errno = 0;
2334                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2335                         if (errno != 0 || end == str_fld[i] ||
2336                                         int_fld[i] > 65535)
2337                                 return -1;
2338                 }
2339
2340                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2341                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2342
2343                 if (hash_index >= nb_entries) {
2344                         printf("Invalid RETA hash index=%d\n", hash_index);
2345                         return -1;
2346                 }
2347
2348                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2349                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2350                 reta_conf[idx].mask |= (1ULL << shift);
2351                 reta_conf[idx].reta[shift] = nb_queue;
2352         }
2353
2354         return 0;
2355 }
2356
2357 static void
2358 cmd_set_rss_reta_parsed(void *parsed_result,
2359                         __attribute__((unused)) struct cmdline *cl,
2360                         __attribute__((unused)) void *data)
2361 {
2362         int ret;
2363         struct rte_eth_dev_info dev_info;
2364         struct rte_eth_rss_reta_entry64 reta_conf[8];
2365         struct cmd_config_rss_reta *res = parsed_result;
2366
2367         memset(&dev_info, 0, sizeof(dev_info));
2368         rte_eth_dev_info_get(res->port_id, &dev_info);
2369         if (dev_info.reta_size == 0) {
2370                 printf("Redirection table size is 0 which is "
2371                                         "invalid for RSS\n");
2372                 return;
2373         } else
2374                 printf("The reta size of port %d is %u\n",
2375                         res->port_id, dev_info.reta_size);
2376         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2377                 printf("Currently do not support more than %u entries of "
2378                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2379                 return;
2380         }
2381
2382         memset(reta_conf, 0, sizeof(reta_conf));
2383         if (!strcmp(res->list_name, "reta")) {
2384                 if (parse_reta_config(res->list_of_items, reta_conf,
2385                                                 dev_info.reta_size)) {
2386                         printf("Invalid RSS Redirection Table "
2387                                         "config entered\n");
2388                         return;
2389                 }
2390                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2391                                 reta_conf, dev_info.reta_size);
2392                 if (ret != 0)
2393                         printf("Bad redirection table parameter, "
2394                                         "return code = %d \n", ret);
2395         }
2396 }
2397
2398 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2399         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2400 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2401         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2402 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2403         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2404 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2405         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2406 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2407         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2408 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2409         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2410                                  NULL);
2411 cmdline_parse_inst_t cmd_config_rss_reta = {
2412         .f = cmd_set_rss_reta_parsed,
2413         .data = NULL,
2414         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2415         .tokens = {
2416                 (void *)&cmd_config_rss_reta_port,
2417                 (void *)&cmd_config_rss_reta_keyword,
2418                 (void *)&cmd_config_rss_reta_port_id,
2419                 (void *)&cmd_config_rss_reta_name,
2420                 (void *)&cmd_config_rss_reta_list_name,
2421                 (void *)&cmd_config_rss_reta_list_of_items,
2422                 NULL,
2423         },
2424 };
2425
2426 /* *** SHOW PORT RETA INFO *** */
2427 struct cmd_showport_reta {
2428         cmdline_fixed_string_t show;
2429         cmdline_fixed_string_t port;
2430         portid_t port_id;
2431         cmdline_fixed_string_t rss;
2432         cmdline_fixed_string_t reta;
2433         uint16_t size;
2434         cmdline_fixed_string_t list_of_items;
2435 };
2436
2437 static int
2438 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2439                            uint16_t nb_entries,
2440                            char *str)
2441 {
2442         uint32_t size;
2443         const char *p, *p0 = str;
2444         char s[256];
2445         char *end;
2446         char *str_fld[8];
2447         uint16_t i;
2448         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2449                         RTE_RETA_GROUP_SIZE;
2450         int ret;
2451
2452         p = strchr(p0, '(');
2453         if (p == NULL)
2454                 return -1;
2455         p++;
2456         p0 = strchr(p, ')');
2457         if (p0 == NULL)
2458                 return -1;
2459         size = p0 - p;
2460         if (size >= sizeof(s)) {
2461                 printf("The string size exceeds the internal buffer size\n");
2462                 return -1;
2463         }
2464         snprintf(s, sizeof(s), "%.*s", size, p);
2465         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2466         if (ret <= 0 || ret != num) {
2467                 printf("The bits of masks do not match the number of "
2468                                         "reta entries: %u\n", num);
2469                 return -1;
2470         }
2471         for (i = 0; i < ret; i++)
2472                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2473
2474         return 0;
2475 }
2476
2477 static void
2478 cmd_showport_reta_parsed(void *parsed_result,
2479                          __attribute__((unused)) struct cmdline *cl,
2480                          __attribute__((unused)) void *data)
2481 {
2482         struct cmd_showport_reta *res = parsed_result;
2483         struct rte_eth_rss_reta_entry64 reta_conf[8];
2484         struct rte_eth_dev_info dev_info;
2485         uint16_t max_reta_size;
2486
2487         memset(&dev_info, 0, sizeof(dev_info));
2488         rte_eth_dev_info_get(res->port_id, &dev_info);
2489         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2490         if (res->size == 0 || res->size > max_reta_size) {
2491                 printf("Invalid redirection table size: %u (1-%u)\n",
2492                         res->size, max_reta_size);
2493                 return;
2494         }
2495
2496         memset(reta_conf, 0, sizeof(reta_conf));
2497         if (showport_parse_reta_config(reta_conf, res->size,
2498                                 res->list_of_items) < 0) {
2499                 printf("Invalid string: %s for reta masks\n",
2500                                         res->list_of_items);
2501                 return;
2502         }
2503         port_rss_reta_info(res->port_id, reta_conf, res->size);
2504 }
2505
2506 cmdline_parse_token_string_t cmd_showport_reta_show =
2507         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2508 cmdline_parse_token_string_t cmd_showport_reta_port =
2509         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2510 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2511         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2512 cmdline_parse_token_string_t cmd_showport_reta_rss =
2513         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2514 cmdline_parse_token_string_t cmd_showport_reta_reta =
2515         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2516 cmdline_parse_token_num_t cmd_showport_reta_size =
2517         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2518 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2519         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2520                                         list_of_items, NULL);
2521
2522 cmdline_parse_inst_t cmd_showport_reta = {
2523         .f = cmd_showport_reta_parsed,
2524         .data = NULL,
2525         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2526         .tokens = {
2527                 (void *)&cmd_showport_reta_show,
2528                 (void *)&cmd_showport_reta_port,
2529                 (void *)&cmd_showport_reta_port_id,
2530                 (void *)&cmd_showport_reta_rss,
2531                 (void *)&cmd_showport_reta_reta,
2532                 (void *)&cmd_showport_reta_size,
2533                 (void *)&cmd_showport_reta_list_of_items,
2534                 NULL,
2535         },
2536 };
2537
2538 /* *** Show RSS hash configuration *** */
2539 struct cmd_showport_rss_hash {
2540         cmdline_fixed_string_t show;
2541         cmdline_fixed_string_t port;
2542         portid_t port_id;
2543         cmdline_fixed_string_t rss_hash;
2544         cmdline_fixed_string_t rss_type;
2545         cmdline_fixed_string_t key; /* optional argument */
2546 };
2547
2548 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2549                                 __attribute__((unused)) struct cmdline *cl,
2550                                 void *show_rss_key)
2551 {
2552         struct cmd_showport_rss_hash *res = parsed_result;
2553
2554         port_rss_hash_conf_show(res->port_id, res->rss_type,
2555                                 show_rss_key != NULL);
2556 }
2557
2558 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2559         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2560 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2561         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2562 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2563         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2564 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2565         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2566                                  "rss-hash");
2567 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2568         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2569                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2570                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2571                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2572                                  "ipv6-tcp-ex#ipv6-udp-ex");
2573 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2574         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2575
2576 cmdline_parse_inst_t cmd_showport_rss_hash = {
2577         .f = cmd_showport_rss_hash_parsed,
2578         .data = NULL,
2579         .help_str = "show port <port_id> rss-hash "
2580                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2581                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2582                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2583         .tokens = {
2584                 (void *)&cmd_showport_rss_hash_show,
2585                 (void *)&cmd_showport_rss_hash_port,
2586                 (void *)&cmd_showport_rss_hash_port_id,
2587                 (void *)&cmd_showport_rss_hash_rss_hash,
2588                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2589                 NULL,
2590         },
2591 };
2592
2593 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2594         .f = cmd_showport_rss_hash_parsed,
2595         .data = (void *)1,
2596         .help_str = "show port <port_id> rss-hash "
2597                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2598                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2599                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2600         .tokens = {
2601                 (void *)&cmd_showport_rss_hash_show,
2602                 (void *)&cmd_showport_rss_hash_port,
2603                 (void *)&cmd_showport_rss_hash_port_id,
2604                 (void *)&cmd_showport_rss_hash_rss_hash,
2605                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2606                 (void *)&cmd_showport_rss_hash_rss_key,
2607                 NULL,
2608         },
2609 };
2610
2611 /* *** Configure DCB *** */
2612 struct cmd_config_dcb {
2613         cmdline_fixed_string_t port;
2614         cmdline_fixed_string_t config;
2615         portid_t port_id;
2616         cmdline_fixed_string_t dcb;
2617         cmdline_fixed_string_t vt;
2618         cmdline_fixed_string_t vt_en;
2619         uint8_t num_tcs;
2620         cmdline_fixed_string_t pfc;
2621         cmdline_fixed_string_t pfc_en;
2622 };
2623
2624 static void
2625 cmd_config_dcb_parsed(void *parsed_result,
2626                         __attribute__((unused)) struct cmdline *cl,
2627                         __attribute__((unused)) void *data)
2628 {
2629         struct cmd_config_dcb *res = parsed_result;
2630         portid_t port_id = res->port_id;
2631         struct rte_port *port;
2632         uint8_t pfc_en;
2633         int ret;
2634
2635         port = &ports[port_id];
2636         /** Check if the port is not started **/
2637         if (port->port_status != RTE_PORT_STOPPED) {
2638                 printf("Please stop port %d first\n", port_id);
2639                 return;
2640         }
2641
2642         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2643                 printf("The invalid number of traffic class,"
2644                         " only 4 or 8 allowed.\n");
2645                 return;
2646         }
2647
2648         if (nb_fwd_lcores < res->num_tcs) {
2649                 printf("nb_cores shouldn't be less than number of TCs.\n");
2650                 return;
2651         }
2652         if (!strncmp(res->pfc_en, "on", 2))
2653                 pfc_en = 1;
2654         else
2655                 pfc_en = 0;
2656
2657         /* DCB in VT mode */
2658         if (!strncmp(res->vt_en, "on", 2))
2659                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2660                                 (enum rte_eth_nb_tcs)res->num_tcs,
2661                                 pfc_en);
2662         else
2663                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2664                                 (enum rte_eth_nb_tcs)res->num_tcs,
2665                                 pfc_en);
2666
2667
2668         if (ret != 0) {
2669                 printf("Cannot initialize network ports.\n");
2670                 return;
2671         }
2672
2673         cmd_reconfig_device_queue(port_id, 1, 1);
2674 }
2675
2676 cmdline_parse_token_string_t cmd_config_dcb_port =
2677         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2678 cmdline_parse_token_string_t cmd_config_dcb_config =
2679         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2680 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2681         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2682 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2683         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2684 cmdline_parse_token_string_t cmd_config_dcb_vt =
2685         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2686 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2687         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2688 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2689         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2690 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2691         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2692 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2693         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2694
2695 cmdline_parse_inst_t cmd_config_dcb = {
2696         .f = cmd_config_dcb_parsed,
2697         .data = NULL,
2698         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2699         .tokens = {
2700                 (void *)&cmd_config_dcb_port,
2701                 (void *)&cmd_config_dcb_config,
2702                 (void *)&cmd_config_dcb_port_id,
2703                 (void *)&cmd_config_dcb_dcb,
2704                 (void *)&cmd_config_dcb_vt,
2705                 (void *)&cmd_config_dcb_vt_en,
2706                 (void *)&cmd_config_dcb_num_tcs,
2707                 (void *)&cmd_config_dcb_pfc,
2708                 (void *)&cmd_config_dcb_pfc_en,
2709                 NULL,
2710         },
2711 };
2712
2713 /* *** configure number of packets per burst *** */
2714 struct cmd_config_burst {
2715         cmdline_fixed_string_t port;
2716         cmdline_fixed_string_t keyword;
2717         cmdline_fixed_string_t all;
2718         cmdline_fixed_string_t name;
2719         uint16_t value;
2720 };
2721
2722 static void
2723 cmd_config_burst_parsed(void *parsed_result,
2724                         __attribute__((unused)) struct cmdline *cl,
2725                         __attribute__((unused)) void *data)
2726 {
2727         struct cmd_config_burst *res = parsed_result;
2728         struct rte_eth_dev_info dev_info;
2729         uint16_t rec_nb_pkts;
2730
2731         if (!all_ports_stopped()) {
2732                 printf("Please stop all ports first\n");
2733                 return;
2734         }
2735
2736         if (!strcmp(res->name, "burst")) {
2737                 if (res->value == 0) {
2738                         /* If user gives a value of zero, query the PMD for
2739                          * its recommended Rx burst size. Testpmd uses a single
2740                          * size for all ports, so assume all ports are the same
2741                          * NIC model and use the values from Port 0.
2742                          */
2743                         rte_eth_dev_info_get(0, &dev_info);
2744                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
2745
2746                         if (rec_nb_pkts == 0) {
2747                                 printf("PMD does not recommend a burst size.\n"
2748                                         "User provided value must be between"
2749                                         " 1 and %d\n", MAX_PKT_BURST);
2750                                 return;
2751                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
2752                                 printf("PMD recommended burst size of %d"
2753                                         " exceeds maximum value of %d\n",
2754                                         rec_nb_pkts, MAX_PKT_BURST);
2755                                 return;
2756                         }
2757                         printf("Using PMD-provided burst value of %d\n",
2758                                 rec_nb_pkts);
2759                         nb_pkt_per_burst = rec_nb_pkts;
2760                 } else if (res->value > MAX_PKT_BURST) {
2761                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2762                         return;
2763                 } else
2764                         nb_pkt_per_burst = res->value;
2765         } else {
2766                 printf("Unknown parameter\n");
2767                 return;
2768         }
2769
2770         init_port_config();
2771
2772         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2773 }
2774
2775 cmdline_parse_token_string_t cmd_config_burst_port =
2776         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2777 cmdline_parse_token_string_t cmd_config_burst_keyword =
2778         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2779 cmdline_parse_token_string_t cmd_config_burst_all =
2780         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2781 cmdline_parse_token_string_t cmd_config_burst_name =
2782         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2783 cmdline_parse_token_num_t cmd_config_burst_value =
2784         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2785
2786 cmdline_parse_inst_t cmd_config_burst = {
2787         .f = cmd_config_burst_parsed,
2788         .data = NULL,
2789         .help_str = "port config all burst <value>",
2790         .tokens = {
2791                 (void *)&cmd_config_burst_port,
2792                 (void *)&cmd_config_burst_keyword,
2793                 (void *)&cmd_config_burst_all,
2794                 (void *)&cmd_config_burst_name,
2795                 (void *)&cmd_config_burst_value,
2796                 NULL,
2797         },
2798 };
2799
2800 /* *** configure rx/tx queues *** */
2801 struct cmd_config_thresh {
2802         cmdline_fixed_string_t port;
2803         cmdline_fixed_string_t keyword;
2804         cmdline_fixed_string_t all;
2805         cmdline_fixed_string_t name;
2806         uint8_t value;
2807 };
2808
2809 static void
2810 cmd_config_thresh_parsed(void *parsed_result,
2811                         __attribute__((unused)) struct cmdline *cl,
2812                         __attribute__((unused)) void *data)
2813 {
2814         struct cmd_config_thresh *res = parsed_result;
2815
2816         if (!all_ports_stopped()) {
2817                 printf("Please stop all ports first\n");
2818                 return;
2819         }
2820
2821         if (!strcmp(res->name, "txpt"))
2822                 tx_pthresh = res->value;
2823         else if(!strcmp(res->name, "txht"))
2824                 tx_hthresh = res->value;
2825         else if(!strcmp(res->name, "txwt"))
2826                 tx_wthresh = res->value;
2827         else if(!strcmp(res->name, "rxpt"))
2828                 rx_pthresh = res->value;
2829         else if(!strcmp(res->name, "rxht"))
2830                 rx_hthresh = res->value;
2831         else if(!strcmp(res->name, "rxwt"))
2832                 rx_wthresh = res->value;
2833         else {
2834                 printf("Unknown parameter\n");
2835                 return;
2836         }
2837
2838         init_port_config();
2839
2840         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2841 }
2842
2843 cmdline_parse_token_string_t cmd_config_thresh_port =
2844         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2845 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2846         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2847 cmdline_parse_token_string_t cmd_config_thresh_all =
2848         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2849 cmdline_parse_token_string_t cmd_config_thresh_name =
2850         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2851                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2852 cmdline_parse_token_num_t cmd_config_thresh_value =
2853         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2854
2855 cmdline_parse_inst_t cmd_config_thresh = {
2856         .f = cmd_config_thresh_parsed,
2857         .data = NULL,
2858         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2859         .tokens = {
2860                 (void *)&cmd_config_thresh_port,
2861                 (void *)&cmd_config_thresh_keyword,
2862                 (void *)&cmd_config_thresh_all,
2863                 (void *)&cmd_config_thresh_name,
2864                 (void *)&cmd_config_thresh_value,
2865                 NULL,
2866         },
2867 };
2868
2869 /* *** configure free/rs threshold *** */
2870 struct cmd_config_threshold {
2871         cmdline_fixed_string_t port;
2872         cmdline_fixed_string_t keyword;
2873         cmdline_fixed_string_t all;
2874         cmdline_fixed_string_t name;
2875         uint16_t value;
2876 };
2877
2878 static void
2879 cmd_config_threshold_parsed(void *parsed_result,
2880                         __attribute__((unused)) struct cmdline *cl,
2881                         __attribute__((unused)) void *data)
2882 {
2883         struct cmd_config_threshold *res = parsed_result;
2884
2885         if (!all_ports_stopped()) {
2886                 printf("Please stop all ports first\n");
2887                 return;
2888         }
2889
2890         if (!strcmp(res->name, "txfreet"))
2891                 tx_free_thresh = res->value;
2892         else if (!strcmp(res->name, "txrst"))
2893                 tx_rs_thresh = res->value;
2894         else if (!strcmp(res->name, "rxfreet"))
2895                 rx_free_thresh = res->value;
2896         else {
2897                 printf("Unknown parameter\n");
2898                 return;
2899         }
2900
2901         init_port_config();
2902
2903         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2904 }
2905
2906 cmdline_parse_token_string_t cmd_config_threshold_port =
2907         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2908 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2909         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2910                                                                 "config");
2911 cmdline_parse_token_string_t cmd_config_threshold_all =
2912         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2913 cmdline_parse_token_string_t cmd_config_threshold_name =
2914         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2915                                                 "txfreet#txrst#rxfreet");
2916 cmdline_parse_token_num_t cmd_config_threshold_value =
2917         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2918
2919 cmdline_parse_inst_t cmd_config_threshold = {
2920         .f = cmd_config_threshold_parsed,
2921         .data = NULL,
2922         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2923         .tokens = {
2924                 (void *)&cmd_config_threshold_port,
2925                 (void *)&cmd_config_threshold_keyword,
2926                 (void *)&cmd_config_threshold_all,
2927                 (void *)&cmd_config_threshold_name,
2928                 (void *)&cmd_config_threshold_value,
2929                 NULL,
2930         },
2931 };
2932
2933 /* *** stop *** */
2934 struct cmd_stop_result {
2935         cmdline_fixed_string_t stop;
2936 };
2937
2938 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2939                             __attribute__((unused)) struct cmdline *cl,
2940                             __attribute__((unused)) void *data)
2941 {
2942         stop_packet_forwarding();
2943 }
2944
2945 cmdline_parse_token_string_t cmd_stop_stop =
2946         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2947
2948 cmdline_parse_inst_t cmd_stop = {
2949         .f = cmd_stop_parsed,
2950         .data = NULL,
2951         .help_str = "stop: Stop packet forwarding",
2952         .tokens = {
2953                 (void *)&cmd_stop_stop,
2954                 NULL,
2955         },
2956 };
2957
2958 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2959
2960 unsigned int
2961 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2962                 unsigned int *parsed_items, int check_unique_values)
2963 {
2964         unsigned int nb_item;
2965         unsigned int value;
2966         unsigned int i;
2967         unsigned int j;
2968         int value_ok;
2969         char c;
2970
2971         /*
2972          * First parse all items in the list and store their value.
2973          */
2974         value = 0;
2975         nb_item = 0;
2976         value_ok = 0;
2977         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2978                 c = str[i];
2979                 if ((c >= '0') && (c <= '9')) {
2980                         value = (unsigned int) (value * 10 + (c - '0'));
2981                         value_ok = 1;
2982                         continue;
2983                 }
2984                 if (c != ',') {
2985                         printf("character %c is not a decimal digit\n", c);
2986                         return 0;
2987                 }
2988                 if (! value_ok) {
2989                         printf("No valid value before comma\n");
2990                         return 0;
2991                 }
2992                 if (nb_item < max_items) {
2993                         parsed_items[nb_item] = value;
2994                         value_ok = 0;
2995                         value = 0;
2996                 }
2997                 nb_item++;
2998         }
2999         if (nb_item >= max_items) {
3000                 printf("Number of %s = %u > %u (maximum items)\n",
3001                        item_name, nb_item + 1, max_items);
3002                 return 0;
3003         }
3004         parsed_items[nb_item++] = value;
3005         if (! check_unique_values)
3006                 return nb_item;
3007
3008         /*
3009          * Then, check that all values in the list are differents.
3010          * No optimization here...
3011          */
3012         for (i = 0; i < nb_item; i++) {
3013                 for (j = i + 1; j < nb_item; j++) {
3014                         if (parsed_items[j] == parsed_items[i]) {
3015                                 printf("duplicated %s %u at index %u and %u\n",
3016                                        item_name, parsed_items[i], i, j);
3017                                 return 0;
3018                         }
3019                 }
3020         }
3021         return nb_item;
3022 }
3023
3024 struct cmd_set_list_result {
3025         cmdline_fixed_string_t cmd_keyword;
3026         cmdline_fixed_string_t list_name;
3027         cmdline_fixed_string_t list_of_items;
3028 };
3029
3030 static void cmd_set_list_parsed(void *parsed_result,
3031                                 __attribute__((unused)) struct cmdline *cl,
3032                                 __attribute__((unused)) void *data)
3033 {
3034         struct cmd_set_list_result *res;
3035         union {
3036                 unsigned int lcorelist[RTE_MAX_LCORE];
3037                 unsigned int portlist[RTE_MAX_ETHPORTS];
3038         } parsed_items;
3039         unsigned int nb_item;
3040
3041         if (test_done == 0) {
3042                 printf("Please stop forwarding first\n");
3043                 return;
3044         }
3045
3046         res = parsed_result;
3047         if (!strcmp(res->list_name, "corelist")) {
3048                 nb_item = parse_item_list(res->list_of_items, "core",
3049                                           RTE_MAX_LCORE,
3050                                           parsed_items.lcorelist, 1);
3051                 if (nb_item > 0) {
3052                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3053                         fwd_config_setup();
3054                 }
3055                 return;
3056         }
3057         if (!strcmp(res->list_name, "portlist")) {
3058                 nb_item = parse_item_list(res->list_of_items, "port",
3059                                           RTE_MAX_ETHPORTS,
3060                                           parsed_items.portlist, 1);
3061                 if (nb_item > 0) {
3062                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3063                         fwd_config_setup();
3064                 }
3065         }
3066 }
3067
3068 cmdline_parse_token_string_t cmd_set_list_keyword =
3069         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3070                                  "set");
3071 cmdline_parse_token_string_t cmd_set_list_name =
3072         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3073                                  "corelist#portlist");
3074 cmdline_parse_token_string_t cmd_set_list_of_items =
3075         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3076                                  NULL);
3077
3078 cmdline_parse_inst_t cmd_set_fwd_list = {
3079         .f = cmd_set_list_parsed,
3080         .data = NULL,
3081         .help_str = "set corelist|portlist <list0[,list1]*>",
3082         .tokens = {
3083                 (void *)&cmd_set_list_keyword,
3084                 (void *)&cmd_set_list_name,
3085                 (void *)&cmd_set_list_of_items,
3086                 NULL,
3087         },
3088 };
3089
3090 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3091
3092 struct cmd_setmask_result {
3093         cmdline_fixed_string_t set;
3094         cmdline_fixed_string_t mask;
3095         uint64_t hexavalue;
3096 };
3097
3098 static void cmd_set_mask_parsed(void *parsed_result,
3099                                 __attribute__((unused)) struct cmdline *cl,
3100                                 __attribute__((unused)) void *data)
3101 {
3102         struct cmd_setmask_result *res = parsed_result;
3103
3104         if (test_done == 0) {
3105                 printf("Please stop forwarding first\n");
3106                 return;
3107         }
3108         if (!strcmp(res->mask, "coremask")) {
3109                 set_fwd_lcores_mask(res->hexavalue);
3110                 fwd_config_setup();
3111         } else if (!strcmp(res->mask, "portmask")) {
3112                 set_fwd_ports_mask(res->hexavalue);
3113                 fwd_config_setup();
3114         }
3115 }
3116
3117 cmdline_parse_token_string_t cmd_setmask_set =
3118         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3119 cmdline_parse_token_string_t cmd_setmask_mask =
3120         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3121                                  "coremask#portmask");
3122 cmdline_parse_token_num_t cmd_setmask_value =
3123         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3124
3125 cmdline_parse_inst_t cmd_set_fwd_mask = {
3126         .f = cmd_set_mask_parsed,
3127         .data = NULL,
3128         .help_str = "set coremask|portmask <hexadecimal value>",
3129         .tokens = {
3130                 (void *)&cmd_setmask_set,
3131                 (void *)&cmd_setmask_mask,
3132                 (void *)&cmd_setmask_value,
3133                 NULL,
3134         },
3135 };
3136
3137 /*
3138  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3139  */
3140 struct cmd_set_result {
3141         cmdline_fixed_string_t set;
3142         cmdline_fixed_string_t what;
3143         uint16_t value;
3144 };
3145
3146 static void cmd_set_parsed(void *parsed_result,
3147                            __attribute__((unused)) struct cmdline *cl,
3148                            __attribute__((unused)) void *data)
3149 {
3150         struct cmd_set_result *res = parsed_result;
3151         if (!strcmp(res->what, "nbport")) {
3152                 set_fwd_ports_number(res->value);
3153                 fwd_config_setup();
3154         } else if (!strcmp(res->what, "nbcore")) {
3155                 set_fwd_lcores_number(res->value);
3156                 fwd_config_setup();
3157         } else if (!strcmp(res->what, "burst"))
3158                 set_nb_pkt_per_burst(res->value);
3159         else if (!strcmp(res->what, "verbose"))
3160                 set_verbose_level(res->value);
3161 }
3162
3163 cmdline_parse_token_string_t cmd_set_set =
3164         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3165 cmdline_parse_token_string_t cmd_set_what =
3166         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3167                                  "nbport#nbcore#burst#verbose");
3168 cmdline_parse_token_num_t cmd_set_value =
3169         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3170
3171 cmdline_parse_inst_t cmd_set_numbers = {
3172         .f = cmd_set_parsed,
3173         .data = NULL,
3174         .help_str = "set nbport|nbcore|burst|verbose <value>",
3175         .tokens = {
3176                 (void *)&cmd_set_set,
3177                 (void *)&cmd_set_what,
3178                 (void *)&cmd_set_value,
3179                 NULL,
3180         },
3181 };
3182
3183 /* *** SET LOG LEVEL CONFIGURATION *** */
3184
3185 struct cmd_set_log_result {
3186         cmdline_fixed_string_t set;
3187         cmdline_fixed_string_t log;
3188         cmdline_fixed_string_t type;
3189         uint32_t level;
3190 };
3191
3192 static void
3193 cmd_set_log_parsed(void *parsed_result,
3194                    __attribute__((unused)) struct cmdline *cl,
3195                    __attribute__((unused)) void *data)
3196 {
3197         struct cmd_set_log_result *res;
3198         int ret;
3199
3200         res = parsed_result;
3201         if (!strcmp(res->type, "global"))
3202                 rte_log_set_global_level(res->level);
3203         else {
3204                 ret = rte_log_set_level_regexp(res->type, res->level);
3205                 if (ret < 0)
3206                         printf("Unable to set log level\n");
3207         }
3208 }
3209
3210 cmdline_parse_token_string_t cmd_set_log_set =
3211         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3212 cmdline_parse_token_string_t cmd_set_log_log =
3213         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3214 cmdline_parse_token_string_t cmd_set_log_type =
3215         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3216 cmdline_parse_token_num_t cmd_set_log_level =
3217         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3218
3219 cmdline_parse_inst_t cmd_set_log = {
3220         .f = cmd_set_log_parsed,
3221         .data = NULL,
3222         .help_str = "set log global|<type> <level>",
3223         .tokens = {
3224                 (void *)&cmd_set_log_set,
3225                 (void *)&cmd_set_log_log,
3226                 (void *)&cmd_set_log_type,
3227                 (void *)&cmd_set_log_level,
3228                 NULL,
3229         },
3230 };
3231
3232 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3233
3234 struct cmd_set_txpkts_result {
3235         cmdline_fixed_string_t cmd_keyword;
3236         cmdline_fixed_string_t txpkts;
3237         cmdline_fixed_string_t seg_lengths;
3238 };
3239
3240 static void
3241 cmd_set_txpkts_parsed(void *parsed_result,
3242                       __attribute__((unused)) struct cmdline *cl,
3243                       __attribute__((unused)) void *data)
3244 {
3245         struct cmd_set_txpkts_result *res;
3246         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3247         unsigned int nb_segs;
3248
3249         res = parsed_result;
3250         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3251                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3252         if (nb_segs > 0)
3253                 set_tx_pkt_segments(seg_lengths, nb_segs);
3254 }
3255
3256 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3257         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3258                                  cmd_keyword, "set");
3259 cmdline_parse_token_string_t cmd_set_txpkts_name =
3260         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3261                                  txpkts, "txpkts");
3262 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3263         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3264                                  seg_lengths, NULL);
3265
3266 cmdline_parse_inst_t cmd_set_txpkts = {
3267         .f = cmd_set_txpkts_parsed,
3268         .data = NULL,
3269         .help_str = "set txpkts <len0[,len1]*>",
3270         .tokens = {
3271                 (void *)&cmd_set_txpkts_keyword,
3272                 (void *)&cmd_set_txpkts_name,
3273                 (void *)&cmd_set_txpkts_lengths,
3274                 NULL,
3275         },
3276 };
3277
3278 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3279
3280 struct cmd_set_txsplit_result {
3281         cmdline_fixed_string_t cmd_keyword;
3282         cmdline_fixed_string_t txsplit;
3283         cmdline_fixed_string_t mode;
3284 };
3285
3286 static void
3287 cmd_set_txsplit_parsed(void *parsed_result,
3288                       __attribute__((unused)) struct cmdline *cl,
3289                       __attribute__((unused)) void *data)
3290 {
3291         struct cmd_set_txsplit_result *res;
3292
3293         res = parsed_result;
3294         set_tx_pkt_split(res->mode);
3295 }
3296
3297 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3298         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3299                                  cmd_keyword, "set");
3300 cmdline_parse_token_string_t cmd_set_txsplit_name =
3301         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3302                                  txsplit, "txsplit");
3303 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3304         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3305                                  mode, NULL);
3306
3307 cmdline_parse_inst_t cmd_set_txsplit = {
3308         .f = cmd_set_txsplit_parsed,
3309         .data = NULL,
3310         .help_str = "set txsplit on|off|rand",
3311         .tokens = {
3312                 (void *)&cmd_set_txsplit_keyword,
3313                 (void *)&cmd_set_txsplit_name,
3314                 (void *)&cmd_set_txsplit_mode,
3315                 NULL,
3316         },
3317 };
3318
3319 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3320 struct cmd_rx_vlan_filter_all_result {
3321         cmdline_fixed_string_t rx_vlan;
3322         cmdline_fixed_string_t what;
3323         cmdline_fixed_string_t all;
3324         portid_t port_id;
3325 };
3326
3327 static void
3328 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3329                               __attribute__((unused)) struct cmdline *cl,
3330                               __attribute__((unused)) void *data)
3331 {
3332         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3333
3334         if (!strcmp(res->what, "add"))
3335                 rx_vlan_all_filter_set(res->port_id, 1);
3336         else
3337                 rx_vlan_all_filter_set(res->port_id, 0);
3338 }
3339
3340 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3341         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3342                                  rx_vlan, "rx_vlan");
3343 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3344         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3345                                  what, "add#rm");
3346 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3347         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3348                                  all, "all");
3349 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3350         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3351                               port_id, UINT16);
3352
3353 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3354         .f = cmd_rx_vlan_filter_all_parsed,
3355         .data = NULL,
3356         .help_str = "rx_vlan add|rm all <port_id>: "
3357                 "Add/Remove all identifiers to/from the set of VLAN "
3358                 "identifiers filtered by a port",
3359         .tokens = {
3360                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3361                 (void *)&cmd_rx_vlan_filter_all_what,
3362                 (void *)&cmd_rx_vlan_filter_all_all,
3363                 (void *)&cmd_rx_vlan_filter_all_portid,
3364                 NULL,
3365         },
3366 };
3367
3368 /* *** VLAN OFFLOAD SET ON A PORT *** */
3369 struct cmd_vlan_offload_result {
3370         cmdline_fixed_string_t vlan;
3371         cmdline_fixed_string_t set;
3372         cmdline_fixed_string_t vlan_type;
3373         cmdline_fixed_string_t what;
3374         cmdline_fixed_string_t on;
3375         cmdline_fixed_string_t port_id;
3376 };
3377
3378 static void
3379 cmd_vlan_offload_parsed(void *parsed_result,
3380                           __attribute__((unused)) struct cmdline *cl,
3381                           __attribute__((unused)) void *data)
3382 {
3383         int on;
3384         struct cmd_vlan_offload_result *res = parsed_result;
3385         char *str;
3386         int i, len = 0;
3387         portid_t port_id = 0;
3388         unsigned int tmp;
3389
3390         str = res->port_id;
3391         len = strnlen(str, STR_TOKEN_SIZE);
3392         i = 0;
3393         /* Get port_id first */
3394         while(i < len){
3395                 if(str[i] == ',')
3396                         break;
3397
3398                 i++;
3399         }
3400         str[i]='\0';
3401         tmp = strtoul(str, NULL, 0);
3402         /* If port_id greater that what portid_t can represent, return */
3403         if(tmp >= RTE_MAX_ETHPORTS)
3404                 return;
3405         port_id = (portid_t)tmp;
3406
3407         if (!strcmp(res->on, "on"))
3408                 on = 1;
3409         else
3410                 on = 0;
3411
3412         if (!strcmp(res->what, "strip"))
3413                 rx_vlan_strip_set(port_id,  on);
3414         else if(!strcmp(res->what, "stripq")){
3415                 uint16_t queue_id = 0;
3416
3417                 /* No queue_id, return */
3418                 if(i + 1 >= len) {
3419                         printf("must specify (port,queue_id)\n");
3420                         return;
3421                 }
3422                 tmp = strtoul(str + i + 1, NULL, 0);
3423                 /* If queue_id greater that what 16-bits can represent, return */
3424                 if(tmp > 0xffff)
3425                         return;
3426
3427                 queue_id = (uint16_t)tmp;
3428                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3429         }
3430         else if (!strcmp(res->what, "filter"))
3431                 rx_vlan_filter_set(port_id, on);
3432         else
3433                 vlan_extend_set(port_id, on);
3434
3435         return;
3436 }
3437
3438 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3439         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3440                                  vlan, "vlan");
3441 cmdline_parse_token_string_t cmd_vlan_offload_set =
3442         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3443                                  set, "set");
3444 cmdline_parse_token_string_t cmd_vlan_offload_what =
3445         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3446                                  what, "strip#filter#qinq#stripq");
3447 cmdline_parse_token_string_t cmd_vlan_offload_on =
3448         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3449                               on, "on#off");
3450 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3451         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3452                               port_id, NULL);
3453
3454 cmdline_parse_inst_t cmd_vlan_offload = {
3455         .f = cmd_vlan_offload_parsed,
3456         .data = NULL,
3457         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3458                 "<port_id[,queue_id]>: "
3459                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3460         .tokens = {
3461                 (void *)&cmd_vlan_offload_vlan,
3462                 (void *)&cmd_vlan_offload_set,
3463                 (void *)&cmd_vlan_offload_what,
3464                 (void *)&cmd_vlan_offload_on,
3465                 (void *)&cmd_vlan_offload_portid,
3466                 NULL,
3467         },
3468 };
3469
3470 /* *** VLAN TPID SET ON A PORT *** */
3471 struct cmd_vlan_tpid_result {
3472         cmdline_fixed_string_t vlan;
3473         cmdline_fixed_string_t set;
3474         cmdline_fixed_string_t vlan_type;
3475         cmdline_fixed_string_t what;
3476         uint16_t tp_id;
3477         portid_t port_id;
3478 };
3479
3480 static void
3481 cmd_vlan_tpid_parsed(void *parsed_result,
3482                           __attribute__((unused)) struct cmdline *cl,
3483                           __attribute__((unused)) void *data)
3484 {
3485         struct cmd_vlan_tpid_result *res = parsed_result;
3486         enum rte_vlan_type vlan_type;
3487
3488         if (!strcmp(res->vlan_type, "inner"))
3489                 vlan_type = ETH_VLAN_TYPE_INNER;
3490         else if (!strcmp(res->vlan_type, "outer"))
3491                 vlan_type = ETH_VLAN_TYPE_OUTER;
3492         else {
3493                 printf("Unknown vlan type\n");
3494                 return;
3495         }
3496         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3497 }
3498
3499 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3500         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3501                                  vlan, "vlan");
3502 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3503         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3504                                  set, "set");
3505 cmdline_parse_token_string_t cmd_vlan_type =
3506         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3507                                  vlan_type, "inner#outer");
3508 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3509         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3510                                  what, "tpid");
3511 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3512         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3513                               tp_id, UINT16);
3514 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3515         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3516                               port_id, UINT16);
3517
3518 cmdline_parse_inst_t cmd_vlan_tpid = {
3519         .f = cmd_vlan_tpid_parsed,
3520         .data = NULL,
3521         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3522                 "Set the VLAN Ether type",
3523         .tokens = {
3524                 (void *)&cmd_vlan_tpid_vlan,
3525                 (void *)&cmd_vlan_tpid_set,
3526                 (void *)&cmd_vlan_type,
3527                 (void *)&cmd_vlan_tpid_what,
3528                 (void *)&cmd_vlan_tpid_tpid,
3529                 (void *)&cmd_vlan_tpid_portid,
3530                 NULL,
3531         },
3532 };
3533
3534 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3535 struct cmd_rx_vlan_filter_result {
3536         cmdline_fixed_string_t rx_vlan;
3537         cmdline_fixed_string_t what;
3538         uint16_t vlan_id;
3539         portid_t port_id;
3540 };
3541
3542 static void
3543 cmd_rx_vlan_filter_parsed(void *parsed_result,
3544                           __attribute__((unused)) struct cmdline *cl,
3545                           __attribute__((unused)) void *data)
3546 {
3547         struct cmd_rx_vlan_filter_result *res = parsed_result;
3548
3549         if (!strcmp(res->what, "add"))
3550                 rx_vft_set(res->port_id, res->vlan_id, 1);
3551         else
3552                 rx_vft_set(res->port_id, res->vlan_id, 0);
3553 }
3554
3555 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3556         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3557                                  rx_vlan, "rx_vlan");
3558 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3559         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3560                                  what, "add#rm");
3561 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3562         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3563                               vlan_id, UINT16);
3564 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3565         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3566                               port_id, UINT16);
3567
3568 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3569         .f = cmd_rx_vlan_filter_parsed,
3570         .data = NULL,
3571         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3572                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3573                 "identifiers filtered by a port",
3574         .tokens = {
3575                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3576                 (void *)&cmd_rx_vlan_filter_what,
3577                 (void *)&cmd_rx_vlan_filter_vlanid,
3578                 (void *)&cmd_rx_vlan_filter_portid,
3579                 NULL,
3580         },
3581 };
3582
3583 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3584 struct cmd_tx_vlan_set_result {
3585         cmdline_fixed_string_t tx_vlan;
3586         cmdline_fixed_string_t set;
3587         portid_t port_id;
3588         uint16_t vlan_id;
3589 };
3590
3591 static void
3592 cmd_tx_vlan_set_parsed(void *parsed_result,
3593                        __attribute__((unused)) struct cmdline *cl,
3594                        __attribute__((unused)) void *data)
3595 {
3596         struct cmd_tx_vlan_set_result *res = parsed_result;
3597
3598         if (!port_is_stopped(res->port_id)) {
3599                 printf("Please stop port %d first\n", res->port_id);
3600                 return;
3601         }
3602
3603         tx_vlan_set(res->port_id, res->vlan_id);
3604
3605         cmd_reconfig_device_queue(res->port_id, 1, 1);
3606 }
3607
3608 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3609         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3610                                  tx_vlan, "tx_vlan");
3611 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3612         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3613                                  set, "set");
3614 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3615         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3616                               port_id, UINT16);
3617 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3618         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3619                               vlan_id, UINT16);
3620
3621 cmdline_parse_inst_t cmd_tx_vlan_set = {
3622         .f = cmd_tx_vlan_set_parsed,
3623         .data = NULL,
3624         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3625                 "Enable hardware insertion of a single VLAN header "
3626                 "with a given TAG Identifier in packets sent on a port",
3627         .tokens = {
3628                 (void *)&cmd_tx_vlan_set_tx_vlan,
3629                 (void *)&cmd_tx_vlan_set_set,
3630                 (void *)&cmd_tx_vlan_set_portid,
3631                 (void *)&cmd_tx_vlan_set_vlanid,
3632                 NULL,
3633         },
3634 };
3635
3636 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3637 struct cmd_tx_vlan_set_qinq_result {
3638         cmdline_fixed_string_t tx_vlan;
3639         cmdline_fixed_string_t set;
3640         portid_t port_id;
3641         uint16_t vlan_id;
3642         uint16_t vlan_id_outer;
3643 };
3644
3645 static void
3646 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3647                             __attribute__((unused)) struct cmdline *cl,
3648                             __attribute__((unused)) void *data)
3649 {
3650         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3651
3652         if (!port_is_stopped(res->port_id)) {
3653                 printf("Please stop port %d first\n", res->port_id);
3654                 return;
3655         }
3656
3657         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3658
3659         cmd_reconfig_device_queue(res->port_id, 1, 1);
3660 }
3661
3662 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3663         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3664                 tx_vlan, "tx_vlan");
3665 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3666         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3667                 set, "set");
3668 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3669         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3670                 port_id, UINT16);
3671 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3672         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3673                 vlan_id, UINT16);
3674 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3675         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3676                 vlan_id_outer, UINT16);
3677
3678 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3679         .f = cmd_tx_vlan_set_qinq_parsed,
3680         .data = NULL,
3681         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3682                 "Enable hardware insertion of double VLAN header "
3683                 "with given TAG Identifiers in packets sent on a port",
3684         .tokens = {
3685                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3686                 (void *)&cmd_tx_vlan_set_qinq_set,
3687                 (void *)&cmd_tx_vlan_set_qinq_portid,
3688                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3689                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3690                 NULL,
3691         },
3692 };
3693
3694 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3695 struct cmd_tx_vlan_set_pvid_result {
3696         cmdline_fixed_string_t tx_vlan;
3697         cmdline_fixed_string_t set;
3698         cmdline_fixed_string_t pvid;
3699         portid_t port_id;
3700         uint16_t vlan_id;
3701         cmdline_fixed_string_t mode;
3702 };
3703
3704 static void
3705 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3706                             __attribute__((unused)) struct cmdline *cl,
3707                             __attribute__((unused)) void *data)
3708 {
3709         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3710
3711         if (strcmp(res->mode, "on") == 0)
3712                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3713         else
3714                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3715 }
3716
3717 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3718         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3719                                  tx_vlan, "tx_vlan");
3720 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3721         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3722                                  set, "set");
3723 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3724         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3725                                  pvid, "pvid");
3726 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3727         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3728                              port_id, UINT16);
3729 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3730         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3731                               vlan_id, UINT16);
3732 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3733         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3734                                  mode, "on#off");
3735
3736 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3737         .f = cmd_tx_vlan_set_pvid_parsed,
3738         .data = NULL,
3739         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3740         .tokens = {
3741                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3742                 (void *)&cmd_tx_vlan_set_pvid_set,
3743                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3744                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3745                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3746                 (void *)&cmd_tx_vlan_set_pvid_mode,
3747                 NULL,
3748         },
3749 };
3750
3751 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3752 struct cmd_tx_vlan_reset_result {
3753         cmdline_fixed_string_t tx_vlan;
3754         cmdline_fixed_string_t reset;
3755         portid_t port_id;
3756 };
3757
3758 static void
3759 cmd_tx_vlan_reset_parsed(void *parsed_result,
3760                          __attribute__((unused)) struct cmdline *cl,
3761                          __attribute__((unused)) void *data)
3762 {
3763         struct cmd_tx_vlan_reset_result *res = parsed_result;
3764
3765         if (!port_is_stopped(res->port_id)) {
3766                 printf("Please stop port %d first\n", res->port_id);
3767                 return;
3768         }
3769
3770         tx_vlan_reset(res->port_id);
3771
3772         cmd_reconfig_device_queue(res->port_id, 1, 1);
3773 }
3774
3775 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3776         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3777                                  tx_vlan, "tx_vlan");
3778 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3779         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3780                                  reset, "reset");
3781 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3782         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3783                               port_id, UINT16);
3784
3785 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3786         .f = cmd_tx_vlan_reset_parsed,
3787         .data = NULL,
3788         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3789                 "VLAN header in packets sent on a port",
3790         .tokens = {
3791                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3792                 (void *)&cmd_tx_vlan_reset_reset,
3793                 (void *)&cmd_tx_vlan_reset_portid,
3794                 NULL,
3795         },
3796 };
3797
3798
3799 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3800 struct cmd_csum_result {
3801         cmdline_fixed_string_t csum;
3802         cmdline_fixed_string_t mode;
3803         cmdline_fixed_string_t proto;
3804         cmdline_fixed_string_t hwsw;
3805         portid_t port_id;
3806 };
3807
3808 static void
3809 csum_show(int port_id)
3810 {
3811         struct rte_eth_dev_info dev_info;
3812         uint64_t tx_offloads;
3813
3814         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3815         printf("Parse tunnel is %s\n",
3816                 (ports[port_id].parse_tunnel) ? "on" : "off");
3817         printf("IP checksum offload is %s\n",
3818                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3819         printf("UDP checksum offload is %s\n",
3820                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3821         printf("TCP checksum offload is %s\n",
3822                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3823         printf("SCTP checksum offload is %s\n",
3824                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3825         printf("Outer-Ip checksum offload is %s\n",
3826                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3827
3828         /* display warnings if configuration is not supported by the NIC */
3829         rte_eth_dev_info_get(port_id, &dev_info);
3830         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3831                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3832                 printf("Warning: hardware IP checksum enabled but not "
3833                         "supported by port %d\n", port_id);
3834         }
3835         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3836                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3837                 printf("Warning: hardware UDP checksum enabled but not "
3838                         "supported by port %d\n", port_id);
3839         }
3840         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3841                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3842                 printf("Warning: hardware TCP checksum enabled but not "
3843                         "supported by port %d\n", port_id);
3844         }
3845         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3846                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3847                 printf("Warning: hardware SCTP checksum enabled but not "
3848                         "supported by port %d\n", port_id);
3849         }
3850         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3851                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3852                 printf("Warning: hardware outer IP checksum enabled but not "
3853                         "supported by port %d\n", port_id);
3854         }
3855 }
3856
3857 static void
3858 cmd_csum_parsed(void *parsed_result,
3859                        __attribute__((unused)) struct cmdline *cl,
3860                        __attribute__((unused)) void *data)
3861 {
3862         struct cmd_csum_result *res = parsed_result;
3863         int hw = 0;
3864         uint64_t csum_offloads = 0;
3865         struct rte_eth_dev_info dev_info;
3866
3867         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3868                 printf("invalid port %d\n", res->port_id);
3869                 return;
3870         }
3871         if (!port_is_stopped(res->port_id)) {
3872                 printf("Please stop port %d first\n", res->port_id);
3873                 return;
3874         }
3875
3876         rte_eth_dev_info_get(res->port_id, &dev_info);
3877         if (!strcmp(res->mode, "set")) {
3878
3879                 if (!strcmp(res->hwsw, "hw"))
3880                         hw = 1;
3881
3882                 if (!strcmp(res->proto, "ip")) {
3883                         if (hw == 0 || (dev_info.tx_offload_capa &
3884                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
3885                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3886                         } else {
3887                                 printf("IP checksum offload is not supported "
3888                                        "by port %u\n", res->port_id);
3889                         }
3890                 } else if (!strcmp(res->proto, "udp")) {
3891                         if (hw == 0 || (dev_info.tx_offload_capa &
3892                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
3893                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3894                         } else {
3895                                 printf("UDP checksum offload is not supported "
3896                                        "by port %u\n", res->port_id);
3897                         }
3898                 } else if (!strcmp(res->proto, "tcp")) {
3899                         if (hw == 0 || (dev_info.tx_offload_capa &
3900                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
3901                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3902                         } else {
3903                                 printf("TCP checksum offload is not supported "
3904                                        "by port %u\n", res->port_id);
3905                         }
3906                 } else if (!strcmp(res->proto, "sctp")) {
3907                         if (hw == 0 || (dev_info.tx_offload_capa &
3908                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
3909                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3910                         } else {
3911                                 printf("SCTP checksum offload is not supported "
3912                                        "by port %u\n", res->port_id);
3913                         }
3914                 } else if (!strcmp(res->proto, "outer-ip")) {
3915                         if (hw == 0 || (dev_info.tx_offload_capa &
3916                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
3917                                 csum_offloads |=
3918                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3919                         } else {
3920                                 printf("Outer IP checksum offload is not "
3921                                        "supported by port %u\n", res->port_id);
3922                         }
3923                 }
3924
3925                 if (hw) {
3926                         ports[res->port_id].dev_conf.txmode.offloads |=
3927                                                         csum_offloads;
3928                 } else {
3929                         ports[res->port_id].dev_conf.txmode.offloads &=
3930                                                         (~csum_offloads);
3931                 }
3932         }
3933         csum_show(res->port_id);
3934
3935         cmd_reconfig_device_queue(res->port_id, 1, 1);
3936 }
3937
3938 cmdline_parse_token_string_t cmd_csum_csum =
3939         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3940                                 csum, "csum");
3941 cmdline_parse_token_string_t cmd_csum_mode =
3942         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3943                                 mode, "set");
3944 cmdline_parse_token_string_t cmd_csum_proto =
3945         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3946                                 proto, "ip#tcp#udp#sctp#outer-ip");
3947 cmdline_parse_token_string_t cmd_csum_hwsw =
3948         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3949                                 hwsw, "hw#sw");
3950 cmdline_parse_token_num_t cmd_csum_portid =
3951         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3952                                 port_id, UINT16);
3953
3954 cmdline_parse_inst_t cmd_csum_set = {
3955         .f = cmd_csum_parsed,
3956         .data = NULL,
3957         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3958                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3959                 "using csum forward engine",
3960         .tokens = {
3961                 (void *)&cmd_csum_csum,
3962                 (void *)&cmd_csum_mode,
3963                 (void *)&cmd_csum_proto,
3964                 (void *)&cmd_csum_hwsw,
3965                 (void *)&cmd_csum_portid,
3966                 NULL,
3967         },
3968 };
3969
3970 cmdline_parse_token_string_t cmd_csum_mode_show =
3971         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3972                                 mode, "show");
3973
3974 cmdline_parse_inst_t cmd_csum_show = {
3975         .f = cmd_csum_parsed,
3976         .data = NULL,
3977         .help_str = "csum show <port_id>: Show checksum offload configuration",
3978         .tokens = {
3979                 (void *)&cmd_csum_csum,
3980                 (void *)&cmd_csum_mode_show,
3981                 (void *)&cmd_csum_portid,
3982                 NULL,
3983         },
3984 };
3985
3986 /* Enable/disable tunnel parsing */
3987 struct cmd_csum_tunnel_result {
3988         cmdline_fixed_string_t csum;
3989         cmdline_fixed_string_t parse;
3990         cmdline_fixed_string_t onoff;
3991         portid_t port_id;
3992 };
3993
3994 static void
3995 cmd_csum_tunnel_parsed(void *parsed_result,
3996                        __attribute__((unused)) struct cmdline *cl,
3997                        __attribute__((unused)) void *data)
3998 {
3999         struct cmd_csum_tunnel_result *res = parsed_result;
4000
4001         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4002                 return;
4003
4004         if (!strcmp(res->onoff, "on"))
4005                 ports[res->port_id].parse_tunnel = 1;
4006         else
4007                 ports[res->port_id].parse_tunnel = 0;
4008
4009         csum_show(res->port_id);
4010 }
4011
4012 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4013         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4014                                 csum, "csum");
4015 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4016         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4017                                 parse, "parse_tunnel");
4018 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4019         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4020                                 onoff, "on#off");
4021 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4022         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4023                                 port_id, UINT16);
4024
4025 cmdline_parse_inst_t cmd_csum_tunnel = {
4026         .f = cmd_csum_tunnel_parsed,
4027         .data = NULL,
4028         .help_str = "csum parse_tunnel on|off <port_id>: "
4029                 "Enable/Disable parsing of tunnels for csum engine",
4030         .tokens = {
4031                 (void *)&cmd_csum_tunnel_csum,
4032                 (void *)&cmd_csum_tunnel_parse,
4033                 (void *)&cmd_csum_tunnel_onoff,
4034                 (void *)&cmd_csum_tunnel_portid,
4035                 NULL,
4036         },
4037 };
4038
4039 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4040 struct cmd_tso_set_result {
4041         cmdline_fixed_string_t tso;
4042         cmdline_fixed_string_t mode;
4043         uint16_t tso_segsz;
4044         portid_t port_id;
4045 };
4046
4047 static void
4048 cmd_tso_set_parsed(void *parsed_result,
4049                        __attribute__((unused)) struct cmdline *cl,
4050                        __attribute__((unused)) void *data)
4051 {
4052         struct cmd_tso_set_result *res = parsed_result;
4053         struct rte_eth_dev_info dev_info;
4054
4055         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4056                 return;
4057         if (!port_is_stopped(res->port_id)) {
4058                 printf("Please stop port %d first\n", res->port_id);
4059                 return;
4060         }
4061
4062         if (!strcmp(res->mode, "set"))
4063                 ports[res->port_id].tso_segsz = res->tso_segsz;
4064
4065         rte_eth_dev_info_get(res->port_id, &dev_info);
4066         if ((ports[res->port_id].tso_segsz != 0) &&
4067                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4068                 printf("Error: TSO is not supported by port %d\n",
4069                        res->port_id);
4070                 return;
4071         }
4072
4073         if (ports[res->port_id].tso_segsz == 0) {
4074                 ports[res->port_id].dev_conf.txmode.offloads &=
4075                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4076                 printf("TSO for non-tunneled packets is disabled\n");
4077         } else {
4078                 ports[res->port_id].dev_conf.txmode.offloads |=
4079                                                 DEV_TX_OFFLOAD_TCP_TSO;
4080                 printf("TSO segment size for non-tunneled packets is %d\n",
4081                         ports[res->port_id].tso_segsz);
4082         }
4083
4084         /* display warnings if configuration is not supported by the NIC */
4085         rte_eth_dev_info_get(res->port_id, &dev_info);
4086         if ((ports[res->port_id].tso_segsz != 0) &&
4087                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4088                 printf("Warning: TSO enabled but not "
4089                         "supported by port %d\n", res->port_id);
4090         }
4091
4092         cmd_reconfig_device_queue(res->port_id, 1, 1);
4093 }
4094
4095 cmdline_parse_token_string_t cmd_tso_set_tso =
4096         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4097                                 tso, "tso");
4098 cmdline_parse_token_string_t cmd_tso_set_mode =
4099         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4100                                 mode, "set");
4101 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4102         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4103                                 tso_segsz, UINT16);
4104 cmdline_parse_token_num_t cmd_tso_set_portid =
4105         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4106                                 port_id, UINT16);
4107
4108 cmdline_parse_inst_t cmd_tso_set = {
4109         .f = cmd_tso_set_parsed,
4110         .data = NULL,
4111         .help_str = "tso set <tso_segsz> <port_id>: "
4112                 "Set TSO segment size of non-tunneled packets for csum engine "
4113                 "(0 to disable)",
4114         .tokens = {
4115                 (void *)&cmd_tso_set_tso,
4116                 (void *)&cmd_tso_set_mode,
4117                 (void *)&cmd_tso_set_tso_segsz,
4118                 (void *)&cmd_tso_set_portid,
4119                 NULL,
4120         },
4121 };
4122
4123 cmdline_parse_token_string_t cmd_tso_show_mode =
4124         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4125                                 mode, "show");
4126
4127
4128 cmdline_parse_inst_t cmd_tso_show = {
4129         .f = cmd_tso_set_parsed,
4130         .data = NULL,
4131         .help_str = "tso show <port_id>: "
4132                 "Show TSO segment size of non-tunneled packets for csum engine",
4133         .tokens = {
4134                 (void *)&cmd_tso_set_tso,
4135                 (void *)&cmd_tso_show_mode,
4136                 (void *)&cmd_tso_set_portid,
4137                 NULL,
4138         },
4139 };
4140
4141 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4142 struct cmd_tunnel_tso_set_result {
4143         cmdline_fixed_string_t tso;
4144         cmdline_fixed_string_t mode;
4145         uint16_t tso_segsz;
4146         portid_t port_id;
4147 };
4148
4149 static struct rte_eth_dev_info
4150 check_tunnel_tso_nic_support(portid_t port_id)
4151 {
4152         struct rte_eth_dev_info dev_info;
4153
4154         rte_eth_dev_info_get(port_id, &dev_info);
4155         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4156                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4157                        "not enabled for port %d\n", port_id);
4158         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4159                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4160                        "not enabled for port %d\n", port_id);
4161         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4162                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4163                        "not enabled for port %d\n", port_id);
4164         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4165                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4166                        "not enabled for port %d\n", port_id);
4167         return dev_info;
4168 }
4169
4170 static void
4171 cmd_tunnel_tso_set_parsed(void *parsed_result,
4172                           __attribute__((unused)) struct cmdline *cl,
4173                           __attribute__((unused)) void *data)
4174 {
4175         struct cmd_tunnel_tso_set_result *res = parsed_result;
4176         struct rte_eth_dev_info dev_info;
4177
4178         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4179                 return;
4180         if (!port_is_stopped(res->port_id)) {
4181                 printf("Please stop port %d first\n", res->port_id);
4182                 return;
4183         }
4184
4185         if (!strcmp(res->mode, "set"))
4186                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4187
4188         dev_info = check_tunnel_tso_nic_support(res->port_id);
4189         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4190                 ports[res->port_id].dev_conf.txmode.offloads &=
4191                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4192                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4193                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4194                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4195                 printf("TSO for tunneled packets is disabled\n");
4196         } else {
4197                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4198                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4199                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4200                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4201
4202                 ports[res->port_id].dev_conf.txmode.offloads |=
4203                         (tso_offloads & dev_info.tx_offload_capa);
4204                 printf("TSO segment size for tunneled packets is %d\n",
4205                         ports[res->port_id].tunnel_tso_segsz);
4206
4207                 /* Below conditions are needed to make it work:
4208                  * (1) tunnel TSO is supported by the NIC;
4209                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4210                  * are recognized;
4211                  * (3) for tunneled pkts with outer L3 of IPv4,
4212                  * "csum set outer-ip" must be set to hw, because after tso,
4213                  * total_len of outer IP header is changed, and the checksum
4214                  * of outer IP header calculated by sw should be wrong; that
4215                  * is not necessary for IPv6 tunneled pkts because there's no
4216                  * checksum in IP header anymore.
4217                  */
4218
4219                 if (!ports[res->port_id].parse_tunnel)
4220                         printf("Warning: csum parse_tunnel must be set "
4221                                 "so that tunneled packets are recognized\n");
4222                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4223                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4224                         printf("Warning: csum set outer-ip must be set to hw "
4225                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4226         }
4227
4228         cmd_reconfig_device_queue(res->port_id, 1, 1);
4229 }
4230
4231 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4232         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4233                                 tso, "tunnel_tso");
4234 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4235         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4236                                 mode, "set");
4237 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4238         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4239                                 tso_segsz, UINT16);
4240 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4241         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4242                                 port_id, UINT16);
4243
4244 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4245         .f = cmd_tunnel_tso_set_parsed,
4246         .data = NULL,
4247         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4248                 "Set TSO segment size of tunneled packets for csum engine "
4249                 "(0 to disable)",
4250         .tokens = {
4251                 (void *)&cmd_tunnel_tso_set_tso,
4252                 (void *)&cmd_tunnel_tso_set_mode,
4253                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4254                 (void *)&cmd_tunnel_tso_set_portid,
4255                 NULL,
4256         },
4257 };
4258
4259 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4260         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4261                                 mode, "show");
4262
4263
4264 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4265         .f = cmd_tunnel_tso_set_parsed,
4266         .data = NULL,
4267         .help_str = "tunnel_tso show <port_id> "
4268                 "Show TSO segment size of tunneled packets for csum engine",
4269         .tokens = {
4270                 (void *)&cmd_tunnel_tso_set_tso,
4271                 (void *)&cmd_tunnel_tso_show_mode,
4272                 (void *)&cmd_tunnel_tso_set_portid,
4273                 NULL,
4274         },
4275 };
4276
4277 /* *** SET GRO FOR A PORT *** */
4278 struct cmd_gro_enable_result {
4279         cmdline_fixed_string_t cmd_set;
4280         cmdline_fixed_string_t cmd_port;
4281         cmdline_fixed_string_t cmd_keyword;
4282         cmdline_fixed_string_t cmd_onoff;
4283         portid_t cmd_pid;
4284 };
4285
4286 static void
4287 cmd_gro_enable_parsed(void *parsed_result,
4288                 __attribute__((unused)) struct cmdline *cl,
4289                 __attribute__((unused)) void *data)
4290 {
4291         struct cmd_gro_enable_result *res;
4292
4293         res = parsed_result;
4294         if (!strcmp(res->cmd_keyword, "gro"))
4295                 setup_gro(res->cmd_onoff, res->cmd_pid);
4296 }
4297
4298 cmdline_parse_token_string_t cmd_gro_enable_set =
4299         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4300                         cmd_set, "set");
4301 cmdline_parse_token_string_t cmd_gro_enable_port =
4302         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4303                         cmd_keyword, "port");
4304 cmdline_parse_token_num_t cmd_gro_enable_pid =
4305         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4306                         cmd_pid, UINT16);
4307 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4308         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4309                         cmd_keyword, "gro");
4310 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4311         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4312                         cmd_onoff, "on#off");
4313
4314 cmdline_parse_inst_t cmd_gro_enable = {
4315         .f = cmd_gro_enable_parsed,
4316         .data = NULL,
4317         .help_str = "set port <port_id> gro on|off",
4318         .tokens = {
4319                 (void *)&cmd_gro_enable_set,
4320                 (void *)&cmd_gro_enable_port,
4321                 (void *)&cmd_gro_enable_pid,
4322                 (void *)&cmd_gro_enable_keyword,
4323                 (void *)&cmd_gro_enable_onoff,
4324                 NULL,
4325         },
4326 };
4327
4328 /* *** DISPLAY GRO CONFIGURATION *** */
4329 struct cmd_gro_show_result {
4330         cmdline_fixed_string_t cmd_show;
4331         cmdline_fixed_string_t cmd_port;
4332         cmdline_fixed_string_t cmd_keyword;
4333         portid_t cmd_pid;
4334 };
4335
4336 static void
4337 cmd_gro_show_parsed(void *parsed_result,
4338                 __attribute__((unused)) struct cmdline *cl,
4339                 __attribute__((unused)) void *data)
4340 {
4341         struct cmd_gro_show_result *res;
4342
4343         res = parsed_result;
4344         if (!strcmp(res->cmd_keyword, "gro"))
4345                 show_gro(res->cmd_pid);
4346 }
4347
4348 cmdline_parse_token_string_t cmd_gro_show_show =
4349         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4350                         cmd_show, "show");
4351 cmdline_parse_token_string_t cmd_gro_show_port =
4352         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4353                         cmd_port, "port");
4354 cmdline_parse_token_num_t cmd_gro_show_pid =
4355         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4356                         cmd_pid, UINT16);
4357 cmdline_parse_token_string_t cmd_gro_show_keyword =
4358         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4359                         cmd_keyword, "gro");
4360
4361 cmdline_parse_inst_t cmd_gro_show = {
4362         .f = cmd_gro_show_parsed,
4363         .data = NULL,
4364         .help_str = "show port <port_id> gro",
4365         .tokens = {
4366                 (void *)&cmd_gro_show_show,
4367                 (void *)&cmd_gro_show_port,
4368                 (void *)&cmd_gro_show_pid,
4369                 (void *)&cmd_gro_show_keyword,
4370                 NULL,
4371         },
4372 };
4373
4374 /* *** SET FLUSH CYCLES FOR GRO *** */
4375 struct cmd_gro_flush_result {
4376         cmdline_fixed_string_t cmd_set;
4377         cmdline_fixed_string_t cmd_keyword;
4378         cmdline_fixed_string_t cmd_flush;
4379         uint8_t cmd_cycles;
4380 };
4381
4382 static void
4383 cmd_gro_flush_parsed(void *parsed_result,
4384                 __attribute__((unused)) struct cmdline *cl,
4385                 __attribute__((unused)) void *data)
4386 {
4387         struct cmd_gro_flush_result *res;
4388
4389         res = parsed_result;
4390         if ((!strcmp(res->cmd_keyword, "gro")) &&
4391                         (!strcmp(res->cmd_flush, "flush")))
4392                 setup_gro_flush_cycles(res->cmd_cycles);
4393 }
4394
4395 cmdline_parse_token_string_t cmd_gro_flush_set =
4396         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4397                         cmd_set, "set");
4398 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4399         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4400                         cmd_keyword, "gro");
4401 cmdline_parse_token_string_t cmd_gro_flush_flush =
4402         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4403                         cmd_flush, "flush");
4404 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4405         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4406                         cmd_cycles, UINT8);
4407
4408 cmdline_parse_inst_t cmd_gro_flush = {
4409         .f = cmd_gro_flush_parsed,
4410         .data = NULL,
4411         .help_str = "set gro flush <cycles>",
4412         .tokens = {
4413                 (void *)&cmd_gro_flush_set,
4414                 (void *)&cmd_gro_flush_keyword,
4415                 (void *)&cmd_gro_flush_flush,
4416                 (void *)&cmd_gro_flush_cycles,
4417                 NULL,
4418         },
4419 };
4420
4421 /* *** ENABLE/DISABLE GSO *** */
4422 struct cmd_gso_enable_result {
4423         cmdline_fixed_string_t cmd_set;
4424         cmdline_fixed_string_t cmd_port;
4425         cmdline_fixed_string_t cmd_keyword;
4426         cmdline_fixed_string_t cmd_mode;
4427         portid_t cmd_pid;
4428 };
4429
4430 static void
4431 cmd_gso_enable_parsed(void *parsed_result,
4432                 __attribute__((unused)) struct cmdline *cl,
4433                 __attribute__((unused)) void *data)
4434 {
4435         struct cmd_gso_enable_result *res;
4436
4437         res = parsed_result;
4438         if (!strcmp(res->cmd_keyword, "gso"))
4439                 setup_gso(res->cmd_mode, res->cmd_pid);
4440 }
4441
4442 cmdline_parse_token_string_t cmd_gso_enable_set =
4443         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4444                         cmd_set, "set");
4445 cmdline_parse_token_string_t cmd_gso_enable_port =
4446         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4447                         cmd_port, "port");
4448 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4449         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4450                         cmd_keyword, "gso");
4451 cmdline_parse_token_string_t cmd_gso_enable_mode =
4452         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4453                         cmd_mode, "on#off");
4454 cmdline_parse_token_num_t cmd_gso_enable_pid =
4455         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4456                         cmd_pid, UINT16);
4457
4458 cmdline_parse_inst_t cmd_gso_enable = {
4459         .f = cmd_gso_enable_parsed,
4460         .data = NULL,
4461         .help_str = "set port <port_id> gso on|off",
4462         .tokens = {
4463                 (void *)&cmd_gso_enable_set,
4464                 (void *)&cmd_gso_enable_port,
4465                 (void *)&cmd_gso_enable_pid,
4466                 (void *)&cmd_gso_enable_keyword,
4467                 (void *)&cmd_gso_enable_mode,
4468                 NULL,
4469         },
4470 };
4471
4472 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4473 struct cmd_gso_size_result {
4474         cmdline_fixed_string_t cmd_set;
4475         cmdline_fixed_string_t cmd_keyword;
4476         cmdline_fixed_string_t cmd_segsz;
4477         uint16_t cmd_size;
4478 };
4479
4480 static void
4481 cmd_gso_size_parsed(void *parsed_result,
4482                        __attribute__((unused)) struct cmdline *cl,
4483                        __attribute__((unused)) void *data)
4484 {
4485         struct cmd_gso_size_result *res = parsed_result;
4486
4487         if (test_done == 0) {
4488                 printf("Before setting GSO segsz, please first"
4489                                 " stop fowarding\n");
4490                 return;
4491         }
4492
4493         if (!strcmp(res->cmd_keyword, "gso") &&
4494                         !strcmp(res->cmd_segsz, "segsz")) {
4495                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4496                         printf("gso_size should be larger than %zu."
4497                                         " Please input a legal value\n",
4498                                         RTE_GSO_SEG_SIZE_MIN);
4499                 else
4500                         gso_max_segment_size = res->cmd_size;
4501         }
4502 }
4503
4504 cmdline_parse_token_string_t cmd_gso_size_set =
4505         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4506                                 cmd_set, "set");
4507 cmdline_parse_token_string_t cmd_gso_size_keyword =
4508         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4509                                 cmd_keyword, "gso");
4510 cmdline_parse_token_string_t cmd_gso_size_segsz =
4511         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4512                                 cmd_segsz, "segsz");
4513 cmdline_parse_token_num_t cmd_gso_size_size =
4514         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4515                                 cmd_size, UINT16);
4516
4517 cmdline_parse_inst_t cmd_gso_size = {
4518         .f = cmd_gso_size_parsed,
4519         .data = NULL,
4520         .help_str = "set gso segsz <length>",
4521         .tokens = {
4522                 (void *)&cmd_gso_size_set,
4523                 (void *)&cmd_gso_size_keyword,
4524                 (void *)&cmd_gso_size_segsz,
4525                 (void *)&cmd_gso_size_size,
4526                 NULL,
4527         },
4528 };
4529
4530 /* *** SHOW GSO CONFIGURATION *** */
4531 struct cmd_gso_show_result {
4532         cmdline_fixed_string_t cmd_show;
4533         cmdline_fixed_string_t cmd_port;
4534         cmdline_fixed_string_t cmd_keyword;
4535         portid_t cmd_pid;
4536 };
4537
4538 static void
4539 cmd_gso_show_parsed(void *parsed_result,
4540                        __attribute__((unused)) struct cmdline *cl,
4541                        __attribute__((unused)) void *data)
4542 {
4543         struct cmd_gso_show_result *res = parsed_result;
4544
4545         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4546                 printf("invalid port id %u\n", res->cmd_pid);
4547                 return;
4548         }
4549         if (!strcmp(res->cmd_keyword, "gso")) {
4550                 if (gso_ports[res->cmd_pid].enable) {
4551                         printf("Max GSO'd packet size: %uB\n"
4552                                         "Supported GSO types: TCP/IPv4, "
4553                                         "VxLAN with inner TCP/IPv4 packet, "
4554                                         "GRE with inner TCP/IPv4  packet\n",
4555                                         gso_max_segment_size);
4556                 } else
4557                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4558         }
4559 }
4560
4561 cmdline_parse_token_string_t cmd_gso_show_show =
4562 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4563                 cmd_show, "show");
4564 cmdline_parse_token_string_t cmd_gso_show_port =
4565 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4566                 cmd_port, "port");
4567 cmdline_parse_token_string_t cmd_gso_show_keyword =
4568         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4569                                 cmd_keyword, "gso");
4570 cmdline_parse_token_num_t cmd_gso_show_pid =
4571         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4572                                 cmd_pid, UINT16);
4573
4574 cmdline_parse_inst_t cmd_gso_show = {
4575         .f = cmd_gso_show_parsed,
4576         .data = NULL,
4577         .help_str = "show port <port_id> gso",
4578         .tokens = {
4579                 (void *)&cmd_gso_show_show,
4580                 (void *)&cmd_gso_show_port,
4581                 (void *)&cmd_gso_show_pid,
4582                 (void *)&cmd_gso_show_keyword,
4583                 NULL,
4584         },
4585 };
4586
4587 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4588 struct cmd_set_flush_rx {
4589         cmdline_fixed_string_t set;
4590         cmdline_fixed_string_t flush_rx;
4591         cmdline_fixed_string_t mode;
4592 };
4593
4594 static void
4595 cmd_set_flush_rx_parsed(void *parsed_result,
4596                 __attribute__((unused)) struct cmdline *cl,
4597                 __attribute__((unused)) void *data)
4598 {
4599         struct cmd_set_flush_rx *res = parsed_result;
4600         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4601 }
4602
4603 cmdline_parse_token_string_t cmd_setflushrx_set =
4604         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4605                         set, "set");
4606 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4607         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4608                         flush_rx, "flush_rx");
4609 cmdline_parse_token_string_t cmd_setflushrx_mode =
4610         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4611                         mode, "on#off");
4612
4613
4614 cmdline_parse_inst_t cmd_set_flush_rx = {
4615         .f = cmd_set_flush_rx_parsed,
4616         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4617         .data = NULL,
4618         .tokens = {
4619                 (void *)&cmd_setflushrx_set,
4620                 (void *)&cmd_setflushrx_flush_rx,
4621                 (void *)&cmd_setflushrx_mode,
4622                 NULL,
4623         },
4624 };
4625
4626 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4627 struct cmd_set_link_check {
4628         cmdline_fixed_string_t set;
4629         cmdline_fixed_string_t link_check;
4630         cmdline_fixed_string_t mode;
4631 };
4632
4633 static void
4634 cmd_set_link_check_parsed(void *parsed_result,
4635                 __attribute__((unused)) struct cmdline *cl,
4636                 __attribute__((unused)) void *data)
4637 {
4638         struct cmd_set_link_check *res = parsed_result;
4639         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4640 }
4641
4642 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4643         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4644                         set, "set");
4645 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4646         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4647                         link_check, "link_check");
4648 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4649         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4650                         mode, "on#off");
4651
4652
4653 cmdline_parse_inst_t cmd_set_link_check = {
4654         .f = cmd_set_link_check_parsed,
4655         .help_str = "set link_check on|off: Enable/Disable link status check "
4656                     "when starting/stopping a port",
4657         .data = NULL,
4658         .tokens = {
4659                 (void *)&cmd_setlinkcheck_set,
4660                 (void *)&cmd_setlinkcheck_link_check,
4661                 (void *)&cmd_setlinkcheck_mode,
4662                 NULL,
4663         },
4664 };
4665
4666 /* *** SET NIC BYPASS MODE *** */
4667 struct cmd_set_bypass_mode_result {
4668         cmdline_fixed_string_t set;
4669         cmdline_fixed_string_t bypass;
4670         cmdline_fixed_string_t mode;
4671         cmdline_fixed_string_t value;
4672         portid_t port_id;
4673 };
4674
4675 static void
4676 cmd_set_bypass_mode_parsed(void *parsed_result,
4677                 __attribute__((unused)) struct cmdline *cl,
4678                 __attribute__((unused)) void *data)
4679 {
4680         struct cmd_set_bypass_mode_result *res = parsed_result;
4681         portid_t port_id = res->port_id;
4682         int32_t rc = -EINVAL;
4683
4684 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4685         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4686
4687         if (!strcmp(res->value, "bypass"))
4688                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4689         else if (!strcmp(res->value, "isolate"))
4690                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4691         else
4692                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4693
4694         /* Set the bypass mode for the relevant port. */
4695         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4696 #endif
4697         if (rc != 0)
4698                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4699 }
4700
4701 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4702         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4703                         set, "set");
4704 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4705         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4706                         bypass, "bypass");
4707 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4708         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4709                         mode, "mode");
4710 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4711         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4712                         value, "normal#bypass#isolate");
4713 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4714         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4715                                 port_id, UINT16);
4716
4717 cmdline_parse_inst_t cmd_set_bypass_mode = {
4718         .f = cmd_set_bypass_mode_parsed,
4719         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4720                     "Set the NIC bypass mode for port_id",
4721         .data = NULL,
4722         .tokens = {
4723                 (void *)&cmd_setbypass_mode_set,
4724                 (void *)&cmd_setbypass_mode_bypass,
4725                 (void *)&cmd_setbypass_mode_mode,
4726                 (void *)&cmd_setbypass_mode_value,
4727                 (void *)&cmd_setbypass_mode_port,
4728                 NULL,
4729         },
4730 };
4731
4732 /* *** SET NIC BYPASS EVENT *** */
4733 struct cmd_set_bypass_event_result {
4734         cmdline_fixed_string_t set;
4735         cmdline_fixed_string_t bypass;
4736         cmdline_fixed_string_t event;
4737         cmdline_fixed_string_t event_value;
4738         cmdline_fixed_string_t mode;
4739         cmdline_fixed_string_t mode_value;
4740         portid_t port_id;
4741 };
4742
4743 static void
4744 cmd_set_bypass_event_parsed(void *parsed_result,
4745                 __attribute__((unused)) struct cmdline *cl,
4746                 __attribute__((unused)) void *data)
4747 {
4748         int32_t rc = -EINVAL;
4749         struct cmd_set_bypass_event_result *res = parsed_result;
4750         portid_t port_id = res->port_id;
4751
4752 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4753         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4754         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4755
4756         if (!strcmp(res->event_value, "timeout"))
4757                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4758         else if (!strcmp(res->event_value, "os_on"))
4759                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4760         else if (!strcmp(res->event_value, "os_off"))
4761                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4762         else if (!strcmp(res->event_value, "power_on"))
4763                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4764         else if (!strcmp(res->event_value, "power_off"))
4765                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4766         else
4767                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4768
4769         if (!strcmp(res->mode_value, "bypass"))
4770                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4771         else if (!strcmp(res->mode_value, "isolate"))
4772                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4773         else
4774                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4775
4776         /* Set the watchdog timeout. */
4777         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4778
4779                 rc = -EINVAL;
4780                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4781                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4782                                                            bypass_timeout);
4783                 }
4784                 if (rc != 0) {
4785                         printf("Failed to set timeout value %u "
4786                         "for port %d, errto code: %d.\n",
4787                         bypass_timeout, port_id, rc);
4788                 }
4789         }
4790
4791         /* Set the bypass event to transition to bypass mode. */
4792         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4793                                               bypass_mode);
4794 #endif
4795
4796         if (rc != 0)
4797                 printf("\t Failed to set bypass event for port = %d.\n",
4798                        port_id);
4799 }
4800
4801 cmdline_parse_token_string_t cmd_setbypass_event_set =
4802         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4803                         set, "set");
4804 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4805         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4806                         bypass, "bypass");
4807 cmdline_parse_token_string_t cmd_setbypass_event_event =
4808         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4809                         event, "event");
4810 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4811         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4812                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4813 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4814         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4815                         mode, "mode");
4816 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4817         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4818                         mode_value, "normal#bypass#isolate");
4819 cmdline_parse_token_num_t cmd_setbypass_event_port =
4820         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4821                                 port_id, UINT16);
4822
4823 cmdline_parse_inst_t cmd_set_bypass_event = {
4824         .f = cmd_set_bypass_event_parsed,
4825         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4826                 "power_off mode normal|bypass|isolate <port_id>: "
4827                 "Set the NIC bypass event mode for port_id",
4828         .data = NULL,
4829         .tokens = {
4830                 (void *)&cmd_setbypass_event_set,
4831                 (void *)&cmd_setbypass_event_bypass,
4832                 (void *)&cmd_setbypass_event_event,
4833                 (void *)&cmd_setbypass_event_event_value,
4834                 (void *)&cmd_setbypass_event_mode,
4835                 (void *)&cmd_setbypass_event_mode_value,
4836                 (void *)&cmd_setbypass_event_port,
4837                 NULL,
4838         },
4839 };
4840
4841
4842 /* *** SET NIC BYPASS TIMEOUT *** */
4843 struct cmd_set_bypass_timeout_result {
4844         cmdline_fixed_string_t set;
4845         cmdline_fixed_string_t bypass;
4846         cmdline_fixed_string_t timeout;
4847         cmdline_fixed_string_t value;
4848 };
4849
4850 static void
4851 cmd_set_bypass_timeout_parsed(void *parsed_result,
4852                 __attribute__((unused)) struct cmdline *cl,
4853                 __attribute__((unused)) void *data)
4854 {
4855         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4856
4857 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4858         if (!strcmp(res->value, "1.5"))
4859                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4860         else if (!strcmp(res->value, "2"))
4861                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4862         else if (!strcmp(res->value, "3"))
4863                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4864         else if (!strcmp(res->value, "4"))
4865                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4866         else if (!strcmp(res->value, "8"))
4867                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4868         else if (!strcmp(res->value, "16"))
4869                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4870         else if (!strcmp(res->value, "32"))
4871                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4872         else
4873                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4874 #endif
4875 }
4876
4877 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4878         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4879                         set, "set");
4880 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4881         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4882                         bypass, "bypass");
4883 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4884         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4885                         timeout, "timeout");
4886 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4887         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4888                         value, "0#1.5#2#3#4#8#16#32");
4889
4890 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4891         .f = cmd_set_bypass_timeout_parsed,
4892         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4893                 "Set the NIC bypass watchdog timeout in seconds",
4894         .data = NULL,
4895         .tokens = {
4896                 (void *)&cmd_setbypass_timeout_set,
4897                 (void *)&cmd_setbypass_timeout_bypass,
4898                 (void *)&cmd_setbypass_timeout_timeout,
4899                 (void *)&cmd_setbypass_timeout_value,
4900                 NULL,
4901         },
4902 };
4903
4904 /* *** SHOW NIC BYPASS MODE *** */
4905 struct cmd_show_bypass_config_result {
4906         cmdline_fixed_string_t show;
4907         cmdline_fixed_string_t bypass;
4908         cmdline_fixed_string_t config;
4909         portid_t port_id;
4910 };
4911
4912 static void
4913 cmd_show_bypass_config_parsed(void *parsed_result,
4914                 __attribute__((unused)) struct cmdline *cl,
4915                 __attribute__((unused)) void *data)
4916 {
4917         struct cmd_show_bypass_config_result *res = parsed_result;
4918         portid_t port_id = res->port_id;
4919         int rc = -EINVAL;
4920 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4921         uint32_t event_mode;
4922         uint32_t bypass_mode;
4923         uint32_t timeout = bypass_timeout;
4924         int i;
4925
4926         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4927                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4928         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4929                 {"UNKNOWN", "normal", "bypass", "isolate"};
4930         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4931                 "NONE",
4932                 "OS/board on",
4933                 "power supply on",
4934                 "OS/board off",
4935                 "power supply off",
4936                 "timeout"};
4937         int num_events = (sizeof events) / (sizeof events[0]);
4938
4939         /* Display the bypass mode.*/
4940         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4941                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4942                 return;
4943         }
4944         else {
4945                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4946                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4947
4948                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4949         }
4950
4951         /* Display the bypass timeout.*/
4952         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4953                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4954
4955         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4956
4957         /* Display the bypass events and associated modes. */
4958         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4959
4960                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4961                         printf("\tFailed to get bypass mode for event = %s\n",
4962                                 events[i]);
4963                 } else {
4964                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4965                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4966
4967                         printf("\tbypass event: %-16s = %s\n", events[i],
4968                                 modes[event_mode]);
4969                 }
4970         }
4971 #endif
4972         if (rc != 0)
4973                 printf("\tFailed to get bypass configuration for port = %d\n",
4974                        port_id);
4975 }
4976
4977 cmdline_parse_token_string_t cmd_showbypass_config_show =
4978         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4979                         show, "show");
4980 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4981         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4982                         bypass, "bypass");
4983 cmdline_parse_token_string_t cmd_showbypass_config_config =
4984         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4985                         config, "config");
4986 cmdline_parse_token_num_t cmd_showbypass_config_port =
4987         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4988                                 port_id, UINT16);
4989
4990 cmdline_parse_inst_t cmd_show_bypass_config = {
4991         .f = cmd_show_bypass_config_parsed,
4992         .help_str = "show bypass config <port_id>: "
4993                     "Show the NIC bypass config for port_id",
4994         .data = NULL,
4995         .tokens = {
4996                 (void *)&cmd_showbypass_config_show,
4997                 (void *)&cmd_showbypass_config_bypass,
4998                 (void *)&cmd_showbypass_config_config,
4999                 (void *)&cmd_showbypass_config_port,
5000                 NULL,
5001         },
5002 };
5003
5004 #ifdef RTE_LIBRTE_PMD_BOND
5005 /* *** SET BONDING MODE *** */
5006 struct cmd_set_bonding_mode_result {
5007         cmdline_fixed_string_t set;
5008         cmdline_fixed_string_t bonding;
5009         cmdline_fixed_string_t mode;
5010         uint8_t value;
5011         portid_t port_id;
5012 };
5013
5014 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5015                 __attribute__((unused))  struct cmdline *cl,
5016                 __attribute__((unused)) void *data)
5017 {
5018         struct cmd_set_bonding_mode_result *res = parsed_result;
5019         portid_t port_id = res->port_id;
5020
5021         /* Set the bonding mode for the relevant port. */
5022         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5023                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5024 }
5025
5026 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5027 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5028                 set, "set");
5029 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5030 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5031                 bonding, "bonding");
5032 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5033 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5034                 mode, "mode");
5035 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5036 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5037                 value, UINT8);
5038 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5039 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5040                 port_id, UINT16);
5041
5042 cmdline_parse_inst_t cmd_set_bonding_mode = {
5043                 .f = cmd_set_bonding_mode_parsed,
5044                 .help_str = "set bonding mode <mode_value> <port_id>: "
5045                         "Set the bonding mode for port_id",
5046                 .data = NULL,
5047                 .tokens = {
5048                                 (void *) &cmd_setbonding_mode_set,
5049                                 (void *) &cmd_setbonding_mode_bonding,
5050                                 (void *) &cmd_setbonding_mode_mode,
5051                                 (void *) &cmd_setbonding_mode_value,
5052                                 (void *) &cmd_setbonding_mode_port,
5053                                 NULL
5054                 }
5055 };
5056
5057 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5058 struct cmd_set_bonding_lacp_dedicated_queues_result {
5059         cmdline_fixed_string_t set;
5060         cmdline_fixed_string_t bonding;
5061         cmdline_fixed_string_t lacp;
5062         cmdline_fixed_string_t dedicated_queues;
5063         portid_t port_id;
5064         cmdline_fixed_string_t mode;
5065 };
5066
5067 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5068                 __attribute__((unused))  struct cmdline *cl,
5069                 __attribute__((unused)) void *data)
5070 {
5071         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5072         portid_t port_id = res->port_id;
5073         struct rte_port *port;
5074
5075         port = &ports[port_id];
5076
5077         /** Check if the port is not started **/
5078         if (port->port_status != RTE_PORT_STOPPED) {
5079                 printf("Please stop port %d first\n", port_id);
5080                 return;
5081         }
5082
5083         if (!strcmp(res->mode, "enable")) {
5084                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5085                         printf("Dedicate queues for LACP control packets"
5086                                         " enabled\n");
5087                 else
5088                         printf("Enabling dedicate queues for LACP control "
5089                                         "packets on port %d failed\n", port_id);
5090         } else if (!strcmp(res->mode, "disable")) {
5091                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5092                         printf("Dedicated queues for LACP control packets "
5093                                         "disabled\n");
5094                 else
5095                         printf("Disabling dedicated queues for LACP control "
5096                                         "traffic on port %d failed\n", port_id);
5097         }
5098 }
5099
5100 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5101 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5102                 set, "set");
5103 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5104 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5105                 bonding, "bonding");
5106 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5107 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5108                 lacp, "lacp");
5109 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5110 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5111                 dedicated_queues, "dedicated_queues");
5112 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5113 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5114                 port_id, UINT16);
5115 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5116 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5117                 mode, "enable#disable");
5118
5119 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5120                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5121                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5122                         "enable|disable: "
5123                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5124                 .data = NULL,
5125                 .tokens = {
5126                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5127                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5128                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5129                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5130                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5131                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5132                         NULL
5133                 }
5134 };
5135
5136 /* *** SET BALANCE XMIT POLICY *** */
5137 struct cmd_set_bonding_balance_xmit_policy_result {
5138         cmdline_fixed_string_t set;
5139         cmdline_fixed_string_t bonding;
5140         cmdline_fixed_string_t balance_xmit_policy;
5141         portid_t port_id;
5142         cmdline_fixed_string_t policy;
5143 };
5144
5145 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5146                 __attribute__((unused))  struct cmdline *cl,
5147                 __attribute__((unused)) void *data)
5148 {
5149         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5150         portid_t port_id = res->port_id;
5151         uint8_t policy;
5152
5153         if (!strcmp(res->policy, "l2")) {
5154                 policy = BALANCE_XMIT_POLICY_LAYER2;
5155         } else if (!strcmp(res->policy, "l23")) {
5156                 policy = BALANCE_XMIT_POLICY_LAYER23;
5157         } else if (!strcmp(res->policy, "l34")) {
5158                 policy = BALANCE_XMIT_POLICY_LAYER34;
5159         } else {
5160                 printf("\t Invalid xmit policy selection");
5161                 return;
5162         }
5163
5164         /* Set the bonding mode for the relevant port. */
5165         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5166                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5167                                 port_id);
5168         }
5169 }
5170
5171 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5172 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5173                 set, "set");
5174 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5175 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5176                 bonding, "bonding");
5177 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5178 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5179                 balance_xmit_policy, "balance_xmit_policy");
5180 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5181 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5182                 port_id, UINT16);
5183 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5184 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5185                 policy, "l2#l23#l34");
5186
5187 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5188                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5189                 .help_str = "set bonding balance_xmit_policy <port_id> "
5190                         "l2|l23|l34: "
5191                         "Set the bonding balance_xmit_policy for port_id",
5192                 .data = NULL,
5193                 .tokens = {
5194                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5195                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5196                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5197                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5198                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5199                                 NULL
5200                 }
5201 };
5202
5203 /* *** SHOW NIC BONDING CONFIGURATION *** */
5204 struct cmd_show_bonding_config_result {
5205         cmdline_fixed_string_t show;
5206         cmdline_fixed_string_t bonding;
5207         cmdline_fixed_string_t config;
5208         portid_t port_id;
5209 };
5210
5211 static void cmd_show_bonding_config_parsed(void *parsed_result,
5212                 __attribute__((unused))  struct cmdline *cl,
5213                 __attribute__((unused)) void *data)
5214 {
5215         struct cmd_show_bonding_config_result *res = parsed_result;
5216         int bonding_mode, agg_mode;
5217         portid_t slaves[RTE_MAX_ETHPORTS];
5218         int num_slaves, num_active_slaves;
5219         int primary_id;
5220         int i;
5221         portid_t port_id = res->port_id;
5222
5223         /* Display the bonding mode.*/
5224         bonding_mode = rte_eth_bond_mode_get(port_id);
5225         if (bonding_mode < 0) {
5226                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5227                 return;
5228         } else
5229                 printf("\tBonding mode: %d\n", bonding_mode);
5230
5231         if (bonding_mode == BONDING_MODE_BALANCE) {
5232                 int balance_xmit_policy;
5233
5234                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5235                 if (balance_xmit_policy < 0) {
5236                         printf("\tFailed to get balance xmit policy for port = %d\n",
5237                                         port_id);
5238                         return;
5239                 } else {
5240                         printf("\tBalance Xmit Policy: ");
5241
5242                         switch (balance_xmit_policy) {
5243                         case BALANCE_XMIT_POLICY_LAYER2:
5244                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5245                                 break;
5246                         case BALANCE_XMIT_POLICY_LAYER23:
5247                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5248                                 break;
5249                         case BALANCE_XMIT_POLICY_LAYER34:
5250                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5251                                 break;
5252                         }
5253                         printf("\n");
5254                 }
5255         }
5256
5257         if (bonding_mode == BONDING_MODE_8023AD) {
5258                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5259                 printf("\tIEEE802.3AD Aggregator Mode: ");
5260                 switch (agg_mode) {
5261                 case AGG_BANDWIDTH:
5262                         printf("bandwidth");
5263                         break;
5264                 case AGG_STABLE:
5265                         printf("stable");
5266                         break;
5267                 case AGG_COUNT:
5268                         printf("count");
5269                         break;
5270                 }
5271                 printf("\n");
5272         }
5273
5274         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5275
5276         if (num_slaves < 0) {
5277                 printf("\tFailed to get slave list for port = %d\n", port_id);
5278                 return;
5279         }
5280         if (num_slaves > 0) {
5281                 printf("\tSlaves (%d): [", num_slaves);
5282                 for (i = 0; i < num_slaves - 1; i++)
5283                         printf("%d ", slaves[i]);
5284
5285                 printf("%d]\n", slaves[num_slaves - 1]);
5286         } else {
5287                 printf("\tSlaves: []\n");
5288
5289         }
5290
5291         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5292                         RTE_MAX_ETHPORTS);
5293
5294         if (num_active_slaves < 0) {
5295                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5296                 return;
5297         }
5298         if (num_active_slaves > 0) {
5299                 printf("\tActive Slaves (%d): [", num_active_slaves);
5300                 for (i = 0; i < num_active_slaves - 1; i++)
5301                         printf("%d ", slaves[i]);
5302
5303                 printf("%d]\n", slaves[num_active_slaves - 1]);
5304
5305         } else {
5306                 printf("\tActive Slaves: []\n");
5307
5308         }
5309
5310         primary_id = rte_eth_bond_primary_get(port_id);
5311         if (primary_id < 0) {
5312                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5313                 return;
5314         } else
5315                 printf("\tPrimary: [%d]\n", primary_id);
5316
5317 }
5318
5319 cmdline_parse_token_string_t cmd_showbonding_config_show =
5320 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5321                 show, "show");
5322 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5323 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5324                 bonding, "bonding");
5325 cmdline_parse_token_string_t cmd_showbonding_config_config =
5326 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5327                 config, "config");
5328 cmdline_parse_token_num_t cmd_showbonding_config_port =
5329 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5330                 port_id, UINT16);
5331
5332 cmdline_parse_inst_t cmd_show_bonding_config = {
5333                 .f = cmd_show_bonding_config_parsed,
5334                 .help_str = "show bonding config <port_id>: "
5335                         "Show the bonding config for port_id",
5336                 .data = NULL,
5337                 .tokens = {
5338                                 (void *)&cmd_showbonding_config_show,
5339                                 (void *)&cmd_showbonding_config_bonding,
5340                                 (void *)&cmd_showbonding_config_config,
5341                                 (void *)&cmd_showbonding_config_port,
5342                                 NULL
5343                 }
5344 };
5345
5346 /* *** SET BONDING PRIMARY *** */
5347 struct cmd_set_bonding_primary_result {
5348         cmdline_fixed_string_t set;
5349         cmdline_fixed_string_t bonding;
5350         cmdline_fixed_string_t primary;
5351         portid_t slave_id;
5352         portid_t port_id;
5353 };
5354
5355 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5356                 __attribute__((unused))  struct cmdline *cl,
5357                 __attribute__((unused)) void *data)
5358 {
5359         struct cmd_set_bonding_primary_result *res = parsed_result;
5360         portid_t master_port_id = res->port_id;
5361         portid_t slave_port_id = res->slave_id;
5362
5363         /* Set the primary slave for a bonded device. */
5364         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5365                 printf("\t Failed to set primary slave for port = %d.\n",
5366                                 master_port_id);
5367                 return;
5368         }
5369         init_port_config();
5370 }
5371
5372 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5373 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5374                 set, "set");
5375 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5376 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5377                 bonding, "bonding");
5378 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5379 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5380                 primary, "primary");
5381 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5382 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5383                 slave_id, UINT16);
5384 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5385 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5386                 port_id, UINT16);
5387
5388 cmdline_parse_inst_t cmd_set_bonding_primary = {
5389                 .f = cmd_set_bonding_primary_parsed,
5390                 .help_str = "set bonding primary <slave_id> <port_id>: "
5391                         "Set the primary slave for port_id",
5392                 .data = NULL,
5393                 .tokens = {
5394                                 (void *)&cmd_setbonding_primary_set,
5395                                 (void *)&cmd_setbonding_primary_bonding,
5396                                 (void *)&cmd_setbonding_primary_primary,
5397                                 (void *)&cmd_setbonding_primary_slave,
5398                                 (void *)&cmd_setbonding_primary_port,
5399                                 NULL
5400                 }
5401 };
5402
5403 /* *** ADD SLAVE *** */
5404 struct cmd_add_bonding_slave_result {
5405         cmdline_fixed_string_t add;
5406         cmdline_fixed_string_t bonding;
5407         cmdline_fixed_string_t slave;
5408         portid_t slave_id;
5409         portid_t port_id;
5410 };
5411
5412 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5413                 __attribute__((unused))  struct cmdline *cl,
5414                 __attribute__((unused)) void *data)
5415 {
5416         struct cmd_add_bonding_slave_result *res = parsed_result;
5417         portid_t master_port_id = res->port_id;
5418         portid_t slave_port_id = res->slave_id;
5419
5420         /* add the slave for a bonded device. */
5421         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5422                 printf("\t Failed to add slave %d to master port = %d.\n",
5423                                 slave_port_id, master_port_id);
5424                 return;
5425         }
5426         init_port_config();
5427         set_port_slave_flag(slave_port_id);
5428 }
5429
5430 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5431 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5432                 add, "add");
5433 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5434 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5435                 bonding, "bonding");
5436 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5437 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5438                 slave, "slave");
5439 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5440 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5441                 slave_id, UINT16);
5442 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5443 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5444                 port_id, UINT16);
5445
5446 cmdline_parse_inst_t cmd_add_bonding_slave = {
5447                 .f = cmd_add_bonding_slave_parsed,
5448                 .help_str = "add bonding slave <slave_id> <port_id>: "
5449                         "Add a slave device to a bonded device",
5450                 .data = NULL,
5451                 .tokens = {
5452                                 (void *)&cmd_addbonding_slave_add,
5453                                 (void *)&cmd_addbonding_slave_bonding,
5454                                 (void *)&cmd_addbonding_slave_slave,
5455                                 (void *)&cmd_addbonding_slave_slaveid,
5456                                 (void *)&cmd_addbonding_slave_port,
5457                                 NULL
5458                 }
5459 };
5460
5461 /* *** REMOVE SLAVE *** */
5462 struct cmd_remove_bonding_slave_result {
5463         cmdline_fixed_string_t remove;
5464         cmdline_fixed_string_t bonding;
5465         cmdline_fixed_string_t slave;
5466         portid_t slave_id;
5467         portid_t port_id;
5468 };
5469
5470 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5471                 __attribute__((unused))  struct cmdline *cl,
5472                 __attribute__((unused)) void *data)
5473 {
5474         struct cmd_remove_bonding_slave_result *res = parsed_result;
5475         portid_t master_port_id = res->port_id;
5476         portid_t slave_port_id = res->slave_id;
5477
5478         /* remove the slave from a bonded device. */
5479         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5480                 printf("\t Failed to remove slave %d from master port = %d.\n",
5481                                 slave_port_id, master_port_id);
5482                 return;
5483         }
5484         init_port_config();
5485         clear_port_slave_flag(slave_port_id);
5486 }
5487
5488 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5489                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5490                                 remove, "remove");
5491 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5492                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5493                                 bonding, "bonding");
5494 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5495                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5496                                 slave, "slave");
5497 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5498                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5499                                 slave_id, UINT16);
5500 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5501                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5502                                 port_id, UINT16);
5503
5504 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5505                 .f = cmd_remove_bonding_slave_parsed,
5506                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5507                         "Remove a slave device from a bonded device",
5508                 .data = NULL,
5509                 .tokens = {
5510                                 (void *)&cmd_removebonding_slave_remove,
5511                                 (void *)&cmd_removebonding_slave_bonding,
5512                                 (void *)&cmd_removebonding_slave_slave,
5513                                 (void *)&cmd_removebonding_slave_slaveid,
5514                                 (void *)&cmd_removebonding_slave_port,
5515                                 NULL
5516                 }
5517 };
5518
5519 /* *** CREATE BONDED DEVICE *** */
5520 struct cmd_create_bonded_device_result {
5521         cmdline_fixed_string_t create;
5522         cmdline_fixed_string_t bonded;
5523         cmdline_fixed_string_t device;
5524         uint8_t mode;
5525         uint8_t socket;
5526 };
5527
5528 static int bond_dev_num = 0;
5529
5530 static void cmd_create_bonded_device_parsed(void *parsed_result,
5531                 __attribute__((unused))  struct cmdline *cl,
5532                 __attribute__((unused)) void *data)
5533 {
5534         struct cmd_create_bonded_device_result *res = parsed_result;
5535         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5536         int port_id;
5537
5538         if (test_done == 0) {
5539                 printf("Please stop forwarding first\n");
5540                 return;
5541         }
5542
5543         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5544                         bond_dev_num++);
5545
5546         /* Create a new bonded device. */
5547         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5548         if (port_id < 0) {
5549                 printf("\t Failed to create bonded device.\n");
5550                 return;
5551         } else {
5552                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5553                                 port_id);
5554
5555                 /* Update number of ports */
5556                 nb_ports = rte_eth_dev_count_avail();
5557                 reconfig(port_id, res->socket);
5558                 rte_eth_promiscuous_enable(port_id);
5559         }
5560
5561 }
5562
5563 cmdline_parse_token_string_t cmd_createbonded_device_create =
5564                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5565                                 create, "create");
5566 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5567                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5568                                 bonded, "bonded");
5569 cmdline_parse_token_string_t cmd_createbonded_device_device =
5570                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5571                                 device, "device");
5572 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5573                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5574                                 mode, UINT8);
5575 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5576                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5577                                 socket, UINT8);
5578
5579 cmdline_parse_inst_t cmd_create_bonded_device = {
5580                 .f = cmd_create_bonded_device_parsed,
5581                 .help_str = "create bonded device <mode> <socket>: "
5582                         "Create a new bonded device with specific bonding mode and socket",
5583                 .data = NULL,
5584                 .tokens = {
5585                                 (void *)&cmd_createbonded_device_create,
5586                                 (void *)&cmd_createbonded_device_bonded,
5587                                 (void *)&cmd_createbonded_device_device,
5588                                 (void *)&cmd_createbonded_device_mode,
5589                                 (void *)&cmd_createbonded_device_socket,
5590                                 NULL
5591                 }
5592 };
5593
5594 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5595 struct cmd_set_bond_mac_addr_result {
5596         cmdline_fixed_string_t set;
5597         cmdline_fixed_string_t bonding;
5598         cmdline_fixed_string_t mac_addr;
5599         uint16_t port_num;
5600         struct ether_addr address;
5601 };
5602
5603 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5604                 __attribute__((unused))  struct cmdline *cl,
5605                 __attribute__((unused)) void *data)
5606 {
5607         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5608         int ret;
5609
5610         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5611                 return;
5612
5613         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5614
5615         /* check the return value and print it if is < 0 */
5616         if (ret < 0)
5617                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5618 }
5619
5620 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5621                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5622 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5623                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5624                                 "bonding");
5625 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5626                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5627                                 "mac_addr");
5628 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5629                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5630                                 port_num, UINT16);
5631 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5632                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5633
5634 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5635                 .f = cmd_set_bond_mac_addr_parsed,
5636                 .data = (void *) 0,
5637                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5638                 .tokens = {
5639                                 (void *)&cmd_set_bond_mac_addr_set,
5640                                 (void *)&cmd_set_bond_mac_addr_bonding,
5641                                 (void *)&cmd_set_bond_mac_addr_mac,
5642                                 (void *)&cmd_set_bond_mac_addr_portnum,
5643                                 (void *)&cmd_set_bond_mac_addr_addr,
5644                                 NULL
5645                 }
5646 };
5647
5648
5649 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5650 struct cmd_set_bond_mon_period_result {
5651         cmdline_fixed_string_t set;
5652         cmdline_fixed_string_t bonding;
5653         cmdline_fixed_string_t mon_period;
5654         uint16_t port_num;
5655         uint32_t period_ms;
5656 };
5657
5658 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5659                 __attribute__((unused))  struct cmdline *cl,
5660                 __attribute__((unused)) void *data)
5661 {
5662         struct cmd_set_bond_mon_period_result *res = parsed_result;
5663         int ret;
5664
5665         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5666
5667         /* check the return value and print it if is < 0 */
5668         if (ret < 0)
5669                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5670 }
5671
5672 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5673                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5674                                 set, "set");
5675 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5676                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5677                                 bonding, "bonding");
5678 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5679                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5680                                 mon_period,     "mon_period");
5681 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5682                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5683                                 port_num, UINT16);
5684 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5685                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5686                                 period_ms, UINT32);
5687
5688 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5689                 .f = cmd_set_bond_mon_period_parsed,
5690                 .data = (void *) 0,
5691                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5692                 .tokens = {
5693                                 (void *)&cmd_set_bond_mon_period_set,
5694                                 (void *)&cmd_set_bond_mon_period_bonding,
5695                                 (void *)&cmd_set_bond_mon_period_mon_period,
5696                                 (void *)&cmd_set_bond_mon_period_portnum,
5697                                 (void *)&cmd_set_bond_mon_period_period_ms,
5698                                 NULL
5699                 }
5700 };
5701
5702
5703
5704 struct cmd_set_bonding_agg_mode_policy_result {
5705         cmdline_fixed_string_t set;
5706         cmdline_fixed_string_t bonding;
5707         cmdline_fixed_string_t agg_mode;
5708         uint16_t port_num;
5709         cmdline_fixed_string_t policy;
5710 };
5711
5712
5713 static void
5714 cmd_set_bonding_agg_mode(void *parsed_result,
5715                 __attribute__((unused)) struct cmdline *cl,
5716                 __attribute__((unused)) void *data)
5717 {
5718         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5719         uint8_t policy = AGG_BANDWIDTH;
5720
5721         if (!strcmp(res->policy, "bandwidth"))
5722                 policy = AGG_BANDWIDTH;
5723         else if (!strcmp(res->policy, "stable"))
5724                 policy = AGG_STABLE;
5725         else if (!strcmp(res->policy, "count"))
5726                 policy = AGG_COUNT;
5727
5728         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5729 }
5730
5731
5732 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5733         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5734                                 set, "set");
5735 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5736         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5737                                 bonding, "bonding");
5738
5739 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5740         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5741                                 agg_mode, "agg_mode");
5742
5743 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5744         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5745                                 port_num, UINT16);
5746
5747 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5748         TOKEN_STRING_INITIALIZER(
5749                         struct cmd_set_bonding_balance_xmit_policy_result,
5750                 policy, "stable#bandwidth#count");
5751
5752 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5753         .f = cmd_set_bonding_agg_mode,
5754         .data = (void *) 0,
5755         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5756         .tokens = {
5757                         (void *)&cmd_set_bonding_agg_mode_set,
5758                         (void *)&cmd_set_bonding_agg_mode_bonding,
5759                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5760                         (void *)&cmd_set_bonding_agg_mode_portnum,
5761                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5762                         NULL
5763                 }
5764 };
5765
5766
5767 #endif /* RTE_LIBRTE_PMD_BOND */
5768
5769 /* *** SET FORWARDING MODE *** */
5770 struct cmd_set_fwd_mode_result {
5771         cmdline_fixed_string_t set;
5772         cmdline_fixed_string_t fwd;
5773         cmdline_fixed_string_t mode;
5774 };
5775
5776 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5777                                     __attribute__((unused)) struct cmdline *cl,
5778                                     __attribute__((unused)) void *data)
5779 {
5780         struct cmd_set_fwd_mode_result *res = parsed_result;
5781
5782         retry_enabled = 0;
5783         set_pkt_forwarding_mode(res->mode);
5784 }
5785
5786 cmdline_parse_token_string_t cmd_setfwd_set =
5787         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5788 cmdline_parse_token_string_t cmd_setfwd_fwd =
5789         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5790 cmdline_parse_token_string_t cmd_setfwd_mode =
5791         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5792                 "" /* defined at init */);
5793
5794 cmdline_parse_inst_t cmd_set_fwd_mode = {
5795         .f = cmd_set_fwd_mode_parsed,
5796         .data = NULL,
5797         .help_str = NULL, /* defined at init */
5798         .tokens = {
5799                 (void *)&cmd_setfwd_set,
5800                 (void *)&cmd_setfwd_fwd,
5801                 (void *)&cmd_setfwd_mode,
5802                 NULL,
5803         },
5804 };
5805
5806 static void cmd_set_fwd_mode_init(void)
5807 {
5808         char *modes, *c;
5809         static char token[128];
5810         static char help[256];
5811         cmdline_parse_token_string_t *token_struct;
5812
5813         modes = list_pkt_forwarding_modes();
5814         snprintf(help, sizeof(help), "set fwd %s: "
5815                 "Set packet forwarding mode", modes);
5816         cmd_set_fwd_mode.help_str = help;
5817
5818         /* string token separator is # */
5819         for (c = token; *modes != '\0'; modes++)
5820                 if (*modes == '|')
5821                         *c++ = '#';
5822                 else
5823                         *c++ = *modes;
5824         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5825         token_struct->string_data.str = token;
5826 }
5827
5828 /* *** SET RETRY FORWARDING MODE *** */
5829 struct cmd_set_fwd_retry_mode_result {
5830         cmdline_fixed_string_t set;
5831         cmdline_fixed_string_t fwd;
5832         cmdline_fixed_string_t mode;
5833         cmdline_fixed_string_t retry;
5834 };
5835
5836 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5837                             __attribute__((unused)) struct cmdline *cl,
5838                             __attribute__((unused)) void *data)
5839 {
5840         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5841
5842         retry_enabled = 1;
5843         set_pkt_forwarding_mode(res->mode);
5844 }
5845
5846 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5847         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5848                         set, "set");
5849 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5850         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5851                         fwd, "fwd");
5852 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5853         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5854                         mode,
5855                 "" /* defined at init */);
5856 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5857         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5858                         retry, "retry");
5859
5860 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5861         .f = cmd_set_fwd_retry_mode_parsed,
5862         .data = NULL,
5863         .help_str = NULL, /* defined at init */
5864         .tokens = {
5865                 (void *)&cmd_setfwd_retry_set,
5866                 (void *)&cmd_setfwd_retry_fwd,
5867                 (void *)&cmd_setfwd_retry_mode,
5868                 (void *)&cmd_setfwd_retry_retry,
5869                 NULL,
5870         },
5871 };
5872
5873 static void cmd_set_fwd_retry_mode_init(void)
5874 {
5875         char *modes, *c;
5876         static char token[128];
5877         static char help[256];
5878         cmdline_parse_token_string_t *token_struct;
5879
5880         modes = list_pkt_forwarding_retry_modes();
5881         snprintf(help, sizeof(help), "set fwd %s retry: "
5882                 "Set packet forwarding mode with retry", modes);
5883         cmd_set_fwd_retry_mode.help_str = help;
5884
5885         /* string token separator is # */
5886         for (c = token; *modes != '\0'; modes++)
5887                 if (*modes == '|')
5888                         *c++ = '#';
5889                 else
5890                         *c++ = *modes;
5891         token_struct = (cmdline_parse_token_string_t *)
5892                 cmd_set_fwd_retry_mode.tokens[2];
5893         token_struct->string_data.str = token;
5894 }
5895
5896 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5897 struct cmd_set_burst_tx_retry_result {
5898         cmdline_fixed_string_t set;
5899         cmdline_fixed_string_t burst;
5900         cmdline_fixed_string_t tx;
5901         cmdline_fixed_string_t delay;
5902         uint32_t time;
5903         cmdline_fixed_string_t retry;
5904         uint32_t retry_num;
5905 };
5906
5907 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5908                                         __attribute__((unused)) struct cmdline *cl,
5909                                         __attribute__((unused)) void *data)
5910 {
5911         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5912
5913         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5914                 && !strcmp(res->tx, "tx")) {
5915                 if (!strcmp(res->delay, "delay"))
5916                         burst_tx_delay_time = res->time;
5917                 if (!strcmp(res->retry, "retry"))
5918                         burst_tx_retry_num = res->retry_num;
5919         }
5920
5921 }
5922
5923 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5924         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5925 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5926         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5927                                  "burst");
5928 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5929         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5930 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5931         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5932 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5933         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5934 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5935         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5936 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5937         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5938
5939 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5940         .f = cmd_set_burst_tx_retry_parsed,
5941         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5942         .tokens = {
5943                 (void *)&cmd_set_burst_tx_retry_set,
5944                 (void *)&cmd_set_burst_tx_retry_burst,
5945                 (void *)&cmd_set_burst_tx_retry_tx,
5946                 (void *)&cmd_set_burst_tx_retry_delay,
5947                 (void *)&cmd_set_burst_tx_retry_time,
5948                 (void *)&cmd_set_burst_tx_retry_retry,
5949                 (void *)&cmd_set_burst_tx_retry_retry_num,
5950                 NULL,
5951         },
5952 };
5953
5954 /* *** SET PROMISC MODE *** */
5955 struct cmd_set_promisc_mode_result {
5956         cmdline_fixed_string_t set;
5957         cmdline_fixed_string_t promisc;
5958         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5959         uint16_t port_num;               /* valid if "allports" argument == 0 */
5960         cmdline_fixed_string_t mode;
5961 };
5962
5963 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5964                                         __attribute__((unused)) struct cmdline *cl,
5965                                         void *allports)
5966 {
5967         struct cmd_set_promisc_mode_result *res = parsed_result;
5968         int enable;
5969         portid_t i;
5970
5971         if (!strcmp(res->mode, "on"))
5972                 enable = 1;
5973         else
5974                 enable = 0;
5975
5976         /* all ports */
5977         if (allports) {
5978                 RTE_ETH_FOREACH_DEV(i) {
5979                         if (enable)
5980                                 rte_eth_promiscuous_enable(i);
5981                         else
5982                                 rte_eth_promiscuous_disable(i);
5983                 }
5984         }
5985         else {
5986                 if (enable)
5987                         rte_eth_promiscuous_enable(res->port_num);
5988                 else
5989                         rte_eth_promiscuous_disable(res->port_num);
5990         }
5991 }
5992
5993 cmdline_parse_token_string_t cmd_setpromisc_set =
5994         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5995 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5996         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5997                                  "promisc");
5998 cmdline_parse_token_string_t cmd_setpromisc_portall =
5999         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6000                                  "all");
6001 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6002         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6003                               UINT16);
6004 cmdline_parse_token_string_t cmd_setpromisc_mode =
6005         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6006                                  "on#off");
6007
6008 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6009         .f = cmd_set_promisc_mode_parsed,
6010         .data = (void *)1,
6011         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6012         .tokens = {
6013                 (void *)&cmd_setpromisc_set,
6014                 (void *)&cmd_setpromisc_promisc,
6015                 (void *)&cmd_setpromisc_portall,
6016                 (void *)&cmd_setpromisc_mode,
6017                 NULL,
6018         },
6019 };
6020
6021 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6022         .f = cmd_set_promisc_mode_parsed,
6023         .data = (void *)0,
6024         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6025         .tokens = {
6026                 (void *)&cmd_setpromisc_set,
6027                 (void *)&cmd_setpromisc_promisc,
6028                 (void *)&cmd_setpromisc_portnum,
6029                 (void *)&cmd_setpromisc_mode,
6030                 NULL,
6031         },
6032 };
6033
6034 /* *** SET ALLMULTI MODE *** */
6035 struct cmd_set_allmulti_mode_result {
6036         cmdline_fixed_string_t set;
6037         cmdline_fixed_string_t allmulti;
6038         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6039         uint16_t port_num;               /* valid if "allports" argument == 0 */
6040         cmdline_fixed_string_t mode;
6041 };
6042
6043 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6044                                         __attribute__((unused)) struct cmdline *cl,
6045                                         void *allports)
6046 {
6047         struct cmd_set_allmulti_mode_result *res = parsed_result;
6048         int enable;
6049         portid_t i;
6050
6051         if (!strcmp(res->mode, "on"))
6052                 enable = 1;
6053         else
6054                 enable = 0;
6055
6056         /* all ports */
6057         if (allports) {
6058                 RTE_ETH_FOREACH_DEV(i) {
6059                         if (enable)
6060                                 rte_eth_allmulticast_enable(i);
6061                         else
6062                                 rte_eth_allmulticast_disable(i);
6063                 }
6064         }
6065         else {
6066                 if (enable)
6067                         rte_eth_allmulticast_enable(res->port_num);
6068                 else
6069                         rte_eth_allmulticast_disable(res->port_num);
6070         }
6071 }
6072
6073 cmdline_parse_token_string_t cmd_setallmulti_set =
6074         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6075 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6076         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6077                                  "allmulti");
6078 cmdline_parse_token_string_t cmd_setallmulti_portall =
6079         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6080                                  "all");
6081 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6082         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6083                               UINT16);
6084 cmdline_parse_token_string_t cmd_setallmulti_mode =
6085         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6086                                  "on#off");
6087
6088 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6089         .f = cmd_set_allmulti_mode_parsed,
6090         .data = (void *)1,
6091         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6092         .tokens = {
6093                 (void *)&cmd_setallmulti_set,
6094                 (void *)&cmd_setallmulti_allmulti,
6095                 (void *)&cmd_setallmulti_portall,
6096                 (void *)&cmd_setallmulti_mode,
6097                 NULL,
6098         },
6099 };
6100
6101 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6102         .f = cmd_set_allmulti_mode_parsed,
6103         .data = (void *)0,
6104         .help_str = "set allmulti <port_id> on|off: "
6105                 "Set allmulti mode on port_id",
6106         .tokens = {
6107                 (void *)&cmd_setallmulti_set,
6108                 (void *)&cmd_setallmulti_allmulti,
6109                 (void *)&cmd_setallmulti_portnum,
6110                 (void *)&cmd_setallmulti_mode,
6111                 NULL,
6112         },
6113 };
6114
6115 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6116 struct cmd_link_flow_ctrl_set_result {
6117         cmdline_fixed_string_t set;
6118         cmdline_fixed_string_t flow_ctrl;
6119         cmdline_fixed_string_t rx;
6120         cmdline_fixed_string_t rx_lfc_mode;
6121         cmdline_fixed_string_t tx;
6122         cmdline_fixed_string_t tx_lfc_mode;
6123         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6124         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6125         cmdline_fixed_string_t autoneg_str;
6126         cmdline_fixed_string_t autoneg;
6127         cmdline_fixed_string_t hw_str;
6128         uint32_t high_water;
6129         cmdline_fixed_string_t lw_str;
6130         uint32_t low_water;
6131         cmdline_fixed_string_t pt_str;
6132         uint16_t pause_time;
6133         cmdline_fixed_string_t xon_str;
6134         uint16_t send_xon;
6135         portid_t port_id;
6136 };
6137
6138 cmdline_parse_token_string_t cmd_lfc_set_set =
6139         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6140                                 set, "set");
6141 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6142         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6143                                 flow_ctrl, "flow_ctrl");
6144 cmdline_parse_token_string_t cmd_lfc_set_rx =
6145         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6146                                 rx, "rx");
6147 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6148         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6149                                 rx_lfc_mode, "on#off");
6150 cmdline_parse_token_string_t cmd_lfc_set_tx =
6151         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6152                                 tx, "tx");
6153 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6154         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6155                                 tx_lfc_mode, "on#off");
6156 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6157         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6158                                 hw_str, "high_water");
6159 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6160         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6161                                 high_water, UINT32);
6162 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6163         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6164                                 lw_str, "low_water");
6165 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6166         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6167                                 low_water, UINT32);
6168 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6169         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6170                                 pt_str, "pause_time");
6171 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6172         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6173                                 pause_time, UINT16);
6174 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6175         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6176                                 xon_str, "send_xon");
6177 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6178         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6179                                 send_xon, UINT16);
6180 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6181         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6182                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6183 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6184         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6185                                 mac_ctrl_frame_fwd_mode, "on#off");
6186 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6187         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6188                                 autoneg_str, "autoneg");
6189 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6190         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6191                                 autoneg, "on#off");
6192 cmdline_parse_token_num_t cmd_lfc_set_portid =
6193         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6194                                 port_id, UINT16);
6195
6196 /* forward declaration */
6197 static void
6198 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6199                               void *data);
6200
6201 cmdline_parse_inst_t cmd_link_flow_control_set = {
6202         .f = cmd_link_flow_ctrl_set_parsed,
6203         .data = NULL,
6204         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6205                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6206                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6207         .tokens = {
6208                 (void *)&cmd_lfc_set_set,
6209                 (void *)&cmd_lfc_set_flow_ctrl,
6210                 (void *)&cmd_lfc_set_rx,
6211                 (void *)&cmd_lfc_set_rx_mode,
6212                 (void *)&cmd_lfc_set_tx,
6213                 (void *)&cmd_lfc_set_tx_mode,
6214                 (void *)&cmd_lfc_set_high_water,
6215                 (void *)&cmd_lfc_set_low_water,
6216                 (void *)&cmd_lfc_set_pause_time,
6217                 (void *)&cmd_lfc_set_send_xon,
6218                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6219                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6220                 (void *)&cmd_lfc_set_autoneg_str,
6221                 (void *)&cmd_lfc_set_autoneg,
6222                 (void *)&cmd_lfc_set_portid,
6223                 NULL,
6224         },
6225 };
6226
6227 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6228         .f = cmd_link_flow_ctrl_set_parsed,
6229         .data = (void *)&cmd_link_flow_control_set_rx,
6230         .help_str = "set flow_ctrl rx on|off <port_id>: "
6231                 "Change rx flow control parameter",
6232         .tokens = {
6233                 (void *)&cmd_lfc_set_set,
6234                 (void *)&cmd_lfc_set_flow_ctrl,
6235                 (void *)&cmd_lfc_set_rx,
6236                 (void *)&cmd_lfc_set_rx_mode,
6237                 (void *)&cmd_lfc_set_portid,
6238                 NULL,
6239         },
6240 };
6241
6242 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6243         .f = cmd_link_flow_ctrl_set_parsed,
6244         .data = (void *)&cmd_link_flow_control_set_tx,
6245         .help_str = "set flow_ctrl tx on|off <port_id>: "
6246                 "Change tx flow control parameter",
6247         .tokens = {
6248                 (void *)&cmd_lfc_set_set,
6249                 (void *)&cmd_lfc_set_flow_ctrl,
6250                 (void *)&cmd_lfc_set_tx,
6251                 (void *)&cmd_lfc_set_tx_mode,
6252                 (void *)&cmd_lfc_set_portid,
6253                 NULL,
6254         },
6255 };
6256
6257 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6258         .f = cmd_link_flow_ctrl_set_parsed,
6259         .data = (void *)&cmd_link_flow_control_set_hw,
6260         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6261                 "Change high water flow control parameter",
6262         .tokens = {
6263                 (void *)&cmd_lfc_set_set,
6264                 (void *)&cmd_lfc_set_flow_ctrl,
6265                 (void *)&cmd_lfc_set_high_water_str,
6266                 (void *)&cmd_lfc_set_high_water,
6267                 (void *)&cmd_lfc_set_portid,
6268                 NULL,
6269         },
6270 };
6271
6272 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6273         .f = cmd_link_flow_ctrl_set_parsed,
6274         .data = (void *)&cmd_link_flow_control_set_lw,
6275         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6276                 "Change low water flow control parameter",
6277         .tokens = {
6278                 (void *)&cmd_lfc_set_set,
6279                 (void *)&cmd_lfc_set_flow_ctrl,
6280                 (void *)&cmd_lfc_set_low_water_str,
6281                 (void *)&cmd_lfc_set_low_water,
6282                 (void *)&cmd_lfc_set_portid,
6283                 NULL,
6284         },
6285 };
6286
6287 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6288         .f = cmd_link_flow_ctrl_set_parsed,
6289         .data = (void *)&cmd_link_flow_control_set_pt,
6290         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6291                 "Change pause time flow control parameter",
6292         .tokens = {
6293                 (void *)&cmd_lfc_set_set,
6294                 (void *)&cmd_lfc_set_flow_ctrl,
6295                 (void *)&cmd_lfc_set_pause_time_str,
6296                 (void *)&cmd_lfc_set_pause_time,
6297                 (void *)&cmd_lfc_set_portid,
6298                 NULL,
6299         },
6300 };
6301
6302 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6303         .f = cmd_link_flow_ctrl_set_parsed,
6304         .data = (void *)&cmd_link_flow_control_set_xon,
6305         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6306                 "Change send_xon flow control parameter",
6307         .tokens = {
6308                 (void *)&cmd_lfc_set_set,
6309                 (void *)&cmd_lfc_set_flow_ctrl,
6310                 (void *)&cmd_lfc_set_send_xon_str,
6311                 (void *)&cmd_lfc_set_send_xon,
6312                 (void *)&cmd_lfc_set_portid,
6313                 NULL,
6314         },
6315 };
6316
6317 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6318         .f = cmd_link_flow_ctrl_set_parsed,
6319         .data = (void *)&cmd_link_flow_control_set_macfwd,
6320         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6321                 "Change mac ctrl fwd flow control parameter",
6322         .tokens = {
6323                 (void *)&cmd_lfc_set_set,
6324                 (void *)&cmd_lfc_set_flow_ctrl,
6325                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6326                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6327                 (void *)&cmd_lfc_set_portid,
6328                 NULL,
6329         },
6330 };
6331
6332 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6333         .f = cmd_link_flow_ctrl_set_parsed,
6334         .data = (void *)&cmd_link_flow_control_set_autoneg,
6335         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6336                 "Change autoneg flow control parameter",
6337         .tokens = {
6338                 (void *)&cmd_lfc_set_set,
6339                 (void *)&cmd_lfc_set_flow_ctrl,
6340                 (void *)&cmd_lfc_set_autoneg_str,
6341                 (void *)&cmd_lfc_set_autoneg,
6342                 (void *)&cmd_lfc_set_portid,
6343                 NULL,
6344         },
6345 };
6346
6347 static void
6348 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6349                               __attribute__((unused)) struct cmdline *cl,
6350                               void *data)
6351 {
6352         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6353         cmdline_parse_inst_t *cmd = data;
6354         struct rte_eth_fc_conf fc_conf;
6355         int rx_fc_en = 0;
6356         int tx_fc_en = 0;
6357         int ret;
6358
6359         /*
6360          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6361          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6362          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6363          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6364          */
6365         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6366                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6367         };
6368
6369         /* Partial command line, retrieve current configuration */
6370         if (cmd) {
6371                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6372                 if (ret != 0) {
6373                         printf("cannot get current flow ctrl parameters, return"
6374                                "code = %d\n", ret);
6375                         return;
6376                 }
6377
6378                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6379                     (fc_conf.mode == RTE_FC_FULL))
6380                         rx_fc_en = 1;
6381                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6382                     (fc_conf.mode == RTE_FC_FULL))
6383                         tx_fc_en = 1;
6384         }
6385
6386         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6387                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6388
6389         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6390                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6391
6392         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6393
6394         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6395                 fc_conf.high_water = res->high_water;
6396
6397         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6398                 fc_conf.low_water = res->low_water;
6399
6400         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6401                 fc_conf.pause_time = res->pause_time;
6402
6403         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6404                 fc_conf.send_xon = res->send_xon;
6405
6406         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6407                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6408                         fc_conf.mac_ctrl_frame_fwd = 1;
6409                 else
6410                         fc_conf.mac_ctrl_frame_fwd = 0;
6411         }
6412
6413         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6414                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6415
6416         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6417         if (ret != 0)
6418                 printf("bad flow contrl parameter, return code = %d \n", ret);
6419 }
6420
6421 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6422 struct cmd_priority_flow_ctrl_set_result {
6423         cmdline_fixed_string_t set;
6424         cmdline_fixed_string_t pfc_ctrl;
6425         cmdline_fixed_string_t rx;
6426         cmdline_fixed_string_t rx_pfc_mode;
6427         cmdline_fixed_string_t tx;
6428         cmdline_fixed_string_t tx_pfc_mode;
6429         uint32_t high_water;
6430         uint32_t low_water;
6431         uint16_t pause_time;
6432         uint8_t  priority;
6433         portid_t port_id;
6434 };
6435
6436 static void
6437 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6438                        __attribute__((unused)) struct cmdline *cl,
6439                        __attribute__((unused)) void *data)
6440 {
6441         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6442         struct rte_eth_pfc_conf pfc_conf;
6443         int rx_fc_enable, tx_fc_enable;
6444         int ret;
6445
6446         /*
6447          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6448          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6449          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6450          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6451          */
6452         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6453                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6454         };
6455
6456         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6457         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6458         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6459         pfc_conf.fc.high_water = res->high_water;
6460         pfc_conf.fc.low_water  = res->low_water;
6461         pfc_conf.fc.pause_time = res->pause_time;
6462         pfc_conf.priority      = res->priority;
6463
6464         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6465         if (ret != 0)
6466                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6467 }
6468
6469 cmdline_parse_token_string_t cmd_pfc_set_set =
6470         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6471                                 set, "set");
6472 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6473         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6474                                 pfc_ctrl, "pfc_ctrl");
6475 cmdline_parse_token_string_t cmd_pfc_set_rx =
6476         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6477                                 rx, "rx");
6478 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6479         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6480                                 rx_pfc_mode, "on#off");
6481 cmdline_parse_token_string_t cmd_pfc_set_tx =
6482         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6483                                 tx, "tx");
6484 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6485         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6486                                 tx_pfc_mode, "on#off");
6487 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6488         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6489                                 high_water, UINT32);
6490 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6491         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6492                                 low_water, UINT32);
6493 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6494         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6495                                 pause_time, UINT16);
6496 cmdline_parse_token_num_t cmd_pfc_set_priority =
6497         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6498                                 priority, UINT8);
6499 cmdline_parse_token_num_t cmd_pfc_set_portid =
6500         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6501                                 port_id, UINT16);
6502
6503 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6504         .f = cmd_priority_flow_ctrl_set_parsed,
6505         .data = NULL,
6506         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6507                 "<pause_time> <priority> <port_id>: "
6508                 "Configure the Ethernet priority flow control",
6509         .tokens = {
6510                 (void *)&cmd_pfc_set_set,
6511                 (void *)&cmd_pfc_set_flow_ctrl,
6512                 (void *)&cmd_pfc_set_rx,
6513                 (void *)&cmd_pfc_set_rx_mode,
6514                 (void *)&cmd_pfc_set_tx,
6515                 (void *)&cmd_pfc_set_tx_mode,
6516                 (void *)&cmd_pfc_set_high_water,
6517                 (void *)&cmd_pfc_set_low_water,
6518                 (void *)&cmd_pfc_set_pause_time,
6519                 (void *)&cmd_pfc_set_priority,
6520                 (void *)&cmd_pfc_set_portid,
6521                 NULL,
6522         },
6523 };
6524
6525 /* *** RESET CONFIGURATION *** */
6526 struct cmd_reset_result {
6527         cmdline_fixed_string_t reset;
6528         cmdline_fixed_string_t def;
6529 };
6530
6531 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6532                              struct cmdline *cl,
6533                              __attribute__((unused)) void *data)
6534 {
6535         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6536         set_def_fwd_config();
6537 }
6538
6539 cmdline_parse_token_string_t cmd_reset_set =
6540         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6541 cmdline_parse_token_string_t cmd_reset_def =
6542         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6543                                  "default");
6544
6545 cmdline_parse_inst_t cmd_reset = {
6546         .f = cmd_reset_parsed,
6547         .data = NULL,
6548         .help_str = "set default: Reset default forwarding configuration",
6549         .tokens = {
6550                 (void *)&cmd_reset_set,
6551                 (void *)&cmd_reset_def,
6552                 NULL,
6553         },
6554 };
6555
6556 /* *** START FORWARDING *** */
6557 struct cmd_start_result {
6558         cmdline_fixed_string_t start;
6559 };
6560
6561 cmdline_parse_token_string_t cmd_start_start =
6562         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6563
6564 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6565                              __attribute__((unused)) struct cmdline *cl,
6566                              __attribute__((unused)) void *data)
6567 {
6568         start_packet_forwarding(0);
6569 }
6570
6571 cmdline_parse_inst_t cmd_start = {
6572         .f = cmd_start_parsed,
6573         .data = NULL,
6574         .help_str = "start: Start packet forwarding",
6575         .tokens = {
6576                 (void *)&cmd_start_start,
6577                 NULL,
6578         },
6579 };
6580
6581 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6582 struct cmd_start_tx_first_result {
6583         cmdline_fixed_string_t start;
6584         cmdline_fixed_string_t tx_first;
6585 };
6586
6587 static void
6588 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6589                           __attribute__((unused)) struct cmdline *cl,
6590                           __attribute__((unused)) void *data)
6591 {
6592         start_packet_forwarding(1);
6593 }
6594
6595 cmdline_parse_token_string_t cmd_start_tx_first_start =
6596         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6597                                  "start");
6598 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6599         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6600                                  tx_first, "tx_first");
6601
6602 cmdline_parse_inst_t cmd_start_tx_first = {
6603         .f = cmd_start_tx_first_parsed,
6604         .data = NULL,
6605         .help_str = "start tx_first: Start packet forwarding, "
6606                 "after sending 1 burst of packets",
6607         .tokens = {
6608                 (void *)&cmd_start_tx_first_start,
6609                 (void *)&cmd_start_tx_first_tx_first,
6610                 NULL,
6611         },
6612 };
6613
6614 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6615 struct cmd_start_tx_first_n_result {
6616         cmdline_fixed_string_t start;
6617         cmdline_fixed_string_t tx_first;
6618         uint32_t tx_num;
6619 };
6620
6621 static void
6622 cmd_start_tx_first_n_parsed(void *parsed_result,
6623                           __attribute__((unused)) struct cmdline *cl,
6624                           __attribute__((unused)) void *data)
6625 {
6626         struct cmd_start_tx_first_n_result *res = parsed_result;
6627
6628         start_packet_forwarding(res->tx_num);
6629 }
6630
6631 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6632         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6633                         start, "start");
6634 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6635         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6636                         tx_first, "tx_first");
6637 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6638         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6639                         tx_num, UINT32);
6640
6641 cmdline_parse_inst_t cmd_start_tx_first_n = {
6642         .f = cmd_start_tx_first_n_parsed,
6643         .data = NULL,
6644         .help_str = "start tx_first <num>: "
6645                 "packet forwarding, after sending <num> bursts of packets",
6646         .tokens = {
6647                 (void *)&cmd_start_tx_first_n_start,
6648                 (void *)&cmd_start_tx_first_n_tx_first,
6649                 (void *)&cmd_start_tx_first_n_tx_num,
6650                 NULL,
6651         },
6652 };
6653
6654 /* *** SET LINK UP *** */
6655 struct cmd_set_link_up_result {
6656         cmdline_fixed_string_t set;
6657         cmdline_fixed_string_t link_up;
6658         cmdline_fixed_string_t port;
6659         portid_t port_id;
6660 };
6661
6662 cmdline_parse_token_string_t cmd_set_link_up_set =
6663         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6664 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6665         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6666                                 "link-up");
6667 cmdline_parse_token_string_t cmd_set_link_up_port =
6668         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6669 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6670         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6671
6672 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6673                              __attribute__((unused)) struct cmdline *cl,
6674                              __attribute__((unused)) void *data)
6675 {
6676         struct cmd_set_link_up_result *res = parsed_result;
6677         dev_set_link_up(res->port_id);
6678 }
6679
6680 cmdline_parse_inst_t cmd_set_link_up = {
6681         .f = cmd_set_link_up_parsed,
6682         .data = NULL,
6683         .help_str = "set link-up port <port id>",
6684         .tokens = {
6685                 (void *)&cmd_set_link_up_set,
6686                 (void *)&cmd_set_link_up_link_up,
6687                 (void *)&cmd_set_link_up_port,
6688                 (void *)&cmd_set_link_up_port_id,
6689                 NULL,
6690         },
6691 };
6692
6693 /* *** SET LINK DOWN *** */
6694 struct cmd_set_link_down_result {
6695         cmdline_fixed_string_t set;
6696         cmdline_fixed_string_t link_down;
6697         cmdline_fixed_string_t port;
6698         portid_t port_id;
6699 };
6700
6701 cmdline_parse_token_string_t cmd_set_link_down_set =
6702         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6703 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6704         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6705                                 "link-down");
6706 cmdline_parse_token_string_t cmd_set_link_down_port =
6707         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6708 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6709         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6710
6711 static void cmd_set_link_down_parsed(
6712                                 __attribute__((unused)) void *parsed_result,
6713                                 __attribute__((unused)) struct cmdline *cl,
6714                                 __attribute__((unused)) void *data)
6715 {
6716         struct cmd_set_link_down_result *res = parsed_result;
6717         dev_set_link_down(res->port_id);
6718 }
6719
6720 cmdline_parse_inst_t cmd_set_link_down = {
6721         .f = cmd_set_link_down_parsed,
6722         .data = NULL,
6723         .help_str = "set link-down port <port id>",
6724         .tokens = {
6725                 (void *)&cmd_set_link_down_set,
6726                 (void *)&cmd_set_link_down_link_down,
6727                 (void *)&cmd_set_link_down_port,
6728                 (void *)&cmd_set_link_down_port_id,
6729                 NULL,
6730         },
6731 };
6732
6733 /* *** SHOW CFG *** */
6734 struct cmd_showcfg_result {
6735         cmdline_fixed_string_t show;
6736         cmdline_fixed_string_t cfg;
6737         cmdline_fixed_string_t what;
6738 };
6739
6740 static void cmd_showcfg_parsed(void *parsed_result,
6741                                __attribute__((unused)) struct cmdline *cl,
6742                                __attribute__((unused)) void *data)
6743 {
6744         struct cmd_showcfg_result *res = parsed_result;
6745         if (!strcmp(res->what, "rxtx"))
6746                 rxtx_config_display();
6747         else if (!strcmp(res->what, "cores"))
6748                 fwd_lcores_config_display();
6749         else if (!strcmp(res->what, "fwd"))
6750                 pkt_fwd_config_display(&cur_fwd_config);
6751         else if (!strcmp(res->what, "txpkts"))
6752                 show_tx_pkt_segments();
6753 }
6754
6755 cmdline_parse_token_string_t cmd_showcfg_show =
6756         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6757 cmdline_parse_token_string_t cmd_showcfg_port =
6758         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6759 cmdline_parse_token_string_t cmd_showcfg_what =
6760         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6761                                  "rxtx#cores#fwd#txpkts");
6762
6763 cmdline_parse_inst_t cmd_showcfg = {
6764         .f = cmd_showcfg_parsed,
6765         .data = NULL,
6766         .help_str = "show config rxtx|cores|fwd|txpkts",
6767         .tokens = {
6768                 (void *)&cmd_showcfg_show,
6769                 (void *)&cmd_showcfg_port,
6770                 (void *)&cmd_showcfg_what,
6771                 NULL,
6772         },
6773 };
6774
6775 /* *** SHOW ALL PORT INFO *** */
6776 struct cmd_showportall_result {
6777         cmdline_fixed_string_t show;
6778         cmdline_fixed_string_t port;
6779         cmdline_fixed_string_t what;
6780         cmdline_fixed_string_t all;
6781 };
6782
6783 static void cmd_showportall_parsed(void *parsed_result,
6784                                 __attribute__((unused)) struct cmdline *cl,
6785                                 __attribute__((unused)) void *data)
6786 {
6787         portid_t i;
6788
6789         struct cmd_showportall_result *res = parsed_result;
6790         if (!strcmp(res->show, "clear")) {
6791                 if (!strcmp(res->what, "stats"))
6792                         RTE_ETH_FOREACH_DEV(i)
6793                                 nic_stats_clear(i);
6794                 else if (!strcmp(res->what, "xstats"))
6795                         RTE_ETH_FOREACH_DEV(i)
6796                                 nic_xstats_clear(i);
6797         } else if (!strcmp(res->what, "info"))
6798                 RTE_ETH_FOREACH_DEV(i)
6799                         port_infos_display(i);
6800         else if (!strcmp(res->what, "stats"))
6801                 RTE_ETH_FOREACH_DEV(i)
6802                         nic_stats_display(i);
6803         else if (!strcmp(res->what, "xstats"))
6804                 RTE_ETH_FOREACH_DEV(i)
6805                         nic_xstats_display(i);
6806         else if (!strcmp(res->what, "fdir"))
6807                 RTE_ETH_FOREACH_DEV(i)
6808                         fdir_get_infos(i);
6809         else if (!strcmp(res->what, "stat_qmap"))
6810                 RTE_ETH_FOREACH_DEV(i)
6811                         nic_stats_mapping_display(i);
6812         else if (!strcmp(res->what, "dcb_tc"))
6813                 RTE_ETH_FOREACH_DEV(i)
6814                         port_dcb_info_display(i);
6815         else if (!strcmp(res->what, "cap"))
6816                 RTE_ETH_FOREACH_DEV(i)
6817                         port_offload_cap_display(i);
6818 }
6819
6820 cmdline_parse_token_string_t cmd_showportall_show =
6821         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6822                                  "show#clear");
6823 cmdline_parse_token_string_t cmd_showportall_port =
6824         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6825 cmdline_parse_token_string_t cmd_showportall_what =
6826         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6827                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6828 cmdline_parse_token_string_t cmd_showportall_all =
6829         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6830 cmdline_parse_inst_t cmd_showportall = {
6831         .f = cmd_showportall_parsed,
6832         .data = NULL,
6833         .help_str = "show|clear port "
6834                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6835         .tokens = {
6836                 (void *)&cmd_showportall_show,
6837                 (void *)&cmd_showportall_port,
6838                 (void *)&cmd_showportall_what,
6839                 (void *)&cmd_showportall_all,
6840                 NULL,
6841         },
6842 };
6843
6844 /* *** SHOW PORT INFO *** */
6845 struct cmd_showport_result {
6846         cmdline_fixed_string_t show;
6847         cmdline_fixed_string_t port;
6848         cmdline_fixed_string_t what;
6849         uint16_t portnum;
6850 };
6851
6852 static void cmd_showport_parsed(void *parsed_result,
6853                                 __attribute__((unused)) struct cmdline *cl,
6854                                 __attribute__((unused)) void *data)
6855 {
6856         struct cmd_showport_result *res = parsed_result;
6857         if (!strcmp(res->show, "clear")) {
6858                 if (!strcmp(res->what, "stats"))
6859                         nic_stats_clear(res->portnum);
6860                 else if (!strcmp(res->what, "xstats"))
6861                         nic_xstats_clear(res->portnum);
6862         } else if (!strcmp(res->what, "info"))
6863                 port_infos_display(res->portnum);
6864         else if (!strcmp(res->what, "stats"))
6865                 nic_stats_display(res->portnum);
6866         else if (!strcmp(res->what, "xstats"))
6867                 nic_xstats_display(res->portnum);
6868         else if (!strcmp(res->what, "fdir"))
6869                  fdir_get_infos(res->portnum);
6870         else if (!strcmp(res->what, "stat_qmap"))
6871                 nic_stats_mapping_display(res->portnum);
6872         else if (!strcmp(res->what, "dcb_tc"))
6873                 port_dcb_info_display(res->portnum);
6874         else if (!strcmp(res->what, "cap"))
6875                 port_offload_cap_display(res->portnum);
6876 }
6877
6878 cmdline_parse_token_string_t cmd_showport_show =
6879         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6880                                  "show#clear");
6881 cmdline_parse_token_string_t cmd_showport_port =
6882         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6883 cmdline_parse_token_string_t cmd_showport_what =
6884         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6885                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6886 cmdline_parse_token_num_t cmd_showport_portnum =
6887         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6888
6889 cmdline_parse_inst_t cmd_showport = {
6890         .f = cmd_showport_parsed,
6891         .data = NULL,
6892         .help_str = "show|clear port "
6893                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6894                 "<port_id>",
6895         .tokens = {
6896                 (void *)&cmd_showport_show,
6897                 (void *)&cmd_showport_port,
6898                 (void *)&cmd_showport_what,
6899                 (void *)&cmd_showport_portnum,
6900                 NULL,
6901         },
6902 };
6903
6904 /* *** SHOW QUEUE INFO *** */
6905 struct cmd_showqueue_result {
6906         cmdline_fixed_string_t show;
6907         cmdline_fixed_string_t type;
6908         cmdline_fixed_string_t what;
6909         uint16_t portnum;
6910         uint16_t queuenum;
6911 };
6912
6913 static void
6914 cmd_showqueue_parsed(void *parsed_result,
6915         __attribute__((unused)) struct cmdline *cl,
6916         __attribute__((unused)) void *data)
6917 {
6918         struct cmd_showqueue_result *res = parsed_result;
6919
6920         if (!strcmp(res->type, "rxq"))
6921                 rx_queue_infos_display(res->portnum, res->queuenum);
6922         else if (!strcmp(res->type, "txq"))
6923                 tx_queue_infos_display(res->portnum, res->queuenum);
6924 }
6925
6926 cmdline_parse_token_string_t cmd_showqueue_show =
6927         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6928 cmdline_parse_token_string_t cmd_showqueue_type =
6929         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6930 cmdline_parse_token_string_t cmd_showqueue_what =
6931         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6932 cmdline_parse_token_num_t cmd_showqueue_portnum =
6933         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6934 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6935         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6936
6937 cmdline_parse_inst_t cmd_showqueue = {
6938         .f = cmd_showqueue_parsed,
6939         .data = NULL,
6940         .help_str = "show rxq|txq info <port_id> <queue_id>",
6941         .tokens = {
6942                 (void *)&cmd_showqueue_show,
6943                 (void *)&cmd_showqueue_type,
6944                 (void *)&cmd_showqueue_what,
6945                 (void *)&cmd_showqueue_portnum,
6946                 (void *)&cmd_showqueue_queuenum,
6947                 NULL,
6948         },
6949 };
6950
6951 /* *** READ PORT REGISTER *** */
6952 struct cmd_read_reg_result {
6953         cmdline_fixed_string_t read;
6954         cmdline_fixed_string_t reg;
6955         portid_t port_id;
6956         uint32_t reg_off;
6957 };
6958
6959 static void
6960 cmd_read_reg_parsed(void *parsed_result,
6961                     __attribute__((unused)) struct cmdline *cl,
6962                     __attribute__((unused)) void *data)
6963 {
6964         struct cmd_read_reg_result *res = parsed_result;
6965         port_reg_display(res->port_id, res->reg_off);
6966 }
6967
6968 cmdline_parse_token_string_t cmd_read_reg_read =
6969         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6970 cmdline_parse_token_string_t cmd_read_reg_reg =
6971         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6972 cmdline_parse_token_num_t cmd_read_reg_port_id =
6973         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6974 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6975         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6976
6977 cmdline_parse_inst_t cmd_read_reg = {
6978         .f = cmd_read_reg_parsed,
6979         .data = NULL,
6980         .help_str = "read reg <port_id> <reg_off>",
6981         .tokens = {
6982                 (void *)&cmd_read_reg_read,
6983                 (void *)&cmd_read_reg_reg,
6984                 (void *)&cmd_read_reg_port_id,
6985                 (void *)&cmd_read_reg_reg_off,
6986                 NULL,
6987         },
6988 };
6989
6990 /* *** READ PORT REGISTER BIT FIELD *** */
6991 struct cmd_read_reg_bit_field_result {
6992         cmdline_fixed_string_t read;
6993         cmdline_fixed_string_t regfield;
6994         portid_t port_id;
6995         uint32_t reg_off;
6996         uint8_t bit1_pos;
6997         uint8_t bit2_pos;
6998 };
6999
7000 static void
7001 cmd_read_reg_bit_field_parsed(void *parsed_result,
7002                               __attribute__((unused)) struct cmdline *cl,
7003                               __attribute__((unused)) void *data)
7004 {
7005         struct cmd_read_reg_bit_field_result *res = parsed_result;
7006         port_reg_bit_field_display(res->port_id, res->reg_off,
7007                                    res->bit1_pos, res->bit2_pos);
7008 }
7009
7010 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7011         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7012                                  "read");
7013 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7014         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7015                                  regfield, "regfield");
7016 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7017         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7018                               UINT16);
7019 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7020         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7021                               UINT32);
7022 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7023         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7024                               UINT8);
7025 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7026         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7027                               UINT8);
7028
7029 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7030         .f = cmd_read_reg_bit_field_parsed,
7031         .data = NULL,
7032         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7033         "Read register bit field between bit_x and bit_y included",
7034         .tokens = {
7035                 (void *)&cmd_read_reg_bit_field_read,
7036                 (void *)&cmd_read_reg_bit_field_regfield,
7037                 (void *)&cmd_read_reg_bit_field_port_id,
7038                 (void *)&cmd_read_reg_bit_field_reg_off,
7039                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7040                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7041                 NULL,
7042         },
7043 };
7044
7045 /* *** READ PORT REGISTER BIT *** */
7046 struct cmd_read_reg_bit_result {
7047         cmdline_fixed_string_t read;
7048         cmdline_fixed_string_t regbit;
7049         portid_t port_id;
7050         uint32_t reg_off;
7051         uint8_t bit_pos;
7052 };
7053
7054 static void
7055 cmd_read_reg_bit_parsed(void *parsed_result,
7056                         __attribute__((unused)) struct cmdline *cl,
7057                         __attribute__((unused)) void *data)
7058 {
7059         struct cmd_read_reg_bit_result *res = parsed_result;
7060         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7061 }
7062
7063 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7064         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7065 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7066         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7067                                  regbit, "regbit");
7068 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7069         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7070 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7071         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7072 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7073         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7074
7075 cmdline_parse_inst_t cmd_read_reg_bit = {
7076         .f = cmd_read_reg_bit_parsed,
7077         .data = NULL,
7078         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7079         .tokens = {
7080                 (void *)&cmd_read_reg_bit_read,
7081                 (void *)&cmd_read_reg_bit_regbit,
7082                 (void *)&cmd_read_reg_bit_port_id,
7083                 (void *)&cmd_read_reg_bit_reg_off,
7084                 (void *)&cmd_read_reg_bit_bit_pos,
7085                 NULL,
7086         },
7087 };
7088
7089 /* *** WRITE PORT REGISTER *** */
7090 struct cmd_write_reg_result {
7091         cmdline_fixed_string_t write;
7092         cmdline_fixed_string_t reg;
7093         portid_t port_id;
7094         uint32_t reg_off;
7095         uint32_t value;
7096 };
7097
7098 static void
7099 cmd_write_reg_parsed(void *parsed_result,
7100                      __attribute__((unused)) struct cmdline *cl,
7101                      __attribute__((unused)) void *data)
7102 {
7103         struct cmd_write_reg_result *res = parsed_result;
7104         port_reg_set(res->port_id, res->reg_off, res->value);
7105 }
7106
7107 cmdline_parse_token_string_t cmd_write_reg_write =
7108         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7109 cmdline_parse_token_string_t cmd_write_reg_reg =
7110         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7111 cmdline_parse_token_num_t cmd_write_reg_port_id =
7112         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7113 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7114         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7115 cmdline_parse_token_num_t cmd_write_reg_value =
7116         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7117
7118 cmdline_parse_inst_t cmd_write_reg = {
7119         .f = cmd_write_reg_parsed,
7120         .data = NULL,
7121         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7122         .tokens = {
7123                 (void *)&cmd_write_reg_write,
7124                 (void *)&cmd_write_reg_reg,
7125                 (void *)&cmd_write_reg_port_id,
7126                 (void *)&cmd_write_reg_reg_off,
7127                 (void *)&cmd_write_reg_value,
7128                 NULL,
7129         },
7130 };
7131
7132 /* *** WRITE PORT REGISTER BIT FIELD *** */
7133 struct cmd_write_reg_bit_field_result {
7134         cmdline_fixed_string_t write;
7135         cmdline_fixed_string_t regfield;
7136         portid_t port_id;
7137         uint32_t reg_off;
7138         uint8_t bit1_pos;
7139         uint8_t bit2_pos;
7140         uint32_t value;
7141 };
7142
7143 static void
7144 cmd_write_reg_bit_field_parsed(void *parsed_result,
7145                                __attribute__((unused)) struct cmdline *cl,
7146                                __attribute__((unused)) void *data)
7147 {
7148         struct cmd_write_reg_bit_field_result *res = parsed_result;
7149         port_reg_bit_field_set(res->port_id, res->reg_off,
7150                           res->bit1_pos, res->bit2_pos, res->value);
7151 }
7152
7153 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7154         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7155                                  "write");
7156 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7157         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7158                                  regfield, "regfield");
7159 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7160         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7161                               UINT16);
7162 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7163         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7164                               UINT32);
7165 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7166         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7167                               UINT8);
7168 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7169         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7170                               UINT8);
7171 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7172         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7173                               UINT32);
7174
7175 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7176         .f = cmd_write_reg_bit_field_parsed,
7177         .data = NULL,
7178         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7179                 "<reg_value>: "
7180                 "Set register bit field between bit_x and bit_y included",
7181         .tokens = {
7182                 (void *)&cmd_write_reg_bit_field_write,
7183                 (void *)&cmd_write_reg_bit_field_regfield,
7184                 (void *)&cmd_write_reg_bit_field_port_id,
7185                 (void *)&cmd_write_reg_bit_field_reg_off,
7186                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7187                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7188                 (void *)&cmd_write_reg_bit_field_value,
7189                 NULL,
7190         },
7191 };
7192
7193 /* *** WRITE PORT REGISTER BIT *** */
7194 struct cmd_write_reg_bit_result {
7195         cmdline_fixed_string_t write;
7196         cmdline_fixed_string_t regbit;
7197         portid_t port_id;
7198         uint32_t reg_off;
7199         uint8_t bit_pos;
7200         uint8_t value;
7201 };
7202
7203 static void
7204 cmd_write_reg_bit_parsed(void *parsed_result,
7205                          __attribute__((unused)) struct cmdline *cl,
7206                          __attribute__((unused)) void *data)
7207 {
7208         struct cmd_write_reg_bit_result *res = parsed_result;
7209         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7210 }
7211
7212 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7213         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7214                                  "write");
7215 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7216         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7217                                  regbit, "regbit");
7218 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7219         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7220 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7221         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7222 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7223         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7224 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7225         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7226
7227 cmdline_parse_inst_t cmd_write_reg_bit = {
7228         .f = cmd_write_reg_bit_parsed,
7229         .data = NULL,
7230         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7231                 "0 <= bit_x <= 31",
7232         .tokens = {
7233                 (void *)&cmd_write_reg_bit_write,
7234                 (void *)&cmd_write_reg_bit_regbit,
7235                 (void *)&cmd_write_reg_bit_port_id,
7236                 (void *)&cmd_write_reg_bit_reg_off,
7237                 (void *)&cmd_write_reg_bit_bit_pos,
7238                 (void *)&cmd_write_reg_bit_value,
7239                 NULL,
7240         },
7241 };
7242
7243 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7244 struct cmd_read_rxd_txd_result {
7245         cmdline_fixed_string_t read;
7246         cmdline_fixed_string_t rxd_txd;
7247         portid_t port_id;
7248         uint16_t queue_id;
7249         uint16_t desc_id;
7250 };
7251
7252 static void
7253 cmd_read_rxd_txd_parsed(void *parsed_result,
7254                         __attribute__((unused)) struct cmdline *cl,
7255                         __attribute__((unused)) void *data)
7256 {
7257         struct cmd_read_rxd_txd_result *res = parsed_result;
7258
7259         if (!strcmp(res->rxd_txd, "rxd"))
7260                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7261         else if (!strcmp(res->rxd_txd, "txd"))
7262                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7263 }
7264
7265 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7266         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7267 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7268         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7269                                  "rxd#txd");
7270 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7271         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7272 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7273         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7274 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7275         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7276
7277 cmdline_parse_inst_t cmd_read_rxd_txd = {
7278         .f = cmd_read_rxd_txd_parsed,
7279         .data = NULL,
7280         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7281         .tokens = {
7282                 (void *)&cmd_read_rxd_txd_read,
7283                 (void *)&cmd_read_rxd_txd_rxd_txd,
7284                 (void *)&cmd_read_rxd_txd_port_id,
7285                 (void *)&cmd_read_rxd_txd_queue_id,
7286                 (void *)&cmd_read_rxd_txd_desc_id,
7287                 NULL,
7288         },
7289 };
7290
7291 /* *** QUIT *** */
7292 struct cmd_quit_result {
7293         cmdline_fixed_string_t quit;
7294 };
7295
7296 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7297                             struct cmdline *cl,
7298                             __attribute__((unused)) void *data)
7299 {
7300         pmd_test_exit();
7301         cmdline_quit(cl);
7302 }
7303
7304 cmdline_parse_token_string_t cmd_quit_quit =
7305         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7306
7307 cmdline_parse_inst_t cmd_quit = {
7308         .f = cmd_quit_parsed,
7309         .data = NULL,
7310         .help_str = "quit: Exit application",
7311         .tokens = {
7312                 (void *)&cmd_quit_quit,
7313                 NULL,
7314         },
7315 };
7316
7317 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7318 struct cmd_mac_addr_result {
7319         cmdline_fixed_string_t mac_addr_cmd;
7320         cmdline_fixed_string_t what;
7321         uint16_t port_num;
7322         struct ether_addr address;
7323 };
7324
7325 static void cmd_mac_addr_parsed(void *parsed_result,
7326                 __attribute__((unused)) struct cmdline *cl,
7327                 __attribute__((unused)) void *data)
7328 {
7329         struct cmd_mac_addr_result *res = parsed_result;
7330         int ret;
7331
7332         if (strcmp(res->what, "add") == 0)
7333                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7334         else if (strcmp(res->what, "set") == 0)
7335                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7336                                                        &res->address);
7337         else
7338                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7339
7340         /* check the return value and print it if is < 0 */
7341         if(ret < 0)
7342                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7343
7344 }
7345
7346 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7347         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7348                                 "mac_addr");
7349 cmdline_parse_token_string_t cmd_mac_addr_what =
7350         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7351                                 "add#remove#set");
7352 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7353                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7354                                         UINT16);
7355 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7356                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7357
7358 cmdline_parse_inst_t cmd_mac_addr = {
7359         .f = cmd_mac_addr_parsed,
7360         .data = (void *)0,
7361         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7362                         "Add/Remove/Set MAC address on port_id",
7363         .tokens = {
7364                 (void *)&cmd_mac_addr_cmd,
7365                 (void *)&cmd_mac_addr_what,
7366                 (void *)&cmd_mac_addr_portnum,
7367                 (void *)&cmd_mac_addr_addr,
7368                 NULL,
7369         },
7370 };
7371
7372 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7373 struct cmd_eth_peer_result {
7374         cmdline_fixed_string_t set;
7375         cmdline_fixed_string_t eth_peer;
7376         portid_t port_id;
7377         cmdline_fixed_string_t peer_addr;
7378 };
7379
7380 static void cmd_set_eth_peer_parsed(void *parsed_result,
7381                         __attribute__((unused)) struct cmdline *cl,
7382                         __attribute__((unused)) void *data)
7383 {
7384                 struct cmd_eth_peer_result *res = parsed_result;
7385
7386                 if (test_done == 0) {
7387                         printf("Please stop forwarding first\n");
7388                         return;
7389                 }
7390                 if (!strcmp(res->eth_peer, "eth-peer")) {
7391                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7392                         fwd_config_setup();
7393                 }
7394 }
7395 cmdline_parse_token_string_t cmd_eth_peer_set =
7396         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7397 cmdline_parse_token_string_t cmd_eth_peer =
7398         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7399 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7400         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7401 cmdline_parse_token_string_t cmd_eth_peer_addr =
7402         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7403
7404 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7405         .f = cmd_set_eth_peer_parsed,
7406         .data = NULL,
7407         .help_str = "set eth-peer <port_id> <peer_mac>",
7408         .tokens = {
7409                 (void *)&cmd_eth_peer_set,
7410                 (void *)&cmd_eth_peer,
7411                 (void *)&cmd_eth_peer_port_id,
7412                 (void *)&cmd_eth_peer_addr,
7413                 NULL,
7414         },
7415 };
7416
7417 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7418 struct cmd_set_qmap_result {
7419         cmdline_fixed_string_t set;
7420         cmdline_fixed_string_t qmap;
7421         cmdline_fixed_string_t what;
7422         portid_t port_id;
7423         uint16_t queue_id;
7424         uint8_t map_value;
7425 };
7426
7427 static void
7428 cmd_set_qmap_parsed(void *parsed_result,
7429                        __attribute__((unused)) struct cmdline *cl,
7430                        __attribute__((unused)) void *data)
7431 {
7432         struct cmd_set_qmap_result *res = parsed_result;
7433         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7434
7435         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7436 }
7437
7438 cmdline_parse_token_string_t cmd_setqmap_set =
7439         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7440                                  set, "set");
7441 cmdline_parse_token_string_t cmd_setqmap_qmap =
7442         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7443                                  qmap, "stat_qmap");
7444 cmdline_parse_token_string_t cmd_setqmap_what =
7445         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7446                                  what, "tx#rx");
7447 cmdline_parse_token_num_t cmd_setqmap_portid =
7448         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7449                               port_id, UINT16);
7450 cmdline_parse_token_num_t cmd_setqmap_queueid =
7451         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7452                               queue_id, UINT16);
7453 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7454         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7455                               map_value, UINT8);
7456
7457 cmdline_parse_inst_t cmd_set_qmap = {
7458         .f = cmd_set_qmap_parsed,
7459         .data = NULL,
7460         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7461                 "Set statistics mapping value on tx|rx queue_id of port_id",
7462         .tokens = {
7463                 (void *)&cmd_setqmap_set,
7464                 (void *)&cmd_setqmap_qmap,
7465                 (void *)&cmd_setqmap_what,
7466                 (void *)&cmd_setqmap_portid,
7467                 (void *)&cmd_setqmap_queueid,
7468                 (void *)&cmd_setqmap_mapvalue,
7469                 NULL,
7470         },
7471 };
7472
7473 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7474 struct cmd_set_xstats_hide_zero_result {
7475         cmdline_fixed_string_t keyword;
7476         cmdline_fixed_string_t name;
7477         cmdline_fixed_string_t on_off;
7478 };
7479
7480 static void
7481 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7482                         __attribute__((unused)) struct cmdline *cl,
7483                         __attribute__((unused)) void *data)
7484 {
7485         struct cmd_set_xstats_hide_zero_result *res;
7486         uint16_t on_off = 0;
7487
7488         res = parsed_result;
7489         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7490         set_xstats_hide_zero(on_off);
7491 }
7492
7493 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7494         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7495                                  keyword, "set");
7496 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7497         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7498                                  name, "xstats-hide-zero");
7499 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7500         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7501                                  on_off, "on#off");
7502
7503 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7504         .f = cmd_set_xstats_hide_zero_parsed,
7505         .data = NULL,
7506         .help_str = "set xstats-hide-zero on|off",
7507         .tokens = {
7508                 (void *)&cmd_set_xstats_hide_zero_keyword,
7509                 (void *)&cmd_set_xstats_hide_zero_name,
7510                 (void *)&cmd_set_xstats_hide_zero_on_off,
7511                 NULL,
7512         },
7513 };
7514
7515 /* *** CONFIGURE UNICAST HASH TABLE *** */
7516 struct cmd_set_uc_hash_table {
7517         cmdline_fixed_string_t set;
7518         cmdline_fixed_string_t port;
7519         portid_t port_id;
7520         cmdline_fixed_string_t what;
7521         struct ether_addr address;
7522         cmdline_fixed_string_t mode;
7523 };
7524
7525 static void
7526 cmd_set_uc_hash_parsed(void *parsed_result,
7527                        __attribute__((unused)) struct cmdline *cl,
7528                        __attribute__((unused)) void *data)
7529 {
7530         int ret=0;
7531         struct cmd_set_uc_hash_table *res = parsed_result;
7532
7533         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7534
7535         if (strcmp(res->what, "uta") == 0)
7536                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7537                                                 &res->address,(uint8_t)is_on);
7538         if (ret < 0)
7539                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7540
7541 }
7542
7543 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7544         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7545                                  set, "set");
7546 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7547         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7548                                  port, "port");
7549 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7550         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7551                               port_id, UINT16);
7552 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7553         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7554                                  what, "uta");
7555 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7556         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7557                                 address);
7558 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7559         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7560                                  mode, "on#off");
7561
7562 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7563         .f = cmd_set_uc_hash_parsed,
7564         .data = NULL,
7565         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7566         .tokens = {
7567                 (void *)&cmd_set_uc_hash_set,
7568                 (void *)&cmd_set_uc_hash_port,
7569                 (void *)&cmd_set_uc_hash_portid,
7570                 (void *)&cmd_set_uc_hash_what,
7571                 (void *)&cmd_set_uc_hash_mac,
7572                 (void *)&cmd_set_uc_hash_mode,
7573                 NULL,
7574         },
7575 };
7576
7577 struct cmd_set_uc_all_hash_table {
7578         cmdline_fixed_string_t set;
7579         cmdline_fixed_string_t port;
7580         portid_t port_id;
7581         cmdline_fixed_string_t what;
7582         cmdline_fixed_string_t value;
7583         cmdline_fixed_string_t mode;
7584 };
7585
7586 static void
7587 cmd_set_uc_all_hash_parsed(void *parsed_result,
7588                        __attribute__((unused)) struct cmdline *cl,
7589                        __attribute__((unused)) void *data)
7590 {
7591         int ret=0;
7592         struct cmd_set_uc_all_hash_table *res = parsed_result;
7593
7594         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7595
7596         if ((strcmp(res->what, "uta") == 0) &&
7597                 (strcmp(res->value, "all") == 0))
7598                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7599         if (ret < 0)
7600                 printf("bad unicast hash table parameter,"
7601                         "return code = %d \n", ret);
7602 }
7603
7604 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7605         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7606                                  set, "set");
7607 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7608         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7609                                  port, "port");
7610 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7611         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7612                               port_id, UINT16);
7613 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7614         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7615                                  what, "uta");
7616 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7617         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7618                                 value,"all");
7619 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7620         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7621                                  mode, "on#off");
7622
7623 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7624         .f = cmd_set_uc_all_hash_parsed,
7625         .data = NULL,
7626         .help_str = "set port <port_id> uta all on|off",
7627         .tokens = {
7628                 (void *)&cmd_set_uc_all_hash_set,
7629                 (void *)&cmd_set_uc_all_hash_port,
7630                 (void *)&cmd_set_uc_all_hash_portid,
7631                 (void *)&cmd_set_uc_all_hash_what,
7632                 (void *)&cmd_set_uc_all_hash_value,
7633                 (void *)&cmd_set_uc_all_hash_mode,
7634                 NULL,
7635         },
7636 };
7637
7638 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7639 struct cmd_set_vf_macvlan_filter {
7640         cmdline_fixed_string_t set;
7641         cmdline_fixed_string_t port;
7642         portid_t port_id;
7643         cmdline_fixed_string_t vf;
7644         uint8_t vf_id;
7645         struct ether_addr address;
7646         cmdline_fixed_string_t filter_type;
7647         cmdline_fixed_string_t mode;
7648 };
7649
7650 static void
7651 cmd_set_vf_macvlan_parsed(void *parsed_result,
7652                        __attribute__((unused)) struct cmdline *cl,
7653                        __attribute__((unused)) void *data)
7654 {
7655         int is_on, ret = 0;
7656         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7657         struct rte_eth_mac_filter filter;
7658
7659         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7660
7661         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7662
7663         /* set VF MAC filter */
7664         filter.is_vf = 1;
7665
7666         /* set VF ID */
7667         filter.dst_id = res->vf_id;
7668
7669         if (!strcmp(res->filter_type, "exact-mac"))
7670                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7671         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7672                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7673         else if (!strcmp(res->filter_type, "hashmac"))
7674                 filter.filter_type = RTE_MAC_HASH_MATCH;
7675         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7676                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7677
7678         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7679
7680         if (is_on)
7681                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7682                                         RTE_ETH_FILTER_MACVLAN,
7683                                         RTE_ETH_FILTER_ADD,
7684                                          &filter);
7685         else
7686                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7687                                         RTE_ETH_FILTER_MACVLAN,
7688                                         RTE_ETH_FILTER_DELETE,
7689                                         &filter);
7690
7691         if (ret < 0)
7692                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7693
7694 }
7695
7696 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7697         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7698                                  set, "set");
7699 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7700         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7701                                  port, "port");
7702 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7703         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7704                               port_id, UINT16);
7705 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7706         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7707                                  vf, "vf");
7708 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7709         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7710                                 vf_id, UINT8);
7711 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7712         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7713                                 address);
7714 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7715         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7716                                 filter_type, "exact-mac#exact-mac-vlan"
7717                                 "#hashmac#hashmac-vlan");
7718 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7719         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7720                                  mode, "on#off");
7721
7722 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7723         .f = cmd_set_vf_macvlan_parsed,
7724         .data = NULL,
7725         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7726                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7727                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7728                 "hash match rule: hash match of MAC and exact match of VLAN",
7729         .tokens = {
7730                 (void *)&cmd_set_vf_macvlan_set,
7731                 (void *)&cmd_set_vf_macvlan_port,
7732                 (void *)&cmd_set_vf_macvlan_portid,
7733                 (void *)&cmd_set_vf_macvlan_vf,
7734                 (void *)&cmd_set_vf_macvlan_vf_id,
7735                 (void *)&cmd_set_vf_macvlan_mac,
7736                 (void *)&cmd_set_vf_macvlan_filter_type,
7737                 (void *)&cmd_set_vf_macvlan_mode,
7738                 NULL,
7739         },
7740 };
7741
7742 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7743 struct cmd_set_vf_traffic {
7744         cmdline_fixed_string_t set;
7745         cmdline_fixed_string_t port;
7746         portid_t port_id;
7747         cmdline_fixed_string_t vf;
7748         uint8_t vf_id;
7749         cmdline_fixed_string_t what;
7750         cmdline_fixed_string_t mode;
7751 };
7752
7753 static void
7754 cmd_set_vf_traffic_parsed(void *parsed_result,
7755                        __attribute__((unused)) struct cmdline *cl,
7756                        __attribute__((unused)) void *data)
7757 {
7758         struct cmd_set_vf_traffic *res = parsed_result;
7759         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7760         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7761
7762         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7763 }
7764
7765 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7766         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7767                                  set, "set");
7768 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7769         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7770                                  port, "port");
7771 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7772         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7773                               port_id, UINT16);
7774 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7775         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7776                                  vf, "vf");
7777 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7778         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7779                               vf_id, UINT8);
7780 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7781         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7782                                  what, "tx#rx");
7783 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7784         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7785                                  mode, "on#off");
7786
7787 cmdline_parse_inst_t cmd_set_vf_traffic = {
7788         .f = cmd_set_vf_traffic_parsed,
7789         .data = NULL,
7790         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7791         .tokens = {
7792                 (void *)&cmd_setvf_traffic_set,
7793                 (void *)&cmd_setvf_traffic_port,
7794                 (void *)&cmd_setvf_traffic_portid,
7795                 (void *)&cmd_setvf_traffic_vf,
7796                 (void *)&cmd_setvf_traffic_vfid,
7797                 (void *)&cmd_setvf_traffic_what,
7798                 (void *)&cmd_setvf_traffic_mode,
7799                 NULL,
7800         },
7801 };
7802
7803 /* *** CONFIGURE VF RECEIVE MODE *** */
7804 struct cmd_set_vf_rxmode {
7805         cmdline_fixed_string_t set;
7806         cmdline_fixed_string_t port;
7807         portid_t port_id;
7808         cmdline_fixed_string_t vf;
7809         uint8_t vf_id;
7810         cmdline_fixed_string_t what;
7811         cmdline_fixed_string_t mode;
7812         cmdline_fixed_string_t on;
7813 };
7814
7815 static void
7816 cmd_set_vf_rxmode_parsed(void *parsed_result,
7817                        __attribute__((unused)) struct cmdline *cl,
7818                        __attribute__((unused)) void *data)
7819 {
7820         int ret = -ENOTSUP;
7821         uint16_t rx_mode = 0;
7822         struct cmd_set_vf_rxmode *res = parsed_result;
7823
7824         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7825         if (!strcmp(res->what,"rxmode")) {
7826                 if (!strcmp(res->mode, "AUPE"))
7827                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7828                 else if (!strcmp(res->mode, "ROPE"))
7829                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7830                 else if (!strcmp(res->mode, "BAM"))
7831                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7832                 else if (!strncmp(res->mode, "MPE",3))
7833                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7834         }
7835
7836         RTE_SET_USED(is_on);
7837
7838 #ifdef RTE_LIBRTE_IXGBE_PMD
7839         if (ret == -ENOTSUP)
7840                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7841                                                   rx_mode, (uint8_t)is_on);
7842 #endif
7843 #ifdef RTE_LIBRTE_BNXT_PMD
7844         if (ret == -ENOTSUP)
7845                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7846                                                  rx_mode, (uint8_t)is_on);
7847 #endif
7848         if (ret < 0)
7849                 printf("bad VF receive mode parameter, return code = %d \n",
7850                 ret);
7851 }
7852
7853 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7854         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7855                                  set, "set");
7856 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7857         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7858                                  port, "port");
7859 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7860         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7861                               port_id, UINT16);
7862 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7863         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7864                                  vf, "vf");
7865 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7866         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7867                               vf_id, UINT8);
7868 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7869         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7870                                  what, "rxmode");
7871 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7872         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7873                                  mode, "AUPE#ROPE#BAM#MPE");
7874 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7875         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7876                                  on, "on#off");
7877
7878 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7879         .f = cmd_set_vf_rxmode_parsed,
7880         .data = NULL,
7881         .help_str = "set port <port_id> vf <vf_id> rxmode "
7882                 "AUPE|ROPE|BAM|MPE on|off",
7883         .tokens = {
7884                 (void *)&cmd_set_vf_rxmode_set,
7885                 (void *)&cmd_set_vf_rxmode_port,
7886                 (void *)&cmd_set_vf_rxmode_portid,
7887                 (void *)&cmd_set_vf_rxmode_vf,
7888                 (void *)&cmd_set_vf_rxmode_vfid,
7889                 (void *)&cmd_set_vf_rxmode_what,
7890                 (void *)&cmd_set_vf_rxmode_mode,
7891                 (void *)&cmd_set_vf_rxmode_on,
7892                 NULL,
7893         },
7894 };
7895
7896 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7897 struct cmd_vf_mac_addr_result {
7898         cmdline_fixed_string_t mac_addr_cmd;
7899         cmdline_fixed_string_t what;
7900         cmdline_fixed_string_t port;
7901         uint16_t port_num;
7902         cmdline_fixed_string_t vf;
7903         uint8_t vf_num;
7904         struct ether_addr address;
7905 };
7906
7907 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7908                 __attribute__((unused)) struct cmdline *cl,
7909                 __attribute__((unused)) void *data)
7910 {
7911         struct cmd_vf_mac_addr_result *res = parsed_result;
7912         int ret = -ENOTSUP;
7913
7914         if (strcmp(res->what, "add") != 0)
7915                 return;
7916
7917 #ifdef RTE_LIBRTE_I40E_PMD
7918         if (ret == -ENOTSUP)
7919                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7920                                                    &res->address);
7921 #endif
7922 #ifdef RTE_LIBRTE_BNXT_PMD
7923         if (ret == -ENOTSUP)
7924                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7925                                                 res->vf_num);
7926 #endif
7927
7928         if(ret < 0)
7929                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7930
7931 }
7932
7933 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7934         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7935                                 mac_addr_cmd,"mac_addr");
7936 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7937         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7938                                 what,"add");
7939 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7940         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7941                                 port,"port");
7942 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7943         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7944                                 port_num, UINT16);
7945 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7946         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7947                                 vf,"vf");
7948 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7949         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7950                                 vf_num, UINT8);
7951 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7952         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7953                                 address);
7954
7955 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7956         .f = cmd_vf_mac_addr_parsed,
7957         .data = (void *)0,
7958         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7959                 "Add MAC address filtering for a VF on port_id",
7960         .tokens = {
7961                 (void *)&cmd_vf_mac_addr_cmd,
7962                 (void *)&cmd_vf_mac_addr_what,
7963                 (void *)&cmd_vf_mac_addr_port,
7964                 (void *)&cmd_vf_mac_addr_portnum,
7965                 (void *)&cmd_vf_mac_addr_vf,
7966                 (void *)&cmd_vf_mac_addr_vfnum,
7967                 (void *)&cmd_vf_mac_addr_addr,
7968                 NULL,
7969         },
7970 };
7971
7972 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7973 struct cmd_vf_rx_vlan_filter {
7974         cmdline_fixed_string_t rx_vlan;
7975         cmdline_fixed_string_t what;
7976         uint16_t vlan_id;
7977         cmdline_fixed_string_t port;
7978         portid_t port_id;
7979         cmdline_fixed_string_t vf;
7980         uint64_t vf_mask;
7981 };
7982
7983 static void
7984 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7985                           __attribute__((unused)) struct cmdline *cl,
7986                           __attribute__((unused)) void *data)
7987 {
7988         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7989         int ret = -ENOTSUP;
7990
7991         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7992
7993 #ifdef RTE_LIBRTE_IXGBE_PMD
7994         if (ret == -ENOTSUP)
7995                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7996                                 res->vlan_id, res->vf_mask, is_add);
7997 #endif
7998 #ifdef RTE_LIBRTE_I40E_PMD
7999         if (ret == -ENOTSUP)
8000                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8001                                 res->vlan_id, res->vf_mask, is_add);
8002 #endif
8003 #ifdef RTE_LIBRTE_BNXT_PMD
8004         if (ret == -ENOTSUP)
8005                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8006                                 res->vlan_id, res->vf_mask, is_add);
8007 #endif
8008
8009         switch (ret) {
8010         case 0:
8011                 break;
8012         case -EINVAL:
8013                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8014                                 res->vlan_id, res->vf_mask);
8015                 break;
8016         case -ENODEV:
8017                 printf("invalid port_id %d\n", res->port_id);
8018                 break;
8019         case -ENOTSUP:
8020                 printf("function not implemented or supported\n");
8021                 break;
8022         default:
8023                 printf("programming error: (%s)\n", strerror(-ret));
8024         }
8025 }
8026
8027 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8028         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8029                                  rx_vlan, "rx_vlan");
8030 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8031         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8032                                  what, "add#rm");
8033 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8034         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8035                               vlan_id, UINT16);
8036 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8037         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8038                                  port, "port");
8039 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8040         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8041                               port_id, UINT16);
8042 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8043         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8044                                  vf, "vf");
8045 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8046         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8047                               vf_mask, UINT64);
8048
8049 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8050         .f = cmd_vf_rx_vlan_filter_parsed,
8051         .data = NULL,
8052         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8053                 "(vf_mask = hexadecimal VF mask)",
8054         .tokens = {
8055                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8056                 (void *)&cmd_vf_rx_vlan_filter_what,
8057                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8058                 (void *)&cmd_vf_rx_vlan_filter_port,
8059                 (void *)&cmd_vf_rx_vlan_filter_portid,
8060                 (void *)&cmd_vf_rx_vlan_filter_vf,
8061                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8062                 NULL,
8063         },
8064 };
8065
8066 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8067 struct cmd_queue_rate_limit_result {
8068         cmdline_fixed_string_t set;
8069         cmdline_fixed_string_t port;
8070         uint16_t port_num;
8071         cmdline_fixed_string_t queue;
8072         uint8_t queue_num;
8073         cmdline_fixed_string_t rate;
8074         uint16_t rate_num;
8075 };
8076
8077 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8078                 __attribute__((unused)) struct cmdline *cl,
8079                 __attribute__((unused)) void *data)
8080 {
8081         struct cmd_queue_rate_limit_result *res = parsed_result;
8082         int ret = 0;
8083
8084         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8085                 && (strcmp(res->queue, "queue") == 0)
8086                 && (strcmp(res->rate, "rate") == 0))
8087                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8088                                         res->rate_num);
8089         if (ret < 0)
8090                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8091
8092 }
8093
8094 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8095         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8096                                 set, "set");
8097 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8098         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8099                                 port, "port");
8100 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8101         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8102                                 port_num, UINT16);
8103 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8104         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8105                                 queue, "queue");
8106 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8107         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8108                                 queue_num, UINT8);
8109 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8110         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8111                                 rate, "rate");
8112 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8113         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8114                                 rate_num, UINT16);
8115
8116 cmdline_parse_inst_t cmd_queue_rate_limit = {
8117         .f = cmd_queue_rate_limit_parsed,
8118         .data = (void *)0,
8119         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8120                 "Set rate limit for a queue on port_id",
8121         .tokens = {
8122                 (void *)&cmd_queue_rate_limit_set,
8123                 (void *)&cmd_queue_rate_limit_port,
8124                 (void *)&cmd_queue_rate_limit_portnum,
8125                 (void *)&cmd_queue_rate_limit_queue,
8126                 (void *)&cmd_queue_rate_limit_queuenum,
8127                 (void *)&cmd_queue_rate_limit_rate,
8128                 (void *)&cmd_queue_rate_limit_ratenum,
8129                 NULL,
8130         },
8131 };
8132
8133 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8134 struct cmd_vf_rate_limit_result {
8135         cmdline_fixed_string_t set;
8136         cmdline_fixed_string_t port;
8137         uint16_t port_num;
8138         cmdline_fixed_string_t vf;
8139         uint8_t vf_num;
8140         cmdline_fixed_string_t rate;
8141         uint16_t rate_num;
8142         cmdline_fixed_string_t q_msk;
8143         uint64_t q_msk_val;
8144 };
8145
8146 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8147                 __attribute__((unused)) struct cmdline *cl,
8148                 __attribute__((unused)) void *data)
8149 {
8150         struct cmd_vf_rate_limit_result *res = parsed_result;
8151         int ret = 0;
8152
8153         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8154                 && (strcmp(res->vf, "vf") == 0)
8155                 && (strcmp(res->rate, "rate") == 0)
8156                 && (strcmp(res->q_msk, "queue_mask") == 0))
8157                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8158                                         res->rate_num, res->q_msk_val);
8159         if (ret < 0)
8160                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8161
8162 }
8163
8164 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8165         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8166                                 set, "set");
8167 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8168         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8169                                 port, "port");
8170 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8171         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8172                                 port_num, UINT16);
8173 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8174         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8175                                 vf, "vf");
8176 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8177         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8178                                 vf_num, UINT8);
8179 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8180         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8181                                 rate, "rate");
8182 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8183         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8184                                 rate_num, UINT16);
8185 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8186         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8187                                 q_msk, "queue_mask");
8188 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8189         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8190                                 q_msk_val, UINT64);
8191
8192 cmdline_parse_inst_t cmd_vf_rate_limit = {
8193         .f = cmd_vf_rate_limit_parsed,
8194         .data = (void *)0,
8195         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8196                 "queue_mask <queue_mask_value>: "
8197                 "Set rate limit for queues of VF on port_id",
8198         .tokens = {
8199                 (void *)&cmd_vf_rate_limit_set,
8200                 (void *)&cmd_vf_rate_limit_port,
8201                 (void *)&cmd_vf_rate_limit_portnum,
8202                 (void *)&cmd_vf_rate_limit_vf,
8203                 (void *)&cmd_vf_rate_limit_vfnum,
8204                 (void *)&cmd_vf_rate_limit_rate,
8205                 (void *)&cmd_vf_rate_limit_ratenum,
8206                 (void *)&cmd_vf_rate_limit_q_msk,
8207                 (void *)&cmd_vf_rate_limit_q_msk_val,
8208                 NULL,
8209         },
8210 };
8211
8212 /* *** ADD TUNNEL FILTER OF A PORT *** */
8213 struct cmd_tunnel_filter_result {
8214         cmdline_fixed_string_t cmd;
8215         cmdline_fixed_string_t what;
8216         portid_t port_id;
8217         struct ether_addr outer_mac;
8218         struct ether_addr inner_mac;
8219         cmdline_ipaddr_t ip_value;
8220         uint16_t inner_vlan;
8221         cmdline_fixed_string_t tunnel_type;
8222         cmdline_fixed_string_t filter_type;
8223         uint32_t tenant_id;
8224         uint16_t queue_num;
8225 };
8226
8227 static void
8228 cmd_tunnel_filter_parsed(void *parsed_result,
8229                           __attribute__((unused)) struct cmdline *cl,
8230                           __attribute__((unused)) void *data)
8231 {
8232         struct cmd_tunnel_filter_result *res = parsed_result;
8233         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8234         int ret = 0;
8235
8236         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8237
8238         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8239         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8240         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8241
8242         if (res->ip_value.family == AF_INET) {
8243                 tunnel_filter_conf.ip_addr.ipv4_addr =
8244                         res->ip_value.addr.ipv4.s_addr;
8245                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8246         } else {
8247                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8248                         &(res->ip_value.addr.ipv6),
8249                         sizeof(struct in6_addr));
8250                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8251         }
8252
8253         if (!strcmp(res->filter_type, "imac-ivlan"))
8254                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8255         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8256                 tunnel_filter_conf.filter_type =
8257                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8258         else if (!strcmp(res->filter_type, "imac-tenid"))
8259                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8260         else if (!strcmp(res->filter_type, "imac"))
8261                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8262         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8263                 tunnel_filter_conf.filter_type =
8264                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8265         else if (!strcmp(res->filter_type, "oip"))
8266                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8267         else if (!strcmp(res->filter_type, "iip"))
8268                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8269         else {
8270                 printf("The filter type is not supported");
8271                 return;
8272         }
8273
8274         if (!strcmp(res->tunnel_type, "vxlan"))
8275                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8276         else if (!strcmp(res->tunnel_type, "nvgre"))
8277                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8278         else if (!strcmp(res->tunnel_type, "ipingre"))
8279                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8280         else {
8281                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8282                 return;
8283         }
8284
8285         tunnel_filter_conf.tenant_id = res->tenant_id;
8286         tunnel_filter_conf.queue_id = res->queue_num;
8287         if (!strcmp(res->what, "add"))
8288                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8289                                         RTE_ETH_FILTER_TUNNEL,
8290                                         RTE_ETH_FILTER_ADD,
8291                                         &tunnel_filter_conf);
8292         else
8293                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8294                                         RTE_ETH_FILTER_TUNNEL,
8295                                         RTE_ETH_FILTER_DELETE,
8296                                         &tunnel_filter_conf);
8297         if (ret < 0)
8298                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8299                                 strerror(-ret));
8300
8301 }
8302 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8303         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8304         cmd, "tunnel_filter");
8305 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8306         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8307         what, "add#rm");
8308 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8309         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8310         port_id, UINT16);
8311 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8312         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8313         outer_mac);
8314 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8315         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8316         inner_mac);
8317 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8318         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8319         inner_vlan, UINT16);
8320 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8321         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8322         ip_value);
8323 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8324         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8325         tunnel_type, "vxlan#nvgre#ipingre");
8326
8327 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8328         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8329         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8330                 "imac#omac-imac-tenid");
8331 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8332         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8333         tenant_id, UINT32);
8334 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8335         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8336         queue_num, UINT16);
8337
8338 cmdline_parse_inst_t cmd_tunnel_filter = {
8339         .f = cmd_tunnel_filter_parsed,
8340         .data = (void *)0,
8341         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8342                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8343                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8344                 "<queue_id>: Add/Rm tunnel filter of a port",
8345         .tokens = {
8346                 (void *)&cmd_tunnel_filter_cmd,
8347                 (void *)&cmd_tunnel_filter_what,
8348                 (void *)&cmd_tunnel_filter_port_id,
8349                 (void *)&cmd_tunnel_filter_outer_mac,
8350                 (void *)&cmd_tunnel_filter_inner_mac,
8351                 (void *)&cmd_tunnel_filter_ip_value,
8352                 (void *)&cmd_tunnel_filter_innner_vlan,
8353                 (void *)&cmd_tunnel_filter_tunnel_type,
8354                 (void *)&cmd_tunnel_filter_filter_type,
8355                 (void *)&cmd_tunnel_filter_tenant_id,
8356                 (void *)&cmd_tunnel_filter_queue_num,
8357                 NULL,
8358         },
8359 };
8360
8361 /* *** CONFIGURE TUNNEL UDP PORT *** */
8362 struct cmd_tunnel_udp_config {
8363         cmdline_fixed_string_t cmd;
8364         cmdline_fixed_string_t what;
8365         uint16_t udp_port;
8366         portid_t port_id;
8367 };
8368
8369 static void
8370 cmd_tunnel_udp_config_parsed(void *parsed_result,
8371                           __attribute__((unused)) struct cmdline *cl,
8372                           __attribute__((unused)) void *data)
8373 {
8374         struct cmd_tunnel_udp_config *res = parsed_result;
8375         struct rte_eth_udp_tunnel tunnel_udp;
8376         int ret;
8377
8378         tunnel_udp.udp_port = res->udp_port;
8379
8380         if (!strcmp(res->cmd, "rx_vxlan_port"))
8381                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8382
8383         if (!strcmp(res->what, "add"))
8384                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8385                                                       &tunnel_udp);
8386         else
8387                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8388                                                          &tunnel_udp);
8389
8390         if (ret < 0)
8391                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8392 }
8393
8394 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8395         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8396                                 cmd, "rx_vxlan_port");
8397 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8398         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8399                                 what, "add#rm");
8400 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8401         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8402                                 udp_port, UINT16);
8403 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8404         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8405                                 port_id, UINT16);
8406
8407 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8408         .f = cmd_tunnel_udp_config_parsed,
8409         .data = (void *)0,
8410         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8411                 "Add/Remove a tunneling UDP port filter",
8412         .tokens = {
8413                 (void *)&cmd_tunnel_udp_config_cmd,
8414                 (void *)&cmd_tunnel_udp_config_what,
8415                 (void *)&cmd_tunnel_udp_config_udp_port,
8416                 (void *)&cmd_tunnel_udp_config_port_id,
8417                 NULL,
8418         },
8419 };
8420
8421 /* *** GLOBAL CONFIG *** */
8422 struct cmd_global_config_result {
8423         cmdline_fixed_string_t cmd;
8424         portid_t port_id;
8425         cmdline_fixed_string_t cfg_type;
8426         uint8_t len;
8427 };
8428
8429 static void
8430 cmd_global_config_parsed(void *parsed_result,
8431                          __attribute__((unused)) struct cmdline *cl,
8432                          __attribute__((unused)) void *data)
8433 {
8434         struct cmd_global_config_result *res = parsed_result;
8435         struct rte_eth_global_cfg conf;
8436         int ret;
8437
8438         memset(&conf, 0, sizeof(conf));
8439         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8440         conf.cfg.gre_key_len = res->len;
8441         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8442                                       RTE_ETH_FILTER_SET, &conf);
8443         if (ret != 0)
8444                 printf("Global config error\n");
8445 }
8446
8447 cmdline_parse_token_string_t cmd_global_config_cmd =
8448         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8449                 "global_config");
8450 cmdline_parse_token_num_t cmd_global_config_port_id =
8451         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8452                                UINT16);
8453 cmdline_parse_token_string_t cmd_global_config_type =
8454         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8455                 cfg_type, "gre-key-len");
8456 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8457         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8458                 len, UINT8);
8459
8460 cmdline_parse_inst_t cmd_global_config = {
8461         .f = cmd_global_config_parsed,
8462         .data = (void *)NULL,
8463         .help_str = "global_config <port_id> gre-key-len <key_len>",
8464         .tokens = {
8465                 (void *)&cmd_global_config_cmd,
8466                 (void *)&cmd_global_config_port_id,
8467                 (void *)&cmd_global_config_type,
8468                 (void *)&cmd_global_config_gre_key_len,
8469                 NULL,
8470         },
8471 };
8472
8473 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8474 struct cmd_set_mirror_mask_result {
8475         cmdline_fixed_string_t set;
8476         cmdline_fixed_string_t port;
8477         portid_t port_id;
8478         cmdline_fixed_string_t mirror;
8479         uint8_t rule_id;
8480         cmdline_fixed_string_t what;
8481         cmdline_fixed_string_t value;
8482         cmdline_fixed_string_t dstpool;
8483         uint8_t dstpool_id;
8484         cmdline_fixed_string_t on;
8485 };
8486
8487 cmdline_parse_token_string_t cmd_mirror_mask_set =
8488         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8489                                 set, "set");
8490 cmdline_parse_token_string_t cmd_mirror_mask_port =
8491         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8492                                 port, "port");
8493 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8494         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8495                                 port_id, UINT16);
8496 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8497         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8498                                 mirror, "mirror-rule");
8499 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8500         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8501                                 rule_id, UINT8);
8502 cmdline_parse_token_string_t cmd_mirror_mask_what =
8503         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8504                                 what, "pool-mirror-up#pool-mirror-down"
8505                                       "#vlan-mirror");
8506 cmdline_parse_token_string_t cmd_mirror_mask_value =
8507         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8508                                 value, NULL);
8509 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8510         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8511                                 dstpool, "dst-pool");
8512 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8513         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8514                                 dstpool_id, UINT8);
8515 cmdline_parse_token_string_t cmd_mirror_mask_on =
8516         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8517                                 on, "on#off");
8518
8519 static void
8520 cmd_set_mirror_mask_parsed(void *parsed_result,
8521                        __attribute__((unused)) struct cmdline *cl,
8522                        __attribute__((unused)) void *data)
8523 {
8524         int ret,nb_item,i;
8525         struct cmd_set_mirror_mask_result *res = parsed_result;
8526         struct rte_eth_mirror_conf mr_conf;
8527
8528         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8529
8530         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8531
8532         mr_conf.dst_pool = res->dstpool_id;
8533
8534         if (!strcmp(res->what, "pool-mirror-up")) {
8535                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8536                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8537         } else if (!strcmp(res->what, "pool-mirror-down")) {
8538                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8539                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8540         } else if (!strcmp(res->what, "vlan-mirror")) {
8541                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8542                 nb_item = parse_item_list(res->value, "vlan",
8543                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8544                 if (nb_item <= 0)
8545                         return;
8546
8547                 for (i = 0; i < nb_item; i++) {
8548                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8549                                 printf("Invalid vlan_id: must be < 4096\n");
8550                                 return;
8551                         }
8552
8553                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8554                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8555                 }
8556         }
8557
8558         if (!strcmp(res->on, "on"))
8559                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8560                                                 res->rule_id, 1);
8561         else
8562                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8563                                                 res->rule_id, 0);
8564         if (ret < 0)
8565                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8566 }
8567
8568 cmdline_parse_inst_t cmd_set_mirror_mask = {
8569                 .f = cmd_set_mirror_mask_parsed,
8570                 .data = NULL,
8571                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8572                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8573                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8574                 .tokens = {
8575                         (void *)&cmd_mirror_mask_set,
8576                         (void *)&cmd_mirror_mask_port,
8577                         (void *)&cmd_mirror_mask_portid,
8578                         (void *)&cmd_mirror_mask_mirror,
8579                         (void *)&cmd_mirror_mask_ruleid,
8580                         (void *)&cmd_mirror_mask_what,
8581                         (void *)&cmd_mirror_mask_value,
8582                         (void *)&cmd_mirror_mask_dstpool,
8583                         (void *)&cmd_mirror_mask_poolid,
8584                         (void *)&cmd_mirror_mask_on,
8585                         NULL,
8586                 },
8587 };
8588
8589 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8590 struct cmd_set_mirror_link_result {
8591         cmdline_fixed_string_t set;
8592         cmdline_fixed_string_t port;
8593         portid_t port_id;
8594         cmdline_fixed_string_t mirror;
8595         uint8_t rule_id;
8596         cmdline_fixed_string_t what;
8597         cmdline_fixed_string_t dstpool;
8598         uint8_t dstpool_id;
8599         cmdline_fixed_string_t on;
8600 };
8601
8602 cmdline_parse_token_string_t cmd_mirror_link_set =
8603         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8604                                  set, "set");
8605 cmdline_parse_token_string_t cmd_mirror_link_port =
8606         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8607                                 port, "port");
8608 cmdline_parse_token_num_t cmd_mirror_link_portid =
8609         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8610                                 port_id, UINT16);
8611 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8612         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8613                                 mirror, "mirror-rule");
8614 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8615         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8616                             rule_id, UINT8);
8617 cmdline_parse_token_string_t cmd_mirror_link_what =
8618         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8619                                 what, "uplink-mirror#downlink-mirror");
8620 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8621         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8622                                 dstpool, "dst-pool");
8623 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8624         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8625                                 dstpool_id, UINT8);
8626 cmdline_parse_token_string_t cmd_mirror_link_on =
8627         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8628                                 on, "on#off");
8629
8630 static void
8631 cmd_set_mirror_link_parsed(void *parsed_result,
8632                        __attribute__((unused)) struct cmdline *cl,
8633                        __attribute__((unused)) void *data)
8634 {
8635         int ret;
8636         struct cmd_set_mirror_link_result *res = parsed_result;
8637         struct rte_eth_mirror_conf mr_conf;
8638
8639         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8640         if (!strcmp(res->what, "uplink-mirror"))
8641                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8642         else
8643                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8644
8645         mr_conf.dst_pool = res->dstpool_id;
8646
8647         if (!strcmp(res->on, "on"))
8648                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8649                                                 res->rule_id, 1);
8650         else
8651                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8652                                                 res->rule_id, 0);
8653
8654         /* check the return value and print it if is < 0 */
8655         if (ret < 0)
8656                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8657
8658 }
8659
8660 cmdline_parse_inst_t cmd_set_mirror_link = {
8661                 .f = cmd_set_mirror_link_parsed,
8662                 .data = NULL,
8663                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8664                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8665                 .tokens = {
8666                         (void *)&cmd_mirror_link_set,
8667                         (void *)&cmd_mirror_link_port,
8668                         (void *)&cmd_mirror_link_portid,
8669                         (void *)&cmd_mirror_link_mirror,
8670                         (void *)&cmd_mirror_link_ruleid,
8671                         (void *)&cmd_mirror_link_what,
8672                         (void *)&cmd_mirror_link_dstpool,
8673                         (void *)&cmd_mirror_link_poolid,
8674                         (void *)&cmd_mirror_link_on,
8675                         NULL,
8676                 },
8677 };
8678
8679 /* *** RESET VM MIRROR RULE *** */
8680 struct cmd_rm_mirror_rule_result {
8681         cmdline_fixed_string_t reset;
8682         cmdline_fixed_string_t port;
8683         portid_t port_id;
8684         cmdline_fixed_string_t mirror;
8685         uint8_t rule_id;
8686 };
8687
8688 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8689         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8690                                  reset, "reset");
8691 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8692         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8693                                 port, "port");
8694 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8695         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8696                                 port_id, UINT16);
8697 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8698         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8699                                 mirror, "mirror-rule");
8700 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8701         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8702                                 rule_id, UINT8);
8703
8704 static void
8705 cmd_reset_mirror_rule_parsed(void *parsed_result,
8706                        __attribute__((unused)) struct cmdline *cl,
8707                        __attribute__((unused)) void *data)
8708 {
8709         int ret;
8710         struct cmd_set_mirror_link_result *res = parsed_result;
8711         /* check rule_id */
8712         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8713         if(ret < 0)
8714                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8715 }
8716
8717 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8718                 .f = cmd_reset_mirror_rule_parsed,
8719                 .data = NULL,
8720                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8721                 .tokens = {
8722                         (void *)&cmd_rm_mirror_rule_reset,
8723                         (void *)&cmd_rm_mirror_rule_port,
8724                         (void *)&cmd_rm_mirror_rule_portid,
8725                         (void *)&cmd_rm_mirror_rule_mirror,
8726                         (void *)&cmd_rm_mirror_rule_ruleid,
8727                         NULL,
8728                 },
8729 };
8730
8731 /* ******************************************************************************** */
8732
8733 struct cmd_dump_result {
8734         cmdline_fixed_string_t dump;
8735 };
8736
8737 static void
8738 dump_struct_sizes(void)
8739 {
8740 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8741         DUMP_SIZE(struct rte_mbuf);
8742         DUMP_SIZE(struct rte_mempool);
8743         DUMP_SIZE(struct rte_ring);
8744 #undef DUMP_SIZE
8745 }
8746
8747 static void cmd_dump_parsed(void *parsed_result,
8748                             __attribute__((unused)) struct cmdline *cl,
8749                             __attribute__((unused)) void *data)
8750 {
8751         struct cmd_dump_result *res = parsed_result;
8752
8753         if (!strcmp(res->dump, "dump_physmem"))
8754                 rte_dump_physmem_layout(stdout);
8755         else if (!strcmp(res->dump, "dump_memzone"))
8756                 rte_memzone_dump(stdout);
8757         else if (!strcmp(res->dump, "dump_struct_sizes"))
8758                 dump_struct_sizes();
8759         else if (!strcmp(res->dump, "dump_ring"))
8760                 rte_ring_list_dump(stdout);
8761         else if (!strcmp(res->dump, "dump_mempool"))
8762                 rte_mempool_list_dump(stdout);
8763         else if (!strcmp(res->dump, "dump_devargs"))
8764                 rte_devargs_dump(stdout);
8765         else if (!strcmp(res->dump, "dump_log_types"))
8766                 rte_log_dump(stdout);
8767 }
8768
8769 cmdline_parse_token_string_t cmd_dump_dump =
8770         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8771                 "dump_physmem#"
8772                 "dump_memzone#"
8773                 "dump_struct_sizes#"
8774                 "dump_ring#"
8775                 "dump_mempool#"
8776                 "dump_devargs#"
8777                 "dump_log_types");
8778
8779 cmdline_parse_inst_t cmd_dump = {
8780         .f = cmd_dump_parsed,  /* function to call */
8781         .data = NULL,      /* 2nd arg of func */
8782         .help_str = "Dump status",
8783         .tokens = {        /* token list, NULL terminated */
8784                 (void *)&cmd_dump_dump,
8785                 NULL,
8786         },
8787 };
8788
8789 /* ******************************************************************************** */
8790
8791 struct cmd_dump_one_result {
8792         cmdline_fixed_string_t dump;
8793         cmdline_fixed_string_t name;
8794 };
8795
8796 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8797                                 __attribute__((unused)) void *data)
8798 {
8799         struct cmd_dump_one_result *res = parsed_result;
8800
8801         if (!strcmp(res->dump, "dump_ring")) {
8802                 struct rte_ring *r;
8803                 r = rte_ring_lookup(res->name);
8804                 if (r == NULL) {
8805                         cmdline_printf(cl, "Cannot find ring\n");
8806                         return;
8807                 }
8808                 rte_ring_dump(stdout, r);
8809         } else if (!strcmp(res->dump, "dump_mempool")) {
8810                 struct rte_mempool *mp;
8811                 mp = rte_mempool_lookup(res->name);
8812                 if (mp == NULL) {
8813                         cmdline_printf(cl, "Cannot find mempool\n");
8814                         return;
8815                 }
8816                 rte_mempool_dump(stdout, mp);
8817         }
8818 }
8819
8820 cmdline_parse_token_string_t cmd_dump_one_dump =
8821         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8822                                  "dump_ring#dump_mempool");
8823
8824 cmdline_parse_token_string_t cmd_dump_one_name =
8825         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8826
8827 cmdline_parse_inst_t cmd_dump_one = {
8828         .f = cmd_dump_one_parsed,  /* function to call */
8829         .data = NULL,      /* 2nd arg of func */
8830         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8831         .tokens = {        /* token list, NULL terminated */
8832                 (void *)&cmd_dump_one_dump,
8833                 (void *)&cmd_dump_one_name,
8834                 NULL,
8835         },
8836 };
8837
8838 /* *** Add/Del syn filter *** */
8839 struct cmd_syn_filter_result {
8840         cmdline_fixed_string_t filter;
8841         portid_t port_id;
8842         cmdline_fixed_string_t ops;
8843         cmdline_fixed_string_t priority;
8844         cmdline_fixed_string_t high;
8845         cmdline_fixed_string_t queue;
8846         uint16_t queue_id;
8847 };
8848
8849 static void
8850 cmd_syn_filter_parsed(void *parsed_result,
8851                         __attribute__((unused)) struct cmdline *cl,
8852                         __attribute__((unused)) void *data)
8853 {
8854         struct cmd_syn_filter_result *res = parsed_result;
8855         struct rte_eth_syn_filter syn_filter;
8856         int ret = 0;
8857
8858         ret = rte_eth_dev_filter_supported(res->port_id,
8859                                         RTE_ETH_FILTER_SYN);
8860         if (ret < 0) {
8861                 printf("syn filter is not supported on port %u.\n",
8862                                 res->port_id);
8863                 return;
8864         }
8865
8866         memset(&syn_filter, 0, sizeof(syn_filter));
8867
8868         if (!strcmp(res->ops, "add")) {
8869                 if (!strcmp(res->high, "high"))
8870                         syn_filter.hig_pri = 1;
8871                 else
8872                         syn_filter.hig_pri = 0;
8873
8874                 syn_filter.queue = res->queue_id;
8875                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8876                                                 RTE_ETH_FILTER_SYN,
8877                                                 RTE_ETH_FILTER_ADD,
8878                                                 &syn_filter);
8879         } else
8880                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8881                                                 RTE_ETH_FILTER_SYN,
8882                                                 RTE_ETH_FILTER_DELETE,
8883                                                 &syn_filter);
8884
8885         if (ret < 0)
8886                 printf("syn filter programming error: (%s)\n",
8887                                 strerror(-ret));
8888 }
8889
8890 cmdline_parse_token_string_t cmd_syn_filter_filter =
8891         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8892         filter, "syn_filter");
8893 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8894         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8895         port_id, UINT16);
8896 cmdline_parse_token_string_t cmd_syn_filter_ops =
8897         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8898         ops, "add#del");
8899 cmdline_parse_token_string_t cmd_syn_filter_priority =
8900         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8901                                 priority, "priority");
8902 cmdline_parse_token_string_t cmd_syn_filter_high =
8903         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8904                                 high, "high#low");
8905 cmdline_parse_token_string_t cmd_syn_filter_queue =
8906         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8907                                 queue, "queue");
8908 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8909         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8910                                 queue_id, UINT16);
8911
8912 cmdline_parse_inst_t cmd_syn_filter = {
8913         .f = cmd_syn_filter_parsed,
8914         .data = NULL,
8915         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8916                 "<queue_id>: Add/Delete syn filter",
8917         .tokens = {
8918                 (void *)&cmd_syn_filter_filter,
8919                 (void *)&cmd_syn_filter_port_id,
8920                 (void *)&cmd_syn_filter_ops,
8921                 (void *)&cmd_syn_filter_priority,
8922                 (void *)&cmd_syn_filter_high,
8923                 (void *)&cmd_syn_filter_queue,
8924                 (void *)&cmd_syn_filter_queue_id,
8925                 NULL,
8926         },
8927 };
8928
8929 /* *** queue region set *** */
8930 struct cmd_queue_region_result {
8931         cmdline_fixed_string_t set;
8932         cmdline_fixed_string_t port;
8933         portid_t port_id;
8934         cmdline_fixed_string_t cmd;
8935         cmdline_fixed_string_t region;
8936         uint8_t  region_id;
8937         cmdline_fixed_string_t queue_start_index;
8938         uint8_t  queue_id;
8939         cmdline_fixed_string_t queue_num;
8940         uint8_t  queue_num_value;
8941 };
8942
8943 static void
8944 cmd_queue_region_parsed(void *parsed_result,
8945                         __attribute__((unused)) struct cmdline *cl,
8946                         __attribute__((unused)) void *data)
8947 {
8948         struct cmd_queue_region_result *res = parsed_result;
8949         int ret = -ENOTSUP;
8950 #ifdef RTE_LIBRTE_I40E_PMD
8951         struct rte_pmd_i40e_queue_region_conf region_conf;
8952         enum rte_pmd_i40e_queue_region_op op_type;
8953 #endif
8954
8955         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8956                 return;
8957
8958 #ifdef RTE_LIBRTE_I40E_PMD
8959         memset(&region_conf, 0, sizeof(region_conf));
8960         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8961         region_conf.region_id = res->region_id;
8962         region_conf.queue_num = res->queue_num_value;
8963         region_conf.queue_start_index = res->queue_id;
8964
8965         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8966                                 op_type, &region_conf);
8967 #endif
8968
8969         switch (ret) {
8970         case 0:
8971                 break;
8972         case -ENOTSUP:
8973                 printf("function not implemented or supported\n");
8974                 break;
8975         default:
8976                 printf("queue region config error: (%s)\n", strerror(-ret));
8977         }
8978 }
8979
8980 cmdline_parse_token_string_t cmd_queue_region_set =
8981 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8982                 set, "set");
8983 cmdline_parse_token_string_t cmd_queue_region_port =
8984         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8985 cmdline_parse_token_num_t cmd_queue_region_port_id =
8986         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8987                                 port_id, UINT16);
8988 cmdline_parse_token_string_t cmd_queue_region_cmd =
8989         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8990                                  cmd, "queue-region");
8991 cmdline_parse_token_string_t cmd_queue_region_id =
8992         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8993                                 region, "region_id");
8994 cmdline_parse_token_num_t cmd_queue_region_index =
8995         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8996                                 region_id, UINT8);
8997 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8998         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8999                                 queue_start_index, "queue_start_index");
9000 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9001         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9002                                 queue_id, UINT8);
9003 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9004         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9005                                 queue_num, "queue_num");
9006 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9007         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9008                                 queue_num_value, UINT8);
9009
9010 cmdline_parse_inst_t cmd_queue_region = {
9011         .f = cmd_queue_region_parsed,
9012         .data = NULL,
9013         .help_str = "set port <port_id> queue-region region_id <value> "
9014                 "queue_start_index <value> queue_num <value>: Set a queue region",
9015         .tokens = {
9016                 (void *)&cmd_queue_region_set,
9017                 (void *)&cmd_queue_region_port,
9018                 (void *)&cmd_queue_region_port_id,
9019                 (void *)&cmd_queue_region_cmd,
9020                 (void *)&cmd_queue_region_id,
9021                 (void *)&cmd_queue_region_index,
9022                 (void *)&cmd_queue_region_queue_start_index,
9023                 (void *)&cmd_queue_region_queue_id,
9024                 (void *)&cmd_queue_region_queue_num,
9025                 (void *)&cmd_queue_region_queue_num_value,
9026                 NULL,
9027         },
9028 };
9029
9030 /* *** queue region and flowtype set *** */
9031 struct cmd_region_flowtype_result {
9032         cmdline_fixed_string_t set;
9033         cmdline_fixed_string_t port;
9034         portid_t port_id;
9035         cmdline_fixed_string_t cmd;
9036         cmdline_fixed_string_t region;
9037         uint8_t  region_id;
9038         cmdline_fixed_string_t flowtype;
9039         uint8_t  flowtype_id;
9040 };
9041
9042 static void
9043 cmd_region_flowtype_parsed(void *parsed_result,
9044                         __attribute__((unused)) struct cmdline *cl,
9045                         __attribute__((unused)) void *data)
9046 {
9047         struct cmd_region_flowtype_result *res = parsed_result;
9048         int ret = -ENOTSUP;
9049 #ifdef RTE_LIBRTE_I40E_PMD
9050         struct rte_pmd_i40e_queue_region_conf region_conf;
9051         enum rte_pmd_i40e_queue_region_op op_type;
9052 #endif
9053
9054         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9055                 return;
9056
9057 #ifdef RTE_LIBRTE_I40E_PMD
9058         memset(&region_conf, 0, sizeof(region_conf));
9059
9060         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9061         region_conf.region_id = res->region_id;
9062         region_conf.hw_flowtype = res->flowtype_id;
9063
9064         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9065                         op_type, &region_conf);
9066 #endif
9067
9068         switch (ret) {
9069         case 0:
9070                 break;
9071         case -ENOTSUP:
9072                 printf("function not implemented or supported\n");
9073                 break;
9074         default:
9075                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9076         }
9077 }
9078
9079 cmdline_parse_token_string_t cmd_region_flowtype_set =
9080 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9081                                 set, "set");
9082 cmdline_parse_token_string_t cmd_region_flowtype_port =
9083         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9084                                 port, "port");
9085 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9086         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9087                                 port_id, UINT16);
9088 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9089         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9090                                 cmd, "queue-region");
9091 cmdline_parse_token_string_t cmd_region_flowtype_index =
9092         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9093                                 region, "region_id");
9094 cmdline_parse_token_num_t cmd_region_flowtype_id =
9095         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9096                                 region_id, UINT8);
9097 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9098         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9099                                 flowtype, "flowtype");
9100 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9101         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9102                                 flowtype_id, UINT8);
9103 cmdline_parse_inst_t cmd_region_flowtype = {
9104         .f = cmd_region_flowtype_parsed,
9105         .data = NULL,
9106         .help_str = "set port <port_id> queue-region region_id <value> "
9107                 "flowtype <value>: Set a flowtype region index",
9108         .tokens = {
9109                 (void *)&cmd_region_flowtype_set,
9110                 (void *)&cmd_region_flowtype_port,
9111                 (void *)&cmd_region_flowtype_port_index,
9112                 (void *)&cmd_region_flowtype_cmd,
9113                 (void *)&cmd_region_flowtype_index,
9114                 (void *)&cmd_region_flowtype_id,
9115                 (void *)&cmd_region_flowtype_flow_index,
9116                 (void *)&cmd_region_flowtype_flow_id,
9117                 NULL,
9118         },
9119 };
9120
9121 /* *** User Priority (UP) to queue region (region_id) set *** */
9122 struct cmd_user_priority_region_result {
9123         cmdline_fixed_string_t set;
9124         cmdline_fixed_string_t port;
9125         portid_t port_id;
9126         cmdline_fixed_string_t cmd;
9127         cmdline_fixed_string_t user_priority;
9128         uint8_t  user_priority_id;
9129         cmdline_fixed_string_t region;
9130         uint8_t  region_id;
9131 };
9132
9133 static void
9134 cmd_user_priority_region_parsed(void *parsed_result,
9135                         __attribute__((unused)) struct cmdline *cl,
9136                         __attribute__((unused)) void *data)
9137 {
9138         struct cmd_user_priority_region_result *res = parsed_result;
9139         int ret = -ENOTSUP;
9140 #ifdef RTE_LIBRTE_I40E_PMD
9141         struct rte_pmd_i40e_queue_region_conf region_conf;
9142         enum rte_pmd_i40e_queue_region_op op_type;
9143 #endif
9144
9145         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9146                 return;
9147
9148 #ifdef RTE_LIBRTE_I40E_PMD
9149         memset(&region_conf, 0, sizeof(region_conf));
9150         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9151         region_conf.user_priority = res->user_priority_id;
9152         region_conf.region_id = res->region_id;
9153
9154         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9155                                 op_type, &region_conf);
9156 #endif
9157
9158         switch (ret) {
9159         case 0:
9160                 break;
9161         case -ENOTSUP:
9162                 printf("function not implemented or supported\n");
9163                 break;
9164         default:
9165                 printf("user_priority region config error: (%s)\n",
9166                                 strerror(-ret));
9167         }
9168 }
9169
9170 cmdline_parse_token_string_t cmd_user_priority_region_set =
9171         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9172                                 set, "set");
9173 cmdline_parse_token_string_t cmd_user_priority_region_port =
9174         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9175                                 port, "port");
9176 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9177         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9178                                 port_id, UINT16);
9179 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9180         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9181                                 cmd, "queue-region");
9182 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9183         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9184                                 user_priority, "UP");
9185 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9186         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9187                                 user_priority_id, UINT8);
9188 cmdline_parse_token_string_t cmd_user_priority_region_region =
9189         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9190                                 region, "region_id");
9191 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9192         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9193                                 region_id, UINT8);
9194
9195 cmdline_parse_inst_t cmd_user_priority_region = {
9196         .f = cmd_user_priority_region_parsed,
9197         .data = NULL,
9198         .help_str = "set port <port_id> queue-region UP <value> "
9199                 "region_id <value>: Set the mapping of User Priority (UP) "
9200                 "to queue region (region_id) ",
9201         .tokens = {
9202                 (void *)&cmd_user_priority_region_set,
9203                 (void *)&cmd_user_priority_region_port,
9204                 (void *)&cmd_user_priority_region_port_index,
9205                 (void *)&cmd_user_priority_region_cmd,
9206                 (void *)&cmd_user_priority_region_UP,
9207                 (void *)&cmd_user_priority_region_UP_id,
9208                 (void *)&cmd_user_priority_region_region,
9209                 (void *)&cmd_user_priority_region_region_id,
9210                 NULL,
9211         },
9212 };
9213
9214 /* *** flush all queue region related configuration *** */
9215 struct cmd_flush_queue_region_result {
9216         cmdline_fixed_string_t set;
9217         cmdline_fixed_string_t port;
9218         portid_t port_id;
9219         cmdline_fixed_string_t cmd;
9220         cmdline_fixed_string_t flush;
9221         cmdline_fixed_string_t what;
9222 };
9223
9224 static void
9225 cmd_flush_queue_region_parsed(void *parsed_result,
9226                         __attribute__((unused)) struct cmdline *cl,
9227                         __attribute__((unused)) void *data)
9228 {
9229         struct cmd_flush_queue_region_result *res = parsed_result;
9230         int ret = -ENOTSUP;
9231 #ifdef RTE_LIBRTE_I40E_PMD
9232         struct rte_pmd_i40e_queue_region_conf region_conf;
9233         enum rte_pmd_i40e_queue_region_op op_type;
9234 #endif
9235
9236         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9237                 return;
9238
9239 #ifdef RTE_LIBRTE_I40E_PMD
9240         memset(&region_conf, 0, sizeof(region_conf));
9241
9242         if (strcmp(res->what, "on") == 0)
9243                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9244         else
9245                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9246
9247         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9248                                 op_type, &region_conf);
9249 #endif
9250
9251         switch (ret) {
9252         case 0:
9253                 break;
9254         case -ENOTSUP:
9255                 printf("function not implemented or supported\n");
9256                 break;
9257         default:
9258                 printf("queue region config flush error: (%s)\n",
9259                                 strerror(-ret));
9260         }
9261 }
9262
9263 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9264         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9265                                 set, "set");
9266 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9267         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9268                                 port, "port");
9269 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9270         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9271                                 port_id, UINT16);
9272 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9273         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9274                                 cmd, "queue-region");
9275 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9276         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9277                                 flush, "flush");
9278 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9279         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9280                                 what, "on#off");
9281
9282 cmdline_parse_inst_t cmd_flush_queue_region = {
9283         .f = cmd_flush_queue_region_parsed,
9284         .data = NULL,
9285         .help_str = "set port <port_id> queue-region flush on|off"
9286                 ": flush all queue region related configuration",
9287         .tokens = {
9288                 (void *)&cmd_flush_queue_region_set,
9289                 (void *)&cmd_flush_queue_region_port,
9290                 (void *)&cmd_flush_queue_region_port_index,
9291                 (void *)&cmd_flush_queue_region_cmd,
9292                 (void *)&cmd_flush_queue_region_flush,
9293                 (void *)&cmd_flush_queue_region_what,
9294                 NULL,
9295         },
9296 };
9297
9298 /* *** get all queue region related configuration info *** */
9299 struct cmd_show_queue_region_info {
9300         cmdline_fixed_string_t show;
9301         cmdline_fixed_string_t port;
9302         portid_t port_id;
9303         cmdline_fixed_string_t cmd;
9304 };
9305
9306 static void
9307 cmd_show_queue_region_info_parsed(void *parsed_result,
9308                         __attribute__((unused)) struct cmdline *cl,
9309                         __attribute__((unused)) void *data)
9310 {
9311         struct cmd_show_queue_region_info *res = parsed_result;
9312         int ret = -ENOTSUP;
9313 #ifdef RTE_LIBRTE_I40E_PMD
9314         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9315         enum rte_pmd_i40e_queue_region_op op_type;
9316 #endif
9317
9318         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9319                 return;
9320
9321 #ifdef RTE_LIBRTE_I40E_PMD
9322         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9323
9324         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9325
9326         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9327                                         op_type, &rte_pmd_regions);
9328
9329         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9330 #endif
9331
9332         switch (ret) {
9333         case 0:
9334                 break;
9335         case -ENOTSUP:
9336                 printf("function not implemented or supported\n");
9337                 break;
9338         default:
9339                 printf("queue region config info show error: (%s)\n",
9340                                 strerror(-ret));
9341         }
9342 }
9343
9344 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9345 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9346                                 show, "show");
9347 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9348         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9349                                 port, "port");
9350 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9351         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9352                                 port_id, UINT16);
9353 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9354         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9355                                 cmd, "queue-region");
9356
9357 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9358         .f = cmd_show_queue_region_info_parsed,
9359         .data = NULL,
9360         .help_str = "show port <port_id> queue-region"
9361                 ": show all queue region related configuration info",
9362         .tokens = {
9363                 (void *)&cmd_show_queue_region_info_get,
9364                 (void *)&cmd_show_queue_region_info_port,
9365                 (void *)&cmd_show_queue_region_info_port_index,
9366                 (void *)&cmd_show_queue_region_info_cmd,
9367                 NULL,
9368         },
9369 };
9370
9371 /* *** ADD/REMOVE A 2tuple FILTER *** */
9372 struct cmd_2tuple_filter_result {
9373         cmdline_fixed_string_t filter;
9374         portid_t port_id;
9375         cmdline_fixed_string_t ops;
9376         cmdline_fixed_string_t dst_port;
9377         uint16_t dst_port_value;
9378         cmdline_fixed_string_t protocol;
9379         uint8_t protocol_value;
9380         cmdline_fixed_string_t mask;
9381         uint8_t  mask_value;
9382         cmdline_fixed_string_t tcp_flags;
9383         uint8_t tcp_flags_value;
9384         cmdline_fixed_string_t priority;
9385         uint8_t  priority_value;
9386         cmdline_fixed_string_t queue;
9387         uint16_t  queue_id;
9388 };
9389
9390 static void
9391 cmd_2tuple_filter_parsed(void *parsed_result,
9392                         __attribute__((unused)) struct cmdline *cl,
9393                         __attribute__((unused)) void *data)
9394 {
9395         struct rte_eth_ntuple_filter filter;
9396         struct cmd_2tuple_filter_result *res = parsed_result;
9397         int ret = 0;
9398
9399         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9400         if (ret < 0) {
9401                 printf("ntuple filter is not supported on port %u.\n",
9402                         res->port_id);
9403                 return;
9404         }
9405
9406         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9407
9408         filter.flags = RTE_2TUPLE_FLAGS;
9409         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9410         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9411         filter.proto = res->protocol_value;
9412         filter.priority = res->priority_value;
9413         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9414                 printf("nonzero tcp_flags is only meaningful"
9415                         " when protocol is TCP.\n");
9416                 return;
9417         }
9418         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9419                 printf("invalid TCP flags.\n");
9420                 return;
9421         }
9422
9423         if (res->tcp_flags_value != 0) {
9424                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9425                 filter.tcp_flags = res->tcp_flags_value;
9426         }
9427
9428         /* need convert to big endian. */
9429         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9430         filter.queue = res->queue_id;
9431
9432         if (!strcmp(res->ops, "add"))
9433                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9434                                 RTE_ETH_FILTER_NTUPLE,
9435                                 RTE_ETH_FILTER_ADD,
9436                                 &filter);
9437         else
9438                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9439                                 RTE_ETH_FILTER_NTUPLE,
9440                                 RTE_ETH_FILTER_DELETE,
9441                                 &filter);
9442         if (ret < 0)
9443                 printf("2tuple filter programming error: (%s)\n",
9444                         strerror(-ret));
9445
9446 }
9447
9448 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9449         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9450                                  filter, "2tuple_filter");
9451 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9452         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9453                                 port_id, UINT16);
9454 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9455         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9456                                  ops, "add#del");
9457 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9458         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9459                                 dst_port, "dst_port");
9460 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9461         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9462                                 dst_port_value, UINT16);
9463 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9464         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9465                                 protocol, "protocol");
9466 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9467         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9468                                 protocol_value, UINT8);
9469 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9470         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9471                                 mask, "mask");
9472 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9473         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9474                                 mask_value, INT8);
9475 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9476         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9477                                 tcp_flags, "tcp_flags");
9478 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9479         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9480                                 tcp_flags_value, UINT8);
9481 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9482         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9483                                 priority, "priority");
9484 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9485         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9486                                 priority_value, UINT8);
9487 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9488         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9489                                 queue, "queue");
9490 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9491         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9492                                 queue_id, UINT16);
9493
9494 cmdline_parse_inst_t cmd_2tuple_filter = {
9495         .f = cmd_2tuple_filter_parsed,
9496         .data = NULL,
9497         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9498                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9499                 "<queue_id>: Add a 2tuple filter",
9500         .tokens = {
9501                 (void *)&cmd_2tuple_filter_filter,
9502                 (void *)&cmd_2tuple_filter_port_id,
9503                 (void *)&cmd_2tuple_filter_ops,
9504                 (void *)&cmd_2tuple_filter_dst_port,
9505                 (void *)&cmd_2tuple_filter_dst_port_value,
9506                 (void *)&cmd_2tuple_filter_protocol,
9507                 (void *)&cmd_2tuple_filter_protocol_value,
9508                 (void *)&cmd_2tuple_filter_mask,
9509                 (void *)&cmd_2tuple_filter_mask_value,
9510                 (void *)&cmd_2tuple_filter_tcp_flags,
9511                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9512                 (void *)&cmd_2tuple_filter_priority,
9513                 (void *)&cmd_2tuple_filter_priority_value,
9514                 (void *)&cmd_2tuple_filter_queue,
9515                 (void *)&cmd_2tuple_filter_queue_id,
9516                 NULL,
9517         },
9518 };
9519
9520 /* *** ADD/REMOVE A 5tuple FILTER *** */
9521 struct cmd_5tuple_filter_result {
9522         cmdline_fixed_string_t filter;
9523         portid_t port_id;
9524         cmdline_fixed_string_t ops;
9525         cmdline_fixed_string_t dst_ip;
9526         cmdline_ipaddr_t dst_ip_value;
9527         cmdline_fixed_string_t src_ip;
9528         cmdline_ipaddr_t src_ip_value;
9529         cmdline_fixed_string_t dst_port;
9530         uint16_t dst_port_value;
9531         cmdline_fixed_string_t src_port;
9532         uint16_t src_port_value;
9533         cmdline_fixed_string_t protocol;
9534         uint8_t protocol_value;
9535         cmdline_fixed_string_t mask;
9536         uint8_t  mask_value;
9537         cmdline_fixed_string_t tcp_flags;
9538         uint8_t tcp_flags_value;
9539         cmdline_fixed_string_t priority;
9540         uint8_t  priority_value;
9541         cmdline_fixed_string_t queue;
9542         uint16_t  queue_id;
9543 };
9544
9545 static void
9546 cmd_5tuple_filter_parsed(void *parsed_result,
9547                         __attribute__((unused)) struct cmdline *cl,
9548                         __attribute__((unused)) void *data)
9549 {
9550         struct rte_eth_ntuple_filter filter;
9551         struct cmd_5tuple_filter_result *res = parsed_result;
9552         int ret = 0;
9553
9554         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9555         if (ret < 0) {
9556                 printf("ntuple filter is not supported on port %u.\n",
9557                         res->port_id);
9558                 return;
9559         }
9560
9561         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9562
9563         filter.flags = RTE_5TUPLE_FLAGS;
9564         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9565         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9566         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9567         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9568         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9569         filter.proto = res->protocol_value;
9570         filter.priority = res->priority_value;
9571         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9572                 printf("nonzero tcp_flags is only meaningful"
9573                         " when protocol is TCP.\n");
9574                 return;
9575         }
9576         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9577                 printf("invalid TCP flags.\n");
9578                 return;
9579         }
9580
9581         if (res->tcp_flags_value != 0) {
9582                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9583                 filter.tcp_flags = res->tcp_flags_value;
9584         }
9585
9586         if (res->dst_ip_value.family == AF_INET)
9587                 /* no need to convert, already big endian. */
9588                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9589         else {
9590                 if (filter.dst_ip_mask == 0) {
9591                         printf("can not support ipv6 involved compare.\n");
9592                         return;
9593                 }
9594                 filter.dst_ip = 0;
9595         }
9596
9597         if (res->src_ip_value.family == AF_INET)
9598                 /* no need to convert, already big endian. */
9599                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9600         else {
9601                 if (filter.src_ip_mask == 0) {
9602                         printf("can not support ipv6 involved compare.\n");
9603                         return;
9604                 }
9605                 filter.src_ip = 0;
9606         }
9607         /* need convert to big endian. */
9608         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9609         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9610         filter.queue = res->queue_id;
9611
9612         if (!strcmp(res->ops, "add"))
9613                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9614                                 RTE_ETH_FILTER_NTUPLE,
9615                                 RTE_ETH_FILTER_ADD,
9616                                 &filter);
9617         else
9618                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9619                                 RTE_ETH_FILTER_NTUPLE,
9620                                 RTE_ETH_FILTER_DELETE,
9621                                 &filter);
9622         if (ret < 0)
9623                 printf("5tuple filter programming error: (%s)\n",
9624                         strerror(-ret));
9625 }
9626
9627 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9628         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9629                                  filter, "5tuple_filter");
9630 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9631         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9632                                 port_id, UINT16);
9633 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9634         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9635                                  ops, "add#del");
9636 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9637         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9638                                 dst_ip, "dst_ip");
9639 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9640         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9641                                 dst_ip_value);
9642 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9643         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9644                                 src_ip, "src_ip");
9645 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9646         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9647                                 src_ip_value);
9648 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9649         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9650                                 dst_port, "dst_port");
9651 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9652         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9653                                 dst_port_value, UINT16);
9654 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9655         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9656                                 src_port, "src_port");
9657 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9658         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9659                                 src_port_value, UINT16);
9660 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9661         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9662                                 protocol, "protocol");
9663 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9664         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9665                                 protocol_value, UINT8);
9666 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9667         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9668                                 mask, "mask");
9669 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9670         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9671                                 mask_value, INT8);
9672 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9673         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9674                                 tcp_flags, "tcp_flags");
9675 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9676         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9677                                 tcp_flags_value, UINT8);
9678 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9679         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9680                                 priority, "priority");
9681 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9682         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9683                                 priority_value, UINT8);
9684 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9685         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9686                                 queue, "queue");
9687 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9688         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9689                                 queue_id, UINT16);
9690
9691 cmdline_parse_inst_t cmd_5tuple_filter = {
9692         .f = cmd_5tuple_filter_parsed,
9693         .data = NULL,
9694         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9695                 "src_ip <value> dst_port <value> src_port <value> "
9696                 "protocol <value>  mask <value> tcp_flags <value> "
9697                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9698         .tokens = {
9699                 (void *)&cmd_5tuple_filter_filter,
9700                 (void *)&cmd_5tuple_filter_port_id,
9701                 (void *)&cmd_5tuple_filter_ops,
9702                 (void *)&cmd_5tuple_filter_dst_ip,
9703                 (void *)&cmd_5tuple_filter_dst_ip_value,
9704                 (void *)&cmd_5tuple_filter_src_ip,
9705                 (void *)&cmd_5tuple_filter_src_ip_value,
9706                 (void *)&cmd_5tuple_filter_dst_port,
9707                 (void *)&cmd_5tuple_filter_dst_port_value,
9708                 (void *)&cmd_5tuple_filter_src_port,
9709                 (void *)&cmd_5tuple_filter_src_port_value,
9710                 (void *)&cmd_5tuple_filter_protocol,
9711                 (void *)&cmd_5tuple_filter_protocol_value,
9712                 (void *)&cmd_5tuple_filter_mask,
9713                 (void *)&cmd_5tuple_filter_mask_value,
9714                 (void *)&cmd_5tuple_filter_tcp_flags,
9715                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9716                 (void *)&cmd_5tuple_filter_priority,
9717                 (void *)&cmd_5tuple_filter_priority_value,
9718                 (void *)&cmd_5tuple_filter_queue,
9719                 (void *)&cmd_5tuple_filter_queue_id,
9720                 NULL,
9721         },
9722 };
9723
9724 /* *** ADD/REMOVE A flex FILTER *** */
9725 struct cmd_flex_filter_result {
9726         cmdline_fixed_string_t filter;
9727         cmdline_fixed_string_t ops;
9728         portid_t port_id;
9729         cmdline_fixed_string_t len;
9730         uint8_t len_value;
9731         cmdline_fixed_string_t bytes;
9732         cmdline_fixed_string_t bytes_value;
9733         cmdline_fixed_string_t mask;
9734         cmdline_fixed_string_t mask_value;
9735         cmdline_fixed_string_t priority;
9736         uint8_t priority_value;
9737         cmdline_fixed_string_t queue;
9738         uint16_t queue_id;
9739 };
9740
9741 static int xdigit2val(unsigned char c)
9742 {
9743         int val;
9744         if (isdigit(c))
9745                 val = c - '0';
9746         else if (isupper(c))
9747                 val = c - 'A' + 10;
9748         else
9749                 val = c - 'a' + 10;
9750         return val;
9751 }
9752
9753 static void
9754 cmd_flex_filter_parsed(void *parsed_result,
9755                           __attribute__((unused)) struct cmdline *cl,
9756                           __attribute__((unused)) void *data)
9757 {
9758         int ret = 0;
9759         struct rte_eth_flex_filter filter;
9760         struct cmd_flex_filter_result *res = parsed_result;
9761         char *bytes_ptr, *mask_ptr;
9762         uint16_t len, i, j = 0;
9763         char c;
9764         int val;
9765         uint8_t byte = 0;
9766
9767         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9768                 printf("the len exceed the max length 128\n");
9769                 return;
9770         }
9771         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9772         filter.len = res->len_value;
9773         filter.priority = res->priority_value;
9774         filter.queue = res->queue_id;
9775         bytes_ptr = res->bytes_value;
9776         mask_ptr = res->mask_value;
9777
9778          /* translate bytes string to array. */
9779         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9780                 (bytes_ptr[1] == 'X')))
9781                 bytes_ptr += 2;
9782         len = strnlen(bytes_ptr, res->len_value * 2);
9783         if (len == 0 || (len % 8 != 0)) {
9784                 printf("please check len and bytes input\n");
9785                 return;
9786         }
9787         for (i = 0; i < len; i++) {
9788                 c = bytes_ptr[i];
9789                 if (isxdigit(c) == 0) {
9790                         /* invalid characters. */
9791                         printf("invalid input\n");
9792                         return;
9793                 }
9794                 val = xdigit2val(c);
9795                 if (i % 2) {
9796                         byte |= val;
9797                         filter.bytes[j] = byte;
9798                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9799                         j++;
9800                         byte = 0;
9801                 } else
9802                         byte |= val << 4;
9803         }
9804         printf("\n");
9805          /* translate mask string to uint8_t array. */
9806         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9807                 (mask_ptr[1] == 'X')))
9808                 mask_ptr += 2;
9809         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9810         if (len == 0) {
9811                 printf("invalid input\n");
9812                 return;
9813         }
9814         j = 0;
9815         byte = 0;
9816         for (i = 0; i < len; i++) {
9817                 c = mask_ptr[i];
9818                 if (isxdigit(c) == 0) {
9819                         /* invalid characters. */
9820                         printf("invalid input\n");
9821                         return;
9822                 }
9823                 val = xdigit2val(c);
9824                 if (i % 2) {
9825                         byte |= val;
9826                         filter.mask[j] = byte;
9827                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9828                         j++;
9829                         byte = 0;
9830                 } else
9831                         byte |= val << 4;
9832         }
9833         printf("\n");
9834
9835         if (!strcmp(res->ops, "add"))
9836                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9837                                 RTE_ETH_FILTER_FLEXIBLE,
9838                                 RTE_ETH_FILTER_ADD,
9839                                 &filter);
9840         else
9841                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9842                                 RTE_ETH_FILTER_FLEXIBLE,
9843                                 RTE_ETH_FILTER_DELETE,
9844                                 &filter);
9845
9846         if (ret < 0)
9847                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9848 }
9849
9850 cmdline_parse_token_string_t cmd_flex_filter_filter =
9851         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9852                                 filter, "flex_filter");
9853 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9854         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9855                                 port_id, UINT16);
9856 cmdline_parse_token_string_t cmd_flex_filter_ops =
9857         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9858                                 ops, "add#del");
9859 cmdline_parse_token_string_t cmd_flex_filter_len =
9860         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9861                                 len, "len");
9862 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9863         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9864                                 len_value, UINT8);
9865 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9866         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9867                                 bytes, "bytes");
9868 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9869         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9870                                 bytes_value, NULL);
9871 cmdline_parse_token_string_t cmd_flex_filter_mask =
9872         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9873                                 mask, "mask");
9874 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9875         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9876                                 mask_value, NULL);
9877 cmdline_parse_token_string_t cmd_flex_filter_priority =
9878         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9879                                 priority, "priority");
9880 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9881         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9882                                 priority_value, UINT8);
9883 cmdline_parse_token_string_t cmd_flex_filter_queue =
9884         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9885                                 queue, "queue");
9886 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9887         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9888                                 queue_id, UINT16);
9889 cmdline_parse_inst_t cmd_flex_filter = {
9890         .f = cmd_flex_filter_parsed,
9891         .data = NULL,
9892         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9893                 "<value> mask <value> priority <value> queue <queue_id>: "
9894                 "Add/Del a flex filter",
9895         .tokens = {
9896                 (void *)&cmd_flex_filter_filter,
9897                 (void *)&cmd_flex_filter_port_id,
9898                 (void *)&cmd_flex_filter_ops,
9899                 (void *)&cmd_flex_filter_len,
9900                 (void *)&cmd_flex_filter_len_value,
9901                 (void *)&cmd_flex_filter_bytes,
9902                 (void *)&cmd_flex_filter_bytes_value,
9903                 (void *)&cmd_flex_filter_mask,
9904                 (void *)&cmd_flex_filter_mask_value,
9905                 (void *)&cmd_flex_filter_priority,
9906                 (void *)&cmd_flex_filter_priority_value,
9907                 (void *)&cmd_flex_filter_queue,
9908                 (void *)&cmd_flex_filter_queue_id,
9909                 NULL,
9910         },
9911 };
9912
9913 /* *** Filters Control *** */
9914
9915 /* *** deal with ethertype filter *** */
9916 struct cmd_ethertype_filter_result {
9917         cmdline_fixed_string_t filter;
9918         portid_t port_id;
9919         cmdline_fixed_string_t ops;
9920         cmdline_fixed_string_t mac;
9921         struct ether_addr mac_addr;
9922         cmdline_fixed_string_t ethertype;
9923         uint16_t ethertype_value;
9924         cmdline_fixed_string_t drop;
9925         cmdline_fixed_string_t queue;
9926         uint16_t  queue_id;
9927 };
9928
9929 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9930         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9931                                  filter, "ethertype_filter");
9932 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9933         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9934                               port_id, UINT16);
9935 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9936         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9937                                  ops, "add#del");
9938 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9939         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9940                                  mac, "mac_addr#mac_ignr");
9941 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9942         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9943                                      mac_addr);
9944 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9945         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9946                                  ethertype, "ethertype");
9947 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9948         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9949                               ethertype_value, UINT16);
9950 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9951         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9952                                  drop, "drop#fwd");
9953 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9954         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9955                                  queue, "queue");
9956 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9957         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9958                               queue_id, UINT16);
9959
9960 static void
9961 cmd_ethertype_filter_parsed(void *parsed_result,
9962                           __attribute__((unused)) struct cmdline *cl,
9963                           __attribute__((unused)) void *data)
9964 {
9965         struct cmd_ethertype_filter_result *res = parsed_result;
9966         struct rte_eth_ethertype_filter filter;
9967         int ret = 0;
9968
9969         ret = rte_eth_dev_filter_supported(res->port_id,
9970                         RTE_ETH_FILTER_ETHERTYPE);
9971         if (ret < 0) {
9972                 printf("ethertype filter is not supported on port %u.\n",
9973                         res->port_id);
9974                 return;
9975         }
9976
9977         memset(&filter, 0, sizeof(filter));
9978         if (!strcmp(res->mac, "mac_addr")) {
9979                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9980                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9981                         sizeof(struct ether_addr));
9982         }
9983         if (!strcmp(res->drop, "drop"))
9984                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9985         filter.ether_type = res->ethertype_value;
9986         filter.queue = res->queue_id;
9987
9988         if (!strcmp(res->ops, "add"))
9989                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9990                                 RTE_ETH_FILTER_ETHERTYPE,
9991                                 RTE_ETH_FILTER_ADD,
9992                                 &filter);
9993         else
9994                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9995                                 RTE_ETH_FILTER_ETHERTYPE,
9996                                 RTE_ETH_FILTER_DELETE,
9997                                 &filter);
9998         if (ret < 0)
9999                 printf("ethertype filter programming error: (%s)\n",
10000                         strerror(-ret));
10001 }
10002
10003 cmdline_parse_inst_t cmd_ethertype_filter = {
10004         .f = cmd_ethertype_filter_parsed,
10005         .data = NULL,
10006         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10007                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10008                 "Add or delete an ethertype filter entry",
10009         .tokens = {
10010                 (void *)&cmd_ethertype_filter_filter,
10011                 (void *)&cmd_ethertype_filter_port_id,
10012                 (void *)&cmd_ethertype_filter_ops,
10013                 (void *)&cmd_ethertype_filter_mac,
10014                 (void *)&cmd_ethertype_filter_mac_addr,
10015                 (void *)&cmd_ethertype_filter_ethertype,
10016                 (void *)&cmd_ethertype_filter_ethertype_value,
10017                 (void *)&cmd_ethertype_filter_drop,
10018                 (void *)&cmd_ethertype_filter_queue,
10019                 (void *)&cmd_ethertype_filter_queue_id,
10020                 NULL,
10021         },
10022 };
10023
10024 /* *** deal with flow director filter *** */
10025 struct cmd_flow_director_result {
10026         cmdline_fixed_string_t flow_director_filter;
10027         portid_t port_id;
10028         cmdline_fixed_string_t mode;
10029         cmdline_fixed_string_t mode_value;
10030         cmdline_fixed_string_t ops;
10031         cmdline_fixed_string_t flow;
10032         cmdline_fixed_string_t flow_type;
10033         cmdline_fixed_string_t ether;
10034         uint16_t ether_type;
10035         cmdline_fixed_string_t src;
10036         cmdline_ipaddr_t ip_src;
10037         uint16_t port_src;
10038         cmdline_fixed_string_t dst;
10039         cmdline_ipaddr_t ip_dst;
10040         uint16_t port_dst;
10041         cmdline_fixed_string_t verify_tag;
10042         uint32_t verify_tag_value;
10043         cmdline_fixed_string_t tos;
10044         uint8_t tos_value;
10045         cmdline_fixed_string_t proto;
10046         uint8_t proto_value;
10047         cmdline_fixed_string_t ttl;
10048         uint8_t ttl_value;
10049         cmdline_fixed_string_t vlan;
10050         uint16_t vlan_value;
10051         cmdline_fixed_string_t flexbytes;
10052         cmdline_fixed_string_t flexbytes_value;
10053         cmdline_fixed_string_t pf_vf;
10054         cmdline_fixed_string_t drop;
10055         cmdline_fixed_string_t queue;
10056         uint16_t  queue_id;
10057         cmdline_fixed_string_t fd_id;
10058         uint32_t  fd_id_value;
10059         cmdline_fixed_string_t mac;
10060         struct ether_addr mac_addr;
10061         cmdline_fixed_string_t tunnel;
10062         cmdline_fixed_string_t tunnel_type;
10063         cmdline_fixed_string_t tunnel_id;
10064         uint32_t tunnel_id_value;
10065         cmdline_fixed_string_t packet;
10066         char filepath[];
10067 };
10068
10069 static inline int
10070 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10071 {
10072         char s[256];
10073         const char *p, *p0 = q_arg;
10074         char *end;
10075         unsigned long int_fld;
10076         char *str_fld[max_num];
10077         int i;
10078         unsigned size;
10079         int ret = -1;
10080
10081         p = strchr(p0, '(');
10082         if (p == NULL)
10083                 return -1;
10084         ++p;
10085         p0 = strchr(p, ')');
10086         if (p0 == NULL)
10087                 return -1;
10088
10089         size = p0 - p;
10090         if (size >= sizeof(s))
10091                 return -1;
10092
10093         snprintf(s, sizeof(s), "%.*s", size, p);
10094         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10095         if (ret < 0 || ret > max_num)
10096                 return -1;
10097         for (i = 0; i < ret; i++) {
10098                 errno = 0;
10099                 int_fld = strtoul(str_fld[i], &end, 0);
10100                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10101                         return -1;
10102                 flexbytes[i] = (uint8_t)int_fld;
10103         }
10104         return ret;
10105 }
10106
10107 static uint16_t
10108 str2flowtype(char *string)
10109 {
10110         uint8_t i = 0;
10111         static const struct {
10112                 char str[32];
10113                 uint16_t type;
10114         } flowtype_str[] = {
10115                 {"raw", RTE_ETH_FLOW_RAW},
10116                 {"ipv4", RTE_ETH_FLOW_IPV4},
10117                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10118                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10119                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10120                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10121                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10122                 {"ipv6", RTE_ETH_FLOW_IPV6},
10123                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10124                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10125                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10126                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10127                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10128                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10129         };
10130
10131         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10132                 if (!strcmp(flowtype_str[i].str, string))
10133                         return flowtype_str[i].type;
10134         }
10135
10136         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10137                 return (uint16_t)atoi(string);
10138
10139         return RTE_ETH_FLOW_UNKNOWN;
10140 }
10141
10142 static enum rte_eth_fdir_tunnel_type
10143 str2fdir_tunneltype(char *string)
10144 {
10145         uint8_t i = 0;
10146
10147         static const struct {
10148                 char str[32];
10149                 enum rte_eth_fdir_tunnel_type type;
10150         } tunneltype_str[] = {
10151                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10152                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10153         };
10154
10155         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10156                 if (!strcmp(tunneltype_str[i].str, string))
10157                         return tunneltype_str[i].type;
10158         }
10159         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10160 }
10161
10162 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10163 do { \
10164         if ((ip_addr).family == AF_INET) \
10165                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10166         else { \
10167                 printf("invalid parameter.\n"); \
10168                 return; \
10169         } \
10170 } while (0)
10171
10172 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10173 do { \
10174         if ((ip_addr).family == AF_INET6) \
10175                 rte_memcpy(&(ip), \
10176                                  &((ip_addr).addr.ipv6), \
10177                                  sizeof(struct in6_addr)); \
10178         else { \
10179                 printf("invalid parameter.\n"); \
10180                 return; \
10181         } \
10182 } while (0)
10183
10184 static void
10185 cmd_flow_director_filter_parsed(void *parsed_result,
10186                           __attribute__((unused)) struct cmdline *cl,
10187                           __attribute__((unused)) void *data)
10188 {
10189         struct cmd_flow_director_result *res = parsed_result;
10190         struct rte_eth_fdir_filter entry;
10191         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10192         char *end;
10193         unsigned long vf_id;
10194         int ret = 0;
10195
10196         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10197         if (ret < 0) {
10198                 printf("flow director is not supported on port %u.\n",
10199                         res->port_id);
10200                 return;
10201         }
10202         memset(flexbytes, 0, sizeof(flexbytes));
10203         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10204
10205         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10206                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10207                         printf("Please set mode to MAC-VLAN.\n");
10208                         return;
10209                 }
10210         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10211                 if (strcmp(res->mode_value, "Tunnel")) {
10212                         printf("Please set mode to Tunnel.\n");
10213                         return;
10214                 }
10215         } else {
10216                 if (!strcmp(res->mode_value, "raw")) {
10217 #ifdef RTE_LIBRTE_I40E_PMD
10218                         struct rte_pmd_i40e_flow_type_mapping
10219                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10220                         struct rte_pmd_i40e_pkt_template_conf conf;
10221                         uint16_t flow_type = str2flowtype(res->flow_type);
10222                         uint16_t i, port = res->port_id;
10223                         uint8_t add;
10224
10225                         memset(&conf, 0, sizeof(conf));
10226
10227                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10228                                 printf("Invalid flow type specified.\n");
10229                                 return;
10230                         }
10231                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10232                                                                  mapping);
10233                         if (ret)
10234                                 return;
10235                         if (mapping[flow_type].pctype == 0ULL) {
10236                                 printf("Invalid flow type specified.\n");
10237                                 return;
10238                         }
10239                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10240                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10241                                         conf.input.pctype = i;
10242                                         break;
10243                                 }
10244                         }
10245
10246                         conf.input.packet = open_file(res->filepath,
10247                                                 &conf.input.length);
10248                         if (!conf.input.packet)
10249                                 return;
10250                         if (!strcmp(res->drop, "drop"))
10251                                 conf.action.behavior =
10252                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10253                         else
10254                                 conf.action.behavior =
10255                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10256                         conf.action.report_status =
10257                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10258                         conf.action.rx_queue = res->queue_id;
10259                         conf.soft_id = res->fd_id_value;
10260                         add  = strcmp(res->ops, "del") ? 1 : 0;
10261                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10262                                                                         &conf,
10263                                                                         add);
10264                         if (ret < 0)
10265                                 printf("flow director config error: (%s)\n",
10266                                        strerror(-ret));
10267                         close_file(conf.input.packet);
10268 #endif
10269                         return;
10270                 } else if (strcmp(res->mode_value, "IP")) {
10271                         printf("Please set mode to IP or raw.\n");
10272                         return;
10273                 }
10274                 entry.input.flow_type = str2flowtype(res->flow_type);
10275         }
10276
10277         ret = parse_flexbytes(res->flexbytes_value,
10278                                         flexbytes,
10279                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10280         if (ret < 0) {
10281                 printf("error: Cannot parse flexbytes input.\n");
10282                 return;
10283         }
10284
10285         switch (entry.input.flow_type) {
10286         case RTE_ETH_FLOW_FRAG_IPV4:
10287         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10288                 entry.input.flow.ip4_flow.proto = res->proto_value;
10289                 /* fall-through */
10290         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10291         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10292                 IPV4_ADDR_TO_UINT(res->ip_dst,
10293                         entry.input.flow.ip4_flow.dst_ip);
10294                 IPV4_ADDR_TO_UINT(res->ip_src,
10295                         entry.input.flow.ip4_flow.src_ip);
10296                 entry.input.flow.ip4_flow.tos = res->tos_value;
10297                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10298                 /* need convert to big endian. */
10299                 entry.input.flow.udp4_flow.dst_port =
10300                                 rte_cpu_to_be_16(res->port_dst);
10301                 entry.input.flow.udp4_flow.src_port =
10302                                 rte_cpu_to_be_16(res->port_src);
10303                 break;
10304         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10305                 IPV4_ADDR_TO_UINT(res->ip_dst,
10306                         entry.input.flow.sctp4_flow.ip.dst_ip);
10307                 IPV4_ADDR_TO_UINT(res->ip_src,
10308                         entry.input.flow.sctp4_flow.ip.src_ip);
10309                 entry.input.flow.ip4_flow.tos = res->tos_value;
10310                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10311                 /* need convert to big endian. */
10312                 entry.input.flow.sctp4_flow.dst_port =
10313                                 rte_cpu_to_be_16(res->port_dst);
10314                 entry.input.flow.sctp4_flow.src_port =
10315                                 rte_cpu_to_be_16(res->port_src);
10316                 entry.input.flow.sctp4_flow.verify_tag =
10317                                 rte_cpu_to_be_32(res->verify_tag_value);
10318                 break;
10319         case RTE_ETH_FLOW_FRAG_IPV6:
10320         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10321                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10322                 /* fall-through */
10323         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10324         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10325                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10326                         entry.input.flow.ipv6_flow.dst_ip);
10327                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10328                         entry.input.flow.ipv6_flow.src_ip);
10329                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10330                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10331                 /* need convert to big endian. */
10332                 entry.input.flow.udp6_flow.dst_port =
10333                                 rte_cpu_to_be_16(res->port_dst);
10334                 entry.input.flow.udp6_flow.src_port =
10335                                 rte_cpu_to_be_16(res->port_src);
10336                 break;
10337         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10338                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10339                         entry.input.flow.sctp6_flow.ip.dst_ip);
10340                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10341                         entry.input.flow.sctp6_flow.ip.src_ip);
10342                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10343                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10344                 /* need convert to big endian. */
10345                 entry.input.flow.sctp6_flow.dst_port =
10346                                 rte_cpu_to_be_16(res->port_dst);
10347                 entry.input.flow.sctp6_flow.src_port =
10348                                 rte_cpu_to_be_16(res->port_src);
10349                 entry.input.flow.sctp6_flow.verify_tag =
10350                                 rte_cpu_to_be_32(res->verify_tag_value);
10351                 break;
10352         case RTE_ETH_FLOW_L2_PAYLOAD:
10353                 entry.input.flow.l2_flow.ether_type =
10354                         rte_cpu_to_be_16(res->ether_type);
10355                 break;
10356         default:
10357                 break;
10358         }
10359
10360         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10361                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10362                                  &res->mac_addr,
10363                                  sizeof(struct ether_addr));
10364
10365         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10366                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10367                                  &res->mac_addr,
10368                                  sizeof(struct ether_addr));
10369                 entry.input.flow.tunnel_flow.tunnel_type =
10370                         str2fdir_tunneltype(res->tunnel_type);
10371                 entry.input.flow.tunnel_flow.tunnel_id =
10372                         rte_cpu_to_be_32(res->tunnel_id_value);
10373         }
10374
10375         rte_memcpy(entry.input.flow_ext.flexbytes,
10376                    flexbytes,
10377                    RTE_ETH_FDIR_MAX_FLEXLEN);
10378
10379         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10380
10381         entry.action.flex_off = 0;  /*use 0 by default */
10382         if (!strcmp(res->drop, "drop"))
10383                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10384         else
10385                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10386
10387         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10388             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10389                 if (!strcmp(res->pf_vf, "pf"))
10390                         entry.input.flow_ext.is_vf = 0;
10391                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10392                         struct rte_eth_dev_info dev_info;
10393
10394                         memset(&dev_info, 0, sizeof(dev_info));
10395                         rte_eth_dev_info_get(res->port_id, &dev_info);
10396                         errno = 0;
10397                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10398                         if (errno != 0 || *end != '\0' ||
10399                             vf_id >= dev_info.max_vfs) {
10400                                 printf("invalid parameter %s.\n", res->pf_vf);
10401                                 return;
10402                         }
10403                         entry.input.flow_ext.is_vf = 1;
10404                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10405                 } else {
10406                         printf("invalid parameter %s.\n", res->pf_vf);
10407                         return;
10408                 }
10409         }
10410
10411         /* set to report FD ID by default */
10412         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10413         entry.action.rx_queue = res->queue_id;
10414         entry.soft_id = res->fd_id_value;
10415         if (!strcmp(res->ops, "add"))
10416                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10417                                              RTE_ETH_FILTER_ADD, &entry);
10418         else if (!strcmp(res->ops, "del"))
10419                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10420                                              RTE_ETH_FILTER_DELETE, &entry);
10421         else
10422                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10423                                              RTE_ETH_FILTER_UPDATE, &entry);
10424         if (ret < 0)
10425                 printf("flow director programming error: (%s)\n",
10426                         strerror(-ret));
10427 }
10428
10429 cmdline_parse_token_string_t cmd_flow_director_filter =
10430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10431                                  flow_director_filter, "flow_director_filter");
10432 cmdline_parse_token_num_t cmd_flow_director_port_id =
10433         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10434                               port_id, UINT16);
10435 cmdline_parse_token_string_t cmd_flow_director_ops =
10436         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10437                                  ops, "add#del#update");
10438 cmdline_parse_token_string_t cmd_flow_director_flow =
10439         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10440                                  flow, "flow");
10441 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10442         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10443                 flow_type, NULL);
10444 cmdline_parse_token_string_t cmd_flow_director_ether =
10445         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10446                                  ether, "ether");
10447 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10448         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10449                               ether_type, UINT16);
10450 cmdline_parse_token_string_t cmd_flow_director_src =
10451         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10452                                  src, "src");
10453 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10454         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10455                                  ip_src);
10456 cmdline_parse_token_num_t cmd_flow_director_port_src =
10457         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10458                               port_src, UINT16);
10459 cmdline_parse_token_string_t cmd_flow_director_dst =
10460         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10461                                  dst, "dst");
10462 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10463         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10464                                  ip_dst);
10465 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10466         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10467                               port_dst, UINT16);
10468 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10469         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10470                                   verify_tag, "verify_tag");
10471 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10472         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10473                               verify_tag_value, UINT32);
10474 cmdline_parse_token_string_t cmd_flow_director_tos =
10475         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10476                                  tos, "tos");
10477 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10478         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10479                               tos_value, UINT8);
10480 cmdline_parse_token_string_t cmd_flow_director_proto =
10481         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10482                                  proto, "proto");
10483 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10484         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10485                               proto_value, UINT8);
10486 cmdline_parse_token_string_t cmd_flow_director_ttl =
10487         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10488                                  ttl, "ttl");
10489 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10490         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10491                               ttl_value, UINT8);
10492 cmdline_parse_token_string_t cmd_flow_director_vlan =
10493         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10494                                  vlan, "vlan");
10495 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10496         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10497                               vlan_value, UINT16);
10498 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10499         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10500                                  flexbytes, "flexbytes");
10501 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10502         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10503                               flexbytes_value, NULL);
10504 cmdline_parse_token_string_t cmd_flow_director_drop =
10505         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10506                                  drop, "drop#fwd");
10507 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10508         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10509                               pf_vf, NULL);
10510 cmdline_parse_token_string_t cmd_flow_director_queue =
10511         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10512                                  queue, "queue");
10513 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10514         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10515                               queue_id, UINT16);
10516 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10517         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10518                                  fd_id, "fd_id");
10519 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10520         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10521                               fd_id_value, UINT32);
10522
10523 cmdline_parse_token_string_t cmd_flow_director_mode =
10524         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10525                                  mode, "mode");
10526 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10527         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10528                                  mode_value, "IP");
10529 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10530         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10531                                  mode_value, "MAC-VLAN");
10532 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10533         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10534                                  mode_value, "Tunnel");
10535 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10536         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10537                                  mode_value, "raw");
10538 cmdline_parse_token_string_t cmd_flow_director_mac =
10539         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10540                                  mac, "mac");
10541 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10542         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10543                                     mac_addr);
10544 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10545         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10546                                  tunnel, "tunnel");
10547 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10548         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10549                                  tunnel_type, "NVGRE#VxLAN");
10550 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10551         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10552                                  tunnel_id, "tunnel-id");
10553 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10554         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10555                               tunnel_id_value, UINT32);
10556 cmdline_parse_token_string_t cmd_flow_director_packet =
10557         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10558                                  packet, "packet");
10559 cmdline_parse_token_string_t cmd_flow_director_filepath =
10560         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10561                                  filepath, NULL);
10562
10563 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10564         .f = cmd_flow_director_filter_parsed,
10565         .data = NULL,
10566         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10567                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10568                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10569                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10570                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10571                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10572                 "fd_id <fd_id_value>: "
10573                 "Add or delete an ip flow director entry on NIC",
10574         .tokens = {
10575                 (void *)&cmd_flow_director_filter,
10576                 (void *)&cmd_flow_director_port_id,
10577                 (void *)&cmd_flow_director_mode,
10578                 (void *)&cmd_flow_director_mode_ip,
10579                 (void *)&cmd_flow_director_ops,
10580                 (void *)&cmd_flow_director_flow,
10581                 (void *)&cmd_flow_director_flow_type,
10582                 (void *)&cmd_flow_director_src,
10583                 (void *)&cmd_flow_director_ip_src,
10584                 (void *)&cmd_flow_director_dst,
10585                 (void *)&cmd_flow_director_ip_dst,
10586                 (void *)&cmd_flow_director_tos,
10587                 (void *)&cmd_flow_director_tos_value,
10588                 (void *)&cmd_flow_director_proto,
10589                 (void *)&cmd_flow_director_proto_value,
10590                 (void *)&cmd_flow_director_ttl,
10591                 (void *)&cmd_flow_director_ttl_value,
10592                 (void *)&cmd_flow_director_vlan,
10593                 (void *)&cmd_flow_director_vlan_value,
10594                 (void *)&cmd_flow_director_flexbytes,
10595                 (void *)&cmd_flow_director_flexbytes_value,
10596                 (void *)&cmd_flow_director_drop,
10597                 (void *)&cmd_flow_director_pf_vf,
10598                 (void *)&cmd_flow_director_queue,
10599                 (void *)&cmd_flow_director_queue_id,
10600                 (void *)&cmd_flow_director_fd_id,
10601                 (void *)&cmd_flow_director_fd_id_value,
10602                 NULL,
10603         },
10604 };
10605
10606 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10607         .f = cmd_flow_director_filter_parsed,
10608         .data = NULL,
10609         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10610                 "director entry on NIC",
10611         .tokens = {
10612                 (void *)&cmd_flow_director_filter,
10613                 (void *)&cmd_flow_director_port_id,
10614                 (void *)&cmd_flow_director_mode,
10615                 (void *)&cmd_flow_director_mode_ip,
10616                 (void *)&cmd_flow_director_ops,
10617                 (void *)&cmd_flow_director_flow,
10618                 (void *)&cmd_flow_director_flow_type,
10619                 (void *)&cmd_flow_director_src,
10620                 (void *)&cmd_flow_director_ip_src,
10621                 (void *)&cmd_flow_director_port_src,
10622                 (void *)&cmd_flow_director_dst,
10623                 (void *)&cmd_flow_director_ip_dst,
10624                 (void *)&cmd_flow_director_port_dst,
10625                 (void *)&cmd_flow_director_tos,
10626                 (void *)&cmd_flow_director_tos_value,
10627                 (void *)&cmd_flow_director_ttl,
10628                 (void *)&cmd_flow_director_ttl_value,
10629                 (void *)&cmd_flow_director_vlan,
10630                 (void *)&cmd_flow_director_vlan_value,
10631                 (void *)&cmd_flow_director_flexbytes,
10632                 (void *)&cmd_flow_director_flexbytes_value,
10633                 (void *)&cmd_flow_director_drop,
10634                 (void *)&cmd_flow_director_pf_vf,
10635                 (void *)&cmd_flow_director_queue,
10636                 (void *)&cmd_flow_director_queue_id,
10637                 (void *)&cmd_flow_director_fd_id,
10638                 (void *)&cmd_flow_director_fd_id_value,
10639                 NULL,
10640         },
10641 };
10642
10643 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10644         .f = cmd_flow_director_filter_parsed,
10645         .data = NULL,
10646         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10647                 "director entry on NIC",
10648         .tokens = {
10649                 (void *)&cmd_flow_director_filter,
10650                 (void *)&cmd_flow_director_port_id,
10651                 (void *)&cmd_flow_director_mode,
10652                 (void *)&cmd_flow_director_mode_ip,
10653                 (void *)&cmd_flow_director_ops,
10654                 (void *)&cmd_flow_director_flow,
10655                 (void *)&cmd_flow_director_flow_type,
10656                 (void *)&cmd_flow_director_src,
10657                 (void *)&cmd_flow_director_ip_src,
10658                 (void *)&cmd_flow_director_port_src,
10659                 (void *)&cmd_flow_director_dst,
10660                 (void *)&cmd_flow_director_ip_dst,
10661                 (void *)&cmd_flow_director_port_dst,
10662                 (void *)&cmd_flow_director_verify_tag,
10663                 (void *)&cmd_flow_director_verify_tag_value,
10664                 (void *)&cmd_flow_director_tos,
10665                 (void *)&cmd_flow_director_tos_value,
10666                 (void *)&cmd_flow_director_ttl,
10667                 (void *)&cmd_flow_director_ttl_value,
10668                 (void *)&cmd_flow_director_vlan,
10669                 (void *)&cmd_flow_director_vlan_value,
10670                 (void *)&cmd_flow_director_flexbytes,
10671                 (void *)&cmd_flow_director_flexbytes_value,
10672                 (void *)&cmd_flow_director_drop,
10673                 (void *)&cmd_flow_director_pf_vf,
10674                 (void *)&cmd_flow_director_queue,
10675                 (void *)&cmd_flow_director_queue_id,
10676                 (void *)&cmd_flow_director_fd_id,
10677                 (void *)&cmd_flow_director_fd_id_value,
10678                 NULL,
10679         },
10680 };
10681
10682 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10683         .f = cmd_flow_director_filter_parsed,
10684         .data = NULL,
10685         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10686                 "director entry on NIC",
10687         .tokens = {
10688                 (void *)&cmd_flow_director_filter,
10689                 (void *)&cmd_flow_director_port_id,
10690                 (void *)&cmd_flow_director_mode,
10691                 (void *)&cmd_flow_director_mode_ip,
10692                 (void *)&cmd_flow_director_ops,
10693                 (void *)&cmd_flow_director_flow,
10694                 (void *)&cmd_flow_director_flow_type,
10695                 (void *)&cmd_flow_director_ether,
10696                 (void *)&cmd_flow_director_ether_type,
10697                 (void *)&cmd_flow_director_flexbytes,
10698                 (void *)&cmd_flow_director_flexbytes_value,
10699                 (void *)&cmd_flow_director_drop,
10700                 (void *)&cmd_flow_director_pf_vf,
10701                 (void *)&cmd_flow_director_queue,
10702                 (void *)&cmd_flow_director_queue_id,
10703                 (void *)&cmd_flow_director_fd_id,
10704                 (void *)&cmd_flow_director_fd_id_value,
10705                 NULL,
10706         },
10707 };
10708
10709 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10710         .f = cmd_flow_director_filter_parsed,
10711         .data = NULL,
10712         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10713                 "director entry on NIC",
10714         .tokens = {
10715                 (void *)&cmd_flow_director_filter,
10716                 (void *)&cmd_flow_director_port_id,
10717                 (void *)&cmd_flow_director_mode,
10718                 (void *)&cmd_flow_director_mode_mac_vlan,
10719                 (void *)&cmd_flow_director_ops,
10720                 (void *)&cmd_flow_director_mac,
10721                 (void *)&cmd_flow_director_mac_addr,
10722                 (void *)&cmd_flow_director_vlan,
10723                 (void *)&cmd_flow_director_vlan_value,
10724                 (void *)&cmd_flow_director_flexbytes,
10725                 (void *)&cmd_flow_director_flexbytes_value,
10726                 (void *)&cmd_flow_director_drop,
10727                 (void *)&cmd_flow_director_queue,
10728                 (void *)&cmd_flow_director_queue_id,
10729                 (void *)&cmd_flow_director_fd_id,
10730                 (void *)&cmd_flow_director_fd_id_value,
10731                 NULL,
10732         },
10733 };
10734
10735 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10736         .f = cmd_flow_director_filter_parsed,
10737         .data = NULL,
10738         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10739                 "director entry on NIC",
10740         .tokens = {
10741                 (void *)&cmd_flow_director_filter,
10742                 (void *)&cmd_flow_director_port_id,
10743                 (void *)&cmd_flow_director_mode,
10744                 (void *)&cmd_flow_director_mode_tunnel,
10745                 (void *)&cmd_flow_director_ops,
10746                 (void *)&cmd_flow_director_mac,
10747                 (void *)&cmd_flow_director_mac_addr,
10748                 (void *)&cmd_flow_director_vlan,
10749                 (void *)&cmd_flow_director_vlan_value,
10750                 (void *)&cmd_flow_director_tunnel,
10751                 (void *)&cmd_flow_director_tunnel_type,
10752                 (void *)&cmd_flow_director_tunnel_id,
10753                 (void *)&cmd_flow_director_tunnel_id_value,
10754                 (void *)&cmd_flow_director_flexbytes,
10755                 (void *)&cmd_flow_director_flexbytes_value,
10756                 (void *)&cmd_flow_director_drop,
10757                 (void *)&cmd_flow_director_queue,
10758                 (void *)&cmd_flow_director_queue_id,
10759                 (void *)&cmd_flow_director_fd_id,
10760                 (void *)&cmd_flow_director_fd_id_value,
10761                 NULL,
10762         },
10763 };
10764
10765 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10766         .f = cmd_flow_director_filter_parsed,
10767         .data = NULL,
10768         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10769                 "director entry on NIC",
10770         .tokens = {
10771                 (void *)&cmd_flow_director_filter,
10772                 (void *)&cmd_flow_director_port_id,
10773                 (void *)&cmd_flow_director_mode,
10774                 (void *)&cmd_flow_director_mode_raw,
10775                 (void *)&cmd_flow_director_ops,
10776                 (void *)&cmd_flow_director_flow,
10777                 (void *)&cmd_flow_director_flow_type,
10778                 (void *)&cmd_flow_director_drop,
10779                 (void *)&cmd_flow_director_queue,
10780                 (void *)&cmd_flow_director_queue_id,
10781                 (void *)&cmd_flow_director_fd_id,
10782                 (void *)&cmd_flow_director_fd_id_value,
10783                 (void *)&cmd_flow_director_packet,
10784                 (void *)&cmd_flow_director_filepath,
10785                 NULL,
10786         },
10787 };
10788
10789 struct cmd_flush_flow_director_result {
10790         cmdline_fixed_string_t flush_flow_director;
10791         portid_t port_id;
10792 };
10793
10794 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10795         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10796                                  flush_flow_director, "flush_flow_director");
10797 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10798         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10799                               port_id, UINT16);
10800
10801 static void
10802 cmd_flush_flow_director_parsed(void *parsed_result,
10803                           __attribute__((unused)) struct cmdline *cl,
10804                           __attribute__((unused)) void *data)
10805 {
10806         struct cmd_flow_director_result *res = parsed_result;
10807         int ret = 0;
10808
10809         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10810         if (ret < 0) {
10811                 printf("flow director is not supported on port %u.\n",
10812                         res->port_id);
10813                 return;
10814         }
10815
10816         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10817                         RTE_ETH_FILTER_FLUSH, NULL);
10818         if (ret < 0)
10819                 printf("flow director table flushing error: (%s)\n",
10820                         strerror(-ret));
10821 }
10822
10823 cmdline_parse_inst_t cmd_flush_flow_director = {
10824         .f = cmd_flush_flow_director_parsed,
10825         .data = NULL,
10826         .help_str = "flush_flow_director <port_id>: "
10827                 "Flush all flow director entries of a device on NIC",
10828         .tokens = {
10829                 (void *)&cmd_flush_flow_director_flush,
10830                 (void *)&cmd_flush_flow_director_port_id,
10831                 NULL,
10832         },
10833 };
10834
10835 /* *** deal with flow director mask *** */
10836 struct cmd_flow_director_mask_result {
10837         cmdline_fixed_string_t flow_director_mask;
10838         portid_t port_id;
10839         cmdline_fixed_string_t mode;
10840         cmdline_fixed_string_t mode_value;
10841         cmdline_fixed_string_t vlan;
10842         uint16_t vlan_mask;
10843         cmdline_fixed_string_t src_mask;
10844         cmdline_ipaddr_t ipv4_src;
10845         cmdline_ipaddr_t ipv6_src;
10846         uint16_t port_src;
10847         cmdline_fixed_string_t dst_mask;
10848         cmdline_ipaddr_t ipv4_dst;
10849         cmdline_ipaddr_t ipv6_dst;
10850         uint16_t port_dst;
10851         cmdline_fixed_string_t mac;
10852         uint8_t mac_addr_byte_mask;
10853         cmdline_fixed_string_t tunnel_id;
10854         uint32_t tunnel_id_mask;
10855         cmdline_fixed_string_t tunnel_type;
10856         uint8_t tunnel_type_mask;
10857 };
10858
10859 static void
10860 cmd_flow_director_mask_parsed(void *parsed_result,
10861                           __attribute__((unused)) struct cmdline *cl,
10862                           __attribute__((unused)) void *data)
10863 {
10864         struct cmd_flow_director_mask_result *res = parsed_result;
10865         struct rte_eth_fdir_masks *mask;
10866         struct rte_port *port;
10867
10868         port = &ports[res->port_id];
10869         /** Check if the port is not started **/
10870         if (port->port_status != RTE_PORT_STOPPED) {
10871                 printf("Please stop port %d first\n", res->port_id);
10872                 return;
10873         }
10874
10875         mask = &port->dev_conf.fdir_conf.mask;
10876
10877         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10878                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10879                         printf("Please set mode to MAC-VLAN.\n");
10880                         return;
10881                 }
10882
10883                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10884         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10885                 if (strcmp(res->mode_value, "Tunnel")) {
10886                         printf("Please set mode to Tunnel.\n");
10887                         return;
10888                 }
10889
10890                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10891                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10892                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10893                 mask->tunnel_type_mask = res->tunnel_type_mask;
10894         } else {
10895                 if (strcmp(res->mode_value, "IP")) {
10896                         printf("Please set mode to IP.\n");
10897                         return;
10898                 }
10899
10900                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10901                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10902                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10903                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10904                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10905                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10906                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10907         }
10908
10909         cmd_reconfig_device_queue(res->port_id, 1, 1);
10910 }
10911
10912 cmdline_parse_token_string_t cmd_flow_director_mask =
10913         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10914                                  flow_director_mask, "flow_director_mask");
10915 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10916         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10917                               port_id, UINT16);
10918 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10919         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10920                                  vlan, "vlan");
10921 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10922         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10923                               vlan_mask, UINT16);
10924 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10925         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10926                                  src_mask, "src_mask");
10927 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10928         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10929                                  ipv4_src);
10930 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10931         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10932                                  ipv6_src);
10933 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10934         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10935                               port_src, UINT16);
10936 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10937         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10938                                  dst_mask, "dst_mask");
10939 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10940         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10941                                  ipv4_dst);
10942 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10943         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10944                                  ipv6_dst);
10945 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10946         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10947                               port_dst, UINT16);
10948
10949 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10950         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10951                                  mode, "mode");
10952 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10953         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10954                                  mode_value, "IP");
10955 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10956         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10957                                  mode_value, "MAC-VLAN");
10958 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10959         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10960                                  mode_value, "Tunnel");
10961 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10962         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10963                                  mac, "mac");
10964 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10965         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10966                               mac_addr_byte_mask, UINT8);
10967 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10968         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10969                                  tunnel_type, "tunnel-type");
10970 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10971         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10972                               tunnel_type_mask, UINT8);
10973 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10974         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10975                                  tunnel_id, "tunnel-id");
10976 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10977         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10978                               tunnel_id_mask, UINT32);
10979
10980 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10981         .f = cmd_flow_director_mask_parsed,
10982         .data = NULL,
10983         .help_str = "flow_director_mask ... : "
10984                 "Set IP mode flow director's mask on NIC",
10985         .tokens = {
10986                 (void *)&cmd_flow_director_mask,
10987                 (void *)&cmd_flow_director_mask_port_id,
10988                 (void *)&cmd_flow_director_mask_mode,
10989                 (void *)&cmd_flow_director_mask_mode_ip,
10990                 (void *)&cmd_flow_director_mask_vlan,
10991                 (void *)&cmd_flow_director_mask_vlan_value,
10992                 (void *)&cmd_flow_director_mask_src,
10993                 (void *)&cmd_flow_director_mask_ipv4_src,
10994                 (void *)&cmd_flow_director_mask_ipv6_src,
10995                 (void *)&cmd_flow_director_mask_port_src,
10996                 (void *)&cmd_flow_director_mask_dst,
10997                 (void *)&cmd_flow_director_mask_ipv4_dst,
10998                 (void *)&cmd_flow_director_mask_ipv6_dst,
10999                 (void *)&cmd_flow_director_mask_port_dst,
11000                 NULL,
11001         },
11002 };
11003
11004 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11005         .f = cmd_flow_director_mask_parsed,
11006         .data = NULL,
11007         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11008                 "flow director's mask on NIC",
11009         .tokens = {
11010                 (void *)&cmd_flow_director_mask,
11011                 (void *)&cmd_flow_director_mask_port_id,
11012                 (void *)&cmd_flow_director_mask_mode,
11013                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11014                 (void *)&cmd_flow_director_mask_vlan,
11015                 (void *)&cmd_flow_director_mask_vlan_value,
11016                 NULL,
11017         },
11018 };
11019
11020 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11021         .f = cmd_flow_director_mask_parsed,
11022         .data = NULL,
11023         .help_str = "flow_director_mask ... : Set tunnel mode "
11024                 "flow director's mask on NIC",
11025         .tokens = {
11026                 (void *)&cmd_flow_director_mask,
11027                 (void *)&cmd_flow_director_mask_port_id,
11028                 (void *)&cmd_flow_director_mask_mode,
11029                 (void *)&cmd_flow_director_mask_mode_tunnel,
11030                 (void *)&cmd_flow_director_mask_vlan,
11031                 (void *)&cmd_flow_director_mask_vlan_value,
11032                 (void *)&cmd_flow_director_mask_mac,
11033                 (void *)&cmd_flow_director_mask_mac_value,
11034                 (void *)&cmd_flow_director_mask_tunnel_type,
11035                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11036                 (void *)&cmd_flow_director_mask_tunnel_id,
11037                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11038                 NULL,
11039         },
11040 };
11041
11042 /* *** deal with flow director mask on flexible payload *** */
11043 struct cmd_flow_director_flex_mask_result {
11044         cmdline_fixed_string_t flow_director_flexmask;
11045         portid_t port_id;
11046         cmdline_fixed_string_t flow;
11047         cmdline_fixed_string_t flow_type;
11048         cmdline_fixed_string_t mask;
11049 };
11050
11051 static void
11052 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11053                           __attribute__((unused)) struct cmdline *cl,
11054                           __attribute__((unused)) void *data)
11055 {
11056         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11057         struct rte_eth_fdir_info fdir_info;
11058         struct rte_eth_fdir_flex_mask flex_mask;
11059         struct rte_port *port;
11060         uint64_t flow_type_mask;
11061         uint16_t i;
11062         int ret;
11063
11064         port = &ports[res->port_id];
11065         /** Check if the port is not started **/
11066         if (port->port_status != RTE_PORT_STOPPED) {
11067                 printf("Please stop port %d first\n", res->port_id);
11068                 return;
11069         }
11070
11071         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11072         ret = parse_flexbytes(res->mask,
11073                         flex_mask.mask,
11074                         RTE_ETH_FDIR_MAX_FLEXLEN);
11075         if (ret < 0) {
11076                 printf("error: Cannot parse mask input.\n");
11077                 return;
11078         }
11079
11080         memset(&fdir_info, 0, sizeof(fdir_info));
11081         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11082                                 RTE_ETH_FILTER_INFO, &fdir_info);
11083         if (ret < 0) {
11084                 printf("Cannot get FDir filter info\n");
11085                 return;
11086         }
11087
11088         if (!strcmp(res->flow_type, "none")) {
11089                 /* means don't specify the flow type */
11090                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11091                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11092                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11093                                0, sizeof(struct rte_eth_fdir_flex_mask));
11094                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11095                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11096                                  &flex_mask,
11097                                  sizeof(struct rte_eth_fdir_flex_mask));
11098                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11099                 return;
11100         }
11101         flow_type_mask = fdir_info.flow_types_mask[0];
11102         if (!strcmp(res->flow_type, "all")) {
11103                 if (!flow_type_mask) {
11104                         printf("No flow type supported\n");
11105                         return;
11106                 }
11107                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11108                         if (flow_type_mask & (1ULL << i)) {
11109                                 flex_mask.flow_type = i;
11110                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11111                         }
11112                 }
11113                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11114                 return;
11115         }
11116         flex_mask.flow_type = str2flowtype(res->flow_type);
11117         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11118                 printf("Flow type %s not supported on port %d\n",
11119                                 res->flow_type, res->port_id);
11120                 return;
11121         }
11122         fdir_set_flex_mask(res->port_id, &flex_mask);
11123         cmd_reconfig_device_queue(res->port_id, 1, 1);
11124 }
11125
11126 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11127         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11128                                  flow_director_flexmask,
11129                                  "flow_director_flex_mask");
11130 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11131         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11132                               port_id, UINT16);
11133 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11134         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11135                                  flow, "flow");
11136 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11137         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11138                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11139                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11140 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11141         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11142                                  mask, NULL);
11143
11144 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11145         .f = cmd_flow_director_flex_mask_parsed,
11146         .data = NULL,
11147         .help_str = "flow_director_flex_mask ... : "
11148                 "Set flow director's flex mask on NIC",
11149         .tokens = {
11150                 (void *)&cmd_flow_director_flexmask,
11151                 (void *)&cmd_flow_director_flexmask_port_id,
11152                 (void *)&cmd_flow_director_flexmask_flow,
11153                 (void *)&cmd_flow_director_flexmask_flow_type,
11154                 (void *)&cmd_flow_director_flexmask_mask,
11155                 NULL,
11156         },
11157 };
11158
11159 /* *** deal with flow director flexible payload configuration *** */
11160 struct cmd_flow_director_flexpayload_result {
11161         cmdline_fixed_string_t flow_director_flexpayload;
11162         portid_t port_id;
11163         cmdline_fixed_string_t payload_layer;
11164         cmdline_fixed_string_t payload_cfg;
11165 };
11166
11167 static inline int
11168 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11169 {
11170         char s[256];
11171         const char *p, *p0 = q_arg;
11172         char *end;
11173         unsigned long int_fld;
11174         char *str_fld[max_num];
11175         int i;
11176         unsigned size;
11177         int ret = -1;
11178
11179         p = strchr(p0, '(');
11180         if (p == NULL)
11181                 return -1;
11182         ++p;
11183         p0 = strchr(p, ')');
11184         if (p0 == NULL)
11185                 return -1;
11186
11187         size = p0 - p;
11188         if (size >= sizeof(s))
11189                 return -1;
11190
11191         snprintf(s, sizeof(s), "%.*s", size, p);
11192         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11193         if (ret < 0 || ret > max_num)
11194                 return -1;
11195         for (i = 0; i < ret; i++) {
11196                 errno = 0;
11197                 int_fld = strtoul(str_fld[i], &end, 0);
11198                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11199                         return -1;
11200                 offsets[i] = (uint16_t)int_fld;
11201         }
11202         return ret;
11203 }
11204
11205 static void
11206 cmd_flow_director_flxpld_parsed(void *parsed_result,
11207                           __attribute__((unused)) struct cmdline *cl,
11208                           __attribute__((unused)) void *data)
11209 {
11210         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11211         struct rte_eth_flex_payload_cfg flex_cfg;
11212         struct rte_port *port;
11213         int ret = 0;
11214
11215         port = &ports[res->port_id];
11216         /** Check if the port is not started **/
11217         if (port->port_status != RTE_PORT_STOPPED) {
11218                 printf("Please stop port %d first\n", res->port_id);
11219                 return;
11220         }
11221
11222         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11223
11224         if (!strcmp(res->payload_layer, "raw"))
11225                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11226         else if (!strcmp(res->payload_layer, "l2"))
11227                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11228         else if (!strcmp(res->payload_layer, "l3"))
11229                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11230         else if (!strcmp(res->payload_layer, "l4"))
11231                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11232
11233         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11234                             RTE_ETH_FDIR_MAX_FLEXLEN);
11235         if (ret < 0) {
11236                 printf("error: Cannot parse flex payload input.\n");
11237                 return;
11238         }
11239
11240         fdir_set_flex_payload(res->port_id, &flex_cfg);
11241         cmd_reconfig_device_queue(res->port_id, 1, 1);
11242 }
11243
11244 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11245         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11246                                  flow_director_flexpayload,
11247                                  "flow_director_flex_payload");
11248 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11249         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11250                               port_id, UINT16);
11251 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11253                                  payload_layer, "raw#l2#l3#l4");
11254 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11255         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11256                                  payload_cfg, NULL);
11257
11258 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11259         .f = cmd_flow_director_flxpld_parsed,
11260         .data = NULL,
11261         .help_str = "flow_director_flexpayload ... : "
11262                 "Set flow director's flex payload on NIC",
11263         .tokens = {
11264                 (void *)&cmd_flow_director_flexpayload,
11265                 (void *)&cmd_flow_director_flexpayload_port_id,
11266                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11267                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11268                 NULL,
11269         },
11270 };
11271
11272 /* Generic flow interface command. */
11273 extern cmdline_parse_inst_t cmd_flow;
11274
11275 /* *** Classification Filters Control *** */
11276 /* *** Get symmetric hash enable per port *** */
11277 struct cmd_get_sym_hash_ena_per_port_result {
11278         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11279         portid_t port_id;
11280 };
11281
11282 static void
11283 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11284                                  __rte_unused struct cmdline *cl,
11285                                  __rte_unused void *data)
11286 {
11287         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11288         struct rte_eth_hash_filter_info info;
11289         int ret;
11290
11291         if (rte_eth_dev_filter_supported(res->port_id,
11292                                 RTE_ETH_FILTER_HASH) < 0) {
11293                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11294                                                         res->port_id);
11295                 return;
11296         }
11297
11298         memset(&info, 0, sizeof(info));
11299         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11300         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11301                                                 RTE_ETH_FILTER_GET, &info);
11302
11303         if (ret < 0) {
11304                 printf("Cannot get symmetric hash enable per port "
11305                                         "on port %u\n", res->port_id);
11306                 return;
11307         }
11308
11309         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11310                                 "enabled" : "disabled", res->port_id);
11311 }
11312
11313 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11314         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11315                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11316 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11317         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11318                 port_id, UINT16);
11319
11320 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11321         .f = cmd_get_sym_hash_per_port_parsed,
11322         .data = NULL,
11323         .help_str = "get_sym_hash_ena_per_port <port_id>",
11324         .tokens = {
11325                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11326                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11327                 NULL,
11328         },
11329 };
11330
11331 /* *** Set symmetric hash enable per port *** */
11332 struct cmd_set_sym_hash_ena_per_port_result {
11333         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11334         cmdline_fixed_string_t enable;
11335         portid_t port_id;
11336 };
11337
11338 static void
11339 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11340                                  __rte_unused struct cmdline *cl,
11341                                  __rte_unused void *data)
11342 {
11343         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11344         struct rte_eth_hash_filter_info info;
11345         int ret;
11346
11347         if (rte_eth_dev_filter_supported(res->port_id,
11348                                 RTE_ETH_FILTER_HASH) < 0) {
11349                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11350                                                         res->port_id);
11351                 return;
11352         }
11353
11354         memset(&info, 0, sizeof(info));
11355         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11356         if (!strcmp(res->enable, "enable"))
11357                 info.info.enable = 1;
11358         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11359                                         RTE_ETH_FILTER_SET, &info);
11360         if (ret < 0) {
11361                 printf("Cannot set symmetric hash enable per port on "
11362                                         "port %u\n", res->port_id);
11363                 return;
11364         }
11365         printf("Symmetric hash has been set to %s on port %u\n",
11366                                         res->enable, res->port_id);
11367 }
11368
11369 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11370         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11371                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11372 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11373         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11374                 port_id, UINT16);
11375 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11376         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11377                 enable, "enable#disable");
11378
11379 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11380         .f = cmd_set_sym_hash_per_port_parsed,
11381         .data = NULL,
11382         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11383         .tokens = {
11384                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11385                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11386                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11387                 NULL,
11388         },
11389 };
11390
11391 /* Get global config of hash function */
11392 struct cmd_get_hash_global_config_result {
11393         cmdline_fixed_string_t get_hash_global_config;
11394         portid_t port_id;
11395 };
11396
11397 static char *
11398 flowtype_to_str(uint16_t ftype)
11399 {
11400         uint16_t i;
11401         static struct {
11402                 char str[16];
11403                 uint16_t ftype;
11404         } ftype_table[] = {
11405                 {"ipv4", RTE_ETH_FLOW_IPV4},
11406                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11407                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11408                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11409                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11410                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11411                 {"ipv6", RTE_ETH_FLOW_IPV6},
11412                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11413                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11414                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11415                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11416                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11417                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11418                 {"port", RTE_ETH_FLOW_PORT},
11419                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11420                 {"geneve", RTE_ETH_FLOW_GENEVE},
11421                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11422         };
11423
11424         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11425                 if (ftype_table[i].ftype == ftype)
11426                         return ftype_table[i].str;
11427         }
11428
11429         return NULL;
11430 }
11431
11432 static void
11433 cmd_get_hash_global_config_parsed(void *parsed_result,
11434                                   __rte_unused struct cmdline *cl,
11435                                   __rte_unused void *data)
11436 {
11437         struct cmd_get_hash_global_config_result *res = parsed_result;
11438         struct rte_eth_hash_filter_info info;
11439         uint32_t idx, offset;
11440         uint16_t i;
11441         char *str;
11442         int ret;
11443
11444         if (rte_eth_dev_filter_supported(res->port_id,
11445                         RTE_ETH_FILTER_HASH) < 0) {
11446                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11447                                                         res->port_id);
11448                 return;
11449         }
11450
11451         memset(&info, 0, sizeof(info));
11452         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11453         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11454                                         RTE_ETH_FILTER_GET, &info);
11455         if (ret < 0) {
11456                 printf("Cannot get hash global configurations by port %d\n",
11457                                                         res->port_id);
11458                 return;
11459         }
11460
11461         switch (info.info.global_conf.hash_func) {
11462         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11463                 printf("Hash function is Toeplitz\n");
11464                 break;
11465         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11466                 printf("Hash function is Simple XOR\n");
11467                 break;
11468         default:
11469                 printf("Unknown hash function\n");
11470                 break;
11471         }
11472
11473         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11474                 idx = i / UINT64_BIT;
11475                 offset = i % UINT64_BIT;
11476                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11477                                                 (1ULL << offset)))
11478                         continue;
11479                 str = flowtype_to_str(i);
11480                 if (!str)
11481                         continue;
11482                 printf("Symmetric hash is %s globally for flow type %s "
11483                                                         "by port %d\n",
11484                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11485                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11486                                                         res->port_id);
11487         }
11488 }
11489
11490 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11491         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11492                 get_hash_global_config, "get_hash_global_config");
11493 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11494         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11495                 port_id, UINT16);
11496
11497 cmdline_parse_inst_t cmd_get_hash_global_config = {
11498         .f = cmd_get_hash_global_config_parsed,
11499         .data = NULL,
11500         .help_str = "get_hash_global_config <port_id>",
11501         .tokens = {
11502                 (void *)&cmd_get_hash_global_config_all,
11503                 (void *)&cmd_get_hash_global_config_port_id,
11504                 NULL,
11505         },
11506 };
11507
11508 /* Set global config of hash function */
11509 struct cmd_set_hash_global_config_result {
11510         cmdline_fixed_string_t set_hash_global_config;
11511         portid_t port_id;
11512         cmdline_fixed_string_t hash_func;
11513         cmdline_fixed_string_t flow_type;
11514         cmdline_fixed_string_t enable;
11515 };
11516
11517 static void
11518 cmd_set_hash_global_config_parsed(void *parsed_result,
11519                                   __rte_unused struct cmdline *cl,
11520                                   __rte_unused void *data)
11521 {
11522         struct cmd_set_hash_global_config_result *res = parsed_result;
11523         struct rte_eth_hash_filter_info info;
11524         uint32_t ftype, idx, offset;
11525         int ret;
11526
11527         if (rte_eth_dev_filter_supported(res->port_id,
11528                                 RTE_ETH_FILTER_HASH) < 0) {
11529                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11530                                                         res->port_id);
11531                 return;
11532         }
11533         memset(&info, 0, sizeof(info));
11534         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11535         if (!strcmp(res->hash_func, "toeplitz"))
11536                 info.info.global_conf.hash_func =
11537                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11538         else if (!strcmp(res->hash_func, "simple_xor"))
11539                 info.info.global_conf.hash_func =
11540                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11541         else if (!strcmp(res->hash_func, "default"))
11542                 info.info.global_conf.hash_func =
11543                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11544
11545         ftype = str2flowtype(res->flow_type);
11546         idx = ftype / UINT64_BIT;
11547         offset = ftype % UINT64_BIT;
11548         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11549         if (!strcmp(res->enable, "enable"))
11550                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11551                                                 (1ULL << offset);
11552         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11553                                         RTE_ETH_FILTER_SET, &info);
11554         if (ret < 0)
11555                 printf("Cannot set global hash configurations by port %d\n",
11556                                                         res->port_id);
11557         else
11558                 printf("Global hash configurations have been set "
11559                         "succcessfully by port %d\n", res->port_id);
11560 }
11561
11562 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11563         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11564                 set_hash_global_config, "set_hash_global_config");
11565 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11566         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11567                 port_id, UINT16);
11568 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11569         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11570                 hash_func, "toeplitz#simple_xor#default");
11571 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11572         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11573                 flow_type,
11574                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11575                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11576 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11577         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11578                 enable, "enable#disable");
11579
11580 cmdline_parse_inst_t cmd_set_hash_global_config = {
11581         .f = cmd_set_hash_global_config_parsed,
11582         .data = NULL,
11583         .help_str = "set_hash_global_config <port_id> "
11584                 "toeplitz|simple_xor|default "
11585                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11586                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11587                 "l2_payload enable|disable",
11588         .tokens = {
11589                 (void *)&cmd_set_hash_global_config_all,
11590                 (void *)&cmd_set_hash_global_config_port_id,
11591                 (void *)&cmd_set_hash_global_config_hash_func,
11592                 (void *)&cmd_set_hash_global_config_flow_type,
11593                 (void *)&cmd_set_hash_global_config_enable,
11594                 NULL,
11595         },
11596 };
11597
11598 /* Set hash input set */
11599 struct cmd_set_hash_input_set_result {
11600         cmdline_fixed_string_t set_hash_input_set;
11601         portid_t port_id;
11602         cmdline_fixed_string_t flow_type;
11603         cmdline_fixed_string_t inset_field;
11604         cmdline_fixed_string_t select;
11605 };
11606
11607 static enum rte_eth_input_set_field
11608 str2inset(char *string)
11609 {
11610         uint16_t i;
11611
11612         static const struct {
11613                 char str[32];
11614                 enum rte_eth_input_set_field inset;
11615         } inset_table[] = {
11616                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11617                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11618                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11619                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11620                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11621                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11622                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11623                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11624                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11625                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11626                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11627                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11628                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11629                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11630                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11631                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11632                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11633                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11634                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11635                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11636                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11637                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11638                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11639                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11640                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11641                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11642                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11643                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11644                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11645                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11646                 {"none", RTE_ETH_INPUT_SET_NONE},
11647         };
11648
11649         for (i = 0; i < RTE_DIM(inset_table); i++) {
11650                 if (!strcmp(string, inset_table[i].str))
11651                         return inset_table[i].inset;
11652         }
11653
11654         return RTE_ETH_INPUT_SET_UNKNOWN;
11655 }
11656
11657 static void
11658 cmd_set_hash_input_set_parsed(void *parsed_result,
11659                               __rte_unused struct cmdline *cl,
11660                               __rte_unused void *data)
11661 {
11662         struct cmd_set_hash_input_set_result *res = parsed_result;
11663         struct rte_eth_hash_filter_info info;
11664
11665         memset(&info, 0, sizeof(info));
11666         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11667         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11668         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11669         info.info.input_set_conf.inset_size = 1;
11670         if (!strcmp(res->select, "select"))
11671                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11672         else if (!strcmp(res->select, "add"))
11673                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11674         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11675                                 RTE_ETH_FILTER_SET, &info);
11676 }
11677
11678 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11679         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11680                 set_hash_input_set, "set_hash_input_set");
11681 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11682         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11683                 port_id, UINT16);
11684 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11685         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11686                 flow_type, NULL);
11687 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11688         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11689                 inset_field,
11690                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11691                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11692                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11693                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11694                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11695                 "fld-8th#none");
11696 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11697         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11698                 select, "select#add");
11699
11700 cmdline_parse_inst_t cmd_set_hash_input_set = {
11701         .f = cmd_set_hash_input_set_parsed,
11702         .data = NULL,
11703         .help_str = "set_hash_input_set <port_id> "
11704         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11705         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11706         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11707         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11708         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11709         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11710         "fld-7th|fld-8th|none select|add",
11711         .tokens = {
11712                 (void *)&cmd_set_hash_input_set_cmd,
11713                 (void *)&cmd_set_hash_input_set_port_id,
11714                 (void *)&cmd_set_hash_input_set_flow_type,
11715                 (void *)&cmd_set_hash_input_set_field,
11716                 (void *)&cmd_set_hash_input_set_select,
11717                 NULL,
11718         },
11719 };
11720
11721 /* Set flow director input set */
11722 struct cmd_set_fdir_input_set_result {
11723         cmdline_fixed_string_t set_fdir_input_set;
11724         portid_t port_id;
11725         cmdline_fixed_string_t flow_type;
11726         cmdline_fixed_string_t inset_field;
11727         cmdline_fixed_string_t select;
11728 };
11729
11730 static void
11731 cmd_set_fdir_input_set_parsed(void *parsed_result,
11732         __rte_unused struct cmdline *cl,
11733         __rte_unused void *data)
11734 {
11735         struct cmd_set_fdir_input_set_result *res = parsed_result;
11736         struct rte_eth_fdir_filter_info info;
11737
11738         memset(&info, 0, sizeof(info));
11739         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11740         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11741         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11742         info.info.input_set_conf.inset_size = 1;
11743         if (!strcmp(res->select, "select"))
11744                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11745         else if (!strcmp(res->select, "add"))
11746                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11747         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11748                 RTE_ETH_FILTER_SET, &info);
11749 }
11750
11751 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11752         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11753         set_fdir_input_set, "set_fdir_input_set");
11754 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11755         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11756         port_id, UINT16);
11757 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11758         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11759         flow_type,
11760         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11761         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11762 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11763         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11764         inset_field,
11765         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11766         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11767         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11768         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11769         "sctp-veri-tag#none");
11770 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11771         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11772         select, "select#add");
11773
11774 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11775         .f = cmd_set_fdir_input_set_parsed,
11776         .data = NULL,
11777         .help_str = "set_fdir_input_set <port_id> "
11778         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11779         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11780         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11781         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11782         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11783         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11784         "sctp-veri-tag|none select|add",
11785         .tokens = {
11786                 (void *)&cmd_set_fdir_input_set_cmd,
11787                 (void *)&cmd_set_fdir_input_set_port_id,
11788                 (void *)&cmd_set_fdir_input_set_flow_type,
11789                 (void *)&cmd_set_fdir_input_set_field,
11790                 (void *)&cmd_set_fdir_input_set_select,
11791                 NULL,
11792         },
11793 };
11794
11795 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11796 struct cmd_mcast_addr_result {
11797         cmdline_fixed_string_t mcast_addr_cmd;
11798         cmdline_fixed_string_t what;
11799         uint16_t port_num;
11800         struct ether_addr mc_addr;
11801 };
11802
11803 static void cmd_mcast_addr_parsed(void *parsed_result,
11804                 __attribute__((unused)) struct cmdline *cl,
11805                 __attribute__((unused)) void *data)
11806 {
11807         struct cmd_mcast_addr_result *res = parsed_result;
11808
11809         if (!is_multicast_ether_addr(&res->mc_addr)) {
11810                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11811                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11812                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11813                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11814                 return;
11815         }
11816         if (strcmp(res->what, "add") == 0)
11817                 mcast_addr_add(res->port_num, &res->mc_addr);
11818         else
11819                 mcast_addr_remove(res->port_num, &res->mc_addr);
11820 }
11821
11822 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11823         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11824                                  mcast_addr_cmd, "mcast_addr");
11825 cmdline_parse_token_string_t cmd_mcast_addr_what =
11826         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11827                                  "add#remove");
11828 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11829         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11830 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11831         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11832
11833 cmdline_parse_inst_t cmd_mcast_addr = {
11834         .f = cmd_mcast_addr_parsed,
11835         .data = (void *)0,
11836         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11837                 "Add/Remove multicast MAC address on port_id",
11838         .tokens = {
11839                 (void *)&cmd_mcast_addr_cmd,
11840                 (void *)&cmd_mcast_addr_what,
11841                 (void *)&cmd_mcast_addr_portnum,
11842                 (void *)&cmd_mcast_addr_addr,
11843                 NULL,
11844         },
11845 };
11846
11847 /* l2 tunnel config
11848  * only support E-tag now.
11849  */
11850
11851 /* Ether type config */
11852 struct cmd_config_l2_tunnel_eth_type_result {
11853         cmdline_fixed_string_t port;
11854         cmdline_fixed_string_t config;
11855         cmdline_fixed_string_t all;
11856         uint8_t id;
11857         cmdline_fixed_string_t l2_tunnel;
11858         cmdline_fixed_string_t l2_tunnel_type;
11859         cmdline_fixed_string_t eth_type;
11860         uint16_t eth_type_val;
11861 };
11862
11863 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11864         TOKEN_STRING_INITIALIZER
11865                 (struct cmd_config_l2_tunnel_eth_type_result,
11866                  port, "port");
11867 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11868         TOKEN_STRING_INITIALIZER
11869                 (struct cmd_config_l2_tunnel_eth_type_result,
11870                  config, "config");
11871 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11872         TOKEN_STRING_INITIALIZER
11873                 (struct cmd_config_l2_tunnel_eth_type_result,
11874                  all, "all");
11875 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11876         TOKEN_NUM_INITIALIZER
11877                 (struct cmd_config_l2_tunnel_eth_type_result,
11878                  id, UINT8);
11879 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11880         TOKEN_STRING_INITIALIZER
11881                 (struct cmd_config_l2_tunnel_eth_type_result,
11882                  l2_tunnel, "l2-tunnel");
11883 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11884         TOKEN_STRING_INITIALIZER
11885                 (struct cmd_config_l2_tunnel_eth_type_result,
11886                  l2_tunnel_type, "E-tag");
11887 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11888         TOKEN_STRING_INITIALIZER
11889                 (struct cmd_config_l2_tunnel_eth_type_result,
11890                  eth_type, "ether-type");
11891 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11892         TOKEN_NUM_INITIALIZER
11893                 (struct cmd_config_l2_tunnel_eth_type_result,
11894                  eth_type_val, UINT16);
11895
11896 static enum rte_eth_tunnel_type
11897 str2fdir_l2_tunnel_type(char *string)
11898 {
11899         uint32_t i = 0;
11900
11901         static const struct {
11902                 char str[32];
11903                 enum rte_eth_tunnel_type type;
11904         } l2_tunnel_type_str[] = {
11905                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11906         };
11907
11908         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11909                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11910                         return l2_tunnel_type_str[i].type;
11911         }
11912         return RTE_TUNNEL_TYPE_NONE;
11913 }
11914
11915 /* ether type config for all ports */
11916 static void
11917 cmd_config_l2_tunnel_eth_type_all_parsed
11918         (void *parsed_result,
11919          __attribute__((unused)) struct cmdline *cl,
11920          __attribute__((unused)) void *data)
11921 {
11922         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11923         struct rte_eth_l2_tunnel_conf entry;
11924         portid_t pid;
11925
11926         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11927         entry.ether_type = res->eth_type_val;
11928
11929         RTE_ETH_FOREACH_DEV(pid) {
11930                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11931         }
11932 }
11933
11934 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11935         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11936         .data = NULL,
11937         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11938         .tokens = {
11939                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11940                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11941                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11942                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11943                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11944                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11945                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11946                 NULL,
11947         },
11948 };
11949
11950 /* ether type config for a specific port */
11951 static void
11952 cmd_config_l2_tunnel_eth_type_specific_parsed(
11953         void *parsed_result,
11954         __attribute__((unused)) struct cmdline *cl,
11955         __attribute__((unused)) void *data)
11956 {
11957         struct cmd_config_l2_tunnel_eth_type_result *res =
11958                  parsed_result;
11959         struct rte_eth_l2_tunnel_conf entry;
11960
11961         if (port_id_is_invalid(res->id, ENABLED_WARN))
11962                 return;
11963
11964         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11965         entry.ether_type = res->eth_type_val;
11966
11967         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11968 }
11969
11970 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11971         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11972         .data = NULL,
11973         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11974         .tokens = {
11975                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11976                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11977                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11978                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11979                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11980                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11981                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11982                 NULL,
11983         },
11984 };
11985
11986 /* Enable/disable l2 tunnel */
11987 struct cmd_config_l2_tunnel_en_dis_result {
11988         cmdline_fixed_string_t port;
11989         cmdline_fixed_string_t config;
11990         cmdline_fixed_string_t all;
11991         uint8_t id;
11992         cmdline_fixed_string_t l2_tunnel;
11993         cmdline_fixed_string_t l2_tunnel_type;
11994         cmdline_fixed_string_t en_dis;
11995 };
11996
11997 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11998         TOKEN_STRING_INITIALIZER
11999                 (struct cmd_config_l2_tunnel_en_dis_result,
12000                  port, "port");
12001 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12002         TOKEN_STRING_INITIALIZER
12003                 (struct cmd_config_l2_tunnel_en_dis_result,
12004                  config, "config");
12005 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12006         TOKEN_STRING_INITIALIZER
12007                 (struct cmd_config_l2_tunnel_en_dis_result,
12008                  all, "all");
12009 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12010         TOKEN_NUM_INITIALIZER
12011                 (struct cmd_config_l2_tunnel_en_dis_result,
12012                  id, UINT8);
12013 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12014         TOKEN_STRING_INITIALIZER
12015                 (struct cmd_config_l2_tunnel_en_dis_result,
12016                  l2_tunnel, "l2-tunnel");
12017 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12018         TOKEN_STRING_INITIALIZER
12019                 (struct cmd_config_l2_tunnel_en_dis_result,
12020                  l2_tunnel_type, "E-tag");
12021 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12022         TOKEN_STRING_INITIALIZER
12023                 (struct cmd_config_l2_tunnel_en_dis_result,
12024                  en_dis, "enable#disable");
12025
12026 /* enable/disable l2 tunnel for all ports */
12027 static void
12028 cmd_config_l2_tunnel_en_dis_all_parsed(
12029         void *parsed_result,
12030         __attribute__((unused)) struct cmdline *cl,
12031         __attribute__((unused)) void *data)
12032 {
12033         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12034         struct rte_eth_l2_tunnel_conf entry;
12035         portid_t pid;
12036         uint8_t en;
12037
12038         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12039
12040         if (!strcmp("enable", res->en_dis))
12041                 en = 1;
12042         else
12043                 en = 0;
12044
12045         RTE_ETH_FOREACH_DEV(pid) {
12046                 rte_eth_dev_l2_tunnel_offload_set(pid,
12047                                                   &entry,
12048                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12049                                                   en);
12050         }
12051 }
12052
12053 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12054         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12055         .data = NULL,
12056         .help_str = "port config all l2-tunnel E-tag enable|disable",
12057         .tokens = {
12058                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12059                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12060                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12061                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12062                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12063                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12064                 NULL,
12065         },
12066 };
12067
12068 /* enable/disable l2 tunnel for a port */
12069 static void
12070 cmd_config_l2_tunnel_en_dis_specific_parsed(
12071         void *parsed_result,
12072         __attribute__((unused)) struct cmdline *cl,
12073         __attribute__((unused)) void *data)
12074 {
12075         struct cmd_config_l2_tunnel_en_dis_result *res =
12076                 parsed_result;
12077         struct rte_eth_l2_tunnel_conf entry;
12078
12079         if (port_id_is_invalid(res->id, ENABLED_WARN))
12080                 return;
12081
12082         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12083
12084         if (!strcmp("enable", res->en_dis))
12085                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12086                                                   &entry,
12087                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12088                                                   1);
12089         else
12090                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12091                                                   &entry,
12092                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12093                                                   0);
12094 }
12095
12096 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12097         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12098         .data = NULL,
12099         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12100         .tokens = {
12101                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12102                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12103                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12104                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12105                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12106                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12107                 NULL,
12108         },
12109 };
12110
12111 /* E-tag configuration */
12112
12113 /* Common result structure for all E-tag configuration */
12114 struct cmd_config_e_tag_result {
12115         cmdline_fixed_string_t e_tag;
12116         cmdline_fixed_string_t set;
12117         cmdline_fixed_string_t insertion;
12118         cmdline_fixed_string_t stripping;
12119         cmdline_fixed_string_t forwarding;
12120         cmdline_fixed_string_t filter;
12121         cmdline_fixed_string_t add;
12122         cmdline_fixed_string_t del;
12123         cmdline_fixed_string_t on;
12124         cmdline_fixed_string_t off;
12125         cmdline_fixed_string_t on_off;
12126         cmdline_fixed_string_t port_tag_id;
12127         uint32_t port_tag_id_val;
12128         cmdline_fixed_string_t e_tag_id;
12129         uint16_t e_tag_id_val;
12130         cmdline_fixed_string_t dst_pool;
12131         uint8_t dst_pool_val;
12132         cmdline_fixed_string_t port;
12133         portid_t port_id;
12134         cmdline_fixed_string_t vf;
12135         uint8_t vf_id;
12136 };
12137
12138 /* Common CLI fields for all E-tag configuration */
12139 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12140         TOKEN_STRING_INITIALIZER
12141                 (struct cmd_config_e_tag_result,
12142                  e_tag, "E-tag");
12143 cmdline_parse_token_string_t cmd_config_e_tag_set =
12144         TOKEN_STRING_INITIALIZER
12145                 (struct cmd_config_e_tag_result,
12146                  set, "set");
12147 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12148         TOKEN_STRING_INITIALIZER
12149                 (struct cmd_config_e_tag_result,
12150                  insertion, "insertion");
12151 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12152         TOKEN_STRING_INITIALIZER
12153                 (struct cmd_config_e_tag_result,
12154                  stripping, "stripping");
12155 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12156         TOKEN_STRING_INITIALIZER
12157                 (struct cmd_config_e_tag_result,
12158                  forwarding, "forwarding");
12159 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12160         TOKEN_STRING_INITIALIZER
12161                 (struct cmd_config_e_tag_result,
12162                  filter, "filter");
12163 cmdline_parse_token_string_t cmd_config_e_tag_add =
12164         TOKEN_STRING_INITIALIZER
12165                 (struct cmd_config_e_tag_result,
12166                  add, "add");
12167 cmdline_parse_token_string_t cmd_config_e_tag_del =
12168         TOKEN_STRING_INITIALIZER
12169                 (struct cmd_config_e_tag_result,
12170                  del, "del");
12171 cmdline_parse_token_string_t cmd_config_e_tag_on =
12172         TOKEN_STRING_INITIALIZER
12173                 (struct cmd_config_e_tag_result,
12174                  on, "on");
12175 cmdline_parse_token_string_t cmd_config_e_tag_off =
12176         TOKEN_STRING_INITIALIZER
12177                 (struct cmd_config_e_tag_result,
12178                  off, "off");
12179 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12180         TOKEN_STRING_INITIALIZER
12181                 (struct cmd_config_e_tag_result,
12182                  on_off, "on#off");
12183 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12184         TOKEN_STRING_INITIALIZER
12185                 (struct cmd_config_e_tag_result,
12186                  port_tag_id, "port-tag-id");
12187 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12188         TOKEN_NUM_INITIALIZER
12189                 (struct cmd_config_e_tag_result,
12190                  port_tag_id_val, UINT32);
12191 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12192         TOKEN_STRING_INITIALIZER
12193                 (struct cmd_config_e_tag_result,
12194                  e_tag_id, "e-tag-id");
12195 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12196         TOKEN_NUM_INITIALIZER
12197                 (struct cmd_config_e_tag_result,
12198                  e_tag_id_val, UINT16);
12199 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12200         TOKEN_STRING_INITIALIZER
12201                 (struct cmd_config_e_tag_result,
12202                  dst_pool, "dst-pool");
12203 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12204         TOKEN_NUM_INITIALIZER
12205                 (struct cmd_config_e_tag_result,
12206                  dst_pool_val, UINT8);
12207 cmdline_parse_token_string_t cmd_config_e_tag_port =
12208         TOKEN_STRING_INITIALIZER
12209                 (struct cmd_config_e_tag_result,
12210                  port, "port");
12211 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12212         TOKEN_NUM_INITIALIZER
12213                 (struct cmd_config_e_tag_result,
12214                  port_id, UINT16);
12215 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12216         TOKEN_STRING_INITIALIZER
12217                 (struct cmd_config_e_tag_result,
12218                  vf, "vf");
12219 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12220         TOKEN_NUM_INITIALIZER
12221                 (struct cmd_config_e_tag_result,
12222                  vf_id, UINT8);
12223
12224 /* E-tag insertion configuration */
12225 static void
12226 cmd_config_e_tag_insertion_en_parsed(
12227         void *parsed_result,
12228         __attribute__((unused)) struct cmdline *cl,
12229         __attribute__((unused)) void *data)
12230 {
12231         struct cmd_config_e_tag_result *res =
12232                 parsed_result;
12233         struct rte_eth_l2_tunnel_conf entry;
12234
12235         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12236                 return;
12237
12238         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12239         entry.tunnel_id = res->port_tag_id_val;
12240         entry.vf_id = res->vf_id;
12241         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12242                                           &entry,
12243                                           ETH_L2_TUNNEL_INSERTION_MASK,
12244                                           1);
12245 }
12246
12247 static void
12248 cmd_config_e_tag_insertion_dis_parsed(
12249         void *parsed_result,
12250         __attribute__((unused)) struct cmdline *cl,
12251         __attribute__((unused)) void *data)
12252 {
12253         struct cmd_config_e_tag_result *res =
12254                 parsed_result;
12255         struct rte_eth_l2_tunnel_conf entry;
12256
12257         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12258                 return;
12259
12260         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12261         entry.vf_id = res->vf_id;
12262
12263         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12264                                           &entry,
12265                                           ETH_L2_TUNNEL_INSERTION_MASK,
12266                                           0);
12267 }
12268
12269 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12270         .f = cmd_config_e_tag_insertion_en_parsed,
12271         .data = NULL,
12272         .help_str = "E-tag ... : E-tag insertion enable",
12273         .tokens = {
12274                 (void *)&cmd_config_e_tag_e_tag,
12275                 (void *)&cmd_config_e_tag_set,
12276                 (void *)&cmd_config_e_tag_insertion,
12277                 (void *)&cmd_config_e_tag_on,
12278                 (void *)&cmd_config_e_tag_port_tag_id,
12279                 (void *)&cmd_config_e_tag_port_tag_id_val,
12280                 (void *)&cmd_config_e_tag_port,
12281                 (void *)&cmd_config_e_tag_port_id,
12282                 (void *)&cmd_config_e_tag_vf,
12283                 (void *)&cmd_config_e_tag_vf_id,
12284                 NULL,
12285         },
12286 };
12287
12288 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12289         .f = cmd_config_e_tag_insertion_dis_parsed,
12290         .data = NULL,
12291         .help_str = "E-tag ... : E-tag insertion disable",
12292         .tokens = {
12293                 (void *)&cmd_config_e_tag_e_tag,
12294                 (void *)&cmd_config_e_tag_set,
12295                 (void *)&cmd_config_e_tag_insertion,
12296                 (void *)&cmd_config_e_tag_off,
12297                 (void *)&cmd_config_e_tag_port,
12298                 (void *)&cmd_config_e_tag_port_id,
12299                 (void *)&cmd_config_e_tag_vf,
12300                 (void *)&cmd_config_e_tag_vf_id,
12301                 NULL,
12302         },
12303 };
12304
12305 /* E-tag stripping configuration */
12306 static void
12307 cmd_config_e_tag_stripping_parsed(
12308         void *parsed_result,
12309         __attribute__((unused)) struct cmdline *cl,
12310         __attribute__((unused)) void *data)
12311 {
12312         struct cmd_config_e_tag_result *res =
12313                 parsed_result;
12314         struct rte_eth_l2_tunnel_conf entry;
12315
12316         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12317                 return;
12318
12319         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12320
12321         if (!strcmp(res->on_off, "on"))
12322                 rte_eth_dev_l2_tunnel_offload_set
12323                         (res->port_id,
12324                          &entry,
12325                          ETH_L2_TUNNEL_STRIPPING_MASK,
12326                          1);
12327         else
12328                 rte_eth_dev_l2_tunnel_offload_set
12329                         (res->port_id,
12330                          &entry,
12331                          ETH_L2_TUNNEL_STRIPPING_MASK,
12332                          0);
12333 }
12334
12335 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12336         .f = cmd_config_e_tag_stripping_parsed,
12337         .data = NULL,
12338         .help_str = "E-tag ... : E-tag stripping enable/disable",
12339         .tokens = {
12340                 (void *)&cmd_config_e_tag_e_tag,
12341                 (void *)&cmd_config_e_tag_set,
12342                 (void *)&cmd_config_e_tag_stripping,
12343                 (void *)&cmd_config_e_tag_on_off,
12344                 (void *)&cmd_config_e_tag_port,
12345                 (void *)&cmd_config_e_tag_port_id,
12346                 NULL,
12347         },
12348 };
12349
12350 /* E-tag forwarding configuration */
12351 static void
12352 cmd_config_e_tag_forwarding_parsed(
12353         void *parsed_result,
12354         __attribute__((unused)) struct cmdline *cl,
12355         __attribute__((unused)) void *data)
12356 {
12357         struct cmd_config_e_tag_result *res = parsed_result;
12358         struct rte_eth_l2_tunnel_conf entry;
12359
12360         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12361                 return;
12362
12363         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12364
12365         if (!strcmp(res->on_off, "on"))
12366                 rte_eth_dev_l2_tunnel_offload_set
12367                         (res->port_id,
12368                          &entry,
12369                          ETH_L2_TUNNEL_FORWARDING_MASK,
12370                          1);
12371         else
12372                 rte_eth_dev_l2_tunnel_offload_set
12373                         (res->port_id,
12374                          &entry,
12375                          ETH_L2_TUNNEL_FORWARDING_MASK,
12376                          0);
12377 }
12378
12379 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12380         .f = cmd_config_e_tag_forwarding_parsed,
12381         .data = NULL,
12382         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12383         .tokens = {
12384                 (void *)&cmd_config_e_tag_e_tag,
12385                 (void *)&cmd_config_e_tag_set,
12386                 (void *)&cmd_config_e_tag_forwarding,
12387                 (void *)&cmd_config_e_tag_on_off,
12388                 (void *)&cmd_config_e_tag_port,
12389                 (void *)&cmd_config_e_tag_port_id,
12390                 NULL,
12391         },
12392 };
12393
12394 /* E-tag filter configuration */
12395 static void
12396 cmd_config_e_tag_filter_add_parsed(
12397         void *parsed_result,
12398         __attribute__((unused)) struct cmdline *cl,
12399         __attribute__((unused)) void *data)
12400 {
12401         struct cmd_config_e_tag_result *res = parsed_result;
12402         struct rte_eth_l2_tunnel_conf entry;
12403         int ret = 0;
12404
12405         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12406                 return;
12407
12408         if (res->e_tag_id_val > 0x3fff) {
12409                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12410                 return;
12411         }
12412
12413         ret = rte_eth_dev_filter_supported(res->port_id,
12414                                            RTE_ETH_FILTER_L2_TUNNEL);
12415         if (ret < 0) {
12416                 printf("E-tag filter is not supported on port %u.\n",
12417                        res->port_id);
12418                 return;
12419         }
12420
12421         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12422         entry.tunnel_id = res->e_tag_id_val;
12423         entry.pool = res->dst_pool_val;
12424
12425         ret = rte_eth_dev_filter_ctrl(res->port_id,
12426                                       RTE_ETH_FILTER_L2_TUNNEL,
12427                                       RTE_ETH_FILTER_ADD,
12428                                       &entry);
12429         if (ret < 0)
12430                 printf("E-tag filter programming error: (%s)\n",
12431                        strerror(-ret));
12432 }
12433
12434 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12435         .f = cmd_config_e_tag_filter_add_parsed,
12436         .data = NULL,
12437         .help_str = "E-tag ... : E-tag filter add",
12438         .tokens = {
12439                 (void *)&cmd_config_e_tag_e_tag,
12440                 (void *)&cmd_config_e_tag_set,
12441                 (void *)&cmd_config_e_tag_filter,
12442                 (void *)&cmd_config_e_tag_add,
12443                 (void *)&cmd_config_e_tag_e_tag_id,
12444                 (void *)&cmd_config_e_tag_e_tag_id_val,
12445                 (void *)&cmd_config_e_tag_dst_pool,
12446                 (void *)&cmd_config_e_tag_dst_pool_val,
12447                 (void *)&cmd_config_e_tag_port,
12448                 (void *)&cmd_config_e_tag_port_id,
12449                 NULL,
12450         },
12451 };
12452
12453 static void
12454 cmd_config_e_tag_filter_del_parsed(
12455         void *parsed_result,
12456         __attribute__((unused)) struct cmdline *cl,
12457         __attribute__((unused)) void *data)
12458 {
12459         struct cmd_config_e_tag_result *res = parsed_result;
12460         struct rte_eth_l2_tunnel_conf entry;
12461         int ret = 0;
12462
12463         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12464                 return;
12465
12466         if (res->e_tag_id_val > 0x3fff) {
12467                 printf("e-tag-id must be less than 0x3fff.\n");
12468                 return;
12469         }
12470
12471         ret = rte_eth_dev_filter_supported(res->port_id,
12472                                            RTE_ETH_FILTER_L2_TUNNEL);
12473         if (ret < 0) {
12474                 printf("E-tag filter is not supported on port %u.\n",
12475                        res->port_id);
12476                 return;
12477         }
12478
12479         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12480         entry.tunnel_id = res->e_tag_id_val;
12481
12482         ret = rte_eth_dev_filter_ctrl(res->port_id,
12483                                       RTE_ETH_FILTER_L2_TUNNEL,
12484                                       RTE_ETH_FILTER_DELETE,
12485                                       &entry);
12486         if (ret < 0)
12487                 printf("E-tag filter programming error: (%s)\n",
12488                        strerror(-ret));
12489 }
12490
12491 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12492         .f = cmd_config_e_tag_filter_del_parsed,
12493         .data = NULL,
12494         .help_str = "E-tag ... : E-tag filter delete",
12495         .tokens = {
12496                 (void *)&cmd_config_e_tag_e_tag,
12497                 (void *)&cmd_config_e_tag_set,
12498                 (void *)&cmd_config_e_tag_filter,
12499                 (void *)&cmd_config_e_tag_del,
12500                 (void *)&cmd_config_e_tag_e_tag_id,
12501                 (void *)&cmd_config_e_tag_e_tag_id_val,
12502                 (void *)&cmd_config_e_tag_port,
12503                 (void *)&cmd_config_e_tag_port_id,
12504                 NULL,
12505         },
12506 };
12507
12508 /* vf vlan anti spoof configuration */
12509
12510 /* Common result structure for vf vlan anti spoof */
12511 struct cmd_vf_vlan_anti_spoof_result {
12512         cmdline_fixed_string_t set;
12513         cmdline_fixed_string_t vf;
12514         cmdline_fixed_string_t vlan;
12515         cmdline_fixed_string_t antispoof;
12516         portid_t port_id;
12517         uint32_t vf_id;
12518         cmdline_fixed_string_t on_off;
12519 };
12520
12521 /* Common CLI fields for vf vlan anti spoof enable disable */
12522 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12523         TOKEN_STRING_INITIALIZER
12524                 (struct cmd_vf_vlan_anti_spoof_result,
12525                  set, "set");
12526 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12527         TOKEN_STRING_INITIALIZER
12528                 (struct cmd_vf_vlan_anti_spoof_result,
12529                  vf, "vf");
12530 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12531         TOKEN_STRING_INITIALIZER
12532                 (struct cmd_vf_vlan_anti_spoof_result,
12533                  vlan, "vlan");
12534 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12535         TOKEN_STRING_INITIALIZER
12536                 (struct cmd_vf_vlan_anti_spoof_result,
12537                  antispoof, "antispoof");
12538 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12539         TOKEN_NUM_INITIALIZER
12540                 (struct cmd_vf_vlan_anti_spoof_result,
12541                  port_id, UINT16);
12542 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12543         TOKEN_NUM_INITIALIZER
12544                 (struct cmd_vf_vlan_anti_spoof_result,
12545                  vf_id, UINT32);
12546 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12547         TOKEN_STRING_INITIALIZER
12548                 (struct cmd_vf_vlan_anti_spoof_result,
12549                  on_off, "on#off");
12550
12551 static void
12552 cmd_set_vf_vlan_anti_spoof_parsed(
12553         void *parsed_result,
12554         __attribute__((unused)) struct cmdline *cl,
12555         __attribute__((unused)) void *data)
12556 {
12557         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12558         int ret = -ENOTSUP;
12559
12560         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12561
12562         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12563                 return;
12564
12565 #ifdef RTE_LIBRTE_IXGBE_PMD
12566         if (ret == -ENOTSUP)
12567                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12568                                 res->vf_id, is_on);
12569 #endif
12570 #ifdef RTE_LIBRTE_I40E_PMD
12571         if (ret == -ENOTSUP)
12572                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12573                                 res->vf_id, is_on);
12574 #endif
12575 #ifdef RTE_LIBRTE_BNXT_PMD
12576         if (ret == -ENOTSUP)
12577                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12578                                 res->vf_id, is_on);
12579 #endif
12580
12581         switch (ret) {
12582         case 0:
12583                 break;
12584         case -EINVAL:
12585                 printf("invalid vf_id %d\n", res->vf_id);
12586                 break;
12587         case -ENODEV:
12588                 printf("invalid port_id %d\n", res->port_id);
12589                 break;
12590         case -ENOTSUP:
12591                 printf("function not implemented\n");
12592                 break;
12593         default:
12594                 printf("programming error: (%s)\n", strerror(-ret));
12595         }
12596 }
12597
12598 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12599         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12600         .data = NULL,
12601         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12602         .tokens = {
12603                 (void *)&cmd_vf_vlan_anti_spoof_set,
12604                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12605                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12606                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12607                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12608                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12609                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12610                 NULL,
12611         },
12612 };
12613
12614 /* vf mac anti spoof configuration */
12615
12616 /* Common result structure for vf mac anti spoof */
12617 struct cmd_vf_mac_anti_spoof_result {
12618         cmdline_fixed_string_t set;
12619         cmdline_fixed_string_t vf;
12620         cmdline_fixed_string_t mac;
12621         cmdline_fixed_string_t antispoof;
12622         portid_t port_id;
12623         uint32_t vf_id;
12624         cmdline_fixed_string_t on_off;
12625 };
12626
12627 /* Common CLI fields for vf mac anti spoof enable disable */
12628 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12629         TOKEN_STRING_INITIALIZER
12630                 (struct cmd_vf_mac_anti_spoof_result,
12631                  set, "set");
12632 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12633         TOKEN_STRING_INITIALIZER
12634                 (struct cmd_vf_mac_anti_spoof_result,
12635                  vf, "vf");
12636 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12637         TOKEN_STRING_INITIALIZER
12638                 (struct cmd_vf_mac_anti_spoof_result,
12639                  mac, "mac");
12640 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12641         TOKEN_STRING_INITIALIZER
12642                 (struct cmd_vf_mac_anti_spoof_result,
12643                  antispoof, "antispoof");
12644 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12645         TOKEN_NUM_INITIALIZER
12646                 (struct cmd_vf_mac_anti_spoof_result,
12647                  port_id, UINT16);
12648 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12649         TOKEN_NUM_INITIALIZER
12650                 (struct cmd_vf_mac_anti_spoof_result,
12651                  vf_id, UINT32);
12652 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12653         TOKEN_STRING_INITIALIZER
12654                 (struct cmd_vf_mac_anti_spoof_result,
12655                  on_off, "on#off");
12656
12657 static void
12658 cmd_set_vf_mac_anti_spoof_parsed(
12659         void *parsed_result,
12660         __attribute__((unused)) struct cmdline *cl,
12661         __attribute__((unused)) void *data)
12662 {
12663         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12664         int ret = -ENOTSUP;
12665
12666         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12667
12668         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12669                 return;
12670
12671 #ifdef RTE_LIBRTE_IXGBE_PMD
12672         if (ret == -ENOTSUP)
12673                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12674                         res->vf_id, is_on);
12675 #endif
12676 #ifdef RTE_LIBRTE_I40E_PMD
12677         if (ret == -ENOTSUP)
12678                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12679                         res->vf_id, is_on);
12680 #endif
12681 #ifdef RTE_LIBRTE_BNXT_PMD
12682         if (ret == -ENOTSUP)
12683                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12684                         res->vf_id, is_on);
12685 #endif
12686
12687         switch (ret) {
12688         case 0:
12689                 break;
12690         case -EINVAL:
12691                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12692                 break;
12693         case -ENODEV:
12694                 printf("invalid port_id %d\n", res->port_id);
12695                 break;
12696         case -ENOTSUP:
12697                 printf("function not implemented\n");
12698                 break;
12699         default:
12700                 printf("programming error: (%s)\n", strerror(-ret));
12701         }
12702 }
12703
12704 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12705         .f = cmd_set_vf_mac_anti_spoof_parsed,
12706         .data = NULL,
12707         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12708         .tokens = {
12709                 (void *)&cmd_vf_mac_anti_spoof_set,
12710                 (void *)&cmd_vf_mac_anti_spoof_vf,
12711                 (void *)&cmd_vf_mac_anti_spoof_mac,
12712                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12713                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12714                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12715                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12716                 NULL,
12717         },
12718 };
12719
12720 /* vf vlan strip queue configuration */
12721
12722 /* Common result structure for vf mac anti spoof */
12723 struct cmd_vf_vlan_stripq_result {
12724         cmdline_fixed_string_t set;
12725         cmdline_fixed_string_t vf;
12726         cmdline_fixed_string_t vlan;
12727         cmdline_fixed_string_t stripq;
12728         portid_t port_id;
12729         uint16_t vf_id;
12730         cmdline_fixed_string_t on_off;
12731 };
12732
12733 /* Common CLI fields for vf vlan strip enable disable */
12734 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12735         TOKEN_STRING_INITIALIZER
12736                 (struct cmd_vf_vlan_stripq_result,
12737                  set, "set");
12738 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12739         TOKEN_STRING_INITIALIZER
12740                 (struct cmd_vf_vlan_stripq_result,
12741                  vf, "vf");
12742 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12743         TOKEN_STRING_INITIALIZER
12744                 (struct cmd_vf_vlan_stripq_result,
12745                  vlan, "vlan");
12746 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12747         TOKEN_STRING_INITIALIZER
12748                 (struct cmd_vf_vlan_stripq_result,
12749                  stripq, "stripq");
12750 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12751         TOKEN_NUM_INITIALIZER
12752                 (struct cmd_vf_vlan_stripq_result,
12753                  port_id, UINT16);
12754 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12755         TOKEN_NUM_INITIALIZER
12756                 (struct cmd_vf_vlan_stripq_result,
12757                  vf_id, UINT16);
12758 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12759         TOKEN_STRING_INITIALIZER
12760                 (struct cmd_vf_vlan_stripq_result,
12761                  on_off, "on#off");
12762
12763 static void
12764 cmd_set_vf_vlan_stripq_parsed(
12765         void *parsed_result,
12766         __attribute__((unused)) struct cmdline *cl,
12767         __attribute__((unused)) void *data)
12768 {
12769         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12770         int ret = -ENOTSUP;
12771
12772         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12773
12774         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12775                 return;
12776
12777 #ifdef RTE_LIBRTE_IXGBE_PMD
12778         if (ret == -ENOTSUP)
12779                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12780                         res->vf_id, is_on);
12781 #endif
12782 #ifdef RTE_LIBRTE_I40E_PMD
12783         if (ret == -ENOTSUP)
12784                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12785                         res->vf_id, is_on);
12786 #endif
12787 #ifdef RTE_LIBRTE_BNXT_PMD
12788         if (ret == -ENOTSUP)
12789                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12790                         res->vf_id, is_on);
12791 #endif
12792
12793         switch (ret) {
12794         case 0:
12795                 break;
12796         case -EINVAL:
12797                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12798                 break;
12799         case -ENODEV:
12800                 printf("invalid port_id %d\n", res->port_id);
12801                 break;
12802         case -ENOTSUP:
12803                 printf("function not implemented\n");
12804                 break;
12805         default:
12806                 printf("programming error: (%s)\n", strerror(-ret));
12807         }
12808 }
12809
12810 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12811         .f = cmd_set_vf_vlan_stripq_parsed,
12812         .data = NULL,
12813         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12814         .tokens = {
12815                 (void *)&cmd_vf_vlan_stripq_set,
12816                 (void *)&cmd_vf_vlan_stripq_vf,
12817                 (void *)&cmd_vf_vlan_stripq_vlan,
12818                 (void *)&cmd_vf_vlan_stripq_stripq,
12819                 (void *)&cmd_vf_vlan_stripq_port_id,
12820                 (void *)&cmd_vf_vlan_stripq_vf_id,
12821                 (void *)&cmd_vf_vlan_stripq_on_off,
12822                 NULL,
12823         },
12824 };
12825
12826 /* vf vlan insert configuration */
12827
12828 /* Common result structure for vf vlan insert */
12829 struct cmd_vf_vlan_insert_result {
12830         cmdline_fixed_string_t set;
12831         cmdline_fixed_string_t vf;
12832         cmdline_fixed_string_t vlan;
12833         cmdline_fixed_string_t insert;
12834         portid_t port_id;
12835         uint16_t vf_id;
12836         uint16_t vlan_id;
12837 };
12838
12839 /* Common CLI fields for vf vlan insert enable disable */
12840 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12841         TOKEN_STRING_INITIALIZER
12842                 (struct cmd_vf_vlan_insert_result,
12843                  set, "set");
12844 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12845         TOKEN_STRING_INITIALIZER
12846                 (struct cmd_vf_vlan_insert_result,
12847                  vf, "vf");
12848 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12849         TOKEN_STRING_INITIALIZER
12850                 (struct cmd_vf_vlan_insert_result,
12851                  vlan, "vlan");
12852 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12853         TOKEN_STRING_INITIALIZER
12854                 (struct cmd_vf_vlan_insert_result,
12855                  insert, "insert");
12856 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12857         TOKEN_NUM_INITIALIZER
12858                 (struct cmd_vf_vlan_insert_result,
12859                  port_id, UINT16);
12860 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12861         TOKEN_NUM_INITIALIZER
12862                 (struct cmd_vf_vlan_insert_result,
12863                  vf_id, UINT16);
12864 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12865         TOKEN_NUM_INITIALIZER
12866                 (struct cmd_vf_vlan_insert_result,
12867                  vlan_id, UINT16);
12868
12869 static void
12870 cmd_set_vf_vlan_insert_parsed(
12871         void *parsed_result,
12872         __attribute__((unused)) struct cmdline *cl,
12873         __attribute__((unused)) void *data)
12874 {
12875         struct cmd_vf_vlan_insert_result *res = parsed_result;
12876         int ret = -ENOTSUP;
12877
12878         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12879                 return;
12880
12881 #ifdef RTE_LIBRTE_IXGBE_PMD
12882         if (ret == -ENOTSUP)
12883                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12884                         res->vlan_id);
12885 #endif
12886 #ifdef RTE_LIBRTE_I40E_PMD
12887         if (ret == -ENOTSUP)
12888                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12889                         res->vlan_id);
12890 #endif
12891 #ifdef RTE_LIBRTE_BNXT_PMD
12892         if (ret == -ENOTSUP)
12893                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12894                         res->vlan_id);
12895 #endif
12896
12897         switch (ret) {
12898         case 0:
12899                 break;
12900         case -EINVAL:
12901                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12902                 break;
12903         case -ENODEV:
12904                 printf("invalid port_id %d\n", res->port_id);
12905                 break;
12906         case -ENOTSUP:
12907                 printf("function not implemented\n");
12908                 break;
12909         default:
12910                 printf("programming error: (%s)\n", strerror(-ret));
12911         }
12912 }
12913
12914 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12915         .f = cmd_set_vf_vlan_insert_parsed,
12916         .data = NULL,
12917         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12918         .tokens = {
12919                 (void *)&cmd_vf_vlan_insert_set,
12920                 (void *)&cmd_vf_vlan_insert_vf,
12921                 (void *)&cmd_vf_vlan_insert_vlan,
12922                 (void *)&cmd_vf_vlan_insert_insert,
12923                 (void *)&cmd_vf_vlan_insert_port_id,
12924                 (void *)&cmd_vf_vlan_insert_vf_id,
12925                 (void *)&cmd_vf_vlan_insert_vlan_id,
12926                 NULL,
12927         },
12928 };
12929
12930 /* tx loopback configuration */
12931
12932 /* Common result structure for tx loopback */
12933 struct cmd_tx_loopback_result {
12934         cmdline_fixed_string_t set;
12935         cmdline_fixed_string_t tx;
12936         cmdline_fixed_string_t loopback;
12937         portid_t port_id;
12938         cmdline_fixed_string_t on_off;
12939 };
12940
12941 /* Common CLI fields for tx loopback enable disable */
12942 cmdline_parse_token_string_t cmd_tx_loopback_set =
12943         TOKEN_STRING_INITIALIZER
12944                 (struct cmd_tx_loopback_result,
12945                  set, "set");
12946 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12947         TOKEN_STRING_INITIALIZER
12948                 (struct cmd_tx_loopback_result,
12949                  tx, "tx");
12950 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12951         TOKEN_STRING_INITIALIZER
12952                 (struct cmd_tx_loopback_result,
12953                  loopback, "loopback");
12954 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12955         TOKEN_NUM_INITIALIZER
12956                 (struct cmd_tx_loopback_result,
12957                  port_id, UINT16);
12958 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12959         TOKEN_STRING_INITIALIZER
12960                 (struct cmd_tx_loopback_result,
12961                  on_off, "on#off");
12962
12963 static void
12964 cmd_set_tx_loopback_parsed(
12965         void *parsed_result,
12966         __attribute__((unused)) struct cmdline *cl,
12967         __attribute__((unused)) void *data)
12968 {
12969         struct cmd_tx_loopback_result *res = parsed_result;
12970         int ret = -ENOTSUP;
12971
12972         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12973
12974         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12975                 return;
12976
12977 #ifdef RTE_LIBRTE_IXGBE_PMD
12978         if (ret == -ENOTSUP)
12979                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12980 #endif
12981 #ifdef RTE_LIBRTE_I40E_PMD
12982         if (ret == -ENOTSUP)
12983                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12984 #endif
12985 #ifdef RTE_LIBRTE_BNXT_PMD
12986         if (ret == -ENOTSUP)
12987                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12988 #endif
12989 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
12990         if (ret == -ENOTSUP)
12991                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12992 #endif
12993
12994         switch (ret) {
12995         case 0:
12996                 break;
12997         case -EINVAL:
12998                 printf("invalid is_on %d\n", is_on);
12999                 break;
13000         case -ENODEV:
13001                 printf("invalid port_id %d\n", res->port_id);
13002                 break;
13003         case -ENOTSUP:
13004                 printf("function not implemented\n");
13005                 break;
13006         default:
13007                 printf("programming error: (%s)\n", strerror(-ret));
13008         }
13009 }
13010
13011 cmdline_parse_inst_t cmd_set_tx_loopback = {
13012         .f = cmd_set_tx_loopback_parsed,
13013         .data = NULL,
13014         .help_str = "set tx loopback <port_id> on|off",
13015         .tokens = {
13016                 (void *)&cmd_tx_loopback_set,
13017                 (void *)&cmd_tx_loopback_tx,
13018                 (void *)&cmd_tx_loopback_loopback,
13019                 (void *)&cmd_tx_loopback_port_id,
13020                 (void *)&cmd_tx_loopback_on_off,
13021                 NULL,
13022         },
13023 };
13024
13025 /* all queues drop enable configuration */
13026
13027 /* Common result structure for all queues drop enable */
13028 struct cmd_all_queues_drop_en_result {
13029         cmdline_fixed_string_t set;
13030         cmdline_fixed_string_t all;
13031         cmdline_fixed_string_t queues;
13032         cmdline_fixed_string_t drop;
13033         portid_t port_id;
13034         cmdline_fixed_string_t on_off;
13035 };
13036
13037 /* Common CLI fields for tx loopback enable disable */
13038 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13039         TOKEN_STRING_INITIALIZER
13040                 (struct cmd_all_queues_drop_en_result,
13041                  set, "set");
13042 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13043         TOKEN_STRING_INITIALIZER
13044                 (struct cmd_all_queues_drop_en_result,
13045                  all, "all");
13046 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13047         TOKEN_STRING_INITIALIZER
13048                 (struct cmd_all_queues_drop_en_result,
13049                  queues, "queues");
13050 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13051         TOKEN_STRING_INITIALIZER
13052                 (struct cmd_all_queues_drop_en_result,
13053                  drop, "drop");
13054 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13055         TOKEN_NUM_INITIALIZER
13056                 (struct cmd_all_queues_drop_en_result,
13057                  port_id, UINT16);
13058 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13059         TOKEN_STRING_INITIALIZER
13060                 (struct cmd_all_queues_drop_en_result,
13061                  on_off, "on#off");
13062
13063 static void
13064 cmd_set_all_queues_drop_en_parsed(
13065         void *parsed_result,
13066         __attribute__((unused)) struct cmdline *cl,
13067         __attribute__((unused)) void *data)
13068 {
13069         struct cmd_all_queues_drop_en_result *res = parsed_result;
13070         int ret = -ENOTSUP;
13071         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13072
13073         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13074                 return;
13075
13076 #ifdef RTE_LIBRTE_IXGBE_PMD
13077         if (ret == -ENOTSUP)
13078                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13079 #endif
13080 #ifdef RTE_LIBRTE_BNXT_PMD
13081         if (ret == -ENOTSUP)
13082                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13083 #endif
13084         switch (ret) {
13085         case 0:
13086                 break;
13087         case -EINVAL:
13088                 printf("invalid is_on %d\n", is_on);
13089                 break;
13090         case -ENODEV:
13091                 printf("invalid port_id %d\n", res->port_id);
13092                 break;
13093         case -ENOTSUP:
13094                 printf("function not implemented\n");
13095                 break;
13096         default:
13097                 printf("programming error: (%s)\n", strerror(-ret));
13098         }
13099 }
13100
13101 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13102         .f = cmd_set_all_queues_drop_en_parsed,
13103         .data = NULL,
13104         .help_str = "set all queues drop <port_id> on|off",
13105         .tokens = {
13106                 (void *)&cmd_all_queues_drop_en_set,
13107                 (void *)&cmd_all_queues_drop_en_all,
13108                 (void *)&cmd_all_queues_drop_en_queues,
13109                 (void *)&cmd_all_queues_drop_en_drop,
13110                 (void *)&cmd_all_queues_drop_en_port_id,
13111                 (void *)&cmd_all_queues_drop_en_on_off,
13112                 NULL,
13113         },
13114 };
13115
13116 /* vf split drop enable configuration */
13117
13118 /* Common result structure for vf split drop enable */
13119 struct cmd_vf_split_drop_en_result {
13120         cmdline_fixed_string_t set;
13121         cmdline_fixed_string_t vf;
13122         cmdline_fixed_string_t split;
13123         cmdline_fixed_string_t drop;
13124         portid_t port_id;
13125         uint16_t vf_id;
13126         cmdline_fixed_string_t on_off;
13127 };
13128
13129 /* Common CLI fields for vf split drop enable disable */
13130 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13131         TOKEN_STRING_INITIALIZER
13132                 (struct cmd_vf_split_drop_en_result,
13133                  set, "set");
13134 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13135         TOKEN_STRING_INITIALIZER
13136                 (struct cmd_vf_split_drop_en_result,
13137                  vf, "vf");
13138 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13139         TOKEN_STRING_INITIALIZER
13140                 (struct cmd_vf_split_drop_en_result,
13141                  split, "split");
13142 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13143         TOKEN_STRING_INITIALIZER
13144                 (struct cmd_vf_split_drop_en_result,
13145                  drop, "drop");
13146 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13147         TOKEN_NUM_INITIALIZER
13148                 (struct cmd_vf_split_drop_en_result,
13149                  port_id, UINT16);
13150 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13151         TOKEN_NUM_INITIALIZER
13152                 (struct cmd_vf_split_drop_en_result,
13153                  vf_id, UINT16);
13154 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13155         TOKEN_STRING_INITIALIZER
13156                 (struct cmd_vf_split_drop_en_result,
13157                  on_off, "on#off");
13158
13159 static void
13160 cmd_set_vf_split_drop_en_parsed(
13161         void *parsed_result,
13162         __attribute__((unused)) struct cmdline *cl,
13163         __attribute__((unused)) void *data)
13164 {
13165         struct cmd_vf_split_drop_en_result *res = parsed_result;
13166         int ret = -ENOTSUP;
13167         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13168
13169         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13170                 return;
13171
13172 #ifdef RTE_LIBRTE_IXGBE_PMD
13173         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13174                         is_on);
13175 #endif
13176         switch (ret) {
13177         case 0:
13178                 break;
13179         case -EINVAL:
13180                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13181                 break;
13182         case -ENODEV:
13183                 printf("invalid port_id %d\n", res->port_id);
13184                 break;
13185         case -ENOTSUP:
13186                 printf("not supported on port %d\n", res->port_id);
13187                 break;
13188         default:
13189                 printf("programming error: (%s)\n", strerror(-ret));
13190         }
13191 }
13192
13193 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13194         .f = cmd_set_vf_split_drop_en_parsed,
13195         .data = NULL,
13196         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13197         .tokens = {
13198                 (void *)&cmd_vf_split_drop_en_set,
13199                 (void *)&cmd_vf_split_drop_en_vf,
13200                 (void *)&cmd_vf_split_drop_en_split,
13201                 (void *)&cmd_vf_split_drop_en_drop,
13202                 (void *)&cmd_vf_split_drop_en_port_id,
13203                 (void *)&cmd_vf_split_drop_en_vf_id,
13204                 (void *)&cmd_vf_split_drop_en_on_off,
13205                 NULL,
13206         },
13207 };
13208
13209 /* vf mac address configuration */
13210
13211 /* Common result structure for vf mac address */
13212 struct cmd_set_vf_mac_addr_result {
13213         cmdline_fixed_string_t set;
13214         cmdline_fixed_string_t vf;
13215         cmdline_fixed_string_t mac;
13216         cmdline_fixed_string_t addr;
13217         portid_t port_id;
13218         uint16_t vf_id;
13219         struct ether_addr mac_addr;
13220
13221 };
13222
13223 /* Common CLI fields for vf split drop enable disable */
13224 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13225         TOKEN_STRING_INITIALIZER
13226                 (struct cmd_set_vf_mac_addr_result,
13227                  set, "set");
13228 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13229         TOKEN_STRING_INITIALIZER
13230                 (struct cmd_set_vf_mac_addr_result,
13231                  vf, "vf");
13232 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13233         TOKEN_STRING_INITIALIZER
13234                 (struct cmd_set_vf_mac_addr_result,
13235                  mac, "mac");
13236 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13237         TOKEN_STRING_INITIALIZER
13238                 (struct cmd_set_vf_mac_addr_result,
13239                  addr, "addr");
13240 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13241         TOKEN_NUM_INITIALIZER
13242                 (struct cmd_set_vf_mac_addr_result,
13243                  port_id, UINT16);
13244 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13245         TOKEN_NUM_INITIALIZER
13246                 (struct cmd_set_vf_mac_addr_result,
13247                  vf_id, UINT16);
13248 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13249         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13250                  mac_addr);
13251
13252 static void
13253 cmd_set_vf_mac_addr_parsed(
13254         void *parsed_result,
13255         __attribute__((unused)) struct cmdline *cl,
13256         __attribute__((unused)) void *data)
13257 {
13258         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13259         int ret = -ENOTSUP;
13260
13261         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13262                 return;
13263
13264 #ifdef RTE_LIBRTE_IXGBE_PMD
13265         if (ret == -ENOTSUP)
13266                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13267                                 &res->mac_addr);
13268 #endif
13269 #ifdef RTE_LIBRTE_I40E_PMD
13270         if (ret == -ENOTSUP)
13271                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13272                                 &res->mac_addr);
13273 #endif
13274 #ifdef RTE_LIBRTE_BNXT_PMD
13275         if (ret == -ENOTSUP)
13276                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13277                                 &res->mac_addr);
13278 #endif
13279
13280         switch (ret) {
13281         case 0:
13282                 break;
13283         case -EINVAL:
13284                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13285                 break;
13286         case -ENODEV:
13287                 printf("invalid port_id %d\n", res->port_id);
13288                 break;
13289         case -ENOTSUP:
13290                 printf("function not implemented\n");
13291                 break;
13292         default:
13293                 printf("programming error: (%s)\n", strerror(-ret));
13294         }
13295 }
13296
13297 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13298         .f = cmd_set_vf_mac_addr_parsed,
13299         .data = NULL,
13300         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13301         .tokens = {
13302                 (void *)&cmd_set_vf_mac_addr_set,
13303                 (void *)&cmd_set_vf_mac_addr_vf,
13304                 (void *)&cmd_set_vf_mac_addr_mac,
13305                 (void *)&cmd_set_vf_mac_addr_addr,
13306                 (void *)&cmd_set_vf_mac_addr_port_id,
13307                 (void *)&cmd_set_vf_mac_addr_vf_id,
13308                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13309                 NULL,
13310         },
13311 };
13312
13313 /* MACsec configuration */
13314
13315 /* Common result structure for MACsec offload enable */
13316 struct cmd_macsec_offload_on_result {
13317         cmdline_fixed_string_t set;
13318         cmdline_fixed_string_t macsec;
13319         cmdline_fixed_string_t offload;
13320         portid_t port_id;
13321         cmdline_fixed_string_t on;
13322         cmdline_fixed_string_t encrypt;
13323         cmdline_fixed_string_t en_on_off;
13324         cmdline_fixed_string_t replay_protect;
13325         cmdline_fixed_string_t rp_on_off;
13326 };
13327
13328 /* Common CLI fields for MACsec offload disable */
13329 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13330         TOKEN_STRING_INITIALIZER
13331                 (struct cmd_macsec_offload_on_result,
13332                  set, "set");
13333 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13334         TOKEN_STRING_INITIALIZER
13335                 (struct cmd_macsec_offload_on_result,
13336                  macsec, "macsec");
13337 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13338         TOKEN_STRING_INITIALIZER
13339                 (struct cmd_macsec_offload_on_result,
13340                  offload, "offload");
13341 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13342         TOKEN_NUM_INITIALIZER
13343                 (struct cmd_macsec_offload_on_result,
13344                  port_id, UINT16);
13345 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13346         TOKEN_STRING_INITIALIZER
13347                 (struct cmd_macsec_offload_on_result,
13348                  on, "on");
13349 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13350         TOKEN_STRING_INITIALIZER
13351                 (struct cmd_macsec_offload_on_result,
13352                  encrypt, "encrypt");
13353 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13354         TOKEN_STRING_INITIALIZER
13355                 (struct cmd_macsec_offload_on_result,
13356                  en_on_off, "on#off");
13357 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13358         TOKEN_STRING_INITIALIZER
13359                 (struct cmd_macsec_offload_on_result,
13360                  replay_protect, "replay-protect");
13361 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13362         TOKEN_STRING_INITIALIZER
13363                 (struct cmd_macsec_offload_on_result,
13364                  rp_on_off, "on#off");
13365
13366 static void
13367 cmd_set_macsec_offload_on_parsed(
13368         void *parsed_result,
13369         __attribute__((unused)) struct cmdline *cl,
13370         __attribute__((unused)) void *data)
13371 {
13372         struct cmd_macsec_offload_on_result *res = parsed_result;
13373         int ret = -ENOTSUP;
13374         portid_t port_id = res->port_id;
13375         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13376         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13377         struct rte_eth_dev_info dev_info;
13378
13379         if (port_id_is_invalid(port_id, ENABLED_WARN))
13380                 return;
13381         if (!port_is_stopped(port_id)) {
13382                 printf("Please stop port %d first\n", port_id);
13383                 return;
13384         }
13385
13386         rte_eth_dev_info_get(port_id, &dev_info);
13387         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13388 #ifdef RTE_LIBRTE_IXGBE_PMD
13389                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13390 #endif
13391         }
13392         RTE_SET_USED(en);
13393         RTE_SET_USED(rp);
13394
13395         switch (ret) {
13396         case 0:
13397                 ports[port_id].dev_conf.txmode.offloads |=
13398                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13399                 cmd_reconfig_device_queue(port_id, 1, 1);
13400                 break;
13401         case -ENODEV:
13402                 printf("invalid port_id %d\n", port_id);
13403                 break;
13404         case -ENOTSUP:
13405                 printf("not supported on port %d\n", port_id);
13406                 break;
13407         default:
13408                 printf("programming error: (%s)\n", strerror(-ret));
13409         }
13410 }
13411
13412 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13413         .f = cmd_set_macsec_offload_on_parsed,
13414         .data = NULL,
13415         .help_str = "set macsec offload <port_id> on "
13416                 "encrypt on|off replay-protect on|off",
13417         .tokens = {
13418                 (void *)&cmd_macsec_offload_on_set,
13419                 (void *)&cmd_macsec_offload_on_macsec,
13420                 (void *)&cmd_macsec_offload_on_offload,
13421                 (void *)&cmd_macsec_offload_on_port_id,
13422                 (void *)&cmd_macsec_offload_on_on,
13423                 (void *)&cmd_macsec_offload_on_encrypt,
13424                 (void *)&cmd_macsec_offload_on_en_on_off,
13425                 (void *)&cmd_macsec_offload_on_replay_protect,
13426                 (void *)&cmd_macsec_offload_on_rp_on_off,
13427                 NULL,
13428         },
13429 };
13430
13431 /* Common result structure for MACsec offload disable */
13432 struct cmd_macsec_offload_off_result {
13433         cmdline_fixed_string_t set;
13434         cmdline_fixed_string_t macsec;
13435         cmdline_fixed_string_t offload;
13436         portid_t port_id;
13437         cmdline_fixed_string_t off;
13438 };
13439
13440 /* Common CLI fields for MACsec offload disable */
13441 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13442         TOKEN_STRING_INITIALIZER
13443                 (struct cmd_macsec_offload_off_result,
13444                  set, "set");
13445 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13446         TOKEN_STRING_INITIALIZER
13447                 (struct cmd_macsec_offload_off_result,
13448                  macsec, "macsec");
13449 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13450         TOKEN_STRING_INITIALIZER
13451                 (struct cmd_macsec_offload_off_result,
13452                  offload, "offload");
13453 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13454         TOKEN_NUM_INITIALIZER
13455                 (struct cmd_macsec_offload_off_result,
13456                  port_id, UINT16);
13457 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13458         TOKEN_STRING_INITIALIZER
13459                 (struct cmd_macsec_offload_off_result,
13460                  off, "off");
13461
13462 static void
13463 cmd_set_macsec_offload_off_parsed(
13464         void *parsed_result,
13465         __attribute__((unused)) struct cmdline *cl,
13466         __attribute__((unused)) void *data)
13467 {
13468         struct cmd_macsec_offload_off_result *res = parsed_result;
13469         int ret = -ENOTSUP;
13470         struct rte_eth_dev_info dev_info;
13471         portid_t port_id = res->port_id;
13472
13473         if (port_id_is_invalid(port_id, ENABLED_WARN))
13474                 return;
13475         if (!port_is_stopped(port_id)) {
13476                 printf("Please stop port %d first\n", port_id);
13477                 return;
13478         }
13479
13480         rte_eth_dev_info_get(port_id, &dev_info);
13481         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13482 #ifdef RTE_LIBRTE_IXGBE_PMD
13483                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13484 #endif
13485         }
13486         switch (ret) {
13487         case 0:
13488                 ports[port_id].dev_conf.txmode.offloads &=
13489                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13490                 cmd_reconfig_device_queue(port_id, 1, 1);
13491                 break;
13492         case -ENODEV:
13493                 printf("invalid port_id %d\n", port_id);
13494                 break;
13495         case -ENOTSUP:
13496                 printf("not supported on port %d\n", port_id);
13497                 break;
13498         default:
13499                 printf("programming error: (%s)\n", strerror(-ret));
13500         }
13501 }
13502
13503 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13504         .f = cmd_set_macsec_offload_off_parsed,
13505         .data = NULL,
13506         .help_str = "set macsec offload <port_id> off",
13507         .tokens = {
13508                 (void *)&cmd_macsec_offload_off_set,
13509                 (void *)&cmd_macsec_offload_off_macsec,
13510                 (void *)&cmd_macsec_offload_off_offload,
13511                 (void *)&cmd_macsec_offload_off_port_id,
13512                 (void *)&cmd_macsec_offload_off_off,
13513                 NULL,
13514         },
13515 };
13516
13517 /* Common result structure for MACsec secure connection configure */
13518 struct cmd_macsec_sc_result {
13519         cmdline_fixed_string_t set;
13520         cmdline_fixed_string_t macsec;
13521         cmdline_fixed_string_t sc;
13522         cmdline_fixed_string_t tx_rx;
13523         portid_t port_id;
13524         struct ether_addr mac;
13525         uint16_t pi;
13526 };
13527
13528 /* Common CLI fields for MACsec secure connection configure */
13529 cmdline_parse_token_string_t cmd_macsec_sc_set =
13530         TOKEN_STRING_INITIALIZER
13531                 (struct cmd_macsec_sc_result,
13532                  set, "set");
13533 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13534         TOKEN_STRING_INITIALIZER
13535                 (struct cmd_macsec_sc_result,
13536                  macsec, "macsec");
13537 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13538         TOKEN_STRING_INITIALIZER
13539                 (struct cmd_macsec_sc_result,
13540                  sc, "sc");
13541 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13542         TOKEN_STRING_INITIALIZER
13543                 (struct cmd_macsec_sc_result,
13544                  tx_rx, "tx#rx");
13545 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13546         TOKEN_NUM_INITIALIZER
13547                 (struct cmd_macsec_sc_result,
13548                  port_id, UINT16);
13549 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13550         TOKEN_ETHERADDR_INITIALIZER
13551                 (struct cmd_macsec_sc_result,
13552                  mac);
13553 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13554         TOKEN_NUM_INITIALIZER
13555                 (struct cmd_macsec_sc_result,
13556                  pi, UINT16);
13557
13558 static void
13559 cmd_set_macsec_sc_parsed(
13560         void *parsed_result,
13561         __attribute__((unused)) struct cmdline *cl,
13562         __attribute__((unused)) void *data)
13563 {
13564         struct cmd_macsec_sc_result *res = parsed_result;
13565         int ret = -ENOTSUP;
13566         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13567
13568 #ifdef RTE_LIBRTE_IXGBE_PMD
13569         ret = is_tx ?
13570                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13571                                 res->mac.addr_bytes) :
13572                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13573                                 res->mac.addr_bytes, res->pi);
13574 #endif
13575         RTE_SET_USED(is_tx);
13576
13577         switch (ret) {
13578         case 0:
13579                 break;
13580         case -ENODEV:
13581                 printf("invalid port_id %d\n", res->port_id);
13582                 break;
13583         case -ENOTSUP:
13584                 printf("not supported on port %d\n", res->port_id);
13585                 break;
13586         default:
13587                 printf("programming error: (%s)\n", strerror(-ret));
13588         }
13589 }
13590
13591 cmdline_parse_inst_t cmd_set_macsec_sc = {
13592         .f = cmd_set_macsec_sc_parsed,
13593         .data = NULL,
13594         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13595         .tokens = {
13596                 (void *)&cmd_macsec_sc_set,
13597                 (void *)&cmd_macsec_sc_macsec,
13598                 (void *)&cmd_macsec_sc_sc,
13599                 (void *)&cmd_macsec_sc_tx_rx,
13600                 (void *)&cmd_macsec_sc_port_id,
13601                 (void *)&cmd_macsec_sc_mac,
13602                 (void *)&cmd_macsec_sc_pi,
13603                 NULL,
13604         },
13605 };
13606
13607 /* Common result structure for MACsec secure connection configure */
13608 struct cmd_macsec_sa_result {
13609         cmdline_fixed_string_t set;
13610         cmdline_fixed_string_t macsec;
13611         cmdline_fixed_string_t sa;
13612         cmdline_fixed_string_t tx_rx;
13613         portid_t port_id;
13614         uint8_t idx;
13615         uint8_t an;
13616         uint32_t pn;
13617         cmdline_fixed_string_t key;
13618 };
13619
13620 /* Common CLI fields for MACsec secure connection configure */
13621 cmdline_parse_token_string_t cmd_macsec_sa_set =
13622         TOKEN_STRING_INITIALIZER
13623                 (struct cmd_macsec_sa_result,
13624                  set, "set");
13625 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13626         TOKEN_STRING_INITIALIZER
13627                 (struct cmd_macsec_sa_result,
13628                  macsec, "macsec");
13629 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13630         TOKEN_STRING_INITIALIZER
13631                 (struct cmd_macsec_sa_result,
13632                  sa, "sa");
13633 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13634         TOKEN_STRING_INITIALIZER
13635                 (struct cmd_macsec_sa_result,
13636                  tx_rx, "tx#rx");
13637 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13638         TOKEN_NUM_INITIALIZER
13639                 (struct cmd_macsec_sa_result,
13640                  port_id, UINT16);
13641 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13642         TOKEN_NUM_INITIALIZER
13643                 (struct cmd_macsec_sa_result,
13644                  idx, UINT8);
13645 cmdline_parse_token_num_t cmd_macsec_sa_an =
13646         TOKEN_NUM_INITIALIZER
13647                 (struct cmd_macsec_sa_result,
13648                  an, UINT8);
13649 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13650         TOKEN_NUM_INITIALIZER
13651                 (struct cmd_macsec_sa_result,
13652                  pn, UINT32);
13653 cmdline_parse_token_string_t cmd_macsec_sa_key =
13654         TOKEN_STRING_INITIALIZER
13655                 (struct cmd_macsec_sa_result,
13656                  key, NULL);
13657
13658 static void
13659 cmd_set_macsec_sa_parsed(
13660         void *parsed_result,
13661         __attribute__((unused)) struct cmdline *cl,
13662         __attribute__((unused)) void *data)
13663 {
13664         struct cmd_macsec_sa_result *res = parsed_result;
13665         int ret = -ENOTSUP;
13666         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13667         uint8_t key[16] = { 0 };
13668         uint8_t xdgt0;
13669         uint8_t xdgt1;
13670         int key_len;
13671         int i;
13672
13673         key_len = strlen(res->key) / 2;
13674         if (key_len > 16)
13675                 key_len = 16;
13676
13677         for (i = 0; i < key_len; i++) {
13678                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13679                 if (xdgt0 == 0xFF)
13680                         return;
13681                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13682                 if (xdgt1 == 0xFF)
13683                         return;
13684                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13685         }
13686
13687 #ifdef RTE_LIBRTE_IXGBE_PMD
13688         ret = is_tx ?
13689                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13690                         res->idx, res->an, res->pn, key) :
13691                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13692                         res->idx, res->an, res->pn, key);
13693 #endif
13694         RTE_SET_USED(is_tx);
13695         RTE_SET_USED(key);
13696
13697         switch (ret) {
13698         case 0:
13699                 break;
13700         case -EINVAL:
13701                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13702                 break;
13703         case -ENODEV:
13704                 printf("invalid port_id %d\n", res->port_id);
13705                 break;
13706         case -ENOTSUP:
13707                 printf("not supported on port %d\n", res->port_id);
13708                 break;
13709         default:
13710                 printf("programming error: (%s)\n", strerror(-ret));
13711         }
13712 }
13713
13714 cmdline_parse_inst_t cmd_set_macsec_sa = {
13715         .f = cmd_set_macsec_sa_parsed,
13716         .data = NULL,
13717         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13718         .tokens = {
13719                 (void *)&cmd_macsec_sa_set,
13720                 (void *)&cmd_macsec_sa_macsec,
13721                 (void *)&cmd_macsec_sa_sa,
13722                 (void *)&cmd_macsec_sa_tx_rx,
13723                 (void *)&cmd_macsec_sa_port_id,
13724                 (void *)&cmd_macsec_sa_idx,
13725                 (void *)&cmd_macsec_sa_an,
13726                 (void *)&cmd_macsec_sa_pn,
13727                 (void *)&cmd_macsec_sa_key,
13728                 NULL,
13729         },
13730 };
13731
13732 /* VF unicast promiscuous mode configuration */
13733
13734 /* Common result structure for VF unicast promiscuous mode */
13735 struct cmd_vf_promisc_result {
13736         cmdline_fixed_string_t set;
13737         cmdline_fixed_string_t vf;
13738         cmdline_fixed_string_t promisc;
13739         portid_t port_id;
13740         uint32_t vf_id;
13741         cmdline_fixed_string_t on_off;
13742 };
13743
13744 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13745 cmdline_parse_token_string_t cmd_vf_promisc_set =
13746         TOKEN_STRING_INITIALIZER
13747                 (struct cmd_vf_promisc_result,
13748                  set, "set");
13749 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13750         TOKEN_STRING_INITIALIZER
13751                 (struct cmd_vf_promisc_result,
13752                  vf, "vf");
13753 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13754         TOKEN_STRING_INITIALIZER
13755                 (struct cmd_vf_promisc_result,
13756                  promisc, "promisc");
13757 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13758         TOKEN_NUM_INITIALIZER
13759                 (struct cmd_vf_promisc_result,
13760                  port_id, UINT16);
13761 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13762         TOKEN_NUM_INITIALIZER
13763                 (struct cmd_vf_promisc_result,
13764                  vf_id, UINT32);
13765 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13766         TOKEN_STRING_INITIALIZER
13767                 (struct cmd_vf_promisc_result,
13768                  on_off, "on#off");
13769
13770 static void
13771 cmd_set_vf_promisc_parsed(
13772         void *parsed_result,
13773         __attribute__((unused)) struct cmdline *cl,
13774         __attribute__((unused)) void *data)
13775 {
13776         struct cmd_vf_promisc_result *res = parsed_result;
13777         int ret = -ENOTSUP;
13778
13779         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13780
13781         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13782                 return;
13783
13784 #ifdef RTE_LIBRTE_I40E_PMD
13785         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13786                                                   res->vf_id, is_on);
13787 #endif
13788
13789         switch (ret) {
13790         case 0:
13791                 break;
13792         case -EINVAL:
13793                 printf("invalid vf_id %d\n", res->vf_id);
13794                 break;
13795         case -ENODEV:
13796                 printf("invalid port_id %d\n", res->port_id);
13797                 break;
13798         case -ENOTSUP:
13799                 printf("function not implemented\n");
13800                 break;
13801         default:
13802                 printf("programming error: (%s)\n", strerror(-ret));
13803         }
13804 }
13805
13806 cmdline_parse_inst_t cmd_set_vf_promisc = {
13807         .f = cmd_set_vf_promisc_parsed,
13808         .data = NULL,
13809         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13810                 "Set unicast promiscuous mode for a VF from the PF",
13811         .tokens = {
13812                 (void *)&cmd_vf_promisc_set,
13813                 (void *)&cmd_vf_promisc_vf,
13814                 (void *)&cmd_vf_promisc_promisc,
13815                 (void *)&cmd_vf_promisc_port_id,
13816                 (void *)&cmd_vf_promisc_vf_id,
13817                 (void *)&cmd_vf_promisc_on_off,
13818                 NULL,
13819         },
13820 };
13821
13822 /* VF multicast promiscuous mode configuration */
13823
13824 /* Common result structure for VF multicast promiscuous mode */
13825 struct cmd_vf_allmulti_result {
13826         cmdline_fixed_string_t set;
13827         cmdline_fixed_string_t vf;
13828         cmdline_fixed_string_t allmulti;
13829         portid_t port_id;
13830         uint32_t vf_id;
13831         cmdline_fixed_string_t on_off;
13832 };
13833
13834 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13835 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13836         TOKEN_STRING_INITIALIZER
13837                 (struct cmd_vf_allmulti_result,
13838                  set, "set");
13839 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13840         TOKEN_STRING_INITIALIZER
13841                 (struct cmd_vf_allmulti_result,
13842                  vf, "vf");
13843 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13844         TOKEN_STRING_INITIALIZER
13845                 (struct cmd_vf_allmulti_result,
13846                  allmulti, "allmulti");
13847 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13848         TOKEN_NUM_INITIALIZER
13849                 (struct cmd_vf_allmulti_result,
13850                  port_id, UINT16);
13851 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13852         TOKEN_NUM_INITIALIZER
13853                 (struct cmd_vf_allmulti_result,
13854                  vf_id, UINT32);
13855 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13856         TOKEN_STRING_INITIALIZER
13857                 (struct cmd_vf_allmulti_result,
13858                  on_off, "on#off");
13859
13860 static void
13861 cmd_set_vf_allmulti_parsed(
13862         void *parsed_result,
13863         __attribute__((unused)) struct cmdline *cl,
13864         __attribute__((unused)) void *data)
13865 {
13866         struct cmd_vf_allmulti_result *res = parsed_result;
13867         int ret = -ENOTSUP;
13868
13869         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13870
13871         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13872                 return;
13873
13874 #ifdef RTE_LIBRTE_I40E_PMD
13875         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13876                                                     res->vf_id, is_on);
13877 #endif
13878
13879         switch (ret) {
13880         case 0:
13881                 break;
13882         case -EINVAL:
13883                 printf("invalid vf_id %d\n", res->vf_id);
13884                 break;
13885         case -ENODEV:
13886                 printf("invalid port_id %d\n", res->port_id);
13887                 break;
13888         case -ENOTSUP:
13889                 printf("function not implemented\n");
13890                 break;
13891         default:
13892                 printf("programming error: (%s)\n", strerror(-ret));
13893         }
13894 }
13895
13896 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13897         .f = cmd_set_vf_allmulti_parsed,
13898         .data = NULL,
13899         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13900                 "Set multicast promiscuous mode for a VF from the PF",
13901         .tokens = {
13902                 (void *)&cmd_vf_allmulti_set,
13903                 (void *)&cmd_vf_allmulti_vf,
13904                 (void *)&cmd_vf_allmulti_allmulti,
13905                 (void *)&cmd_vf_allmulti_port_id,
13906                 (void *)&cmd_vf_allmulti_vf_id,
13907                 (void *)&cmd_vf_allmulti_on_off,
13908                 NULL,
13909         },
13910 };
13911
13912 /* vf broadcast mode configuration */
13913
13914 /* Common result structure for vf broadcast */
13915 struct cmd_set_vf_broadcast_result {
13916         cmdline_fixed_string_t set;
13917         cmdline_fixed_string_t vf;
13918         cmdline_fixed_string_t broadcast;
13919         portid_t port_id;
13920         uint16_t vf_id;
13921         cmdline_fixed_string_t on_off;
13922 };
13923
13924 /* Common CLI fields for vf broadcast enable disable */
13925 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13926         TOKEN_STRING_INITIALIZER
13927                 (struct cmd_set_vf_broadcast_result,
13928                  set, "set");
13929 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13930         TOKEN_STRING_INITIALIZER
13931                 (struct cmd_set_vf_broadcast_result,
13932                  vf, "vf");
13933 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13934         TOKEN_STRING_INITIALIZER
13935                 (struct cmd_set_vf_broadcast_result,
13936                  broadcast, "broadcast");
13937 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13938         TOKEN_NUM_INITIALIZER
13939                 (struct cmd_set_vf_broadcast_result,
13940                  port_id, UINT16);
13941 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13942         TOKEN_NUM_INITIALIZER
13943                 (struct cmd_set_vf_broadcast_result,
13944                  vf_id, UINT16);
13945 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13946         TOKEN_STRING_INITIALIZER
13947                 (struct cmd_set_vf_broadcast_result,
13948                  on_off, "on#off");
13949
13950 static void
13951 cmd_set_vf_broadcast_parsed(
13952         void *parsed_result,
13953         __attribute__((unused)) struct cmdline *cl,
13954         __attribute__((unused)) void *data)
13955 {
13956         struct cmd_set_vf_broadcast_result *res = parsed_result;
13957         int ret = -ENOTSUP;
13958
13959         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13960
13961         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13962                 return;
13963
13964 #ifdef RTE_LIBRTE_I40E_PMD
13965         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13966                                             res->vf_id, is_on);
13967 #endif
13968
13969         switch (ret) {
13970         case 0:
13971                 break;
13972         case -EINVAL:
13973                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13974                 break;
13975         case -ENODEV:
13976                 printf("invalid port_id %d\n", res->port_id);
13977                 break;
13978         case -ENOTSUP:
13979                 printf("function not implemented\n");
13980                 break;
13981         default:
13982                 printf("programming error: (%s)\n", strerror(-ret));
13983         }
13984 }
13985
13986 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13987         .f = cmd_set_vf_broadcast_parsed,
13988         .data = NULL,
13989         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13990         .tokens = {
13991                 (void *)&cmd_set_vf_broadcast_set,
13992                 (void *)&cmd_set_vf_broadcast_vf,
13993                 (void *)&cmd_set_vf_broadcast_broadcast,
13994                 (void *)&cmd_set_vf_broadcast_port_id,
13995                 (void *)&cmd_set_vf_broadcast_vf_id,
13996                 (void *)&cmd_set_vf_broadcast_on_off,
13997                 NULL,
13998         },
13999 };
14000
14001 /* vf vlan tag configuration */
14002
14003 /* Common result structure for vf vlan tag */
14004 struct cmd_set_vf_vlan_tag_result {
14005         cmdline_fixed_string_t set;
14006         cmdline_fixed_string_t vf;
14007         cmdline_fixed_string_t vlan;
14008         cmdline_fixed_string_t tag;
14009         portid_t port_id;
14010         uint16_t vf_id;
14011         cmdline_fixed_string_t on_off;
14012 };
14013
14014 /* Common CLI fields for vf vlan tag enable disable */
14015 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14016         TOKEN_STRING_INITIALIZER
14017                 (struct cmd_set_vf_vlan_tag_result,
14018                  set, "set");
14019 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14020         TOKEN_STRING_INITIALIZER
14021                 (struct cmd_set_vf_vlan_tag_result,
14022                  vf, "vf");
14023 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14024         TOKEN_STRING_INITIALIZER
14025                 (struct cmd_set_vf_vlan_tag_result,
14026                  vlan, "vlan");
14027 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14028         TOKEN_STRING_INITIALIZER
14029                 (struct cmd_set_vf_vlan_tag_result,
14030                  tag, "tag");
14031 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14032         TOKEN_NUM_INITIALIZER
14033                 (struct cmd_set_vf_vlan_tag_result,
14034                  port_id, UINT16);
14035 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14036         TOKEN_NUM_INITIALIZER
14037                 (struct cmd_set_vf_vlan_tag_result,
14038                  vf_id, UINT16);
14039 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14040         TOKEN_STRING_INITIALIZER
14041                 (struct cmd_set_vf_vlan_tag_result,
14042                  on_off, "on#off");
14043
14044 static void
14045 cmd_set_vf_vlan_tag_parsed(
14046         void *parsed_result,
14047         __attribute__((unused)) struct cmdline *cl,
14048         __attribute__((unused)) void *data)
14049 {
14050         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14051         int ret = -ENOTSUP;
14052
14053         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14054
14055         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14056                 return;
14057
14058 #ifdef RTE_LIBRTE_I40E_PMD
14059         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14060                                            res->vf_id, is_on);
14061 #endif
14062
14063         switch (ret) {
14064         case 0:
14065                 break;
14066         case -EINVAL:
14067                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14068                 break;
14069         case -ENODEV:
14070                 printf("invalid port_id %d\n", res->port_id);
14071                 break;
14072         case -ENOTSUP:
14073                 printf("function not implemented\n");
14074                 break;
14075         default:
14076                 printf("programming error: (%s)\n", strerror(-ret));
14077         }
14078 }
14079
14080 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14081         .f = cmd_set_vf_vlan_tag_parsed,
14082         .data = NULL,
14083         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14084         .tokens = {
14085                 (void *)&cmd_set_vf_vlan_tag_set,
14086                 (void *)&cmd_set_vf_vlan_tag_vf,
14087                 (void *)&cmd_set_vf_vlan_tag_vlan,
14088                 (void *)&cmd_set_vf_vlan_tag_tag,
14089                 (void *)&cmd_set_vf_vlan_tag_port_id,
14090                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14091                 (void *)&cmd_set_vf_vlan_tag_on_off,
14092                 NULL,
14093         },
14094 };
14095
14096 /* Common definition of VF and TC TX bandwidth configuration */
14097 struct cmd_vf_tc_bw_result {
14098         cmdline_fixed_string_t set;
14099         cmdline_fixed_string_t vf;
14100         cmdline_fixed_string_t tc;
14101         cmdline_fixed_string_t tx;
14102         cmdline_fixed_string_t min_bw;
14103         cmdline_fixed_string_t max_bw;
14104         cmdline_fixed_string_t strict_link_prio;
14105         portid_t port_id;
14106         uint16_t vf_id;
14107         uint8_t tc_no;
14108         uint32_t bw;
14109         cmdline_fixed_string_t bw_list;
14110         uint8_t tc_map;
14111 };
14112
14113 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14114         TOKEN_STRING_INITIALIZER
14115                 (struct cmd_vf_tc_bw_result,
14116                  set, "set");
14117 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14118         TOKEN_STRING_INITIALIZER
14119                 (struct cmd_vf_tc_bw_result,
14120                  vf, "vf");
14121 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14122         TOKEN_STRING_INITIALIZER
14123                 (struct cmd_vf_tc_bw_result,
14124                  tc, "tc");
14125 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14126         TOKEN_STRING_INITIALIZER
14127                 (struct cmd_vf_tc_bw_result,
14128                  tx, "tx");
14129 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14130         TOKEN_STRING_INITIALIZER
14131                 (struct cmd_vf_tc_bw_result,
14132                  strict_link_prio, "strict-link-priority");
14133 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14134         TOKEN_STRING_INITIALIZER
14135                 (struct cmd_vf_tc_bw_result,
14136                  min_bw, "min-bandwidth");
14137 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14138         TOKEN_STRING_INITIALIZER
14139                 (struct cmd_vf_tc_bw_result,
14140                  max_bw, "max-bandwidth");
14141 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14142         TOKEN_NUM_INITIALIZER
14143                 (struct cmd_vf_tc_bw_result,
14144                  port_id, UINT16);
14145 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14146         TOKEN_NUM_INITIALIZER
14147                 (struct cmd_vf_tc_bw_result,
14148                  vf_id, UINT16);
14149 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14150         TOKEN_NUM_INITIALIZER
14151                 (struct cmd_vf_tc_bw_result,
14152                  tc_no, UINT8);
14153 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14154         TOKEN_NUM_INITIALIZER
14155                 (struct cmd_vf_tc_bw_result,
14156                  bw, UINT32);
14157 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14158         TOKEN_STRING_INITIALIZER
14159                 (struct cmd_vf_tc_bw_result,
14160                  bw_list, NULL);
14161 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14162         TOKEN_NUM_INITIALIZER
14163                 (struct cmd_vf_tc_bw_result,
14164                  tc_map, UINT8);
14165
14166 /* VF max bandwidth setting */
14167 static void
14168 cmd_vf_max_bw_parsed(
14169         void *parsed_result,
14170         __attribute__((unused)) struct cmdline *cl,
14171         __attribute__((unused)) void *data)
14172 {
14173         struct cmd_vf_tc_bw_result *res = parsed_result;
14174         int ret = -ENOTSUP;
14175
14176         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14177                 return;
14178
14179 #ifdef RTE_LIBRTE_I40E_PMD
14180         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14181                                          res->vf_id, res->bw);
14182 #endif
14183
14184         switch (ret) {
14185         case 0:
14186                 break;
14187         case -EINVAL:
14188                 printf("invalid vf_id %d or bandwidth %d\n",
14189                        res->vf_id, res->bw);
14190                 break;
14191         case -ENODEV:
14192                 printf("invalid port_id %d\n", res->port_id);
14193                 break;
14194         case -ENOTSUP:
14195                 printf("function not implemented\n");
14196                 break;
14197         default:
14198                 printf("programming error: (%s)\n", strerror(-ret));
14199         }
14200 }
14201
14202 cmdline_parse_inst_t cmd_vf_max_bw = {
14203         .f = cmd_vf_max_bw_parsed,
14204         .data = NULL,
14205         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14206         .tokens = {
14207                 (void *)&cmd_vf_tc_bw_set,
14208                 (void *)&cmd_vf_tc_bw_vf,
14209                 (void *)&cmd_vf_tc_bw_tx,
14210                 (void *)&cmd_vf_tc_bw_max_bw,
14211                 (void *)&cmd_vf_tc_bw_port_id,
14212                 (void *)&cmd_vf_tc_bw_vf_id,
14213                 (void *)&cmd_vf_tc_bw_bw,
14214                 NULL,
14215         },
14216 };
14217
14218 static int
14219 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14220                            uint8_t *tc_num,
14221                            char *str)
14222 {
14223         uint32_t size;
14224         const char *p, *p0 = str;
14225         char s[256];
14226         char *end;
14227         char *str_fld[16];
14228         uint16_t i;
14229         int ret;
14230
14231         p = strchr(p0, '(');
14232         if (p == NULL) {
14233                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14234                 return -1;
14235         }
14236         p++;
14237         p0 = strchr(p, ')');
14238         if (p0 == NULL) {
14239                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14240                 return -1;
14241         }
14242         size = p0 - p;
14243         if (size >= sizeof(s)) {
14244                 printf("The string size exceeds the internal buffer size\n");
14245                 return -1;
14246         }
14247         snprintf(s, sizeof(s), "%.*s", size, p);
14248         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14249         if (ret <= 0) {
14250                 printf("Failed to get the bandwidth list. ");
14251                 return -1;
14252         }
14253         *tc_num = ret;
14254         for (i = 0; i < ret; i++)
14255                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14256
14257         return 0;
14258 }
14259
14260 /* TC min bandwidth setting */
14261 static void
14262 cmd_vf_tc_min_bw_parsed(
14263         void *parsed_result,
14264         __attribute__((unused)) struct cmdline *cl,
14265         __attribute__((unused)) void *data)
14266 {
14267         struct cmd_vf_tc_bw_result *res = parsed_result;
14268         uint8_t tc_num;
14269         uint8_t bw[16];
14270         int ret = -ENOTSUP;
14271
14272         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14273                 return;
14274
14275         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14276         if (ret)
14277                 return;
14278
14279 #ifdef RTE_LIBRTE_I40E_PMD
14280         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14281                                               tc_num, bw);
14282 #endif
14283
14284         switch (ret) {
14285         case 0:
14286                 break;
14287         case -EINVAL:
14288                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14289                 break;
14290         case -ENODEV:
14291                 printf("invalid port_id %d\n", res->port_id);
14292                 break;
14293         case -ENOTSUP:
14294                 printf("function not implemented\n");
14295                 break;
14296         default:
14297                 printf("programming error: (%s)\n", strerror(-ret));
14298         }
14299 }
14300
14301 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14302         .f = cmd_vf_tc_min_bw_parsed,
14303         .data = NULL,
14304         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14305                     " <bw1, bw2, ...>",
14306         .tokens = {
14307                 (void *)&cmd_vf_tc_bw_set,
14308                 (void *)&cmd_vf_tc_bw_vf,
14309                 (void *)&cmd_vf_tc_bw_tc,
14310                 (void *)&cmd_vf_tc_bw_tx,
14311                 (void *)&cmd_vf_tc_bw_min_bw,
14312                 (void *)&cmd_vf_tc_bw_port_id,
14313                 (void *)&cmd_vf_tc_bw_vf_id,
14314                 (void *)&cmd_vf_tc_bw_bw_list,
14315                 NULL,
14316         },
14317 };
14318
14319 static void
14320 cmd_tc_min_bw_parsed(
14321         void *parsed_result,
14322         __attribute__((unused)) struct cmdline *cl,
14323         __attribute__((unused)) void *data)
14324 {
14325         struct cmd_vf_tc_bw_result *res = parsed_result;
14326         struct rte_port *port;
14327         uint8_t tc_num;
14328         uint8_t bw[16];
14329         int ret = -ENOTSUP;
14330
14331         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14332                 return;
14333
14334         port = &ports[res->port_id];
14335         /** Check if the port is not started **/
14336         if (port->port_status != RTE_PORT_STOPPED) {
14337                 printf("Please stop port %d first\n", res->port_id);
14338                 return;
14339         }
14340
14341         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14342         if (ret)
14343                 return;
14344
14345 #ifdef RTE_LIBRTE_IXGBE_PMD
14346         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14347 #endif
14348
14349         switch (ret) {
14350         case 0:
14351                 break;
14352         case -EINVAL:
14353                 printf("invalid bandwidth\n");
14354                 break;
14355         case -ENODEV:
14356                 printf("invalid port_id %d\n", res->port_id);
14357                 break;
14358         case -ENOTSUP:
14359                 printf("function not implemented\n");
14360                 break;
14361         default:
14362                 printf("programming error: (%s)\n", strerror(-ret));
14363         }
14364 }
14365
14366 cmdline_parse_inst_t cmd_tc_min_bw = {
14367         .f = cmd_tc_min_bw_parsed,
14368         .data = NULL,
14369         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14370         .tokens = {
14371                 (void *)&cmd_vf_tc_bw_set,
14372                 (void *)&cmd_vf_tc_bw_tc,
14373                 (void *)&cmd_vf_tc_bw_tx,
14374                 (void *)&cmd_vf_tc_bw_min_bw,
14375                 (void *)&cmd_vf_tc_bw_port_id,
14376                 (void *)&cmd_vf_tc_bw_bw_list,
14377                 NULL,
14378         },
14379 };
14380
14381 /* TC max bandwidth setting */
14382 static void
14383 cmd_vf_tc_max_bw_parsed(
14384         void *parsed_result,
14385         __attribute__((unused)) struct cmdline *cl,
14386         __attribute__((unused)) void *data)
14387 {
14388         struct cmd_vf_tc_bw_result *res = parsed_result;
14389         int ret = -ENOTSUP;
14390
14391         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14392                 return;
14393
14394 #ifdef RTE_LIBRTE_I40E_PMD
14395         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14396                                             res->tc_no, res->bw);
14397 #endif
14398
14399         switch (ret) {
14400         case 0:
14401                 break;
14402         case -EINVAL:
14403                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14404                        res->vf_id, res->tc_no, res->bw);
14405                 break;
14406         case -ENODEV:
14407                 printf("invalid port_id %d\n", res->port_id);
14408                 break;
14409         case -ENOTSUP:
14410                 printf("function not implemented\n");
14411                 break;
14412         default:
14413                 printf("programming error: (%s)\n", strerror(-ret));
14414         }
14415 }
14416
14417 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14418         .f = cmd_vf_tc_max_bw_parsed,
14419         .data = NULL,
14420         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14421                     " <bandwidth>",
14422         .tokens = {
14423                 (void *)&cmd_vf_tc_bw_set,
14424                 (void *)&cmd_vf_tc_bw_vf,
14425                 (void *)&cmd_vf_tc_bw_tc,
14426                 (void *)&cmd_vf_tc_bw_tx,
14427                 (void *)&cmd_vf_tc_bw_max_bw,
14428                 (void *)&cmd_vf_tc_bw_port_id,
14429                 (void *)&cmd_vf_tc_bw_vf_id,
14430                 (void *)&cmd_vf_tc_bw_tc_no,
14431                 (void *)&cmd_vf_tc_bw_bw,
14432                 NULL,
14433         },
14434 };
14435
14436
14437 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14438
14439 /* *** Set Port default Traffic Management Hierarchy *** */
14440 struct cmd_set_port_tm_hierarchy_default_result {
14441         cmdline_fixed_string_t set;
14442         cmdline_fixed_string_t port;
14443         cmdline_fixed_string_t tm;
14444         cmdline_fixed_string_t hierarchy;
14445         cmdline_fixed_string_t def;
14446         portid_t port_id;
14447 };
14448
14449 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14450         TOKEN_STRING_INITIALIZER(
14451                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14452 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14453         TOKEN_STRING_INITIALIZER(
14454                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14455 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14456         TOKEN_STRING_INITIALIZER(
14457                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14458 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14459         TOKEN_STRING_INITIALIZER(
14460                 struct cmd_set_port_tm_hierarchy_default_result,
14461                         hierarchy, "hierarchy");
14462 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14463         TOKEN_STRING_INITIALIZER(
14464                 struct cmd_set_port_tm_hierarchy_default_result,
14465                         def, "default");
14466 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14467         TOKEN_NUM_INITIALIZER(
14468                 struct cmd_set_port_tm_hierarchy_default_result,
14469                         port_id, UINT16);
14470
14471 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14472         __attribute__((unused)) struct cmdline *cl,
14473         __attribute__((unused)) void *data)
14474 {
14475         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14476         struct rte_port *p;
14477         portid_t port_id = res->port_id;
14478
14479         if (port_id_is_invalid(port_id, ENABLED_WARN))
14480                 return;
14481
14482         p = &ports[port_id];
14483
14484         /* Port tm flag */
14485         if (p->softport.tm_flag == 0) {
14486                 printf("  tm not enabled on port %u (error)\n", port_id);
14487                 return;
14488         }
14489
14490         /* Forward mode: tm */
14491         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14492                 printf("  tm mode not enabled(error)\n");
14493                 return;
14494         }
14495
14496         /* Set the default tm hierarchy */
14497         p->softport.tm.default_hierarchy_enable = 1;
14498 }
14499
14500 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14501         .f = cmd_set_port_tm_hierarchy_default_parsed,
14502         .data = NULL,
14503         .help_str = "set port tm hierarchy default <port_id>",
14504         .tokens = {
14505                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14506                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14507                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14508                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14509                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14510                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14511                 NULL,
14512         },
14513 };
14514 #endif
14515
14516 /* Strict link priority scheduling mode setting */
14517 static void
14518 cmd_strict_link_prio_parsed(
14519         void *parsed_result,
14520         __attribute__((unused)) struct cmdline *cl,
14521         __attribute__((unused)) void *data)
14522 {
14523         struct cmd_vf_tc_bw_result *res = parsed_result;
14524         int ret = -ENOTSUP;
14525
14526         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14527                 return;
14528
14529 #ifdef RTE_LIBRTE_I40E_PMD
14530         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14531 #endif
14532
14533         switch (ret) {
14534         case 0:
14535                 break;
14536         case -EINVAL:
14537                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14538                 break;
14539         case -ENODEV:
14540                 printf("invalid port_id %d\n", res->port_id);
14541                 break;
14542         case -ENOTSUP:
14543                 printf("function not implemented\n");
14544                 break;
14545         default:
14546                 printf("programming error: (%s)\n", strerror(-ret));
14547         }
14548 }
14549
14550 cmdline_parse_inst_t cmd_strict_link_prio = {
14551         .f = cmd_strict_link_prio_parsed,
14552         .data = NULL,
14553         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14554         .tokens = {
14555                 (void *)&cmd_vf_tc_bw_set,
14556                 (void *)&cmd_vf_tc_bw_tx,
14557                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14558                 (void *)&cmd_vf_tc_bw_port_id,
14559                 (void *)&cmd_vf_tc_bw_tc_map,
14560                 NULL,
14561         },
14562 };
14563
14564 /* Load dynamic device personalization*/
14565 struct cmd_ddp_add_result {
14566         cmdline_fixed_string_t ddp;
14567         cmdline_fixed_string_t add;
14568         portid_t port_id;
14569         char filepath[];
14570 };
14571
14572 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14573         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14574 cmdline_parse_token_string_t cmd_ddp_add_add =
14575         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14576 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14577         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14578 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14579         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14580
14581 static void
14582 cmd_ddp_add_parsed(
14583         void *parsed_result,
14584         __attribute__((unused)) struct cmdline *cl,
14585         __attribute__((unused)) void *data)
14586 {
14587         struct cmd_ddp_add_result *res = parsed_result;
14588         uint8_t *buff;
14589         uint32_t size;
14590         char *filepath;
14591         char *file_fld[2];
14592         int file_num;
14593         int ret = -ENOTSUP;
14594
14595         if (!all_ports_stopped()) {
14596                 printf("Please stop all ports first\n");
14597                 return;
14598         }
14599
14600         filepath = strdup(res->filepath);
14601         if (filepath == NULL) {
14602                 printf("Failed to allocate memory\n");
14603                 return;
14604         }
14605         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14606
14607         buff = open_file(file_fld[0], &size);
14608         if (!buff) {
14609                 free((void *)filepath);
14610                 return;
14611         }
14612
14613 #ifdef RTE_LIBRTE_I40E_PMD
14614         if (ret == -ENOTSUP)
14615                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14616                                                buff, size,
14617                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14618 #endif
14619
14620         if (ret == -EEXIST)
14621                 printf("Profile has already existed.\n");
14622         else if (ret < 0)
14623                 printf("Failed to load profile.\n");
14624         else if (file_num == 2)
14625                 save_file(file_fld[1], buff, size);
14626
14627         close_file(buff);
14628         free((void *)filepath);
14629 }
14630
14631 cmdline_parse_inst_t cmd_ddp_add = {
14632         .f = cmd_ddp_add_parsed,
14633         .data = NULL,
14634         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14635         .tokens = {
14636                 (void *)&cmd_ddp_add_ddp,
14637                 (void *)&cmd_ddp_add_add,
14638                 (void *)&cmd_ddp_add_port_id,
14639                 (void *)&cmd_ddp_add_filepath,
14640                 NULL,
14641         },
14642 };
14643
14644 /* Delete dynamic device personalization*/
14645 struct cmd_ddp_del_result {
14646         cmdline_fixed_string_t ddp;
14647         cmdline_fixed_string_t del;
14648         portid_t port_id;
14649         char filepath[];
14650 };
14651
14652 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14653         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14654 cmdline_parse_token_string_t cmd_ddp_del_del =
14655         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14656 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14657         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14658 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14659         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14660
14661 static void
14662 cmd_ddp_del_parsed(
14663         void *parsed_result,
14664         __attribute__((unused)) struct cmdline *cl,
14665         __attribute__((unused)) void *data)
14666 {
14667         struct cmd_ddp_del_result *res = parsed_result;
14668         uint8_t *buff;
14669         uint32_t size;
14670         int ret = -ENOTSUP;
14671
14672         if (!all_ports_stopped()) {
14673                 printf("Please stop all ports first\n");
14674                 return;
14675         }
14676
14677         buff = open_file(res->filepath, &size);
14678         if (!buff)
14679                 return;
14680
14681 #ifdef RTE_LIBRTE_I40E_PMD
14682         if (ret == -ENOTSUP)
14683                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14684                                                buff, size,
14685                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14686 #endif
14687
14688         if (ret == -EACCES)
14689                 printf("Profile does not exist.\n");
14690         else if (ret < 0)
14691                 printf("Failed to delete profile.\n");
14692
14693         close_file(buff);
14694 }
14695
14696 cmdline_parse_inst_t cmd_ddp_del = {
14697         .f = cmd_ddp_del_parsed,
14698         .data = NULL,
14699         .help_str = "ddp del <port_id> <backup_profile_path>",
14700         .tokens = {
14701                 (void *)&cmd_ddp_del_ddp,
14702                 (void *)&cmd_ddp_del_del,
14703                 (void *)&cmd_ddp_del_port_id,
14704                 (void *)&cmd_ddp_del_filepath,
14705                 NULL,
14706         },
14707 };
14708
14709 /* Get dynamic device personalization profile info */
14710 struct cmd_ddp_info_result {
14711         cmdline_fixed_string_t ddp;
14712         cmdline_fixed_string_t get;
14713         cmdline_fixed_string_t info;
14714         char filepath[];
14715 };
14716
14717 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14718         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14719 cmdline_parse_token_string_t cmd_ddp_info_get =
14720         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14721 cmdline_parse_token_string_t cmd_ddp_info_info =
14722         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14723 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14724         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14725
14726 static void
14727 cmd_ddp_info_parsed(
14728         void *parsed_result,
14729         __attribute__((unused)) struct cmdline *cl,
14730         __attribute__((unused)) void *data)
14731 {
14732         struct cmd_ddp_info_result *res = parsed_result;
14733         uint8_t *pkg;
14734         uint32_t pkg_size;
14735         int ret = -ENOTSUP;
14736 #ifdef RTE_LIBRTE_I40E_PMD
14737         uint32_t i, j, n;
14738         uint8_t *buff;
14739         uint32_t buff_size = 0;
14740         struct rte_pmd_i40e_profile_info info;
14741         uint32_t dev_num = 0;
14742         struct rte_pmd_i40e_ddp_device_id *devs;
14743         uint32_t proto_num = 0;
14744         struct rte_pmd_i40e_proto_info *proto = NULL;
14745         uint32_t pctype_num = 0;
14746         struct rte_pmd_i40e_ptype_info *pctype;
14747         uint32_t ptype_num = 0;
14748         struct rte_pmd_i40e_ptype_info *ptype;
14749         uint8_t proto_id;
14750
14751 #endif
14752
14753         pkg = open_file(res->filepath, &pkg_size);
14754         if (!pkg)
14755                 return;
14756
14757 #ifdef RTE_LIBRTE_I40E_PMD
14758         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14759                                 (uint8_t *)&info, sizeof(info),
14760                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14761         if (!ret) {
14762                 printf("Global Track id:       0x%x\n", info.track_id);
14763                 printf("Global Version:        %d.%d.%d.%d\n",
14764                         info.version.major,
14765                         info.version.minor,
14766                         info.version.update,
14767                         info.version.draft);
14768                 printf("Global Package name:   %s\n\n", info.name);
14769         }
14770
14771         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14772                                 (uint8_t *)&info, sizeof(info),
14773                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14774         if (!ret) {
14775                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14776                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14777                         info.version.major,
14778                         info.version.minor,
14779                         info.version.update,
14780                         info.version.draft);
14781                 printf("i40e Profile name:     %s\n\n", info.name);
14782         }
14783
14784         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14785                                 (uint8_t *)&buff_size, sizeof(buff_size),
14786                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14787         if (!ret && buff_size) {
14788                 buff = (uint8_t *)malloc(buff_size);
14789                 if (buff) {
14790                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14791                                                 buff, buff_size,
14792                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14793                         if (!ret)
14794                                 printf("Package Notes:\n%s\n\n", buff);
14795                         free(buff);
14796                 }
14797         }
14798
14799         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14800                                 (uint8_t *)&dev_num, sizeof(dev_num),
14801                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14802         if (!ret && dev_num) {
14803                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14804                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14805                 if (devs) {
14806                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14807                                                 (uint8_t *)devs, buff_size,
14808                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14809                         if (!ret) {
14810                                 printf("List of supported devices:\n");
14811                                 for (i = 0; i < dev_num; i++) {
14812                                         printf("  %04X:%04X %04X:%04X\n",
14813                                                 devs[i].vendor_dev_id >> 16,
14814                                                 devs[i].vendor_dev_id & 0xFFFF,
14815                                                 devs[i].sub_vendor_dev_id >> 16,
14816                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14817                                 }
14818                                 printf("\n");
14819                         }
14820                         free(devs);
14821                 }
14822         }
14823
14824         /* get information about protocols and packet types */
14825         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14826                 (uint8_t *)&proto_num, sizeof(proto_num),
14827                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14828         if (ret || !proto_num)
14829                 goto no_print_return;
14830
14831         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14832         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14833         if (!proto)
14834                 goto no_print_return;
14835
14836         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14837                                         buff_size,
14838                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14839         if (!ret) {
14840                 printf("List of used protocols:\n");
14841                 for (i = 0; i < proto_num; i++)
14842                         printf("  %2u: %s\n", proto[i].proto_id,
14843                                proto[i].name);
14844                 printf("\n");
14845         }
14846         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14847                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14848                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14849         if (ret || !pctype_num)
14850                 goto no_print_pctypes;
14851
14852         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14853         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14854         if (!pctype)
14855                 goto no_print_pctypes;
14856
14857         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14858                                         buff_size,
14859                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14860         if (ret) {
14861                 free(pctype);
14862                 goto no_print_pctypes;
14863         }
14864
14865         printf("List of defined packet classification types:\n");
14866         for (i = 0; i < pctype_num; i++) {
14867                 printf("  %2u:", pctype[i].ptype_id);
14868                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14869                         proto_id = pctype[i].protocols[j];
14870                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14871                                 for (n = 0; n < proto_num; n++) {
14872                                         if (proto[n].proto_id == proto_id) {
14873                                                 printf(" %s", proto[n].name);
14874                                                 break;
14875                                         }
14876                                 }
14877                         }
14878                 }
14879                 printf("\n");
14880         }
14881         printf("\n");
14882         free(pctype);
14883
14884 no_print_pctypes:
14885
14886         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14887                                         sizeof(ptype_num),
14888                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14889         if (ret || !ptype_num)
14890                 goto no_print_return;
14891
14892         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14893         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14894         if (!ptype)
14895                 goto no_print_return;
14896
14897         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14898                                         buff_size,
14899                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14900         if (ret) {
14901                 free(ptype);
14902                 goto no_print_return;
14903         }
14904         printf("List of defined packet types:\n");
14905         for (i = 0; i < ptype_num; i++) {
14906                 printf("  %2u:", ptype[i].ptype_id);
14907                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14908                         proto_id = ptype[i].protocols[j];
14909                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14910                                 for (n = 0; n < proto_num; n++) {
14911                                         if (proto[n].proto_id == proto_id) {
14912                                                 printf(" %s", proto[n].name);
14913                                                 break;
14914                                         }
14915                                 }
14916                         }
14917                 }
14918                 printf("\n");
14919         }
14920         free(ptype);
14921         printf("\n");
14922
14923         ret = 0;
14924 no_print_return:
14925         if (proto)
14926                 free(proto);
14927 #endif
14928         if (ret == -ENOTSUP)
14929                 printf("Function not supported in PMD driver\n");
14930         close_file(pkg);
14931 }
14932
14933 cmdline_parse_inst_t cmd_ddp_get_info = {
14934         .f = cmd_ddp_info_parsed,
14935         .data = NULL,
14936         .help_str = "ddp get info <profile_path>",
14937         .tokens = {
14938                 (void *)&cmd_ddp_info_ddp,
14939                 (void *)&cmd_ddp_info_get,
14940                 (void *)&cmd_ddp_info_info,
14941                 (void *)&cmd_ddp_info_filepath,
14942                 NULL,
14943         },
14944 };
14945
14946 /* Get dynamic device personalization profile info list*/
14947 #define PROFILE_INFO_SIZE 48
14948 #define MAX_PROFILE_NUM 16
14949
14950 struct cmd_ddp_get_list_result {
14951         cmdline_fixed_string_t ddp;
14952         cmdline_fixed_string_t get;
14953         cmdline_fixed_string_t list;
14954         portid_t port_id;
14955 };
14956
14957 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14958         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14959 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14960         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14961 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14962         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14963 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14964         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14965
14966 static void
14967 cmd_ddp_get_list_parsed(
14968         __attribute__((unused)) void *parsed_result,
14969         __attribute__((unused)) struct cmdline *cl,
14970         __attribute__((unused)) void *data)
14971 {
14972 #ifdef RTE_LIBRTE_I40E_PMD
14973         struct cmd_ddp_get_list_result *res = parsed_result;
14974         struct rte_pmd_i40e_profile_list *p_list;
14975         struct rte_pmd_i40e_profile_info *p_info;
14976         uint32_t p_num;
14977         uint32_t size;
14978         uint32_t i;
14979 #endif
14980         int ret = -ENOTSUP;
14981
14982 #ifdef RTE_LIBRTE_I40E_PMD
14983         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14984         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14985         if (!p_list)
14986                 printf("%s: Failed to malloc buffer\n", __func__);
14987
14988         if (ret == -ENOTSUP)
14989                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14990                                                 (uint8_t *)p_list, size);
14991
14992         if (!ret) {
14993                 p_num = p_list->p_count;
14994                 printf("Profile number is: %d\n\n", p_num);
14995
14996                 for (i = 0; i < p_num; i++) {
14997                         p_info = &p_list->p_info[i];
14998                         printf("Profile %d:\n", i);
14999                         printf("Track id:     0x%x\n", p_info->track_id);
15000                         printf("Version:      %d.%d.%d.%d\n",
15001                                p_info->version.major,
15002                                p_info->version.minor,
15003                                p_info->version.update,
15004                                p_info->version.draft);
15005                         printf("Profile name: %s\n\n", p_info->name);
15006                 }
15007         }
15008
15009         free(p_list);
15010 #endif
15011
15012         if (ret < 0)
15013                 printf("Failed to get ddp list\n");
15014 }
15015
15016 cmdline_parse_inst_t cmd_ddp_get_list = {
15017         .f = cmd_ddp_get_list_parsed,
15018         .data = NULL,
15019         .help_str = "ddp get list <port_id>",
15020         .tokens = {
15021                 (void *)&cmd_ddp_get_list_ddp,
15022                 (void *)&cmd_ddp_get_list_get,
15023                 (void *)&cmd_ddp_get_list_list,
15024                 (void *)&cmd_ddp_get_list_port_id,
15025                 NULL,
15026         },
15027 };
15028
15029 /* Configure input set */
15030 struct cmd_cfg_input_set_result {
15031         cmdline_fixed_string_t port;
15032         cmdline_fixed_string_t cfg;
15033         portid_t port_id;
15034         cmdline_fixed_string_t pctype;
15035         uint8_t pctype_id;
15036         cmdline_fixed_string_t inset_type;
15037         cmdline_fixed_string_t opt;
15038         cmdline_fixed_string_t field;
15039         uint8_t field_idx;
15040 };
15041
15042 static void
15043 cmd_cfg_input_set_parsed(
15044         __attribute__((unused)) void *parsed_result,
15045         __attribute__((unused)) struct cmdline *cl,
15046         __attribute__((unused)) void *data)
15047 {
15048 #ifdef RTE_LIBRTE_I40E_PMD
15049         struct cmd_cfg_input_set_result *res = parsed_result;
15050         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15051         struct rte_pmd_i40e_inset inset;
15052 #endif
15053         int ret = -ENOTSUP;
15054
15055         if (!all_ports_stopped()) {
15056                 printf("Please stop all ports first\n");
15057                 return;
15058         }
15059
15060 #ifdef RTE_LIBRTE_I40E_PMD
15061         if (!strcmp(res->inset_type, "hash_inset"))
15062                 inset_type = INSET_HASH;
15063         else if (!strcmp(res->inset_type, "fdir_inset"))
15064                 inset_type = INSET_FDIR;
15065         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15066                 inset_type = INSET_FDIR_FLX;
15067         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15068                                      &inset, inset_type);
15069         if (ret) {
15070                 printf("Failed to get input set.\n");
15071                 return;
15072         }
15073
15074         if (!strcmp(res->opt, "get")) {
15075                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15076                                                    res->field_idx);
15077                 if (ret)
15078                         printf("Field index %d is enabled.\n", res->field_idx);
15079                 else
15080                         printf("Field index %d is disabled.\n", res->field_idx);
15081                 return;
15082         } else if (!strcmp(res->opt, "set"))
15083                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15084                                                    res->field_idx);
15085         else if (!strcmp(res->opt, "clear"))
15086                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15087                                                      res->field_idx);
15088         if (ret) {
15089                 printf("Failed to configure input set field.\n");
15090                 return;
15091         }
15092
15093         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15094                                      &inset, inset_type);
15095         if (ret) {
15096                 printf("Failed to set input set.\n");
15097                 return;
15098         }
15099 #endif
15100
15101         if (ret == -ENOTSUP)
15102                 printf("Function not supported\n");
15103 }
15104
15105 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15106         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15107                                  port, "port");
15108 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15109         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15110                                  cfg, "config");
15111 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15112         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15113                               port_id, UINT16);
15114 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15115         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15116                                  pctype, "pctype");
15117 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15118         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15119                               pctype_id, UINT8);
15120 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15121         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15122                                  inset_type,
15123                                  "hash_inset#fdir_inset#fdir_flx_inset");
15124 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15125         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15126                                  opt, "get#set#clear");
15127 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15128         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15129                                  field, "field");
15130 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15131         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15132                               field_idx, UINT8);
15133
15134 cmdline_parse_inst_t cmd_cfg_input_set = {
15135         .f = cmd_cfg_input_set_parsed,
15136         .data = NULL,
15137         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15138                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15139         .tokens = {
15140                 (void *)&cmd_cfg_input_set_port,
15141                 (void *)&cmd_cfg_input_set_cfg,
15142                 (void *)&cmd_cfg_input_set_port_id,
15143                 (void *)&cmd_cfg_input_set_pctype,
15144                 (void *)&cmd_cfg_input_set_pctype_id,
15145                 (void *)&cmd_cfg_input_set_inset_type,
15146                 (void *)&cmd_cfg_input_set_opt,
15147                 (void *)&cmd_cfg_input_set_field,
15148                 (void *)&cmd_cfg_input_set_field_idx,
15149                 NULL,
15150         },
15151 };
15152
15153 /* Clear input set */
15154 struct cmd_clear_input_set_result {
15155         cmdline_fixed_string_t port;
15156         cmdline_fixed_string_t cfg;
15157         portid_t port_id;
15158         cmdline_fixed_string_t pctype;
15159         uint8_t pctype_id;
15160         cmdline_fixed_string_t inset_type;
15161         cmdline_fixed_string_t clear;
15162         cmdline_fixed_string_t all;
15163 };
15164
15165 static void
15166 cmd_clear_input_set_parsed(
15167         __attribute__((unused)) void *parsed_result,
15168         __attribute__((unused)) struct cmdline *cl,
15169         __attribute__((unused)) void *data)
15170 {
15171 #ifdef RTE_LIBRTE_I40E_PMD
15172         struct cmd_clear_input_set_result *res = parsed_result;
15173         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15174         struct rte_pmd_i40e_inset inset;
15175 #endif
15176         int ret = -ENOTSUP;
15177
15178         if (!all_ports_stopped()) {
15179                 printf("Please stop all ports first\n");
15180                 return;
15181         }
15182
15183 #ifdef RTE_LIBRTE_I40E_PMD
15184         if (!strcmp(res->inset_type, "hash_inset"))
15185                 inset_type = INSET_HASH;
15186         else if (!strcmp(res->inset_type, "fdir_inset"))
15187                 inset_type = INSET_FDIR;
15188         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15189                 inset_type = INSET_FDIR_FLX;
15190
15191         memset(&inset, 0, sizeof(inset));
15192
15193         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15194                                      &inset, inset_type);
15195         if (ret) {
15196                 printf("Failed to clear input set.\n");
15197                 return;
15198         }
15199
15200 #endif
15201
15202         if (ret == -ENOTSUP)
15203                 printf("Function not supported\n");
15204 }
15205
15206 cmdline_parse_token_string_t cmd_clear_input_set_port =
15207         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15208                                  port, "port");
15209 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15210         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15211                                  cfg, "config");
15212 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15213         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15214                               port_id, UINT16);
15215 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15216         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15217                                  pctype, "pctype");
15218 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15219         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15220                               pctype_id, UINT8);
15221 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15222         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15223                                  inset_type,
15224                                  "hash_inset#fdir_inset#fdir_flx_inset");
15225 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15226         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15227                                  clear, "clear");
15228 cmdline_parse_token_string_t cmd_clear_input_set_all =
15229         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15230                                  all, "all");
15231
15232 cmdline_parse_inst_t cmd_clear_input_set = {
15233         .f = cmd_clear_input_set_parsed,
15234         .data = NULL,
15235         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15236                     "fdir_inset|fdir_flx_inset clear all",
15237         .tokens = {
15238                 (void *)&cmd_clear_input_set_port,
15239                 (void *)&cmd_clear_input_set_cfg,
15240                 (void *)&cmd_clear_input_set_port_id,
15241                 (void *)&cmd_clear_input_set_pctype,
15242                 (void *)&cmd_clear_input_set_pctype_id,
15243                 (void *)&cmd_clear_input_set_inset_type,
15244                 (void *)&cmd_clear_input_set_clear,
15245                 (void *)&cmd_clear_input_set_all,
15246                 NULL,
15247         },
15248 };
15249
15250 /* show vf stats */
15251
15252 /* Common result structure for show vf stats */
15253 struct cmd_show_vf_stats_result {
15254         cmdline_fixed_string_t show;
15255         cmdline_fixed_string_t vf;
15256         cmdline_fixed_string_t stats;
15257         portid_t port_id;
15258         uint16_t vf_id;
15259 };
15260
15261 /* Common CLI fields show vf stats*/
15262 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15263         TOKEN_STRING_INITIALIZER
15264                 (struct cmd_show_vf_stats_result,
15265                  show, "show");
15266 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15267         TOKEN_STRING_INITIALIZER
15268                 (struct cmd_show_vf_stats_result,
15269                  vf, "vf");
15270 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15271         TOKEN_STRING_INITIALIZER
15272                 (struct cmd_show_vf_stats_result,
15273                  stats, "stats");
15274 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15275         TOKEN_NUM_INITIALIZER
15276                 (struct cmd_show_vf_stats_result,
15277                  port_id, UINT16);
15278 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15279         TOKEN_NUM_INITIALIZER
15280                 (struct cmd_show_vf_stats_result,
15281                  vf_id, UINT16);
15282
15283 static void
15284 cmd_show_vf_stats_parsed(
15285         void *parsed_result,
15286         __attribute__((unused)) struct cmdline *cl,
15287         __attribute__((unused)) void *data)
15288 {
15289         struct cmd_show_vf_stats_result *res = parsed_result;
15290         struct rte_eth_stats stats;
15291         int ret = -ENOTSUP;
15292         static const char *nic_stats_border = "########################";
15293
15294         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15295                 return;
15296
15297         memset(&stats, 0, sizeof(stats));
15298
15299 #ifdef RTE_LIBRTE_I40E_PMD
15300         if (ret == -ENOTSUP)
15301                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15302                                                 res->vf_id,
15303                                                 &stats);
15304 #endif
15305 #ifdef RTE_LIBRTE_BNXT_PMD
15306         if (ret == -ENOTSUP)
15307                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15308                                                 res->vf_id,
15309                                                 &stats);
15310 #endif
15311
15312         switch (ret) {
15313         case 0:
15314                 break;
15315         case -EINVAL:
15316                 printf("invalid vf_id %d\n", res->vf_id);
15317                 break;
15318         case -ENODEV:
15319                 printf("invalid port_id %d\n", res->port_id);
15320                 break;
15321         case -ENOTSUP:
15322                 printf("function not implemented\n");
15323                 break;
15324         default:
15325                 printf("programming error: (%s)\n", strerror(-ret));
15326         }
15327
15328         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15329                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15330
15331         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15332                "%-"PRIu64"\n",
15333                stats.ipackets, stats.imissed, stats.ibytes);
15334         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15335         printf("  RX-nombuf:  %-10"PRIu64"\n",
15336                stats.rx_nombuf);
15337         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15338                "%-"PRIu64"\n",
15339                stats.opackets, stats.oerrors, stats.obytes);
15340
15341         printf("  %s############################%s\n",
15342                                nic_stats_border, nic_stats_border);
15343 }
15344
15345 cmdline_parse_inst_t cmd_show_vf_stats = {
15346         .f = cmd_show_vf_stats_parsed,
15347         .data = NULL,
15348         .help_str = "show vf stats <port_id> <vf_id>",
15349         .tokens = {
15350                 (void *)&cmd_show_vf_stats_show,
15351                 (void *)&cmd_show_vf_stats_vf,
15352                 (void *)&cmd_show_vf_stats_stats,
15353                 (void *)&cmd_show_vf_stats_port_id,
15354                 (void *)&cmd_show_vf_stats_vf_id,
15355                 NULL,
15356         },
15357 };
15358
15359 /* clear vf stats */
15360
15361 /* Common result structure for clear vf stats */
15362 struct cmd_clear_vf_stats_result {
15363         cmdline_fixed_string_t clear;
15364         cmdline_fixed_string_t vf;
15365         cmdline_fixed_string_t stats;
15366         portid_t port_id;
15367         uint16_t vf_id;
15368 };
15369
15370 /* Common CLI fields clear vf stats*/
15371 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15372         TOKEN_STRING_INITIALIZER
15373                 (struct cmd_clear_vf_stats_result,
15374                  clear, "clear");
15375 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15376         TOKEN_STRING_INITIALIZER
15377                 (struct cmd_clear_vf_stats_result,
15378                  vf, "vf");
15379 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15380         TOKEN_STRING_INITIALIZER
15381                 (struct cmd_clear_vf_stats_result,
15382                  stats, "stats");
15383 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15384         TOKEN_NUM_INITIALIZER
15385                 (struct cmd_clear_vf_stats_result,
15386                  port_id, UINT16);
15387 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15388         TOKEN_NUM_INITIALIZER
15389                 (struct cmd_clear_vf_stats_result,
15390                  vf_id, UINT16);
15391
15392 static void
15393 cmd_clear_vf_stats_parsed(
15394         void *parsed_result,
15395         __attribute__((unused)) struct cmdline *cl,
15396         __attribute__((unused)) void *data)
15397 {
15398         struct cmd_clear_vf_stats_result *res = parsed_result;
15399         int ret = -ENOTSUP;
15400
15401         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15402                 return;
15403
15404 #ifdef RTE_LIBRTE_I40E_PMD
15405         if (ret == -ENOTSUP)
15406                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15407                                                   res->vf_id);
15408 #endif
15409 #ifdef RTE_LIBRTE_BNXT_PMD
15410         if (ret == -ENOTSUP)
15411                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15412                                                   res->vf_id);
15413 #endif
15414
15415         switch (ret) {
15416         case 0:
15417                 break;
15418         case -EINVAL:
15419                 printf("invalid vf_id %d\n", res->vf_id);
15420                 break;
15421         case -ENODEV:
15422                 printf("invalid port_id %d\n", res->port_id);
15423                 break;
15424         case -ENOTSUP:
15425                 printf("function not implemented\n");
15426                 break;
15427         default:
15428                 printf("programming error: (%s)\n", strerror(-ret));
15429         }
15430 }
15431
15432 cmdline_parse_inst_t cmd_clear_vf_stats = {
15433         .f = cmd_clear_vf_stats_parsed,
15434         .data = NULL,
15435         .help_str = "clear vf stats <port_id> <vf_id>",
15436         .tokens = {
15437                 (void *)&cmd_clear_vf_stats_clear,
15438                 (void *)&cmd_clear_vf_stats_vf,
15439                 (void *)&cmd_clear_vf_stats_stats,
15440                 (void *)&cmd_clear_vf_stats_port_id,
15441                 (void *)&cmd_clear_vf_stats_vf_id,
15442                 NULL,
15443         },
15444 };
15445
15446 /* port config pctype mapping reset */
15447
15448 /* Common result structure for port config pctype mapping reset */
15449 struct cmd_pctype_mapping_reset_result {
15450         cmdline_fixed_string_t port;
15451         cmdline_fixed_string_t config;
15452         portid_t port_id;
15453         cmdline_fixed_string_t pctype;
15454         cmdline_fixed_string_t mapping;
15455         cmdline_fixed_string_t reset;
15456 };
15457
15458 /* Common CLI fields for port config pctype mapping reset*/
15459 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15460         TOKEN_STRING_INITIALIZER
15461                 (struct cmd_pctype_mapping_reset_result,
15462                  port, "port");
15463 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15464         TOKEN_STRING_INITIALIZER
15465                 (struct cmd_pctype_mapping_reset_result,
15466                  config, "config");
15467 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15468         TOKEN_NUM_INITIALIZER
15469                 (struct cmd_pctype_mapping_reset_result,
15470                  port_id, UINT16);
15471 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15472         TOKEN_STRING_INITIALIZER
15473                 (struct cmd_pctype_mapping_reset_result,
15474                  pctype, "pctype");
15475 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15476         TOKEN_STRING_INITIALIZER
15477                 (struct cmd_pctype_mapping_reset_result,
15478                  mapping, "mapping");
15479 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15480         TOKEN_STRING_INITIALIZER
15481                 (struct cmd_pctype_mapping_reset_result,
15482                  reset, "reset");
15483
15484 static void
15485 cmd_pctype_mapping_reset_parsed(
15486         void *parsed_result,
15487         __attribute__((unused)) struct cmdline *cl,
15488         __attribute__((unused)) void *data)
15489 {
15490         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15491         int ret = -ENOTSUP;
15492
15493         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15494                 return;
15495
15496 #ifdef RTE_LIBRTE_I40E_PMD
15497         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15498 #endif
15499
15500         switch (ret) {
15501         case 0:
15502                 break;
15503         case -ENODEV:
15504                 printf("invalid port_id %d\n", res->port_id);
15505                 break;
15506         case -ENOTSUP:
15507                 printf("function not implemented\n");
15508                 break;
15509         default:
15510                 printf("programming error: (%s)\n", strerror(-ret));
15511         }
15512 }
15513
15514 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15515         .f = cmd_pctype_mapping_reset_parsed,
15516         .data = NULL,
15517         .help_str = "port config <port_id> pctype mapping reset",
15518         .tokens = {
15519                 (void *)&cmd_pctype_mapping_reset_port,
15520                 (void *)&cmd_pctype_mapping_reset_config,
15521                 (void *)&cmd_pctype_mapping_reset_port_id,
15522                 (void *)&cmd_pctype_mapping_reset_pctype,
15523                 (void *)&cmd_pctype_mapping_reset_mapping,
15524                 (void *)&cmd_pctype_mapping_reset_reset,
15525                 NULL,
15526         },
15527 };
15528
15529 /* show port pctype mapping */
15530
15531 /* Common result structure for show port pctype mapping */
15532 struct cmd_pctype_mapping_get_result {
15533         cmdline_fixed_string_t show;
15534         cmdline_fixed_string_t port;
15535         portid_t port_id;
15536         cmdline_fixed_string_t pctype;
15537         cmdline_fixed_string_t mapping;
15538 };
15539
15540 /* Common CLI fields for pctype mapping get */
15541 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15542         TOKEN_STRING_INITIALIZER
15543                 (struct cmd_pctype_mapping_get_result,
15544                  show, "show");
15545 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15546         TOKEN_STRING_INITIALIZER
15547                 (struct cmd_pctype_mapping_get_result,
15548                  port, "port");
15549 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15550         TOKEN_NUM_INITIALIZER
15551                 (struct cmd_pctype_mapping_get_result,
15552                  port_id, UINT16);
15553 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15554         TOKEN_STRING_INITIALIZER
15555                 (struct cmd_pctype_mapping_get_result,
15556                  pctype, "pctype");
15557 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15558         TOKEN_STRING_INITIALIZER
15559                 (struct cmd_pctype_mapping_get_result,
15560                  mapping, "mapping");
15561
15562 static void
15563 cmd_pctype_mapping_get_parsed(
15564         void *parsed_result,
15565         __attribute__((unused)) struct cmdline *cl,
15566         __attribute__((unused)) void *data)
15567 {
15568         struct cmd_pctype_mapping_get_result *res = parsed_result;
15569         int ret = -ENOTSUP;
15570 #ifdef RTE_LIBRTE_I40E_PMD
15571         struct rte_pmd_i40e_flow_type_mapping
15572                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15573         int i, j, first_pctype;
15574 #endif
15575
15576         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15577                 return;
15578
15579 #ifdef RTE_LIBRTE_I40E_PMD
15580         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15581 #endif
15582
15583         switch (ret) {
15584         case 0:
15585                 break;
15586         case -ENODEV:
15587                 printf("invalid port_id %d\n", res->port_id);
15588                 return;
15589         case -ENOTSUP:
15590                 printf("function not implemented\n");
15591                 return;
15592         default:
15593                 printf("programming error: (%s)\n", strerror(-ret));
15594                 return;
15595         }
15596
15597 #ifdef RTE_LIBRTE_I40E_PMD
15598         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15599                 if (mapping[i].pctype != 0ULL) {
15600                         first_pctype = 1;
15601
15602                         printf("pctype: ");
15603                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15604                                 if (mapping[i].pctype & (1ULL << j)) {
15605                                         printf(first_pctype ?
15606                                                "%02d" : ",%02d", j);
15607                                         first_pctype = 0;
15608                                 }
15609                         }
15610                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15611                 }
15612         }
15613 #endif
15614 }
15615
15616 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15617         .f = cmd_pctype_mapping_get_parsed,
15618         .data = NULL,
15619         .help_str = "show port <port_id> pctype mapping",
15620         .tokens = {
15621                 (void *)&cmd_pctype_mapping_get_show,
15622                 (void *)&cmd_pctype_mapping_get_port,
15623                 (void *)&cmd_pctype_mapping_get_port_id,
15624                 (void *)&cmd_pctype_mapping_get_pctype,
15625                 (void *)&cmd_pctype_mapping_get_mapping,
15626                 NULL,
15627         },
15628 };
15629
15630 /* port config pctype mapping update */
15631
15632 /* Common result structure for port config pctype mapping update */
15633 struct cmd_pctype_mapping_update_result {
15634         cmdline_fixed_string_t port;
15635         cmdline_fixed_string_t config;
15636         portid_t port_id;
15637         cmdline_fixed_string_t pctype;
15638         cmdline_fixed_string_t mapping;
15639         cmdline_fixed_string_t update;
15640         cmdline_fixed_string_t pctype_list;
15641         uint16_t flow_type;
15642 };
15643
15644 /* Common CLI fields for pctype mapping update*/
15645 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15646         TOKEN_STRING_INITIALIZER
15647                 (struct cmd_pctype_mapping_update_result,
15648                  port, "port");
15649 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15650         TOKEN_STRING_INITIALIZER
15651                 (struct cmd_pctype_mapping_update_result,
15652                  config, "config");
15653 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15654         TOKEN_NUM_INITIALIZER
15655                 (struct cmd_pctype_mapping_update_result,
15656                  port_id, UINT16);
15657 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15658         TOKEN_STRING_INITIALIZER
15659                 (struct cmd_pctype_mapping_update_result,
15660                  pctype, "pctype");
15661 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15662         TOKEN_STRING_INITIALIZER
15663                 (struct cmd_pctype_mapping_update_result,
15664                  mapping, "mapping");
15665 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15666         TOKEN_STRING_INITIALIZER
15667                 (struct cmd_pctype_mapping_update_result,
15668                  update, "update");
15669 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15670         TOKEN_STRING_INITIALIZER
15671                 (struct cmd_pctype_mapping_update_result,
15672                  pctype_list, NULL);
15673 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15674         TOKEN_NUM_INITIALIZER
15675                 (struct cmd_pctype_mapping_update_result,
15676                  flow_type, UINT16);
15677
15678 static void
15679 cmd_pctype_mapping_update_parsed(
15680         void *parsed_result,
15681         __attribute__((unused)) struct cmdline *cl,
15682         __attribute__((unused)) void *data)
15683 {
15684         struct cmd_pctype_mapping_update_result *res = parsed_result;
15685         int ret = -ENOTSUP;
15686 #ifdef RTE_LIBRTE_I40E_PMD
15687         struct rte_pmd_i40e_flow_type_mapping mapping;
15688         unsigned int i;
15689         unsigned int nb_item;
15690         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15691 #endif
15692
15693         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15694                 return;
15695
15696 #ifdef RTE_LIBRTE_I40E_PMD
15697         nb_item = parse_item_list(res->pctype_list, "pctypes",
15698                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15699         mapping.flow_type = res->flow_type;
15700         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15701                 mapping.pctype |= (1ULL << pctype_list[i]);
15702         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15703                                                 &mapping,
15704                                                 1,
15705                                                 0);
15706 #endif
15707
15708         switch (ret) {
15709         case 0:
15710                 break;
15711         case -EINVAL:
15712                 printf("invalid pctype or flow type\n");
15713                 break;
15714         case -ENODEV:
15715                 printf("invalid port_id %d\n", res->port_id);
15716                 break;
15717         case -ENOTSUP:
15718                 printf("function not implemented\n");
15719                 break;
15720         default:
15721                 printf("programming error: (%s)\n", strerror(-ret));
15722         }
15723 }
15724
15725 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15726         .f = cmd_pctype_mapping_update_parsed,
15727         .data = NULL,
15728         .help_str = "port config <port_id> pctype mapping update"
15729         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15730         .tokens = {
15731                 (void *)&cmd_pctype_mapping_update_port,
15732                 (void *)&cmd_pctype_mapping_update_config,
15733                 (void *)&cmd_pctype_mapping_update_port_id,
15734                 (void *)&cmd_pctype_mapping_update_pctype,
15735                 (void *)&cmd_pctype_mapping_update_mapping,
15736                 (void *)&cmd_pctype_mapping_update_update,
15737                 (void *)&cmd_pctype_mapping_update_pc_type,
15738                 (void *)&cmd_pctype_mapping_update_flow_type,
15739                 NULL,
15740         },
15741 };
15742
15743 /* ptype mapping get */
15744
15745 /* Common result structure for ptype mapping get */
15746 struct cmd_ptype_mapping_get_result {
15747         cmdline_fixed_string_t ptype;
15748         cmdline_fixed_string_t mapping;
15749         cmdline_fixed_string_t get;
15750         portid_t port_id;
15751         uint8_t valid_only;
15752 };
15753
15754 /* Common CLI fields for ptype mapping get */
15755 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15756         TOKEN_STRING_INITIALIZER
15757                 (struct cmd_ptype_mapping_get_result,
15758                  ptype, "ptype");
15759 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15760         TOKEN_STRING_INITIALIZER
15761                 (struct cmd_ptype_mapping_get_result,
15762                  mapping, "mapping");
15763 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15764         TOKEN_STRING_INITIALIZER
15765                 (struct cmd_ptype_mapping_get_result,
15766                  get, "get");
15767 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15768         TOKEN_NUM_INITIALIZER
15769                 (struct cmd_ptype_mapping_get_result,
15770                  port_id, UINT16);
15771 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15772         TOKEN_NUM_INITIALIZER
15773                 (struct cmd_ptype_mapping_get_result,
15774                  valid_only, UINT8);
15775
15776 static void
15777 cmd_ptype_mapping_get_parsed(
15778         void *parsed_result,
15779         __attribute__((unused)) struct cmdline *cl,
15780         __attribute__((unused)) void *data)
15781 {
15782         struct cmd_ptype_mapping_get_result *res = parsed_result;
15783         int ret = -ENOTSUP;
15784 #ifdef RTE_LIBRTE_I40E_PMD
15785         int max_ptype_num = 256;
15786         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15787         uint16_t count;
15788         int i;
15789 #endif
15790
15791         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15792                 return;
15793
15794 #ifdef RTE_LIBRTE_I40E_PMD
15795         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15796                                         mapping,
15797                                         max_ptype_num,
15798                                         &count,
15799                                         res->valid_only);
15800 #endif
15801
15802         switch (ret) {
15803         case 0:
15804                 break;
15805         case -ENODEV:
15806                 printf("invalid port_id %d\n", res->port_id);
15807                 break;
15808         case -ENOTSUP:
15809                 printf("function not implemented\n");
15810                 break;
15811         default:
15812                 printf("programming error: (%s)\n", strerror(-ret));
15813         }
15814
15815 #ifdef RTE_LIBRTE_I40E_PMD
15816         if (!ret) {
15817                 for (i = 0; i < count; i++)
15818                         printf("%3d\t0x%08x\n",
15819                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15820         }
15821 #endif
15822 }
15823
15824 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15825         .f = cmd_ptype_mapping_get_parsed,
15826         .data = NULL,
15827         .help_str = "ptype mapping get <port_id> <valid_only>",
15828         .tokens = {
15829                 (void *)&cmd_ptype_mapping_get_ptype,
15830                 (void *)&cmd_ptype_mapping_get_mapping,
15831                 (void *)&cmd_ptype_mapping_get_get,
15832                 (void *)&cmd_ptype_mapping_get_port_id,
15833                 (void *)&cmd_ptype_mapping_get_valid_only,
15834                 NULL,
15835         },
15836 };
15837
15838 /* ptype mapping replace */
15839
15840 /* Common result structure for ptype mapping replace */
15841 struct cmd_ptype_mapping_replace_result {
15842         cmdline_fixed_string_t ptype;
15843         cmdline_fixed_string_t mapping;
15844         cmdline_fixed_string_t replace;
15845         portid_t port_id;
15846         uint32_t target;
15847         uint8_t mask;
15848         uint32_t pkt_type;
15849 };
15850
15851 /* Common CLI fields for ptype mapping replace */
15852 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15853         TOKEN_STRING_INITIALIZER
15854                 (struct cmd_ptype_mapping_replace_result,
15855                  ptype, "ptype");
15856 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15857         TOKEN_STRING_INITIALIZER
15858                 (struct cmd_ptype_mapping_replace_result,
15859                  mapping, "mapping");
15860 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15861         TOKEN_STRING_INITIALIZER
15862                 (struct cmd_ptype_mapping_replace_result,
15863                  replace, "replace");
15864 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15865         TOKEN_NUM_INITIALIZER
15866                 (struct cmd_ptype_mapping_replace_result,
15867                  port_id, UINT16);
15868 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15869         TOKEN_NUM_INITIALIZER
15870                 (struct cmd_ptype_mapping_replace_result,
15871                  target, UINT32);
15872 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15873         TOKEN_NUM_INITIALIZER
15874                 (struct cmd_ptype_mapping_replace_result,
15875                  mask, UINT8);
15876 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15877         TOKEN_NUM_INITIALIZER
15878                 (struct cmd_ptype_mapping_replace_result,
15879                  pkt_type, UINT32);
15880
15881 static void
15882 cmd_ptype_mapping_replace_parsed(
15883         void *parsed_result,
15884         __attribute__((unused)) struct cmdline *cl,
15885         __attribute__((unused)) void *data)
15886 {
15887         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15888         int ret = -ENOTSUP;
15889
15890         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15891                 return;
15892
15893 #ifdef RTE_LIBRTE_I40E_PMD
15894         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15895                                         res->target,
15896                                         res->mask,
15897                                         res->pkt_type);
15898 #endif
15899
15900         switch (ret) {
15901         case 0:
15902                 break;
15903         case -EINVAL:
15904                 printf("invalid ptype 0x%8x or 0x%8x\n",
15905                                 res->target, res->pkt_type);
15906                 break;
15907         case -ENODEV:
15908                 printf("invalid port_id %d\n", res->port_id);
15909                 break;
15910         case -ENOTSUP:
15911                 printf("function not implemented\n");
15912                 break;
15913         default:
15914                 printf("programming error: (%s)\n", strerror(-ret));
15915         }
15916 }
15917
15918 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15919         .f = cmd_ptype_mapping_replace_parsed,
15920         .data = NULL,
15921         .help_str =
15922                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15923         .tokens = {
15924                 (void *)&cmd_ptype_mapping_replace_ptype,
15925                 (void *)&cmd_ptype_mapping_replace_mapping,
15926                 (void *)&cmd_ptype_mapping_replace_replace,
15927                 (void *)&cmd_ptype_mapping_replace_port_id,
15928                 (void *)&cmd_ptype_mapping_replace_target,
15929                 (void *)&cmd_ptype_mapping_replace_mask,
15930                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15931                 NULL,
15932         },
15933 };
15934
15935 /* ptype mapping reset */
15936
15937 /* Common result structure for ptype mapping reset */
15938 struct cmd_ptype_mapping_reset_result {
15939         cmdline_fixed_string_t ptype;
15940         cmdline_fixed_string_t mapping;
15941         cmdline_fixed_string_t reset;
15942         portid_t port_id;
15943 };
15944
15945 /* Common CLI fields for ptype mapping reset*/
15946 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15947         TOKEN_STRING_INITIALIZER
15948                 (struct cmd_ptype_mapping_reset_result,
15949                  ptype, "ptype");
15950 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15951         TOKEN_STRING_INITIALIZER
15952                 (struct cmd_ptype_mapping_reset_result,
15953                  mapping, "mapping");
15954 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15955         TOKEN_STRING_INITIALIZER
15956                 (struct cmd_ptype_mapping_reset_result,
15957                  reset, "reset");
15958 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15959         TOKEN_NUM_INITIALIZER
15960                 (struct cmd_ptype_mapping_reset_result,
15961                  port_id, UINT16);
15962
15963 static void
15964 cmd_ptype_mapping_reset_parsed(
15965         void *parsed_result,
15966         __attribute__((unused)) struct cmdline *cl,
15967         __attribute__((unused)) void *data)
15968 {
15969         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15970         int ret = -ENOTSUP;
15971
15972         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15973                 return;
15974
15975 #ifdef RTE_LIBRTE_I40E_PMD
15976         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15977 #endif
15978
15979         switch (ret) {
15980         case 0:
15981                 break;
15982         case -ENODEV:
15983                 printf("invalid port_id %d\n", res->port_id);
15984                 break;
15985         case -ENOTSUP:
15986                 printf("function not implemented\n");
15987                 break;
15988         default:
15989                 printf("programming error: (%s)\n", strerror(-ret));
15990         }
15991 }
15992
15993 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15994         .f = cmd_ptype_mapping_reset_parsed,
15995         .data = NULL,
15996         .help_str = "ptype mapping reset <port_id>",
15997         .tokens = {
15998                 (void *)&cmd_ptype_mapping_reset_ptype,
15999                 (void *)&cmd_ptype_mapping_reset_mapping,
16000                 (void *)&cmd_ptype_mapping_reset_reset,
16001                 (void *)&cmd_ptype_mapping_reset_port_id,
16002                 NULL,
16003         },
16004 };
16005
16006 /* ptype mapping update */
16007
16008 /* Common result structure for ptype mapping update */
16009 struct cmd_ptype_mapping_update_result {
16010         cmdline_fixed_string_t ptype;
16011         cmdline_fixed_string_t mapping;
16012         cmdline_fixed_string_t reset;
16013         portid_t port_id;
16014         uint8_t hw_ptype;
16015         uint32_t sw_ptype;
16016 };
16017
16018 /* Common CLI fields for ptype mapping update*/
16019 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16020         TOKEN_STRING_INITIALIZER
16021                 (struct cmd_ptype_mapping_update_result,
16022                  ptype, "ptype");
16023 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16024         TOKEN_STRING_INITIALIZER
16025                 (struct cmd_ptype_mapping_update_result,
16026                  mapping, "mapping");
16027 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16028         TOKEN_STRING_INITIALIZER
16029                 (struct cmd_ptype_mapping_update_result,
16030                  reset, "update");
16031 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16032         TOKEN_NUM_INITIALIZER
16033                 (struct cmd_ptype_mapping_update_result,
16034                  port_id, UINT16);
16035 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16036         TOKEN_NUM_INITIALIZER
16037                 (struct cmd_ptype_mapping_update_result,
16038                  hw_ptype, UINT8);
16039 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16040         TOKEN_NUM_INITIALIZER
16041                 (struct cmd_ptype_mapping_update_result,
16042                  sw_ptype, UINT32);
16043
16044 static void
16045 cmd_ptype_mapping_update_parsed(
16046         void *parsed_result,
16047         __attribute__((unused)) struct cmdline *cl,
16048         __attribute__((unused)) void *data)
16049 {
16050         struct cmd_ptype_mapping_update_result *res = parsed_result;
16051         int ret = -ENOTSUP;
16052 #ifdef RTE_LIBRTE_I40E_PMD
16053         struct rte_pmd_i40e_ptype_mapping mapping;
16054 #endif
16055         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16056                 return;
16057
16058 #ifdef RTE_LIBRTE_I40E_PMD
16059         mapping.hw_ptype = res->hw_ptype;
16060         mapping.sw_ptype = res->sw_ptype;
16061         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16062                                                 &mapping,
16063                                                 1,
16064                                                 0);
16065 #endif
16066
16067         switch (ret) {
16068         case 0:
16069                 break;
16070         case -EINVAL:
16071                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16072                 break;
16073         case -ENODEV:
16074                 printf("invalid port_id %d\n", res->port_id);
16075                 break;
16076         case -ENOTSUP:
16077                 printf("function not implemented\n");
16078                 break;
16079         default:
16080                 printf("programming error: (%s)\n", strerror(-ret));
16081         }
16082 }
16083
16084 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16085         .f = cmd_ptype_mapping_update_parsed,
16086         .data = NULL,
16087         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16088         .tokens = {
16089                 (void *)&cmd_ptype_mapping_update_ptype,
16090                 (void *)&cmd_ptype_mapping_update_mapping,
16091                 (void *)&cmd_ptype_mapping_update_update,
16092                 (void *)&cmd_ptype_mapping_update_port_id,
16093                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16094                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16095                 NULL,
16096         },
16097 };
16098
16099 /* Common result structure for file commands */
16100 struct cmd_cmdfile_result {
16101         cmdline_fixed_string_t load;
16102         cmdline_fixed_string_t filename;
16103 };
16104
16105 /* Common CLI fields for file commands */
16106 cmdline_parse_token_string_t cmd_load_cmdfile =
16107         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16108 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16109         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16110
16111 static void
16112 cmd_load_from_file_parsed(
16113         void *parsed_result,
16114         __attribute__((unused)) struct cmdline *cl,
16115         __attribute__((unused)) void *data)
16116 {
16117         struct cmd_cmdfile_result *res = parsed_result;
16118
16119         cmdline_read_from_file(res->filename);
16120 }
16121
16122 cmdline_parse_inst_t cmd_load_from_file = {
16123         .f = cmd_load_from_file_parsed,
16124         .data = NULL,
16125         .help_str = "load <filename>",
16126         .tokens = {
16127                 (void *)&cmd_load_cmdfile,
16128                 (void *)&cmd_load_cmdfile_filename,
16129                 NULL,
16130         },
16131 };
16132
16133 /* ******************************************************************************** */
16134
16135 /* list of instructions */
16136 cmdline_parse_ctx_t main_ctx[] = {
16137         (cmdline_parse_inst_t *)&cmd_help_brief,
16138         (cmdline_parse_inst_t *)&cmd_help_long,
16139         (cmdline_parse_inst_t *)&cmd_quit,
16140         (cmdline_parse_inst_t *)&cmd_load_from_file,
16141         (cmdline_parse_inst_t *)&cmd_showport,
16142         (cmdline_parse_inst_t *)&cmd_showqueue,
16143         (cmdline_parse_inst_t *)&cmd_showportall,
16144         (cmdline_parse_inst_t *)&cmd_showcfg,
16145         (cmdline_parse_inst_t *)&cmd_start,
16146         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16147         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16148         (cmdline_parse_inst_t *)&cmd_set_link_up,
16149         (cmdline_parse_inst_t *)&cmd_set_link_down,
16150         (cmdline_parse_inst_t *)&cmd_reset,
16151         (cmdline_parse_inst_t *)&cmd_set_numbers,
16152         (cmdline_parse_inst_t *)&cmd_set_log,
16153         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16154         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16155         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16156         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16157         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16158         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16159         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16160         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16161         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16162         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16163         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16164         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16165         (cmdline_parse_inst_t *)&cmd_set_link_check,
16166         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16167         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16168         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16169         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16170 #ifdef RTE_LIBRTE_PMD_BOND
16171         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16172         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16173         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16174         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16175         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16176         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16177         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16178         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16179         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16180         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16181         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16182 #endif
16183         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16184         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16185         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16186         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16187         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16188         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16189         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16190         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16191         (cmdline_parse_inst_t *)&cmd_csum_set,
16192         (cmdline_parse_inst_t *)&cmd_csum_show,
16193         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16194         (cmdline_parse_inst_t *)&cmd_tso_set,
16195         (cmdline_parse_inst_t *)&cmd_tso_show,
16196         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16197         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16198         (cmdline_parse_inst_t *)&cmd_gro_enable,
16199         (cmdline_parse_inst_t *)&cmd_gro_flush,
16200         (cmdline_parse_inst_t *)&cmd_gro_show,
16201         (cmdline_parse_inst_t *)&cmd_gso_enable,
16202         (cmdline_parse_inst_t *)&cmd_gso_size,
16203         (cmdline_parse_inst_t *)&cmd_gso_show,
16204         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16205         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16206         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16207         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16208         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16209         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16210         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16211         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16212         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16213         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16214         (cmdline_parse_inst_t *)&cmd_config_dcb,
16215         (cmdline_parse_inst_t *)&cmd_read_reg,
16216         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16217         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16218         (cmdline_parse_inst_t *)&cmd_write_reg,
16219         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16220         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16221         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16222         (cmdline_parse_inst_t *)&cmd_stop,
16223         (cmdline_parse_inst_t *)&cmd_mac_addr,
16224         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16225         (cmdline_parse_inst_t *)&cmd_set_qmap,
16226         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16227         (cmdline_parse_inst_t *)&cmd_operate_port,
16228         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16229         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16230         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16231         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16232         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16233         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16234         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16235         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16236         (cmdline_parse_inst_t *)&cmd_config_mtu,
16237         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16238         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16239         (cmdline_parse_inst_t *)&cmd_config_rss,
16240         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16241         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16242         (cmdline_parse_inst_t *)&cmd_showport_reta,
16243         (cmdline_parse_inst_t *)&cmd_config_burst,
16244         (cmdline_parse_inst_t *)&cmd_config_thresh,
16245         (cmdline_parse_inst_t *)&cmd_config_threshold,
16246         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16247         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16248         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16249         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16250         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16251         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16252         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16253         (cmdline_parse_inst_t *)&cmd_global_config,
16254         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16255         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16256         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16257         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16258         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16259         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16260         (cmdline_parse_inst_t *)&cmd_dump,
16261         (cmdline_parse_inst_t *)&cmd_dump_one,
16262         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16263         (cmdline_parse_inst_t *)&cmd_syn_filter,
16264         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16265         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16266         (cmdline_parse_inst_t *)&cmd_flex_filter,
16267         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16268         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16269         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16270         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16271         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16272         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16273         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16274         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16275         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16276         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16277         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16278         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16279         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16280         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16281         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16282         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16283         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16284         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16285         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16286         (cmdline_parse_inst_t *)&cmd_flow,
16287         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16288         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16289         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16290         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16291         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16292         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16293         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16294         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16295         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16296         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16297         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16298         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16299         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16300         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16301         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16302         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16303         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16304         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16305         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16306         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16307         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16308         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16309         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16310         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16311         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16312         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16313         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16314         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16315         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16316         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16317         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16318         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16319         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16320         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16321         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16322         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16323         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16324         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16325         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16326         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16327         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16328         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16329         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16330         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16331         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16332         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16333         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16334         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16335         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16336 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16337         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16338 #endif
16339         (cmdline_parse_inst_t *)&cmd_ddp_add,
16340         (cmdline_parse_inst_t *)&cmd_ddp_del,
16341         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16342         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16343         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16344         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16345         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16346         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16347         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16348         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16349         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16350         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16351
16352         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16353         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16354         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16355         (cmdline_parse_inst_t *)&cmd_queue_region,
16356         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16357         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16358         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16359         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16360         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16361         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16362         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16363         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16364         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16365         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16366         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16367         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16368         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16369         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16370         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16371         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16372         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16373         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16374         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16375         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16376         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16377         NULL,
16378 };
16379
16380 /* read cmdline commands from file */
16381 void
16382 cmdline_read_from_file(const char *filename)
16383 {
16384         struct cmdline *cl;
16385
16386         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16387         if (cl == NULL) {
16388                 printf("Failed to create file based cmdline context: %s\n",
16389                        filename);
16390                 return;
16391         }
16392
16393         cmdline_interact(cl);
16394         cmdline_quit(cl);
16395
16396         cmdline_free(cl);
16397
16398         printf("Read CLI commands from %s\n", filename);
16399 }
16400
16401 /* prompt function, called from main on MASTER lcore */
16402 void
16403 prompt(void)
16404 {
16405         /* initialize non-constant commands */
16406         cmd_set_fwd_mode_init();
16407         cmd_set_fwd_retry_mode_init();
16408
16409         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16410         if (testpmd_cl == NULL)
16411                 return;
16412         cmdline_interact(testpmd_cl);
16413         cmdline_stdin_exit(testpmd_cl);
16414 }
16415
16416 void
16417 prompt_exit(void)
16418 {
16419         if (testpmd_cl != NULL)
16420                 cmdline_quit(testpmd_cl);
16421 }
16422
16423 static void
16424 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16425 {
16426         if (id == (portid_t)RTE_PORT_ALL) {
16427                 portid_t pid;
16428
16429                 RTE_ETH_FOREACH_DEV(pid) {
16430                         /* check if need_reconfig has been set to 1 */
16431                         if (ports[pid].need_reconfig == 0)
16432                                 ports[pid].need_reconfig = dev;
16433                         /* check if need_reconfig_queues has been set to 1 */
16434                         if (ports[pid].need_reconfig_queues == 0)
16435                                 ports[pid].need_reconfig_queues = queue;
16436                 }
16437         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16438                 /* check if need_reconfig has been set to 1 */
16439                 if (ports[id].need_reconfig == 0)
16440                         ports[id].need_reconfig = dev;
16441                 /* check if need_reconfig_queues has been set to 1 */
16442                 if (ports[id].need_reconfig_queues == 0)
16443                         ports[id].need_reconfig_queues = queue;
16444         }
16445 }