app/testpmd: support generic tunnel Tx offloads
[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         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4168                 printf("Warning: IP TUNNEL TSO not supported therefore "
4169                        "not enabled for port %d\n", port_id);
4170         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4171                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4172                        "not enabled for port %d\n", port_id);
4173         return dev_info;
4174 }
4175
4176 static void
4177 cmd_tunnel_tso_set_parsed(void *parsed_result,
4178                           __attribute__((unused)) struct cmdline *cl,
4179                           __attribute__((unused)) void *data)
4180 {
4181         struct cmd_tunnel_tso_set_result *res = parsed_result;
4182         struct rte_eth_dev_info dev_info;
4183
4184         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4185                 return;
4186         if (!port_is_stopped(res->port_id)) {
4187                 printf("Please stop port %d first\n", res->port_id);
4188                 return;
4189         }
4190
4191         if (!strcmp(res->mode, "set"))
4192                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4193
4194         dev_info = check_tunnel_tso_nic_support(res->port_id);
4195         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4196                 ports[res->port_id].dev_conf.txmode.offloads &=
4197                         ~(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                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4202                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4203                 printf("TSO for tunneled packets is disabled\n");
4204         } else {
4205                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4206                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4207                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4208                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4209                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4210                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4211
4212                 ports[res->port_id].dev_conf.txmode.offloads |=
4213                         (tso_offloads & dev_info.tx_offload_capa);
4214                 printf("TSO segment size for tunneled packets is %d\n",
4215                         ports[res->port_id].tunnel_tso_segsz);
4216
4217                 /* Below conditions are needed to make it work:
4218                  * (1) tunnel TSO is supported by the NIC;
4219                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4220                  * are recognized;
4221                  * (3) for tunneled pkts with outer L3 of IPv4,
4222                  * "csum set outer-ip" must be set to hw, because after tso,
4223                  * total_len of outer IP header is changed, and the checksum
4224                  * of outer IP header calculated by sw should be wrong; that
4225                  * is not necessary for IPv6 tunneled pkts because there's no
4226                  * checksum in IP header anymore.
4227                  */
4228
4229                 if (!ports[res->port_id].parse_tunnel)
4230                         printf("Warning: csum parse_tunnel must be set "
4231                                 "so that tunneled packets are recognized\n");
4232                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4233                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4234                         printf("Warning: csum set outer-ip must be set to hw "
4235                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4236         }
4237
4238         cmd_reconfig_device_queue(res->port_id, 1, 1);
4239 }
4240
4241 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4242         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4243                                 tso, "tunnel_tso");
4244 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4245         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4246                                 mode, "set");
4247 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4248         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4249                                 tso_segsz, UINT16);
4250 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4251         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4252                                 port_id, UINT16);
4253
4254 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4255         .f = cmd_tunnel_tso_set_parsed,
4256         .data = NULL,
4257         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4258                 "Set TSO segment size of tunneled packets for csum engine "
4259                 "(0 to disable)",
4260         .tokens = {
4261                 (void *)&cmd_tunnel_tso_set_tso,
4262                 (void *)&cmd_tunnel_tso_set_mode,
4263                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4264                 (void *)&cmd_tunnel_tso_set_portid,
4265                 NULL,
4266         },
4267 };
4268
4269 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4270         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4271                                 mode, "show");
4272
4273
4274 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4275         .f = cmd_tunnel_tso_set_parsed,
4276         .data = NULL,
4277         .help_str = "tunnel_tso show <port_id> "
4278                 "Show TSO segment size of tunneled packets for csum engine",
4279         .tokens = {
4280                 (void *)&cmd_tunnel_tso_set_tso,
4281                 (void *)&cmd_tunnel_tso_show_mode,
4282                 (void *)&cmd_tunnel_tso_set_portid,
4283                 NULL,
4284         },
4285 };
4286
4287 /* *** SET GRO FOR A PORT *** */
4288 struct cmd_gro_enable_result {
4289         cmdline_fixed_string_t cmd_set;
4290         cmdline_fixed_string_t cmd_port;
4291         cmdline_fixed_string_t cmd_keyword;
4292         cmdline_fixed_string_t cmd_onoff;
4293         portid_t cmd_pid;
4294 };
4295
4296 static void
4297 cmd_gro_enable_parsed(void *parsed_result,
4298                 __attribute__((unused)) struct cmdline *cl,
4299                 __attribute__((unused)) void *data)
4300 {
4301         struct cmd_gro_enable_result *res;
4302
4303         res = parsed_result;
4304         if (!strcmp(res->cmd_keyword, "gro"))
4305                 setup_gro(res->cmd_onoff, res->cmd_pid);
4306 }
4307
4308 cmdline_parse_token_string_t cmd_gro_enable_set =
4309         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4310                         cmd_set, "set");
4311 cmdline_parse_token_string_t cmd_gro_enable_port =
4312         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4313                         cmd_keyword, "port");
4314 cmdline_parse_token_num_t cmd_gro_enable_pid =
4315         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4316                         cmd_pid, UINT16);
4317 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4318         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4319                         cmd_keyword, "gro");
4320 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4321         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4322                         cmd_onoff, "on#off");
4323
4324 cmdline_parse_inst_t cmd_gro_enable = {
4325         .f = cmd_gro_enable_parsed,
4326         .data = NULL,
4327         .help_str = "set port <port_id> gro on|off",
4328         .tokens = {
4329                 (void *)&cmd_gro_enable_set,
4330                 (void *)&cmd_gro_enable_port,
4331                 (void *)&cmd_gro_enable_pid,
4332                 (void *)&cmd_gro_enable_keyword,
4333                 (void *)&cmd_gro_enable_onoff,
4334                 NULL,
4335         },
4336 };
4337
4338 /* *** DISPLAY GRO CONFIGURATION *** */
4339 struct cmd_gro_show_result {
4340         cmdline_fixed_string_t cmd_show;
4341         cmdline_fixed_string_t cmd_port;
4342         cmdline_fixed_string_t cmd_keyword;
4343         portid_t cmd_pid;
4344 };
4345
4346 static void
4347 cmd_gro_show_parsed(void *parsed_result,
4348                 __attribute__((unused)) struct cmdline *cl,
4349                 __attribute__((unused)) void *data)
4350 {
4351         struct cmd_gro_show_result *res;
4352
4353         res = parsed_result;
4354         if (!strcmp(res->cmd_keyword, "gro"))
4355                 show_gro(res->cmd_pid);
4356 }
4357
4358 cmdline_parse_token_string_t cmd_gro_show_show =
4359         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4360                         cmd_show, "show");
4361 cmdline_parse_token_string_t cmd_gro_show_port =
4362         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4363                         cmd_port, "port");
4364 cmdline_parse_token_num_t cmd_gro_show_pid =
4365         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4366                         cmd_pid, UINT16);
4367 cmdline_parse_token_string_t cmd_gro_show_keyword =
4368         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4369                         cmd_keyword, "gro");
4370
4371 cmdline_parse_inst_t cmd_gro_show = {
4372         .f = cmd_gro_show_parsed,
4373         .data = NULL,
4374         .help_str = "show port <port_id> gro",
4375         .tokens = {
4376                 (void *)&cmd_gro_show_show,
4377                 (void *)&cmd_gro_show_port,
4378                 (void *)&cmd_gro_show_pid,
4379                 (void *)&cmd_gro_show_keyword,
4380                 NULL,
4381         },
4382 };
4383
4384 /* *** SET FLUSH CYCLES FOR GRO *** */
4385 struct cmd_gro_flush_result {
4386         cmdline_fixed_string_t cmd_set;
4387         cmdline_fixed_string_t cmd_keyword;
4388         cmdline_fixed_string_t cmd_flush;
4389         uint8_t cmd_cycles;
4390 };
4391
4392 static void
4393 cmd_gro_flush_parsed(void *parsed_result,
4394                 __attribute__((unused)) struct cmdline *cl,
4395                 __attribute__((unused)) void *data)
4396 {
4397         struct cmd_gro_flush_result *res;
4398
4399         res = parsed_result;
4400         if ((!strcmp(res->cmd_keyword, "gro")) &&
4401                         (!strcmp(res->cmd_flush, "flush")))
4402                 setup_gro_flush_cycles(res->cmd_cycles);
4403 }
4404
4405 cmdline_parse_token_string_t cmd_gro_flush_set =
4406         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4407                         cmd_set, "set");
4408 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4409         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4410                         cmd_keyword, "gro");
4411 cmdline_parse_token_string_t cmd_gro_flush_flush =
4412         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4413                         cmd_flush, "flush");
4414 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4415         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4416                         cmd_cycles, UINT8);
4417
4418 cmdline_parse_inst_t cmd_gro_flush = {
4419         .f = cmd_gro_flush_parsed,
4420         .data = NULL,
4421         .help_str = "set gro flush <cycles>",
4422         .tokens = {
4423                 (void *)&cmd_gro_flush_set,
4424                 (void *)&cmd_gro_flush_keyword,
4425                 (void *)&cmd_gro_flush_flush,
4426                 (void *)&cmd_gro_flush_cycles,
4427                 NULL,
4428         },
4429 };
4430
4431 /* *** ENABLE/DISABLE GSO *** */
4432 struct cmd_gso_enable_result {
4433         cmdline_fixed_string_t cmd_set;
4434         cmdline_fixed_string_t cmd_port;
4435         cmdline_fixed_string_t cmd_keyword;
4436         cmdline_fixed_string_t cmd_mode;
4437         portid_t cmd_pid;
4438 };
4439
4440 static void
4441 cmd_gso_enable_parsed(void *parsed_result,
4442                 __attribute__((unused)) struct cmdline *cl,
4443                 __attribute__((unused)) void *data)
4444 {
4445         struct cmd_gso_enable_result *res;
4446
4447         res = parsed_result;
4448         if (!strcmp(res->cmd_keyword, "gso"))
4449                 setup_gso(res->cmd_mode, res->cmd_pid);
4450 }
4451
4452 cmdline_parse_token_string_t cmd_gso_enable_set =
4453         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4454                         cmd_set, "set");
4455 cmdline_parse_token_string_t cmd_gso_enable_port =
4456         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4457                         cmd_port, "port");
4458 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4459         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4460                         cmd_keyword, "gso");
4461 cmdline_parse_token_string_t cmd_gso_enable_mode =
4462         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4463                         cmd_mode, "on#off");
4464 cmdline_parse_token_num_t cmd_gso_enable_pid =
4465         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4466                         cmd_pid, UINT16);
4467
4468 cmdline_parse_inst_t cmd_gso_enable = {
4469         .f = cmd_gso_enable_parsed,
4470         .data = NULL,
4471         .help_str = "set port <port_id> gso on|off",
4472         .tokens = {
4473                 (void *)&cmd_gso_enable_set,
4474                 (void *)&cmd_gso_enable_port,
4475                 (void *)&cmd_gso_enable_pid,
4476                 (void *)&cmd_gso_enable_keyword,
4477                 (void *)&cmd_gso_enable_mode,
4478                 NULL,
4479         },
4480 };
4481
4482 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4483 struct cmd_gso_size_result {
4484         cmdline_fixed_string_t cmd_set;
4485         cmdline_fixed_string_t cmd_keyword;
4486         cmdline_fixed_string_t cmd_segsz;
4487         uint16_t cmd_size;
4488 };
4489
4490 static void
4491 cmd_gso_size_parsed(void *parsed_result,
4492                        __attribute__((unused)) struct cmdline *cl,
4493                        __attribute__((unused)) void *data)
4494 {
4495         struct cmd_gso_size_result *res = parsed_result;
4496
4497         if (test_done == 0) {
4498                 printf("Before setting GSO segsz, please first"
4499                                 " stop fowarding\n");
4500                 return;
4501         }
4502
4503         if (!strcmp(res->cmd_keyword, "gso") &&
4504                         !strcmp(res->cmd_segsz, "segsz")) {
4505                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4506                         printf("gso_size should be larger than %zu."
4507                                         " Please input a legal value\n",
4508                                         RTE_GSO_SEG_SIZE_MIN);
4509                 else
4510                         gso_max_segment_size = res->cmd_size;
4511         }
4512 }
4513
4514 cmdline_parse_token_string_t cmd_gso_size_set =
4515         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4516                                 cmd_set, "set");
4517 cmdline_parse_token_string_t cmd_gso_size_keyword =
4518         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4519                                 cmd_keyword, "gso");
4520 cmdline_parse_token_string_t cmd_gso_size_segsz =
4521         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4522                                 cmd_segsz, "segsz");
4523 cmdline_parse_token_num_t cmd_gso_size_size =
4524         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4525                                 cmd_size, UINT16);
4526
4527 cmdline_parse_inst_t cmd_gso_size = {
4528         .f = cmd_gso_size_parsed,
4529         .data = NULL,
4530         .help_str = "set gso segsz <length>",
4531         .tokens = {
4532                 (void *)&cmd_gso_size_set,
4533                 (void *)&cmd_gso_size_keyword,
4534                 (void *)&cmd_gso_size_segsz,
4535                 (void *)&cmd_gso_size_size,
4536                 NULL,
4537         },
4538 };
4539
4540 /* *** SHOW GSO CONFIGURATION *** */
4541 struct cmd_gso_show_result {
4542         cmdline_fixed_string_t cmd_show;
4543         cmdline_fixed_string_t cmd_port;
4544         cmdline_fixed_string_t cmd_keyword;
4545         portid_t cmd_pid;
4546 };
4547
4548 static void
4549 cmd_gso_show_parsed(void *parsed_result,
4550                        __attribute__((unused)) struct cmdline *cl,
4551                        __attribute__((unused)) void *data)
4552 {
4553         struct cmd_gso_show_result *res = parsed_result;
4554
4555         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4556                 printf("invalid port id %u\n", res->cmd_pid);
4557                 return;
4558         }
4559         if (!strcmp(res->cmd_keyword, "gso")) {
4560                 if (gso_ports[res->cmd_pid].enable) {
4561                         printf("Max GSO'd packet size: %uB\n"
4562                                         "Supported GSO types: TCP/IPv4, "
4563                                         "VxLAN with inner TCP/IPv4 packet, "
4564                                         "GRE with inner TCP/IPv4  packet\n",
4565                                         gso_max_segment_size);
4566                 } else
4567                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4568         }
4569 }
4570
4571 cmdline_parse_token_string_t cmd_gso_show_show =
4572 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4573                 cmd_show, "show");
4574 cmdline_parse_token_string_t cmd_gso_show_port =
4575 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4576                 cmd_port, "port");
4577 cmdline_parse_token_string_t cmd_gso_show_keyword =
4578         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4579                                 cmd_keyword, "gso");
4580 cmdline_parse_token_num_t cmd_gso_show_pid =
4581         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4582                                 cmd_pid, UINT16);
4583
4584 cmdline_parse_inst_t cmd_gso_show = {
4585         .f = cmd_gso_show_parsed,
4586         .data = NULL,
4587         .help_str = "show port <port_id> gso",
4588         .tokens = {
4589                 (void *)&cmd_gso_show_show,
4590                 (void *)&cmd_gso_show_port,
4591                 (void *)&cmd_gso_show_pid,
4592                 (void *)&cmd_gso_show_keyword,
4593                 NULL,
4594         },
4595 };
4596
4597 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4598 struct cmd_set_flush_rx {
4599         cmdline_fixed_string_t set;
4600         cmdline_fixed_string_t flush_rx;
4601         cmdline_fixed_string_t mode;
4602 };
4603
4604 static void
4605 cmd_set_flush_rx_parsed(void *parsed_result,
4606                 __attribute__((unused)) struct cmdline *cl,
4607                 __attribute__((unused)) void *data)
4608 {
4609         struct cmd_set_flush_rx *res = parsed_result;
4610         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4611 }
4612
4613 cmdline_parse_token_string_t cmd_setflushrx_set =
4614         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4615                         set, "set");
4616 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4617         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4618                         flush_rx, "flush_rx");
4619 cmdline_parse_token_string_t cmd_setflushrx_mode =
4620         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4621                         mode, "on#off");
4622
4623
4624 cmdline_parse_inst_t cmd_set_flush_rx = {
4625         .f = cmd_set_flush_rx_parsed,
4626         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4627         .data = NULL,
4628         .tokens = {
4629                 (void *)&cmd_setflushrx_set,
4630                 (void *)&cmd_setflushrx_flush_rx,
4631                 (void *)&cmd_setflushrx_mode,
4632                 NULL,
4633         },
4634 };
4635
4636 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4637 struct cmd_set_link_check {
4638         cmdline_fixed_string_t set;
4639         cmdline_fixed_string_t link_check;
4640         cmdline_fixed_string_t mode;
4641 };
4642
4643 static void
4644 cmd_set_link_check_parsed(void *parsed_result,
4645                 __attribute__((unused)) struct cmdline *cl,
4646                 __attribute__((unused)) void *data)
4647 {
4648         struct cmd_set_link_check *res = parsed_result;
4649         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4650 }
4651
4652 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4653         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4654                         set, "set");
4655 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4656         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4657                         link_check, "link_check");
4658 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4659         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4660                         mode, "on#off");
4661
4662
4663 cmdline_parse_inst_t cmd_set_link_check = {
4664         .f = cmd_set_link_check_parsed,
4665         .help_str = "set link_check on|off: Enable/Disable link status check "
4666                     "when starting/stopping a port",
4667         .data = NULL,
4668         .tokens = {
4669                 (void *)&cmd_setlinkcheck_set,
4670                 (void *)&cmd_setlinkcheck_link_check,
4671                 (void *)&cmd_setlinkcheck_mode,
4672                 NULL,
4673         },
4674 };
4675
4676 /* *** SET NIC BYPASS MODE *** */
4677 struct cmd_set_bypass_mode_result {
4678         cmdline_fixed_string_t set;
4679         cmdline_fixed_string_t bypass;
4680         cmdline_fixed_string_t mode;
4681         cmdline_fixed_string_t value;
4682         portid_t port_id;
4683 };
4684
4685 static void
4686 cmd_set_bypass_mode_parsed(void *parsed_result,
4687                 __attribute__((unused)) struct cmdline *cl,
4688                 __attribute__((unused)) void *data)
4689 {
4690         struct cmd_set_bypass_mode_result *res = parsed_result;
4691         portid_t port_id = res->port_id;
4692         int32_t rc = -EINVAL;
4693
4694 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4695         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4696
4697         if (!strcmp(res->value, "bypass"))
4698                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4699         else if (!strcmp(res->value, "isolate"))
4700                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4701         else
4702                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4703
4704         /* Set the bypass mode for the relevant port. */
4705         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4706 #endif
4707         if (rc != 0)
4708                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4709 }
4710
4711 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4712         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4713                         set, "set");
4714 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4715         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4716                         bypass, "bypass");
4717 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4718         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4719                         mode, "mode");
4720 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4721         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4722                         value, "normal#bypass#isolate");
4723 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4724         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4725                                 port_id, UINT16);
4726
4727 cmdline_parse_inst_t cmd_set_bypass_mode = {
4728         .f = cmd_set_bypass_mode_parsed,
4729         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4730                     "Set the NIC bypass mode for port_id",
4731         .data = NULL,
4732         .tokens = {
4733                 (void *)&cmd_setbypass_mode_set,
4734                 (void *)&cmd_setbypass_mode_bypass,
4735                 (void *)&cmd_setbypass_mode_mode,
4736                 (void *)&cmd_setbypass_mode_value,
4737                 (void *)&cmd_setbypass_mode_port,
4738                 NULL,
4739         },
4740 };
4741
4742 /* *** SET NIC BYPASS EVENT *** */
4743 struct cmd_set_bypass_event_result {
4744         cmdline_fixed_string_t set;
4745         cmdline_fixed_string_t bypass;
4746         cmdline_fixed_string_t event;
4747         cmdline_fixed_string_t event_value;
4748         cmdline_fixed_string_t mode;
4749         cmdline_fixed_string_t mode_value;
4750         portid_t port_id;
4751 };
4752
4753 static void
4754 cmd_set_bypass_event_parsed(void *parsed_result,
4755                 __attribute__((unused)) struct cmdline *cl,
4756                 __attribute__((unused)) void *data)
4757 {
4758         int32_t rc = -EINVAL;
4759         struct cmd_set_bypass_event_result *res = parsed_result;
4760         portid_t port_id = res->port_id;
4761
4762 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4763         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4764         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4765
4766         if (!strcmp(res->event_value, "timeout"))
4767                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4768         else if (!strcmp(res->event_value, "os_on"))
4769                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4770         else if (!strcmp(res->event_value, "os_off"))
4771                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4772         else if (!strcmp(res->event_value, "power_on"))
4773                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4774         else if (!strcmp(res->event_value, "power_off"))
4775                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4776         else
4777                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4778
4779         if (!strcmp(res->mode_value, "bypass"))
4780                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4781         else if (!strcmp(res->mode_value, "isolate"))
4782                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4783         else
4784                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4785
4786         /* Set the watchdog timeout. */
4787         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4788
4789                 rc = -EINVAL;
4790                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4791                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4792                                                            bypass_timeout);
4793                 }
4794                 if (rc != 0) {
4795                         printf("Failed to set timeout value %u "
4796                         "for port %d, errto code: %d.\n",
4797                         bypass_timeout, port_id, rc);
4798                 }
4799         }
4800
4801         /* Set the bypass event to transition to bypass mode. */
4802         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4803                                               bypass_mode);
4804 #endif
4805
4806         if (rc != 0)
4807                 printf("\t Failed to set bypass event for port = %d.\n",
4808                        port_id);
4809 }
4810
4811 cmdline_parse_token_string_t cmd_setbypass_event_set =
4812         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4813                         set, "set");
4814 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4815         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4816                         bypass, "bypass");
4817 cmdline_parse_token_string_t cmd_setbypass_event_event =
4818         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4819                         event, "event");
4820 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4821         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4822                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4823 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4824         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4825                         mode, "mode");
4826 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4827         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4828                         mode_value, "normal#bypass#isolate");
4829 cmdline_parse_token_num_t cmd_setbypass_event_port =
4830         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4831                                 port_id, UINT16);
4832
4833 cmdline_parse_inst_t cmd_set_bypass_event = {
4834         .f = cmd_set_bypass_event_parsed,
4835         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4836                 "power_off mode normal|bypass|isolate <port_id>: "
4837                 "Set the NIC bypass event mode for port_id",
4838         .data = NULL,
4839         .tokens = {
4840                 (void *)&cmd_setbypass_event_set,
4841                 (void *)&cmd_setbypass_event_bypass,
4842                 (void *)&cmd_setbypass_event_event,
4843                 (void *)&cmd_setbypass_event_event_value,
4844                 (void *)&cmd_setbypass_event_mode,
4845                 (void *)&cmd_setbypass_event_mode_value,
4846                 (void *)&cmd_setbypass_event_port,
4847                 NULL,
4848         },
4849 };
4850
4851
4852 /* *** SET NIC BYPASS TIMEOUT *** */
4853 struct cmd_set_bypass_timeout_result {
4854         cmdline_fixed_string_t set;
4855         cmdline_fixed_string_t bypass;
4856         cmdline_fixed_string_t timeout;
4857         cmdline_fixed_string_t value;
4858 };
4859
4860 static void
4861 cmd_set_bypass_timeout_parsed(void *parsed_result,
4862                 __attribute__((unused)) struct cmdline *cl,
4863                 __attribute__((unused)) void *data)
4864 {
4865         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4866
4867 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4868         if (!strcmp(res->value, "1.5"))
4869                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4870         else if (!strcmp(res->value, "2"))
4871                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4872         else if (!strcmp(res->value, "3"))
4873                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4874         else if (!strcmp(res->value, "4"))
4875                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4876         else if (!strcmp(res->value, "8"))
4877                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4878         else if (!strcmp(res->value, "16"))
4879                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4880         else if (!strcmp(res->value, "32"))
4881                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4882         else
4883                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4884 #endif
4885 }
4886
4887 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4888         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4889                         set, "set");
4890 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4891         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4892                         bypass, "bypass");
4893 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4894         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4895                         timeout, "timeout");
4896 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4897         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4898                         value, "0#1.5#2#3#4#8#16#32");
4899
4900 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4901         .f = cmd_set_bypass_timeout_parsed,
4902         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4903                 "Set the NIC bypass watchdog timeout in seconds",
4904         .data = NULL,
4905         .tokens = {
4906                 (void *)&cmd_setbypass_timeout_set,
4907                 (void *)&cmd_setbypass_timeout_bypass,
4908                 (void *)&cmd_setbypass_timeout_timeout,
4909                 (void *)&cmd_setbypass_timeout_value,
4910                 NULL,
4911         },
4912 };
4913
4914 /* *** SHOW NIC BYPASS MODE *** */
4915 struct cmd_show_bypass_config_result {
4916         cmdline_fixed_string_t show;
4917         cmdline_fixed_string_t bypass;
4918         cmdline_fixed_string_t config;
4919         portid_t port_id;
4920 };
4921
4922 static void
4923 cmd_show_bypass_config_parsed(void *parsed_result,
4924                 __attribute__((unused)) struct cmdline *cl,
4925                 __attribute__((unused)) void *data)
4926 {
4927         struct cmd_show_bypass_config_result *res = parsed_result;
4928         portid_t port_id = res->port_id;
4929         int rc = -EINVAL;
4930 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4931         uint32_t event_mode;
4932         uint32_t bypass_mode;
4933         uint32_t timeout = bypass_timeout;
4934         int i;
4935
4936         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4937                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4938         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4939                 {"UNKNOWN", "normal", "bypass", "isolate"};
4940         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4941                 "NONE",
4942                 "OS/board on",
4943                 "power supply on",
4944                 "OS/board off",
4945                 "power supply off",
4946                 "timeout"};
4947         int num_events = (sizeof events) / (sizeof events[0]);
4948
4949         /* Display the bypass mode.*/
4950         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4951                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4952                 return;
4953         }
4954         else {
4955                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4956                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4957
4958                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4959         }
4960
4961         /* Display the bypass timeout.*/
4962         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4963                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4964
4965         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4966
4967         /* Display the bypass events and associated modes. */
4968         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4969
4970                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4971                         printf("\tFailed to get bypass mode for event = %s\n",
4972                                 events[i]);
4973                 } else {
4974                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4975                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4976
4977                         printf("\tbypass event: %-16s = %s\n", events[i],
4978                                 modes[event_mode]);
4979                 }
4980         }
4981 #endif
4982         if (rc != 0)
4983                 printf("\tFailed to get bypass configuration for port = %d\n",
4984                        port_id);
4985 }
4986
4987 cmdline_parse_token_string_t cmd_showbypass_config_show =
4988         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4989                         show, "show");
4990 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4991         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4992                         bypass, "bypass");
4993 cmdline_parse_token_string_t cmd_showbypass_config_config =
4994         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4995                         config, "config");
4996 cmdline_parse_token_num_t cmd_showbypass_config_port =
4997         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4998                                 port_id, UINT16);
4999
5000 cmdline_parse_inst_t cmd_show_bypass_config = {
5001         .f = cmd_show_bypass_config_parsed,
5002         .help_str = "show bypass config <port_id>: "
5003                     "Show the NIC bypass config for port_id",
5004         .data = NULL,
5005         .tokens = {
5006                 (void *)&cmd_showbypass_config_show,
5007                 (void *)&cmd_showbypass_config_bypass,
5008                 (void *)&cmd_showbypass_config_config,
5009                 (void *)&cmd_showbypass_config_port,
5010                 NULL,
5011         },
5012 };
5013
5014 #ifdef RTE_LIBRTE_PMD_BOND
5015 /* *** SET BONDING MODE *** */
5016 struct cmd_set_bonding_mode_result {
5017         cmdline_fixed_string_t set;
5018         cmdline_fixed_string_t bonding;
5019         cmdline_fixed_string_t mode;
5020         uint8_t value;
5021         portid_t port_id;
5022 };
5023
5024 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5025                 __attribute__((unused))  struct cmdline *cl,
5026                 __attribute__((unused)) void *data)
5027 {
5028         struct cmd_set_bonding_mode_result *res = parsed_result;
5029         portid_t port_id = res->port_id;
5030
5031         /* Set the bonding mode for the relevant port. */
5032         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5033                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5034 }
5035
5036 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5037 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5038                 set, "set");
5039 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5040 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5041                 bonding, "bonding");
5042 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5043 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5044                 mode, "mode");
5045 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5046 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5047                 value, UINT8);
5048 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5049 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5050                 port_id, UINT16);
5051
5052 cmdline_parse_inst_t cmd_set_bonding_mode = {
5053                 .f = cmd_set_bonding_mode_parsed,
5054                 .help_str = "set bonding mode <mode_value> <port_id>: "
5055                         "Set the bonding mode for port_id",
5056                 .data = NULL,
5057                 .tokens = {
5058                                 (void *) &cmd_setbonding_mode_set,
5059                                 (void *) &cmd_setbonding_mode_bonding,
5060                                 (void *) &cmd_setbonding_mode_mode,
5061                                 (void *) &cmd_setbonding_mode_value,
5062                                 (void *) &cmd_setbonding_mode_port,
5063                                 NULL
5064                 }
5065 };
5066
5067 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5068 struct cmd_set_bonding_lacp_dedicated_queues_result {
5069         cmdline_fixed_string_t set;
5070         cmdline_fixed_string_t bonding;
5071         cmdline_fixed_string_t lacp;
5072         cmdline_fixed_string_t dedicated_queues;
5073         portid_t port_id;
5074         cmdline_fixed_string_t mode;
5075 };
5076
5077 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5078                 __attribute__((unused))  struct cmdline *cl,
5079                 __attribute__((unused)) void *data)
5080 {
5081         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5082         portid_t port_id = res->port_id;
5083         struct rte_port *port;
5084
5085         port = &ports[port_id];
5086
5087         /** Check if the port is not started **/
5088         if (port->port_status != RTE_PORT_STOPPED) {
5089                 printf("Please stop port %d first\n", port_id);
5090                 return;
5091         }
5092
5093         if (!strcmp(res->mode, "enable")) {
5094                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5095                         printf("Dedicate queues for LACP control packets"
5096                                         " enabled\n");
5097                 else
5098                         printf("Enabling dedicate queues for LACP control "
5099                                         "packets on port %d failed\n", port_id);
5100         } else if (!strcmp(res->mode, "disable")) {
5101                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5102                         printf("Dedicated queues for LACP control packets "
5103                                         "disabled\n");
5104                 else
5105                         printf("Disabling dedicated queues for LACP control "
5106                                         "traffic on port %d failed\n", port_id);
5107         }
5108 }
5109
5110 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5111 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5112                 set, "set");
5113 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5114 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5115                 bonding, "bonding");
5116 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5117 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5118                 lacp, "lacp");
5119 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5120 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5121                 dedicated_queues, "dedicated_queues");
5122 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5123 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5124                 port_id, UINT16);
5125 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5126 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5127                 mode, "enable#disable");
5128
5129 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5130                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5131                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5132                         "enable|disable: "
5133                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5134                 .data = NULL,
5135                 .tokens = {
5136                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5137                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5138                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5139                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5140                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5141                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5142                         NULL
5143                 }
5144 };
5145
5146 /* *** SET BALANCE XMIT POLICY *** */
5147 struct cmd_set_bonding_balance_xmit_policy_result {
5148         cmdline_fixed_string_t set;
5149         cmdline_fixed_string_t bonding;
5150         cmdline_fixed_string_t balance_xmit_policy;
5151         portid_t port_id;
5152         cmdline_fixed_string_t policy;
5153 };
5154
5155 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5156                 __attribute__((unused))  struct cmdline *cl,
5157                 __attribute__((unused)) void *data)
5158 {
5159         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5160         portid_t port_id = res->port_id;
5161         uint8_t policy;
5162
5163         if (!strcmp(res->policy, "l2")) {
5164                 policy = BALANCE_XMIT_POLICY_LAYER2;
5165         } else if (!strcmp(res->policy, "l23")) {
5166                 policy = BALANCE_XMIT_POLICY_LAYER23;
5167         } else if (!strcmp(res->policy, "l34")) {
5168                 policy = BALANCE_XMIT_POLICY_LAYER34;
5169         } else {
5170                 printf("\t Invalid xmit policy selection");
5171                 return;
5172         }
5173
5174         /* Set the bonding mode for the relevant port. */
5175         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5176                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5177                                 port_id);
5178         }
5179 }
5180
5181 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5182 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5183                 set, "set");
5184 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5185 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5186                 bonding, "bonding");
5187 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5188 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5189                 balance_xmit_policy, "balance_xmit_policy");
5190 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5191 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5192                 port_id, UINT16);
5193 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5194 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5195                 policy, "l2#l23#l34");
5196
5197 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5198                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5199                 .help_str = "set bonding balance_xmit_policy <port_id> "
5200                         "l2|l23|l34: "
5201                         "Set the bonding balance_xmit_policy for port_id",
5202                 .data = NULL,
5203                 .tokens = {
5204                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5205                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5206                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5207                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5208                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5209                                 NULL
5210                 }
5211 };
5212
5213 /* *** SHOW NIC BONDING CONFIGURATION *** */
5214 struct cmd_show_bonding_config_result {
5215         cmdline_fixed_string_t show;
5216         cmdline_fixed_string_t bonding;
5217         cmdline_fixed_string_t config;
5218         portid_t port_id;
5219 };
5220
5221 static void cmd_show_bonding_config_parsed(void *parsed_result,
5222                 __attribute__((unused))  struct cmdline *cl,
5223                 __attribute__((unused)) void *data)
5224 {
5225         struct cmd_show_bonding_config_result *res = parsed_result;
5226         int bonding_mode, agg_mode;
5227         portid_t slaves[RTE_MAX_ETHPORTS];
5228         int num_slaves, num_active_slaves;
5229         int primary_id;
5230         int i;
5231         portid_t port_id = res->port_id;
5232
5233         /* Display the bonding mode.*/
5234         bonding_mode = rte_eth_bond_mode_get(port_id);
5235         if (bonding_mode < 0) {
5236                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5237                 return;
5238         } else
5239                 printf("\tBonding mode: %d\n", bonding_mode);
5240
5241         if (bonding_mode == BONDING_MODE_BALANCE) {
5242                 int balance_xmit_policy;
5243
5244                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5245                 if (balance_xmit_policy < 0) {
5246                         printf("\tFailed to get balance xmit policy for port = %d\n",
5247                                         port_id);
5248                         return;
5249                 } else {
5250                         printf("\tBalance Xmit Policy: ");
5251
5252                         switch (balance_xmit_policy) {
5253                         case BALANCE_XMIT_POLICY_LAYER2:
5254                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5255                                 break;
5256                         case BALANCE_XMIT_POLICY_LAYER23:
5257                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5258                                 break;
5259                         case BALANCE_XMIT_POLICY_LAYER34:
5260                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5261                                 break;
5262                         }
5263                         printf("\n");
5264                 }
5265         }
5266
5267         if (bonding_mode == BONDING_MODE_8023AD) {
5268                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5269                 printf("\tIEEE802.3AD Aggregator Mode: ");
5270                 switch (agg_mode) {
5271                 case AGG_BANDWIDTH:
5272                         printf("bandwidth");
5273                         break;
5274                 case AGG_STABLE:
5275                         printf("stable");
5276                         break;
5277                 case AGG_COUNT:
5278                         printf("count");
5279                         break;
5280                 }
5281                 printf("\n");
5282         }
5283
5284         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5285
5286         if (num_slaves < 0) {
5287                 printf("\tFailed to get slave list for port = %d\n", port_id);
5288                 return;
5289         }
5290         if (num_slaves > 0) {
5291                 printf("\tSlaves (%d): [", num_slaves);
5292                 for (i = 0; i < num_slaves - 1; i++)
5293                         printf("%d ", slaves[i]);
5294
5295                 printf("%d]\n", slaves[num_slaves - 1]);
5296         } else {
5297                 printf("\tSlaves: []\n");
5298
5299         }
5300
5301         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5302                         RTE_MAX_ETHPORTS);
5303
5304         if (num_active_slaves < 0) {
5305                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5306                 return;
5307         }
5308         if (num_active_slaves > 0) {
5309                 printf("\tActive Slaves (%d): [", num_active_slaves);
5310                 for (i = 0; i < num_active_slaves - 1; i++)
5311                         printf("%d ", slaves[i]);
5312
5313                 printf("%d]\n", slaves[num_active_slaves - 1]);
5314
5315         } else {
5316                 printf("\tActive Slaves: []\n");
5317
5318         }
5319
5320         primary_id = rte_eth_bond_primary_get(port_id);
5321         if (primary_id < 0) {
5322                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5323                 return;
5324         } else
5325                 printf("\tPrimary: [%d]\n", primary_id);
5326
5327 }
5328
5329 cmdline_parse_token_string_t cmd_showbonding_config_show =
5330 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5331                 show, "show");
5332 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5333 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5334                 bonding, "bonding");
5335 cmdline_parse_token_string_t cmd_showbonding_config_config =
5336 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5337                 config, "config");
5338 cmdline_parse_token_num_t cmd_showbonding_config_port =
5339 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5340                 port_id, UINT16);
5341
5342 cmdline_parse_inst_t cmd_show_bonding_config = {
5343                 .f = cmd_show_bonding_config_parsed,
5344                 .help_str = "show bonding config <port_id>: "
5345                         "Show the bonding config for port_id",
5346                 .data = NULL,
5347                 .tokens = {
5348                                 (void *)&cmd_showbonding_config_show,
5349                                 (void *)&cmd_showbonding_config_bonding,
5350                                 (void *)&cmd_showbonding_config_config,
5351                                 (void *)&cmd_showbonding_config_port,
5352                                 NULL
5353                 }
5354 };
5355
5356 /* *** SET BONDING PRIMARY *** */
5357 struct cmd_set_bonding_primary_result {
5358         cmdline_fixed_string_t set;
5359         cmdline_fixed_string_t bonding;
5360         cmdline_fixed_string_t primary;
5361         portid_t slave_id;
5362         portid_t port_id;
5363 };
5364
5365 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5366                 __attribute__((unused))  struct cmdline *cl,
5367                 __attribute__((unused)) void *data)
5368 {
5369         struct cmd_set_bonding_primary_result *res = parsed_result;
5370         portid_t master_port_id = res->port_id;
5371         portid_t slave_port_id = res->slave_id;
5372
5373         /* Set the primary slave for a bonded device. */
5374         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5375                 printf("\t Failed to set primary slave for port = %d.\n",
5376                                 master_port_id);
5377                 return;
5378         }
5379         init_port_config();
5380 }
5381
5382 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5383 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5384                 set, "set");
5385 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5386 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5387                 bonding, "bonding");
5388 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5389 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5390                 primary, "primary");
5391 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5392 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5393                 slave_id, UINT16);
5394 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5395 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5396                 port_id, UINT16);
5397
5398 cmdline_parse_inst_t cmd_set_bonding_primary = {
5399                 .f = cmd_set_bonding_primary_parsed,
5400                 .help_str = "set bonding primary <slave_id> <port_id>: "
5401                         "Set the primary slave for port_id",
5402                 .data = NULL,
5403                 .tokens = {
5404                                 (void *)&cmd_setbonding_primary_set,
5405                                 (void *)&cmd_setbonding_primary_bonding,
5406                                 (void *)&cmd_setbonding_primary_primary,
5407                                 (void *)&cmd_setbonding_primary_slave,
5408                                 (void *)&cmd_setbonding_primary_port,
5409                                 NULL
5410                 }
5411 };
5412
5413 /* *** ADD SLAVE *** */
5414 struct cmd_add_bonding_slave_result {
5415         cmdline_fixed_string_t add;
5416         cmdline_fixed_string_t bonding;
5417         cmdline_fixed_string_t slave;
5418         portid_t slave_id;
5419         portid_t port_id;
5420 };
5421
5422 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5423                 __attribute__((unused))  struct cmdline *cl,
5424                 __attribute__((unused)) void *data)
5425 {
5426         struct cmd_add_bonding_slave_result *res = parsed_result;
5427         portid_t master_port_id = res->port_id;
5428         portid_t slave_port_id = res->slave_id;
5429
5430         /* add the slave for a bonded device. */
5431         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5432                 printf("\t Failed to add slave %d to master port = %d.\n",
5433                                 slave_port_id, master_port_id);
5434                 return;
5435         }
5436         init_port_config();
5437         set_port_slave_flag(slave_port_id);
5438 }
5439
5440 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5441 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5442                 add, "add");
5443 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5444 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5445                 bonding, "bonding");
5446 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5447 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5448                 slave, "slave");
5449 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5450 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5451                 slave_id, UINT16);
5452 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5453 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5454                 port_id, UINT16);
5455
5456 cmdline_parse_inst_t cmd_add_bonding_slave = {
5457                 .f = cmd_add_bonding_slave_parsed,
5458                 .help_str = "add bonding slave <slave_id> <port_id>: "
5459                         "Add a slave device to a bonded device",
5460                 .data = NULL,
5461                 .tokens = {
5462                                 (void *)&cmd_addbonding_slave_add,
5463                                 (void *)&cmd_addbonding_slave_bonding,
5464                                 (void *)&cmd_addbonding_slave_slave,
5465                                 (void *)&cmd_addbonding_slave_slaveid,
5466                                 (void *)&cmd_addbonding_slave_port,
5467                                 NULL
5468                 }
5469 };
5470
5471 /* *** REMOVE SLAVE *** */
5472 struct cmd_remove_bonding_slave_result {
5473         cmdline_fixed_string_t remove;
5474         cmdline_fixed_string_t bonding;
5475         cmdline_fixed_string_t slave;
5476         portid_t slave_id;
5477         portid_t port_id;
5478 };
5479
5480 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5481                 __attribute__((unused))  struct cmdline *cl,
5482                 __attribute__((unused)) void *data)
5483 {
5484         struct cmd_remove_bonding_slave_result *res = parsed_result;
5485         portid_t master_port_id = res->port_id;
5486         portid_t slave_port_id = res->slave_id;
5487
5488         /* remove the slave from a bonded device. */
5489         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5490                 printf("\t Failed to remove slave %d from master port = %d.\n",
5491                                 slave_port_id, master_port_id);
5492                 return;
5493         }
5494         init_port_config();
5495         clear_port_slave_flag(slave_port_id);
5496 }
5497
5498 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5499                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5500                                 remove, "remove");
5501 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5502                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5503                                 bonding, "bonding");
5504 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5505                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5506                                 slave, "slave");
5507 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5508                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5509                                 slave_id, UINT16);
5510 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5511                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5512                                 port_id, UINT16);
5513
5514 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5515                 .f = cmd_remove_bonding_slave_parsed,
5516                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5517                         "Remove a slave device from a bonded device",
5518                 .data = NULL,
5519                 .tokens = {
5520                                 (void *)&cmd_removebonding_slave_remove,
5521                                 (void *)&cmd_removebonding_slave_bonding,
5522                                 (void *)&cmd_removebonding_slave_slave,
5523                                 (void *)&cmd_removebonding_slave_slaveid,
5524                                 (void *)&cmd_removebonding_slave_port,
5525                                 NULL
5526                 }
5527 };
5528
5529 /* *** CREATE BONDED DEVICE *** */
5530 struct cmd_create_bonded_device_result {
5531         cmdline_fixed_string_t create;
5532         cmdline_fixed_string_t bonded;
5533         cmdline_fixed_string_t device;
5534         uint8_t mode;
5535         uint8_t socket;
5536 };
5537
5538 static int bond_dev_num = 0;
5539
5540 static void cmd_create_bonded_device_parsed(void *parsed_result,
5541                 __attribute__((unused))  struct cmdline *cl,
5542                 __attribute__((unused)) void *data)
5543 {
5544         struct cmd_create_bonded_device_result *res = parsed_result;
5545         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5546         int port_id;
5547
5548         if (test_done == 0) {
5549                 printf("Please stop forwarding first\n");
5550                 return;
5551         }
5552
5553         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5554                         bond_dev_num++);
5555
5556         /* Create a new bonded device. */
5557         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5558         if (port_id < 0) {
5559                 printf("\t Failed to create bonded device.\n");
5560                 return;
5561         } else {
5562                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5563                                 port_id);
5564
5565                 /* Update number of ports */
5566                 nb_ports = rte_eth_dev_count_avail();
5567                 reconfig(port_id, res->socket);
5568                 rte_eth_promiscuous_enable(port_id);
5569         }
5570
5571 }
5572
5573 cmdline_parse_token_string_t cmd_createbonded_device_create =
5574                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5575                                 create, "create");
5576 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5577                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5578                                 bonded, "bonded");
5579 cmdline_parse_token_string_t cmd_createbonded_device_device =
5580                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5581                                 device, "device");
5582 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5583                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5584                                 mode, UINT8);
5585 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5586                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5587                                 socket, UINT8);
5588
5589 cmdline_parse_inst_t cmd_create_bonded_device = {
5590                 .f = cmd_create_bonded_device_parsed,
5591                 .help_str = "create bonded device <mode> <socket>: "
5592                         "Create a new bonded device with specific bonding mode and socket",
5593                 .data = NULL,
5594                 .tokens = {
5595                                 (void *)&cmd_createbonded_device_create,
5596                                 (void *)&cmd_createbonded_device_bonded,
5597                                 (void *)&cmd_createbonded_device_device,
5598                                 (void *)&cmd_createbonded_device_mode,
5599                                 (void *)&cmd_createbonded_device_socket,
5600                                 NULL
5601                 }
5602 };
5603
5604 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5605 struct cmd_set_bond_mac_addr_result {
5606         cmdline_fixed_string_t set;
5607         cmdline_fixed_string_t bonding;
5608         cmdline_fixed_string_t mac_addr;
5609         uint16_t port_num;
5610         struct ether_addr address;
5611 };
5612
5613 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5614                 __attribute__((unused))  struct cmdline *cl,
5615                 __attribute__((unused)) void *data)
5616 {
5617         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5618         int ret;
5619
5620         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5621                 return;
5622
5623         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5624
5625         /* check the return value and print it if is < 0 */
5626         if (ret < 0)
5627                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5628 }
5629
5630 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5631                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5632 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5633                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5634                                 "bonding");
5635 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5636                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5637                                 "mac_addr");
5638 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5639                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5640                                 port_num, UINT16);
5641 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5642                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5643
5644 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5645                 .f = cmd_set_bond_mac_addr_parsed,
5646                 .data = (void *) 0,
5647                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5648                 .tokens = {
5649                                 (void *)&cmd_set_bond_mac_addr_set,
5650                                 (void *)&cmd_set_bond_mac_addr_bonding,
5651                                 (void *)&cmd_set_bond_mac_addr_mac,
5652                                 (void *)&cmd_set_bond_mac_addr_portnum,
5653                                 (void *)&cmd_set_bond_mac_addr_addr,
5654                                 NULL
5655                 }
5656 };
5657
5658
5659 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5660 struct cmd_set_bond_mon_period_result {
5661         cmdline_fixed_string_t set;
5662         cmdline_fixed_string_t bonding;
5663         cmdline_fixed_string_t mon_period;
5664         uint16_t port_num;
5665         uint32_t period_ms;
5666 };
5667
5668 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5669                 __attribute__((unused))  struct cmdline *cl,
5670                 __attribute__((unused)) void *data)
5671 {
5672         struct cmd_set_bond_mon_period_result *res = parsed_result;
5673         int ret;
5674
5675         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5676
5677         /* check the return value and print it if is < 0 */
5678         if (ret < 0)
5679                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5680 }
5681
5682 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5683                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5684                                 set, "set");
5685 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5686                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5687                                 bonding, "bonding");
5688 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5689                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5690                                 mon_period,     "mon_period");
5691 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5692                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5693                                 port_num, UINT16);
5694 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5695                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5696                                 period_ms, UINT32);
5697
5698 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5699                 .f = cmd_set_bond_mon_period_parsed,
5700                 .data = (void *) 0,
5701                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5702                 .tokens = {
5703                                 (void *)&cmd_set_bond_mon_period_set,
5704                                 (void *)&cmd_set_bond_mon_period_bonding,
5705                                 (void *)&cmd_set_bond_mon_period_mon_period,
5706                                 (void *)&cmd_set_bond_mon_period_portnum,
5707                                 (void *)&cmd_set_bond_mon_period_period_ms,
5708                                 NULL
5709                 }
5710 };
5711
5712
5713
5714 struct cmd_set_bonding_agg_mode_policy_result {
5715         cmdline_fixed_string_t set;
5716         cmdline_fixed_string_t bonding;
5717         cmdline_fixed_string_t agg_mode;
5718         uint16_t port_num;
5719         cmdline_fixed_string_t policy;
5720 };
5721
5722
5723 static void
5724 cmd_set_bonding_agg_mode(void *parsed_result,
5725                 __attribute__((unused)) struct cmdline *cl,
5726                 __attribute__((unused)) void *data)
5727 {
5728         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5729         uint8_t policy = AGG_BANDWIDTH;
5730
5731         if (!strcmp(res->policy, "bandwidth"))
5732                 policy = AGG_BANDWIDTH;
5733         else if (!strcmp(res->policy, "stable"))
5734                 policy = AGG_STABLE;
5735         else if (!strcmp(res->policy, "count"))
5736                 policy = AGG_COUNT;
5737
5738         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5739 }
5740
5741
5742 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5743         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5744                                 set, "set");
5745 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5746         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5747                                 bonding, "bonding");
5748
5749 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5750         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5751                                 agg_mode, "agg_mode");
5752
5753 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5754         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5755                                 port_num, UINT16);
5756
5757 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5758         TOKEN_STRING_INITIALIZER(
5759                         struct cmd_set_bonding_balance_xmit_policy_result,
5760                 policy, "stable#bandwidth#count");
5761
5762 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5763         .f = cmd_set_bonding_agg_mode,
5764         .data = (void *) 0,
5765         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5766         .tokens = {
5767                         (void *)&cmd_set_bonding_agg_mode_set,
5768                         (void *)&cmd_set_bonding_agg_mode_bonding,
5769                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5770                         (void *)&cmd_set_bonding_agg_mode_portnum,
5771                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5772                         NULL
5773                 }
5774 };
5775
5776
5777 #endif /* RTE_LIBRTE_PMD_BOND */
5778
5779 /* *** SET FORWARDING MODE *** */
5780 struct cmd_set_fwd_mode_result {
5781         cmdline_fixed_string_t set;
5782         cmdline_fixed_string_t fwd;
5783         cmdline_fixed_string_t mode;
5784 };
5785
5786 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5787                                     __attribute__((unused)) struct cmdline *cl,
5788                                     __attribute__((unused)) void *data)
5789 {
5790         struct cmd_set_fwd_mode_result *res = parsed_result;
5791
5792         retry_enabled = 0;
5793         set_pkt_forwarding_mode(res->mode);
5794 }
5795
5796 cmdline_parse_token_string_t cmd_setfwd_set =
5797         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5798 cmdline_parse_token_string_t cmd_setfwd_fwd =
5799         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5800 cmdline_parse_token_string_t cmd_setfwd_mode =
5801         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5802                 "" /* defined at init */);
5803
5804 cmdline_parse_inst_t cmd_set_fwd_mode = {
5805         .f = cmd_set_fwd_mode_parsed,
5806         .data = NULL,
5807         .help_str = NULL, /* defined at init */
5808         .tokens = {
5809                 (void *)&cmd_setfwd_set,
5810                 (void *)&cmd_setfwd_fwd,
5811                 (void *)&cmd_setfwd_mode,
5812                 NULL,
5813         },
5814 };
5815
5816 static void cmd_set_fwd_mode_init(void)
5817 {
5818         char *modes, *c;
5819         static char token[128];
5820         static char help[256];
5821         cmdline_parse_token_string_t *token_struct;
5822
5823         modes = list_pkt_forwarding_modes();
5824         snprintf(help, sizeof(help), "set fwd %s: "
5825                 "Set packet forwarding mode", modes);
5826         cmd_set_fwd_mode.help_str = help;
5827
5828         /* string token separator is # */
5829         for (c = token; *modes != '\0'; modes++)
5830                 if (*modes == '|')
5831                         *c++ = '#';
5832                 else
5833                         *c++ = *modes;
5834         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5835         token_struct->string_data.str = token;
5836 }
5837
5838 /* *** SET RETRY FORWARDING MODE *** */
5839 struct cmd_set_fwd_retry_mode_result {
5840         cmdline_fixed_string_t set;
5841         cmdline_fixed_string_t fwd;
5842         cmdline_fixed_string_t mode;
5843         cmdline_fixed_string_t retry;
5844 };
5845
5846 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5847                             __attribute__((unused)) struct cmdline *cl,
5848                             __attribute__((unused)) void *data)
5849 {
5850         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5851
5852         retry_enabled = 1;
5853         set_pkt_forwarding_mode(res->mode);
5854 }
5855
5856 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5857         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5858                         set, "set");
5859 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5860         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5861                         fwd, "fwd");
5862 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5863         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5864                         mode,
5865                 "" /* defined at init */);
5866 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5867         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5868                         retry, "retry");
5869
5870 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5871         .f = cmd_set_fwd_retry_mode_parsed,
5872         .data = NULL,
5873         .help_str = NULL, /* defined at init */
5874         .tokens = {
5875                 (void *)&cmd_setfwd_retry_set,
5876                 (void *)&cmd_setfwd_retry_fwd,
5877                 (void *)&cmd_setfwd_retry_mode,
5878                 (void *)&cmd_setfwd_retry_retry,
5879                 NULL,
5880         },
5881 };
5882
5883 static void cmd_set_fwd_retry_mode_init(void)
5884 {
5885         char *modes, *c;
5886         static char token[128];
5887         static char help[256];
5888         cmdline_parse_token_string_t *token_struct;
5889
5890         modes = list_pkt_forwarding_retry_modes();
5891         snprintf(help, sizeof(help), "set fwd %s retry: "
5892                 "Set packet forwarding mode with retry", modes);
5893         cmd_set_fwd_retry_mode.help_str = help;
5894
5895         /* string token separator is # */
5896         for (c = token; *modes != '\0'; modes++)
5897                 if (*modes == '|')
5898                         *c++ = '#';
5899                 else
5900                         *c++ = *modes;
5901         token_struct = (cmdline_parse_token_string_t *)
5902                 cmd_set_fwd_retry_mode.tokens[2];
5903         token_struct->string_data.str = token;
5904 }
5905
5906 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5907 struct cmd_set_burst_tx_retry_result {
5908         cmdline_fixed_string_t set;
5909         cmdline_fixed_string_t burst;
5910         cmdline_fixed_string_t tx;
5911         cmdline_fixed_string_t delay;
5912         uint32_t time;
5913         cmdline_fixed_string_t retry;
5914         uint32_t retry_num;
5915 };
5916
5917 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5918                                         __attribute__((unused)) struct cmdline *cl,
5919                                         __attribute__((unused)) void *data)
5920 {
5921         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5922
5923         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5924                 && !strcmp(res->tx, "tx")) {
5925                 if (!strcmp(res->delay, "delay"))
5926                         burst_tx_delay_time = res->time;
5927                 if (!strcmp(res->retry, "retry"))
5928                         burst_tx_retry_num = res->retry_num;
5929         }
5930
5931 }
5932
5933 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5934         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5935 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5936         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5937                                  "burst");
5938 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5939         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5940 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5941         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5942 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5943         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5944 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5945         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5946 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5947         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5948
5949 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5950         .f = cmd_set_burst_tx_retry_parsed,
5951         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5952         .tokens = {
5953                 (void *)&cmd_set_burst_tx_retry_set,
5954                 (void *)&cmd_set_burst_tx_retry_burst,
5955                 (void *)&cmd_set_burst_tx_retry_tx,
5956                 (void *)&cmd_set_burst_tx_retry_delay,
5957                 (void *)&cmd_set_burst_tx_retry_time,
5958                 (void *)&cmd_set_burst_tx_retry_retry,
5959                 (void *)&cmd_set_burst_tx_retry_retry_num,
5960                 NULL,
5961         },
5962 };
5963
5964 /* *** SET PROMISC MODE *** */
5965 struct cmd_set_promisc_mode_result {
5966         cmdline_fixed_string_t set;
5967         cmdline_fixed_string_t promisc;
5968         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5969         uint16_t port_num;               /* valid if "allports" argument == 0 */
5970         cmdline_fixed_string_t mode;
5971 };
5972
5973 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5974                                         __attribute__((unused)) struct cmdline *cl,
5975                                         void *allports)
5976 {
5977         struct cmd_set_promisc_mode_result *res = parsed_result;
5978         int enable;
5979         portid_t i;
5980
5981         if (!strcmp(res->mode, "on"))
5982                 enable = 1;
5983         else
5984                 enable = 0;
5985
5986         /* all ports */
5987         if (allports) {
5988                 RTE_ETH_FOREACH_DEV(i) {
5989                         if (enable)
5990                                 rte_eth_promiscuous_enable(i);
5991                         else
5992                                 rte_eth_promiscuous_disable(i);
5993                 }
5994         }
5995         else {
5996                 if (enable)
5997                         rte_eth_promiscuous_enable(res->port_num);
5998                 else
5999                         rte_eth_promiscuous_disable(res->port_num);
6000         }
6001 }
6002
6003 cmdline_parse_token_string_t cmd_setpromisc_set =
6004         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6005 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6006         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6007                                  "promisc");
6008 cmdline_parse_token_string_t cmd_setpromisc_portall =
6009         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6010                                  "all");
6011 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6012         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6013                               UINT16);
6014 cmdline_parse_token_string_t cmd_setpromisc_mode =
6015         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6016                                  "on#off");
6017
6018 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6019         .f = cmd_set_promisc_mode_parsed,
6020         .data = (void *)1,
6021         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6022         .tokens = {
6023                 (void *)&cmd_setpromisc_set,
6024                 (void *)&cmd_setpromisc_promisc,
6025                 (void *)&cmd_setpromisc_portall,
6026                 (void *)&cmd_setpromisc_mode,
6027                 NULL,
6028         },
6029 };
6030
6031 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6032         .f = cmd_set_promisc_mode_parsed,
6033         .data = (void *)0,
6034         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6035         .tokens = {
6036                 (void *)&cmd_setpromisc_set,
6037                 (void *)&cmd_setpromisc_promisc,
6038                 (void *)&cmd_setpromisc_portnum,
6039                 (void *)&cmd_setpromisc_mode,
6040                 NULL,
6041         },
6042 };
6043
6044 /* *** SET ALLMULTI MODE *** */
6045 struct cmd_set_allmulti_mode_result {
6046         cmdline_fixed_string_t set;
6047         cmdline_fixed_string_t allmulti;
6048         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6049         uint16_t port_num;               /* valid if "allports" argument == 0 */
6050         cmdline_fixed_string_t mode;
6051 };
6052
6053 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6054                                         __attribute__((unused)) struct cmdline *cl,
6055                                         void *allports)
6056 {
6057         struct cmd_set_allmulti_mode_result *res = parsed_result;
6058         int enable;
6059         portid_t i;
6060
6061         if (!strcmp(res->mode, "on"))
6062                 enable = 1;
6063         else
6064                 enable = 0;
6065
6066         /* all ports */
6067         if (allports) {
6068                 RTE_ETH_FOREACH_DEV(i) {
6069                         if (enable)
6070                                 rte_eth_allmulticast_enable(i);
6071                         else
6072                                 rte_eth_allmulticast_disable(i);
6073                 }
6074         }
6075         else {
6076                 if (enable)
6077                         rte_eth_allmulticast_enable(res->port_num);
6078                 else
6079                         rte_eth_allmulticast_disable(res->port_num);
6080         }
6081 }
6082
6083 cmdline_parse_token_string_t cmd_setallmulti_set =
6084         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6085 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6086         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6087                                  "allmulti");
6088 cmdline_parse_token_string_t cmd_setallmulti_portall =
6089         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6090                                  "all");
6091 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6092         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6093                               UINT16);
6094 cmdline_parse_token_string_t cmd_setallmulti_mode =
6095         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6096                                  "on#off");
6097
6098 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6099         .f = cmd_set_allmulti_mode_parsed,
6100         .data = (void *)1,
6101         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6102         .tokens = {
6103                 (void *)&cmd_setallmulti_set,
6104                 (void *)&cmd_setallmulti_allmulti,
6105                 (void *)&cmd_setallmulti_portall,
6106                 (void *)&cmd_setallmulti_mode,
6107                 NULL,
6108         },
6109 };
6110
6111 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6112         .f = cmd_set_allmulti_mode_parsed,
6113         .data = (void *)0,
6114         .help_str = "set allmulti <port_id> on|off: "
6115                 "Set allmulti mode on port_id",
6116         .tokens = {
6117                 (void *)&cmd_setallmulti_set,
6118                 (void *)&cmd_setallmulti_allmulti,
6119                 (void *)&cmd_setallmulti_portnum,
6120                 (void *)&cmd_setallmulti_mode,
6121                 NULL,
6122         },
6123 };
6124
6125 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6126 struct cmd_link_flow_ctrl_set_result {
6127         cmdline_fixed_string_t set;
6128         cmdline_fixed_string_t flow_ctrl;
6129         cmdline_fixed_string_t rx;
6130         cmdline_fixed_string_t rx_lfc_mode;
6131         cmdline_fixed_string_t tx;
6132         cmdline_fixed_string_t tx_lfc_mode;
6133         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6134         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6135         cmdline_fixed_string_t autoneg_str;
6136         cmdline_fixed_string_t autoneg;
6137         cmdline_fixed_string_t hw_str;
6138         uint32_t high_water;
6139         cmdline_fixed_string_t lw_str;
6140         uint32_t low_water;
6141         cmdline_fixed_string_t pt_str;
6142         uint16_t pause_time;
6143         cmdline_fixed_string_t xon_str;
6144         uint16_t send_xon;
6145         portid_t port_id;
6146 };
6147
6148 cmdline_parse_token_string_t cmd_lfc_set_set =
6149         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6150                                 set, "set");
6151 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6152         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6153                                 flow_ctrl, "flow_ctrl");
6154 cmdline_parse_token_string_t cmd_lfc_set_rx =
6155         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6156                                 rx, "rx");
6157 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6158         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6159                                 rx_lfc_mode, "on#off");
6160 cmdline_parse_token_string_t cmd_lfc_set_tx =
6161         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6162                                 tx, "tx");
6163 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6164         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6165                                 tx_lfc_mode, "on#off");
6166 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6167         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6168                                 hw_str, "high_water");
6169 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6170         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6171                                 high_water, UINT32);
6172 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6173         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6174                                 lw_str, "low_water");
6175 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6176         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6177                                 low_water, UINT32);
6178 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6179         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6180                                 pt_str, "pause_time");
6181 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6182         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6183                                 pause_time, UINT16);
6184 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6185         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6186                                 xon_str, "send_xon");
6187 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6188         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6189                                 send_xon, UINT16);
6190 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6191         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6192                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6193 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6194         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6195                                 mac_ctrl_frame_fwd_mode, "on#off");
6196 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6197         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6198                                 autoneg_str, "autoneg");
6199 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6200         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6201                                 autoneg, "on#off");
6202 cmdline_parse_token_num_t cmd_lfc_set_portid =
6203         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6204                                 port_id, UINT16);
6205
6206 /* forward declaration */
6207 static void
6208 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6209                               void *data);
6210
6211 cmdline_parse_inst_t cmd_link_flow_control_set = {
6212         .f = cmd_link_flow_ctrl_set_parsed,
6213         .data = NULL,
6214         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6215                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6216                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6217         .tokens = {
6218                 (void *)&cmd_lfc_set_set,
6219                 (void *)&cmd_lfc_set_flow_ctrl,
6220                 (void *)&cmd_lfc_set_rx,
6221                 (void *)&cmd_lfc_set_rx_mode,
6222                 (void *)&cmd_lfc_set_tx,
6223                 (void *)&cmd_lfc_set_tx_mode,
6224                 (void *)&cmd_lfc_set_high_water,
6225                 (void *)&cmd_lfc_set_low_water,
6226                 (void *)&cmd_lfc_set_pause_time,
6227                 (void *)&cmd_lfc_set_send_xon,
6228                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6229                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6230                 (void *)&cmd_lfc_set_autoneg_str,
6231                 (void *)&cmd_lfc_set_autoneg,
6232                 (void *)&cmd_lfc_set_portid,
6233                 NULL,
6234         },
6235 };
6236
6237 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6238         .f = cmd_link_flow_ctrl_set_parsed,
6239         .data = (void *)&cmd_link_flow_control_set_rx,
6240         .help_str = "set flow_ctrl rx on|off <port_id>: "
6241                 "Change rx flow control parameter",
6242         .tokens = {
6243                 (void *)&cmd_lfc_set_set,
6244                 (void *)&cmd_lfc_set_flow_ctrl,
6245                 (void *)&cmd_lfc_set_rx,
6246                 (void *)&cmd_lfc_set_rx_mode,
6247                 (void *)&cmd_lfc_set_portid,
6248                 NULL,
6249         },
6250 };
6251
6252 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6253         .f = cmd_link_flow_ctrl_set_parsed,
6254         .data = (void *)&cmd_link_flow_control_set_tx,
6255         .help_str = "set flow_ctrl tx on|off <port_id>: "
6256                 "Change tx flow control parameter",
6257         .tokens = {
6258                 (void *)&cmd_lfc_set_set,
6259                 (void *)&cmd_lfc_set_flow_ctrl,
6260                 (void *)&cmd_lfc_set_tx,
6261                 (void *)&cmd_lfc_set_tx_mode,
6262                 (void *)&cmd_lfc_set_portid,
6263                 NULL,
6264         },
6265 };
6266
6267 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6268         .f = cmd_link_flow_ctrl_set_parsed,
6269         .data = (void *)&cmd_link_flow_control_set_hw,
6270         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6271                 "Change high water flow control parameter",
6272         .tokens = {
6273                 (void *)&cmd_lfc_set_set,
6274                 (void *)&cmd_lfc_set_flow_ctrl,
6275                 (void *)&cmd_lfc_set_high_water_str,
6276                 (void *)&cmd_lfc_set_high_water,
6277                 (void *)&cmd_lfc_set_portid,
6278                 NULL,
6279         },
6280 };
6281
6282 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6283         .f = cmd_link_flow_ctrl_set_parsed,
6284         .data = (void *)&cmd_link_flow_control_set_lw,
6285         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6286                 "Change low water flow control parameter",
6287         .tokens = {
6288                 (void *)&cmd_lfc_set_set,
6289                 (void *)&cmd_lfc_set_flow_ctrl,
6290                 (void *)&cmd_lfc_set_low_water_str,
6291                 (void *)&cmd_lfc_set_low_water,
6292                 (void *)&cmd_lfc_set_portid,
6293                 NULL,
6294         },
6295 };
6296
6297 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6298         .f = cmd_link_flow_ctrl_set_parsed,
6299         .data = (void *)&cmd_link_flow_control_set_pt,
6300         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6301                 "Change pause time flow control parameter",
6302         .tokens = {
6303                 (void *)&cmd_lfc_set_set,
6304                 (void *)&cmd_lfc_set_flow_ctrl,
6305                 (void *)&cmd_lfc_set_pause_time_str,
6306                 (void *)&cmd_lfc_set_pause_time,
6307                 (void *)&cmd_lfc_set_portid,
6308                 NULL,
6309         },
6310 };
6311
6312 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6313         .f = cmd_link_flow_ctrl_set_parsed,
6314         .data = (void *)&cmd_link_flow_control_set_xon,
6315         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6316                 "Change send_xon flow control parameter",
6317         .tokens = {
6318                 (void *)&cmd_lfc_set_set,
6319                 (void *)&cmd_lfc_set_flow_ctrl,
6320                 (void *)&cmd_lfc_set_send_xon_str,
6321                 (void *)&cmd_lfc_set_send_xon,
6322                 (void *)&cmd_lfc_set_portid,
6323                 NULL,
6324         },
6325 };
6326
6327 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6328         .f = cmd_link_flow_ctrl_set_parsed,
6329         .data = (void *)&cmd_link_flow_control_set_macfwd,
6330         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6331                 "Change mac ctrl fwd flow control parameter",
6332         .tokens = {
6333                 (void *)&cmd_lfc_set_set,
6334                 (void *)&cmd_lfc_set_flow_ctrl,
6335                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6336                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6337                 (void *)&cmd_lfc_set_portid,
6338                 NULL,
6339         },
6340 };
6341
6342 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6343         .f = cmd_link_flow_ctrl_set_parsed,
6344         .data = (void *)&cmd_link_flow_control_set_autoneg,
6345         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6346                 "Change autoneg flow control parameter",
6347         .tokens = {
6348                 (void *)&cmd_lfc_set_set,
6349                 (void *)&cmd_lfc_set_flow_ctrl,
6350                 (void *)&cmd_lfc_set_autoneg_str,
6351                 (void *)&cmd_lfc_set_autoneg,
6352                 (void *)&cmd_lfc_set_portid,
6353                 NULL,
6354         },
6355 };
6356
6357 static void
6358 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6359                               __attribute__((unused)) struct cmdline *cl,
6360                               void *data)
6361 {
6362         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6363         cmdline_parse_inst_t *cmd = data;
6364         struct rte_eth_fc_conf fc_conf;
6365         int rx_fc_en = 0;
6366         int tx_fc_en = 0;
6367         int ret;
6368
6369         /*
6370          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6371          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6372          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6373          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6374          */
6375         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6376                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6377         };
6378
6379         /* Partial command line, retrieve current configuration */
6380         if (cmd) {
6381                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6382                 if (ret != 0) {
6383                         printf("cannot get current flow ctrl parameters, return"
6384                                "code = %d\n", ret);
6385                         return;
6386                 }
6387
6388                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6389                     (fc_conf.mode == RTE_FC_FULL))
6390                         rx_fc_en = 1;
6391                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6392                     (fc_conf.mode == RTE_FC_FULL))
6393                         tx_fc_en = 1;
6394         }
6395
6396         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6397                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6398
6399         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6400                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6401
6402         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6403
6404         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6405                 fc_conf.high_water = res->high_water;
6406
6407         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6408                 fc_conf.low_water = res->low_water;
6409
6410         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6411                 fc_conf.pause_time = res->pause_time;
6412
6413         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6414                 fc_conf.send_xon = res->send_xon;
6415
6416         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6417                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6418                         fc_conf.mac_ctrl_frame_fwd = 1;
6419                 else
6420                         fc_conf.mac_ctrl_frame_fwd = 0;
6421         }
6422
6423         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6424                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6425
6426         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6427         if (ret != 0)
6428                 printf("bad flow contrl parameter, return code = %d \n", ret);
6429 }
6430
6431 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6432 struct cmd_priority_flow_ctrl_set_result {
6433         cmdline_fixed_string_t set;
6434         cmdline_fixed_string_t pfc_ctrl;
6435         cmdline_fixed_string_t rx;
6436         cmdline_fixed_string_t rx_pfc_mode;
6437         cmdline_fixed_string_t tx;
6438         cmdline_fixed_string_t tx_pfc_mode;
6439         uint32_t high_water;
6440         uint32_t low_water;
6441         uint16_t pause_time;
6442         uint8_t  priority;
6443         portid_t port_id;
6444 };
6445
6446 static void
6447 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6448                        __attribute__((unused)) struct cmdline *cl,
6449                        __attribute__((unused)) void *data)
6450 {
6451         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6452         struct rte_eth_pfc_conf pfc_conf;
6453         int rx_fc_enable, tx_fc_enable;
6454         int ret;
6455
6456         /*
6457          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6458          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6459          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6460          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6461          */
6462         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6463                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6464         };
6465
6466         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6467         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6468         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6469         pfc_conf.fc.high_water = res->high_water;
6470         pfc_conf.fc.low_water  = res->low_water;
6471         pfc_conf.fc.pause_time = res->pause_time;
6472         pfc_conf.priority      = res->priority;
6473
6474         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6475         if (ret != 0)
6476                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6477 }
6478
6479 cmdline_parse_token_string_t cmd_pfc_set_set =
6480         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6481                                 set, "set");
6482 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6483         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6484                                 pfc_ctrl, "pfc_ctrl");
6485 cmdline_parse_token_string_t cmd_pfc_set_rx =
6486         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6487                                 rx, "rx");
6488 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6489         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6490                                 rx_pfc_mode, "on#off");
6491 cmdline_parse_token_string_t cmd_pfc_set_tx =
6492         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6493                                 tx, "tx");
6494 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6495         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6496                                 tx_pfc_mode, "on#off");
6497 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6498         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6499                                 high_water, UINT32);
6500 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6501         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6502                                 low_water, UINT32);
6503 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6504         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6505                                 pause_time, UINT16);
6506 cmdline_parse_token_num_t cmd_pfc_set_priority =
6507         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6508                                 priority, UINT8);
6509 cmdline_parse_token_num_t cmd_pfc_set_portid =
6510         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6511                                 port_id, UINT16);
6512
6513 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6514         .f = cmd_priority_flow_ctrl_set_parsed,
6515         .data = NULL,
6516         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6517                 "<pause_time> <priority> <port_id>: "
6518                 "Configure the Ethernet priority flow control",
6519         .tokens = {
6520                 (void *)&cmd_pfc_set_set,
6521                 (void *)&cmd_pfc_set_flow_ctrl,
6522                 (void *)&cmd_pfc_set_rx,
6523                 (void *)&cmd_pfc_set_rx_mode,
6524                 (void *)&cmd_pfc_set_tx,
6525                 (void *)&cmd_pfc_set_tx_mode,
6526                 (void *)&cmd_pfc_set_high_water,
6527                 (void *)&cmd_pfc_set_low_water,
6528                 (void *)&cmd_pfc_set_pause_time,
6529                 (void *)&cmd_pfc_set_priority,
6530                 (void *)&cmd_pfc_set_portid,
6531                 NULL,
6532         },
6533 };
6534
6535 /* *** RESET CONFIGURATION *** */
6536 struct cmd_reset_result {
6537         cmdline_fixed_string_t reset;
6538         cmdline_fixed_string_t def;
6539 };
6540
6541 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6542                              struct cmdline *cl,
6543                              __attribute__((unused)) void *data)
6544 {
6545         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6546         set_def_fwd_config();
6547 }
6548
6549 cmdline_parse_token_string_t cmd_reset_set =
6550         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6551 cmdline_parse_token_string_t cmd_reset_def =
6552         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6553                                  "default");
6554
6555 cmdline_parse_inst_t cmd_reset = {
6556         .f = cmd_reset_parsed,
6557         .data = NULL,
6558         .help_str = "set default: Reset default forwarding configuration",
6559         .tokens = {
6560                 (void *)&cmd_reset_set,
6561                 (void *)&cmd_reset_def,
6562                 NULL,
6563         },
6564 };
6565
6566 /* *** START FORWARDING *** */
6567 struct cmd_start_result {
6568         cmdline_fixed_string_t start;
6569 };
6570
6571 cmdline_parse_token_string_t cmd_start_start =
6572         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6573
6574 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6575                              __attribute__((unused)) struct cmdline *cl,
6576                              __attribute__((unused)) void *data)
6577 {
6578         start_packet_forwarding(0);
6579 }
6580
6581 cmdline_parse_inst_t cmd_start = {
6582         .f = cmd_start_parsed,
6583         .data = NULL,
6584         .help_str = "start: Start packet forwarding",
6585         .tokens = {
6586                 (void *)&cmd_start_start,
6587                 NULL,
6588         },
6589 };
6590
6591 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6592 struct cmd_start_tx_first_result {
6593         cmdline_fixed_string_t start;
6594         cmdline_fixed_string_t tx_first;
6595 };
6596
6597 static void
6598 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6599                           __attribute__((unused)) struct cmdline *cl,
6600                           __attribute__((unused)) void *data)
6601 {
6602         start_packet_forwarding(1);
6603 }
6604
6605 cmdline_parse_token_string_t cmd_start_tx_first_start =
6606         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6607                                  "start");
6608 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6609         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6610                                  tx_first, "tx_first");
6611
6612 cmdline_parse_inst_t cmd_start_tx_first = {
6613         .f = cmd_start_tx_first_parsed,
6614         .data = NULL,
6615         .help_str = "start tx_first: Start packet forwarding, "
6616                 "after sending 1 burst of packets",
6617         .tokens = {
6618                 (void *)&cmd_start_tx_first_start,
6619                 (void *)&cmd_start_tx_first_tx_first,
6620                 NULL,
6621         },
6622 };
6623
6624 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6625 struct cmd_start_tx_first_n_result {
6626         cmdline_fixed_string_t start;
6627         cmdline_fixed_string_t tx_first;
6628         uint32_t tx_num;
6629 };
6630
6631 static void
6632 cmd_start_tx_first_n_parsed(void *parsed_result,
6633                           __attribute__((unused)) struct cmdline *cl,
6634                           __attribute__((unused)) void *data)
6635 {
6636         struct cmd_start_tx_first_n_result *res = parsed_result;
6637
6638         start_packet_forwarding(res->tx_num);
6639 }
6640
6641 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6642         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6643                         start, "start");
6644 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6645         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6646                         tx_first, "tx_first");
6647 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6648         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6649                         tx_num, UINT32);
6650
6651 cmdline_parse_inst_t cmd_start_tx_first_n = {
6652         .f = cmd_start_tx_first_n_parsed,
6653         .data = NULL,
6654         .help_str = "start tx_first <num>: "
6655                 "packet forwarding, after sending <num> bursts of packets",
6656         .tokens = {
6657                 (void *)&cmd_start_tx_first_n_start,
6658                 (void *)&cmd_start_tx_first_n_tx_first,
6659                 (void *)&cmd_start_tx_first_n_tx_num,
6660                 NULL,
6661         },
6662 };
6663
6664 /* *** SET LINK UP *** */
6665 struct cmd_set_link_up_result {
6666         cmdline_fixed_string_t set;
6667         cmdline_fixed_string_t link_up;
6668         cmdline_fixed_string_t port;
6669         portid_t port_id;
6670 };
6671
6672 cmdline_parse_token_string_t cmd_set_link_up_set =
6673         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6674 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6675         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6676                                 "link-up");
6677 cmdline_parse_token_string_t cmd_set_link_up_port =
6678         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6679 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6680         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6681
6682 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6683                              __attribute__((unused)) struct cmdline *cl,
6684                              __attribute__((unused)) void *data)
6685 {
6686         struct cmd_set_link_up_result *res = parsed_result;
6687         dev_set_link_up(res->port_id);
6688 }
6689
6690 cmdline_parse_inst_t cmd_set_link_up = {
6691         .f = cmd_set_link_up_parsed,
6692         .data = NULL,
6693         .help_str = "set link-up port <port id>",
6694         .tokens = {
6695                 (void *)&cmd_set_link_up_set,
6696                 (void *)&cmd_set_link_up_link_up,
6697                 (void *)&cmd_set_link_up_port,
6698                 (void *)&cmd_set_link_up_port_id,
6699                 NULL,
6700         },
6701 };
6702
6703 /* *** SET LINK DOWN *** */
6704 struct cmd_set_link_down_result {
6705         cmdline_fixed_string_t set;
6706         cmdline_fixed_string_t link_down;
6707         cmdline_fixed_string_t port;
6708         portid_t port_id;
6709 };
6710
6711 cmdline_parse_token_string_t cmd_set_link_down_set =
6712         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6713 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6714         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6715                                 "link-down");
6716 cmdline_parse_token_string_t cmd_set_link_down_port =
6717         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6718 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6719         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6720
6721 static void cmd_set_link_down_parsed(
6722                                 __attribute__((unused)) void *parsed_result,
6723                                 __attribute__((unused)) struct cmdline *cl,
6724                                 __attribute__((unused)) void *data)
6725 {
6726         struct cmd_set_link_down_result *res = parsed_result;
6727         dev_set_link_down(res->port_id);
6728 }
6729
6730 cmdline_parse_inst_t cmd_set_link_down = {
6731         .f = cmd_set_link_down_parsed,
6732         .data = NULL,
6733         .help_str = "set link-down port <port id>",
6734         .tokens = {
6735                 (void *)&cmd_set_link_down_set,
6736                 (void *)&cmd_set_link_down_link_down,
6737                 (void *)&cmd_set_link_down_port,
6738                 (void *)&cmd_set_link_down_port_id,
6739                 NULL,
6740         },
6741 };
6742
6743 /* *** SHOW CFG *** */
6744 struct cmd_showcfg_result {
6745         cmdline_fixed_string_t show;
6746         cmdline_fixed_string_t cfg;
6747         cmdline_fixed_string_t what;
6748 };
6749
6750 static void cmd_showcfg_parsed(void *parsed_result,
6751                                __attribute__((unused)) struct cmdline *cl,
6752                                __attribute__((unused)) void *data)
6753 {
6754         struct cmd_showcfg_result *res = parsed_result;
6755         if (!strcmp(res->what, "rxtx"))
6756                 rxtx_config_display();
6757         else if (!strcmp(res->what, "cores"))
6758                 fwd_lcores_config_display();
6759         else if (!strcmp(res->what, "fwd"))
6760                 pkt_fwd_config_display(&cur_fwd_config);
6761         else if (!strcmp(res->what, "txpkts"))
6762                 show_tx_pkt_segments();
6763 }
6764
6765 cmdline_parse_token_string_t cmd_showcfg_show =
6766         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6767 cmdline_parse_token_string_t cmd_showcfg_port =
6768         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6769 cmdline_parse_token_string_t cmd_showcfg_what =
6770         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6771                                  "rxtx#cores#fwd#txpkts");
6772
6773 cmdline_parse_inst_t cmd_showcfg = {
6774         .f = cmd_showcfg_parsed,
6775         .data = NULL,
6776         .help_str = "show config rxtx|cores|fwd|txpkts",
6777         .tokens = {
6778                 (void *)&cmd_showcfg_show,
6779                 (void *)&cmd_showcfg_port,
6780                 (void *)&cmd_showcfg_what,
6781                 NULL,
6782         },
6783 };
6784
6785 /* *** SHOW ALL PORT INFO *** */
6786 struct cmd_showportall_result {
6787         cmdline_fixed_string_t show;
6788         cmdline_fixed_string_t port;
6789         cmdline_fixed_string_t what;
6790         cmdline_fixed_string_t all;
6791 };
6792
6793 static void cmd_showportall_parsed(void *parsed_result,
6794                                 __attribute__((unused)) struct cmdline *cl,
6795                                 __attribute__((unused)) void *data)
6796 {
6797         portid_t i;
6798
6799         struct cmd_showportall_result *res = parsed_result;
6800         if (!strcmp(res->show, "clear")) {
6801                 if (!strcmp(res->what, "stats"))
6802                         RTE_ETH_FOREACH_DEV(i)
6803                                 nic_stats_clear(i);
6804                 else if (!strcmp(res->what, "xstats"))
6805                         RTE_ETH_FOREACH_DEV(i)
6806                                 nic_xstats_clear(i);
6807         } else if (!strcmp(res->what, "info"))
6808                 RTE_ETH_FOREACH_DEV(i)
6809                         port_infos_display(i);
6810         else if (!strcmp(res->what, "stats"))
6811                 RTE_ETH_FOREACH_DEV(i)
6812                         nic_stats_display(i);
6813         else if (!strcmp(res->what, "xstats"))
6814                 RTE_ETH_FOREACH_DEV(i)
6815                         nic_xstats_display(i);
6816         else if (!strcmp(res->what, "fdir"))
6817                 RTE_ETH_FOREACH_DEV(i)
6818                         fdir_get_infos(i);
6819         else if (!strcmp(res->what, "stat_qmap"))
6820                 RTE_ETH_FOREACH_DEV(i)
6821                         nic_stats_mapping_display(i);
6822         else if (!strcmp(res->what, "dcb_tc"))
6823                 RTE_ETH_FOREACH_DEV(i)
6824                         port_dcb_info_display(i);
6825         else if (!strcmp(res->what, "cap"))
6826                 RTE_ETH_FOREACH_DEV(i)
6827                         port_offload_cap_display(i);
6828 }
6829
6830 cmdline_parse_token_string_t cmd_showportall_show =
6831         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6832                                  "show#clear");
6833 cmdline_parse_token_string_t cmd_showportall_port =
6834         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6835 cmdline_parse_token_string_t cmd_showportall_what =
6836         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6837                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6838 cmdline_parse_token_string_t cmd_showportall_all =
6839         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6840 cmdline_parse_inst_t cmd_showportall = {
6841         .f = cmd_showportall_parsed,
6842         .data = NULL,
6843         .help_str = "show|clear port "
6844                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6845         .tokens = {
6846                 (void *)&cmd_showportall_show,
6847                 (void *)&cmd_showportall_port,
6848                 (void *)&cmd_showportall_what,
6849                 (void *)&cmd_showportall_all,
6850                 NULL,
6851         },
6852 };
6853
6854 /* *** SHOW PORT INFO *** */
6855 struct cmd_showport_result {
6856         cmdline_fixed_string_t show;
6857         cmdline_fixed_string_t port;
6858         cmdline_fixed_string_t what;
6859         uint16_t portnum;
6860 };
6861
6862 static void cmd_showport_parsed(void *parsed_result,
6863                                 __attribute__((unused)) struct cmdline *cl,
6864                                 __attribute__((unused)) void *data)
6865 {
6866         struct cmd_showport_result *res = parsed_result;
6867         if (!strcmp(res->show, "clear")) {
6868                 if (!strcmp(res->what, "stats"))
6869                         nic_stats_clear(res->portnum);
6870                 else if (!strcmp(res->what, "xstats"))
6871                         nic_xstats_clear(res->portnum);
6872         } else if (!strcmp(res->what, "info"))
6873                 port_infos_display(res->portnum);
6874         else if (!strcmp(res->what, "stats"))
6875                 nic_stats_display(res->portnum);
6876         else if (!strcmp(res->what, "xstats"))
6877                 nic_xstats_display(res->portnum);
6878         else if (!strcmp(res->what, "fdir"))
6879                  fdir_get_infos(res->portnum);
6880         else if (!strcmp(res->what, "stat_qmap"))
6881                 nic_stats_mapping_display(res->portnum);
6882         else if (!strcmp(res->what, "dcb_tc"))
6883                 port_dcb_info_display(res->portnum);
6884         else if (!strcmp(res->what, "cap"))
6885                 port_offload_cap_display(res->portnum);
6886 }
6887
6888 cmdline_parse_token_string_t cmd_showport_show =
6889         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6890                                  "show#clear");
6891 cmdline_parse_token_string_t cmd_showport_port =
6892         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6893 cmdline_parse_token_string_t cmd_showport_what =
6894         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6895                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6896 cmdline_parse_token_num_t cmd_showport_portnum =
6897         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6898
6899 cmdline_parse_inst_t cmd_showport = {
6900         .f = cmd_showport_parsed,
6901         .data = NULL,
6902         .help_str = "show|clear port "
6903                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6904                 "<port_id>",
6905         .tokens = {
6906                 (void *)&cmd_showport_show,
6907                 (void *)&cmd_showport_port,
6908                 (void *)&cmd_showport_what,
6909                 (void *)&cmd_showport_portnum,
6910                 NULL,
6911         },
6912 };
6913
6914 /* *** SHOW QUEUE INFO *** */
6915 struct cmd_showqueue_result {
6916         cmdline_fixed_string_t show;
6917         cmdline_fixed_string_t type;
6918         cmdline_fixed_string_t what;
6919         uint16_t portnum;
6920         uint16_t queuenum;
6921 };
6922
6923 static void
6924 cmd_showqueue_parsed(void *parsed_result,
6925         __attribute__((unused)) struct cmdline *cl,
6926         __attribute__((unused)) void *data)
6927 {
6928         struct cmd_showqueue_result *res = parsed_result;
6929
6930         if (!strcmp(res->type, "rxq"))
6931                 rx_queue_infos_display(res->portnum, res->queuenum);
6932         else if (!strcmp(res->type, "txq"))
6933                 tx_queue_infos_display(res->portnum, res->queuenum);
6934 }
6935
6936 cmdline_parse_token_string_t cmd_showqueue_show =
6937         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6938 cmdline_parse_token_string_t cmd_showqueue_type =
6939         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6940 cmdline_parse_token_string_t cmd_showqueue_what =
6941         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6942 cmdline_parse_token_num_t cmd_showqueue_portnum =
6943         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6944 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6945         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6946
6947 cmdline_parse_inst_t cmd_showqueue = {
6948         .f = cmd_showqueue_parsed,
6949         .data = NULL,
6950         .help_str = "show rxq|txq info <port_id> <queue_id>",
6951         .tokens = {
6952                 (void *)&cmd_showqueue_show,
6953                 (void *)&cmd_showqueue_type,
6954                 (void *)&cmd_showqueue_what,
6955                 (void *)&cmd_showqueue_portnum,
6956                 (void *)&cmd_showqueue_queuenum,
6957                 NULL,
6958         },
6959 };
6960
6961 /* *** READ PORT REGISTER *** */
6962 struct cmd_read_reg_result {
6963         cmdline_fixed_string_t read;
6964         cmdline_fixed_string_t reg;
6965         portid_t port_id;
6966         uint32_t reg_off;
6967 };
6968
6969 static void
6970 cmd_read_reg_parsed(void *parsed_result,
6971                     __attribute__((unused)) struct cmdline *cl,
6972                     __attribute__((unused)) void *data)
6973 {
6974         struct cmd_read_reg_result *res = parsed_result;
6975         port_reg_display(res->port_id, res->reg_off);
6976 }
6977
6978 cmdline_parse_token_string_t cmd_read_reg_read =
6979         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6980 cmdline_parse_token_string_t cmd_read_reg_reg =
6981         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6982 cmdline_parse_token_num_t cmd_read_reg_port_id =
6983         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6984 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6985         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6986
6987 cmdline_parse_inst_t cmd_read_reg = {
6988         .f = cmd_read_reg_parsed,
6989         .data = NULL,
6990         .help_str = "read reg <port_id> <reg_off>",
6991         .tokens = {
6992                 (void *)&cmd_read_reg_read,
6993                 (void *)&cmd_read_reg_reg,
6994                 (void *)&cmd_read_reg_port_id,
6995                 (void *)&cmd_read_reg_reg_off,
6996                 NULL,
6997         },
6998 };
6999
7000 /* *** READ PORT REGISTER BIT FIELD *** */
7001 struct cmd_read_reg_bit_field_result {
7002         cmdline_fixed_string_t read;
7003         cmdline_fixed_string_t regfield;
7004         portid_t port_id;
7005         uint32_t reg_off;
7006         uint8_t bit1_pos;
7007         uint8_t bit2_pos;
7008 };
7009
7010 static void
7011 cmd_read_reg_bit_field_parsed(void *parsed_result,
7012                               __attribute__((unused)) struct cmdline *cl,
7013                               __attribute__((unused)) void *data)
7014 {
7015         struct cmd_read_reg_bit_field_result *res = parsed_result;
7016         port_reg_bit_field_display(res->port_id, res->reg_off,
7017                                    res->bit1_pos, res->bit2_pos);
7018 }
7019
7020 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7021         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7022                                  "read");
7023 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7024         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7025                                  regfield, "regfield");
7026 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7027         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7028                               UINT16);
7029 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7030         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7031                               UINT32);
7032 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7033         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7034                               UINT8);
7035 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7036         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7037                               UINT8);
7038
7039 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7040         .f = cmd_read_reg_bit_field_parsed,
7041         .data = NULL,
7042         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7043         "Read register bit field between bit_x and bit_y included",
7044         .tokens = {
7045                 (void *)&cmd_read_reg_bit_field_read,
7046                 (void *)&cmd_read_reg_bit_field_regfield,
7047                 (void *)&cmd_read_reg_bit_field_port_id,
7048                 (void *)&cmd_read_reg_bit_field_reg_off,
7049                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7050                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7051                 NULL,
7052         },
7053 };
7054
7055 /* *** READ PORT REGISTER BIT *** */
7056 struct cmd_read_reg_bit_result {
7057         cmdline_fixed_string_t read;
7058         cmdline_fixed_string_t regbit;
7059         portid_t port_id;
7060         uint32_t reg_off;
7061         uint8_t bit_pos;
7062 };
7063
7064 static void
7065 cmd_read_reg_bit_parsed(void *parsed_result,
7066                         __attribute__((unused)) struct cmdline *cl,
7067                         __attribute__((unused)) void *data)
7068 {
7069         struct cmd_read_reg_bit_result *res = parsed_result;
7070         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7071 }
7072
7073 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7074         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7075 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7076         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7077                                  regbit, "regbit");
7078 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7079         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7080 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7081         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7082 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7083         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7084
7085 cmdline_parse_inst_t cmd_read_reg_bit = {
7086         .f = cmd_read_reg_bit_parsed,
7087         .data = NULL,
7088         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7089         .tokens = {
7090                 (void *)&cmd_read_reg_bit_read,
7091                 (void *)&cmd_read_reg_bit_regbit,
7092                 (void *)&cmd_read_reg_bit_port_id,
7093                 (void *)&cmd_read_reg_bit_reg_off,
7094                 (void *)&cmd_read_reg_bit_bit_pos,
7095                 NULL,
7096         },
7097 };
7098
7099 /* *** WRITE PORT REGISTER *** */
7100 struct cmd_write_reg_result {
7101         cmdline_fixed_string_t write;
7102         cmdline_fixed_string_t reg;
7103         portid_t port_id;
7104         uint32_t reg_off;
7105         uint32_t value;
7106 };
7107
7108 static void
7109 cmd_write_reg_parsed(void *parsed_result,
7110                      __attribute__((unused)) struct cmdline *cl,
7111                      __attribute__((unused)) void *data)
7112 {
7113         struct cmd_write_reg_result *res = parsed_result;
7114         port_reg_set(res->port_id, res->reg_off, res->value);
7115 }
7116
7117 cmdline_parse_token_string_t cmd_write_reg_write =
7118         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7119 cmdline_parse_token_string_t cmd_write_reg_reg =
7120         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7121 cmdline_parse_token_num_t cmd_write_reg_port_id =
7122         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7123 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7124         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7125 cmdline_parse_token_num_t cmd_write_reg_value =
7126         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7127
7128 cmdline_parse_inst_t cmd_write_reg = {
7129         .f = cmd_write_reg_parsed,
7130         .data = NULL,
7131         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7132         .tokens = {
7133                 (void *)&cmd_write_reg_write,
7134                 (void *)&cmd_write_reg_reg,
7135                 (void *)&cmd_write_reg_port_id,
7136                 (void *)&cmd_write_reg_reg_off,
7137                 (void *)&cmd_write_reg_value,
7138                 NULL,
7139         },
7140 };
7141
7142 /* *** WRITE PORT REGISTER BIT FIELD *** */
7143 struct cmd_write_reg_bit_field_result {
7144         cmdline_fixed_string_t write;
7145         cmdline_fixed_string_t regfield;
7146         portid_t port_id;
7147         uint32_t reg_off;
7148         uint8_t bit1_pos;
7149         uint8_t bit2_pos;
7150         uint32_t value;
7151 };
7152
7153 static void
7154 cmd_write_reg_bit_field_parsed(void *parsed_result,
7155                                __attribute__((unused)) struct cmdline *cl,
7156                                __attribute__((unused)) void *data)
7157 {
7158         struct cmd_write_reg_bit_field_result *res = parsed_result;
7159         port_reg_bit_field_set(res->port_id, res->reg_off,
7160                           res->bit1_pos, res->bit2_pos, res->value);
7161 }
7162
7163 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7164         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7165                                  "write");
7166 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7167         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7168                                  regfield, "regfield");
7169 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7170         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7171                               UINT16);
7172 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7173         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7174                               UINT32);
7175 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7176         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7177                               UINT8);
7178 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7179         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7180                               UINT8);
7181 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7182         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7183                               UINT32);
7184
7185 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7186         .f = cmd_write_reg_bit_field_parsed,
7187         .data = NULL,
7188         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7189                 "<reg_value>: "
7190                 "Set register bit field between bit_x and bit_y included",
7191         .tokens = {
7192                 (void *)&cmd_write_reg_bit_field_write,
7193                 (void *)&cmd_write_reg_bit_field_regfield,
7194                 (void *)&cmd_write_reg_bit_field_port_id,
7195                 (void *)&cmd_write_reg_bit_field_reg_off,
7196                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7197                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7198                 (void *)&cmd_write_reg_bit_field_value,
7199                 NULL,
7200         },
7201 };
7202
7203 /* *** WRITE PORT REGISTER BIT *** */
7204 struct cmd_write_reg_bit_result {
7205         cmdline_fixed_string_t write;
7206         cmdline_fixed_string_t regbit;
7207         portid_t port_id;
7208         uint32_t reg_off;
7209         uint8_t bit_pos;
7210         uint8_t value;
7211 };
7212
7213 static void
7214 cmd_write_reg_bit_parsed(void *parsed_result,
7215                          __attribute__((unused)) struct cmdline *cl,
7216                          __attribute__((unused)) void *data)
7217 {
7218         struct cmd_write_reg_bit_result *res = parsed_result;
7219         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7220 }
7221
7222 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7223         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7224                                  "write");
7225 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7226         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7227                                  regbit, "regbit");
7228 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7229         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7230 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7231         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7232 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7233         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7234 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7235         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7236
7237 cmdline_parse_inst_t cmd_write_reg_bit = {
7238         .f = cmd_write_reg_bit_parsed,
7239         .data = NULL,
7240         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7241                 "0 <= bit_x <= 31",
7242         .tokens = {
7243                 (void *)&cmd_write_reg_bit_write,
7244                 (void *)&cmd_write_reg_bit_regbit,
7245                 (void *)&cmd_write_reg_bit_port_id,
7246                 (void *)&cmd_write_reg_bit_reg_off,
7247                 (void *)&cmd_write_reg_bit_bit_pos,
7248                 (void *)&cmd_write_reg_bit_value,
7249                 NULL,
7250         },
7251 };
7252
7253 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7254 struct cmd_read_rxd_txd_result {
7255         cmdline_fixed_string_t read;
7256         cmdline_fixed_string_t rxd_txd;
7257         portid_t port_id;
7258         uint16_t queue_id;
7259         uint16_t desc_id;
7260 };
7261
7262 static void
7263 cmd_read_rxd_txd_parsed(void *parsed_result,
7264                         __attribute__((unused)) struct cmdline *cl,
7265                         __attribute__((unused)) void *data)
7266 {
7267         struct cmd_read_rxd_txd_result *res = parsed_result;
7268
7269         if (!strcmp(res->rxd_txd, "rxd"))
7270                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7271         else if (!strcmp(res->rxd_txd, "txd"))
7272                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7273 }
7274
7275 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7276         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7277 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7278         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7279                                  "rxd#txd");
7280 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7281         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7282 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7283         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7284 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7285         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7286
7287 cmdline_parse_inst_t cmd_read_rxd_txd = {
7288         .f = cmd_read_rxd_txd_parsed,
7289         .data = NULL,
7290         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7291         .tokens = {
7292                 (void *)&cmd_read_rxd_txd_read,
7293                 (void *)&cmd_read_rxd_txd_rxd_txd,
7294                 (void *)&cmd_read_rxd_txd_port_id,
7295                 (void *)&cmd_read_rxd_txd_queue_id,
7296                 (void *)&cmd_read_rxd_txd_desc_id,
7297                 NULL,
7298         },
7299 };
7300
7301 /* *** QUIT *** */
7302 struct cmd_quit_result {
7303         cmdline_fixed_string_t quit;
7304 };
7305
7306 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7307                             struct cmdline *cl,
7308                             __attribute__((unused)) void *data)
7309 {
7310         pmd_test_exit();
7311         cmdline_quit(cl);
7312 }
7313
7314 cmdline_parse_token_string_t cmd_quit_quit =
7315         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7316
7317 cmdline_parse_inst_t cmd_quit = {
7318         .f = cmd_quit_parsed,
7319         .data = NULL,
7320         .help_str = "quit: Exit application",
7321         .tokens = {
7322                 (void *)&cmd_quit_quit,
7323                 NULL,
7324         },
7325 };
7326
7327 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7328 struct cmd_mac_addr_result {
7329         cmdline_fixed_string_t mac_addr_cmd;
7330         cmdline_fixed_string_t what;
7331         uint16_t port_num;
7332         struct ether_addr address;
7333 };
7334
7335 static void cmd_mac_addr_parsed(void *parsed_result,
7336                 __attribute__((unused)) struct cmdline *cl,
7337                 __attribute__((unused)) void *data)
7338 {
7339         struct cmd_mac_addr_result *res = parsed_result;
7340         int ret;
7341
7342         if (strcmp(res->what, "add") == 0)
7343                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7344         else if (strcmp(res->what, "set") == 0)
7345                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7346                                                        &res->address);
7347         else
7348                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7349
7350         /* check the return value and print it if is < 0 */
7351         if(ret < 0)
7352                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7353
7354 }
7355
7356 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7357         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7358                                 "mac_addr");
7359 cmdline_parse_token_string_t cmd_mac_addr_what =
7360         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7361                                 "add#remove#set");
7362 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7363                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7364                                         UINT16);
7365 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7366                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7367
7368 cmdline_parse_inst_t cmd_mac_addr = {
7369         .f = cmd_mac_addr_parsed,
7370         .data = (void *)0,
7371         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7372                         "Add/Remove/Set MAC address on port_id",
7373         .tokens = {
7374                 (void *)&cmd_mac_addr_cmd,
7375                 (void *)&cmd_mac_addr_what,
7376                 (void *)&cmd_mac_addr_portnum,
7377                 (void *)&cmd_mac_addr_addr,
7378                 NULL,
7379         },
7380 };
7381
7382 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7383 struct cmd_eth_peer_result {
7384         cmdline_fixed_string_t set;
7385         cmdline_fixed_string_t eth_peer;
7386         portid_t port_id;
7387         cmdline_fixed_string_t peer_addr;
7388 };
7389
7390 static void cmd_set_eth_peer_parsed(void *parsed_result,
7391                         __attribute__((unused)) struct cmdline *cl,
7392                         __attribute__((unused)) void *data)
7393 {
7394                 struct cmd_eth_peer_result *res = parsed_result;
7395
7396                 if (test_done == 0) {
7397                         printf("Please stop forwarding first\n");
7398                         return;
7399                 }
7400                 if (!strcmp(res->eth_peer, "eth-peer")) {
7401                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7402                         fwd_config_setup();
7403                 }
7404 }
7405 cmdline_parse_token_string_t cmd_eth_peer_set =
7406         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7407 cmdline_parse_token_string_t cmd_eth_peer =
7408         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7409 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7410         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7411 cmdline_parse_token_string_t cmd_eth_peer_addr =
7412         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7413
7414 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7415         .f = cmd_set_eth_peer_parsed,
7416         .data = NULL,
7417         .help_str = "set eth-peer <port_id> <peer_mac>",
7418         .tokens = {
7419                 (void *)&cmd_eth_peer_set,
7420                 (void *)&cmd_eth_peer,
7421                 (void *)&cmd_eth_peer_port_id,
7422                 (void *)&cmd_eth_peer_addr,
7423                 NULL,
7424         },
7425 };
7426
7427 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7428 struct cmd_set_qmap_result {
7429         cmdline_fixed_string_t set;
7430         cmdline_fixed_string_t qmap;
7431         cmdline_fixed_string_t what;
7432         portid_t port_id;
7433         uint16_t queue_id;
7434         uint8_t map_value;
7435 };
7436
7437 static void
7438 cmd_set_qmap_parsed(void *parsed_result,
7439                        __attribute__((unused)) struct cmdline *cl,
7440                        __attribute__((unused)) void *data)
7441 {
7442         struct cmd_set_qmap_result *res = parsed_result;
7443         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7444
7445         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7446 }
7447
7448 cmdline_parse_token_string_t cmd_setqmap_set =
7449         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7450                                  set, "set");
7451 cmdline_parse_token_string_t cmd_setqmap_qmap =
7452         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7453                                  qmap, "stat_qmap");
7454 cmdline_parse_token_string_t cmd_setqmap_what =
7455         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7456                                  what, "tx#rx");
7457 cmdline_parse_token_num_t cmd_setqmap_portid =
7458         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7459                               port_id, UINT16);
7460 cmdline_parse_token_num_t cmd_setqmap_queueid =
7461         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7462                               queue_id, UINT16);
7463 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7464         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7465                               map_value, UINT8);
7466
7467 cmdline_parse_inst_t cmd_set_qmap = {
7468         .f = cmd_set_qmap_parsed,
7469         .data = NULL,
7470         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7471                 "Set statistics mapping value on tx|rx queue_id of port_id",
7472         .tokens = {
7473                 (void *)&cmd_setqmap_set,
7474                 (void *)&cmd_setqmap_qmap,
7475                 (void *)&cmd_setqmap_what,
7476                 (void *)&cmd_setqmap_portid,
7477                 (void *)&cmd_setqmap_queueid,
7478                 (void *)&cmd_setqmap_mapvalue,
7479                 NULL,
7480         },
7481 };
7482
7483 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7484 struct cmd_set_xstats_hide_zero_result {
7485         cmdline_fixed_string_t keyword;
7486         cmdline_fixed_string_t name;
7487         cmdline_fixed_string_t on_off;
7488 };
7489
7490 static void
7491 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7492                         __attribute__((unused)) struct cmdline *cl,
7493                         __attribute__((unused)) void *data)
7494 {
7495         struct cmd_set_xstats_hide_zero_result *res;
7496         uint16_t on_off = 0;
7497
7498         res = parsed_result;
7499         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7500         set_xstats_hide_zero(on_off);
7501 }
7502
7503 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7504         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7505                                  keyword, "set");
7506 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7507         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7508                                  name, "xstats-hide-zero");
7509 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7510         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7511                                  on_off, "on#off");
7512
7513 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7514         .f = cmd_set_xstats_hide_zero_parsed,
7515         .data = NULL,
7516         .help_str = "set xstats-hide-zero on|off",
7517         .tokens = {
7518                 (void *)&cmd_set_xstats_hide_zero_keyword,
7519                 (void *)&cmd_set_xstats_hide_zero_name,
7520                 (void *)&cmd_set_xstats_hide_zero_on_off,
7521                 NULL,
7522         },
7523 };
7524
7525 /* *** CONFIGURE UNICAST HASH TABLE *** */
7526 struct cmd_set_uc_hash_table {
7527         cmdline_fixed_string_t set;
7528         cmdline_fixed_string_t port;
7529         portid_t port_id;
7530         cmdline_fixed_string_t what;
7531         struct ether_addr address;
7532         cmdline_fixed_string_t mode;
7533 };
7534
7535 static void
7536 cmd_set_uc_hash_parsed(void *parsed_result,
7537                        __attribute__((unused)) struct cmdline *cl,
7538                        __attribute__((unused)) void *data)
7539 {
7540         int ret=0;
7541         struct cmd_set_uc_hash_table *res = parsed_result;
7542
7543         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7544
7545         if (strcmp(res->what, "uta") == 0)
7546                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7547                                                 &res->address,(uint8_t)is_on);
7548         if (ret < 0)
7549                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7550
7551 }
7552
7553 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7554         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7555                                  set, "set");
7556 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7557         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7558                                  port, "port");
7559 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7560         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7561                               port_id, UINT16);
7562 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7563         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7564                                  what, "uta");
7565 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7566         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7567                                 address);
7568 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7569         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7570                                  mode, "on#off");
7571
7572 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7573         .f = cmd_set_uc_hash_parsed,
7574         .data = NULL,
7575         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7576         .tokens = {
7577                 (void *)&cmd_set_uc_hash_set,
7578                 (void *)&cmd_set_uc_hash_port,
7579                 (void *)&cmd_set_uc_hash_portid,
7580                 (void *)&cmd_set_uc_hash_what,
7581                 (void *)&cmd_set_uc_hash_mac,
7582                 (void *)&cmd_set_uc_hash_mode,
7583                 NULL,
7584         },
7585 };
7586
7587 struct cmd_set_uc_all_hash_table {
7588         cmdline_fixed_string_t set;
7589         cmdline_fixed_string_t port;
7590         portid_t port_id;
7591         cmdline_fixed_string_t what;
7592         cmdline_fixed_string_t value;
7593         cmdline_fixed_string_t mode;
7594 };
7595
7596 static void
7597 cmd_set_uc_all_hash_parsed(void *parsed_result,
7598                        __attribute__((unused)) struct cmdline *cl,
7599                        __attribute__((unused)) void *data)
7600 {
7601         int ret=0;
7602         struct cmd_set_uc_all_hash_table *res = parsed_result;
7603
7604         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7605
7606         if ((strcmp(res->what, "uta") == 0) &&
7607                 (strcmp(res->value, "all") == 0))
7608                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7609         if (ret < 0)
7610                 printf("bad unicast hash table parameter,"
7611                         "return code = %d \n", ret);
7612 }
7613
7614 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7615         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7616                                  set, "set");
7617 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7618         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7619                                  port, "port");
7620 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7621         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7622                               port_id, UINT16);
7623 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7624         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7625                                  what, "uta");
7626 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7627         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7628                                 value,"all");
7629 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7630         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7631                                  mode, "on#off");
7632
7633 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7634         .f = cmd_set_uc_all_hash_parsed,
7635         .data = NULL,
7636         .help_str = "set port <port_id> uta all on|off",
7637         .tokens = {
7638                 (void *)&cmd_set_uc_all_hash_set,
7639                 (void *)&cmd_set_uc_all_hash_port,
7640                 (void *)&cmd_set_uc_all_hash_portid,
7641                 (void *)&cmd_set_uc_all_hash_what,
7642                 (void *)&cmd_set_uc_all_hash_value,
7643                 (void *)&cmd_set_uc_all_hash_mode,
7644                 NULL,
7645         },
7646 };
7647
7648 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7649 struct cmd_set_vf_macvlan_filter {
7650         cmdline_fixed_string_t set;
7651         cmdline_fixed_string_t port;
7652         portid_t port_id;
7653         cmdline_fixed_string_t vf;
7654         uint8_t vf_id;
7655         struct ether_addr address;
7656         cmdline_fixed_string_t filter_type;
7657         cmdline_fixed_string_t mode;
7658 };
7659
7660 static void
7661 cmd_set_vf_macvlan_parsed(void *parsed_result,
7662                        __attribute__((unused)) struct cmdline *cl,
7663                        __attribute__((unused)) void *data)
7664 {
7665         int is_on, ret = 0;
7666         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7667         struct rte_eth_mac_filter filter;
7668
7669         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7670
7671         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7672
7673         /* set VF MAC filter */
7674         filter.is_vf = 1;
7675
7676         /* set VF ID */
7677         filter.dst_id = res->vf_id;
7678
7679         if (!strcmp(res->filter_type, "exact-mac"))
7680                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7681         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7682                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7683         else if (!strcmp(res->filter_type, "hashmac"))
7684                 filter.filter_type = RTE_MAC_HASH_MATCH;
7685         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7686                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7687
7688         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7689
7690         if (is_on)
7691                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7692                                         RTE_ETH_FILTER_MACVLAN,
7693                                         RTE_ETH_FILTER_ADD,
7694                                          &filter);
7695         else
7696                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7697                                         RTE_ETH_FILTER_MACVLAN,
7698                                         RTE_ETH_FILTER_DELETE,
7699                                         &filter);
7700
7701         if (ret < 0)
7702                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7703
7704 }
7705
7706 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7707         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7708                                  set, "set");
7709 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7710         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7711                                  port, "port");
7712 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7713         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7714                               port_id, UINT16);
7715 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7716         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7717                                  vf, "vf");
7718 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7719         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7720                                 vf_id, UINT8);
7721 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7722         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7723                                 address);
7724 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7725         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7726                                 filter_type, "exact-mac#exact-mac-vlan"
7727                                 "#hashmac#hashmac-vlan");
7728 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7729         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7730                                  mode, "on#off");
7731
7732 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7733         .f = cmd_set_vf_macvlan_parsed,
7734         .data = NULL,
7735         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7736                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7737                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7738                 "hash match rule: hash match of MAC and exact match of VLAN",
7739         .tokens = {
7740                 (void *)&cmd_set_vf_macvlan_set,
7741                 (void *)&cmd_set_vf_macvlan_port,
7742                 (void *)&cmd_set_vf_macvlan_portid,
7743                 (void *)&cmd_set_vf_macvlan_vf,
7744                 (void *)&cmd_set_vf_macvlan_vf_id,
7745                 (void *)&cmd_set_vf_macvlan_mac,
7746                 (void *)&cmd_set_vf_macvlan_filter_type,
7747                 (void *)&cmd_set_vf_macvlan_mode,
7748                 NULL,
7749         },
7750 };
7751
7752 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7753 struct cmd_set_vf_traffic {
7754         cmdline_fixed_string_t set;
7755         cmdline_fixed_string_t port;
7756         portid_t port_id;
7757         cmdline_fixed_string_t vf;
7758         uint8_t vf_id;
7759         cmdline_fixed_string_t what;
7760         cmdline_fixed_string_t mode;
7761 };
7762
7763 static void
7764 cmd_set_vf_traffic_parsed(void *parsed_result,
7765                        __attribute__((unused)) struct cmdline *cl,
7766                        __attribute__((unused)) void *data)
7767 {
7768         struct cmd_set_vf_traffic *res = parsed_result;
7769         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7770         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7771
7772         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7773 }
7774
7775 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7776         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7777                                  set, "set");
7778 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7779         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7780                                  port, "port");
7781 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7782         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7783                               port_id, UINT16);
7784 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7785         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7786                                  vf, "vf");
7787 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7788         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7789                               vf_id, UINT8);
7790 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7791         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7792                                  what, "tx#rx");
7793 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7794         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7795                                  mode, "on#off");
7796
7797 cmdline_parse_inst_t cmd_set_vf_traffic = {
7798         .f = cmd_set_vf_traffic_parsed,
7799         .data = NULL,
7800         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7801         .tokens = {
7802                 (void *)&cmd_setvf_traffic_set,
7803                 (void *)&cmd_setvf_traffic_port,
7804                 (void *)&cmd_setvf_traffic_portid,
7805                 (void *)&cmd_setvf_traffic_vf,
7806                 (void *)&cmd_setvf_traffic_vfid,
7807                 (void *)&cmd_setvf_traffic_what,
7808                 (void *)&cmd_setvf_traffic_mode,
7809                 NULL,
7810         },
7811 };
7812
7813 /* *** CONFIGURE VF RECEIVE MODE *** */
7814 struct cmd_set_vf_rxmode {
7815         cmdline_fixed_string_t set;
7816         cmdline_fixed_string_t port;
7817         portid_t port_id;
7818         cmdline_fixed_string_t vf;
7819         uint8_t vf_id;
7820         cmdline_fixed_string_t what;
7821         cmdline_fixed_string_t mode;
7822         cmdline_fixed_string_t on;
7823 };
7824
7825 static void
7826 cmd_set_vf_rxmode_parsed(void *parsed_result,
7827                        __attribute__((unused)) struct cmdline *cl,
7828                        __attribute__((unused)) void *data)
7829 {
7830         int ret = -ENOTSUP;
7831         uint16_t rx_mode = 0;
7832         struct cmd_set_vf_rxmode *res = parsed_result;
7833
7834         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7835         if (!strcmp(res->what,"rxmode")) {
7836                 if (!strcmp(res->mode, "AUPE"))
7837                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7838                 else if (!strcmp(res->mode, "ROPE"))
7839                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7840                 else if (!strcmp(res->mode, "BAM"))
7841                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7842                 else if (!strncmp(res->mode, "MPE",3))
7843                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7844         }
7845
7846         RTE_SET_USED(is_on);
7847
7848 #ifdef RTE_LIBRTE_IXGBE_PMD
7849         if (ret == -ENOTSUP)
7850                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7851                                                   rx_mode, (uint8_t)is_on);
7852 #endif
7853 #ifdef RTE_LIBRTE_BNXT_PMD
7854         if (ret == -ENOTSUP)
7855                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7856                                                  rx_mode, (uint8_t)is_on);
7857 #endif
7858         if (ret < 0)
7859                 printf("bad VF receive mode parameter, return code = %d \n",
7860                 ret);
7861 }
7862
7863 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7864         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7865                                  set, "set");
7866 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7867         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7868                                  port, "port");
7869 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7870         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7871                               port_id, UINT16);
7872 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7873         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7874                                  vf, "vf");
7875 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7876         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7877                               vf_id, UINT8);
7878 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7879         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7880                                  what, "rxmode");
7881 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7882         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7883                                  mode, "AUPE#ROPE#BAM#MPE");
7884 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7885         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7886                                  on, "on#off");
7887
7888 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7889         .f = cmd_set_vf_rxmode_parsed,
7890         .data = NULL,
7891         .help_str = "set port <port_id> vf <vf_id> rxmode "
7892                 "AUPE|ROPE|BAM|MPE on|off",
7893         .tokens = {
7894                 (void *)&cmd_set_vf_rxmode_set,
7895                 (void *)&cmd_set_vf_rxmode_port,
7896                 (void *)&cmd_set_vf_rxmode_portid,
7897                 (void *)&cmd_set_vf_rxmode_vf,
7898                 (void *)&cmd_set_vf_rxmode_vfid,
7899                 (void *)&cmd_set_vf_rxmode_what,
7900                 (void *)&cmd_set_vf_rxmode_mode,
7901                 (void *)&cmd_set_vf_rxmode_on,
7902                 NULL,
7903         },
7904 };
7905
7906 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7907 struct cmd_vf_mac_addr_result {
7908         cmdline_fixed_string_t mac_addr_cmd;
7909         cmdline_fixed_string_t what;
7910         cmdline_fixed_string_t port;
7911         uint16_t port_num;
7912         cmdline_fixed_string_t vf;
7913         uint8_t vf_num;
7914         struct ether_addr address;
7915 };
7916
7917 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7918                 __attribute__((unused)) struct cmdline *cl,
7919                 __attribute__((unused)) void *data)
7920 {
7921         struct cmd_vf_mac_addr_result *res = parsed_result;
7922         int ret = -ENOTSUP;
7923
7924         if (strcmp(res->what, "add") != 0)
7925                 return;
7926
7927 #ifdef RTE_LIBRTE_I40E_PMD
7928         if (ret == -ENOTSUP)
7929                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7930                                                    &res->address);
7931 #endif
7932 #ifdef RTE_LIBRTE_BNXT_PMD
7933         if (ret == -ENOTSUP)
7934                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7935                                                 res->vf_num);
7936 #endif
7937
7938         if(ret < 0)
7939                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7940
7941 }
7942
7943 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7944         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7945                                 mac_addr_cmd,"mac_addr");
7946 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7947         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7948                                 what,"add");
7949 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7950         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7951                                 port,"port");
7952 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7953         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7954                                 port_num, UINT16);
7955 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7956         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7957                                 vf,"vf");
7958 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7959         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7960                                 vf_num, UINT8);
7961 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7962         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7963                                 address);
7964
7965 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7966         .f = cmd_vf_mac_addr_parsed,
7967         .data = (void *)0,
7968         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7969                 "Add MAC address filtering for a VF on port_id",
7970         .tokens = {
7971                 (void *)&cmd_vf_mac_addr_cmd,
7972                 (void *)&cmd_vf_mac_addr_what,
7973                 (void *)&cmd_vf_mac_addr_port,
7974                 (void *)&cmd_vf_mac_addr_portnum,
7975                 (void *)&cmd_vf_mac_addr_vf,
7976                 (void *)&cmd_vf_mac_addr_vfnum,
7977                 (void *)&cmd_vf_mac_addr_addr,
7978                 NULL,
7979         },
7980 };
7981
7982 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7983 struct cmd_vf_rx_vlan_filter {
7984         cmdline_fixed_string_t rx_vlan;
7985         cmdline_fixed_string_t what;
7986         uint16_t vlan_id;
7987         cmdline_fixed_string_t port;
7988         portid_t port_id;
7989         cmdline_fixed_string_t vf;
7990         uint64_t vf_mask;
7991 };
7992
7993 static void
7994 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7995                           __attribute__((unused)) struct cmdline *cl,
7996                           __attribute__((unused)) void *data)
7997 {
7998         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7999         int ret = -ENOTSUP;
8000
8001         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8002
8003 #ifdef RTE_LIBRTE_IXGBE_PMD
8004         if (ret == -ENOTSUP)
8005                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8006                                 res->vlan_id, res->vf_mask, is_add);
8007 #endif
8008 #ifdef RTE_LIBRTE_I40E_PMD
8009         if (ret == -ENOTSUP)
8010                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8011                                 res->vlan_id, res->vf_mask, is_add);
8012 #endif
8013 #ifdef RTE_LIBRTE_BNXT_PMD
8014         if (ret == -ENOTSUP)
8015                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8016                                 res->vlan_id, res->vf_mask, is_add);
8017 #endif
8018
8019         switch (ret) {
8020         case 0:
8021                 break;
8022         case -EINVAL:
8023                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8024                                 res->vlan_id, res->vf_mask);
8025                 break;
8026         case -ENODEV:
8027                 printf("invalid port_id %d\n", res->port_id);
8028                 break;
8029         case -ENOTSUP:
8030                 printf("function not implemented or supported\n");
8031                 break;
8032         default:
8033                 printf("programming error: (%s)\n", strerror(-ret));
8034         }
8035 }
8036
8037 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8038         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8039                                  rx_vlan, "rx_vlan");
8040 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8041         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8042                                  what, "add#rm");
8043 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8044         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8045                               vlan_id, UINT16);
8046 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8047         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8048                                  port, "port");
8049 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8050         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8051                               port_id, UINT16);
8052 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8053         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8054                                  vf, "vf");
8055 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8056         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8057                               vf_mask, UINT64);
8058
8059 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8060         .f = cmd_vf_rx_vlan_filter_parsed,
8061         .data = NULL,
8062         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8063                 "(vf_mask = hexadecimal VF mask)",
8064         .tokens = {
8065                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8066                 (void *)&cmd_vf_rx_vlan_filter_what,
8067                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8068                 (void *)&cmd_vf_rx_vlan_filter_port,
8069                 (void *)&cmd_vf_rx_vlan_filter_portid,
8070                 (void *)&cmd_vf_rx_vlan_filter_vf,
8071                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8072                 NULL,
8073         },
8074 };
8075
8076 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8077 struct cmd_queue_rate_limit_result {
8078         cmdline_fixed_string_t set;
8079         cmdline_fixed_string_t port;
8080         uint16_t port_num;
8081         cmdline_fixed_string_t queue;
8082         uint8_t queue_num;
8083         cmdline_fixed_string_t rate;
8084         uint16_t rate_num;
8085 };
8086
8087 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8088                 __attribute__((unused)) struct cmdline *cl,
8089                 __attribute__((unused)) void *data)
8090 {
8091         struct cmd_queue_rate_limit_result *res = parsed_result;
8092         int ret = 0;
8093
8094         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8095                 && (strcmp(res->queue, "queue") == 0)
8096                 && (strcmp(res->rate, "rate") == 0))
8097                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8098                                         res->rate_num);
8099         if (ret < 0)
8100                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8101
8102 }
8103
8104 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8105         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8106                                 set, "set");
8107 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8108         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8109                                 port, "port");
8110 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8111         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8112                                 port_num, UINT16);
8113 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8114         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8115                                 queue, "queue");
8116 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8117         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8118                                 queue_num, UINT8);
8119 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8120         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8121                                 rate, "rate");
8122 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8123         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8124                                 rate_num, UINT16);
8125
8126 cmdline_parse_inst_t cmd_queue_rate_limit = {
8127         .f = cmd_queue_rate_limit_parsed,
8128         .data = (void *)0,
8129         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8130                 "Set rate limit for a queue on port_id",
8131         .tokens = {
8132                 (void *)&cmd_queue_rate_limit_set,
8133                 (void *)&cmd_queue_rate_limit_port,
8134                 (void *)&cmd_queue_rate_limit_portnum,
8135                 (void *)&cmd_queue_rate_limit_queue,
8136                 (void *)&cmd_queue_rate_limit_queuenum,
8137                 (void *)&cmd_queue_rate_limit_rate,
8138                 (void *)&cmd_queue_rate_limit_ratenum,
8139                 NULL,
8140         },
8141 };
8142
8143 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8144 struct cmd_vf_rate_limit_result {
8145         cmdline_fixed_string_t set;
8146         cmdline_fixed_string_t port;
8147         uint16_t port_num;
8148         cmdline_fixed_string_t vf;
8149         uint8_t vf_num;
8150         cmdline_fixed_string_t rate;
8151         uint16_t rate_num;
8152         cmdline_fixed_string_t q_msk;
8153         uint64_t q_msk_val;
8154 };
8155
8156 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8157                 __attribute__((unused)) struct cmdline *cl,
8158                 __attribute__((unused)) void *data)
8159 {
8160         struct cmd_vf_rate_limit_result *res = parsed_result;
8161         int ret = 0;
8162
8163         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8164                 && (strcmp(res->vf, "vf") == 0)
8165                 && (strcmp(res->rate, "rate") == 0)
8166                 && (strcmp(res->q_msk, "queue_mask") == 0))
8167                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8168                                         res->rate_num, res->q_msk_val);
8169         if (ret < 0)
8170                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8171
8172 }
8173
8174 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8175         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8176                                 set, "set");
8177 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8178         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8179                                 port, "port");
8180 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8181         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8182                                 port_num, UINT16);
8183 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8184         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8185                                 vf, "vf");
8186 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8187         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8188                                 vf_num, UINT8);
8189 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8190         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8191                                 rate, "rate");
8192 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8193         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8194                                 rate_num, UINT16);
8195 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8196         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8197                                 q_msk, "queue_mask");
8198 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8199         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8200                                 q_msk_val, UINT64);
8201
8202 cmdline_parse_inst_t cmd_vf_rate_limit = {
8203         .f = cmd_vf_rate_limit_parsed,
8204         .data = (void *)0,
8205         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8206                 "queue_mask <queue_mask_value>: "
8207                 "Set rate limit for queues of VF on port_id",
8208         .tokens = {
8209                 (void *)&cmd_vf_rate_limit_set,
8210                 (void *)&cmd_vf_rate_limit_port,
8211                 (void *)&cmd_vf_rate_limit_portnum,
8212                 (void *)&cmd_vf_rate_limit_vf,
8213                 (void *)&cmd_vf_rate_limit_vfnum,
8214                 (void *)&cmd_vf_rate_limit_rate,
8215                 (void *)&cmd_vf_rate_limit_ratenum,
8216                 (void *)&cmd_vf_rate_limit_q_msk,
8217                 (void *)&cmd_vf_rate_limit_q_msk_val,
8218                 NULL,
8219         },
8220 };
8221
8222 /* *** ADD TUNNEL FILTER OF A PORT *** */
8223 struct cmd_tunnel_filter_result {
8224         cmdline_fixed_string_t cmd;
8225         cmdline_fixed_string_t what;
8226         portid_t port_id;
8227         struct ether_addr outer_mac;
8228         struct ether_addr inner_mac;
8229         cmdline_ipaddr_t ip_value;
8230         uint16_t inner_vlan;
8231         cmdline_fixed_string_t tunnel_type;
8232         cmdline_fixed_string_t filter_type;
8233         uint32_t tenant_id;
8234         uint16_t queue_num;
8235 };
8236
8237 static void
8238 cmd_tunnel_filter_parsed(void *parsed_result,
8239                           __attribute__((unused)) struct cmdline *cl,
8240                           __attribute__((unused)) void *data)
8241 {
8242         struct cmd_tunnel_filter_result *res = parsed_result;
8243         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8244         int ret = 0;
8245
8246         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8247
8248         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8249         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8250         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8251
8252         if (res->ip_value.family == AF_INET) {
8253                 tunnel_filter_conf.ip_addr.ipv4_addr =
8254                         res->ip_value.addr.ipv4.s_addr;
8255                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8256         } else {
8257                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8258                         &(res->ip_value.addr.ipv6),
8259                         sizeof(struct in6_addr));
8260                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8261         }
8262
8263         if (!strcmp(res->filter_type, "imac-ivlan"))
8264                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8265         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8266                 tunnel_filter_conf.filter_type =
8267                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8268         else if (!strcmp(res->filter_type, "imac-tenid"))
8269                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8270         else if (!strcmp(res->filter_type, "imac"))
8271                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8272         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8273                 tunnel_filter_conf.filter_type =
8274                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8275         else if (!strcmp(res->filter_type, "oip"))
8276                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8277         else if (!strcmp(res->filter_type, "iip"))
8278                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8279         else {
8280                 printf("The filter type is not supported");
8281                 return;
8282         }
8283
8284         if (!strcmp(res->tunnel_type, "vxlan"))
8285                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8286         else if (!strcmp(res->tunnel_type, "nvgre"))
8287                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8288         else if (!strcmp(res->tunnel_type, "ipingre"))
8289                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8290         else {
8291                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8292                 return;
8293         }
8294
8295         tunnel_filter_conf.tenant_id = res->tenant_id;
8296         tunnel_filter_conf.queue_id = res->queue_num;
8297         if (!strcmp(res->what, "add"))
8298                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8299                                         RTE_ETH_FILTER_TUNNEL,
8300                                         RTE_ETH_FILTER_ADD,
8301                                         &tunnel_filter_conf);
8302         else
8303                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8304                                         RTE_ETH_FILTER_TUNNEL,
8305                                         RTE_ETH_FILTER_DELETE,
8306                                         &tunnel_filter_conf);
8307         if (ret < 0)
8308                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8309                                 strerror(-ret));
8310
8311 }
8312 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8313         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8314         cmd, "tunnel_filter");
8315 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8316         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8317         what, "add#rm");
8318 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8319         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8320         port_id, UINT16);
8321 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8322         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8323         outer_mac);
8324 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8325         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8326         inner_mac);
8327 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8328         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8329         inner_vlan, UINT16);
8330 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8331         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8332         ip_value);
8333 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8334         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8335         tunnel_type, "vxlan#nvgre#ipingre");
8336
8337 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8338         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8339         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8340                 "imac#omac-imac-tenid");
8341 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8342         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8343         tenant_id, UINT32);
8344 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8345         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8346         queue_num, UINT16);
8347
8348 cmdline_parse_inst_t cmd_tunnel_filter = {
8349         .f = cmd_tunnel_filter_parsed,
8350         .data = (void *)0,
8351         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8352                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8353                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8354                 "<queue_id>: Add/Rm tunnel filter of a port",
8355         .tokens = {
8356                 (void *)&cmd_tunnel_filter_cmd,
8357                 (void *)&cmd_tunnel_filter_what,
8358                 (void *)&cmd_tunnel_filter_port_id,
8359                 (void *)&cmd_tunnel_filter_outer_mac,
8360                 (void *)&cmd_tunnel_filter_inner_mac,
8361                 (void *)&cmd_tunnel_filter_ip_value,
8362                 (void *)&cmd_tunnel_filter_innner_vlan,
8363                 (void *)&cmd_tunnel_filter_tunnel_type,
8364                 (void *)&cmd_tunnel_filter_filter_type,
8365                 (void *)&cmd_tunnel_filter_tenant_id,
8366                 (void *)&cmd_tunnel_filter_queue_num,
8367                 NULL,
8368         },
8369 };
8370
8371 /* *** CONFIGURE TUNNEL UDP PORT *** */
8372 struct cmd_tunnel_udp_config {
8373         cmdline_fixed_string_t cmd;
8374         cmdline_fixed_string_t what;
8375         uint16_t udp_port;
8376         portid_t port_id;
8377 };
8378
8379 static void
8380 cmd_tunnel_udp_config_parsed(void *parsed_result,
8381                           __attribute__((unused)) struct cmdline *cl,
8382                           __attribute__((unused)) void *data)
8383 {
8384         struct cmd_tunnel_udp_config *res = parsed_result;
8385         struct rte_eth_udp_tunnel tunnel_udp;
8386         int ret;
8387
8388         tunnel_udp.udp_port = res->udp_port;
8389
8390         if (!strcmp(res->cmd, "rx_vxlan_port"))
8391                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8392
8393         if (!strcmp(res->what, "add"))
8394                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8395                                                       &tunnel_udp);
8396         else
8397                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8398                                                          &tunnel_udp);
8399
8400         if (ret < 0)
8401                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8402 }
8403
8404 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8405         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8406                                 cmd, "rx_vxlan_port");
8407 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8408         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8409                                 what, "add#rm");
8410 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8411         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8412                                 udp_port, UINT16);
8413 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8414         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8415                                 port_id, UINT16);
8416
8417 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8418         .f = cmd_tunnel_udp_config_parsed,
8419         .data = (void *)0,
8420         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8421                 "Add/Remove a tunneling UDP port filter",
8422         .tokens = {
8423                 (void *)&cmd_tunnel_udp_config_cmd,
8424                 (void *)&cmd_tunnel_udp_config_what,
8425                 (void *)&cmd_tunnel_udp_config_udp_port,
8426                 (void *)&cmd_tunnel_udp_config_port_id,
8427                 NULL,
8428         },
8429 };
8430
8431 /* *** GLOBAL CONFIG *** */
8432 struct cmd_global_config_result {
8433         cmdline_fixed_string_t cmd;
8434         portid_t port_id;
8435         cmdline_fixed_string_t cfg_type;
8436         uint8_t len;
8437 };
8438
8439 static void
8440 cmd_global_config_parsed(void *parsed_result,
8441                          __attribute__((unused)) struct cmdline *cl,
8442                          __attribute__((unused)) void *data)
8443 {
8444         struct cmd_global_config_result *res = parsed_result;
8445         struct rte_eth_global_cfg conf;
8446         int ret;
8447
8448         memset(&conf, 0, sizeof(conf));
8449         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8450         conf.cfg.gre_key_len = res->len;
8451         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8452                                       RTE_ETH_FILTER_SET, &conf);
8453         if (ret != 0)
8454                 printf("Global config error\n");
8455 }
8456
8457 cmdline_parse_token_string_t cmd_global_config_cmd =
8458         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8459                 "global_config");
8460 cmdline_parse_token_num_t cmd_global_config_port_id =
8461         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8462                                UINT16);
8463 cmdline_parse_token_string_t cmd_global_config_type =
8464         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8465                 cfg_type, "gre-key-len");
8466 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8467         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8468                 len, UINT8);
8469
8470 cmdline_parse_inst_t cmd_global_config = {
8471         .f = cmd_global_config_parsed,
8472         .data = (void *)NULL,
8473         .help_str = "global_config <port_id> gre-key-len <key_len>",
8474         .tokens = {
8475                 (void *)&cmd_global_config_cmd,
8476                 (void *)&cmd_global_config_port_id,
8477                 (void *)&cmd_global_config_type,
8478                 (void *)&cmd_global_config_gre_key_len,
8479                 NULL,
8480         },
8481 };
8482
8483 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8484 struct cmd_set_mirror_mask_result {
8485         cmdline_fixed_string_t set;
8486         cmdline_fixed_string_t port;
8487         portid_t port_id;
8488         cmdline_fixed_string_t mirror;
8489         uint8_t rule_id;
8490         cmdline_fixed_string_t what;
8491         cmdline_fixed_string_t value;
8492         cmdline_fixed_string_t dstpool;
8493         uint8_t dstpool_id;
8494         cmdline_fixed_string_t on;
8495 };
8496
8497 cmdline_parse_token_string_t cmd_mirror_mask_set =
8498         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8499                                 set, "set");
8500 cmdline_parse_token_string_t cmd_mirror_mask_port =
8501         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8502                                 port, "port");
8503 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8504         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8505                                 port_id, UINT16);
8506 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8507         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8508                                 mirror, "mirror-rule");
8509 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8510         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8511                                 rule_id, UINT8);
8512 cmdline_parse_token_string_t cmd_mirror_mask_what =
8513         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8514                                 what, "pool-mirror-up#pool-mirror-down"
8515                                       "#vlan-mirror");
8516 cmdline_parse_token_string_t cmd_mirror_mask_value =
8517         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8518                                 value, NULL);
8519 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8520         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8521                                 dstpool, "dst-pool");
8522 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8523         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8524                                 dstpool_id, UINT8);
8525 cmdline_parse_token_string_t cmd_mirror_mask_on =
8526         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8527                                 on, "on#off");
8528
8529 static void
8530 cmd_set_mirror_mask_parsed(void *parsed_result,
8531                        __attribute__((unused)) struct cmdline *cl,
8532                        __attribute__((unused)) void *data)
8533 {
8534         int ret,nb_item,i;
8535         struct cmd_set_mirror_mask_result *res = parsed_result;
8536         struct rte_eth_mirror_conf mr_conf;
8537
8538         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8539
8540         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8541
8542         mr_conf.dst_pool = res->dstpool_id;
8543
8544         if (!strcmp(res->what, "pool-mirror-up")) {
8545                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8546                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8547         } else if (!strcmp(res->what, "pool-mirror-down")) {
8548                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8549                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8550         } else if (!strcmp(res->what, "vlan-mirror")) {
8551                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8552                 nb_item = parse_item_list(res->value, "vlan",
8553                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8554                 if (nb_item <= 0)
8555                         return;
8556
8557                 for (i = 0; i < nb_item; i++) {
8558                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8559                                 printf("Invalid vlan_id: must be < 4096\n");
8560                                 return;
8561                         }
8562
8563                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8564                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8565                 }
8566         }
8567
8568         if (!strcmp(res->on, "on"))
8569                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8570                                                 res->rule_id, 1);
8571         else
8572                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8573                                                 res->rule_id, 0);
8574         if (ret < 0)
8575                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8576 }
8577
8578 cmdline_parse_inst_t cmd_set_mirror_mask = {
8579                 .f = cmd_set_mirror_mask_parsed,
8580                 .data = NULL,
8581                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8582                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8583                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8584                 .tokens = {
8585                         (void *)&cmd_mirror_mask_set,
8586                         (void *)&cmd_mirror_mask_port,
8587                         (void *)&cmd_mirror_mask_portid,
8588                         (void *)&cmd_mirror_mask_mirror,
8589                         (void *)&cmd_mirror_mask_ruleid,
8590                         (void *)&cmd_mirror_mask_what,
8591                         (void *)&cmd_mirror_mask_value,
8592                         (void *)&cmd_mirror_mask_dstpool,
8593                         (void *)&cmd_mirror_mask_poolid,
8594                         (void *)&cmd_mirror_mask_on,
8595                         NULL,
8596                 },
8597 };
8598
8599 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8600 struct cmd_set_mirror_link_result {
8601         cmdline_fixed_string_t set;
8602         cmdline_fixed_string_t port;
8603         portid_t port_id;
8604         cmdline_fixed_string_t mirror;
8605         uint8_t rule_id;
8606         cmdline_fixed_string_t what;
8607         cmdline_fixed_string_t dstpool;
8608         uint8_t dstpool_id;
8609         cmdline_fixed_string_t on;
8610 };
8611
8612 cmdline_parse_token_string_t cmd_mirror_link_set =
8613         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8614                                  set, "set");
8615 cmdline_parse_token_string_t cmd_mirror_link_port =
8616         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8617                                 port, "port");
8618 cmdline_parse_token_num_t cmd_mirror_link_portid =
8619         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8620                                 port_id, UINT16);
8621 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8622         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8623                                 mirror, "mirror-rule");
8624 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8625         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8626                             rule_id, UINT8);
8627 cmdline_parse_token_string_t cmd_mirror_link_what =
8628         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8629                                 what, "uplink-mirror#downlink-mirror");
8630 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8631         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8632                                 dstpool, "dst-pool");
8633 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8634         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8635                                 dstpool_id, UINT8);
8636 cmdline_parse_token_string_t cmd_mirror_link_on =
8637         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8638                                 on, "on#off");
8639
8640 static void
8641 cmd_set_mirror_link_parsed(void *parsed_result,
8642                        __attribute__((unused)) struct cmdline *cl,
8643                        __attribute__((unused)) void *data)
8644 {
8645         int ret;
8646         struct cmd_set_mirror_link_result *res = parsed_result;
8647         struct rte_eth_mirror_conf mr_conf;
8648
8649         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8650         if (!strcmp(res->what, "uplink-mirror"))
8651                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8652         else
8653                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8654
8655         mr_conf.dst_pool = res->dstpool_id;
8656
8657         if (!strcmp(res->on, "on"))
8658                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8659                                                 res->rule_id, 1);
8660         else
8661                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8662                                                 res->rule_id, 0);
8663
8664         /* check the return value and print it if is < 0 */
8665         if (ret < 0)
8666                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8667
8668 }
8669
8670 cmdline_parse_inst_t cmd_set_mirror_link = {
8671                 .f = cmd_set_mirror_link_parsed,
8672                 .data = NULL,
8673                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8674                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8675                 .tokens = {
8676                         (void *)&cmd_mirror_link_set,
8677                         (void *)&cmd_mirror_link_port,
8678                         (void *)&cmd_mirror_link_portid,
8679                         (void *)&cmd_mirror_link_mirror,
8680                         (void *)&cmd_mirror_link_ruleid,
8681                         (void *)&cmd_mirror_link_what,
8682                         (void *)&cmd_mirror_link_dstpool,
8683                         (void *)&cmd_mirror_link_poolid,
8684                         (void *)&cmd_mirror_link_on,
8685                         NULL,
8686                 },
8687 };
8688
8689 /* *** RESET VM MIRROR RULE *** */
8690 struct cmd_rm_mirror_rule_result {
8691         cmdline_fixed_string_t reset;
8692         cmdline_fixed_string_t port;
8693         portid_t port_id;
8694         cmdline_fixed_string_t mirror;
8695         uint8_t rule_id;
8696 };
8697
8698 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8699         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8700                                  reset, "reset");
8701 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8702         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8703                                 port, "port");
8704 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8705         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8706                                 port_id, UINT16);
8707 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8708         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8709                                 mirror, "mirror-rule");
8710 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8711         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8712                                 rule_id, UINT8);
8713
8714 static void
8715 cmd_reset_mirror_rule_parsed(void *parsed_result,
8716                        __attribute__((unused)) struct cmdline *cl,
8717                        __attribute__((unused)) void *data)
8718 {
8719         int ret;
8720         struct cmd_set_mirror_link_result *res = parsed_result;
8721         /* check rule_id */
8722         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8723         if(ret < 0)
8724                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8725 }
8726
8727 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8728                 .f = cmd_reset_mirror_rule_parsed,
8729                 .data = NULL,
8730                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8731                 .tokens = {
8732                         (void *)&cmd_rm_mirror_rule_reset,
8733                         (void *)&cmd_rm_mirror_rule_port,
8734                         (void *)&cmd_rm_mirror_rule_portid,
8735                         (void *)&cmd_rm_mirror_rule_mirror,
8736                         (void *)&cmd_rm_mirror_rule_ruleid,
8737                         NULL,
8738                 },
8739 };
8740
8741 /* ******************************************************************************** */
8742
8743 struct cmd_dump_result {
8744         cmdline_fixed_string_t dump;
8745 };
8746
8747 static void
8748 dump_struct_sizes(void)
8749 {
8750 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8751         DUMP_SIZE(struct rte_mbuf);
8752         DUMP_SIZE(struct rte_mempool);
8753         DUMP_SIZE(struct rte_ring);
8754 #undef DUMP_SIZE
8755 }
8756
8757 static void cmd_dump_parsed(void *parsed_result,
8758                             __attribute__((unused)) struct cmdline *cl,
8759                             __attribute__((unused)) void *data)
8760 {
8761         struct cmd_dump_result *res = parsed_result;
8762
8763         if (!strcmp(res->dump, "dump_physmem"))
8764                 rte_dump_physmem_layout(stdout);
8765         else if (!strcmp(res->dump, "dump_memzone"))
8766                 rte_memzone_dump(stdout);
8767         else if (!strcmp(res->dump, "dump_struct_sizes"))
8768                 dump_struct_sizes();
8769         else if (!strcmp(res->dump, "dump_ring"))
8770                 rte_ring_list_dump(stdout);
8771         else if (!strcmp(res->dump, "dump_mempool"))
8772                 rte_mempool_list_dump(stdout);
8773         else if (!strcmp(res->dump, "dump_devargs"))
8774                 rte_devargs_dump(stdout);
8775         else if (!strcmp(res->dump, "dump_log_types"))
8776                 rte_log_dump(stdout);
8777 }
8778
8779 cmdline_parse_token_string_t cmd_dump_dump =
8780         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8781                 "dump_physmem#"
8782                 "dump_memzone#"
8783                 "dump_struct_sizes#"
8784                 "dump_ring#"
8785                 "dump_mempool#"
8786                 "dump_devargs#"
8787                 "dump_log_types");
8788
8789 cmdline_parse_inst_t cmd_dump = {
8790         .f = cmd_dump_parsed,  /* function to call */
8791         .data = NULL,      /* 2nd arg of func */
8792         .help_str = "Dump status",
8793         .tokens = {        /* token list, NULL terminated */
8794                 (void *)&cmd_dump_dump,
8795                 NULL,
8796         },
8797 };
8798
8799 /* ******************************************************************************** */
8800
8801 struct cmd_dump_one_result {
8802         cmdline_fixed_string_t dump;
8803         cmdline_fixed_string_t name;
8804 };
8805
8806 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8807                                 __attribute__((unused)) void *data)
8808 {
8809         struct cmd_dump_one_result *res = parsed_result;
8810
8811         if (!strcmp(res->dump, "dump_ring")) {
8812                 struct rte_ring *r;
8813                 r = rte_ring_lookup(res->name);
8814                 if (r == NULL) {
8815                         cmdline_printf(cl, "Cannot find ring\n");
8816                         return;
8817                 }
8818                 rte_ring_dump(stdout, r);
8819         } else if (!strcmp(res->dump, "dump_mempool")) {
8820                 struct rte_mempool *mp;
8821                 mp = rte_mempool_lookup(res->name);
8822                 if (mp == NULL) {
8823                         cmdline_printf(cl, "Cannot find mempool\n");
8824                         return;
8825                 }
8826                 rte_mempool_dump(stdout, mp);
8827         }
8828 }
8829
8830 cmdline_parse_token_string_t cmd_dump_one_dump =
8831         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8832                                  "dump_ring#dump_mempool");
8833
8834 cmdline_parse_token_string_t cmd_dump_one_name =
8835         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8836
8837 cmdline_parse_inst_t cmd_dump_one = {
8838         .f = cmd_dump_one_parsed,  /* function to call */
8839         .data = NULL,      /* 2nd arg of func */
8840         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8841         .tokens = {        /* token list, NULL terminated */
8842                 (void *)&cmd_dump_one_dump,
8843                 (void *)&cmd_dump_one_name,
8844                 NULL,
8845         },
8846 };
8847
8848 /* *** Add/Del syn filter *** */
8849 struct cmd_syn_filter_result {
8850         cmdline_fixed_string_t filter;
8851         portid_t port_id;
8852         cmdline_fixed_string_t ops;
8853         cmdline_fixed_string_t priority;
8854         cmdline_fixed_string_t high;
8855         cmdline_fixed_string_t queue;
8856         uint16_t queue_id;
8857 };
8858
8859 static void
8860 cmd_syn_filter_parsed(void *parsed_result,
8861                         __attribute__((unused)) struct cmdline *cl,
8862                         __attribute__((unused)) void *data)
8863 {
8864         struct cmd_syn_filter_result *res = parsed_result;
8865         struct rte_eth_syn_filter syn_filter;
8866         int ret = 0;
8867
8868         ret = rte_eth_dev_filter_supported(res->port_id,
8869                                         RTE_ETH_FILTER_SYN);
8870         if (ret < 0) {
8871                 printf("syn filter is not supported on port %u.\n",
8872                                 res->port_id);
8873                 return;
8874         }
8875
8876         memset(&syn_filter, 0, sizeof(syn_filter));
8877
8878         if (!strcmp(res->ops, "add")) {
8879                 if (!strcmp(res->high, "high"))
8880                         syn_filter.hig_pri = 1;
8881                 else
8882                         syn_filter.hig_pri = 0;
8883
8884                 syn_filter.queue = res->queue_id;
8885                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8886                                                 RTE_ETH_FILTER_SYN,
8887                                                 RTE_ETH_FILTER_ADD,
8888                                                 &syn_filter);
8889         } else
8890                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8891                                                 RTE_ETH_FILTER_SYN,
8892                                                 RTE_ETH_FILTER_DELETE,
8893                                                 &syn_filter);
8894
8895         if (ret < 0)
8896                 printf("syn filter programming error: (%s)\n",
8897                                 strerror(-ret));
8898 }
8899
8900 cmdline_parse_token_string_t cmd_syn_filter_filter =
8901         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8902         filter, "syn_filter");
8903 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8904         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8905         port_id, UINT16);
8906 cmdline_parse_token_string_t cmd_syn_filter_ops =
8907         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8908         ops, "add#del");
8909 cmdline_parse_token_string_t cmd_syn_filter_priority =
8910         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8911                                 priority, "priority");
8912 cmdline_parse_token_string_t cmd_syn_filter_high =
8913         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8914                                 high, "high#low");
8915 cmdline_parse_token_string_t cmd_syn_filter_queue =
8916         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8917                                 queue, "queue");
8918 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8919         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8920                                 queue_id, UINT16);
8921
8922 cmdline_parse_inst_t cmd_syn_filter = {
8923         .f = cmd_syn_filter_parsed,
8924         .data = NULL,
8925         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8926                 "<queue_id>: Add/Delete syn filter",
8927         .tokens = {
8928                 (void *)&cmd_syn_filter_filter,
8929                 (void *)&cmd_syn_filter_port_id,
8930                 (void *)&cmd_syn_filter_ops,
8931                 (void *)&cmd_syn_filter_priority,
8932                 (void *)&cmd_syn_filter_high,
8933                 (void *)&cmd_syn_filter_queue,
8934                 (void *)&cmd_syn_filter_queue_id,
8935                 NULL,
8936         },
8937 };
8938
8939 /* *** queue region set *** */
8940 struct cmd_queue_region_result {
8941         cmdline_fixed_string_t set;
8942         cmdline_fixed_string_t port;
8943         portid_t port_id;
8944         cmdline_fixed_string_t cmd;
8945         cmdline_fixed_string_t region;
8946         uint8_t  region_id;
8947         cmdline_fixed_string_t queue_start_index;
8948         uint8_t  queue_id;
8949         cmdline_fixed_string_t queue_num;
8950         uint8_t  queue_num_value;
8951 };
8952
8953 static void
8954 cmd_queue_region_parsed(void *parsed_result,
8955                         __attribute__((unused)) struct cmdline *cl,
8956                         __attribute__((unused)) void *data)
8957 {
8958         struct cmd_queue_region_result *res = parsed_result;
8959         int ret = -ENOTSUP;
8960 #ifdef RTE_LIBRTE_I40E_PMD
8961         struct rte_pmd_i40e_queue_region_conf region_conf;
8962         enum rte_pmd_i40e_queue_region_op op_type;
8963 #endif
8964
8965         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8966                 return;
8967
8968 #ifdef RTE_LIBRTE_I40E_PMD
8969         memset(&region_conf, 0, sizeof(region_conf));
8970         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8971         region_conf.region_id = res->region_id;
8972         region_conf.queue_num = res->queue_num_value;
8973         region_conf.queue_start_index = res->queue_id;
8974
8975         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8976                                 op_type, &region_conf);
8977 #endif
8978
8979         switch (ret) {
8980         case 0:
8981                 break;
8982         case -ENOTSUP:
8983                 printf("function not implemented or supported\n");
8984                 break;
8985         default:
8986                 printf("queue region config error: (%s)\n", strerror(-ret));
8987         }
8988 }
8989
8990 cmdline_parse_token_string_t cmd_queue_region_set =
8991 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8992                 set, "set");
8993 cmdline_parse_token_string_t cmd_queue_region_port =
8994         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8995 cmdline_parse_token_num_t cmd_queue_region_port_id =
8996         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8997                                 port_id, UINT16);
8998 cmdline_parse_token_string_t cmd_queue_region_cmd =
8999         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9000                                  cmd, "queue-region");
9001 cmdline_parse_token_string_t cmd_queue_region_id =
9002         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9003                                 region, "region_id");
9004 cmdline_parse_token_num_t cmd_queue_region_index =
9005         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9006                                 region_id, UINT8);
9007 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9008         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9009                                 queue_start_index, "queue_start_index");
9010 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9011         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9012                                 queue_id, UINT8);
9013 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9014         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9015                                 queue_num, "queue_num");
9016 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9017         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9018                                 queue_num_value, UINT8);
9019
9020 cmdline_parse_inst_t cmd_queue_region = {
9021         .f = cmd_queue_region_parsed,
9022         .data = NULL,
9023         .help_str = "set port <port_id> queue-region region_id <value> "
9024                 "queue_start_index <value> queue_num <value>: Set a queue region",
9025         .tokens = {
9026                 (void *)&cmd_queue_region_set,
9027                 (void *)&cmd_queue_region_port,
9028                 (void *)&cmd_queue_region_port_id,
9029                 (void *)&cmd_queue_region_cmd,
9030                 (void *)&cmd_queue_region_id,
9031                 (void *)&cmd_queue_region_index,
9032                 (void *)&cmd_queue_region_queue_start_index,
9033                 (void *)&cmd_queue_region_queue_id,
9034                 (void *)&cmd_queue_region_queue_num,
9035                 (void *)&cmd_queue_region_queue_num_value,
9036                 NULL,
9037         },
9038 };
9039
9040 /* *** queue region and flowtype set *** */
9041 struct cmd_region_flowtype_result {
9042         cmdline_fixed_string_t set;
9043         cmdline_fixed_string_t port;
9044         portid_t port_id;
9045         cmdline_fixed_string_t cmd;
9046         cmdline_fixed_string_t region;
9047         uint8_t  region_id;
9048         cmdline_fixed_string_t flowtype;
9049         uint8_t  flowtype_id;
9050 };
9051
9052 static void
9053 cmd_region_flowtype_parsed(void *parsed_result,
9054                         __attribute__((unused)) struct cmdline *cl,
9055                         __attribute__((unused)) void *data)
9056 {
9057         struct cmd_region_flowtype_result *res = parsed_result;
9058         int ret = -ENOTSUP;
9059 #ifdef RTE_LIBRTE_I40E_PMD
9060         struct rte_pmd_i40e_queue_region_conf region_conf;
9061         enum rte_pmd_i40e_queue_region_op op_type;
9062 #endif
9063
9064         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9065                 return;
9066
9067 #ifdef RTE_LIBRTE_I40E_PMD
9068         memset(&region_conf, 0, sizeof(region_conf));
9069
9070         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9071         region_conf.region_id = res->region_id;
9072         region_conf.hw_flowtype = res->flowtype_id;
9073
9074         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9075                         op_type, &region_conf);
9076 #endif
9077
9078         switch (ret) {
9079         case 0:
9080                 break;
9081         case -ENOTSUP:
9082                 printf("function not implemented or supported\n");
9083                 break;
9084         default:
9085                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9086         }
9087 }
9088
9089 cmdline_parse_token_string_t cmd_region_flowtype_set =
9090 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9091                                 set, "set");
9092 cmdline_parse_token_string_t cmd_region_flowtype_port =
9093         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9094                                 port, "port");
9095 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9096         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9097                                 port_id, UINT16);
9098 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9099         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9100                                 cmd, "queue-region");
9101 cmdline_parse_token_string_t cmd_region_flowtype_index =
9102         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9103                                 region, "region_id");
9104 cmdline_parse_token_num_t cmd_region_flowtype_id =
9105         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9106                                 region_id, UINT8);
9107 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9108         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9109                                 flowtype, "flowtype");
9110 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9111         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9112                                 flowtype_id, UINT8);
9113 cmdline_parse_inst_t cmd_region_flowtype = {
9114         .f = cmd_region_flowtype_parsed,
9115         .data = NULL,
9116         .help_str = "set port <port_id> queue-region region_id <value> "
9117                 "flowtype <value>: Set a flowtype region index",
9118         .tokens = {
9119                 (void *)&cmd_region_flowtype_set,
9120                 (void *)&cmd_region_flowtype_port,
9121                 (void *)&cmd_region_flowtype_port_index,
9122                 (void *)&cmd_region_flowtype_cmd,
9123                 (void *)&cmd_region_flowtype_index,
9124                 (void *)&cmd_region_flowtype_id,
9125                 (void *)&cmd_region_flowtype_flow_index,
9126                 (void *)&cmd_region_flowtype_flow_id,
9127                 NULL,
9128         },
9129 };
9130
9131 /* *** User Priority (UP) to queue region (region_id) set *** */
9132 struct cmd_user_priority_region_result {
9133         cmdline_fixed_string_t set;
9134         cmdline_fixed_string_t port;
9135         portid_t port_id;
9136         cmdline_fixed_string_t cmd;
9137         cmdline_fixed_string_t user_priority;
9138         uint8_t  user_priority_id;
9139         cmdline_fixed_string_t region;
9140         uint8_t  region_id;
9141 };
9142
9143 static void
9144 cmd_user_priority_region_parsed(void *parsed_result,
9145                         __attribute__((unused)) struct cmdline *cl,
9146                         __attribute__((unused)) void *data)
9147 {
9148         struct cmd_user_priority_region_result *res = parsed_result;
9149         int ret = -ENOTSUP;
9150 #ifdef RTE_LIBRTE_I40E_PMD
9151         struct rte_pmd_i40e_queue_region_conf region_conf;
9152         enum rte_pmd_i40e_queue_region_op op_type;
9153 #endif
9154
9155         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9156                 return;
9157
9158 #ifdef RTE_LIBRTE_I40E_PMD
9159         memset(&region_conf, 0, sizeof(region_conf));
9160         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9161         region_conf.user_priority = res->user_priority_id;
9162         region_conf.region_id = res->region_id;
9163
9164         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9165                                 op_type, &region_conf);
9166 #endif
9167
9168         switch (ret) {
9169         case 0:
9170                 break;
9171         case -ENOTSUP:
9172                 printf("function not implemented or supported\n");
9173                 break;
9174         default:
9175                 printf("user_priority region config error: (%s)\n",
9176                                 strerror(-ret));
9177         }
9178 }
9179
9180 cmdline_parse_token_string_t cmd_user_priority_region_set =
9181         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9182                                 set, "set");
9183 cmdline_parse_token_string_t cmd_user_priority_region_port =
9184         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9185                                 port, "port");
9186 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9187         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9188                                 port_id, UINT16);
9189 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9190         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9191                                 cmd, "queue-region");
9192 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9193         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9194                                 user_priority, "UP");
9195 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9196         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9197                                 user_priority_id, UINT8);
9198 cmdline_parse_token_string_t cmd_user_priority_region_region =
9199         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9200                                 region, "region_id");
9201 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9202         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9203                                 region_id, UINT8);
9204
9205 cmdline_parse_inst_t cmd_user_priority_region = {
9206         .f = cmd_user_priority_region_parsed,
9207         .data = NULL,
9208         .help_str = "set port <port_id> queue-region UP <value> "
9209                 "region_id <value>: Set the mapping of User Priority (UP) "
9210                 "to queue region (region_id) ",
9211         .tokens = {
9212                 (void *)&cmd_user_priority_region_set,
9213                 (void *)&cmd_user_priority_region_port,
9214                 (void *)&cmd_user_priority_region_port_index,
9215                 (void *)&cmd_user_priority_region_cmd,
9216                 (void *)&cmd_user_priority_region_UP,
9217                 (void *)&cmd_user_priority_region_UP_id,
9218                 (void *)&cmd_user_priority_region_region,
9219                 (void *)&cmd_user_priority_region_region_id,
9220                 NULL,
9221         },
9222 };
9223
9224 /* *** flush all queue region related configuration *** */
9225 struct cmd_flush_queue_region_result {
9226         cmdline_fixed_string_t set;
9227         cmdline_fixed_string_t port;
9228         portid_t port_id;
9229         cmdline_fixed_string_t cmd;
9230         cmdline_fixed_string_t flush;
9231         cmdline_fixed_string_t what;
9232 };
9233
9234 static void
9235 cmd_flush_queue_region_parsed(void *parsed_result,
9236                         __attribute__((unused)) struct cmdline *cl,
9237                         __attribute__((unused)) void *data)
9238 {
9239         struct cmd_flush_queue_region_result *res = parsed_result;
9240         int ret = -ENOTSUP;
9241 #ifdef RTE_LIBRTE_I40E_PMD
9242         struct rte_pmd_i40e_queue_region_conf region_conf;
9243         enum rte_pmd_i40e_queue_region_op op_type;
9244 #endif
9245
9246         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9247                 return;
9248
9249 #ifdef RTE_LIBRTE_I40E_PMD
9250         memset(&region_conf, 0, sizeof(region_conf));
9251
9252         if (strcmp(res->what, "on") == 0)
9253                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9254         else
9255                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9256
9257         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9258                                 op_type, &region_conf);
9259 #endif
9260
9261         switch (ret) {
9262         case 0:
9263                 break;
9264         case -ENOTSUP:
9265                 printf("function not implemented or supported\n");
9266                 break;
9267         default:
9268                 printf("queue region config flush error: (%s)\n",
9269                                 strerror(-ret));
9270         }
9271 }
9272
9273 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9274         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9275                                 set, "set");
9276 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9277         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9278                                 port, "port");
9279 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9280         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9281                                 port_id, UINT16);
9282 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9283         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9284                                 cmd, "queue-region");
9285 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9286         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9287                                 flush, "flush");
9288 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9289         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9290                                 what, "on#off");
9291
9292 cmdline_parse_inst_t cmd_flush_queue_region = {
9293         .f = cmd_flush_queue_region_parsed,
9294         .data = NULL,
9295         .help_str = "set port <port_id> queue-region flush on|off"
9296                 ": flush all queue region related configuration",
9297         .tokens = {
9298                 (void *)&cmd_flush_queue_region_set,
9299                 (void *)&cmd_flush_queue_region_port,
9300                 (void *)&cmd_flush_queue_region_port_index,
9301                 (void *)&cmd_flush_queue_region_cmd,
9302                 (void *)&cmd_flush_queue_region_flush,
9303                 (void *)&cmd_flush_queue_region_what,
9304                 NULL,
9305         },
9306 };
9307
9308 /* *** get all queue region related configuration info *** */
9309 struct cmd_show_queue_region_info {
9310         cmdline_fixed_string_t show;
9311         cmdline_fixed_string_t port;
9312         portid_t port_id;
9313         cmdline_fixed_string_t cmd;
9314 };
9315
9316 static void
9317 cmd_show_queue_region_info_parsed(void *parsed_result,
9318                         __attribute__((unused)) struct cmdline *cl,
9319                         __attribute__((unused)) void *data)
9320 {
9321         struct cmd_show_queue_region_info *res = parsed_result;
9322         int ret = -ENOTSUP;
9323 #ifdef RTE_LIBRTE_I40E_PMD
9324         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9325         enum rte_pmd_i40e_queue_region_op op_type;
9326 #endif
9327
9328         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9329                 return;
9330
9331 #ifdef RTE_LIBRTE_I40E_PMD
9332         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9333
9334         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9335
9336         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9337                                         op_type, &rte_pmd_regions);
9338
9339         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9340 #endif
9341
9342         switch (ret) {
9343         case 0:
9344                 break;
9345         case -ENOTSUP:
9346                 printf("function not implemented or supported\n");
9347                 break;
9348         default:
9349                 printf("queue region config info show error: (%s)\n",
9350                                 strerror(-ret));
9351         }
9352 }
9353
9354 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9355 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9356                                 show, "show");
9357 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9358         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9359                                 port, "port");
9360 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9361         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9362                                 port_id, UINT16);
9363 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9364         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9365                                 cmd, "queue-region");
9366
9367 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9368         .f = cmd_show_queue_region_info_parsed,
9369         .data = NULL,
9370         .help_str = "show port <port_id> queue-region"
9371                 ": show all queue region related configuration info",
9372         .tokens = {
9373                 (void *)&cmd_show_queue_region_info_get,
9374                 (void *)&cmd_show_queue_region_info_port,
9375                 (void *)&cmd_show_queue_region_info_port_index,
9376                 (void *)&cmd_show_queue_region_info_cmd,
9377                 NULL,
9378         },
9379 };
9380
9381 /* *** ADD/REMOVE A 2tuple FILTER *** */
9382 struct cmd_2tuple_filter_result {
9383         cmdline_fixed_string_t filter;
9384         portid_t port_id;
9385         cmdline_fixed_string_t ops;
9386         cmdline_fixed_string_t dst_port;
9387         uint16_t dst_port_value;
9388         cmdline_fixed_string_t protocol;
9389         uint8_t protocol_value;
9390         cmdline_fixed_string_t mask;
9391         uint8_t  mask_value;
9392         cmdline_fixed_string_t tcp_flags;
9393         uint8_t tcp_flags_value;
9394         cmdline_fixed_string_t priority;
9395         uint8_t  priority_value;
9396         cmdline_fixed_string_t queue;
9397         uint16_t  queue_id;
9398 };
9399
9400 static void
9401 cmd_2tuple_filter_parsed(void *parsed_result,
9402                         __attribute__((unused)) struct cmdline *cl,
9403                         __attribute__((unused)) void *data)
9404 {
9405         struct rte_eth_ntuple_filter filter;
9406         struct cmd_2tuple_filter_result *res = parsed_result;
9407         int ret = 0;
9408
9409         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9410         if (ret < 0) {
9411                 printf("ntuple filter is not supported on port %u.\n",
9412                         res->port_id);
9413                 return;
9414         }
9415
9416         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9417
9418         filter.flags = RTE_2TUPLE_FLAGS;
9419         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9420         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9421         filter.proto = res->protocol_value;
9422         filter.priority = res->priority_value;
9423         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9424                 printf("nonzero tcp_flags is only meaningful"
9425                         " when protocol is TCP.\n");
9426                 return;
9427         }
9428         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9429                 printf("invalid TCP flags.\n");
9430                 return;
9431         }
9432
9433         if (res->tcp_flags_value != 0) {
9434                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9435                 filter.tcp_flags = res->tcp_flags_value;
9436         }
9437
9438         /* need convert to big endian. */
9439         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9440         filter.queue = res->queue_id;
9441
9442         if (!strcmp(res->ops, "add"))
9443                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9444                                 RTE_ETH_FILTER_NTUPLE,
9445                                 RTE_ETH_FILTER_ADD,
9446                                 &filter);
9447         else
9448                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9449                                 RTE_ETH_FILTER_NTUPLE,
9450                                 RTE_ETH_FILTER_DELETE,
9451                                 &filter);
9452         if (ret < 0)
9453                 printf("2tuple filter programming error: (%s)\n",
9454                         strerror(-ret));
9455
9456 }
9457
9458 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9459         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9460                                  filter, "2tuple_filter");
9461 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9462         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9463                                 port_id, UINT16);
9464 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9465         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9466                                  ops, "add#del");
9467 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9468         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9469                                 dst_port, "dst_port");
9470 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9471         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9472                                 dst_port_value, UINT16);
9473 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9474         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9475                                 protocol, "protocol");
9476 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9477         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9478                                 protocol_value, UINT8);
9479 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9480         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9481                                 mask, "mask");
9482 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9483         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9484                                 mask_value, INT8);
9485 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9486         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9487                                 tcp_flags, "tcp_flags");
9488 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9489         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9490                                 tcp_flags_value, UINT8);
9491 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9492         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9493                                 priority, "priority");
9494 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9495         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9496                                 priority_value, UINT8);
9497 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9498         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9499                                 queue, "queue");
9500 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9501         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9502                                 queue_id, UINT16);
9503
9504 cmdline_parse_inst_t cmd_2tuple_filter = {
9505         .f = cmd_2tuple_filter_parsed,
9506         .data = NULL,
9507         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9508                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9509                 "<queue_id>: Add a 2tuple filter",
9510         .tokens = {
9511                 (void *)&cmd_2tuple_filter_filter,
9512                 (void *)&cmd_2tuple_filter_port_id,
9513                 (void *)&cmd_2tuple_filter_ops,
9514                 (void *)&cmd_2tuple_filter_dst_port,
9515                 (void *)&cmd_2tuple_filter_dst_port_value,
9516                 (void *)&cmd_2tuple_filter_protocol,
9517                 (void *)&cmd_2tuple_filter_protocol_value,
9518                 (void *)&cmd_2tuple_filter_mask,
9519                 (void *)&cmd_2tuple_filter_mask_value,
9520                 (void *)&cmd_2tuple_filter_tcp_flags,
9521                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9522                 (void *)&cmd_2tuple_filter_priority,
9523                 (void *)&cmd_2tuple_filter_priority_value,
9524                 (void *)&cmd_2tuple_filter_queue,
9525                 (void *)&cmd_2tuple_filter_queue_id,
9526                 NULL,
9527         },
9528 };
9529
9530 /* *** ADD/REMOVE A 5tuple FILTER *** */
9531 struct cmd_5tuple_filter_result {
9532         cmdline_fixed_string_t filter;
9533         portid_t port_id;
9534         cmdline_fixed_string_t ops;
9535         cmdline_fixed_string_t dst_ip;
9536         cmdline_ipaddr_t dst_ip_value;
9537         cmdline_fixed_string_t src_ip;
9538         cmdline_ipaddr_t src_ip_value;
9539         cmdline_fixed_string_t dst_port;
9540         uint16_t dst_port_value;
9541         cmdline_fixed_string_t src_port;
9542         uint16_t src_port_value;
9543         cmdline_fixed_string_t protocol;
9544         uint8_t protocol_value;
9545         cmdline_fixed_string_t mask;
9546         uint8_t  mask_value;
9547         cmdline_fixed_string_t tcp_flags;
9548         uint8_t tcp_flags_value;
9549         cmdline_fixed_string_t priority;
9550         uint8_t  priority_value;
9551         cmdline_fixed_string_t queue;
9552         uint16_t  queue_id;
9553 };
9554
9555 static void
9556 cmd_5tuple_filter_parsed(void *parsed_result,
9557                         __attribute__((unused)) struct cmdline *cl,
9558                         __attribute__((unused)) void *data)
9559 {
9560         struct rte_eth_ntuple_filter filter;
9561         struct cmd_5tuple_filter_result *res = parsed_result;
9562         int ret = 0;
9563
9564         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9565         if (ret < 0) {
9566                 printf("ntuple filter is not supported on port %u.\n",
9567                         res->port_id);
9568                 return;
9569         }
9570
9571         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9572
9573         filter.flags = RTE_5TUPLE_FLAGS;
9574         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9575         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9576         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9577         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9578         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9579         filter.proto = res->protocol_value;
9580         filter.priority = res->priority_value;
9581         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9582                 printf("nonzero tcp_flags is only meaningful"
9583                         " when protocol is TCP.\n");
9584                 return;
9585         }
9586         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9587                 printf("invalid TCP flags.\n");
9588                 return;
9589         }
9590
9591         if (res->tcp_flags_value != 0) {
9592                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9593                 filter.tcp_flags = res->tcp_flags_value;
9594         }
9595
9596         if (res->dst_ip_value.family == AF_INET)
9597                 /* no need to convert, already big endian. */
9598                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9599         else {
9600                 if (filter.dst_ip_mask == 0) {
9601                         printf("can not support ipv6 involved compare.\n");
9602                         return;
9603                 }
9604                 filter.dst_ip = 0;
9605         }
9606
9607         if (res->src_ip_value.family == AF_INET)
9608                 /* no need to convert, already big endian. */
9609                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9610         else {
9611                 if (filter.src_ip_mask == 0) {
9612                         printf("can not support ipv6 involved compare.\n");
9613                         return;
9614                 }
9615                 filter.src_ip = 0;
9616         }
9617         /* need convert to big endian. */
9618         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9619         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9620         filter.queue = res->queue_id;
9621
9622         if (!strcmp(res->ops, "add"))
9623                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9624                                 RTE_ETH_FILTER_NTUPLE,
9625                                 RTE_ETH_FILTER_ADD,
9626                                 &filter);
9627         else
9628                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9629                                 RTE_ETH_FILTER_NTUPLE,
9630                                 RTE_ETH_FILTER_DELETE,
9631                                 &filter);
9632         if (ret < 0)
9633                 printf("5tuple filter programming error: (%s)\n",
9634                         strerror(-ret));
9635 }
9636
9637 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9638         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9639                                  filter, "5tuple_filter");
9640 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9641         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9642                                 port_id, UINT16);
9643 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9644         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9645                                  ops, "add#del");
9646 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9647         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9648                                 dst_ip, "dst_ip");
9649 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9650         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9651                                 dst_ip_value);
9652 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9653         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9654                                 src_ip, "src_ip");
9655 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9656         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9657                                 src_ip_value);
9658 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9659         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9660                                 dst_port, "dst_port");
9661 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9662         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9663                                 dst_port_value, UINT16);
9664 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9665         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9666                                 src_port, "src_port");
9667 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9668         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9669                                 src_port_value, UINT16);
9670 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9671         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9672                                 protocol, "protocol");
9673 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9674         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9675                                 protocol_value, UINT8);
9676 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9677         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9678                                 mask, "mask");
9679 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9680         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9681                                 mask_value, INT8);
9682 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9683         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9684                                 tcp_flags, "tcp_flags");
9685 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9686         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9687                                 tcp_flags_value, UINT8);
9688 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9689         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9690                                 priority, "priority");
9691 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9692         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9693                                 priority_value, UINT8);
9694 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9695         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9696                                 queue, "queue");
9697 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9698         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9699                                 queue_id, UINT16);
9700
9701 cmdline_parse_inst_t cmd_5tuple_filter = {
9702         .f = cmd_5tuple_filter_parsed,
9703         .data = NULL,
9704         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9705                 "src_ip <value> dst_port <value> src_port <value> "
9706                 "protocol <value>  mask <value> tcp_flags <value> "
9707                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9708         .tokens = {
9709                 (void *)&cmd_5tuple_filter_filter,
9710                 (void *)&cmd_5tuple_filter_port_id,
9711                 (void *)&cmd_5tuple_filter_ops,
9712                 (void *)&cmd_5tuple_filter_dst_ip,
9713                 (void *)&cmd_5tuple_filter_dst_ip_value,
9714                 (void *)&cmd_5tuple_filter_src_ip,
9715                 (void *)&cmd_5tuple_filter_src_ip_value,
9716                 (void *)&cmd_5tuple_filter_dst_port,
9717                 (void *)&cmd_5tuple_filter_dst_port_value,
9718                 (void *)&cmd_5tuple_filter_src_port,
9719                 (void *)&cmd_5tuple_filter_src_port_value,
9720                 (void *)&cmd_5tuple_filter_protocol,
9721                 (void *)&cmd_5tuple_filter_protocol_value,
9722                 (void *)&cmd_5tuple_filter_mask,
9723                 (void *)&cmd_5tuple_filter_mask_value,
9724                 (void *)&cmd_5tuple_filter_tcp_flags,
9725                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9726                 (void *)&cmd_5tuple_filter_priority,
9727                 (void *)&cmd_5tuple_filter_priority_value,
9728                 (void *)&cmd_5tuple_filter_queue,
9729                 (void *)&cmd_5tuple_filter_queue_id,
9730                 NULL,
9731         },
9732 };
9733
9734 /* *** ADD/REMOVE A flex FILTER *** */
9735 struct cmd_flex_filter_result {
9736         cmdline_fixed_string_t filter;
9737         cmdline_fixed_string_t ops;
9738         portid_t port_id;
9739         cmdline_fixed_string_t len;
9740         uint8_t len_value;
9741         cmdline_fixed_string_t bytes;
9742         cmdline_fixed_string_t bytes_value;
9743         cmdline_fixed_string_t mask;
9744         cmdline_fixed_string_t mask_value;
9745         cmdline_fixed_string_t priority;
9746         uint8_t priority_value;
9747         cmdline_fixed_string_t queue;
9748         uint16_t queue_id;
9749 };
9750
9751 static int xdigit2val(unsigned char c)
9752 {
9753         int val;
9754         if (isdigit(c))
9755                 val = c - '0';
9756         else if (isupper(c))
9757                 val = c - 'A' + 10;
9758         else
9759                 val = c - 'a' + 10;
9760         return val;
9761 }
9762
9763 static void
9764 cmd_flex_filter_parsed(void *parsed_result,
9765                           __attribute__((unused)) struct cmdline *cl,
9766                           __attribute__((unused)) void *data)
9767 {
9768         int ret = 0;
9769         struct rte_eth_flex_filter filter;
9770         struct cmd_flex_filter_result *res = parsed_result;
9771         char *bytes_ptr, *mask_ptr;
9772         uint16_t len, i, j = 0;
9773         char c;
9774         int val;
9775         uint8_t byte = 0;
9776
9777         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9778                 printf("the len exceed the max length 128\n");
9779                 return;
9780         }
9781         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9782         filter.len = res->len_value;
9783         filter.priority = res->priority_value;
9784         filter.queue = res->queue_id;
9785         bytes_ptr = res->bytes_value;
9786         mask_ptr = res->mask_value;
9787
9788          /* translate bytes string to array. */
9789         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9790                 (bytes_ptr[1] == 'X')))
9791                 bytes_ptr += 2;
9792         len = strnlen(bytes_ptr, res->len_value * 2);
9793         if (len == 0 || (len % 8 != 0)) {
9794                 printf("please check len and bytes input\n");
9795                 return;
9796         }
9797         for (i = 0; i < len; i++) {
9798                 c = bytes_ptr[i];
9799                 if (isxdigit(c) == 0) {
9800                         /* invalid characters. */
9801                         printf("invalid input\n");
9802                         return;
9803                 }
9804                 val = xdigit2val(c);
9805                 if (i % 2) {
9806                         byte |= val;
9807                         filter.bytes[j] = byte;
9808                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9809                         j++;
9810                         byte = 0;
9811                 } else
9812                         byte |= val << 4;
9813         }
9814         printf("\n");
9815          /* translate mask string to uint8_t array. */
9816         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9817                 (mask_ptr[1] == 'X')))
9818                 mask_ptr += 2;
9819         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9820         if (len == 0) {
9821                 printf("invalid input\n");
9822                 return;
9823         }
9824         j = 0;
9825         byte = 0;
9826         for (i = 0; i < len; i++) {
9827                 c = mask_ptr[i];
9828                 if (isxdigit(c) == 0) {
9829                         /* invalid characters. */
9830                         printf("invalid input\n");
9831                         return;
9832                 }
9833                 val = xdigit2val(c);
9834                 if (i % 2) {
9835                         byte |= val;
9836                         filter.mask[j] = byte;
9837                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9838                         j++;
9839                         byte = 0;
9840                 } else
9841                         byte |= val << 4;
9842         }
9843         printf("\n");
9844
9845         if (!strcmp(res->ops, "add"))
9846                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9847                                 RTE_ETH_FILTER_FLEXIBLE,
9848                                 RTE_ETH_FILTER_ADD,
9849                                 &filter);
9850         else
9851                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9852                                 RTE_ETH_FILTER_FLEXIBLE,
9853                                 RTE_ETH_FILTER_DELETE,
9854                                 &filter);
9855
9856         if (ret < 0)
9857                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9858 }
9859
9860 cmdline_parse_token_string_t cmd_flex_filter_filter =
9861         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9862                                 filter, "flex_filter");
9863 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9864         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9865                                 port_id, UINT16);
9866 cmdline_parse_token_string_t cmd_flex_filter_ops =
9867         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9868                                 ops, "add#del");
9869 cmdline_parse_token_string_t cmd_flex_filter_len =
9870         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9871                                 len, "len");
9872 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9873         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9874                                 len_value, UINT8);
9875 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9876         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9877                                 bytes, "bytes");
9878 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9879         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9880                                 bytes_value, NULL);
9881 cmdline_parse_token_string_t cmd_flex_filter_mask =
9882         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9883                                 mask, "mask");
9884 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9885         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9886                                 mask_value, NULL);
9887 cmdline_parse_token_string_t cmd_flex_filter_priority =
9888         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9889                                 priority, "priority");
9890 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9891         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9892                                 priority_value, UINT8);
9893 cmdline_parse_token_string_t cmd_flex_filter_queue =
9894         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9895                                 queue, "queue");
9896 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9897         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9898                                 queue_id, UINT16);
9899 cmdline_parse_inst_t cmd_flex_filter = {
9900         .f = cmd_flex_filter_parsed,
9901         .data = NULL,
9902         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9903                 "<value> mask <value> priority <value> queue <queue_id>: "
9904                 "Add/Del a flex filter",
9905         .tokens = {
9906                 (void *)&cmd_flex_filter_filter,
9907                 (void *)&cmd_flex_filter_port_id,
9908                 (void *)&cmd_flex_filter_ops,
9909                 (void *)&cmd_flex_filter_len,
9910                 (void *)&cmd_flex_filter_len_value,
9911                 (void *)&cmd_flex_filter_bytes,
9912                 (void *)&cmd_flex_filter_bytes_value,
9913                 (void *)&cmd_flex_filter_mask,
9914                 (void *)&cmd_flex_filter_mask_value,
9915                 (void *)&cmd_flex_filter_priority,
9916                 (void *)&cmd_flex_filter_priority_value,
9917                 (void *)&cmd_flex_filter_queue,
9918                 (void *)&cmd_flex_filter_queue_id,
9919                 NULL,
9920         },
9921 };
9922
9923 /* *** Filters Control *** */
9924
9925 /* *** deal with ethertype filter *** */
9926 struct cmd_ethertype_filter_result {
9927         cmdline_fixed_string_t filter;
9928         portid_t port_id;
9929         cmdline_fixed_string_t ops;
9930         cmdline_fixed_string_t mac;
9931         struct ether_addr mac_addr;
9932         cmdline_fixed_string_t ethertype;
9933         uint16_t ethertype_value;
9934         cmdline_fixed_string_t drop;
9935         cmdline_fixed_string_t queue;
9936         uint16_t  queue_id;
9937 };
9938
9939 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9940         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9941                                  filter, "ethertype_filter");
9942 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9943         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9944                               port_id, UINT16);
9945 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9946         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9947                                  ops, "add#del");
9948 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9949         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9950                                  mac, "mac_addr#mac_ignr");
9951 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9952         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9953                                      mac_addr);
9954 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9955         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9956                                  ethertype, "ethertype");
9957 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9958         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9959                               ethertype_value, UINT16);
9960 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9961         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9962                                  drop, "drop#fwd");
9963 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9964         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9965                                  queue, "queue");
9966 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9967         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9968                               queue_id, UINT16);
9969
9970 static void
9971 cmd_ethertype_filter_parsed(void *parsed_result,
9972                           __attribute__((unused)) struct cmdline *cl,
9973                           __attribute__((unused)) void *data)
9974 {
9975         struct cmd_ethertype_filter_result *res = parsed_result;
9976         struct rte_eth_ethertype_filter filter;
9977         int ret = 0;
9978
9979         ret = rte_eth_dev_filter_supported(res->port_id,
9980                         RTE_ETH_FILTER_ETHERTYPE);
9981         if (ret < 0) {
9982                 printf("ethertype filter is not supported on port %u.\n",
9983                         res->port_id);
9984                 return;
9985         }
9986
9987         memset(&filter, 0, sizeof(filter));
9988         if (!strcmp(res->mac, "mac_addr")) {
9989                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9990                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9991                         sizeof(struct ether_addr));
9992         }
9993         if (!strcmp(res->drop, "drop"))
9994                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9995         filter.ether_type = res->ethertype_value;
9996         filter.queue = res->queue_id;
9997
9998         if (!strcmp(res->ops, "add"))
9999                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10000                                 RTE_ETH_FILTER_ETHERTYPE,
10001                                 RTE_ETH_FILTER_ADD,
10002                                 &filter);
10003         else
10004                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10005                                 RTE_ETH_FILTER_ETHERTYPE,
10006                                 RTE_ETH_FILTER_DELETE,
10007                                 &filter);
10008         if (ret < 0)
10009                 printf("ethertype filter programming error: (%s)\n",
10010                         strerror(-ret));
10011 }
10012
10013 cmdline_parse_inst_t cmd_ethertype_filter = {
10014         .f = cmd_ethertype_filter_parsed,
10015         .data = NULL,
10016         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10017                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10018                 "Add or delete an ethertype filter entry",
10019         .tokens = {
10020                 (void *)&cmd_ethertype_filter_filter,
10021                 (void *)&cmd_ethertype_filter_port_id,
10022                 (void *)&cmd_ethertype_filter_ops,
10023                 (void *)&cmd_ethertype_filter_mac,
10024                 (void *)&cmd_ethertype_filter_mac_addr,
10025                 (void *)&cmd_ethertype_filter_ethertype,
10026                 (void *)&cmd_ethertype_filter_ethertype_value,
10027                 (void *)&cmd_ethertype_filter_drop,
10028                 (void *)&cmd_ethertype_filter_queue,
10029                 (void *)&cmd_ethertype_filter_queue_id,
10030                 NULL,
10031         },
10032 };
10033
10034 /* *** deal with flow director filter *** */
10035 struct cmd_flow_director_result {
10036         cmdline_fixed_string_t flow_director_filter;
10037         portid_t port_id;
10038         cmdline_fixed_string_t mode;
10039         cmdline_fixed_string_t mode_value;
10040         cmdline_fixed_string_t ops;
10041         cmdline_fixed_string_t flow;
10042         cmdline_fixed_string_t flow_type;
10043         cmdline_fixed_string_t ether;
10044         uint16_t ether_type;
10045         cmdline_fixed_string_t src;
10046         cmdline_ipaddr_t ip_src;
10047         uint16_t port_src;
10048         cmdline_fixed_string_t dst;
10049         cmdline_ipaddr_t ip_dst;
10050         uint16_t port_dst;
10051         cmdline_fixed_string_t verify_tag;
10052         uint32_t verify_tag_value;
10053         cmdline_fixed_string_t tos;
10054         uint8_t tos_value;
10055         cmdline_fixed_string_t proto;
10056         uint8_t proto_value;
10057         cmdline_fixed_string_t ttl;
10058         uint8_t ttl_value;
10059         cmdline_fixed_string_t vlan;
10060         uint16_t vlan_value;
10061         cmdline_fixed_string_t flexbytes;
10062         cmdline_fixed_string_t flexbytes_value;
10063         cmdline_fixed_string_t pf_vf;
10064         cmdline_fixed_string_t drop;
10065         cmdline_fixed_string_t queue;
10066         uint16_t  queue_id;
10067         cmdline_fixed_string_t fd_id;
10068         uint32_t  fd_id_value;
10069         cmdline_fixed_string_t mac;
10070         struct ether_addr mac_addr;
10071         cmdline_fixed_string_t tunnel;
10072         cmdline_fixed_string_t tunnel_type;
10073         cmdline_fixed_string_t tunnel_id;
10074         uint32_t tunnel_id_value;
10075         cmdline_fixed_string_t packet;
10076         char filepath[];
10077 };
10078
10079 static inline int
10080 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10081 {
10082         char s[256];
10083         const char *p, *p0 = q_arg;
10084         char *end;
10085         unsigned long int_fld;
10086         char *str_fld[max_num];
10087         int i;
10088         unsigned size;
10089         int ret = -1;
10090
10091         p = strchr(p0, '(');
10092         if (p == NULL)
10093                 return -1;
10094         ++p;
10095         p0 = strchr(p, ')');
10096         if (p0 == NULL)
10097                 return -1;
10098
10099         size = p0 - p;
10100         if (size >= sizeof(s))
10101                 return -1;
10102
10103         snprintf(s, sizeof(s), "%.*s", size, p);
10104         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10105         if (ret < 0 || ret > max_num)
10106                 return -1;
10107         for (i = 0; i < ret; i++) {
10108                 errno = 0;
10109                 int_fld = strtoul(str_fld[i], &end, 0);
10110                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10111                         return -1;
10112                 flexbytes[i] = (uint8_t)int_fld;
10113         }
10114         return ret;
10115 }
10116
10117 static uint16_t
10118 str2flowtype(char *string)
10119 {
10120         uint8_t i = 0;
10121         static const struct {
10122                 char str[32];
10123                 uint16_t type;
10124         } flowtype_str[] = {
10125                 {"raw", RTE_ETH_FLOW_RAW},
10126                 {"ipv4", RTE_ETH_FLOW_IPV4},
10127                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10128                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10129                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10130                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10131                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10132                 {"ipv6", RTE_ETH_FLOW_IPV6},
10133                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10134                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10135                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10136                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10137                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10138                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10139         };
10140
10141         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10142                 if (!strcmp(flowtype_str[i].str, string))
10143                         return flowtype_str[i].type;
10144         }
10145
10146         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10147                 return (uint16_t)atoi(string);
10148
10149         return RTE_ETH_FLOW_UNKNOWN;
10150 }
10151
10152 static enum rte_eth_fdir_tunnel_type
10153 str2fdir_tunneltype(char *string)
10154 {
10155         uint8_t i = 0;
10156
10157         static const struct {
10158                 char str[32];
10159                 enum rte_eth_fdir_tunnel_type type;
10160         } tunneltype_str[] = {
10161                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10162                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10163         };
10164
10165         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10166                 if (!strcmp(tunneltype_str[i].str, string))
10167                         return tunneltype_str[i].type;
10168         }
10169         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10170 }
10171
10172 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10173 do { \
10174         if ((ip_addr).family == AF_INET) \
10175                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10176         else { \
10177                 printf("invalid parameter.\n"); \
10178                 return; \
10179         } \
10180 } while (0)
10181
10182 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10183 do { \
10184         if ((ip_addr).family == AF_INET6) \
10185                 rte_memcpy(&(ip), \
10186                                  &((ip_addr).addr.ipv6), \
10187                                  sizeof(struct in6_addr)); \
10188         else { \
10189                 printf("invalid parameter.\n"); \
10190                 return; \
10191         } \
10192 } while (0)
10193
10194 static void
10195 cmd_flow_director_filter_parsed(void *parsed_result,
10196                           __attribute__((unused)) struct cmdline *cl,
10197                           __attribute__((unused)) void *data)
10198 {
10199         struct cmd_flow_director_result *res = parsed_result;
10200         struct rte_eth_fdir_filter entry;
10201         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10202         char *end;
10203         unsigned long vf_id;
10204         int ret = 0;
10205
10206         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10207         if (ret < 0) {
10208                 printf("flow director is not supported on port %u.\n",
10209                         res->port_id);
10210                 return;
10211         }
10212         memset(flexbytes, 0, sizeof(flexbytes));
10213         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10214
10215         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10216                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10217                         printf("Please set mode to MAC-VLAN.\n");
10218                         return;
10219                 }
10220         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10221                 if (strcmp(res->mode_value, "Tunnel")) {
10222                         printf("Please set mode to Tunnel.\n");
10223                         return;
10224                 }
10225         } else {
10226                 if (!strcmp(res->mode_value, "raw")) {
10227 #ifdef RTE_LIBRTE_I40E_PMD
10228                         struct rte_pmd_i40e_flow_type_mapping
10229                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10230                         struct rte_pmd_i40e_pkt_template_conf conf;
10231                         uint16_t flow_type = str2flowtype(res->flow_type);
10232                         uint16_t i, port = res->port_id;
10233                         uint8_t add;
10234
10235                         memset(&conf, 0, sizeof(conf));
10236
10237                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10238                                 printf("Invalid flow type specified.\n");
10239                                 return;
10240                         }
10241                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10242                                                                  mapping);
10243                         if (ret)
10244                                 return;
10245                         if (mapping[flow_type].pctype == 0ULL) {
10246                                 printf("Invalid flow type specified.\n");
10247                                 return;
10248                         }
10249                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10250                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10251                                         conf.input.pctype = i;
10252                                         break;
10253                                 }
10254                         }
10255
10256                         conf.input.packet = open_file(res->filepath,
10257                                                 &conf.input.length);
10258                         if (!conf.input.packet)
10259                                 return;
10260                         if (!strcmp(res->drop, "drop"))
10261                                 conf.action.behavior =
10262                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10263                         else
10264                                 conf.action.behavior =
10265                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10266                         conf.action.report_status =
10267                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10268                         conf.action.rx_queue = res->queue_id;
10269                         conf.soft_id = res->fd_id_value;
10270                         add  = strcmp(res->ops, "del") ? 1 : 0;
10271                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10272                                                                         &conf,
10273                                                                         add);
10274                         if (ret < 0)
10275                                 printf("flow director config error: (%s)\n",
10276                                        strerror(-ret));
10277                         close_file(conf.input.packet);
10278 #endif
10279                         return;
10280                 } else if (strcmp(res->mode_value, "IP")) {
10281                         printf("Please set mode to IP or raw.\n");
10282                         return;
10283                 }
10284                 entry.input.flow_type = str2flowtype(res->flow_type);
10285         }
10286
10287         ret = parse_flexbytes(res->flexbytes_value,
10288                                         flexbytes,
10289                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10290         if (ret < 0) {
10291                 printf("error: Cannot parse flexbytes input.\n");
10292                 return;
10293         }
10294
10295         switch (entry.input.flow_type) {
10296         case RTE_ETH_FLOW_FRAG_IPV4:
10297         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10298                 entry.input.flow.ip4_flow.proto = res->proto_value;
10299                 /* fall-through */
10300         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10301         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10302                 IPV4_ADDR_TO_UINT(res->ip_dst,
10303                         entry.input.flow.ip4_flow.dst_ip);
10304                 IPV4_ADDR_TO_UINT(res->ip_src,
10305                         entry.input.flow.ip4_flow.src_ip);
10306                 entry.input.flow.ip4_flow.tos = res->tos_value;
10307                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10308                 /* need convert to big endian. */
10309                 entry.input.flow.udp4_flow.dst_port =
10310                                 rte_cpu_to_be_16(res->port_dst);
10311                 entry.input.flow.udp4_flow.src_port =
10312                                 rte_cpu_to_be_16(res->port_src);
10313                 break;
10314         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10315                 IPV4_ADDR_TO_UINT(res->ip_dst,
10316                         entry.input.flow.sctp4_flow.ip.dst_ip);
10317                 IPV4_ADDR_TO_UINT(res->ip_src,
10318                         entry.input.flow.sctp4_flow.ip.src_ip);
10319                 entry.input.flow.ip4_flow.tos = res->tos_value;
10320                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10321                 /* need convert to big endian. */
10322                 entry.input.flow.sctp4_flow.dst_port =
10323                                 rte_cpu_to_be_16(res->port_dst);
10324                 entry.input.flow.sctp4_flow.src_port =
10325                                 rte_cpu_to_be_16(res->port_src);
10326                 entry.input.flow.sctp4_flow.verify_tag =
10327                                 rte_cpu_to_be_32(res->verify_tag_value);
10328                 break;
10329         case RTE_ETH_FLOW_FRAG_IPV6:
10330         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10331                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10332                 /* fall-through */
10333         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10334         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10335                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10336                         entry.input.flow.ipv6_flow.dst_ip);
10337                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10338                         entry.input.flow.ipv6_flow.src_ip);
10339                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10340                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10341                 /* need convert to big endian. */
10342                 entry.input.flow.udp6_flow.dst_port =
10343                                 rte_cpu_to_be_16(res->port_dst);
10344                 entry.input.flow.udp6_flow.src_port =
10345                                 rte_cpu_to_be_16(res->port_src);
10346                 break;
10347         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10348                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10349                         entry.input.flow.sctp6_flow.ip.dst_ip);
10350                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10351                         entry.input.flow.sctp6_flow.ip.src_ip);
10352                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10353                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10354                 /* need convert to big endian. */
10355                 entry.input.flow.sctp6_flow.dst_port =
10356                                 rte_cpu_to_be_16(res->port_dst);
10357                 entry.input.flow.sctp6_flow.src_port =
10358                                 rte_cpu_to_be_16(res->port_src);
10359                 entry.input.flow.sctp6_flow.verify_tag =
10360                                 rte_cpu_to_be_32(res->verify_tag_value);
10361                 break;
10362         case RTE_ETH_FLOW_L2_PAYLOAD:
10363                 entry.input.flow.l2_flow.ether_type =
10364                         rte_cpu_to_be_16(res->ether_type);
10365                 break;
10366         default:
10367                 break;
10368         }
10369
10370         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10371                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10372                                  &res->mac_addr,
10373                                  sizeof(struct ether_addr));
10374
10375         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10376                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10377                                  &res->mac_addr,
10378                                  sizeof(struct ether_addr));
10379                 entry.input.flow.tunnel_flow.tunnel_type =
10380                         str2fdir_tunneltype(res->tunnel_type);
10381                 entry.input.flow.tunnel_flow.tunnel_id =
10382                         rte_cpu_to_be_32(res->tunnel_id_value);
10383         }
10384
10385         rte_memcpy(entry.input.flow_ext.flexbytes,
10386                    flexbytes,
10387                    RTE_ETH_FDIR_MAX_FLEXLEN);
10388
10389         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10390
10391         entry.action.flex_off = 0;  /*use 0 by default */
10392         if (!strcmp(res->drop, "drop"))
10393                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10394         else
10395                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10396
10397         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10398             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10399                 if (!strcmp(res->pf_vf, "pf"))
10400                         entry.input.flow_ext.is_vf = 0;
10401                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10402                         struct rte_eth_dev_info dev_info;
10403
10404                         memset(&dev_info, 0, sizeof(dev_info));
10405                         rte_eth_dev_info_get(res->port_id, &dev_info);
10406                         errno = 0;
10407                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10408                         if (errno != 0 || *end != '\0' ||
10409                             vf_id >= dev_info.max_vfs) {
10410                                 printf("invalid parameter %s.\n", res->pf_vf);
10411                                 return;
10412                         }
10413                         entry.input.flow_ext.is_vf = 1;
10414                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10415                 } else {
10416                         printf("invalid parameter %s.\n", res->pf_vf);
10417                         return;
10418                 }
10419         }
10420
10421         /* set to report FD ID by default */
10422         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10423         entry.action.rx_queue = res->queue_id;
10424         entry.soft_id = res->fd_id_value;
10425         if (!strcmp(res->ops, "add"))
10426                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10427                                              RTE_ETH_FILTER_ADD, &entry);
10428         else if (!strcmp(res->ops, "del"))
10429                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10430                                              RTE_ETH_FILTER_DELETE, &entry);
10431         else
10432                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10433                                              RTE_ETH_FILTER_UPDATE, &entry);
10434         if (ret < 0)
10435                 printf("flow director programming error: (%s)\n",
10436                         strerror(-ret));
10437 }
10438
10439 cmdline_parse_token_string_t cmd_flow_director_filter =
10440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10441                                  flow_director_filter, "flow_director_filter");
10442 cmdline_parse_token_num_t cmd_flow_director_port_id =
10443         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10444                               port_id, UINT16);
10445 cmdline_parse_token_string_t cmd_flow_director_ops =
10446         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10447                                  ops, "add#del#update");
10448 cmdline_parse_token_string_t cmd_flow_director_flow =
10449         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10450                                  flow, "flow");
10451 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10452         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10453                 flow_type, NULL);
10454 cmdline_parse_token_string_t cmd_flow_director_ether =
10455         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10456                                  ether, "ether");
10457 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10458         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10459                               ether_type, UINT16);
10460 cmdline_parse_token_string_t cmd_flow_director_src =
10461         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10462                                  src, "src");
10463 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10464         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10465                                  ip_src);
10466 cmdline_parse_token_num_t cmd_flow_director_port_src =
10467         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10468                               port_src, UINT16);
10469 cmdline_parse_token_string_t cmd_flow_director_dst =
10470         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10471                                  dst, "dst");
10472 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10473         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10474                                  ip_dst);
10475 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10476         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10477                               port_dst, UINT16);
10478 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10479         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10480                                   verify_tag, "verify_tag");
10481 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10482         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10483                               verify_tag_value, UINT32);
10484 cmdline_parse_token_string_t cmd_flow_director_tos =
10485         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10486                                  tos, "tos");
10487 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10488         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10489                               tos_value, UINT8);
10490 cmdline_parse_token_string_t cmd_flow_director_proto =
10491         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10492                                  proto, "proto");
10493 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10494         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10495                               proto_value, UINT8);
10496 cmdline_parse_token_string_t cmd_flow_director_ttl =
10497         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10498                                  ttl, "ttl");
10499 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10500         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10501                               ttl_value, UINT8);
10502 cmdline_parse_token_string_t cmd_flow_director_vlan =
10503         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10504                                  vlan, "vlan");
10505 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10506         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10507                               vlan_value, UINT16);
10508 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10509         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10510                                  flexbytes, "flexbytes");
10511 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10512         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10513                               flexbytes_value, NULL);
10514 cmdline_parse_token_string_t cmd_flow_director_drop =
10515         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10516                                  drop, "drop#fwd");
10517 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10518         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10519                               pf_vf, NULL);
10520 cmdline_parse_token_string_t cmd_flow_director_queue =
10521         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10522                                  queue, "queue");
10523 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10524         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10525                               queue_id, UINT16);
10526 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10527         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10528                                  fd_id, "fd_id");
10529 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10530         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10531                               fd_id_value, UINT32);
10532
10533 cmdline_parse_token_string_t cmd_flow_director_mode =
10534         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10535                                  mode, "mode");
10536 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10537         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10538                                  mode_value, "IP");
10539 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10540         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10541                                  mode_value, "MAC-VLAN");
10542 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10543         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10544                                  mode_value, "Tunnel");
10545 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10546         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10547                                  mode_value, "raw");
10548 cmdline_parse_token_string_t cmd_flow_director_mac =
10549         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10550                                  mac, "mac");
10551 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10552         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10553                                     mac_addr);
10554 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10555         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10556                                  tunnel, "tunnel");
10557 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10558         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10559                                  tunnel_type, "NVGRE#VxLAN");
10560 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10561         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10562                                  tunnel_id, "tunnel-id");
10563 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10564         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10565                               tunnel_id_value, UINT32);
10566 cmdline_parse_token_string_t cmd_flow_director_packet =
10567         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10568                                  packet, "packet");
10569 cmdline_parse_token_string_t cmd_flow_director_filepath =
10570         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10571                                  filepath, NULL);
10572
10573 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10574         .f = cmd_flow_director_filter_parsed,
10575         .data = NULL,
10576         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10577                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10578                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10579                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10580                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10581                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10582                 "fd_id <fd_id_value>: "
10583                 "Add or delete an ip flow director entry on NIC",
10584         .tokens = {
10585                 (void *)&cmd_flow_director_filter,
10586                 (void *)&cmd_flow_director_port_id,
10587                 (void *)&cmd_flow_director_mode,
10588                 (void *)&cmd_flow_director_mode_ip,
10589                 (void *)&cmd_flow_director_ops,
10590                 (void *)&cmd_flow_director_flow,
10591                 (void *)&cmd_flow_director_flow_type,
10592                 (void *)&cmd_flow_director_src,
10593                 (void *)&cmd_flow_director_ip_src,
10594                 (void *)&cmd_flow_director_dst,
10595                 (void *)&cmd_flow_director_ip_dst,
10596                 (void *)&cmd_flow_director_tos,
10597                 (void *)&cmd_flow_director_tos_value,
10598                 (void *)&cmd_flow_director_proto,
10599                 (void *)&cmd_flow_director_proto_value,
10600                 (void *)&cmd_flow_director_ttl,
10601                 (void *)&cmd_flow_director_ttl_value,
10602                 (void *)&cmd_flow_director_vlan,
10603                 (void *)&cmd_flow_director_vlan_value,
10604                 (void *)&cmd_flow_director_flexbytes,
10605                 (void *)&cmd_flow_director_flexbytes_value,
10606                 (void *)&cmd_flow_director_drop,
10607                 (void *)&cmd_flow_director_pf_vf,
10608                 (void *)&cmd_flow_director_queue,
10609                 (void *)&cmd_flow_director_queue_id,
10610                 (void *)&cmd_flow_director_fd_id,
10611                 (void *)&cmd_flow_director_fd_id_value,
10612                 NULL,
10613         },
10614 };
10615
10616 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10617         .f = cmd_flow_director_filter_parsed,
10618         .data = NULL,
10619         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10620                 "director entry on NIC",
10621         .tokens = {
10622                 (void *)&cmd_flow_director_filter,
10623                 (void *)&cmd_flow_director_port_id,
10624                 (void *)&cmd_flow_director_mode,
10625                 (void *)&cmd_flow_director_mode_ip,
10626                 (void *)&cmd_flow_director_ops,
10627                 (void *)&cmd_flow_director_flow,
10628                 (void *)&cmd_flow_director_flow_type,
10629                 (void *)&cmd_flow_director_src,
10630                 (void *)&cmd_flow_director_ip_src,
10631                 (void *)&cmd_flow_director_port_src,
10632                 (void *)&cmd_flow_director_dst,
10633                 (void *)&cmd_flow_director_ip_dst,
10634                 (void *)&cmd_flow_director_port_dst,
10635                 (void *)&cmd_flow_director_tos,
10636                 (void *)&cmd_flow_director_tos_value,
10637                 (void *)&cmd_flow_director_ttl,
10638                 (void *)&cmd_flow_director_ttl_value,
10639                 (void *)&cmd_flow_director_vlan,
10640                 (void *)&cmd_flow_director_vlan_value,
10641                 (void *)&cmd_flow_director_flexbytes,
10642                 (void *)&cmd_flow_director_flexbytes_value,
10643                 (void *)&cmd_flow_director_drop,
10644                 (void *)&cmd_flow_director_pf_vf,
10645                 (void *)&cmd_flow_director_queue,
10646                 (void *)&cmd_flow_director_queue_id,
10647                 (void *)&cmd_flow_director_fd_id,
10648                 (void *)&cmd_flow_director_fd_id_value,
10649                 NULL,
10650         },
10651 };
10652
10653 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10654         .f = cmd_flow_director_filter_parsed,
10655         .data = NULL,
10656         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10657                 "director entry on NIC",
10658         .tokens = {
10659                 (void *)&cmd_flow_director_filter,
10660                 (void *)&cmd_flow_director_port_id,
10661                 (void *)&cmd_flow_director_mode,
10662                 (void *)&cmd_flow_director_mode_ip,
10663                 (void *)&cmd_flow_director_ops,
10664                 (void *)&cmd_flow_director_flow,
10665                 (void *)&cmd_flow_director_flow_type,
10666                 (void *)&cmd_flow_director_src,
10667                 (void *)&cmd_flow_director_ip_src,
10668                 (void *)&cmd_flow_director_port_src,
10669                 (void *)&cmd_flow_director_dst,
10670                 (void *)&cmd_flow_director_ip_dst,
10671                 (void *)&cmd_flow_director_port_dst,
10672                 (void *)&cmd_flow_director_verify_tag,
10673                 (void *)&cmd_flow_director_verify_tag_value,
10674                 (void *)&cmd_flow_director_tos,
10675                 (void *)&cmd_flow_director_tos_value,
10676                 (void *)&cmd_flow_director_ttl,
10677                 (void *)&cmd_flow_director_ttl_value,
10678                 (void *)&cmd_flow_director_vlan,
10679                 (void *)&cmd_flow_director_vlan_value,
10680                 (void *)&cmd_flow_director_flexbytes,
10681                 (void *)&cmd_flow_director_flexbytes_value,
10682                 (void *)&cmd_flow_director_drop,
10683                 (void *)&cmd_flow_director_pf_vf,
10684                 (void *)&cmd_flow_director_queue,
10685                 (void *)&cmd_flow_director_queue_id,
10686                 (void *)&cmd_flow_director_fd_id,
10687                 (void *)&cmd_flow_director_fd_id_value,
10688                 NULL,
10689         },
10690 };
10691
10692 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10693         .f = cmd_flow_director_filter_parsed,
10694         .data = NULL,
10695         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10696                 "director entry on NIC",
10697         .tokens = {
10698                 (void *)&cmd_flow_director_filter,
10699                 (void *)&cmd_flow_director_port_id,
10700                 (void *)&cmd_flow_director_mode,
10701                 (void *)&cmd_flow_director_mode_ip,
10702                 (void *)&cmd_flow_director_ops,
10703                 (void *)&cmd_flow_director_flow,
10704                 (void *)&cmd_flow_director_flow_type,
10705                 (void *)&cmd_flow_director_ether,
10706                 (void *)&cmd_flow_director_ether_type,
10707                 (void *)&cmd_flow_director_flexbytes,
10708                 (void *)&cmd_flow_director_flexbytes_value,
10709                 (void *)&cmd_flow_director_drop,
10710                 (void *)&cmd_flow_director_pf_vf,
10711                 (void *)&cmd_flow_director_queue,
10712                 (void *)&cmd_flow_director_queue_id,
10713                 (void *)&cmd_flow_director_fd_id,
10714                 (void *)&cmd_flow_director_fd_id_value,
10715                 NULL,
10716         },
10717 };
10718
10719 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10720         .f = cmd_flow_director_filter_parsed,
10721         .data = NULL,
10722         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10723                 "director entry on NIC",
10724         .tokens = {
10725                 (void *)&cmd_flow_director_filter,
10726                 (void *)&cmd_flow_director_port_id,
10727                 (void *)&cmd_flow_director_mode,
10728                 (void *)&cmd_flow_director_mode_mac_vlan,
10729                 (void *)&cmd_flow_director_ops,
10730                 (void *)&cmd_flow_director_mac,
10731                 (void *)&cmd_flow_director_mac_addr,
10732                 (void *)&cmd_flow_director_vlan,
10733                 (void *)&cmd_flow_director_vlan_value,
10734                 (void *)&cmd_flow_director_flexbytes,
10735                 (void *)&cmd_flow_director_flexbytes_value,
10736                 (void *)&cmd_flow_director_drop,
10737                 (void *)&cmd_flow_director_queue,
10738                 (void *)&cmd_flow_director_queue_id,
10739                 (void *)&cmd_flow_director_fd_id,
10740                 (void *)&cmd_flow_director_fd_id_value,
10741                 NULL,
10742         },
10743 };
10744
10745 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10746         .f = cmd_flow_director_filter_parsed,
10747         .data = NULL,
10748         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10749                 "director entry on NIC",
10750         .tokens = {
10751                 (void *)&cmd_flow_director_filter,
10752                 (void *)&cmd_flow_director_port_id,
10753                 (void *)&cmd_flow_director_mode,
10754                 (void *)&cmd_flow_director_mode_tunnel,
10755                 (void *)&cmd_flow_director_ops,
10756                 (void *)&cmd_flow_director_mac,
10757                 (void *)&cmd_flow_director_mac_addr,
10758                 (void *)&cmd_flow_director_vlan,
10759                 (void *)&cmd_flow_director_vlan_value,
10760                 (void *)&cmd_flow_director_tunnel,
10761                 (void *)&cmd_flow_director_tunnel_type,
10762                 (void *)&cmd_flow_director_tunnel_id,
10763                 (void *)&cmd_flow_director_tunnel_id_value,
10764                 (void *)&cmd_flow_director_flexbytes,
10765                 (void *)&cmd_flow_director_flexbytes_value,
10766                 (void *)&cmd_flow_director_drop,
10767                 (void *)&cmd_flow_director_queue,
10768                 (void *)&cmd_flow_director_queue_id,
10769                 (void *)&cmd_flow_director_fd_id,
10770                 (void *)&cmd_flow_director_fd_id_value,
10771                 NULL,
10772         },
10773 };
10774
10775 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10776         .f = cmd_flow_director_filter_parsed,
10777         .data = NULL,
10778         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10779                 "director entry on NIC",
10780         .tokens = {
10781                 (void *)&cmd_flow_director_filter,
10782                 (void *)&cmd_flow_director_port_id,
10783                 (void *)&cmd_flow_director_mode,
10784                 (void *)&cmd_flow_director_mode_raw,
10785                 (void *)&cmd_flow_director_ops,
10786                 (void *)&cmd_flow_director_flow,
10787                 (void *)&cmd_flow_director_flow_type,
10788                 (void *)&cmd_flow_director_drop,
10789                 (void *)&cmd_flow_director_queue,
10790                 (void *)&cmd_flow_director_queue_id,
10791                 (void *)&cmd_flow_director_fd_id,
10792                 (void *)&cmd_flow_director_fd_id_value,
10793                 (void *)&cmd_flow_director_packet,
10794                 (void *)&cmd_flow_director_filepath,
10795                 NULL,
10796         },
10797 };
10798
10799 struct cmd_flush_flow_director_result {
10800         cmdline_fixed_string_t flush_flow_director;
10801         portid_t port_id;
10802 };
10803
10804 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10805         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10806                                  flush_flow_director, "flush_flow_director");
10807 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10808         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10809                               port_id, UINT16);
10810
10811 static void
10812 cmd_flush_flow_director_parsed(void *parsed_result,
10813                           __attribute__((unused)) struct cmdline *cl,
10814                           __attribute__((unused)) void *data)
10815 {
10816         struct cmd_flow_director_result *res = parsed_result;
10817         int ret = 0;
10818
10819         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10820         if (ret < 0) {
10821                 printf("flow director is not supported on port %u.\n",
10822                         res->port_id);
10823                 return;
10824         }
10825
10826         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10827                         RTE_ETH_FILTER_FLUSH, NULL);
10828         if (ret < 0)
10829                 printf("flow director table flushing error: (%s)\n",
10830                         strerror(-ret));
10831 }
10832
10833 cmdline_parse_inst_t cmd_flush_flow_director = {
10834         .f = cmd_flush_flow_director_parsed,
10835         .data = NULL,
10836         .help_str = "flush_flow_director <port_id>: "
10837                 "Flush all flow director entries of a device on NIC",
10838         .tokens = {
10839                 (void *)&cmd_flush_flow_director_flush,
10840                 (void *)&cmd_flush_flow_director_port_id,
10841                 NULL,
10842         },
10843 };
10844
10845 /* *** deal with flow director mask *** */
10846 struct cmd_flow_director_mask_result {
10847         cmdline_fixed_string_t flow_director_mask;
10848         portid_t port_id;
10849         cmdline_fixed_string_t mode;
10850         cmdline_fixed_string_t mode_value;
10851         cmdline_fixed_string_t vlan;
10852         uint16_t vlan_mask;
10853         cmdline_fixed_string_t src_mask;
10854         cmdline_ipaddr_t ipv4_src;
10855         cmdline_ipaddr_t ipv6_src;
10856         uint16_t port_src;
10857         cmdline_fixed_string_t dst_mask;
10858         cmdline_ipaddr_t ipv4_dst;
10859         cmdline_ipaddr_t ipv6_dst;
10860         uint16_t port_dst;
10861         cmdline_fixed_string_t mac;
10862         uint8_t mac_addr_byte_mask;
10863         cmdline_fixed_string_t tunnel_id;
10864         uint32_t tunnel_id_mask;
10865         cmdline_fixed_string_t tunnel_type;
10866         uint8_t tunnel_type_mask;
10867 };
10868
10869 static void
10870 cmd_flow_director_mask_parsed(void *parsed_result,
10871                           __attribute__((unused)) struct cmdline *cl,
10872                           __attribute__((unused)) void *data)
10873 {
10874         struct cmd_flow_director_mask_result *res = parsed_result;
10875         struct rte_eth_fdir_masks *mask;
10876         struct rte_port *port;
10877
10878         port = &ports[res->port_id];
10879         /** Check if the port is not started **/
10880         if (port->port_status != RTE_PORT_STOPPED) {
10881                 printf("Please stop port %d first\n", res->port_id);
10882                 return;
10883         }
10884
10885         mask = &port->dev_conf.fdir_conf.mask;
10886
10887         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10888                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10889                         printf("Please set mode to MAC-VLAN.\n");
10890                         return;
10891                 }
10892
10893                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10894         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10895                 if (strcmp(res->mode_value, "Tunnel")) {
10896                         printf("Please set mode to Tunnel.\n");
10897                         return;
10898                 }
10899
10900                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10901                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10902                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10903                 mask->tunnel_type_mask = res->tunnel_type_mask;
10904         } else {
10905                 if (strcmp(res->mode_value, "IP")) {
10906                         printf("Please set mode to IP.\n");
10907                         return;
10908                 }
10909
10910                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10911                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10912                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10913                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10914                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10915                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10916                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10917         }
10918
10919         cmd_reconfig_device_queue(res->port_id, 1, 1);
10920 }
10921
10922 cmdline_parse_token_string_t cmd_flow_director_mask =
10923         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10924                                  flow_director_mask, "flow_director_mask");
10925 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10926         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10927                               port_id, UINT16);
10928 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10929         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10930                                  vlan, "vlan");
10931 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10932         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10933                               vlan_mask, UINT16);
10934 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10935         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10936                                  src_mask, "src_mask");
10937 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10938         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10939                                  ipv4_src);
10940 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10941         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10942                                  ipv6_src);
10943 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10944         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10945                               port_src, UINT16);
10946 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10947         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10948                                  dst_mask, "dst_mask");
10949 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10950         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10951                                  ipv4_dst);
10952 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10953         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10954                                  ipv6_dst);
10955 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10956         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10957                               port_dst, UINT16);
10958
10959 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10960         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10961                                  mode, "mode");
10962 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10963         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10964                                  mode_value, "IP");
10965 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10966         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10967                                  mode_value, "MAC-VLAN");
10968 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10969         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10970                                  mode_value, "Tunnel");
10971 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10972         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10973                                  mac, "mac");
10974 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10975         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10976                               mac_addr_byte_mask, UINT8);
10977 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10978         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10979                                  tunnel_type, "tunnel-type");
10980 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10981         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10982                               tunnel_type_mask, UINT8);
10983 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10984         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10985                                  tunnel_id, "tunnel-id");
10986 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10987         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10988                               tunnel_id_mask, UINT32);
10989
10990 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10991         .f = cmd_flow_director_mask_parsed,
10992         .data = NULL,
10993         .help_str = "flow_director_mask ... : "
10994                 "Set IP mode flow director's mask on NIC",
10995         .tokens = {
10996                 (void *)&cmd_flow_director_mask,
10997                 (void *)&cmd_flow_director_mask_port_id,
10998                 (void *)&cmd_flow_director_mask_mode,
10999                 (void *)&cmd_flow_director_mask_mode_ip,
11000                 (void *)&cmd_flow_director_mask_vlan,
11001                 (void *)&cmd_flow_director_mask_vlan_value,
11002                 (void *)&cmd_flow_director_mask_src,
11003                 (void *)&cmd_flow_director_mask_ipv4_src,
11004                 (void *)&cmd_flow_director_mask_ipv6_src,
11005                 (void *)&cmd_flow_director_mask_port_src,
11006                 (void *)&cmd_flow_director_mask_dst,
11007                 (void *)&cmd_flow_director_mask_ipv4_dst,
11008                 (void *)&cmd_flow_director_mask_ipv6_dst,
11009                 (void *)&cmd_flow_director_mask_port_dst,
11010                 NULL,
11011         },
11012 };
11013
11014 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11015         .f = cmd_flow_director_mask_parsed,
11016         .data = NULL,
11017         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11018                 "flow director's mask on NIC",
11019         .tokens = {
11020                 (void *)&cmd_flow_director_mask,
11021                 (void *)&cmd_flow_director_mask_port_id,
11022                 (void *)&cmd_flow_director_mask_mode,
11023                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11024                 (void *)&cmd_flow_director_mask_vlan,
11025                 (void *)&cmd_flow_director_mask_vlan_value,
11026                 NULL,
11027         },
11028 };
11029
11030 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11031         .f = cmd_flow_director_mask_parsed,
11032         .data = NULL,
11033         .help_str = "flow_director_mask ... : Set tunnel mode "
11034                 "flow director's mask on NIC",
11035         .tokens = {
11036                 (void *)&cmd_flow_director_mask,
11037                 (void *)&cmd_flow_director_mask_port_id,
11038                 (void *)&cmd_flow_director_mask_mode,
11039                 (void *)&cmd_flow_director_mask_mode_tunnel,
11040                 (void *)&cmd_flow_director_mask_vlan,
11041                 (void *)&cmd_flow_director_mask_vlan_value,
11042                 (void *)&cmd_flow_director_mask_mac,
11043                 (void *)&cmd_flow_director_mask_mac_value,
11044                 (void *)&cmd_flow_director_mask_tunnel_type,
11045                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11046                 (void *)&cmd_flow_director_mask_tunnel_id,
11047                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11048                 NULL,
11049         },
11050 };
11051
11052 /* *** deal with flow director mask on flexible payload *** */
11053 struct cmd_flow_director_flex_mask_result {
11054         cmdline_fixed_string_t flow_director_flexmask;
11055         portid_t port_id;
11056         cmdline_fixed_string_t flow;
11057         cmdline_fixed_string_t flow_type;
11058         cmdline_fixed_string_t mask;
11059 };
11060
11061 static void
11062 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11063                           __attribute__((unused)) struct cmdline *cl,
11064                           __attribute__((unused)) void *data)
11065 {
11066         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11067         struct rte_eth_fdir_info fdir_info;
11068         struct rte_eth_fdir_flex_mask flex_mask;
11069         struct rte_port *port;
11070         uint64_t flow_type_mask;
11071         uint16_t i;
11072         int ret;
11073
11074         port = &ports[res->port_id];
11075         /** Check if the port is not started **/
11076         if (port->port_status != RTE_PORT_STOPPED) {
11077                 printf("Please stop port %d first\n", res->port_id);
11078                 return;
11079         }
11080
11081         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11082         ret = parse_flexbytes(res->mask,
11083                         flex_mask.mask,
11084                         RTE_ETH_FDIR_MAX_FLEXLEN);
11085         if (ret < 0) {
11086                 printf("error: Cannot parse mask input.\n");
11087                 return;
11088         }
11089
11090         memset(&fdir_info, 0, sizeof(fdir_info));
11091         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11092                                 RTE_ETH_FILTER_INFO, &fdir_info);
11093         if (ret < 0) {
11094                 printf("Cannot get FDir filter info\n");
11095                 return;
11096         }
11097
11098         if (!strcmp(res->flow_type, "none")) {
11099                 /* means don't specify the flow type */
11100                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11101                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11102                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11103                                0, sizeof(struct rte_eth_fdir_flex_mask));
11104                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11105                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11106                                  &flex_mask,
11107                                  sizeof(struct rte_eth_fdir_flex_mask));
11108                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11109                 return;
11110         }
11111         flow_type_mask = fdir_info.flow_types_mask[0];
11112         if (!strcmp(res->flow_type, "all")) {
11113                 if (!flow_type_mask) {
11114                         printf("No flow type supported\n");
11115                         return;
11116                 }
11117                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11118                         if (flow_type_mask & (1ULL << i)) {
11119                                 flex_mask.flow_type = i;
11120                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11121                         }
11122                 }
11123                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11124                 return;
11125         }
11126         flex_mask.flow_type = str2flowtype(res->flow_type);
11127         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11128                 printf("Flow type %s not supported on port %d\n",
11129                                 res->flow_type, res->port_id);
11130                 return;
11131         }
11132         fdir_set_flex_mask(res->port_id, &flex_mask);
11133         cmd_reconfig_device_queue(res->port_id, 1, 1);
11134 }
11135
11136 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11137         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11138                                  flow_director_flexmask,
11139                                  "flow_director_flex_mask");
11140 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11141         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11142                               port_id, UINT16);
11143 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11144         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11145                                  flow, "flow");
11146 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11147         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11148                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11149                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11150 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11151         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11152                                  mask, NULL);
11153
11154 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11155         .f = cmd_flow_director_flex_mask_parsed,
11156         .data = NULL,
11157         .help_str = "flow_director_flex_mask ... : "
11158                 "Set flow director's flex mask on NIC",
11159         .tokens = {
11160                 (void *)&cmd_flow_director_flexmask,
11161                 (void *)&cmd_flow_director_flexmask_port_id,
11162                 (void *)&cmd_flow_director_flexmask_flow,
11163                 (void *)&cmd_flow_director_flexmask_flow_type,
11164                 (void *)&cmd_flow_director_flexmask_mask,
11165                 NULL,
11166         },
11167 };
11168
11169 /* *** deal with flow director flexible payload configuration *** */
11170 struct cmd_flow_director_flexpayload_result {
11171         cmdline_fixed_string_t flow_director_flexpayload;
11172         portid_t port_id;
11173         cmdline_fixed_string_t payload_layer;
11174         cmdline_fixed_string_t payload_cfg;
11175 };
11176
11177 static inline int
11178 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11179 {
11180         char s[256];
11181         const char *p, *p0 = q_arg;
11182         char *end;
11183         unsigned long int_fld;
11184         char *str_fld[max_num];
11185         int i;
11186         unsigned size;
11187         int ret = -1;
11188
11189         p = strchr(p0, '(');
11190         if (p == NULL)
11191                 return -1;
11192         ++p;
11193         p0 = strchr(p, ')');
11194         if (p0 == NULL)
11195                 return -1;
11196
11197         size = p0 - p;
11198         if (size >= sizeof(s))
11199                 return -1;
11200
11201         snprintf(s, sizeof(s), "%.*s", size, p);
11202         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11203         if (ret < 0 || ret > max_num)
11204                 return -1;
11205         for (i = 0; i < ret; i++) {
11206                 errno = 0;
11207                 int_fld = strtoul(str_fld[i], &end, 0);
11208                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11209                         return -1;
11210                 offsets[i] = (uint16_t)int_fld;
11211         }
11212         return ret;
11213 }
11214
11215 static void
11216 cmd_flow_director_flxpld_parsed(void *parsed_result,
11217                           __attribute__((unused)) struct cmdline *cl,
11218                           __attribute__((unused)) void *data)
11219 {
11220         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11221         struct rte_eth_flex_payload_cfg flex_cfg;
11222         struct rte_port *port;
11223         int ret = 0;
11224
11225         port = &ports[res->port_id];
11226         /** Check if the port is not started **/
11227         if (port->port_status != RTE_PORT_STOPPED) {
11228                 printf("Please stop port %d first\n", res->port_id);
11229                 return;
11230         }
11231
11232         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11233
11234         if (!strcmp(res->payload_layer, "raw"))
11235                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11236         else if (!strcmp(res->payload_layer, "l2"))
11237                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11238         else if (!strcmp(res->payload_layer, "l3"))
11239                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11240         else if (!strcmp(res->payload_layer, "l4"))
11241                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11242
11243         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11244                             RTE_ETH_FDIR_MAX_FLEXLEN);
11245         if (ret < 0) {
11246                 printf("error: Cannot parse flex payload input.\n");
11247                 return;
11248         }
11249
11250         fdir_set_flex_payload(res->port_id, &flex_cfg);
11251         cmd_reconfig_device_queue(res->port_id, 1, 1);
11252 }
11253
11254 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11255         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11256                                  flow_director_flexpayload,
11257                                  "flow_director_flex_payload");
11258 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11259         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11260                               port_id, UINT16);
11261 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11262         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11263                                  payload_layer, "raw#l2#l3#l4");
11264 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11265         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11266                                  payload_cfg, NULL);
11267
11268 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11269         .f = cmd_flow_director_flxpld_parsed,
11270         .data = NULL,
11271         .help_str = "flow_director_flexpayload ... : "
11272                 "Set flow director's flex payload on NIC",
11273         .tokens = {
11274                 (void *)&cmd_flow_director_flexpayload,
11275                 (void *)&cmd_flow_director_flexpayload_port_id,
11276                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11277                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11278                 NULL,
11279         },
11280 };
11281
11282 /* Generic flow interface command. */
11283 extern cmdline_parse_inst_t cmd_flow;
11284
11285 /* *** Classification Filters Control *** */
11286 /* *** Get symmetric hash enable per port *** */
11287 struct cmd_get_sym_hash_ena_per_port_result {
11288         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11289         portid_t port_id;
11290 };
11291
11292 static void
11293 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11294                                  __rte_unused struct cmdline *cl,
11295                                  __rte_unused void *data)
11296 {
11297         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11298         struct rte_eth_hash_filter_info info;
11299         int ret;
11300
11301         if (rte_eth_dev_filter_supported(res->port_id,
11302                                 RTE_ETH_FILTER_HASH) < 0) {
11303                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11304                                                         res->port_id);
11305                 return;
11306         }
11307
11308         memset(&info, 0, sizeof(info));
11309         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11310         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11311                                                 RTE_ETH_FILTER_GET, &info);
11312
11313         if (ret < 0) {
11314                 printf("Cannot get symmetric hash enable per port "
11315                                         "on port %u\n", res->port_id);
11316                 return;
11317         }
11318
11319         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11320                                 "enabled" : "disabled", res->port_id);
11321 }
11322
11323 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11324         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11325                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11326 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11327         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11328                 port_id, UINT16);
11329
11330 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11331         .f = cmd_get_sym_hash_per_port_parsed,
11332         .data = NULL,
11333         .help_str = "get_sym_hash_ena_per_port <port_id>",
11334         .tokens = {
11335                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11336                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11337                 NULL,
11338         },
11339 };
11340
11341 /* *** Set symmetric hash enable per port *** */
11342 struct cmd_set_sym_hash_ena_per_port_result {
11343         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11344         cmdline_fixed_string_t enable;
11345         portid_t port_id;
11346 };
11347
11348 static void
11349 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11350                                  __rte_unused struct cmdline *cl,
11351                                  __rte_unused void *data)
11352 {
11353         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11354         struct rte_eth_hash_filter_info info;
11355         int ret;
11356
11357         if (rte_eth_dev_filter_supported(res->port_id,
11358                                 RTE_ETH_FILTER_HASH) < 0) {
11359                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11360                                                         res->port_id);
11361                 return;
11362         }
11363
11364         memset(&info, 0, sizeof(info));
11365         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11366         if (!strcmp(res->enable, "enable"))
11367                 info.info.enable = 1;
11368         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11369                                         RTE_ETH_FILTER_SET, &info);
11370         if (ret < 0) {
11371                 printf("Cannot set symmetric hash enable per port on "
11372                                         "port %u\n", res->port_id);
11373                 return;
11374         }
11375         printf("Symmetric hash has been set to %s on port %u\n",
11376                                         res->enable, res->port_id);
11377 }
11378
11379 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11380         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11381                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11382 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11383         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11384                 port_id, UINT16);
11385 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11386         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11387                 enable, "enable#disable");
11388
11389 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11390         .f = cmd_set_sym_hash_per_port_parsed,
11391         .data = NULL,
11392         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11393         .tokens = {
11394                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11395                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11396                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11397                 NULL,
11398         },
11399 };
11400
11401 /* Get global config of hash function */
11402 struct cmd_get_hash_global_config_result {
11403         cmdline_fixed_string_t get_hash_global_config;
11404         portid_t port_id;
11405 };
11406
11407 static char *
11408 flowtype_to_str(uint16_t ftype)
11409 {
11410         uint16_t i;
11411         static struct {
11412                 char str[16];
11413                 uint16_t ftype;
11414         } ftype_table[] = {
11415                 {"ipv4", RTE_ETH_FLOW_IPV4},
11416                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11417                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11418                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11419                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11420                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11421                 {"ipv6", RTE_ETH_FLOW_IPV6},
11422                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11423                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11424                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11425                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11426                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11427                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11428                 {"port", RTE_ETH_FLOW_PORT},
11429                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11430                 {"geneve", RTE_ETH_FLOW_GENEVE},
11431                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11432         };
11433
11434         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11435                 if (ftype_table[i].ftype == ftype)
11436                         return ftype_table[i].str;
11437         }
11438
11439         return NULL;
11440 }
11441
11442 static void
11443 cmd_get_hash_global_config_parsed(void *parsed_result,
11444                                   __rte_unused struct cmdline *cl,
11445                                   __rte_unused void *data)
11446 {
11447         struct cmd_get_hash_global_config_result *res = parsed_result;
11448         struct rte_eth_hash_filter_info info;
11449         uint32_t idx, offset;
11450         uint16_t i;
11451         char *str;
11452         int ret;
11453
11454         if (rte_eth_dev_filter_supported(res->port_id,
11455                         RTE_ETH_FILTER_HASH) < 0) {
11456                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11457                                                         res->port_id);
11458                 return;
11459         }
11460
11461         memset(&info, 0, sizeof(info));
11462         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11463         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11464                                         RTE_ETH_FILTER_GET, &info);
11465         if (ret < 0) {
11466                 printf("Cannot get hash global configurations by port %d\n",
11467                                                         res->port_id);
11468                 return;
11469         }
11470
11471         switch (info.info.global_conf.hash_func) {
11472         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11473                 printf("Hash function is Toeplitz\n");
11474                 break;
11475         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11476                 printf("Hash function is Simple XOR\n");
11477                 break;
11478         default:
11479                 printf("Unknown hash function\n");
11480                 break;
11481         }
11482
11483         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11484                 idx = i / UINT64_BIT;
11485                 offset = i % UINT64_BIT;
11486                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11487                                                 (1ULL << offset)))
11488                         continue;
11489                 str = flowtype_to_str(i);
11490                 if (!str)
11491                         continue;
11492                 printf("Symmetric hash is %s globally for flow type %s "
11493                                                         "by port %d\n",
11494                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11495                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11496                                                         res->port_id);
11497         }
11498 }
11499
11500 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11501         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11502                 get_hash_global_config, "get_hash_global_config");
11503 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11504         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11505                 port_id, UINT16);
11506
11507 cmdline_parse_inst_t cmd_get_hash_global_config = {
11508         .f = cmd_get_hash_global_config_parsed,
11509         .data = NULL,
11510         .help_str = "get_hash_global_config <port_id>",
11511         .tokens = {
11512                 (void *)&cmd_get_hash_global_config_all,
11513                 (void *)&cmd_get_hash_global_config_port_id,
11514                 NULL,
11515         },
11516 };
11517
11518 /* Set global config of hash function */
11519 struct cmd_set_hash_global_config_result {
11520         cmdline_fixed_string_t set_hash_global_config;
11521         portid_t port_id;
11522         cmdline_fixed_string_t hash_func;
11523         cmdline_fixed_string_t flow_type;
11524         cmdline_fixed_string_t enable;
11525 };
11526
11527 static void
11528 cmd_set_hash_global_config_parsed(void *parsed_result,
11529                                   __rte_unused struct cmdline *cl,
11530                                   __rte_unused void *data)
11531 {
11532         struct cmd_set_hash_global_config_result *res = parsed_result;
11533         struct rte_eth_hash_filter_info info;
11534         uint32_t ftype, idx, offset;
11535         int ret;
11536
11537         if (rte_eth_dev_filter_supported(res->port_id,
11538                                 RTE_ETH_FILTER_HASH) < 0) {
11539                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11540                                                         res->port_id);
11541                 return;
11542         }
11543         memset(&info, 0, sizeof(info));
11544         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11545         if (!strcmp(res->hash_func, "toeplitz"))
11546                 info.info.global_conf.hash_func =
11547                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11548         else if (!strcmp(res->hash_func, "simple_xor"))
11549                 info.info.global_conf.hash_func =
11550                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11551         else if (!strcmp(res->hash_func, "default"))
11552                 info.info.global_conf.hash_func =
11553                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11554
11555         ftype = str2flowtype(res->flow_type);
11556         idx = ftype / UINT64_BIT;
11557         offset = ftype % UINT64_BIT;
11558         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11559         if (!strcmp(res->enable, "enable"))
11560                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11561                                                 (1ULL << offset);
11562         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11563                                         RTE_ETH_FILTER_SET, &info);
11564         if (ret < 0)
11565                 printf("Cannot set global hash configurations by port %d\n",
11566                                                         res->port_id);
11567         else
11568                 printf("Global hash configurations have been set "
11569                         "succcessfully by port %d\n", res->port_id);
11570 }
11571
11572 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11573         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11574                 set_hash_global_config, "set_hash_global_config");
11575 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11576         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11577                 port_id, UINT16);
11578 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11579         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11580                 hash_func, "toeplitz#simple_xor#default");
11581 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11582         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11583                 flow_type,
11584                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11585                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11586 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11587         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11588                 enable, "enable#disable");
11589
11590 cmdline_parse_inst_t cmd_set_hash_global_config = {
11591         .f = cmd_set_hash_global_config_parsed,
11592         .data = NULL,
11593         .help_str = "set_hash_global_config <port_id> "
11594                 "toeplitz|simple_xor|default "
11595                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11596                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11597                 "l2_payload enable|disable",
11598         .tokens = {
11599                 (void *)&cmd_set_hash_global_config_all,
11600                 (void *)&cmd_set_hash_global_config_port_id,
11601                 (void *)&cmd_set_hash_global_config_hash_func,
11602                 (void *)&cmd_set_hash_global_config_flow_type,
11603                 (void *)&cmd_set_hash_global_config_enable,
11604                 NULL,
11605         },
11606 };
11607
11608 /* Set hash input set */
11609 struct cmd_set_hash_input_set_result {
11610         cmdline_fixed_string_t set_hash_input_set;
11611         portid_t port_id;
11612         cmdline_fixed_string_t flow_type;
11613         cmdline_fixed_string_t inset_field;
11614         cmdline_fixed_string_t select;
11615 };
11616
11617 static enum rte_eth_input_set_field
11618 str2inset(char *string)
11619 {
11620         uint16_t i;
11621
11622         static const struct {
11623                 char str[32];
11624                 enum rte_eth_input_set_field inset;
11625         } inset_table[] = {
11626                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11627                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11628                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11629                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11630                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11631                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11632                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11633                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11634                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11635                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11636                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11637                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11638                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11639                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11640                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11641                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11642                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11643                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11644                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11645                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11646                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11647                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11648                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11649                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11650                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11651                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11652                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11653                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11654                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11655                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11656                 {"none", RTE_ETH_INPUT_SET_NONE},
11657         };
11658
11659         for (i = 0; i < RTE_DIM(inset_table); i++) {
11660                 if (!strcmp(string, inset_table[i].str))
11661                         return inset_table[i].inset;
11662         }
11663
11664         return RTE_ETH_INPUT_SET_UNKNOWN;
11665 }
11666
11667 static void
11668 cmd_set_hash_input_set_parsed(void *parsed_result,
11669                               __rte_unused struct cmdline *cl,
11670                               __rte_unused void *data)
11671 {
11672         struct cmd_set_hash_input_set_result *res = parsed_result;
11673         struct rte_eth_hash_filter_info info;
11674
11675         memset(&info, 0, sizeof(info));
11676         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11677         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11678         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11679         info.info.input_set_conf.inset_size = 1;
11680         if (!strcmp(res->select, "select"))
11681                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11682         else if (!strcmp(res->select, "add"))
11683                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11684         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11685                                 RTE_ETH_FILTER_SET, &info);
11686 }
11687
11688 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11689         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11690                 set_hash_input_set, "set_hash_input_set");
11691 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11692         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11693                 port_id, UINT16);
11694 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11695         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11696                 flow_type, NULL);
11697 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11698         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11699                 inset_field,
11700                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11701                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11702                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11703                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11704                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11705                 "fld-8th#none");
11706 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11707         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11708                 select, "select#add");
11709
11710 cmdline_parse_inst_t cmd_set_hash_input_set = {
11711         .f = cmd_set_hash_input_set_parsed,
11712         .data = NULL,
11713         .help_str = "set_hash_input_set <port_id> "
11714         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11715         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11716         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11717         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11718         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11719         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11720         "fld-7th|fld-8th|none select|add",
11721         .tokens = {
11722                 (void *)&cmd_set_hash_input_set_cmd,
11723                 (void *)&cmd_set_hash_input_set_port_id,
11724                 (void *)&cmd_set_hash_input_set_flow_type,
11725                 (void *)&cmd_set_hash_input_set_field,
11726                 (void *)&cmd_set_hash_input_set_select,
11727                 NULL,
11728         },
11729 };
11730
11731 /* Set flow director input set */
11732 struct cmd_set_fdir_input_set_result {
11733         cmdline_fixed_string_t set_fdir_input_set;
11734         portid_t port_id;
11735         cmdline_fixed_string_t flow_type;
11736         cmdline_fixed_string_t inset_field;
11737         cmdline_fixed_string_t select;
11738 };
11739
11740 static void
11741 cmd_set_fdir_input_set_parsed(void *parsed_result,
11742         __rte_unused struct cmdline *cl,
11743         __rte_unused void *data)
11744 {
11745         struct cmd_set_fdir_input_set_result *res = parsed_result;
11746         struct rte_eth_fdir_filter_info info;
11747
11748         memset(&info, 0, sizeof(info));
11749         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11750         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11751         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11752         info.info.input_set_conf.inset_size = 1;
11753         if (!strcmp(res->select, "select"))
11754                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11755         else if (!strcmp(res->select, "add"))
11756                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11757         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11758                 RTE_ETH_FILTER_SET, &info);
11759 }
11760
11761 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11762         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11763         set_fdir_input_set, "set_fdir_input_set");
11764 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11765         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11766         port_id, UINT16);
11767 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11768         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11769         flow_type,
11770         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11771         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11772 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11773         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11774         inset_field,
11775         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11776         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11777         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11778         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11779         "sctp-veri-tag#none");
11780 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11781         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11782         select, "select#add");
11783
11784 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11785         .f = cmd_set_fdir_input_set_parsed,
11786         .data = NULL,
11787         .help_str = "set_fdir_input_set <port_id> "
11788         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11789         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11790         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11791         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11792         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11793         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11794         "sctp-veri-tag|none select|add",
11795         .tokens = {
11796                 (void *)&cmd_set_fdir_input_set_cmd,
11797                 (void *)&cmd_set_fdir_input_set_port_id,
11798                 (void *)&cmd_set_fdir_input_set_flow_type,
11799                 (void *)&cmd_set_fdir_input_set_field,
11800                 (void *)&cmd_set_fdir_input_set_select,
11801                 NULL,
11802         },
11803 };
11804
11805 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11806 struct cmd_mcast_addr_result {
11807         cmdline_fixed_string_t mcast_addr_cmd;
11808         cmdline_fixed_string_t what;
11809         uint16_t port_num;
11810         struct ether_addr mc_addr;
11811 };
11812
11813 static void cmd_mcast_addr_parsed(void *parsed_result,
11814                 __attribute__((unused)) struct cmdline *cl,
11815                 __attribute__((unused)) void *data)
11816 {
11817         struct cmd_mcast_addr_result *res = parsed_result;
11818
11819         if (!is_multicast_ether_addr(&res->mc_addr)) {
11820                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11821                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11822                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11823                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11824                 return;
11825         }
11826         if (strcmp(res->what, "add") == 0)
11827                 mcast_addr_add(res->port_num, &res->mc_addr);
11828         else
11829                 mcast_addr_remove(res->port_num, &res->mc_addr);
11830 }
11831
11832 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11833         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11834                                  mcast_addr_cmd, "mcast_addr");
11835 cmdline_parse_token_string_t cmd_mcast_addr_what =
11836         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11837                                  "add#remove");
11838 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11839         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11840 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11841         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11842
11843 cmdline_parse_inst_t cmd_mcast_addr = {
11844         .f = cmd_mcast_addr_parsed,
11845         .data = (void *)0,
11846         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11847                 "Add/Remove multicast MAC address on port_id",
11848         .tokens = {
11849                 (void *)&cmd_mcast_addr_cmd,
11850                 (void *)&cmd_mcast_addr_what,
11851                 (void *)&cmd_mcast_addr_portnum,
11852                 (void *)&cmd_mcast_addr_addr,
11853                 NULL,
11854         },
11855 };
11856
11857 /* l2 tunnel config
11858  * only support E-tag now.
11859  */
11860
11861 /* Ether type config */
11862 struct cmd_config_l2_tunnel_eth_type_result {
11863         cmdline_fixed_string_t port;
11864         cmdline_fixed_string_t config;
11865         cmdline_fixed_string_t all;
11866         uint8_t id;
11867         cmdline_fixed_string_t l2_tunnel;
11868         cmdline_fixed_string_t l2_tunnel_type;
11869         cmdline_fixed_string_t eth_type;
11870         uint16_t eth_type_val;
11871 };
11872
11873 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11874         TOKEN_STRING_INITIALIZER
11875                 (struct cmd_config_l2_tunnel_eth_type_result,
11876                  port, "port");
11877 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11878         TOKEN_STRING_INITIALIZER
11879                 (struct cmd_config_l2_tunnel_eth_type_result,
11880                  config, "config");
11881 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11882         TOKEN_STRING_INITIALIZER
11883                 (struct cmd_config_l2_tunnel_eth_type_result,
11884                  all, "all");
11885 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11886         TOKEN_NUM_INITIALIZER
11887                 (struct cmd_config_l2_tunnel_eth_type_result,
11888                  id, UINT8);
11889 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11890         TOKEN_STRING_INITIALIZER
11891                 (struct cmd_config_l2_tunnel_eth_type_result,
11892                  l2_tunnel, "l2-tunnel");
11893 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11894         TOKEN_STRING_INITIALIZER
11895                 (struct cmd_config_l2_tunnel_eth_type_result,
11896                  l2_tunnel_type, "E-tag");
11897 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11898         TOKEN_STRING_INITIALIZER
11899                 (struct cmd_config_l2_tunnel_eth_type_result,
11900                  eth_type, "ether-type");
11901 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11902         TOKEN_NUM_INITIALIZER
11903                 (struct cmd_config_l2_tunnel_eth_type_result,
11904                  eth_type_val, UINT16);
11905
11906 static enum rte_eth_tunnel_type
11907 str2fdir_l2_tunnel_type(char *string)
11908 {
11909         uint32_t i = 0;
11910
11911         static const struct {
11912                 char str[32];
11913                 enum rte_eth_tunnel_type type;
11914         } l2_tunnel_type_str[] = {
11915                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11916         };
11917
11918         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11919                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11920                         return l2_tunnel_type_str[i].type;
11921         }
11922         return RTE_TUNNEL_TYPE_NONE;
11923 }
11924
11925 /* ether type config for all ports */
11926 static void
11927 cmd_config_l2_tunnel_eth_type_all_parsed
11928         (void *parsed_result,
11929          __attribute__((unused)) struct cmdline *cl,
11930          __attribute__((unused)) void *data)
11931 {
11932         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11933         struct rte_eth_l2_tunnel_conf entry;
11934         portid_t pid;
11935
11936         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11937         entry.ether_type = res->eth_type_val;
11938
11939         RTE_ETH_FOREACH_DEV(pid) {
11940                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11941         }
11942 }
11943
11944 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11945         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11946         .data = NULL,
11947         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11948         .tokens = {
11949                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11950                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11951                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11952                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11953                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11954                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11955                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11956                 NULL,
11957         },
11958 };
11959
11960 /* ether type config for a specific port */
11961 static void
11962 cmd_config_l2_tunnel_eth_type_specific_parsed(
11963         void *parsed_result,
11964         __attribute__((unused)) struct cmdline *cl,
11965         __attribute__((unused)) void *data)
11966 {
11967         struct cmd_config_l2_tunnel_eth_type_result *res =
11968                  parsed_result;
11969         struct rte_eth_l2_tunnel_conf entry;
11970
11971         if (port_id_is_invalid(res->id, ENABLED_WARN))
11972                 return;
11973
11974         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11975         entry.ether_type = res->eth_type_val;
11976
11977         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11978 }
11979
11980 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11981         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11982         .data = NULL,
11983         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11984         .tokens = {
11985                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11986                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11987                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11988                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11989                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11990                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11991                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11992                 NULL,
11993         },
11994 };
11995
11996 /* Enable/disable l2 tunnel */
11997 struct cmd_config_l2_tunnel_en_dis_result {
11998         cmdline_fixed_string_t port;
11999         cmdline_fixed_string_t config;
12000         cmdline_fixed_string_t all;
12001         uint8_t id;
12002         cmdline_fixed_string_t l2_tunnel;
12003         cmdline_fixed_string_t l2_tunnel_type;
12004         cmdline_fixed_string_t en_dis;
12005 };
12006
12007 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12008         TOKEN_STRING_INITIALIZER
12009                 (struct cmd_config_l2_tunnel_en_dis_result,
12010                  port, "port");
12011 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12012         TOKEN_STRING_INITIALIZER
12013                 (struct cmd_config_l2_tunnel_en_dis_result,
12014                  config, "config");
12015 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12016         TOKEN_STRING_INITIALIZER
12017                 (struct cmd_config_l2_tunnel_en_dis_result,
12018                  all, "all");
12019 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12020         TOKEN_NUM_INITIALIZER
12021                 (struct cmd_config_l2_tunnel_en_dis_result,
12022                  id, UINT8);
12023 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12024         TOKEN_STRING_INITIALIZER
12025                 (struct cmd_config_l2_tunnel_en_dis_result,
12026                  l2_tunnel, "l2-tunnel");
12027 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12028         TOKEN_STRING_INITIALIZER
12029                 (struct cmd_config_l2_tunnel_en_dis_result,
12030                  l2_tunnel_type, "E-tag");
12031 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12032         TOKEN_STRING_INITIALIZER
12033                 (struct cmd_config_l2_tunnel_en_dis_result,
12034                  en_dis, "enable#disable");
12035
12036 /* enable/disable l2 tunnel for all ports */
12037 static void
12038 cmd_config_l2_tunnel_en_dis_all_parsed(
12039         void *parsed_result,
12040         __attribute__((unused)) struct cmdline *cl,
12041         __attribute__((unused)) void *data)
12042 {
12043         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12044         struct rte_eth_l2_tunnel_conf entry;
12045         portid_t pid;
12046         uint8_t en;
12047
12048         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12049
12050         if (!strcmp("enable", res->en_dis))
12051                 en = 1;
12052         else
12053                 en = 0;
12054
12055         RTE_ETH_FOREACH_DEV(pid) {
12056                 rte_eth_dev_l2_tunnel_offload_set(pid,
12057                                                   &entry,
12058                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12059                                                   en);
12060         }
12061 }
12062
12063 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12064         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12065         .data = NULL,
12066         .help_str = "port config all l2-tunnel E-tag enable|disable",
12067         .tokens = {
12068                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12069                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12070                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12071                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12072                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12073                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12074                 NULL,
12075         },
12076 };
12077
12078 /* enable/disable l2 tunnel for a port */
12079 static void
12080 cmd_config_l2_tunnel_en_dis_specific_parsed(
12081         void *parsed_result,
12082         __attribute__((unused)) struct cmdline *cl,
12083         __attribute__((unused)) void *data)
12084 {
12085         struct cmd_config_l2_tunnel_en_dis_result *res =
12086                 parsed_result;
12087         struct rte_eth_l2_tunnel_conf entry;
12088
12089         if (port_id_is_invalid(res->id, ENABLED_WARN))
12090                 return;
12091
12092         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12093
12094         if (!strcmp("enable", res->en_dis))
12095                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12096                                                   &entry,
12097                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12098                                                   1);
12099         else
12100                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12101                                                   &entry,
12102                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12103                                                   0);
12104 }
12105
12106 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12107         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12108         .data = NULL,
12109         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12110         .tokens = {
12111                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12112                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12113                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12114                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12115                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12116                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12117                 NULL,
12118         },
12119 };
12120
12121 /* E-tag configuration */
12122
12123 /* Common result structure for all E-tag configuration */
12124 struct cmd_config_e_tag_result {
12125         cmdline_fixed_string_t e_tag;
12126         cmdline_fixed_string_t set;
12127         cmdline_fixed_string_t insertion;
12128         cmdline_fixed_string_t stripping;
12129         cmdline_fixed_string_t forwarding;
12130         cmdline_fixed_string_t filter;
12131         cmdline_fixed_string_t add;
12132         cmdline_fixed_string_t del;
12133         cmdline_fixed_string_t on;
12134         cmdline_fixed_string_t off;
12135         cmdline_fixed_string_t on_off;
12136         cmdline_fixed_string_t port_tag_id;
12137         uint32_t port_tag_id_val;
12138         cmdline_fixed_string_t e_tag_id;
12139         uint16_t e_tag_id_val;
12140         cmdline_fixed_string_t dst_pool;
12141         uint8_t dst_pool_val;
12142         cmdline_fixed_string_t port;
12143         portid_t port_id;
12144         cmdline_fixed_string_t vf;
12145         uint8_t vf_id;
12146 };
12147
12148 /* Common CLI fields for all E-tag configuration */
12149 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12150         TOKEN_STRING_INITIALIZER
12151                 (struct cmd_config_e_tag_result,
12152                  e_tag, "E-tag");
12153 cmdline_parse_token_string_t cmd_config_e_tag_set =
12154         TOKEN_STRING_INITIALIZER
12155                 (struct cmd_config_e_tag_result,
12156                  set, "set");
12157 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12158         TOKEN_STRING_INITIALIZER
12159                 (struct cmd_config_e_tag_result,
12160                  insertion, "insertion");
12161 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12162         TOKEN_STRING_INITIALIZER
12163                 (struct cmd_config_e_tag_result,
12164                  stripping, "stripping");
12165 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12166         TOKEN_STRING_INITIALIZER
12167                 (struct cmd_config_e_tag_result,
12168                  forwarding, "forwarding");
12169 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12170         TOKEN_STRING_INITIALIZER
12171                 (struct cmd_config_e_tag_result,
12172                  filter, "filter");
12173 cmdline_parse_token_string_t cmd_config_e_tag_add =
12174         TOKEN_STRING_INITIALIZER
12175                 (struct cmd_config_e_tag_result,
12176                  add, "add");
12177 cmdline_parse_token_string_t cmd_config_e_tag_del =
12178         TOKEN_STRING_INITIALIZER
12179                 (struct cmd_config_e_tag_result,
12180                  del, "del");
12181 cmdline_parse_token_string_t cmd_config_e_tag_on =
12182         TOKEN_STRING_INITIALIZER
12183                 (struct cmd_config_e_tag_result,
12184                  on, "on");
12185 cmdline_parse_token_string_t cmd_config_e_tag_off =
12186         TOKEN_STRING_INITIALIZER
12187                 (struct cmd_config_e_tag_result,
12188                  off, "off");
12189 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12190         TOKEN_STRING_INITIALIZER
12191                 (struct cmd_config_e_tag_result,
12192                  on_off, "on#off");
12193 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12194         TOKEN_STRING_INITIALIZER
12195                 (struct cmd_config_e_tag_result,
12196                  port_tag_id, "port-tag-id");
12197 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12198         TOKEN_NUM_INITIALIZER
12199                 (struct cmd_config_e_tag_result,
12200                  port_tag_id_val, UINT32);
12201 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12202         TOKEN_STRING_INITIALIZER
12203                 (struct cmd_config_e_tag_result,
12204                  e_tag_id, "e-tag-id");
12205 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12206         TOKEN_NUM_INITIALIZER
12207                 (struct cmd_config_e_tag_result,
12208                  e_tag_id_val, UINT16);
12209 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12210         TOKEN_STRING_INITIALIZER
12211                 (struct cmd_config_e_tag_result,
12212                  dst_pool, "dst-pool");
12213 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12214         TOKEN_NUM_INITIALIZER
12215                 (struct cmd_config_e_tag_result,
12216                  dst_pool_val, UINT8);
12217 cmdline_parse_token_string_t cmd_config_e_tag_port =
12218         TOKEN_STRING_INITIALIZER
12219                 (struct cmd_config_e_tag_result,
12220                  port, "port");
12221 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12222         TOKEN_NUM_INITIALIZER
12223                 (struct cmd_config_e_tag_result,
12224                  port_id, UINT16);
12225 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12226         TOKEN_STRING_INITIALIZER
12227                 (struct cmd_config_e_tag_result,
12228                  vf, "vf");
12229 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12230         TOKEN_NUM_INITIALIZER
12231                 (struct cmd_config_e_tag_result,
12232                  vf_id, UINT8);
12233
12234 /* E-tag insertion configuration */
12235 static void
12236 cmd_config_e_tag_insertion_en_parsed(
12237         void *parsed_result,
12238         __attribute__((unused)) struct cmdline *cl,
12239         __attribute__((unused)) void *data)
12240 {
12241         struct cmd_config_e_tag_result *res =
12242                 parsed_result;
12243         struct rte_eth_l2_tunnel_conf entry;
12244
12245         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12246                 return;
12247
12248         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12249         entry.tunnel_id = res->port_tag_id_val;
12250         entry.vf_id = res->vf_id;
12251         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12252                                           &entry,
12253                                           ETH_L2_TUNNEL_INSERTION_MASK,
12254                                           1);
12255 }
12256
12257 static void
12258 cmd_config_e_tag_insertion_dis_parsed(
12259         void *parsed_result,
12260         __attribute__((unused)) struct cmdline *cl,
12261         __attribute__((unused)) void *data)
12262 {
12263         struct cmd_config_e_tag_result *res =
12264                 parsed_result;
12265         struct rte_eth_l2_tunnel_conf entry;
12266
12267         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12268                 return;
12269
12270         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12271         entry.vf_id = res->vf_id;
12272
12273         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12274                                           &entry,
12275                                           ETH_L2_TUNNEL_INSERTION_MASK,
12276                                           0);
12277 }
12278
12279 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12280         .f = cmd_config_e_tag_insertion_en_parsed,
12281         .data = NULL,
12282         .help_str = "E-tag ... : E-tag insertion enable",
12283         .tokens = {
12284                 (void *)&cmd_config_e_tag_e_tag,
12285                 (void *)&cmd_config_e_tag_set,
12286                 (void *)&cmd_config_e_tag_insertion,
12287                 (void *)&cmd_config_e_tag_on,
12288                 (void *)&cmd_config_e_tag_port_tag_id,
12289                 (void *)&cmd_config_e_tag_port_tag_id_val,
12290                 (void *)&cmd_config_e_tag_port,
12291                 (void *)&cmd_config_e_tag_port_id,
12292                 (void *)&cmd_config_e_tag_vf,
12293                 (void *)&cmd_config_e_tag_vf_id,
12294                 NULL,
12295         },
12296 };
12297
12298 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12299         .f = cmd_config_e_tag_insertion_dis_parsed,
12300         .data = NULL,
12301         .help_str = "E-tag ... : E-tag insertion disable",
12302         .tokens = {
12303                 (void *)&cmd_config_e_tag_e_tag,
12304                 (void *)&cmd_config_e_tag_set,
12305                 (void *)&cmd_config_e_tag_insertion,
12306                 (void *)&cmd_config_e_tag_off,
12307                 (void *)&cmd_config_e_tag_port,
12308                 (void *)&cmd_config_e_tag_port_id,
12309                 (void *)&cmd_config_e_tag_vf,
12310                 (void *)&cmd_config_e_tag_vf_id,
12311                 NULL,
12312         },
12313 };
12314
12315 /* E-tag stripping configuration */
12316 static void
12317 cmd_config_e_tag_stripping_parsed(
12318         void *parsed_result,
12319         __attribute__((unused)) struct cmdline *cl,
12320         __attribute__((unused)) void *data)
12321 {
12322         struct cmd_config_e_tag_result *res =
12323                 parsed_result;
12324         struct rte_eth_l2_tunnel_conf entry;
12325
12326         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12327                 return;
12328
12329         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12330
12331         if (!strcmp(res->on_off, "on"))
12332                 rte_eth_dev_l2_tunnel_offload_set
12333                         (res->port_id,
12334                          &entry,
12335                          ETH_L2_TUNNEL_STRIPPING_MASK,
12336                          1);
12337         else
12338                 rte_eth_dev_l2_tunnel_offload_set
12339                         (res->port_id,
12340                          &entry,
12341                          ETH_L2_TUNNEL_STRIPPING_MASK,
12342                          0);
12343 }
12344
12345 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12346         .f = cmd_config_e_tag_stripping_parsed,
12347         .data = NULL,
12348         .help_str = "E-tag ... : E-tag stripping enable/disable",
12349         .tokens = {
12350                 (void *)&cmd_config_e_tag_e_tag,
12351                 (void *)&cmd_config_e_tag_set,
12352                 (void *)&cmd_config_e_tag_stripping,
12353                 (void *)&cmd_config_e_tag_on_off,
12354                 (void *)&cmd_config_e_tag_port,
12355                 (void *)&cmd_config_e_tag_port_id,
12356                 NULL,
12357         },
12358 };
12359
12360 /* E-tag forwarding configuration */
12361 static void
12362 cmd_config_e_tag_forwarding_parsed(
12363         void *parsed_result,
12364         __attribute__((unused)) struct cmdline *cl,
12365         __attribute__((unused)) void *data)
12366 {
12367         struct cmd_config_e_tag_result *res = parsed_result;
12368         struct rte_eth_l2_tunnel_conf entry;
12369
12370         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12371                 return;
12372
12373         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12374
12375         if (!strcmp(res->on_off, "on"))
12376                 rte_eth_dev_l2_tunnel_offload_set
12377                         (res->port_id,
12378                          &entry,
12379                          ETH_L2_TUNNEL_FORWARDING_MASK,
12380                          1);
12381         else
12382                 rte_eth_dev_l2_tunnel_offload_set
12383                         (res->port_id,
12384                          &entry,
12385                          ETH_L2_TUNNEL_FORWARDING_MASK,
12386                          0);
12387 }
12388
12389 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12390         .f = cmd_config_e_tag_forwarding_parsed,
12391         .data = NULL,
12392         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12393         .tokens = {
12394                 (void *)&cmd_config_e_tag_e_tag,
12395                 (void *)&cmd_config_e_tag_set,
12396                 (void *)&cmd_config_e_tag_forwarding,
12397                 (void *)&cmd_config_e_tag_on_off,
12398                 (void *)&cmd_config_e_tag_port,
12399                 (void *)&cmd_config_e_tag_port_id,
12400                 NULL,
12401         },
12402 };
12403
12404 /* E-tag filter configuration */
12405 static void
12406 cmd_config_e_tag_filter_add_parsed(
12407         void *parsed_result,
12408         __attribute__((unused)) struct cmdline *cl,
12409         __attribute__((unused)) void *data)
12410 {
12411         struct cmd_config_e_tag_result *res = parsed_result;
12412         struct rte_eth_l2_tunnel_conf entry;
12413         int ret = 0;
12414
12415         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12416                 return;
12417
12418         if (res->e_tag_id_val > 0x3fff) {
12419                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12420                 return;
12421         }
12422
12423         ret = rte_eth_dev_filter_supported(res->port_id,
12424                                            RTE_ETH_FILTER_L2_TUNNEL);
12425         if (ret < 0) {
12426                 printf("E-tag filter is not supported on port %u.\n",
12427                        res->port_id);
12428                 return;
12429         }
12430
12431         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12432         entry.tunnel_id = res->e_tag_id_val;
12433         entry.pool = res->dst_pool_val;
12434
12435         ret = rte_eth_dev_filter_ctrl(res->port_id,
12436                                       RTE_ETH_FILTER_L2_TUNNEL,
12437                                       RTE_ETH_FILTER_ADD,
12438                                       &entry);
12439         if (ret < 0)
12440                 printf("E-tag filter programming error: (%s)\n",
12441                        strerror(-ret));
12442 }
12443
12444 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12445         .f = cmd_config_e_tag_filter_add_parsed,
12446         .data = NULL,
12447         .help_str = "E-tag ... : E-tag filter add",
12448         .tokens = {
12449                 (void *)&cmd_config_e_tag_e_tag,
12450                 (void *)&cmd_config_e_tag_set,
12451                 (void *)&cmd_config_e_tag_filter,
12452                 (void *)&cmd_config_e_tag_add,
12453                 (void *)&cmd_config_e_tag_e_tag_id,
12454                 (void *)&cmd_config_e_tag_e_tag_id_val,
12455                 (void *)&cmd_config_e_tag_dst_pool,
12456                 (void *)&cmd_config_e_tag_dst_pool_val,
12457                 (void *)&cmd_config_e_tag_port,
12458                 (void *)&cmd_config_e_tag_port_id,
12459                 NULL,
12460         },
12461 };
12462
12463 static void
12464 cmd_config_e_tag_filter_del_parsed(
12465         void *parsed_result,
12466         __attribute__((unused)) struct cmdline *cl,
12467         __attribute__((unused)) void *data)
12468 {
12469         struct cmd_config_e_tag_result *res = parsed_result;
12470         struct rte_eth_l2_tunnel_conf entry;
12471         int ret = 0;
12472
12473         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12474                 return;
12475
12476         if (res->e_tag_id_val > 0x3fff) {
12477                 printf("e-tag-id must be less than 0x3fff.\n");
12478                 return;
12479         }
12480
12481         ret = rte_eth_dev_filter_supported(res->port_id,
12482                                            RTE_ETH_FILTER_L2_TUNNEL);
12483         if (ret < 0) {
12484                 printf("E-tag filter is not supported on port %u.\n",
12485                        res->port_id);
12486                 return;
12487         }
12488
12489         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12490         entry.tunnel_id = res->e_tag_id_val;
12491
12492         ret = rte_eth_dev_filter_ctrl(res->port_id,
12493                                       RTE_ETH_FILTER_L2_TUNNEL,
12494                                       RTE_ETH_FILTER_DELETE,
12495                                       &entry);
12496         if (ret < 0)
12497                 printf("E-tag filter programming error: (%s)\n",
12498                        strerror(-ret));
12499 }
12500
12501 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12502         .f = cmd_config_e_tag_filter_del_parsed,
12503         .data = NULL,
12504         .help_str = "E-tag ... : E-tag filter delete",
12505         .tokens = {
12506                 (void *)&cmd_config_e_tag_e_tag,
12507                 (void *)&cmd_config_e_tag_set,
12508                 (void *)&cmd_config_e_tag_filter,
12509                 (void *)&cmd_config_e_tag_del,
12510                 (void *)&cmd_config_e_tag_e_tag_id,
12511                 (void *)&cmd_config_e_tag_e_tag_id_val,
12512                 (void *)&cmd_config_e_tag_port,
12513                 (void *)&cmd_config_e_tag_port_id,
12514                 NULL,
12515         },
12516 };
12517
12518 /* vf vlan anti spoof configuration */
12519
12520 /* Common result structure for vf vlan anti spoof */
12521 struct cmd_vf_vlan_anti_spoof_result {
12522         cmdline_fixed_string_t set;
12523         cmdline_fixed_string_t vf;
12524         cmdline_fixed_string_t vlan;
12525         cmdline_fixed_string_t antispoof;
12526         portid_t port_id;
12527         uint32_t vf_id;
12528         cmdline_fixed_string_t on_off;
12529 };
12530
12531 /* Common CLI fields for vf vlan anti spoof enable disable */
12532 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12533         TOKEN_STRING_INITIALIZER
12534                 (struct cmd_vf_vlan_anti_spoof_result,
12535                  set, "set");
12536 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12537         TOKEN_STRING_INITIALIZER
12538                 (struct cmd_vf_vlan_anti_spoof_result,
12539                  vf, "vf");
12540 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12541         TOKEN_STRING_INITIALIZER
12542                 (struct cmd_vf_vlan_anti_spoof_result,
12543                  vlan, "vlan");
12544 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12545         TOKEN_STRING_INITIALIZER
12546                 (struct cmd_vf_vlan_anti_spoof_result,
12547                  antispoof, "antispoof");
12548 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12549         TOKEN_NUM_INITIALIZER
12550                 (struct cmd_vf_vlan_anti_spoof_result,
12551                  port_id, UINT16);
12552 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12553         TOKEN_NUM_INITIALIZER
12554                 (struct cmd_vf_vlan_anti_spoof_result,
12555                  vf_id, UINT32);
12556 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12557         TOKEN_STRING_INITIALIZER
12558                 (struct cmd_vf_vlan_anti_spoof_result,
12559                  on_off, "on#off");
12560
12561 static void
12562 cmd_set_vf_vlan_anti_spoof_parsed(
12563         void *parsed_result,
12564         __attribute__((unused)) struct cmdline *cl,
12565         __attribute__((unused)) void *data)
12566 {
12567         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12568         int ret = -ENOTSUP;
12569
12570         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12571
12572         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12573                 return;
12574
12575 #ifdef RTE_LIBRTE_IXGBE_PMD
12576         if (ret == -ENOTSUP)
12577                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12578                                 res->vf_id, is_on);
12579 #endif
12580 #ifdef RTE_LIBRTE_I40E_PMD
12581         if (ret == -ENOTSUP)
12582                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12583                                 res->vf_id, is_on);
12584 #endif
12585 #ifdef RTE_LIBRTE_BNXT_PMD
12586         if (ret == -ENOTSUP)
12587                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12588                                 res->vf_id, is_on);
12589 #endif
12590
12591         switch (ret) {
12592         case 0:
12593                 break;
12594         case -EINVAL:
12595                 printf("invalid vf_id %d\n", res->vf_id);
12596                 break;
12597         case -ENODEV:
12598                 printf("invalid port_id %d\n", res->port_id);
12599                 break;
12600         case -ENOTSUP:
12601                 printf("function not implemented\n");
12602                 break;
12603         default:
12604                 printf("programming error: (%s)\n", strerror(-ret));
12605         }
12606 }
12607
12608 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12609         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12610         .data = NULL,
12611         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12612         .tokens = {
12613                 (void *)&cmd_vf_vlan_anti_spoof_set,
12614                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12615                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12616                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12617                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12618                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12619                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12620                 NULL,
12621         },
12622 };
12623
12624 /* vf mac anti spoof configuration */
12625
12626 /* Common result structure for vf mac anti spoof */
12627 struct cmd_vf_mac_anti_spoof_result {
12628         cmdline_fixed_string_t set;
12629         cmdline_fixed_string_t vf;
12630         cmdline_fixed_string_t mac;
12631         cmdline_fixed_string_t antispoof;
12632         portid_t port_id;
12633         uint32_t vf_id;
12634         cmdline_fixed_string_t on_off;
12635 };
12636
12637 /* Common CLI fields for vf mac anti spoof enable disable */
12638 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12639         TOKEN_STRING_INITIALIZER
12640                 (struct cmd_vf_mac_anti_spoof_result,
12641                  set, "set");
12642 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12643         TOKEN_STRING_INITIALIZER
12644                 (struct cmd_vf_mac_anti_spoof_result,
12645                  vf, "vf");
12646 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12647         TOKEN_STRING_INITIALIZER
12648                 (struct cmd_vf_mac_anti_spoof_result,
12649                  mac, "mac");
12650 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12651         TOKEN_STRING_INITIALIZER
12652                 (struct cmd_vf_mac_anti_spoof_result,
12653                  antispoof, "antispoof");
12654 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12655         TOKEN_NUM_INITIALIZER
12656                 (struct cmd_vf_mac_anti_spoof_result,
12657                  port_id, UINT16);
12658 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12659         TOKEN_NUM_INITIALIZER
12660                 (struct cmd_vf_mac_anti_spoof_result,
12661                  vf_id, UINT32);
12662 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12663         TOKEN_STRING_INITIALIZER
12664                 (struct cmd_vf_mac_anti_spoof_result,
12665                  on_off, "on#off");
12666
12667 static void
12668 cmd_set_vf_mac_anti_spoof_parsed(
12669         void *parsed_result,
12670         __attribute__((unused)) struct cmdline *cl,
12671         __attribute__((unused)) void *data)
12672 {
12673         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12674         int ret = -ENOTSUP;
12675
12676         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12677
12678         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12679                 return;
12680
12681 #ifdef RTE_LIBRTE_IXGBE_PMD
12682         if (ret == -ENOTSUP)
12683                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12684                         res->vf_id, is_on);
12685 #endif
12686 #ifdef RTE_LIBRTE_I40E_PMD
12687         if (ret == -ENOTSUP)
12688                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12689                         res->vf_id, is_on);
12690 #endif
12691 #ifdef RTE_LIBRTE_BNXT_PMD
12692         if (ret == -ENOTSUP)
12693                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12694                         res->vf_id, is_on);
12695 #endif
12696
12697         switch (ret) {
12698         case 0:
12699                 break;
12700         case -EINVAL:
12701                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12702                 break;
12703         case -ENODEV:
12704                 printf("invalid port_id %d\n", res->port_id);
12705                 break;
12706         case -ENOTSUP:
12707                 printf("function not implemented\n");
12708                 break;
12709         default:
12710                 printf("programming error: (%s)\n", strerror(-ret));
12711         }
12712 }
12713
12714 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12715         .f = cmd_set_vf_mac_anti_spoof_parsed,
12716         .data = NULL,
12717         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12718         .tokens = {
12719                 (void *)&cmd_vf_mac_anti_spoof_set,
12720                 (void *)&cmd_vf_mac_anti_spoof_vf,
12721                 (void *)&cmd_vf_mac_anti_spoof_mac,
12722                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12723                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12724                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12725                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12726                 NULL,
12727         },
12728 };
12729
12730 /* vf vlan strip queue configuration */
12731
12732 /* Common result structure for vf mac anti spoof */
12733 struct cmd_vf_vlan_stripq_result {
12734         cmdline_fixed_string_t set;
12735         cmdline_fixed_string_t vf;
12736         cmdline_fixed_string_t vlan;
12737         cmdline_fixed_string_t stripq;
12738         portid_t port_id;
12739         uint16_t vf_id;
12740         cmdline_fixed_string_t on_off;
12741 };
12742
12743 /* Common CLI fields for vf vlan strip enable disable */
12744 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12745         TOKEN_STRING_INITIALIZER
12746                 (struct cmd_vf_vlan_stripq_result,
12747                  set, "set");
12748 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12749         TOKEN_STRING_INITIALIZER
12750                 (struct cmd_vf_vlan_stripq_result,
12751                  vf, "vf");
12752 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12753         TOKEN_STRING_INITIALIZER
12754                 (struct cmd_vf_vlan_stripq_result,
12755                  vlan, "vlan");
12756 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12757         TOKEN_STRING_INITIALIZER
12758                 (struct cmd_vf_vlan_stripq_result,
12759                  stripq, "stripq");
12760 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12761         TOKEN_NUM_INITIALIZER
12762                 (struct cmd_vf_vlan_stripq_result,
12763                  port_id, UINT16);
12764 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12765         TOKEN_NUM_INITIALIZER
12766                 (struct cmd_vf_vlan_stripq_result,
12767                  vf_id, UINT16);
12768 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12769         TOKEN_STRING_INITIALIZER
12770                 (struct cmd_vf_vlan_stripq_result,
12771                  on_off, "on#off");
12772
12773 static void
12774 cmd_set_vf_vlan_stripq_parsed(
12775         void *parsed_result,
12776         __attribute__((unused)) struct cmdline *cl,
12777         __attribute__((unused)) void *data)
12778 {
12779         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12780         int ret = -ENOTSUP;
12781
12782         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12783
12784         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12785                 return;
12786
12787 #ifdef RTE_LIBRTE_IXGBE_PMD
12788         if (ret == -ENOTSUP)
12789                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12790                         res->vf_id, is_on);
12791 #endif
12792 #ifdef RTE_LIBRTE_I40E_PMD
12793         if (ret == -ENOTSUP)
12794                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12795                         res->vf_id, is_on);
12796 #endif
12797 #ifdef RTE_LIBRTE_BNXT_PMD
12798         if (ret == -ENOTSUP)
12799                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12800                         res->vf_id, is_on);
12801 #endif
12802
12803         switch (ret) {
12804         case 0:
12805                 break;
12806         case -EINVAL:
12807                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12808                 break;
12809         case -ENODEV:
12810                 printf("invalid port_id %d\n", res->port_id);
12811                 break;
12812         case -ENOTSUP:
12813                 printf("function not implemented\n");
12814                 break;
12815         default:
12816                 printf("programming error: (%s)\n", strerror(-ret));
12817         }
12818 }
12819
12820 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12821         .f = cmd_set_vf_vlan_stripq_parsed,
12822         .data = NULL,
12823         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12824         .tokens = {
12825                 (void *)&cmd_vf_vlan_stripq_set,
12826                 (void *)&cmd_vf_vlan_stripq_vf,
12827                 (void *)&cmd_vf_vlan_stripq_vlan,
12828                 (void *)&cmd_vf_vlan_stripq_stripq,
12829                 (void *)&cmd_vf_vlan_stripq_port_id,
12830                 (void *)&cmd_vf_vlan_stripq_vf_id,
12831                 (void *)&cmd_vf_vlan_stripq_on_off,
12832                 NULL,
12833         },
12834 };
12835
12836 /* vf vlan insert configuration */
12837
12838 /* Common result structure for vf vlan insert */
12839 struct cmd_vf_vlan_insert_result {
12840         cmdline_fixed_string_t set;
12841         cmdline_fixed_string_t vf;
12842         cmdline_fixed_string_t vlan;
12843         cmdline_fixed_string_t insert;
12844         portid_t port_id;
12845         uint16_t vf_id;
12846         uint16_t vlan_id;
12847 };
12848
12849 /* Common CLI fields for vf vlan insert enable disable */
12850 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12851         TOKEN_STRING_INITIALIZER
12852                 (struct cmd_vf_vlan_insert_result,
12853                  set, "set");
12854 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12855         TOKEN_STRING_INITIALIZER
12856                 (struct cmd_vf_vlan_insert_result,
12857                  vf, "vf");
12858 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12859         TOKEN_STRING_INITIALIZER
12860                 (struct cmd_vf_vlan_insert_result,
12861                  vlan, "vlan");
12862 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12863         TOKEN_STRING_INITIALIZER
12864                 (struct cmd_vf_vlan_insert_result,
12865                  insert, "insert");
12866 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12867         TOKEN_NUM_INITIALIZER
12868                 (struct cmd_vf_vlan_insert_result,
12869                  port_id, UINT16);
12870 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12871         TOKEN_NUM_INITIALIZER
12872                 (struct cmd_vf_vlan_insert_result,
12873                  vf_id, UINT16);
12874 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12875         TOKEN_NUM_INITIALIZER
12876                 (struct cmd_vf_vlan_insert_result,
12877                  vlan_id, UINT16);
12878
12879 static void
12880 cmd_set_vf_vlan_insert_parsed(
12881         void *parsed_result,
12882         __attribute__((unused)) struct cmdline *cl,
12883         __attribute__((unused)) void *data)
12884 {
12885         struct cmd_vf_vlan_insert_result *res = parsed_result;
12886         int ret = -ENOTSUP;
12887
12888         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12889                 return;
12890
12891 #ifdef RTE_LIBRTE_IXGBE_PMD
12892         if (ret == -ENOTSUP)
12893                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12894                         res->vlan_id);
12895 #endif
12896 #ifdef RTE_LIBRTE_I40E_PMD
12897         if (ret == -ENOTSUP)
12898                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12899                         res->vlan_id);
12900 #endif
12901 #ifdef RTE_LIBRTE_BNXT_PMD
12902         if (ret == -ENOTSUP)
12903                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12904                         res->vlan_id);
12905 #endif
12906
12907         switch (ret) {
12908         case 0:
12909                 break;
12910         case -EINVAL:
12911                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12912                 break;
12913         case -ENODEV:
12914                 printf("invalid port_id %d\n", res->port_id);
12915                 break;
12916         case -ENOTSUP:
12917                 printf("function not implemented\n");
12918                 break;
12919         default:
12920                 printf("programming error: (%s)\n", strerror(-ret));
12921         }
12922 }
12923
12924 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12925         .f = cmd_set_vf_vlan_insert_parsed,
12926         .data = NULL,
12927         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12928         .tokens = {
12929                 (void *)&cmd_vf_vlan_insert_set,
12930                 (void *)&cmd_vf_vlan_insert_vf,
12931                 (void *)&cmd_vf_vlan_insert_vlan,
12932                 (void *)&cmd_vf_vlan_insert_insert,
12933                 (void *)&cmd_vf_vlan_insert_port_id,
12934                 (void *)&cmd_vf_vlan_insert_vf_id,
12935                 (void *)&cmd_vf_vlan_insert_vlan_id,
12936                 NULL,
12937         },
12938 };
12939
12940 /* tx loopback configuration */
12941
12942 /* Common result structure for tx loopback */
12943 struct cmd_tx_loopback_result {
12944         cmdline_fixed_string_t set;
12945         cmdline_fixed_string_t tx;
12946         cmdline_fixed_string_t loopback;
12947         portid_t port_id;
12948         cmdline_fixed_string_t on_off;
12949 };
12950
12951 /* Common CLI fields for tx loopback enable disable */
12952 cmdline_parse_token_string_t cmd_tx_loopback_set =
12953         TOKEN_STRING_INITIALIZER
12954                 (struct cmd_tx_loopback_result,
12955                  set, "set");
12956 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12957         TOKEN_STRING_INITIALIZER
12958                 (struct cmd_tx_loopback_result,
12959                  tx, "tx");
12960 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12961         TOKEN_STRING_INITIALIZER
12962                 (struct cmd_tx_loopback_result,
12963                  loopback, "loopback");
12964 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12965         TOKEN_NUM_INITIALIZER
12966                 (struct cmd_tx_loopback_result,
12967                  port_id, UINT16);
12968 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12969         TOKEN_STRING_INITIALIZER
12970                 (struct cmd_tx_loopback_result,
12971                  on_off, "on#off");
12972
12973 static void
12974 cmd_set_tx_loopback_parsed(
12975         void *parsed_result,
12976         __attribute__((unused)) struct cmdline *cl,
12977         __attribute__((unused)) void *data)
12978 {
12979         struct cmd_tx_loopback_result *res = parsed_result;
12980         int ret = -ENOTSUP;
12981
12982         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12983
12984         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12985                 return;
12986
12987 #ifdef RTE_LIBRTE_IXGBE_PMD
12988         if (ret == -ENOTSUP)
12989                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12990 #endif
12991 #ifdef RTE_LIBRTE_I40E_PMD
12992         if (ret == -ENOTSUP)
12993                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12994 #endif
12995 #ifdef RTE_LIBRTE_BNXT_PMD
12996         if (ret == -ENOTSUP)
12997                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12998 #endif
12999 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13000         if (ret == -ENOTSUP)
13001                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13002 #endif
13003
13004         switch (ret) {
13005         case 0:
13006                 break;
13007         case -EINVAL:
13008                 printf("invalid is_on %d\n", is_on);
13009                 break;
13010         case -ENODEV:
13011                 printf("invalid port_id %d\n", res->port_id);
13012                 break;
13013         case -ENOTSUP:
13014                 printf("function not implemented\n");
13015                 break;
13016         default:
13017                 printf("programming error: (%s)\n", strerror(-ret));
13018         }
13019 }
13020
13021 cmdline_parse_inst_t cmd_set_tx_loopback = {
13022         .f = cmd_set_tx_loopback_parsed,
13023         .data = NULL,
13024         .help_str = "set tx loopback <port_id> on|off",
13025         .tokens = {
13026                 (void *)&cmd_tx_loopback_set,
13027                 (void *)&cmd_tx_loopback_tx,
13028                 (void *)&cmd_tx_loopback_loopback,
13029                 (void *)&cmd_tx_loopback_port_id,
13030                 (void *)&cmd_tx_loopback_on_off,
13031                 NULL,
13032         },
13033 };
13034
13035 /* all queues drop enable configuration */
13036
13037 /* Common result structure for all queues drop enable */
13038 struct cmd_all_queues_drop_en_result {
13039         cmdline_fixed_string_t set;
13040         cmdline_fixed_string_t all;
13041         cmdline_fixed_string_t queues;
13042         cmdline_fixed_string_t drop;
13043         portid_t port_id;
13044         cmdline_fixed_string_t on_off;
13045 };
13046
13047 /* Common CLI fields for tx loopback enable disable */
13048 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13049         TOKEN_STRING_INITIALIZER
13050                 (struct cmd_all_queues_drop_en_result,
13051                  set, "set");
13052 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13053         TOKEN_STRING_INITIALIZER
13054                 (struct cmd_all_queues_drop_en_result,
13055                  all, "all");
13056 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13057         TOKEN_STRING_INITIALIZER
13058                 (struct cmd_all_queues_drop_en_result,
13059                  queues, "queues");
13060 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13061         TOKEN_STRING_INITIALIZER
13062                 (struct cmd_all_queues_drop_en_result,
13063                  drop, "drop");
13064 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13065         TOKEN_NUM_INITIALIZER
13066                 (struct cmd_all_queues_drop_en_result,
13067                  port_id, UINT16);
13068 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13069         TOKEN_STRING_INITIALIZER
13070                 (struct cmd_all_queues_drop_en_result,
13071                  on_off, "on#off");
13072
13073 static void
13074 cmd_set_all_queues_drop_en_parsed(
13075         void *parsed_result,
13076         __attribute__((unused)) struct cmdline *cl,
13077         __attribute__((unused)) void *data)
13078 {
13079         struct cmd_all_queues_drop_en_result *res = parsed_result;
13080         int ret = -ENOTSUP;
13081         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13082
13083         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13084                 return;
13085
13086 #ifdef RTE_LIBRTE_IXGBE_PMD
13087         if (ret == -ENOTSUP)
13088                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13089 #endif
13090 #ifdef RTE_LIBRTE_BNXT_PMD
13091         if (ret == -ENOTSUP)
13092                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13093 #endif
13094         switch (ret) {
13095         case 0:
13096                 break;
13097         case -EINVAL:
13098                 printf("invalid is_on %d\n", is_on);
13099                 break;
13100         case -ENODEV:
13101                 printf("invalid port_id %d\n", res->port_id);
13102                 break;
13103         case -ENOTSUP:
13104                 printf("function not implemented\n");
13105                 break;
13106         default:
13107                 printf("programming error: (%s)\n", strerror(-ret));
13108         }
13109 }
13110
13111 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13112         .f = cmd_set_all_queues_drop_en_parsed,
13113         .data = NULL,
13114         .help_str = "set all queues drop <port_id> on|off",
13115         .tokens = {
13116                 (void *)&cmd_all_queues_drop_en_set,
13117                 (void *)&cmd_all_queues_drop_en_all,
13118                 (void *)&cmd_all_queues_drop_en_queues,
13119                 (void *)&cmd_all_queues_drop_en_drop,
13120                 (void *)&cmd_all_queues_drop_en_port_id,
13121                 (void *)&cmd_all_queues_drop_en_on_off,
13122                 NULL,
13123         },
13124 };
13125
13126 /* vf split drop enable configuration */
13127
13128 /* Common result structure for vf split drop enable */
13129 struct cmd_vf_split_drop_en_result {
13130         cmdline_fixed_string_t set;
13131         cmdline_fixed_string_t vf;
13132         cmdline_fixed_string_t split;
13133         cmdline_fixed_string_t drop;
13134         portid_t port_id;
13135         uint16_t vf_id;
13136         cmdline_fixed_string_t on_off;
13137 };
13138
13139 /* Common CLI fields for vf split drop enable disable */
13140 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13141         TOKEN_STRING_INITIALIZER
13142                 (struct cmd_vf_split_drop_en_result,
13143                  set, "set");
13144 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13145         TOKEN_STRING_INITIALIZER
13146                 (struct cmd_vf_split_drop_en_result,
13147                  vf, "vf");
13148 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13149         TOKEN_STRING_INITIALIZER
13150                 (struct cmd_vf_split_drop_en_result,
13151                  split, "split");
13152 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13153         TOKEN_STRING_INITIALIZER
13154                 (struct cmd_vf_split_drop_en_result,
13155                  drop, "drop");
13156 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13157         TOKEN_NUM_INITIALIZER
13158                 (struct cmd_vf_split_drop_en_result,
13159                  port_id, UINT16);
13160 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13161         TOKEN_NUM_INITIALIZER
13162                 (struct cmd_vf_split_drop_en_result,
13163                  vf_id, UINT16);
13164 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13165         TOKEN_STRING_INITIALIZER
13166                 (struct cmd_vf_split_drop_en_result,
13167                  on_off, "on#off");
13168
13169 static void
13170 cmd_set_vf_split_drop_en_parsed(
13171         void *parsed_result,
13172         __attribute__((unused)) struct cmdline *cl,
13173         __attribute__((unused)) void *data)
13174 {
13175         struct cmd_vf_split_drop_en_result *res = parsed_result;
13176         int ret = -ENOTSUP;
13177         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13178
13179         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13180                 return;
13181
13182 #ifdef RTE_LIBRTE_IXGBE_PMD
13183         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13184                         is_on);
13185 #endif
13186         switch (ret) {
13187         case 0:
13188                 break;
13189         case -EINVAL:
13190                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13191                 break;
13192         case -ENODEV:
13193                 printf("invalid port_id %d\n", res->port_id);
13194                 break;
13195         case -ENOTSUP:
13196                 printf("not supported on port %d\n", res->port_id);
13197                 break;
13198         default:
13199                 printf("programming error: (%s)\n", strerror(-ret));
13200         }
13201 }
13202
13203 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13204         .f = cmd_set_vf_split_drop_en_parsed,
13205         .data = NULL,
13206         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13207         .tokens = {
13208                 (void *)&cmd_vf_split_drop_en_set,
13209                 (void *)&cmd_vf_split_drop_en_vf,
13210                 (void *)&cmd_vf_split_drop_en_split,
13211                 (void *)&cmd_vf_split_drop_en_drop,
13212                 (void *)&cmd_vf_split_drop_en_port_id,
13213                 (void *)&cmd_vf_split_drop_en_vf_id,
13214                 (void *)&cmd_vf_split_drop_en_on_off,
13215                 NULL,
13216         },
13217 };
13218
13219 /* vf mac address configuration */
13220
13221 /* Common result structure for vf mac address */
13222 struct cmd_set_vf_mac_addr_result {
13223         cmdline_fixed_string_t set;
13224         cmdline_fixed_string_t vf;
13225         cmdline_fixed_string_t mac;
13226         cmdline_fixed_string_t addr;
13227         portid_t port_id;
13228         uint16_t vf_id;
13229         struct ether_addr mac_addr;
13230
13231 };
13232
13233 /* Common CLI fields for vf split drop enable disable */
13234 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13235         TOKEN_STRING_INITIALIZER
13236                 (struct cmd_set_vf_mac_addr_result,
13237                  set, "set");
13238 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13239         TOKEN_STRING_INITIALIZER
13240                 (struct cmd_set_vf_mac_addr_result,
13241                  vf, "vf");
13242 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13243         TOKEN_STRING_INITIALIZER
13244                 (struct cmd_set_vf_mac_addr_result,
13245                  mac, "mac");
13246 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13247         TOKEN_STRING_INITIALIZER
13248                 (struct cmd_set_vf_mac_addr_result,
13249                  addr, "addr");
13250 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13251         TOKEN_NUM_INITIALIZER
13252                 (struct cmd_set_vf_mac_addr_result,
13253                  port_id, UINT16);
13254 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13255         TOKEN_NUM_INITIALIZER
13256                 (struct cmd_set_vf_mac_addr_result,
13257                  vf_id, UINT16);
13258 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13259         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13260                  mac_addr);
13261
13262 static void
13263 cmd_set_vf_mac_addr_parsed(
13264         void *parsed_result,
13265         __attribute__((unused)) struct cmdline *cl,
13266         __attribute__((unused)) void *data)
13267 {
13268         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13269         int ret = -ENOTSUP;
13270
13271         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13272                 return;
13273
13274 #ifdef RTE_LIBRTE_IXGBE_PMD
13275         if (ret == -ENOTSUP)
13276                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13277                                 &res->mac_addr);
13278 #endif
13279 #ifdef RTE_LIBRTE_I40E_PMD
13280         if (ret == -ENOTSUP)
13281                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13282                                 &res->mac_addr);
13283 #endif
13284 #ifdef RTE_LIBRTE_BNXT_PMD
13285         if (ret == -ENOTSUP)
13286                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13287                                 &res->mac_addr);
13288 #endif
13289
13290         switch (ret) {
13291         case 0:
13292                 break;
13293         case -EINVAL:
13294                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13295                 break;
13296         case -ENODEV:
13297                 printf("invalid port_id %d\n", res->port_id);
13298                 break;
13299         case -ENOTSUP:
13300                 printf("function not implemented\n");
13301                 break;
13302         default:
13303                 printf("programming error: (%s)\n", strerror(-ret));
13304         }
13305 }
13306
13307 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13308         .f = cmd_set_vf_mac_addr_parsed,
13309         .data = NULL,
13310         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13311         .tokens = {
13312                 (void *)&cmd_set_vf_mac_addr_set,
13313                 (void *)&cmd_set_vf_mac_addr_vf,
13314                 (void *)&cmd_set_vf_mac_addr_mac,
13315                 (void *)&cmd_set_vf_mac_addr_addr,
13316                 (void *)&cmd_set_vf_mac_addr_port_id,
13317                 (void *)&cmd_set_vf_mac_addr_vf_id,
13318                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13319                 NULL,
13320         },
13321 };
13322
13323 /* MACsec configuration */
13324
13325 /* Common result structure for MACsec offload enable */
13326 struct cmd_macsec_offload_on_result {
13327         cmdline_fixed_string_t set;
13328         cmdline_fixed_string_t macsec;
13329         cmdline_fixed_string_t offload;
13330         portid_t port_id;
13331         cmdline_fixed_string_t on;
13332         cmdline_fixed_string_t encrypt;
13333         cmdline_fixed_string_t en_on_off;
13334         cmdline_fixed_string_t replay_protect;
13335         cmdline_fixed_string_t rp_on_off;
13336 };
13337
13338 /* Common CLI fields for MACsec offload disable */
13339 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13340         TOKEN_STRING_INITIALIZER
13341                 (struct cmd_macsec_offload_on_result,
13342                  set, "set");
13343 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13344         TOKEN_STRING_INITIALIZER
13345                 (struct cmd_macsec_offload_on_result,
13346                  macsec, "macsec");
13347 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13348         TOKEN_STRING_INITIALIZER
13349                 (struct cmd_macsec_offload_on_result,
13350                  offload, "offload");
13351 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13352         TOKEN_NUM_INITIALIZER
13353                 (struct cmd_macsec_offload_on_result,
13354                  port_id, UINT16);
13355 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13356         TOKEN_STRING_INITIALIZER
13357                 (struct cmd_macsec_offload_on_result,
13358                  on, "on");
13359 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13360         TOKEN_STRING_INITIALIZER
13361                 (struct cmd_macsec_offload_on_result,
13362                  encrypt, "encrypt");
13363 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13364         TOKEN_STRING_INITIALIZER
13365                 (struct cmd_macsec_offload_on_result,
13366                  en_on_off, "on#off");
13367 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13368         TOKEN_STRING_INITIALIZER
13369                 (struct cmd_macsec_offload_on_result,
13370                  replay_protect, "replay-protect");
13371 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13372         TOKEN_STRING_INITIALIZER
13373                 (struct cmd_macsec_offload_on_result,
13374                  rp_on_off, "on#off");
13375
13376 static void
13377 cmd_set_macsec_offload_on_parsed(
13378         void *parsed_result,
13379         __attribute__((unused)) struct cmdline *cl,
13380         __attribute__((unused)) void *data)
13381 {
13382         struct cmd_macsec_offload_on_result *res = parsed_result;
13383         int ret = -ENOTSUP;
13384         portid_t port_id = res->port_id;
13385         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13386         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13387         struct rte_eth_dev_info dev_info;
13388
13389         if (port_id_is_invalid(port_id, ENABLED_WARN))
13390                 return;
13391         if (!port_is_stopped(port_id)) {
13392                 printf("Please stop port %d first\n", port_id);
13393                 return;
13394         }
13395
13396         rte_eth_dev_info_get(port_id, &dev_info);
13397         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13398 #ifdef RTE_LIBRTE_IXGBE_PMD
13399                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13400 #endif
13401         }
13402         RTE_SET_USED(en);
13403         RTE_SET_USED(rp);
13404
13405         switch (ret) {
13406         case 0:
13407                 ports[port_id].dev_conf.txmode.offloads |=
13408                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13409                 cmd_reconfig_device_queue(port_id, 1, 1);
13410                 break;
13411         case -ENODEV:
13412                 printf("invalid port_id %d\n", port_id);
13413                 break;
13414         case -ENOTSUP:
13415                 printf("not supported on port %d\n", port_id);
13416                 break;
13417         default:
13418                 printf("programming error: (%s)\n", strerror(-ret));
13419         }
13420 }
13421
13422 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13423         .f = cmd_set_macsec_offload_on_parsed,
13424         .data = NULL,
13425         .help_str = "set macsec offload <port_id> on "
13426                 "encrypt on|off replay-protect on|off",
13427         .tokens = {
13428                 (void *)&cmd_macsec_offload_on_set,
13429                 (void *)&cmd_macsec_offload_on_macsec,
13430                 (void *)&cmd_macsec_offload_on_offload,
13431                 (void *)&cmd_macsec_offload_on_port_id,
13432                 (void *)&cmd_macsec_offload_on_on,
13433                 (void *)&cmd_macsec_offload_on_encrypt,
13434                 (void *)&cmd_macsec_offload_on_en_on_off,
13435                 (void *)&cmd_macsec_offload_on_replay_protect,
13436                 (void *)&cmd_macsec_offload_on_rp_on_off,
13437                 NULL,
13438         },
13439 };
13440
13441 /* Common result structure for MACsec offload disable */
13442 struct cmd_macsec_offload_off_result {
13443         cmdline_fixed_string_t set;
13444         cmdline_fixed_string_t macsec;
13445         cmdline_fixed_string_t offload;
13446         portid_t port_id;
13447         cmdline_fixed_string_t off;
13448 };
13449
13450 /* Common CLI fields for MACsec offload disable */
13451 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13452         TOKEN_STRING_INITIALIZER
13453                 (struct cmd_macsec_offload_off_result,
13454                  set, "set");
13455 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13456         TOKEN_STRING_INITIALIZER
13457                 (struct cmd_macsec_offload_off_result,
13458                  macsec, "macsec");
13459 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13460         TOKEN_STRING_INITIALIZER
13461                 (struct cmd_macsec_offload_off_result,
13462                  offload, "offload");
13463 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13464         TOKEN_NUM_INITIALIZER
13465                 (struct cmd_macsec_offload_off_result,
13466                  port_id, UINT16);
13467 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13468         TOKEN_STRING_INITIALIZER
13469                 (struct cmd_macsec_offload_off_result,
13470                  off, "off");
13471
13472 static void
13473 cmd_set_macsec_offload_off_parsed(
13474         void *parsed_result,
13475         __attribute__((unused)) struct cmdline *cl,
13476         __attribute__((unused)) void *data)
13477 {
13478         struct cmd_macsec_offload_off_result *res = parsed_result;
13479         int ret = -ENOTSUP;
13480         struct rte_eth_dev_info dev_info;
13481         portid_t port_id = res->port_id;
13482
13483         if (port_id_is_invalid(port_id, ENABLED_WARN))
13484                 return;
13485         if (!port_is_stopped(port_id)) {
13486                 printf("Please stop port %d first\n", port_id);
13487                 return;
13488         }
13489
13490         rte_eth_dev_info_get(port_id, &dev_info);
13491         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13492 #ifdef RTE_LIBRTE_IXGBE_PMD
13493                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13494 #endif
13495         }
13496         switch (ret) {
13497         case 0:
13498                 ports[port_id].dev_conf.txmode.offloads &=
13499                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13500                 cmd_reconfig_device_queue(port_id, 1, 1);
13501                 break;
13502         case -ENODEV:
13503                 printf("invalid port_id %d\n", port_id);
13504                 break;
13505         case -ENOTSUP:
13506                 printf("not supported on port %d\n", port_id);
13507                 break;
13508         default:
13509                 printf("programming error: (%s)\n", strerror(-ret));
13510         }
13511 }
13512
13513 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13514         .f = cmd_set_macsec_offload_off_parsed,
13515         .data = NULL,
13516         .help_str = "set macsec offload <port_id> off",
13517         .tokens = {
13518                 (void *)&cmd_macsec_offload_off_set,
13519                 (void *)&cmd_macsec_offload_off_macsec,
13520                 (void *)&cmd_macsec_offload_off_offload,
13521                 (void *)&cmd_macsec_offload_off_port_id,
13522                 (void *)&cmd_macsec_offload_off_off,
13523                 NULL,
13524         },
13525 };
13526
13527 /* Common result structure for MACsec secure connection configure */
13528 struct cmd_macsec_sc_result {
13529         cmdline_fixed_string_t set;
13530         cmdline_fixed_string_t macsec;
13531         cmdline_fixed_string_t sc;
13532         cmdline_fixed_string_t tx_rx;
13533         portid_t port_id;
13534         struct ether_addr mac;
13535         uint16_t pi;
13536 };
13537
13538 /* Common CLI fields for MACsec secure connection configure */
13539 cmdline_parse_token_string_t cmd_macsec_sc_set =
13540         TOKEN_STRING_INITIALIZER
13541                 (struct cmd_macsec_sc_result,
13542                  set, "set");
13543 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13544         TOKEN_STRING_INITIALIZER
13545                 (struct cmd_macsec_sc_result,
13546                  macsec, "macsec");
13547 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13548         TOKEN_STRING_INITIALIZER
13549                 (struct cmd_macsec_sc_result,
13550                  sc, "sc");
13551 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13552         TOKEN_STRING_INITIALIZER
13553                 (struct cmd_macsec_sc_result,
13554                  tx_rx, "tx#rx");
13555 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13556         TOKEN_NUM_INITIALIZER
13557                 (struct cmd_macsec_sc_result,
13558                  port_id, UINT16);
13559 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13560         TOKEN_ETHERADDR_INITIALIZER
13561                 (struct cmd_macsec_sc_result,
13562                  mac);
13563 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13564         TOKEN_NUM_INITIALIZER
13565                 (struct cmd_macsec_sc_result,
13566                  pi, UINT16);
13567
13568 static void
13569 cmd_set_macsec_sc_parsed(
13570         void *parsed_result,
13571         __attribute__((unused)) struct cmdline *cl,
13572         __attribute__((unused)) void *data)
13573 {
13574         struct cmd_macsec_sc_result *res = parsed_result;
13575         int ret = -ENOTSUP;
13576         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13577
13578 #ifdef RTE_LIBRTE_IXGBE_PMD
13579         ret = is_tx ?
13580                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13581                                 res->mac.addr_bytes) :
13582                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13583                                 res->mac.addr_bytes, res->pi);
13584 #endif
13585         RTE_SET_USED(is_tx);
13586
13587         switch (ret) {
13588         case 0:
13589                 break;
13590         case -ENODEV:
13591                 printf("invalid port_id %d\n", res->port_id);
13592                 break;
13593         case -ENOTSUP:
13594                 printf("not supported on port %d\n", res->port_id);
13595                 break;
13596         default:
13597                 printf("programming error: (%s)\n", strerror(-ret));
13598         }
13599 }
13600
13601 cmdline_parse_inst_t cmd_set_macsec_sc = {
13602         .f = cmd_set_macsec_sc_parsed,
13603         .data = NULL,
13604         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13605         .tokens = {
13606                 (void *)&cmd_macsec_sc_set,
13607                 (void *)&cmd_macsec_sc_macsec,
13608                 (void *)&cmd_macsec_sc_sc,
13609                 (void *)&cmd_macsec_sc_tx_rx,
13610                 (void *)&cmd_macsec_sc_port_id,
13611                 (void *)&cmd_macsec_sc_mac,
13612                 (void *)&cmd_macsec_sc_pi,
13613                 NULL,
13614         },
13615 };
13616
13617 /* Common result structure for MACsec secure connection configure */
13618 struct cmd_macsec_sa_result {
13619         cmdline_fixed_string_t set;
13620         cmdline_fixed_string_t macsec;
13621         cmdline_fixed_string_t sa;
13622         cmdline_fixed_string_t tx_rx;
13623         portid_t port_id;
13624         uint8_t idx;
13625         uint8_t an;
13626         uint32_t pn;
13627         cmdline_fixed_string_t key;
13628 };
13629
13630 /* Common CLI fields for MACsec secure connection configure */
13631 cmdline_parse_token_string_t cmd_macsec_sa_set =
13632         TOKEN_STRING_INITIALIZER
13633                 (struct cmd_macsec_sa_result,
13634                  set, "set");
13635 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13636         TOKEN_STRING_INITIALIZER
13637                 (struct cmd_macsec_sa_result,
13638                  macsec, "macsec");
13639 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13640         TOKEN_STRING_INITIALIZER
13641                 (struct cmd_macsec_sa_result,
13642                  sa, "sa");
13643 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13644         TOKEN_STRING_INITIALIZER
13645                 (struct cmd_macsec_sa_result,
13646                  tx_rx, "tx#rx");
13647 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13648         TOKEN_NUM_INITIALIZER
13649                 (struct cmd_macsec_sa_result,
13650                  port_id, UINT16);
13651 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13652         TOKEN_NUM_INITIALIZER
13653                 (struct cmd_macsec_sa_result,
13654                  idx, UINT8);
13655 cmdline_parse_token_num_t cmd_macsec_sa_an =
13656         TOKEN_NUM_INITIALIZER
13657                 (struct cmd_macsec_sa_result,
13658                  an, UINT8);
13659 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13660         TOKEN_NUM_INITIALIZER
13661                 (struct cmd_macsec_sa_result,
13662                  pn, UINT32);
13663 cmdline_parse_token_string_t cmd_macsec_sa_key =
13664         TOKEN_STRING_INITIALIZER
13665                 (struct cmd_macsec_sa_result,
13666                  key, NULL);
13667
13668 static void
13669 cmd_set_macsec_sa_parsed(
13670         void *parsed_result,
13671         __attribute__((unused)) struct cmdline *cl,
13672         __attribute__((unused)) void *data)
13673 {
13674         struct cmd_macsec_sa_result *res = parsed_result;
13675         int ret = -ENOTSUP;
13676         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13677         uint8_t key[16] = { 0 };
13678         uint8_t xdgt0;
13679         uint8_t xdgt1;
13680         int key_len;
13681         int i;
13682
13683         key_len = strlen(res->key) / 2;
13684         if (key_len > 16)
13685                 key_len = 16;
13686
13687         for (i = 0; i < key_len; i++) {
13688                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13689                 if (xdgt0 == 0xFF)
13690                         return;
13691                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13692                 if (xdgt1 == 0xFF)
13693                         return;
13694                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13695         }
13696
13697 #ifdef RTE_LIBRTE_IXGBE_PMD
13698         ret = is_tx ?
13699                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13700                         res->idx, res->an, res->pn, key) :
13701                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13702                         res->idx, res->an, res->pn, key);
13703 #endif
13704         RTE_SET_USED(is_tx);
13705         RTE_SET_USED(key);
13706
13707         switch (ret) {
13708         case 0:
13709                 break;
13710         case -EINVAL:
13711                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13712                 break;
13713         case -ENODEV:
13714                 printf("invalid port_id %d\n", res->port_id);
13715                 break;
13716         case -ENOTSUP:
13717                 printf("not supported on port %d\n", res->port_id);
13718                 break;
13719         default:
13720                 printf("programming error: (%s)\n", strerror(-ret));
13721         }
13722 }
13723
13724 cmdline_parse_inst_t cmd_set_macsec_sa = {
13725         .f = cmd_set_macsec_sa_parsed,
13726         .data = NULL,
13727         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13728         .tokens = {
13729                 (void *)&cmd_macsec_sa_set,
13730                 (void *)&cmd_macsec_sa_macsec,
13731                 (void *)&cmd_macsec_sa_sa,
13732                 (void *)&cmd_macsec_sa_tx_rx,
13733                 (void *)&cmd_macsec_sa_port_id,
13734                 (void *)&cmd_macsec_sa_idx,
13735                 (void *)&cmd_macsec_sa_an,
13736                 (void *)&cmd_macsec_sa_pn,
13737                 (void *)&cmd_macsec_sa_key,
13738                 NULL,
13739         },
13740 };
13741
13742 /* VF unicast promiscuous mode configuration */
13743
13744 /* Common result structure for VF unicast promiscuous mode */
13745 struct cmd_vf_promisc_result {
13746         cmdline_fixed_string_t set;
13747         cmdline_fixed_string_t vf;
13748         cmdline_fixed_string_t promisc;
13749         portid_t port_id;
13750         uint32_t vf_id;
13751         cmdline_fixed_string_t on_off;
13752 };
13753
13754 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13755 cmdline_parse_token_string_t cmd_vf_promisc_set =
13756         TOKEN_STRING_INITIALIZER
13757                 (struct cmd_vf_promisc_result,
13758                  set, "set");
13759 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13760         TOKEN_STRING_INITIALIZER
13761                 (struct cmd_vf_promisc_result,
13762                  vf, "vf");
13763 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13764         TOKEN_STRING_INITIALIZER
13765                 (struct cmd_vf_promisc_result,
13766                  promisc, "promisc");
13767 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13768         TOKEN_NUM_INITIALIZER
13769                 (struct cmd_vf_promisc_result,
13770                  port_id, UINT16);
13771 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13772         TOKEN_NUM_INITIALIZER
13773                 (struct cmd_vf_promisc_result,
13774                  vf_id, UINT32);
13775 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13776         TOKEN_STRING_INITIALIZER
13777                 (struct cmd_vf_promisc_result,
13778                  on_off, "on#off");
13779
13780 static void
13781 cmd_set_vf_promisc_parsed(
13782         void *parsed_result,
13783         __attribute__((unused)) struct cmdline *cl,
13784         __attribute__((unused)) void *data)
13785 {
13786         struct cmd_vf_promisc_result *res = parsed_result;
13787         int ret = -ENOTSUP;
13788
13789         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13790
13791         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13792                 return;
13793
13794 #ifdef RTE_LIBRTE_I40E_PMD
13795         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13796                                                   res->vf_id, is_on);
13797 #endif
13798
13799         switch (ret) {
13800         case 0:
13801                 break;
13802         case -EINVAL:
13803                 printf("invalid vf_id %d\n", res->vf_id);
13804                 break;
13805         case -ENODEV:
13806                 printf("invalid port_id %d\n", res->port_id);
13807                 break;
13808         case -ENOTSUP:
13809                 printf("function not implemented\n");
13810                 break;
13811         default:
13812                 printf("programming error: (%s)\n", strerror(-ret));
13813         }
13814 }
13815
13816 cmdline_parse_inst_t cmd_set_vf_promisc = {
13817         .f = cmd_set_vf_promisc_parsed,
13818         .data = NULL,
13819         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13820                 "Set unicast promiscuous mode for a VF from the PF",
13821         .tokens = {
13822                 (void *)&cmd_vf_promisc_set,
13823                 (void *)&cmd_vf_promisc_vf,
13824                 (void *)&cmd_vf_promisc_promisc,
13825                 (void *)&cmd_vf_promisc_port_id,
13826                 (void *)&cmd_vf_promisc_vf_id,
13827                 (void *)&cmd_vf_promisc_on_off,
13828                 NULL,
13829         },
13830 };
13831
13832 /* VF multicast promiscuous mode configuration */
13833
13834 /* Common result structure for VF multicast promiscuous mode */
13835 struct cmd_vf_allmulti_result {
13836         cmdline_fixed_string_t set;
13837         cmdline_fixed_string_t vf;
13838         cmdline_fixed_string_t allmulti;
13839         portid_t port_id;
13840         uint32_t vf_id;
13841         cmdline_fixed_string_t on_off;
13842 };
13843
13844 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13845 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13846         TOKEN_STRING_INITIALIZER
13847                 (struct cmd_vf_allmulti_result,
13848                  set, "set");
13849 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13850         TOKEN_STRING_INITIALIZER
13851                 (struct cmd_vf_allmulti_result,
13852                  vf, "vf");
13853 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13854         TOKEN_STRING_INITIALIZER
13855                 (struct cmd_vf_allmulti_result,
13856                  allmulti, "allmulti");
13857 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13858         TOKEN_NUM_INITIALIZER
13859                 (struct cmd_vf_allmulti_result,
13860                  port_id, UINT16);
13861 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13862         TOKEN_NUM_INITIALIZER
13863                 (struct cmd_vf_allmulti_result,
13864                  vf_id, UINT32);
13865 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13866         TOKEN_STRING_INITIALIZER
13867                 (struct cmd_vf_allmulti_result,
13868                  on_off, "on#off");
13869
13870 static void
13871 cmd_set_vf_allmulti_parsed(
13872         void *parsed_result,
13873         __attribute__((unused)) struct cmdline *cl,
13874         __attribute__((unused)) void *data)
13875 {
13876         struct cmd_vf_allmulti_result *res = parsed_result;
13877         int ret = -ENOTSUP;
13878
13879         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13880
13881         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13882                 return;
13883
13884 #ifdef RTE_LIBRTE_I40E_PMD
13885         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13886                                                     res->vf_id, is_on);
13887 #endif
13888
13889         switch (ret) {
13890         case 0:
13891                 break;
13892         case -EINVAL:
13893                 printf("invalid vf_id %d\n", res->vf_id);
13894                 break;
13895         case -ENODEV:
13896                 printf("invalid port_id %d\n", res->port_id);
13897                 break;
13898         case -ENOTSUP:
13899                 printf("function not implemented\n");
13900                 break;
13901         default:
13902                 printf("programming error: (%s)\n", strerror(-ret));
13903         }
13904 }
13905
13906 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13907         .f = cmd_set_vf_allmulti_parsed,
13908         .data = NULL,
13909         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13910                 "Set multicast promiscuous mode for a VF from the PF",
13911         .tokens = {
13912                 (void *)&cmd_vf_allmulti_set,
13913                 (void *)&cmd_vf_allmulti_vf,
13914                 (void *)&cmd_vf_allmulti_allmulti,
13915                 (void *)&cmd_vf_allmulti_port_id,
13916                 (void *)&cmd_vf_allmulti_vf_id,
13917                 (void *)&cmd_vf_allmulti_on_off,
13918                 NULL,
13919         },
13920 };
13921
13922 /* vf broadcast mode configuration */
13923
13924 /* Common result structure for vf broadcast */
13925 struct cmd_set_vf_broadcast_result {
13926         cmdline_fixed_string_t set;
13927         cmdline_fixed_string_t vf;
13928         cmdline_fixed_string_t broadcast;
13929         portid_t port_id;
13930         uint16_t vf_id;
13931         cmdline_fixed_string_t on_off;
13932 };
13933
13934 /* Common CLI fields for vf broadcast enable disable */
13935 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13936         TOKEN_STRING_INITIALIZER
13937                 (struct cmd_set_vf_broadcast_result,
13938                  set, "set");
13939 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13940         TOKEN_STRING_INITIALIZER
13941                 (struct cmd_set_vf_broadcast_result,
13942                  vf, "vf");
13943 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13944         TOKEN_STRING_INITIALIZER
13945                 (struct cmd_set_vf_broadcast_result,
13946                  broadcast, "broadcast");
13947 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13948         TOKEN_NUM_INITIALIZER
13949                 (struct cmd_set_vf_broadcast_result,
13950                  port_id, UINT16);
13951 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13952         TOKEN_NUM_INITIALIZER
13953                 (struct cmd_set_vf_broadcast_result,
13954                  vf_id, UINT16);
13955 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13956         TOKEN_STRING_INITIALIZER
13957                 (struct cmd_set_vf_broadcast_result,
13958                  on_off, "on#off");
13959
13960 static void
13961 cmd_set_vf_broadcast_parsed(
13962         void *parsed_result,
13963         __attribute__((unused)) struct cmdline *cl,
13964         __attribute__((unused)) void *data)
13965 {
13966         struct cmd_set_vf_broadcast_result *res = parsed_result;
13967         int ret = -ENOTSUP;
13968
13969         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13970
13971         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13972                 return;
13973
13974 #ifdef RTE_LIBRTE_I40E_PMD
13975         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13976                                             res->vf_id, is_on);
13977 #endif
13978
13979         switch (ret) {
13980         case 0:
13981                 break;
13982         case -EINVAL:
13983                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13984                 break;
13985         case -ENODEV:
13986                 printf("invalid port_id %d\n", res->port_id);
13987                 break;
13988         case -ENOTSUP:
13989                 printf("function not implemented\n");
13990                 break;
13991         default:
13992                 printf("programming error: (%s)\n", strerror(-ret));
13993         }
13994 }
13995
13996 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13997         .f = cmd_set_vf_broadcast_parsed,
13998         .data = NULL,
13999         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14000         .tokens = {
14001                 (void *)&cmd_set_vf_broadcast_set,
14002                 (void *)&cmd_set_vf_broadcast_vf,
14003                 (void *)&cmd_set_vf_broadcast_broadcast,
14004                 (void *)&cmd_set_vf_broadcast_port_id,
14005                 (void *)&cmd_set_vf_broadcast_vf_id,
14006                 (void *)&cmd_set_vf_broadcast_on_off,
14007                 NULL,
14008         },
14009 };
14010
14011 /* vf vlan tag configuration */
14012
14013 /* Common result structure for vf vlan tag */
14014 struct cmd_set_vf_vlan_tag_result {
14015         cmdline_fixed_string_t set;
14016         cmdline_fixed_string_t vf;
14017         cmdline_fixed_string_t vlan;
14018         cmdline_fixed_string_t tag;
14019         portid_t port_id;
14020         uint16_t vf_id;
14021         cmdline_fixed_string_t on_off;
14022 };
14023
14024 /* Common CLI fields for vf vlan tag enable disable */
14025 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14026         TOKEN_STRING_INITIALIZER
14027                 (struct cmd_set_vf_vlan_tag_result,
14028                  set, "set");
14029 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14030         TOKEN_STRING_INITIALIZER
14031                 (struct cmd_set_vf_vlan_tag_result,
14032                  vf, "vf");
14033 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14034         TOKEN_STRING_INITIALIZER
14035                 (struct cmd_set_vf_vlan_tag_result,
14036                  vlan, "vlan");
14037 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14038         TOKEN_STRING_INITIALIZER
14039                 (struct cmd_set_vf_vlan_tag_result,
14040                  tag, "tag");
14041 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14042         TOKEN_NUM_INITIALIZER
14043                 (struct cmd_set_vf_vlan_tag_result,
14044                  port_id, UINT16);
14045 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14046         TOKEN_NUM_INITIALIZER
14047                 (struct cmd_set_vf_vlan_tag_result,
14048                  vf_id, UINT16);
14049 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14050         TOKEN_STRING_INITIALIZER
14051                 (struct cmd_set_vf_vlan_tag_result,
14052                  on_off, "on#off");
14053
14054 static void
14055 cmd_set_vf_vlan_tag_parsed(
14056         void *parsed_result,
14057         __attribute__((unused)) struct cmdline *cl,
14058         __attribute__((unused)) void *data)
14059 {
14060         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14061         int ret = -ENOTSUP;
14062
14063         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14064
14065         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14066                 return;
14067
14068 #ifdef RTE_LIBRTE_I40E_PMD
14069         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14070                                            res->vf_id, is_on);
14071 #endif
14072
14073         switch (ret) {
14074         case 0:
14075                 break;
14076         case -EINVAL:
14077                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14078                 break;
14079         case -ENODEV:
14080                 printf("invalid port_id %d\n", res->port_id);
14081                 break;
14082         case -ENOTSUP:
14083                 printf("function not implemented\n");
14084                 break;
14085         default:
14086                 printf("programming error: (%s)\n", strerror(-ret));
14087         }
14088 }
14089
14090 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14091         .f = cmd_set_vf_vlan_tag_parsed,
14092         .data = NULL,
14093         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14094         .tokens = {
14095                 (void *)&cmd_set_vf_vlan_tag_set,
14096                 (void *)&cmd_set_vf_vlan_tag_vf,
14097                 (void *)&cmd_set_vf_vlan_tag_vlan,
14098                 (void *)&cmd_set_vf_vlan_tag_tag,
14099                 (void *)&cmd_set_vf_vlan_tag_port_id,
14100                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14101                 (void *)&cmd_set_vf_vlan_tag_on_off,
14102                 NULL,
14103         },
14104 };
14105
14106 /* Common definition of VF and TC TX bandwidth configuration */
14107 struct cmd_vf_tc_bw_result {
14108         cmdline_fixed_string_t set;
14109         cmdline_fixed_string_t vf;
14110         cmdline_fixed_string_t tc;
14111         cmdline_fixed_string_t tx;
14112         cmdline_fixed_string_t min_bw;
14113         cmdline_fixed_string_t max_bw;
14114         cmdline_fixed_string_t strict_link_prio;
14115         portid_t port_id;
14116         uint16_t vf_id;
14117         uint8_t tc_no;
14118         uint32_t bw;
14119         cmdline_fixed_string_t bw_list;
14120         uint8_t tc_map;
14121 };
14122
14123 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14124         TOKEN_STRING_INITIALIZER
14125                 (struct cmd_vf_tc_bw_result,
14126                  set, "set");
14127 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14128         TOKEN_STRING_INITIALIZER
14129                 (struct cmd_vf_tc_bw_result,
14130                  vf, "vf");
14131 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14132         TOKEN_STRING_INITIALIZER
14133                 (struct cmd_vf_tc_bw_result,
14134                  tc, "tc");
14135 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14136         TOKEN_STRING_INITIALIZER
14137                 (struct cmd_vf_tc_bw_result,
14138                  tx, "tx");
14139 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14140         TOKEN_STRING_INITIALIZER
14141                 (struct cmd_vf_tc_bw_result,
14142                  strict_link_prio, "strict-link-priority");
14143 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14144         TOKEN_STRING_INITIALIZER
14145                 (struct cmd_vf_tc_bw_result,
14146                  min_bw, "min-bandwidth");
14147 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14148         TOKEN_STRING_INITIALIZER
14149                 (struct cmd_vf_tc_bw_result,
14150                  max_bw, "max-bandwidth");
14151 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14152         TOKEN_NUM_INITIALIZER
14153                 (struct cmd_vf_tc_bw_result,
14154                  port_id, UINT16);
14155 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14156         TOKEN_NUM_INITIALIZER
14157                 (struct cmd_vf_tc_bw_result,
14158                  vf_id, UINT16);
14159 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14160         TOKEN_NUM_INITIALIZER
14161                 (struct cmd_vf_tc_bw_result,
14162                  tc_no, UINT8);
14163 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14164         TOKEN_NUM_INITIALIZER
14165                 (struct cmd_vf_tc_bw_result,
14166                  bw, UINT32);
14167 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14168         TOKEN_STRING_INITIALIZER
14169                 (struct cmd_vf_tc_bw_result,
14170                  bw_list, NULL);
14171 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14172         TOKEN_NUM_INITIALIZER
14173                 (struct cmd_vf_tc_bw_result,
14174                  tc_map, UINT8);
14175
14176 /* VF max bandwidth setting */
14177 static void
14178 cmd_vf_max_bw_parsed(
14179         void *parsed_result,
14180         __attribute__((unused)) struct cmdline *cl,
14181         __attribute__((unused)) void *data)
14182 {
14183         struct cmd_vf_tc_bw_result *res = parsed_result;
14184         int ret = -ENOTSUP;
14185
14186         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14187                 return;
14188
14189 #ifdef RTE_LIBRTE_I40E_PMD
14190         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14191                                          res->vf_id, res->bw);
14192 #endif
14193
14194         switch (ret) {
14195         case 0:
14196                 break;
14197         case -EINVAL:
14198                 printf("invalid vf_id %d or bandwidth %d\n",
14199                        res->vf_id, res->bw);
14200                 break;
14201         case -ENODEV:
14202                 printf("invalid port_id %d\n", res->port_id);
14203                 break;
14204         case -ENOTSUP:
14205                 printf("function not implemented\n");
14206                 break;
14207         default:
14208                 printf("programming error: (%s)\n", strerror(-ret));
14209         }
14210 }
14211
14212 cmdline_parse_inst_t cmd_vf_max_bw = {
14213         .f = cmd_vf_max_bw_parsed,
14214         .data = NULL,
14215         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14216         .tokens = {
14217                 (void *)&cmd_vf_tc_bw_set,
14218                 (void *)&cmd_vf_tc_bw_vf,
14219                 (void *)&cmd_vf_tc_bw_tx,
14220                 (void *)&cmd_vf_tc_bw_max_bw,
14221                 (void *)&cmd_vf_tc_bw_port_id,
14222                 (void *)&cmd_vf_tc_bw_vf_id,
14223                 (void *)&cmd_vf_tc_bw_bw,
14224                 NULL,
14225         },
14226 };
14227
14228 static int
14229 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14230                            uint8_t *tc_num,
14231                            char *str)
14232 {
14233         uint32_t size;
14234         const char *p, *p0 = str;
14235         char s[256];
14236         char *end;
14237         char *str_fld[16];
14238         uint16_t i;
14239         int ret;
14240
14241         p = strchr(p0, '(');
14242         if (p == NULL) {
14243                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14244                 return -1;
14245         }
14246         p++;
14247         p0 = strchr(p, ')');
14248         if (p0 == NULL) {
14249                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14250                 return -1;
14251         }
14252         size = p0 - p;
14253         if (size >= sizeof(s)) {
14254                 printf("The string size exceeds the internal buffer size\n");
14255                 return -1;
14256         }
14257         snprintf(s, sizeof(s), "%.*s", size, p);
14258         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14259         if (ret <= 0) {
14260                 printf("Failed to get the bandwidth list. ");
14261                 return -1;
14262         }
14263         *tc_num = ret;
14264         for (i = 0; i < ret; i++)
14265                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14266
14267         return 0;
14268 }
14269
14270 /* TC min bandwidth setting */
14271 static void
14272 cmd_vf_tc_min_bw_parsed(
14273         void *parsed_result,
14274         __attribute__((unused)) struct cmdline *cl,
14275         __attribute__((unused)) void *data)
14276 {
14277         struct cmd_vf_tc_bw_result *res = parsed_result;
14278         uint8_t tc_num;
14279         uint8_t bw[16];
14280         int ret = -ENOTSUP;
14281
14282         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14283                 return;
14284
14285         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14286         if (ret)
14287                 return;
14288
14289 #ifdef RTE_LIBRTE_I40E_PMD
14290         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14291                                               tc_num, bw);
14292 #endif
14293
14294         switch (ret) {
14295         case 0:
14296                 break;
14297         case -EINVAL:
14298                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14299                 break;
14300         case -ENODEV:
14301                 printf("invalid port_id %d\n", res->port_id);
14302                 break;
14303         case -ENOTSUP:
14304                 printf("function not implemented\n");
14305                 break;
14306         default:
14307                 printf("programming error: (%s)\n", strerror(-ret));
14308         }
14309 }
14310
14311 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14312         .f = cmd_vf_tc_min_bw_parsed,
14313         .data = NULL,
14314         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14315                     " <bw1, bw2, ...>",
14316         .tokens = {
14317                 (void *)&cmd_vf_tc_bw_set,
14318                 (void *)&cmd_vf_tc_bw_vf,
14319                 (void *)&cmd_vf_tc_bw_tc,
14320                 (void *)&cmd_vf_tc_bw_tx,
14321                 (void *)&cmd_vf_tc_bw_min_bw,
14322                 (void *)&cmd_vf_tc_bw_port_id,
14323                 (void *)&cmd_vf_tc_bw_vf_id,
14324                 (void *)&cmd_vf_tc_bw_bw_list,
14325                 NULL,
14326         },
14327 };
14328
14329 static void
14330 cmd_tc_min_bw_parsed(
14331         void *parsed_result,
14332         __attribute__((unused)) struct cmdline *cl,
14333         __attribute__((unused)) void *data)
14334 {
14335         struct cmd_vf_tc_bw_result *res = parsed_result;
14336         struct rte_port *port;
14337         uint8_t tc_num;
14338         uint8_t bw[16];
14339         int ret = -ENOTSUP;
14340
14341         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14342                 return;
14343
14344         port = &ports[res->port_id];
14345         /** Check if the port is not started **/
14346         if (port->port_status != RTE_PORT_STOPPED) {
14347                 printf("Please stop port %d first\n", res->port_id);
14348                 return;
14349         }
14350
14351         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14352         if (ret)
14353                 return;
14354
14355 #ifdef RTE_LIBRTE_IXGBE_PMD
14356         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14357 #endif
14358
14359         switch (ret) {
14360         case 0:
14361                 break;
14362         case -EINVAL:
14363                 printf("invalid bandwidth\n");
14364                 break;
14365         case -ENODEV:
14366                 printf("invalid port_id %d\n", res->port_id);
14367                 break;
14368         case -ENOTSUP:
14369                 printf("function not implemented\n");
14370                 break;
14371         default:
14372                 printf("programming error: (%s)\n", strerror(-ret));
14373         }
14374 }
14375
14376 cmdline_parse_inst_t cmd_tc_min_bw = {
14377         .f = cmd_tc_min_bw_parsed,
14378         .data = NULL,
14379         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14380         .tokens = {
14381                 (void *)&cmd_vf_tc_bw_set,
14382                 (void *)&cmd_vf_tc_bw_tc,
14383                 (void *)&cmd_vf_tc_bw_tx,
14384                 (void *)&cmd_vf_tc_bw_min_bw,
14385                 (void *)&cmd_vf_tc_bw_port_id,
14386                 (void *)&cmd_vf_tc_bw_bw_list,
14387                 NULL,
14388         },
14389 };
14390
14391 /* TC max bandwidth setting */
14392 static void
14393 cmd_vf_tc_max_bw_parsed(
14394         void *parsed_result,
14395         __attribute__((unused)) struct cmdline *cl,
14396         __attribute__((unused)) void *data)
14397 {
14398         struct cmd_vf_tc_bw_result *res = parsed_result;
14399         int ret = -ENOTSUP;
14400
14401         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14402                 return;
14403
14404 #ifdef RTE_LIBRTE_I40E_PMD
14405         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14406                                             res->tc_no, res->bw);
14407 #endif
14408
14409         switch (ret) {
14410         case 0:
14411                 break;
14412         case -EINVAL:
14413                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14414                        res->vf_id, res->tc_no, res->bw);
14415                 break;
14416         case -ENODEV:
14417                 printf("invalid port_id %d\n", res->port_id);
14418                 break;
14419         case -ENOTSUP:
14420                 printf("function not implemented\n");
14421                 break;
14422         default:
14423                 printf("programming error: (%s)\n", strerror(-ret));
14424         }
14425 }
14426
14427 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14428         .f = cmd_vf_tc_max_bw_parsed,
14429         .data = NULL,
14430         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14431                     " <bandwidth>",
14432         .tokens = {
14433                 (void *)&cmd_vf_tc_bw_set,
14434                 (void *)&cmd_vf_tc_bw_vf,
14435                 (void *)&cmd_vf_tc_bw_tc,
14436                 (void *)&cmd_vf_tc_bw_tx,
14437                 (void *)&cmd_vf_tc_bw_max_bw,
14438                 (void *)&cmd_vf_tc_bw_port_id,
14439                 (void *)&cmd_vf_tc_bw_vf_id,
14440                 (void *)&cmd_vf_tc_bw_tc_no,
14441                 (void *)&cmd_vf_tc_bw_bw,
14442                 NULL,
14443         },
14444 };
14445
14446
14447 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14448
14449 /* *** Set Port default Traffic Management Hierarchy *** */
14450 struct cmd_set_port_tm_hierarchy_default_result {
14451         cmdline_fixed_string_t set;
14452         cmdline_fixed_string_t port;
14453         cmdline_fixed_string_t tm;
14454         cmdline_fixed_string_t hierarchy;
14455         cmdline_fixed_string_t def;
14456         portid_t port_id;
14457 };
14458
14459 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14460         TOKEN_STRING_INITIALIZER(
14461                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14462 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14463         TOKEN_STRING_INITIALIZER(
14464                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14465 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14466         TOKEN_STRING_INITIALIZER(
14467                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14468 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14469         TOKEN_STRING_INITIALIZER(
14470                 struct cmd_set_port_tm_hierarchy_default_result,
14471                         hierarchy, "hierarchy");
14472 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14473         TOKEN_STRING_INITIALIZER(
14474                 struct cmd_set_port_tm_hierarchy_default_result,
14475                         def, "default");
14476 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14477         TOKEN_NUM_INITIALIZER(
14478                 struct cmd_set_port_tm_hierarchy_default_result,
14479                         port_id, UINT16);
14480
14481 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14482         __attribute__((unused)) struct cmdline *cl,
14483         __attribute__((unused)) void *data)
14484 {
14485         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14486         struct rte_port *p;
14487         portid_t port_id = res->port_id;
14488
14489         if (port_id_is_invalid(port_id, ENABLED_WARN))
14490                 return;
14491
14492         p = &ports[port_id];
14493
14494         /* Port tm flag */
14495         if (p->softport.tm_flag == 0) {
14496                 printf("  tm not enabled on port %u (error)\n", port_id);
14497                 return;
14498         }
14499
14500         /* Forward mode: tm */
14501         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14502                 printf("  tm mode not enabled(error)\n");
14503                 return;
14504         }
14505
14506         /* Set the default tm hierarchy */
14507         p->softport.tm.default_hierarchy_enable = 1;
14508 }
14509
14510 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14511         .f = cmd_set_port_tm_hierarchy_default_parsed,
14512         .data = NULL,
14513         .help_str = "set port tm hierarchy default <port_id>",
14514         .tokens = {
14515                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14516                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14517                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14518                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14519                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14520                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14521                 NULL,
14522         },
14523 };
14524 #endif
14525
14526 /* Strict link priority scheduling mode setting */
14527 static void
14528 cmd_strict_link_prio_parsed(
14529         void *parsed_result,
14530         __attribute__((unused)) struct cmdline *cl,
14531         __attribute__((unused)) void *data)
14532 {
14533         struct cmd_vf_tc_bw_result *res = parsed_result;
14534         int ret = -ENOTSUP;
14535
14536         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14537                 return;
14538
14539 #ifdef RTE_LIBRTE_I40E_PMD
14540         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14541 #endif
14542
14543         switch (ret) {
14544         case 0:
14545                 break;
14546         case -EINVAL:
14547                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14548                 break;
14549         case -ENODEV:
14550                 printf("invalid port_id %d\n", res->port_id);
14551                 break;
14552         case -ENOTSUP:
14553                 printf("function not implemented\n");
14554                 break;
14555         default:
14556                 printf("programming error: (%s)\n", strerror(-ret));
14557         }
14558 }
14559
14560 cmdline_parse_inst_t cmd_strict_link_prio = {
14561         .f = cmd_strict_link_prio_parsed,
14562         .data = NULL,
14563         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14564         .tokens = {
14565                 (void *)&cmd_vf_tc_bw_set,
14566                 (void *)&cmd_vf_tc_bw_tx,
14567                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14568                 (void *)&cmd_vf_tc_bw_port_id,
14569                 (void *)&cmd_vf_tc_bw_tc_map,
14570                 NULL,
14571         },
14572 };
14573
14574 /* Load dynamic device personalization*/
14575 struct cmd_ddp_add_result {
14576         cmdline_fixed_string_t ddp;
14577         cmdline_fixed_string_t add;
14578         portid_t port_id;
14579         char filepath[];
14580 };
14581
14582 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14583         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14584 cmdline_parse_token_string_t cmd_ddp_add_add =
14585         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14586 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14587         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14588 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14589         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14590
14591 static void
14592 cmd_ddp_add_parsed(
14593         void *parsed_result,
14594         __attribute__((unused)) struct cmdline *cl,
14595         __attribute__((unused)) void *data)
14596 {
14597         struct cmd_ddp_add_result *res = parsed_result;
14598         uint8_t *buff;
14599         uint32_t size;
14600         char *filepath;
14601         char *file_fld[2];
14602         int file_num;
14603         int ret = -ENOTSUP;
14604
14605         if (!all_ports_stopped()) {
14606                 printf("Please stop all ports first\n");
14607                 return;
14608         }
14609
14610         filepath = strdup(res->filepath);
14611         if (filepath == NULL) {
14612                 printf("Failed to allocate memory\n");
14613                 return;
14614         }
14615         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14616
14617         buff = open_file(file_fld[0], &size);
14618         if (!buff) {
14619                 free((void *)filepath);
14620                 return;
14621         }
14622
14623 #ifdef RTE_LIBRTE_I40E_PMD
14624         if (ret == -ENOTSUP)
14625                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14626                                                buff, size,
14627                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14628 #endif
14629
14630         if (ret == -EEXIST)
14631                 printf("Profile has already existed.\n");
14632         else if (ret < 0)
14633                 printf("Failed to load profile.\n");
14634         else if (file_num == 2)
14635                 save_file(file_fld[1], buff, size);
14636
14637         close_file(buff);
14638         free((void *)filepath);
14639 }
14640
14641 cmdline_parse_inst_t cmd_ddp_add = {
14642         .f = cmd_ddp_add_parsed,
14643         .data = NULL,
14644         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14645         .tokens = {
14646                 (void *)&cmd_ddp_add_ddp,
14647                 (void *)&cmd_ddp_add_add,
14648                 (void *)&cmd_ddp_add_port_id,
14649                 (void *)&cmd_ddp_add_filepath,
14650                 NULL,
14651         },
14652 };
14653
14654 /* Delete dynamic device personalization*/
14655 struct cmd_ddp_del_result {
14656         cmdline_fixed_string_t ddp;
14657         cmdline_fixed_string_t del;
14658         portid_t port_id;
14659         char filepath[];
14660 };
14661
14662 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14663         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14664 cmdline_parse_token_string_t cmd_ddp_del_del =
14665         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14666 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14667         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14668 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14669         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14670
14671 static void
14672 cmd_ddp_del_parsed(
14673         void *parsed_result,
14674         __attribute__((unused)) struct cmdline *cl,
14675         __attribute__((unused)) void *data)
14676 {
14677         struct cmd_ddp_del_result *res = parsed_result;
14678         uint8_t *buff;
14679         uint32_t size;
14680         int ret = -ENOTSUP;
14681
14682         if (!all_ports_stopped()) {
14683                 printf("Please stop all ports first\n");
14684                 return;
14685         }
14686
14687         buff = open_file(res->filepath, &size);
14688         if (!buff)
14689                 return;
14690
14691 #ifdef RTE_LIBRTE_I40E_PMD
14692         if (ret == -ENOTSUP)
14693                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14694                                                buff, size,
14695                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14696 #endif
14697
14698         if (ret == -EACCES)
14699                 printf("Profile does not exist.\n");
14700         else if (ret < 0)
14701                 printf("Failed to delete profile.\n");
14702
14703         close_file(buff);
14704 }
14705
14706 cmdline_parse_inst_t cmd_ddp_del = {
14707         .f = cmd_ddp_del_parsed,
14708         .data = NULL,
14709         .help_str = "ddp del <port_id> <backup_profile_path>",
14710         .tokens = {
14711                 (void *)&cmd_ddp_del_ddp,
14712                 (void *)&cmd_ddp_del_del,
14713                 (void *)&cmd_ddp_del_port_id,
14714                 (void *)&cmd_ddp_del_filepath,
14715                 NULL,
14716         },
14717 };
14718
14719 /* Get dynamic device personalization profile info */
14720 struct cmd_ddp_info_result {
14721         cmdline_fixed_string_t ddp;
14722         cmdline_fixed_string_t get;
14723         cmdline_fixed_string_t info;
14724         char filepath[];
14725 };
14726
14727 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14728         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14729 cmdline_parse_token_string_t cmd_ddp_info_get =
14730         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14731 cmdline_parse_token_string_t cmd_ddp_info_info =
14732         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14733 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14734         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14735
14736 static void
14737 cmd_ddp_info_parsed(
14738         void *parsed_result,
14739         __attribute__((unused)) struct cmdline *cl,
14740         __attribute__((unused)) void *data)
14741 {
14742         struct cmd_ddp_info_result *res = parsed_result;
14743         uint8_t *pkg;
14744         uint32_t pkg_size;
14745         int ret = -ENOTSUP;
14746 #ifdef RTE_LIBRTE_I40E_PMD
14747         uint32_t i, j, n;
14748         uint8_t *buff;
14749         uint32_t buff_size = 0;
14750         struct rte_pmd_i40e_profile_info info;
14751         uint32_t dev_num = 0;
14752         struct rte_pmd_i40e_ddp_device_id *devs;
14753         uint32_t proto_num = 0;
14754         struct rte_pmd_i40e_proto_info *proto = NULL;
14755         uint32_t pctype_num = 0;
14756         struct rte_pmd_i40e_ptype_info *pctype;
14757         uint32_t ptype_num = 0;
14758         struct rte_pmd_i40e_ptype_info *ptype;
14759         uint8_t proto_id;
14760
14761 #endif
14762
14763         pkg = open_file(res->filepath, &pkg_size);
14764         if (!pkg)
14765                 return;
14766
14767 #ifdef RTE_LIBRTE_I40E_PMD
14768         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14769                                 (uint8_t *)&info, sizeof(info),
14770                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14771         if (!ret) {
14772                 printf("Global Track id:       0x%x\n", info.track_id);
14773                 printf("Global Version:        %d.%d.%d.%d\n",
14774                         info.version.major,
14775                         info.version.minor,
14776                         info.version.update,
14777                         info.version.draft);
14778                 printf("Global Package name:   %s\n\n", info.name);
14779         }
14780
14781         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14782                                 (uint8_t *)&info, sizeof(info),
14783                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14784         if (!ret) {
14785                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14786                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14787                         info.version.major,
14788                         info.version.minor,
14789                         info.version.update,
14790                         info.version.draft);
14791                 printf("i40e Profile name:     %s\n\n", info.name);
14792         }
14793
14794         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14795                                 (uint8_t *)&buff_size, sizeof(buff_size),
14796                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14797         if (!ret && buff_size) {
14798                 buff = (uint8_t *)malloc(buff_size);
14799                 if (buff) {
14800                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14801                                                 buff, buff_size,
14802                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14803                         if (!ret)
14804                                 printf("Package Notes:\n%s\n\n", buff);
14805                         free(buff);
14806                 }
14807         }
14808
14809         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14810                                 (uint8_t *)&dev_num, sizeof(dev_num),
14811                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14812         if (!ret && dev_num) {
14813                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14814                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14815                 if (devs) {
14816                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14817                                                 (uint8_t *)devs, buff_size,
14818                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14819                         if (!ret) {
14820                                 printf("List of supported devices:\n");
14821                                 for (i = 0; i < dev_num; i++) {
14822                                         printf("  %04X:%04X %04X:%04X\n",
14823                                                 devs[i].vendor_dev_id >> 16,
14824                                                 devs[i].vendor_dev_id & 0xFFFF,
14825                                                 devs[i].sub_vendor_dev_id >> 16,
14826                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14827                                 }
14828                                 printf("\n");
14829                         }
14830                         free(devs);
14831                 }
14832         }
14833
14834         /* get information about protocols and packet types */
14835         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14836                 (uint8_t *)&proto_num, sizeof(proto_num),
14837                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14838         if (ret || !proto_num)
14839                 goto no_print_return;
14840
14841         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14842         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14843         if (!proto)
14844                 goto no_print_return;
14845
14846         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14847                                         buff_size,
14848                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14849         if (!ret) {
14850                 printf("List of used protocols:\n");
14851                 for (i = 0; i < proto_num; i++)
14852                         printf("  %2u: %s\n", proto[i].proto_id,
14853                                proto[i].name);
14854                 printf("\n");
14855         }
14856         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14857                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14858                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14859         if (ret || !pctype_num)
14860                 goto no_print_pctypes;
14861
14862         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14863         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14864         if (!pctype)
14865                 goto no_print_pctypes;
14866
14867         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14868                                         buff_size,
14869                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14870         if (ret) {
14871                 free(pctype);
14872                 goto no_print_pctypes;
14873         }
14874
14875         printf("List of defined packet classification types:\n");
14876         for (i = 0; i < pctype_num; i++) {
14877                 printf("  %2u:", pctype[i].ptype_id);
14878                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14879                         proto_id = pctype[i].protocols[j];
14880                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14881                                 for (n = 0; n < proto_num; n++) {
14882                                         if (proto[n].proto_id == proto_id) {
14883                                                 printf(" %s", proto[n].name);
14884                                                 break;
14885                                         }
14886                                 }
14887                         }
14888                 }
14889                 printf("\n");
14890         }
14891         printf("\n");
14892         free(pctype);
14893
14894 no_print_pctypes:
14895
14896         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14897                                         sizeof(ptype_num),
14898                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14899         if (ret || !ptype_num)
14900                 goto no_print_return;
14901
14902         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14903         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14904         if (!ptype)
14905                 goto no_print_return;
14906
14907         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14908                                         buff_size,
14909                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14910         if (ret) {
14911                 free(ptype);
14912                 goto no_print_return;
14913         }
14914         printf("List of defined packet types:\n");
14915         for (i = 0; i < ptype_num; i++) {
14916                 printf("  %2u:", ptype[i].ptype_id);
14917                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14918                         proto_id = ptype[i].protocols[j];
14919                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14920                                 for (n = 0; n < proto_num; n++) {
14921                                         if (proto[n].proto_id == proto_id) {
14922                                                 printf(" %s", proto[n].name);
14923                                                 break;
14924                                         }
14925                                 }
14926                         }
14927                 }
14928                 printf("\n");
14929         }
14930         free(ptype);
14931         printf("\n");
14932
14933         ret = 0;
14934 no_print_return:
14935         if (proto)
14936                 free(proto);
14937 #endif
14938         if (ret == -ENOTSUP)
14939                 printf("Function not supported in PMD driver\n");
14940         close_file(pkg);
14941 }
14942
14943 cmdline_parse_inst_t cmd_ddp_get_info = {
14944         .f = cmd_ddp_info_parsed,
14945         .data = NULL,
14946         .help_str = "ddp get info <profile_path>",
14947         .tokens = {
14948                 (void *)&cmd_ddp_info_ddp,
14949                 (void *)&cmd_ddp_info_get,
14950                 (void *)&cmd_ddp_info_info,
14951                 (void *)&cmd_ddp_info_filepath,
14952                 NULL,
14953         },
14954 };
14955
14956 /* Get dynamic device personalization profile info list*/
14957 #define PROFILE_INFO_SIZE 48
14958 #define MAX_PROFILE_NUM 16
14959
14960 struct cmd_ddp_get_list_result {
14961         cmdline_fixed_string_t ddp;
14962         cmdline_fixed_string_t get;
14963         cmdline_fixed_string_t list;
14964         portid_t port_id;
14965 };
14966
14967 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14968         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14969 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14970         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14971 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14972         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14973 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14974         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14975
14976 static void
14977 cmd_ddp_get_list_parsed(
14978         __attribute__((unused)) void *parsed_result,
14979         __attribute__((unused)) struct cmdline *cl,
14980         __attribute__((unused)) void *data)
14981 {
14982 #ifdef RTE_LIBRTE_I40E_PMD
14983         struct cmd_ddp_get_list_result *res = parsed_result;
14984         struct rte_pmd_i40e_profile_list *p_list;
14985         struct rte_pmd_i40e_profile_info *p_info;
14986         uint32_t p_num;
14987         uint32_t size;
14988         uint32_t i;
14989 #endif
14990         int ret = -ENOTSUP;
14991
14992 #ifdef RTE_LIBRTE_I40E_PMD
14993         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14994         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14995         if (!p_list)
14996                 printf("%s: Failed to malloc buffer\n", __func__);
14997
14998         if (ret == -ENOTSUP)
14999                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15000                                                 (uint8_t *)p_list, size);
15001
15002         if (!ret) {
15003                 p_num = p_list->p_count;
15004                 printf("Profile number is: %d\n\n", p_num);
15005
15006                 for (i = 0; i < p_num; i++) {
15007                         p_info = &p_list->p_info[i];
15008                         printf("Profile %d:\n", i);
15009                         printf("Track id:     0x%x\n", p_info->track_id);
15010                         printf("Version:      %d.%d.%d.%d\n",
15011                                p_info->version.major,
15012                                p_info->version.minor,
15013                                p_info->version.update,
15014                                p_info->version.draft);
15015                         printf("Profile name: %s\n\n", p_info->name);
15016                 }
15017         }
15018
15019         free(p_list);
15020 #endif
15021
15022         if (ret < 0)
15023                 printf("Failed to get ddp list\n");
15024 }
15025
15026 cmdline_parse_inst_t cmd_ddp_get_list = {
15027         .f = cmd_ddp_get_list_parsed,
15028         .data = NULL,
15029         .help_str = "ddp get list <port_id>",
15030         .tokens = {
15031                 (void *)&cmd_ddp_get_list_ddp,
15032                 (void *)&cmd_ddp_get_list_get,
15033                 (void *)&cmd_ddp_get_list_list,
15034                 (void *)&cmd_ddp_get_list_port_id,
15035                 NULL,
15036         },
15037 };
15038
15039 /* Configure input set */
15040 struct cmd_cfg_input_set_result {
15041         cmdline_fixed_string_t port;
15042         cmdline_fixed_string_t cfg;
15043         portid_t port_id;
15044         cmdline_fixed_string_t pctype;
15045         uint8_t pctype_id;
15046         cmdline_fixed_string_t inset_type;
15047         cmdline_fixed_string_t opt;
15048         cmdline_fixed_string_t field;
15049         uint8_t field_idx;
15050 };
15051
15052 static void
15053 cmd_cfg_input_set_parsed(
15054         __attribute__((unused)) void *parsed_result,
15055         __attribute__((unused)) struct cmdline *cl,
15056         __attribute__((unused)) void *data)
15057 {
15058 #ifdef RTE_LIBRTE_I40E_PMD
15059         struct cmd_cfg_input_set_result *res = parsed_result;
15060         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15061         struct rte_pmd_i40e_inset inset;
15062 #endif
15063         int ret = -ENOTSUP;
15064
15065         if (!all_ports_stopped()) {
15066                 printf("Please stop all ports first\n");
15067                 return;
15068         }
15069
15070 #ifdef RTE_LIBRTE_I40E_PMD
15071         if (!strcmp(res->inset_type, "hash_inset"))
15072                 inset_type = INSET_HASH;
15073         else if (!strcmp(res->inset_type, "fdir_inset"))
15074                 inset_type = INSET_FDIR;
15075         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15076                 inset_type = INSET_FDIR_FLX;
15077         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15078                                      &inset, inset_type);
15079         if (ret) {
15080                 printf("Failed to get input set.\n");
15081                 return;
15082         }
15083
15084         if (!strcmp(res->opt, "get")) {
15085                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15086                                                    res->field_idx);
15087                 if (ret)
15088                         printf("Field index %d is enabled.\n", res->field_idx);
15089                 else
15090                         printf("Field index %d is disabled.\n", res->field_idx);
15091                 return;
15092         } else if (!strcmp(res->opt, "set"))
15093                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15094                                                    res->field_idx);
15095         else if (!strcmp(res->opt, "clear"))
15096                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15097                                                      res->field_idx);
15098         if (ret) {
15099                 printf("Failed to configure input set field.\n");
15100                 return;
15101         }
15102
15103         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15104                                      &inset, inset_type);
15105         if (ret) {
15106                 printf("Failed to set input set.\n");
15107                 return;
15108         }
15109 #endif
15110
15111         if (ret == -ENOTSUP)
15112                 printf("Function not supported\n");
15113 }
15114
15115 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15116         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15117                                  port, "port");
15118 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15119         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15120                                  cfg, "config");
15121 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15122         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15123                               port_id, UINT16);
15124 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15125         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15126                                  pctype, "pctype");
15127 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15128         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15129                               pctype_id, UINT8);
15130 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15131         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15132                                  inset_type,
15133                                  "hash_inset#fdir_inset#fdir_flx_inset");
15134 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15135         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15136                                  opt, "get#set#clear");
15137 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15138         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15139                                  field, "field");
15140 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15141         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15142                               field_idx, UINT8);
15143
15144 cmdline_parse_inst_t cmd_cfg_input_set = {
15145         .f = cmd_cfg_input_set_parsed,
15146         .data = NULL,
15147         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15148                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15149         .tokens = {
15150                 (void *)&cmd_cfg_input_set_port,
15151                 (void *)&cmd_cfg_input_set_cfg,
15152                 (void *)&cmd_cfg_input_set_port_id,
15153                 (void *)&cmd_cfg_input_set_pctype,
15154                 (void *)&cmd_cfg_input_set_pctype_id,
15155                 (void *)&cmd_cfg_input_set_inset_type,
15156                 (void *)&cmd_cfg_input_set_opt,
15157                 (void *)&cmd_cfg_input_set_field,
15158                 (void *)&cmd_cfg_input_set_field_idx,
15159                 NULL,
15160         },
15161 };
15162
15163 /* Clear input set */
15164 struct cmd_clear_input_set_result {
15165         cmdline_fixed_string_t port;
15166         cmdline_fixed_string_t cfg;
15167         portid_t port_id;
15168         cmdline_fixed_string_t pctype;
15169         uint8_t pctype_id;
15170         cmdline_fixed_string_t inset_type;
15171         cmdline_fixed_string_t clear;
15172         cmdline_fixed_string_t all;
15173 };
15174
15175 static void
15176 cmd_clear_input_set_parsed(
15177         __attribute__((unused)) void *parsed_result,
15178         __attribute__((unused)) struct cmdline *cl,
15179         __attribute__((unused)) void *data)
15180 {
15181 #ifdef RTE_LIBRTE_I40E_PMD
15182         struct cmd_clear_input_set_result *res = parsed_result;
15183         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15184         struct rte_pmd_i40e_inset inset;
15185 #endif
15186         int ret = -ENOTSUP;
15187
15188         if (!all_ports_stopped()) {
15189                 printf("Please stop all ports first\n");
15190                 return;
15191         }
15192
15193 #ifdef RTE_LIBRTE_I40E_PMD
15194         if (!strcmp(res->inset_type, "hash_inset"))
15195                 inset_type = INSET_HASH;
15196         else if (!strcmp(res->inset_type, "fdir_inset"))
15197                 inset_type = INSET_FDIR;
15198         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15199                 inset_type = INSET_FDIR_FLX;
15200
15201         memset(&inset, 0, sizeof(inset));
15202
15203         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15204                                      &inset, inset_type);
15205         if (ret) {
15206                 printf("Failed to clear input set.\n");
15207                 return;
15208         }
15209
15210 #endif
15211
15212         if (ret == -ENOTSUP)
15213                 printf("Function not supported\n");
15214 }
15215
15216 cmdline_parse_token_string_t cmd_clear_input_set_port =
15217         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15218                                  port, "port");
15219 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15220         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15221                                  cfg, "config");
15222 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15223         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15224                               port_id, UINT16);
15225 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15226         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15227                                  pctype, "pctype");
15228 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15229         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15230                               pctype_id, UINT8);
15231 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15232         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15233                                  inset_type,
15234                                  "hash_inset#fdir_inset#fdir_flx_inset");
15235 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15236         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15237                                  clear, "clear");
15238 cmdline_parse_token_string_t cmd_clear_input_set_all =
15239         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15240                                  all, "all");
15241
15242 cmdline_parse_inst_t cmd_clear_input_set = {
15243         .f = cmd_clear_input_set_parsed,
15244         .data = NULL,
15245         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15246                     "fdir_inset|fdir_flx_inset clear all",
15247         .tokens = {
15248                 (void *)&cmd_clear_input_set_port,
15249                 (void *)&cmd_clear_input_set_cfg,
15250                 (void *)&cmd_clear_input_set_port_id,
15251                 (void *)&cmd_clear_input_set_pctype,
15252                 (void *)&cmd_clear_input_set_pctype_id,
15253                 (void *)&cmd_clear_input_set_inset_type,
15254                 (void *)&cmd_clear_input_set_clear,
15255                 (void *)&cmd_clear_input_set_all,
15256                 NULL,
15257         },
15258 };
15259
15260 /* show vf stats */
15261
15262 /* Common result structure for show vf stats */
15263 struct cmd_show_vf_stats_result {
15264         cmdline_fixed_string_t show;
15265         cmdline_fixed_string_t vf;
15266         cmdline_fixed_string_t stats;
15267         portid_t port_id;
15268         uint16_t vf_id;
15269 };
15270
15271 /* Common CLI fields show vf stats*/
15272 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15273         TOKEN_STRING_INITIALIZER
15274                 (struct cmd_show_vf_stats_result,
15275                  show, "show");
15276 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15277         TOKEN_STRING_INITIALIZER
15278                 (struct cmd_show_vf_stats_result,
15279                  vf, "vf");
15280 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15281         TOKEN_STRING_INITIALIZER
15282                 (struct cmd_show_vf_stats_result,
15283                  stats, "stats");
15284 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15285         TOKEN_NUM_INITIALIZER
15286                 (struct cmd_show_vf_stats_result,
15287                  port_id, UINT16);
15288 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15289         TOKEN_NUM_INITIALIZER
15290                 (struct cmd_show_vf_stats_result,
15291                  vf_id, UINT16);
15292
15293 static void
15294 cmd_show_vf_stats_parsed(
15295         void *parsed_result,
15296         __attribute__((unused)) struct cmdline *cl,
15297         __attribute__((unused)) void *data)
15298 {
15299         struct cmd_show_vf_stats_result *res = parsed_result;
15300         struct rte_eth_stats stats;
15301         int ret = -ENOTSUP;
15302         static const char *nic_stats_border = "########################";
15303
15304         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15305                 return;
15306
15307         memset(&stats, 0, sizeof(stats));
15308
15309 #ifdef RTE_LIBRTE_I40E_PMD
15310         if (ret == -ENOTSUP)
15311                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15312                                                 res->vf_id,
15313                                                 &stats);
15314 #endif
15315 #ifdef RTE_LIBRTE_BNXT_PMD
15316         if (ret == -ENOTSUP)
15317                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15318                                                 res->vf_id,
15319                                                 &stats);
15320 #endif
15321
15322         switch (ret) {
15323         case 0:
15324                 break;
15325         case -EINVAL:
15326                 printf("invalid vf_id %d\n", res->vf_id);
15327                 break;
15328         case -ENODEV:
15329                 printf("invalid port_id %d\n", res->port_id);
15330                 break;
15331         case -ENOTSUP:
15332                 printf("function not implemented\n");
15333                 break;
15334         default:
15335                 printf("programming error: (%s)\n", strerror(-ret));
15336         }
15337
15338         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15339                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15340
15341         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15342                "%-"PRIu64"\n",
15343                stats.ipackets, stats.imissed, stats.ibytes);
15344         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15345         printf("  RX-nombuf:  %-10"PRIu64"\n",
15346                stats.rx_nombuf);
15347         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15348                "%-"PRIu64"\n",
15349                stats.opackets, stats.oerrors, stats.obytes);
15350
15351         printf("  %s############################%s\n",
15352                                nic_stats_border, nic_stats_border);
15353 }
15354
15355 cmdline_parse_inst_t cmd_show_vf_stats = {
15356         .f = cmd_show_vf_stats_parsed,
15357         .data = NULL,
15358         .help_str = "show vf stats <port_id> <vf_id>",
15359         .tokens = {
15360                 (void *)&cmd_show_vf_stats_show,
15361                 (void *)&cmd_show_vf_stats_vf,
15362                 (void *)&cmd_show_vf_stats_stats,
15363                 (void *)&cmd_show_vf_stats_port_id,
15364                 (void *)&cmd_show_vf_stats_vf_id,
15365                 NULL,
15366         },
15367 };
15368
15369 /* clear vf stats */
15370
15371 /* Common result structure for clear vf stats */
15372 struct cmd_clear_vf_stats_result {
15373         cmdline_fixed_string_t clear;
15374         cmdline_fixed_string_t vf;
15375         cmdline_fixed_string_t stats;
15376         portid_t port_id;
15377         uint16_t vf_id;
15378 };
15379
15380 /* Common CLI fields clear vf stats*/
15381 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15382         TOKEN_STRING_INITIALIZER
15383                 (struct cmd_clear_vf_stats_result,
15384                  clear, "clear");
15385 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15386         TOKEN_STRING_INITIALIZER
15387                 (struct cmd_clear_vf_stats_result,
15388                  vf, "vf");
15389 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15390         TOKEN_STRING_INITIALIZER
15391                 (struct cmd_clear_vf_stats_result,
15392                  stats, "stats");
15393 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15394         TOKEN_NUM_INITIALIZER
15395                 (struct cmd_clear_vf_stats_result,
15396                  port_id, UINT16);
15397 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15398         TOKEN_NUM_INITIALIZER
15399                 (struct cmd_clear_vf_stats_result,
15400                  vf_id, UINT16);
15401
15402 static void
15403 cmd_clear_vf_stats_parsed(
15404         void *parsed_result,
15405         __attribute__((unused)) struct cmdline *cl,
15406         __attribute__((unused)) void *data)
15407 {
15408         struct cmd_clear_vf_stats_result *res = parsed_result;
15409         int ret = -ENOTSUP;
15410
15411         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15412                 return;
15413
15414 #ifdef RTE_LIBRTE_I40E_PMD
15415         if (ret == -ENOTSUP)
15416                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15417                                                   res->vf_id);
15418 #endif
15419 #ifdef RTE_LIBRTE_BNXT_PMD
15420         if (ret == -ENOTSUP)
15421                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15422                                                   res->vf_id);
15423 #endif
15424
15425         switch (ret) {
15426         case 0:
15427                 break;
15428         case -EINVAL:
15429                 printf("invalid vf_id %d\n", res->vf_id);
15430                 break;
15431         case -ENODEV:
15432                 printf("invalid port_id %d\n", res->port_id);
15433                 break;
15434         case -ENOTSUP:
15435                 printf("function not implemented\n");
15436                 break;
15437         default:
15438                 printf("programming error: (%s)\n", strerror(-ret));
15439         }
15440 }
15441
15442 cmdline_parse_inst_t cmd_clear_vf_stats = {
15443         .f = cmd_clear_vf_stats_parsed,
15444         .data = NULL,
15445         .help_str = "clear vf stats <port_id> <vf_id>",
15446         .tokens = {
15447                 (void *)&cmd_clear_vf_stats_clear,
15448                 (void *)&cmd_clear_vf_stats_vf,
15449                 (void *)&cmd_clear_vf_stats_stats,
15450                 (void *)&cmd_clear_vf_stats_port_id,
15451                 (void *)&cmd_clear_vf_stats_vf_id,
15452                 NULL,
15453         },
15454 };
15455
15456 /* port config pctype mapping reset */
15457
15458 /* Common result structure for port config pctype mapping reset */
15459 struct cmd_pctype_mapping_reset_result {
15460         cmdline_fixed_string_t port;
15461         cmdline_fixed_string_t config;
15462         portid_t port_id;
15463         cmdline_fixed_string_t pctype;
15464         cmdline_fixed_string_t mapping;
15465         cmdline_fixed_string_t reset;
15466 };
15467
15468 /* Common CLI fields for port config pctype mapping reset*/
15469 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15470         TOKEN_STRING_INITIALIZER
15471                 (struct cmd_pctype_mapping_reset_result,
15472                  port, "port");
15473 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15474         TOKEN_STRING_INITIALIZER
15475                 (struct cmd_pctype_mapping_reset_result,
15476                  config, "config");
15477 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15478         TOKEN_NUM_INITIALIZER
15479                 (struct cmd_pctype_mapping_reset_result,
15480                  port_id, UINT16);
15481 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15482         TOKEN_STRING_INITIALIZER
15483                 (struct cmd_pctype_mapping_reset_result,
15484                  pctype, "pctype");
15485 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15486         TOKEN_STRING_INITIALIZER
15487                 (struct cmd_pctype_mapping_reset_result,
15488                  mapping, "mapping");
15489 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15490         TOKEN_STRING_INITIALIZER
15491                 (struct cmd_pctype_mapping_reset_result,
15492                  reset, "reset");
15493
15494 static void
15495 cmd_pctype_mapping_reset_parsed(
15496         void *parsed_result,
15497         __attribute__((unused)) struct cmdline *cl,
15498         __attribute__((unused)) void *data)
15499 {
15500         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15501         int ret = -ENOTSUP;
15502
15503         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15504                 return;
15505
15506 #ifdef RTE_LIBRTE_I40E_PMD
15507         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15508 #endif
15509
15510         switch (ret) {
15511         case 0:
15512                 break;
15513         case -ENODEV:
15514                 printf("invalid port_id %d\n", res->port_id);
15515                 break;
15516         case -ENOTSUP:
15517                 printf("function not implemented\n");
15518                 break;
15519         default:
15520                 printf("programming error: (%s)\n", strerror(-ret));
15521         }
15522 }
15523
15524 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15525         .f = cmd_pctype_mapping_reset_parsed,
15526         .data = NULL,
15527         .help_str = "port config <port_id> pctype mapping reset",
15528         .tokens = {
15529                 (void *)&cmd_pctype_mapping_reset_port,
15530                 (void *)&cmd_pctype_mapping_reset_config,
15531                 (void *)&cmd_pctype_mapping_reset_port_id,
15532                 (void *)&cmd_pctype_mapping_reset_pctype,
15533                 (void *)&cmd_pctype_mapping_reset_mapping,
15534                 (void *)&cmd_pctype_mapping_reset_reset,
15535                 NULL,
15536         },
15537 };
15538
15539 /* show port pctype mapping */
15540
15541 /* Common result structure for show port pctype mapping */
15542 struct cmd_pctype_mapping_get_result {
15543         cmdline_fixed_string_t show;
15544         cmdline_fixed_string_t port;
15545         portid_t port_id;
15546         cmdline_fixed_string_t pctype;
15547         cmdline_fixed_string_t mapping;
15548 };
15549
15550 /* Common CLI fields for pctype mapping get */
15551 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15552         TOKEN_STRING_INITIALIZER
15553                 (struct cmd_pctype_mapping_get_result,
15554                  show, "show");
15555 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15556         TOKEN_STRING_INITIALIZER
15557                 (struct cmd_pctype_mapping_get_result,
15558                  port, "port");
15559 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15560         TOKEN_NUM_INITIALIZER
15561                 (struct cmd_pctype_mapping_get_result,
15562                  port_id, UINT16);
15563 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15564         TOKEN_STRING_INITIALIZER
15565                 (struct cmd_pctype_mapping_get_result,
15566                  pctype, "pctype");
15567 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15568         TOKEN_STRING_INITIALIZER
15569                 (struct cmd_pctype_mapping_get_result,
15570                  mapping, "mapping");
15571
15572 static void
15573 cmd_pctype_mapping_get_parsed(
15574         void *parsed_result,
15575         __attribute__((unused)) struct cmdline *cl,
15576         __attribute__((unused)) void *data)
15577 {
15578         struct cmd_pctype_mapping_get_result *res = parsed_result;
15579         int ret = -ENOTSUP;
15580 #ifdef RTE_LIBRTE_I40E_PMD
15581         struct rte_pmd_i40e_flow_type_mapping
15582                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15583         int i, j, first_pctype;
15584 #endif
15585
15586         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15587                 return;
15588
15589 #ifdef RTE_LIBRTE_I40E_PMD
15590         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15591 #endif
15592
15593         switch (ret) {
15594         case 0:
15595                 break;
15596         case -ENODEV:
15597                 printf("invalid port_id %d\n", res->port_id);
15598                 return;
15599         case -ENOTSUP:
15600                 printf("function not implemented\n");
15601                 return;
15602         default:
15603                 printf("programming error: (%s)\n", strerror(-ret));
15604                 return;
15605         }
15606
15607 #ifdef RTE_LIBRTE_I40E_PMD
15608         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15609                 if (mapping[i].pctype != 0ULL) {
15610                         first_pctype = 1;
15611
15612                         printf("pctype: ");
15613                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15614                                 if (mapping[i].pctype & (1ULL << j)) {
15615                                         printf(first_pctype ?
15616                                                "%02d" : ",%02d", j);
15617                                         first_pctype = 0;
15618                                 }
15619                         }
15620                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15621                 }
15622         }
15623 #endif
15624 }
15625
15626 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15627         .f = cmd_pctype_mapping_get_parsed,
15628         .data = NULL,
15629         .help_str = "show port <port_id> pctype mapping",
15630         .tokens = {
15631                 (void *)&cmd_pctype_mapping_get_show,
15632                 (void *)&cmd_pctype_mapping_get_port,
15633                 (void *)&cmd_pctype_mapping_get_port_id,
15634                 (void *)&cmd_pctype_mapping_get_pctype,
15635                 (void *)&cmd_pctype_mapping_get_mapping,
15636                 NULL,
15637         },
15638 };
15639
15640 /* port config pctype mapping update */
15641
15642 /* Common result structure for port config pctype mapping update */
15643 struct cmd_pctype_mapping_update_result {
15644         cmdline_fixed_string_t port;
15645         cmdline_fixed_string_t config;
15646         portid_t port_id;
15647         cmdline_fixed_string_t pctype;
15648         cmdline_fixed_string_t mapping;
15649         cmdline_fixed_string_t update;
15650         cmdline_fixed_string_t pctype_list;
15651         uint16_t flow_type;
15652 };
15653
15654 /* Common CLI fields for pctype mapping update*/
15655 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15656         TOKEN_STRING_INITIALIZER
15657                 (struct cmd_pctype_mapping_update_result,
15658                  port, "port");
15659 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15660         TOKEN_STRING_INITIALIZER
15661                 (struct cmd_pctype_mapping_update_result,
15662                  config, "config");
15663 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15664         TOKEN_NUM_INITIALIZER
15665                 (struct cmd_pctype_mapping_update_result,
15666                  port_id, UINT16);
15667 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15668         TOKEN_STRING_INITIALIZER
15669                 (struct cmd_pctype_mapping_update_result,
15670                  pctype, "pctype");
15671 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15672         TOKEN_STRING_INITIALIZER
15673                 (struct cmd_pctype_mapping_update_result,
15674                  mapping, "mapping");
15675 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15676         TOKEN_STRING_INITIALIZER
15677                 (struct cmd_pctype_mapping_update_result,
15678                  update, "update");
15679 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15680         TOKEN_STRING_INITIALIZER
15681                 (struct cmd_pctype_mapping_update_result,
15682                  pctype_list, NULL);
15683 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15684         TOKEN_NUM_INITIALIZER
15685                 (struct cmd_pctype_mapping_update_result,
15686                  flow_type, UINT16);
15687
15688 static void
15689 cmd_pctype_mapping_update_parsed(
15690         void *parsed_result,
15691         __attribute__((unused)) struct cmdline *cl,
15692         __attribute__((unused)) void *data)
15693 {
15694         struct cmd_pctype_mapping_update_result *res = parsed_result;
15695         int ret = -ENOTSUP;
15696 #ifdef RTE_LIBRTE_I40E_PMD
15697         struct rte_pmd_i40e_flow_type_mapping mapping;
15698         unsigned int i;
15699         unsigned int nb_item;
15700         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15701 #endif
15702
15703         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15704                 return;
15705
15706 #ifdef RTE_LIBRTE_I40E_PMD
15707         nb_item = parse_item_list(res->pctype_list, "pctypes",
15708                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15709         mapping.flow_type = res->flow_type;
15710         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15711                 mapping.pctype |= (1ULL << pctype_list[i]);
15712         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15713                                                 &mapping,
15714                                                 1,
15715                                                 0);
15716 #endif
15717
15718         switch (ret) {
15719         case 0:
15720                 break;
15721         case -EINVAL:
15722                 printf("invalid pctype or flow type\n");
15723                 break;
15724         case -ENODEV:
15725                 printf("invalid port_id %d\n", res->port_id);
15726                 break;
15727         case -ENOTSUP:
15728                 printf("function not implemented\n");
15729                 break;
15730         default:
15731                 printf("programming error: (%s)\n", strerror(-ret));
15732         }
15733 }
15734
15735 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15736         .f = cmd_pctype_mapping_update_parsed,
15737         .data = NULL,
15738         .help_str = "port config <port_id> pctype mapping update"
15739         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15740         .tokens = {
15741                 (void *)&cmd_pctype_mapping_update_port,
15742                 (void *)&cmd_pctype_mapping_update_config,
15743                 (void *)&cmd_pctype_mapping_update_port_id,
15744                 (void *)&cmd_pctype_mapping_update_pctype,
15745                 (void *)&cmd_pctype_mapping_update_mapping,
15746                 (void *)&cmd_pctype_mapping_update_update,
15747                 (void *)&cmd_pctype_mapping_update_pc_type,
15748                 (void *)&cmd_pctype_mapping_update_flow_type,
15749                 NULL,
15750         },
15751 };
15752
15753 /* ptype mapping get */
15754
15755 /* Common result structure for ptype mapping get */
15756 struct cmd_ptype_mapping_get_result {
15757         cmdline_fixed_string_t ptype;
15758         cmdline_fixed_string_t mapping;
15759         cmdline_fixed_string_t get;
15760         portid_t port_id;
15761         uint8_t valid_only;
15762 };
15763
15764 /* Common CLI fields for ptype mapping get */
15765 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15766         TOKEN_STRING_INITIALIZER
15767                 (struct cmd_ptype_mapping_get_result,
15768                  ptype, "ptype");
15769 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15770         TOKEN_STRING_INITIALIZER
15771                 (struct cmd_ptype_mapping_get_result,
15772                  mapping, "mapping");
15773 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15774         TOKEN_STRING_INITIALIZER
15775                 (struct cmd_ptype_mapping_get_result,
15776                  get, "get");
15777 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15778         TOKEN_NUM_INITIALIZER
15779                 (struct cmd_ptype_mapping_get_result,
15780                  port_id, UINT16);
15781 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15782         TOKEN_NUM_INITIALIZER
15783                 (struct cmd_ptype_mapping_get_result,
15784                  valid_only, UINT8);
15785
15786 static void
15787 cmd_ptype_mapping_get_parsed(
15788         void *parsed_result,
15789         __attribute__((unused)) struct cmdline *cl,
15790         __attribute__((unused)) void *data)
15791 {
15792         struct cmd_ptype_mapping_get_result *res = parsed_result;
15793         int ret = -ENOTSUP;
15794 #ifdef RTE_LIBRTE_I40E_PMD
15795         int max_ptype_num = 256;
15796         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15797         uint16_t count;
15798         int i;
15799 #endif
15800
15801         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15802                 return;
15803
15804 #ifdef RTE_LIBRTE_I40E_PMD
15805         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15806                                         mapping,
15807                                         max_ptype_num,
15808                                         &count,
15809                                         res->valid_only);
15810 #endif
15811
15812         switch (ret) {
15813         case 0:
15814                 break;
15815         case -ENODEV:
15816                 printf("invalid port_id %d\n", res->port_id);
15817                 break;
15818         case -ENOTSUP:
15819                 printf("function not implemented\n");
15820                 break;
15821         default:
15822                 printf("programming error: (%s)\n", strerror(-ret));
15823         }
15824
15825 #ifdef RTE_LIBRTE_I40E_PMD
15826         if (!ret) {
15827                 for (i = 0; i < count; i++)
15828                         printf("%3d\t0x%08x\n",
15829                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15830         }
15831 #endif
15832 }
15833
15834 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15835         .f = cmd_ptype_mapping_get_parsed,
15836         .data = NULL,
15837         .help_str = "ptype mapping get <port_id> <valid_only>",
15838         .tokens = {
15839                 (void *)&cmd_ptype_mapping_get_ptype,
15840                 (void *)&cmd_ptype_mapping_get_mapping,
15841                 (void *)&cmd_ptype_mapping_get_get,
15842                 (void *)&cmd_ptype_mapping_get_port_id,
15843                 (void *)&cmd_ptype_mapping_get_valid_only,
15844                 NULL,
15845         },
15846 };
15847
15848 /* ptype mapping replace */
15849
15850 /* Common result structure for ptype mapping replace */
15851 struct cmd_ptype_mapping_replace_result {
15852         cmdline_fixed_string_t ptype;
15853         cmdline_fixed_string_t mapping;
15854         cmdline_fixed_string_t replace;
15855         portid_t port_id;
15856         uint32_t target;
15857         uint8_t mask;
15858         uint32_t pkt_type;
15859 };
15860
15861 /* Common CLI fields for ptype mapping replace */
15862 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15863         TOKEN_STRING_INITIALIZER
15864                 (struct cmd_ptype_mapping_replace_result,
15865                  ptype, "ptype");
15866 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15867         TOKEN_STRING_INITIALIZER
15868                 (struct cmd_ptype_mapping_replace_result,
15869                  mapping, "mapping");
15870 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15871         TOKEN_STRING_INITIALIZER
15872                 (struct cmd_ptype_mapping_replace_result,
15873                  replace, "replace");
15874 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15875         TOKEN_NUM_INITIALIZER
15876                 (struct cmd_ptype_mapping_replace_result,
15877                  port_id, UINT16);
15878 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15879         TOKEN_NUM_INITIALIZER
15880                 (struct cmd_ptype_mapping_replace_result,
15881                  target, UINT32);
15882 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15883         TOKEN_NUM_INITIALIZER
15884                 (struct cmd_ptype_mapping_replace_result,
15885                  mask, UINT8);
15886 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15887         TOKEN_NUM_INITIALIZER
15888                 (struct cmd_ptype_mapping_replace_result,
15889                  pkt_type, UINT32);
15890
15891 static void
15892 cmd_ptype_mapping_replace_parsed(
15893         void *parsed_result,
15894         __attribute__((unused)) struct cmdline *cl,
15895         __attribute__((unused)) void *data)
15896 {
15897         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15898         int ret = -ENOTSUP;
15899
15900         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15901                 return;
15902
15903 #ifdef RTE_LIBRTE_I40E_PMD
15904         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15905                                         res->target,
15906                                         res->mask,
15907                                         res->pkt_type);
15908 #endif
15909
15910         switch (ret) {
15911         case 0:
15912                 break;
15913         case -EINVAL:
15914                 printf("invalid ptype 0x%8x or 0x%8x\n",
15915                                 res->target, res->pkt_type);
15916                 break;
15917         case -ENODEV:
15918                 printf("invalid port_id %d\n", res->port_id);
15919                 break;
15920         case -ENOTSUP:
15921                 printf("function not implemented\n");
15922                 break;
15923         default:
15924                 printf("programming error: (%s)\n", strerror(-ret));
15925         }
15926 }
15927
15928 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15929         .f = cmd_ptype_mapping_replace_parsed,
15930         .data = NULL,
15931         .help_str =
15932                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15933         .tokens = {
15934                 (void *)&cmd_ptype_mapping_replace_ptype,
15935                 (void *)&cmd_ptype_mapping_replace_mapping,
15936                 (void *)&cmd_ptype_mapping_replace_replace,
15937                 (void *)&cmd_ptype_mapping_replace_port_id,
15938                 (void *)&cmd_ptype_mapping_replace_target,
15939                 (void *)&cmd_ptype_mapping_replace_mask,
15940                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15941                 NULL,
15942         },
15943 };
15944
15945 /* ptype mapping reset */
15946
15947 /* Common result structure for ptype mapping reset */
15948 struct cmd_ptype_mapping_reset_result {
15949         cmdline_fixed_string_t ptype;
15950         cmdline_fixed_string_t mapping;
15951         cmdline_fixed_string_t reset;
15952         portid_t port_id;
15953 };
15954
15955 /* Common CLI fields for ptype mapping reset*/
15956 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15957         TOKEN_STRING_INITIALIZER
15958                 (struct cmd_ptype_mapping_reset_result,
15959                  ptype, "ptype");
15960 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15961         TOKEN_STRING_INITIALIZER
15962                 (struct cmd_ptype_mapping_reset_result,
15963                  mapping, "mapping");
15964 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15965         TOKEN_STRING_INITIALIZER
15966                 (struct cmd_ptype_mapping_reset_result,
15967                  reset, "reset");
15968 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15969         TOKEN_NUM_INITIALIZER
15970                 (struct cmd_ptype_mapping_reset_result,
15971                  port_id, UINT16);
15972
15973 static void
15974 cmd_ptype_mapping_reset_parsed(
15975         void *parsed_result,
15976         __attribute__((unused)) struct cmdline *cl,
15977         __attribute__((unused)) void *data)
15978 {
15979         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15980         int ret = -ENOTSUP;
15981
15982         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15983                 return;
15984
15985 #ifdef RTE_LIBRTE_I40E_PMD
15986         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15987 #endif
15988
15989         switch (ret) {
15990         case 0:
15991                 break;
15992         case -ENODEV:
15993                 printf("invalid port_id %d\n", res->port_id);
15994                 break;
15995         case -ENOTSUP:
15996                 printf("function not implemented\n");
15997                 break;
15998         default:
15999                 printf("programming error: (%s)\n", strerror(-ret));
16000         }
16001 }
16002
16003 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16004         .f = cmd_ptype_mapping_reset_parsed,
16005         .data = NULL,
16006         .help_str = "ptype mapping reset <port_id>",
16007         .tokens = {
16008                 (void *)&cmd_ptype_mapping_reset_ptype,
16009                 (void *)&cmd_ptype_mapping_reset_mapping,
16010                 (void *)&cmd_ptype_mapping_reset_reset,
16011                 (void *)&cmd_ptype_mapping_reset_port_id,
16012                 NULL,
16013         },
16014 };
16015
16016 /* ptype mapping update */
16017
16018 /* Common result structure for ptype mapping update */
16019 struct cmd_ptype_mapping_update_result {
16020         cmdline_fixed_string_t ptype;
16021         cmdline_fixed_string_t mapping;
16022         cmdline_fixed_string_t reset;
16023         portid_t port_id;
16024         uint8_t hw_ptype;
16025         uint32_t sw_ptype;
16026 };
16027
16028 /* Common CLI fields for ptype mapping update*/
16029 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16030         TOKEN_STRING_INITIALIZER
16031                 (struct cmd_ptype_mapping_update_result,
16032                  ptype, "ptype");
16033 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16034         TOKEN_STRING_INITIALIZER
16035                 (struct cmd_ptype_mapping_update_result,
16036                  mapping, "mapping");
16037 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16038         TOKEN_STRING_INITIALIZER
16039                 (struct cmd_ptype_mapping_update_result,
16040                  reset, "update");
16041 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16042         TOKEN_NUM_INITIALIZER
16043                 (struct cmd_ptype_mapping_update_result,
16044                  port_id, UINT16);
16045 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16046         TOKEN_NUM_INITIALIZER
16047                 (struct cmd_ptype_mapping_update_result,
16048                  hw_ptype, UINT8);
16049 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16050         TOKEN_NUM_INITIALIZER
16051                 (struct cmd_ptype_mapping_update_result,
16052                  sw_ptype, UINT32);
16053
16054 static void
16055 cmd_ptype_mapping_update_parsed(
16056         void *parsed_result,
16057         __attribute__((unused)) struct cmdline *cl,
16058         __attribute__((unused)) void *data)
16059 {
16060         struct cmd_ptype_mapping_update_result *res = parsed_result;
16061         int ret = -ENOTSUP;
16062 #ifdef RTE_LIBRTE_I40E_PMD
16063         struct rte_pmd_i40e_ptype_mapping mapping;
16064 #endif
16065         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16066                 return;
16067
16068 #ifdef RTE_LIBRTE_I40E_PMD
16069         mapping.hw_ptype = res->hw_ptype;
16070         mapping.sw_ptype = res->sw_ptype;
16071         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16072                                                 &mapping,
16073                                                 1,
16074                                                 0);
16075 #endif
16076
16077         switch (ret) {
16078         case 0:
16079                 break;
16080         case -EINVAL:
16081                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16082                 break;
16083         case -ENODEV:
16084                 printf("invalid port_id %d\n", res->port_id);
16085                 break;
16086         case -ENOTSUP:
16087                 printf("function not implemented\n");
16088                 break;
16089         default:
16090                 printf("programming error: (%s)\n", strerror(-ret));
16091         }
16092 }
16093
16094 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16095         .f = cmd_ptype_mapping_update_parsed,
16096         .data = NULL,
16097         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16098         .tokens = {
16099                 (void *)&cmd_ptype_mapping_update_ptype,
16100                 (void *)&cmd_ptype_mapping_update_mapping,
16101                 (void *)&cmd_ptype_mapping_update_update,
16102                 (void *)&cmd_ptype_mapping_update_port_id,
16103                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16104                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16105                 NULL,
16106         },
16107 };
16108
16109 /* Common result structure for file commands */
16110 struct cmd_cmdfile_result {
16111         cmdline_fixed_string_t load;
16112         cmdline_fixed_string_t filename;
16113 };
16114
16115 /* Common CLI fields for file commands */
16116 cmdline_parse_token_string_t cmd_load_cmdfile =
16117         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16118 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16119         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16120
16121 static void
16122 cmd_load_from_file_parsed(
16123         void *parsed_result,
16124         __attribute__((unused)) struct cmdline *cl,
16125         __attribute__((unused)) void *data)
16126 {
16127         struct cmd_cmdfile_result *res = parsed_result;
16128
16129         cmdline_read_from_file(res->filename);
16130 }
16131
16132 cmdline_parse_inst_t cmd_load_from_file = {
16133         .f = cmd_load_from_file_parsed,
16134         .data = NULL,
16135         .help_str = "load <filename>",
16136         .tokens = {
16137                 (void *)&cmd_load_cmdfile,
16138                 (void *)&cmd_load_cmdfile_filename,
16139                 NULL,
16140         },
16141 };
16142
16143 /* ******************************************************************************** */
16144
16145 /* list of instructions */
16146 cmdline_parse_ctx_t main_ctx[] = {
16147         (cmdline_parse_inst_t *)&cmd_help_brief,
16148         (cmdline_parse_inst_t *)&cmd_help_long,
16149         (cmdline_parse_inst_t *)&cmd_quit,
16150         (cmdline_parse_inst_t *)&cmd_load_from_file,
16151         (cmdline_parse_inst_t *)&cmd_showport,
16152         (cmdline_parse_inst_t *)&cmd_showqueue,
16153         (cmdline_parse_inst_t *)&cmd_showportall,
16154         (cmdline_parse_inst_t *)&cmd_showcfg,
16155         (cmdline_parse_inst_t *)&cmd_start,
16156         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16157         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16158         (cmdline_parse_inst_t *)&cmd_set_link_up,
16159         (cmdline_parse_inst_t *)&cmd_set_link_down,
16160         (cmdline_parse_inst_t *)&cmd_reset,
16161         (cmdline_parse_inst_t *)&cmd_set_numbers,
16162         (cmdline_parse_inst_t *)&cmd_set_log,
16163         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16164         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16165         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16166         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16167         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16168         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16169         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16170         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16171         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16172         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16173         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16174         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16175         (cmdline_parse_inst_t *)&cmd_set_link_check,
16176         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16177         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16178         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16179         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16180 #ifdef RTE_LIBRTE_PMD_BOND
16181         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16182         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16183         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16184         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16185         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16186         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16187         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16188         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16189         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16190         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16191         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16192 #endif
16193         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16194         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16195         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16196         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16197         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16198         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16199         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16200         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16201         (cmdline_parse_inst_t *)&cmd_csum_set,
16202         (cmdline_parse_inst_t *)&cmd_csum_show,
16203         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16204         (cmdline_parse_inst_t *)&cmd_tso_set,
16205         (cmdline_parse_inst_t *)&cmd_tso_show,
16206         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16207         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16208         (cmdline_parse_inst_t *)&cmd_gro_enable,
16209         (cmdline_parse_inst_t *)&cmd_gro_flush,
16210         (cmdline_parse_inst_t *)&cmd_gro_show,
16211         (cmdline_parse_inst_t *)&cmd_gso_enable,
16212         (cmdline_parse_inst_t *)&cmd_gso_size,
16213         (cmdline_parse_inst_t *)&cmd_gso_show,
16214         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16215         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16216         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16217         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16218         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16219         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16220         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16221         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16222         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16223         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16224         (cmdline_parse_inst_t *)&cmd_config_dcb,
16225         (cmdline_parse_inst_t *)&cmd_read_reg,
16226         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16227         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16228         (cmdline_parse_inst_t *)&cmd_write_reg,
16229         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16230         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16231         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16232         (cmdline_parse_inst_t *)&cmd_stop,
16233         (cmdline_parse_inst_t *)&cmd_mac_addr,
16234         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16235         (cmdline_parse_inst_t *)&cmd_set_qmap,
16236         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16237         (cmdline_parse_inst_t *)&cmd_operate_port,
16238         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16239         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16240         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16241         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16242         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16243         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16244         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16245         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16246         (cmdline_parse_inst_t *)&cmd_config_mtu,
16247         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16248         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16249         (cmdline_parse_inst_t *)&cmd_config_rss,
16250         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16251         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16252         (cmdline_parse_inst_t *)&cmd_showport_reta,
16253         (cmdline_parse_inst_t *)&cmd_config_burst,
16254         (cmdline_parse_inst_t *)&cmd_config_thresh,
16255         (cmdline_parse_inst_t *)&cmd_config_threshold,
16256         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16257         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16258         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16259         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16260         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16261         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16262         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16263         (cmdline_parse_inst_t *)&cmd_global_config,
16264         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16265         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16266         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16267         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16268         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16269         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16270         (cmdline_parse_inst_t *)&cmd_dump,
16271         (cmdline_parse_inst_t *)&cmd_dump_one,
16272         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16273         (cmdline_parse_inst_t *)&cmd_syn_filter,
16274         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16275         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16276         (cmdline_parse_inst_t *)&cmd_flex_filter,
16277         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16278         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16279         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16280         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16281         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16282         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16283         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16284         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16285         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16286         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16287         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16288         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16289         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16290         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16291         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16292         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16293         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16294         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16295         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16296         (cmdline_parse_inst_t *)&cmd_flow,
16297         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16298         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16299         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16300         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16301         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16302         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16303         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16304         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16305         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16306         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16307         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16308         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16309         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16310         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16311         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16312         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16313         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16314         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16315         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16316         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16317         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16318         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16319         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16320         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16321         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16322         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16323         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16324         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16325         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16326         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16327         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16328         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16329         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16330         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16331         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16332         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16333         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16334         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16335         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16336         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16337         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16338         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16339         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16340         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16341         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16342         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16343         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16344         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16345         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16346 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16347         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16348 #endif
16349         (cmdline_parse_inst_t *)&cmd_ddp_add,
16350         (cmdline_parse_inst_t *)&cmd_ddp_del,
16351         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16352         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16353         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16354         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16355         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16356         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16357         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16358         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16359         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16360         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16361
16362         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16363         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16364         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16365         (cmdline_parse_inst_t *)&cmd_queue_region,
16366         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16367         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16368         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16369         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16370         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16371         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16372         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16373         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16374         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16375         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16376         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16377         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16378         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16379         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16380         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16381         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16382         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16383         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16384         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16385         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16386         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16387         NULL,
16388 };
16389
16390 /* read cmdline commands from file */
16391 void
16392 cmdline_read_from_file(const char *filename)
16393 {
16394         struct cmdline *cl;
16395
16396         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16397         if (cl == NULL) {
16398                 printf("Failed to create file based cmdline context: %s\n",
16399                        filename);
16400                 return;
16401         }
16402
16403         cmdline_interact(cl);
16404         cmdline_quit(cl);
16405
16406         cmdline_free(cl);
16407
16408         printf("Read CLI commands from %s\n", filename);
16409 }
16410
16411 /* prompt function, called from main on MASTER lcore */
16412 void
16413 prompt(void)
16414 {
16415         /* initialize non-constant commands */
16416         cmd_set_fwd_mode_init();
16417         cmd_set_fwd_retry_mode_init();
16418
16419         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16420         if (testpmd_cl == NULL)
16421                 return;
16422         cmdline_interact(testpmd_cl);
16423         cmdline_stdin_exit(testpmd_cl);
16424 }
16425
16426 void
16427 prompt_exit(void)
16428 {
16429         if (testpmd_cl != NULL)
16430                 cmdline_quit(testpmd_cl);
16431 }
16432
16433 static void
16434 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16435 {
16436         if (id == (portid_t)RTE_PORT_ALL) {
16437                 portid_t pid;
16438
16439                 RTE_ETH_FOREACH_DEV(pid) {
16440                         /* check if need_reconfig has been set to 1 */
16441                         if (ports[pid].need_reconfig == 0)
16442                                 ports[pid].need_reconfig = dev;
16443                         /* check if need_reconfig_queues has been set to 1 */
16444                         if (ports[pid].need_reconfig_queues == 0)
16445                                 ports[pid].need_reconfig_queues = queue;
16446                 }
16447         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16448                 /* check if need_reconfig has been set to 1 */
16449                 if (ports[id].need_reconfig == 0)
16450                         ports[id].need_reconfig = dev;
16451                 /* check if need_reconfig_queues has been set to 1 */
16452                 if (ports[id].need_reconfig_queues == 0)
16453                         ports[id].need_reconfig_queues = queue;
16454         }
16455 }