276c7516246902ad0aa9ebadd4f62a6de4cf53c4
[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 (port_id) (rxq|txq) (queue_id) setup\n"
854                         "    Setup a rx/tx queue of port X.\n\n"
855
856                         "port config (port_id|all) l2-tunnel E-tag ether-type"
857                         " (value)\n"
858                         "    Set the value of E-tag ether-type.\n\n"
859
860                         "port config (port_id|all) l2-tunnel E-tag"
861                         " (enable|disable)\n"
862                         "    Enable/disable the E-tag support.\n\n"
863
864                         "port config (port_id) pctype mapping reset\n"
865                         "    Reset flow type to pctype mapping on a port\n\n"
866
867                         "port config (port_id) pctype mapping update"
868                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
869                         "    Update a flow type to pctype mapping item on a port\n\n"
870
871                         "port config (port_id) pctype (pctype_id) hash_inset|"
872                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
873                         " (field_idx)\n"
874                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
875
876                         "port config (port_id) pctype (pctype_id) hash_inset|"
877                         "fdir_inset|fdir_flx_inset clear all"
878                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
879                 );
880         }
881
882         if (show_all || !strcmp(res->section, "registers")) {
883
884                 cmdline_printf(
885                         cl,
886                         "\n"
887                         "Registers:\n"
888                         "----------\n\n"
889
890                         "read reg (port_id) (address)\n"
891                         "    Display value of a port register.\n\n"
892
893                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
894                         "    Display a port register bit field.\n\n"
895
896                         "read regbit (port_id) (address) (bit_x)\n"
897                         "    Display a single port register bit.\n\n"
898
899                         "write reg (port_id) (address) (value)\n"
900                         "    Set value of a port register.\n\n"
901
902                         "write regfield (port_id) (address) (bit_x) (bit_y)"
903                         " (value)\n"
904                         "    Set bit field of a port register.\n\n"
905
906                         "write regbit (port_id) (address) (bit_x) (value)\n"
907                         "    Set single bit value of a port register.\n\n"
908                 );
909         }
910         if (show_all || !strcmp(res->section, "filters")) {
911
912                 cmdline_printf(
913                         cl,
914                         "\n"
915                         "filters:\n"
916                         "--------\n\n"
917
918                         "ethertype_filter (port_id) (add|del)"
919                         " (mac_addr|mac_ignr) (mac_address) ethertype"
920                         " (ether_type) (drop|fwd) queue (queue_id)\n"
921                         "    Add/Del an ethertype filter.\n\n"
922
923                         "2tuple_filter (port_id) (add|del)"
924                         " dst_port (dst_port_value) protocol (protocol_value)"
925                         " mask (mask_value) tcp_flags (tcp_flags_value)"
926                         " priority (prio_value) queue (queue_id)\n"
927                         "    Add/Del a 2tuple filter.\n\n"
928
929                         "5tuple_filter (port_id) (add|del)"
930                         " dst_ip (dst_address) src_ip (src_address)"
931                         " dst_port (dst_port_value) src_port (src_port_value)"
932                         " protocol (protocol_value)"
933                         " mask (mask_value) tcp_flags (tcp_flags_value)"
934                         " priority (prio_value) queue (queue_id)\n"
935                         "    Add/Del a 5tuple filter.\n\n"
936
937                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
938                         "    Add/Del syn filter.\n\n"
939
940                         "flex_filter (port_id) (add|del) len (len_value)"
941                         " bytes (bytes_value) mask (mask_value)"
942                         " priority (prio_value) queue (queue_id)\n"
943                         "    Add/Del a flex filter.\n\n"
944
945                         "flow_director_filter (port_id) mode IP (add|del|update)"
946                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
947                         " src (src_ip_address) dst (dst_ip_address)"
948                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
949                         " vlan (vlan_value) flexbytes (flexbytes_value)"
950                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
951                         " fd_id (fd_id_value)\n"
952                         "    Add/Del an IP type flow director filter.\n\n"
953
954                         "flow_director_filter (port_id) mode IP (add|del|update)"
955                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
956                         " src (src_ip_address) (src_port)"
957                         " dst (dst_ip_address) (dst_port)"
958                         " tos (tos_value) ttl (ttl_value)"
959                         " vlan (vlan_value) flexbytes (flexbytes_value)"
960                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
961                         " fd_id (fd_id_value)\n"
962                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
963
964                         "flow_director_filter (port_id) mode IP (add|del|update)"
965                         " flow (ipv4-sctp|ipv6-sctp)"
966                         " src (src_ip_address) (src_port)"
967                         " dst (dst_ip_address) (dst_port)"
968                         " tag (verification_tag) "
969                         " tos (tos_value) ttl (ttl_value)"
970                         " vlan (vlan_value)"
971                         " flexbytes (flexbytes_value) (drop|fwd)"
972                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
973                         "    Add/Del a SCTP type flow director filter.\n\n"
974
975                         "flow_director_filter (port_id) mode IP (add|del|update)"
976                         " flow l2_payload ether (ethertype)"
977                         " flexbytes (flexbytes_value) (drop|fwd)"
978                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
979                         "    Add/Del a l2 payload type flow director filter.\n\n"
980
981                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
982                         " mac (mac_address) vlan (vlan_value)"
983                         " flexbytes (flexbytes_value) (drop|fwd)"
984                         " queue (queue_id) fd_id (fd_id_value)\n"
985                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
986
987                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
988                         " mac (mac_address) vlan (vlan_value)"
989                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
990                         " flexbytes (flexbytes_value) (drop|fwd)"
991                         " queue (queue_id) fd_id (fd_id_value)\n"
992                         "    Add/Del a Tunnel flow director filter.\n\n"
993
994                         "flow_director_filter (port_id) mode raw (add|del|update)"
995                         " flow (flow_id) (drop|fwd) queue (queue_id)"
996                         " fd_id (fd_id_value) packet (packet file name)\n"
997                         "    Add/Del a raw type flow director filter.\n\n"
998
999                         "flush_flow_director (port_id)\n"
1000                         "    Flush all flow director entries of a device.\n\n"
1001
1002                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1003                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1004                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1005                         "    Set flow director IP mask.\n\n"
1006
1007                         "flow_director_mask (port_id) mode MAC-VLAN"
1008                         " vlan (vlan_value)\n"
1009                         "    Set flow director MAC-VLAN mask.\n\n"
1010
1011                         "flow_director_mask (port_id) mode Tunnel"
1012                         " vlan (vlan_value) mac (mac_value)"
1013                         " tunnel-type (tunnel_type_value)"
1014                         " tunnel-id (tunnel_id_value)\n"
1015                         "    Set flow director Tunnel mask.\n\n"
1016
1017                         "flow_director_flex_mask (port_id)"
1018                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1019                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1020                         " (mask)\n"
1021                         "    Configure mask of flex payload.\n\n"
1022
1023                         "flow_director_flex_payload (port_id)"
1024                         " (raw|l2|l3|l4) (config)\n"
1025                         "    Configure flex payload selection.\n\n"
1026
1027                         "get_sym_hash_ena_per_port (port_id)\n"
1028                         "    get symmetric hash enable configuration per port.\n\n"
1029
1030                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1031                         "    set symmetric hash enable configuration per port"
1032                         " to enable or disable.\n\n"
1033
1034                         "get_hash_global_config (port_id)\n"
1035                         "    Get the global configurations of hash filters.\n\n"
1036
1037                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1038                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1039                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1040                         " (enable|disable)\n"
1041                         "    Set the global configurations of hash filters.\n\n"
1042
1043                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1044                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1045                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1046                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1047                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1048                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1049                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1050                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1051                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1052                         "fld-8th|none) (select|add)\n"
1053                         "    Set the input set for hash.\n\n"
1054
1055                         "set_fdir_input_set (port_id) "
1056                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1057                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1058                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1059                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1060                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1061                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1062                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1063                         " (select|add)\n"
1064                         "    Set the input set for FDir.\n\n"
1065
1066                         "flow validate {port_id}"
1067                         " [group {group_id}] [priority {level}]"
1068                         " [ingress] [egress]"
1069                         " pattern {item} [/ {item} [...]] / end"
1070                         " actions {action} [/ {action} [...]] / end\n"
1071                         "    Check whether a flow rule can be created.\n\n"
1072
1073                         "flow create {port_id}"
1074                         " [group {group_id}] [priority {level}]"
1075                         " [ingress] [egress]"
1076                         " pattern {item} [/ {item} [...]] / end"
1077                         " actions {action} [/ {action} [...]] / end\n"
1078                         "    Create a flow rule.\n\n"
1079
1080                         "flow destroy {port_id} rule {rule_id} [...]\n"
1081                         "    Destroy specific flow rules.\n\n"
1082
1083                         "flow flush {port_id}\n"
1084                         "    Destroy all flow rules.\n\n"
1085
1086                         "flow query {port_id} {rule_id} {action}\n"
1087                         "    Query an existing flow rule.\n\n"
1088
1089                         "flow list {port_id} [group {group_id}] [...]\n"
1090                         "    List existing flow rules sorted by priority,"
1091                         " filtered by group identifiers.\n\n"
1092
1093                         "flow isolate {port_id} {boolean}\n"
1094                         "    Restrict ingress traffic to the defined"
1095                         " flow rules\n\n"
1096                 );
1097         }
1098 }
1099
1100 cmdline_parse_token_string_t cmd_help_long_help =
1101         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1102
1103 cmdline_parse_token_string_t cmd_help_long_section =
1104         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1105                         "all#control#display#config#"
1106                         "ports#registers#filters");
1107
1108 cmdline_parse_inst_t cmd_help_long = {
1109         .f = cmd_help_long_parsed,
1110         .data = NULL,
1111         .help_str = "help all|control|display|config|ports|register|filters: "
1112                 "Show help",
1113         .tokens = {
1114                 (void *)&cmd_help_long_help,
1115                 (void *)&cmd_help_long_section,
1116                 NULL,
1117         },
1118 };
1119
1120
1121 /* *** start/stop/close all ports *** */
1122 struct cmd_operate_port_result {
1123         cmdline_fixed_string_t keyword;
1124         cmdline_fixed_string_t name;
1125         cmdline_fixed_string_t value;
1126 };
1127
1128 static void cmd_operate_port_parsed(void *parsed_result,
1129                                 __attribute__((unused)) struct cmdline *cl,
1130                                 __attribute__((unused)) void *data)
1131 {
1132         struct cmd_operate_port_result *res = parsed_result;
1133
1134         if (!strcmp(res->name, "start"))
1135                 start_port(RTE_PORT_ALL);
1136         else if (!strcmp(res->name, "stop"))
1137                 stop_port(RTE_PORT_ALL);
1138         else if (!strcmp(res->name, "close"))
1139                 close_port(RTE_PORT_ALL);
1140         else if (!strcmp(res->name, "reset"))
1141                 reset_port(RTE_PORT_ALL);
1142         else
1143                 printf("Unknown parameter\n");
1144 }
1145
1146 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1147         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1148                                                                 "port");
1149 cmdline_parse_token_string_t cmd_operate_port_all_port =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1151                                                 "start#stop#close#reset");
1152 cmdline_parse_token_string_t cmd_operate_port_all_all =
1153         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1154
1155 cmdline_parse_inst_t cmd_operate_port = {
1156         .f = cmd_operate_port_parsed,
1157         .data = NULL,
1158         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1159         .tokens = {
1160                 (void *)&cmd_operate_port_all_cmd,
1161                 (void *)&cmd_operate_port_all_port,
1162                 (void *)&cmd_operate_port_all_all,
1163                 NULL,
1164         },
1165 };
1166
1167 /* *** start/stop/close specific port *** */
1168 struct cmd_operate_specific_port_result {
1169         cmdline_fixed_string_t keyword;
1170         cmdline_fixed_string_t name;
1171         uint8_t value;
1172 };
1173
1174 static void cmd_operate_specific_port_parsed(void *parsed_result,
1175                         __attribute__((unused)) struct cmdline *cl,
1176                                 __attribute__((unused)) void *data)
1177 {
1178         struct cmd_operate_specific_port_result *res = parsed_result;
1179
1180         if (!strcmp(res->name, "start"))
1181                 start_port(res->value);
1182         else if (!strcmp(res->name, "stop"))
1183                 stop_port(res->value);
1184         else if (!strcmp(res->name, "close"))
1185                 close_port(res->value);
1186         else if (!strcmp(res->name, "reset"))
1187                 reset_port(res->value);
1188         else
1189                 printf("Unknown parameter\n");
1190 }
1191
1192 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1193         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1194                                                         keyword, "port");
1195 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1196         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1197                                                 name, "start#stop#close#reset");
1198 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1199         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1200                                                         value, UINT8);
1201
1202 cmdline_parse_inst_t cmd_operate_specific_port = {
1203         .f = cmd_operate_specific_port_parsed,
1204         .data = NULL,
1205         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1206         .tokens = {
1207                 (void *)&cmd_operate_specific_port_cmd,
1208                 (void *)&cmd_operate_specific_port_port,
1209                 (void *)&cmd_operate_specific_port_id,
1210                 NULL,
1211         },
1212 };
1213
1214 /* *** attach a specified port *** */
1215 struct cmd_operate_attach_port_result {
1216         cmdline_fixed_string_t port;
1217         cmdline_fixed_string_t keyword;
1218         cmdline_fixed_string_t identifier;
1219 };
1220
1221 static void cmd_operate_attach_port_parsed(void *parsed_result,
1222                                 __attribute__((unused)) struct cmdline *cl,
1223                                 __attribute__((unused)) void *data)
1224 {
1225         struct cmd_operate_attach_port_result *res = parsed_result;
1226
1227         if (!strcmp(res->keyword, "attach"))
1228                 attach_port(res->identifier);
1229         else
1230                 printf("Unknown parameter\n");
1231 }
1232
1233 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1235                         port, "port");
1236 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1238                         keyword, "attach");
1239 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1240         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1241                         identifier, NULL);
1242
1243 cmdline_parse_inst_t cmd_operate_attach_port = {
1244         .f = cmd_operate_attach_port_parsed,
1245         .data = NULL,
1246         .help_str = "port attach <identifier>: "
1247                 "(identifier: pci address or virtual dev name)",
1248         .tokens = {
1249                 (void *)&cmd_operate_attach_port_port,
1250                 (void *)&cmd_operate_attach_port_keyword,
1251                 (void *)&cmd_operate_attach_port_identifier,
1252                 NULL,
1253         },
1254 };
1255
1256 /* *** detach a specified port *** */
1257 struct cmd_operate_detach_port_result {
1258         cmdline_fixed_string_t port;
1259         cmdline_fixed_string_t keyword;
1260         portid_t port_id;
1261 };
1262
1263 static void cmd_operate_detach_port_parsed(void *parsed_result,
1264                                 __attribute__((unused)) struct cmdline *cl,
1265                                 __attribute__((unused)) void *data)
1266 {
1267         struct cmd_operate_detach_port_result *res = parsed_result;
1268
1269         if (!strcmp(res->keyword, "detach"))
1270                 detach_port(res->port_id);
1271         else
1272                 printf("Unknown parameter\n");
1273 }
1274
1275 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1277                         port, "port");
1278 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1279         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1280                         keyword, "detach");
1281 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1282         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1283                         port_id, UINT16);
1284
1285 cmdline_parse_inst_t cmd_operate_detach_port = {
1286         .f = cmd_operate_detach_port_parsed,
1287         .data = NULL,
1288         .help_str = "port detach <port_id>",
1289         .tokens = {
1290                 (void *)&cmd_operate_detach_port_port,
1291                 (void *)&cmd_operate_detach_port_keyword,
1292                 (void *)&cmd_operate_detach_port_port_id,
1293                 NULL,
1294         },
1295 };
1296
1297 /* *** configure speed for all ports *** */
1298 struct cmd_config_speed_all {
1299         cmdline_fixed_string_t port;
1300         cmdline_fixed_string_t keyword;
1301         cmdline_fixed_string_t all;
1302         cmdline_fixed_string_t item1;
1303         cmdline_fixed_string_t item2;
1304         cmdline_fixed_string_t value1;
1305         cmdline_fixed_string_t value2;
1306 };
1307
1308 static int
1309 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1310 {
1311
1312         int duplex;
1313
1314         if (!strcmp(duplexstr, "half")) {
1315                 duplex = ETH_LINK_HALF_DUPLEX;
1316         } else if (!strcmp(duplexstr, "full")) {
1317                 duplex = ETH_LINK_FULL_DUPLEX;
1318         } else if (!strcmp(duplexstr, "auto")) {
1319                 duplex = ETH_LINK_FULL_DUPLEX;
1320         } else {
1321                 printf("Unknown duplex parameter\n");
1322                 return -1;
1323         }
1324
1325         if (!strcmp(speedstr, "10")) {
1326                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1327                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1328         } else if (!strcmp(speedstr, "100")) {
1329                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1330                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1331         } else {
1332                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1333                         printf("Invalid speed/duplex parameters\n");
1334                         return -1;
1335                 }
1336                 if (!strcmp(speedstr, "1000")) {
1337                         *speed = ETH_LINK_SPEED_1G;
1338                 } else if (!strcmp(speedstr, "10000")) {
1339                         *speed = ETH_LINK_SPEED_10G;
1340                 } else if (!strcmp(speedstr, "25000")) {
1341                         *speed = ETH_LINK_SPEED_25G;
1342                 } else if (!strcmp(speedstr, "40000")) {
1343                         *speed = ETH_LINK_SPEED_40G;
1344                 } else if (!strcmp(speedstr, "50000")) {
1345                         *speed = ETH_LINK_SPEED_50G;
1346                 } else if (!strcmp(speedstr, "100000")) {
1347                         *speed = ETH_LINK_SPEED_100G;
1348                 } else if (!strcmp(speedstr, "auto")) {
1349                         *speed = ETH_LINK_SPEED_AUTONEG;
1350                 } else {
1351                         printf("Unknown speed parameter\n");
1352                         return -1;
1353                 }
1354         }
1355
1356         return 0;
1357 }
1358
1359 static void
1360 cmd_config_speed_all_parsed(void *parsed_result,
1361                         __attribute__((unused)) struct cmdline *cl,
1362                         __attribute__((unused)) void *data)
1363 {
1364         struct cmd_config_speed_all *res = parsed_result;
1365         uint32_t link_speed;
1366         portid_t pid;
1367
1368         if (!all_ports_stopped()) {
1369                 printf("Please stop all ports first\n");
1370                 return;
1371         }
1372
1373         if (parse_and_check_speed_duplex(res->value1, res->value2,
1374                         &link_speed) < 0)
1375                 return;
1376
1377         RTE_ETH_FOREACH_DEV(pid) {
1378                 ports[pid].dev_conf.link_speeds = link_speed;
1379         }
1380
1381         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1382 }
1383
1384 cmdline_parse_token_string_t cmd_config_speed_all_port =
1385         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1386 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1387         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1388                                                         "config");
1389 cmdline_parse_token_string_t cmd_config_speed_all_all =
1390         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1391 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1393 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1395                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1396 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1397         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1398 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1399         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1400                                                 "half#full#auto");
1401
1402 cmdline_parse_inst_t cmd_config_speed_all = {
1403         .f = cmd_config_speed_all_parsed,
1404         .data = NULL,
1405         .help_str = "port config all speed "
1406                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1407                                                         "half|full|auto",
1408         .tokens = {
1409                 (void *)&cmd_config_speed_all_port,
1410                 (void *)&cmd_config_speed_all_keyword,
1411                 (void *)&cmd_config_speed_all_all,
1412                 (void *)&cmd_config_speed_all_item1,
1413                 (void *)&cmd_config_speed_all_value1,
1414                 (void *)&cmd_config_speed_all_item2,
1415                 (void *)&cmd_config_speed_all_value2,
1416                 NULL,
1417         },
1418 };
1419
1420 /* *** configure speed for specific port *** */
1421 struct cmd_config_speed_specific {
1422         cmdline_fixed_string_t port;
1423         cmdline_fixed_string_t keyword;
1424         portid_t id;
1425         cmdline_fixed_string_t item1;
1426         cmdline_fixed_string_t item2;
1427         cmdline_fixed_string_t value1;
1428         cmdline_fixed_string_t value2;
1429 };
1430
1431 static void
1432 cmd_config_speed_specific_parsed(void *parsed_result,
1433                                 __attribute__((unused)) struct cmdline *cl,
1434                                 __attribute__((unused)) void *data)
1435 {
1436         struct cmd_config_speed_specific *res = parsed_result;
1437         uint32_t link_speed;
1438
1439         if (!all_ports_stopped()) {
1440                 printf("Please stop all ports first\n");
1441                 return;
1442         }
1443
1444         if (port_id_is_invalid(res->id, ENABLED_WARN))
1445                 return;
1446
1447         if (parse_and_check_speed_duplex(res->value1, res->value2,
1448                         &link_speed) < 0)
1449                 return;
1450
1451         ports[res->id].dev_conf.link_speeds = link_speed;
1452
1453         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1454 }
1455
1456
1457 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1459                                                                 "port");
1460 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1461         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1462                                                                 "config");
1463 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1464         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1465 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1467                                                                 "speed");
1468 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1470                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1473                                                                 "duplex");
1474 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1475         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1476                                                         "half#full#auto");
1477
1478 cmdline_parse_inst_t cmd_config_speed_specific = {
1479         .f = cmd_config_speed_specific_parsed,
1480         .data = NULL,
1481         .help_str = "port config <port_id> speed "
1482                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1483                                                         "half|full|auto",
1484         .tokens = {
1485                 (void *)&cmd_config_speed_specific_port,
1486                 (void *)&cmd_config_speed_specific_keyword,
1487                 (void *)&cmd_config_speed_specific_id,
1488                 (void *)&cmd_config_speed_specific_item1,
1489                 (void *)&cmd_config_speed_specific_value1,
1490                 (void *)&cmd_config_speed_specific_item2,
1491                 (void *)&cmd_config_speed_specific_value2,
1492                 NULL,
1493         },
1494 };
1495
1496 /* *** configure loopback for all ports *** */
1497 struct cmd_config_loopback_all {
1498         cmdline_fixed_string_t port;
1499         cmdline_fixed_string_t keyword;
1500         cmdline_fixed_string_t all;
1501         cmdline_fixed_string_t item;
1502         uint32_t mode;
1503 };
1504
1505 static void
1506 cmd_config_loopback_all_parsed(void *parsed_result,
1507                         __attribute__((unused)) struct cmdline *cl,
1508                         __attribute__((unused)) void *data)
1509 {
1510         struct cmd_config_loopback_all *res = parsed_result;
1511         portid_t pid;
1512
1513         if (!all_ports_stopped()) {
1514                 printf("Please stop all ports first\n");
1515                 return;
1516         }
1517
1518         RTE_ETH_FOREACH_DEV(pid) {
1519                 ports[pid].dev_conf.lpbk_mode = res->mode;
1520         }
1521
1522         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1523 }
1524
1525 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1526         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1527 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1528         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1529                                                         "config");
1530 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1531         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1532 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1533         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1534                                                         "loopback");
1535 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1536         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1537
1538 cmdline_parse_inst_t cmd_config_loopback_all = {
1539         .f = cmd_config_loopback_all_parsed,
1540         .data = NULL,
1541         .help_str = "port config all loopback <mode>",
1542         .tokens = {
1543                 (void *)&cmd_config_loopback_all_port,
1544                 (void *)&cmd_config_loopback_all_keyword,
1545                 (void *)&cmd_config_loopback_all_all,
1546                 (void *)&cmd_config_loopback_all_item,
1547                 (void *)&cmd_config_loopback_all_mode,
1548                 NULL,
1549         },
1550 };
1551
1552 /* *** configure loopback for specific port *** */
1553 struct cmd_config_loopback_specific {
1554         cmdline_fixed_string_t port;
1555         cmdline_fixed_string_t keyword;
1556         uint16_t port_id;
1557         cmdline_fixed_string_t item;
1558         uint32_t mode;
1559 };
1560
1561 static void
1562 cmd_config_loopback_specific_parsed(void *parsed_result,
1563                                 __attribute__((unused)) struct cmdline *cl,
1564                                 __attribute__((unused)) void *data)
1565 {
1566         struct cmd_config_loopback_specific *res = parsed_result;
1567
1568         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1569                 return;
1570
1571         if (!port_is_stopped(res->port_id)) {
1572                 printf("Please stop port %u first\n", res->port_id);
1573                 return;
1574         }
1575
1576         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1577
1578         cmd_reconfig_device_queue(res->port_id, 1, 1);
1579 }
1580
1581
1582 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1583         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1584                                                                 "port");
1585 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1586         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1587                                                                 "config");
1588 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1589         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1590                                                                 UINT16);
1591 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1592         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1593                                                                 "loopback");
1594 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1595         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1596                               UINT32);
1597
1598 cmdline_parse_inst_t cmd_config_loopback_specific = {
1599         .f = cmd_config_loopback_specific_parsed,
1600         .data = NULL,
1601         .help_str = "port config <port_id> loopback <mode>",
1602         .tokens = {
1603                 (void *)&cmd_config_loopback_specific_port,
1604                 (void *)&cmd_config_loopback_specific_keyword,
1605                 (void *)&cmd_config_loopback_specific_id,
1606                 (void *)&cmd_config_loopback_specific_item,
1607                 (void *)&cmd_config_loopback_specific_mode,
1608                 NULL,
1609         },
1610 };
1611
1612 /* *** configure txq/rxq, txd/rxd *** */
1613 struct cmd_config_rx_tx {
1614         cmdline_fixed_string_t port;
1615         cmdline_fixed_string_t keyword;
1616         cmdline_fixed_string_t all;
1617         cmdline_fixed_string_t name;
1618         uint16_t value;
1619 };
1620
1621 static void
1622 cmd_config_rx_tx_parsed(void *parsed_result,
1623                         __attribute__((unused)) struct cmdline *cl,
1624                         __attribute__((unused)) void *data)
1625 {
1626         struct cmd_config_rx_tx *res = parsed_result;
1627
1628         if (!all_ports_stopped()) {
1629                 printf("Please stop all ports first\n");
1630                 return;
1631         }
1632         if (!strcmp(res->name, "rxq")) {
1633                 if (!res->value && !nb_txq) {
1634                         printf("Warning: Either rx or tx queues should be non zero\n");
1635                         return;
1636                 }
1637                 if (check_nb_rxq(res->value) != 0)
1638                         return;
1639                 nb_rxq = res->value;
1640         }
1641         else if (!strcmp(res->name, "txq")) {
1642                 if (!res->value && !nb_rxq) {
1643                         printf("Warning: Either rx or tx queues should be non zero\n");
1644                         return;
1645                 }
1646                 if (check_nb_txq(res->value) != 0)
1647                         return;
1648                 nb_txq = res->value;
1649         }
1650         else if (!strcmp(res->name, "rxd")) {
1651                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1652                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1653                                         res->value, RTE_TEST_RX_DESC_MAX);
1654                         return;
1655                 }
1656                 nb_rxd = res->value;
1657         } else if (!strcmp(res->name, "txd")) {
1658                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1659                         printf("txd %d invalid - must be > 0 && <= %d\n",
1660                                         res->value, RTE_TEST_TX_DESC_MAX);
1661                         return;
1662                 }
1663                 nb_txd = res->value;
1664         } else {
1665                 printf("Unknown parameter\n");
1666                 return;
1667         }
1668
1669         fwd_config_setup();
1670
1671         init_port_config();
1672
1673         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1674 }
1675
1676 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1677         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1678 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1679         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1680 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1681         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1682 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1683         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1684                                                 "rxq#txq#rxd#txd");
1685 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1686         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1687
1688 cmdline_parse_inst_t cmd_config_rx_tx = {
1689         .f = cmd_config_rx_tx_parsed,
1690         .data = NULL,
1691         .help_str = "port config all rxq|txq|rxd|txd <value>",
1692         .tokens = {
1693                 (void *)&cmd_config_rx_tx_port,
1694                 (void *)&cmd_config_rx_tx_keyword,
1695                 (void *)&cmd_config_rx_tx_all,
1696                 (void *)&cmd_config_rx_tx_name,
1697                 (void *)&cmd_config_rx_tx_value,
1698                 NULL,
1699         },
1700 };
1701
1702 /* *** config max packet length *** */
1703 struct cmd_config_max_pkt_len_result {
1704         cmdline_fixed_string_t port;
1705         cmdline_fixed_string_t keyword;
1706         cmdline_fixed_string_t all;
1707         cmdline_fixed_string_t name;
1708         uint32_t value;
1709 };
1710
1711 static void
1712 cmd_config_max_pkt_len_parsed(void *parsed_result,
1713                                 __attribute__((unused)) struct cmdline *cl,
1714                                 __attribute__((unused)) void *data)
1715 {
1716         struct cmd_config_max_pkt_len_result *res = parsed_result;
1717         portid_t pid;
1718
1719         if (!all_ports_stopped()) {
1720                 printf("Please stop all ports first\n");
1721                 return;
1722         }
1723
1724         RTE_ETH_FOREACH_DEV(pid) {
1725                 struct rte_port *port = &ports[pid];
1726                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1727
1728                 if (!strcmp(res->name, "max-pkt-len")) {
1729                         if (res->value < ETHER_MIN_LEN) {
1730                                 printf("max-pkt-len can not be less than %d\n",
1731                                                 ETHER_MIN_LEN);
1732                                 return;
1733                         }
1734                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1735                                 return;
1736
1737                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1738                         if (res->value > ETHER_MAX_LEN)
1739                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1740                         else
1741                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1742                         port->dev_conf.rxmode.offloads = rx_offloads;
1743                 } else {
1744                         printf("Unknown parameter\n");
1745                         return;
1746                 }
1747         }
1748
1749         init_port_config();
1750
1751         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1752 }
1753
1754 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1755         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1756                                                                 "port");
1757 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1758         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1759                                                                 "config");
1760 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1761         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1762                                                                 "all");
1763 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1764         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1765                                                                 "max-pkt-len");
1766 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1767         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1768                                                                 UINT32);
1769
1770 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1771         .f = cmd_config_max_pkt_len_parsed,
1772         .data = NULL,
1773         .help_str = "port config all max-pkt-len <value>",
1774         .tokens = {
1775                 (void *)&cmd_config_max_pkt_len_port,
1776                 (void *)&cmd_config_max_pkt_len_keyword,
1777                 (void *)&cmd_config_max_pkt_len_all,
1778                 (void *)&cmd_config_max_pkt_len_name,
1779                 (void *)&cmd_config_max_pkt_len_value,
1780                 NULL,
1781         },
1782 };
1783
1784 /* *** configure port MTU *** */
1785 struct cmd_config_mtu_result {
1786         cmdline_fixed_string_t port;
1787         cmdline_fixed_string_t keyword;
1788         cmdline_fixed_string_t mtu;
1789         portid_t port_id;
1790         uint16_t value;
1791 };
1792
1793 static void
1794 cmd_config_mtu_parsed(void *parsed_result,
1795                       __attribute__((unused)) struct cmdline *cl,
1796                       __attribute__((unused)) void *data)
1797 {
1798         struct cmd_config_mtu_result *res = parsed_result;
1799
1800         if (res->value < ETHER_MIN_LEN) {
1801                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1802                 return;
1803         }
1804         port_mtu_set(res->port_id, res->value);
1805 }
1806
1807 cmdline_parse_token_string_t cmd_config_mtu_port =
1808         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1809                                  "port");
1810 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1811         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1812                                  "config");
1813 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1814         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1815                                  "mtu");
1816 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1817         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1818 cmdline_parse_token_num_t cmd_config_mtu_value =
1819         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1820
1821 cmdline_parse_inst_t cmd_config_mtu = {
1822         .f = cmd_config_mtu_parsed,
1823         .data = NULL,
1824         .help_str = "port config mtu <port_id> <value>",
1825         .tokens = {
1826                 (void *)&cmd_config_mtu_port,
1827                 (void *)&cmd_config_mtu_keyword,
1828                 (void *)&cmd_config_mtu_mtu,
1829                 (void *)&cmd_config_mtu_port_id,
1830                 (void *)&cmd_config_mtu_value,
1831                 NULL,
1832         },
1833 };
1834
1835 /* *** configure rx mode *** */
1836 struct cmd_config_rx_mode_flag {
1837         cmdline_fixed_string_t port;
1838         cmdline_fixed_string_t keyword;
1839         cmdline_fixed_string_t all;
1840         cmdline_fixed_string_t name;
1841         cmdline_fixed_string_t value;
1842 };
1843
1844 static void
1845 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1846                                 __attribute__((unused)) struct cmdline *cl,
1847                                 __attribute__((unused)) void *data)
1848 {
1849         struct cmd_config_rx_mode_flag *res = parsed_result;
1850         portid_t pid;
1851
1852         if (!all_ports_stopped()) {
1853                 printf("Please stop all ports first\n");
1854                 return;
1855         }
1856
1857         RTE_ETH_FOREACH_DEV(pid) {
1858                 struct rte_port *port;
1859                 uint64_t rx_offloads;
1860
1861                 port = &ports[pid];
1862                 rx_offloads = port->dev_conf.rxmode.offloads;
1863                 if (!strcmp(res->name, "crc-strip")) {
1864                         if (!strcmp(res->value, "on"))
1865                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1866                         else if (!strcmp(res->value, "off"))
1867                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1868                         else {
1869                                 printf("Unknown parameter\n");
1870                                 return;
1871                         }
1872                 } else if (!strcmp(res->name, "scatter")) {
1873                         if (!strcmp(res->value, "on")) {
1874                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1875                         } else if (!strcmp(res->value, "off")) {
1876                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1877                         } else {
1878                                 printf("Unknown parameter\n");
1879                                 return;
1880                         }
1881                 } else if (!strcmp(res->name, "rx-cksum")) {
1882                         if (!strcmp(res->value, "on"))
1883                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1884                         else if (!strcmp(res->value, "off"))
1885                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1886                         else {
1887                                 printf("Unknown parameter\n");
1888                                 return;
1889                         }
1890                 } else if (!strcmp(res->name, "rx-timestamp")) {
1891                         if (!strcmp(res->value, "on"))
1892                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1893                         else if (!strcmp(res->value, "off"))
1894                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1895                         else {
1896                                 printf("Unknown parameter\n");
1897                                 return;
1898                         }
1899                 } else if (!strcmp(res->name, "hw-vlan")) {
1900                         if (!strcmp(res->value, "on")) {
1901                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1902                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1903                         } else if (!strcmp(res->value, "off")) {
1904                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1905                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1906                         } else {
1907                                 printf("Unknown parameter\n");
1908                                 return;
1909                         }
1910                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1911                         if (!strcmp(res->value, "on"))
1912                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1913                         else if (!strcmp(res->value, "off"))
1914                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1915                         else {
1916                                 printf("Unknown parameter\n");
1917                                 return;
1918                         }
1919                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1920                         if (!strcmp(res->value, "on"))
1921                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1922                         else if (!strcmp(res->value, "off"))
1923                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1924                         else {
1925                                 printf("Unknown parameter\n");
1926                                 return;
1927                         }
1928                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1929                         if (!strcmp(res->value, "on"))
1930                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1931                         else if (!strcmp(res->value, "off"))
1932                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1933                         else {
1934                                 printf("Unknown parameter\n");
1935                                 return;
1936                         }
1937                 } else if (!strcmp(res->name, "drop-en")) {
1938                         if (!strcmp(res->value, "on"))
1939                                 rx_drop_en = 1;
1940                         else if (!strcmp(res->value, "off"))
1941                                 rx_drop_en = 0;
1942                         else {
1943                                 printf("Unknown parameter\n");
1944                                 return;
1945                         }
1946                 } else {
1947                         printf("Unknown parameter\n");
1948                         return;
1949                 }
1950                 port->dev_conf.rxmode.offloads = rx_offloads;
1951         }
1952
1953         init_port_config();
1954
1955         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1956 }
1957
1958 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1959         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1960 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1962                                                                 "config");
1963 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1964         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1965 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1966         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1967                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1968                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1969 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1970         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1971                                                         "on#off");
1972
1973 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1974         .f = cmd_config_rx_mode_flag_parsed,
1975         .data = NULL,
1976         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1977                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1978         .tokens = {
1979                 (void *)&cmd_config_rx_mode_flag_port,
1980                 (void *)&cmd_config_rx_mode_flag_keyword,
1981                 (void *)&cmd_config_rx_mode_flag_all,
1982                 (void *)&cmd_config_rx_mode_flag_name,
1983                 (void *)&cmd_config_rx_mode_flag_value,
1984                 NULL,
1985         },
1986 };
1987
1988 /* *** configure rss *** */
1989 struct cmd_config_rss {
1990         cmdline_fixed_string_t port;
1991         cmdline_fixed_string_t keyword;
1992         cmdline_fixed_string_t all;
1993         cmdline_fixed_string_t name;
1994         cmdline_fixed_string_t value;
1995 };
1996
1997 static void
1998 cmd_config_rss_parsed(void *parsed_result,
1999                         __attribute__((unused)) struct cmdline *cl,
2000                         __attribute__((unused)) void *data)
2001 {
2002         struct cmd_config_rss *res = parsed_result;
2003         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2004         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2005         int diag;
2006         uint16_t i;
2007
2008         if (!strcmp(res->value, "all"))
2009                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2010                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2011                                         ETH_RSS_L2_PAYLOAD;
2012         else if (!strcmp(res->value, "ip"))
2013                 rss_conf.rss_hf = ETH_RSS_IP;
2014         else if (!strcmp(res->value, "udp"))
2015                 rss_conf.rss_hf = ETH_RSS_UDP;
2016         else if (!strcmp(res->value, "tcp"))
2017                 rss_conf.rss_hf = ETH_RSS_TCP;
2018         else if (!strcmp(res->value, "sctp"))
2019                 rss_conf.rss_hf = ETH_RSS_SCTP;
2020         else if (!strcmp(res->value, "ether"))
2021                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2022         else if (!strcmp(res->value, "port"))
2023                 rss_conf.rss_hf = ETH_RSS_PORT;
2024         else if (!strcmp(res->value, "vxlan"))
2025                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2026         else if (!strcmp(res->value, "geneve"))
2027                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2028         else if (!strcmp(res->value, "nvgre"))
2029                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2030         else if (!strcmp(res->value, "none") || !strcmp(res->value, "default"))
2031                 rss_conf.rss_hf = 0;
2032         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2033                                                 atoi(res->value) < 64)
2034                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2035         else {
2036                 printf("Unknown parameter\n");
2037                 return;
2038         }
2039         rss_conf.rss_key = NULL;
2040         /* Update global configuration for RSS types. */
2041         rss_hf = rss_conf.rss_hf;
2042         RTE_ETH_FOREACH_DEV(i) {
2043                 if (!strcmp(res->value, "default")) {
2044                         rte_eth_dev_info_get(i, &dev_info);
2045                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2046                 }
2047                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
2048                 if (diag < 0)
2049                         printf("Configuration of RSS hash at ethernet port %d "
2050                                 "failed with error (%d): %s.\n",
2051                                 i, -diag, strerror(-diag));
2052         }
2053 }
2054
2055 cmdline_parse_token_string_t cmd_config_rss_port =
2056         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2057 cmdline_parse_token_string_t cmd_config_rss_keyword =
2058         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2059 cmdline_parse_token_string_t cmd_config_rss_all =
2060         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2061 cmdline_parse_token_string_t cmd_config_rss_name =
2062         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2063 cmdline_parse_token_string_t cmd_config_rss_value =
2064         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2065
2066 cmdline_parse_inst_t cmd_config_rss = {
2067         .f = cmd_config_rss_parsed,
2068         .data = NULL,
2069         .help_str = "port config all rss "
2070                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2071         .tokens = {
2072                 (void *)&cmd_config_rss_port,
2073                 (void *)&cmd_config_rss_keyword,
2074                 (void *)&cmd_config_rss_all,
2075                 (void *)&cmd_config_rss_name,
2076                 (void *)&cmd_config_rss_value,
2077                 NULL,
2078         },
2079 };
2080
2081 /* *** configure rss hash key *** */
2082 struct cmd_config_rss_hash_key {
2083         cmdline_fixed_string_t port;
2084         cmdline_fixed_string_t config;
2085         portid_t port_id;
2086         cmdline_fixed_string_t rss_hash_key;
2087         cmdline_fixed_string_t rss_type;
2088         cmdline_fixed_string_t key;
2089 };
2090
2091 static uint8_t
2092 hexa_digit_to_value(char hexa_digit)
2093 {
2094         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2095                 return (uint8_t) (hexa_digit - '0');
2096         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2097                 return (uint8_t) ((hexa_digit - 'a') + 10);
2098         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2099                 return (uint8_t) ((hexa_digit - 'A') + 10);
2100         /* Invalid hexa digit */
2101         return 0xFF;
2102 }
2103
2104 static uint8_t
2105 parse_and_check_key_hexa_digit(char *key, int idx)
2106 {
2107         uint8_t hexa_v;
2108
2109         hexa_v = hexa_digit_to_value(key[idx]);
2110         if (hexa_v == 0xFF)
2111                 printf("invalid key: character %c at position %d is not a "
2112                        "valid hexa digit\n", key[idx], idx);
2113         return hexa_v;
2114 }
2115
2116 static void
2117 cmd_config_rss_hash_key_parsed(void *parsed_result,
2118                                __attribute__((unused)) struct cmdline *cl,
2119                                __attribute__((unused)) void *data)
2120 {
2121         struct cmd_config_rss_hash_key *res = parsed_result;
2122         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2123         uint8_t xdgt0;
2124         uint8_t xdgt1;
2125         int i;
2126         struct rte_eth_dev_info dev_info;
2127         uint8_t hash_key_size;
2128         uint32_t key_len;
2129
2130         memset(&dev_info, 0, sizeof(dev_info));
2131         rte_eth_dev_info_get(res->port_id, &dev_info);
2132         if (dev_info.hash_key_size > 0 &&
2133                         dev_info.hash_key_size <= sizeof(hash_key))
2134                 hash_key_size = dev_info.hash_key_size;
2135         else {
2136                 printf("dev_info did not provide a valid hash key size\n");
2137                 return;
2138         }
2139         /* Check the length of the RSS hash key */
2140         key_len = strlen(res->key);
2141         if (key_len != (hash_key_size * 2)) {
2142                 printf("key length: %d invalid - key must be a string of %d"
2143                            " hexa-decimal numbers\n",
2144                            (int) key_len, hash_key_size * 2);
2145                 return;
2146         }
2147         /* Translate RSS hash key into binary representation */
2148         for (i = 0; i < hash_key_size; i++) {
2149                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2150                 if (xdgt0 == 0xFF)
2151                         return;
2152                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2153                 if (xdgt1 == 0xFF)
2154                         return;
2155                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2156         }
2157         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2158                         hash_key_size);
2159 }
2160
2161 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2162         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2163 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2164         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2165                                  "config");
2166 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2167         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2168 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2169         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2170                                  rss_hash_key, "rss-hash-key");
2171 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2172         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2173                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2174                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2175                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2176                                  "ipv6-tcp-ex#ipv6-udp-ex");
2177 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2178         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2179
2180 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2181         .f = cmd_config_rss_hash_key_parsed,
2182         .data = NULL,
2183         .help_str = "port config <port_id> rss-hash-key "
2184                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2185                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2186                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2187                 "<string of hex digits (variable length, NIC dependent)>",
2188         .tokens = {
2189                 (void *)&cmd_config_rss_hash_key_port,
2190                 (void *)&cmd_config_rss_hash_key_config,
2191                 (void *)&cmd_config_rss_hash_key_port_id,
2192                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2193                 (void *)&cmd_config_rss_hash_key_rss_type,
2194                 (void *)&cmd_config_rss_hash_key_value,
2195                 NULL,
2196         },
2197 };
2198
2199 /* *** configure port rxq/txq start/stop *** */
2200 struct cmd_config_rxtx_queue {
2201         cmdline_fixed_string_t port;
2202         portid_t portid;
2203         cmdline_fixed_string_t rxtxq;
2204         uint16_t qid;
2205         cmdline_fixed_string_t opname;
2206 };
2207
2208 static void
2209 cmd_config_rxtx_queue_parsed(void *parsed_result,
2210                         __attribute__((unused)) struct cmdline *cl,
2211                         __attribute__((unused)) void *data)
2212 {
2213         struct cmd_config_rxtx_queue *res = parsed_result;
2214         uint8_t isrx;
2215         uint8_t isstart;
2216         int ret = 0;
2217
2218         if (test_done == 0) {
2219                 printf("Please stop forwarding first\n");
2220                 return;
2221         }
2222
2223         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2224                 return;
2225
2226         if (port_is_started(res->portid) != 1) {
2227                 printf("Please start port %u first\n", res->portid);
2228                 return;
2229         }
2230
2231         if (!strcmp(res->rxtxq, "rxq"))
2232                 isrx = 1;
2233         else if (!strcmp(res->rxtxq, "txq"))
2234                 isrx = 0;
2235         else {
2236                 printf("Unknown parameter\n");
2237                 return;
2238         }
2239
2240         if (isrx && rx_queue_id_is_invalid(res->qid))
2241                 return;
2242         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2243                 return;
2244
2245         if (!strcmp(res->opname, "start"))
2246                 isstart = 1;
2247         else if (!strcmp(res->opname, "stop"))
2248                 isstart = 0;
2249         else {
2250                 printf("Unknown parameter\n");
2251                 return;
2252         }
2253
2254         if (isstart && isrx)
2255                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2256         else if (!isstart && isrx)
2257                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2258         else if (isstart && !isrx)
2259                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2260         else
2261                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2262
2263         if (ret == -ENOTSUP)
2264                 printf("Function not supported in PMD driver\n");
2265 }
2266
2267 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2268         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2269 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2270         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2271 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2272         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2273 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2274         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2275 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2276         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2277                                                 "start#stop");
2278
2279 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2280         .f = cmd_config_rxtx_queue_parsed,
2281         .data = NULL,
2282         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2283         .tokens = {
2284                 (void *)&cmd_config_rxtx_queue_port,
2285                 (void *)&cmd_config_rxtx_queue_portid,
2286                 (void *)&cmd_config_rxtx_queue_rxtxq,
2287                 (void *)&cmd_config_rxtx_queue_qid,
2288                 (void *)&cmd_config_rxtx_queue_opname,
2289                 NULL,
2290         },
2291 };
2292
2293 /* *** configure port rxq/txq setup *** */
2294 struct cmd_setup_rxtx_queue {
2295         cmdline_fixed_string_t port;
2296         portid_t portid;
2297         cmdline_fixed_string_t rxtxq;
2298         uint16_t qid;
2299         cmdline_fixed_string_t setup;
2300 };
2301
2302 /* Common CLI fields for queue setup */
2303 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2304         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2305 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2306         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2307 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2308         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2309 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2310         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2311 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2312         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2313
2314 static void
2315 cmd_setup_rxtx_queue_parsed(
2316         void *parsed_result,
2317         __attribute__((unused)) struct cmdline *cl,
2318         __attribute__((unused)) void *data)
2319 {
2320         struct cmd_setup_rxtx_queue *res = parsed_result;
2321         struct rte_port *port;
2322         struct rte_mempool *mp;
2323         unsigned int socket_id;
2324         uint8_t isrx = 0;
2325         int ret;
2326
2327         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2328                 return;
2329
2330         if (res->portid == (portid_t)RTE_PORT_ALL) {
2331                 printf("Invalid port id\n");
2332                 return;
2333         }
2334
2335         if (!strcmp(res->rxtxq, "rxq"))
2336                 isrx = 1;
2337         else if (!strcmp(res->rxtxq, "txq"))
2338                 isrx = 0;
2339         else {
2340                 printf("Unknown parameter\n");
2341                 return;
2342         }
2343
2344         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2345                 printf("Invalid rx queue\n");
2346                 return;
2347         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2348                 printf("Invalid tx queue\n");
2349                 return;
2350         }
2351
2352         port = &ports[res->portid];
2353         if (isrx) {
2354                 socket_id = rxring_numa[res->portid];
2355                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2356                         socket_id = port->socket_id;
2357
2358                 mp = mbuf_pool_find(socket_id);
2359                 if (mp == NULL) {
2360                         printf("Failed to setup RX queue: "
2361                                 "No mempool allocation"
2362                                 " on the socket %d\n",
2363                                 rxring_numa[res->portid]);
2364                         return;
2365                 }
2366                 ret = rte_eth_rx_queue_setup(res->portid,
2367                                              res->qid,
2368                                              port->nb_rx_desc[res->qid],
2369                                              socket_id,
2370                                              &port->rx_conf[res->qid],
2371                                              mp);
2372                 if (ret)
2373                         printf("Failed to setup RX queue\n");
2374         } else {
2375                 socket_id = txring_numa[res->portid];
2376                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2377                         socket_id = port->socket_id;
2378
2379                 ret = rte_eth_tx_queue_setup(res->portid,
2380                                              res->qid,
2381                                              port->nb_tx_desc[res->qid],
2382                                              socket_id,
2383                                              &port->tx_conf[res->qid]);
2384                 if (ret)
2385                         printf("Failed to setup TX queue\n");
2386         }
2387 }
2388
2389 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2390         .f = cmd_setup_rxtx_queue_parsed,
2391         .data = NULL,
2392         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2393         .tokens = {
2394                 (void *)&cmd_setup_rxtx_queue_port,
2395                 (void *)&cmd_setup_rxtx_queue_portid,
2396                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2397                 (void *)&cmd_setup_rxtx_queue_qid,
2398                 (void *)&cmd_setup_rxtx_queue_setup,
2399                 NULL,
2400         },
2401 };
2402
2403
2404 /* *** Configure RSS RETA *** */
2405 struct cmd_config_rss_reta {
2406         cmdline_fixed_string_t port;
2407         cmdline_fixed_string_t keyword;
2408         portid_t port_id;
2409         cmdline_fixed_string_t name;
2410         cmdline_fixed_string_t list_name;
2411         cmdline_fixed_string_t list_of_items;
2412 };
2413
2414 static int
2415 parse_reta_config(const char *str,
2416                   struct rte_eth_rss_reta_entry64 *reta_conf,
2417                   uint16_t nb_entries)
2418 {
2419         int i;
2420         unsigned size;
2421         uint16_t hash_index, idx, shift;
2422         uint16_t nb_queue;
2423         char s[256];
2424         const char *p, *p0 = str;
2425         char *end;
2426         enum fieldnames {
2427                 FLD_HASH_INDEX = 0,
2428                 FLD_QUEUE,
2429                 _NUM_FLD
2430         };
2431         unsigned long int_fld[_NUM_FLD];
2432         char *str_fld[_NUM_FLD];
2433
2434         while ((p = strchr(p0,'(')) != NULL) {
2435                 ++p;
2436                 if((p0 = strchr(p,')')) == NULL)
2437                         return -1;
2438
2439                 size = p0 - p;
2440                 if(size >= sizeof(s))
2441                         return -1;
2442
2443                 snprintf(s, sizeof(s), "%.*s", size, p);
2444                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2445                         return -1;
2446                 for (i = 0; i < _NUM_FLD; i++) {
2447                         errno = 0;
2448                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2449                         if (errno != 0 || end == str_fld[i] ||
2450                                         int_fld[i] > 65535)
2451                                 return -1;
2452                 }
2453
2454                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2455                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2456
2457                 if (hash_index >= nb_entries) {
2458                         printf("Invalid RETA hash index=%d\n", hash_index);
2459                         return -1;
2460                 }
2461
2462                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2463                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2464                 reta_conf[idx].mask |= (1ULL << shift);
2465                 reta_conf[idx].reta[shift] = nb_queue;
2466         }
2467
2468         return 0;
2469 }
2470
2471 static void
2472 cmd_set_rss_reta_parsed(void *parsed_result,
2473                         __attribute__((unused)) struct cmdline *cl,
2474                         __attribute__((unused)) void *data)
2475 {
2476         int ret;
2477         struct rte_eth_dev_info dev_info;
2478         struct rte_eth_rss_reta_entry64 reta_conf[8];
2479         struct cmd_config_rss_reta *res = parsed_result;
2480
2481         memset(&dev_info, 0, sizeof(dev_info));
2482         rte_eth_dev_info_get(res->port_id, &dev_info);
2483         if (dev_info.reta_size == 0) {
2484                 printf("Redirection table size is 0 which is "
2485                                         "invalid for RSS\n");
2486                 return;
2487         } else
2488                 printf("The reta size of port %d is %u\n",
2489                         res->port_id, dev_info.reta_size);
2490         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2491                 printf("Currently do not support more than %u entries of "
2492                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2493                 return;
2494         }
2495
2496         memset(reta_conf, 0, sizeof(reta_conf));
2497         if (!strcmp(res->list_name, "reta")) {
2498                 if (parse_reta_config(res->list_of_items, reta_conf,
2499                                                 dev_info.reta_size)) {
2500                         printf("Invalid RSS Redirection Table "
2501                                         "config entered\n");
2502                         return;
2503                 }
2504                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2505                                 reta_conf, dev_info.reta_size);
2506                 if (ret != 0)
2507                         printf("Bad redirection table parameter, "
2508                                         "return code = %d \n", ret);
2509         }
2510 }
2511
2512 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2513         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2514 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2515         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2516 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2517         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2518 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2519         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2520 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2521         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2522 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2523         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2524                                  NULL);
2525 cmdline_parse_inst_t cmd_config_rss_reta = {
2526         .f = cmd_set_rss_reta_parsed,
2527         .data = NULL,
2528         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2529         .tokens = {
2530                 (void *)&cmd_config_rss_reta_port,
2531                 (void *)&cmd_config_rss_reta_keyword,
2532                 (void *)&cmd_config_rss_reta_port_id,
2533                 (void *)&cmd_config_rss_reta_name,
2534                 (void *)&cmd_config_rss_reta_list_name,
2535                 (void *)&cmd_config_rss_reta_list_of_items,
2536                 NULL,
2537         },
2538 };
2539
2540 /* *** SHOW PORT RETA INFO *** */
2541 struct cmd_showport_reta {
2542         cmdline_fixed_string_t show;
2543         cmdline_fixed_string_t port;
2544         portid_t port_id;
2545         cmdline_fixed_string_t rss;
2546         cmdline_fixed_string_t reta;
2547         uint16_t size;
2548         cmdline_fixed_string_t list_of_items;
2549 };
2550
2551 static int
2552 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2553                            uint16_t nb_entries,
2554                            char *str)
2555 {
2556         uint32_t size;
2557         const char *p, *p0 = str;
2558         char s[256];
2559         char *end;
2560         char *str_fld[8];
2561         uint16_t i;
2562         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2563                         RTE_RETA_GROUP_SIZE;
2564         int ret;
2565
2566         p = strchr(p0, '(');
2567         if (p == NULL)
2568                 return -1;
2569         p++;
2570         p0 = strchr(p, ')');
2571         if (p0 == NULL)
2572                 return -1;
2573         size = p0 - p;
2574         if (size >= sizeof(s)) {
2575                 printf("The string size exceeds the internal buffer size\n");
2576                 return -1;
2577         }
2578         snprintf(s, sizeof(s), "%.*s", size, p);
2579         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2580         if (ret <= 0 || ret != num) {
2581                 printf("The bits of masks do not match the number of "
2582                                         "reta entries: %u\n", num);
2583                 return -1;
2584         }
2585         for (i = 0; i < ret; i++)
2586                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2587
2588         return 0;
2589 }
2590
2591 static void
2592 cmd_showport_reta_parsed(void *parsed_result,
2593                          __attribute__((unused)) struct cmdline *cl,
2594                          __attribute__((unused)) void *data)
2595 {
2596         struct cmd_showport_reta *res = parsed_result;
2597         struct rte_eth_rss_reta_entry64 reta_conf[8];
2598         struct rte_eth_dev_info dev_info;
2599         uint16_t max_reta_size;
2600
2601         memset(&dev_info, 0, sizeof(dev_info));
2602         rte_eth_dev_info_get(res->port_id, &dev_info);
2603         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2604         if (res->size == 0 || res->size > max_reta_size) {
2605                 printf("Invalid redirection table size: %u (1-%u)\n",
2606                         res->size, max_reta_size);
2607                 return;
2608         }
2609
2610         memset(reta_conf, 0, sizeof(reta_conf));
2611         if (showport_parse_reta_config(reta_conf, res->size,
2612                                 res->list_of_items) < 0) {
2613                 printf("Invalid string: %s for reta masks\n",
2614                                         res->list_of_items);
2615                 return;
2616         }
2617         port_rss_reta_info(res->port_id, reta_conf, res->size);
2618 }
2619
2620 cmdline_parse_token_string_t cmd_showport_reta_show =
2621         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2622 cmdline_parse_token_string_t cmd_showport_reta_port =
2623         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2624 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2625         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2626 cmdline_parse_token_string_t cmd_showport_reta_rss =
2627         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2628 cmdline_parse_token_string_t cmd_showport_reta_reta =
2629         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2630 cmdline_parse_token_num_t cmd_showport_reta_size =
2631         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2632 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2633         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2634                                         list_of_items, NULL);
2635
2636 cmdline_parse_inst_t cmd_showport_reta = {
2637         .f = cmd_showport_reta_parsed,
2638         .data = NULL,
2639         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2640         .tokens = {
2641                 (void *)&cmd_showport_reta_show,
2642                 (void *)&cmd_showport_reta_port,
2643                 (void *)&cmd_showport_reta_port_id,
2644                 (void *)&cmd_showport_reta_rss,
2645                 (void *)&cmd_showport_reta_reta,
2646                 (void *)&cmd_showport_reta_size,
2647                 (void *)&cmd_showport_reta_list_of_items,
2648                 NULL,
2649         },
2650 };
2651
2652 /* *** Show RSS hash configuration *** */
2653 struct cmd_showport_rss_hash {
2654         cmdline_fixed_string_t show;
2655         cmdline_fixed_string_t port;
2656         portid_t port_id;
2657         cmdline_fixed_string_t rss_hash;
2658         cmdline_fixed_string_t rss_type;
2659         cmdline_fixed_string_t key; /* optional argument */
2660 };
2661
2662 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2663                                 __attribute__((unused)) struct cmdline *cl,
2664                                 void *show_rss_key)
2665 {
2666         struct cmd_showport_rss_hash *res = parsed_result;
2667
2668         port_rss_hash_conf_show(res->port_id, res->rss_type,
2669                                 show_rss_key != NULL);
2670 }
2671
2672 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2673         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2674 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2675         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2676 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2677         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2678 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2679         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2680                                  "rss-hash");
2681 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2682         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2683                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2684                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2685                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2686                                  "ipv6-tcp-ex#ipv6-udp-ex");
2687 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2688         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2689
2690 cmdline_parse_inst_t cmd_showport_rss_hash = {
2691         .f = cmd_showport_rss_hash_parsed,
2692         .data = NULL,
2693         .help_str = "show port <port_id> rss-hash "
2694                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2695                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2696                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2697         .tokens = {
2698                 (void *)&cmd_showport_rss_hash_show,
2699                 (void *)&cmd_showport_rss_hash_port,
2700                 (void *)&cmd_showport_rss_hash_port_id,
2701                 (void *)&cmd_showport_rss_hash_rss_hash,
2702                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2703                 NULL,
2704         },
2705 };
2706
2707 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2708         .f = cmd_showport_rss_hash_parsed,
2709         .data = (void *)1,
2710         .help_str = "show port <port_id> rss-hash "
2711                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2712                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2713                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2714         .tokens = {
2715                 (void *)&cmd_showport_rss_hash_show,
2716                 (void *)&cmd_showport_rss_hash_port,
2717                 (void *)&cmd_showport_rss_hash_port_id,
2718                 (void *)&cmd_showport_rss_hash_rss_hash,
2719                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2720                 (void *)&cmd_showport_rss_hash_rss_key,
2721                 NULL,
2722         },
2723 };
2724
2725 /* *** Configure DCB *** */
2726 struct cmd_config_dcb {
2727         cmdline_fixed_string_t port;
2728         cmdline_fixed_string_t config;
2729         portid_t port_id;
2730         cmdline_fixed_string_t dcb;
2731         cmdline_fixed_string_t vt;
2732         cmdline_fixed_string_t vt_en;
2733         uint8_t num_tcs;
2734         cmdline_fixed_string_t pfc;
2735         cmdline_fixed_string_t pfc_en;
2736 };
2737
2738 static void
2739 cmd_config_dcb_parsed(void *parsed_result,
2740                         __attribute__((unused)) struct cmdline *cl,
2741                         __attribute__((unused)) void *data)
2742 {
2743         struct cmd_config_dcb *res = parsed_result;
2744         portid_t port_id = res->port_id;
2745         struct rte_port *port;
2746         uint8_t pfc_en;
2747         int ret;
2748
2749         port = &ports[port_id];
2750         /** Check if the port is not started **/
2751         if (port->port_status != RTE_PORT_STOPPED) {
2752                 printf("Please stop port %d first\n", port_id);
2753                 return;
2754         }
2755
2756         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2757                 printf("The invalid number of traffic class,"
2758                         " only 4 or 8 allowed.\n");
2759                 return;
2760         }
2761
2762         if (nb_fwd_lcores < res->num_tcs) {
2763                 printf("nb_cores shouldn't be less than number of TCs.\n");
2764                 return;
2765         }
2766         if (!strncmp(res->pfc_en, "on", 2))
2767                 pfc_en = 1;
2768         else
2769                 pfc_en = 0;
2770
2771         /* DCB in VT mode */
2772         if (!strncmp(res->vt_en, "on", 2))
2773                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2774                                 (enum rte_eth_nb_tcs)res->num_tcs,
2775                                 pfc_en);
2776         else
2777                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2778                                 (enum rte_eth_nb_tcs)res->num_tcs,
2779                                 pfc_en);
2780
2781
2782         if (ret != 0) {
2783                 printf("Cannot initialize network ports.\n");
2784                 return;
2785         }
2786
2787         cmd_reconfig_device_queue(port_id, 1, 1);
2788 }
2789
2790 cmdline_parse_token_string_t cmd_config_dcb_port =
2791         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2792 cmdline_parse_token_string_t cmd_config_dcb_config =
2793         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2794 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2795         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2796 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2797         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2798 cmdline_parse_token_string_t cmd_config_dcb_vt =
2799         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2800 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2801         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2802 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2803         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2804 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2805         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2806 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2807         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2808
2809 cmdline_parse_inst_t cmd_config_dcb = {
2810         .f = cmd_config_dcb_parsed,
2811         .data = NULL,
2812         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2813         .tokens = {
2814                 (void *)&cmd_config_dcb_port,
2815                 (void *)&cmd_config_dcb_config,
2816                 (void *)&cmd_config_dcb_port_id,
2817                 (void *)&cmd_config_dcb_dcb,
2818                 (void *)&cmd_config_dcb_vt,
2819                 (void *)&cmd_config_dcb_vt_en,
2820                 (void *)&cmd_config_dcb_num_tcs,
2821                 (void *)&cmd_config_dcb_pfc,
2822                 (void *)&cmd_config_dcb_pfc_en,
2823                 NULL,
2824         },
2825 };
2826
2827 /* *** configure number of packets per burst *** */
2828 struct cmd_config_burst {
2829         cmdline_fixed_string_t port;
2830         cmdline_fixed_string_t keyword;
2831         cmdline_fixed_string_t all;
2832         cmdline_fixed_string_t name;
2833         uint16_t value;
2834 };
2835
2836 static void
2837 cmd_config_burst_parsed(void *parsed_result,
2838                         __attribute__((unused)) struct cmdline *cl,
2839                         __attribute__((unused)) void *data)
2840 {
2841         struct cmd_config_burst *res = parsed_result;
2842         struct rte_eth_dev_info dev_info;
2843         uint16_t rec_nb_pkts;
2844
2845         if (!all_ports_stopped()) {
2846                 printf("Please stop all ports first\n");
2847                 return;
2848         }
2849
2850         if (!strcmp(res->name, "burst")) {
2851                 if (res->value == 0) {
2852                         /* If user gives a value of zero, query the PMD for
2853                          * its recommended Rx burst size. Testpmd uses a single
2854                          * size for all ports, so assume all ports are the same
2855                          * NIC model and use the values from Port 0.
2856                          */
2857                         rte_eth_dev_info_get(0, &dev_info);
2858                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
2859
2860                         if (rec_nb_pkts == 0) {
2861                                 printf("PMD does not recommend a burst size.\n"
2862                                         "User provided value must be between"
2863                                         " 1 and %d\n", MAX_PKT_BURST);
2864                                 return;
2865                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
2866                                 printf("PMD recommended burst size of %d"
2867                                         " exceeds maximum value of %d\n",
2868                                         rec_nb_pkts, MAX_PKT_BURST);
2869                                 return;
2870                         }
2871                         printf("Using PMD-provided burst value of %d\n",
2872                                 rec_nb_pkts);
2873                         nb_pkt_per_burst = rec_nb_pkts;
2874                 } else if (res->value > MAX_PKT_BURST) {
2875                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2876                         return;
2877                 } else
2878                         nb_pkt_per_burst = res->value;
2879         } else {
2880                 printf("Unknown parameter\n");
2881                 return;
2882         }
2883
2884         init_port_config();
2885
2886         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2887 }
2888
2889 cmdline_parse_token_string_t cmd_config_burst_port =
2890         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2891 cmdline_parse_token_string_t cmd_config_burst_keyword =
2892         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2893 cmdline_parse_token_string_t cmd_config_burst_all =
2894         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2895 cmdline_parse_token_string_t cmd_config_burst_name =
2896         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2897 cmdline_parse_token_num_t cmd_config_burst_value =
2898         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2899
2900 cmdline_parse_inst_t cmd_config_burst = {
2901         .f = cmd_config_burst_parsed,
2902         .data = NULL,
2903         .help_str = "port config all burst <value>",
2904         .tokens = {
2905                 (void *)&cmd_config_burst_port,
2906                 (void *)&cmd_config_burst_keyword,
2907                 (void *)&cmd_config_burst_all,
2908                 (void *)&cmd_config_burst_name,
2909                 (void *)&cmd_config_burst_value,
2910                 NULL,
2911         },
2912 };
2913
2914 /* *** configure rx/tx queues *** */
2915 struct cmd_config_thresh {
2916         cmdline_fixed_string_t port;
2917         cmdline_fixed_string_t keyword;
2918         cmdline_fixed_string_t all;
2919         cmdline_fixed_string_t name;
2920         uint8_t value;
2921 };
2922
2923 static void
2924 cmd_config_thresh_parsed(void *parsed_result,
2925                         __attribute__((unused)) struct cmdline *cl,
2926                         __attribute__((unused)) void *data)
2927 {
2928         struct cmd_config_thresh *res = parsed_result;
2929
2930         if (!all_ports_stopped()) {
2931                 printf("Please stop all ports first\n");
2932                 return;
2933         }
2934
2935         if (!strcmp(res->name, "txpt"))
2936                 tx_pthresh = res->value;
2937         else if(!strcmp(res->name, "txht"))
2938                 tx_hthresh = res->value;
2939         else if(!strcmp(res->name, "txwt"))
2940                 tx_wthresh = res->value;
2941         else if(!strcmp(res->name, "rxpt"))
2942                 rx_pthresh = res->value;
2943         else if(!strcmp(res->name, "rxht"))
2944                 rx_hthresh = res->value;
2945         else if(!strcmp(res->name, "rxwt"))
2946                 rx_wthresh = res->value;
2947         else {
2948                 printf("Unknown parameter\n");
2949                 return;
2950         }
2951
2952         init_port_config();
2953
2954         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2955 }
2956
2957 cmdline_parse_token_string_t cmd_config_thresh_port =
2958         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2959 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2960         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2961 cmdline_parse_token_string_t cmd_config_thresh_all =
2962         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2963 cmdline_parse_token_string_t cmd_config_thresh_name =
2964         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2965                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2966 cmdline_parse_token_num_t cmd_config_thresh_value =
2967         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2968
2969 cmdline_parse_inst_t cmd_config_thresh = {
2970         .f = cmd_config_thresh_parsed,
2971         .data = NULL,
2972         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2973         .tokens = {
2974                 (void *)&cmd_config_thresh_port,
2975                 (void *)&cmd_config_thresh_keyword,
2976                 (void *)&cmd_config_thresh_all,
2977                 (void *)&cmd_config_thresh_name,
2978                 (void *)&cmd_config_thresh_value,
2979                 NULL,
2980         },
2981 };
2982
2983 /* *** configure free/rs threshold *** */
2984 struct cmd_config_threshold {
2985         cmdline_fixed_string_t port;
2986         cmdline_fixed_string_t keyword;
2987         cmdline_fixed_string_t all;
2988         cmdline_fixed_string_t name;
2989         uint16_t value;
2990 };
2991
2992 static void
2993 cmd_config_threshold_parsed(void *parsed_result,
2994                         __attribute__((unused)) struct cmdline *cl,
2995                         __attribute__((unused)) void *data)
2996 {
2997         struct cmd_config_threshold *res = parsed_result;
2998
2999         if (!all_ports_stopped()) {
3000                 printf("Please stop all ports first\n");
3001                 return;
3002         }
3003
3004         if (!strcmp(res->name, "txfreet"))
3005                 tx_free_thresh = res->value;
3006         else if (!strcmp(res->name, "txrst"))
3007                 tx_rs_thresh = res->value;
3008         else if (!strcmp(res->name, "rxfreet"))
3009                 rx_free_thresh = res->value;
3010         else {
3011                 printf("Unknown parameter\n");
3012                 return;
3013         }
3014
3015         init_port_config();
3016
3017         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3018 }
3019
3020 cmdline_parse_token_string_t cmd_config_threshold_port =
3021         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3022 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3023         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3024                                                                 "config");
3025 cmdline_parse_token_string_t cmd_config_threshold_all =
3026         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3027 cmdline_parse_token_string_t cmd_config_threshold_name =
3028         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3029                                                 "txfreet#txrst#rxfreet");
3030 cmdline_parse_token_num_t cmd_config_threshold_value =
3031         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3032
3033 cmdline_parse_inst_t cmd_config_threshold = {
3034         .f = cmd_config_threshold_parsed,
3035         .data = NULL,
3036         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3037         .tokens = {
3038                 (void *)&cmd_config_threshold_port,
3039                 (void *)&cmd_config_threshold_keyword,
3040                 (void *)&cmd_config_threshold_all,
3041                 (void *)&cmd_config_threshold_name,
3042                 (void *)&cmd_config_threshold_value,
3043                 NULL,
3044         },
3045 };
3046
3047 /* *** stop *** */
3048 struct cmd_stop_result {
3049         cmdline_fixed_string_t stop;
3050 };
3051
3052 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3053                             __attribute__((unused)) struct cmdline *cl,
3054                             __attribute__((unused)) void *data)
3055 {
3056         stop_packet_forwarding();
3057 }
3058
3059 cmdline_parse_token_string_t cmd_stop_stop =
3060         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3061
3062 cmdline_parse_inst_t cmd_stop = {
3063         .f = cmd_stop_parsed,
3064         .data = NULL,
3065         .help_str = "stop: Stop packet forwarding",
3066         .tokens = {
3067                 (void *)&cmd_stop_stop,
3068                 NULL,
3069         },
3070 };
3071
3072 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3073
3074 unsigned int
3075 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3076                 unsigned int *parsed_items, int check_unique_values)
3077 {
3078         unsigned int nb_item;
3079         unsigned int value;
3080         unsigned int i;
3081         unsigned int j;
3082         int value_ok;
3083         char c;
3084
3085         /*
3086          * First parse all items in the list and store their value.
3087          */
3088         value = 0;
3089         nb_item = 0;
3090         value_ok = 0;
3091         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3092                 c = str[i];
3093                 if ((c >= '0') && (c <= '9')) {
3094                         value = (unsigned int) (value * 10 + (c - '0'));
3095                         value_ok = 1;
3096                         continue;
3097                 }
3098                 if (c != ',') {
3099                         printf("character %c is not a decimal digit\n", c);
3100                         return 0;
3101                 }
3102                 if (! value_ok) {
3103                         printf("No valid value before comma\n");
3104                         return 0;
3105                 }
3106                 if (nb_item < max_items) {
3107                         parsed_items[nb_item] = value;
3108                         value_ok = 0;
3109                         value = 0;
3110                 }
3111                 nb_item++;
3112         }
3113         if (nb_item >= max_items) {
3114                 printf("Number of %s = %u > %u (maximum items)\n",
3115                        item_name, nb_item + 1, max_items);
3116                 return 0;
3117         }
3118         parsed_items[nb_item++] = value;
3119         if (! check_unique_values)
3120                 return nb_item;
3121
3122         /*
3123          * Then, check that all values in the list are differents.
3124          * No optimization here...
3125          */
3126         for (i = 0; i < nb_item; i++) {
3127                 for (j = i + 1; j < nb_item; j++) {
3128                         if (parsed_items[j] == parsed_items[i]) {
3129                                 printf("duplicated %s %u at index %u and %u\n",
3130                                        item_name, parsed_items[i], i, j);
3131                                 return 0;
3132                         }
3133                 }
3134         }
3135         return nb_item;
3136 }
3137
3138 struct cmd_set_list_result {
3139         cmdline_fixed_string_t cmd_keyword;
3140         cmdline_fixed_string_t list_name;
3141         cmdline_fixed_string_t list_of_items;
3142 };
3143
3144 static void cmd_set_list_parsed(void *parsed_result,
3145                                 __attribute__((unused)) struct cmdline *cl,
3146                                 __attribute__((unused)) void *data)
3147 {
3148         struct cmd_set_list_result *res;
3149         union {
3150                 unsigned int lcorelist[RTE_MAX_LCORE];
3151                 unsigned int portlist[RTE_MAX_ETHPORTS];
3152         } parsed_items;
3153         unsigned int nb_item;
3154
3155         if (test_done == 0) {
3156                 printf("Please stop forwarding first\n");
3157                 return;
3158         }
3159
3160         res = parsed_result;
3161         if (!strcmp(res->list_name, "corelist")) {
3162                 nb_item = parse_item_list(res->list_of_items, "core",
3163                                           RTE_MAX_LCORE,
3164                                           parsed_items.lcorelist, 1);
3165                 if (nb_item > 0) {
3166                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3167                         fwd_config_setup();
3168                 }
3169                 return;
3170         }
3171         if (!strcmp(res->list_name, "portlist")) {
3172                 nb_item = parse_item_list(res->list_of_items, "port",
3173                                           RTE_MAX_ETHPORTS,
3174                                           parsed_items.portlist, 1);
3175                 if (nb_item > 0) {
3176                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3177                         fwd_config_setup();
3178                 }
3179         }
3180 }
3181
3182 cmdline_parse_token_string_t cmd_set_list_keyword =
3183         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3184                                  "set");
3185 cmdline_parse_token_string_t cmd_set_list_name =
3186         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3187                                  "corelist#portlist");
3188 cmdline_parse_token_string_t cmd_set_list_of_items =
3189         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3190                                  NULL);
3191
3192 cmdline_parse_inst_t cmd_set_fwd_list = {
3193         .f = cmd_set_list_parsed,
3194         .data = NULL,
3195         .help_str = "set corelist|portlist <list0[,list1]*>",
3196         .tokens = {
3197                 (void *)&cmd_set_list_keyword,
3198                 (void *)&cmd_set_list_name,
3199                 (void *)&cmd_set_list_of_items,
3200                 NULL,
3201         },
3202 };
3203
3204 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3205
3206 struct cmd_setmask_result {
3207         cmdline_fixed_string_t set;
3208         cmdline_fixed_string_t mask;
3209         uint64_t hexavalue;
3210 };
3211
3212 static void cmd_set_mask_parsed(void *parsed_result,
3213                                 __attribute__((unused)) struct cmdline *cl,
3214                                 __attribute__((unused)) void *data)
3215 {
3216         struct cmd_setmask_result *res = parsed_result;
3217
3218         if (test_done == 0) {
3219                 printf("Please stop forwarding first\n");
3220                 return;
3221         }
3222         if (!strcmp(res->mask, "coremask")) {
3223                 set_fwd_lcores_mask(res->hexavalue);
3224                 fwd_config_setup();
3225         } else if (!strcmp(res->mask, "portmask")) {
3226                 set_fwd_ports_mask(res->hexavalue);
3227                 fwd_config_setup();
3228         }
3229 }
3230
3231 cmdline_parse_token_string_t cmd_setmask_set =
3232         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3233 cmdline_parse_token_string_t cmd_setmask_mask =
3234         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3235                                  "coremask#portmask");
3236 cmdline_parse_token_num_t cmd_setmask_value =
3237         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3238
3239 cmdline_parse_inst_t cmd_set_fwd_mask = {
3240         .f = cmd_set_mask_parsed,
3241         .data = NULL,
3242         .help_str = "set coremask|portmask <hexadecimal value>",
3243         .tokens = {
3244                 (void *)&cmd_setmask_set,
3245                 (void *)&cmd_setmask_mask,
3246                 (void *)&cmd_setmask_value,
3247                 NULL,
3248         },
3249 };
3250
3251 /*
3252  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3253  */
3254 struct cmd_set_result {
3255         cmdline_fixed_string_t set;
3256         cmdline_fixed_string_t what;
3257         uint16_t value;
3258 };
3259
3260 static void cmd_set_parsed(void *parsed_result,
3261                            __attribute__((unused)) struct cmdline *cl,
3262                            __attribute__((unused)) void *data)
3263 {
3264         struct cmd_set_result *res = parsed_result;
3265         if (!strcmp(res->what, "nbport")) {
3266                 set_fwd_ports_number(res->value);
3267                 fwd_config_setup();
3268         } else if (!strcmp(res->what, "nbcore")) {
3269                 set_fwd_lcores_number(res->value);
3270                 fwd_config_setup();
3271         } else if (!strcmp(res->what, "burst"))
3272                 set_nb_pkt_per_burst(res->value);
3273         else if (!strcmp(res->what, "verbose"))
3274                 set_verbose_level(res->value);
3275 }
3276
3277 cmdline_parse_token_string_t cmd_set_set =
3278         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3279 cmdline_parse_token_string_t cmd_set_what =
3280         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3281                                  "nbport#nbcore#burst#verbose");
3282 cmdline_parse_token_num_t cmd_set_value =
3283         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3284
3285 cmdline_parse_inst_t cmd_set_numbers = {
3286         .f = cmd_set_parsed,
3287         .data = NULL,
3288         .help_str = "set nbport|nbcore|burst|verbose <value>",
3289         .tokens = {
3290                 (void *)&cmd_set_set,
3291                 (void *)&cmd_set_what,
3292                 (void *)&cmd_set_value,
3293                 NULL,
3294         },
3295 };
3296
3297 /* *** SET LOG LEVEL CONFIGURATION *** */
3298
3299 struct cmd_set_log_result {
3300         cmdline_fixed_string_t set;
3301         cmdline_fixed_string_t log;
3302         cmdline_fixed_string_t type;
3303         uint32_t level;
3304 };
3305
3306 static void
3307 cmd_set_log_parsed(void *parsed_result,
3308                    __attribute__((unused)) struct cmdline *cl,
3309                    __attribute__((unused)) void *data)
3310 {
3311         struct cmd_set_log_result *res;
3312         int ret;
3313
3314         res = parsed_result;
3315         if (!strcmp(res->type, "global"))
3316                 rte_log_set_global_level(res->level);
3317         else {
3318                 ret = rte_log_set_level_regexp(res->type, res->level);
3319                 if (ret < 0)
3320                         printf("Unable to set log level\n");
3321         }
3322 }
3323
3324 cmdline_parse_token_string_t cmd_set_log_set =
3325         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3326 cmdline_parse_token_string_t cmd_set_log_log =
3327         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3328 cmdline_parse_token_string_t cmd_set_log_type =
3329         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3330 cmdline_parse_token_num_t cmd_set_log_level =
3331         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3332
3333 cmdline_parse_inst_t cmd_set_log = {
3334         .f = cmd_set_log_parsed,
3335         .data = NULL,
3336         .help_str = "set log global|<type> <level>",
3337         .tokens = {
3338                 (void *)&cmd_set_log_set,
3339                 (void *)&cmd_set_log_log,
3340                 (void *)&cmd_set_log_type,
3341                 (void *)&cmd_set_log_level,
3342                 NULL,
3343         },
3344 };
3345
3346 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3347
3348 struct cmd_set_txpkts_result {
3349         cmdline_fixed_string_t cmd_keyword;
3350         cmdline_fixed_string_t txpkts;
3351         cmdline_fixed_string_t seg_lengths;
3352 };
3353
3354 static void
3355 cmd_set_txpkts_parsed(void *parsed_result,
3356                       __attribute__((unused)) struct cmdline *cl,
3357                       __attribute__((unused)) void *data)
3358 {
3359         struct cmd_set_txpkts_result *res;
3360         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3361         unsigned int nb_segs;
3362
3363         res = parsed_result;
3364         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3365                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3366         if (nb_segs > 0)
3367                 set_tx_pkt_segments(seg_lengths, nb_segs);
3368 }
3369
3370 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3371         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3372                                  cmd_keyword, "set");
3373 cmdline_parse_token_string_t cmd_set_txpkts_name =
3374         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3375                                  txpkts, "txpkts");
3376 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3377         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3378                                  seg_lengths, NULL);
3379
3380 cmdline_parse_inst_t cmd_set_txpkts = {
3381         .f = cmd_set_txpkts_parsed,
3382         .data = NULL,
3383         .help_str = "set txpkts <len0[,len1]*>",
3384         .tokens = {
3385                 (void *)&cmd_set_txpkts_keyword,
3386                 (void *)&cmd_set_txpkts_name,
3387                 (void *)&cmd_set_txpkts_lengths,
3388                 NULL,
3389         },
3390 };
3391
3392 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3393
3394 struct cmd_set_txsplit_result {
3395         cmdline_fixed_string_t cmd_keyword;
3396         cmdline_fixed_string_t txsplit;
3397         cmdline_fixed_string_t mode;
3398 };
3399
3400 static void
3401 cmd_set_txsplit_parsed(void *parsed_result,
3402                       __attribute__((unused)) struct cmdline *cl,
3403                       __attribute__((unused)) void *data)
3404 {
3405         struct cmd_set_txsplit_result *res;
3406
3407         res = parsed_result;
3408         set_tx_pkt_split(res->mode);
3409 }
3410
3411 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3412         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3413                                  cmd_keyword, "set");
3414 cmdline_parse_token_string_t cmd_set_txsplit_name =
3415         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3416                                  txsplit, "txsplit");
3417 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3418         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3419                                  mode, NULL);
3420
3421 cmdline_parse_inst_t cmd_set_txsplit = {
3422         .f = cmd_set_txsplit_parsed,
3423         .data = NULL,
3424         .help_str = "set txsplit on|off|rand",
3425         .tokens = {
3426                 (void *)&cmd_set_txsplit_keyword,
3427                 (void *)&cmd_set_txsplit_name,
3428                 (void *)&cmd_set_txsplit_mode,
3429                 NULL,
3430         },
3431 };
3432
3433 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3434 struct cmd_rx_vlan_filter_all_result {
3435         cmdline_fixed_string_t rx_vlan;
3436         cmdline_fixed_string_t what;
3437         cmdline_fixed_string_t all;
3438         portid_t port_id;
3439 };
3440
3441 static void
3442 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3443                               __attribute__((unused)) struct cmdline *cl,
3444                               __attribute__((unused)) void *data)
3445 {
3446         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3447
3448         if (!strcmp(res->what, "add"))
3449                 rx_vlan_all_filter_set(res->port_id, 1);
3450         else
3451                 rx_vlan_all_filter_set(res->port_id, 0);
3452 }
3453
3454 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3455         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3456                                  rx_vlan, "rx_vlan");
3457 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3458         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3459                                  what, "add#rm");
3460 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3461         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3462                                  all, "all");
3463 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3464         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3465                               port_id, UINT16);
3466
3467 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3468         .f = cmd_rx_vlan_filter_all_parsed,
3469         .data = NULL,
3470         .help_str = "rx_vlan add|rm all <port_id>: "
3471                 "Add/Remove all identifiers to/from the set of VLAN "
3472                 "identifiers filtered by a port",
3473         .tokens = {
3474                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3475                 (void *)&cmd_rx_vlan_filter_all_what,
3476                 (void *)&cmd_rx_vlan_filter_all_all,
3477                 (void *)&cmd_rx_vlan_filter_all_portid,
3478                 NULL,
3479         },
3480 };
3481
3482 /* *** VLAN OFFLOAD SET ON A PORT *** */
3483 struct cmd_vlan_offload_result {
3484         cmdline_fixed_string_t vlan;
3485         cmdline_fixed_string_t set;
3486         cmdline_fixed_string_t vlan_type;
3487         cmdline_fixed_string_t what;
3488         cmdline_fixed_string_t on;
3489         cmdline_fixed_string_t port_id;
3490 };
3491
3492 static void
3493 cmd_vlan_offload_parsed(void *parsed_result,
3494                           __attribute__((unused)) struct cmdline *cl,
3495                           __attribute__((unused)) void *data)
3496 {
3497         int on;
3498         struct cmd_vlan_offload_result *res = parsed_result;
3499         char *str;
3500         int i, len = 0;
3501         portid_t port_id = 0;
3502         unsigned int tmp;
3503
3504         str = res->port_id;
3505         len = strnlen(str, STR_TOKEN_SIZE);
3506         i = 0;
3507         /* Get port_id first */
3508         while(i < len){
3509                 if(str[i] == ',')
3510                         break;
3511
3512                 i++;
3513         }
3514         str[i]='\0';
3515         tmp = strtoul(str, NULL, 0);
3516         /* If port_id greater that what portid_t can represent, return */
3517         if(tmp >= RTE_MAX_ETHPORTS)
3518                 return;
3519         port_id = (portid_t)tmp;
3520
3521         if (!strcmp(res->on, "on"))
3522                 on = 1;
3523         else
3524                 on = 0;
3525
3526         if (!strcmp(res->what, "strip"))
3527                 rx_vlan_strip_set(port_id,  on);
3528         else if(!strcmp(res->what, "stripq")){
3529                 uint16_t queue_id = 0;
3530
3531                 /* No queue_id, return */
3532                 if(i + 1 >= len) {
3533                         printf("must specify (port,queue_id)\n");
3534                         return;
3535                 }
3536                 tmp = strtoul(str + i + 1, NULL, 0);
3537                 /* If queue_id greater that what 16-bits can represent, return */
3538                 if(tmp > 0xffff)
3539                         return;
3540
3541                 queue_id = (uint16_t)tmp;
3542                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3543         }
3544         else if (!strcmp(res->what, "filter"))
3545                 rx_vlan_filter_set(port_id, on);
3546         else
3547                 vlan_extend_set(port_id, on);
3548
3549         return;
3550 }
3551
3552 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3553         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3554                                  vlan, "vlan");
3555 cmdline_parse_token_string_t cmd_vlan_offload_set =
3556         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3557                                  set, "set");
3558 cmdline_parse_token_string_t cmd_vlan_offload_what =
3559         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3560                                  what, "strip#filter#qinq#stripq");
3561 cmdline_parse_token_string_t cmd_vlan_offload_on =
3562         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3563                               on, "on#off");
3564 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3565         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3566                               port_id, NULL);
3567
3568 cmdline_parse_inst_t cmd_vlan_offload = {
3569         .f = cmd_vlan_offload_parsed,
3570         .data = NULL,
3571         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3572                 "<port_id[,queue_id]>: "
3573                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3574         .tokens = {
3575                 (void *)&cmd_vlan_offload_vlan,
3576                 (void *)&cmd_vlan_offload_set,
3577                 (void *)&cmd_vlan_offload_what,
3578                 (void *)&cmd_vlan_offload_on,
3579                 (void *)&cmd_vlan_offload_portid,
3580                 NULL,
3581         },
3582 };
3583
3584 /* *** VLAN TPID SET ON A PORT *** */
3585 struct cmd_vlan_tpid_result {
3586         cmdline_fixed_string_t vlan;
3587         cmdline_fixed_string_t set;
3588         cmdline_fixed_string_t vlan_type;
3589         cmdline_fixed_string_t what;
3590         uint16_t tp_id;
3591         portid_t port_id;
3592 };
3593
3594 static void
3595 cmd_vlan_tpid_parsed(void *parsed_result,
3596                           __attribute__((unused)) struct cmdline *cl,
3597                           __attribute__((unused)) void *data)
3598 {
3599         struct cmd_vlan_tpid_result *res = parsed_result;
3600         enum rte_vlan_type vlan_type;
3601
3602         if (!strcmp(res->vlan_type, "inner"))
3603                 vlan_type = ETH_VLAN_TYPE_INNER;
3604         else if (!strcmp(res->vlan_type, "outer"))
3605                 vlan_type = ETH_VLAN_TYPE_OUTER;
3606         else {
3607                 printf("Unknown vlan type\n");
3608                 return;
3609         }
3610         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3611 }
3612
3613 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3614         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3615                                  vlan, "vlan");
3616 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3617         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3618                                  set, "set");
3619 cmdline_parse_token_string_t cmd_vlan_type =
3620         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3621                                  vlan_type, "inner#outer");
3622 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3623         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3624                                  what, "tpid");
3625 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3626         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3627                               tp_id, UINT16);
3628 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3629         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3630                               port_id, UINT16);
3631
3632 cmdline_parse_inst_t cmd_vlan_tpid = {
3633         .f = cmd_vlan_tpid_parsed,
3634         .data = NULL,
3635         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3636                 "Set the VLAN Ether type",
3637         .tokens = {
3638                 (void *)&cmd_vlan_tpid_vlan,
3639                 (void *)&cmd_vlan_tpid_set,
3640                 (void *)&cmd_vlan_type,
3641                 (void *)&cmd_vlan_tpid_what,
3642                 (void *)&cmd_vlan_tpid_tpid,
3643                 (void *)&cmd_vlan_tpid_portid,
3644                 NULL,
3645         },
3646 };
3647
3648 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3649 struct cmd_rx_vlan_filter_result {
3650         cmdline_fixed_string_t rx_vlan;
3651         cmdline_fixed_string_t what;
3652         uint16_t vlan_id;
3653         portid_t port_id;
3654 };
3655
3656 static void
3657 cmd_rx_vlan_filter_parsed(void *parsed_result,
3658                           __attribute__((unused)) struct cmdline *cl,
3659                           __attribute__((unused)) void *data)
3660 {
3661         struct cmd_rx_vlan_filter_result *res = parsed_result;
3662
3663         if (!strcmp(res->what, "add"))
3664                 rx_vft_set(res->port_id, res->vlan_id, 1);
3665         else
3666                 rx_vft_set(res->port_id, res->vlan_id, 0);
3667 }
3668
3669 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3670         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3671                                  rx_vlan, "rx_vlan");
3672 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3673         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3674                                  what, "add#rm");
3675 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3676         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3677                               vlan_id, UINT16);
3678 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3679         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3680                               port_id, UINT16);
3681
3682 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3683         .f = cmd_rx_vlan_filter_parsed,
3684         .data = NULL,
3685         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3686                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3687                 "identifiers filtered by a port",
3688         .tokens = {
3689                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3690                 (void *)&cmd_rx_vlan_filter_what,
3691                 (void *)&cmd_rx_vlan_filter_vlanid,
3692                 (void *)&cmd_rx_vlan_filter_portid,
3693                 NULL,
3694         },
3695 };
3696
3697 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3698 struct cmd_tx_vlan_set_result {
3699         cmdline_fixed_string_t tx_vlan;
3700         cmdline_fixed_string_t set;
3701         portid_t port_id;
3702         uint16_t vlan_id;
3703 };
3704
3705 static void
3706 cmd_tx_vlan_set_parsed(void *parsed_result,
3707                        __attribute__((unused)) struct cmdline *cl,
3708                        __attribute__((unused)) void *data)
3709 {
3710         struct cmd_tx_vlan_set_result *res = parsed_result;
3711
3712         if (!port_is_stopped(res->port_id)) {
3713                 printf("Please stop port %d first\n", res->port_id);
3714                 return;
3715         }
3716
3717         tx_vlan_set(res->port_id, res->vlan_id);
3718
3719         cmd_reconfig_device_queue(res->port_id, 1, 1);
3720 }
3721
3722 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3723         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3724                                  tx_vlan, "tx_vlan");
3725 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3726         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3727                                  set, "set");
3728 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3729         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3730                               port_id, UINT16);
3731 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3732         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3733                               vlan_id, UINT16);
3734
3735 cmdline_parse_inst_t cmd_tx_vlan_set = {
3736         .f = cmd_tx_vlan_set_parsed,
3737         .data = NULL,
3738         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3739                 "Enable hardware insertion of a single VLAN header "
3740                 "with a given TAG Identifier in packets sent on a port",
3741         .tokens = {
3742                 (void *)&cmd_tx_vlan_set_tx_vlan,
3743                 (void *)&cmd_tx_vlan_set_set,
3744                 (void *)&cmd_tx_vlan_set_portid,
3745                 (void *)&cmd_tx_vlan_set_vlanid,
3746                 NULL,
3747         },
3748 };
3749
3750 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3751 struct cmd_tx_vlan_set_qinq_result {
3752         cmdline_fixed_string_t tx_vlan;
3753         cmdline_fixed_string_t set;
3754         portid_t port_id;
3755         uint16_t vlan_id;
3756         uint16_t vlan_id_outer;
3757 };
3758
3759 static void
3760 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3761                             __attribute__((unused)) struct cmdline *cl,
3762                             __attribute__((unused)) void *data)
3763 {
3764         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3765
3766         if (!port_is_stopped(res->port_id)) {
3767                 printf("Please stop port %d first\n", res->port_id);
3768                 return;
3769         }
3770
3771         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3772
3773         cmd_reconfig_device_queue(res->port_id, 1, 1);
3774 }
3775
3776 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3777         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3778                 tx_vlan, "tx_vlan");
3779 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3780         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3781                 set, "set");
3782 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3783         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3784                 port_id, UINT16);
3785 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3786         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3787                 vlan_id, UINT16);
3788 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3789         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3790                 vlan_id_outer, UINT16);
3791
3792 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3793         .f = cmd_tx_vlan_set_qinq_parsed,
3794         .data = NULL,
3795         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3796                 "Enable hardware insertion of double VLAN header "
3797                 "with given TAG Identifiers in packets sent on a port",
3798         .tokens = {
3799                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3800                 (void *)&cmd_tx_vlan_set_qinq_set,
3801                 (void *)&cmd_tx_vlan_set_qinq_portid,
3802                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3803                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3804                 NULL,
3805         },
3806 };
3807
3808 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3809 struct cmd_tx_vlan_set_pvid_result {
3810         cmdline_fixed_string_t tx_vlan;
3811         cmdline_fixed_string_t set;
3812         cmdline_fixed_string_t pvid;
3813         portid_t port_id;
3814         uint16_t vlan_id;
3815         cmdline_fixed_string_t mode;
3816 };
3817
3818 static void
3819 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3820                             __attribute__((unused)) struct cmdline *cl,
3821                             __attribute__((unused)) void *data)
3822 {
3823         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3824
3825         if (strcmp(res->mode, "on") == 0)
3826                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3827         else
3828                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3829 }
3830
3831 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3832         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3833                                  tx_vlan, "tx_vlan");
3834 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3835         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3836                                  set, "set");
3837 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3838         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3839                                  pvid, "pvid");
3840 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3841         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3842                              port_id, UINT16);
3843 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3844         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3845                               vlan_id, UINT16);
3846 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3847         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3848                                  mode, "on#off");
3849
3850 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3851         .f = cmd_tx_vlan_set_pvid_parsed,
3852         .data = NULL,
3853         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3854         .tokens = {
3855                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3856                 (void *)&cmd_tx_vlan_set_pvid_set,
3857                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3858                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3859                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3860                 (void *)&cmd_tx_vlan_set_pvid_mode,
3861                 NULL,
3862         },
3863 };
3864
3865 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3866 struct cmd_tx_vlan_reset_result {
3867         cmdline_fixed_string_t tx_vlan;
3868         cmdline_fixed_string_t reset;
3869         portid_t port_id;
3870 };
3871
3872 static void
3873 cmd_tx_vlan_reset_parsed(void *parsed_result,
3874                          __attribute__((unused)) struct cmdline *cl,
3875                          __attribute__((unused)) void *data)
3876 {
3877         struct cmd_tx_vlan_reset_result *res = parsed_result;
3878
3879         if (!port_is_stopped(res->port_id)) {
3880                 printf("Please stop port %d first\n", res->port_id);
3881                 return;
3882         }
3883
3884         tx_vlan_reset(res->port_id);
3885
3886         cmd_reconfig_device_queue(res->port_id, 1, 1);
3887 }
3888
3889 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3890         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3891                                  tx_vlan, "tx_vlan");
3892 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3893         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3894                                  reset, "reset");
3895 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3896         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3897                               port_id, UINT16);
3898
3899 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3900         .f = cmd_tx_vlan_reset_parsed,
3901         .data = NULL,
3902         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3903                 "VLAN header in packets sent on a port",
3904         .tokens = {
3905                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3906                 (void *)&cmd_tx_vlan_reset_reset,
3907                 (void *)&cmd_tx_vlan_reset_portid,
3908                 NULL,
3909         },
3910 };
3911
3912
3913 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3914 struct cmd_csum_result {
3915         cmdline_fixed_string_t csum;
3916         cmdline_fixed_string_t mode;
3917         cmdline_fixed_string_t proto;
3918         cmdline_fixed_string_t hwsw;
3919         portid_t port_id;
3920 };
3921
3922 static void
3923 csum_show(int port_id)
3924 {
3925         struct rte_eth_dev_info dev_info;
3926         uint64_t tx_offloads;
3927
3928         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3929         printf("Parse tunnel is %s\n",
3930                 (ports[port_id].parse_tunnel) ? "on" : "off");
3931         printf("IP checksum offload is %s\n",
3932                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3933         printf("UDP checksum offload is %s\n",
3934                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3935         printf("TCP checksum offload is %s\n",
3936                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3937         printf("SCTP checksum offload is %s\n",
3938                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3939         printf("Outer-Ip checksum offload is %s\n",
3940                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3941
3942         /* display warnings if configuration is not supported by the NIC */
3943         rte_eth_dev_info_get(port_id, &dev_info);
3944         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3945                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3946                 printf("Warning: hardware IP checksum enabled but not "
3947                         "supported by port %d\n", port_id);
3948         }
3949         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3950                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3951                 printf("Warning: hardware UDP checksum enabled but not "
3952                         "supported by port %d\n", port_id);
3953         }
3954         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3955                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3956                 printf("Warning: hardware TCP checksum enabled but not "
3957                         "supported by port %d\n", port_id);
3958         }
3959         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3960                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3961                 printf("Warning: hardware SCTP checksum enabled but not "
3962                         "supported by port %d\n", port_id);
3963         }
3964         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3965                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3966                 printf("Warning: hardware outer IP checksum enabled but not "
3967                         "supported by port %d\n", port_id);
3968         }
3969 }
3970
3971 static void
3972 cmd_csum_parsed(void *parsed_result,
3973                        __attribute__((unused)) struct cmdline *cl,
3974                        __attribute__((unused)) void *data)
3975 {
3976         struct cmd_csum_result *res = parsed_result;
3977         int hw = 0;
3978         uint64_t csum_offloads = 0;
3979         struct rte_eth_dev_info dev_info;
3980
3981         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3982                 printf("invalid port %d\n", res->port_id);
3983                 return;
3984         }
3985         if (!port_is_stopped(res->port_id)) {
3986                 printf("Please stop port %d first\n", res->port_id);
3987                 return;
3988         }
3989
3990         rte_eth_dev_info_get(res->port_id, &dev_info);
3991         if (!strcmp(res->mode, "set")) {
3992
3993                 if (!strcmp(res->hwsw, "hw"))
3994                         hw = 1;
3995
3996                 if (!strcmp(res->proto, "ip")) {
3997                         if (hw == 0 || (dev_info.tx_offload_capa &
3998                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
3999                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4000                         } else {
4001                                 printf("IP checksum offload is not supported "
4002                                        "by port %u\n", res->port_id);
4003                         }
4004                 } else if (!strcmp(res->proto, "udp")) {
4005                         if (hw == 0 || (dev_info.tx_offload_capa &
4006                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4007                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4008                         } else {
4009                                 printf("UDP checksum offload is not supported "
4010                                        "by port %u\n", res->port_id);
4011                         }
4012                 } else if (!strcmp(res->proto, "tcp")) {
4013                         if (hw == 0 || (dev_info.tx_offload_capa &
4014                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4015                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4016                         } else {
4017                                 printf("TCP checksum offload is not supported "
4018                                        "by port %u\n", res->port_id);
4019                         }
4020                 } else if (!strcmp(res->proto, "sctp")) {
4021                         if (hw == 0 || (dev_info.tx_offload_capa &
4022                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4023                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4024                         } else {
4025                                 printf("SCTP checksum offload is not supported "
4026                                        "by port %u\n", res->port_id);
4027                         }
4028                 } else if (!strcmp(res->proto, "outer-ip")) {
4029                         if (hw == 0 || (dev_info.tx_offload_capa &
4030                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4031                                 csum_offloads |=
4032                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4033                         } else {
4034                                 printf("Outer IP checksum offload is not "
4035                                        "supported by port %u\n", res->port_id);
4036                         }
4037                 }
4038
4039                 if (hw) {
4040                         ports[res->port_id].dev_conf.txmode.offloads |=
4041                                                         csum_offloads;
4042                 } else {
4043                         ports[res->port_id].dev_conf.txmode.offloads &=
4044                                                         (~csum_offloads);
4045                 }
4046         }
4047         csum_show(res->port_id);
4048
4049         cmd_reconfig_device_queue(res->port_id, 1, 1);
4050 }
4051
4052 cmdline_parse_token_string_t cmd_csum_csum =
4053         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4054                                 csum, "csum");
4055 cmdline_parse_token_string_t cmd_csum_mode =
4056         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4057                                 mode, "set");
4058 cmdline_parse_token_string_t cmd_csum_proto =
4059         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4060                                 proto, "ip#tcp#udp#sctp#outer-ip");
4061 cmdline_parse_token_string_t cmd_csum_hwsw =
4062         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4063                                 hwsw, "hw#sw");
4064 cmdline_parse_token_num_t cmd_csum_portid =
4065         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4066                                 port_id, UINT16);
4067
4068 cmdline_parse_inst_t cmd_csum_set = {
4069         .f = cmd_csum_parsed,
4070         .data = NULL,
4071         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4072                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4073                 "using csum forward engine",
4074         .tokens = {
4075                 (void *)&cmd_csum_csum,
4076                 (void *)&cmd_csum_mode,
4077                 (void *)&cmd_csum_proto,
4078                 (void *)&cmd_csum_hwsw,
4079                 (void *)&cmd_csum_portid,
4080                 NULL,
4081         },
4082 };
4083
4084 cmdline_parse_token_string_t cmd_csum_mode_show =
4085         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4086                                 mode, "show");
4087
4088 cmdline_parse_inst_t cmd_csum_show = {
4089         .f = cmd_csum_parsed,
4090         .data = NULL,
4091         .help_str = "csum show <port_id>: Show checksum offload configuration",
4092         .tokens = {
4093                 (void *)&cmd_csum_csum,
4094                 (void *)&cmd_csum_mode_show,
4095                 (void *)&cmd_csum_portid,
4096                 NULL,
4097         },
4098 };
4099
4100 /* Enable/disable tunnel parsing */
4101 struct cmd_csum_tunnel_result {
4102         cmdline_fixed_string_t csum;
4103         cmdline_fixed_string_t parse;
4104         cmdline_fixed_string_t onoff;
4105         portid_t port_id;
4106 };
4107
4108 static void
4109 cmd_csum_tunnel_parsed(void *parsed_result,
4110                        __attribute__((unused)) struct cmdline *cl,
4111                        __attribute__((unused)) void *data)
4112 {
4113         struct cmd_csum_tunnel_result *res = parsed_result;
4114
4115         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4116                 return;
4117
4118         if (!strcmp(res->onoff, "on"))
4119                 ports[res->port_id].parse_tunnel = 1;
4120         else
4121                 ports[res->port_id].parse_tunnel = 0;
4122
4123         csum_show(res->port_id);
4124 }
4125
4126 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4127         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4128                                 csum, "csum");
4129 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4130         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4131                                 parse, "parse_tunnel");
4132 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4133         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4134                                 onoff, "on#off");
4135 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4136         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4137                                 port_id, UINT16);
4138
4139 cmdline_parse_inst_t cmd_csum_tunnel = {
4140         .f = cmd_csum_tunnel_parsed,
4141         .data = NULL,
4142         .help_str = "csum parse_tunnel on|off <port_id>: "
4143                 "Enable/Disable parsing of tunnels for csum engine",
4144         .tokens = {
4145                 (void *)&cmd_csum_tunnel_csum,
4146                 (void *)&cmd_csum_tunnel_parse,
4147                 (void *)&cmd_csum_tunnel_onoff,
4148                 (void *)&cmd_csum_tunnel_portid,
4149                 NULL,
4150         },
4151 };
4152
4153 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4154 struct cmd_tso_set_result {
4155         cmdline_fixed_string_t tso;
4156         cmdline_fixed_string_t mode;
4157         uint16_t tso_segsz;
4158         portid_t port_id;
4159 };
4160
4161 static void
4162 cmd_tso_set_parsed(void *parsed_result,
4163                        __attribute__((unused)) struct cmdline *cl,
4164                        __attribute__((unused)) void *data)
4165 {
4166         struct cmd_tso_set_result *res = parsed_result;
4167         struct rte_eth_dev_info dev_info;
4168
4169         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4170                 return;
4171         if (!port_is_stopped(res->port_id)) {
4172                 printf("Please stop port %d first\n", res->port_id);
4173                 return;
4174         }
4175
4176         if (!strcmp(res->mode, "set"))
4177                 ports[res->port_id].tso_segsz = res->tso_segsz;
4178
4179         rte_eth_dev_info_get(res->port_id, &dev_info);
4180         if ((ports[res->port_id].tso_segsz != 0) &&
4181                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4182                 printf("Error: TSO is not supported by port %d\n",
4183                        res->port_id);
4184                 return;
4185         }
4186
4187         if (ports[res->port_id].tso_segsz == 0) {
4188                 ports[res->port_id].dev_conf.txmode.offloads &=
4189                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4190                 printf("TSO for non-tunneled packets is disabled\n");
4191         } else {
4192                 ports[res->port_id].dev_conf.txmode.offloads |=
4193                                                 DEV_TX_OFFLOAD_TCP_TSO;
4194                 printf("TSO segment size for non-tunneled packets is %d\n",
4195                         ports[res->port_id].tso_segsz);
4196         }
4197
4198         /* display warnings if configuration is not supported by the NIC */
4199         rte_eth_dev_info_get(res->port_id, &dev_info);
4200         if ((ports[res->port_id].tso_segsz != 0) &&
4201                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4202                 printf("Warning: TSO enabled but not "
4203                         "supported by port %d\n", res->port_id);
4204         }
4205
4206         cmd_reconfig_device_queue(res->port_id, 1, 1);
4207 }
4208
4209 cmdline_parse_token_string_t cmd_tso_set_tso =
4210         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4211                                 tso, "tso");
4212 cmdline_parse_token_string_t cmd_tso_set_mode =
4213         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4214                                 mode, "set");
4215 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4216         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4217                                 tso_segsz, UINT16);
4218 cmdline_parse_token_num_t cmd_tso_set_portid =
4219         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4220                                 port_id, UINT16);
4221
4222 cmdline_parse_inst_t cmd_tso_set = {
4223         .f = cmd_tso_set_parsed,
4224         .data = NULL,
4225         .help_str = "tso set <tso_segsz> <port_id>: "
4226                 "Set TSO segment size of non-tunneled packets for csum engine "
4227                 "(0 to disable)",
4228         .tokens = {
4229                 (void *)&cmd_tso_set_tso,
4230                 (void *)&cmd_tso_set_mode,
4231                 (void *)&cmd_tso_set_tso_segsz,
4232                 (void *)&cmd_tso_set_portid,
4233                 NULL,
4234         },
4235 };
4236
4237 cmdline_parse_token_string_t cmd_tso_show_mode =
4238         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4239                                 mode, "show");
4240
4241
4242 cmdline_parse_inst_t cmd_tso_show = {
4243         .f = cmd_tso_set_parsed,
4244         .data = NULL,
4245         .help_str = "tso show <port_id>: "
4246                 "Show TSO segment size of non-tunneled packets for csum engine",
4247         .tokens = {
4248                 (void *)&cmd_tso_set_tso,
4249                 (void *)&cmd_tso_show_mode,
4250                 (void *)&cmd_tso_set_portid,
4251                 NULL,
4252         },
4253 };
4254
4255 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4256 struct cmd_tunnel_tso_set_result {
4257         cmdline_fixed_string_t tso;
4258         cmdline_fixed_string_t mode;
4259         uint16_t tso_segsz;
4260         portid_t port_id;
4261 };
4262
4263 static struct rte_eth_dev_info
4264 check_tunnel_tso_nic_support(portid_t port_id)
4265 {
4266         struct rte_eth_dev_info dev_info;
4267
4268         rte_eth_dev_info_get(port_id, &dev_info);
4269         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4270                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4271                        "not enabled for port %d\n", port_id);
4272         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4273                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4274                        "not enabled for port %d\n", port_id);
4275         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4276                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4277                        "not enabled for port %d\n", port_id);
4278         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4279                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4280                        "not enabled for port %d\n", port_id);
4281         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4282                 printf("Warning: IP TUNNEL TSO not supported therefore "
4283                        "not enabled for port %d\n", port_id);
4284         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4285                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4286                        "not enabled for port %d\n", port_id);
4287         return dev_info;
4288 }
4289
4290 static void
4291 cmd_tunnel_tso_set_parsed(void *parsed_result,
4292                           __attribute__((unused)) struct cmdline *cl,
4293                           __attribute__((unused)) void *data)
4294 {
4295         struct cmd_tunnel_tso_set_result *res = parsed_result;
4296         struct rte_eth_dev_info dev_info;
4297
4298         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4299                 return;
4300         if (!port_is_stopped(res->port_id)) {
4301                 printf("Please stop port %d first\n", res->port_id);
4302                 return;
4303         }
4304
4305         if (!strcmp(res->mode, "set"))
4306                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4307
4308         dev_info = check_tunnel_tso_nic_support(res->port_id);
4309         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4310                 ports[res->port_id].dev_conf.txmode.offloads &=
4311                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4312                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4313                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4314                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4315                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4316                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4317                 printf("TSO for tunneled packets is disabled\n");
4318         } else {
4319                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4320                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4321                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4322                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4323                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4324                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4325
4326                 ports[res->port_id].dev_conf.txmode.offloads |=
4327                         (tso_offloads & dev_info.tx_offload_capa);
4328                 printf("TSO segment size for tunneled packets is %d\n",
4329                         ports[res->port_id].tunnel_tso_segsz);
4330
4331                 /* Below conditions are needed to make it work:
4332                  * (1) tunnel TSO is supported by the NIC;
4333                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4334                  * are recognized;
4335                  * (3) for tunneled pkts with outer L3 of IPv4,
4336                  * "csum set outer-ip" must be set to hw, because after tso,
4337                  * total_len of outer IP header is changed, and the checksum
4338                  * of outer IP header calculated by sw should be wrong; that
4339                  * is not necessary for IPv6 tunneled pkts because there's no
4340                  * checksum in IP header anymore.
4341                  */
4342
4343                 if (!ports[res->port_id].parse_tunnel)
4344                         printf("Warning: csum parse_tunnel must be set "
4345                                 "so that tunneled packets are recognized\n");
4346                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4347                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4348                         printf("Warning: csum set outer-ip must be set to hw "
4349                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4350         }
4351
4352         cmd_reconfig_device_queue(res->port_id, 1, 1);
4353 }
4354
4355 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4356         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4357                                 tso, "tunnel_tso");
4358 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4359         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4360                                 mode, "set");
4361 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4362         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4363                                 tso_segsz, UINT16);
4364 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4365         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4366                                 port_id, UINT16);
4367
4368 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4369         .f = cmd_tunnel_tso_set_parsed,
4370         .data = NULL,
4371         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4372                 "Set TSO segment size of tunneled packets for csum engine "
4373                 "(0 to disable)",
4374         .tokens = {
4375                 (void *)&cmd_tunnel_tso_set_tso,
4376                 (void *)&cmd_tunnel_tso_set_mode,
4377                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4378                 (void *)&cmd_tunnel_tso_set_portid,
4379                 NULL,
4380         },
4381 };
4382
4383 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4384         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4385                                 mode, "show");
4386
4387
4388 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4389         .f = cmd_tunnel_tso_set_parsed,
4390         .data = NULL,
4391         .help_str = "tunnel_tso show <port_id> "
4392                 "Show TSO segment size of tunneled packets for csum engine",
4393         .tokens = {
4394                 (void *)&cmd_tunnel_tso_set_tso,
4395                 (void *)&cmd_tunnel_tso_show_mode,
4396                 (void *)&cmd_tunnel_tso_set_portid,
4397                 NULL,
4398         },
4399 };
4400
4401 /* *** SET GRO FOR A PORT *** */
4402 struct cmd_gro_enable_result {
4403         cmdline_fixed_string_t cmd_set;
4404         cmdline_fixed_string_t cmd_port;
4405         cmdline_fixed_string_t cmd_keyword;
4406         cmdline_fixed_string_t cmd_onoff;
4407         portid_t cmd_pid;
4408 };
4409
4410 static void
4411 cmd_gro_enable_parsed(void *parsed_result,
4412                 __attribute__((unused)) struct cmdline *cl,
4413                 __attribute__((unused)) void *data)
4414 {
4415         struct cmd_gro_enable_result *res;
4416
4417         res = parsed_result;
4418         if (!strcmp(res->cmd_keyword, "gro"))
4419                 setup_gro(res->cmd_onoff, res->cmd_pid);
4420 }
4421
4422 cmdline_parse_token_string_t cmd_gro_enable_set =
4423         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4424                         cmd_set, "set");
4425 cmdline_parse_token_string_t cmd_gro_enable_port =
4426         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4427                         cmd_keyword, "port");
4428 cmdline_parse_token_num_t cmd_gro_enable_pid =
4429         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4430                         cmd_pid, UINT16);
4431 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4432         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4433                         cmd_keyword, "gro");
4434 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4435         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4436                         cmd_onoff, "on#off");
4437
4438 cmdline_parse_inst_t cmd_gro_enable = {
4439         .f = cmd_gro_enable_parsed,
4440         .data = NULL,
4441         .help_str = "set port <port_id> gro on|off",
4442         .tokens = {
4443                 (void *)&cmd_gro_enable_set,
4444                 (void *)&cmd_gro_enable_port,
4445                 (void *)&cmd_gro_enable_pid,
4446                 (void *)&cmd_gro_enable_keyword,
4447                 (void *)&cmd_gro_enable_onoff,
4448                 NULL,
4449         },
4450 };
4451
4452 /* *** DISPLAY GRO CONFIGURATION *** */
4453 struct cmd_gro_show_result {
4454         cmdline_fixed_string_t cmd_show;
4455         cmdline_fixed_string_t cmd_port;
4456         cmdline_fixed_string_t cmd_keyword;
4457         portid_t cmd_pid;
4458 };
4459
4460 static void
4461 cmd_gro_show_parsed(void *parsed_result,
4462                 __attribute__((unused)) struct cmdline *cl,
4463                 __attribute__((unused)) void *data)
4464 {
4465         struct cmd_gro_show_result *res;
4466
4467         res = parsed_result;
4468         if (!strcmp(res->cmd_keyword, "gro"))
4469                 show_gro(res->cmd_pid);
4470 }
4471
4472 cmdline_parse_token_string_t cmd_gro_show_show =
4473         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4474                         cmd_show, "show");
4475 cmdline_parse_token_string_t cmd_gro_show_port =
4476         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4477                         cmd_port, "port");
4478 cmdline_parse_token_num_t cmd_gro_show_pid =
4479         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4480                         cmd_pid, UINT16);
4481 cmdline_parse_token_string_t cmd_gro_show_keyword =
4482         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4483                         cmd_keyword, "gro");
4484
4485 cmdline_parse_inst_t cmd_gro_show = {
4486         .f = cmd_gro_show_parsed,
4487         .data = NULL,
4488         .help_str = "show port <port_id> gro",
4489         .tokens = {
4490                 (void *)&cmd_gro_show_show,
4491                 (void *)&cmd_gro_show_port,
4492                 (void *)&cmd_gro_show_pid,
4493                 (void *)&cmd_gro_show_keyword,
4494                 NULL,
4495         },
4496 };
4497
4498 /* *** SET FLUSH CYCLES FOR GRO *** */
4499 struct cmd_gro_flush_result {
4500         cmdline_fixed_string_t cmd_set;
4501         cmdline_fixed_string_t cmd_keyword;
4502         cmdline_fixed_string_t cmd_flush;
4503         uint8_t cmd_cycles;
4504 };
4505
4506 static void
4507 cmd_gro_flush_parsed(void *parsed_result,
4508                 __attribute__((unused)) struct cmdline *cl,
4509                 __attribute__((unused)) void *data)
4510 {
4511         struct cmd_gro_flush_result *res;
4512
4513         res = parsed_result;
4514         if ((!strcmp(res->cmd_keyword, "gro")) &&
4515                         (!strcmp(res->cmd_flush, "flush")))
4516                 setup_gro_flush_cycles(res->cmd_cycles);
4517 }
4518
4519 cmdline_parse_token_string_t cmd_gro_flush_set =
4520         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4521                         cmd_set, "set");
4522 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4523         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4524                         cmd_keyword, "gro");
4525 cmdline_parse_token_string_t cmd_gro_flush_flush =
4526         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4527                         cmd_flush, "flush");
4528 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4529         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4530                         cmd_cycles, UINT8);
4531
4532 cmdline_parse_inst_t cmd_gro_flush = {
4533         .f = cmd_gro_flush_parsed,
4534         .data = NULL,
4535         .help_str = "set gro flush <cycles>",
4536         .tokens = {
4537                 (void *)&cmd_gro_flush_set,
4538                 (void *)&cmd_gro_flush_keyword,
4539                 (void *)&cmd_gro_flush_flush,
4540                 (void *)&cmd_gro_flush_cycles,
4541                 NULL,
4542         },
4543 };
4544
4545 /* *** ENABLE/DISABLE GSO *** */
4546 struct cmd_gso_enable_result {
4547         cmdline_fixed_string_t cmd_set;
4548         cmdline_fixed_string_t cmd_port;
4549         cmdline_fixed_string_t cmd_keyword;
4550         cmdline_fixed_string_t cmd_mode;
4551         portid_t cmd_pid;
4552 };
4553
4554 static void
4555 cmd_gso_enable_parsed(void *parsed_result,
4556                 __attribute__((unused)) struct cmdline *cl,
4557                 __attribute__((unused)) void *data)
4558 {
4559         struct cmd_gso_enable_result *res;
4560
4561         res = parsed_result;
4562         if (!strcmp(res->cmd_keyword, "gso"))
4563                 setup_gso(res->cmd_mode, res->cmd_pid);
4564 }
4565
4566 cmdline_parse_token_string_t cmd_gso_enable_set =
4567         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4568                         cmd_set, "set");
4569 cmdline_parse_token_string_t cmd_gso_enable_port =
4570         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4571                         cmd_port, "port");
4572 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4573         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4574                         cmd_keyword, "gso");
4575 cmdline_parse_token_string_t cmd_gso_enable_mode =
4576         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4577                         cmd_mode, "on#off");
4578 cmdline_parse_token_num_t cmd_gso_enable_pid =
4579         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4580                         cmd_pid, UINT16);
4581
4582 cmdline_parse_inst_t cmd_gso_enable = {
4583         .f = cmd_gso_enable_parsed,
4584         .data = NULL,
4585         .help_str = "set port <port_id> gso on|off",
4586         .tokens = {
4587                 (void *)&cmd_gso_enable_set,
4588                 (void *)&cmd_gso_enable_port,
4589                 (void *)&cmd_gso_enable_pid,
4590                 (void *)&cmd_gso_enable_keyword,
4591                 (void *)&cmd_gso_enable_mode,
4592                 NULL,
4593         },
4594 };
4595
4596 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4597 struct cmd_gso_size_result {
4598         cmdline_fixed_string_t cmd_set;
4599         cmdline_fixed_string_t cmd_keyword;
4600         cmdline_fixed_string_t cmd_segsz;
4601         uint16_t cmd_size;
4602 };
4603
4604 static void
4605 cmd_gso_size_parsed(void *parsed_result,
4606                        __attribute__((unused)) struct cmdline *cl,
4607                        __attribute__((unused)) void *data)
4608 {
4609         struct cmd_gso_size_result *res = parsed_result;
4610
4611         if (test_done == 0) {
4612                 printf("Before setting GSO segsz, please first"
4613                                 " stop fowarding\n");
4614                 return;
4615         }
4616
4617         if (!strcmp(res->cmd_keyword, "gso") &&
4618                         !strcmp(res->cmd_segsz, "segsz")) {
4619                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4620                         printf("gso_size should be larger than %zu."
4621                                         " Please input a legal value\n",
4622                                         RTE_GSO_SEG_SIZE_MIN);
4623                 else
4624                         gso_max_segment_size = res->cmd_size;
4625         }
4626 }
4627
4628 cmdline_parse_token_string_t cmd_gso_size_set =
4629         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4630                                 cmd_set, "set");
4631 cmdline_parse_token_string_t cmd_gso_size_keyword =
4632         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4633                                 cmd_keyword, "gso");
4634 cmdline_parse_token_string_t cmd_gso_size_segsz =
4635         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4636                                 cmd_segsz, "segsz");
4637 cmdline_parse_token_num_t cmd_gso_size_size =
4638         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4639                                 cmd_size, UINT16);
4640
4641 cmdline_parse_inst_t cmd_gso_size = {
4642         .f = cmd_gso_size_parsed,
4643         .data = NULL,
4644         .help_str = "set gso segsz <length>",
4645         .tokens = {
4646                 (void *)&cmd_gso_size_set,
4647                 (void *)&cmd_gso_size_keyword,
4648                 (void *)&cmd_gso_size_segsz,
4649                 (void *)&cmd_gso_size_size,
4650                 NULL,
4651         },
4652 };
4653
4654 /* *** SHOW GSO CONFIGURATION *** */
4655 struct cmd_gso_show_result {
4656         cmdline_fixed_string_t cmd_show;
4657         cmdline_fixed_string_t cmd_port;
4658         cmdline_fixed_string_t cmd_keyword;
4659         portid_t cmd_pid;
4660 };
4661
4662 static void
4663 cmd_gso_show_parsed(void *parsed_result,
4664                        __attribute__((unused)) struct cmdline *cl,
4665                        __attribute__((unused)) void *data)
4666 {
4667         struct cmd_gso_show_result *res = parsed_result;
4668
4669         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4670                 printf("invalid port id %u\n", res->cmd_pid);
4671                 return;
4672         }
4673         if (!strcmp(res->cmd_keyword, "gso")) {
4674                 if (gso_ports[res->cmd_pid].enable) {
4675                         printf("Max GSO'd packet size: %uB\n"
4676                                         "Supported GSO types: TCP/IPv4, "
4677                                         "VxLAN with inner TCP/IPv4 packet, "
4678                                         "GRE with inner TCP/IPv4  packet\n",
4679                                         gso_max_segment_size);
4680                 } else
4681                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4682         }
4683 }
4684
4685 cmdline_parse_token_string_t cmd_gso_show_show =
4686 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4687                 cmd_show, "show");
4688 cmdline_parse_token_string_t cmd_gso_show_port =
4689 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4690                 cmd_port, "port");
4691 cmdline_parse_token_string_t cmd_gso_show_keyword =
4692         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4693                                 cmd_keyword, "gso");
4694 cmdline_parse_token_num_t cmd_gso_show_pid =
4695         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4696                                 cmd_pid, UINT16);
4697
4698 cmdline_parse_inst_t cmd_gso_show = {
4699         .f = cmd_gso_show_parsed,
4700         .data = NULL,
4701         .help_str = "show port <port_id> gso",
4702         .tokens = {
4703                 (void *)&cmd_gso_show_show,
4704                 (void *)&cmd_gso_show_port,
4705                 (void *)&cmd_gso_show_pid,
4706                 (void *)&cmd_gso_show_keyword,
4707                 NULL,
4708         },
4709 };
4710
4711 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4712 struct cmd_set_flush_rx {
4713         cmdline_fixed_string_t set;
4714         cmdline_fixed_string_t flush_rx;
4715         cmdline_fixed_string_t mode;
4716 };
4717
4718 static void
4719 cmd_set_flush_rx_parsed(void *parsed_result,
4720                 __attribute__((unused)) struct cmdline *cl,
4721                 __attribute__((unused)) void *data)
4722 {
4723         struct cmd_set_flush_rx *res = parsed_result;
4724         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4725 }
4726
4727 cmdline_parse_token_string_t cmd_setflushrx_set =
4728         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4729                         set, "set");
4730 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4731         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4732                         flush_rx, "flush_rx");
4733 cmdline_parse_token_string_t cmd_setflushrx_mode =
4734         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4735                         mode, "on#off");
4736
4737
4738 cmdline_parse_inst_t cmd_set_flush_rx = {
4739         .f = cmd_set_flush_rx_parsed,
4740         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4741         .data = NULL,
4742         .tokens = {
4743                 (void *)&cmd_setflushrx_set,
4744                 (void *)&cmd_setflushrx_flush_rx,
4745                 (void *)&cmd_setflushrx_mode,
4746                 NULL,
4747         },
4748 };
4749
4750 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4751 struct cmd_set_link_check {
4752         cmdline_fixed_string_t set;
4753         cmdline_fixed_string_t link_check;
4754         cmdline_fixed_string_t mode;
4755 };
4756
4757 static void
4758 cmd_set_link_check_parsed(void *parsed_result,
4759                 __attribute__((unused)) struct cmdline *cl,
4760                 __attribute__((unused)) void *data)
4761 {
4762         struct cmd_set_link_check *res = parsed_result;
4763         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4764 }
4765
4766 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4767         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4768                         set, "set");
4769 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4770         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4771                         link_check, "link_check");
4772 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4773         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4774                         mode, "on#off");
4775
4776
4777 cmdline_parse_inst_t cmd_set_link_check = {
4778         .f = cmd_set_link_check_parsed,
4779         .help_str = "set link_check on|off: Enable/Disable link status check "
4780                     "when starting/stopping a port",
4781         .data = NULL,
4782         .tokens = {
4783                 (void *)&cmd_setlinkcheck_set,
4784                 (void *)&cmd_setlinkcheck_link_check,
4785                 (void *)&cmd_setlinkcheck_mode,
4786                 NULL,
4787         },
4788 };
4789
4790 /* *** SET NIC BYPASS MODE *** */
4791 struct cmd_set_bypass_mode_result {
4792         cmdline_fixed_string_t set;
4793         cmdline_fixed_string_t bypass;
4794         cmdline_fixed_string_t mode;
4795         cmdline_fixed_string_t value;
4796         portid_t port_id;
4797 };
4798
4799 static void
4800 cmd_set_bypass_mode_parsed(void *parsed_result,
4801                 __attribute__((unused)) struct cmdline *cl,
4802                 __attribute__((unused)) void *data)
4803 {
4804         struct cmd_set_bypass_mode_result *res = parsed_result;
4805         portid_t port_id = res->port_id;
4806         int32_t rc = -EINVAL;
4807
4808 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4809         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4810
4811         if (!strcmp(res->value, "bypass"))
4812                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4813         else if (!strcmp(res->value, "isolate"))
4814                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4815         else
4816                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4817
4818         /* Set the bypass mode for the relevant port. */
4819         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4820 #endif
4821         if (rc != 0)
4822                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4823 }
4824
4825 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4826         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4827                         set, "set");
4828 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4829         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4830                         bypass, "bypass");
4831 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4832         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4833                         mode, "mode");
4834 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4835         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4836                         value, "normal#bypass#isolate");
4837 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4838         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4839                                 port_id, UINT16);
4840
4841 cmdline_parse_inst_t cmd_set_bypass_mode = {
4842         .f = cmd_set_bypass_mode_parsed,
4843         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4844                     "Set the NIC bypass mode for port_id",
4845         .data = NULL,
4846         .tokens = {
4847                 (void *)&cmd_setbypass_mode_set,
4848                 (void *)&cmd_setbypass_mode_bypass,
4849                 (void *)&cmd_setbypass_mode_mode,
4850                 (void *)&cmd_setbypass_mode_value,
4851                 (void *)&cmd_setbypass_mode_port,
4852                 NULL,
4853         },
4854 };
4855
4856 /* *** SET NIC BYPASS EVENT *** */
4857 struct cmd_set_bypass_event_result {
4858         cmdline_fixed_string_t set;
4859         cmdline_fixed_string_t bypass;
4860         cmdline_fixed_string_t event;
4861         cmdline_fixed_string_t event_value;
4862         cmdline_fixed_string_t mode;
4863         cmdline_fixed_string_t mode_value;
4864         portid_t port_id;
4865 };
4866
4867 static void
4868 cmd_set_bypass_event_parsed(void *parsed_result,
4869                 __attribute__((unused)) struct cmdline *cl,
4870                 __attribute__((unused)) void *data)
4871 {
4872         int32_t rc = -EINVAL;
4873         struct cmd_set_bypass_event_result *res = parsed_result;
4874         portid_t port_id = res->port_id;
4875
4876 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4877         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4878         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4879
4880         if (!strcmp(res->event_value, "timeout"))
4881                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4882         else if (!strcmp(res->event_value, "os_on"))
4883                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4884         else if (!strcmp(res->event_value, "os_off"))
4885                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4886         else if (!strcmp(res->event_value, "power_on"))
4887                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4888         else if (!strcmp(res->event_value, "power_off"))
4889                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4890         else
4891                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4892
4893         if (!strcmp(res->mode_value, "bypass"))
4894                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4895         else if (!strcmp(res->mode_value, "isolate"))
4896                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4897         else
4898                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4899
4900         /* Set the watchdog timeout. */
4901         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4902
4903                 rc = -EINVAL;
4904                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4905                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4906                                                            bypass_timeout);
4907                 }
4908                 if (rc != 0) {
4909                         printf("Failed to set timeout value %u "
4910                         "for port %d, errto code: %d.\n",
4911                         bypass_timeout, port_id, rc);
4912                 }
4913         }
4914
4915         /* Set the bypass event to transition to bypass mode. */
4916         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4917                                               bypass_mode);
4918 #endif
4919
4920         if (rc != 0)
4921                 printf("\t Failed to set bypass event for port = %d.\n",
4922                        port_id);
4923 }
4924
4925 cmdline_parse_token_string_t cmd_setbypass_event_set =
4926         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4927                         set, "set");
4928 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4929         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4930                         bypass, "bypass");
4931 cmdline_parse_token_string_t cmd_setbypass_event_event =
4932         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4933                         event, "event");
4934 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4935         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4936                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4937 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4938         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4939                         mode, "mode");
4940 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4941         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4942                         mode_value, "normal#bypass#isolate");
4943 cmdline_parse_token_num_t cmd_setbypass_event_port =
4944         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4945                                 port_id, UINT16);
4946
4947 cmdline_parse_inst_t cmd_set_bypass_event = {
4948         .f = cmd_set_bypass_event_parsed,
4949         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4950                 "power_off mode normal|bypass|isolate <port_id>: "
4951                 "Set the NIC bypass event mode for port_id",
4952         .data = NULL,
4953         .tokens = {
4954                 (void *)&cmd_setbypass_event_set,
4955                 (void *)&cmd_setbypass_event_bypass,
4956                 (void *)&cmd_setbypass_event_event,
4957                 (void *)&cmd_setbypass_event_event_value,
4958                 (void *)&cmd_setbypass_event_mode,
4959                 (void *)&cmd_setbypass_event_mode_value,
4960                 (void *)&cmd_setbypass_event_port,
4961                 NULL,
4962         },
4963 };
4964
4965
4966 /* *** SET NIC BYPASS TIMEOUT *** */
4967 struct cmd_set_bypass_timeout_result {
4968         cmdline_fixed_string_t set;
4969         cmdline_fixed_string_t bypass;
4970         cmdline_fixed_string_t timeout;
4971         cmdline_fixed_string_t value;
4972 };
4973
4974 static void
4975 cmd_set_bypass_timeout_parsed(void *parsed_result,
4976                 __attribute__((unused)) struct cmdline *cl,
4977                 __attribute__((unused)) void *data)
4978 {
4979         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4980
4981 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4982         if (!strcmp(res->value, "1.5"))
4983                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4984         else if (!strcmp(res->value, "2"))
4985                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4986         else if (!strcmp(res->value, "3"))
4987                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4988         else if (!strcmp(res->value, "4"))
4989                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4990         else if (!strcmp(res->value, "8"))
4991                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4992         else if (!strcmp(res->value, "16"))
4993                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4994         else if (!strcmp(res->value, "32"))
4995                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4996         else
4997                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4998 #endif
4999 }
5000
5001 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5002         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5003                         set, "set");
5004 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5005         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5006                         bypass, "bypass");
5007 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5008         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5009                         timeout, "timeout");
5010 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5011         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5012                         value, "0#1.5#2#3#4#8#16#32");
5013
5014 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5015         .f = cmd_set_bypass_timeout_parsed,
5016         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5017                 "Set the NIC bypass watchdog timeout in seconds",
5018         .data = NULL,
5019         .tokens = {
5020                 (void *)&cmd_setbypass_timeout_set,
5021                 (void *)&cmd_setbypass_timeout_bypass,
5022                 (void *)&cmd_setbypass_timeout_timeout,
5023                 (void *)&cmd_setbypass_timeout_value,
5024                 NULL,
5025         },
5026 };
5027
5028 /* *** SHOW NIC BYPASS MODE *** */
5029 struct cmd_show_bypass_config_result {
5030         cmdline_fixed_string_t show;
5031         cmdline_fixed_string_t bypass;
5032         cmdline_fixed_string_t config;
5033         portid_t port_id;
5034 };
5035
5036 static void
5037 cmd_show_bypass_config_parsed(void *parsed_result,
5038                 __attribute__((unused)) struct cmdline *cl,
5039                 __attribute__((unused)) void *data)
5040 {
5041         struct cmd_show_bypass_config_result *res = parsed_result;
5042         portid_t port_id = res->port_id;
5043         int rc = -EINVAL;
5044 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5045         uint32_t event_mode;
5046         uint32_t bypass_mode;
5047         uint32_t timeout = bypass_timeout;
5048         int i;
5049
5050         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5051                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5052         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5053                 {"UNKNOWN", "normal", "bypass", "isolate"};
5054         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5055                 "NONE",
5056                 "OS/board on",
5057                 "power supply on",
5058                 "OS/board off",
5059                 "power supply off",
5060                 "timeout"};
5061         int num_events = (sizeof events) / (sizeof events[0]);
5062
5063         /* Display the bypass mode.*/
5064         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5065                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5066                 return;
5067         }
5068         else {
5069                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5070                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5071
5072                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5073         }
5074
5075         /* Display the bypass timeout.*/
5076         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5077                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5078
5079         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5080
5081         /* Display the bypass events and associated modes. */
5082         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5083
5084                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5085                         printf("\tFailed to get bypass mode for event = %s\n",
5086                                 events[i]);
5087                 } else {
5088                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5089                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5090
5091                         printf("\tbypass event: %-16s = %s\n", events[i],
5092                                 modes[event_mode]);
5093                 }
5094         }
5095 #endif
5096         if (rc != 0)
5097                 printf("\tFailed to get bypass configuration for port = %d\n",
5098                        port_id);
5099 }
5100
5101 cmdline_parse_token_string_t cmd_showbypass_config_show =
5102         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5103                         show, "show");
5104 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5105         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5106                         bypass, "bypass");
5107 cmdline_parse_token_string_t cmd_showbypass_config_config =
5108         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5109                         config, "config");
5110 cmdline_parse_token_num_t cmd_showbypass_config_port =
5111         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5112                                 port_id, UINT16);
5113
5114 cmdline_parse_inst_t cmd_show_bypass_config = {
5115         .f = cmd_show_bypass_config_parsed,
5116         .help_str = "show bypass config <port_id>: "
5117                     "Show the NIC bypass config for port_id",
5118         .data = NULL,
5119         .tokens = {
5120                 (void *)&cmd_showbypass_config_show,
5121                 (void *)&cmd_showbypass_config_bypass,
5122                 (void *)&cmd_showbypass_config_config,
5123                 (void *)&cmd_showbypass_config_port,
5124                 NULL,
5125         },
5126 };
5127
5128 #ifdef RTE_LIBRTE_PMD_BOND
5129 /* *** SET BONDING MODE *** */
5130 struct cmd_set_bonding_mode_result {
5131         cmdline_fixed_string_t set;
5132         cmdline_fixed_string_t bonding;
5133         cmdline_fixed_string_t mode;
5134         uint8_t value;
5135         portid_t port_id;
5136 };
5137
5138 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5139                 __attribute__((unused))  struct cmdline *cl,
5140                 __attribute__((unused)) void *data)
5141 {
5142         struct cmd_set_bonding_mode_result *res = parsed_result;
5143         portid_t port_id = res->port_id;
5144
5145         /* Set the bonding mode for the relevant port. */
5146         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5147                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5148 }
5149
5150 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5151 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5152                 set, "set");
5153 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5154 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5155                 bonding, "bonding");
5156 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5157 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5158                 mode, "mode");
5159 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5160 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5161                 value, UINT8);
5162 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5163 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5164                 port_id, UINT16);
5165
5166 cmdline_parse_inst_t cmd_set_bonding_mode = {
5167                 .f = cmd_set_bonding_mode_parsed,
5168                 .help_str = "set bonding mode <mode_value> <port_id>: "
5169                         "Set the bonding mode for port_id",
5170                 .data = NULL,
5171                 .tokens = {
5172                                 (void *) &cmd_setbonding_mode_set,
5173                                 (void *) &cmd_setbonding_mode_bonding,
5174                                 (void *) &cmd_setbonding_mode_mode,
5175                                 (void *) &cmd_setbonding_mode_value,
5176                                 (void *) &cmd_setbonding_mode_port,
5177                                 NULL
5178                 }
5179 };
5180
5181 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5182 struct cmd_set_bonding_lacp_dedicated_queues_result {
5183         cmdline_fixed_string_t set;
5184         cmdline_fixed_string_t bonding;
5185         cmdline_fixed_string_t lacp;
5186         cmdline_fixed_string_t dedicated_queues;
5187         portid_t port_id;
5188         cmdline_fixed_string_t mode;
5189 };
5190
5191 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5192                 __attribute__((unused))  struct cmdline *cl,
5193                 __attribute__((unused)) void *data)
5194 {
5195         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5196         portid_t port_id = res->port_id;
5197         struct rte_port *port;
5198
5199         port = &ports[port_id];
5200
5201         /** Check if the port is not started **/
5202         if (port->port_status != RTE_PORT_STOPPED) {
5203                 printf("Please stop port %d first\n", port_id);
5204                 return;
5205         }
5206
5207         if (!strcmp(res->mode, "enable")) {
5208                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5209                         printf("Dedicate queues for LACP control packets"
5210                                         " enabled\n");
5211                 else
5212                         printf("Enabling dedicate queues for LACP control "
5213                                         "packets on port %d failed\n", port_id);
5214         } else if (!strcmp(res->mode, "disable")) {
5215                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5216                         printf("Dedicated queues for LACP control packets "
5217                                         "disabled\n");
5218                 else
5219                         printf("Disabling dedicated queues for LACP control "
5220                                         "traffic on port %d failed\n", port_id);
5221         }
5222 }
5223
5224 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5225 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5226                 set, "set");
5227 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5228 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5229                 bonding, "bonding");
5230 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5231 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5232                 lacp, "lacp");
5233 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5234 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5235                 dedicated_queues, "dedicated_queues");
5236 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5237 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5238                 port_id, UINT16);
5239 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5240 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5241                 mode, "enable#disable");
5242
5243 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5244                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5245                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5246                         "enable|disable: "
5247                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5248                 .data = NULL,
5249                 .tokens = {
5250                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5251                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5252                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5253                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5254                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5255                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5256                         NULL
5257                 }
5258 };
5259
5260 /* *** SET BALANCE XMIT POLICY *** */
5261 struct cmd_set_bonding_balance_xmit_policy_result {
5262         cmdline_fixed_string_t set;
5263         cmdline_fixed_string_t bonding;
5264         cmdline_fixed_string_t balance_xmit_policy;
5265         portid_t port_id;
5266         cmdline_fixed_string_t policy;
5267 };
5268
5269 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5270                 __attribute__((unused))  struct cmdline *cl,
5271                 __attribute__((unused)) void *data)
5272 {
5273         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5274         portid_t port_id = res->port_id;
5275         uint8_t policy;
5276
5277         if (!strcmp(res->policy, "l2")) {
5278                 policy = BALANCE_XMIT_POLICY_LAYER2;
5279         } else if (!strcmp(res->policy, "l23")) {
5280                 policy = BALANCE_XMIT_POLICY_LAYER23;
5281         } else if (!strcmp(res->policy, "l34")) {
5282                 policy = BALANCE_XMIT_POLICY_LAYER34;
5283         } else {
5284                 printf("\t Invalid xmit policy selection");
5285                 return;
5286         }
5287
5288         /* Set the bonding mode for the relevant port. */
5289         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5290                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5291                                 port_id);
5292         }
5293 }
5294
5295 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5296 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5297                 set, "set");
5298 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5299 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5300                 bonding, "bonding");
5301 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5302 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5303                 balance_xmit_policy, "balance_xmit_policy");
5304 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5305 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5306                 port_id, UINT16);
5307 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5308 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5309                 policy, "l2#l23#l34");
5310
5311 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5312                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5313                 .help_str = "set bonding balance_xmit_policy <port_id> "
5314                         "l2|l23|l34: "
5315                         "Set the bonding balance_xmit_policy for port_id",
5316                 .data = NULL,
5317                 .tokens = {
5318                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5319                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5320                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5321                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5322                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5323                                 NULL
5324                 }
5325 };
5326
5327 /* *** SHOW NIC BONDING CONFIGURATION *** */
5328 struct cmd_show_bonding_config_result {
5329         cmdline_fixed_string_t show;
5330         cmdline_fixed_string_t bonding;
5331         cmdline_fixed_string_t config;
5332         portid_t port_id;
5333 };
5334
5335 static void cmd_show_bonding_config_parsed(void *parsed_result,
5336                 __attribute__((unused))  struct cmdline *cl,
5337                 __attribute__((unused)) void *data)
5338 {
5339         struct cmd_show_bonding_config_result *res = parsed_result;
5340         int bonding_mode, agg_mode;
5341         portid_t slaves[RTE_MAX_ETHPORTS];
5342         int num_slaves, num_active_slaves;
5343         int primary_id;
5344         int i;
5345         portid_t port_id = res->port_id;
5346
5347         /* Display the bonding mode.*/
5348         bonding_mode = rte_eth_bond_mode_get(port_id);
5349         if (bonding_mode < 0) {
5350                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5351                 return;
5352         } else
5353                 printf("\tBonding mode: %d\n", bonding_mode);
5354
5355         if (bonding_mode == BONDING_MODE_BALANCE) {
5356                 int balance_xmit_policy;
5357
5358                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5359                 if (balance_xmit_policy < 0) {
5360                         printf("\tFailed to get balance xmit policy for port = %d\n",
5361                                         port_id);
5362                         return;
5363                 } else {
5364                         printf("\tBalance Xmit Policy: ");
5365
5366                         switch (balance_xmit_policy) {
5367                         case BALANCE_XMIT_POLICY_LAYER2:
5368                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5369                                 break;
5370                         case BALANCE_XMIT_POLICY_LAYER23:
5371                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5372                                 break;
5373                         case BALANCE_XMIT_POLICY_LAYER34:
5374                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5375                                 break;
5376                         }
5377                         printf("\n");
5378                 }
5379         }
5380
5381         if (bonding_mode == BONDING_MODE_8023AD) {
5382                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5383                 printf("\tIEEE802.3AD Aggregator Mode: ");
5384                 switch (agg_mode) {
5385                 case AGG_BANDWIDTH:
5386                         printf("bandwidth");
5387                         break;
5388                 case AGG_STABLE:
5389                         printf("stable");
5390                         break;
5391                 case AGG_COUNT:
5392                         printf("count");
5393                         break;
5394                 }
5395                 printf("\n");
5396         }
5397
5398         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5399
5400         if (num_slaves < 0) {
5401                 printf("\tFailed to get slave list for port = %d\n", port_id);
5402                 return;
5403         }
5404         if (num_slaves > 0) {
5405                 printf("\tSlaves (%d): [", num_slaves);
5406                 for (i = 0; i < num_slaves - 1; i++)
5407                         printf("%d ", slaves[i]);
5408
5409                 printf("%d]\n", slaves[num_slaves - 1]);
5410         } else {
5411                 printf("\tSlaves: []\n");
5412
5413         }
5414
5415         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5416                         RTE_MAX_ETHPORTS);
5417
5418         if (num_active_slaves < 0) {
5419                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5420                 return;
5421         }
5422         if (num_active_slaves > 0) {
5423                 printf("\tActive Slaves (%d): [", num_active_slaves);
5424                 for (i = 0; i < num_active_slaves - 1; i++)
5425                         printf("%d ", slaves[i]);
5426
5427                 printf("%d]\n", slaves[num_active_slaves - 1]);
5428
5429         } else {
5430                 printf("\tActive Slaves: []\n");
5431
5432         }
5433
5434         primary_id = rte_eth_bond_primary_get(port_id);
5435         if (primary_id < 0) {
5436                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5437                 return;
5438         } else
5439                 printf("\tPrimary: [%d]\n", primary_id);
5440
5441 }
5442
5443 cmdline_parse_token_string_t cmd_showbonding_config_show =
5444 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5445                 show, "show");
5446 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5447 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5448                 bonding, "bonding");
5449 cmdline_parse_token_string_t cmd_showbonding_config_config =
5450 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5451                 config, "config");
5452 cmdline_parse_token_num_t cmd_showbonding_config_port =
5453 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5454                 port_id, UINT16);
5455
5456 cmdline_parse_inst_t cmd_show_bonding_config = {
5457                 .f = cmd_show_bonding_config_parsed,
5458                 .help_str = "show bonding config <port_id>: "
5459                         "Show the bonding config for port_id",
5460                 .data = NULL,
5461                 .tokens = {
5462                                 (void *)&cmd_showbonding_config_show,
5463                                 (void *)&cmd_showbonding_config_bonding,
5464                                 (void *)&cmd_showbonding_config_config,
5465                                 (void *)&cmd_showbonding_config_port,
5466                                 NULL
5467                 }
5468 };
5469
5470 /* *** SET BONDING PRIMARY *** */
5471 struct cmd_set_bonding_primary_result {
5472         cmdline_fixed_string_t set;
5473         cmdline_fixed_string_t bonding;
5474         cmdline_fixed_string_t primary;
5475         portid_t slave_id;
5476         portid_t port_id;
5477 };
5478
5479 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5480                 __attribute__((unused))  struct cmdline *cl,
5481                 __attribute__((unused)) void *data)
5482 {
5483         struct cmd_set_bonding_primary_result *res = parsed_result;
5484         portid_t master_port_id = res->port_id;
5485         portid_t slave_port_id = res->slave_id;
5486
5487         /* Set the primary slave for a bonded device. */
5488         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5489                 printf("\t Failed to set primary slave for port = %d.\n",
5490                                 master_port_id);
5491                 return;
5492         }
5493         init_port_config();
5494 }
5495
5496 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5497 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5498                 set, "set");
5499 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5500 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5501                 bonding, "bonding");
5502 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5503 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5504                 primary, "primary");
5505 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5506 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5507                 slave_id, UINT16);
5508 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5509 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5510                 port_id, UINT16);
5511
5512 cmdline_parse_inst_t cmd_set_bonding_primary = {
5513                 .f = cmd_set_bonding_primary_parsed,
5514                 .help_str = "set bonding primary <slave_id> <port_id>: "
5515                         "Set the primary slave for port_id",
5516                 .data = NULL,
5517                 .tokens = {
5518                                 (void *)&cmd_setbonding_primary_set,
5519                                 (void *)&cmd_setbonding_primary_bonding,
5520                                 (void *)&cmd_setbonding_primary_primary,
5521                                 (void *)&cmd_setbonding_primary_slave,
5522                                 (void *)&cmd_setbonding_primary_port,
5523                                 NULL
5524                 }
5525 };
5526
5527 /* *** ADD SLAVE *** */
5528 struct cmd_add_bonding_slave_result {
5529         cmdline_fixed_string_t add;
5530         cmdline_fixed_string_t bonding;
5531         cmdline_fixed_string_t slave;
5532         portid_t slave_id;
5533         portid_t port_id;
5534 };
5535
5536 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5537                 __attribute__((unused))  struct cmdline *cl,
5538                 __attribute__((unused)) void *data)
5539 {
5540         struct cmd_add_bonding_slave_result *res = parsed_result;
5541         portid_t master_port_id = res->port_id;
5542         portid_t slave_port_id = res->slave_id;
5543
5544         /* add the slave for a bonded device. */
5545         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5546                 printf("\t Failed to add slave %d to master port = %d.\n",
5547                                 slave_port_id, master_port_id);
5548                 return;
5549         }
5550         init_port_config();
5551         set_port_slave_flag(slave_port_id);
5552 }
5553
5554 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5555 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5556                 add, "add");
5557 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5558 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5559                 bonding, "bonding");
5560 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5561 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5562                 slave, "slave");
5563 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5564 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5565                 slave_id, UINT16);
5566 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5567 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5568                 port_id, UINT16);
5569
5570 cmdline_parse_inst_t cmd_add_bonding_slave = {
5571                 .f = cmd_add_bonding_slave_parsed,
5572                 .help_str = "add bonding slave <slave_id> <port_id>: "
5573                         "Add a slave device to a bonded device",
5574                 .data = NULL,
5575                 .tokens = {
5576                                 (void *)&cmd_addbonding_slave_add,
5577                                 (void *)&cmd_addbonding_slave_bonding,
5578                                 (void *)&cmd_addbonding_slave_slave,
5579                                 (void *)&cmd_addbonding_slave_slaveid,
5580                                 (void *)&cmd_addbonding_slave_port,
5581                                 NULL
5582                 }
5583 };
5584
5585 /* *** REMOVE SLAVE *** */
5586 struct cmd_remove_bonding_slave_result {
5587         cmdline_fixed_string_t remove;
5588         cmdline_fixed_string_t bonding;
5589         cmdline_fixed_string_t slave;
5590         portid_t slave_id;
5591         portid_t port_id;
5592 };
5593
5594 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5595                 __attribute__((unused))  struct cmdline *cl,
5596                 __attribute__((unused)) void *data)
5597 {
5598         struct cmd_remove_bonding_slave_result *res = parsed_result;
5599         portid_t master_port_id = res->port_id;
5600         portid_t slave_port_id = res->slave_id;
5601
5602         /* remove the slave from a bonded device. */
5603         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5604                 printf("\t Failed to remove slave %d from master port = %d.\n",
5605                                 slave_port_id, master_port_id);
5606                 return;
5607         }
5608         init_port_config();
5609         clear_port_slave_flag(slave_port_id);
5610 }
5611
5612 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5613                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5614                                 remove, "remove");
5615 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5616                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5617                                 bonding, "bonding");
5618 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5619                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5620                                 slave, "slave");
5621 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5622                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5623                                 slave_id, UINT16);
5624 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5625                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5626                                 port_id, UINT16);
5627
5628 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5629                 .f = cmd_remove_bonding_slave_parsed,
5630                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5631                         "Remove a slave device from a bonded device",
5632                 .data = NULL,
5633                 .tokens = {
5634                                 (void *)&cmd_removebonding_slave_remove,
5635                                 (void *)&cmd_removebonding_slave_bonding,
5636                                 (void *)&cmd_removebonding_slave_slave,
5637                                 (void *)&cmd_removebonding_slave_slaveid,
5638                                 (void *)&cmd_removebonding_slave_port,
5639                                 NULL
5640                 }
5641 };
5642
5643 /* *** CREATE BONDED DEVICE *** */
5644 struct cmd_create_bonded_device_result {
5645         cmdline_fixed_string_t create;
5646         cmdline_fixed_string_t bonded;
5647         cmdline_fixed_string_t device;
5648         uint8_t mode;
5649         uint8_t socket;
5650 };
5651
5652 static int bond_dev_num = 0;
5653
5654 static void cmd_create_bonded_device_parsed(void *parsed_result,
5655                 __attribute__((unused))  struct cmdline *cl,
5656                 __attribute__((unused)) void *data)
5657 {
5658         struct cmd_create_bonded_device_result *res = parsed_result;
5659         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5660         int port_id;
5661
5662         if (test_done == 0) {
5663                 printf("Please stop forwarding first\n");
5664                 return;
5665         }
5666
5667         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5668                         bond_dev_num++);
5669
5670         /* Create a new bonded device. */
5671         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5672         if (port_id < 0) {
5673                 printf("\t Failed to create bonded device.\n");
5674                 return;
5675         } else {
5676                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5677                                 port_id);
5678
5679                 /* Update number of ports */
5680                 nb_ports = rte_eth_dev_count_avail();
5681                 reconfig(port_id, res->socket);
5682                 rte_eth_promiscuous_enable(port_id);
5683         }
5684
5685 }
5686
5687 cmdline_parse_token_string_t cmd_createbonded_device_create =
5688                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5689                                 create, "create");
5690 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5691                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5692                                 bonded, "bonded");
5693 cmdline_parse_token_string_t cmd_createbonded_device_device =
5694                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5695                                 device, "device");
5696 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5697                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5698                                 mode, UINT8);
5699 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5700                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5701                                 socket, UINT8);
5702
5703 cmdline_parse_inst_t cmd_create_bonded_device = {
5704                 .f = cmd_create_bonded_device_parsed,
5705                 .help_str = "create bonded device <mode> <socket>: "
5706                         "Create a new bonded device with specific bonding mode and socket",
5707                 .data = NULL,
5708                 .tokens = {
5709                                 (void *)&cmd_createbonded_device_create,
5710                                 (void *)&cmd_createbonded_device_bonded,
5711                                 (void *)&cmd_createbonded_device_device,
5712                                 (void *)&cmd_createbonded_device_mode,
5713                                 (void *)&cmd_createbonded_device_socket,
5714                                 NULL
5715                 }
5716 };
5717
5718 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5719 struct cmd_set_bond_mac_addr_result {
5720         cmdline_fixed_string_t set;
5721         cmdline_fixed_string_t bonding;
5722         cmdline_fixed_string_t mac_addr;
5723         uint16_t port_num;
5724         struct ether_addr address;
5725 };
5726
5727 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5728                 __attribute__((unused))  struct cmdline *cl,
5729                 __attribute__((unused)) void *data)
5730 {
5731         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5732         int ret;
5733
5734         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5735                 return;
5736
5737         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5738
5739         /* check the return value and print it if is < 0 */
5740         if (ret < 0)
5741                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5742 }
5743
5744 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5745                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5746 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5747                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5748                                 "bonding");
5749 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5750                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5751                                 "mac_addr");
5752 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5753                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5754                                 port_num, UINT16);
5755 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5756                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5757
5758 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5759                 .f = cmd_set_bond_mac_addr_parsed,
5760                 .data = (void *) 0,
5761                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5762                 .tokens = {
5763                                 (void *)&cmd_set_bond_mac_addr_set,
5764                                 (void *)&cmd_set_bond_mac_addr_bonding,
5765                                 (void *)&cmd_set_bond_mac_addr_mac,
5766                                 (void *)&cmd_set_bond_mac_addr_portnum,
5767                                 (void *)&cmd_set_bond_mac_addr_addr,
5768                                 NULL
5769                 }
5770 };
5771
5772
5773 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5774 struct cmd_set_bond_mon_period_result {
5775         cmdline_fixed_string_t set;
5776         cmdline_fixed_string_t bonding;
5777         cmdline_fixed_string_t mon_period;
5778         uint16_t port_num;
5779         uint32_t period_ms;
5780 };
5781
5782 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5783                 __attribute__((unused))  struct cmdline *cl,
5784                 __attribute__((unused)) void *data)
5785 {
5786         struct cmd_set_bond_mon_period_result *res = parsed_result;
5787         int ret;
5788
5789         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5790
5791         /* check the return value and print it if is < 0 */
5792         if (ret < 0)
5793                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5794 }
5795
5796 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5797                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5798                                 set, "set");
5799 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5800                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5801                                 bonding, "bonding");
5802 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5803                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5804                                 mon_period,     "mon_period");
5805 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5806                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5807                                 port_num, UINT16);
5808 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5809                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5810                                 period_ms, UINT32);
5811
5812 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5813                 .f = cmd_set_bond_mon_period_parsed,
5814                 .data = (void *) 0,
5815                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5816                 .tokens = {
5817                                 (void *)&cmd_set_bond_mon_period_set,
5818                                 (void *)&cmd_set_bond_mon_period_bonding,
5819                                 (void *)&cmd_set_bond_mon_period_mon_period,
5820                                 (void *)&cmd_set_bond_mon_period_portnum,
5821                                 (void *)&cmd_set_bond_mon_period_period_ms,
5822                                 NULL
5823                 }
5824 };
5825
5826
5827
5828 struct cmd_set_bonding_agg_mode_policy_result {
5829         cmdline_fixed_string_t set;
5830         cmdline_fixed_string_t bonding;
5831         cmdline_fixed_string_t agg_mode;
5832         uint16_t port_num;
5833         cmdline_fixed_string_t policy;
5834 };
5835
5836
5837 static void
5838 cmd_set_bonding_agg_mode(void *parsed_result,
5839                 __attribute__((unused)) struct cmdline *cl,
5840                 __attribute__((unused)) void *data)
5841 {
5842         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5843         uint8_t policy = AGG_BANDWIDTH;
5844
5845         if (!strcmp(res->policy, "bandwidth"))
5846                 policy = AGG_BANDWIDTH;
5847         else if (!strcmp(res->policy, "stable"))
5848                 policy = AGG_STABLE;
5849         else if (!strcmp(res->policy, "count"))
5850                 policy = AGG_COUNT;
5851
5852         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5853 }
5854
5855
5856 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5857         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5858                                 set, "set");
5859 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5860         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5861                                 bonding, "bonding");
5862
5863 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5864         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5865                                 agg_mode, "agg_mode");
5866
5867 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5868         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5869                                 port_num, UINT16);
5870
5871 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5872         TOKEN_STRING_INITIALIZER(
5873                         struct cmd_set_bonding_balance_xmit_policy_result,
5874                 policy, "stable#bandwidth#count");
5875
5876 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5877         .f = cmd_set_bonding_agg_mode,
5878         .data = (void *) 0,
5879         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5880         .tokens = {
5881                         (void *)&cmd_set_bonding_agg_mode_set,
5882                         (void *)&cmd_set_bonding_agg_mode_bonding,
5883                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5884                         (void *)&cmd_set_bonding_agg_mode_portnum,
5885                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5886                         NULL
5887                 }
5888 };
5889
5890
5891 #endif /* RTE_LIBRTE_PMD_BOND */
5892
5893 /* *** SET FORWARDING MODE *** */
5894 struct cmd_set_fwd_mode_result {
5895         cmdline_fixed_string_t set;
5896         cmdline_fixed_string_t fwd;
5897         cmdline_fixed_string_t mode;
5898 };
5899
5900 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5901                                     __attribute__((unused)) struct cmdline *cl,
5902                                     __attribute__((unused)) void *data)
5903 {
5904         struct cmd_set_fwd_mode_result *res = parsed_result;
5905
5906         retry_enabled = 0;
5907         set_pkt_forwarding_mode(res->mode);
5908 }
5909
5910 cmdline_parse_token_string_t cmd_setfwd_set =
5911         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5912 cmdline_parse_token_string_t cmd_setfwd_fwd =
5913         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5914 cmdline_parse_token_string_t cmd_setfwd_mode =
5915         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5916                 "" /* defined at init */);
5917
5918 cmdline_parse_inst_t cmd_set_fwd_mode = {
5919         .f = cmd_set_fwd_mode_parsed,
5920         .data = NULL,
5921         .help_str = NULL, /* defined at init */
5922         .tokens = {
5923                 (void *)&cmd_setfwd_set,
5924                 (void *)&cmd_setfwd_fwd,
5925                 (void *)&cmd_setfwd_mode,
5926                 NULL,
5927         },
5928 };
5929
5930 static void cmd_set_fwd_mode_init(void)
5931 {
5932         char *modes, *c;
5933         static char token[128];
5934         static char help[256];
5935         cmdline_parse_token_string_t *token_struct;
5936
5937         modes = list_pkt_forwarding_modes();
5938         snprintf(help, sizeof(help), "set fwd %s: "
5939                 "Set packet forwarding mode", modes);
5940         cmd_set_fwd_mode.help_str = help;
5941
5942         /* string token separator is # */
5943         for (c = token; *modes != '\0'; modes++)
5944                 if (*modes == '|')
5945                         *c++ = '#';
5946                 else
5947                         *c++ = *modes;
5948         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5949         token_struct->string_data.str = token;
5950 }
5951
5952 /* *** SET RETRY FORWARDING MODE *** */
5953 struct cmd_set_fwd_retry_mode_result {
5954         cmdline_fixed_string_t set;
5955         cmdline_fixed_string_t fwd;
5956         cmdline_fixed_string_t mode;
5957         cmdline_fixed_string_t retry;
5958 };
5959
5960 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5961                             __attribute__((unused)) struct cmdline *cl,
5962                             __attribute__((unused)) void *data)
5963 {
5964         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5965
5966         retry_enabled = 1;
5967         set_pkt_forwarding_mode(res->mode);
5968 }
5969
5970 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5971         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5972                         set, "set");
5973 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5974         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5975                         fwd, "fwd");
5976 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5977         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5978                         mode,
5979                 "" /* defined at init */);
5980 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5981         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5982                         retry, "retry");
5983
5984 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5985         .f = cmd_set_fwd_retry_mode_parsed,
5986         .data = NULL,
5987         .help_str = NULL, /* defined at init */
5988         .tokens = {
5989                 (void *)&cmd_setfwd_retry_set,
5990                 (void *)&cmd_setfwd_retry_fwd,
5991                 (void *)&cmd_setfwd_retry_mode,
5992                 (void *)&cmd_setfwd_retry_retry,
5993                 NULL,
5994         },
5995 };
5996
5997 static void cmd_set_fwd_retry_mode_init(void)
5998 {
5999         char *modes, *c;
6000         static char token[128];
6001         static char help[256];
6002         cmdline_parse_token_string_t *token_struct;
6003
6004         modes = list_pkt_forwarding_retry_modes();
6005         snprintf(help, sizeof(help), "set fwd %s retry: "
6006                 "Set packet forwarding mode with retry", modes);
6007         cmd_set_fwd_retry_mode.help_str = help;
6008
6009         /* string token separator is # */
6010         for (c = token; *modes != '\0'; modes++)
6011                 if (*modes == '|')
6012                         *c++ = '#';
6013                 else
6014                         *c++ = *modes;
6015         token_struct = (cmdline_parse_token_string_t *)
6016                 cmd_set_fwd_retry_mode.tokens[2];
6017         token_struct->string_data.str = token;
6018 }
6019
6020 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6021 struct cmd_set_burst_tx_retry_result {
6022         cmdline_fixed_string_t set;
6023         cmdline_fixed_string_t burst;
6024         cmdline_fixed_string_t tx;
6025         cmdline_fixed_string_t delay;
6026         uint32_t time;
6027         cmdline_fixed_string_t retry;
6028         uint32_t retry_num;
6029 };
6030
6031 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6032                                         __attribute__((unused)) struct cmdline *cl,
6033                                         __attribute__((unused)) void *data)
6034 {
6035         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6036
6037         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6038                 && !strcmp(res->tx, "tx")) {
6039                 if (!strcmp(res->delay, "delay"))
6040                         burst_tx_delay_time = res->time;
6041                 if (!strcmp(res->retry, "retry"))
6042                         burst_tx_retry_num = res->retry_num;
6043         }
6044
6045 }
6046
6047 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6048         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6049 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6050         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6051                                  "burst");
6052 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6053         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6054 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6055         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6056 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6057         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6058 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6059         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6060 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6061         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6062
6063 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6064         .f = cmd_set_burst_tx_retry_parsed,
6065         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6066         .tokens = {
6067                 (void *)&cmd_set_burst_tx_retry_set,
6068                 (void *)&cmd_set_burst_tx_retry_burst,
6069                 (void *)&cmd_set_burst_tx_retry_tx,
6070                 (void *)&cmd_set_burst_tx_retry_delay,
6071                 (void *)&cmd_set_burst_tx_retry_time,
6072                 (void *)&cmd_set_burst_tx_retry_retry,
6073                 (void *)&cmd_set_burst_tx_retry_retry_num,
6074                 NULL,
6075         },
6076 };
6077
6078 /* *** SET PROMISC MODE *** */
6079 struct cmd_set_promisc_mode_result {
6080         cmdline_fixed_string_t set;
6081         cmdline_fixed_string_t promisc;
6082         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6083         uint16_t port_num;               /* valid if "allports" argument == 0 */
6084         cmdline_fixed_string_t mode;
6085 };
6086
6087 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6088                                         __attribute__((unused)) struct cmdline *cl,
6089                                         void *allports)
6090 {
6091         struct cmd_set_promisc_mode_result *res = parsed_result;
6092         int enable;
6093         portid_t i;
6094
6095         if (!strcmp(res->mode, "on"))
6096                 enable = 1;
6097         else
6098                 enable = 0;
6099
6100         /* all ports */
6101         if (allports) {
6102                 RTE_ETH_FOREACH_DEV(i) {
6103                         if (enable)
6104                                 rte_eth_promiscuous_enable(i);
6105                         else
6106                                 rte_eth_promiscuous_disable(i);
6107                 }
6108         }
6109         else {
6110                 if (enable)
6111                         rte_eth_promiscuous_enable(res->port_num);
6112                 else
6113                         rte_eth_promiscuous_disable(res->port_num);
6114         }
6115 }
6116
6117 cmdline_parse_token_string_t cmd_setpromisc_set =
6118         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6119 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6120         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6121                                  "promisc");
6122 cmdline_parse_token_string_t cmd_setpromisc_portall =
6123         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6124                                  "all");
6125 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6126         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6127                               UINT16);
6128 cmdline_parse_token_string_t cmd_setpromisc_mode =
6129         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6130                                  "on#off");
6131
6132 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6133         .f = cmd_set_promisc_mode_parsed,
6134         .data = (void *)1,
6135         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6136         .tokens = {
6137                 (void *)&cmd_setpromisc_set,
6138                 (void *)&cmd_setpromisc_promisc,
6139                 (void *)&cmd_setpromisc_portall,
6140                 (void *)&cmd_setpromisc_mode,
6141                 NULL,
6142         },
6143 };
6144
6145 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6146         .f = cmd_set_promisc_mode_parsed,
6147         .data = (void *)0,
6148         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6149         .tokens = {
6150                 (void *)&cmd_setpromisc_set,
6151                 (void *)&cmd_setpromisc_promisc,
6152                 (void *)&cmd_setpromisc_portnum,
6153                 (void *)&cmd_setpromisc_mode,
6154                 NULL,
6155         },
6156 };
6157
6158 /* *** SET ALLMULTI MODE *** */
6159 struct cmd_set_allmulti_mode_result {
6160         cmdline_fixed_string_t set;
6161         cmdline_fixed_string_t allmulti;
6162         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6163         uint16_t port_num;               /* valid if "allports" argument == 0 */
6164         cmdline_fixed_string_t mode;
6165 };
6166
6167 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6168                                         __attribute__((unused)) struct cmdline *cl,
6169                                         void *allports)
6170 {
6171         struct cmd_set_allmulti_mode_result *res = parsed_result;
6172         int enable;
6173         portid_t i;
6174
6175         if (!strcmp(res->mode, "on"))
6176                 enable = 1;
6177         else
6178                 enable = 0;
6179
6180         /* all ports */
6181         if (allports) {
6182                 RTE_ETH_FOREACH_DEV(i) {
6183                         if (enable)
6184                                 rte_eth_allmulticast_enable(i);
6185                         else
6186                                 rte_eth_allmulticast_disable(i);
6187                 }
6188         }
6189         else {
6190                 if (enable)
6191                         rte_eth_allmulticast_enable(res->port_num);
6192                 else
6193                         rte_eth_allmulticast_disable(res->port_num);
6194         }
6195 }
6196
6197 cmdline_parse_token_string_t cmd_setallmulti_set =
6198         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6199 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6200         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6201                                  "allmulti");
6202 cmdline_parse_token_string_t cmd_setallmulti_portall =
6203         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6204                                  "all");
6205 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6206         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6207                               UINT16);
6208 cmdline_parse_token_string_t cmd_setallmulti_mode =
6209         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6210                                  "on#off");
6211
6212 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6213         .f = cmd_set_allmulti_mode_parsed,
6214         .data = (void *)1,
6215         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6216         .tokens = {
6217                 (void *)&cmd_setallmulti_set,
6218                 (void *)&cmd_setallmulti_allmulti,
6219                 (void *)&cmd_setallmulti_portall,
6220                 (void *)&cmd_setallmulti_mode,
6221                 NULL,
6222         },
6223 };
6224
6225 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6226         .f = cmd_set_allmulti_mode_parsed,
6227         .data = (void *)0,
6228         .help_str = "set allmulti <port_id> on|off: "
6229                 "Set allmulti mode on port_id",
6230         .tokens = {
6231                 (void *)&cmd_setallmulti_set,
6232                 (void *)&cmd_setallmulti_allmulti,
6233                 (void *)&cmd_setallmulti_portnum,
6234                 (void *)&cmd_setallmulti_mode,
6235                 NULL,
6236         },
6237 };
6238
6239 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6240 struct cmd_link_flow_ctrl_set_result {
6241         cmdline_fixed_string_t set;
6242         cmdline_fixed_string_t flow_ctrl;
6243         cmdline_fixed_string_t rx;
6244         cmdline_fixed_string_t rx_lfc_mode;
6245         cmdline_fixed_string_t tx;
6246         cmdline_fixed_string_t tx_lfc_mode;
6247         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6248         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6249         cmdline_fixed_string_t autoneg_str;
6250         cmdline_fixed_string_t autoneg;
6251         cmdline_fixed_string_t hw_str;
6252         uint32_t high_water;
6253         cmdline_fixed_string_t lw_str;
6254         uint32_t low_water;
6255         cmdline_fixed_string_t pt_str;
6256         uint16_t pause_time;
6257         cmdline_fixed_string_t xon_str;
6258         uint16_t send_xon;
6259         portid_t port_id;
6260 };
6261
6262 cmdline_parse_token_string_t cmd_lfc_set_set =
6263         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6264                                 set, "set");
6265 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6266         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6267                                 flow_ctrl, "flow_ctrl");
6268 cmdline_parse_token_string_t cmd_lfc_set_rx =
6269         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6270                                 rx, "rx");
6271 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6272         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6273                                 rx_lfc_mode, "on#off");
6274 cmdline_parse_token_string_t cmd_lfc_set_tx =
6275         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6276                                 tx, "tx");
6277 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6278         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6279                                 tx_lfc_mode, "on#off");
6280 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6281         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6282                                 hw_str, "high_water");
6283 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6284         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6285                                 high_water, UINT32);
6286 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6287         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6288                                 lw_str, "low_water");
6289 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6290         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6291                                 low_water, UINT32);
6292 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6293         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6294                                 pt_str, "pause_time");
6295 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6296         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6297                                 pause_time, UINT16);
6298 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6299         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6300                                 xon_str, "send_xon");
6301 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6302         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6303                                 send_xon, UINT16);
6304 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6305         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6306                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6307 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6308         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6309                                 mac_ctrl_frame_fwd_mode, "on#off");
6310 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6311         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6312                                 autoneg_str, "autoneg");
6313 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6314         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6315                                 autoneg, "on#off");
6316 cmdline_parse_token_num_t cmd_lfc_set_portid =
6317         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6318                                 port_id, UINT16);
6319
6320 /* forward declaration */
6321 static void
6322 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6323                               void *data);
6324
6325 cmdline_parse_inst_t cmd_link_flow_control_set = {
6326         .f = cmd_link_flow_ctrl_set_parsed,
6327         .data = NULL,
6328         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6329                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6330                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6331         .tokens = {
6332                 (void *)&cmd_lfc_set_set,
6333                 (void *)&cmd_lfc_set_flow_ctrl,
6334                 (void *)&cmd_lfc_set_rx,
6335                 (void *)&cmd_lfc_set_rx_mode,
6336                 (void *)&cmd_lfc_set_tx,
6337                 (void *)&cmd_lfc_set_tx_mode,
6338                 (void *)&cmd_lfc_set_high_water,
6339                 (void *)&cmd_lfc_set_low_water,
6340                 (void *)&cmd_lfc_set_pause_time,
6341                 (void *)&cmd_lfc_set_send_xon,
6342                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6343                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6344                 (void *)&cmd_lfc_set_autoneg_str,
6345                 (void *)&cmd_lfc_set_autoneg,
6346                 (void *)&cmd_lfc_set_portid,
6347                 NULL,
6348         },
6349 };
6350
6351 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6352         .f = cmd_link_flow_ctrl_set_parsed,
6353         .data = (void *)&cmd_link_flow_control_set_rx,
6354         .help_str = "set flow_ctrl rx on|off <port_id>: "
6355                 "Change rx flow control parameter",
6356         .tokens = {
6357                 (void *)&cmd_lfc_set_set,
6358                 (void *)&cmd_lfc_set_flow_ctrl,
6359                 (void *)&cmd_lfc_set_rx,
6360                 (void *)&cmd_lfc_set_rx_mode,
6361                 (void *)&cmd_lfc_set_portid,
6362                 NULL,
6363         },
6364 };
6365
6366 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6367         .f = cmd_link_flow_ctrl_set_parsed,
6368         .data = (void *)&cmd_link_flow_control_set_tx,
6369         .help_str = "set flow_ctrl tx on|off <port_id>: "
6370                 "Change tx flow control parameter",
6371         .tokens = {
6372                 (void *)&cmd_lfc_set_set,
6373                 (void *)&cmd_lfc_set_flow_ctrl,
6374                 (void *)&cmd_lfc_set_tx,
6375                 (void *)&cmd_lfc_set_tx_mode,
6376                 (void *)&cmd_lfc_set_portid,
6377                 NULL,
6378         },
6379 };
6380
6381 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6382         .f = cmd_link_flow_ctrl_set_parsed,
6383         .data = (void *)&cmd_link_flow_control_set_hw,
6384         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6385                 "Change high water flow control parameter",
6386         .tokens = {
6387                 (void *)&cmd_lfc_set_set,
6388                 (void *)&cmd_lfc_set_flow_ctrl,
6389                 (void *)&cmd_lfc_set_high_water_str,
6390                 (void *)&cmd_lfc_set_high_water,
6391                 (void *)&cmd_lfc_set_portid,
6392                 NULL,
6393         },
6394 };
6395
6396 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6397         .f = cmd_link_flow_ctrl_set_parsed,
6398         .data = (void *)&cmd_link_flow_control_set_lw,
6399         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6400                 "Change low water flow control parameter",
6401         .tokens = {
6402                 (void *)&cmd_lfc_set_set,
6403                 (void *)&cmd_lfc_set_flow_ctrl,
6404                 (void *)&cmd_lfc_set_low_water_str,
6405                 (void *)&cmd_lfc_set_low_water,
6406                 (void *)&cmd_lfc_set_portid,
6407                 NULL,
6408         },
6409 };
6410
6411 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6412         .f = cmd_link_flow_ctrl_set_parsed,
6413         .data = (void *)&cmd_link_flow_control_set_pt,
6414         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6415                 "Change pause time flow control parameter",
6416         .tokens = {
6417                 (void *)&cmd_lfc_set_set,
6418                 (void *)&cmd_lfc_set_flow_ctrl,
6419                 (void *)&cmd_lfc_set_pause_time_str,
6420                 (void *)&cmd_lfc_set_pause_time,
6421                 (void *)&cmd_lfc_set_portid,
6422                 NULL,
6423         },
6424 };
6425
6426 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6427         .f = cmd_link_flow_ctrl_set_parsed,
6428         .data = (void *)&cmd_link_flow_control_set_xon,
6429         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6430                 "Change send_xon flow control parameter",
6431         .tokens = {
6432                 (void *)&cmd_lfc_set_set,
6433                 (void *)&cmd_lfc_set_flow_ctrl,
6434                 (void *)&cmd_lfc_set_send_xon_str,
6435                 (void *)&cmd_lfc_set_send_xon,
6436                 (void *)&cmd_lfc_set_portid,
6437                 NULL,
6438         },
6439 };
6440
6441 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6442         .f = cmd_link_flow_ctrl_set_parsed,
6443         .data = (void *)&cmd_link_flow_control_set_macfwd,
6444         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6445                 "Change mac ctrl fwd flow control parameter",
6446         .tokens = {
6447                 (void *)&cmd_lfc_set_set,
6448                 (void *)&cmd_lfc_set_flow_ctrl,
6449                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6450                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6451                 (void *)&cmd_lfc_set_portid,
6452                 NULL,
6453         },
6454 };
6455
6456 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6457         .f = cmd_link_flow_ctrl_set_parsed,
6458         .data = (void *)&cmd_link_flow_control_set_autoneg,
6459         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6460                 "Change autoneg flow control parameter",
6461         .tokens = {
6462                 (void *)&cmd_lfc_set_set,
6463                 (void *)&cmd_lfc_set_flow_ctrl,
6464                 (void *)&cmd_lfc_set_autoneg_str,
6465                 (void *)&cmd_lfc_set_autoneg,
6466                 (void *)&cmd_lfc_set_portid,
6467                 NULL,
6468         },
6469 };
6470
6471 static void
6472 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6473                               __attribute__((unused)) struct cmdline *cl,
6474                               void *data)
6475 {
6476         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6477         cmdline_parse_inst_t *cmd = data;
6478         struct rte_eth_fc_conf fc_conf;
6479         int rx_fc_en = 0;
6480         int tx_fc_en = 0;
6481         int ret;
6482
6483         /*
6484          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6485          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6486          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6487          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6488          */
6489         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6490                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6491         };
6492
6493         /* Partial command line, retrieve current configuration */
6494         if (cmd) {
6495                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6496                 if (ret != 0) {
6497                         printf("cannot get current flow ctrl parameters, return"
6498                                "code = %d\n", ret);
6499                         return;
6500                 }
6501
6502                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6503                     (fc_conf.mode == RTE_FC_FULL))
6504                         rx_fc_en = 1;
6505                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6506                     (fc_conf.mode == RTE_FC_FULL))
6507                         tx_fc_en = 1;
6508         }
6509
6510         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6511                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6512
6513         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6514                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6515
6516         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6517
6518         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6519                 fc_conf.high_water = res->high_water;
6520
6521         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6522                 fc_conf.low_water = res->low_water;
6523
6524         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6525                 fc_conf.pause_time = res->pause_time;
6526
6527         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6528                 fc_conf.send_xon = res->send_xon;
6529
6530         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6531                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6532                         fc_conf.mac_ctrl_frame_fwd = 1;
6533                 else
6534                         fc_conf.mac_ctrl_frame_fwd = 0;
6535         }
6536
6537         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6538                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6539
6540         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6541         if (ret != 0)
6542                 printf("bad flow contrl parameter, return code = %d \n", ret);
6543 }
6544
6545 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6546 struct cmd_priority_flow_ctrl_set_result {
6547         cmdline_fixed_string_t set;
6548         cmdline_fixed_string_t pfc_ctrl;
6549         cmdline_fixed_string_t rx;
6550         cmdline_fixed_string_t rx_pfc_mode;
6551         cmdline_fixed_string_t tx;
6552         cmdline_fixed_string_t tx_pfc_mode;
6553         uint32_t high_water;
6554         uint32_t low_water;
6555         uint16_t pause_time;
6556         uint8_t  priority;
6557         portid_t port_id;
6558 };
6559
6560 static void
6561 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6562                        __attribute__((unused)) struct cmdline *cl,
6563                        __attribute__((unused)) void *data)
6564 {
6565         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6566         struct rte_eth_pfc_conf pfc_conf;
6567         int rx_fc_enable, tx_fc_enable;
6568         int ret;
6569
6570         /*
6571          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6572          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6573          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6574          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6575          */
6576         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6577                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6578         };
6579
6580         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6581         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6582         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6583         pfc_conf.fc.high_water = res->high_water;
6584         pfc_conf.fc.low_water  = res->low_water;
6585         pfc_conf.fc.pause_time = res->pause_time;
6586         pfc_conf.priority      = res->priority;
6587
6588         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6589         if (ret != 0)
6590                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6591 }
6592
6593 cmdline_parse_token_string_t cmd_pfc_set_set =
6594         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6595                                 set, "set");
6596 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6597         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6598                                 pfc_ctrl, "pfc_ctrl");
6599 cmdline_parse_token_string_t cmd_pfc_set_rx =
6600         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6601                                 rx, "rx");
6602 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6603         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6604                                 rx_pfc_mode, "on#off");
6605 cmdline_parse_token_string_t cmd_pfc_set_tx =
6606         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6607                                 tx, "tx");
6608 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6609         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6610                                 tx_pfc_mode, "on#off");
6611 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6612         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6613                                 high_water, UINT32);
6614 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6615         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6616                                 low_water, UINT32);
6617 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6618         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6619                                 pause_time, UINT16);
6620 cmdline_parse_token_num_t cmd_pfc_set_priority =
6621         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6622                                 priority, UINT8);
6623 cmdline_parse_token_num_t cmd_pfc_set_portid =
6624         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6625                                 port_id, UINT16);
6626
6627 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6628         .f = cmd_priority_flow_ctrl_set_parsed,
6629         .data = NULL,
6630         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6631                 "<pause_time> <priority> <port_id>: "
6632                 "Configure the Ethernet priority flow control",
6633         .tokens = {
6634                 (void *)&cmd_pfc_set_set,
6635                 (void *)&cmd_pfc_set_flow_ctrl,
6636                 (void *)&cmd_pfc_set_rx,
6637                 (void *)&cmd_pfc_set_rx_mode,
6638                 (void *)&cmd_pfc_set_tx,
6639                 (void *)&cmd_pfc_set_tx_mode,
6640                 (void *)&cmd_pfc_set_high_water,
6641                 (void *)&cmd_pfc_set_low_water,
6642                 (void *)&cmd_pfc_set_pause_time,
6643                 (void *)&cmd_pfc_set_priority,
6644                 (void *)&cmd_pfc_set_portid,
6645                 NULL,
6646         },
6647 };
6648
6649 /* *** RESET CONFIGURATION *** */
6650 struct cmd_reset_result {
6651         cmdline_fixed_string_t reset;
6652         cmdline_fixed_string_t def;
6653 };
6654
6655 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6656                              struct cmdline *cl,
6657                              __attribute__((unused)) void *data)
6658 {
6659         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6660         set_def_fwd_config();
6661 }
6662
6663 cmdline_parse_token_string_t cmd_reset_set =
6664         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6665 cmdline_parse_token_string_t cmd_reset_def =
6666         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6667                                  "default");
6668
6669 cmdline_parse_inst_t cmd_reset = {
6670         .f = cmd_reset_parsed,
6671         .data = NULL,
6672         .help_str = "set default: Reset default forwarding configuration",
6673         .tokens = {
6674                 (void *)&cmd_reset_set,
6675                 (void *)&cmd_reset_def,
6676                 NULL,
6677         },
6678 };
6679
6680 /* *** START FORWARDING *** */
6681 struct cmd_start_result {
6682         cmdline_fixed_string_t start;
6683 };
6684
6685 cmdline_parse_token_string_t cmd_start_start =
6686         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6687
6688 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6689                              __attribute__((unused)) struct cmdline *cl,
6690                              __attribute__((unused)) void *data)
6691 {
6692         start_packet_forwarding(0);
6693 }
6694
6695 cmdline_parse_inst_t cmd_start = {
6696         .f = cmd_start_parsed,
6697         .data = NULL,
6698         .help_str = "start: Start packet forwarding",
6699         .tokens = {
6700                 (void *)&cmd_start_start,
6701                 NULL,
6702         },
6703 };
6704
6705 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6706 struct cmd_start_tx_first_result {
6707         cmdline_fixed_string_t start;
6708         cmdline_fixed_string_t tx_first;
6709 };
6710
6711 static void
6712 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6713                           __attribute__((unused)) struct cmdline *cl,
6714                           __attribute__((unused)) void *data)
6715 {
6716         start_packet_forwarding(1);
6717 }
6718
6719 cmdline_parse_token_string_t cmd_start_tx_first_start =
6720         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6721                                  "start");
6722 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6723         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6724                                  tx_first, "tx_first");
6725
6726 cmdline_parse_inst_t cmd_start_tx_first = {
6727         .f = cmd_start_tx_first_parsed,
6728         .data = NULL,
6729         .help_str = "start tx_first: Start packet forwarding, "
6730                 "after sending 1 burst of packets",
6731         .tokens = {
6732                 (void *)&cmd_start_tx_first_start,
6733                 (void *)&cmd_start_tx_first_tx_first,
6734                 NULL,
6735         },
6736 };
6737
6738 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6739 struct cmd_start_tx_first_n_result {
6740         cmdline_fixed_string_t start;
6741         cmdline_fixed_string_t tx_first;
6742         uint32_t tx_num;
6743 };
6744
6745 static void
6746 cmd_start_tx_first_n_parsed(void *parsed_result,
6747                           __attribute__((unused)) struct cmdline *cl,
6748                           __attribute__((unused)) void *data)
6749 {
6750         struct cmd_start_tx_first_n_result *res = parsed_result;
6751
6752         start_packet_forwarding(res->tx_num);
6753 }
6754
6755 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6756         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6757                         start, "start");
6758 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6759         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6760                         tx_first, "tx_first");
6761 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6762         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6763                         tx_num, UINT32);
6764
6765 cmdline_parse_inst_t cmd_start_tx_first_n = {
6766         .f = cmd_start_tx_first_n_parsed,
6767         .data = NULL,
6768         .help_str = "start tx_first <num>: "
6769                 "packet forwarding, after sending <num> bursts of packets",
6770         .tokens = {
6771                 (void *)&cmd_start_tx_first_n_start,
6772                 (void *)&cmd_start_tx_first_n_tx_first,
6773                 (void *)&cmd_start_tx_first_n_tx_num,
6774                 NULL,
6775         },
6776 };
6777
6778 /* *** SET LINK UP *** */
6779 struct cmd_set_link_up_result {
6780         cmdline_fixed_string_t set;
6781         cmdline_fixed_string_t link_up;
6782         cmdline_fixed_string_t port;
6783         portid_t port_id;
6784 };
6785
6786 cmdline_parse_token_string_t cmd_set_link_up_set =
6787         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6788 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6789         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6790                                 "link-up");
6791 cmdline_parse_token_string_t cmd_set_link_up_port =
6792         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6793 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6794         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6795
6796 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6797                              __attribute__((unused)) struct cmdline *cl,
6798                              __attribute__((unused)) void *data)
6799 {
6800         struct cmd_set_link_up_result *res = parsed_result;
6801         dev_set_link_up(res->port_id);
6802 }
6803
6804 cmdline_parse_inst_t cmd_set_link_up = {
6805         .f = cmd_set_link_up_parsed,
6806         .data = NULL,
6807         .help_str = "set link-up port <port id>",
6808         .tokens = {
6809                 (void *)&cmd_set_link_up_set,
6810                 (void *)&cmd_set_link_up_link_up,
6811                 (void *)&cmd_set_link_up_port,
6812                 (void *)&cmd_set_link_up_port_id,
6813                 NULL,
6814         },
6815 };
6816
6817 /* *** SET LINK DOWN *** */
6818 struct cmd_set_link_down_result {
6819         cmdline_fixed_string_t set;
6820         cmdline_fixed_string_t link_down;
6821         cmdline_fixed_string_t port;
6822         portid_t port_id;
6823 };
6824
6825 cmdline_parse_token_string_t cmd_set_link_down_set =
6826         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6827 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6828         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6829                                 "link-down");
6830 cmdline_parse_token_string_t cmd_set_link_down_port =
6831         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6832 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6833         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6834
6835 static void cmd_set_link_down_parsed(
6836                                 __attribute__((unused)) void *parsed_result,
6837                                 __attribute__((unused)) struct cmdline *cl,
6838                                 __attribute__((unused)) void *data)
6839 {
6840         struct cmd_set_link_down_result *res = parsed_result;
6841         dev_set_link_down(res->port_id);
6842 }
6843
6844 cmdline_parse_inst_t cmd_set_link_down = {
6845         .f = cmd_set_link_down_parsed,
6846         .data = NULL,
6847         .help_str = "set link-down port <port id>",
6848         .tokens = {
6849                 (void *)&cmd_set_link_down_set,
6850                 (void *)&cmd_set_link_down_link_down,
6851                 (void *)&cmd_set_link_down_port,
6852                 (void *)&cmd_set_link_down_port_id,
6853                 NULL,
6854         },
6855 };
6856
6857 /* *** SHOW CFG *** */
6858 struct cmd_showcfg_result {
6859         cmdline_fixed_string_t show;
6860         cmdline_fixed_string_t cfg;
6861         cmdline_fixed_string_t what;
6862 };
6863
6864 static void cmd_showcfg_parsed(void *parsed_result,
6865                                __attribute__((unused)) struct cmdline *cl,
6866                                __attribute__((unused)) void *data)
6867 {
6868         struct cmd_showcfg_result *res = parsed_result;
6869         if (!strcmp(res->what, "rxtx"))
6870                 rxtx_config_display();
6871         else if (!strcmp(res->what, "cores"))
6872                 fwd_lcores_config_display();
6873         else if (!strcmp(res->what, "fwd"))
6874                 pkt_fwd_config_display(&cur_fwd_config);
6875         else if (!strcmp(res->what, "txpkts"))
6876                 show_tx_pkt_segments();
6877 }
6878
6879 cmdline_parse_token_string_t cmd_showcfg_show =
6880         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6881 cmdline_parse_token_string_t cmd_showcfg_port =
6882         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6883 cmdline_parse_token_string_t cmd_showcfg_what =
6884         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6885                                  "rxtx#cores#fwd#txpkts");
6886
6887 cmdline_parse_inst_t cmd_showcfg = {
6888         .f = cmd_showcfg_parsed,
6889         .data = NULL,
6890         .help_str = "show config rxtx|cores|fwd|txpkts",
6891         .tokens = {
6892                 (void *)&cmd_showcfg_show,
6893                 (void *)&cmd_showcfg_port,
6894                 (void *)&cmd_showcfg_what,
6895                 NULL,
6896         },
6897 };
6898
6899 /* *** SHOW ALL PORT INFO *** */
6900 struct cmd_showportall_result {
6901         cmdline_fixed_string_t show;
6902         cmdline_fixed_string_t port;
6903         cmdline_fixed_string_t what;
6904         cmdline_fixed_string_t all;
6905 };
6906
6907 static void cmd_showportall_parsed(void *parsed_result,
6908                                 __attribute__((unused)) struct cmdline *cl,
6909                                 __attribute__((unused)) void *data)
6910 {
6911         portid_t i;
6912
6913         struct cmd_showportall_result *res = parsed_result;
6914         if (!strcmp(res->show, "clear")) {
6915                 if (!strcmp(res->what, "stats"))
6916                         RTE_ETH_FOREACH_DEV(i)
6917                                 nic_stats_clear(i);
6918                 else if (!strcmp(res->what, "xstats"))
6919                         RTE_ETH_FOREACH_DEV(i)
6920                                 nic_xstats_clear(i);
6921         } else if (!strcmp(res->what, "info"))
6922                 RTE_ETH_FOREACH_DEV(i)
6923                         port_infos_display(i);
6924         else if (!strcmp(res->what, "stats"))
6925                 RTE_ETH_FOREACH_DEV(i)
6926                         nic_stats_display(i);
6927         else if (!strcmp(res->what, "xstats"))
6928                 RTE_ETH_FOREACH_DEV(i)
6929                         nic_xstats_display(i);
6930         else if (!strcmp(res->what, "fdir"))
6931                 RTE_ETH_FOREACH_DEV(i)
6932                         fdir_get_infos(i);
6933         else if (!strcmp(res->what, "stat_qmap"))
6934                 RTE_ETH_FOREACH_DEV(i)
6935                         nic_stats_mapping_display(i);
6936         else if (!strcmp(res->what, "dcb_tc"))
6937                 RTE_ETH_FOREACH_DEV(i)
6938                         port_dcb_info_display(i);
6939         else if (!strcmp(res->what, "cap"))
6940                 RTE_ETH_FOREACH_DEV(i)
6941                         port_offload_cap_display(i);
6942 }
6943
6944 cmdline_parse_token_string_t cmd_showportall_show =
6945         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6946                                  "show#clear");
6947 cmdline_parse_token_string_t cmd_showportall_port =
6948         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6949 cmdline_parse_token_string_t cmd_showportall_what =
6950         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6951                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6952 cmdline_parse_token_string_t cmd_showportall_all =
6953         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6954 cmdline_parse_inst_t cmd_showportall = {
6955         .f = cmd_showportall_parsed,
6956         .data = NULL,
6957         .help_str = "show|clear port "
6958                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6959         .tokens = {
6960                 (void *)&cmd_showportall_show,
6961                 (void *)&cmd_showportall_port,
6962                 (void *)&cmd_showportall_what,
6963                 (void *)&cmd_showportall_all,
6964                 NULL,
6965         },
6966 };
6967
6968 /* *** SHOW PORT INFO *** */
6969 struct cmd_showport_result {
6970         cmdline_fixed_string_t show;
6971         cmdline_fixed_string_t port;
6972         cmdline_fixed_string_t what;
6973         uint16_t portnum;
6974 };
6975
6976 static void cmd_showport_parsed(void *parsed_result,
6977                                 __attribute__((unused)) struct cmdline *cl,
6978                                 __attribute__((unused)) void *data)
6979 {
6980         struct cmd_showport_result *res = parsed_result;
6981         if (!strcmp(res->show, "clear")) {
6982                 if (!strcmp(res->what, "stats"))
6983                         nic_stats_clear(res->portnum);
6984                 else if (!strcmp(res->what, "xstats"))
6985                         nic_xstats_clear(res->portnum);
6986         } else if (!strcmp(res->what, "info"))
6987                 port_infos_display(res->portnum);
6988         else if (!strcmp(res->what, "stats"))
6989                 nic_stats_display(res->portnum);
6990         else if (!strcmp(res->what, "xstats"))
6991                 nic_xstats_display(res->portnum);
6992         else if (!strcmp(res->what, "fdir"))
6993                  fdir_get_infos(res->portnum);
6994         else if (!strcmp(res->what, "stat_qmap"))
6995                 nic_stats_mapping_display(res->portnum);
6996         else if (!strcmp(res->what, "dcb_tc"))
6997                 port_dcb_info_display(res->portnum);
6998         else if (!strcmp(res->what, "cap"))
6999                 port_offload_cap_display(res->portnum);
7000 }
7001
7002 cmdline_parse_token_string_t cmd_showport_show =
7003         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7004                                  "show#clear");
7005 cmdline_parse_token_string_t cmd_showport_port =
7006         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7007 cmdline_parse_token_string_t cmd_showport_what =
7008         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7009                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7010 cmdline_parse_token_num_t cmd_showport_portnum =
7011         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7012
7013 cmdline_parse_inst_t cmd_showport = {
7014         .f = cmd_showport_parsed,
7015         .data = NULL,
7016         .help_str = "show|clear port "
7017                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7018                 "<port_id>",
7019         .tokens = {
7020                 (void *)&cmd_showport_show,
7021                 (void *)&cmd_showport_port,
7022                 (void *)&cmd_showport_what,
7023                 (void *)&cmd_showport_portnum,
7024                 NULL,
7025         },
7026 };
7027
7028 /* *** SHOW QUEUE INFO *** */
7029 struct cmd_showqueue_result {
7030         cmdline_fixed_string_t show;
7031         cmdline_fixed_string_t type;
7032         cmdline_fixed_string_t what;
7033         uint16_t portnum;
7034         uint16_t queuenum;
7035 };
7036
7037 static void
7038 cmd_showqueue_parsed(void *parsed_result,
7039         __attribute__((unused)) struct cmdline *cl,
7040         __attribute__((unused)) void *data)
7041 {
7042         struct cmd_showqueue_result *res = parsed_result;
7043
7044         if (!strcmp(res->type, "rxq"))
7045                 rx_queue_infos_display(res->portnum, res->queuenum);
7046         else if (!strcmp(res->type, "txq"))
7047                 tx_queue_infos_display(res->portnum, res->queuenum);
7048 }
7049
7050 cmdline_parse_token_string_t cmd_showqueue_show =
7051         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7052 cmdline_parse_token_string_t cmd_showqueue_type =
7053         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7054 cmdline_parse_token_string_t cmd_showqueue_what =
7055         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7056 cmdline_parse_token_num_t cmd_showqueue_portnum =
7057         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7058 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7059         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7060
7061 cmdline_parse_inst_t cmd_showqueue = {
7062         .f = cmd_showqueue_parsed,
7063         .data = NULL,
7064         .help_str = "show rxq|txq info <port_id> <queue_id>",
7065         .tokens = {
7066                 (void *)&cmd_showqueue_show,
7067                 (void *)&cmd_showqueue_type,
7068                 (void *)&cmd_showqueue_what,
7069                 (void *)&cmd_showqueue_portnum,
7070                 (void *)&cmd_showqueue_queuenum,
7071                 NULL,
7072         },
7073 };
7074
7075 /* *** READ PORT REGISTER *** */
7076 struct cmd_read_reg_result {
7077         cmdline_fixed_string_t read;
7078         cmdline_fixed_string_t reg;
7079         portid_t port_id;
7080         uint32_t reg_off;
7081 };
7082
7083 static void
7084 cmd_read_reg_parsed(void *parsed_result,
7085                     __attribute__((unused)) struct cmdline *cl,
7086                     __attribute__((unused)) void *data)
7087 {
7088         struct cmd_read_reg_result *res = parsed_result;
7089         port_reg_display(res->port_id, res->reg_off);
7090 }
7091
7092 cmdline_parse_token_string_t cmd_read_reg_read =
7093         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7094 cmdline_parse_token_string_t cmd_read_reg_reg =
7095         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7096 cmdline_parse_token_num_t cmd_read_reg_port_id =
7097         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7098 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7099         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7100
7101 cmdline_parse_inst_t cmd_read_reg = {
7102         .f = cmd_read_reg_parsed,
7103         .data = NULL,
7104         .help_str = "read reg <port_id> <reg_off>",
7105         .tokens = {
7106                 (void *)&cmd_read_reg_read,
7107                 (void *)&cmd_read_reg_reg,
7108                 (void *)&cmd_read_reg_port_id,
7109                 (void *)&cmd_read_reg_reg_off,
7110                 NULL,
7111         },
7112 };
7113
7114 /* *** READ PORT REGISTER BIT FIELD *** */
7115 struct cmd_read_reg_bit_field_result {
7116         cmdline_fixed_string_t read;
7117         cmdline_fixed_string_t regfield;
7118         portid_t port_id;
7119         uint32_t reg_off;
7120         uint8_t bit1_pos;
7121         uint8_t bit2_pos;
7122 };
7123
7124 static void
7125 cmd_read_reg_bit_field_parsed(void *parsed_result,
7126                               __attribute__((unused)) struct cmdline *cl,
7127                               __attribute__((unused)) void *data)
7128 {
7129         struct cmd_read_reg_bit_field_result *res = parsed_result;
7130         port_reg_bit_field_display(res->port_id, res->reg_off,
7131                                    res->bit1_pos, res->bit2_pos);
7132 }
7133
7134 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7135         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7136                                  "read");
7137 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7138         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7139                                  regfield, "regfield");
7140 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7141         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7142                               UINT16);
7143 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7144         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7145                               UINT32);
7146 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7147         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7148                               UINT8);
7149 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7150         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7151                               UINT8);
7152
7153 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7154         .f = cmd_read_reg_bit_field_parsed,
7155         .data = NULL,
7156         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7157         "Read register bit field between bit_x and bit_y included",
7158         .tokens = {
7159                 (void *)&cmd_read_reg_bit_field_read,
7160                 (void *)&cmd_read_reg_bit_field_regfield,
7161                 (void *)&cmd_read_reg_bit_field_port_id,
7162                 (void *)&cmd_read_reg_bit_field_reg_off,
7163                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7164                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7165                 NULL,
7166         },
7167 };
7168
7169 /* *** READ PORT REGISTER BIT *** */
7170 struct cmd_read_reg_bit_result {
7171         cmdline_fixed_string_t read;
7172         cmdline_fixed_string_t regbit;
7173         portid_t port_id;
7174         uint32_t reg_off;
7175         uint8_t bit_pos;
7176 };
7177
7178 static void
7179 cmd_read_reg_bit_parsed(void *parsed_result,
7180                         __attribute__((unused)) struct cmdline *cl,
7181                         __attribute__((unused)) void *data)
7182 {
7183         struct cmd_read_reg_bit_result *res = parsed_result;
7184         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7185 }
7186
7187 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7188         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7189 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7190         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7191                                  regbit, "regbit");
7192 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7193         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7194 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7195         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7196 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7197         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7198
7199 cmdline_parse_inst_t cmd_read_reg_bit = {
7200         .f = cmd_read_reg_bit_parsed,
7201         .data = NULL,
7202         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7203         .tokens = {
7204                 (void *)&cmd_read_reg_bit_read,
7205                 (void *)&cmd_read_reg_bit_regbit,
7206                 (void *)&cmd_read_reg_bit_port_id,
7207                 (void *)&cmd_read_reg_bit_reg_off,
7208                 (void *)&cmd_read_reg_bit_bit_pos,
7209                 NULL,
7210         },
7211 };
7212
7213 /* *** WRITE PORT REGISTER *** */
7214 struct cmd_write_reg_result {
7215         cmdline_fixed_string_t write;
7216         cmdline_fixed_string_t reg;
7217         portid_t port_id;
7218         uint32_t reg_off;
7219         uint32_t value;
7220 };
7221
7222 static void
7223 cmd_write_reg_parsed(void *parsed_result,
7224                      __attribute__((unused)) struct cmdline *cl,
7225                      __attribute__((unused)) void *data)
7226 {
7227         struct cmd_write_reg_result *res = parsed_result;
7228         port_reg_set(res->port_id, res->reg_off, res->value);
7229 }
7230
7231 cmdline_parse_token_string_t cmd_write_reg_write =
7232         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7233 cmdline_parse_token_string_t cmd_write_reg_reg =
7234         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7235 cmdline_parse_token_num_t cmd_write_reg_port_id =
7236         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7237 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7238         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7239 cmdline_parse_token_num_t cmd_write_reg_value =
7240         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7241
7242 cmdline_parse_inst_t cmd_write_reg = {
7243         .f = cmd_write_reg_parsed,
7244         .data = NULL,
7245         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7246         .tokens = {
7247                 (void *)&cmd_write_reg_write,
7248                 (void *)&cmd_write_reg_reg,
7249                 (void *)&cmd_write_reg_port_id,
7250                 (void *)&cmd_write_reg_reg_off,
7251                 (void *)&cmd_write_reg_value,
7252                 NULL,
7253         },
7254 };
7255
7256 /* *** WRITE PORT REGISTER BIT FIELD *** */
7257 struct cmd_write_reg_bit_field_result {
7258         cmdline_fixed_string_t write;
7259         cmdline_fixed_string_t regfield;
7260         portid_t port_id;
7261         uint32_t reg_off;
7262         uint8_t bit1_pos;
7263         uint8_t bit2_pos;
7264         uint32_t value;
7265 };
7266
7267 static void
7268 cmd_write_reg_bit_field_parsed(void *parsed_result,
7269                                __attribute__((unused)) struct cmdline *cl,
7270                                __attribute__((unused)) void *data)
7271 {
7272         struct cmd_write_reg_bit_field_result *res = parsed_result;
7273         port_reg_bit_field_set(res->port_id, res->reg_off,
7274                           res->bit1_pos, res->bit2_pos, res->value);
7275 }
7276
7277 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7278         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7279                                  "write");
7280 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7281         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7282                                  regfield, "regfield");
7283 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7284         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7285                               UINT16);
7286 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7287         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7288                               UINT32);
7289 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7290         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7291                               UINT8);
7292 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7293         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7294                               UINT8);
7295 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7296         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7297                               UINT32);
7298
7299 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7300         .f = cmd_write_reg_bit_field_parsed,
7301         .data = NULL,
7302         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7303                 "<reg_value>: "
7304                 "Set register bit field between bit_x and bit_y included",
7305         .tokens = {
7306                 (void *)&cmd_write_reg_bit_field_write,
7307                 (void *)&cmd_write_reg_bit_field_regfield,
7308                 (void *)&cmd_write_reg_bit_field_port_id,
7309                 (void *)&cmd_write_reg_bit_field_reg_off,
7310                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7311                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7312                 (void *)&cmd_write_reg_bit_field_value,
7313                 NULL,
7314         },
7315 };
7316
7317 /* *** WRITE PORT REGISTER BIT *** */
7318 struct cmd_write_reg_bit_result {
7319         cmdline_fixed_string_t write;
7320         cmdline_fixed_string_t regbit;
7321         portid_t port_id;
7322         uint32_t reg_off;
7323         uint8_t bit_pos;
7324         uint8_t value;
7325 };
7326
7327 static void
7328 cmd_write_reg_bit_parsed(void *parsed_result,
7329                          __attribute__((unused)) struct cmdline *cl,
7330                          __attribute__((unused)) void *data)
7331 {
7332         struct cmd_write_reg_bit_result *res = parsed_result;
7333         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7334 }
7335
7336 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7337         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7338                                  "write");
7339 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7340         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7341                                  regbit, "regbit");
7342 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7343         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7344 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7345         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7346 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7347         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7348 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7349         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7350
7351 cmdline_parse_inst_t cmd_write_reg_bit = {
7352         .f = cmd_write_reg_bit_parsed,
7353         .data = NULL,
7354         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7355                 "0 <= bit_x <= 31",
7356         .tokens = {
7357                 (void *)&cmd_write_reg_bit_write,
7358                 (void *)&cmd_write_reg_bit_regbit,
7359                 (void *)&cmd_write_reg_bit_port_id,
7360                 (void *)&cmd_write_reg_bit_reg_off,
7361                 (void *)&cmd_write_reg_bit_bit_pos,
7362                 (void *)&cmd_write_reg_bit_value,
7363                 NULL,
7364         },
7365 };
7366
7367 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7368 struct cmd_read_rxd_txd_result {
7369         cmdline_fixed_string_t read;
7370         cmdline_fixed_string_t rxd_txd;
7371         portid_t port_id;
7372         uint16_t queue_id;
7373         uint16_t desc_id;
7374 };
7375
7376 static void
7377 cmd_read_rxd_txd_parsed(void *parsed_result,
7378                         __attribute__((unused)) struct cmdline *cl,
7379                         __attribute__((unused)) void *data)
7380 {
7381         struct cmd_read_rxd_txd_result *res = parsed_result;
7382
7383         if (!strcmp(res->rxd_txd, "rxd"))
7384                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7385         else if (!strcmp(res->rxd_txd, "txd"))
7386                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7387 }
7388
7389 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7390         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7391 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7392         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7393                                  "rxd#txd");
7394 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7395         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7396 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7397         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7398 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7399         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7400
7401 cmdline_parse_inst_t cmd_read_rxd_txd = {
7402         .f = cmd_read_rxd_txd_parsed,
7403         .data = NULL,
7404         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7405         .tokens = {
7406                 (void *)&cmd_read_rxd_txd_read,
7407                 (void *)&cmd_read_rxd_txd_rxd_txd,
7408                 (void *)&cmd_read_rxd_txd_port_id,
7409                 (void *)&cmd_read_rxd_txd_queue_id,
7410                 (void *)&cmd_read_rxd_txd_desc_id,
7411                 NULL,
7412         },
7413 };
7414
7415 /* *** QUIT *** */
7416 struct cmd_quit_result {
7417         cmdline_fixed_string_t quit;
7418 };
7419
7420 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7421                             struct cmdline *cl,
7422                             __attribute__((unused)) void *data)
7423 {
7424         pmd_test_exit();
7425         cmdline_quit(cl);
7426 }
7427
7428 cmdline_parse_token_string_t cmd_quit_quit =
7429         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7430
7431 cmdline_parse_inst_t cmd_quit = {
7432         .f = cmd_quit_parsed,
7433         .data = NULL,
7434         .help_str = "quit: Exit application",
7435         .tokens = {
7436                 (void *)&cmd_quit_quit,
7437                 NULL,
7438         },
7439 };
7440
7441 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7442 struct cmd_mac_addr_result {
7443         cmdline_fixed_string_t mac_addr_cmd;
7444         cmdline_fixed_string_t what;
7445         uint16_t port_num;
7446         struct ether_addr address;
7447 };
7448
7449 static void cmd_mac_addr_parsed(void *parsed_result,
7450                 __attribute__((unused)) struct cmdline *cl,
7451                 __attribute__((unused)) void *data)
7452 {
7453         struct cmd_mac_addr_result *res = parsed_result;
7454         int ret;
7455
7456         if (strcmp(res->what, "add") == 0)
7457                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7458         else if (strcmp(res->what, "set") == 0)
7459                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7460                                                        &res->address);
7461         else
7462                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7463
7464         /* check the return value and print it if is < 0 */
7465         if(ret < 0)
7466                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7467
7468 }
7469
7470 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7471         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7472                                 "mac_addr");
7473 cmdline_parse_token_string_t cmd_mac_addr_what =
7474         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7475                                 "add#remove#set");
7476 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7477                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7478                                         UINT16);
7479 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7480                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7481
7482 cmdline_parse_inst_t cmd_mac_addr = {
7483         .f = cmd_mac_addr_parsed,
7484         .data = (void *)0,
7485         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7486                         "Add/Remove/Set MAC address on port_id",
7487         .tokens = {
7488                 (void *)&cmd_mac_addr_cmd,
7489                 (void *)&cmd_mac_addr_what,
7490                 (void *)&cmd_mac_addr_portnum,
7491                 (void *)&cmd_mac_addr_addr,
7492                 NULL,
7493         },
7494 };
7495
7496 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7497 struct cmd_eth_peer_result {
7498         cmdline_fixed_string_t set;
7499         cmdline_fixed_string_t eth_peer;
7500         portid_t port_id;
7501         cmdline_fixed_string_t peer_addr;
7502 };
7503
7504 static void cmd_set_eth_peer_parsed(void *parsed_result,
7505                         __attribute__((unused)) struct cmdline *cl,
7506                         __attribute__((unused)) void *data)
7507 {
7508                 struct cmd_eth_peer_result *res = parsed_result;
7509
7510                 if (test_done == 0) {
7511                         printf("Please stop forwarding first\n");
7512                         return;
7513                 }
7514                 if (!strcmp(res->eth_peer, "eth-peer")) {
7515                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7516                         fwd_config_setup();
7517                 }
7518 }
7519 cmdline_parse_token_string_t cmd_eth_peer_set =
7520         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7521 cmdline_parse_token_string_t cmd_eth_peer =
7522         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7523 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7524         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7525 cmdline_parse_token_string_t cmd_eth_peer_addr =
7526         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7527
7528 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7529         .f = cmd_set_eth_peer_parsed,
7530         .data = NULL,
7531         .help_str = "set eth-peer <port_id> <peer_mac>",
7532         .tokens = {
7533                 (void *)&cmd_eth_peer_set,
7534                 (void *)&cmd_eth_peer,
7535                 (void *)&cmd_eth_peer_port_id,
7536                 (void *)&cmd_eth_peer_addr,
7537                 NULL,
7538         },
7539 };
7540
7541 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7542 struct cmd_set_qmap_result {
7543         cmdline_fixed_string_t set;
7544         cmdline_fixed_string_t qmap;
7545         cmdline_fixed_string_t what;
7546         portid_t port_id;
7547         uint16_t queue_id;
7548         uint8_t map_value;
7549 };
7550
7551 static void
7552 cmd_set_qmap_parsed(void *parsed_result,
7553                        __attribute__((unused)) struct cmdline *cl,
7554                        __attribute__((unused)) void *data)
7555 {
7556         struct cmd_set_qmap_result *res = parsed_result;
7557         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7558
7559         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7560 }
7561
7562 cmdline_parse_token_string_t cmd_setqmap_set =
7563         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7564                                  set, "set");
7565 cmdline_parse_token_string_t cmd_setqmap_qmap =
7566         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7567                                  qmap, "stat_qmap");
7568 cmdline_parse_token_string_t cmd_setqmap_what =
7569         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7570                                  what, "tx#rx");
7571 cmdline_parse_token_num_t cmd_setqmap_portid =
7572         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7573                               port_id, UINT16);
7574 cmdline_parse_token_num_t cmd_setqmap_queueid =
7575         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7576                               queue_id, UINT16);
7577 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7578         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7579                               map_value, UINT8);
7580
7581 cmdline_parse_inst_t cmd_set_qmap = {
7582         .f = cmd_set_qmap_parsed,
7583         .data = NULL,
7584         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7585                 "Set statistics mapping value on tx|rx queue_id of port_id",
7586         .tokens = {
7587                 (void *)&cmd_setqmap_set,
7588                 (void *)&cmd_setqmap_qmap,
7589                 (void *)&cmd_setqmap_what,
7590                 (void *)&cmd_setqmap_portid,
7591                 (void *)&cmd_setqmap_queueid,
7592                 (void *)&cmd_setqmap_mapvalue,
7593                 NULL,
7594         },
7595 };
7596
7597 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7598 struct cmd_set_xstats_hide_zero_result {
7599         cmdline_fixed_string_t keyword;
7600         cmdline_fixed_string_t name;
7601         cmdline_fixed_string_t on_off;
7602 };
7603
7604 static void
7605 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7606                         __attribute__((unused)) struct cmdline *cl,
7607                         __attribute__((unused)) void *data)
7608 {
7609         struct cmd_set_xstats_hide_zero_result *res;
7610         uint16_t on_off = 0;
7611
7612         res = parsed_result;
7613         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7614         set_xstats_hide_zero(on_off);
7615 }
7616
7617 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7618         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7619                                  keyword, "set");
7620 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7621         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7622                                  name, "xstats-hide-zero");
7623 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7624         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7625                                  on_off, "on#off");
7626
7627 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7628         .f = cmd_set_xstats_hide_zero_parsed,
7629         .data = NULL,
7630         .help_str = "set xstats-hide-zero on|off",
7631         .tokens = {
7632                 (void *)&cmd_set_xstats_hide_zero_keyword,
7633                 (void *)&cmd_set_xstats_hide_zero_name,
7634                 (void *)&cmd_set_xstats_hide_zero_on_off,
7635                 NULL,
7636         },
7637 };
7638
7639 /* *** CONFIGURE UNICAST HASH TABLE *** */
7640 struct cmd_set_uc_hash_table {
7641         cmdline_fixed_string_t set;
7642         cmdline_fixed_string_t port;
7643         portid_t port_id;
7644         cmdline_fixed_string_t what;
7645         struct ether_addr address;
7646         cmdline_fixed_string_t mode;
7647 };
7648
7649 static void
7650 cmd_set_uc_hash_parsed(void *parsed_result,
7651                        __attribute__((unused)) struct cmdline *cl,
7652                        __attribute__((unused)) void *data)
7653 {
7654         int ret=0;
7655         struct cmd_set_uc_hash_table *res = parsed_result;
7656
7657         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7658
7659         if (strcmp(res->what, "uta") == 0)
7660                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7661                                                 &res->address,(uint8_t)is_on);
7662         if (ret < 0)
7663                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7664
7665 }
7666
7667 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7668         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7669                                  set, "set");
7670 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7671         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7672                                  port, "port");
7673 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7674         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7675                               port_id, UINT16);
7676 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7677         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7678                                  what, "uta");
7679 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7680         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7681                                 address);
7682 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7683         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7684                                  mode, "on#off");
7685
7686 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7687         .f = cmd_set_uc_hash_parsed,
7688         .data = NULL,
7689         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7690         .tokens = {
7691                 (void *)&cmd_set_uc_hash_set,
7692                 (void *)&cmd_set_uc_hash_port,
7693                 (void *)&cmd_set_uc_hash_portid,
7694                 (void *)&cmd_set_uc_hash_what,
7695                 (void *)&cmd_set_uc_hash_mac,
7696                 (void *)&cmd_set_uc_hash_mode,
7697                 NULL,
7698         },
7699 };
7700
7701 struct cmd_set_uc_all_hash_table {
7702         cmdline_fixed_string_t set;
7703         cmdline_fixed_string_t port;
7704         portid_t port_id;
7705         cmdline_fixed_string_t what;
7706         cmdline_fixed_string_t value;
7707         cmdline_fixed_string_t mode;
7708 };
7709
7710 static void
7711 cmd_set_uc_all_hash_parsed(void *parsed_result,
7712                        __attribute__((unused)) struct cmdline *cl,
7713                        __attribute__((unused)) void *data)
7714 {
7715         int ret=0;
7716         struct cmd_set_uc_all_hash_table *res = parsed_result;
7717
7718         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7719
7720         if ((strcmp(res->what, "uta") == 0) &&
7721                 (strcmp(res->value, "all") == 0))
7722                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7723         if (ret < 0)
7724                 printf("bad unicast hash table parameter,"
7725                         "return code = %d \n", ret);
7726 }
7727
7728 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7729         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7730                                  set, "set");
7731 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7732         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7733                                  port, "port");
7734 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7735         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7736                               port_id, UINT16);
7737 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7738         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7739                                  what, "uta");
7740 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7741         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7742                                 value,"all");
7743 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7744         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7745                                  mode, "on#off");
7746
7747 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7748         .f = cmd_set_uc_all_hash_parsed,
7749         .data = NULL,
7750         .help_str = "set port <port_id> uta all on|off",
7751         .tokens = {
7752                 (void *)&cmd_set_uc_all_hash_set,
7753                 (void *)&cmd_set_uc_all_hash_port,
7754                 (void *)&cmd_set_uc_all_hash_portid,
7755                 (void *)&cmd_set_uc_all_hash_what,
7756                 (void *)&cmd_set_uc_all_hash_value,
7757                 (void *)&cmd_set_uc_all_hash_mode,
7758                 NULL,
7759         },
7760 };
7761
7762 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7763 struct cmd_set_vf_macvlan_filter {
7764         cmdline_fixed_string_t set;
7765         cmdline_fixed_string_t port;
7766         portid_t port_id;
7767         cmdline_fixed_string_t vf;
7768         uint8_t vf_id;
7769         struct ether_addr address;
7770         cmdline_fixed_string_t filter_type;
7771         cmdline_fixed_string_t mode;
7772 };
7773
7774 static void
7775 cmd_set_vf_macvlan_parsed(void *parsed_result,
7776                        __attribute__((unused)) struct cmdline *cl,
7777                        __attribute__((unused)) void *data)
7778 {
7779         int is_on, ret = 0;
7780         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7781         struct rte_eth_mac_filter filter;
7782
7783         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7784
7785         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7786
7787         /* set VF MAC filter */
7788         filter.is_vf = 1;
7789
7790         /* set VF ID */
7791         filter.dst_id = res->vf_id;
7792
7793         if (!strcmp(res->filter_type, "exact-mac"))
7794                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7795         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7796                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7797         else if (!strcmp(res->filter_type, "hashmac"))
7798                 filter.filter_type = RTE_MAC_HASH_MATCH;
7799         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7800                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7801
7802         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7803
7804         if (is_on)
7805                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7806                                         RTE_ETH_FILTER_MACVLAN,
7807                                         RTE_ETH_FILTER_ADD,
7808                                          &filter);
7809         else
7810                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7811                                         RTE_ETH_FILTER_MACVLAN,
7812                                         RTE_ETH_FILTER_DELETE,
7813                                         &filter);
7814
7815         if (ret < 0)
7816                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7817
7818 }
7819
7820 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7821         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7822                                  set, "set");
7823 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7824         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7825                                  port, "port");
7826 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7827         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7828                               port_id, UINT16);
7829 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7830         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7831                                  vf, "vf");
7832 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7833         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7834                                 vf_id, UINT8);
7835 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7836         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7837                                 address);
7838 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7839         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7840                                 filter_type, "exact-mac#exact-mac-vlan"
7841                                 "#hashmac#hashmac-vlan");
7842 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7843         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7844                                  mode, "on#off");
7845
7846 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7847         .f = cmd_set_vf_macvlan_parsed,
7848         .data = NULL,
7849         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7850                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7851                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7852                 "hash match rule: hash match of MAC and exact match of VLAN",
7853         .tokens = {
7854                 (void *)&cmd_set_vf_macvlan_set,
7855                 (void *)&cmd_set_vf_macvlan_port,
7856                 (void *)&cmd_set_vf_macvlan_portid,
7857                 (void *)&cmd_set_vf_macvlan_vf,
7858                 (void *)&cmd_set_vf_macvlan_vf_id,
7859                 (void *)&cmd_set_vf_macvlan_mac,
7860                 (void *)&cmd_set_vf_macvlan_filter_type,
7861                 (void *)&cmd_set_vf_macvlan_mode,
7862                 NULL,
7863         },
7864 };
7865
7866 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7867 struct cmd_set_vf_traffic {
7868         cmdline_fixed_string_t set;
7869         cmdline_fixed_string_t port;
7870         portid_t port_id;
7871         cmdline_fixed_string_t vf;
7872         uint8_t vf_id;
7873         cmdline_fixed_string_t what;
7874         cmdline_fixed_string_t mode;
7875 };
7876
7877 static void
7878 cmd_set_vf_traffic_parsed(void *parsed_result,
7879                        __attribute__((unused)) struct cmdline *cl,
7880                        __attribute__((unused)) void *data)
7881 {
7882         struct cmd_set_vf_traffic *res = parsed_result;
7883         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7884         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7885
7886         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7887 }
7888
7889 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7890         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7891                                  set, "set");
7892 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7893         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7894                                  port, "port");
7895 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7896         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7897                               port_id, UINT16);
7898 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7899         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7900                                  vf, "vf");
7901 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7902         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7903                               vf_id, UINT8);
7904 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7905         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7906                                  what, "tx#rx");
7907 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7908         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7909                                  mode, "on#off");
7910
7911 cmdline_parse_inst_t cmd_set_vf_traffic = {
7912         .f = cmd_set_vf_traffic_parsed,
7913         .data = NULL,
7914         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7915         .tokens = {
7916                 (void *)&cmd_setvf_traffic_set,
7917                 (void *)&cmd_setvf_traffic_port,
7918                 (void *)&cmd_setvf_traffic_portid,
7919                 (void *)&cmd_setvf_traffic_vf,
7920                 (void *)&cmd_setvf_traffic_vfid,
7921                 (void *)&cmd_setvf_traffic_what,
7922                 (void *)&cmd_setvf_traffic_mode,
7923                 NULL,
7924         },
7925 };
7926
7927 /* *** CONFIGURE VF RECEIVE MODE *** */
7928 struct cmd_set_vf_rxmode {
7929         cmdline_fixed_string_t set;
7930         cmdline_fixed_string_t port;
7931         portid_t port_id;
7932         cmdline_fixed_string_t vf;
7933         uint8_t vf_id;
7934         cmdline_fixed_string_t what;
7935         cmdline_fixed_string_t mode;
7936         cmdline_fixed_string_t on;
7937 };
7938
7939 static void
7940 cmd_set_vf_rxmode_parsed(void *parsed_result,
7941                        __attribute__((unused)) struct cmdline *cl,
7942                        __attribute__((unused)) void *data)
7943 {
7944         int ret = -ENOTSUP;
7945         uint16_t rx_mode = 0;
7946         struct cmd_set_vf_rxmode *res = parsed_result;
7947
7948         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7949         if (!strcmp(res->what,"rxmode")) {
7950                 if (!strcmp(res->mode, "AUPE"))
7951                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7952                 else if (!strcmp(res->mode, "ROPE"))
7953                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7954                 else if (!strcmp(res->mode, "BAM"))
7955                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7956                 else if (!strncmp(res->mode, "MPE",3))
7957                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7958         }
7959
7960         RTE_SET_USED(is_on);
7961
7962 #ifdef RTE_LIBRTE_IXGBE_PMD
7963         if (ret == -ENOTSUP)
7964                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7965                                                   rx_mode, (uint8_t)is_on);
7966 #endif
7967 #ifdef RTE_LIBRTE_BNXT_PMD
7968         if (ret == -ENOTSUP)
7969                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7970                                                  rx_mode, (uint8_t)is_on);
7971 #endif
7972         if (ret < 0)
7973                 printf("bad VF receive mode parameter, return code = %d \n",
7974                 ret);
7975 }
7976
7977 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7978         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7979                                  set, "set");
7980 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7981         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7982                                  port, "port");
7983 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7984         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7985                               port_id, UINT16);
7986 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7987         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7988                                  vf, "vf");
7989 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7990         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7991                               vf_id, UINT8);
7992 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7993         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7994                                  what, "rxmode");
7995 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7996         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7997                                  mode, "AUPE#ROPE#BAM#MPE");
7998 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7999         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8000                                  on, "on#off");
8001
8002 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8003         .f = cmd_set_vf_rxmode_parsed,
8004         .data = NULL,
8005         .help_str = "set port <port_id> vf <vf_id> rxmode "
8006                 "AUPE|ROPE|BAM|MPE on|off",
8007         .tokens = {
8008                 (void *)&cmd_set_vf_rxmode_set,
8009                 (void *)&cmd_set_vf_rxmode_port,
8010                 (void *)&cmd_set_vf_rxmode_portid,
8011                 (void *)&cmd_set_vf_rxmode_vf,
8012                 (void *)&cmd_set_vf_rxmode_vfid,
8013                 (void *)&cmd_set_vf_rxmode_what,
8014                 (void *)&cmd_set_vf_rxmode_mode,
8015                 (void *)&cmd_set_vf_rxmode_on,
8016                 NULL,
8017         },
8018 };
8019
8020 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8021 struct cmd_vf_mac_addr_result {
8022         cmdline_fixed_string_t mac_addr_cmd;
8023         cmdline_fixed_string_t what;
8024         cmdline_fixed_string_t port;
8025         uint16_t port_num;
8026         cmdline_fixed_string_t vf;
8027         uint8_t vf_num;
8028         struct ether_addr address;
8029 };
8030
8031 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8032                 __attribute__((unused)) struct cmdline *cl,
8033                 __attribute__((unused)) void *data)
8034 {
8035         struct cmd_vf_mac_addr_result *res = parsed_result;
8036         int ret = -ENOTSUP;
8037
8038         if (strcmp(res->what, "add") != 0)
8039                 return;
8040
8041 #ifdef RTE_LIBRTE_I40E_PMD
8042         if (ret == -ENOTSUP)
8043                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8044                                                    &res->address);
8045 #endif
8046 #ifdef RTE_LIBRTE_BNXT_PMD
8047         if (ret == -ENOTSUP)
8048                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8049                                                 res->vf_num);
8050 #endif
8051
8052         if(ret < 0)
8053                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8054
8055 }
8056
8057 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8058         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8059                                 mac_addr_cmd,"mac_addr");
8060 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8061         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8062                                 what,"add");
8063 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8064         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8065                                 port,"port");
8066 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8067         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8068                                 port_num, UINT16);
8069 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8070         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8071                                 vf,"vf");
8072 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8073         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8074                                 vf_num, UINT8);
8075 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8076         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8077                                 address);
8078
8079 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8080         .f = cmd_vf_mac_addr_parsed,
8081         .data = (void *)0,
8082         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8083                 "Add MAC address filtering for a VF on port_id",
8084         .tokens = {
8085                 (void *)&cmd_vf_mac_addr_cmd,
8086                 (void *)&cmd_vf_mac_addr_what,
8087                 (void *)&cmd_vf_mac_addr_port,
8088                 (void *)&cmd_vf_mac_addr_portnum,
8089                 (void *)&cmd_vf_mac_addr_vf,
8090                 (void *)&cmd_vf_mac_addr_vfnum,
8091                 (void *)&cmd_vf_mac_addr_addr,
8092                 NULL,
8093         },
8094 };
8095
8096 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8097 struct cmd_vf_rx_vlan_filter {
8098         cmdline_fixed_string_t rx_vlan;
8099         cmdline_fixed_string_t what;
8100         uint16_t vlan_id;
8101         cmdline_fixed_string_t port;
8102         portid_t port_id;
8103         cmdline_fixed_string_t vf;
8104         uint64_t vf_mask;
8105 };
8106
8107 static void
8108 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8109                           __attribute__((unused)) struct cmdline *cl,
8110                           __attribute__((unused)) void *data)
8111 {
8112         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8113         int ret = -ENOTSUP;
8114
8115         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8116
8117 #ifdef RTE_LIBRTE_IXGBE_PMD
8118         if (ret == -ENOTSUP)
8119                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8120                                 res->vlan_id, res->vf_mask, is_add);
8121 #endif
8122 #ifdef RTE_LIBRTE_I40E_PMD
8123         if (ret == -ENOTSUP)
8124                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8125                                 res->vlan_id, res->vf_mask, is_add);
8126 #endif
8127 #ifdef RTE_LIBRTE_BNXT_PMD
8128         if (ret == -ENOTSUP)
8129                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8130                                 res->vlan_id, res->vf_mask, is_add);
8131 #endif
8132
8133         switch (ret) {
8134         case 0:
8135                 break;
8136         case -EINVAL:
8137                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8138                                 res->vlan_id, res->vf_mask);
8139                 break;
8140         case -ENODEV:
8141                 printf("invalid port_id %d\n", res->port_id);
8142                 break;
8143         case -ENOTSUP:
8144                 printf("function not implemented or supported\n");
8145                 break;
8146         default:
8147                 printf("programming error: (%s)\n", strerror(-ret));
8148         }
8149 }
8150
8151 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8152         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8153                                  rx_vlan, "rx_vlan");
8154 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8155         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8156                                  what, "add#rm");
8157 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8158         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8159                               vlan_id, UINT16);
8160 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8161         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8162                                  port, "port");
8163 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8164         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8165                               port_id, UINT16);
8166 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8167         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8168                                  vf, "vf");
8169 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8170         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8171                               vf_mask, UINT64);
8172
8173 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8174         .f = cmd_vf_rx_vlan_filter_parsed,
8175         .data = NULL,
8176         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8177                 "(vf_mask = hexadecimal VF mask)",
8178         .tokens = {
8179                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8180                 (void *)&cmd_vf_rx_vlan_filter_what,
8181                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8182                 (void *)&cmd_vf_rx_vlan_filter_port,
8183                 (void *)&cmd_vf_rx_vlan_filter_portid,
8184                 (void *)&cmd_vf_rx_vlan_filter_vf,
8185                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8186                 NULL,
8187         },
8188 };
8189
8190 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8191 struct cmd_queue_rate_limit_result {
8192         cmdline_fixed_string_t set;
8193         cmdline_fixed_string_t port;
8194         uint16_t port_num;
8195         cmdline_fixed_string_t queue;
8196         uint8_t queue_num;
8197         cmdline_fixed_string_t rate;
8198         uint16_t rate_num;
8199 };
8200
8201 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8202                 __attribute__((unused)) struct cmdline *cl,
8203                 __attribute__((unused)) void *data)
8204 {
8205         struct cmd_queue_rate_limit_result *res = parsed_result;
8206         int ret = 0;
8207
8208         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8209                 && (strcmp(res->queue, "queue") == 0)
8210                 && (strcmp(res->rate, "rate") == 0))
8211                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8212                                         res->rate_num);
8213         if (ret < 0)
8214                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8215
8216 }
8217
8218 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8219         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8220                                 set, "set");
8221 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8222         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8223                                 port, "port");
8224 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8225         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8226                                 port_num, UINT16);
8227 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8228         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8229                                 queue, "queue");
8230 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8231         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8232                                 queue_num, UINT8);
8233 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8234         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8235                                 rate, "rate");
8236 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8237         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8238                                 rate_num, UINT16);
8239
8240 cmdline_parse_inst_t cmd_queue_rate_limit = {
8241         .f = cmd_queue_rate_limit_parsed,
8242         .data = (void *)0,
8243         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8244                 "Set rate limit for a queue on port_id",
8245         .tokens = {
8246                 (void *)&cmd_queue_rate_limit_set,
8247                 (void *)&cmd_queue_rate_limit_port,
8248                 (void *)&cmd_queue_rate_limit_portnum,
8249                 (void *)&cmd_queue_rate_limit_queue,
8250                 (void *)&cmd_queue_rate_limit_queuenum,
8251                 (void *)&cmd_queue_rate_limit_rate,
8252                 (void *)&cmd_queue_rate_limit_ratenum,
8253                 NULL,
8254         },
8255 };
8256
8257 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8258 struct cmd_vf_rate_limit_result {
8259         cmdline_fixed_string_t set;
8260         cmdline_fixed_string_t port;
8261         uint16_t port_num;
8262         cmdline_fixed_string_t vf;
8263         uint8_t vf_num;
8264         cmdline_fixed_string_t rate;
8265         uint16_t rate_num;
8266         cmdline_fixed_string_t q_msk;
8267         uint64_t q_msk_val;
8268 };
8269
8270 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8271                 __attribute__((unused)) struct cmdline *cl,
8272                 __attribute__((unused)) void *data)
8273 {
8274         struct cmd_vf_rate_limit_result *res = parsed_result;
8275         int ret = 0;
8276
8277         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8278                 && (strcmp(res->vf, "vf") == 0)
8279                 && (strcmp(res->rate, "rate") == 0)
8280                 && (strcmp(res->q_msk, "queue_mask") == 0))
8281                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8282                                         res->rate_num, res->q_msk_val);
8283         if (ret < 0)
8284                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8285
8286 }
8287
8288 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8289         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8290                                 set, "set");
8291 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8292         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8293                                 port, "port");
8294 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8295         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8296                                 port_num, UINT16);
8297 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8298         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8299                                 vf, "vf");
8300 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8301         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8302                                 vf_num, UINT8);
8303 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8304         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8305                                 rate, "rate");
8306 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8307         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8308                                 rate_num, UINT16);
8309 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8310         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8311                                 q_msk, "queue_mask");
8312 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8313         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8314                                 q_msk_val, UINT64);
8315
8316 cmdline_parse_inst_t cmd_vf_rate_limit = {
8317         .f = cmd_vf_rate_limit_parsed,
8318         .data = (void *)0,
8319         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8320                 "queue_mask <queue_mask_value>: "
8321                 "Set rate limit for queues of VF on port_id",
8322         .tokens = {
8323                 (void *)&cmd_vf_rate_limit_set,
8324                 (void *)&cmd_vf_rate_limit_port,
8325                 (void *)&cmd_vf_rate_limit_portnum,
8326                 (void *)&cmd_vf_rate_limit_vf,
8327                 (void *)&cmd_vf_rate_limit_vfnum,
8328                 (void *)&cmd_vf_rate_limit_rate,
8329                 (void *)&cmd_vf_rate_limit_ratenum,
8330                 (void *)&cmd_vf_rate_limit_q_msk,
8331                 (void *)&cmd_vf_rate_limit_q_msk_val,
8332                 NULL,
8333         },
8334 };
8335
8336 /* *** ADD TUNNEL FILTER OF A PORT *** */
8337 struct cmd_tunnel_filter_result {
8338         cmdline_fixed_string_t cmd;
8339         cmdline_fixed_string_t what;
8340         portid_t port_id;
8341         struct ether_addr outer_mac;
8342         struct ether_addr inner_mac;
8343         cmdline_ipaddr_t ip_value;
8344         uint16_t inner_vlan;
8345         cmdline_fixed_string_t tunnel_type;
8346         cmdline_fixed_string_t filter_type;
8347         uint32_t tenant_id;
8348         uint16_t queue_num;
8349 };
8350
8351 static void
8352 cmd_tunnel_filter_parsed(void *parsed_result,
8353                           __attribute__((unused)) struct cmdline *cl,
8354                           __attribute__((unused)) void *data)
8355 {
8356         struct cmd_tunnel_filter_result *res = parsed_result;
8357         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8358         int ret = 0;
8359
8360         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8361
8362         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8363         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8364         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8365
8366         if (res->ip_value.family == AF_INET) {
8367                 tunnel_filter_conf.ip_addr.ipv4_addr =
8368                         res->ip_value.addr.ipv4.s_addr;
8369                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8370         } else {
8371                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8372                         &(res->ip_value.addr.ipv6),
8373                         sizeof(struct in6_addr));
8374                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8375         }
8376
8377         if (!strcmp(res->filter_type, "imac-ivlan"))
8378                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8379         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8380                 tunnel_filter_conf.filter_type =
8381                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8382         else if (!strcmp(res->filter_type, "imac-tenid"))
8383                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8384         else if (!strcmp(res->filter_type, "imac"))
8385                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8386         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8387                 tunnel_filter_conf.filter_type =
8388                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8389         else if (!strcmp(res->filter_type, "oip"))
8390                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8391         else if (!strcmp(res->filter_type, "iip"))
8392                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8393         else {
8394                 printf("The filter type is not supported");
8395                 return;
8396         }
8397
8398         if (!strcmp(res->tunnel_type, "vxlan"))
8399                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8400         else if (!strcmp(res->tunnel_type, "nvgre"))
8401                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8402         else if (!strcmp(res->tunnel_type, "ipingre"))
8403                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8404         else {
8405                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8406                 return;
8407         }
8408
8409         tunnel_filter_conf.tenant_id = res->tenant_id;
8410         tunnel_filter_conf.queue_id = res->queue_num;
8411         if (!strcmp(res->what, "add"))
8412                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8413                                         RTE_ETH_FILTER_TUNNEL,
8414                                         RTE_ETH_FILTER_ADD,
8415                                         &tunnel_filter_conf);
8416         else
8417                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8418                                         RTE_ETH_FILTER_TUNNEL,
8419                                         RTE_ETH_FILTER_DELETE,
8420                                         &tunnel_filter_conf);
8421         if (ret < 0)
8422                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8423                                 strerror(-ret));
8424
8425 }
8426 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8427         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8428         cmd, "tunnel_filter");
8429 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8430         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8431         what, "add#rm");
8432 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8433         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8434         port_id, UINT16);
8435 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8436         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8437         outer_mac);
8438 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8439         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8440         inner_mac);
8441 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8442         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8443         inner_vlan, UINT16);
8444 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8445         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8446         ip_value);
8447 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8448         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8449         tunnel_type, "vxlan#nvgre#ipingre");
8450
8451 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8452         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8453         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8454                 "imac#omac-imac-tenid");
8455 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8456         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8457         tenant_id, UINT32);
8458 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8459         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8460         queue_num, UINT16);
8461
8462 cmdline_parse_inst_t cmd_tunnel_filter = {
8463         .f = cmd_tunnel_filter_parsed,
8464         .data = (void *)0,
8465         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8466                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8467                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8468                 "<queue_id>: Add/Rm tunnel filter of a port",
8469         .tokens = {
8470                 (void *)&cmd_tunnel_filter_cmd,
8471                 (void *)&cmd_tunnel_filter_what,
8472                 (void *)&cmd_tunnel_filter_port_id,
8473                 (void *)&cmd_tunnel_filter_outer_mac,
8474                 (void *)&cmd_tunnel_filter_inner_mac,
8475                 (void *)&cmd_tunnel_filter_ip_value,
8476                 (void *)&cmd_tunnel_filter_innner_vlan,
8477                 (void *)&cmd_tunnel_filter_tunnel_type,
8478                 (void *)&cmd_tunnel_filter_filter_type,
8479                 (void *)&cmd_tunnel_filter_tenant_id,
8480                 (void *)&cmd_tunnel_filter_queue_num,
8481                 NULL,
8482         },
8483 };
8484
8485 /* *** CONFIGURE TUNNEL UDP PORT *** */
8486 struct cmd_tunnel_udp_config {
8487         cmdline_fixed_string_t cmd;
8488         cmdline_fixed_string_t what;
8489         uint16_t udp_port;
8490         portid_t port_id;
8491 };
8492
8493 static void
8494 cmd_tunnel_udp_config_parsed(void *parsed_result,
8495                           __attribute__((unused)) struct cmdline *cl,
8496                           __attribute__((unused)) void *data)
8497 {
8498         struct cmd_tunnel_udp_config *res = parsed_result;
8499         struct rte_eth_udp_tunnel tunnel_udp;
8500         int ret;
8501
8502         tunnel_udp.udp_port = res->udp_port;
8503
8504         if (!strcmp(res->cmd, "rx_vxlan_port"))
8505                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8506
8507         if (!strcmp(res->what, "add"))
8508                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8509                                                       &tunnel_udp);
8510         else
8511                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8512                                                          &tunnel_udp);
8513
8514         if (ret < 0)
8515                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8516 }
8517
8518 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8519         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8520                                 cmd, "rx_vxlan_port");
8521 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8522         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8523                                 what, "add#rm");
8524 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8525         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8526                                 udp_port, UINT16);
8527 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8528         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8529                                 port_id, UINT16);
8530
8531 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8532         .f = cmd_tunnel_udp_config_parsed,
8533         .data = (void *)0,
8534         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8535                 "Add/Remove a tunneling UDP port filter",
8536         .tokens = {
8537                 (void *)&cmd_tunnel_udp_config_cmd,
8538                 (void *)&cmd_tunnel_udp_config_what,
8539                 (void *)&cmd_tunnel_udp_config_udp_port,
8540                 (void *)&cmd_tunnel_udp_config_port_id,
8541                 NULL,
8542         },
8543 };
8544
8545 /* *** GLOBAL CONFIG *** */
8546 struct cmd_global_config_result {
8547         cmdline_fixed_string_t cmd;
8548         portid_t port_id;
8549         cmdline_fixed_string_t cfg_type;
8550         uint8_t len;
8551 };
8552
8553 static void
8554 cmd_global_config_parsed(void *parsed_result,
8555                          __attribute__((unused)) struct cmdline *cl,
8556                          __attribute__((unused)) void *data)
8557 {
8558         struct cmd_global_config_result *res = parsed_result;
8559         struct rte_eth_global_cfg conf;
8560         int ret;
8561
8562         memset(&conf, 0, sizeof(conf));
8563         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8564         conf.cfg.gre_key_len = res->len;
8565         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8566                                       RTE_ETH_FILTER_SET, &conf);
8567         if (ret != 0)
8568                 printf("Global config error\n");
8569 }
8570
8571 cmdline_parse_token_string_t cmd_global_config_cmd =
8572         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8573                 "global_config");
8574 cmdline_parse_token_num_t cmd_global_config_port_id =
8575         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8576                                UINT16);
8577 cmdline_parse_token_string_t cmd_global_config_type =
8578         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8579                 cfg_type, "gre-key-len");
8580 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8581         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8582                 len, UINT8);
8583
8584 cmdline_parse_inst_t cmd_global_config = {
8585         .f = cmd_global_config_parsed,
8586         .data = (void *)NULL,
8587         .help_str = "global_config <port_id> gre-key-len <key_len>",
8588         .tokens = {
8589                 (void *)&cmd_global_config_cmd,
8590                 (void *)&cmd_global_config_port_id,
8591                 (void *)&cmd_global_config_type,
8592                 (void *)&cmd_global_config_gre_key_len,
8593                 NULL,
8594         },
8595 };
8596
8597 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8598 struct cmd_set_mirror_mask_result {
8599         cmdline_fixed_string_t set;
8600         cmdline_fixed_string_t port;
8601         portid_t port_id;
8602         cmdline_fixed_string_t mirror;
8603         uint8_t rule_id;
8604         cmdline_fixed_string_t what;
8605         cmdline_fixed_string_t value;
8606         cmdline_fixed_string_t dstpool;
8607         uint8_t dstpool_id;
8608         cmdline_fixed_string_t on;
8609 };
8610
8611 cmdline_parse_token_string_t cmd_mirror_mask_set =
8612         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8613                                 set, "set");
8614 cmdline_parse_token_string_t cmd_mirror_mask_port =
8615         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8616                                 port, "port");
8617 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8618         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8619                                 port_id, UINT16);
8620 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8621         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8622                                 mirror, "mirror-rule");
8623 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8624         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8625                                 rule_id, UINT8);
8626 cmdline_parse_token_string_t cmd_mirror_mask_what =
8627         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8628                                 what, "pool-mirror-up#pool-mirror-down"
8629                                       "#vlan-mirror");
8630 cmdline_parse_token_string_t cmd_mirror_mask_value =
8631         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8632                                 value, NULL);
8633 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8634         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8635                                 dstpool, "dst-pool");
8636 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8637         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8638                                 dstpool_id, UINT8);
8639 cmdline_parse_token_string_t cmd_mirror_mask_on =
8640         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8641                                 on, "on#off");
8642
8643 static void
8644 cmd_set_mirror_mask_parsed(void *parsed_result,
8645                        __attribute__((unused)) struct cmdline *cl,
8646                        __attribute__((unused)) void *data)
8647 {
8648         int ret,nb_item,i;
8649         struct cmd_set_mirror_mask_result *res = parsed_result;
8650         struct rte_eth_mirror_conf mr_conf;
8651
8652         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8653
8654         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8655
8656         mr_conf.dst_pool = res->dstpool_id;
8657
8658         if (!strcmp(res->what, "pool-mirror-up")) {
8659                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8660                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8661         } else if (!strcmp(res->what, "pool-mirror-down")) {
8662                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8663                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8664         } else if (!strcmp(res->what, "vlan-mirror")) {
8665                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8666                 nb_item = parse_item_list(res->value, "vlan",
8667                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8668                 if (nb_item <= 0)
8669                         return;
8670
8671                 for (i = 0; i < nb_item; i++) {
8672                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8673                                 printf("Invalid vlan_id: must be < 4096\n");
8674                                 return;
8675                         }
8676
8677                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8678                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8679                 }
8680         }
8681
8682         if (!strcmp(res->on, "on"))
8683                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8684                                                 res->rule_id, 1);
8685         else
8686                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8687                                                 res->rule_id, 0);
8688         if (ret < 0)
8689                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8690 }
8691
8692 cmdline_parse_inst_t cmd_set_mirror_mask = {
8693                 .f = cmd_set_mirror_mask_parsed,
8694                 .data = NULL,
8695                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8696                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8697                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8698                 .tokens = {
8699                         (void *)&cmd_mirror_mask_set,
8700                         (void *)&cmd_mirror_mask_port,
8701                         (void *)&cmd_mirror_mask_portid,
8702                         (void *)&cmd_mirror_mask_mirror,
8703                         (void *)&cmd_mirror_mask_ruleid,
8704                         (void *)&cmd_mirror_mask_what,
8705                         (void *)&cmd_mirror_mask_value,
8706                         (void *)&cmd_mirror_mask_dstpool,
8707                         (void *)&cmd_mirror_mask_poolid,
8708                         (void *)&cmd_mirror_mask_on,
8709                         NULL,
8710                 },
8711 };
8712
8713 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8714 struct cmd_set_mirror_link_result {
8715         cmdline_fixed_string_t set;
8716         cmdline_fixed_string_t port;
8717         portid_t port_id;
8718         cmdline_fixed_string_t mirror;
8719         uint8_t rule_id;
8720         cmdline_fixed_string_t what;
8721         cmdline_fixed_string_t dstpool;
8722         uint8_t dstpool_id;
8723         cmdline_fixed_string_t on;
8724 };
8725
8726 cmdline_parse_token_string_t cmd_mirror_link_set =
8727         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8728                                  set, "set");
8729 cmdline_parse_token_string_t cmd_mirror_link_port =
8730         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8731                                 port, "port");
8732 cmdline_parse_token_num_t cmd_mirror_link_portid =
8733         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8734                                 port_id, UINT16);
8735 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8736         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8737                                 mirror, "mirror-rule");
8738 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8739         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8740                             rule_id, UINT8);
8741 cmdline_parse_token_string_t cmd_mirror_link_what =
8742         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8743                                 what, "uplink-mirror#downlink-mirror");
8744 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8745         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8746                                 dstpool, "dst-pool");
8747 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8748         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8749                                 dstpool_id, UINT8);
8750 cmdline_parse_token_string_t cmd_mirror_link_on =
8751         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8752                                 on, "on#off");
8753
8754 static void
8755 cmd_set_mirror_link_parsed(void *parsed_result,
8756                        __attribute__((unused)) struct cmdline *cl,
8757                        __attribute__((unused)) void *data)
8758 {
8759         int ret;
8760         struct cmd_set_mirror_link_result *res = parsed_result;
8761         struct rte_eth_mirror_conf mr_conf;
8762
8763         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8764         if (!strcmp(res->what, "uplink-mirror"))
8765                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8766         else
8767                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8768
8769         mr_conf.dst_pool = res->dstpool_id;
8770
8771         if (!strcmp(res->on, "on"))
8772                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8773                                                 res->rule_id, 1);
8774         else
8775                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8776                                                 res->rule_id, 0);
8777
8778         /* check the return value and print it if is < 0 */
8779         if (ret < 0)
8780                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8781
8782 }
8783
8784 cmdline_parse_inst_t cmd_set_mirror_link = {
8785                 .f = cmd_set_mirror_link_parsed,
8786                 .data = NULL,
8787                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8788                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8789                 .tokens = {
8790                         (void *)&cmd_mirror_link_set,
8791                         (void *)&cmd_mirror_link_port,
8792                         (void *)&cmd_mirror_link_portid,
8793                         (void *)&cmd_mirror_link_mirror,
8794                         (void *)&cmd_mirror_link_ruleid,
8795                         (void *)&cmd_mirror_link_what,
8796                         (void *)&cmd_mirror_link_dstpool,
8797                         (void *)&cmd_mirror_link_poolid,
8798                         (void *)&cmd_mirror_link_on,
8799                         NULL,
8800                 },
8801 };
8802
8803 /* *** RESET VM MIRROR RULE *** */
8804 struct cmd_rm_mirror_rule_result {
8805         cmdline_fixed_string_t reset;
8806         cmdline_fixed_string_t port;
8807         portid_t port_id;
8808         cmdline_fixed_string_t mirror;
8809         uint8_t rule_id;
8810 };
8811
8812 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8813         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8814                                  reset, "reset");
8815 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8816         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8817                                 port, "port");
8818 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8819         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8820                                 port_id, UINT16);
8821 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8822         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8823                                 mirror, "mirror-rule");
8824 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8825         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8826                                 rule_id, UINT8);
8827
8828 static void
8829 cmd_reset_mirror_rule_parsed(void *parsed_result,
8830                        __attribute__((unused)) struct cmdline *cl,
8831                        __attribute__((unused)) void *data)
8832 {
8833         int ret;
8834         struct cmd_set_mirror_link_result *res = parsed_result;
8835         /* check rule_id */
8836         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8837         if(ret < 0)
8838                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8839 }
8840
8841 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8842                 .f = cmd_reset_mirror_rule_parsed,
8843                 .data = NULL,
8844                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8845                 .tokens = {
8846                         (void *)&cmd_rm_mirror_rule_reset,
8847                         (void *)&cmd_rm_mirror_rule_port,
8848                         (void *)&cmd_rm_mirror_rule_portid,
8849                         (void *)&cmd_rm_mirror_rule_mirror,
8850                         (void *)&cmd_rm_mirror_rule_ruleid,
8851                         NULL,
8852                 },
8853 };
8854
8855 /* ******************************************************************************** */
8856
8857 struct cmd_dump_result {
8858         cmdline_fixed_string_t dump;
8859 };
8860
8861 static void
8862 dump_struct_sizes(void)
8863 {
8864 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8865         DUMP_SIZE(struct rte_mbuf);
8866         DUMP_SIZE(struct rte_mempool);
8867         DUMP_SIZE(struct rte_ring);
8868 #undef DUMP_SIZE
8869 }
8870
8871 static void cmd_dump_parsed(void *parsed_result,
8872                             __attribute__((unused)) struct cmdline *cl,
8873                             __attribute__((unused)) void *data)
8874 {
8875         struct cmd_dump_result *res = parsed_result;
8876
8877         if (!strcmp(res->dump, "dump_physmem"))
8878                 rte_dump_physmem_layout(stdout);
8879         else if (!strcmp(res->dump, "dump_memzone"))
8880                 rte_memzone_dump(stdout);
8881         else if (!strcmp(res->dump, "dump_struct_sizes"))
8882                 dump_struct_sizes();
8883         else if (!strcmp(res->dump, "dump_ring"))
8884                 rte_ring_list_dump(stdout);
8885         else if (!strcmp(res->dump, "dump_mempool"))
8886                 rte_mempool_list_dump(stdout);
8887         else if (!strcmp(res->dump, "dump_devargs"))
8888                 rte_devargs_dump(stdout);
8889         else if (!strcmp(res->dump, "dump_log_types"))
8890                 rte_log_dump(stdout);
8891 }
8892
8893 cmdline_parse_token_string_t cmd_dump_dump =
8894         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8895                 "dump_physmem#"
8896                 "dump_memzone#"
8897                 "dump_struct_sizes#"
8898                 "dump_ring#"
8899                 "dump_mempool#"
8900                 "dump_devargs#"
8901                 "dump_log_types");
8902
8903 cmdline_parse_inst_t cmd_dump = {
8904         .f = cmd_dump_parsed,  /* function to call */
8905         .data = NULL,      /* 2nd arg of func */
8906         .help_str = "Dump status",
8907         .tokens = {        /* token list, NULL terminated */
8908                 (void *)&cmd_dump_dump,
8909                 NULL,
8910         },
8911 };
8912
8913 /* ******************************************************************************** */
8914
8915 struct cmd_dump_one_result {
8916         cmdline_fixed_string_t dump;
8917         cmdline_fixed_string_t name;
8918 };
8919
8920 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8921                                 __attribute__((unused)) void *data)
8922 {
8923         struct cmd_dump_one_result *res = parsed_result;
8924
8925         if (!strcmp(res->dump, "dump_ring")) {
8926                 struct rte_ring *r;
8927                 r = rte_ring_lookup(res->name);
8928                 if (r == NULL) {
8929                         cmdline_printf(cl, "Cannot find ring\n");
8930                         return;
8931                 }
8932                 rte_ring_dump(stdout, r);
8933         } else if (!strcmp(res->dump, "dump_mempool")) {
8934                 struct rte_mempool *mp;
8935                 mp = rte_mempool_lookup(res->name);
8936                 if (mp == NULL) {
8937                         cmdline_printf(cl, "Cannot find mempool\n");
8938                         return;
8939                 }
8940                 rte_mempool_dump(stdout, mp);
8941         }
8942 }
8943
8944 cmdline_parse_token_string_t cmd_dump_one_dump =
8945         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8946                                  "dump_ring#dump_mempool");
8947
8948 cmdline_parse_token_string_t cmd_dump_one_name =
8949         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8950
8951 cmdline_parse_inst_t cmd_dump_one = {
8952         .f = cmd_dump_one_parsed,  /* function to call */
8953         .data = NULL,      /* 2nd arg of func */
8954         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8955         .tokens = {        /* token list, NULL terminated */
8956                 (void *)&cmd_dump_one_dump,
8957                 (void *)&cmd_dump_one_name,
8958                 NULL,
8959         },
8960 };
8961
8962 /* *** Add/Del syn filter *** */
8963 struct cmd_syn_filter_result {
8964         cmdline_fixed_string_t filter;
8965         portid_t port_id;
8966         cmdline_fixed_string_t ops;
8967         cmdline_fixed_string_t priority;
8968         cmdline_fixed_string_t high;
8969         cmdline_fixed_string_t queue;
8970         uint16_t queue_id;
8971 };
8972
8973 static void
8974 cmd_syn_filter_parsed(void *parsed_result,
8975                         __attribute__((unused)) struct cmdline *cl,
8976                         __attribute__((unused)) void *data)
8977 {
8978         struct cmd_syn_filter_result *res = parsed_result;
8979         struct rte_eth_syn_filter syn_filter;
8980         int ret = 0;
8981
8982         ret = rte_eth_dev_filter_supported(res->port_id,
8983                                         RTE_ETH_FILTER_SYN);
8984         if (ret < 0) {
8985                 printf("syn filter is not supported on port %u.\n",
8986                                 res->port_id);
8987                 return;
8988         }
8989
8990         memset(&syn_filter, 0, sizeof(syn_filter));
8991
8992         if (!strcmp(res->ops, "add")) {
8993                 if (!strcmp(res->high, "high"))
8994                         syn_filter.hig_pri = 1;
8995                 else
8996                         syn_filter.hig_pri = 0;
8997
8998                 syn_filter.queue = res->queue_id;
8999                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9000                                                 RTE_ETH_FILTER_SYN,
9001                                                 RTE_ETH_FILTER_ADD,
9002                                                 &syn_filter);
9003         } else
9004                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9005                                                 RTE_ETH_FILTER_SYN,
9006                                                 RTE_ETH_FILTER_DELETE,
9007                                                 &syn_filter);
9008
9009         if (ret < 0)
9010                 printf("syn filter programming error: (%s)\n",
9011                                 strerror(-ret));
9012 }
9013
9014 cmdline_parse_token_string_t cmd_syn_filter_filter =
9015         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9016         filter, "syn_filter");
9017 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9018         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9019         port_id, UINT16);
9020 cmdline_parse_token_string_t cmd_syn_filter_ops =
9021         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9022         ops, "add#del");
9023 cmdline_parse_token_string_t cmd_syn_filter_priority =
9024         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9025                                 priority, "priority");
9026 cmdline_parse_token_string_t cmd_syn_filter_high =
9027         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9028                                 high, "high#low");
9029 cmdline_parse_token_string_t cmd_syn_filter_queue =
9030         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9031                                 queue, "queue");
9032 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9033         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9034                                 queue_id, UINT16);
9035
9036 cmdline_parse_inst_t cmd_syn_filter = {
9037         .f = cmd_syn_filter_parsed,
9038         .data = NULL,
9039         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9040                 "<queue_id>: Add/Delete syn filter",
9041         .tokens = {
9042                 (void *)&cmd_syn_filter_filter,
9043                 (void *)&cmd_syn_filter_port_id,
9044                 (void *)&cmd_syn_filter_ops,
9045                 (void *)&cmd_syn_filter_priority,
9046                 (void *)&cmd_syn_filter_high,
9047                 (void *)&cmd_syn_filter_queue,
9048                 (void *)&cmd_syn_filter_queue_id,
9049                 NULL,
9050         },
9051 };
9052
9053 /* *** queue region set *** */
9054 struct cmd_queue_region_result {
9055         cmdline_fixed_string_t set;
9056         cmdline_fixed_string_t port;
9057         portid_t port_id;
9058         cmdline_fixed_string_t cmd;
9059         cmdline_fixed_string_t region;
9060         uint8_t  region_id;
9061         cmdline_fixed_string_t queue_start_index;
9062         uint8_t  queue_id;
9063         cmdline_fixed_string_t queue_num;
9064         uint8_t  queue_num_value;
9065 };
9066
9067 static void
9068 cmd_queue_region_parsed(void *parsed_result,
9069                         __attribute__((unused)) struct cmdline *cl,
9070                         __attribute__((unused)) void *data)
9071 {
9072         struct cmd_queue_region_result *res = parsed_result;
9073         int ret = -ENOTSUP;
9074 #ifdef RTE_LIBRTE_I40E_PMD
9075         struct rte_pmd_i40e_queue_region_conf region_conf;
9076         enum rte_pmd_i40e_queue_region_op op_type;
9077 #endif
9078
9079         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9080                 return;
9081
9082 #ifdef RTE_LIBRTE_I40E_PMD
9083         memset(&region_conf, 0, sizeof(region_conf));
9084         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9085         region_conf.region_id = res->region_id;
9086         region_conf.queue_num = res->queue_num_value;
9087         region_conf.queue_start_index = res->queue_id;
9088
9089         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9090                                 op_type, &region_conf);
9091 #endif
9092
9093         switch (ret) {
9094         case 0:
9095                 break;
9096         case -ENOTSUP:
9097                 printf("function not implemented or supported\n");
9098                 break;
9099         default:
9100                 printf("queue region config error: (%s)\n", strerror(-ret));
9101         }
9102 }
9103
9104 cmdline_parse_token_string_t cmd_queue_region_set =
9105 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9106                 set, "set");
9107 cmdline_parse_token_string_t cmd_queue_region_port =
9108         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9109 cmdline_parse_token_num_t cmd_queue_region_port_id =
9110         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9111                                 port_id, UINT16);
9112 cmdline_parse_token_string_t cmd_queue_region_cmd =
9113         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9114                                  cmd, "queue-region");
9115 cmdline_parse_token_string_t cmd_queue_region_id =
9116         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9117                                 region, "region_id");
9118 cmdline_parse_token_num_t cmd_queue_region_index =
9119         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9120                                 region_id, UINT8);
9121 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9122         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9123                                 queue_start_index, "queue_start_index");
9124 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9125         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9126                                 queue_id, UINT8);
9127 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9128         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9129                                 queue_num, "queue_num");
9130 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9131         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9132                                 queue_num_value, UINT8);
9133
9134 cmdline_parse_inst_t cmd_queue_region = {
9135         .f = cmd_queue_region_parsed,
9136         .data = NULL,
9137         .help_str = "set port <port_id> queue-region region_id <value> "
9138                 "queue_start_index <value> queue_num <value>: Set a queue region",
9139         .tokens = {
9140                 (void *)&cmd_queue_region_set,
9141                 (void *)&cmd_queue_region_port,
9142                 (void *)&cmd_queue_region_port_id,
9143                 (void *)&cmd_queue_region_cmd,
9144                 (void *)&cmd_queue_region_id,
9145                 (void *)&cmd_queue_region_index,
9146                 (void *)&cmd_queue_region_queue_start_index,
9147                 (void *)&cmd_queue_region_queue_id,
9148                 (void *)&cmd_queue_region_queue_num,
9149                 (void *)&cmd_queue_region_queue_num_value,
9150                 NULL,
9151         },
9152 };
9153
9154 /* *** queue region and flowtype set *** */
9155 struct cmd_region_flowtype_result {
9156         cmdline_fixed_string_t set;
9157         cmdline_fixed_string_t port;
9158         portid_t port_id;
9159         cmdline_fixed_string_t cmd;
9160         cmdline_fixed_string_t region;
9161         uint8_t  region_id;
9162         cmdline_fixed_string_t flowtype;
9163         uint8_t  flowtype_id;
9164 };
9165
9166 static void
9167 cmd_region_flowtype_parsed(void *parsed_result,
9168                         __attribute__((unused)) struct cmdline *cl,
9169                         __attribute__((unused)) void *data)
9170 {
9171         struct cmd_region_flowtype_result *res = parsed_result;
9172         int ret = -ENOTSUP;
9173 #ifdef RTE_LIBRTE_I40E_PMD
9174         struct rte_pmd_i40e_queue_region_conf region_conf;
9175         enum rte_pmd_i40e_queue_region_op op_type;
9176 #endif
9177
9178         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9179                 return;
9180
9181 #ifdef RTE_LIBRTE_I40E_PMD
9182         memset(&region_conf, 0, sizeof(region_conf));
9183
9184         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9185         region_conf.region_id = res->region_id;
9186         region_conf.hw_flowtype = res->flowtype_id;
9187
9188         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9189                         op_type, &region_conf);
9190 #endif
9191
9192         switch (ret) {
9193         case 0:
9194                 break;
9195         case -ENOTSUP:
9196                 printf("function not implemented or supported\n");
9197                 break;
9198         default:
9199                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9200         }
9201 }
9202
9203 cmdline_parse_token_string_t cmd_region_flowtype_set =
9204 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9205                                 set, "set");
9206 cmdline_parse_token_string_t cmd_region_flowtype_port =
9207         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9208                                 port, "port");
9209 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9210         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9211                                 port_id, UINT16);
9212 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9213         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9214                                 cmd, "queue-region");
9215 cmdline_parse_token_string_t cmd_region_flowtype_index =
9216         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9217                                 region, "region_id");
9218 cmdline_parse_token_num_t cmd_region_flowtype_id =
9219         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9220                                 region_id, UINT8);
9221 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9222         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9223                                 flowtype, "flowtype");
9224 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9225         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9226                                 flowtype_id, UINT8);
9227 cmdline_parse_inst_t cmd_region_flowtype = {
9228         .f = cmd_region_flowtype_parsed,
9229         .data = NULL,
9230         .help_str = "set port <port_id> queue-region region_id <value> "
9231                 "flowtype <value>: Set a flowtype region index",
9232         .tokens = {
9233                 (void *)&cmd_region_flowtype_set,
9234                 (void *)&cmd_region_flowtype_port,
9235                 (void *)&cmd_region_flowtype_port_index,
9236                 (void *)&cmd_region_flowtype_cmd,
9237                 (void *)&cmd_region_flowtype_index,
9238                 (void *)&cmd_region_flowtype_id,
9239                 (void *)&cmd_region_flowtype_flow_index,
9240                 (void *)&cmd_region_flowtype_flow_id,
9241                 NULL,
9242         },
9243 };
9244
9245 /* *** User Priority (UP) to queue region (region_id) set *** */
9246 struct cmd_user_priority_region_result {
9247         cmdline_fixed_string_t set;
9248         cmdline_fixed_string_t port;
9249         portid_t port_id;
9250         cmdline_fixed_string_t cmd;
9251         cmdline_fixed_string_t user_priority;
9252         uint8_t  user_priority_id;
9253         cmdline_fixed_string_t region;
9254         uint8_t  region_id;
9255 };
9256
9257 static void
9258 cmd_user_priority_region_parsed(void *parsed_result,
9259                         __attribute__((unused)) struct cmdline *cl,
9260                         __attribute__((unused)) void *data)
9261 {
9262         struct cmd_user_priority_region_result *res = parsed_result;
9263         int ret = -ENOTSUP;
9264 #ifdef RTE_LIBRTE_I40E_PMD
9265         struct rte_pmd_i40e_queue_region_conf region_conf;
9266         enum rte_pmd_i40e_queue_region_op op_type;
9267 #endif
9268
9269         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9270                 return;
9271
9272 #ifdef RTE_LIBRTE_I40E_PMD
9273         memset(&region_conf, 0, sizeof(region_conf));
9274         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9275         region_conf.user_priority = res->user_priority_id;
9276         region_conf.region_id = res->region_id;
9277
9278         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9279                                 op_type, &region_conf);
9280 #endif
9281
9282         switch (ret) {
9283         case 0:
9284                 break;
9285         case -ENOTSUP:
9286                 printf("function not implemented or supported\n");
9287                 break;
9288         default:
9289                 printf("user_priority region config error: (%s)\n",
9290                                 strerror(-ret));
9291         }
9292 }
9293
9294 cmdline_parse_token_string_t cmd_user_priority_region_set =
9295         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9296                                 set, "set");
9297 cmdline_parse_token_string_t cmd_user_priority_region_port =
9298         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9299                                 port, "port");
9300 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9301         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9302                                 port_id, UINT16);
9303 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9304         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9305                                 cmd, "queue-region");
9306 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9307         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9308                                 user_priority, "UP");
9309 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9310         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9311                                 user_priority_id, UINT8);
9312 cmdline_parse_token_string_t cmd_user_priority_region_region =
9313         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9314                                 region, "region_id");
9315 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9316         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9317                                 region_id, UINT8);
9318
9319 cmdline_parse_inst_t cmd_user_priority_region = {
9320         .f = cmd_user_priority_region_parsed,
9321         .data = NULL,
9322         .help_str = "set port <port_id> queue-region UP <value> "
9323                 "region_id <value>: Set the mapping of User Priority (UP) "
9324                 "to queue region (region_id) ",
9325         .tokens = {
9326                 (void *)&cmd_user_priority_region_set,
9327                 (void *)&cmd_user_priority_region_port,
9328                 (void *)&cmd_user_priority_region_port_index,
9329                 (void *)&cmd_user_priority_region_cmd,
9330                 (void *)&cmd_user_priority_region_UP,
9331                 (void *)&cmd_user_priority_region_UP_id,
9332                 (void *)&cmd_user_priority_region_region,
9333                 (void *)&cmd_user_priority_region_region_id,
9334                 NULL,
9335         },
9336 };
9337
9338 /* *** flush all queue region related configuration *** */
9339 struct cmd_flush_queue_region_result {
9340         cmdline_fixed_string_t set;
9341         cmdline_fixed_string_t port;
9342         portid_t port_id;
9343         cmdline_fixed_string_t cmd;
9344         cmdline_fixed_string_t flush;
9345         cmdline_fixed_string_t what;
9346 };
9347
9348 static void
9349 cmd_flush_queue_region_parsed(void *parsed_result,
9350                         __attribute__((unused)) struct cmdline *cl,
9351                         __attribute__((unused)) void *data)
9352 {
9353         struct cmd_flush_queue_region_result *res = parsed_result;
9354         int ret = -ENOTSUP;
9355 #ifdef RTE_LIBRTE_I40E_PMD
9356         struct rte_pmd_i40e_queue_region_conf region_conf;
9357         enum rte_pmd_i40e_queue_region_op op_type;
9358 #endif
9359
9360         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9361                 return;
9362
9363 #ifdef RTE_LIBRTE_I40E_PMD
9364         memset(&region_conf, 0, sizeof(region_conf));
9365
9366         if (strcmp(res->what, "on") == 0)
9367                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9368         else
9369                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9370
9371         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9372                                 op_type, &region_conf);
9373 #endif
9374
9375         switch (ret) {
9376         case 0:
9377                 break;
9378         case -ENOTSUP:
9379                 printf("function not implemented or supported\n");
9380                 break;
9381         default:
9382                 printf("queue region config flush error: (%s)\n",
9383                                 strerror(-ret));
9384         }
9385 }
9386
9387 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9388         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9389                                 set, "set");
9390 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9391         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9392                                 port, "port");
9393 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9394         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9395                                 port_id, UINT16);
9396 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9397         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9398                                 cmd, "queue-region");
9399 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9400         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9401                                 flush, "flush");
9402 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9403         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9404                                 what, "on#off");
9405
9406 cmdline_parse_inst_t cmd_flush_queue_region = {
9407         .f = cmd_flush_queue_region_parsed,
9408         .data = NULL,
9409         .help_str = "set port <port_id> queue-region flush on|off"
9410                 ": flush all queue region related configuration",
9411         .tokens = {
9412                 (void *)&cmd_flush_queue_region_set,
9413                 (void *)&cmd_flush_queue_region_port,
9414                 (void *)&cmd_flush_queue_region_port_index,
9415                 (void *)&cmd_flush_queue_region_cmd,
9416                 (void *)&cmd_flush_queue_region_flush,
9417                 (void *)&cmd_flush_queue_region_what,
9418                 NULL,
9419         },
9420 };
9421
9422 /* *** get all queue region related configuration info *** */
9423 struct cmd_show_queue_region_info {
9424         cmdline_fixed_string_t show;
9425         cmdline_fixed_string_t port;
9426         portid_t port_id;
9427         cmdline_fixed_string_t cmd;
9428 };
9429
9430 static void
9431 cmd_show_queue_region_info_parsed(void *parsed_result,
9432                         __attribute__((unused)) struct cmdline *cl,
9433                         __attribute__((unused)) void *data)
9434 {
9435         struct cmd_show_queue_region_info *res = parsed_result;
9436         int ret = -ENOTSUP;
9437 #ifdef RTE_LIBRTE_I40E_PMD
9438         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9439         enum rte_pmd_i40e_queue_region_op op_type;
9440 #endif
9441
9442         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9443                 return;
9444
9445 #ifdef RTE_LIBRTE_I40E_PMD
9446         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9447
9448         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9449
9450         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9451                                         op_type, &rte_pmd_regions);
9452
9453         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9454 #endif
9455
9456         switch (ret) {
9457         case 0:
9458                 break;
9459         case -ENOTSUP:
9460                 printf("function not implemented or supported\n");
9461                 break;
9462         default:
9463                 printf("queue region config info show error: (%s)\n",
9464                                 strerror(-ret));
9465         }
9466 }
9467
9468 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9469 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9470                                 show, "show");
9471 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9472         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9473                                 port, "port");
9474 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9475         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9476                                 port_id, UINT16);
9477 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9478         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9479                                 cmd, "queue-region");
9480
9481 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9482         .f = cmd_show_queue_region_info_parsed,
9483         .data = NULL,
9484         .help_str = "show port <port_id> queue-region"
9485                 ": show all queue region related configuration info",
9486         .tokens = {
9487                 (void *)&cmd_show_queue_region_info_get,
9488                 (void *)&cmd_show_queue_region_info_port,
9489                 (void *)&cmd_show_queue_region_info_port_index,
9490                 (void *)&cmd_show_queue_region_info_cmd,
9491                 NULL,
9492         },
9493 };
9494
9495 /* *** ADD/REMOVE A 2tuple FILTER *** */
9496 struct cmd_2tuple_filter_result {
9497         cmdline_fixed_string_t filter;
9498         portid_t port_id;
9499         cmdline_fixed_string_t ops;
9500         cmdline_fixed_string_t dst_port;
9501         uint16_t dst_port_value;
9502         cmdline_fixed_string_t protocol;
9503         uint8_t protocol_value;
9504         cmdline_fixed_string_t mask;
9505         uint8_t  mask_value;
9506         cmdline_fixed_string_t tcp_flags;
9507         uint8_t tcp_flags_value;
9508         cmdline_fixed_string_t priority;
9509         uint8_t  priority_value;
9510         cmdline_fixed_string_t queue;
9511         uint16_t  queue_id;
9512 };
9513
9514 static void
9515 cmd_2tuple_filter_parsed(void *parsed_result,
9516                         __attribute__((unused)) struct cmdline *cl,
9517                         __attribute__((unused)) void *data)
9518 {
9519         struct rte_eth_ntuple_filter filter;
9520         struct cmd_2tuple_filter_result *res = parsed_result;
9521         int ret = 0;
9522
9523         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9524         if (ret < 0) {
9525                 printf("ntuple filter is not supported on port %u.\n",
9526                         res->port_id);
9527                 return;
9528         }
9529
9530         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9531
9532         filter.flags = RTE_2TUPLE_FLAGS;
9533         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9534         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9535         filter.proto = res->protocol_value;
9536         filter.priority = res->priority_value;
9537         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9538                 printf("nonzero tcp_flags is only meaningful"
9539                         " when protocol is TCP.\n");
9540                 return;
9541         }
9542         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9543                 printf("invalid TCP flags.\n");
9544                 return;
9545         }
9546
9547         if (res->tcp_flags_value != 0) {
9548                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9549                 filter.tcp_flags = res->tcp_flags_value;
9550         }
9551
9552         /* need convert to big endian. */
9553         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9554         filter.queue = res->queue_id;
9555
9556         if (!strcmp(res->ops, "add"))
9557                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9558                                 RTE_ETH_FILTER_NTUPLE,
9559                                 RTE_ETH_FILTER_ADD,
9560                                 &filter);
9561         else
9562                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9563                                 RTE_ETH_FILTER_NTUPLE,
9564                                 RTE_ETH_FILTER_DELETE,
9565                                 &filter);
9566         if (ret < 0)
9567                 printf("2tuple filter programming error: (%s)\n",
9568                         strerror(-ret));
9569
9570 }
9571
9572 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9573         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9574                                  filter, "2tuple_filter");
9575 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9576         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9577                                 port_id, UINT16);
9578 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9579         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9580                                  ops, "add#del");
9581 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9582         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9583                                 dst_port, "dst_port");
9584 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9585         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9586                                 dst_port_value, UINT16);
9587 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9588         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9589                                 protocol, "protocol");
9590 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9591         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9592                                 protocol_value, UINT8);
9593 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9594         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9595                                 mask, "mask");
9596 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9597         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9598                                 mask_value, INT8);
9599 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9600         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9601                                 tcp_flags, "tcp_flags");
9602 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9603         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9604                                 tcp_flags_value, UINT8);
9605 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9606         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9607                                 priority, "priority");
9608 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9609         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9610                                 priority_value, UINT8);
9611 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9612         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9613                                 queue, "queue");
9614 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9615         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9616                                 queue_id, UINT16);
9617
9618 cmdline_parse_inst_t cmd_2tuple_filter = {
9619         .f = cmd_2tuple_filter_parsed,
9620         .data = NULL,
9621         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9622                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9623                 "<queue_id>: Add a 2tuple filter",
9624         .tokens = {
9625                 (void *)&cmd_2tuple_filter_filter,
9626                 (void *)&cmd_2tuple_filter_port_id,
9627                 (void *)&cmd_2tuple_filter_ops,
9628                 (void *)&cmd_2tuple_filter_dst_port,
9629                 (void *)&cmd_2tuple_filter_dst_port_value,
9630                 (void *)&cmd_2tuple_filter_protocol,
9631                 (void *)&cmd_2tuple_filter_protocol_value,
9632                 (void *)&cmd_2tuple_filter_mask,
9633                 (void *)&cmd_2tuple_filter_mask_value,
9634                 (void *)&cmd_2tuple_filter_tcp_flags,
9635                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9636                 (void *)&cmd_2tuple_filter_priority,
9637                 (void *)&cmd_2tuple_filter_priority_value,
9638                 (void *)&cmd_2tuple_filter_queue,
9639                 (void *)&cmd_2tuple_filter_queue_id,
9640                 NULL,
9641         },
9642 };
9643
9644 /* *** ADD/REMOVE A 5tuple FILTER *** */
9645 struct cmd_5tuple_filter_result {
9646         cmdline_fixed_string_t filter;
9647         portid_t port_id;
9648         cmdline_fixed_string_t ops;
9649         cmdline_fixed_string_t dst_ip;
9650         cmdline_ipaddr_t dst_ip_value;
9651         cmdline_fixed_string_t src_ip;
9652         cmdline_ipaddr_t src_ip_value;
9653         cmdline_fixed_string_t dst_port;
9654         uint16_t dst_port_value;
9655         cmdline_fixed_string_t src_port;
9656         uint16_t src_port_value;
9657         cmdline_fixed_string_t protocol;
9658         uint8_t protocol_value;
9659         cmdline_fixed_string_t mask;
9660         uint8_t  mask_value;
9661         cmdline_fixed_string_t tcp_flags;
9662         uint8_t tcp_flags_value;
9663         cmdline_fixed_string_t priority;
9664         uint8_t  priority_value;
9665         cmdline_fixed_string_t queue;
9666         uint16_t  queue_id;
9667 };
9668
9669 static void
9670 cmd_5tuple_filter_parsed(void *parsed_result,
9671                         __attribute__((unused)) struct cmdline *cl,
9672                         __attribute__((unused)) void *data)
9673 {
9674         struct rte_eth_ntuple_filter filter;
9675         struct cmd_5tuple_filter_result *res = parsed_result;
9676         int ret = 0;
9677
9678         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9679         if (ret < 0) {
9680                 printf("ntuple filter is not supported on port %u.\n",
9681                         res->port_id);
9682                 return;
9683         }
9684
9685         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9686
9687         filter.flags = RTE_5TUPLE_FLAGS;
9688         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9689         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9690         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9691         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9692         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9693         filter.proto = res->protocol_value;
9694         filter.priority = res->priority_value;
9695         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9696                 printf("nonzero tcp_flags is only meaningful"
9697                         " when protocol is TCP.\n");
9698                 return;
9699         }
9700         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9701                 printf("invalid TCP flags.\n");
9702                 return;
9703         }
9704
9705         if (res->tcp_flags_value != 0) {
9706                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9707                 filter.tcp_flags = res->tcp_flags_value;
9708         }
9709
9710         if (res->dst_ip_value.family == AF_INET)
9711                 /* no need to convert, already big endian. */
9712                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9713         else {
9714                 if (filter.dst_ip_mask == 0) {
9715                         printf("can not support ipv6 involved compare.\n");
9716                         return;
9717                 }
9718                 filter.dst_ip = 0;
9719         }
9720
9721         if (res->src_ip_value.family == AF_INET)
9722                 /* no need to convert, already big endian. */
9723                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9724         else {
9725                 if (filter.src_ip_mask == 0) {
9726                         printf("can not support ipv6 involved compare.\n");
9727                         return;
9728                 }
9729                 filter.src_ip = 0;
9730         }
9731         /* need convert to big endian. */
9732         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9733         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9734         filter.queue = res->queue_id;
9735
9736         if (!strcmp(res->ops, "add"))
9737                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9738                                 RTE_ETH_FILTER_NTUPLE,
9739                                 RTE_ETH_FILTER_ADD,
9740                                 &filter);
9741         else
9742                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9743                                 RTE_ETH_FILTER_NTUPLE,
9744                                 RTE_ETH_FILTER_DELETE,
9745                                 &filter);
9746         if (ret < 0)
9747                 printf("5tuple filter programming error: (%s)\n",
9748                         strerror(-ret));
9749 }
9750
9751 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9752         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9753                                  filter, "5tuple_filter");
9754 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9755         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9756                                 port_id, UINT16);
9757 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9758         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9759                                  ops, "add#del");
9760 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9761         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9762                                 dst_ip, "dst_ip");
9763 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9764         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9765                                 dst_ip_value);
9766 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9767         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9768                                 src_ip, "src_ip");
9769 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9770         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9771                                 src_ip_value);
9772 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9773         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9774                                 dst_port, "dst_port");
9775 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9776         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9777                                 dst_port_value, UINT16);
9778 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9779         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9780                                 src_port, "src_port");
9781 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9782         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9783                                 src_port_value, UINT16);
9784 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9785         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9786                                 protocol, "protocol");
9787 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9788         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9789                                 protocol_value, UINT8);
9790 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9791         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9792                                 mask, "mask");
9793 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9794         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9795                                 mask_value, INT8);
9796 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9797         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9798                                 tcp_flags, "tcp_flags");
9799 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9800         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9801                                 tcp_flags_value, UINT8);
9802 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9803         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9804                                 priority, "priority");
9805 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9806         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9807                                 priority_value, UINT8);
9808 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9809         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9810                                 queue, "queue");
9811 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9812         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9813                                 queue_id, UINT16);
9814
9815 cmdline_parse_inst_t cmd_5tuple_filter = {
9816         .f = cmd_5tuple_filter_parsed,
9817         .data = NULL,
9818         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9819                 "src_ip <value> dst_port <value> src_port <value> "
9820                 "protocol <value>  mask <value> tcp_flags <value> "
9821                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9822         .tokens = {
9823                 (void *)&cmd_5tuple_filter_filter,
9824                 (void *)&cmd_5tuple_filter_port_id,
9825                 (void *)&cmd_5tuple_filter_ops,
9826                 (void *)&cmd_5tuple_filter_dst_ip,
9827                 (void *)&cmd_5tuple_filter_dst_ip_value,
9828                 (void *)&cmd_5tuple_filter_src_ip,
9829                 (void *)&cmd_5tuple_filter_src_ip_value,
9830                 (void *)&cmd_5tuple_filter_dst_port,
9831                 (void *)&cmd_5tuple_filter_dst_port_value,
9832                 (void *)&cmd_5tuple_filter_src_port,
9833                 (void *)&cmd_5tuple_filter_src_port_value,
9834                 (void *)&cmd_5tuple_filter_protocol,
9835                 (void *)&cmd_5tuple_filter_protocol_value,
9836                 (void *)&cmd_5tuple_filter_mask,
9837                 (void *)&cmd_5tuple_filter_mask_value,
9838                 (void *)&cmd_5tuple_filter_tcp_flags,
9839                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9840                 (void *)&cmd_5tuple_filter_priority,
9841                 (void *)&cmd_5tuple_filter_priority_value,
9842                 (void *)&cmd_5tuple_filter_queue,
9843                 (void *)&cmd_5tuple_filter_queue_id,
9844                 NULL,
9845         },
9846 };
9847
9848 /* *** ADD/REMOVE A flex FILTER *** */
9849 struct cmd_flex_filter_result {
9850         cmdline_fixed_string_t filter;
9851         cmdline_fixed_string_t ops;
9852         portid_t port_id;
9853         cmdline_fixed_string_t len;
9854         uint8_t len_value;
9855         cmdline_fixed_string_t bytes;
9856         cmdline_fixed_string_t bytes_value;
9857         cmdline_fixed_string_t mask;
9858         cmdline_fixed_string_t mask_value;
9859         cmdline_fixed_string_t priority;
9860         uint8_t priority_value;
9861         cmdline_fixed_string_t queue;
9862         uint16_t queue_id;
9863 };
9864
9865 static int xdigit2val(unsigned char c)
9866 {
9867         int val;
9868         if (isdigit(c))
9869                 val = c - '0';
9870         else if (isupper(c))
9871                 val = c - 'A' + 10;
9872         else
9873                 val = c - 'a' + 10;
9874         return val;
9875 }
9876
9877 static void
9878 cmd_flex_filter_parsed(void *parsed_result,
9879                           __attribute__((unused)) struct cmdline *cl,
9880                           __attribute__((unused)) void *data)
9881 {
9882         int ret = 0;
9883         struct rte_eth_flex_filter filter;
9884         struct cmd_flex_filter_result *res = parsed_result;
9885         char *bytes_ptr, *mask_ptr;
9886         uint16_t len, i, j = 0;
9887         char c;
9888         int val;
9889         uint8_t byte = 0;
9890
9891         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9892                 printf("the len exceed the max length 128\n");
9893                 return;
9894         }
9895         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9896         filter.len = res->len_value;
9897         filter.priority = res->priority_value;
9898         filter.queue = res->queue_id;
9899         bytes_ptr = res->bytes_value;
9900         mask_ptr = res->mask_value;
9901
9902          /* translate bytes string to array. */
9903         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9904                 (bytes_ptr[1] == 'X')))
9905                 bytes_ptr += 2;
9906         len = strnlen(bytes_ptr, res->len_value * 2);
9907         if (len == 0 || (len % 8 != 0)) {
9908                 printf("please check len and bytes input\n");
9909                 return;
9910         }
9911         for (i = 0; i < len; i++) {
9912                 c = bytes_ptr[i];
9913                 if (isxdigit(c) == 0) {
9914                         /* invalid characters. */
9915                         printf("invalid input\n");
9916                         return;
9917                 }
9918                 val = xdigit2val(c);
9919                 if (i % 2) {
9920                         byte |= val;
9921                         filter.bytes[j] = byte;
9922                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9923                         j++;
9924                         byte = 0;
9925                 } else
9926                         byte |= val << 4;
9927         }
9928         printf("\n");
9929          /* translate mask string to uint8_t array. */
9930         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9931                 (mask_ptr[1] == 'X')))
9932                 mask_ptr += 2;
9933         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9934         if (len == 0) {
9935                 printf("invalid input\n");
9936                 return;
9937         }
9938         j = 0;
9939         byte = 0;
9940         for (i = 0; i < len; i++) {
9941                 c = mask_ptr[i];
9942                 if (isxdigit(c) == 0) {
9943                         /* invalid characters. */
9944                         printf("invalid input\n");
9945                         return;
9946                 }
9947                 val = xdigit2val(c);
9948                 if (i % 2) {
9949                         byte |= val;
9950                         filter.mask[j] = byte;
9951                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9952                         j++;
9953                         byte = 0;
9954                 } else
9955                         byte |= val << 4;
9956         }
9957         printf("\n");
9958
9959         if (!strcmp(res->ops, "add"))
9960                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9961                                 RTE_ETH_FILTER_FLEXIBLE,
9962                                 RTE_ETH_FILTER_ADD,
9963                                 &filter);
9964         else
9965                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9966                                 RTE_ETH_FILTER_FLEXIBLE,
9967                                 RTE_ETH_FILTER_DELETE,
9968                                 &filter);
9969
9970         if (ret < 0)
9971                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9972 }
9973
9974 cmdline_parse_token_string_t cmd_flex_filter_filter =
9975         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9976                                 filter, "flex_filter");
9977 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9978         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9979                                 port_id, UINT16);
9980 cmdline_parse_token_string_t cmd_flex_filter_ops =
9981         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9982                                 ops, "add#del");
9983 cmdline_parse_token_string_t cmd_flex_filter_len =
9984         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9985                                 len, "len");
9986 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9987         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9988                                 len_value, UINT8);
9989 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9990         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9991                                 bytes, "bytes");
9992 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9993         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9994                                 bytes_value, NULL);
9995 cmdline_parse_token_string_t cmd_flex_filter_mask =
9996         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9997                                 mask, "mask");
9998 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9999         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10000                                 mask_value, NULL);
10001 cmdline_parse_token_string_t cmd_flex_filter_priority =
10002         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10003                                 priority, "priority");
10004 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10005         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10006                                 priority_value, UINT8);
10007 cmdline_parse_token_string_t cmd_flex_filter_queue =
10008         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10009                                 queue, "queue");
10010 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10011         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10012                                 queue_id, UINT16);
10013 cmdline_parse_inst_t cmd_flex_filter = {
10014         .f = cmd_flex_filter_parsed,
10015         .data = NULL,
10016         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10017                 "<value> mask <value> priority <value> queue <queue_id>: "
10018                 "Add/Del a flex filter",
10019         .tokens = {
10020                 (void *)&cmd_flex_filter_filter,
10021                 (void *)&cmd_flex_filter_port_id,
10022                 (void *)&cmd_flex_filter_ops,
10023                 (void *)&cmd_flex_filter_len,
10024                 (void *)&cmd_flex_filter_len_value,
10025                 (void *)&cmd_flex_filter_bytes,
10026                 (void *)&cmd_flex_filter_bytes_value,
10027                 (void *)&cmd_flex_filter_mask,
10028                 (void *)&cmd_flex_filter_mask_value,
10029                 (void *)&cmd_flex_filter_priority,
10030                 (void *)&cmd_flex_filter_priority_value,
10031                 (void *)&cmd_flex_filter_queue,
10032                 (void *)&cmd_flex_filter_queue_id,
10033                 NULL,
10034         },
10035 };
10036
10037 /* *** Filters Control *** */
10038
10039 /* *** deal with ethertype filter *** */
10040 struct cmd_ethertype_filter_result {
10041         cmdline_fixed_string_t filter;
10042         portid_t port_id;
10043         cmdline_fixed_string_t ops;
10044         cmdline_fixed_string_t mac;
10045         struct ether_addr mac_addr;
10046         cmdline_fixed_string_t ethertype;
10047         uint16_t ethertype_value;
10048         cmdline_fixed_string_t drop;
10049         cmdline_fixed_string_t queue;
10050         uint16_t  queue_id;
10051 };
10052
10053 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10054         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10055                                  filter, "ethertype_filter");
10056 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10057         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10058                               port_id, UINT16);
10059 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10060         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10061                                  ops, "add#del");
10062 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10063         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10064                                  mac, "mac_addr#mac_ignr");
10065 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10066         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10067                                      mac_addr);
10068 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10069         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10070                                  ethertype, "ethertype");
10071 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10072         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10073                               ethertype_value, UINT16);
10074 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10075         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10076                                  drop, "drop#fwd");
10077 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10078         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10079                                  queue, "queue");
10080 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10081         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10082                               queue_id, UINT16);
10083
10084 static void
10085 cmd_ethertype_filter_parsed(void *parsed_result,
10086                           __attribute__((unused)) struct cmdline *cl,
10087                           __attribute__((unused)) void *data)
10088 {
10089         struct cmd_ethertype_filter_result *res = parsed_result;
10090         struct rte_eth_ethertype_filter filter;
10091         int ret = 0;
10092
10093         ret = rte_eth_dev_filter_supported(res->port_id,
10094                         RTE_ETH_FILTER_ETHERTYPE);
10095         if (ret < 0) {
10096                 printf("ethertype filter is not supported on port %u.\n",
10097                         res->port_id);
10098                 return;
10099         }
10100
10101         memset(&filter, 0, sizeof(filter));
10102         if (!strcmp(res->mac, "mac_addr")) {
10103                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10104                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10105                         sizeof(struct ether_addr));
10106         }
10107         if (!strcmp(res->drop, "drop"))
10108                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10109         filter.ether_type = res->ethertype_value;
10110         filter.queue = res->queue_id;
10111
10112         if (!strcmp(res->ops, "add"))
10113                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10114                                 RTE_ETH_FILTER_ETHERTYPE,
10115                                 RTE_ETH_FILTER_ADD,
10116                                 &filter);
10117         else
10118                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10119                                 RTE_ETH_FILTER_ETHERTYPE,
10120                                 RTE_ETH_FILTER_DELETE,
10121                                 &filter);
10122         if (ret < 0)
10123                 printf("ethertype filter programming error: (%s)\n",
10124                         strerror(-ret));
10125 }
10126
10127 cmdline_parse_inst_t cmd_ethertype_filter = {
10128         .f = cmd_ethertype_filter_parsed,
10129         .data = NULL,
10130         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10131                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10132                 "Add or delete an ethertype filter entry",
10133         .tokens = {
10134                 (void *)&cmd_ethertype_filter_filter,
10135                 (void *)&cmd_ethertype_filter_port_id,
10136                 (void *)&cmd_ethertype_filter_ops,
10137                 (void *)&cmd_ethertype_filter_mac,
10138                 (void *)&cmd_ethertype_filter_mac_addr,
10139                 (void *)&cmd_ethertype_filter_ethertype,
10140                 (void *)&cmd_ethertype_filter_ethertype_value,
10141                 (void *)&cmd_ethertype_filter_drop,
10142                 (void *)&cmd_ethertype_filter_queue,
10143                 (void *)&cmd_ethertype_filter_queue_id,
10144                 NULL,
10145         },
10146 };
10147
10148 /* *** deal with flow director filter *** */
10149 struct cmd_flow_director_result {
10150         cmdline_fixed_string_t flow_director_filter;
10151         portid_t port_id;
10152         cmdline_fixed_string_t mode;
10153         cmdline_fixed_string_t mode_value;
10154         cmdline_fixed_string_t ops;
10155         cmdline_fixed_string_t flow;
10156         cmdline_fixed_string_t flow_type;
10157         cmdline_fixed_string_t ether;
10158         uint16_t ether_type;
10159         cmdline_fixed_string_t src;
10160         cmdline_ipaddr_t ip_src;
10161         uint16_t port_src;
10162         cmdline_fixed_string_t dst;
10163         cmdline_ipaddr_t ip_dst;
10164         uint16_t port_dst;
10165         cmdline_fixed_string_t verify_tag;
10166         uint32_t verify_tag_value;
10167         cmdline_fixed_string_t tos;
10168         uint8_t tos_value;
10169         cmdline_fixed_string_t proto;
10170         uint8_t proto_value;
10171         cmdline_fixed_string_t ttl;
10172         uint8_t ttl_value;
10173         cmdline_fixed_string_t vlan;
10174         uint16_t vlan_value;
10175         cmdline_fixed_string_t flexbytes;
10176         cmdline_fixed_string_t flexbytes_value;
10177         cmdline_fixed_string_t pf_vf;
10178         cmdline_fixed_string_t drop;
10179         cmdline_fixed_string_t queue;
10180         uint16_t  queue_id;
10181         cmdline_fixed_string_t fd_id;
10182         uint32_t  fd_id_value;
10183         cmdline_fixed_string_t mac;
10184         struct ether_addr mac_addr;
10185         cmdline_fixed_string_t tunnel;
10186         cmdline_fixed_string_t tunnel_type;
10187         cmdline_fixed_string_t tunnel_id;
10188         uint32_t tunnel_id_value;
10189         cmdline_fixed_string_t packet;
10190         char filepath[];
10191 };
10192
10193 static inline int
10194 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10195 {
10196         char s[256];
10197         const char *p, *p0 = q_arg;
10198         char *end;
10199         unsigned long int_fld;
10200         char *str_fld[max_num];
10201         int i;
10202         unsigned size;
10203         int ret = -1;
10204
10205         p = strchr(p0, '(');
10206         if (p == NULL)
10207                 return -1;
10208         ++p;
10209         p0 = strchr(p, ')');
10210         if (p0 == NULL)
10211                 return -1;
10212
10213         size = p0 - p;
10214         if (size >= sizeof(s))
10215                 return -1;
10216
10217         snprintf(s, sizeof(s), "%.*s", size, p);
10218         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10219         if (ret < 0 || ret > max_num)
10220                 return -1;
10221         for (i = 0; i < ret; i++) {
10222                 errno = 0;
10223                 int_fld = strtoul(str_fld[i], &end, 0);
10224                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10225                         return -1;
10226                 flexbytes[i] = (uint8_t)int_fld;
10227         }
10228         return ret;
10229 }
10230
10231 static uint16_t
10232 str2flowtype(char *string)
10233 {
10234         uint8_t i = 0;
10235         static const struct {
10236                 char str[32];
10237                 uint16_t type;
10238         } flowtype_str[] = {
10239                 {"raw", RTE_ETH_FLOW_RAW},
10240                 {"ipv4", RTE_ETH_FLOW_IPV4},
10241                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10242                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10243                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10244                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10245                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10246                 {"ipv6", RTE_ETH_FLOW_IPV6},
10247                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10248                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10249                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10250                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10251                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10252                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10253         };
10254
10255         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10256                 if (!strcmp(flowtype_str[i].str, string))
10257                         return flowtype_str[i].type;
10258         }
10259
10260         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10261                 return (uint16_t)atoi(string);
10262
10263         return RTE_ETH_FLOW_UNKNOWN;
10264 }
10265
10266 static enum rte_eth_fdir_tunnel_type
10267 str2fdir_tunneltype(char *string)
10268 {
10269         uint8_t i = 0;
10270
10271         static const struct {
10272                 char str[32];
10273                 enum rte_eth_fdir_tunnel_type type;
10274         } tunneltype_str[] = {
10275                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10276                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10277         };
10278
10279         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10280                 if (!strcmp(tunneltype_str[i].str, string))
10281                         return tunneltype_str[i].type;
10282         }
10283         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10284 }
10285
10286 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10287 do { \
10288         if ((ip_addr).family == AF_INET) \
10289                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10290         else { \
10291                 printf("invalid parameter.\n"); \
10292                 return; \
10293         } \
10294 } while (0)
10295
10296 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10297 do { \
10298         if ((ip_addr).family == AF_INET6) \
10299                 rte_memcpy(&(ip), \
10300                                  &((ip_addr).addr.ipv6), \
10301                                  sizeof(struct in6_addr)); \
10302         else { \
10303                 printf("invalid parameter.\n"); \
10304                 return; \
10305         } \
10306 } while (0)
10307
10308 static void
10309 cmd_flow_director_filter_parsed(void *parsed_result,
10310                           __attribute__((unused)) struct cmdline *cl,
10311                           __attribute__((unused)) void *data)
10312 {
10313         struct cmd_flow_director_result *res = parsed_result;
10314         struct rte_eth_fdir_filter entry;
10315         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10316         char *end;
10317         unsigned long vf_id;
10318         int ret = 0;
10319
10320         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10321         if (ret < 0) {
10322                 printf("flow director is not supported on port %u.\n",
10323                         res->port_id);
10324                 return;
10325         }
10326         memset(flexbytes, 0, sizeof(flexbytes));
10327         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10328
10329         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10330                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10331                         printf("Please set mode to MAC-VLAN.\n");
10332                         return;
10333                 }
10334         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10335                 if (strcmp(res->mode_value, "Tunnel")) {
10336                         printf("Please set mode to Tunnel.\n");
10337                         return;
10338                 }
10339         } else {
10340                 if (!strcmp(res->mode_value, "raw")) {
10341 #ifdef RTE_LIBRTE_I40E_PMD
10342                         struct rte_pmd_i40e_flow_type_mapping
10343                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10344                         struct rte_pmd_i40e_pkt_template_conf conf;
10345                         uint16_t flow_type = str2flowtype(res->flow_type);
10346                         uint16_t i, port = res->port_id;
10347                         uint8_t add;
10348
10349                         memset(&conf, 0, sizeof(conf));
10350
10351                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10352                                 printf("Invalid flow type specified.\n");
10353                                 return;
10354                         }
10355                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10356                                                                  mapping);
10357                         if (ret)
10358                                 return;
10359                         if (mapping[flow_type].pctype == 0ULL) {
10360                                 printf("Invalid flow type specified.\n");
10361                                 return;
10362                         }
10363                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10364                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10365                                         conf.input.pctype = i;
10366                                         break;
10367                                 }
10368                         }
10369
10370                         conf.input.packet = open_file(res->filepath,
10371                                                 &conf.input.length);
10372                         if (!conf.input.packet)
10373                                 return;
10374                         if (!strcmp(res->drop, "drop"))
10375                                 conf.action.behavior =
10376                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10377                         else
10378                                 conf.action.behavior =
10379                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10380                         conf.action.report_status =
10381                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10382                         conf.action.rx_queue = res->queue_id;
10383                         conf.soft_id = res->fd_id_value;
10384                         add  = strcmp(res->ops, "del") ? 1 : 0;
10385                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10386                                                                         &conf,
10387                                                                         add);
10388                         if (ret < 0)
10389                                 printf("flow director config error: (%s)\n",
10390                                        strerror(-ret));
10391                         close_file(conf.input.packet);
10392 #endif
10393                         return;
10394                 } else if (strcmp(res->mode_value, "IP")) {
10395                         printf("Please set mode to IP or raw.\n");
10396                         return;
10397                 }
10398                 entry.input.flow_type = str2flowtype(res->flow_type);
10399         }
10400
10401         ret = parse_flexbytes(res->flexbytes_value,
10402                                         flexbytes,
10403                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10404         if (ret < 0) {
10405                 printf("error: Cannot parse flexbytes input.\n");
10406                 return;
10407         }
10408
10409         switch (entry.input.flow_type) {
10410         case RTE_ETH_FLOW_FRAG_IPV4:
10411         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10412                 entry.input.flow.ip4_flow.proto = res->proto_value;
10413                 /* fall-through */
10414         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10415         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10416                 IPV4_ADDR_TO_UINT(res->ip_dst,
10417                         entry.input.flow.ip4_flow.dst_ip);
10418                 IPV4_ADDR_TO_UINT(res->ip_src,
10419                         entry.input.flow.ip4_flow.src_ip);
10420                 entry.input.flow.ip4_flow.tos = res->tos_value;
10421                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10422                 /* need convert to big endian. */
10423                 entry.input.flow.udp4_flow.dst_port =
10424                                 rte_cpu_to_be_16(res->port_dst);
10425                 entry.input.flow.udp4_flow.src_port =
10426                                 rte_cpu_to_be_16(res->port_src);
10427                 break;
10428         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10429                 IPV4_ADDR_TO_UINT(res->ip_dst,
10430                         entry.input.flow.sctp4_flow.ip.dst_ip);
10431                 IPV4_ADDR_TO_UINT(res->ip_src,
10432                         entry.input.flow.sctp4_flow.ip.src_ip);
10433                 entry.input.flow.ip4_flow.tos = res->tos_value;
10434                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10435                 /* need convert to big endian. */
10436                 entry.input.flow.sctp4_flow.dst_port =
10437                                 rte_cpu_to_be_16(res->port_dst);
10438                 entry.input.flow.sctp4_flow.src_port =
10439                                 rte_cpu_to_be_16(res->port_src);
10440                 entry.input.flow.sctp4_flow.verify_tag =
10441                                 rte_cpu_to_be_32(res->verify_tag_value);
10442                 break;
10443         case RTE_ETH_FLOW_FRAG_IPV6:
10444         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10445                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10446                 /* fall-through */
10447         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10448         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10449                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10450                         entry.input.flow.ipv6_flow.dst_ip);
10451                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10452                         entry.input.flow.ipv6_flow.src_ip);
10453                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10454                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10455                 /* need convert to big endian. */
10456                 entry.input.flow.udp6_flow.dst_port =
10457                                 rte_cpu_to_be_16(res->port_dst);
10458                 entry.input.flow.udp6_flow.src_port =
10459                                 rte_cpu_to_be_16(res->port_src);
10460                 break;
10461         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10462                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10463                         entry.input.flow.sctp6_flow.ip.dst_ip);
10464                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10465                         entry.input.flow.sctp6_flow.ip.src_ip);
10466                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10467                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10468                 /* need convert to big endian. */
10469                 entry.input.flow.sctp6_flow.dst_port =
10470                                 rte_cpu_to_be_16(res->port_dst);
10471                 entry.input.flow.sctp6_flow.src_port =
10472                                 rte_cpu_to_be_16(res->port_src);
10473                 entry.input.flow.sctp6_flow.verify_tag =
10474                                 rte_cpu_to_be_32(res->verify_tag_value);
10475                 break;
10476         case RTE_ETH_FLOW_L2_PAYLOAD:
10477                 entry.input.flow.l2_flow.ether_type =
10478                         rte_cpu_to_be_16(res->ether_type);
10479                 break;
10480         default:
10481                 break;
10482         }
10483
10484         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10485                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10486                                  &res->mac_addr,
10487                                  sizeof(struct ether_addr));
10488
10489         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10490                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10491                                  &res->mac_addr,
10492                                  sizeof(struct ether_addr));
10493                 entry.input.flow.tunnel_flow.tunnel_type =
10494                         str2fdir_tunneltype(res->tunnel_type);
10495                 entry.input.flow.tunnel_flow.tunnel_id =
10496                         rte_cpu_to_be_32(res->tunnel_id_value);
10497         }
10498
10499         rte_memcpy(entry.input.flow_ext.flexbytes,
10500                    flexbytes,
10501                    RTE_ETH_FDIR_MAX_FLEXLEN);
10502
10503         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10504
10505         entry.action.flex_off = 0;  /*use 0 by default */
10506         if (!strcmp(res->drop, "drop"))
10507                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10508         else
10509                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10510
10511         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10512             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10513                 if (!strcmp(res->pf_vf, "pf"))
10514                         entry.input.flow_ext.is_vf = 0;
10515                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10516                         struct rte_eth_dev_info dev_info;
10517
10518                         memset(&dev_info, 0, sizeof(dev_info));
10519                         rte_eth_dev_info_get(res->port_id, &dev_info);
10520                         errno = 0;
10521                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10522                         if (errno != 0 || *end != '\0' ||
10523                             vf_id >= dev_info.max_vfs) {
10524                                 printf("invalid parameter %s.\n", res->pf_vf);
10525                                 return;
10526                         }
10527                         entry.input.flow_ext.is_vf = 1;
10528                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10529                 } else {
10530                         printf("invalid parameter %s.\n", res->pf_vf);
10531                         return;
10532                 }
10533         }
10534
10535         /* set to report FD ID by default */
10536         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10537         entry.action.rx_queue = res->queue_id;
10538         entry.soft_id = res->fd_id_value;
10539         if (!strcmp(res->ops, "add"))
10540                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10541                                              RTE_ETH_FILTER_ADD, &entry);
10542         else if (!strcmp(res->ops, "del"))
10543                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10544                                              RTE_ETH_FILTER_DELETE, &entry);
10545         else
10546                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10547                                              RTE_ETH_FILTER_UPDATE, &entry);
10548         if (ret < 0)
10549                 printf("flow director programming error: (%s)\n",
10550                         strerror(-ret));
10551 }
10552
10553 cmdline_parse_token_string_t cmd_flow_director_filter =
10554         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10555                                  flow_director_filter, "flow_director_filter");
10556 cmdline_parse_token_num_t cmd_flow_director_port_id =
10557         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10558                               port_id, UINT16);
10559 cmdline_parse_token_string_t cmd_flow_director_ops =
10560         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10561                                  ops, "add#del#update");
10562 cmdline_parse_token_string_t cmd_flow_director_flow =
10563         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10564                                  flow, "flow");
10565 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10566         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10567                 flow_type, NULL);
10568 cmdline_parse_token_string_t cmd_flow_director_ether =
10569         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10570                                  ether, "ether");
10571 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10572         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10573                               ether_type, UINT16);
10574 cmdline_parse_token_string_t cmd_flow_director_src =
10575         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10576                                  src, "src");
10577 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10578         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10579                                  ip_src);
10580 cmdline_parse_token_num_t cmd_flow_director_port_src =
10581         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10582                               port_src, UINT16);
10583 cmdline_parse_token_string_t cmd_flow_director_dst =
10584         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10585                                  dst, "dst");
10586 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10587         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10588                                  ip_dst);
10589 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10590         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10591                               port_dst, UINT16);
10592 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10593         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10594                                   verify_tag, "verify_tag");
10595 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10596         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10597                               verify_tag_value, UINT32);
10598 cmdline_parse_token_string_t cmd_flow_director_tos =
10599         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10600                                  tos, "tos");
10601 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10602         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10603                               tos_value, UINT8);
10604 cmdline_parse_token_string_t cmd_flow_director_proto =
10605         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10606                                  proto, "proto");
10607 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10608         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10609                               proto_value, UINT8);
10610 cmdline_parse_token_string_t cmd_flow_director_ttl =
10611         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10612                                  ttl, "ttl");
10613 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10614         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10615                               ttl_value, UINT8);
10616 cmdline_parse_token_string_t cmd_flow_director_vlan =
10617         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10618                                  vlan, "vlan");
10619 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10620         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10621                               vlan_value, UINT16);
10622 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10623         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10624                                  flexbytes, "flexbytes");
10625 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10626         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10627                               flexbytes_value, NULL);
10628 cmdline_parse_token_string_t cmd_flow_director_drop =
10629         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10630                                  drop, "drop#fwd");
10631 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10632         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10633                               pf_vf, NULL);
10634 cmdline_parse_token_string_t cmd_flow_director_queue =
10635         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10636                                  queue, "queue");
10637 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10638         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10639                               queue_id, UINT16);
10640 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10641         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10642                                  fd_id, "fd_id");
10643 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10644         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10645                               fd_id_value, UINT32);
10646
10647 cmdline_parse_token_string_t cmd_flow_director_mode =
10648         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10649                                  mode, "mode");
10650 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10651         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10652                                  mode_value, "IP");
10653 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10654         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10655                                  mode_value, "MAC-VLAN");
10656 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10657         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10658                                  mode_value, "Tunnel");
10659 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10660         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10661                                  mode_value, "raw");
10662 cmdline_parse_token_string_t cmd_flow_director_mac =
10663         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10664                                  mac, "mac");
10665 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10666         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10667                                     mac_addr);
10668 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10669         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10670                                  tunnel, "tunnel");
10671 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10672         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10673                                  tunnel_type, "NVGRE#VxLAN");
10674 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10675         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10676                                  tunnel_id, "tunnel-id");
10677 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10678         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10679                               tunnel_id_value, UINT32);
10680 cmdline_parse_token_string_t cmd_flow_director_packet =
10681         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10682                                  packet, "packet");
10683 cmdline_parse_token_string_t cmd_flow_director_filepath =
10684         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10685                                  filepath, NULL);
10686
10687 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10688         .f = cmd_flow_director_filter_parsed,
10689         .data = NULL,
10690         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10691                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10692                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10693                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10694                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10695                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10696                 "fd_id <fd_id_value>: "
10697                 "Add or delete an ip flow director entry on NIC",
10698         .tokens = {
10699                 (void *)&cmd_flow_director_filter,
10700                 (void *)&cmd_flow_director_port_id,
10701                 (void *)&cmd_flow_director_mode,
10702                 (void *)&cmd_flow_director_mode_ip,
10703                 (void *)&cmd_flow_director_ops,
10704                 (void *)&cmd_flow_director_flow,
10705                 (void *)&cmd_flow_director_flow_type,
10706                 (void *)&cmd_flow_director_src,
10707                 (void *)&cmd_flow_director_ip_src,
10708                 (void *)&cmd_flow_director_dst,
10709                 (void *)&cmd_flow_director_ip_dst,
10710                 (void *)&cmd_flow_director_tos,
10711                 (void *)&cmd_flow_director_tos_value,
10712                 (void *)&cmd_flow_director_proto,
10713                 (void *)&cmd_flow_director_proto_value,
10714                 (void *)&cmd_flow_director_ttl,
10715                 (void *)&cmd_flow_director_ttl_value,
10716                 (void *)&cmd_flow_director_vlan,
10717                 (void *)&cmd_flow_director_vlan_value,
10718                 (void *)&cmd_flow_director_flexbytes,
10719                 (void *)&cmd_flow_director_flexbytes_value,
10720                 (void *)&cmd_flow_director_drop,
10721                 (void *)&cmd_flow_director_pf_vf,
10722                 (void *)&cmd_flow_director_queue,
10723                 (void *)&cmd_flow_director_queue_id,
10724                 (void *)&cmd_flow_director_fd_id,
10725                 (void *)&cmd_flow_director_fd_id_value,
10726                 NULL,
10727         },
10728 };
10729
10730 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10731         .f = cmd_flow_director_filter_parsed,
10732         .data = NULL,
10733         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10734                 "director entry on NIC",
10735         .tokens = {
10736                 (void *)&cmd_flow_director_filter,
10737                 (void *)&cmd_flow_director_port_id,
10738                 (void *)&cmd_flow_director_mode,
10739                 (void *)&cmd_flow_director_mode_ip,
10740                 (void *)&cmd_flow_director_ops,
10741                 (void *)&cmd_flow_director_flow,
10742                 (void *)&cmd_flow_director_flow_type,
10743                 (void *)&cmd_flow_director_src,
10744                 (void *)&cmd_flow_director_ip_src,
10745                 (void *)&cmd_flow_director_port_src,
10746                 (void *)&cmd_flow_director_dst,
10747                 (void *)&cmd_flow_director_ip_dst,
10748                 (void *)&cmd_flow_director_port_dst,
10749                 (void *)&cmd_flow_director_tos,
10750                 (void *)&cmd_flow_director_tos_value,
10751                 (void *)&cmd_flow_director_ttl,
10752                 (void *)&cmd_flow_director_ttl_value,
10753                 (void *)&cmd_flow_director_vlan,
10754                 (void *)&cmd_flow_director_vlan_value,
10755                 (void *)&cmd_flow_director_flexbytes,
10756                 (void *)&cmd_flow_director_flexbytes_value,
10757                 (void *)&cmd_flow_director_drop,
10758                 (void *)&cmd_flow_director_pf_vf,
10759                 (void *)&cmd_flow_director_queue,
10760                 (void *)&cmd_flow_director_queue_id,
10761                 (void *)&cmd_flow_director_fd_id,
10762                 (void *)&cmd_flow_director_fd_id_value,
10763                 NULL,
10764         },
10765 };
10766
10767 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10768         .f = cmd_flow_director_filter_parsed,
10769         .data = NULL,
10770         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10771                 "director entry on NIC",
10772         .tokens = {
10773                 (void *)&cmd_flow_director_filter,
10774                 (void *)&cmd_flow_director_port_id,
10775                 (void *)&cmd_flow_director_mode,
10776                 (void *)&cmd_flow_director_mode_ip,
10777                 (void *)&cmd_flow_director_ops,
10778                 (void *)&cmd_flow_director_flow,
10779                 (void *)&cmd_flow_director_flow_type,
10780                 (void *)&cmd_flow_director_src,
10781                 (void *)&cmd_flow_director_ip_src,
10782                 (void *)&cmd_flow_director_port_src,
10783                 (void *)&cmd_flow_director_dst,
10784                 (void *)&cmd_flow_director_ip_dst,
10785                 (void *)&cmd_flow_director_port_dst,
10786                 (void *)&cmd_flow_director_verify_tag,
10787                 (void *)&cmd_flow_director_verify_tag_value,
10788                 (void *)&cmd_flow_director_tos,
10789                 (void *)&cmd_flow_director_tos_value,
10790                 (void *)&cmd_flow_director_ttl,
10791                 (void *)&cmd_flow_director_ttl_value,
10792                 (void *)&cmd_flow_director_vlan,
10793                 (void *)&cmd_flow_director_vlan_value,
10794                 (void *)&cmd_flow_director_flexbytes,
10795                 (void *)&cmd_flow_director_flexbytes_value,
10796                 (void *)&cmd_flow_director_drop,
10797                 (void *)&cmd_flow_director_pf_vf,
10798                 (void *)&cmd_flow_director_queue,
10799                 (void *)&cmd_flow_director_queue_id,
10800                 (void *)&cmd_flow_director_fd_id,
10801                 (void *)&cmd_flow_director_fd_id_value,
10802                 NULL,
10803         },
10804 };
10805
10806 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10807         .f = cmd_flow_director_filter_parsed,
10808         .data = NULL,
10809         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10810                 "director entry on NIC",
10811         .tokens = {
10812                 (void *)&cmd_flow_director_filter,
10813                 (void *)&cmd_flow_director_port_id,
10814                 (void *)&cmd_flow_director_mode,
10815                 (void *)&cmd_flow_director_mode_ip,
10816                 (void *)&cmd_flow_director_ops,
10817                 (void *)&cmd_flow_director_flow,
10818                 (void *)&cmd_flow_director_flow_type,
10819                 (void *)&cmd_flow_director_ether,
10820                 (void *)&cmd_flow_director_ether_type,
10821                 (void *)&cmd_flow_director_flexbytes,
10822                 (void *)&cmd_flow_director_flexbytes_value,
10823                 (void *)&cmd_flow_director_drop,
10824                 (void *)&cmd_flow_director_pf_vf,
10825                 (void *)&cmd_flow_director_queue,
10826                 (void *)&cmd_flow_director_queue_id,
10827                 (void *)&cmd_flow_director_fd_id,
10828                 (void *)&cmd_flow_director_fd_id_value,
10829                 NULL,
10830         },
10831 };
10832
10833 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10834         .f = cmd_flow_director_filter_parsed,
10835         .data = NULL,
10836         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10837                 "director entry on NIC",
10838         .tokens = {
10839                 (void *)&cmd_flow_director_filter,
10840                 (void *)&cmd_flow_director_port_id,
10841                 (void *)&cmd_flow_director_mode,
10842                 (void *)&cmd_flow_director_mode_mac_vlan,
10843                 (void *)&cmd_flow_director_ops,
10844                 (void *)&cmd_flow_director_mac,
10845                 (void *)&cmd_flow_director_mac_addr,
10846                 (void *)&cmd_flow_director_vlan,
10847                 (void *)&cmd_flow_director_vlan_value,
10848                 (void *)&cmd_flow_director_flexbytes,
10849                 (void *)&cmd_flow_director_flexbytes_value,
10850                 (void *)&cmd_flow_director_drop,
10851                 (void *)&cmd_flow_director_queue,
10852                 (void *)&cmd_flow_director_queue_id,
10853                 (void *)&cmd_flow_director_fd_id,
10854                 (void *)&cmd_flow_director_fd_id_value,
10855                 NULL,
10856         },
10857 };
10858
10859 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10860         .f = cmd_flow_director_filter_parsed,
10861         .data = NULL,
10862         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10863                 "director entry on NIC",
10864         .tokens = {
10865                 (void *)&cmd_flow_director_filter,
10866                 (void *)&cmd_flow_director_port_id,
10867                 (void *)&cmd_flow_director_mode,
10868                 (void *)&cmd_flow_director_mode_tunnel,
10869                 (void *)&cmd_flow_director_ops,
10870                 (void *)&cmd_flow_director_mac,
10871                 (void *)&cmd_flow_director_mac_addr,
10872                 (void *)&cmd_flow_director_vlan,
10873                 (void *)&cmd_flow_director_vlan_value,
10874                 (void *)&cmd_flow_director_tunnel,
10875                 (void *)&cmd_flow_director_tunnel_type,
10876                 (void *)&cmd_flow_director_tunnel_id,
10877                 (void *)&cmd_flow_director_tunnel_id_value,
10878                 (void *)&cmd_flow_director_flexbytes,
10879                 (void *)&cmd_flow_director_flexbytes_value,
10880                 (void *)&cmd_flow_director_drop,
10881                 (void *)&cmd_flow_director_queue,
10882                 (void *)&cmd_flow_director_queue_id,
10883                 (void *)&cmd_flow_director_fd_id,
10884                 (void *)&cmd_flow_director_fd_id_value,
10885                 NULL,
10886         },
10887 };
10888
10889 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10890         .f = cmd_flow_director_filter_parsed,
10891         .data = NULL,
10892         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10893                 "director entry on NIC",
10894         .tokens = {
10895                 (void *)&cmd_flow_director_filter,
10896                 (void *)&cmd_flow_director_port_id,
10897                 (void *)&cmd_flow_director_mode,
10898                 (void *)&cmd_flow_director_mode_raw,
10899                 (void *)&cmd_flow_director_ops,
10900                 (void *)&cmd_flow_director_flow,
10901                 (void *)&cmd_flow_director_flow_type,
10902                 (void *)&cmd_flow_director_drop,
10903                 (void *)&cmd_flow_director_queue,
10904                 (void *)&cmd_flow_director_queue_id,
10905                 (void *)&cmd_flow_director_fd_id,
10906                 (void *)&cmd_flow_director_fd_id_value,
10907                 (void *)&cmd_flow_director_packet,
10908                 (void *)&cmd_flow_director_filepath,
10909                 NULL,
10910         },
10911 };
10912
10913 struct cmd_flush_flow_director_result {
10914         cmdline_fixed_string_t flush_flow_director;
10915         portid_t port_id;
10916 };
10917
10918 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10919         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10920                                  flush_flow_director, "flush_flow_director");
10921 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10922         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10923                               port_id, UINT16);
10924
10925 static void
10926 cmd_flush_flow_director_parsed(void *parsed_result,
10927                           __attribute__((unused)) struct cmdline *cl,
10928                           __attribute__((unused)) void *data)
10929 {
10930         struct cmd_flow_director_result *res = parsed_result;
10931         int ret = 0;
10932
10933         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10934         if (ret < 0) {
10935                 printf("flow director is not supported on port %u.\n",
10936                         res->port_id);
10937                 return;
10938         }
10939
10940         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10941                         RTE_ETH_FILTER_FLUSH, NULL);
10942         if (ret < 0)
10943                 printf("flow director table flushing error: (%s)\n",
10944                         strerror(-ret));
10945 }
10946
10947 cmdline_parse_inst_t cmd_flush_flow_director = {
10948         .f = cmd_flush_flow_director_parsed,
10949         .data = NULL,
10950         .help_str = "flush_flow_director <port_id>: "
10951                 "Flush all flow director entries of a device on NIC",
10952         .tokens = {
10953                 (void *)&cmd_flush_flow_director_flush,
10954                 (void *)&cmd_flush_flow_director_port_id,
10955                 NULL,
10956         },
10957 };
10958
10959 /* *** deal with flow director mask *** */
10960 struct cmd_flow_director_mask_result {
10961         cmdline_fixed_string_t flow_director_mask;
10962         portid_t port_id;
10963         cmdline_fixed_string_t mode;
10964         cmdline_fixed_string_t mode_value;
10965         cmdline_fixed_string_t vlan;
10966         uint16_t vlan_mask;
10967         cmdline_fixed_string_t src_mask;
10968         cmdline_ipaddr_t ipv4_src;
10969         cmdline_ipaddr_t ipv6_src;
10970         uint16_t port_src;
10971         cmdline_fixed_string_t dst_mask;
10972         cmdline_ipaddr_t ipv4_dst;
10973         cmdline_ipaddr_t ipv6_dst;
10974         uint16_t port_dst;
10975         cmdline_fixed_string_t mac;
10976         uint8_t mac_addr_byte_mask;
10977         cmdline_fixed_string_t tunnel_id;
10978         uint32_t tunnel_id_mask;
10979         cmdline_fixed_string_t tunnel_type;
10980         uint8_t tunnel_type_mask;
10981 };
10982
10983 static void
10984 cmd_flow_director_mask_parsed(void *parsed_result,
10985                           __attribute__((unused)) struct cmdline *cl,
10986                           __attribute__((unused)) void *data)
10987 {
10988         struct cmd_flow_director_mask_result *res = parsed_result;
10989         struct rte_eth_fdir_masks *mask;
10990         struct rte_port *port;
10991
10992         port = &ports[res->port_id];
10993         /** Check if the port is not started **/
10994         if (port->port_status != RTE_PORT_STOPPED) {
10995                 printf("Please stop port %d first\n", res->port_id);
10996                 return;
10997         }
10998
10999         mask = &port->dev_conf.fdir_conf.mask;
11000
11001         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11002                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11003                         printf("Please set mode to MAC-VLAN.\n");
11004                         return;
11005                 }
11006
11007                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11008         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11009                 if (strcmp(res->mode_value, "Tunnel")) {
11010                         printf("Please set mode to Tunnel.\n");
11011                         return;
11012                 }
11013
11014                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11015                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11016                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11017                 mask->tunnel_type_mask = res->tunnel_type_mask;
11018         } else {
11019                 if (strcmp(res->mode_value, "IP")) {
11020                         printf("Please set mode to IP.\n");
11021                         return;
11022                 }
11023
11024                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11025                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11026                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11027                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11028                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11029                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11030                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11031         }
11032
11033         cmd_reconfig_device_queue(res->port_id, 1, 1);
11034 }
11035
11036 cmdline_parse_token_string_t cmd_flow_director_mask =
11037         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11038                                  flow_director_mask, "flow_director_mask");
11039 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11040         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11041                               port_id, UINT16);
11042 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11043         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11044                                  vlan, "vlan");
11045 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11046         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11047                               vlan_mask, UINT16);
11048 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11049         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11050                                  src_mask, "src_mask");
11051 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11052         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11053                                  ipv4_src);
11054 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11055         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11056                                  ipv6_src);
11057 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11058         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11059                               port_src, UINT16);
11060 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11061         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11062                                  dst_mask, "dst_mask");
11063 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11064         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11065                                  ipv4_dst);
11066 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11067         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11068                                  ipv6_dst);
11069 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11070         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11071                               port_dst, UINT16);
11072
11073 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11074         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11075                                  mode, "mode");
11076 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11077         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11078                                  mode_value, "IP");
11079 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11080         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11081                                  mode_value, "MAC-VLAN");
11082 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11083         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11084                                  mode_value, "Tunnel");
11085 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11086         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11087                                  mac, "mac");
11088 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11089         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11090                               mac_addr_byte_mask, UINT8);
11091 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11092         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11093                                  tunnel_type, "tunnel-type");
11094 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11095         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11096                               tunnel_type_mask, UINT8);
11097 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11098         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11099                                  tunnel_id, "tunnel-id");
11100 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11101         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11102                               tunnel_id_mask, UINT32);
11103
11104 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11105         .f = cmd_flow_director_mask_parsed,
11106         .data = NULL,
11107         .help_str = "flow_director_mask ... : "
11108                 "Set IP mode flow director's mask on NIC",
11109         .tokens = {
11110                 (void *)&cmd_flow_director_mask,
11111                 (void *)&cmd_flow_director_mask_port_id,
11112                 (void *)&cmd_flow_director_mask_mode,
11113                 (void *)&cmd_flow_director_mask_mode_ip,
11114                 (void *)&cmd_flow_director_mask_vlan,
11115                 (void *)&cmd_flow_director_mask_vlan_value,
11116                 (void *)&cmd_flow_director_mask_src,
11117                 (void *)&cmd_flow_director_mask_ipv4_src,
11118                 (void *)&cmd_flow_director_mask_ipv6_src,
11119                 (void *)&cmd_flow_director_mask_port_src,
11120                 (void *)&cmd_flow_director_mask_dst,
11121                 (void *)&cmd_flow_director_mask_ipv4_dst,
11122                 (void *)&cmd_flow_director_mask_ipv6_dst,
11123                 (void *)&cmd_flow_director_mask_port_dst,
11124                 NULL,
11125         },
11126 };
11127
11128 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11129         .f = cmd_flow_director_mask_parsed,
11130         .data = NULL,
11131         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11132                 "flow director's mask on NIC",
11133         .tokens = {
11134                 (void *)&cmd_flow_director_mask,
11135                 (void *)&cmd_flow_director_mask_port_id,
11136                 (void *)&cmd_flow_director_mask_mode,
11137                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11138                 (void *)&cmd_flow_director_mask_vlan,
11139                 (void *)&cmd_flow_director_mask_vlan_value,
11140                 NULL,
11141         },
11142 };
11143
11144 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11145         .f = cmd_flow_director_mask_parsed,
11146         .data = NULL,
11147         .help_str = "flow_director_mask ... : Set tunnel mode "
11148                 "flow director's mask on NIC",
11149         .tokens = {
11150                 (void *)&cmd_flow_director_mask,
11151                 (void *)&cmd_flow_director_mask_port_id,
11152                 (void *)&cmd_flow_director_mask_mode,
11153                 (void *)&cmd_flow_director_mask_mode_tunnel,
11154                 (void *)&cmd_flow_director_mask_vlan,
11155                 (void *)&cmd_flow_director_mask_vlan_value,
11156                 (void *)&cmd_flow_director_mask_mac,
11157                 (void *)&cmd_flow_director_mask_mac_value,
11158                 (void *)&cmd_flow_director_mask_tunnel_type,
11159                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11160                 (void *)&cmd_flow_director_mask_tunnel_id,
11161                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11162                 NULL,
11163         },
11164 };
11165
11166 /* *** deal with flow director mask on flexible payload *** */
11167 struct cmd_flow_director_flex_mask_result {
11168         cmdline_fixed_string_t flow_director_flexmask;
11169         portid_t port_id;
11170         cmdline_fixed_string_t flow;
11171         cmdline_fixed_string_t flow_type;
11172         cmdline_fixed_string_t mask;
11173 };
11174
11175 static void
11176 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11177                           __attribute__((unused)) struct cmdline *cl,
11178                           __attribute__((unused)) void *data)
11179 {
11180         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11181         struct rte_eth_fdir_info fdir_info;
11182         struct rte_eth_fdir_flex_mask flex_mask;
11183         struct rte_port *port;
11184         uint64_t flow_type_mask;
11185         uint16_t i;
11186         int ret;
11187
11188         port = &ports[res->port_id];
11189         /** Check if the port is not started **/
11190         if (port->port_status != RTE_PORT_STOPPED) {
11191                 printf("Please stop port %d first\n", res->port_id);
11192                 return;
11193         }
11194
11195         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11196         ret = parse_flexbytes(res->mask,
11197                         flex_mask.mask,
11198                         RTE_ETH_FDIR_MAX_FLEXLEN);
11199         if (ret < 0) {
11200                 printf("error: Cannot parse mask input.\n");
11201                 return;
11202         }
11203
11204         memset(&fdir_info, 0, sizeof(fdir_info));
11205         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11206                                 RTE_ETH_FILTER_INFO, &fdir_info);
11207         if (ret < 0) {
11208                 printf("Cannot get FDir filter info\n");
11209                 return;
11210         }
11211
11212         if (!strcmp(res->flow_type, "none")) {
11213                 /* means don't specify the flow type */
11214                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11215                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11216                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11217                                0, sizeof(struct rte_eth_fdir_flex_mask));
11218                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11219                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11220                                  &flex_mask,
11221                                  sizeof(struct rte_eth_fdir_flex_mask));
11222                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11223                 return;
11224         }
11225         flow_type_mask = fdir_info.flow_types_mask[0];
11226         if (!strcmp(res->flow_type, "all")) {
11227                 if (!flow_type_mask) {
11228                         printf("No flow type supported\n");
11229                         return;
11230                 }
11231                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11232                         if (flow_type_mask & (1ULL << i)) {
11233                                 flex_mask.flow_type = i;
11234                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11235                         }
11236                 }
11237                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11238                 return;
11239         }
11240         flex_mask.flow_type = str2flowtype(res->flow_type);
11241         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11242                 printf("Flow type %s not supported on port %d\n",
11243                                 res->flow_type, res->port_id);
11244                 return;
11245         }
11246         fdir_set_flex_mask(res->port_id, &flex_mask);
11247         cmd_reconfig_device_queue(res->port_id, 1, 1);
11248 }
11249
11250 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11251         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11252                                  flow_director_flexmask,
11253                                  "flow_director_flex_mask");
11254 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11255         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11256                               port_id, UINT16);
11257 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11258         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11259                                  flow, "flow");
11260 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11261         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11262                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11263                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11264 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11265         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11266                                  mask, NULL);
11267
11268 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11269         .f = cmd_flow_director_flex_mask_parsed,
11270         .data = NULL,
11271         .help_str = "flow_director_flex_mask ... : "
11272                 "Set flow director's flex mask on NIC",
11273         .tokens = {
11274                 (void *)&cmd_flow_director_flexmask,
11275                 (void *)&cmd_flow_director_flexmask_port_id,
11276                 (void *)&cmd_flow_director_flexmask_flow,
11277                 (void *)&cmd_flow_director_flexmask_flow_type,
11278                 (void *)&cmd_flow_director_flexmask_mask,
11279                 NULL,
11280         },
11281 };
11282
11283 /* *** deal with flow director flexible payload configuration *** */
11284 struct cmd_flow_director_flexpayload_result {
11285         cmdline_fixed_string_t flow_director_flexpayload;
11286         portid_t port_id;
11287         cmdline_fixed_string_t payload_layer;
11288         cmdline_fixed_string_t payload_cfg;
11289 };
11290
11291 static inline int
11292 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11293 {
11294         char s[256];
11295         const char *p, *p0 = q_arg;
11296         char *end;
11297         unsigned long int_fld;
11298         char *str_fld[max_num];
11299         int i;
11300         unsigned size;
11301         int ret = -1;
11302
11303         p = strchr(p0, '(');
11304         if (p == NULL)
11305                 return -1;
11306         ++p;
11307         p0 = strchr(p, ')');
11308         if (p0 == NULL)
11309                 return -1;
11310
11311         size = p0 - p;
11312         if (size >= sizeof(s))
11313                 return -1;
11314
11315         snprintf(s, sizeof(s), "%.*s", size, p);
11316         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11317         if (ret < 0 || ret > max_num)
11318                 return -1;
11319         for (i = 0; i < ret; i++) {
11320                 errno = 0;
11321                 int_fld = strtoul(str_fld[i], &end, 0);
11322                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11323                         return -1;
11324                 offsets[i] = (uint16_t)int_fld;
11325         }
11326         return ret;
11327 }
11328
11329 static void
11330 cmd_flow_director_flxpld_parsed(void *parsed_result,
11331                           __attribute__((unused)) struct cmdline *cl,
11332                           __attribute__((unused)) void *data)
11333 {
11334         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11335         struct rte_eth_flex_payload_cfg flex_cfg;
11336         struct rte_port *port;
11337         int ret = 0;
11338
11339         port = &ports[res->port_id];
11340         /** Check if the port is not started **/
11341         if (port->port_status != RTE_PORT_STOPPED) {
11342                 printf("Please stop port %d first\n", res->port_id);
11343                 return;
11344         }
11345
11346         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11347
11348         if (!strcmp(res->payload_layer, "raw"))
11349                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11350         else if (!strcmp(res->payload_layer, "l2"))
11351                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11352         else if (!strcmp(res->payload_layer, "l3"))
11353                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11354         else if (!strcmp(res->payload_layer, "l4"))
11355                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11356
11357         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11358                             RTE_ETH_FDIR_MAX_FLEXLEN);
11359         if (ret < 0) {
11360                 printf("error: Cannot parse flex payload input.\n");
11361                 return;
11362         }
11363
11364         fdir_set_flex_payload(res->port_id, &flex_cfg);
11365         cmd_reconfig_device_queue(res->port_id, 1, 1);
11366 }
11367
11368 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11369         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11370                                  flow_director_flexpayload,
11371                                  "flow_director_flex_payload");
11372 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11373         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11374                               port_id, UINT16);
11375 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11376         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11377                                  payload_layer, "raw#l2#l3#l4");
11378 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11379         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11380                                  payload_cfg, NULL);
11381
11382 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11383         .f = cmd_flow_director_flxpld_parsed,
11384         .data = NULL,
11385         .help_str = "flow_director_flexpayload ... : "
11386                 "Set flow director's flex payload on NIC",
11387         .tokens = {
11388                 (void *)&cmd_flow_director_flexpayload,
11389                 (void *)&cmd_flow_director_flexpayload_port_id,
11390                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11391                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11392                 NULL,
11393         },
11394 };
11395
11396 /* Generic flow interface command. */
11397 extern cmdline_parse_inst_t cmd_flow;
11398
11399 /* *** Classification Filters Control *** */
11400 /* *** Get symmetric hash enable per port *** */
11401 struct cmd_get_sym_hash_ena_per_port_result {
11402         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11403         portid_t port_id;
11404 };
11405
11406 static void
11407 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11408                                  __rte_unused struct cmdline *cl,
11409                                  __rte_unused void *data)
11410 {
11411         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11412         struct rte_eth_hash_filter_info info;
11413         int ret;
11414
11415         if (rte_eth_dev_filter_supported(res->port_id,
11416                                 RTE_ETH_FILTER_HASH) < 0) {
11417                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11418                                                         res->port_id);
11419                 return;
11420         }
11421
11422         memset(&info, 0, sizeof(info));
11423         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11424         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11425                                                 RTE_ETH_FILTER_GET, &info);
11426
11427         if (ret < 0) {
11428                 printf("Cannot get symmetric hash enable per port "
11429                                         "on port %u\n", res->port_id);
11430                 return;
11431         }
11432
11433         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11434                                 "enabled" : "disabled", res->port_id);
11435 }
11436
11437 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11438         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11439                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11440 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11441         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11442                 port_id, UINT16);
11443
11444 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11445         .f = cmd_get_sym_hash_per_port_parsed,
11446         .data = NULL,
11447         .help_str = "get_sym_hash_ena_per_port <port_id>",
11448         .tokens = {
11449                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11450                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11451                 NULL,
11452         },
11453 };
11454
11455 /* *** Set symmetric hash enable per port *** */
11456 struct cmd_set_sym_hash_ena_per_port_result {
11457         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11458         cmdline_fixed_string_t enable;
11459         portid_t port_id;
11460 };
11461
11462 static void
11463 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11464                                  __rte_unused struct cmdline *cl,
11465                                  __rte_unused void *data)
11466 {
11467         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11468         struct rte_eth_hash_filter_info info;
11469         int ret;
11470
11471         if (rte_eth_dev_filter_supported(res->port_id,
11472                                 RTE_ETH_FILTER_HASH) < 0) {
11473                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11474                                                         res->port_id);
11475                 return;
11476         }
11477
11478         memset(&info, 0, sizeof(info));
11479         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11480         if (!strcmp(res->enable, "enable"))
11481                 info.info.enable = 1;
11482         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11483                                         RTE_ETH_FILTER_SET, &info);
11484         if (ret < 0) {
11485                 printf("Cannot set symmetric hash enable per port on "
11486                                         "port %u\n", res->port_id);
11487                 return;
11488         }
11489         printf("Symmetric hash has been set to %s on port %u\n",
11490                                         res->enable, res->port_id);
11491 }
11492
11493 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11494         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11495                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11496 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11497         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11498                 port_id, UINT16);
11499 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11500         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11501                 enable, "enable#disable");
11502
11503 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11504         .f = cmd_set_sym_hash_per_port_parsed,
11505         .data = NULL,
11506         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11507         .tokens = {
11508                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11509                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11510                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11511                 NULL,
11512         },
11513 };
11514
11515 /* Get global config of hash function */
11516 struct cmd_get_hash_global_config_result {
11517         cmdline_fixed_string_t get_hash_global_config;
11518         portid_t port_id;
11519 };
11520
11521 static char *
11522 flowtype_to_str(uint16_t ftype)
11523 {
11524         uint16_t i;
11525         static struct {
11526                 char str[16];
11527                 uint16_t ftype;
11528         } ftype_table[] = {
11529                 {"ipv4", RTE_ETH_FLOW_IPV4},
11530                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11531                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11532                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11533                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11534                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11535                 {"ipv6", RTE_ETH_FLOW_IPV6},
11536                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11537                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11538                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11539                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11540                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11541                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11542                 {"port", RTE_ETH_FLOW_PORT},
11543                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11544                 {"geneve", RTE_ETH_FLOW_GENEVE},
11545                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11546         };
11547
11548         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11549                 if (ftype_table[i].ftype == ftype)
11550                         return ftype_table[i].str;
11551         }
11552
11553         return NULL;
11554 }
11555
11556 static void
11557 cmd_get_hash_global_config_parsed(void *parsed_result,
11558                                   __rte_unused struct cmdline *cl,
11559                                   __rte_unused void *data)
11560 {
11561         struct cmd_get_hash_global_config_result *res = parsed_result;
11562         struct rte_eth_hash_filter_info info;
11563         uint32_t idx, offset;
11564         uint16_t i;
11565         char *str;
11566         int ret;
11567
11568         if (rte_eth_dev_filter_supported(res->port_id,
11569                         RTE_ETH_FILTER_HASH) < 0) {
11570                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11571                                                         res->port_id);
11572                 return;
11573         }
11574
11575         memset(&info, 0, sizeof(info));
11576         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11577         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11578                                         RTE_ETH_FILTER_GET, &info);
11579         if (ret < 0) {
11580                 printf("Cannot get hash global configurations by port %d\n",
11581                                                         res->port_id);
11582                 return;
11583         }
11584
11585         switch (info.info.global_conf.hash_func) {
11586         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11587                 printf("Hash function is Toeplitz\n");
11588                 break;
11589         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11590                 printf("Hash function is Simple XOR\n");
11591                 break;
11592         default:
11593                 printf("Unknown hash function\n");
11594                 break;
11595         }
11596
11597         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11598                 idx = i / UINT64_BIT;
11599                 offset = i % UINT64_BIT;
11600                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11601                                                 (1ULL << offset)))
11602                         continue;
11603                 str = flowtype_to_str(i);
11604                 if (!str)
11605                         continue;
11606                 printf("Symmetric hash is %s globally for flow type %s "
11607                                                         "by port %d\n",
11608                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11609                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11610                                                         res->port_id);
11611         }
11612 }
11613
11614 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11615         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11616                 get_hash_global_config, "get_hash_global_config");
11617 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11618         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11619                 port_id, UINT16);
11620
11621 cmdline_parse_inst_t cmd_get_hash_global_config = {
11622         .f = cmd_get_hash_global_config_parsed,
11623         .data = NULL,
11624         .help_str = "get_hash_global_config <port_id>",
11625         .tokens = {
11626                 (void *)&cmd_get_hash_global_config_all,
11627                 (void *)&cmd_get_hash_global_config_port_id,
11628                 NULL,
11629         },
11630 };
11631
11632 /* Set global config of hash function */
11633 struct cmd_set_hash_global_config_result {
11634         cmdline_fixed_string_t set_hash_global_config;
11635         portid_t port_id;
11636         cmdline_fixed_string_t hash_func;
11637         cmdline_fixed_string_t flow_type;
11638         cmdline_fixed_string_t enable;
11639 };
11640
11641 static void
11642 cmd_set_hash_global_config_parsed(void *parsed_result,
11643                                   __rte_unused struct cmdline *cl,
11644                                   __rte_unused void *data)
11645 {
11646         struct cmd_set_hash_global_config_result *res = parsed_result;
11647         struct rte_eth_hash_filter_info info;
11648         uint32_t ftype, idx, offset;
11649         int ret;
11650
11651         if (rte_eth_dev_filter_supported(res->port_id,
11652                                 RTE_ETH_FILTER_HASH) < 0) {
11653                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11654                                                         res->port_id);
11655                 return;
11656         }
11657         memset(&info, 0, sizeof(info));
11658         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11659         if (!strcmp(res->hash_func, "toeplitz"))
11660                 info.info.global_conf.hash_func =
11661                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11662         else if (!strcmp(res->hash_func, "simple_xor"))
11663                 info.info.global_conf.hash_func =
11664                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11665         else if (!strcmp(res->hash_func, "default"))
11666                 info.info.global_conf.hash_func =
11667                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11668
11669         ftype = str2flowtype(res->flow_type);
11670         idx = ftype / UINT64_BIT;
11671         offset = ftype % UINT64_BIT;
11672         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11673         if (!strcmp(res->enable, "enable"))
11674                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11675                                                 (1ULL << offset);
11676         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11677                                         RTE_ETH_FILTER_SET, &info);
11678         if (ret < 0)
11679                 printf("Cannot set global hash configurations by port %d\n",
11680                                                         res->port_id);
11681         else
11682                 printf("Global hash configurations have been set "
11683                         "succcessfully by port %d\n", res->port_id);
11684 }
11685
11686 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11687         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11688                 set_hash_global_config, "set_hash_global_config");
11689 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11690         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11691                 port_id, UINT16);
11692 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11693         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11694                 hash_func, "toeplitz#simple_xor#default");
11695 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11696         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11697                 flow_type,
11698                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11699                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11700 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11701         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11702                 enable, "enable#disable");
11703
11704 cmdline_parse_inst_t cmd_set_hash_global_config = {
11705         .f = cmd_set_hash_global_config_parsed,
11706         .data = NULL,
11707         .help_str = "set_hash_global_config <port_id> "
11708                 "toeplitz|simple_xor|default "
11709                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11710                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11711                 "l2_payload enable|disable",
11712         .tokens = {
11713                 (void *)&cmd_set_hash_global_config_all,
11714                 (void *)&cmd_set_hash_global_config_port_id,
11715                 (void *)&cmd_set_hash_global_config_hash_func,
11716                 (void *)&cmd_set_hash_global_config_flow_type,
11717                 (void *)&cmd_set_hash_global_config_enable,
11718                 NULL,
11719         },
11720 };
11721
11722 /* Set hash input set */
11723 struct cmd_set_hash_input_set_result {
11724         cmdline_fixed_string_t set_hash_input_set;
11725         portid_t port_id;
11726         cmdline_fixed_string_t flow_type;
11727         cmdline_fixed_string_t inset_field;
11728         cmdline_fixed_string_t select;
11729 };
11730
11731 static enum rte_eth_input_set_field
11732 str2inset(char *string)
11733 {
11734         uint16_t i;
11735
11736         static const struct {
11737                 char str[32];
11738                 enum rte_eth_input_set_field inset;
11739         } inset_table[] = {
11740                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11741                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11742                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11743                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11744                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11745                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11746                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11747                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11748                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11749                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11750                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11751                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11752                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11753                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11754                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11755                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11756                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11757                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11758                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11759                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11760                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11761                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11762                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11763                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11764                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11765                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11766                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11767                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11768                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11769                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11770                 {"none", RTE_ETH_INPUT_SET_NONE},
11771         };
11772
11773         for (i = 0; i < RTE_DIM(inset_table); i++) {
11774                 if (!strcmp(string, inset_table[i].str))
11775                         return inset_table[i].inset;
11776         }
11777
11778         return RTE_ETH_INPUT_SET_UNKNOWN;
11779 }
11780
11781 static void
11782 cmd_set_hash_input_set_parsed(void *parsed_result,
11783                               __rte_unused struct cmdline *cl,
11784                               __rte_unused void *data)
11785 {
11786         struct cmd_set_hash_input_set_result *res = parsed_result;
11787         struct rte_eth_hash_filter_info info;
11788
11789         memset(&info, 0, sizeof(info));
11790         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11791         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11792         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11793         info.info.input_set_conf.inset_size = 1;
11794         if (!strcmp(res->select, "select"))
11795                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11796         else if (!strcmp(res->select, "add"))
11797                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11798         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11799                                 RTE_ETH_FILTER_SET, &info);
11800 }
11801
11802 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11803         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11804                 set_hash_input_set, "set_hash_input_set");
11805 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11806         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11807                 port_id, UINT16);
11808 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11809         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11810                 flow_type, NULL);
11811 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11812         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11813                 inset_field,
11814                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11815                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11816                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11817                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11818                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11819                 "fld-8th#none");
11820 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11821         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11822                 select, "select#add");
11823
11824 cmdline_parse_inst_t cmd_set_hash_input_set = {
11825         .f = cmd_set_hash_input_set_parsed,
11826         .data = NULL,
11827         .help_str = "set_hash_input_set <port_id> "
11828         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11829         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11830         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11831         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11832         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11833         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11834         "fld-7th|fld-8th|none select|add",
11835         .tokens = {
11836                 (void *)&cmd_set_hash_input_set_cmd,
11837                 (void *)&cmd_set_hash_input_set_port_id,
11838                 (void *)&cmd_set_hash_input_set_flow_type,
11839                 (void *)&cmd_set_hash_input_set_field,
11840                 (void *)&cmd_set_hash_input_set_select,
11841                 NULL,
11842         },
11843 };
11844
11845 /* Set flow director input set */
11846 struct cmd_set_fdir_input_set_result {
11847         cmdline_fixed_string_t set_fdir_input_set;
11848         portid_t port_id;
11849         cmdline_fixed_string_t flow_type;
11850         cmdline_fixed_string_t inset_field;
11851         cmdline_fixed_string_t select;
11852 };
11853
11854 static void
11855 cmd_set_fdir_input_set_parsed(void *parsed_result,
11856         __rte_unused struct cmdline *cl,
11857         __rte_unused void *data)
11858 {
11859         struct cmd_set_fdir_input_set_result *res = parsed_result;
11860         struct rte_eth_fdir_filter_info info;
11861
11862         memset(&info, 0, sizeof(info));
11863         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11864         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11865         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11866         info.info.input_set_conf.inset_size = 1;
11867         if (!strcmp(res->select, "select"))
11868                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11869         else if (!strcmp(res->select, "add"))
11870                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11871         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11872                 RTE_ETH_FILTER_SET, &info);
11873 }
11874
11875 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11876         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11877         set_fdir_input_set, "set_fdir_input_set");
11878 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11879         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11880         port_id, UINT16);
11881 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11882         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11883         flow_type,
11884         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11885         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11886 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11887         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11888         inset_field,
11889         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11890         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11891         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11892         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11893         "sctp-veri-tag#none");
11894 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11895         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11896         select, "select#add");
11897
11898 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11899         .f = cmd_set_fdir_input_set_parsed,
11900         .data = NULL,
11901         .help_str = "set_fdir_input_set <port_id> "
11902         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11903         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11904         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11905         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11906         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11907         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11908         "sctp-veri-tag|none select|add",
11909         .tokens = {
11910                 (void *)&cmd_set_fdir_input_set_cmd,
11911                 (void *)&cmd_set_fdir_input_set_port_id,
11912                 (void *)&cmd_set_fdir_input_set_flow_type,
11913                 (void *)&cmd_set_fdir_input_set_field,
11914                 (void *)&cmd_set_fdir_input_set_select,
11915                 NULL,
11916         },
11917 };
11918
11919 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11920 struct cmd_mcast_addr_result {
11921         cmdline_fixed_string_t mcast_addr_cmd;
11922         cmdline_fixed_string_t what;
11923         uint16_t port_num;
11924         struct ether_addr mc_addr;
11925 };
11926
11927 static void cmd_mcast_addr_parsed(void *parsed_result,
11928                 __attribute__((unused)) struct cmdline *cl,
11929                 __attribute__((unused)) void *data)
11930 {
11931         struct cmd_mcast_addr_result *res = parsed_result;
11932
11933         if (!is_multicast_ether_addr(&res->mc_addr)) {
11934                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11935                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11936                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11937                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11938                 return;
11939         }
11940         if (strcmp(res->what, "add") == 0)
11941                 mcast_addr_add(res->port_num, &res->mc_addr);
11942         else
11943                 mcast_addr_remove(res->port_num, &res->mc_addr);
11944 }
11945
11946 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11947         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11948                                  mcast_addr_cmd, "mcast_addr");
11949 cmdline_parse_token_string_t cmd_mcast_addr_what =
11950         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11951                                  "add#remove");
11952 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11953         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11954 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11955         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11956
11957 cmdline_parse_inst_t cmd_mcast_addr = {
11958         .f = cmd_mcast_addr_parsed,
11959         .data = (void *)0,
11960         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11961                 "Add/Remove multicast MAC address on port_id",
11962         .tokens = {
11963                 (void *)&cmd_mcast_addr_cmd,
11964                 (void *)&cmd_mcast_addr_what,
11965                 (void *)&cmd_mcast_addr_portnum,
11966                 (void *)&cmd_mcast_addr_addr,
11967                 NULL,
11968         },
11969 };
11970
11971 /* l2 tunnel config
11972  * only support E-tag now.
11973  */
11974
11975 /* Ether type config */
11976 struct cmd_config_l2_tunnel_eth_type_result {
11977         cmdline_fixed_string_t port;
11978         cmdline_fixed_string_t config;
11979         cmdline_fixed_string_t all;
11980         portid_t id;
11981         cmdline_fixed_string_t l2_tunnel;
11982         cmdline_fixed_string_t l2_tunnel_type;
11983         cmdline_fixed_string_t eth_type;
11984         uint16_t eth_type_val;
11985 };
11986
11987 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11988         TOKEN_STRING_INITIALIZER
11989                 (struct cmd_config_l2_tunnel_eth_type_result,
11990                  port, "port");
11991 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11992         TOKEN_STRING_INITIALIZER
11993                 (struct cmd_config_l2_tunnel_eth_type_result,
11994                  config, "config");
11995 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11996         TOKEN_STRING_INITIALIZER
11997                 (struct cmd_config_l2_tunnel_eth_type_result,
11998                  all, "all");
11999 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12000         TOKEN_NUM_INITIALIZER
12001                 (struct cmd_config_l2_tunnel_eth_type_result,
12002                  id, UINT16);
12003 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12004         TOKEN_STRING_INITIALIZER
12005                 (struct cmd_config_l2_tunnel_eth_type_result,
12006                  l2_tunnel, "l2-tunnel");
12007 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12008         TOKEN_STRING_INITIALIZER
12009                 (struct cmd_config_l2_tunnel_eth_type_result,
12010                  l2_tunnel_type, "E-tag");
12011 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12012         TOKEN_STRING_INITIALIZER
12013                 (struct cmd_config_l2_tunnel_eth_type_result,
12014                  eth_type, "ether-type");
12015 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12016         TOKEN_NUM_INITIALIZER
12017                 (struct cmd_config_l2_tunnel_eth_type_result,
12018                  eth_type_val, UINT16);
12019
12020 static enum rte_eth_tunnel_type
12021 str2fdir_l2_tunnel_type(char *string)
12022 {
12023         uint32_t i = 0;
12024
12025         static const struct {
12026                 char str[32];
12027                 enum rte_eth_tunnel_type type;
12028         } l2_tunnel_type_str[] = {
12029                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12030         };
12031
12032         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12033                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12034                         return l2_tunnel_type_str[i].type;
12035         }
12036         return RTE_TUNNEL_TYPE_NONE;
12037 }
12038
12039 /* ether type config for all ports */
12040 static void
12041 cmd_config_l2_tunnel_eth_type_all_parsed
12042         (void *parsed_result,
12043          __attribute__((unused)) struct cmdline *cl,
12044          __attribute__((unused)) void *data)
12045 {
12046         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12047         struct rte_eth_l2_tunnel_conf entry;
12048         portid_t pid;
12049
12050         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12051         entry.ether_type = res->eth_type_val;
12052
12053         RTE_ETH_FOREACH_DEV(pid) {
12054                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12055         }
12056 }
12057
12058 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12059         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12060         .data = NULL,
12061         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12062         .tokens = {
12063                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12064                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12065                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12066                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12067                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12068                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12069                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12070                 NULL,
12071         },
12072 };
12073
12074 /* ether type config for a specific port */
12075 static void
12076 cmd_config_l2_tunnel_eth_type_specific_parsed(
12077         void *parsed_result,
12078         __attribute__((unused)) struct cmdline *cl,
12079         __attribute__((unused)) void *data)
12080 {
12081         struct cmd_config_l2_tunnel_eth_type_result *res =
12082                  parsed_result;
12083         struct rte_eth_l2_tunnel_conf entry;
12084
12085         if (port_id_is_invalid(res->id, ENABLED_WARN))
12086                 return;
12087
12088         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12089         entry.ether_type = res->eth_type_val;
12090
12091         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12092 }
12093
12094 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12095         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12096         .data = NULL,
12097         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12098         .tokens = {
12099                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12100                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12101                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12102                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12103                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12104                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12105                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12106                 NULL,
12107         },
12108 };
12109
12110 /* Enable/disable l2 tunnel */
12111 struct cmd_config_l2_tunnel_en_dis_result {
12112         cmdline_fixed_string_t port;
12113         cmdline_fixed_string_t config;
12114         cmdline_fixed_string_t all;
12115         portid_t id;
12116         cmdline_fixed_string_t l2_tunnel;
12117         cmdline_fixed_string_t l2_tunnel_type;
12118         cmdline_fixed_string_t en_dis;
12119 };
12120
12121 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12122         TOKEN_STRING_INITIALIZER
12123                 (struct cmd_config_l2_tunnel_en_dis_result,
12124                  port, "port");
12125 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12126         TOKEN_STRING_INITIALIZER
12127                 (struct cmd_config_l2_tunnel_en_dis_result,
12128                  config, "config");
12129 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12130         TOKEN_STRING_INITIALIZER
12131                 (struct cmd_config_l2_tunnel_en_dis_result,
12132                  all, "all");
12133 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12134         TOKEN_NUM_INITIALIZER
12135                 (struct cmd_config_l2_tunnel_en_dis_result,
12136                  id, UINT16);
12137 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12138         TOKEN_STRING_INITIALIZER
12139                 (struct cmd_config_l2_tunnel_en_dis_result,
12140                  l2_tunnel, "l2-tunnel");
12141 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12142         TOKEN_STRING_INITIALIZER
12143                 (struct cmd_config_l2_tunnel_en_dis_result,
12144                  l2_tunnel_type, "E-tag");
12145 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12146         TOKEN_STRING_INITIALIZER
12147                 (struct cmd_config_l2_tunnel_en_dis_result,
12148                  en_dis, "enable#disable");
12149
12150 /* enable/disable l2 tunnel for all ports */
12151 static void
12152 cmd_config_l2_tunnel_en_dis_all_parsed(
12153         void *parsed_result,
12154         __attribute__((unused)) struct cmdline *cl,
12155         __attribute__((unused)) void *data)
12156 {
12157         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12158         struct rte_eth_l2_tunnel_conf entry;
12159         portid_t pid;
12160         uint8_t en;
12161
12162         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12163
12164         if (!strcmp("enable", res->en_dis))
12165                 en = 1;
12166         else
12167                 en = 0;
12168
12169         RTE_ETH_FOREACH_DEV(pid) {
12170                 rte_eth_dev_l2_tunnel_offload_set(pid,
12171                                                   &entry,
12172                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12173                                                   en);
12174         }
12175 }
12176
12177 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12178         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12179         .data = NULL,
12180         .help_str = "port config all l2-tunnel E-tag enable|disable",
12181         .tokens = {
12182                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12183                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12184                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12185                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12186                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12187                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12188                 NULL,
12189         },
12190 };
12191
12192 /* enable/disable l2 tunnel for a port */
12193 static void
12194 cmd_config_l2_tunnel_en_dis_specific_parsed(
12195         void *parsed_result,
12196         __attribute__((unused)) struct cmdline *cl,
12197         __attribute__((unused)) void *data)
12198 {
12199         struct cmd_config_l2_tunnel_en_dis_result *res =
12200                 parsed_result;
12201         struct rte_eth_l2_tunnel_conf entry;
12202
12203         if (port_id_is_invalid(res->id, ENABLED_WARN))
12204                 return;
12205
12206         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12207
12208         if (!strcmp("enable", res->en_dis))
12209                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12210                                                   &entry,
12211                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12212                                                   1);
12213         else
12214                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12215                                                   &entry,
12216                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12217                                                   0);
12218 }
12219
12220 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12221         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12222         .data = NULL,
12223         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12224         .tokens = {
12225                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12226                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12227                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12228                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12229                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12230                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12231                 NULL,
12232         },
12233 };
12234
12235 /* E-tag configuration */
12236
12237 /* Common result structure for all E-tag configuration */
12238 struct cmd_config_e_tag_result {
12239         cmdline_fixed_string_t e_tag;
12240         cmdline_fixed_string_t set;
12241         cmdline_fixed_string_t insertion;
12242         cmdline_fixed_string_t stripping;
12243         cmdline_fixed_string_t forwarding;
12244         cmdline_fixed_string_t filter;
12245         cmdline_fixed_string_t add;
12246         cmdline_fixed_string_t del;
12247         cmdline_fixed_string_t on;
12248         cmdline_fixed_string_t off;
12249         cmdline_fixed_string_t on_off;
12250         cmdline_fixed_string_t port_tag_id;
12251         uint32_t port_tag_id_val;
12252         cmdline_fixed_string_t e_tag_id;
12253         uint16_t e_tag_id_val;
12254         cmdline_fixed_string_t dst_pool;
12255         uint8_t dst_pool_val;
12256         cmdline_fixed_string_t port;
12257         portid_t port_id;
12258         cmdline_fixed_string_t vf;
12259         uint8_t vf_id;
12260 };
12261
12262 /* Common CLI fields for all E-tag configuration */
12263 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12264         TOKEN_STRING_INITIALIZER
12265                 (struct cmd_config_e_tag_result,
12266                  e_tag, "E-tag");
12267 cmdline_parse_token_string_t cmd_config_e_tag_set =
12268         TOKEN_STRING_INITIALIZER
12269                 (struct cmd_config_e_tag_result,
12270                  set, "set");
12271 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12272         TOKEN_STRING_INITIALIZER
12273                 (struct cmd_config_e_tag_result,
12274                  insertion, "insertion");
12275 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12276         TOKEN_STRING_INITIALIZER
12277                 (struct cmd_config_e_tag_result,
12278                  stripping, "stripping");
12279 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12280         TOKEN_STRING_INITIALIZER
12281                 (struct cmd_config_e_tag_result,
12282                  forwarding, "forwarding");
12283 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12284         TOKEN_STRING_INITIALIZER
12285                 (struct cmd_config_e_tag_result,
12286                  filter, "filter");
12287 cmdline_parse_token_string_t cmd_config_e_tag_add =
12288         TOKEN_STRING_INITIALIZER
12289                 (struct cmd_config_e_tag_result,
12290                  add, "add");
12291 cmdline_parse_token_string_t cmd_config_e_tag_del =
12292         TOKEN_STRING_INITIALIZER
12293                 (struct cmd_config_e_tag_result,
12294                  del, "del");
12295 cmdline_parse_token_string_t cmd_config_e_tag_on =
12296         TOKEN_STRING_INITIALIZER
12297                 (struct cmd_config_e_tag_result,
12298                  on, "on");
12299 cmdline_parse_token_string_t cmd_config_e_tag_off =
12300         TOKEN_STRING_INITIALIZER
12301                 (struct cmd_config_e_tag_result,
12302                  off, "off");
12303 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12304         TOKEN_STRING_INITIALIZER
12305                 (struct cmd_config_e_tag_result,
12306                  on_off, "on#off");
12307 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12308         TOKEN_STRING_INITIALIZER
12309                 (struct cmd_config_e_tag_result,
12310                  port_tag_id, "port-tag-id");
12311 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12312         TOKEN_NUM_INITIALIZER
12313                 (struct cmd_config_e_tag_result,
12314                  port_tag_id_val, UINT32);
12315 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12316         TOKEN_STRING_INITIALIZER
12317                 (struct cmd_config_e_tag_result,
12318                  e_tag_id, "e-tag-id");
12319 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12320         TOKEN_NUM_INITIALIZER
12321                 (struct cmd_config_e_tag_result,
12322                  e_tag_id_val, UINT16);
12323 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12324         TOKEN_STRING_INITIALIZER
12325                 (struct cmd_config_e_tag_result,
12326                  dst_pool, "dst-pool");
12327 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12328         TOKEN_NUM_INITIALIZER
12329                 (struct cmd_config_e_tag_result,
12330                  dst_pool_val, UINT8);
12331 cmdline_parse_token_string_t cmd_config_e_tag_port =
12332         TOKEN_STRING_INITIALIZER
12333                 (struct cmd_config_e_tag_result,
12334                  port, "port");
12335 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12336         TOKEN_NUM_INITIALIZER
12337                 (struct cmd_config_e_tag_result,
12338                  port_id, UINT16);
12339 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12340         TOKEN_STRING_INITIALIZER
12341                 (struct cmd_config_e_tag_result,
12342                  vf, "vf");
12343 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12344         TOKEN_NUM_INITIALIZER
12345                 (struct cmd_config_e_tag_result,
12346                  vf_id, UINT8);
12347
12348 /* E-tag insertion configuration */
12349 static void
12350 cmd_config_e_tag_insertion_en_parsed(
12351         void *parsed_result,
12352         __attribute__((unused)) struct cmdline *cl,
12353         __attribute__((unused)) void *data)
12354 {
12355         struct cmd_config_e_tag_result *res =
12356                 parsed_result;
12357         struct rte_eth_l2_tunnel_conf entry;
12358
12359         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12360                 return;
12361
12362         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12363         entry.tunnel_id = res->port_tag_id_val;
12364         entry.vf_id = res->vf_id;
12365         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12366                                           &entry,
12367                                           ETH_L2_TUNNEL_INSERTION_MASK,
12368                                           1);
12369 }
12370
12371 static void
12372 cmd_config_e_tag_insertion_dis_parsed(
12373         void *parsed_result,
12374         __attribute__((unused)) struct cmdline *cl,
12375         __attribute__((unused)) void *data)
12376 {
12377         struct cmd_config_e_tag_result *res =
12378                 parsed_result;
12379         struct rte_eth_l2_tunnel_conf entry;
12380
12381         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12382                 return;
12383
12384         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12385         entry.vf_id = res->vf_id;
12386
12387         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12388                                           &entry,
12389                                           ETH_L2_TUNNEL_INSERTION_MASK,
12390                                           0);
12391 }
12392
12393 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12394         .f = cmd_config_e_tag_insertion_en_parsed,
12395         .data = NULL,
12396         .help_str = "E-tag ... : E-tag insertion enable",
12397         .tokens = {
12398                 (void *)&cmd_config_e_tag_e_tag,
12399                 (void *)&cmd_config_e_tag_set,
12400                 (void *)&cmd_config_e_tag_insertion,
12401                 (void *)&cmd_config_e_tag_on,
12402                 (void *)&cmd_config_e_tag_port_tag_id,
12403                 (void *)&cmd_config_e_tag_port_tag_id_val,
12404                 (void *)&cmd_config_e_tag_port,
12405                 (void *)&cmd_config_e_tag_port_id,
12406                 (void *)&cmd_config_e_tag_vf,
12407                 (void *)&cmd_config_e_tag_vf_id,
12408                 NULL,
12409         },
12410 };
12411
12412 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12413         .f = cmd_config_e_tag_insertion_dis_parsed,
12414         .data = NULL,
12415         .help_str = "E-tag ... : E-tag insertion disable",
12416         .tokens = {
12417                 (void *)&cmd_config_e_tag_e_tag,
12418                 (void *)&cmd_config_e_tag_set,
12419                 (void *)&cmd_config_e_tag_insertion,
12420                 (void *)&cmd_config_e_tag_off,
12421                 (void *)&cmd_config_e_tag_port,
12422                 (void *)&cmd_config_e_tag_port_id,
12423                 (void *)&cmd_config_e_tag_vf,
12424                 (void *)&cmd_config_e_tag_vf_id,
12425                 NULL,
12426         },
12427 };
12428
12429 /* E-tag stripping configuration */
12430 static void
12431 cmd_config_e_tag_stripping_parsed(
12432         void *parsed_result,
12433         __attribute__((unused)) struct cmdline *cl,
12434         __attribute__((unused)) void *data)
12435 {
12436         struct cmd_config_e_tag_result *res =
12437                 parsed_result;
12438         struct rte_eth_l2_tunnel_conf entry;
12439
12440         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12441                 return;
12442
12443         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12444
12445         if (!strcmp(res->on_off, "on"))
12446                 rte_eth_dev_l2_tunnel_offload_set
12447                         (res->port_id,
12448                          &entry,
12449                          ETH_L2_TUNNEL_STRIPPING_MASK,
12450                          1);
12451         else
12452                 rte_eth_dev_l2_tunnel_offload_set
12453                         (res->port_id,
12454                          &entry,
12455                          ETH_L2_TUNNEL_STRIPPING_MASK,
12456                          0);
12457 }
12458
12459 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12460         .f = cmd_config_e_tag_stripping_parsed,
12461         .data = NULL,
12462         .help_str = "E-tag ... : E-tag stripping enable/disable",
12463         .tokens = {
12464                 (void *)&cmd_config_e_tag_e_tag,
12465                 (void *)&cmd_config_e_tag_set,
12466                 (void *)&cmd_config_e_tag_stripping,
12467                 (void *)&cmd_config_e_tag_on_off,
12468                 (void *)&cmd_config_e_tag_port,
12469                 (void *)&cmd_config_e_tag_port_id,
12470                 NULL,
12471         },
12472 };
12473
12474 /* E-tag forwarding configuration */
12475 static void
12476 cmd_config_e_tag_forwarding_parsed(
12477         void *parsed_result,
12478         __attribute__((unused)) struct cmdline *cl,
12479         __attribute__((unused)) void *data)
12480 {
12481         struct cmd_config_e_tag_result *res = parsed_result;
12482         struct rte_eth_l2_tunnel_conf entry;
12483
12484         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12485                 return;
12486
12487         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12488
12489         if (!strcmp(res->on_off, "on"))
12490                 rte_eth_dev_l2_tunnel_offload_set
12491                         (res->port_id,
12492                          &entry,
12493                          ETH_L2_TUNNEL_FORWARDING_MASK,
12494                          1);
12495         else
12496                 rte_eth_dev_l2_tunnel_offload_set
12497                         (res->port_id,
12498                          &entry,
12499                          ETH_L2_TUNNEL_FORWARDING_MASK,
12500                          0);
12501 }
12502
12503 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12504         .f = cmd_config_e_tag_forwarding_parsed,
12505         .data = NULL,
12506         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12507         .tokens = {
12508                 (void *)&cmd_config_e_tag_e_tag,
12509                 (void *)&cmd_config_e_tag_set,
12510                 (void *)&cmd_config_e_tag_forwarding,
12511                 (void *)&cmd_config_e_tag_on_off,
12512                 (void *)&cmd_config_e_tag_port,
12513                 (void *)&cmd_config_e_tag_port_id,
12514                 NULL,
12515         },
12516 };
12517
12518 /* E-tag filter configuration */
12519 static void
12520 cmd_config_e_tag_filter_add_parsed(
12521         void *parsed_result,
12522         __attribute__((unused)) struct cmdline *cl,
12523         __attribute__((unused)) void *data)
12524 {
12525         struct cmd_config_e_tag_result *res = parsed_result;
12526         struct rte_eth_l2_tunnel_conf entry;
12527         int ret = 0;
12528
12529         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12530                 return;
12531
12532         if (res->e_tag_id_val > 0x3fff) {
12533                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12534                 return;
12535         }
12536
12537         ret = rte_eth_dev_filter_supported(res->port_id,
12538                                            RTE_ETH_FILTER_L2_TUNNEL);
12539         if (ret < 0) {
12540                 printf("E-tag filter is not supported on port %u.\n",
12541                        res->port_id);
12542                 return;
12543         }
12544
12545         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12546         entry.tunnel_id = res->e_tag_id_val;
12547         entry.pool = res->dst_pool_val;
12548
12549         ret = rte_eth_dev_filter_ctrl(res->port_id,
12550                                       RTE_ETH_FILTER_L2_TUNNEL,
12551                                       RTE_ETH_FILTER_ADD,
12552                                       &entry);
12553         if (ret < 0)
12554                 printf("E-tag filter programming error: (%s)\n",
12555                        strerror(-ret));
12556 }
12557
12558 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12559         .f = cmd_config_e_tag_filter_add_parsed,
12560         .data = NULL,
12561         .help_str = "E-tag ... : E-tag filter add",
12562         .tokens = {
12563                 (void *)&cmd_config_e_tag_e_tag,
12564                 (void *)&cmd_config_e_tag_set,
12565                 (void *)&cmd_config_e_tag_filter,
12566                 (void *)&cmd_config_e_tag_add,
12567                 (void *)&cmd_config_e_tag_e_tag_id,
12568                 (void *)&cmd_config_e_tag_e_tag_id_val,
12569                 (void *)&cmd_config_e_tag_dst_pool,
12570                 (void *)&cmd_config_e_tag_dst_pool_val,
12571                 (void *)&cmd_config_e_tag_port,
12572                 (void *)&cmd_config_e_tag_port_id,
12573                 NULL,
12574         },
12575 };
12576
12577 static void
12578 cmd_config_e_tag_filter_del_parsed(
12579         void *parsed_result,
12580         __attribute__((unused)) struct cmdline *cl,
12581         __attribute__((unused)) void *data)
12582 {
12583         struct cmd_config_e_tag_result *res = parsed_result;
12584         struct rte_eth_l2_tunnel_conf entry;
12585         int ret = 0;
12586
12587         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12588                 return;
12589
12590         if (res->e_tag_id_val > 0x3fff) {
12591                 printf("e-tag-id must be less than 0x3fff.\n");
12592                 return;
12593         }
12594
12595         ret = rte_eth_dev_filter_supported(res->port_id,
12596                                            RTE_ETH_FILTER_L2_TUNNEL);
12597         if (ret < 0) {
12598                 printf("E-tag filter is not supported on port %u.\n",
12599                        res->port_id);
12600                 return;
12601         }
12602
12603         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12604         entry.tunnel_id = res->e_tag_id_val;
12605
12606         ret = rte_eth_dev_filter_ctrl(res->port_id,
12607                                       RTE_ETH_FILTER_L2_TUNNEL,
12608                                       RTE_ETH_FILTER_DELETE,
12609                                       &entry);
12610         if (ret < 0)
12611                 printf("E-tag filter programming error: (%s)\n",
12612                        strerror(-ret));
12613 }
12614
12615 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12616         .f = cmd_config_e_tag_filter_del_parsed,
12617         .data = NULL,
12618         .help_str = "E-tag ... : E-tag filter delete",
12619         .tokens = {
12620                 (void *)&cmd_config_e_tag_e_tag,
12621                 (void *)&cmd_config_e_tag_set,
12622                 (void *)&cmd_config_e_tag_filter,
12623                 (void *)&cmd_config_e_tag_del,
12624                 (void *)&cmd_config_e_tag_e_tag_id,
12625                 (void *)&cmd_config_e_tag_e_tag_id_val,
12626                 (void *)&cmd_config_e_tag_port,
12627                 (void *)&cmd_config_e_tag_port_id,
12628                 NULL,
12629         },
12630 };
12631
12632 /* vf vlan anti spoof configuration */
12633
12634 /* Common result structure for vf vlan anti spoof */
12635 struct cmd_vf_vlan_anti_spoof_result {
12636         cmdline_fixed_string_t set;
12637         cmdline_fixed_string_t vf;
12638         cmdline_fixed_string_t vlan;
12639         cmdline_fixed_string_t antispoof;
12640         portid_t port_id;
12641         uint32_t vf_id;
12642         cmdline_fixed_string_t on_off;
12643 };
12644
12645 /* Common CLI fields for vf vlan anti spoof enable disable */
12646 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12647         TOKEN_STRING_INITIALIZER
12648                 (struct cmd_vf_vlan_anti_spoof_result,
12649                  set, "set");
12650 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12651         TOKEN_STRING_INITIALIZER
12652                 (struct cmd_vf_vlan_anti_spoof_result,
12653                  vf, "vf");
12654 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12655         TOKEN_STRING_INITIALIZER
12656                 (struct cmd_vf_vlan_anti_spoof_result,
12657                  vlan, "vlan");
12658 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12659         TOKEN_STRING_INITIALIZER
12660                 (struct cmd_vf_vlan_anti_spoof_result,
12661                  antispoof, "antispoof");
12662 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12663         TOKEN_NUM_INITIALIZER
12664                 (struct cmd_vf_vlan_anti_spoof_result,
12665                  port_id, UINT16);
12666 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12667         TOKEN_NUM_INITIALIZER
12668                 (struct cmd_vf_vlan_anti_spoof_result,
12669                  vf_id, UINT32);
12670 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12671         TOKEN_STRING_INITIALIZER
12672                 (struct cmd_vf_vlan_anti_spoof_result,
12673                  on_off, "on#off");
12674
12675 static void
12676 cmd_set_vf_vlan_anti_spoof_parsed(
12677         void *parsed_result,
12678         __attribute__((unused)) struct cmdline *cl,
12679         __attribute__((unused)) void *data)
12680 {
12681         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12682         int ret = -ENOTSUP;
12683
12684         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12685
12686         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12687                 return;
12688
12689 #ifdef RTE_LIBRTE_IXGBE_PMD
12690         if (ret == -ENOTSUP)
12691                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12692                                 res->vf_id, is_on);
12693 #endif
12694 #ifdef RTE_LIBRTE_I40E_PMD
12695         if (ret == -ENOTSUP)
12696                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12697                                 res->vf_id, is_on);
12698 #endif
12699 #ifdef RTE_LIBRTE_BNXT_PMD
12700         if (ret == -ENOTSUP)
12701                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12702                                 res->vf_id, is_on);
12703 #endif
12704
12705         switch (ret) {
12706         case 0:
12707                 break;
12708         case -EINVAL:
12709                 printf("invalid vf_id %d\n", res->vf_id);
12710                 break;
12711         case -ENODEV:
12712                 printf("invalid port_id %d\n", res->port_id);
12713                 break;
12714         case -ENOTSUP:
12715                 printf("function not implemented\n");
12716                 break;
12717         default:
12718                 printf("programming error: (%s)\n", strerror(-ret));
12719         }
12720 }
12721
12722 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12723         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12724         .data = NULL,
12725         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12726         .tokens = {
12727                 (void *)&cmd_vf_vlan_anti_spoof_set,
12728                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12729                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12730                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12731                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12732                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12733                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12734                 NULL,
12735         },
12736 };
12737
12738 /* vf mac anti spoof configuration */
12739
12740 /* Common result structure for vf mac anti spoof */
12741 struct cmd_vf_mac_anti_spoof_result {
12742         cmdline_fixed_string_t set;
12743         cmdline_fixed_string_t vf;
12744         cmdline_fixed_string_t mac;
12745         cmdline_fixed_string_t antispoof;
12746         portid_t port_id;
12747         uint32_t vf_id;
12748         cmdline_fixed_string_t on_off;
12749 };
12750
12751 /* Common CLI fields for vf mac anti spoof enable disable */
12752 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12753         TOKEN_STRING_INITIALIZER
12754                 (struct cmd_vf_mac_anti_spoof_result,
12755                  set, "set");
12756 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12757         TOKEN_STRING_INITIALIZER
12758                 (struct cmd_vf_mac_anti_spoof_result,
12759                  vf, "vf");
12760 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12761         TOKEN_STRING_INITIALIZER
12762                 (struct cmd_vf_mac_anti_spoof_result,
12763                  mac, "mac");
12764 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12765         TOKEN_STRING_INITIALIZER
12766                 (struct cmd_vf_mac_anti_spoof_result,
12767                  antispoof, "antispoof");
12768 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12769         TOKEN_NUM_INITIALIZER
12770                 (struct cmd_vf_mac_anti_spoof_result,
12771                  port_id, UINT16);
12772 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12773         TOKEN_NUM_INITIALIZER
12774                 (struct cmd_vf_mac_anti_spoof_result,
12775                  vf_id, UINT32);
12776 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12777         TOKEN_STRING_INITIALIZER
12778                 (struct cmd_vf_mac_anti_spoof_result,
12779                  on_off, "on#off");
12780
12781 static void
12782 cmd_set_vf_mac_anti_spoof_parsed(
12783         void *parsed_result,
12784         __attribute__((unused)) struct cmdline *cl,
12785         __attribute__((unused)) void *data)
12786 {
12787         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12788         int ret = -ENOTSUP;
12789
12790         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12791
12792         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12793                 return;
12794
12795 #ifdef RTE_LIBRTE_IXGBE_PMD
12796         if (ret == -ENOTSUP)
12797                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12798                         res->vf_id, is_on);
12799 #endif
12800 #ifdef RTE_LIBRTE_I40E_PMD
12801         if (ret == -ENOTSUP)
12802                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12803                         res->vf_id, is_on);
12804 #endif
12805 #ifdef RTE_LIBRTE_BNXT_PMD
12806         if (ret == -ENOTSUP)
12807                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12808                         res->vf_id, is_on);
12809 #endif
12810
12811         switch (ret) {
12812         case 0:
12813                 break;
12814         case -EINVAL:
12815                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12816                 break;
12817         case -ENODEV:
12818                 printf("invalid port_id %d\n", res->port_id);
12819                 break;
12820         case -ENOTSUP:
12821                 printf("function not implemented\n");
12822                 break;
12823         default:
12824                 printf("programming error: (%s)\n", strerror(-ret));
12825         }
12826 }
12827
12828 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12829         .f = cmd_set_vf_mac_anti_spoof_parsed,
12830         .data = NULL,
12831         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12832         .tokens = {
12833                 (void *)&cmd_vf_mac_anti_spoof_set,
12834                 (void *)&cmd_vf_mac_anti_spoof_vf,
12835                 (void *)&cmd_vf_mac_anti_spoof_mac,
12836                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12837                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12838                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12839                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12840                 NULL,
12841         },
12842 };
12843
12844 /* vf vlan strip queue configuration */
12845
12846 /* Common result structure for vf mac anti spoof */
12847 struct cmd_vf_vlan_stripq_result {
12848         cmdline_fixed_string_t set;
12849         cmdline_fixed_string_t vf;
12850         cmdline_fixed_string_t vlan;
12851         cmdline_fixed_string_t stripq;
12852         portid_t port_id;
12853         uint16_t vf_id;
12854         cmdline_fixed_string_t on_off;
12855 };
12856
12857 /* Common CLI fields for vf vlan strip enable disable */
12858 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12859         TOKEN_STRING_INITIALIZER
12860                 (struct cmd_vf_vlan_stripq_result,
12861                  set, "set");
12862 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12863         TOKEN_STRING_INITIALIZER
12864                 (struct cmd_vf_vlan_stripq_result,
12865                  vf, "vf");
12866 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12867         TOKEN_STRING_INITIALIZER
12868                 (struct cmd_vf_vlan_stripq_result,
12869                  vlan, "vlan");
12870 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12871         TOKEN_STRING_INITIALIZER
12872                 (struct cmd_vf_vlan_stripq_result,
12873                  stripq, "stripq");
12874 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12875         TOKEN_NUM_INITIALIZER
12876                 (struct cmd_vf_vlan_stripq_result,
12877                  port_id, UINT16);
12878 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12879         TOKEN_NUM_INITIALIZER
12880                 (struct cmd_vf_vlan_stripq_result,
12881                  vf_id, UINT16);
12882 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12883         TOKEN_STRING_INITIALIZER
12884                 (struct cmd_vf_vlan_stripq_result,
12885                  on_off, "on#off");
12886
12887 static void
12888 cmd_set_vf_vlan_stripq_parsed(
12889         void *parsed_result,
12890         __attribute__((unused)) struct cmdline *cl,
12891         __attribute__((unused)) void *data)
12892 {
12893         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12894         int ret = -ENOTSUP;
12895
12896         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12897
12898         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12899                 return;
12900
12901 #ifdef RTE_LIBRTE_IXGBE_PMD
12902         if (ret == -ENOTSUP)
12903                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12904                         res->vf_id, is_on);
12905 #endif
12906 #ifdef RTE_LIBRTE_I40E_PMD
12907         if (ret == -ENOTSUP)
12908                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12909                         res->vf_id, is_on);
12910 #endif
12911 #ifdef RTE_LIBRTE_BNXT_PMD
12912         if (ret == -ENOTSUP)
12913                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12914                         res->vf_id, is_on);
12915 #endif
12916
12917         switch (ret) {
12918         case 0:
12919                 break;
12920         case -EINVAL:
12921                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12922                 break;
12923         case -ENODEV:
12924                 printf("invalid port_id %d\n", res->port_id);
12925                 break;
12926         case -ENOTSUP:
12927                 printf("function not implemented\n");
12928                 break;
12929         default:
12930                 printf("programming error: (%s)\n", strerror(-ret));
12931         }
12932 }
12933
12934 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12935         .f = cmd_set_vf_vlan_stripq_parsed,
12936         .data = NULL,
12937         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12938         .tokens = {
12939                 (void *)&cmd_vf_vlan_stripq_set,
12940                 (void *)&cmd_vf_vlan_stripq_vf,
12941                 (void *)&cmd_vf_vlan_stripq_vlan,
12942                 (void *)&cmd_vf_vlan_stripq_stripq,
12943                 (void *)&cmd_vf_vlan_stripq_port_id,
12944                 (void *)&cmd_vf_vlan_stripq_vf_id,
12945                 (void *)&cmd_vf_vlan_stripq_on_off,
12946                 NULL,
12947         },
12948 };
12949
12950 /* vf vlan insert configuration */
12951
12952 /* Common result structure for vf vlan insert */
12953 struct cmd_vf_vlan_insert_result {
12954         cmdline_fixed_string_t set;
12955         cmdline_fixed_string_t vf;
12956         cmdline_fixed_string_t vlan;
12957         cmdline_fixed_string_t insert;
12958         portid_t port_id;
12959         uint16_t vf_id;
12960         uint16_t vlan_id;
12961 };
12962
12963 /* Common CLI fields for vf vlan insert enable disable */
12964 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12965         TOKEN_STRING_INITIALIZER
12966                 (struct cmd_vf_vlan_insert_result,
12967                  set, "set");
12968 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12969         TOKEN_STRING_INITIALIZER
12970                 (struct cmd_vf_vlan_insert_result,
12971                  vf, "vf");
12972 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12973         TOKEN_STRING_INITIALIZER
12974                 (struct cmd_vf_vlan_insert_result,
12975                  vlan, "vlan");
12976 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12977         TOKEN_STRING_INITIALIZER
12978                 (struct cmd_vf_vlan_insert_result,
12979                  insert, "insert");
12980 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12981         TOKEN_NUM_INITIALIZER
12982                 (struct cmd_vf_vlan_insert_result,
12983                  port_id, UINT16);
12984 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12985         TOKEN_NUM_INITIALIZER
12986                 (struct cmd_vf_vlan_insert_result,
12987                  vf_id, UINT16);
12988 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12989         TOKEN_NUM_INITIALIZER
12990                 (struct cmd_vf_vlan_insert_result,
12991                  vlan_id, UINT16);
12992
12993 static void
12994 cmd_set_vf_vlan_insert_parsed(
12995         void *parsed_result,
12996         __attribute__((unused)) struct cmdline *cl,
12997         __attribute__((unused)) void *data)
12998 {
12999         struct cmd_vf_vlan_insert_result *res = parsed_result;
13000         int ret = -ENOTSUP;
13001
13002         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13003                 return;
13004
13005 #ifdef RTE_LIBRTE_IXGBE_PMD
13006         if (ret == -ENOTSUP)
13007                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13008                         res->vlan_id);
13009 #endif
13010 #ifdef RTE_LIBRTE_I40E_PMD
13011         if (ret == -ENOTSUP)
13012                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13013                         res->vlan_id);
13014 #endif
13015 #ifdef RTE_LIBRTE_BNXT_PMD
13016         if (ret == -ENOTSUP)
13017                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13018                         res->vlan_id);
13019 #endif
13020
13021         switch (ret) {
13022         case 0:
13023                 break;
13024         case -EINVAL:
13025                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13026                 break;
13027         case -ENODEV:
13028                 printf("invalid port_id %d\n", res->port_id);
13029                 break;
13030         case -ENOTSUP:
13031                 printf("function not implemented\n");
13032                 break;
13033         default:
13034                 printf("programming error: (%s)\n", strerror(-ret));
13035         }
13036 }
13037
13038 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13039         .f = cmd_set_vf_vlan_insert_parsed,
13040         .data = NULL,
13041         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13042         .tokens = {
13043                 (void *)&cmd_vf_vlan_insert_set,
13044                 (void *)&cmd_vf_vlan_insert_vf,
13045                 (void *)&cmd_vf_vlan_insert_vlan,
13046                 (void *)&cmd_vf_vlan_insert_insert,
13047                 (void *)&cmd_vf_vlan_insert_port_id,
13048                 (void *)&cmd_vf_vlan_insert_vf_id,
13049                 (void *)&cmd_vf_vlan_insert_vlan_id,
13050                 NULL,
13051         },
13052 };
13053
13054 /* tx loopback configuration */
13055
13056 /* Common result structure for tx loopback */
13057 struct cmd_tx_loopback_result {
13058         cmdline_fixed_string_t set;
13059         cmdline_fixed_string_t tx;
13060         cmdline_fixed_string_t loopback;
13061         portid_t port_id;
13062         cmdline_fixed_string_t on_off;
13063 };
13064
13065 /* Common CLI fields for tx loopback enable disable */
13066 cmdline_parse_token_string_t cmd_tx_loopback_set =
13067         TOKEN_STRING_INITIALIZER
13068                 (struct cmd_tx_loopback_result,
13069                  set, "set");
13070 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13071         TOKEN_STRING_INITIALIZER
13072                 (struct cmd_tx_loopback_result,
13073                  tx, "tx");
13074 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13075         TOKEN_STRING_INITIALIZER
13076                 (struct cmd_tx_loopback_result,
13077                  loopback, "loopback");
13078 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13079         TOKEN_NUM_INITIALIZER
13080                 (struct cmd_tx_loopback_result,
13081                  port_id, UINT16);
13082 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13083         TOKEN_STRING_INITIALIZER
13084                 (struct cmd_tx_loopback_result,
13085                  on_off, "on#off");
13086
13087 static void
13088 cmd_set_tx_loopback_parsed(
13089         void *parsed_result,
13090         __attribute__((unused)) struct cmdline *cl,
13091         __attribute__((unused)) void *data)
13092 {
13093         struct cmd_tx_loopback_result *res = parsed_result;
13094         int ret = -ENOTSUP;
13095
13096         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13097
13098         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13099                 return;
13100
13101 #ifdef RTE_LIBRTE_IXGBE_PMD
13102         if (ret == -ENOTSUP)
13103                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13104 #endif
13105 #ifdef RTE_LIBRTE_I40E_PMD
13106         if (ret == -ENOTSUP)
13107                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13108 #endif
13109 #ifdef RTE_LIBRTE_BNXT_PMD
13110         if (ret == -ENOTSUP)
13111                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13112 #endif
13113 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13114         if (ret == -ENOTSUP)
13115                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13116 #endif
13117
13118         switch (ret) {
13119         case 0:
13120                 break;
13121         case -EINVAL:
13122                 printf("invalid is_on %d\n", is_on);
13123                 break;
13124         case -ENODEV:
13125                 printf("invalid port_id %d\n", res->port_id);
13126                 break;
13127         case -ENOTSUP:
13128                 printf("function not implemented\n");
13129                 break;
13130         default:
13131                 printf("programming error: (%s)\n", strerror(-ret));
13132         }
13133 }
13134
13135 cmdline_parse_inst_t cmd_set_tx_loopback = {
13136         .f = cmd_set_tx_loopback_parsed,
13137         .data = NULL,
13138         .help_str = "set tx loopback <port_id> on|off",
13139         .tokens = {
13140                 (void *)&cmd_tx_loopback_set,
13141                 (void *)&cmd_tx_loopback_tx,
13142                 (void *)&cmd_tx_loopback_loopback,
13143                 (void *)&cmd_tx_loopback_port_id,
13144                 (void *)&cmd_tx_loopback_on_off,
13145                 NULL,
13146         },
13147 };
13148
13149 /* all queues drop enable configuration */
13150
13151 /* Common result structure for all queues drop enable */
13152 struct cmd_all_queues_drop_en_result {
13153         cmdline_fixed_string_t set;
13154         cmdline_fixed_string_t all;
13155         cmdline_fixed_string_t queues;
13156         cmdline_fixed_string_t drop;
13157         portid_t port_id;
13158         cmdline_fixed_string_t on_off;
13159 };
13160
13161 /* Common CLI fields for tx loopback enable disable */
13162 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13163         TOKEN_STRING_INITIALIZER
13164                 (struct cmd_all_queues_drop_en_result,
13165                  set, "set");
13166 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13167         TOKEN_STRING_INITIALIZER
13168                 (struct cmd_all_queues_drop_en_result,
13169                  all, "all");
13170 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13171         TOKEN_STRING_INITIALIZER
13172                 (struct cmd_all_queues_drop_en_result,
13173                  queues, "queues");
13174 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13175         TOKEN_STRING_INITIALIZER
13176                 (struct cmd_all_queues_drop_en_result,
13177                  drop, "drop");
13178 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13179         TOKEN_NUM_INITIALIZER
13180                 (struct cmd_all_queues_drop_en_result,
13181                  port_id, UINT16);
13182 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13183         TOKEN_STRING_INITIALIZER
13184                 (struct cmd_all_queues_drop_en_result,
13185                  on_off, "on#off");
13186
13187 static void
13188 cmd_set_all_queues_drop_en_parsed(
13189         void *parsed_result,
13190         __attribute__((unused)) struct cmdline *cl,
13191         __attribute__((unused)) void *data)
13192 {
13193         struct cmd_all_queues_drop_en_result *res = parsed_result;
13194         int ret = -ENOTSUP;
13195         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13196
13197         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13198                 return;
13199
13200 #ifdef RTE_LIBRTE_IXGBE_PMD
13201         if (ret == -ENOTSUP)
13202                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13203 #endif
13204 #ifdef RTE_LIBRTE_BNXT_PMD
13205         if (ret == -ENOTSUP)
13206                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13207 #endif
13208         switch (ret) {
13209         case 0:
13210                 break;
13211         case -EINVAL:
13212                 printf("invalid is_on %d\n", is_on);
13213                 break;
13214         case -ENODEV:
13215                 printf("invalid port_id %d\n", res->port_id);
13216                 break;
13217         case -ENOTSUP:
13218                 printf("function not implemented\n");
13219                 break;
13220         default:
13221                 printf("programming error: (%s)\n", strerror(-ret));
13222         }
13223 }
13224
13225 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13226         .f = cmd_set_all_queues_drop_en_parsed,
13227         .data = NULL,
13228         .help_str = "set all queues drop <port_id> on|off",
13229         .tokens = {
13230                 (void *)&cmd_all_queues_drop_en_set,
13231                 (void *)&cmd_all_queues_drop_en_all,
13232                 (void *)&cmd_all_queues_drop_en_queues,
13233                 (void *)&cmd_all_queues_drop_en_drop,
13234                 (void *)&cmd_all_queues_drop_en_port_id,
13235                 (void *)&cmd_all_queues_drop_en_on_off,
13236                 NULL,
13237         },
13238 };
13239
13240 /* vf split drop enable configuration */
13241
13242 /* Common result structure for vf split drop enable */
13243 struct cmd_vf_split_drop_en_result {
13244         cmdline_fixed_string_t set;
13245         cmdline_fixed_string_t vf;
13246         cmdline_fixed_string_t split;
13247         cmdline_fixed_string_t drop;
13248         portid_t port_id;
13249         uint16_t vf_id;
13250         cmdline_fixed_string_t on_off;
13251 };
13252
13253 /* Common CLI fields for vf split drop enable disable */
13254 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13255         TOKEN_STRING_INITIALIZER
13256                 (struct cmd_vf_split_drop_en_result,
13257                  set, "set");
13258 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13259         TOKEN_STRING_INITIALIZER
13260                 (struct cmd_vf_split_drop_en_result,
13261                  vf, "vf");
13262 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13263         TOKEN_STRING_INITIALIZER
13264                 (struct cmd_vf_split_drop_en_result,
13265                  split, "split");
13266 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13267         TOKEN_STRING_INITIALIZER
13268                 (struct cmd_vf_split_drop_en_result,
13269                  drop, "drop");
13270 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13271         TOKEN_NUM_INITIALIZER
13272                 (struct cmd_vf_split_drop_en_result,
13273                  port_id, UINT16);
13274 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13275         TOKEN_NUM_INITIALIZER
13276                 (struct cmd_vf_split_drop_en_result,
13277                  vf_id, UINT16);
13278 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13279         TOKEN_STRING_INITIALIZER
13280                 (struct cmd_vf_split_drop_en_result,
13281                  on_off, "on#off");
13282
13283 static void
13284 cmd_set_vf_split_drop_en_parsed(
13285         void *parsed_result,
13286         __attribute__((unused)) struct cmdline *cl,
13287         __attribute__((unused)) void *data)
13288 {
13289         struct cmd_vf_split_drop_en_result *res = parsed_result;
13290         int ret = -ENOTSUP;
13291         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13292
13293         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13294                 return;
13295
13296 #ifdef RTE_LIBRTE_IXGBE_PMD
13297         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13298                         is_on);
13299 #endif
13300         switch (ret) {
13301         case 0:
13302                 break;
13303         case -EINVAL:
13304                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13305                 break;
13306         case -ENODEV:
13307                 printf("invalid port_id %d\n", res->port_id);
13308                 break;
13309         case -ENOTSUP:
13310                 printf("not supported on port %d\n", res->port_id);
13311                 break;
13312         default:
13313                 printf("programming error: (%s)\n", strerror(-ret));
13314         }
13315 }
13316
13317 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13318         .f = cmd_set_vf_split_drop_en_parsed,
13319         .data = NULL,
13320         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13321         .tokens = {
13322                 (void *)&cmd_vf_split_drop_en_set,
13323                 (void *)&cmd_vf_split_drop_en_vf,
13324                 (void *)&cmd_vf_split_drop_en_split,
13325                 (void *)&cmd_vf_split_drop_en_drop,
13326                 (void *)&cmd_vf_split_drop_en_port_id,
13327                 (void *)&cmd_vf_split_drop_en_vf_id,
13328                 (void *)&cmd_vf_split_drop_en_on_off,
13329                 NULL,
13330         },
13331 };
13332
13333 /* vf mac address configuration */
13334
13335 /* Common result structure for vf mac address */
13336 struct cmd_set_vf_mac_addr_result {
13337         cmdline_fixed_string_t set;
13338         cmdline_fixed_string_t vf;
13339         cmdline_fixed_string_t mac;
13340         cmdline_fixed_string_t addr;
13341         portid_t port_id;
13342         uint16_t vf_id;
13343         struct ether_addr mac_addr;
13344
13345 };
13346
13347 /* Common CLI fields for vf split drop enable disable */
13348 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13349         TOKEN_STRING_INITIALIZER
13350                 (struct cmd_set_vf_mac_addr_result,
13351                  set, "set");
13352 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13353         TOKEN_STRING_INITIALIZER
13354                 (struct cmd_set_vf_mac_addr_result,
13355                  vf, "vf");
13356 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13357         TOKEN_STRING_INITIALIZER
13358                 (struct cmd_set_vf_mac_addr_result,
13359                  mac, "mac");
13360 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13361         TOKEN_STRING_INITIALIZER
13362                 (struct cmd_set_vf_mac_addr_result,
13363                  addr, "addr");
13364 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13365         TOKEN_NUM_INITIALIZER
13366                 (struct cmd_set_vf_mac_addr_result,
13367                  port_id, UINT16);
13368 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13369         TOKEN_NUM_INITIALIZER
13370                 (struct cmd_set_vf_mac_addr_result,
13371                  vf_id, UINT16);
13372 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13373         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13374                  mac_addr);
13375
13376 static void
13377 cmd_set_vf_mac_addr_parsed(
13378         void *parsed_result,
13379         __attribute__((unused)) struct cmdline *cl,
13380         __attribute__((unused)) void *data)
13381 {
13382         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13383         int ret = -ENOTSUP;
13384
13385         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13386                 return;
13387
13388 #ifdef RTE_LIBRTE_IXGBE_PMD
13389         if (ret == -ENOTSUP)
13390                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13391                                 &res->mac_addr);
13392 #endif
13393 #ifdef RTE_LIBRTE_I40E_PMD
13394         if (ret == -ENOTSUP)
13395                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13396                                 &res->mac_addr);
13397 #endif
13398 #ifdef RTE_LIBRTE_BNXT_PMD
13399         if (ret == -ENOTSUP)
13400                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13401                                 &res->mac_addr);
13402 #endif
13403
13404         switch (ret) {
13405         case 0:
13406                 break;
13407         case -EINVAL:
13408                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13409                 break;
13410         case -ENODEV:
13411                 printf("invalid port_id %d\n", res->port_id);
13412                 break;
13413         case -ENOTSUP:
13414                 printf("function not implemented\n");
13415                 break;
13416         default:
13417                 printf("programming error: (%s)\n", strerror(-ret));
13418         }
13419 }
13420
13421 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13422         .f = cmd_set_vf_mac_addr_parsed,
13423         .data = NULL,
13424         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13425         .tokens = {
13426                 (void *)&cmd_set_vf_mac_addr_set,
13427                 (void *)&cmd_set_vf_mac_addr_vf,
13428                 (void *)&cmd_set_vf_mac_addr_mac,
13429                 (void *)&cmd_set_vf_mac_addr_addr,
13430                 (void *)&cmd_set_vf_mac_addr_port_id,
13431                 (void *)&cmd_set_vf_mac_addr_vf_id,
13432                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13433                 NULL,
13434         },
13435 };
13436
13437 /* MACsec configuration */
13438
13439 /* Common result structure for MACsec offload enable */
13440 struct cmd_macsec_offload_on_result {
13441         cmdline_fixed_string_t set;
13442         cmdline_fixed_string_t macsec;
13443         cmdline_fixed_string_t offload;
13444         portid_t port_id;
13445         cmdline_fixed_string_t on;
13446         cmdline_fixed_string_t encrypt;
13447         cmdline_fixed_string_t en_on_off;
13448         cmdline_fixed_string_t replay_protect;
13449         cmdline_fixed_string_t rp_on_off;
13450 };
13451
13452 /* Common CLI fields for MACsec offload disable */
13453 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13454         TOKEN_STRING_INITIALIZER
13455                 (struct cmd_macsec_offload_on_result,
13456                  set, "set");
13457 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13458         TOKEN_STRING_INITIALIZER
13459                 (struct cmd_macsec_offload_on_result,
13460                  macsec, "macsec");
13461 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13462         TOKEN_STRING_INITIALIZER
13463                 (struct cmd_macsec_offload_on_result,
13464                  offload, "offload");
13465 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13466         TOKEN_NUM_INITIALIZER
13467                 (struct cmd_macsec_offload_on_result,
13468                  port_id, UINT16);
13469 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13470         TOKEN_STRING_INITIALIZER
13471                 (struct cmd_macsec_offload_on_result,
13472                  on, "on");
13473 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13474         TOKEN_STRING_INITIALIZER
13475                 (struct cmd_macsec_offload_on_result,
13476                  encrypt, "encrypt");
13477 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13478         TOKEN_STRING_INITIALIZER
13479                 (struct cmd_macsec_offload_on_result,
13480                  en_on_off, "on#off");
13481 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13482         TOKEN_STRING_INITIALIZER
13483                 (struct cmd_macsec_offload_on_result,
13484                  replay_protect, "replay-protect");
13485 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13486         TOKEN_STRING_INITIALIZER
13487                 (struct cmd_macsec_offload_on_result,
13488                  rp_on_off, "on#off");
13489
13490 static void
13491 cmd_set_macsec_offload_on_parsed(
13492         void *parsed_result,
13493         __attribute__((unused)) struct cmdline *cl,
13494         __attribute__((unused)) void *data)
13495 {
13496         struct cmd_macsec_offload_on_result *res = parsed_result;
13497         int ret = -ENOTSUP;
13498         portid_t port_id = res->port_id;
13499         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13500         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13501         struct rte_eth_dev_info dev_info;
13502
13503         if (port_id_is_invalid(port_id, ENABLED_WARN))
13504                 return;
13505         if (!port_is_stopped(port_id)) {
13506                 printf("Please stop port %d first\n", port_id);
13507                 return;
13508         }
13509
13510         rte_eth_dev_info_get(port_id, &dev_info);
13511         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13512 #ifdef RTE_LIBRTE_IXGBE_PMD
13513                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13514 #endif
13515         }
13516         RTE_SET_USED(en);
13517         RTE_SET_USED(rp);
13518
13519         switch (ret) {
13520         case 0:
13521                 ports[port_id].dev_conf.txmode.offloads |=
13522                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13523                 cmd_reconfig_device_queue(port_id, 1, 1);
13524                 break;
13525         case -ENODEV:
13526                 printf("invalid port_id %d\n", port_id);
13527                 break;
13528         case -ENOTSUP:
13529                 printf("not supported on port %d\n", port_id);
13530                 break;
13531         default:
13532                 printf("programming error: (%s)\n", strerror(-ret));
13533         }
13534 }
13535
13536 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13537         .f = cmd_set_macsec_offload_on_parsed,
13538         .data = NULL,
13539         .help_str = "set macsec offload <port_id> on "
13540                 "encrypt on|off replay-protect on|off",
13541         .tokens = {
13542                 (void *)&cmd_macsec_offload_on_set,
13543                 (void *)&cmd_macsec_offload_on_macsec,
13544                 (void *)&cmd_macsec_offload_on_offload,
13545                 (void *)&cmd_macsec_offload_on_port_id,
13546                 (void *)&cmd_macsec_offload_on_on,
13547                 (void *)&cmd_macsec_offload_on_encrypt,
13548                 (void *)&cmd_macsec_offload_on_en_on_off,
13549                 (void *)&cmd_macsec_offload_on_replay_protect,
13550                 (void *)&cmd_macsec_offload_on_rp_on_off,
13551                 NULL,
13552         },
13553 };
13554
13555 /* Common result structure for MACsec offload disable */
13556 struct cmd_macsec_offload_off_result {
13557         cmdline_fixed_string_t set;
13558         cmdline_fixed_string_t macsec;
13559         cmdline_fixed_string_t offload;
13560         portid_t port_id;
13561         cmdline_fixed_string_t off;
13562 };
13563
13564 /* Common CLI fields for MACsec offload disable */
13565 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13566         TOKEN_STRING_INITIALIZER
13567                 (struct cmd_macsec_offload_off_result,
13568                  set, "set");
13569 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13570         TOKEN_STRING_INITIALIZER
13571                 (struct cmd_macsec_offload_off_result,
13572                  macsec, "macsec");
13573 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13574         TOKEN_STRING_INITIALIZER
13575                 (struct cmd_macsec_offload_off_result,
13576                  offload, "offload");
13577 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13578         TOKEN_NUM_INITIALIZER
13579                 (struct cmd_macsec_offload_off_result,
13580                  port_id, UINT16);
13581 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13582         TOKEN_STRING_INITIALIZER
13583                 (struct cmd_macsec_offload_off_result,
13584                  off, "off");
13585
13586 static void
13587 cmd_set_macsec_offload_off_parsed(
13588         void *parsed_result,
13589         __attribute__((unused)) struct cmdline *cl,
13590         __attribute__((unused)) void *data)
13591 {
13592         struct cmd_macsec_offload_off_result *res = parsed_result;
13593         int ret = -ENOTSUP;
13594         struct rte_eth_dev_info dev_info;
13595         portid_t port_id = res->port_id;
13596
13597         if (port_id_is_invalid(port_id, ENABLED_WARN))
13598                 return;
13599         if (!port_is_stopped(port_id)) {
13600                 printf("Please stop port %d first\n", port_id);
13601                 return;
13602         }
13603
13604         rte_eth_dev_info_get(port_id, &dev_info);
13605         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13606 #ifdef RTE_LIBRTE_IXGBE_PMD
13607                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13608 #endif
13609         }
13610         switch (ret) {
13611         case 0:
13612                 ports[port_id].dev_conf.txmode.offloads &=
13613                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13614                 cmd_reconfig_device_queue(port_id, 1, 1);
13615                 break;
13616         case -ENODEV:
13617                 printf("invalid port_id %d\n", port_id);
13618                 break;
13619         case -ENOTSUP:
13620                 printf("not supported on port %d\n", port_id);
13621                 break;
13622         default:
13623                 printf("programming error: (%s)\n", strerror(-ret));
13624         }
13625 }
13626
13627 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13628         .f = cmd_set_macsec_offload_off_parsed,
13629         .data = NULL,
13630         .help_str = "set macsec offload <port_id> off",
13631         .tokens = {
13632                 (void *)&cmd_macsec_offload_off_set,
13633                 (void *)&cmd_macsec_offload_off_macsec,
13634                 (void *)&cmd_macsec_offload_off_offload,
13635                 (void *)&cmd_macsec_offload_off_port_id,
13636                 (void *)&cmd_macsec_offload_off_off,
13637                 NULL,
13638         },
13639 };
13640
13641 /* Common result structure for MACsec secure connection configure */
13642 struct cmd_macsec_sc_result {
13643         cmdline_fixed_string_t set;
13644         cmdline_fixed_string_t macsec;
13645         cmdline_fixed_string_t sc;
13646         cmdline_fixed_string_t tx_rx;
13647         portid_t port_id;
13648         struct ether_addr mac;
13649         uint16_t pi;
13650 };
13651
13652 /* Common CLI fields for MACsec secure connection configure */
13653 cmdline_parse_token_string_t cmd_macsec_sc_set =
13654         TOKEN_STRING_INITIALIZER
13655                 (struct cmd_macsec_sc_result,
13656                  set, "set");
13657 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13658         TOKEN_STRING_INITIALIZER
13659                 (struct cmd_macsec_sc_result,
13660                  macsec, "macsec");
13661 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13662         TOKEN_STRING_INITIALIZER
13663                 (struct cmd_macsec_sc_result,
13664                  sc, "sc");
13665 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13666         TOKEN_STRING_INITIALIZER
13667                 (struct cmd_macsec_sc_result,
13668                  tx_rx, "tx#rx");
13669 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13670         TOKEN_NUM_INITIALIZER
13671                 (struct cmd_macsec_sc_result,
13672                  port_id, UINT16);
13673 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13674         TOKEN_ETHERADDR_INITIALIZER
13675                 (struct cmd_macsec_sc_result,
13676                  mac);
13677 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13678         TOKEN_NUM_INITIALIZER
13679                 (struct cmd_macsec_sc_result,
13680                  pi, UINT16);
13681
13682 static void
13683 cmd_set_macsec_sc_parsed(
13684         void *parsed_result,
13685         __attribute__((unused)) struct cmdline *cl,
13686         __attribute__((unused)) void *data)
13687 {
13688         struct cmd_macsec_sc_result *res = parsed_result;
13689         int ret = -ENOTSUP;
13690         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13691
13692 #ifdef RTE_LIBRTE_IXGBE_PMD
13693         ret = is_tx ?
13694                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13695                                 res->mac.addr_bytes) :
13696                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13697                                 res->mac.addr_bytes, res->pi);
13698 #endif
13699         RTE_SET_USED(is_tx);
13700
13701         switch (ret) {
13702         case 0:
13703                 break;
13704         case -ENODEV:
13705                 printf("invalid port_id %d\n", res->port_id);
13706                 break;
13707         case -ENOTSUP:
13708                 printf("not supported on port %d\n", res->port_id);
13709                 break;
13710         default:
13711                 printf("programming error: (%s)\n", strerror(-ret));
13712         }
13713 }
13714
13715 cmdline_parse_inst_t cmd_set_macsec_sc = {
13716         .f = cmd_set_macsec_sc_parsed,
13717         .data = NULL,
13718         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13719         .tokens = {
13720                 (void *)&cmd_macsec_sc_set,
13721                 (void *)&cmd_macsec_sc_macsec,
13722                 (void *)&cmd_macsec_sc_sc,
13723                 (void *)&cmd_macsec_sc_tx_rx,
13724                 (void *)&cmd_macsec_sc_port_id,
13725                 (void *)&cmd_macsec_sc_mac,
13726                 (void *)&cmd_macsec_sc_pi,
13727                 NULL,
13728         },
13729 };
13730
13731 /* Common result structure for MACsec secure connection configure */
13732 struct cmd_macsec_sa_result {
13733         cmdline_fixed_string_t set;
13734         cmdline_fixed_string_t macsec;
13735         cmdline_fixed_string_t sa;
13736         cmdline_fixed_string_t tx_rx;
13737         portid_t port_id;
13738         uint8_t idx;
13739         uint8_t an;
13740         uint32_t pn;
13741         cmdline_fixed_string_t key;
13742 };
13743
13744 /* Common CLI fields for MACsec secure connection configure */
13745 cmdline_parse_token_string_t cmd_macsec_sa_set =
13746         TOKEN_STRING_INITIALIZER
13747                 (struct cmd_macsec_sa_result,
13748                  set, "set");
13749 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13750         TOKEN_STRING_INITIALIZER
13751                 (struct cmd_macsec_sa_result,
13752                  macsec, "macsec");
13753 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13754         TOKEN_STRING_INITIALIZER
13755                 (struct cmd_macsec_sa_result,
13756                  sa, "sa");
13757 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13758         TOKEN_STRING_INITIALIZER
13759                 (struct cmd_macsec_sa_result,
13760                  tx_rx, "tx#rx");
13761 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13762         TOKEN_NUM_INITIALIZER
13763                 (struct cmd_macsec_sa_result,
13764                  port_id, UINT16);
13765 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13766         TOKEN_NUM_INITIALIZER
13767                 (struct cmd_macsec_sa_result,
13768                  idx, UINT8);
13769 cmdline_parse_token_num_t cmd_macsec_sa_an =
13770         TOKEN_NUM_INITIALIZER
13771                 (struct cmd_macsec_sa_result,
13772                  an, UINT8);
13773 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13774         TOKEN_NUM_INITIALIZER
13775                 (struct cmd_macsec_sa_result,
13776                  pn, UINT32);
13777 cmdline_parse_token_string_t cmd_macsec_sa_key =
13778         TOKEN_STRING_INITIALIZER
13779                 (struct cmd_macsec_sa_result,
13780                  key, NULL);
13781
13782 static void
13783 cmd_set_macsec_sa_parsed(
13784         void *parsed_result,
13785         __attribute__((unused)) struct cmdline *cl,
13786         __attribute__((unused)) void *data)
13787 {
13788         struct cmd_macsec_sa_result *res = parsed_result;
13789         int ret = -ENOTSUP;
13790         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13791         uint8_t key[16] = { 0 };
13792         uint8_t xdgt0;
13793         uint8_t xdgt1;
13794         int key_len;
13795         int i;
13796
13797         key_len = strlen(res->key) / 2;
13798         if (key_len > 16)
13799                 key_len = 16;
13800
13801         for (i = 0; i < key_len; i++) {
13802                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13803                 if (xdgt0 == 0xFF)
13804                         return;
13805                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13806                 if (xdgt1 == 0xFF)
13807                         return;
13808                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13809         }
13810
13811 #ifdef RTE_LIBRTE_IXGBE_PMD
13812         ret = is_tx ?
13813                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13814                         res->idx, res->an, res->pn, key) :
13815                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13816                         res->idx, res->an, res->pn, key);
13817 #endif
13818         RTE_SET_USED(is_tx);
13819         RTE_SET_USED(key);
13820
13821         switch (ret) {
13822         case 0:
13823                 break;
13824         case -EINVAL:
13825                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13826                 break;
13827         case -ENODEV:
13828                 printf("invalid port_id %d\n", res->port_id);
13829                 break;
13830         case -ENOTSUP:
13831                 printf("not supported on port %d\n", res->port_id);
13832                 break;
13833         default:
13834                 printf("programming error: (%s)\n", strerror(-ret));
13835         }
13836 }
13837
13838 cmdline_parse_inst_t cmd_set_macsec_sa = {
13839         .f = cmd_set_macsec_sa_parsed,
13840         .data = NULL,
13841         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13842         .tokens = {
13843                 (void *)&cmd_macsec_sa_set,
13844                 (void *)&cmd_macsec_sa_macsec,
13845                 (void *)&cmd_macsec_sa_sa,
13846                 (void *)&cmd_macsec_sa_tx_rx,
13847                 (void *)&cmd_macsec_sa_port_id,
13848                 (void *)&cmd_macsec_sa_idx,
13849                 (void *)&cmd_macsec_sa_an,
13850                 (void *)&cmd_macsec_sa_pn,
13851                 (void *)&cmd_macsec_sa_key,
13852                 NULL,
13853         },
13854 };
13855
13856 /* VF unicast promiscuous mode configuration */
13857
13858 /* Common result structure for VF unicast promiscuous mode */
13859 struct cmd_vf_promisc_result {
13860         cmdline_fixed_string_t set;
13861         cmdline_fixed_string_t vf;
13862         cmdline_fixed_string_t promisc;
13863         portid_t port_id;
13864         uint32_t vf_id;
13865         cmdline_fixed_string_t on_off;
13866 };
13867
13868 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13869 cmdline_parse_token_string_t cmd_vf_promisc_set =
13870         TOKEN_STRING_INITIALIZER
13871                 (struct cmd_vf_promisc_result,
13872                  set, "set");
13873 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13874         TOKEN_STRING_INITIALIZER
13875                 (struct cmd_vf_promisc_result,
13876                  vf, "vf");
13877 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13878         TOKEN_STRING_INITIALIZER
13879                 (struct cmd_vf_promisc_result,
13880                  promisc, "promisc");
13881 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13882         TOKEN_NUM_INITIALIZER
13883                 (struct cmd_vf_promisc_result,
13884                  port_id, UINT16);
13885 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13886         TOKEN_NUM_INITIALIZER
13887                 (struct cmd_vf_promisc_result,
13888                  vf_id, UINT32);
13889 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13890         TOKEN_STRING_INITIALIZER
13891                 (struct cmd_vf_promisc_result,
13892                  on_off, "on#off");
13893
13894 static void
13895 cmd_set_vf_promisc_parsed(
13896         void *parsed_result,
13897         __attribute__((unused)) struct cmdline *cl,
13898         __attribute__((unused)) void *data)
13899 {
13900         struct cmd_vf_promisc_result *res = parsed_result;
13901         int ret = -ENOTSUP;
13902
13903         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13904
13905         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13906                 return;
13907
13908 #ifdef RTE_LIBRTE_I40E_PMD
13909         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13910                                                   res->vf_id, is_on);
13911 #endif
13912
13913         switch (ret) {
13914         case 0:
13915                 break;
13916         case -EINVAL:
13917                 printf("invalid vf_id %d\n", res->vf_id);
13918                 break;
13919         case -ENODEV:
13920                 printf("invalid port_id %d\n", res->port_id);
13921                 break;
13922         case -ENOTSUP:
13923                 printf("function not implemented\n");
13924                 break;
13925         default:
13926                 printf("programming error: (%s)\n", strerror(-ret));
13927         }
13928 }
13929
13930 cmdline_parse_inst_t cmd_set_vf_promisc = {
13931         .f = cmd_set_vf_promisc_parsed,
13932         .data = NULL,
13933         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13934                 "Set unicast promiscuous mode for a VF from the PF",
13935         .tokens = {
13936                 (void *)&cmd_vf_promisc_set,
13937                 (void *)&cmd_vf_promisc_vf,
13938                 (void *)&cmd_vf_promisc_promisc,
13939                 (void *)&cmd_vf_promisc_port_id,
13940                 (void *)&cmd_vf_promisc_vf_id,
13941                 (void *)&cmd_vf_promisc_on_off,
13942                 NULL,
13943         },
13944 };
13945
13946 /* VF multicast promiscuous mode configuration */
13947
13948 /* Common result structure for VF multicast promiscuous mode */
13949 struct cmd_vf_allmulti_result {
13950         cmdline_fixed_string_t set;
13951         cmdline_fixed_string_t vf;
13952         cmdline_fixed_string_t allmulti;
13953         portid_t port_id;
13954         uint32_t vf_id;
13955         cmdline_fixed_string_t on_off;
13956 };
13957
13958 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13959 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13960         TOKEN_STRING_INITIALIZER
13961                 (struct cmd_vf_allmulti_result,
13962                  set, "set");
13963 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13964         TOKEN_STRING_INITIALIZER
13965                 (struct cmd_vf_allmulti_result,
13966                  vf, "vf");
13967 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13968         TOKEN_STRING_INITIALIZER
13969                 (struct cmd_vf_allmulti_result,
13970                  allmulti, "allmulti");
13971 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13972         TOKEN_NUM_INITIALIZER
13973                 (struct cmd_vf_allmulti_result,
13974                  port_id, UINT16);
13975 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13976         TOKEN_NUM_INITIALIZER
13977                 (struct cmd_vf_allmulti_result,
13978                  vf_id, UINT32);
13979 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13980         TOKEN_STRING_INITIALIZER
13981                 (struct cmd_vf_allmulti_result,
13982                  on_off, "on#off");
13983
13984 static void
13985 cmd_set_vf_allmulti_parsed(
13986         void *parsed_result,
13987         __attribute__((unused)) struct cmdline *cl,
13988         __attribute__((unused)) void *data)
13989 {
13990         struct cmd_vf_allmulti_result *res = parsed_result;
13991         int ret = -ENOTSUP;
13992
13993         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13994
13995         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13996                 return;
13997
13998 #ifdef RTE_LIBRTE_I40E_PMD
13999         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14000                                                     res->vf_id, is_on);
14001 #endif
14002
14003         switch (ret) {
14004         case 0:
14005                 break;
14006         case -EINVAL:
14007                 printf("invalid vf_id %d\n", res->vf_id);
14008                 break;
14009         case -ENODEV:
14010                 printf("invalid port_id %d\n", res->port_id);
14011                 break;
14012         case -ENOTSUP:
14013                 printf("function not implemented\n");
14014                 break;
14015         default:
14016                 printf("programming error: (%s)\n", strerror(-ret));
14017         }
14018 }
14019
14020 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14021         .f = cmd_set_vf_allmulti_parsed,
14022         .data = NULL,
14023         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14024                 "Set multicast promiscuous mode for a VF from the PF",
14025         .tokens = {
14026                 (void *)&cmd_vf_allmulti_set,
14027                 (void *)&cmd_vf_allmulti_vf,
14028                 (void *)&cmd_vf_allmulti_allmulti,
14029                 (void *)&cmd_vf_allmulti_port_id,
14030                 (void *)&cmd_vf_allmulti_vf_id,
14031                 (void *)&cmd_vf_allmulti_on_off,
14032                 NULL,
14033         },
14034 };
14035
14036 /* vf broadcast mode configuration */
14037
14038 /* Common result structure for vf broadcast */
14039 struct cmd_set_vf_broadcast_result {
14040         cmdline_fixed_string_t set;
14041         cmdline_fixed_string_t vf;
14042         cmdline_fixed_string_t broadcast;
14043         portid_t port_id;
14044         uint16_t vf_id;
14045         cmdline_fixed_string_t on_off;
14046 };
14047
14048 /* Common CLI fields for vf broadcast enable disable */
14049 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14050         TOKEN_STRING_INITIALIZER
14051                 (struct cmd_set_vf_broadcast_result,
14052                  set, "set");
14053 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14054         TOKEN_STRING_INITIALIZER
14055                 (struct cmd_set_vf_broadcast_result,
14056                  vf, "vf");
14057 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14058         TOKEN_STRING_INITIALIZER
14059                 (struct cmd_set_vf_broadcast_result,
14060                  broadcast, "broadcast");
14061 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14062         TOKEN_NUM_INITIALIZER
14063                 (struct cmd_set_vf_broadcast_result,
14064                  port_id, UINT16);
14065 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14066         TOKEN_NUM_INITIALIZER
14067                 (struct cmd_set_vf_broadcast_result,
14068                  vf_id, UINT16);
14069 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14070         TOKEN_STRING_INITIALIZER
14071                 (struct cmd_set_vf_broadcast_result,
14072                  on_off, "on#off");
14073
14074 static void
14075 cmd_set_vf_broadcast_parsed(
14076         void *parsed_result,
14077         __attribute__((unused)) struct cmdline *cl,
14078         __attribute__((unused)) void *data)
14079 {
14080         struct cmd_set_vf_broadcast_result *res = parsed_result;
14081         int ret = -ENOTSUP;
14082
14083         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14084
14085         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14086                 return;
14087
14088 #ifdef RTE_LIBRTE_I40E_PMD
14089         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14090                                             res->vf_id, is_on);
14091 #endif
14092
14093         switch (ret) {
14094         case 0:
14095                 break;
14096         case -EINVAL:
14097                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14098                 break;
14099         case -ENODEV:
14100                 printf("invalid port_id %d\n", res->port_id);
14101                 break;
14102         case -ENOTSUP:
14103                 printf("function not implemented\n");
14104                 break;
14105         default:
14106                 printf("programming error: (%s)\n", strerror(-ret));
14107         }
14108 }
14109
14110 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14111         .f = cmd_set_vf_broadcast_parsed,
14112         .data = NULL,
14113         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14114         .tokens = {
14115                 (void *)&cmd_set_vf_broadcast_set,
14116                 (void *)&cmd_set_vf_broadcast_vf,
14117                 (void *)&cmd_set_vf_broadcast_broadcast,
14118                 (void *)&cmd_set_vf_broadcast_port_id,
14119                 (void *)&cmd_set_vf_broadcast_vf_id,
14120                 (void *)&cmd_set_vf_broadcast_on_off,
14121                 NULL,
14122         },
14123 };
14124
14125 /* vf vlan tag configuration */
14126
14127 /* Common result structure for vf vlan tag */
14128 struct cmd_set_vf_vlan_tag_result {
14129         cmdline_fixed_string_t set;
14130         cmdline_fixed_string_t vf;
14131         cmdline_fixed_string_t vlan;
14132         cmdline_fixed_string_t tag;
14133         portid_t port_id;
14134         uint16_t vf_id;
14135         cmdline_fixed_string_t on_off;
14136 };
14137
14138 /* Common CLI fields for vf vlan tag enable disable */
14139 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14140         TOKEN_STRING_INITIALIZER
14141                 (struct cmd_set_vf_vlan_tag_result,
14142                  set, "set");
14143 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14144         TOKEN_STRING_INITIALIZER
14145                 (struct cmd_set_vf_vlan_tag_result,
14146                  vf, "vf");
14147 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14148         TOKEN_STRING_INITIALIZER
14149                 (struct cmd_set_vf_vlan_tag_result,
14150                  vlan, "vlan");
14151 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14152         TOKEN_STRING_INITIALIZER
14153                 (struct cmd_set_vf_vlan_tag_result,
14154                  tag, "tag");
14155 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14156         TOKEN_NUM_INITIALIZER
14157                 (struct cmd_set_vf_vlan_tag_result,
14158                  port_id, UINT16);
14159 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14160         TOKEN_NUM_INITIALIZER
14161                 (struct cmd_set_vf_vlan_tag_result,
14162                  vf_id, UINT16);
14163 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14164         TOKEN_STRING_INITIALIZER
14165                 (struct cmd_set_vf_vlan_tag_result,
14166                  on_off, "on#off");
14167
14168 static void
14169 cmd_set_vf_vlan_tag_parsed(
14170         void *parsed_result,
14171         __attribute__((unused)) struct cmdline *cl,
14172         __attribute__((unused)) void *data)
14173 {
14174         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14175         int ret = -ENOTSUP;
14176
14177         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14178
14179         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14180                 return;
14181
14182 #ifdef RTE_LIBRTE_I40E_PMD
14183         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14184                                            res->vf_id, is_on);
14185 #endif
14186
14187         switch (ret) {
14188         case 0:
14189                 break;
14190         case -EINVAL:
14191                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14192                 break;
14193         case -ENODEV:
14194                 printf("invalid port_id %d\n", res->port_id);
14195                 break;
14196         case -ENOTSUP:
14197                 printf("function not implemented\n");
14198                 break;
14199         default:
14200                 printf("programming error: (%s)\n", strerror(-ret));
14201         }
14202 }
14203
14204 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14205         .f = cmd_set_vf_vlan_tag_parsed,
14206         .data = NULL,
14207         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14208         .tokens = {
14209                 (void *)&cmd_set_vf_vlan_tag_set,
14210                 (void *)&cmd_set_vf_vlan_tag_vf,
14211                 (void *)&cmd_set_vf_vlan_tag_vlan,
14212                 (void *)&cmd_set_vf_vlan_tag_tag,
14213                 (void *)&cmd_set_vf_vlan_tag_port_id,
14214                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14215                 (void *)&cmd_set_vf_vlan_tag_on_off,
14216                 NULL,
14217         },
14218 };
14219
14220 /* Common definition of VF and TC TX bandwidth configuration */
14221 struct cmd_vf_tc_bw_result {
14222         cmdline_fixed_string_t set;
14223         cmdline_fixed_string_t vf;
14224         cmdline_fixed_string_t tc;
14225         cmdline_fixed_string_t tx;
14226         cmdline_fixed_string_t min_bw;
14227         cmdline_fixed_string_t max_bw;
14228         cmdline_fixed_string_t strict_link_prio;
14229         portid_t port_id;
14230         uint16_t vf_id;
14231         uint8_t tc_no;
14232         uint32_t bw;
14233         cmdline_fixed_string_t bw_list;
14234         uint8_t tc_map;
14235 };
14236
14237 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14238         TOKEN_STRING_INITIALIZER
14239                 (struct cmd_vf_tc_bw_result,
14240                  set, "set");
14241 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14242         TOKEN_STRING_INITIALIZER
14243                 (struct cmd_vf_tc_bw_result,
14244                  vf, "vf");
14245 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14246         TOKEN_STRING_INITIALIZER
14247                 (struct cmd_vf_tc_bw_result,
14248                  tc, "tc");
14249 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14250         TOKEN_STRING_INITIALIZER
14251                 (struct cmd_vf_tc_bw_result,
14252                  tx, "tx");
14253 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14254         TOKEN_STRING_INITIALIZER
14255                 (struct cmd_vf_tc_bw_result,
14256                  strict_link_prio, "strict-link-priority");
14257 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14258         TOKEN_STRING_INITIALIZER
14259                 (struct cmd_vf_tc_bw_result,
14260                  min_bw, "min-bandwidth");
14261 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14262         TOKEN_STRING_INITIALIZER
14263                 (struct cmd_vf_tc_bw_result,
14264                  max_bw, "max-bandwidth");
14265 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14266         TOKEN_NUM_INITIALIZER
14267                 (struct cmd_vf_tc_bw_result,
14268                  port_id, UINT16);
14269 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14270         TOKEN_NUM_INITIALIZER
14271                 (struct cmd_vf_tc_bw_result,
14272                  vf_id, UINT16);
14273 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14274         TOKEN_NUM_INITIALIZER
14275                 (struct cmd_vf_tc_bw_result,
14276                  tc_no, UINT8);
14277 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14278         TOKEN_NUM_INITIALIZER
14279                 (struct cmd_vf_tc_bw_result,
14280                  bw, UINT32);
14281 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14282         TOKEN_STRING_INITIALIZER
14283                 (struct cmd_vf_tc_bw_result,
14284                  bw_list, NULL);
14285 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14286         TOKEN_NUM_INITIALIZER
14287                 (struct cmd_vf_tc_bw_result,
14288                  tc_map, UINT8);
14289
14290 /* VF max bandwidth setting */
14291 static void
14292 cmd_vf_max_bw_parsed(
14293         void *parsed_result,
14294         __attribute__((unused)) struct cmdline *cl,
14295         __attribute__((unused)) void *data)
14296 {
14297         struct cmd_vf_tc_bw_result *res = parsed_result;
14298         int ret = -ENOTSUP;
14299
14300         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14301                 return;
14302
14303 #ifdef RTE_LIBRTE_I40E_PMD
14304         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14305                                          res->vf_id, res->bw);
14306 #endif
14307
14308         switch (ret) {
14309         case 0:
14310                 break;
14311         case -EINVAL:
14312                 printf("invalid vf_id %d or bandwidth %d\n",
14313                        res->vf_id, res->bw);
14314                 break;
14315         case -ENODEV:
14316                 printf("invalid port_id %d\n", res->port_id);
14317                 break;
14318         case -ENOTSUP:
14319                 printf("function not implemented\n");
14320                 break;
14321         default:
14322                 printf("programming error: (%s)\n", strerror(-ret));
14323         }
14324 }
14325
14326 cmdline_parse_inst_t cmd_vf_max_bw = {
14327         .f = cmd_vf_max_bw_parsed,
14328         .data = NULL,
14329         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14330         .tokens = {
14331                 (void *)&cmd_vf_tc_bw_set,
14332                 (void *)&cmd_vf_tc_bw_vf,
14333                 (void *)&cmd_vf_tc_bw_tx,
14334                 (void *)&cmd_vf_tc_bw_max_bw,
14335                 (void *)&cmd_vf_tc_bw_port_id,
14336                 (void *)&cmd_vf_tc_bw_vf_id,
14337                 (void *)&cmd_vf_tc_bw_bw,
14338                 NULL,
14339         },
14340 };
14341
14342 static int
14343 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14344                            uint8_t *tc_num,
14345                            char *str)
14346 {
14347         uint32_t size;
14348         const char *p, *p0 = str;
14349         char s[256];
14350         char *end;
14351         char *str_fld[16];
14352         uint16_t i;
14353         int ret;
14354
14355         p = strchr(p0, '(');
14356         if (p == NULL) {
14357                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14358                 return -1;
14359         }
14360         p++;
14361         p0 = strchr(p, ')');
14362         if (p0 == NULL) {
14363                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14364                 return -1;
14365         }
14366         size = p0 - p;
14367         if (size >= sizeof(s)) {
14368                 printf("The string size exceeds the internal buffer size\n");
14369                 return -1;
14370         }
14371         snprintf(s, sizeof(s), "%.*s", size, p);
14372         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14373         if (ret <= 0) {
14374                 printf("Failed to get the bandwidth list. ");
14375                 return -1;
14376         }
14377         *tc_num = ret;
14378         for (i = 0; i < ret; i++)
14379                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14380
14381         return 0;
14382 }
14383
14384 /* TC min bandwidth setting */
14385 static void
14386 cmd_vf_tc_min_bw_parsed(
14387         void *parsed_result,
14388         __attribute__((unused)) struct cmdline *cl,
14389         __attribute__((unused)) void *data)
14390 {
14391         struct cmd_vf_tc_bw_result *res = parsed_result;
14392         uint8_t tc_num;
14393         uint8_t bw[16];
14394         int ret = -ENOTSUP;
14395
14396         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14397                 return;
14398
14399         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14400         if (ret)
14401                 return;
14402
14403 #ifdef RTE_LIBRTE_I40E_PMD
14404         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14405                                               tc_num, bw);
14406 #endif
14407
14408         switch (ret) {
14409         case 0:
14410                 break;
14411         case -EINVAL:
14412                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14413                 break;
14414         case -ENODEV:
14415                 printf("invalid port_id %d\n", res->port_id);
14416                 break;
14417         case -ENOTSUP:
14418                 printf("function not implemented\n");
14419                 break;
14420         default:
14421                 printf("programming error: (%s)\n", strerror(-ret));
14422         }
14423 }
14424
14425 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14426         .f = cmd_vf_tc_min_bw_parsed,
14427         .data = NULL,
14428         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14429                     " <bw1, bw2, ...>",
14430         .tokens = {
14431                 (void *)&cmd_vf_tc_bw_set,
14432                 (void *)&cmd_vf_tc_bw_vf,
14433                 (void *)&cmd_vf_tc_bw_tc,
14434                 (void *)&cmd_vf_tc_bw_tx,
14435                 (void *)&cmd_vf_tc_bw_min_bw,
14436                 (void *)&cmd_vf_tc_bw_port_id,
14437                 (void *)&cmd_vf_tc_bw_vf_id,
14438                 (void *)&cmd_vf_tc_bw_bw_list,
14439                 NULL,
14440         },
14441 };
14442
14443 static void
14444 cmd_tc_min_bw_parsed(
14445         void *parsed_result,
14446         __attribute__((unused)) struct cmdline *cl,
14447         __attribute__((unused)) void *data)
14448 {
14449         struct cmd_vf_tc_bw_result *res = parsed_result;
14450         struct rte_port *port;
14451         uint8_t tc_num;
14452         uint8_t bw[16];
14453         int ret = -ENOTSUP;
14454
14455         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14456                 return;
14457
14458         port = &ports[res->port_id];
14459         /** Check if the port is not started **/
14460         if (port->port_status != RTE_PORT_STOPPED) {
14461                 printf("Please stop port %d first\n", res->port_id);
14462                 return;
14463         }
14464
14465         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14466         if (ret)
14467                 return;
14468
14469 #ifdef RTE_LIBRTE_IXGBE_PMD
14470         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14471 #endif
14472
14473         switch (ret) {
14474         case 0:
14475                 break;
14476         case -EINVAL:
14477                 printf("invalid bandwidth\n");
14478                 break;
14479         case -ENODEV:
14480                 printf("invalid port_id %d\n", res->port_id);
14481                 break;
14482         case -ENOTSUP:
14483                 printf("function not implemented\n");
14484                 break;
14485         default:
14486                 printf("programming error: (%s)\n", strerror(-ret));
14487         }
14488 }
14489
14490 cmdline_parse_inst_t cmd_tc_min_bw = {
14491         .f = cmd_tc_min_bw_parsed,
14492         .data = NULL,
14493         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14494         .tokens = {
14495                 (void *)&cmd_vf_tc_bw_set,
14496                 (void *)&cmd_vf_tc_bw_tc,
14497                 (void *)&cmd_vf_tc_bw_tx,
14498                 (void *)&cmd_vf_tc_bw_min_bw,
14499                 (void *)&cmd_vf_tc_bw_port_id,
14500                 (void *)&cmd_vf_tc_bw_bw_list,
14501                 NULL,
14502         },
14503 };
14504
14505 /* TC max bandwidth setting */
14506 static void
14507 cmd_vf_tc_max_bw_parsed(
14508         void *parsed_result,
14509         __attribute__((unused)) struct cmdline *cl,
14510         __attribute__((unused)) void *data)
14511 {
14512         struct cmd_vf_tc_bw_result *res = parsed_result;
14513         int ret = -ENOTSUP;
14514
14515         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14516                 return;
14517
14518 #ifdef RTE_LIBRTE_I40E_PMD
14519         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14520                                             res->tc_no, res->bw);
14521 #endif
14522
14523         switch (ret) {
14524         case 0:
14525                 break;
14526         case -EINVAL:
14527                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14528                        res->vf_id, res->tc_no, res->bw);
14529                 break;
14530         case -ENODEV:
14531                 printf("invalid port_id %d\n", res->port_id);
14532                 break;
14533         case -ENOTSUP:
14534                 printf("function not implemented\n");
14535                 break;
14536         default:
14537                 printf("programming error: (%s)\n", strerror(-ret));
14538         }
14539 }
14540
14541 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14542         .f = cmd_vf_tc_max_bw_parsed,
14543         .data = NULL,
14544         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14545                     " <bandwidth>",
14546         .tokens = {
14547                 (void *)&cmd_vf_tc_bw_set,
14548                 (void *)&cmd_vf_tc_bw_vf,
14549                 (void *)&cmd_vf_tc_bw_tc,
14550                 (void *)&cmd_vf_tc_bw_tx,
14551                 (void *)&cmd_vf_tc_bw_max_bw,
14552                 (void *)&cmd_vf_tc_bw_port_id,
14553                 (void *)&cmd_vf_tc_bw_vf_id,
14554                 (void *)&cmd_vf_tc_bw_tc_no,
14555                 (void *)&cmd_vf_tc_bw_bw,
14556                 NULL,
14557         },
14558 };
14559
14560
14561 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14562
14563 /* *** Set Port default Traffic Management Hierarchy *** */
14564 struct cmd_set_port_tm_hierarchy_default_result {
14565         cmdline_fixed_string_t set;
14566         cmdline_fixed_string_t port;
14567         cmdline_fixed_string_t tm;
14568         cmdline_fixed_string_t hierarchy;
14569         cmdline_fixed_string_t def;
14570         portid_t port_id;
14571 };
14572
14573 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14574         TOKEN_STRING_INITIALIZER(
14575                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14576 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14577         TOKEN_STRING_INITIALIZER(
14578                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14579 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14580         TOKEN_STRING_INITIALIZER(
14581                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14582 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14583         TOKEN_STRING_INITIALIZER(
14584                 struct cmd_set_port_tm_hierarchy_default_result,
14585                         hierarchy, "hierarchy");
14586 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14587         TOKEN_STRING_INITIALIZER(
14588                 struct cmd_set_port_tm_hierarchy_default_result,
14589                         def, "default");
14590 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14591         TOKEN_NUM_INITIALIZER(
14592                 struct cmd_set_port_tm_hierarchy_default_result,
14593                         port_id, UINT16);
14594
14595 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14596         __attribute__((unused)) struct cmdline *cl,
14597         __attribute__((unused)) void *data)
14598 {
14599         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14600         struct rte_port *p;
14601         portid_t port_id = res->port_id;
14602
14603         if (port_id_is_invalid(port_id, ENABLED_WARN))
14604                 return;
14605
14606         p = &ports[port_id];
14607
14608         /* Port tm flag */
14609         if (p->softport.tm_flag == 0) {
14610                 printf("  tm not enabled on port %u (error)\n", port_id);
14611                 return;
14612         }
14613
14614         /* Forward mode: tm */
14615         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14616                 printf("  tm mode not enabled(error)\n");
14617                 return;
14618         }
14619
14620         /* Set the default tm hierarchy */
14621         p->softport.tm.default_hierarchy_enable = 1;
14622 }
14623
14624 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14625         .f = cmd_set_port_tm_hierarchy_default_parsed,
14626         .data = NULL,
14627         .help_str = "set port tm hierarchy default <port_id>",
14628         .tokens = {
14629                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14630                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14631                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14632                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14633                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14634                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14635                 NULL,
14636         },
14637 };
14638 #endif
14639
14640 /* Strict link priority scheduling mode setting */
14641 static void
14642 cmd_strict_link_prio_parsed(
14643         void *parsed_result,
14644         __attribute__((unused)) struct cmdline *cl,
14645         __attribute__((unused)) void *data)
14646 {
14647         struct cmd_vf_tc_bw_result *res = parsed_result;
14648         int ret = -ENOTSUP;
14649
14650         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14651                 return;
14652
14653 #ifdef RTE_LIBRTE_I40E_PMD
14654         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14655 #endif
14656
14657         switch (ret) {
14658         case 0:
14659                 break;
14660         case -EINVAL:
14661                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14662                 break;
14663         case -ENODEV:
14664                 printf("invalid port_id %d\n", res->port_id);
14665                 break;
14666         case -ENOTSUP:
14667                 printf("function not implemented\n");
14668                 break;
14669         default:
14670                 printf("programming error: (%s)\n", strerror(-ret));
14671         }
14672 }
14673
14674 cmdline_parse_inst_t cmd_strict_link_prio = {
14675         .f = cmd_strict_link_prio_parsed,
14676         .data = NULL,
14677         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14678         .tokens = {
14679                 (void *)&cmd_vf_tc_bw_set,
14680                 (void *)&cmd_vf_tc_bw_tx,
14681                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14682                 (void *)&cmd_vf_tc_bw_port_id,
14683                 (void *)&cmd_vf_tc_bw_tc_map,
14684                 NULL,
14685         },
14686 };
14687
14688 /* Load dynamic device personalization*/
14689 struct cmd_ddp_add_result {
14690         cmdline_fixed_string_t ddp;
14691         cmdline_fixed_string_t add;
14692         portid_t port_id;
14693         char filepath[];
14694 };
14695
14696 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14697         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14698 cmdline_parse_token_string_t cmd_ddp_add_add =
14699         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14700 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14701         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14702 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14703         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14704
14705 static void
14706 cmd_ddp_add_parsed(
14707         void *parsed_result,
14708         __attribute__((unused)) struct cmdline *cl,
14709         __attribute__((unused)) void *data)
14710 {
14711         struct cmd_ddp_add_result *res = parsed_result;
14712         uint8_t *buff;
14713         uint32_t size;
14714         char *filepath;
14715         char *file_fld[2];
14716         int file_num;
14717         int ret = -ENOTSUP;
14718
14719         if (!all_ports_stopped()) {
14720                 printf("Please stop all ports first\n");
14721                 return;
14722         }
14723
14724         filepath = strdup(res->filepath);
14725         if (filepath == NULL) {
14726                 printf("Failed to allocate memory\n");
14727                 return;
14728         }
14729         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14730
14731         buff = open_file(file_fld[0], &size);
14732         if (!buff) {
14733                 free((void *)filepath);
14734                 return;
14735         }
14736
14737 #ifdef RTE_LIBRTE_I40E_PMD
14738         if (ret == -ENOTSUP)
14739                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14740                                                buff, size,
14741                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14742 #endif
14743
14744         if (ret == -EEXIST)
14745                 printf("Profile has already existed.\n");
14746         else if (ret < 0)
14747                 printf("Failed to load profile.\n");
14748         else if (file_num == 2)
14749                 save_file(file_fld[1], buff, size);
14750
14751         close_file(buff);
14752         free((void *)filepath);
14753 }
14754
14755 cmdline_parse_inst_t cmd_ddp_add = {
14756         .f = cmd_ddp_add_parsed,
14757         .data = NULL,
14758         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14759         .tokens = {
14760                 (void *)&cmd_ddp_add_ddp,
14761                 (void *)&cmd_ddp_add_add,
14762                 (void *)&cmd_ddp_add_port_id,
14763                 (void *)&cmd_ddp_add_filepath,
14764                 NULL,
14765         },
14766 };
14767
14768 /* Delete dynamic device personalization*/
14769 struct cmd_ddp_del_result {
14770         cmdline_fixed_string_t ddp;
14771         cmdline_fixed_string_t del;
14772         portid_t port_id;
14773         char filepath[];
14774 };
14775
14776 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14777         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14778 cmdline_parse_token_string_t cmd_ddp_del_del =
14779         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14780 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14781         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14782 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14783         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14784
14785 static void
14786 cmd_ddp_del_parsed(
14787         void *parsed_result,
14788         __attribute__((unused)) struct cmdline *cl,
14789         __attribute__((unused)) void *data)
14790 {
14791         struct cmd_ddp_del_result *res = parsed_result;
14792         uint8_t *buff;
14793         uint32_t size;
14794         int ret = -ENOTSUP;
14795
14796         if (!all_ports_stopped()) {
14797                 printf("Please stop all ports first\n");
14798                 return;
14799         }
14800
14801         buff = open_file(res->filepath, &size);
14802         if (!buff)
14803                 return;
14804
14805 #ifdef RTE_LIBRTE_I40E_PMD
14806         if (ret == -ENOTSUP)
14807                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14808                                                buff, size,
14809                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14810 #endif
14811
14812         if (ret == -EACCES)
14813                 printf("Profile does not exist.\n");
14814         else if (ret < 0)
14815                 printf("Failed to delete profile.\n");
14816
14817         close_file(buff);
14818 }
14819
14820 cmdline_parse_inst_t cmd_ddp_del = {
14821         .f = cmd_ddp_del_parsed,
14822         .data = NULL,
14823         .help_str = "ddp del <port_id> <backup_profile_path>",
14824         .tokens = {
14825                 (void *)&cmd_ddp_del_ddp,
14826                 (void *)&cmd_ddp_del_del,
14827                 (void *)&cmd_ddp_del_port_id,
14828                 (void *)&cmd_ddp_del_filepath,
14829                 NULL,
14830         },
14831 };
14832
14833 /* Get dynamic device personalization profile info */
14834 struct cmd_ddp_info_result {
14835         cmdline_fixed_string_t ddp;
14836         cmdline_fixed_string_t get;
14837         cmdline_fixed_string_t info;
14838         char filepath[];
14839 };
14840
14841 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14842         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14843 cmdline_parse_token_string_t cmd_ddp_info_get =
14844         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14845 cmdline_parse_token_string_t cmd_ddp_info_info =
14846         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14847 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14848         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14849
14850 static void
14851 cmd_ddp_info_parsed(
14852         void *parsed_result,
14853         __attribute__((unused)) struct cmdline *cl,
14854         __attribute__((unused)) void *data)
14855 {
14856         struct cmd_ddp_info_result *res = parsed_result;
14857         uint8_t *pkg;
14858         uint32_t pkg_size;
14859         int ret = -ENOTSUP;
14860 #ifdef RTE_LIBRTE_I40E_PMD
14861         uint32_t i, j, n;
14862         uint8_t *buff;
14863         uint32_t buff_size = 0;
14864         struct rte_pmd_i40e_profile_info info;
14865         uint32_t dev_num = 0;
14866         struct rte_pmd_i40e_ddp_device_id *devs;
14867         uint32_t proto_num = 0;
14868         struct rte_pmd_i40e_proto_info *proto = NULL;
14869         uint32_t pctype_num = 0;
14870         struct rte_pmd_i40e_ptype_info *pctype;
14871         uint32_t ptype_num = 0;
14872         struct rte_pmd_i40e_ptype_info *ptype;
14873         uint8_t proto_id;
14874
14875 #endif
14876
14877         pkg = open_file(res->filepath, &pkg_size);
14878         if (!pkg)
14879                 return;
14880
14881 #ifdef RTE_LIBRTE_I40E_PMD
14882         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14883                                 (uint8_t *)&info, sizeof(info),
14884                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14885         if (!ret) {
14886                 printf("Global Track id:       0x%x\n", info.track_id);
14887                 printf("Global Version:        %d.%d.%d.%d\n",
14888                         info.version.major,
14889                         info.version.minor,
14890                         info.version.update,
14891                         info.version.draft);
14892                 printf("Global Package name:   %s\n\n", info.name);
14893         }
14894
14895         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14896                                 (uint8_t *)&info, sizeof(info),
14897                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14898         if (!ret) {
14899                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14900                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14901                         info.version.major,
14902                         info.version.minor,
14903                         info.version.update,
14904                         info.version.draft);
14905                 printf("i40e Profile name:     %s\n\n", info.name);
14906         }
14907
14908         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14909                                 (uint8_t *)&buff_size, sizeof(buff_size),
14910                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14911         if (!ret && buff_size) {
14912                 buff = (uint8_t *)malloc(buff_size);
14913                 if (buff) {
14914                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14915                                                 buff, buff_size,
14916                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14917                         if (!ret)
14918                                 printf("Package Notes:\n%s\n\n", buff);
14919                         free(buff);
14920                 }
14921         }
14922
14923         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14924                                 (uint8_t *)&dev_num, sizeof(dev_num),
14925                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14926         if (!ret && dev_num) {
14927                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14928                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14929                 if (devs) {
14930                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14931                                                 (uint8_t *)devs, buff_size,
14932                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14933                         if (!ret) {
14934                                 printf("List of supported devices:\n");
14935                                 for (i = 0; i < dev_num; i++) {
14936                                         printf("  %04X:%04X %04X:%04X\n",
14937                                                 devs[i].vendor_dev_id >> 16,
14938                                                 devs[i].vendor_dev_id & 0xFFFF,
14939                                                 devs[i].sub_vendor_dev_id >> 16,
14940                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14941                                 }
14942                                 printf("\n");
14943                         }
14944                         free(devs);
14945                 }
14946         }
14947
14948         /* get information about protocols and packet types */
14949         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14950                 (uint8_t *)&proto_num, sizeof(proto_num),
14951                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14952         if (ret || !proto_num)
14953                 goto no_print_return;
14954
14955         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14956         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14957         if (!proto)
14958                 goto no_print_return;
14959
14960         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14961                                         buff_size,
14962                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14963         if (!ret) {
14964                 printf("List of used protocols:\n");
14965                 for (i = 0; i < proto_num; i++)
14966                         printf("  %2u: %s\n", proto[i].proto_id,
14967                                proto[i].name);
14968                 printf("\n");
14969         }
14970         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14971                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14972                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14973         if (ret || !pctype_num)
14974                 goto no_print_pctypes;
14975
14976         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14977         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14978         if (!pctype)
14979                 goto no_print_pctypes;
14980
14981         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14982                                         buff_size,
14983                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14984         if (ret) {
14985                 free(pctype);
14986                 goto no_print_pctypes;
14987         }
14988
14989         printf("List of defined packet classification types:\n");
14990         for (i = 0; i < pctype_num; i++) {
14991                 printf("  %2u:", pctype[i].ptype_id);
14992                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14993                         proto_id = pctype[i].protocols[j];
14994                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14995                                 for (n = 0; n < proto_num; n++) {
14996                                         if (proto[n].proto_id == proto_id) {
14997                                                 printf(" %s", proto[n].name);
14998                                                 break;
14999                                         }
15000                                 }
15001                         }
15002                 }
15003                 printf("\n");
15004         }
15005         printf("\n");
15006         free(pctype);
15007
15008 no_print_pctypes:
15009
15010         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15011                                         sizeof(ptype_num),
15012                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15013         if (ret || !ptype_num)
15014                 goto no_print_return;
15015
15016         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15017         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15018         if (!ptype)
15019                 goto no_print_return;
15020
15021         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15022                                         buff_size,
15023                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15024         if (ret) {
15025                 free(ptype);
15026                 goto no_print_return;
15027         }
15028         printf("List of defined packet types:\n");
15029         for (i = 0; i < ptype_num; i++) {
15030                 printf("  %2u:", ptype[i].ptype_id);
15031                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15032                         proto_id = ptype[i].protocols[j];
15033                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15034                                 for (n = 0; n < proto_num; n++) {
15035                                         if (proto[n].proto_id == proto_id) {
15036                                                 printf(" %s", proto[n].name);
15037                                                 break;
15038                                         }
15039                                 }
15040                         }
15041                 }
15042                 printf("\n");
15043         }
15044         free(ptype);
15045         printf("\n");
15046
15047         ret = 0;
15048 no_print_return:
15049         if (proto)
15050                 free(proto);
15051 #endif
15052         if (ret == -ENOTSUP)
15053                 printf("Function not supported in PMD driver\n");
15054         close_file(pkg);
15055 }
15056
15057 cmdline_parse_inst_t cmd_ddp_get_info = {
15058         .f = cmd_ddp_info_parsed,
15059         .data = NULL,
15060         .help_str = "ddp get info <profile_path>",
15061         .tokens = {
15062                 (void *)&cmd_ddp_info_ddp,
15063                 (void *)&cmd_ddp_info_get,
15064                 (void *)&cmd_ddp_info_info,
15065                 (void *)&cmd_ddp_info_filepath,
15066                 NULL,
15067         },
15068 };
15069
15070 /* Get dynamic device personalization profile info list*/
15071 #define PROFILE_INFO_SIZE 48
15072 #define MAX_PROFILE_NUM 16
15073
15074 struct cmd_ddp_get_list_result {
15075         cmdline_fixed_string_t ddp;
15076         cmdline_fixed_string_t get;
15077         cmdline_fixed_string_t list;
15078         portid_t port_id;
15079 };
15080
15081 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15082         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15083 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15084         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15085 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15086         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15087 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15088         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15089
15090 static void
15091 cmd_ddp_get_list_parsed(
15092         __attribute__((unused)) void *parsed_result,
15093         __attribute__((unused)) struct cmdline *cl,
15094         __attribute__((unused)) void *data)
15095 {
15096 #ifdef RTE_LIBRTE_I40E_PMD
15097         struct cmd_ddp_get_list_result *res = parsed_result;
15098         struct rte_pmd_i40e_profile_list *p_list;
15099         struct rte_pmd_i40e_profile_info *p_info;
15100         uint32_t p_num;
15101         uint32_t size;
15102         uint32_t i;
15103 #endif
15104         int ret = -ENOTSUP;
15105
15106 #ifdef RTE_LIBRTE_I40E_PMD
15107         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15108         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15109         if (!p_list)
15110                 printf("%s: Failed to malloc buffer\n", __func__);
15111
15112         if (ret == -ENOTSUP)
15113                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15114                                                 (uint8_t *)p_list, size);
15115
15116         if (!ret) {
15117                 p_num = p_list->p_count;
15118                 printf("Profile number is: %d\n\n", p_num);
15119
15120                 for (i = 0; i < p_num; i++) {
15121                         p_info = &p_list->p_info[i];
15122                         printf("Profile %d:\n", i);
15123                         printf("Track id:     0x%x\n", p_info->track_id);
15124                         printf("Version:      %d.%d.%d.%d\n",
15125                                p_info->version.major,
15126                                p_info->version.minor,
15127                                p_info->version.update,
15128                                p_info->version.draft);
15129                         printf("Profile name: %s\n\n", p_info->name);
15130                 }
15131         }
15132
15133         free(p_list);
15134 #endif
15135
15136         if (ret < 0)
15137                 printf("Failed to get ddp list\n");
15138 }
15139
15140 cmdline_parse_inst_t cmd_ddp_get_list = {
15141         .f = cmd_ddp_get_list_parsed,
15142         .data = NULL,
15143         .help_str = "ddp get list <port_id>",
15144         .tokens = {
15145                 (void *)&cmd_ddp_get_list_ddp,
15146                 (void *)&cmd_ddp_get_list_get,
15147                 (void *)&cmd_ddp_get_list_list,
15148                 (void *)&cmd_ddp_get_list_port_id,
15149                 NULL,
15150         },
15151 };
15152
15153 /* Configure input set */
15154 struct cmd_cfg_input_set_result {
15155         cmdline_fixed_string_t port;
15156         cmdline_fixed_string_t cfg;
15157         portid_t port_id;
15158         cmdline_fixed_string_t pctype;
15159         uint8_t pctype_id;
15160         cmdline_fixed_string_t inset_type;
15161         cmdline_fixed_string_t opt;
15162         cmdline_fixed_string_t field;
15163         uint8_t field_idx;
15164 };
15165
15166 static void
15167 cmd_cfg_input_set_parsed(
15168         __attribute__((unused)) void *parsed_result,
15169         __attribute__((unused)) struct cmdline *cl,
15170         __attribute__((unused)) void *data)
15171 {
15172 #ifdef RTE_LIBRTE_I40E_PMD
15173         struct cmd_cfg_input_set_result *res = parsed_result;
15174         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15175         struct rte_pmd_i40e_inset inset;
15176 #endif
15177         int ret = -ENOTSUP;
15178
15179         if (!all_ports_stopped()) {
15180                 printf("Please stop all ports first\n");
15181                 return;
15182         }
15183
15184 #ifdef RTE_LIBRTE_I40E_PMD
15185         if (!strcmp(res->inset_type, "hash_inset"))
15186                 inset_type = INSET_HASH;
15187         else if (!strcmp(res->inset_type, "fdir_inset"))
15188                 inset_type = INSET_FDIR;
15189         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15190                 inset_type = INSET_FDIR_FLX;
15191         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15192                                      &inset, inset_type);
15193         if (ret) {
15194                 printf("Failed to get input set.\n");
15195                 return;
15196         }
15197
15198         if (!strcmp(res->opt, "get")) {
15199                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15200                                                    res->field_idx);
15201                 if (ret)
15202                         printf("Field index %d is enabled.\n", res->field_idx);
15203                 else
15204                         printf("Field index %d is disabled.\n", res->field_idx);
15205                 return;
15206         } else if (!strcmp(res->opt, "set"))
15207                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15208                                                    res->field_idx);
15209         else if (!strcmp(res->opt, "clear"))
15210                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15211                                                      res->field_idx);
15212         if (ret) {
15213                 printf("Failed to configure input set field.\n");
15214                 return;
15215         }
15216
15217         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15218                                      &inset, inset_type);
15219         if (ret) {
15220                 printf("Failed to set input set.\n");
15221                 return;
15222         }
15223 #endif
15224
15225         if (ret == -ENOTSUP)
15226                 printf("Function not supported\n");
15227 }
15228
15229 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15230         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15231                                  port, "port");
15232 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15233         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15234                                  cfg, "config");
15235 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15236         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15237                               port_id, UINT16);
15238 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15239         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15240                                  pctype, "pctype");
15241 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15242         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15243                               pctype_id, UINT8);
15244 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15245         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15246                                  inset_type,
15247                                  "hash_inset#fdir_inset#fdir_flx_inset");
15248 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15249         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15250                                  opt, "get#set#clear");
15251 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15252         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15253                                  field, "field");
15254 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15255         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15256                               field_idx, UINT8);
15257
15258 cmdline_parse_inst_t cmd_cfg_input_set = {
15259         .f = cmd_cfg_input_set_parsed,
15260         .data = NULL,
15261         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15262                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15263         .tokens = {
15264                 (void *)&cmd_cfg_input_set_port,
15265                 (void *)&cmd_cfg_input_set_cfg,
15266                 (void *)&cmd_cfg_input_set_port_id,
15267                 (void *)&cmd_cfg_input_set_pctype,
15268                 (void *)&cmd_cfg_input_set_pctype_id,
15269                 (void *)&cmd_cfg_input_set_inset_type,
15270                 (void *)&cmd_cfg_input_set_opt,
15271                 (void *)&cmd_cfg_input_set_field,
15272                 (void *)&cmd_cfg_input_set_field_idx,
15273                 NULL,
15274         },
15275 };
15276
15277 /* Clear input set */
15278 struct cmd_clear_input_set_result {
15279         cmdline_fixed_string_t port;
15280         cmdline_fixed_string_t cfg;
15281         portid_t port_id;
15282         cmdline_fixed_string_t pctype;
15283         uint8_t pctype_id;
15284         cmdline_fixed_string_t inset_type;
15285         cmdline_fixed_string_t clear;
15286         cmdline_fixed_string_t all;
15287 };
15288
15289 static void
15290 cmd_clear_input_set_parsed(
15291         __attribute__((unused)) void *parsed_result,
15292         __attribute__((unused)) struct cmdline *cl,
15293         __attribute__((unused)) void *data)
15294 {
15295 #ifdef RTE_LIBRTE_I40E_PMD
15296         struct cmd_clear_input_set_result *res = parsed_result;
15297         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15298         struct rte_pmd_i40e_inset inset;
15299 #endif
15300         int ret = -ENOTSUP;
15301
15302         if (!all_ports_stopped()) {
15303                 printf("Please stop all ports first\n");
15304                 return;
15305         }
15306
15307 #ifdef RTE_LIBRTE_I40E_PMD
15308         if (!strcmp(res->inset_type, "hash_inset"))
15309                 inset_type = INSET_HASH;
15310         else if (!strcmp(res->inset_type, "fdir_inset"))
15311                 inset_type = INSET_FDIR;
15312         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15313                 inset_type = INSET_FDIR_FLX;
15314
15315         memset(&inset, 0, sizeof(inset));
15316
15317         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15318                                      &inset, inset_type);
15319         if (ret) {
15320                 printf("Failed to clear input set.\n");
15321                 return;
15322         }
15323
15324 #endif
15325
15326         if (ret == -ENOTSUP)
15327                 printf("Function not supported\n");
15328 }
15329
15330 cmdline_parse_token_string_t cmd_clear_input_set_port =
15331         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15332                                  port, "port");
15333 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15334         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15335                                  cfg, "config");
15336 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15337         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15338                               port_id, UINT16);
15339 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15340         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15341                                  pctype, "pctype");
15342 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15343         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15344                               pctype_id, UINT8);
15345 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15346         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15347                                  inset_type,
15348                                  "hash_inset#fdir_inset#fdir_flx_inset");
15349 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15350         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15351                                  clear, "clear");
15352 cmdline_parse_token_string_t cmd_clear_input_set_all =
15353         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15354                                  all, "all");
15355
15356 cmdline_parse_inst_t cmd_clear_input_set = {
15357         .f = cmd_clear_input_set_parsed,
15358         .data = NULL,
15359         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15360                     "fdir_inset|fdir_flx_inset clear all",
15361         .tokens = {
15362                 (void *)&cmd_clear_input_set_port,
15363                 (void *)&cmd_clear_input_set_cfg,
15364                 (void *)&cmd_clear_input_set_port_id,
15365                 (void *)&cmd_clear_input_set_pctype,
15366                 (void *)&cmd_clear_input_set_pctype_id,
15367                 (void *)&cmd_clear_input_set_inset_type,
15368                 (void *)&cmd_clear_input_set_clear,
15369                 (void *)&cmd_clear_input_set_all,
15370                 NULL,
15371         },
15372 };
15373
15374 /* show vf stats */
15375
15376 /* Common result structure for show vf stats */
15377 struct cmd_show_vf_stats_result {
15378         cmdline_fixed_string_t show;
15379         cmdline_fixed_string_t vf;
15380         cmdline_fixed_string_t stats;
15381         portid_t port_id;
15382         uint16_t vf_id;
15383 };
15384
15385 /* Common CLI fields show vf stats*/
15386 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15387         TOKEN_STRING_INITIALIZER
15388                 (struct cmd_show_vf_stats_result,
15389                  show, "show");
15390 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15391         TOKEN_STRING_INITIALIZER
15392                 (struct cmd_show_vf_stats_result,
15393                  vf, "vf");
15394 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15395         TOKEN_STRING_INITIALIZER
15396                 (struct cmd_show_vf_stats_result,
15397                  stats, "stats");
15398 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15399         TOKEN_NUM_INITIALIZER
15400                 (struct cmd_show_vf_stats_result,
15401                  port_id, UINT16);
15402 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15403         TOKEN_NUM_INITIALIZER
15404                 (struct cmd_show_vf_stats_result,
15405                  vf_id, UINT16);
15406
15407 static void
15408 cmd_show_vf_stats_parsed(
15409         void *parsed_result,
15410         __attribute__((unused)) struct cmdline *cl,
15411         __attribute__((unused)) void *data)
15412 {
15413         struct cmd_show_vf_stats_result *res = parsed_result;
15414         struct rte_eth_stats stats;
15415         int ret = -ENOTSUP;
15416         static const char *nic_stats_border = "########################";
15417
15418         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15419                 return;
15420
15421         memset(&stats, 0, sizeof(stats));
15422
15423 #ifdef RTE_LIBRTE_I40E_PMD
15424         if (ret == -ENOTSUP)
15425                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15426                                                 res->vf_id,
15427                                                 &stats);
15428 #endif
15429 #ifdef RTE_LIBRTE_BNXT_PMD
15430         if (ret == -ENOTSUP)
15431                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15432                                                 res->vf_id,
15433                                                 &stats);
15434 #endif
15435
15436         switch (ret) {
15437         case 0:
15438                 break;
15439         case -EINVAL:
15440                 printf("invalid vf_id %d\n", res->vf_id);
15441                 break;
15442         case -ENODEV:
15443                 printf("invalid port_id %d\n", res->port_id);
15444                 break;
15445         case -ENOTSUP:
15446                 printf("function not implemented\n");
15447                 break;
15448         default:
15449                 printf("programming error: (%s)\n", strerror(-ret));
15450         }
15451
15452         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15453                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15454
15455         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15456                "%-"PRIu64"\n",
15457                stats.ipackets, stats.imissed, stats.ibytes);
15458         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15459         printf("  RX-nombuf:  %-10"PRIu64"\n",
15460                stats.rx_nombuf);
15461         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15462                "%-"PRIu64"\n",
15463                stats.opackets, stats.oerrors, stats.obytes);
15464
15465         printf("  %s############################%s\n",
15466                                nic_stats_border, nic_stats_border);
15467 }
15468
15469 cmdline_parse_inst_t cmd_show_vf_stats = {
15470         .f = cmd_show_vf_stats_parsed,
15471         .data = NULL,
15472         .help_str = "show vf stats <port_id> <vf_id>",
15473         .tokens = {
15474                 (void *)&cmd_show_vf_stats_show,
15475                 (void *)&cmd_show_vf_stats_vf,
15476                 (void *)&cmd_show_vf_stats_stats,
15477                 (void *)&cmd_show_vf_stats_port_id,
15478                 (void *)&cmd_show_vf_stats_vf_id,
15479                 NULL,
15480         },
15481 };
15482
15483 /* clear vf stats */
15484
15485 /* Common result structure for clear vf stats */
15486 struct cmd_clear_vf_stats_result {
15487         cmdline_fixed_string_t clear;
15488         cmdline_fixed_string_t vf;
15489         cmdline_fixed_string_t stats;
15490         portid_t port_id;
15491         uint16_t vf_id;
15492 };
15493
15494 /* Common CLI fields clear vf stats*/
15495 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15496         TOKEN_STRING_INITIALIZER
15497                 (struct cmd_clear_vf_stats_result,
15498                  clear, "clear");
15499 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15500         TOKEN_STRING_INITIALIZER
15501                 (struct cmd_clear_vf_stats_result,
15502                  vf, "vf");
15503 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15504         TOKEN_STRING_INITIALIZER
15505                 (struct cmd_clear_vf_stats_result,
15506                  stats, "stats");
15507 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15508         TOKEN_NUM_INITIALIZER
15509                 (struct cmd_clear_vf_stats_result,
15510                  port_id, UINT16);
15511 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15512         TOKEN_NUM_INITIALIZER
15513                 (struct cmd_clear_vf_stats_result,
15514                  vf_id, UINT16);
15515
15516 static void
15517 cmd_clear_vf_stats_parsed(
15518         void *parsed_result,
15519         __attribute__((unused)) struct cmdline *cl,
15520         __attribute__((unused)) void *data)
15521 {
15522         struct cmd_clear_vf_stats_result *res = parsed_result;
15523         int ret = -ENOTSUP;
15524
15525         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15526                 return;
15527
15528 #ifdef RTE_LIBRTE_I40E_PMD
15529         if (ret == -ENOTSUP)
15530                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15531                                                   res->vf_id);
15532 #endif
15533 #ifdef RTE_LIBRTE_BNXT_PMD
15534         if (ret == -ENOTSUP)
15535                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15536                                                   res->vf_id);
15537 #endif
15538
15539         switch (ret) {
15540         case 0:
15541                 break;
15542         case -EINVAL:
15543                 printf("invalid vf_id %d\n", res->vf_id);
15544                 break;
15545         case -ENODEV:
15546                 printf("invalid port_id %d\n", res->port_id);
15547                 break;
15548         case -ENOTSUP:
15549                 printf("function not implemented\n");
15550                 break;
15551         default:
15552                 printf("programming error: (%s)\n", strerror(-ret));
15553         }
15554 }
15555
15556 cmdline_parse_inst_t cmd_clear_vf_stats = {
15557         .f = cmd_clear_vf_stats_parsed,
15558         .data = NULL,
15559         .help_str = "clear vf stats <port_id> <vf_id>",
15560         .tokens = {
15561                 (void *)&cmd_clear_vf_stats_clear,
15562                 (void *)&cmd_clear_vf_stats_vf,
15563                 (void *)&cmd_clear_vf_stats_stats,
15564                 (void *)&cmd_clear_vf_stats_port_id,
15565                 (void *)&cmd_clear_vf_stats_vf_id,
15566                 NULL,
15567         },
15568 };
15569
15570 /* port config pctype mapping reset */
15571
15572 /* Common result structure for port config pctype mapping reset */
15573 struct cmd_pctype_mapping_reset_result {
15574         cmdline_fixed_string_t port;
15575         cmdline_fixed_string_t config;
15576         portid_t port_id;
15577         cmdline_fixed_string_t pctype;
15578         cmdline_fixed_string_t mapping;
15579         cmdline_fixed_string_t reset;
15580 };
15581
15582 /* Common CLI fields for port config pctype mapping reset*/
15583 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15584         TOKEN_STRING_INITIALIZER
15585                 (struct cmd_pctype_mapping_reset_result,
15586                  port, "port");
15587 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15588         TOKEN_STRING_INITIALIZER
15589                 (struct cmd_pctype_mapping_reset_result,
15590                  config, "config");
15591 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15592         TOKEN_NUM_INITIALIZER
15593                 (struct cmd_pctype_mapping_reset_result,
15594                  port_id, UINT16);
15595 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15596         TOKEN_STRING_INITIALIZER
15597                 (struct cmd_pctype_mapping_reset_result,
15598                  pctype, "pctype");
15599 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15600         TOKEN_STRING_INITIALIZER
15601                 (struct cmd_pctype_mapping_reset_result,
15602                  mapping, "mapping");
15603 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15604         TOKEN_STRING_INITIALIZER
15605                 (struct cmd_pctype_mapping_reset_result,
15606                  reset, "reset");
15607
15608 static void
15609 cmd_pctype_mapping_reset_parsed(
15610         void *parsed_result,
15611         __attribute__((unused)) struct cmdline *cl,
15612         __attribute__((unused)) void *data)
15613 {
15614         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15615         int ret = -ENOTSUP;
15616
15617         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15618                 return;
15619
15620 #ifdef RTE_LIBRTE_I40E_PMD
15621         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15622 #endif
15623
15624         switch (ret) {
15625         case 0:
15626                 break;
15627         case -ENODEV:
15628                 printf("invalid port_id %d\n", res->port_id);
15629                 break;
15630         case -ENOTSUP:
15631                 printf("function not implemented\n");
15632                 break;
15633         default:
15634                 printf("programming error: (%s)\n", strerror(-ret));
15635         }
15636 }
15637
15638 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15639         .f = cmd_pctype_mapping_reset_parsed,
15640         .data = NULL,
15641         .help_str = "port config <port_id> pctype mapping reset",
15642         .tokens = {
15643                 (void *)&cmd_pctype_mapping_reset_port,
15644                 (void *)&cmd_pctype_mapping_reset_config,
15645                 (void *)&cmd_pctype_mapping_reset_port_id,
15646                 (void *)&cmd_pctype_mapping_reset_pctype,
15647                 (void *)&cmd_pctype_mapping_reset_mapping,
15648                 (void *)&cmd_pctype_mapping_reset_reset,
15649                 NULL,
15650         },
15651 };
15652
15653 /* show port pctype mapping */
15654
15655 /* Common result structure for show port pctype mapping */
15656 struct cmd_pctype_mapping_get_result {
15657         cmdline_fixed_string_t show;
15658         cmdline_fixed_string_t port;
15659         portid_t port_id;
15660         cmdline_fixed_string_t pctype;
15661         cmdline_fixed_string_t mapping;
15662 };
15663
15664 /* Common CLI fields for pctype mapping get */
15665 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15666         TOKEN_STRING_INITIALIZER
15667                 (struct cmd_pctype_mapping_get_result,
15668                  show, "show");
15669 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15670         TOKEN_STRING_INITIALIZER
15671                 (struct cmd_pctype_mapping_get_result,
15672                  port, "port");
15673 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15674         TOKEN_NUM_INITIALIZER
15675                 (struct cmd_pctype_mapping_get_result,
15676                  port_id, UINT16);
15677 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15678         TOKEN_STRING_INITIALIZER
15679                 (struct cmd_pctype_mapping_get_result,
15680                  pctype, "pctype");
15681 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15682         TOKEN_STRING_INITIALIZER
15683                 (struct cmd_pctype_mapping_get_result,
15684                  mapping, "mapping");
15685
15686 static void
15687 cmd_pctype_mapping_get_parsed(
15688         void *parsed_result,
15689         __attribute__((unused)) struct cmdline *cl,
15690         __attribute__((unused)) void *data)
15691 {
15692         struct cmd_pctype_mapping_get_result *res = parsed_result;
15693         int ret = -ENOTSUP;
15694 #ifdef RTE_LIBRTE_I40E_PMD
15695         struct rte_pmd_i40e_flow_type_mapping
15696                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15697         int i, j, first_pctype;
15698 #endif
15699
15700         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15701                 return;
15702
15703 #ifdef RTE_LIBRTE_I40E_PMD
15704         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15705 #endif
15706
15707         switch (ret) {
15708         case 0:
15709                 break;
15710         case -ENODEV:
15711                 printf("invalid port_id %d\n", res->port_id);
15712                 return;
15713         case -ENOTSUP:
15714                 printf("function not implemented\n");
15715                 return;
15716         default:
15717                 printf("programming error: (%s)\n", strerror(-ret));
15718                 return;
15719         }
15720
15721 #ifdef RTE_LIBRTE_I40E_PMD
15722         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15723                 if (mapping[i].pctype != 0ULL) {
15724                         first_pctype = 1;
15725
15726                         printf("pctype: ");
15727                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15728                                 if (mapping[i].pctype & (1ULL << j)) {
15729                                         printf(first_pctype ?
15730                                                "%02d" : ",%02d", j);
15731                                         first_pctype = 0;
15732                                 }
15733                         }
15734                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15735                 }
15736         }
15737 #endif
15738 }
15739
15740 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15741         .f = cmd_pctype_mapping_get_parsed,
15742         .data = NULL,
15743         .help_str = "show port <port_id> pctype mapping",
15744         .tokens = {
15745                 (void *)&cmd_pctype_mapping_get_show,
15746                 (void *)&cmd_pctype_mapping_get_port,
15747                 (void *)&cmd_pctype_mapping_get_port_id,
15748                 (void *)&cmd_pctype_mapping_get_pctype,
15749                 (void *)&cmd_pctype_mapping_get_mapping,
15750                 NULL,
15751         },
15752 };
15753
15754 /* port config pctype mapping update */
15755
15756 /* Common result structure for port config pctype mapping update */
15757 struct cmd_pctype_mapping_update_result {
15758         cmdline_fixed_string_t port;
15759         cmdline_fixed_string_t config;
15760         portid_t port_id;
15761         cmdline_fixed_string_t pctype;
15762         cmdline_fixed_string_t mapping;
15763         cmdline_fixed_string_t update;
15764         cmdline_fixed_string_t pctype_list;
15765         uint16_t flow_type;
15766 };
15767
15768 /* Common CLI fields for pctype mapping update*/
15769 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15770         TOKEN_STRING_INITIALIZER
15771                 (struct cmd_pctype_mapping_update_result,
15772                  port, "port");
15773 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15774         TOKEN_STRING_INITIALIZER
15775                 (struct cmd_pctype_mapping_update_result,
15776                  config, "config");
15777 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15778         TOKEN_NUM_INITIALIZER
15779                 (struct cmd_pctype_mapping_update_result,
15780                  port_id, UINT16);
15781 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15782         TOKEN_STRING_INITIALIZER
15783                 (struct cmd_pctype_mapping_update_result,
15784                  pctype, "pctype");
15785 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15786         TOKEN_STRING_INITIALIZER
15787                 (struct cmd_pctype_mapping_update_result,
15788                  mapping, "mapping");
15789 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15790         TOKEN_STRING_INITIALIZER
15791                 (struct cmd_pctype_mapping_update_result,
15792                  update, "update");
15793 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15794         TOKEN_STRING_INITIALIZER
15795                 (struct cmd_pctype_mapping_update_result,
15796                  pctype_list, NULL);
15797 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15798         TOKEN_NUM_INITIALIZER
15799                 (struct cmd_pctype_mapping_update_result,
15800                  flow_type, UINT16);
15801
15802 static void
15803 cmd_pctype_mapping_update_parsed(
15804         void *parsed_result,
15805         __attribute__((unused)) struct cmdline *cl,
15806         __attribute__((unused)) void *data)
15807 {
15808         struct cmd_pctype_mapping_update_result *res = parsed_result;
15809         int ret = -ENOTSUP;
15810 #ifdef RTE_LIBRTE_I40E_PMD
15811         struct rte_pmd_i40e_flow_type_mapping mapping;
15812         unsigned int i;
15813         unsigned int nb_item;
15814         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15815 #endif
15816
15817         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15818                 return;
15819
15820 #ifdef RTE_LIBRTE_I40E_PMD
15821         nb_item = parse_item_list(res->pctype_list, "pctypes",
15822                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15823         mapping.flow_type = res->flow_type;
15824         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15825                 mapping.pctype |= (1ULL << pctype_list[i]);
15826         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15827                                                 &mapping,
15828                                                 1,
15829                                                 0);
15830 #endif
15831
15832         switch (ret) {
15833         case 0:
15834                 break;
15835         case -EINVAL:
15836                 printf("invalid pctype or flow type\n");
15837                 break;
15838         case -ENODEV:
15839                 printf("invalid port_id %d\n", res->port_id);
15840                 break;
15841         case -ENOTSUP:
15842                 printf("function not implemented\n");
15843                 break;
15844         default:
15845                 printf("programming error: (%s)\n", strerror(-ret));
15846         }
15847 }
15848
15849 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15850         .f = cmd_pctype_mapping_update_parsed,
15851         .data = NULL,
15852         .help_str = "port config <port_id> pctype mapping update"
15853         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15854         .tokens = {
15855                 (void *)&cmd_pctype_mapping_update_port,
15856                 (void *)&cmd_pctype_mapping_update_config,
15857                 (void *)&cmd_pctype_mapping_update_port_id,
15858                 (void *)&cmd_pctype_mapping_update_pctype,
15859                 (void *)&cmd_pctype_mapping_update_mapping,
15860                 (void *)&cmd_pctype_mapping_update_update,
15861                 (void *)&cmd_pctype_mapping_update_pc_type,
15862                 (void *)&cmd_pctype_mapping_update_flow_type,
15863                 NULL,
15864         },
15865 };
15866
15867 /* ptype mapping get */
15868
15869 /* Common result structure for ptype mapping get */
15870 struct cmd_ptype_mapping_get_result {
15871         cmdline_fixed_string_t ptype;
15872         cmdline_fixed_string_t mapping;
15873         cmdline_fixed_string_t get;
15874         portid_t port_id;
15875         uint8_t valid_only;
15876 };
15877
15878 /* Common CLI fields for ptype mapping get */
15879 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15880         TOKEN_STRING_INITIALIZER
15881                 (struct cmd_ptype_mapping_get_result,
15882                  ptype, "ptype");
15883 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15884         TOKEN_STRING_INITIALIZER
15885                 (struct cmd_ptype_mapping_get_result,
15886                  mapping, "mapping");
15887 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15888         TOKEN_STRING_INITIALIZER
15889                 (struct cmd_ptype_mapping_get_result,
15890                  get, "get");
15891 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15892         TOKEN_NUM_INITIALIZER
15893                 (struct cmd_ptype_mapping_get_result,
15894                  port_id, UINT16);
15895 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15896         TOKEN_NUM_INITIALIZER
15897                 (struct cmd_ptype_mapping_get_result,
15898                  valid_only, UINT8);
15899
15900 static void
15901 cmd_ptype_mapping_get_parsed(
15902         void *parsed_result,
15903         __attribute__((unused)) struct cmdline *cl,
15904         __attribute__((unused)) void *data)
15905 {
15906         struct cmd_ptype_mapping_get_result *res = parsed_result;
15907         int ret = -ENOTSUP;
15908 #ifdef RTE_LIBRTE_I40E_PMD
15909         int max_ptype_num = 256;
15910         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15911         uint16_t count;
15912         int i;
15913 #endif
15914
15915         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15916                 return;
15917
15918 #ifdef RTE_LIBRTE_I40E_PMD
15919         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15920                                         mapping,
15921                                         max_ptype_num,
15922                                         &count,
15923                                         res->valid_only);
15924 #endif
15925
15926         switch (ret) {
15927         case 0:
15928                 break;
15929         case -ENODEV:
15930                 printf("invalid port_id %d\n", res->port_id);
15931                 break;
15932         case -ENOTSUP:
15933                 printf("function not implemented\n");
15934                 break;
15935         default:
15936                 printf("programming error: (%s)\n", strerror(-ret));
15937         }
15938
15939 #ifdef RTE_LIBRTE_I40E_PMD
15940         if (!ret) {
15941                 for (i = 0; i < count; i++)
15942                         printf("%3d\t0x%08x\n",
15943                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15944         }
15945 #endif
15946 }
15947
15948 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15949         .f = cmd_ptype_mapping_get_parsed,
15950         .data = NULL,
15951         .help_str = "ptype mapping get <port_id> <valid_only>",
15952         .tokens = {
15953                 (void *)&cmd_ptype_mapping_get_ptype,
15954                 (void *)&cmd_ptype_mapping_get_mapping,
15955                 (void *)&cmd_ptype_mapping_get_get,
15956                 (void *)&cmd_ptype_mapping_get_port_id,
15957                 (void *)&cmd_ptype_mapping_get_valid_only,
15958                 NULL,
15959         },
15960 };
15961
15962 /* ptype mapping replace */
15963
15964 /* Common result structure for ptype mapping replace */
15965 struct cmd_ptype_mapping_replace_result {
15966         cmdline_fixed_string_t ptype;
15967         cmdline_fixed_string_t mapping;
15968         cmdline_fixed_string_t replace;
15969         portid_t port_id;
15970         uint32_t target;
15971         uint8_t mask;
15972         uint32_t pkt_type;
15973 };
15974
15975 /* Common CLI fields for ptype mapping replace */
15976 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15977         TOKEN_STRING_INITIALIZER
15978                 (struct cmd_ptype_mapping_replace_result,
15979                  ptype, "ptype");
15980 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15981         TOKEN_STRING_INITIALIZER
15982                 (struct cmd_ptype_mapping_replace_result,
15983                  mapping, "mapping");
15984 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15985         TOKEN_STRING_INITIALIZER
15986                 (struct cmd_ptype_mapping_replace_result,
15987                  replace, "replace");
15988 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15989         TOKEN_NUM_INITIALIZER
15990                 (struct cmd_ptype_mapping_replace_result,
15991                  port_id, UINT16);
15992 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15993         TOKEN_NUM_INITIALIZER
15994                 (struct cmd_ptype_mapping_replace_result,
15995                  target, UINT32);
15996 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15997         TOKEN_NUM_INITIALIZER
15998                 (struct cmd_ptype_mapping_replace_result,
15999                  mask, UINT8);
16000 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16001         TOKEN_NUM_INITIALIZER
16002                 (struct cmd_ptype_mapping_replace_result,
16003                  pkt_type, UINT32);
16004
16005 static void
16006 cmd_ptype_mapping_replace_parsed(
16007         void *parsed_result,
16008         __attribute__((unused)) struct cmdline *cl,
16009         __attribute__((unused)) void *data)
16010 {
16011         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16012         int ret = -ENOTSUP;
16013
16014         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16015                 return;
16016
16017 #ifdef RTE_LIBRTE_I40E_PMD
16018         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16019                                         res->target,
16020                                         res->mask,
16021                                         res->pkt_type);
16022 #endif
16023
16024         switch (ret) {
16025         case 0:
16026                 break;
16027         case -EINVAL:
16028                 printf("invalid ptype 0x%8x or 0x%8x\n",
16029                                 res->target, res->pkt_type);
16030                 break;
16031         case -ENODEV:
16032                 printf("invalid port_id %d\n", res->port_id);
16033                 break;
16034         case -ENOTSUP:
16035                 printf("function not implemented\n");
16036                 break;
16037         default:
16038                 printf("programming error: (%s)\n", strerror(-ret));
16039         }
16040 }
16041
16042 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16043         .f = cmd_ptype_mapping_replace_parsed,
16044         .data = NULL,
16045         .help_str =
16046                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16047         .tokens = {
16048                 (void *)&cmd_ptype_mapping_replace_ptype,
16049                 (void *)&cmd_ptype_mapping_replace_mapping,
16050                 (void *)&cmd_ptype_mapping_replace_replace,
16051                 (void *)&cmd_ptype_mapping_replace_port_id,
16052                 (void *)&cmd_ptype_mapping_replace_target,
16053                 (void *)&cmd_ptype_mapping_replace_mask,
16054                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16055                 NULL,
16056         },
16057 };
16058
16059 /* ptype mapping reset */
16060
16061 /* Common result structure for ptype mapping reset */
16062 struct cmd_ptype_mapping_reset_result {
16063         cmdline_fixed_string_t ptype;
16064         cmdline_fixed_string_t mapping;
16065         cmdline_fixed_string_t reset;
16066         portid_t port_id;
16067 };
16068
16069 /* Common CLI fields for ptype mapping reset*/
16070 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16071         TOKEN_STRING_INITIALIZER
16072                 (struct cmd_ptype_mapping_reset_result,
16073                  ptype, "ptype");
16074 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16075         TOKEN_STRING_INITIALIZER
16076                 (struct cmd_ptype_mapping_reset_result,
16077                  mapping, "mapping");
16078 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16079         TOKEN_STRING_INITIALIZER
16080                 (struct cmd_ptype_mapping_reset_result,
16081                  reset, "reset");
16082 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16083         TOKEN_NUM_INITIALIZER
16084                 (struct cmd_ptype_mapping_reset_result,
16085                  port_id, UINT16);
16086
16087 static void
16088 cmd_ptype_mapping_reset_parsed(
16089         void *parsed_result,
16090         __attribute__((unused)) struct cmdline *cl,
16091         __attribute__((unused)) void *data)
16092 {
16093         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16094         int ret = -ENOTSUP;
16095
16096         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16097                 return;
16098
16099 #ifdef RTE_LIBRTE_I40E_PMD
16100         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16101 #endif
16102
16103         switch (ret) {
16104         case 0:
16105                 break;
16106         case -ENODEV:
16107                 printf("invalid port_id %d\n", res->port_id);
16108                 break;
16109         case -ENOTSUP:
16110                 printf("function not implemented\n");
16111                 break;
16112         default:
16113                 printf("programming error: (%s)\n", strerror(-ret));
16114         }
16115 }
16116
16117 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16118         .f = cmd_ptype_mapping_reset_parsed,
16119         .data = NULL,
16120         .help_str = "ptype mapping reset <port_id>",
16121         .tokens = {
16122                 (void *)&cmd_ptype_mapping_reset_ptype,
16123                 (void *)&cmd_ptype_mapping_reset_mapping,
16124                 (void *)&cmd_ptype_mapping_reset_reset,
16125                 (void *)&cmd_ptype_mapping_reset_port_id,
16126                 NULL,
16127         },
16128 };
16129
16130 /* ptype mapping update */
16131
16132 /* Common result structure for ptype mapping update */
16133 struct cmd_ptype_mapping_update_result {
16134         cmdline_fixed_string_t ptype;
16135         cmdline_fixed_string_t mapping;
16136         cmdline_fixed_string_t reset;
16137         portid_t port_id;
16138         uint8_t hw_ptype;
16139         uint32_t sw_ptype;
16140 };
16141
16142 /* Common CLI fields for ptype mapping update*/
16143 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16144         TOKEN_STRING_INITIALIZER
16145                 (struct cmd_ptype_mapping_update_result,
16146                  ptype, "ptype");
16147 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16148         TOKEN_STRING_INITIALIZER
16149                 (struct cmd_ptype_mapping_update_result,
16150                  mapping, "mapping");
16151 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16152         TOKEN_STRING_INITIALIZER
16153                 (struct cmd_ptype_mapping_update_result,
16154                  reset, "update");
16155 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16156         TOKEN_NUM_INITIALIZER
16157                 (struct cmd_ptype_mapping_update_result,
16158                  port_id, UINT16);
16159 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16160         TOKEN_NUM_INITIALIZER
16161                 (struct cmd_ptype_mapping_update_result,
16162                  hw_ptype, UINT8);
16163 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16164         TOKEN_NUM_INITIALIZER
16165                 (struct cmd_ptype_mapping_update_result,
16166                  sw_ptype, UINT32);
16167
16168 static void
16169 cmd_ptype_mapping_update_parsed(
16170         void *parsed_result,
16171         __attribute__((unused)) struct cmdline *cl,
16172         __attribute__((unused)) void *data)
16173 {
16174         struct cmd_ptype_mapping_update_result *res = parsed_result;
16175         int ret = -ENOTSUP;
16176 #ifdef RTE_LIBRTE_I40E_PMD
16177         struct rte_pmd_i40e_ptype_mapping mapping;
16178 #endif
16179         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16180                 return;
16181
16182 #ifdef RTE_LIBRTE_I40E_PMD
16183         mapping.hw_ptype = res->hw_ptype;
16184         mapping.sw_ptype = res->sw_ptype;
16185         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16186                                                 &mapping,
16187                                                 1,
16188                                                 0);
16189 #endif
16190
16191         switch (ret) {
16192         case 0:
16193                 break;
16194         case -EINVAL:
16195                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16196                 break;
16197         case -ENODEV:
16198                 printf("invalid port_id %d\n", res->port_id);
16199                 break;
16200         case -ENOTSUP:
16201                 printf("function not implemented\n");
16202                 break;
16203         default:
16204                 printf("programming error: (%s)\n", strerror(-ret));
16205         }
16206 }
16207
16208 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16209         .f = cmd_ptype_mapping_update_parsed,
16210         .data = NULL,
16211         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16212         .tokens = {
16213                 (void *)&cmd_ptype_mapping_update_ptype,
16214                 (void *)&cmd_ptype_mapping_update_mapping,
16215                 (void *)&cmd_ptype_mapping_update_update,
16216                 (void *)&cmd_ptype_mapping_update_port_id,
16217                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16218                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16219                 NULL,
16220         },
16221 };
16222
16223 /* Common result structure for file commands */
16224 struct cmd_cmdfile_result {
16225         cmdline_fixed_string_t load;
16226         cmdline_fixed_string_t filename;
16227 };
16228
16229 /* Common CLI fields for file commands */
16230 cmdline_parse_token_string_t cmd_load_cmdfile =
16231         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16232 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16233         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16234
16235 static void
16236 cmd_load_from_file_parsed(
16237         void *parsed_result,
16238         __attribute__((unused)) struct cmdline *cl,
16239         __attribute__((unused)) void *data)
16240 {
16241         struct cmd_cmdfile_result *res = parsed_result;
16242
16243         cmdline_read_from_file(res->filename);
16244 }
16245
16246 cmdline_parse_inst_t cmd_load_from_file = {
16247         .f = cmd_load_from_file_parsed,
16248         .data = NULL,
16249         .help_str = "load <filename>",
16250         .tokens = {
16251                 (void *)&cmd_load_cmdfile,
16252                 (void *)&cmd_load_cmdfile_filename,
16253                 NULL,
16254         },
16255 };
16256
16257 /* ******************************************************************************** */
16258
16259 /* list of instructions */
16260 cmdline_parse_ctx_t main_ctx[] = {
16261         (cmdline_parse_inst_t *)&cmd_help_brief,
16262         (cmdline_parse_inst_t *)&cmd_help_long,
16263         (cmdline_parse_inst_t *)&cmd_quit,
16264         (cmdline_parse_inst_t *)&cmd_load_from_file,
16265         (cmdline_parse_inst_t *)&cmd_showport,
16266         (cmdline_parse_inst_t *)&cmd_showqueue,
16267         (cmdline_parse_inst_t *)&cmd_showportall,
16268         (cmdline_parse_inst_t *)&cmd_showcfg,
16269         (cmdline_parse_inst_t *)&cmd_start,
16270         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16271         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16272         (cmdline_parse_inst_t *)&cmd_set_link_up,
16273         (cmdline_parse_inst_t *)&cmd_set_link_down,
16274         (cmdline_parse_inst_t *)&cmd_reset,
16275         (cmdline_parse_inst_t *)&cmd_set_numbers,
16276         (cmdline_parse_inst_t *)&cmd_set_log,
16277         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16278         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16279         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16280         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16281         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16282         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16283         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16284         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16285         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16286         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16287         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16288         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16289         (cmdline_parse_inst_t *)&cmd_set_link_check,
16290         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16291         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16292         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16293         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16294 #ifdef RTE_LIBRTE_PMD_BOND
16295         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16296         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16297         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16298         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16299         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16300         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16301         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16302         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16303         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16304         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16305         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16306 #endif
16307         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16308         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16309         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16310         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16311         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16312         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16313         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16314         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16315         (cmdline_parse_inst_t *)&cmd_csum_set,
16316         (cmdline_parse_inst_t *)&cmd_csum_show,
16317         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16318         (cmdline_parse_inst_t *)&cmd_tso_set,
16319         (cmdline_parse_inst_t *)&cmd_tso_show,
16320         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16321         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16322         (cmdline_parse_inst_t *)&cmd_gro_enable,
16323         (cmdline_parse_inst_t *)&cmd_gro_flush,
16324         (cmdline_parse_inst_t *)&cmd_gro_show,
16325         (cmdline_parse_inst_t *)&cmd_gso_enable,
16326         (cmdline_parse_inst_t *)&cmd_gso_size,
16327         (cmdline_parse_inst_t *)&cmd_gso_show,
16328         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16329         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16330         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16331         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16332         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16333         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16334         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16335         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16336         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16337         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16338         (cmdline_parse_inst_t *)&cmd_config_dcb,
16339         (cmdline_parse_inst_t *)&cmd_read_reg,
16340         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16341         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16342         (cmdline_parse_inst_t *)&cmd_write_reg,
16343         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16344         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16345         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16346         (cmdline_parse_inst_t *)&cmd_stop,
16347         (cmdline_parse_inst_t *)&cmd_mac_addr,
16348         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16349         (cmdline_parse_inst_t *)&cmd_set_qmap,
16350         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16351         (cmdline_parse_inst_t *)&cmd_operate_port,
16352         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16353         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16354         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16355         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16356         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16357         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16358         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16359         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16360         (cmdline_parse_inst_t *)&cmd_config_mtu,
16361         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16362         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16363         (cmdline_parse_inst_t *)&cmd_config_rss,
16364         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16365         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
16366         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16367         (cmdline_parse_inst_t *)&cmd_showport_reta,
16368         (cmdline_parse_inst_t *)&cmd_config_burst,
16369         (cmdline_parse_inst_t *)&cmd_config_thresh,
16370         (cmdline_parse_inst_t *)&cmd_config_threshold,
16371         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16372         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16373         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16374         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16375         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16376         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16377         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16378         (cmdline_parse_inst_t *)&cmd_global_config,
16379         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16380         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16381         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16382         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16383         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16384         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16385         (cmdline_parse_inst_t *)&cmd_dump,
16386         (cmdline_parse_inst_t *)&cmd_dump_one,
16387         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16388         (cmdline_parse_inst_t *)&cmd_syn_filter,
16389         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16390         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16391         (cmdline_parse_inst_t *)&cmd_flex_filter,
16392         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16393         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16394         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16395         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16396         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16397         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16398         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16399         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16400         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16401         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16402         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16403         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16404         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16405         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16406         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16407         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16408         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16409         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16410         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16411         (cmdline_parse_inst_t *)&cmd_flow,
16412         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16413         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16414         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16415         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16416         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16417         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16418         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16419         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16420         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16421         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16422         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16423         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16424         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16425         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16426         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16427         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16428         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16429         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16430         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16431         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16432         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16433         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16434         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16435         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16436         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16437         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16438         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16439         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16440         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16441         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16442         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16443         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16444         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16445         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16446         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16447         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16448         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16449         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16450         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16451         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16452         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16453         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16454         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16455         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16456         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16457         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16458         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16459         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16460         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16461 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16462         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16463 #endif
16464         (cmdline_parse_inst_t *)&cmd_ddp_add,
16465         (cmdline_parse_inst_t *)&cmd_ddp_del,
16466         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16467         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16468         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16469         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16470         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16471         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16472         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16473         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16474         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16475         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16476
16477         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16478         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16479         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16480         (cmdline_parse_inst_t *)&cmd_queue_region,
16481         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16482         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16483         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16484         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16485         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16486         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16487         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16488         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16489         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16490         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16491         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16492         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16493         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16494         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16495         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16496         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16497         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16498         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16499         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16500         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16501         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16502         NULL,
16503 };
16504
16505 /* read cmdline commands from file */
16506 void
16507 cmdline_read_from_file(const char *filename)
16508 {
16509         struct cmdline *cl;
16510
16511         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16512         if (cl == NULL) {
16513                 printf("Failed to create file based cmdline context: %s\n",
16514                        filename);
16515                 return;
16516         }
16517
16518         cmdline_interact(cl);
16519         cmdline_quit(cl);
16520
16521         cmdline_free(cl);
16522
16523         printf("Read CLI commands from %s\n", filename);
16524 }
16525
16526 /* prompt function, called from main on MASTER lcore */
16527 void
16528 prompt(void)
16529 {
16530         /* initialize non-constant commands */
16531         cmd_set_fwd_mode_init();
16532         cmd_set_fwd_retry_mode_init();
16533
16534         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16535         if (testpmd_cl == NULL)
16536                 return;
16537         cmdline_interact(testpmd_cl);
16538         cmdline_stdin_exit(testpmd_cl);
16539 }
16540
16541 void
16542 prompt_exit(void)
16543 {
16544         if (testpmd_cl != NULL)
16545                 cmdline_quit(testpmd_cl);
16546 }
16547
16548 static void
16549 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16550 {
16551         if (id == (portid_t)RTE_PORT_ALL) {
16552                 portid_t pid;
16553
16554                 RTE_ETH_FOREACH_DEV(pid) {
16555                         /* check if need_reconfig has been set to 1 */
16556                         if (ports[pid].need_reconfig == 0)
16557                                 ports[pid].need_reconfig = dev;
16558                         /* check if need_reconfig_queues has been set to 1 */
16559                         if (ports[pid].need_reconfig_queues == 0)
16560                                 ports[pid].need_reconfig_queues = queue;
16561                 }
16562         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16563                 /* check if need_reconfig has been set to 1 */
16564                 if (ports[id].need_reconfig == 0)
16565                         ports[id].need_reconfig = dev;
16566                 /* check if need_reconfig_queues has been set to 1 */
16567                 if (ports[id].need_reconfig_queues == 0)
16568                         ports[id].need_reconfig_queues = queue;
16569         }
16570 }