92ef7e19d824f4be22b1e7049b6eb2f27753ae57
[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|ip|tcp|udp|sctp|ether|port|vxlan|"
825                         "geneve|nvgre|none|<flowtype_id>)\n"
826                         "    Set the RSS mode.\n\n"
827
828                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
829                         "    Set the RSS redirection table.\n\n"
830
831                         "port config (port_id) dcb vt (on|off) (traffic_class)"
832                         " pfc (on|off)\n"
833                         "    Set the DCB mode.\n\n"
834
835                         "port config all burst (value)\n"
836                         "    Set the number of packets per burst.\n\n"
837
838                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
839                         " (value)\n"
840                         "    Set the ring prefetch/host/writeback threshold"
841                         " for tx/rx queue.\n\n"
842
843                         "port config all (txfreet|txrst|rxfreet) (value)\n"
844                         "    Set free threshold for rx/tx, or set"
845                         " tx rs bit threshold.\n\n"
846                         "port config mtu X value\n"
847                         "    Set the MTU of port X to a given value\n\n"
848
849                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
850                         "    Start/stop a rx/tx queue of port X. Only take effect"
851                         " when port X is started\n\n"
852
853                         "port config (port_id|all) l2-tunnel E-tag ether-type"
854                         " (value)\n"
855                         "    Set the value of E-tag ether-type.\n\n"
856
857                         "port config (port_id|all) l2-tunnel E-tag"
858                         " (enable|disable)\n"
859                         "    Enable/disable the E-tag support.\n\n"
860
861                         "port config (port_id) pctype mapping reset\n"
862                         "    Reset flow type to pctype mapping on a port\n\n"
863
864                         "port config (port_id) pctype mapping update"
865                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
866                         "    Update a flow type to pctype mapping item on a port\n\n"
867
868                         "port config (port_id) pctype (pctype_id) hash_inset|"
869                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
870                         " (field_idx)\n"
871                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
872
873                         "port config (port_id) pctype (pctype_id) hash_inset|"
874                         "fdir_inset|fdir_flx_inset clear all"
875                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
876                 );
877         }
878
879         if (show_all || !strcmp(res->section, "registers")) {
880
881                 cmdline_printf(
882                         cl,
883                         "\n"
884                         "Registers:\n"
885                         "----------\n\n"
886
887                         "read reg (port_id) (address)\n"
888                         "    Display value of a port register.\n\n"
889
890                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
891                         "    Display a port register bit field.\n\n"
892
893                         "read regbit (port_id) (address) (bit_x)\n"
894                         "    Display a single port register bit.\n\n"
895
896                         "write reg (port_id) (address) (value)\n"
897                         "    Set value of a port register.\n\n"
898
899                         "write regfield (port_id) (address) (bit_x) (bit_y)"
900                         " (value)\n"
901                         "    Set bit field of a port register.\n\n"
902
903                         "write regbit (port_id) (address) (bit_x) (value)\n"
904                         "    Set single bit value of a port register.\n\n"
905                 );
906         }
907         if (show_all || !strcmp(res->section, "filters")) {
908
909                 cmdline_printf(
910                         cl,
911                         "\n"
912                         "filters:\n"
913                         "--------\n\n"
914
915                         "ethertype_filter (port_id) (add|del)"
916                         " (mac_addr|mac_ignr) (mac_address) ethertype"
917                         " (ether_type) (drop|fwd) queue (queue_id)\n"
918                         "    Add/Del an ethertype filter.\n\n"
919
920                         "2tuple_filter (port_id) (add|del)"
921                         " dst_port (dst_port_value) protocol (protocol_value)"
922                         " mask (mask_value) tcp_flags (tcp_flags_value)"
923                         " priority (prio_value) queue (queue_id)\n"
924                         "    Add/Del a 2tuple filter.\n\n"
925
926                         "5tuple_filter (port_id) (add|del)"
927                         " dst_ip (dst_address) src_ip (src_address)"
928                         " dst_port (dst_port_value) src_port (src_port_value)"
929                         " protocol (protocol_value)"
930                         " mask (mask_value) tcp_flags (tcp_flags_value)"
931                         " priority (prio_value) queue (queue_id)\n"
932                         "    Add/Del a 5tuple filter.\n\n"
933
934                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
935                         "    Add/Del syn filter.\n\n"
936
937                         "flex_filter (port_id) (add|del) len (len_value)"
938                         " bytes (bytes_value) mask (mask_value)"
939                         " priority (prio_value) queue (queue_id)\n"
940                         "    Add/Del a flex filter.\n\n"
941
942                         "flow_director_filter (port_id) mode IP (add|del|update)"
943                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
944                         " src (src_ip_address) dst (dst_ip_address)"
945                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
946                         " vlan (vlan_value) flexbytes (flexbytes_value)"
947                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
948                         " fd_id (fd_id_value)\n"
949                         "    Add/Del an IP type flow director filter.\n\n"
950
951                         "flow_director_filter (port_id) mode IP (add|del|update)"
952                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
953                         " src (src_ip_address) (src_port)"
954                         " dst (dst_ip_address) (dst_port)"
955                         " tos (tos_value) ttl (ttl_value)"
956                         " vlan (vlan_value) flexbytes (flexbytes_value)"
957                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
958                         " fd_id (fd_id_value)\n"
959                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
960
961                         "flow_director_filter (port_id) mode IP (add|del|update)"
962                         " flow (ipv4-sctp|ipv6-sctp)"
963                         " src (src_ip_address) (src_port)"
964                         " dst (dst_ip_address) (dst_port)"
965                         " tag (verification_tag) "
966                         " tos (tos_value) ttl (ttl_value)"
967                         " vlan (vlan_value)"
968                         " flexbytes (flexbytes_value) (drop|fwd)"
969                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
970                         "    Add/Del a SCTP type flow director filter.\n\n"
971
972                         "flow_director_filter (port_id) mode IP (add|del|update)"
973                         " flow l2_payload ether (ethertype)"
974                         " flexbytes (flexbytes_value) (drop|fwd)"
975                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
976                         "    Add/Del a l2 payload type flow director filter.\n\n"
977
978                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
979                         " mac (mac_address) vlan (vlan_value)"
980                         " flexbytes (flexbytes_value) (drop|fwd)"
981                         " queue (queue_id) fd_id (fd_id_value)\n"
982                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
983
984                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
985                         " mac (mac_address) vlan (vlan_value)"
986                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
987                         " flexbytes (flexbytes_value) (drop|fwd)"
988                         " queue (queue_id) fd_id (fd_id_value)\n"
989                         "    Add/Del a Tunnel flow director filter.\n\n"
990
991                         "flow_director_filter (port_id) mode raw (add|del|update)"
992                         " flow (flow_id) (drop|fwd) queue (queue_id)"
993                         " fd_id (fd_id_value) packet (packet file name)\n"
994                         "    Add/Del a raw type flow director filter.\n\n"
995
996                         "flush_flow_director (port_id)\n"
997                         "    Flush all flow director entries of a device.\n\n"
998
999                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1000                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1001                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1002                         "    Set flow director IP mask.\n\n"
1003
1004                         "flow_director_mask (port_id) mode MAC-VLAN"
1005                         " vlan (vlan_value)\n"
1006                         "    Set flow director MAC-VLAN mask.\n\n"
1007
1008                         "flow_director_mask (port_id) mode Tunnel"
1009                         " vlan (vlan_value) mac (mac_value)"
1010                         " tunnel-type (tunnel_type_value)"
1011                         " tunnel-id (tunnel_id_value)\n"
1012                         "    Set flow director Tunnel mask.\n\n"
1013
1014                         "flow_director_flex_mask (port_id)"
1015                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1016                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1017                         " (mask)\n"
1018                         "    Configure mask of flex payload.\n\n"
1019
1020                         "flow_director_flex_payload (port_id)"
1021                         " (raw|l2|l3|l4) (config)\n"
1022                         "    Configure flex payload selection.\n\n"
1023
1024                         "get_sym_hash_ena_per_port (port_id)\n"
1025                         "    get symmetric hash enable configuration per port.\n\n"
1026
1027                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1028                         "    set symmetric hash enable configuration per port"
1029                         " to enable or disable.\n\n"
1030
1031                         "get_hash_global_config (port_id)\n"
1032                         "    Get the global configurations of hash filters.\n\n"
1033
1034                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1035                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1036                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1037                         " (enable|disable)\n"
1038                         "    Set the global configurations of hash filters.\n\n"
1039
1040                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1041                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1042                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1043                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1044                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1045                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1046                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1047                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1048                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1049                         "fld-8th|none) (select|add)\n"
1050                         "    Set the input set for hash.\n\n"
1051
1052                         "set_fdir_input_set (port_id) "
1053                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1054                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1055                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1056                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1057                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1058                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1059                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1060                         " (select|add)\n"
1061                         "    Set the input set for FDir.\n\n"
1062
1063                         "flow validate {port_id}"
1064                         " [group {group_id}] [priority {level}]"
1065                         " [ingress] [egress]"
1066                         " pattern {item} [/ {item} [...]] / end"
1067                         " actions {action} [/ {action} [...]] / end\n"
1068                         "    Check whether a flow rule can be created.\n\n"
1069
1070                         "flow create {port_id}"
1071                         " [group {group_id}] [priority {level}]"
1072                         " [ingress] [egress]"
1073                         " pattern {item} [/ {item} [...]] / end"
1074                         " actions {action} [/ {action} [...]] / end\n"
1075                         "    Create a flow rule.\n\n"
1076
1077                         "flow destroy {port_id} rule {rule_id} [...]\n"
1078                         "    Destroy specific flow rules.\n\n"
1079
1080                         "flow flush {port_id}\n"
1081                         "    Destroy all flow rules.\n\n"
1082
1083                         "flow query {port_id} {rule_id} {action}\n"
1084                         "    Query an existing flow rule.\n\n"
1085
1086                         "flow list {port_id} [group {group_id}] [...]\n"
1087                         "    List existing flow rules sorted by priority,"
1088                         " filtered by group identifiers.\n\n"
1089
1090                         "flow isolate {port_id} {boolean}\n"
1091                         "    Restrict ingress traffic to the defined"
1092                         " flow rules\n\n"
1093                 );
1094         }
1095 }
1096
1097 cmdline_parse_token_string_t cmd_help_long_help =
1098         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1099
1100 cmdline_parse_token_string_t cmd_help_long_section =
1101         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1102                         "all#control#display#config#"
1103                         "ports#registers#filters");
1104
1105 cmdline_parse_inst_t cmd_help_long = {
1106         .f = cmd_help_long_parsed,
1107         .data = NULL,
1108         .help_str = "help all|control|display|config|ports|register|filters: "
1109                 "Show help",
1110         .tokens = {
1111                 (void *)&cmd_help_long_help,
1112                 (void *)&cmd_help_long_section,
1113                 NULL,
1114         },
1115 };
1116
1117
1118 /* *** start/stop/close all ports *** */
1119 struct cmd_operate_port_result {
1120         cmdline_fixed_string_t keyword;
1121         cmdline_fixed_string_t name;
1122         cmdline_fixed_string_t value;
1123 };
1124
1125 static void cmd_operate_port_parsed(void *parsed_result,
1126                                 __attribute__((unused)) struct cmdline *cl,
1127                                 __attribute__((unused)) void *data)
1128 {
1129         struct cmd_operate_port_result *res = parsed_result;
1130
1131         if (!strcmp(res->name, "start"))
1132                 start_port(RTE_PORT_ALL);
1133         else if (!strcmp(res->name, "stop"))
1134                 stop_port(RTE_PORT_ALL);
1135         else if (!strcmp(res->name, "close"))
1136                 close_port(RTE_PORT_ALL);
1137         else if (!strcmp(res->name, "reset"))
1138                 reset_port(RTE_PORT_ALL);
1139         else
1140                 printf("Unknown parameter\n");
1141 }
1142
1143 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1144         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1145                                                                 "port");
1146 cmdline_parse_token_string_t cmd_operate_port_all_port =
1147         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1148                                                 "start#stop#close#reset");
1149 cmdline_parse_token_string_t cmd_operate_port_all_all =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1151
1152 cmdline_parse_inst_t cmd_operate_port = {
1153         .f = cmd_operate_port_parsed,
1154         .data = NULL,
1155         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1156         .tokens = {
1157                 (void *)&cmd_operate_port_all_cmd,
1158                 (void *)&cmd_operate_port_all_port,
1159                 (void *)&cmd_operate_port_all_all,
1160                 NULL,
1161         },
1162 };
1163
1164 /* *** start/stop/close specific port *** */
1165 struct cmd_operate_specific_port_result {
1166         cmdline_fixed_string_t keyword;
1167         cmdline_fixed_string_t name;
1168         uint8_t value;
1169 };
1170
1171 static void cmd_operate_specific_port_parsed(void *parsed_result,
1172                         __attribute__((unused)) struct cmdline *cl,
1173                                 __attribute__((unused)) void *data)
1174 {
1175         struct cmd_operate_specific_port_result *res = parsed_result;
1176
1177         if (!strcmp(res->name, "start"))
1178                 start_port(res->value);
1179         else if (!strcmp(res->name, "stop"))
1180                 stop_port(res->value);
1181         else if (!strcmp(res->name, "close"))
1182                 close_port(res->value);
1183         else if (!strcmp(res->name, "reset"))
1184                 reset_port(res->value);
1185         else
1186                 printf("Unknown parameter\n");
1187 }
1188
1189 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1190         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1191                                                         keyword, "port");
1192 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1193         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1194                                                 name, "start#stop#close#reset");
1195 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1196         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1197                                                         value, UINT8);
1198
1199 cmdline_parse_inst_t cmd_operate_specific_port = {
1200         .f = cmd_operate_specific_port_parsed,
1201         .data = NULL,
1202         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1203         .tokens = {
1204                 (void *)&cmd_operate_specific_port_cmd,
1205                 (void *)&cmd_operate_specific_port_port,
1206                 (void *)&cmd_operate_specific_port_id,
1207                 NULL,
1208         },
1209 };
1210
1211 /* *** attach a specified port *** */
1212 struct cmd_operate_attach_port_result {
1213         cmdline_fixed_string_t port;
1214         cmdline_fixed_string_t keyword;
1215         cmdline_fixed_string_t identifier;
1216 };
1217
1218 static void cmd_operate_attach_port_parsed(void *parsed_result,
1219                                 __attribute__((unused)) struct cmdline *cl,
1220                                 __attribute__((unused)) void *data)
1221 {
1222         struct cmd_operate_attach_port_result *res = parsed_result;
1223
1224         if (!strcmp(res->keyword, "attach"))
1225                 attach_port(res->identifier);
1226         else
1227                 printf("Unknown parameter\n");
1228 }
1229
1230 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1231         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1232                         port, "port");
1233 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1235                         keyword, "attach");
1236 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1238                         identifier, NULL);
1239
1240 cmdline_parse_inst_t cmd_operate_attach_port = {
1241         .f = cmd_operate_attach_port_parsed,
1242         .data = NULL,
1243         .help_str = "port attach <identifier>: "
1244                 "(identifier: pci address or virtual dev name)",
1245         .tokens = {
1246                 (void *)&cmd_operate_attach_port_port,
1247                 (void *)&cmd_operate_attach_port_keyword,
1248                 (void *)&cmd_operate_attach_port_identifier,
1249                 NULL,
1250         },
1251 };
1252
1253 /* *** detach a specified port *** */
1254 struct cmd_operate_detach_port_result {
1255         cmdline_fixed_string_t port;
1256         cmdline_fixed_string_t keyword;
1257         portid_t port_id;
1258 };
1259
1260 static void cmd_operate_detach_port_parsed(void *parsed_result,
1261                                 __attribute__((unused)) struct cmdline *cl,
1262                                 __attribute__((unused)) void *data)
1263 {
1264         struct cmd_operate_detach_port_result *res = parsed_result;
1265
1266         if (!strcmp(res->keyword, "detach"))
1267                 detach_port(res->port_id);
1268         else
1269                 printf("Unknown parameter\n");
1270 }
1271
1272 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1273         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1274                         port, "port");
1275 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1277                         keyword, "detach");
1278 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1279         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1280                         port_id, UINT16);
1281
1282 cmdline_parse_inst_t cmd_operate_detach_port = {
1283         .f = cmd_operate_detach_port_parsed,
1284         .data = NULL,
1285         .help_str = "port detach <port_id>",
1286         .tokens = {
1287                 (void *)&cmd_operate_detach_port_port,
1288                 (void *)&cmd_operate_detach_port_keyword,
1289                 (void *)&cmd_operate_detach_port_port_id,
1290                 NULL,
1291         },
1292 };
1293
1294 /* *** configure speed for all ports *** */
1295 struct cmd_config_speed_all {
1296         cmdline_fixed_string_t port;
1297         cmdline_fixed_string_t keyword;
1298         cmdline_fixed_string_t all;
1299         cmdline_fixed_string_t item1;
1300         cmdline_fixed_string_t item2;
1301         cmdline_fixed_string_t value1;
1302         cmdline_fixed_string_t value2;
1303 };
1304
1305 static int
1306 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1307 {
1308
1309         int duplex;
1310
1311         if (!strcmp(duplexstr, "half")) {
1312                 duplex = ETH_LINK_HALF_DUPLEX;
1313         } else if (!strcmp(duplexstr, "full")) {
1314                 duplex = ETH_LINK_FULL_DUPLEX;
1315         } else if (!strcmp(duplexstr, "auto")) {
1316                 duplex = ETH_LINK_FULL_DUPLEX;
1317         } else {
1318                 printf("Unknown duplex parameter\n");
1319                 return -1;
1320         }
1321
1322         if (!strcmp(speedstr, "10")) {
1323                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1324                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1325         } else if (!strcmp(speedstr, "100")) {
1326                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1327                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1328         } else {
1329                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1330                         printf("Invalid speed/duplex parameters\n");
1331                         return -1;
1332                 }
1333                 if (!strcmp(speedstr, "1000")) {
1334                         *speed = ETH_LINK_SPEED_1G;
1335                 } else if (!strcmp(speedstr, "10000")) {
1336                         *speed = ETH_LINK_SPEED_10G;
1337                 } else if (!strcmp(speedstr, "25000")) {
1338                         *speed = ETH_LINK_SPEED_25G;
1339                 } else if (!strcmp(speedstr, "40000")) {
1340                         *speed = ETH_LINK_SPEED_40G;
1341                 } else if (!strcmp(speedstr, "50000")) {
1342                         *speed = ETH_LINK_SPEED_50G;
1343                 } else if (!strcmp(speedstr, "100000")) {
1344                         *speed = ETH_LINK_SPEED_100G;
1345                 } else if (!strcmp(speedstr, "auto")) {
1346                         *speed = ETH_LINK_SPEED_AUTONEG;
1347                 } else {
1348                         printf("Unknown speed parameter\n");
1349                         return -1;
1350                 }
1351         }
1352
1353         return 0;
1354 }
1355
1356 static void
1357 cmd_config_speed_all_parsed(void *parsed_result,
1358                         __attribute__((unused)) struct cmdline *cl,
1359                         __attribute__((unused)) void *data)
1360 {
1361         struct cmd_config_speed_all *res = parsed_result;
1362         uint32_t link_speed;
1363         portid_t pid;
1364
1365         if (!all_ports_stopped()) {
1366                 printf("Please stop all ports first\n");
1367                 return;
1368         }
1369
1370         if (parse_and_check_speed_duplex(res->value1, res->value2,
1371                         &link_speed) < 0)
1372                 return;
1373
1374         RTE_ETH_FOREACH_DEV(pid) {
1375                 ports[pid].dev_conf.link_speeds = link_speed;
1376         }
1377
1378         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1379 }
1380
1381 cmdline_parse_token_string_t cmd_config_speed_all_port =
1382         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1383 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1384         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1385                                                         "config");
1386 cmdline_parse_token_string_t cmd_config_speed_all_all =
1387         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1388 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1389         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1390 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1391         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1392                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1393 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1395 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1396         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1397                                                 "half#full#auto");
1398
1399 cmdline_parse_inst_t cmd_config_speed_all = {
1400         .f = cmd_config_speed_all_parsed,
1401         .data = NULL,
1402         .help_str = "port config all speed "
1403                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1404                                                         "half|full|auto",
1405         .tokens = {
1406                 (void *)&cmd_config_speed_all_port,
1407                 (void *)&cmd_config_speed_all_keyword,
1408                 (void *)&cmd_config_speed_all_all,
1409                 (void *)&cmd_config_speed_all_item1,
1410                 (void *)&cmd_config_speed_all_value1,
1411                 (void *)&cmd_config_speed_all_item2,
1412                 (void *)&cmd_config_speed_all_value2,
1413                 NULL,
1414         },
1415 };
1416
1417 /* *** configure speed for specific port *** */
1418 struct cmd_config_speed_specific {
1419         cmdline_fixed_string_t port;
1420         cmdline_fixed_string_t keyword;
1421         uint8_t id;
1422         cmdline_fixed_string_t item1;
1423         cmdline_fixed_string_t item2;
1424         cmdline_fixed_string_t value1;
1425         cmdline_fixed_string_t value2;
1426 };
1427
1428 static void
1429 cmd_config_speed_specific_parsed(void *parsed_result,
1430                                 __attribute__((unused)) struct cmdline *cl,
1431                                 __attribute__((unused)) void *data)
1432 {
1433         struct cmd_config_speed_specific *res = parsed_result;
1434         uint32_t link_speed;
1435
1436         if (!all_ports_stopped()) {
1437                 printf("Please stop all ports first\n");
1438                 return;
1439         }
1440
1441         if (port_id_is_invalid(res->id, ENABLED_WARN))
1442                 return;
1443
1444         if (parse_and_check_speed_duplex(res->value1, res->value2,
1445                         &link_speed) < 0)
1446                 return;
1447
1448         ports[res->id].dev_conf.link_speeds = link_speed;
1449
1450         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1451 }
1452
1453
1454 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1455         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1456                                                                 "port");
1457 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1459                                                                 "config");
1460 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1461         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1462 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1463         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1464                                                                 "speed");
1465 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1467                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1468 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1470                                                                 "duplex");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1473                                                         "half#full#auto");
1474
1475 cmdline_parse_inst_t cmd_config_speed_specific = {
1476         .f = cmd_config_speed_specific_parsed,
1477         .data = NULL,
1478         .help_str = "port config <port_id> speed "
1479                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1480                                                         "half|full|auto",
1481         .tokens = {
1482                 (void *)&cmd_config_speed_specific_port,
1483                 (void *)&cmd_config_speed_specific_keyword,
1484                 (void *)&cmd_config_speed_specific_id,
1485                 (void *)&cmd_config_speed_specific_item1,
1486                 (void *)&cmd_config_speed_specific_value1,
1487                 (void *)&cmd_config_speed_specific_item2,
1488                 (void *)&cmd_config_speed_specific_value2,
1489                 NULL,
1490         },
1491 };
1492
1493 /* *** configure loopback for all ports *** */
1494 struct cmd_config_loopback_all {
1495         cmdline_fixed_string_t port;
1496         cmdline_fixed_string_t keyword;
1497         cmdline_fixed_string_t all;
1498         cmdline_fixed_string_t item;
1499         uint32_t mode;
1500 };
1501
1502 static void
1503 cmd_config_loopback_all_parsed(void *parsed_result,
1504                         __attribute__((unused)) struct cmdline *cl,
1505                         __attribute__((unused)) void *data)
1506 {
1507         struct cmd_config_loopback_all *res = parsed_result;
1508         portid_t pid;
1509
1510         if (!all_ports_stopped()) {
1511                 printf("Please stop all ports first\n");
1512                 return;
1513         }
1514
1515         RTE_ETH_FOREACH_DEV(pid) {
1516                 ports[pid].dev_conf.lpbk_mode = res->mode;
1517         }
1518
1519         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1520 }
1521
1522 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1523         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1524 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1525         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1526                                                         "config");
1527 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1528         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1529 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1530         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1531                                                         "loopback");
1532 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1533         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1534
1535 cmdline_parse_inst_t cmd_config_loopback_all = {
1536         .f = cmd_config_loopback_all_parsed,
1537         .data = NULL,
1538         .help_str = "port config all loopback <mode>",
1539         .tokens = {
1540                 (void *)&cmd_config_loopback_all_port,
1541                 (void *)&cmd_config_loopback_all_keyword,
1542                 (void *)&cmd_config_loopback_all_all,
1543                 (void *)&cmd_config_loopback_all_item,
1544                 (void *)&cmd_config_loopback_all_mode,
1545                 NULL,
1546         },
1547 };
1548
1549 /* *** configure loopback for specific port *** */
1550 struct cmd_config_loopback_specific {
1551         cmdline_fixed_string_t port;
1552         cmdline_fixed_string_t keyword;
1553         uint16_t port_id;
1554         cmdline_fixed_string_t item;
1555         uint32_t mode;
1556 };
1557
1558 static void
1559 cmd_config_loopback_specific_parsed(void *parsed_result,
1560                                 __attribute__((unused)) struct cmdline *cl,
1561                                 __attribute__((unused)) void *data)
1562 {
1563         struct cmd_config_loopback_specific *res = parsed_result;
1564
1565         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1566                 return;
1567
1568         if (!port_is_stopped(res->port_id)) {
1569                 printf("Please stop port %u first\n", res->port_id);
1570                 return;
1571         }
1572
1573         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1574
1575         cmd_reconfig_device_queue(res->port_id, 1, 1);
1576 }
1577
1578
1579 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1580         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1581                                                                 "port");
1582 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1583         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1584                                                                 "config");
1585 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1586         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1587                                                                 UINT16);
1588 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1589         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1590                                                                 "loopback");
1591 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1592         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1593                               UINT32);
1594
1595 cmdline_parse_inst_t cmd_config_loopback_specific = {
1596         .f = cmd_config_loopback_specific_parsed,
1597         .data = NULL,
1598         .help_str = "port config <port_id> loopback <mode>",
1599         .tokens = {
1600                 (void *)&cmd_config_loopback_specific_port,
1601                 (void *)&cmd_config_loopback_specific_keyword,
1602                 (void *)&cmd_config_loopback_specific_id,
1603                 (void *)&cmd_config_loopback_specific_item,
1604                 (void *)&cmd_config_loopback_specific_mode,
1605                 NULL,
1606         },
1607 };
1608
1609 /* *** configure txq/rxq, txd/rxd *** */
1610 struct cmd_config_rx_tx {
1611         cmdline_fixed_string_t port;
1612         cmdline_fixed_string_t keyword;
1613         cmdline_fixed_string_t all;
1614         cmdline_fixed_string_t name;
1615         uint16_t value;
1616 };
1617
1618 static void
1619 cmd_config_rx_tx_parsed(void *parsed_result,
1620                         __attribute__((unused)) struct cmdline *cl,
1621                         __attribute__((unused)) void *data)
1622 {
1623         struct cmd_config_rx_tx *res = parsed_result;
1624
1625         if (!all_ports_stopped()) {
1626                 printf("Please stop all ports first\n");
1627                 return;
1628         }
1629         if (!strcmp(res->name, "rxq")) {
1630                 if (!res->value && !nb_txq) {
1631                         printf("Warning: Either rx or tx queues should be non zero\n");
1632                         return;
1633                 }
1634                 if (check_nb_rxq(res->value) != 0)
1635                         return;
1636                 nb_rxq = res->value;
1637         }
1638         else if (!strcmp(res->name, "txq")) {
1639                 if (!res->value && !nb_rxq) {
1640                         printf("Warning: Either rx or tx queues should be non zero\n");
1641                         return;
1642                 }
1643                 if (check_nb_txq(res->value) != 0)
1644                         return;
1645                 nb_txq = res->value;
1646         }
1647         else if (!strcmp(res->name, "rxd")) {
1648                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1649                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1650                                         res->value, RTE_TEST_RX_DESC_MAX);
1651                         return;
1652                 }
1653                 nb_rxd = res->value;
1654         } else if (!strcmp(res->name, "txd")) {
1655                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1656                         printf("txd %d invalid - must be > 0 && <= %d\n",
1657                                         res->value, RTE_TEST_TX_DESC_MAX);
1658                         return;
1659                 }
1660                 nb_txd = res->value;
1661         } else {
1662                 printf("Unknown parameter\n");
1663                 return;
1664         }
1665
1666         fwd_config_setup();
1667
1668         init_port_config();
1669
1670         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1671 }
1672
1673 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1675 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1676         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1677 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1679 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1680         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1681                                                 "rxq#txq#rxd#txd");
1682 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1683         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1684
1685 cmdline_parse_inst_t cmd_config_rx_tx = {
1686         .f = cmd_config_rx_tx_parsed,
1687         .data = NULL,
1688         .help_str = "port config all rxq|txq|rxd|txd <value>",
1689         .tokens = {
1690                 (void *)&cmd_config_rx_tx_port,
1691                 (void *)&cmd_config_rx_tx_keyword,
1692                 (void *)&cmd_config_rx_tx_all,
1693                 (void *)&cmd_config_rx_tx_name,
1694                 (void *)&cmd_config_rx_tx_value,
1695                 NULL,
1696         },
1697 };
1698
1699 /* *** config max packet length *** */
1700 struct cmd_config_max_pkt_len_result {
1701         cmdline_fixed_string_t port;
1702         cmdline_fixed_string_t keyword;
1703         cmdline_fixed_string_t all;
1704         cmdline_fixed_string_t name;
1705         uint32_t value;
1706 };
1707
1708 static void
1709 cmd_config_max_pkt_len_parsed(void *parsed_result,
1710                                 __attribute__((unused)) struct cmdline *cl,
1711                                 __attribute__((unused)) void *data)
1712 {
1713         struct cmd_config_max_pkt_len_result *res = parsed_result;
1714         portid_t pid;
1715
1716         if (!all_ports_stopped()) {
1717                 printf("Please stop all ports first\n");
1718                 return;
1719         }
1720
1721         RTE_ETH_FOREACH_DEV(pid) {
1722                 struct rte_port *port = &ports[pid];
1723                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1724
1725                 if (!strcmp(res->name, "max-pkt-len")) {
1726                         if (res->value < ETHER_MIN_LEN) {
1727                                 printf("max-pkt-len can not be less than %d\n",
1728                                                 ETHER_MIN_LEN);
1729                                 return;
1730                         }
1731                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1732                                 return;
1733
1734                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1735                         if (res->value > ETHER_MAX_LEN)
1736                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1737                         else
1738                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1739                         port->dev_conf.rxmode.offloads = rx_offloads;
1740                 } else {
1741                         printf("Unknown parameter\n");
1742                         return;
1743                 }
1744         }
1745
1746         init_port_config();
1747
1748         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1749 }
1750
1751 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1752         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1753                                                                 "port");
1754 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1755         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1756                                                                 "config");
1757 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1758         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1759                                                                 "all");
1760 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1761         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1762                                                                 "max-pkt-len");
1763 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1764         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1765                                                                 UINT32);
1766
1767 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1768         .f = cmd_config_max_pkt_len_parsed,
1769         .data = NULL,
1770         .help_str = "port config all max-pkt-len <value>",
1771         .tokens = {
1772                 (void *)&cmd_config_max_pkt_len_port,
1773                 (void *)&cmd_config_max_pkt_len_keyword,
1774                 (void *)&cmd_config_max_pkt_len_all,
1775                 (void *)&cmd_config_max_pkt_len_name,
1776                 (void *)&cmd_config_max_pkt_len_value,
1777                 NULL,
1778         },
1779 };
1780
1781 /* *** configure port MTU *** */
1782 struct cmd_config_mtu_result {
1783         cmdline_fixed_string_t port;
1784         cmdline_fixed_string_t keyword;
1785         cmdline_fixed_string_t mtu;
1786         portid_t port_id;
1787         uint16_t value;
1788 };
1789
1790 static void
1791 cmd_config_mtu_parsed(void *parsed_result,
1792                       __attribute__((unused)) struct cmdline *cl,
1793                       __attribute__((unused)) void *data)
1794 {
1795         struct cmd_config_mtu_result *res = parsed_result;
1796
1797         if (res->value < ETHER_MIN_LEN) {
1798                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1799                 return;
1800         }
1801         port_mtu_set(res->port_id, res->value);
1802 }
1803
1804 cmdline_parse_token_string_t cmd_config_mtu_port =
1805         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1806                                  "port");
1807 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1808         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1809                                  "config");
1810 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1811         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1812                                  "mtu");
1813 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1814         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1815 cmdline_parse_token_num_t cmd_config_mtu_value =
1816         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1817
1818 cmdline_parse_inst_t cmd_config_mtu = {
1819         .f = cmd_config_mtu_parsed,
1820         .data = NULL,
1821         .help_str = "port config mtu <port_id> <value>",
1822         .tokens = {
1823                 (void *)&cmd_config_mtu_port,
1824                 (void *)&cmd_config_mtu_keyword,
1825                 (void *)&cmd_config_mtu_mtu,
1826                 (void *)&cmd_config_mtu_port_id,
1827                 (void *)&cmd_config_mtu_value,
1828                 NULL,
1829         },
1830 };
1831
1832 /* *** configure rx mode *** */
1833 struct cmd_config_rx_mode_flag {
1834         cmdline_fixed_string_t port;
1835         cmdline_fixed_string_t keyword;
1836         cmdline_fixed_string_t all;
1837         cmdline_fixed_string_t name;
1838         cmdline_fixed_string_t value;
1839 };
1840
1841 static void
1842 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1843                                 __attribute__((unused)) struct cmdline *cl,
1844                                 __attribute__((unused)) void *data)
1845 {
1846         struct cmd_config_rx_mode_flag *res = parsed_result;
1847         portid_t pid;
1848
1849         if (!all_ports_stopped()) {
1850                 printf("Please stop all ports first\n");
1851                 return;
1852         }
1853
1854         RTE_ETH_FOREACH_DEV(pid) {
1855                 struct rte_port *port;
1856                 uint64_t rx_offloads;
1857
1858                 port = &ports[pid];
1859                 rx_offloads = port->dev_conf.rxmode.offloads;
1860                 if (!strcmp(res->name, "crc-strip")) {
1861                         if (!strcmp(res->value, "on"))
1862                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1863                         else if (!strcmp(res->value, "off"))
1864                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1865                         else {
1866                                 printf("Unknown parameter\n");
1867                                 return;
1868                         }
1869                 } else if (!strcmp(res->name, "scatter")) {
1870                         if (!strcmp(res->value, "on")) {
1871                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1872                         } else if (!strcmp(res->value, "off")) {
1873                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1874                         } else {
1875                                 printf("Unknown parameter\n");
1876                                 return;
1877                         }
1878                 } else if (!strcmp(res->name, "rx-cksum")) {
1879                         if (!strcmp(res->value, "on"))
1880                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1881                         else if (!strcmp(res->value, "off"))
1882                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1883                         else {
1884                                 printf("Unknown parameter\n");
1885                                 return;
1886                         }
1887                 } else if (!strcmp(res->name, "rx-timestamp")) {
1888                         if (!strcmp(res->value, "on"))
1889                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1890                         else if (!strcmp(res->value, "off"))
1891                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1892                         else {
1893                                 printf("Unknown parameter\n");
1894                                 return;
1895                         }
1896                 } else if (!strcmp(res->name, "hw-vlan")) {
1897                         if (!strcmp(res->value, "on")) {
1898                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1899                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1900                         } else if (!strcmp(res->value, "off")) {
1901                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1902                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1903                         } else {
1904                                 printf("Unknown parameter\n");
1905                                 return;
1906                         }
1907                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1908                         if (!strcmp(res->value, "on"))
1909                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1910                         else if (!strcmp(res->value, "off"))
1911                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1912                         else {
1913                                 printf("Unknown parameter\n");
1914                                 return;
1915                         }
1916                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1917                         if (!strcmp(res->value, "on"))
1918                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1919                         else if (!strcmp(res->value, "off"))
1920                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1921                         else {
1922                                 printf("Unknown parameter\n");
1923                                 return;
1924                         }
1925                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1926                         if (!strcmp(res->value, "on"))
1927                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1928                         else if (!strcmp(res->value, "off"))
1929                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1930                         else {
1931                                 printf("Unknown parameter\n");
1932                                 return;
1933                         }
1934                 } else if (!strcmp(res->name, "drop-en")) {
1935                         if (!strcmp(res->value, "on"))
1936                                 rx_drop_en = 1;
1937                         else if (!strcmp(res->value, "off"))
1938                                 rx_drop_en = 0;
1939                         else {
1940                                 printf("Unknown parameter\n");
1941                                 return;
1942                         }
1943                 } else {
1944                         printf("Unknown parameter\n");
1945                         return;
1946                 }
1947                 port->dev_conf.rxmode.offloads = rx_offloads;
1948         }
1949
1950         init_port_config();
1951
1952         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1953 }
1954
1955 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1956         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1957 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1959                                                                 "config");
1960 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1962 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1963         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1964                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1965                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1966 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1967         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1968                                                         "on#off");
1969
1970 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1971         .f = cmd_config_rx_mode_flag_parsed,
1972         .data = NULL,
1973         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1974                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1975         .tokens = {
1976                 (void *)&cmd_config_rx_mode_flag_port,
1977                 (void *)&cmd_config_rx_mode_flag_keyword,
1978                 (void *)&cmd_config_rx_mode_flag_all,
1979                 (void *)&cmd_config_rx_mode_flag_name,
1980                 (void *)&cmd_config_rx_mode_flag_value,
1981                 NULL,
1982         },
1983 };
1984
1985 /* *** configure rss *** */
1986 struct cmd_config_rss {
1987         cmdline_fixed_string_t port;
1988         cmdline_fixed_string_t keyword;
1989         cmdline_fixed_string_t all;
1990         cmdline_fixed_string_t name;
1991         cmdline_fixed_string_t value;
1992 };
1993
1994 static void
1995 cmd_config_rss_parsed(void *parsed_result,
1996                         __attribute__((unused)) struct cmdline *cl,
1997                         __attribute__((unused)) void *data)
1998 {
1999         struct cmd_config_rss *res = parsed_result;
2000         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2001         int diag;
2002         uint8_t i;
2003
2004         if (!strcmp(res->value, "all"))
2005                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2006                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2007                                         ETH_RSS_L2_PAYLOAD;
2008         else if (!strcmp(res->value, "ip"))
2009                 rss_conf.rss_hf = ETH_RSS_IP;
2010         else if (!strcmp(res->value, "udp"))
2011                 rss_conf.rss_hf = ETH_RSS_UDP;
2012         else if (!strcmp(res->value, "tcp"))
2013                 rss_conf.rss_hf = ETH_RSS_TCP;
2014         else if (!strcmp(res->value, "sctp"))
2015                 rss_conf.rss_hf = ETH_RSS_SCTP;
2016         else if (!strcmp(res->value, "ether"))
2017                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2018         else if (!strcmp(res->value, "port"))
2019                 rss_conf.rss_hf = ETH_RSS_PORT;
2020         else if (!strcmp(res->value, "vxlan"))
2021                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2022         else if (!strcmp(res->value, "geneve"))
2023                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2024         else if (!strcmp(res->value, "nvgre"))
2025                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2026         else if (!strcmp(res->value, "none"))
2027                 rss_conf.rss_hf = 0;
2028         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2029                                                 atoi(res->value) < 64)
2030                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2031         else {
2032                 printf("Unknown parameter\n");
2033                 return;
2034         }
2035         rss_conf.rss_key = NULL;
2036         for (i = 0; i < rte_eth_dev_count(); i++) {
2037                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
2038                 if (diag < 0)
2039                         printf("Configuration of RSS hash at ethernet port %d "
2040                                 "failed with error (%d): %s.\n",
2041                                 i, -diag, strerror(-diag));
2042         }
2043 }
2044
2045 cmdline_parse_token_string_t cmd_config_rss_port =
2046         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2047 cmdline_parse_token_string_t cmd_config_rss_keyword =
2048         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2049 cmdline_parse_token_string_t cmd_config_rss_all =
2050         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2051 cmdline_parse_token_string_t cmd_config_rss_name =
2052         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2053 cmdline_parse_token_string_t cmd_config_rss_value =
2054         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2055
2056 cmdline_parse_inst_t cmd_config_rss = {
2057         .f = cmd_config_rss_parsed,
2058         .data = NULL,
2059         .help_str = "port config all rss "
2060                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2061         .tokens = {
2062                 (void *)&cmd_config_rss_port,
2063                 (void *)&cmd_config_rss_keyword,
2064                 (void *)&cmd_config_rss_all,
2065                 (void *)&cmd_config_rss_name,
2066                 (void *)&cmd_config_rss_value,
2067                 NULL,
2068         },
2069 };
2070
2071 /* *** configure rss hash key *** */
2072 struct cmd_config_rss_hash_key {
2073         cmdline_fixed_string_t port;
2074         cmdline_fixed_string_t config;
2075         portid_t port_id;
2076         cmdline_fixed_string_t rss_hash_key;
2077         cmdline_fixed_string_t rss_type;
2078         cmdline_fixed_string_t key;
2079 };
2080
2081 static uint8_t
2082 hexa_digit_to_value(char hexa_digit)
2083 {
2084         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2085                 return (uint8_t) (hexa_digit - '0');
2086         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2087                 return (uint8_t) ((hexa_digit - 'a') + 10);
2088         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2089                 return (uint8_t) ((hexa_digit - 'A') + 10);
2090         /* Invalid hexa digit */
2091         return 0xFF;
2092 }
2093
2094 static uint8_t
2095 parse_and_check_key_hexa_digit(char *key, int idx)
2096 {
2097         uint8_t hexa_v;
2098
2099         hexa_v = hexa_digit_to_value(key[idx]);
2100         if (hexa_v == 0xFF)
2101                 printf("invalid key: character %c at position %d is not a "
2102                        "valid hexa digit\n", key[idx], idx);
2103         return hexa_v;
2104 }
2105
2106 static void
2107 cmd_config_rss_hash_key_parsed(void *parsed_result,
2108                                __attribute__((unused)) struct cmdline *cl,
2109                                __attribute__((unused)) void *data)
2110 {
2111         struct cmd_config_rss_hash_key *res = parsed_result;
2112         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2113         uint8_t xdgt0;
2114         uint8_t xdgt1;
2115         int i;
2116         struct rte_eth_dev_info dev_info;
2117         uint8_t hash_key_size;
2118         uint32_t key_len;
2119
2120         memset(&dev_info, 0, sizeof(dev_info));
2121         rte_eth_dev_info_get(res->port_id, &dev_info);
2122         if (dev_info.hash_key_size > 0 &&
2123                         dev_info.hash_key_size <= sizeof(hash_key))
2124                 hash_key_size = dev_info.hash_key_size;
2125         else {
2126                 printf("dev_info did not provide a valid hash key size\n");
2127                 return;
2128         }
2129         /* Check the length of the RSS hash key */
2130         key_len = strlen(res->key);
2131         if (key_len != (hash_key_size * 2)) {
2132                 printf("key length: %d invalid - key must be a string of %d"
2133                            " hexa-decimal numbers\n",
2134                            (int) key_len, hash_key_size * 2);
2135                 return;
2136         }
2137         /* Translate RSS hash key into binary representation */
2138         for (i = 0; i < hash_key_size; i++) {
2139                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2140                 if (xdgt0 == 0xFF)
2141                         return;
2142                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2143                 if (xdgt1 == 0xFF)
2144                         return;
2145                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2146         }
2147         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2148                         hash_key_size);
2149 }
2150
2151 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2152         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2153 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2154         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2155                                  "config");
2156 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2157         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2158 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2159         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2160                                  rss_hash_key, "rss-hash-key");
2161 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2162         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2163                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2164                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2165                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2166                                  "ipv6-tcp-ex#ipv6-udp-ex");
2167 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2168         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2169
2170 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2171         .f = cmd_config_rss_hash_key_parsed,
2172         .data = NULL,
2173         .help_str = "port config <port_id> rss-hash-key "
2174                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2175                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2176                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2177                 "<string of hex digits (variable length, NIC dependent)>",
2178         .tokens = {
2179                 (void *)&cmd_config_rss_hash_key_port,
2180                 (void *)&cmd_config_rss_hash_key_config,
2181                 (void *)&cmd_config_rss_hash_key_port_id,
2182                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2183                 (void *)&cmd_config_rss_hash_key_rss_type,
2184                 (void *)&cmd_config_rss_hash_key_value,
2185                 NULL,
2186         },
2187 };
2188
2189 /* *** configure port rxq/txq start/stop *** */
2190 struct cmd_config_rxtx_queue {
2191         cmdline_fixed_string_t port;
2192         portid_t portid;
2193         cmdline_fixed_string_t rxtxq;
2194         uint16_t qid;
2195         cmdline_fixed_string_t opname;
2196 };
2197
2198 static void
2199 cmd_config_rxtx_queue_parsed(void *parsed_result,
2200                         __attribute__((unused)) struct cmdline *cl,
2201                         __attribute__((unused)) void *data)
2202 {
2203         struct cmd_config_rxtx_queue *res = parsed_result;
2204         uint8_t isrx;
2205         uint8_t isstart;
2206         int ret = 0;
2207
2208         if (test_done == 0) {
2209                 printf("Please stop forwarding first\n");
2210                 return;
2211         }
2212
2213         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2214                 return;
2215
2216         if (port_is_started(res->portid) != 1) {
2217                 printf("Please start port %u first\n", res->portid);
2218                 return;
2219         }
2220
2221         if (!strcmp(res->rxtxq, "rxq"))
2222                 isrx = 1;
2223         else if (!strcmp(res->rxtxq, "txq"))
2224                 isrx = 0;
2225         else {
2226                 printf("Unknown parameter\n");
2227                 return;
2228         }
2229
2230         if (isrx && rx_queue_id_is_invalid(res->qid))
2231                 return;
2232         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2233                 return;
2234
2235         if (!strcmp(res->opname, "start"))
2236                 isstart = 1;
2237         else if (!strcmp(res->opname, "stop"))
2238                 isstart = 0;
2239         else {
2240                 printf("Unknown parameter\n");
2241                 return;
2242         }
2243
2244         if (isstart && isrx)
2245                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2246         else if (!isstart && isrx)
2247                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2248         else if (isstart && !isrx)
2249                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2250         else
2251                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2252
2253         if (ret == -ENOTSUP)
2254                 printf("Function not supported in PMD driver\n");
2255 }
2256
2257 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2258         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2259 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2260         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2261 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2262         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2263 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2264         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2265 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2266         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2267                                                 "start#stop");
2268
2269 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2270         .f = cmd_config_rxtx_queue_parsed,
2271         .data = NULL,
2272         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2273         .tokens = {
2274                 (void *)&cmd_config_speed_all_port,
2275                 (void *)&cmd_config_rxtx_queue_portid,
2276                 (void *)&cmd_config_rxtx_queue_rxtxq,
2277                 (void *)&cmd_config_rxtx_queue_qid,
2278                 (void *)&cmd_config_rxtx_queue_opname,
2279                 NULL,
2280         },
2281 };
2282
2283 /* *** Configure RSS RETA *** */
2284 struct cmd_config_rss_reta {
2285         cmdline_fixed_string_t port;
2286         cmdline_fixed_string_t keyword;
2287         portid_t port_id;
2288         cmdline_fixed_string_t name;
2289         cmdline_fixed_string_t list_name;
2290         cmdline_fixed_string_t list_of_items;
2291 };
2292
2293 static int
2294 parse_reta_config(const char *str,
2295                   struct rte_eth_rss_reta_entry64 *reta_conf,
2296                   uint16_t nb_entries)
2297 {
2298         int i;
2299         unsigned size;
2300         uint16_t hash_index, idx, shift;
2301         uint16_t nb_queue;
2302         char s[256];
2303         const char *p, *p0 = str;
2304         char *end;
2305         enum fieldnames {
2306                 FLD_HASH_INDEX = 0,
2307                 FLD_QUEUE,
2308                 _NUM_FLD
2309         };
2310         unsigned long int_fld[_NUM_FLD];
2311         char *str_fld[_NUM_FLD];
2312
2313         while ((p = strchr(p0,'(')) != NULL) {
2314                 ++p;
2315                 if((p0 = strchr(p,')')) == NULL)
2316                         return -1;
2317
2318                 size = p0 - p;
2319                 if(size >= sizeof(s))
2320                         return -1;
2321
2322                 snprintf(s, sizeof(s), "%.*s", size, p);
2323                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2324                         return -1;
2325                 for (i = 0; i < _NUM_FLD; i++) {
2326                         errno = 0;
2327                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2328                         if (errno != 0 || end == str_fld[i] ||
2329                                         int_fld[i] > 65535)
2330                                 return -1;
2331                 }
2332
2333                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2334                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2335
2336                 if (hash_index >= nb_entries) {
2337                         printf("Invalid RETA hash index=%d\n", hash_index);
2338                         return -1;
2339                 }
2340
2341                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2342                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2343                 reta_conf[idx].mask |= (1ULL << shift);
2344                 reta_conf[idx].reta[shift] = nb_queue;
2345         }
2346
2347         return 0;
2348 }
2349
2350 static void
2351 cmd_set_rss_reta_parsed(void *parsed_result,
2352                         __attribute__((unused)) struct cmdline *cl,
2353                         __attribute__((unused)) void *data)
2354 {
2355         int ret;
2356         struct rte_eth_dev_info dev_info;
2357         struct rte_eth_rss_reta_entry64 reta_conf[8];
2358         struct cmd_config_rss_reta *res = parsed_result;
2359
2360         memset(&dev_info, 0, sizeof(dev_info));
2361         rte_eth_dev_info_get(res->port_id, &dev_info);
2362         if (dev_info.reta_size == 0) {
2363                 printf("Redirection table size is 0 which is "
2364                                         "invalid for RSS\n");
2365                 return;
2366         } else
2367                 printf("The reta size of port %d is %u\n",
2368                         res->port_id, dev_info.reta_size);
2369         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2370                 printf("Currently do not support more than %u entries of "
2371                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2372                 return;
2373         }
2374
2375         memset(reta_conf, 0, sizeof(reta_conf));
2376         if (!strcmp(res->list_name, "reta")) {
2377                 if (parse_reta_config(res->list_of_items, reta_conf,
2378                                                 dev_info.reta_size)) {
2379                         printf("Invalid RSS Redirection Table "
2380                                         "config entered\n");
2381                         return;
2382                 }
2383                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2384                                 reta_conf, dev_info.reta_size);
2385                 if (ret != 0)
2386                         printf("Bad redirection table parameter, "
2387                                         "return code = %d \n", ret);
2388         }
2389 }
2390
2391 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2392         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2393 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2394         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2395 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2396         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2397 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2398         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2399 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2400         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2401 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2402         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2403                                  NULL);
2404 cmdline_parse_inst_t cmd_config_rss_reta = {
2405         .f = cmd_set_rss_reta_parsed,
2406         .data = NULL,
2407         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2408         .tokens = {
2409                 (void *)&cmd_config_rss_reta_port,
2410                 (void *)&cmd_config_rss_reta_keyword,
2411                 (void *)&cmd_config_rss_reta_port_id,
2412                 (void *)&cmd_config_rss_reta_name,
2413                 (void *)&cmd_config_rss_reta_list_name,
2414                 (void *)&cmd_config_rss_reta_list_of_items,
2415                 NULL,
2416         },
2417 };
2418
2419 /* *** SHOW PORT RETA INFO *** */
2420 struct cmd_showport_reta {
2421         cmdline_fixed_string_t show;
2422         cmdline_fixed_string_t port;
2423         portid_t port_id;
2424         cmdline_fixed_string_t rss;
2425         cmdline_fixed_string_t reta;
2426         uint16_t size;
2427         cmdline_fixed_string_t list_of_items;
2428 };
2429
2430 static int
2431 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2432                            uint16_t nb_entries,
2433                            char *str)
2434 {
2435         uint32_t size;
2436         const char *p, *p0 = str;
2437         char s[256];
2438         char *end;
2439         char *str_fld[8];
2440         uint16_t i;
2441         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2442                         RTE_RETA_GROUP_SIZE;
2443         int ret;
2444
2445         p = strchr(p0, '(');
2446         if (p == NULL)
2447                 return -1;
2448         p++;
2449         p0 = strchr(p, ')');
2450         if (p0 == NULL)
2451                 return -1;
2452         size = p0 - p;
2453         if (size >= sizeof(s)) {
2454                 printf("The string size exceeds the internal buffer size\n");
2455                 return -1;
2456         }
2457         snprintf(s, sizeof(s), "%.*s", size, p);
2458         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2459         if (ret <= 0 || ret != num) {
2460                 printf("The bits of masks do not match the number of "
2461                                         "reta entries: %u\n", num);
2462                 return -1;
2463         }
2464         for (i = 0; i < ret; i++)
2465                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2466
2467         return 0;
2468 }
2469
2470 static void
2471 cmd_showport_reta_parsed(void *parsed_result,
2472                          __attribute__((unused)) struct cmdline *cl,
2473                          __attribute__((unused)) void *data)
2474 {
2475         struct cmd_showport_reta *res = parsed_result;
2476         struct rte_eth_rss_reta_entry64 reta_conf[8];
2477         struct rte_eth_dev_info dev_info;
2478         uint16_t max_reta_size;
2479
2480         memset(&dev_info, 0, sizeof(dev_info));
2481         rte_eth_dev_info_get(res->port_id, &dev_info);
2482         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2483         if (res->size == 0 || res->size > max_reta_size) {
2484                 printf("Invalid redirection table size: %u (1-%u)\n",
2485                         res->size, max_reta_size);
2486                 return;
2487         }
2488
2489         memset(reta_conf, 0, sizeof(reta_conf));
2490         if (showport_parse_reta_config(reta_conf, res->size,
2491                                 res->list_of_items) < 0) {
2492                 printf("Invalid string: %s for reta masks\n",
2493                                         res->list_of_items);
2494                 return;
2495         }
2496         port_rss_reta_info(res->port_id, reta_conf, res->size);
2497 }
2498
2499 cmdline_parse_token_string_t cmd_showport_reta_show =
2500         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2501 cmdline_parse_token_string_t cmd_showport_reta_port =
2502         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2503 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2504         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2505 cmdline_parse_token_string_t cmd_showport_reta_rss =
2506         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2507 cmdline_parse_token_string_t cmd_showport_reta_reta =
2508         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2509 cmdline_parse_token_num_t cmd_showport_reta_size =
2510         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2511 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2512         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2513                                         list_of_items, NULL);
2514
2515 cmdline_parse_inst_t cmd_showport_reta = {
2516         .f = cmd_showport_reta_parsed,
2517         .data = NULL,
2518         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2519         .tokens = {
2520                 (void *)&cmd_showport_reta_show,
2521                 (void *)&cmd_showport_reta_port,
2522                 (void *)&cmd_showport_reta_port_id,
2523                 (void *)&cmd_showport_reta_rss,
2524                 (void *)&cmd_showport_reta_reta,
2525                 (void *)&cmd_showport_reta_size,
2526                 (void *)&cmd_showport_reta_list_of_items,
2527                 NULL,
2528         },
2529 };
2530
2531 /* *** Show RSS hash configuration *** */
2532 struct cmd_showport_rss_hash {
2533         cmdline_fixed_string_t show;
2534         cmdline_fixed_string_t port;
2535         portid_t port_id;
2536         cmdline_fixed_string_t rss_hash;
2537         cmdline_fixed_string_t rss_type;
2538         cmdline_fixed_string_t key; /* optional argument */
2539 };
2540
2541 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2542                                 __attribute__((unused)) struct cmdline *cl,
2543                                 void *show_rss_key)
2544 {
2545         struct cmd_showport_rss_hash *res = parsed_result;
2546
2547         port_rss_hash_conf_show(res->port_id, res->rss_type,
2548                                 show_rss_key != NULL);
2549 }
2550
2551 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2552         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2553 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2554         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2555 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2556         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2557 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2558         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2559                                  "rss-hash");
2560 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2561         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2562                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2563                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2564                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2565                                  "ipv6-tcp-ex#ipv6-udp-ex");
2566 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2567         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2568
2569 cmdline_parse_inst_t cmd_showport_rss_hash = {
2570         .f = cmd_showport_rss_hash_parsed,
2571         .data = NULL,
2572         .help_str = "show port <port_id> rss-hash "
2573                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2574                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2575                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2576         .tokens = {
2577                 (void *)&cmd_showport_rss_hash_show,
2578                 (void *)&cmd_showport_rss_hash_port,
2579                 (void *)&cmd_showport_rss_hash_port_id,
2580                 (void *)&cmd_showport_rss_hash_rss_hash,
2581                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2582                 NULL,
2583         },
2584 };
2585
2586 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2587         .f = cmd_showport_rss_hash_parsed,
2588         .data = (void *)1,
2589         .help_str = "show port <port_id> rss-hash "
2590                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2591                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2592                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2593         .tokens = {
2594                 (void *)&cmd_showport_rss_hash_show,
2595                 (void *)&cmd_showport_rss_hash_port,
2596                 (void *)&cmd_showport_rss_hash_port_id,
2597                 (void *)&cmd_showport_rss_hash_rss_hash,
2598                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2599                 (void *)&cmd_showport_rss_hash_rss_key,
2600                 NULL,
2601         },
2602 };
2603
2604 /* *** Configure DCB *** */
2605 struct cmd_config_dcb {
2606         cmdline_fixed_string_t port;
2607         cmdline_fixed_string_t config;
2608         portid_t port_id;
2609         cmdline_fixed_string_t dcb;
2610         cmdline_fixed_string_t vt;
2611         cmdline_fixed_string_t vt_en;
2612         uint8_t num_tcs;
2613         cmdline_fixed_string_t pfc;
2614         cmdline_fixed_string_t pfc_en;
2615 };
2616
2617 static void
2618 cmd_config_dcb_parsed(void *parsed_result,
2619                         __attribute__((unused)) struct cmdline *cl,
2620                         __attribute__((unused)) void *data)
2621 {
2622         struct cmd_config_dcb *res = parsed_result;
2623         portid_t port_id = res->port_id;
2624         struct rte_port *port;
2625         uint8_t pfc_en;
2626         int ret;
2627
2628         port = &ports[port_id];
2629         /** Check if the port is not started **/
2630         if (port->port_status != RTE_PORT_STOPPED) {
2631                 printf("Please stop port %d first\n", port_id);
2632                 return;
2633         }
2634
2635         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2636                 printf("The invalid number of traffic class,"
2637                         " only 4 or 8 allowed.\n");
2638                 return;
2639         }
2640
2641         if (nb_fwd_lcores < res->num_tcs) {
2642                 printf("nb_cores shouldn't be less than number of TCs.\n");
2643                 return;
2644         }
2645         if (!strncmp(res->pfc_en, "on", 2))
2646                 pfc_en = 1;
2647         else
2648                 pfc_en = 0;
2649
2650         /* DCB in VT mode */
2651         if (!strncmp(res->vt_en, "on", 2))
2652                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2653                                 (enum rte_eth_nb_tcs)res->num_tcs,
2654                                 pfc_en);
2655         else
2656                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2657                                 (enum rte_eth_nb_tcs)res->num_tcs,
2658                                 pfc_en);
2659
2660
2661         if (ret != 0) {
2662                 printf("Cannot initialize network ports.\n");
2663                 return;
2664         }
2665
2666         cmd_reconfig_device_queue(port_id, 1, 1);
2667 }
2668
2669 cmdline_parse_token_string_t cmd_config_dcb_port =
2670         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2671 cmdline_parse_token_string_t cmd_config_dcb_config =
2672         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2673 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2674         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2675 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2676         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2677 cmdline_parse_token_string_t cmd_config_dcb_vt =
2678         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2679 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2680         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2681 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2682         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2683 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2684         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2685 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2686         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2687
2688 cmdline_parse_inst_t cmd_config_dcb = {
2689         .f = cmd_config_dcb_parsed,
2690         .data = NULL,
2691         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2692         .tokens = {
2693                 (void *)&cmd_config_dcb_port,
2694                 (void *)&cmd_config_dcb_config,
2695                 (void *)&cmd_config_dcb_port_id,
2696                 (void *)&cmd_config_dcb_dcb,
2697                 (void *)&cmd_config_dcb_vt,
2698                 (void *)&cmd_config_dcb_vt_en,
2699                 (void *)&cmd_config_dcb_num_tcs,
2700                 (void *)&cmd_config_dcb_pfc,
2701                 (void *)&cmd_config_dcb_pfc_en,
2702                 NULL,
2703         },
2704 };
2705
2706 /* *** configure number of packets per burst *** */
2707 struct cmd_config_burst {
2708         cmdline_fixed_string_t port;
2709         cmdline_fixed_string_t keyword;
2710         cmdline_fixed_string_t all;
2711         cmdline_fixed_string_t name;
2712         uint16_t value;
2713 };
2714
2715 static void
2716 cmd_config_burst_parsed(void *parsed_result,
2717                         __attribute__((unused)) struct cmdline *cl,
2718                         __attribute__((unused)) void *data)
2719 {
2720         struct cmd_config_burst *res = parsed_result;
2721
2722         if (!all_ports_stopped()) {
2723                 printf("Please stop all ports first\n");
2724                 return;
2725         }
2726
2727         if (!strcmp(res->name, "burst")) {
2728                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2729                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2730                         return;
2731                 }
2732                 nb_pkt_per_burst = res->value;
2733         } else {
2734                 printf("Unknown parameter\n");
2735                 return;
2736         }
2737
2738         init_port_config();
2739
2740         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2741 }
2742
2743 cmdline_parse_token_string_t cmd_config_burst_port =
2744         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2745 cmdline_parse_token_string_t cmd_config_burst_keyword =
2746         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2747 cmdline_parse_token_string_t cmd_config_burst_all =
2748         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2749 cmdline_parse_token_string_t cmd_config_burst_name =
2750         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2751 cmdline_parse_token_num_t cmd_config_burst_value =
2752         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2753
2754 cmdline_parse_inst_t cmd_config_burst = {
2755         .f = cmd_config_burst_parsed,
2756         .data = NULL,
2757         .help_str = "port config all burst <value>",
2758         .tokens = {
2759                 (void *)&cmd_config_burst_port,
2760                 (void *)&cmd_config_burst_keyword,
2761                 (void *)&cmd_config_burst_all,
2762                 (void *)&cmd_config_burst_name,
2763                 (void *)&cmd_config_burst_value,
2764                 NULL,
2765         },
2766 };
2767
2768 /* *** configure rx/tx queues *** */
2769 struct cmd_config_thresh {
2770         cmdline_fixed_string_t port;
2771         cmdline_fixed_string_t keyword;
2772         cmdline_fixed_string_t all;
2773         cmdline_fixed_string_t name;
2774         uint8_t value;
2775 };
2776
2777 static void
2778 cmd_config_thresh_parsed(void *parsed_result,
2779                         __attribute__((unused)) struct cmdline *cl,
2780                         __attribute__((unused)) void *data)
2781 {
2782         struct cmd_config_thresh *res = parsed_result;
2783
2784         if (!all_ports_stopped()) {
2785                 printf("Please stop all ports first\n");
2786                 return;
2787         }
2788
2789         if (!strcmp(res->name, "txpt"))
2790                 tx_pthresh = res->value;
2791         else if(!strcmp(res->name, "txht"))
2792                 tx_hthresh = res->value;
2793         else if(!strcmp(res->name, "txwt"))
2794                 tx_wthresh = res->value;
2795         else if(!strcmp(res->name, "rxpt"))
2796                 rx_pthresh = res->value;
2797         else if(!strcmp(res->name, "rxht"))
2798                 rx_hthresh = res->value;
2799         else if(!strcmp(res->name, "rxwt"))
2800                 rx_wthresh = res->value;
2801         else {
2802                 printf("Unknown parameter\n");
2803                 return;
2804         }
2805
2806         init_port_config();
2807
2808         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2809 }
2810
2811 cmdline_parse_token_string_t cmd_config_thresh_port =
2812         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2813 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2814         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2815 cmdline_parse_token_string_t cmd_config_thresh_all =
2816         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2817 cmdline_parse_token_string_t cmd_config_thresh_name =
2818         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2819                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2820 cmdline_parse_token_num_t cmd_config_thresh_value =
2821         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2822
2823 cmdline_parse_inst_t cmd_config_thresh = {
2824         .f = cmd_config_thresh_parsed,
2825         .data = NULL,
2826         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2827         .tokens = {
2828                 (void *)&cmd_config_thresh_port,
2829                 (void *)&cmd_config_thresh_keyword,
2830                 (void *)&cmd_config_thresh_all,
2831                 (void *)&cmd_config_thresh_name,
2832                 (void *)&cmd_config_thresh_value,
2833                 NULL,
2834         },
2835 };
2836
2837 /* *** configure free/rs threshold *** */
2838 struct cmd_config_threshold {
2839         cmdline_fixed_string_t port;
2840         cmdline_fixed_string_t keyword;
2841         cmdline_fixed_string_t all;
2842         cmdline_fixed_string_t name;
2843         uint16_t value;
2844 };
2845
2846 static void
2847 cmd_config_threshold_parsed(void *parsed_result,
2848                         __attribute__((unused)) struct cmdline *cl,
2849                         __attribute__((unused)) void *data)
2850 {
2851         struct cmd_config_threshold *res = parsed_result;
2852
2853         if (!all_ports_stopped()) {
2854                 printf("Please stop all ports first\n");
2855                 return;
2856         }
2857
2858         if (!strcmp(res->name, "txfreet"))
2859                 tx_free_thresh = res->value;
2860         else if (!strcmp(res->name, "txrst"))
2861                 tx_rs_thresh = res->value;
2862         else if (!strcmp(res->name, "rxfreet"))
2863                 rx_free_thresh = res->value;
2864         else {
2865                 printf("Unknown parameter\n");
2866                 return;
2867         }
2868
2869         init_port_config();
2870
2871         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2872 }
2873
2874 cmdline_parse_token_string_t cmd_config_threshold_port =
2875         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2876 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2877         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2878                                                                 "config");
2879 cmdline_parse_token_string_t cmd_config_threshold_all =
2880         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2881 cmdline_parse_token_string_t cmd_config_threshold_name =
2882         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2883                                                 "txfreet#txrst#rxfreet");
2884 cmdline_parse_token_num_t cmd_config_threshold_value =
2885         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2886
2887 cmdline_parse_inst_t cmd_config_threshold = {
2888         .f = cmd_config_threshold_parsed,
2889         .data = NULL,
2890         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2891         .tokens = {
2892                 (void *)&cmd_config_threshold_port,
2893                 (void *)&cmd_config_threshold_keyword,
2894                 (void *)&cmd_config_threshold_all,
2895                 (void *)&cmd_config_threshold_name,
2896                 (void *)&cmd_config_threshold_value,
2897                 NULL,
2898         },
2899 };
2900
2901 /* *** stop *** */
2902 struct cmd_stop_result {
2903         cmdline_fixed_string_t stop;
2904 };
2905
2906 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2907                             __attribute__((unused)) struct cmdline *cl,
2908                             __attribute__((unused)) void *data)
2909 {
2910         stop_packet_forwarding();
2911 }
2912
2913 cmdline_parse_token_string_t cmd_stop_stop =
2914         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2915
2916 cmdline_parse_inst_t cmd_stop = {
2917         .f = cmd_stop_parsed,
2918         .data = NULL,
2919         .help_str = "stop: Stop packet forwarding",
2920         .tokens = {
2921                 (void *)&cmd_stop_stop,
2922                 NULL,
2923         },
2924 };
2925
2926 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2927
2928 unsigned int
2929 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2930                 unsigned int *parsed_items, int check_unique_values)
2931 {
2932         unsigned int nb_item;
2933         unsigned int value;
2934         unsigned int i;
2935         unsigned int j;
2936         int value_ok;
2937         char c;
2938
2939         /*
2940          * First parse all items in the list and store their value.
2941          */
2942         value = 0;
2943         nb_item = 0;
2944         value_ok = 0;
2945         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2946                 c = str[i];
2947                 if ((c >= '0') && (c <= '9')) {
2948                         value = (unsigned int) (value * 10 + (c - '0'));
2949                         value_ok = 1;
2950                         continue;
2951                 }
2952                 if (c != ',') {
2953                         printf("character %c is not a decimal digit\n", c);
2954                         return 0;
2955                 }
2956                 if (! value_ok) {
2957                         printf("No valid value before comma\n");
2958                         return 0;
2959                 }
2960                 if (nb_item < max_items) {
2961                         parsed_items[nb_item] = value;
2962                         value_ok = 0;
2963                         value = 0;
2964                 }
2965                 nb_item++;
2966         }
2967         if (nb_item >= max_items) {
2968                 printf("Number of %s = %u > %u (maximum items)\n",
2969                        item_name, nb_item + 1, max_items);
2970                 return 0;
2971         }
2972         parsed_items[nb_item++] = value;
2973         if (! check_unique_values)
2974                 return nb_item;
2975
2976         /*
2977          * Then, check that all values in the list are differents.
2978          * No optimization here...
2979          */
2980         for (i = 0; i < nb_item; i++) {
2981                 for (j = i + 1; j < nb_item; j++) {
2982                         if (parsed_items[j] == parsed_items[i]) {
2983                                 printf("duplicated %s %u at index %u and %u\n",
2984                                        item_name, parsed_items[i], i, j);
2985                                 return 0;
2986                         }
2987                 }
2988         }
2989         return nb_item;
2990 }
2991
2992 struct cmd_set_list_result {
2993         cmdline_fixed_string_t cmd_keyword;
2994         cmdline_fixed_string_t list_name;
2995         cmdline_fixed_string_t list_of_items;
2996 };
2997
2998 static void cmd_set_list_parsed(void *parsed_result,
2999                                 __attribute__((unused)) struct cmdline *cl,
3000                                 __attribute__((unused)) void *data)
3001 {
3002         struct cmd_set_list_result *res;
3003         union {
3004                 unsigned int lcorelist[RTE_MAX_LCORE];
3005                 unsigned int portlist[RTE_MAX_ETHPORTS];
3006         } parsed_items;
3007         unsigned int nb_item;
3008
3009         if (test_done == 0) {
3010                 printf("Please stop forwarding first\n");
3011                 return;
3012         }
3013
3014         res = parsed_result;
3015         if (!strcmp(res->list_name, "corelist")) {
3016                 nb_item = parse_item_list(res->list_of_items, "core",
3017                                           RTE_MAX_LCORE,
3018                                           parsed_items.lcorelist, 1);
3019                 if (nb_item > 0) {
3020                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3021                         fwd_config_setup();
3022                 }
3023                 return;
3024         }
3025         if (!strcmp(res->list_name, "portlist")) {
3026                 nb_item = parse_item_list(res->list_of_items, "port",
3027                                           RTE_MAX_ETHPORTS,
3028                                           parsed_items.portlist, 1);
3029                 if (nb_item > 0) {
3030                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3031                         fwd_config_setup();
3032                 }
3033         }
3034 }
3035
3036 cmdline_parse_token_string_t cmd_set_list_keyword =
3037         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3038                                  "set");
3039 cmdline_parse_token_string_t cmd_set_list_name =
3040         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3041                                  "corelist#portlist");
3042 cmdline_parse_token_string_t cmd_set_list_of_items =
3043         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3044                                  NULL);
3045
3046 cmdline_parse_inst_t cmd_set_fwd_list = {
3047         .f = cmd_set_list_parsed,
3048         .data = NULL,
3049         .help_str = "set corelist|portlist <list0[,list1]*>",
3050         .tokens = {
3051                 (void *)&cmd_set_list_keyword,
3052                 (void *)&cmd_set_list_name,
3053                 (void *)&cmd_set_list_of_items,
3054                 NULL,
3055         },
3056 };
3057
3058 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3059
3060 struct cmd_setmask_result {
3061         cmdline_fixed_string_t set;
3062         cmdline_fixed_string_t mask;
3063         uint64_t hexavalue;
3064 };
3065
3066 static void cmd_set_mask_parsed(void *parsed_result,
3067                                 __attribute__((unused)) struct cmdline *cl,
3068                                 __attribute__((unused)) void *data)
3069 {
3070         struct cmd_setmask_result *res = parsed_result;
3071
3072         if (test_done == 0) {
3073                 printf("Please stop forwarding first\n");
3074                 return;
3075         }
3076         if (!strcmp(res->mask, "coremask")) {
3077                 set_fwd_lcores_mask(res->hexavalue);
3078                 fwd_config_setup();
3079         } else if (!strcmp(res->mask, "portmask")) {
3080                 set_fwd_ports_mask(res->hexavalue);
3081                 fwd_config_setup();
3082         }
3083 }
3084
3085 cmdline_parse_token_string_t cmd_setmask_set =
3086         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3087 cmdline_parse_token_string_t cmd_setmask_mask =
3088         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3089                                  "coremask#portmask");
3090 cmdline_parse_token_num_t cmd_setmask_value =
3091         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3092
3093 cmdline_parse_inst_t cmd_set_fwd_mask = {
3094         .f = cmd_set_mask_parsed,
3095         .data = NULL,
3096         .help_str = "set coremask|portmask <hexadecimal value>",
3097         .tokens = {
3098                 (void *)&cmd_setmask_set,
3099                 (void *)&cmd_setmask_mask,
3100                 (void *)&cmd_setmask_value,
3101                 NULL,
3102         },
3103 };
3104
3105 /*
3106  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3107  */
3108 struct cmd_set_result {
3109         cmdline_fixed_string_t set;
3110         cmdline_fixed_string_t what;
3111         uint16_t value;
3112 };
3113
3114 static void cmd_set_parsed(void *parsed_result,
3115                            __attribute__((unused)) struct cmdline *cl,
3116                            __attribute__((unused)) void *data)
3117 {
3118         struct cmd_set_result *res = parsed_result;
3119         if (!strcmp(res->what, "nbport")) {
3120                 set_fwd_ports_number(res->value);
3121                 fwd_config_setup();
3122         } else if (!strcmp(res->what, "nbcore")) {
3123                 set_fwd_lcores_number(res->value);
3124                 fwd_config_setup();
3125         } else if (!strcmp(res->what, "burst"))
3126                 set_nb_pkt_per_burst(res->value);
3127         else if (!strcmp(res->what, "verbose"))
3128                 set_verbose_level(res->value);
3129 }
3130
3131 cmdline_parse_token_string_t cmd_set_set =
3132         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3133 cmdline_parse_token_string_t cmd_set_what =
3134         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3135                                  "nbport#nbcore#burst#verbose");
3136 cmdline_parse_token_num_t cmd_set_value =
3137         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3138
3139 cmdline_parse_inst_t cmd_set_numbers = {
3140         .f = cmd_set_parsed,
3141         .data = NULL,
3142         .help_str = "set nbport|nbcore|burst|verbose <value>",
3143         .tokens = {
3144                 (void *)&cmd_set_set,
3145                 (void *)&cmd_set_what,
3146                 (void *)&cmd_set_value,
3147                 NULL,
3148         },
3149 };
3150
3151 /* *** SET LOG LEVEL CONFIGURATION *** */
3152
3153 struct cmd_set_log_result {
3154         cmdline_fixed_string_t set;
3155         cmdline_fixed_string_t log;
3156         cmdline_fixed_string_t type;
3157         uint32_t level;
3158 };
3159
3160 static void
3161 cmd_set_log_parsed(void *parsed_result,
3162                    __attribute__((unused)) struct cmdline *cl,
3163                    __attribute__((unused)) void *data)
3164 {
3165         struct cmd_set_log_result *res;
3166         int ret;
3167
3168         res = parsed_result;
3169         if (!strcmp(res->type, "global"))
3170                 rte_log_set_global_level(res->level);
3171         else {
3172                 ret = rte_log_set_level_regexp(res->type, res->level);
3173                 if (ret < 0)
3174                         printf("Unable to set log level\n");
3175         }
3176 }
3177
3178 cmdline_parse_token_string_t cmd_set_log_set =
3179         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3180 cmdline_parse_token_string_t cmd_set_log_log =
3181         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3182 cmdline_parse_token_string_t cmd_set_log_type =
3183         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3184 cmdline_parse_token_num_t cmd_set_log_level =
3185         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3186
3187 cmdline_parse_inst_t cmd_set_log = {
3188         .f = cmd_set_log_parsed,
3189         .data = NULL,
3190         .help_str = "set log global|<type> <level>",
3191         .tokens = {
3192                 (void *)&cmd_set_log_set,
3193                 (void *)&cmd_set_log_log,
3194                 (void *)&cmd_set_log_type,
3195                 (void *)&cmd_set_log_level,
3196                 NULL,
3197         },
3198 };
3199
3200 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3201
3202 struct cmd_set_txpkts_result {
3203         cmdline_fixed_string_t cmd_keyword;
3204         cmdline_fixed_string_t txpkts;
3205         cmdline_fixed_string_t seg_lengths;
3206 };
3207
3208 static void
3209 cmd_set_txpkts_parsed(void *parsed_result,
3210                       __attribute__((unused)) struct cmdline *cl,
3211                       __attribute__((unused)) void *data)
3212 {
3213         struct cmd_set_txpkts_result *res;
3214         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3215         unsigned int nb_segs;
3216
3217         res = parsed_result;
3218         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3219                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3220         if (nb_segs > 0)
3221                 set_tx_pkt_segments(seg_lengths, nb_segs);
3222 }
3223
3224 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3225         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3226                                  cmd_keyword, "set");
3227 cmdline_parse_token_string_t cmd_set_txpkts_name =
3228         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3229                                  txpkts, "txpkts");
3230 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3231         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3232                                  seg_lengths, NULL);
3233
3234 cmdline_parse_inst_t cmd_set_txpkts = {
3235         .f = cmd_set_txpkts_parsed,
3236         .data = NULL,
3237         .help_str = "set txpkts <len0[,len1]*>",
3238         .tokens = {
3239                 (void *)&cmd_set_txpkts_keyword,
3240                 (void *)&cmd_set_txpkts_name,
3241                 (void *)&cmd_set_txpkts_lengths,
3242                 NULL,
3243         },
3244 };
3245
3246 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3247
3248 struct cmd_set_txsplit_result {
3249         cmdline_fixed_string_t cmd_keyword;
3250         cmdline_fixed_string_t txsplit;
3251         cmdline_fixed_string_t mode;
3252 };
3253
3254 static void
3255 cmd_set_txsplit_parsed(void *parsed_result,
3256                       __attribute__((unused)) struct cmdline *cl,
3257                       __attribute__((unused)) void *data)
3258 {
3259         struct cmd_set_txsplit_result *res;
3260
3261         res = parsed_result;
3262         set_tx_pkt_split(res->mode);
3263 }
3264
3265 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3266         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3267                                  cmd_keyword, "set");
3268 cmdline_parse_token_string_t cmd_set_txsplit_name =
3269         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3270                                  txsplit, "txsplit");
3271 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3272         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3273                                  mode, NULL);
3274
3275 cmdline_parse_inst_t cmd_set_txsplit = {
3276         .f = cmd_set_txsplit_parsed,
3277         .data = NULL,
3278         .help_str = "set txsplit on|off|rand",
3279         .tokens = {
3280                 (void *)&cmd_set_txsplit_keyword,
3281                 (void *)&cmd_set_txsplit_name,
3282                 (void *)&cmd_set_txsplit_mode,
3283                 NULL,
3284         },
3285 };
3286
3287 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3288 struct cmd_rx_vlan_filter_all_result {
3289         cmdline_fixed_string_t rx_vlan;
3290         cmdline_fixed_string_t what;
3291         cmdline_fixed_string_t all;
3292         portid_t port_id;
3293 };
3294
3295 static void
3296 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3297                               __attribute__((unused)) struct cmdline *cl,
3298                               __attribute__((unused)) void *data)
3299 {
3300         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3301
3302         if (!strcmp(res->what, "add"))
3303                 rx_vlan_all_filter_set(res->port_id, 1);
3304         else
3305                 rx_vlan_all_filter_set(res->port_id, 0);
3306 }
3307
3308 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3309         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3310                                  rx_vlan, "rx_vlan");
3311 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3312         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3313                                  what, "add#rm");
3314 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3315         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3316                                  all, "all");
3317 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3318         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3319                               port_id, UINT16);
3320
3321 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3322         .f = cmd_rx_vlan_filter_all_parsed,
3323         .data = NULL,
3324         .help_str = "rx_vlan add|rm all <port_id>: "
3325                 "Add/Remove all identifiers to/from the set of VLAN "
3326                 "identifiers filtered by a port",
3327         .tokens = {
3328                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3329                 (void *)&cmd_rx_vlan_filter_all_what,
3330                 (void *)&cmd_rx_vlan_filter_all_all,
3331                 (void *)&cmd_rx_vlan_filter_all_portid,
3332                 NULL,
3333         },
3334 };
3335
3336 /* *** VLAN OFFLOAD SET ON A PORT *** */
3337 struct cmd_vlan_offload_result {
3338         cmdline_fixed_string_t vlan;
3339         cmdline_fixed_string_t set;
3340         cmdline_fixed_string_t vlan_type;
3341         cmdline_fixed_string_t what;
3342         cmdline_fixed_string_t on;
3343         cmdline_fixed_string_t port_id;
3344 };
3345
3346 static void
3347 cmd_vlan_offload_parsed(void *parsed_result,
3348                           __attribute__((unused)) struct cmdline *cl,
3349                           __attribute__((unused)) void *data)
3350 {
3351         int on;
3352         struct cmd_vlan_offload_result *res = parsed_result;
3353         char *str;
3354         int i, len = 0;
3355         portid_t port_id = 0;
3356         unsigned int tmp;
3357
3358         str = res->port_id;
3359         len = strnlen(str, STR_TOKEN_SIZE);
3360         i = 0;
3361         /* Get port_id first */
3362         while(i < len){
3363                 if(str[i] == ',')
3364                         break;
3365
3366                 i++;
3367         }
3368         str[i]='\0';
3369         tmp = strtoul(str, NULL, 0);
3370         /* If port_id greater that what portid_t can represent, return */
3371         if(tmp >= RTE_MAX_ETHPORTS)
3372                 return;
3373         port_id = (portid_t)tmp;
3374
3375         if (!strcmp(res->on, "on"))
3376                 on = 1;
3377         else
3378                 on = 0;
3379
3380         if (!strcmp(res->what, "strip"))
3381                 rx_vlan_strip_set(port_id,  on);
3382         else if(!strcmp(res->what, "stripq")){
3383                 uint16_t queue_id = 0;
3384
3385                 /* No queue_id, return */
3386                 if(i + 1 >= len) {
3387                         printf("must specify (port,queue_id)\n");
3388                         return;
3389                 }
3390                 tmp = strtoul(str + i + 1, NULL, 0);
3391                 /* If queue_id greater that what 16-bits can represent, return */
3392                 if(tmp > 0xffff)
3393                         return;
3394
3395                 queue_id = (uint16_t)tmp;
3396                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3397         }
3398         else if (!strcmp(res->what, "filter"))
3399                 rx_vlan_filter_set(port_id, on);
3400         else
3401                 vlan_extend_set(port_id, on);
3402
3403         return;
3404 }
3405
3406 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3407         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3408                                  vlan, "vlan");
3409 cmdline_parse_token_string_t cmd_vlan_offload_set =
3410         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3411                                  set, "set");
3412 cmdline_parse_token_string_t cmd_vlan_offload_what =
3413         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3414                                  what, "strip#filter#qinq#stripq");
3415 cmdline_parse_token_string_t cmd_vlan_offload_on =
3416         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3417                               on, "on#off");
3418 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3419         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3420                               port_id, NULL);
3421
3422 cmdline_parse_inst_t cmd_vlan_offload = {
3423         .f = cmd_vlan_offload_parsed,
3424         .data = NULL,
3425         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3426                 "<port_id[,queue_id]>: "
3427                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3428         .tokens = {
3429                 (void *)&cmd_vlan_offload_vlan,
3430                 (void *)&cmd_vlan_offload_set,
3431                 (void *)&cmd_vlan_offload_what,
3432                 (void *)&cmd_vlan_offload_on,
3433                 (void *)&cmd_vlan_offload_portid,
3434                 NULL,
3435         },
3436 };
3437
3438 /* *** VLAN TPID SET ON A PORT *** */
3439 struct cmd_vlan_tpid_result {
3440         cmdline_fixed_string_t vlan;
3441         cmdline_fixed_string_t set;
3442         cmdline_fixed_string_t vlan_type;
3443         cmdline_fixed_string_t what;
3444         uint16_t tp_id;
3445         portid_t port_id;
3446 };
3447
3448 static void
3449 cmd_vlan_tpid_parsed(void *parsed_result,
3450                           __attribute__((unused)) struct cmdline *cl,
3451                           __attribute__((unused)) void *data)
3452 {
3453         struct cmd_vlan_tpid_result *res = parsed_result;
3454         enum rte_vlan_type vlan_type;
3455
3456         if (!strcmp(res->vlan_type, "inner"))
3457                 vlan_type = ETH_VLAN_TYPE_INNER;
3458         else if (!strcmp(res->vlan_type, "outer"))
3459                 vlan_type = ETH_VLAN_TYPE_OUTER;
3460         else {
3461                 printf("Unknown vlan type\n");
3462                 return;
3463         }
3464         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3465 }
3466
3467 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3468         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3469                                  vlan, "vlan");
3470 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3471         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3472                                  set, "set");
3473 cmdline_parse_token_string_t cmd_vlan_type =
3474         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3475                                  vlan_type, "inner#outer");
3476 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3477         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3478                                  what, "tpid");
3479 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3480         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3481                               tp_id, UINT16);
3482 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3483         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3484                               port_id, UINT16);
3485
3486 cmdline_parse_inst_t cmd_vlan_tpid = {
3487         .f = cmd_vlan_tpid_parsed,
3488         .data = NULL,
3489         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3490                 "Set the VLAN Ether type",
3491         .tokens = {
3492                 (void *)&cmd_vlan_tpid_vlan,
3493                 (void *)&cmd_vlan_tpid_set,
3494                 (void *)&cmd_vlan_type,
3495                 (void *)&cmd_vlan_tpid_what,
3496                 (void *)&cmd_vlan_tpid_tpid,
3497                 (void *)&cmd_vlan_tpid_portid,
3498                 NULL,
3499         },
3500 };
3501
3502 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3503 struct cmd_rx_vlan_filter_result {
3504         cmdline_fixed_string_t rx_vlan;
3505         cmdline_fixed_string_t what;
3506         uint16_t vlan_id;
3507         portid_t port_id;
3508 };
3509
3510 static void
3511 cmd_rx_vlan_filter_parsed(void *parsed_result,
3512                           __attribute__((unused)) struct cmdline *cl,
3513                           __attribute__((unused)) void *data)
3514 {
3515         struct cmd_rx_vlan_filter_result *res = parsed_result;
3516
3517         if (!strcmp(res->what, "add"))
3518                 rx_vft_set(res->port_id, res->vlan_id, 1);
3519         else
3520                 rx_vft_set(res->port_id, res->vlan_id, 0);
3521 }
3522
3523 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3524         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3525                                  rx_vlan, "rx_vlan");
3526 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3527         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3528                                  what, "add#rm");
3529 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3530         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3531                               vlan_id, UINT16);
3532 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3533         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3534                               port_id, UINT16);
3535
3536 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3537         .f = cmd_rx_vlan_filter_parsed,
3538         .data = NULL,
3539         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3540                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3541                 "identifiers filtered by a port",
3542         .tokens = {
3543                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3544                 (void *)&cmd_rx_vlan_filter_what,
3545                 (void *)&cmd_rx_vlan_filter_vlanid,
3546                 (void *)&cmd_rx_vlan_filter_portid,
3547                 NULL,
3548         },
3549 };
3550
3551 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3552 struct cmd_tx_vlan_set_result {
3553         cmdline_fixed_string_t tx_vlan;
3554         cmdline_fixed_string_t set;
3555         portid_t port_id;
3556         uint16_t vlan_id;
3557 };
3558
3559 static void
3560 cmd_tx_vlan_set_parsed(void *parsed_result,
3561                        __attribute__((unused)) struct cmdline *cl,
3562                        __attribute__((unused)) void *data)
3563 {
3564         struct cmd_tx_vlan_set_result *res = parsed_result;
3565
3566         if (!port_is_stopped(res->port_id)) {
3567                 printf("Please stop port %d first\n", res->port_id);
3568                 return;
3569         }
3570
3571         tx_vlan_set(res->port_id, res->vlan_id);
3572
3573         cmd_reconfig_device_queue(res->port_id, 1, 1);
3574 }
3575
3576 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3577         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3578                                  tx_vlan, "tx_vlan");
3579 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3580         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3581                                  set, "set");
3582 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3583         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3584                               port_id, UINT16);
3585 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3586         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3587                               vlan_id, UINT16);
3588
3589 cmdline_parse_inst_t cmd_tx_vlan_set = {
3590         .f = cmd_tx_vlan_set_parsed,
3591         .data = NULL,
3592         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3593                 "Enable hardware insertion of a single VLAN header "
3594                 "with a given TAG Identifier in packets sent on a port",
3595         .tokens = {
3596                 (void *)&cmd_tx_vlan_set_tx_vlan,
3597                 (void *)&cmd_tx_vlan_set_set,
3598                 (void *)&cmd_tx_vlan_set_portid,
3599                 (void *)&cmd_tx_vlan_set_vlanid,
3600                 NULL,
3601         },
3602 };
3603
3604 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3605 struct cmd_tx_vlan_set_qinq_result {
3606         cmdline_fixed_string_t tx_vlan;
3607         cmdline_fixed_string_t set;
3608         portid_t port_id;
3609         uint16_t vlan_id;
3610         uint16_t vlan_id_outer;
3611 };
3612
3613 static void
3614 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3615                             __attribute__((unused)) struct cmdline *cl,
3616                             __attribute__((unused)) void *data)
3617 {
3618         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3619
3620         if (!port_is_stopped(res->port_id)) {
3621                 printf("Please stop port %d first\n", res->port_id);
3622                 return;
3623         }
3624
3625         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3626
3627         cmd_reconfig_device_queue(res->port_id, 1, 1);
3628 }
3629
3630 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3631         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3632                 tx_vlan, "tx_vlan");
3633 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3634         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3635                 set, "set");
3636 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3637         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3638                 port_id, UINT16);
3639 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3640         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3641                 vlan_id, UINT16);
3642 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3643         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3644                 vlan_id_outer, UINT16);
3645
3646 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3647         .f = cmd_tx_vlan_set_qinq_parsed,
3648         .data = NULL,
3649         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3650                 "Enable hardware insertion of double VLAN header "
3651                 "with given TAG Identifiers in packets sent on a port",
3652         .tokens = {
3653                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3654                 (void *)&cmd_tx_vlan_set_qinq_set,
3655                 (void *)&cmd_tx_vlan_set_qinq_portid,
3656                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3657                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3658                 NULL,
3659         },
3660 };
3661
3662 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3663 struct cmd_tx_vlan_set_pvid_result {
3664         cmdline_fixed_string_t tx_vlan;
3665         cmdline_fixed_string_t set;
3666         cmdline_fixed_string_t pvid;
3667         portid_t port_id;
3668         uint16_t vlan_id;
3669         cmdline_fixed_string_t mode;
3670 };
3671
3672 static void
3673 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3674                             __attribute__((unused)) struct cmdline *cl,
3675                             __attribute__((unused)) void *data)
3676 {
3677         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3678
3679         if (strcmp(res->mode, "on") == 0)
3680                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3681         else
3682                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3683 }
3684
3685 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3686         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3687                                  tx_vlan, "tx_vlan");
3688 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3689         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3690                                  set, "set");
3691 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3692         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3693                                  pvid, "pvid");
3694 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3695         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3696                              port_id, UINT16);
3697 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3698         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3699                               vlan_id, UINT16);
3700 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3701         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3702                                  mode, "on#off");
3703
3704 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3705         .f = cmd_tx_vlan_set_pvid_parsed,
3706         .data = NULL,
3707         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3708         .tokens = {
3709                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3710                 (void *)&cmd_tx_vlan_set_pvid_set,
3711                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3712                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3713                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3714                 (void *)&cmd_tx_vlan_set_pvid_mode,
3715                 NULL,
3716         },
3717 };
3718
3719 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3720 struct cmd_tx_vlan_reset_result {
3721         cmdline_fixed_string_t tx_vlan;
3722         cmdline_fixed_string_t reset;
3723         portid_t port_id;
3724 };
3725
3726 static void
3727 cmd_tx_vlan_reset_parsed(void *parsed_result,
3728                          __attribute__((unused)) struct cmdline *cl,
3729                          __attribute__((unused)) void *data)
3730 {
3731         struct cmd_tx_vlan_reset_result *res = parsed_result;
3732
3733         if (!port_is_stopped(res->port_id)) {
3734                 printf("Please stop port %d first\n", res->port_id);
3735                 return;
3736         }
3737
3738         tx_vlan_reset(res->port_id);
3739
3740         cmd_reconfig_device_queue(res->port_id, 1, 1);
3741 }
3742
3743 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3744         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3745                                  tx_vlan, "tx_vlan");
3746 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3747         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3748                                  reset, "reset");
3749 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3750         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3751                               port_id, UINT16);
3752
3753 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3754         .f = cmd_tx_vlan_reset_parsed,
3755         .data = NULL,
3756         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3757                 "VLAN header in packets sent on a port",
3758         .tokens = {
3759                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3760                 (void *)&cmd_tx_vlan_reset_reset,
3761                 (void *)&cmd_tx_vlan_reset_portid,
3762                 NULL,
3763         },
3764 };
3765
3766
3767 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3768 struct cmd_csum_result {
3769         cmdline_fixed_string_t csum;
3770         cmdline_fixed_string_t mode;
3771         cmdline_fixed_string_t proto;
3772         cmdline_fixed_string_t hwsw;
3773         portid_t port_id;
3774 };
3775
3776 static void
3777 csum_show(int port_id)
3778 {
3779         struct rte_eth_dev_info dev_info;
3780         uint64_t tx_offloads;
3781
3782         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3783         printf("Parse tunnel is %s\n",
3784                 (ports[port_id].parse_tunnel) ? "on" : "off");
3785         printf("IP checksum offload is %s\n",
3786                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3787         printf("UDP checksum offload is %s\n",
3788                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3789         printf("TCP checksum offload is %s\n",
3790                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3791         printf("SCTP checksum offload is %s\n",
3792                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3793         printf("Outer-Ip checksum offload is %s\n",
3794                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3795
3796         /* display warnings if configuration is not supported by the NIC */
3797         rte_eth_dev_info_get(port_id, &dev_info);
3798         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3799                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3800                 printf("Warning: hardware IP checksum enabled but not "
3801                         "supported by port %d\n", port_id);
3802         }
3803         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3804                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3805                 printf("Warning: hardware UDP checksum enabled but not "
3806                         "supported by port %d\n", port_id);
3807         }
3808         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3809                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3810                 printf("Warning: hardware TCP checksum enabled but not "
3811                         "supported by port %d\n", port_id);
3812         }
3813         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3814                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3815                 printf("Warning: hardware SCTP checksum enabled but not "
3816                         "supported by port %d\n", port_id);
3817         }
3818         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3819                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3820                 printf("Warning: hardware outer IP checksum enabled but not "
3821                         "supported by port %d\n", port_id);
3822         }
3823 }
3824
3825 static void
3826 cmd_csum_parsed(void *parsed_result,
3827                        __attribute__((unused)) struct cmdline *cl,
3828                        __attribute__((unused)) void *data)
3829 {
3830         struct cmd_csum_result *res = parsed_result;
3831         int hw = 0;
3832         uint64_t csum_offloads = 0;
3833         struct rte_eth_dev_info dev_info;
3834
3835         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3836                 printf("invalid port %d\n", res->port_id);
3837                 return;
3838         }
3839         if (!port_is_stopped(res->port_id)) {
3840                 printf("Please stop port %d first\n", res->port_id);
3841                 return;
3842         }
3843
3844         rte_eth_dev_info_get(res->port_id, &dev_info);
3845         if (!strcmp(res->mode, "set")) {
3846
3847                 if (!strcmp(res->hwsw, "hw"))
3848                         hw = 1;
3849
3850                 if (!strcmp(res->proto, "ip")) {
3851                         if (hw == 0 || (dev_info.tx_offload_capa &
3852                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
3853                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3854                         } else {
3855                                 printf("IP checksum offload is not supported "
3856                                        "by port %u\n", res->port_id);
3857                         }
3858                 } else if (!strcmp(res->proto, "udp")) {
3859                         if (hw == 0 || (dev_info.tx_offload_capa &
3860                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
3861                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3862                         } else {
3863                                 printf("UDP checksum offload is not supported "
3864                                        "by port %u\n", res->port_id);
3865                         }
3866                 } else if (!strcmp(res->proto, "tcp")) {
3867                         if (hw == 0 || (dev_info.tx_offload_capa &
3868                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
3869                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3870                         } else {
3871                                 printf("TCP checksum offload is not supported "
3872                                        "by port %u\n", res->port_id);
3873                         }
3874                 } else if (!strcmp(res->proto, "sctp")) {
3875                         if (hw == 0 || (dev_info.tx_offload_capa &
3876                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
3877                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3878                         } else {
3879                                 printf("SCTP checksum offload is not supported "
3880                                        "by port %u\n", res->port_id);
3881                         }
3882                 } else if (!strcmp(res->proto, "outer-ip")) {
3883                         if (hw == 0 || (dev_info.tx_offload_capa &
3884                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
3885                                 csum_offloads |=
3886                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3887                         } else {
3888                                 printf("Outer IP checksum offload is not "
3889                                        "supported by port %u\n", res->port_id);
3890                         }
3891                 }
3892
3893                 if (hw) {
3894                         ports[res->port_id].dev_conf.txmode.offloads |=
3895                                                         csum_offloads;
3896                 } else {
3897                         ports[res->port_id].dev_conf.txmode.offloads &=
3898                                                         (~csum_offloads);
3899                 }
3900         }
3901         csum_show(res->port_id);
3902
3903         cmd_reconfig_device_queue(res->port_id, 1, 1);
3904 }
3905
3906 cmdline_parse_token_string_t cmd_csum_csum =
3907         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3908                                 csum, "csum");
3909 cmdline_parse_token_string_t cmd_csum_mode =
3910         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3911                                 mode, "set");
3912 cmdline_parse_token_string_t cmd_csum_proto =
3913         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3914                                 proto, "ip#tcp#udp#sctp#outer-ip");
3915 cmdline_parse_token_string_t cmd_csum_hwsw =
3916         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3917                                 hwsw, "hw#sw");
3918 cmdline_parse_token_num_t cmd_csum_portid =
3919         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3920                                 port_id, UINT16);
3921
3922 cmdline_parse_inst_t cmd_csum_set = {
3923         .f = cmd_csum_parsed,
3924         .data = NULL,
3925         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3926                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3927                 "using csum forward engine",
3928         .tokens = {
3929                 (void *)&cmd_csum_csum,
3930                 (void *)&cmd_csum_mode,
3931                 (void *)&cmd_csum_proto,
3932                 (void *)&cmd_csum_hwsw,
3933                 (void *)&cmd_csum_portid,
3934                 NULL,
3935         },
3936 };
3937
3938 cmdline_parse_token_string_t cmd_csum_mode_show =
3939         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3940                                 mode, "show");
3941
3942 cmdline_parse_inst_t cmd_csum_show = {
3943         .f = cmd_csum_parsed,
3944         .data = NULL,
3945         .help_str = "csum show <port_id>: Show checksum offload configuration",
3946         .tokens = {
3947                 (void *)&cmd_csum_csum,
3948                 (void *)&cmd_csum_mode_show,
3949                 (void *)&cmd_csum_portid,
3950                 NULL,
3951         },
3952 };
3953
3954 /* Enable/disable tunnel parsing */
3955 struct cmd_csum_tunnel_result {
3956         cmdline_fixed_string_t csum;
3957         cmdline_fixed_string_t parse;
3958         cmdline_fixed_string_t onoff;
3959         portid_t port_id;
3960 };
3961
3962 static void
3963 cmd_csum_tunnel_parsed(void *parsed_result,
3964                        __attribute__((unused)) struct cmdline *cl,
3965                        __attribute__((unused)) void *data)
3966 {
3967         struct cmd_csum_tunnel_result *res = parsed_result;
3968
3969         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3970                 return;
3971
3972         if (!strcmp(res->onoff, "on"))
3973                 ports[res->port_id].parse_tunnel = 1;
3974         else
3975                 ports[res->port_id].parse_tunnel = 0;
3976
3977         csum_show(res->port_id);
3978 }
3979
3980 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3981         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3982                                 csum, "csum");
3983 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3984         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3985                                 parse, "parse_tunnel");
3986 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3987         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3988                                 onoff, "on#off");
3989 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3990         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3991                                 port_id, UINT16);
3992
3993 cmdline_parse_inst_t cmd_csum_tunnel = {
3994         .f = cmd_csum_tunnel_parsed,
3995         .data = NULL,
3996         .help_str = "csum parse_tunnel on|off <port_id>: "
3997                 "Enable/Disable parsing of tunnels for csum engine",
3998         .tokens = {
3999                 (void *)&cmd_csum_tunnel_csum,
4000                 (void *)&cmd_csum_tunnel_parse,
4001                 (void *)&cmd_csum_tunnel_onoff,
4002                 (void *)&cmd_csum_tunnel_portid,
4003                 NULL,
4004         },
4005 };
4006
4007 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4008 struct cmd_tso_set_result {
4009         cmdline_fixed_string_t tso;
4010         cmdline_fixed_string_t mode;
4011         uint16_t tso_segsz;
4012         portid_t port_id;
4013 };
4014
4015 static void
4016 cmd_tso_set_parsed(void *parsed_result,
4017                        __attribute__((unused)) struct cmdline *cl,
4018                        __attribute__((unused)) void *data)
4019 {
4020         struct cmd_tso_set_result *res = parsed_result;
4021         struct rte_eth_dev_info dev_info;
4022
4023         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4024                 return;
4025         if (!port_is_stopped(res->port_id)) {
4026                 printf("Please stop port %d first\n", res->port_id);
4027                 return;
4028         }
4029
4030         if (!strcmp(res->mode, "set"))
4031                 ports[res->port_id].tso_segsz = res->tso_segsz;
4032
4033         rte_eth_dev_info_get(res->port_id, &dev_info);
4034         if ((ports[res->port_id].tso_segsz != 0) &&
4035                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4036                 printf("Error: TSO is not supported by port %d\n",
4037                        res->port_id);
4038                 return;
4039         }
4040
4041         if (ports[res->port_id].tso_segsz == 0) {
4042                 ports[res->port_id].dev_conf.txmode.offloads &=
4043                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4044                 printf("TSO for non-tunneled packets is disabled\n");
4045         } else {
4046                 ports[res->port_id].dev_conf.txmode.offloads |=
4047                                                 DEV_TX_OFFLOAD_TCP_TSO;
4048                 printf("TSO segment size for non-tunneled packets is %d\n",
4049                         ports[res->port_id].tso_segsz);
4050         }
4051
4052         /* display warnings if configuration is not supported by the NIC */
4053         rte_eth_dev_info_get(res->port_id, &dev_info);
4054         if ((ports[res->port_id].tso_segsz != 0) &&
4055                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4056                 printf("Warning: TSO enabled but not "
4057                         "supported by port %d\n", res->port_id);
4058         }
4059
4060         cmd_reconfig_device_queue(res->port_id, 1, 1);
4061 }
4062
4063 cmdline_parse_token_string_t cmd_tso_set_tso =
4064         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4065                                 tso, "tso");
4066 cmdline_parse_token_string_t cmd_tso_set_mode =
4067         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4068                                 mode, "set");
4069 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4070         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4071                                 tso_segsz, UINT16);
4072 cmdline_parse_token_num_t cmd_tso_set_portid =
4073         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4074                                 port_id, UINT16);
4075
4076 cmdline_parse_inst_t cmd_tso_set = {
4077         .f = cmd_tso_set_parsed,
4078         .data = NULL,
4079         .help_str = "tso set <tso_segsz> <port_id>: "
4080                 "Set TSO segment size of non-tunneled packets for csum engine "
4081                 "(0 to disable)",
4082         .tokens = {
4083                 (void *)&cmd_tso_set_tso,
4084                 (void *)&cmd_tso_set_mode,
4085                 (void *)&cmd_tso_set_tso_segsz,
4086                 (void *)&cmd_tso_set_portid,
4087                 NULL,
4088         },
4089 };
4090
4091 cmdline_parse_token_string_t cmd_tso_show_mode =
4092         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4093                                 mode, "show");
4094
4095
4096 cmdline_parse_inst_t cmd_tso_show = {
4097         .f = cmd_tso_set_parsed,
4098         .data = NULL,
4099         .help_str = "tso show <port_id>: "
4100                 "Show TSO segment size of non-tunneled packets for csum engine",
4101         .tokens = {
4102                 (void *)&cmd_tso_set_tso,
4103                 (void *)&cmd_tso_show_mode,
4104                 (void *)&cmd_tso_set_portid,
4105                 NULL,
4106         },
4107 };
4108
4109 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4110 struct cmd_tunnel_tso_set_result {
4111         cmdline_fixed_string_t tso;
4112         cmdline_fixed_string_t mode;
4113         uint16_t tso_segsz;
4114         portid_t port_id;
4115 };
4116
4117 static struct rte_eth_dev_info
4118 check_tunnel_tso_nic_support(portid_t port_id)
4119 {
4120         struct rte_eth_dev_info dev_info;
4121
4122         rte_eth_dev_info_get(port_id, &dev_info);
4123         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4124                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4125                        "not enabled for port %d\n", port_id);
4126         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4127                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4128                        "not enabled for port %d\n", port_id);
4129         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4130                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4131                        "not enabled for port %d\n", port_id);
4132         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4133                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4134                        "not enabled for port %d\n", port_id);
4135         return dev_info;
4136 }
4137
4138 static void
4139 cmd_tunnel_tso_set_parsed(void *parsed_result,
4140                           __attribute__((unused)) struct cmdline *cl,
4141                           __attribute__((unused)) void *data)
4142 {
4143         struct cmd_tunnel_tso_set_result *res = parsed_result;
4144         struct rte_eth_dev_info dev_info;
4145
4146         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4147                 return;
4148         if (!port_is_stopped(res->port_id)) {
4149                 printf("Please stop port %d first\n", res->port_id);
4150                 return;
4151         }
4152
4153         if (!strcmp(res->mode, "set"))
4154                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4155
4156         dev_info = check_tunnel_tso_nic_support(res->port_id);
4157         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4158                 ports[res->port_id].dev_conf.txmode.offloads &=
4159                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4160                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4161                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4162                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4163                 printf("TSO for tunneled packets is disabled\n");
4164         } else {
4165                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4166                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4167                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4168                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4169
4170                 ports[res->port_id].dev_conf.txmode.offloads |=
4171                         (tso_offloads & dev_info.tx_offload_capa);
4172                 printf("TSO segment size for tunneled packets is %d\n",
4173                         ports[res->port_id].tunnel_tso_segsz);
4174
4175                 /* Below conditions are needed to make it work:
4176                  * (1) tunnel TSO is supported by the NIC;
4177                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4178                  * are recognized;
4179                  * (3) for tunneled pkts with outer L3 of IPv4,
4180                  * "csum set outer-ip" must be set to hw, because after tso,
4181                  * total_len of outer IP header is changed, and the checksum
4182                  * of outer IP header calculated by sw should be wrong; that
4183                  * is not necessary for IPv6 tunneled pkts because there's no
4184                  * checksum in IP header anymore.
4185                  */
4186
4187                 if (!ports[res->port_id].parse_tunnel)
4188                         printf("Warning: csum parse_tunnel must be set "
4189                                 "so that tunneled packets are recognized\n");
4190                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4191                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4192                         printf("Warning: csum set outer-ip must be set to hw "
4193                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4194         }
4195
4196         cmd_reconfig_device_queue(res->port_id, 1, 1);
4197 }
4198
4199 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4200         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4201                                 tso, "tunnel_tso");
4202 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4203         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4204                                 mode, "set");
4205 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4206         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4207                                 tso_segsz, UINT16);
4208 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4209         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4210                                 port_id, UINT16);
4211
4212 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4213         .f = cmd_tunnel_tso_set_parsed,
4214         .data = NULL,
4215         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4216                 "Set TSO segment size of tunneled packets for csum engine "
4217                 "(0 to disable)",
4218         .tokens = {
4219                 (void *)&cmd_tunnel_tso_set_tso,
4220                 (void *)&cmd_tunnel_tso_set_mode,
4221                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4222                 (void *)&cmd_tunnel_tso_set_portid,
4223                 NULL,
4224         },
4225 };
4226
4227 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4228         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4229                                 mode, "show");
4230
4231
4232 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4233         .f = cmd_tunnel_tso_set_parsed,
4234         .data = NULL,
4235         .help_str = "tunnel_tso show <port_id> "
4236                 "Show TSO segment size of tunneled packets for csum engine",
4237         .tokens = {
4238                 (void *)&cmd_tunnel_tso_set_tso,
4239                 (void *)&cmd_tunnel_tso_show_mode,
4240                 (void *)&cmd_tunnel_tso_set_portid,
4241                 NULL,
4242         },
4243 };
4244
4245 /* *** SET GRO FOR A PORT *** */
4246 struct cmd_gro_enable_result {
4247         cmdline_fixed_string_t cmd_set;
4248         cmdline_fixed_string_t cmd_port;
4249         cmdline_fixed_string_t cmd_keyword;
4250         cmdline_fixed_string_t cmd_onoff;
4251         portid_t cmd_pid;
4252 };
4253
4254 static void
4255 cmd_gro_enable_parsed(void *parsed_result,
4256                 __attribute__((unused)) struct cmdline *cl,
4257                 __attribute__((unused)) void *data)
4258 {
4259         struct cmd_gro_enable_result *res;
4260
4261         res = parsed_result;
4262         if (!strcmp(res->cmd_keyword, "gro"))
4263                 setup_gro(res->cmd_onoff, res->cmd_pid);
4264 }
4265
4266 cmdline_parse_token_string_t cmd_gro_enable_set =
4267         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4268                         cmd_set, "set");
4269 cmdline_parse_token_string_t cmd_gro_enable_port =
4270         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4271                         cmd_keyword, "port");
4272 cmdline_parse_token_num_t cmd_gro_enable_pid =
4273         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4274                         cmd_pid, UINT16);
4275 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4276         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4277                         cmd_keyword, "gro");
4278 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4279         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4280                         cmd_onoff, "on#off");
4281
4282 cmdline_parse_inst_t cmd_gro_enable = {
4283         .f = cmd_gro_enable_parsed,
4284         .data = NULL,
4285         .help_str = "set port <port_id> gro on|off",
4286         .tokens = {
4287                 (void *)&cmd_gro_enable_set,
4288                 (void *)&cmd_gro_enable_port,
4289                 (void *)&cmd_gro_enable_pid,
4290                 (void *)&cmd_gro_enable_keyword,
4291                 (void *)&cmd_gro_enable_onoff,
4292                 NULL,
4293         },
4294 };
4295
4296 /* *** DISPLAY GRO CONFIGURATION *** */
4297 struct cmd_gro_show_result {
4298         cmdline_fixed_string_t cmd_show;
4299         cmdline_fixed_string_t cmd_port;
4300         cmdline_fixed_string_t cmd_keyword;
4301         portid_t cmd_pid;
4302 };
4303
4304 static void
4305 cmd_gro_show_parsed(void *parsed_result,
4306                 __attribute__((unused)) struct cmdline *cl,
4307                 __attribute__((unused)) void *data)
4308 {
4309         struct cmd_gro_show_result *res;
4310
4311         res = parsed_result;
4312         if (!strcmp(res->cmd_keyword, "gro"))
4313                 show_gro(res->cmd_pid);
4314 }
4315
4316 cmdline_parse_token_string_t cmd_gro_show_show =
4317         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4318                         cmd_show, "show");
4319 cmdline_parse_token_string_t cmd_gro_show_port =
4320         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4321                         cmd_port, "port");
4322 cmdline_parse_token_num_t cmd_gro_show_pid =
4323         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4324                         cmd_pid, UINT16);
4325 cmdline_parse_token_string_t cmd_gro_show_keyword =
4326         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4327                         cmd_keyword, "gro");
4328
4329 cmdline_parse_inst_t cmd_gro_show = {
4330         .f = cmd_gro_show_parsed,
4331         .data = NULL,
4332         .help_str = "show port <port_id> gro",
4333         .tokens = {
4334                 (void *)&cmd_gro_show_show,
4335                 (void *)&cmd_gro_show_port,
4336                 (void *)&cmd_gro_show_pid,
4337                 (void *)&cmd_gro_show_keyword,
4338                 NULL,
4339         },
4340 };
4341
4342 /* *** SET FLUSH CYCLES FOR GRO *** */
4343 struct cmd_gro_flush_result {
4344         cmdline_fixed_string_t cmd_set;
4345         cmdline_fixed_string_t cmd_keyword;
4346         cmdline_fixed_string_t cmd_flush;
4347         uint8_t cmd_cycles;
4348 };
4349
4350 static void
4351 cmd_gro_flush_parsed(void *parsed_result,
4352                 __attribute__((unused)) struct cmdline *cl,
4353                 __attribute__((unused)) void *data)
4354 {
4355         struct cmd_gro_flush_result *res;
4356
4357         res = parsed_result;
4358         if ((!strcmp(res->cmd_keyword, "gro")) &&
4359                         (!strcmp(res->cmd_flush, "flush")))
4360                 setup_gro_flush_cycles(res->cmd_cycles);
4361 }
4362
4363 cmdline_parse_token_string_t cmd_gro_flush_set =
4364         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4365                         cmd_set, "set");
4366 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4367         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4368                         cmd_keyword, "gro");
4369 cmdline_parse_token_string_t cmd_gro_flush_flush =
4370         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4371                         cmd_flush, "flush");
4372 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4373         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4374                         cmd_cycles, UINT8);
4375
4376 cmdline_parse_inst_t cmd_gro_flush = {
4377         .f = cmd_gro_flush_parsed,
4378         .data = NULL,
4379         .help_str = "set gro flush <cycles>",
4380         .tokens = {
4381                 (void *)&cmd_gro_flush_set,
4382                 (void *)&cmd_gro_flush_keyword,
4383                 (void *)&cmd_gro_flush_flush,
4384                 (void *)&cmd_gro_flush_cycles,
4385                 NULL,
4386         },
4387 };
4388
4389 /* *** ENABLE/DISABLE GSO *** */
4390 struct cmd_gso_enable_result {
4391         cmdline_fixed_string_t cmd_set;
4392         cmdline_fixed_string_t cmd_port;
4393         cmdline_fixed_string_t cmd_keyword;
4394         cmdline_fixed_string_t cmd_mode;
4395         portid_t cmd_pid;
4396 };
4397
4398 static void
4399 cmd_gso_enable_parsed(void *parsed_result,
4400                 __attribute__((unused)) struct cmdline *cl,
4401                 __attribute__((unused)) void *data)
4402 {
4403         struct cmd_gso_enable_result *res;
4404
4405         res = parsed_result;
4406         if (!strcmp(res->cmd_keyword, "gso"))
4407                 setup_gso(res->cmd_mode, res->cmd_pid);
4408 }
4409
4410 cmdline_parse_token_string_t cmd_gso_enable_set =
4411         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4412                         cmd_set, "set");
4413 cmdline_parse_token_string_t cmd_gso_enable_port =
4414         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4415                         cmd_port, "port");
4416 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4417         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4418                         cmd_keyword, "gso");
4419 cmdline_parse_token_string_t cmd_gso_enable_mode =
4420         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4421                         cmd_mode, "on#off");
4422 cmdline_parse_token_num_t cmd_gso_enable_pid =
4423         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4424                         cmd_pid, UINT16);
4425
4426 cmdline_parse_inst_t cmd_gso_enable = {
4427         .f = cmd_gso_enable_parsed,
4428         .data = NULL,
4429         .help_str = "set port <port_id> gso on|off",
4430         .tokens = {
4431                 (void *)&cmd_gso_enable_set,
4432                 (void *)&cmd_gso_enable_port,
4433                 (void *)&cmd_gso_enable_pid,
4434                 (void *)&cmd_gso_enable_keyword,
4435                 (void *)&cmd_gso_enable_mode,
4436                 NULL,
4437         },
4438 };
4439
4440 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4441 struct cmd_gso_size_result {
4442         cmdline_fixed_string_t cmd_set;
4443         cmdline_fixed_string_t cmd_keyword;
4444         cmdline_fixed_string_t cmd_segsz;
4445         uint16_t cmd_size;
4446 };
4447
4448 static void
4449 cmd_gso_size_parsed(void *parsed_result,
4450                        __attribute__((unused)) struct cmdline *cl,
4451                        __attribute__((unused)) void *data)
4452 {
4453         struct cmd_gso_size_result *res = parsed_result;
4454
4455         if (test_done == 0) {
4456                 printf("Before setting GSO segsz, please first"
4457                                 " stop fowarding\n");
4458                 return;
4459         }
4460
4461         if (!strcmp(res->cmd_keyword, "gso") &&
4462                         !strcmp(res->cmd_segsz, "segsz")) {
4463                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4464                         printf("gso_size should be larger than %zu."
4465                                         " Please input a legal value\n",
4466                                         RTE_GSO_SEG_SIZE_MIN);
4467                 else
4468                         gso_max_segment_size = res->cmd_size;
4469         }
4470 }
4471
4472 cmdline_parse_token_string_t cmd_gso_size_set =
4473         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4474                                 cmd_set, "set");
4475 cmdline_parse_token_string_t cmd_gso_size_keyword =
4476         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4477                                 cmd_keyword, "gso");
4478 cmdline_parse_token_string_t cmd_gso_size_segsz =
4479         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4480                                 cmd_segsz, "segsz");
4481 cmdline_parse_token_num_t cmd_gso_size_size =
4482         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4483                                 cmd_size, UINT16);
4484
4485 cmdline_parse_inst_t cmd_gso_size = {
4486         .f = cmd_gso_size_parsed,
4487         .data = NULL,
4488         .help_str = "set gso segsz <length>",
4489         .tokens = {
4490                 (void *)&cmd_gso_size_set,
4491                 (void *)&cmd_gso_size_keyword,
4492                 (void *)&cmd_gso_size_segsz,
4493                 (void *)&cmd_gso_size_size,
4494                 NULL,
4495         },
4496 };
4497
4498 /* *** SHOW GSO CONFIGURATION *** */
4499 struct cmd_gso_show_result {
4500         cmdline_fixed_string_t cmd_show;
4501         cmdline_fixed_string_t cmd_port;
4502         cmdline_fixed_string_t cmd_keyword;
4503         portid_t cmd_pid;
4504 };
4505
4506 static void
4507 cmd_gso_show_parsed(void *parsed_result,
4508                        __attribute__((unused)) struct cmdline *cl,
4509                        __attribute__((unused)) void *data)
4510 {
4511         struct cmd_gso_show_result *res = parsed_result;
4512
4513         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4514                 printf("invalid port id %u\n", res->cmd_pid);
4515                 return;
4516         }
4517         if (!strcmp(res->cmd_keyword, "gso")) {
4518                 if (gso_ports[res->cmd_pid].enable) {
4519                         printf("Max GSO'd packet size: %uB\n"
4520                                         "Supported GSO types: TCP/IPv4, "
4521                                         "VxLAN with inner TCP/IPv4 packet, "
4522                                         "GRE with inner TCP/IPv4  packet\n",
4523                                         gso_max_segment_size);
4524                 } else
4525                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4526         }
4527 }
4528
4529 cmdline_parse_token_string_t cmd_gso_show_show =
4530 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4531                 cmd_show, "show");
4532 cmdline_parse_token_string_t cmd_gso_show_port =
4533 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4534                 cmd_port, "port");
4535 cmdline_parse_token_string_t cmd_gso_show_keyword =
4536         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4537                                 cmd_keyword, "gso");
4538 cmdline_parse_token_num_t cmd_gso_show_pid =
4539         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4540                                 cmd_pid, UINT16);
4541
4542 cmdline_parse_inst_t cmd_gso_show = {
4543         .f = cmd_gso_show_parsed,
4544         .data = NULL,
4545         .help_str = "show port <port_id> gso",
4546         .tokens = {
4547                 (void *)&cmd_gso_show_show,
4548                 (void *)&cmd_gso_show_port,
4549                 (void *)&cmd_gso_show_pid,
4550                 (void *)&cmd_gso_show_keyword,
4551                 NULL,
4552         },
4553 };
4554
4555 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4556 struct cmd_set_flush_rx {
4557         cmdline_fixed_string_t set;
4558         cmdline_fixed_string_t flush_rx;
4559         cmdline_fixed_string_t mode;
4560 };
4561
4562 static void
4563 cmd_set_flush_rx_parsed(void *parsed_result,
4564                 __attribute__((unused)) struct cmdline *cl,
4565                 __attribute__((unused)) void *data)
4566 {
4567         struct cmd_set_flush_rx *res = parsed_result;
4568         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4569 }
4570
4571 cmdline_parse_token_string_t cmd_setflushrx_set =
4572         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4573                         set, "set");
4574 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4575         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4576                         flush_rx, "flush_rx");
4577 cmdline_parse_token_string_t cmd_setflushrx_mode =
4578         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4579                         mode, "on#off");
4580
4581
4582 cmdline_parse_inst_t cmd_set_flush_rx = {
4583         .f = cmd_set_flush_rx_parsed,
4584         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4585         .data = NULL,
4586         .tokens = {
4587                 (void *)&cmd_setflushrx_set,
4588                 (void *)&cmd_setflushrx_flush_rx,
4589                 (void *)&cmd_setflushrx_mode,
4590                 NULL,
4591         },
4592 };
4593
4594 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4595 struct cmd_set_link_check {
4596         cmdline_fixed_string_t set;
4597         cmdline_fixed_string_t link_check;
4598         cmdline_fixed_string_t mode;
4599 };
4600
4601 static void
4602 cmd_set_link_check_parsed(void *parsed_result,
4603                 __attribute__((unused)) struct cmdline *cl,
4604                 __attribute__((unused)) void *data)
4605 {
4606         struct cmd_set_link_check *res = parsed_result;
4607         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4608 }
4609
4610 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4611         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4612                         set, "set");
4613 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4614         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4615                         link_check, "link_check");
4616 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4617         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4618                         mode, "on#off");
4619
4620
4621 cmdline_parse_inst_t cmd_set_link_check = {
4622         .f = cmd_set_link_check_parsed,
4623         .help_str = "set link_check on|off: Enable/Disable link status check "
4624                     "when starting/stopping a port",
4625         .data = NULL,
4626         .tokens = {
4627                 (void *)&cmd_setlinkcheck_set,
4628                 (void *)&cmd_setlinkcheck_link_check,
4629                 (void *)&cmd_setlinkcheck_mode,
4630                 NULL,
4631         },
4632 };
4633
4634 /* *** SET NIC BYPASS MODE *** */
4635 struct cmd_set_bypass_mode_result {
4636         cmdline_fixed_string_t set;
4637         cmdline_fixed_string_t bypass;
4638         cmdline_fixed_string_t mode;
4639         cmdline_fixed_string_t value;
4640         portid_t port_id;
4641 };
4642
4643 static void
4644 cmd_set_bypass_mode_parsed(void *parsed_result,
4645                 __attribute__((unused)) struct cmdline *cl,
4646                 __attribute__((unused)) void *data)
4647 {
4648         struct cmd_set_bypass_mode_result *res = parsed_result;
4649         portid_t port_id = res->port_id;
4650         int32_t rc = -EINVAL;
4651
4652 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4653         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4654
4655         if (!strcmp(res->value, "bypass"))
4656                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4657         else if (!strcmp(res->value, "isolate"))
4658                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4659         else
4660                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4661
4662         /* Set the bypass mode for the relevant port. */
4663         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4664 #endif
4665         if (rc != 0)
4666                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4667 }
4668
4669 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4670         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4671                         set, "set");
4672 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4673         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4674                         bypass, "bypass");
4675 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4676         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4677                         mode, "mode");
4678 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4679         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4680                         value, "normal#bypass#isolate");
4681 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4682         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4683                                 port_id, UINT16);
4684
4685 cmdline_parse_inst_t cmd_set_bypass_mode = {
4686         .f = cmd_set_bypass_mode_parsed,
4687         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4688                     "Set the NIC bypass mode for port_id",
4689         .data = NULL,
4690         .tokens = {
4691                 (void *)&cmd_setbypass_mode_set,
4692                 (void *)&cmd_setbypass_mode_bypass,
4693                 (void *)&cmd_setbypass_mode_mode,
4694                 (void *)&cmd_setbypass_mode_value,
4695                 (void *)&cmd_setbypass_mode_port,
4696                 NULL,
4697         },
4698 };
4699
4700 /* *** SET NIC BYPASS EVENT *** */
4701 struct cmd_set_bypass_event_result {
4702         cmdline_fixed_string_t set;
4703         cmdline_fixed_string_t bypass;
4704         cmdline_fixed_string_t event;
4705         cmdline_fixed_string_t event_value;
4706         cmdline_fixed_string_t mode;
4707         cmdline_fixed_string_t mode_value;
4708         portid_t port_id;
4709 };
4710
4711 static void
4712 cmd_set_bypass_event_parsed(void *parsed_result,
4713                 __attribute__((unused)) struct cmdline *cl,
4714                 __attribute__((unused)) void *data)
4715 {
4716         int32_t rc = -EINVAL;
4717         struct cmd_set_bypass_event_result *res = parsed_result;
4718         portid_t port_id = res->port_id;
4719
4720 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4721         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4722         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4723
4724         if (!strcmp(res->event_value, "timeout"))
4725                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4726         else if (!strcmp(res->event_value, "os_on"))
4727                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4728         else if (!strcmp(res->event_value, "os_off"))
4729                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4730         else if (!strcmp(res->event_value, "power_on"))
4731                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4732         else if (!strcmp(res->event_value, "power_off"))
4733                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4734         else
4735                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4736
4737         if (!strcmp(res->mode_value, "bypass"))
4738                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4739         else if (!strcmp(res->mode_value, "isolate"))
4740                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4741         else
4742                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4743
4744         /* Set the watchdog timeout. */
4745         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4746
4747                 rc = -EINVAL;
4748                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4749                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4750                                                            bypass_timeout);
4751                 }
4752                 if (rc != 0) {
4753                         printf("Failed to set timeout value %u "
4754                         "for port %d, errto code: %d.\n",
4755                         bypass_timeout, port_id, rc);
4756                 }
4757         }
4758
4759         /* Set the bypass event to transition to bypass mode. */
4760         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4761                                               bypass_mode);
4762 #endif
4763
4764         if (rc != 0)
4765                 printf("\t Failed to set bypass event for port = %d.\n",
4766                        port_id);
4767 }
4768
4769 cmdline_parse_token_string_t cmd_setbypass_event_set =
4770         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4771                         set, "set");
4772 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4773         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4774                         bypass, "bypass");
4775 cmdline_parse_token_string_t cmd_setbypass_event_event =
4776         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4777                         event, "event");
4778 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4779         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4780                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4781 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4782         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4783                         mode, "mode");
4784 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4785         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4786                         mode_value, "normal#bypass#isolate");
4787 cmdline_parse_token_num_t cmd_setbypass_event_port =
4788         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4789                                 port_id, UINT16);
4790
4791 cmdline_parse_inst_t cmd_set_bypass_event = {
4792         .f = cmd_set_bypass_event_parsed,
4793         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4794                 "power_off mode normal|bypass|isolate <port_id>: "
4795                 "Set the NIC bypass event mode for port_id",
4796         .data = NULL,
4797         .tokens = {
4798                 (void *)&cmd_setbypass_event_set,
4799                 (void *)&cmd_setbypass_event_bypass,
4800                 (void *)&cmd_setbypass_event_event,
4801                 (void *)&cmd_setbypass_event_event_value,
4802                 (void *)&cmd_setbypass_event_mode,
4803                 (void *)&cmd_setbypass_event_mode_value,
4804                 (void *)&cmd_setbypass_event_port,
4805                 NULL,
4806         },
4807 };
4808
4809
4810 /* *** SET NIC BYPASS TIMEOUT *** */
4811 struct cmd_set_bypass_timeout_result {
4812         cmdline_fixed_string_t set;
4813         cmdline_fixed_string_t bypass;
4814         cmdline_fixed_string_t timeout;
4815         cmdline_fixed_string_t value;
4816 };
4817
4818 static void
4819 cmd_set_bypass_timeout_parsed(void *parsed_result,
4820                 __attribute__((unused)) struct cmdline *cl,
4821                 __attribute__((unused)) void *data)
4822 {
4823         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4824
4825 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4826         if (!strcmp(res->value, "1.5"))
4827                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4828         else if (!strcmp(res->value, "2"))
4829                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4830         else if (!strcmp(res->value, "3"))
4831                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4832         else if (!strcmp(res->value, "4"))
4833                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4834         else if (!strcmp(res->value, "8"))
4835                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4836         else if (!strcmp(res->value, "16"))
4837                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4838         else if (!strcmp(res->value, "32"))
4839                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4840         else
4841                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4842 #endif
4843 }
4844
4845 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4846         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4847                         set, "set");
4848 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4849         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4850                         bypass, "bypass");
4851 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4852         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4853                         timeout, "timeout");
4854 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4855         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4856                         value, "0#1.5#2#3#4#8#16#32");
4857
4858 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4859         .f = cmd_set_bypass_timeout_parsed,
4860         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4861                 "Set the NIC bypass watchdog timeout in seconds",
4862         .data = NULL,
4863         .tokens = {
4864                 (void *)&cmd_setbypass_timeout_set,
4865                 (void *)&cmd_setbypass_timeout_bypass,
4866                 (void *)&cmd_setbypass_timeout_timeout,
4867                 (void *)&cmd_setbypass_timeout_value,
4868                 NULL,
4869         },
4870 };
4871
4872 /* *** SHOW NIC BYPASS MODE *** */
4873 struct cmd_show_bypass_config_result {
4874         cmdline_fixed_string_t show;
4875         cmdline_fixed_string_t bypass;
4876         cmdline_fixed_string_t config;
4877         portid_t port_id;
4878 };
4879
4880 static void
4881 cmd_show_bypass_config_parsed(void *parsed_result,
4882                 __attribute__((unused)) struct cmdline *cl,
4883                 __attribute__((unused)) void *data)
4884 {
4885         struct cmd_show_bypass_config_result *res = parsed_result;
4886         portid_t port_id = res->port_id;
4887         int rc = -EINVAL;
4888 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4889         uint32_t event_mode;
4890         uint32_t bypass_mode;
4891         uint32_t timeout = bypass_timeout;
4892         int i;
4893
4894         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4895                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4896         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4897                 {"UNKNOWN", "normal", "bypass", "isolate"};
4898         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4899                 "NONE",
4900                 "OS/board on",
4901                 "power supply on",
4902                 "OS/board off",
4903                 "power supply off",
4904                 "timeout"};
4905         int num_events = (sizeof events) / (sizeof events[0]);
4906
4907         /* Display the bypass mode.*/
4908         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4909                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4910                 return;
4911         }
4912         else {
4913                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4914                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4915
4916                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4917         }
4918
4919         /* Display the bypass timeout.*/
4920         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4921                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4922
4923         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4924
4925         /* Display the bypass events and associated modes. */
4926         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4927
4928                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4929                         printf("\tFailed to get bypass mode for event = %s\n",
4930                                 events[i]);
4931                 } else {
4932                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4933                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4934
4935                         printf("\tbypass event: %-16s = %s\n", events[i],
4936                                 modes[event_mode]);
4937                 }
4938         }
4939 #endif
4940         if (rc != 0)
4941                 printf("\tFailed to get bypass configuration for port = %d\n",
4942                        port_id);
4943 }
4944
4945 cmdline_parse_token_string_t cmd_showbypass_config_show =
4946         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4947                         show, "show");
4948 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4949         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4950                         bypass, "bypass");
4951 cmdline_parse_token_string_t cmd_showbypass_config_config =
4952         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4953                         config, "config");
4954 cmdline_parse_token_num_t cmd_showbypass_config_port =
4955         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4956                                 port_id, UINT16);
4957
4958 cmdline_parse_inst_t cmd_show_bypass_config = {
4959         .f = cmd_show_bypass_config_parsed,
4960         .help_str = "show bypass config <port_id>: "
4961                     "Show the NIC bypass config for port_id",
4962         .data = NULL,
4963         .tokens = {
4964                 (void *)&cmd_showbypass_config_show,
4965                 (void *)&cmd_showbypass_config_bypass,
4966                 (void *)&cmd_showbypass_config_config,
4967                 (void *)&cmd_showbypass_config_port,
4968                 NULL,
4969         },
4970 };
4971
4972 #ifdef RTE_LIBRTE_PMD_BOND
4973 /* *** SET BONDING MODE *** */
4974 struct cmd_set_bonding_mode_result {
4975         cmdline_fixed_string_t set;
4976         cmdline_fixed_string_t bonding;
4977         cmdline_fixed_string_t mode;
4978         uint8_t value;
4979         portid_t port_id;
4980 };
4981
4982 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4983                 __attribute__((unused))  struct cmdline *cl,
4984                 __attribute__((unused)) void *data)
4985 {
4986         struct cmd_set_bonding_mode_result *res = parsed_result;
4987         portid_t port_id = res->port_id;
4988
4989         /* Set the bonding mode for the relevant port. */
4990         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4991                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4992 }
4993
4994 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4995 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4996                 set, "set");
4997 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4998 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4999                 bonding, "bonding");
5000 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5001 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5002                 mode, "mode");
5003 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5004 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5005                 value, UINT8);
5006 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5007 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5008                 port_id, UINT16);
5009
5010 cmdline_parse_inst_t cmd_set_bonding_mode = {
5011                 .f = cmd_set_bonding_mode_parsed,
5012                 .help_str = "set bonding mode <mode_value> <port_id>: "
5013                         "Set the bonding mode for port_id",
5014                 .data = NULL,
5015                 .tokens = {
5016                                 (void *) &cmd_setbonding_mode_set,
5017                                 (void *) &cmd_setbonding_mode_bonding,
5018                                 (void *) &cmd_setbonding_mode_mode,
5019                                 (void *) &cmd_setbonding_mode_value,
5020                                 (void *) &cmd_setbonding_mode_port,
5021                                 NULL
5022                 }
5023 };
5024
5025 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5026 struct cmd_set_bonding_lacp_dedicated_queues_result {
5027         cmdline_fixed_string_t set;
5028         cmdline_fixed_string_t bonding;
5029         cmdline_fixed_string_t lacp;
5030         cmdline_fixed_string_t dedicated_queues;
5031         portid_t port_id;
5032         cmdline_fixed_string_t mode;
5033 };
5034
5035 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5036                 __attribute__((unused))  struct cmdline *cl,
5037                 __attribute__((unused)) void *data)
5038 {
5039         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5040         portid_t port_id = res->port_id;
5041         struct rte_port *port;
5042
5043         port = &ports[port_id];
5044
5045         /** Check if the port is not started **/
5046         if (port->port_status != RTE_PORT_STOPPED) {
5047                 printf("Please stop port %d first\n", port_id);
5048                 return;
5049         }
5050
5051         if (!strcmp(res->mode, "enable")) {
5052                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5053                         printf("Dedicate queues for LACP control packets"
5054                                         " enabled\n");
5055                 else
5056                         printf("Enabling dedicate queues for LACP control "
5057                                         "packets on port %d failed\n", port_id);
5058         } else if (!strcmp(res->mode, "disable")) {
5059                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5060                         printf("Dedicated queues for LACP control packets "
5061                                         "disabled\n");
5062                 else
5063                         printf("Disabling dedicated queues for LACP control "
5064                                         "traffic on port %d failed\n", port_id);
5065         }
5066 }
5067
5068 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5069 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5070                 set, "set");
5071 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5072 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5073                 bonding, "bonding");
5074 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5075 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5076                 lacp, "lacp");
5077 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5078 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5079                 dedicated_queues, "dedicated_queues");
5080 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5081 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5082                 port_id, UINT16);
5083 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5084 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5085                 mode, "enable#disable");
5086
5087 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5088                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5089                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5090                         "enable|disable: "
5091                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5092                 .data = NULL,
5093                 .tokens = {
5094                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5095                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5096                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5097                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5098                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5099                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5100                         NULL
5101                 }
5102 };
5103
5104 /* *** SET BALANCE XMIT POLICY *** */
5105 struct cmd_set_bonding_balance_xmit_policy_result {
5106         cmdline_fixed_string_t set;
5107         cmdline_fixed_string_t bonding;
5108         cmdline_fixed_string_t balance_xmit_policy;
5109         portid_t port_id;
5110         cmdline_fixed_string_t policy;
5111 };
5112
5113 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5114                 __attribute__((unused))  struct cmdline *cl,
5115                 __attribute__((unused)) void *data)
5116 {
5117         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5118         portid_t port_id = res->port_id;
5119         uint8_t policy;
5120
5121         if (!strcmp(res->policy, "l2")) {
5122                 policy = BALANCE_XMIT_POLICY_LAYER2;
5123         } else if (!strcmp(res->policy, "l23")) {
5124                 policy = BALANCE_XMIT_POLICY_LAYER23;
5125         } else if (!strcmp(res->policy, "l34")) {
5126                 policy = BALANCE_XMIT_POLICY_LAYER34;
5127         } else {
5128                 printf("\t Invalid xmit policy selection");
5129                 return;
5130         }
5131
5132         /* Set the bonding mode for the relevant port. */
5133         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5134                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5135                                 port_id);
5136         }
5137 }
5138
5139 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5140 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5141                 set, "set");
5142 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5143 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5144                 bonding, "bonding");
5145 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5146 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5147                 balance_xmit_policy, "balance_xmit_policy");
5148 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5149 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5150                 port_id, UINT16);
5151 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5152 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5153                 policy, "l2#l23#l34");
5154
5155 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5156                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5157                 .help_str = "set bonding balance_xmit_policy <port_id> "
5158                         "l2|l23|l34: "
5159                         "Set the bonding balance_xmit_policy for port_id",
5160                 .data = NULL,
5161                 .tokens = {
5162                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5163                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5164                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5165                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5166                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5167                                 NULL
5168                 }
5169 };
5170
5171 /* *** SHOW NIC BONDING CONFIGURATION *** */
5172 struct cmd_show_bonding_config_result {
5173         cmdline_fixed_string_t show;
5174         cmdline_fixed_string_t bonding;
5175         cmdline_fixed_string_t config;
5176         portid_t port_id;
5177 };
5178
5179 static void cmd_show_bonding_config_parsed(void *parsed_result,
5180                 __attribute__((unused))  struct cmdline *cl,
5181                 __attribute__((unused)) void *data)
5182 {
5183         struct cmd_show_bonding_config_result *res = parsed_result;
5184         int bonding_mode, agg_mode;
5185         portid_t slaves[RTE_MAX_ETHPORTS];
5186         int num_slaves, num_active_slaves;
5187         int primary_id;
5188         int i;
5189         portid_t port_id = res->port_id;
5190
5191         /* Display the bonding mode.*/
5192         bonding_mode = rte_eth_bond_mode_get(port_id);
5193         if (bonding_mode < 0) {
5194                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5195                 return;
5196         } else
5197                 printf("\tBonding mode: %d\n", bonding_mode);
5198
5199         if (bonding_mode == BONDING_MODE_BALANCE) {
5200                 int balance_xmit_policy;
5201
5202                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5203                 if (balance_xmit_policy < 0) {
5204                         printf("\tFailed to get balance xmit policy for port = %d\n",
5205                                         port_id);
5206                         return;
5207                 } else {
5208                         printf("\tBalance Xmit Policy: ");
5209
5210                         switch (balance_xmit_policy) {
5211                         case BALANCE_XMIT_POLICY_LAYER2:
5212                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5213                                 break;
5214                         case BALANCE_XMIT_POLICY_LAYER23:
5215                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5216                                 break;
5217                         case BALANCE_XMIT_POLICY_LAYER34:
5218                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5219                                 break;
5220                         }
5221                         printf("\n");
5222                 }
5223         }
5224
5225         if (bonding_mode == BONDING_MODE_8023AD) {
5226                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5227                 printf("\tIEEE802.3AD Aggregator Mode: ");
5228                 switch (agg_mode) {
5229                 case AGG_BANDWIDTH:
5230                         printf("bandwidth");
5231                         break;
5232                 case AGG_STABLE:
5233                         printf("stable");
5234                         break;
5235                 case AGG_COUNT:
5236                         printf("count");
5237                         break;
5238                 }
5239                 printf("\n");
5240         }
5241
5242         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5243
5244         if (num_slaves < 0) {
5245                 printf("\tFailed to get slave list for port = %d\n", port_id);
5246                 return;
5247         }
5248         if (num_slaves > 0) {
5249                 printf("\tSlaves (%d): [", num_slaves);
5250                 for (i = 0; i < num_slaves - 1; i++)
5251                         printf("%d ", slaves[i]);
5252
5253                 printf("%d]\n", slaves[num_slaves - 1]);
5254         } else {
5255                 printf("\tSlaves: []\n");
5256
5257         }
5258
5259         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5260                         RTE_MAX_ETHPORTS);
5261
5262         if (num_active_slaves < 0) {
5263                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5264                 return;
5265         }
5266         if (num_active_slaves > 0) {
5267                 printf("\tActive Slaves (%d): [", num_active_slaves);
5268                 for (i = 0; i < num_active_slaves - 1; i++)
5269                         printf("%d ", slaves[i]);
5270
5271                 printf("%d]\n", slaves[num_active_slaves - 1]);
5272
5273         } else {
5274                 printf("\tActive Slaves: []\n");
5275
5276         }
5277
5278         primary_id = rte_eth_bond_primary_get(port_id);
5279         if (primary_id < 0) {
5280                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5281                 return;
5282         } else
5283                 printf("\tPrimary: [%d]\n", primary_id);
5284
5285 }
5286
5287 cmdline_parse_token_string_t cmd_showbonding_config_show =
5288 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5289                 show, "show");
5290 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5291 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5292                 bonding, "bonding");
5293 cmdline_parse_token_string_t cmd_showbonding_config_config =
5294 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5295                 config, "config");
5296 cmdline_parse_token_num_t cmd_showbonding_config_port =
5297 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5298                 port_id, UINT16);
5299
5300 cmdline_parse_inst_t cmd_show_bonding_config = {
5301                 .f = cmd_show_bonding_config_parsed,
5302                 .help_str = "show bonding config <port_id>: "
5303                         "Show the bonding config for port_id",
5304                 .data = NULL,
5305                 .tokens = {
5306                                 (void *)&cmd_showbonding_config_show,
5307                                 (void *)&cmd_showbonding_config_bonding,
5308                                 (void *)&cmd_showbonding_config_config,
5309                                 (void *)&cmd_showbonding_config_port,
5310                                 NULL
5311                 }
5312 };
5313
5314 /* *** SET BONDING PRIMARY *** */
5315 struct cmd_set_bonding_primary_result {
5316         cmdline_fixed_string_t set;
5317         cmdline_fixed_string_t bonding;
5318         cmdline_fixed_string_t primary;
5319         portid_t slave_id;
5320         portid_t port_id;
5321 };
5322
5323 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5324                 __attribute__((unused))  struct cmdline *cl,
5325                 __attribute__((unused)) void *data)
5326 {
5327         struct cmd_set_bonding_primary_result *res = parsed_result;
5328         portid_t master_port_id = res->port_id;
5329         portid_t slave_port_id = res->slave_id;
5330
5331         /* Set the primary slave for a bonded device. */
5332         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5333                 printf("\t Failed to set primary slave for port = %d.\n",
5334                                 master_port_id);
5335                 return;
5336         }
5337         init_port_config();
5338 }
5339
5340 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5341 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5342                 set, "set");
5343 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5344 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5345                 bonding, "bonding");
5346 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5347 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5348                 primary, "primary");
5349 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5350 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5351                 slave_id, UINT16);
5352 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5353 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5354                 port_id, UINT16);
5355
5356 cmdline_parse_inst_t cmd_set_bonding_primary = {
5357                 .f = cmd_set_bonding_primary_parsed,
5358                 .help_str = "set bonding primary <slave_id> <port_id>: "
5359                         "Set the primary slave for port_id",
5360                 .data = NULL,
5361                 .tokens = {
5362                                 (void *)&cmd_setbonding_primary_set,
5363                                 (void *)&cmd_setbonding_primary_bonding,
5364                                 (void *)&cmd_setbonding_primary_primary,
5365                                 (void *)&cmd_setbonding_primary_slave,
5366                                 (void *)&cmd_setbonding_primary_port,
5367                                 NULL
5368                 }
5369 };
5370
5371 /* *** ADD SLAVE *** */
5372 struct cmd_add_bonding_slave_result {
5373         cmdline_fixed_string_t add;
5374         cmdline_fixed_string_t bonding;
5375         cmdline_fixed_string_t slave;
5376         portid_t slave_id;
5377         portid_t port_id;
5378 };
5379
5380 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5381                 __attribute__((unused))  struct cmdline *cl,
5382                 __attribute__((unused)) void *data)
5383 {
5384         struct cmd_add_bonding_slave_result *res = parsed_result;
5385         portid_t master_port_id = res->port_id;
5386         portid_t slave_port_id = res->slave_id;
5387
5388         /* add the slave for a bonded device. */
5389         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5390                 printf("\t Failed to add slave %d to master port = %d.\n",
5391                                 slave_port_id, master_port_id);
5392                 return;
5393         }
5394         init_port_config();
5395         set_port_slave_flag(slave_port_id);
5396 }
5397
5398 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5399 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5400                 add, "add");
5401 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5402 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5403                 bonding, "bonding");
5404 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5405 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5406                 slave, "slave");
5407 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5408 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5409                 slave_id, UINT16);
5410 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5411 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5412                 port_id, UINT16);
5413
5414 cmdline_parse_inst_t cmd_add_bonding_slave = {
5415                 .f = cmd_add_bonding_slave_parsed,
5416                 .help_str = "add bonding slave <slave_id> <port_id>: "
5417                         "Add a slave device to a bonded device",
5418                 .data = NULL,
5419                 .tokens = {
5420                                 (void *)&cmd_addbonding_slave_add,
5421                                 (void *)&cmd_addbonding_slave_bonding,
5422                                 (void *)&cmd_addbonding_slave_slave,
5423                                 (void *)&cmd_addbonding_slave_slaveid,
5424                                 (void *)&cmd_addbonding_slave_port,
5425                                 NULL
5426                 }
5427 };
5428
5429 /* *** REMOVE SLAVE *** */
5430 struct cmd_remove_bonding_slave_result {
5431         cmdline_fixed_string_t remove;
5432         cmdline_fixed_string_t bonding;
5433         cmdline_fixed_string_t slave;
5434         portid_t slave_id;
5435         portid_t port_id;
5436 };
5437
5438 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5439                 __attribute__((unused))  struct cmdline *cl,
5440                 __attribute__((unused)) void *data)
5441 {
5442         struct cmd_remove_bonding_slave_result *res = parsed_result;
5443         portid_t master_port_id = res->port_id;
5444         portid_t slave_port_id = res->slave_id;
5445
5446         /* remove the slave from a bonded device. */
5447         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5448                 printf("\t Failed to remove slave %d from master port = %d.\n",
5449                                 slave_port_id, master_port_id);
5450                 return;
5451         }
5452         init_port_config();
5453         clear_port_slave_flag(slave_port_id);
5454 }
5455
5456 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5457                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5458                                 remove, "remove");
5459 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5460                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5461                                 bonding, "bonding");
5462 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5463                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5464                                 slave, "slave");
5465 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5466                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5467                                 slave_id, UINT16);
5468 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5469                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5470                                 port_id, UINT16);
5471
5472 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5473                 .f = cmd_remove_bonding_slave_parsed,
5474                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5475                         "Remove a slave device from a bonded device",
5476                 .data = NULL,
5477                 .tokens = {
5478                                 (void *)&cmd_removebonding_slave_remove,
5479                                 (void *)&cmd_removebonding_slave_bonding,
5480                                 (void *)&cmd_removebonding_slave_slave,
5481                                 (void *)&cmd_removebonding_slave_slaveid,
5482                                 (void *)&cmd_removebonding_slave_port,
5483                                 NULL
5484                 }
5485 };
5486
5487 /* *** CREATE BONDED DEVICE *** */
5488 struct cmd_create_bonded_device_result {
5489         cmdline_fixed_string_t create;
5490         cmdline_fixed_string_t bonded;
5491         cmdline_fixed_string_t device;
5492         uint8_t mode;
5493         uint8_t socket;
5494 };
5495
5496 static int bond_dev_num = 0;
5497
5498 static void cmd_create_bonded_device_parsed(void *parsed_result,
5499                 __attribute__((unused))  struct cmdline *cl,
5500                 __attribute__((unused)) void *data)
5501 {
5502         struct cmd_create_bonded_device_result *res = parsed_result;
5503         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5504         int port_id;
5505
5506         if (test_done == 0) {
5507                 printf("Please stop forwarding first\n");
5508                 return;
5509         }
5510
5511         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5512                         bond_dev_num++);
5513
5514         /* Create a new bonded device. */
5515         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5516         if (port_id < 0) {
5517                 printf("\t Failed to create bonded device.\n");
5518                 return;
5519         } else {
5520                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5521                                 port_id);
5522
5523                 /* Update number of ports */
5524                 nb_ports = rte_eth_dev_count();
5525                 reconfig(port_id, res->socket);
5526                 rte_eth_promiscuous_enable(port_id);
5527         }
5528
5529 }
5530
5531 cmdline_parse_token_string_t cmd_createbonded_device_create =
5532                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5533                                 create, "create");
5534 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5535                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5536                                 bonded, "bonded");
5537 cmdline_parse_token_string_t cmd_createbonded_device_device =
5538                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5539                                 device, "device");
5540 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5541                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5542                                 mode, UINT8);
5543 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5544                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5545                                 socket, UINT8);
5546
5547 cmdline_parse_inst_t cmd_create_bonded_device = {
5548                 .f = cmd_create_bonded_device_parsed,
5549                 .help_str = "create bonded device <mode> <socket>: "
5550                         "Create a new bonded device with specific bonding mode and socket",
5551                 .data = NULL,
5552                 .tokens = {
5553                                 (void *)&cmd_createbonded_device_create,
5554                                 (void *)&cmd_createbonded_device_bonded,
5555                                 (void *)&cmd_createbonded_device_device,
5556                                 (void *)&cmd_createbonded_device_mode,
5557                                 (void *)&cmd_createbonded_device_socket,
5558                                 NULL
5559                 }
5560 };
5561
5562 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5563 struct cmd_set_bond_mac_addr_result {
5564         cmdline_fixed_string_t set;
5565         cmdline_fixed_string_t bonding;
5566         cmdline_fixed_string_t mac_addr;
5567         uint16_t port_num;
5568         struct ether_addr address;
5569 };
5570
5571 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5572                 __attribute__((unused))  struct cmdline *cl,
5573                 __attribute__((unused)) void *data)
5574 {
5575         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5576         int ret;
5577
5578         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5579                 return;
5580
5581         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5582
5583         /* check the return value and print it if is < 0 */
5584         if (ret < 0)
5585                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5586 }
5587
5588 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5589                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5590 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5591                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5592                                 "bonding");
5593 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5594                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5595                                 "mac_addr");
5596 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5597                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5598                                 port_num, UINT16);
5599 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5600                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5601
5602 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5603                 .f = cmd_set_bond_mac_addr_parsed,
5604                 .data = (void *) 0,
5605                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5606                 .tokens = {
5607                                 (void *)&cmd_set_bond_mac_addr_set,
5608                                 (void *)&cmd_set_bond_mac_addr_bonding,
5609                                 (void *)&cmd_set_bond_mac_addr_mac,
5610                                 (void *)&cmd_set_bond_mac_addr_portnum,
5611                                 (void *)&cmd_set_bond_mac_addr_addr,
5612                                 NULL
5613                 }
5614 };
5615
5616
5617 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5618 struct cmd_set_bond_mon_period_result {
5619         cmdline_fixed_string_t set;
5620         cmdline_fixed_string_t bonding;
5621         cmdline_fixed_string_t mon_period;
5622         uint16_t port_num;
5623         uint32_t period_ms;
5624 };
5625
5626 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5627                 __attribute__((unused))  struct cmdline *cl,
5628                 __attribute__((unused)) void *data)
5629 {
5630         struct cmd_set_bond_mon_period_result *res = parsed_result;
5631         int ret;
5632
5633         if (res->port_num >= nb_ports) {
5634                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5635                 return;
5636         }
5637
5638         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5639
5640         /* check the return value and print it if is < 0 */
5641         if (ret < 0)
5642                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5643 }
5644
5645 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5646                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5647                                 set, "set");
5648 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5649                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5650                                 bonding, "bonding");
5651 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5652                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5653                                 mon_period,     "mon_period");
5654 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5655                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5656                                 port_num, UINT16);
5657 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5658                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5659                                 period_ms, UINT32);
5660
5661 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5662                 .f = cmd_set_bond_mon_period_parsed,
5663                 .data = (void *) 0,
5664                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5665                 .tokens = {
5666                                 (void *)&cmd_set_bond_mon_period_set,
5667                                 (void *)&cmd_set_bond_mon_period_bonding,
5668                                 (void *)&cmd_set_bond_mon_period_mon_period,
5669                                 (void *)&cmd_set_bond_mon_period_portnum,
5670                                 (void *)&cmd_set_bond_mon_period_period_ms,
5671                                 NULL
5672                 }
5673 };
5674
5675
5676
5677 struct cmd_set_bonding_agg_mode_policy_result {
5678         cmdline_fixed_string_t set;
5679         cmdline_fixed_string_t bonding;
5680         cmdline_fixed_string_t agg_mode;
5681         uint16_t port_num;
5682         cmdline_fixed_string_t policy;
5683 };
5684
5685
5686 static void
5687 cmd_set_bonding_agg_mode(void *parsed_result,
5688                 __attribute__((unused)) struct cmdline *cl,
5689                 __attribute__((unused)) void *data)
5690 {
5691         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5692         uint8_t policy = AGG_BANDWIDTH;
5693
5694         if (res->port_num >= nb_ports) {
5695                 printf("Port id %d must be less than %d\n",
5696                                 res->port_num, nb_ports);
5697                 return;
5698         }
5699
5700         if (!strcmp(res->policy, "bandwidth"))
5701                 policy = AGG_BANDWIDTH;
5702         else if (!strcmp(res->policy, "stable"))
5703                 policy = AGG_STABLE;
5704         else if (!strcmp(res->policy, "count"))
5705                 policy = AGG_COUNT;
5706
5707         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5708 }
5709
5710
5711 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5712         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5713                                 set, "set");
5714 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5715         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5716                                 bonding, "bonding");
5717
5718 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5719         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5720                                 agg_mode, "agg_mode");
5721
5722 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5723         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5724                                 port_num, UINT16);
5725
5726 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5727         TOKEN_STRING_INITIALIZER(
5728                         struct cmd_set_bonding_balance_xmit_policy_result,
5729                 policy, "stable#bandwidth#count");
5730
5731 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5732         .f = cmd_set_bonding_agg_mode,
5733         .data = (void *) 0,
5734         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5735         .tokens = {
5736                         (void *)&cmd_set_bonding_agg_mode_set,
5737                         (void *)&cmd_set_bonding_agg_mode_bonding,
5738                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5739                         (void *)&cmd_set_bonding_agg_mode_portnum,
5740                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5741                         NULL
5742                 }
5743 };
5744
5745
5746 #endif /* RTE_LIBRTE_PMD_BOND */
5747
5748 /* *** SET FORWARDING MODE *** */
5749 struct cmd_set_fwd_mode_result {
5750         cmdline_fixed_string_t set;
5751         cmdline_fixed_string_t fwd;
5752         cmdline_fixed_string_t mode;
5753 };
5754
5755 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5756                                     __attribute__((unused)) struct cmdline *cl,
5757                                     __attribute__((unused)) void *data)
5758 {
5759         struct cmd_set_fwd_mode_result *res = parsed_result;
5760
5761         retry_enabled = 0;
5762         set_pkt_forwarding_mode(res->mode);
5763 }
5764
5765 cmdline_parse_token_string_t cmd_setfwd_set =
5766         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5767 cmdline_parse_token_string_t cmd_setfwd_fwd =
5768         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5769 cmdline_parse_token_string_t cmd_setfwd_mode =
5770         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5771                 "" /* defined at init */);
5772
5773 cmdline_parse_inst_t cmd_set_fwd_mode = {
5774         .f = cmd_set_fwd_mode_parsed,
5775         .data = NULL,
5776         .help_str = NULL, /* defined at init */
5777         .tokens = {
5778                 (void *)&cmd_setfwd_set,
5779                 (void *)&cmd_setfwd_fwd,
5780                 (void *)&cmd_setfwd_mode,
5781                 NULL,
5782         },
5783 };
5784
5785 static void cmd_set_fwd_mode_init(void)
5786 {
5787         char *modes, *c;
5788         static char token[128];
5789         static char help[256];
5790         cmdline_parse_token_string_t *token_struct;
5791
5792         modes = list_pkt_forwarding_modes();
5793         snprintf(help, sizeof(help), "set fwd %s: "
5794                 "Set packet forwarding mode", modes);
5795         cmd_set_fwd_mode.help_str = help;
5796
5797         /* string token separator is # */
5798         for (c = token; *modes != '\0'; modes++)
5799                 if (*modes == '|')
5800                         *c++ = '#';
5801                 else
5802                         *c++ = *modes;
5803         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5804         token_struct->string_data.str = token;
5805 }
5806
5807 /* *** SET RETRY FORWARDING MODE *** */
5808 struct cmd_set_fwd_retry_mode_result {
5809         cmdline_fixed_string_t set;
5810         cmdline_fixed_string_t fwd;
5811         cmdline_fixed_string_t mode;
5812         cmdline_fixed_string_t retry;
5813 };
5814
5815 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5816                             __attribute__((unused)) struct cmdline *cl,
5817                             __attribute__((unused)) void *data)
5818 {
5819         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5820
5821         retry_enabled = 1;
5822         set_pkt_forwarding_mode(res->mode);
5823 }
5824
5825 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5826         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5827                         set, "set");
5828 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5829         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5830                         fwd, "fwd");
5831 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5832         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5833                         mode,
5834                 "" /* defined at init */);
5835 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5836         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5837                         retry, "retry");
5838
5839 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5840         .f = cmd_set_fwd_retry_mode_parsed,
5841         .data = NULL,
5842         .help_str = NULL, /* defined at init */
5843         .tokens = {
5844                 (void *)&cmd_setfwd_retry_set,
5845                 (void *)&cmd_setfwd_retry_fwd,
5846                 (void *)&cmd_setfwd_retry_mode,
5847                 (void *)&cmd_setfwd_retry_retry,
5848                 NULL,
5849         },
5850 };
5851
5852 static void cmd_set_fwd_retry_mode_init(void)
5853 {
5854         char *modes, *c;
5855         static char token[128];
5856         static char help[256];
5857         cmdline_parse_token_string_t *token_struct;
5858
5859         modes = list_pkt_forwarding_retry_modes();
5860         snprintf(help, sizeof(help), "set fwd %s retry: "
5861                 "Set packet forwarding mode with retry", modes);
5862         cmd_set_fwd_retry_mode.help_str = help;
5863
5864         /* string token separator is # */
5865         for (c = token; *modes != '\0'; modes++)
5866                 if (*modes == '|')
5867                         *c++ = '#';
5868                 else
5869                         *c++ = *modes;
5870         token_struct = (cmdline_parse_token_string_t *)
5871                 cmd_set_fwd_retry_mode.tokens[2];
5872         token_struct->string_data.str = token;
5873 }
5874
5875 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5876 struct cmd_set_burst_tx_retry_result {
5877         cmdline_fixed_string_t set;
5878         cmdline_fixed_string_t burst;
5879         cmdline_fixed_string_t tx;
5880         cmdline_fixed_string_t delay;
5881         uint32_t time;
5882         cmdline_fixed_string_t retry;
5883         uint32_t retry_num;
5884 };
5885
5886 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5887                                         __attribute__((unused)) struct cmdline *cl,
5888                                         __attribute__((unused)) void *data)
5889 {
5890         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5891
5892         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5893                 && !strcmp(res->tx, "tx")) {
5894                 if (!strcmp(res->delay, "delay"))
5895                         burst_tx_delay_time = res->time;
5896                 if (!strcmp(res->retry, "retry"))
5897                         burst_tx_retry_num = res->retry_num;
5898         }
5899
5900 }
5901
5902 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5903         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5904 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5905         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5906                                  "burst");
5907 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5908         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5909 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5910         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5911 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5912         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5913 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5914         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5915 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5916         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5917
5918 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5919         .f = cmd_set_burst_tx_retry_parsed,
5920         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5921         .tokens = {
5922                 (void *)&cmd_set_burst_tx_retry_set,
5923                 (void *)&cmd_set_burst_tx_retry_burst,
5924                 (void *)&cmd_set_burst_tx_retry_tx,
5925                 (void *)&cmd_set_burst_tx_retry_delay,
5926                 (void *)&cmd_set_burst_tx_retry_time,
5927                 (void *)&cmd_set_burst_tx_retry_retry,
5928                 (void *)&cmd_set_burst_tx_retry_retry_num,
5929                 NULL,
5930         },
5931 };
5932
5933 /* *** SET PROMISC MODE *** */
5934 struct cmd_set_promisc_mode_result {
5935         cmdline_fixed_string_t set;
5936         cmdline_fixed_string_t promisc;
5937         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5938         uint16_t port_num;               /* valid if "allports" argument == 0 */
5939         cmdline_fixed_string_t mode;
5940 };
5941
5942 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5943                                         __attribute__((unused)) struct cmdline *cl,
5944                                         void *allports)
5945 {
5946         struct cmd_set_promisc_mode_result *res = parsed_result;
5947         int enable;
5948         portid_t i;
5949
5950         if (!strcmp(res->mode, "on"))
5951                 enable = 1;
5952         else
5953                 enable = 0;
5954
5955         /* all ports */
5956         if (allports) {
5957                 RTE_ETH_FOREACH_DEV(i) {
5958                         if (enable)
5959                                 rte_eth_promiscuous_enable(i);
5960                         else
5961                                 rte_eth_promiscuous_disable(i);
5962                 }
5963         }
5964         else {
5965                 if (enable)
5966                         rte_eth_promiscuous_enable(res->port_num);
5967                 else
5968                         rte_eth_promiscuous_disable(res->port_num);
5969         }
5970 }
5971
5972 cmdline_parse_token_string_t cmd_setpromisc_set =
5973         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5974 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5975         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5976                                  "promisc");
5977 cmdline_parse_token_string_t cmd_setpromisc_portall =
5978         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5979                                  "all");
5980 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5981         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5982                               UINT16);
5983 cmdline_parse_token_string_t cmd_setpromisc_mode =
5984         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5985                                  "on#off");
5986
5987 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5988         .f = cmd_set_promisc_mode_parsed,
5989         .data = (void *)1,
5990         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5991         .tokens = {
5992                 (void *)&cmd_setpromisc_set,
5993                 (void *)&cmd_setpromisc_promisc,
5994                 (void *)&cmd_setpromisc_portall,
5995                 (void *)&cmd_setpromisc_mode,
5996                 NULL,
5997         },
5998 };
5999
6000 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6001         .f = cmd_set_promisc_mode_parsed,
6002         .data = (void *)0,
6003         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6004         .tokens = {
6005                 (void *)&cmd_setpromisc_set,
6006                 (void *)&cmd_setpromisc_promisc,
6007                 (void *)&cmd_setpromisc_portnum,
6008                 (void *)&cmd_setpromisc_mode,
6009                 NULL,
6010         },
6011 };
6012
6013 /* *** SET ALLMULTI MODE *** */
6014 struct cmd_set_allmulti_mode_result {
6015         cmdline_fixed_string_t set;
6016         cmdline_fixed_string_t allmulti;
6017         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6018         uint16_t port_num;               /* valid if "allports" argument == 0 */
6019         cmdline_fixed_string_t mode;
6020 };
6021
6022 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6023                                         __attribute__((unused)) struct cmdline *cl,
6024                                         void *allports)
6025 {
6026         struct cmd_set_allmulti_mode_result *res = parsed_result;
6027         int enable;
6028         portid_t i;
6029
6030         if (!strcmp(res->mode, "on"))
6031                 enable = 1;
6032         else
6033                 enable = 0;
6034
6035         /* all ports */
6036         if (allports) {
6037                 RTE_ETH_FOREACH_DEV(i) {
6038                         if (enable)
6039                                 rte_eth_allmulticast_enable(i);
6040                         else
6041                                 rte_eth_allmulticast_disable(i);
6042                 }
6043         }
6044         else {
6045                 if (enable)
6046                         rte_eth_allmulticast_enable(res->port_num);
6047                 else
6048                         rte_eth_allmulticast_disable(res->port_num);
6049         }
6050 }
6051
6052 cmdline_parse_token_string_t cmd_setallmulti_set =
6053         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6054 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6055         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6056                                  "allmulti");
6057 cmdline_parse_token_string_t cmd_setallmulti_portall =
6058         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6059                                  "all");
6060 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6061         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6062                               UINT16);
6063 cmdline_parse_token_string_t cmd_setallmulti_mode =
6064         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6065                                  "on#off");
6066
6067 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6068         .f = cmd_set_allmulti_mode_parsed,
6069         .data = (void *)1,
6070         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6071         .tokens = {
6072                 (void *)&cmd_setallmulti_set,
6073                 (void *)&cmd_setallmulti_allmulti,
6074                 (void *)&cmd_setallmulti_portall,
6075                 (void *)&cmd_setallmulti_mode,
6076                 NULL,
6077         },
6078 };
6079
6080 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6081         .f = cmd_set_allmulti_mode_parsed,
6082         .data = (void *)0,
6083         .help_str = "set allmulti <port_id> on|off: "
6084                 "Set allmulti mode on port_id",
6085         .tokens = {
6086                 (void *)&cmd_setallmulti_set,
6087                 (void *)&cmd_setallmulti_allmulti,
6088                 (void *)&cmd_setallmulti_portnum,
6089                 (void *)&cmd_setallmulti_mode,
6090                 NULL,
6091         },
6092 };
6093
6094 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6095 struct cmd_link_flow_ctrl_set_result {
6096         cmdline_fixed_string_t set;
6097         cmdline_fixed_string_t flow_ctrl;
6098         cmdline_fixed_string_t rx;
6099         cmdline_fixed_string_t rx_lfc_mode;
6100         cmdline_fixed_string_t tx;
6101         cmdline_fixed_string_t tx_lfc_mode;
6102         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6103         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6104         cmdline_fixed_string_t autoneg_str;
6105         cmdline_fixed_string_t autoneg;
6106         cmdline_fixed_string_t hw_str;
6107         uint32_t high_water;
6108         cmdline_fixed_string_t lw_str;
6109         uint32_t low_water;
6110         cmdline_fixed_string_t pt_str;
6111         uint16_t pause_time;
6112         cmdline_fixed_string_t xon_str;
6113         uint16_t send_xon;
6114         portid_t port_id;
6115 };
6116
6117 cmdline_parse_token_string_t cmd_lfc_set_set =
6118         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6119                                 set, "set");
6120 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6121         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6122                                 flow_ctrl, "flow_ctrl");
6123 cmdline_parse_token_string_t cmd_lfc_set_rx =
6124         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6125                                 rx, "rx");
6126 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6127         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6128                                 rx_lfc_mode, "on#off");
6129 cmdline_parse_token_string_t cmd_lfc_set_tx =
6130         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6131                                 tx, "tx");
6132 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6133         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6134                                 tx_lfc_mode, "on#off");
6135 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6136         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6137                                 hw_str, "high_water");
6138 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6139         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6140                                 high_water, UINT32);
6141 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6142         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6143                                 lw_str, "low_water");
6144 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6145         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6146                                 low_water, UINT32);
6147 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6148         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6149                                 pt_str, "pause_time");
6150 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6151         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6152                                 pause_time, UINT16);
6153 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6154         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6155                                 xon_str, "send_xon");
6156 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6157         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6158                                 send_xon, UINT16);
6159 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6160         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6161                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6162 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6163         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6164                                 mac_ctrl_frame_fwd_mode, "on#off");
6165 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6166         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6167                                 autoneg_str, "autoneg");
6168 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6169         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6170                                 autoneg, "on#off");
6171 cmdline_parse_token_num_t cmd_lfc_set_portid =
6172         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6173                                 port_id, UINT16);
6174
6175 /* forward declaration */
6176 static void
6177 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6178                               void *data);
6179
6180 cmdline_parse_inst_t cmd_link_flow_control_set = {
6181         .f = cmd_link_flow_ctrl_set_parsed,
6182         .data = NULL,
6183         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6184                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6185                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6186         .tokens = {
6187                 (void *)&cmd_lfc_set_set,
6188                 (void *)&cmd_lfc_set_flow_ctrl,
6189                 (void *)&cmd_lfc_set_rx,
6190                 (void *)&cmd_lfc_set_rx_mode,
6191                 (void *)&cmd_lfc_set_tx,
6192                 (void *)&cmd_lfc_set_tx_mode,
6193                 (void *)&cmd_lfc_set_high_water,
6194                 (void *)&cmd_lfc_set_low_water,
6195                 (void *)&cmd_lfc_set_pause_time,
6196                 (void *)&cmd_lfc_set_send_xon,
6197                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6198                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6199                 (void *)&cmd_lfc_set_autoneg_str,
6200                 (void *)&cmd_lfc_set_autoneg,
6201                 (void *)&cmd_lfc_set_portid,
6202                 NULL,
6203         },
6204 };
6205
6206 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6207         .f = cmd_link_flow_ctrl_set_parsed,
6208         .data = (void *)&cmd_link_flow_control_set_rx,
6209         .help_str = "set flow_ctrl rx on|off <port_id>: "
6210                 "Change rx flow control parameter",
6211         .tokens = {
6212                 (void *)&cmd_lfc_set_set,
6213                 (void *)&cmd_lfc_set_flow_ctrl,
6214                 (void *)&cmd_lfc_set_rx,
6215                 (void *)&cmd_lfc_set_rx_mode,
6216                 (void *)&cmd_lfc_set_portid,
6217                 NULL,
6218         },
6219 };
6220
6221 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6222         .f = cmd_link_flow_ctrl_set_parsed,
6223         .data = (void *)&cmd_link_flow_control_set_tx,
6224         .help_str = "set flow_ctrl tx on|off <port_id>: "
6225                 "Change tx flow control parameter",
6226         .tokens = {
6227                 (void *)&cmd_lfc_set_set,
6228                 (void *)&cmd_lfc_set_flow_ctrl,
6229                 (void *)&cmd_lfc_set_tx,
6230                 (void *)&cmd_lfc_set_tx_mode,
6231                 (void *)&cmd_lfc_set_portid,
6232                 NULL,
6233         },
6234 };
6235
6236 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6237         .f = cmd_link_flow_ctrl_set_parsed,
6238         .data = (void *)&cmd_link_flow_control_set_hw,
6239         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6240                 "Change high water flow control parameter",
6241         .tokens = {
6242                 (void *)&cmd_lfc_set_set,
6243                 (void *)&cmd_lfc_set_flow_ctrl,
6244                 (void *)&cmd_lfc_set_high_water_str,
6245                 (void *)&cmd_lfc_set_high_water,
6246                 (void *)&cmd_lfc_set_portid,
6247                 NULL,
6248         },
6249 };
6250
6251 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6252         .f = cmd_link_flow_ctrl_set_parsed,
6253         .data = (void *)&cmd_link_flow_control_set_lw,
6254         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6255                 "Change low water flow control parameter",
6256         .tokens = {
6257                 (void *)&cmd_lfc_set_set,
6258                 (void *)&cmd_lfc_set_flow_ctrl,
6259                 (void *)&cmd_lfc_set_low_water_str,
6260                 (void *)&cmd_lfc_set_low_water,
6261                 (void *)&cmd_lfc_set_portid,
6262                 NULL,
6263         },
6264 };
6265
6266 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6267         .f = cmd_link_flow_ctrl_set_parsed,
6268         .data = (void *)&cmd_link_flow_control_set_pt,
6269         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6270                 "Change pause time flow control parameter",
6271         .tokens = {
6272                 (void *)&cmd_lfc_set_set,
6273                 (void *)&cmd_lfc_set_flow_ctrl,
6274                 (void *)&cmd_lfc_set_pause_time_str,
6275                 (void *)&cmd_lfc_set_pause_time,
6276                 (void *)&cmd_lfc_set_portid,
6277                 NULL,
6278         },
6279 };
6280
6281 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6282         .f = cmd_link_flow_ctrl_set_parsed,
6283         .data = (void *)&cmd_link_flow_control_set_xon,
6284         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6285                 "Change send_xon flow control parameter",
6286         .tokens = {
6287                 (void *)&cmd_lfc_set_set,
6288                 (void *)&cmd_lfc_set_flow_ctrl,
6289                 (void *)&cmd_lfc_set_send_xon_str,
6290                 (void *)&cmd_lfc_set_send_xon,
6291                 (void *)&cmd_lfc_set_portid,
6292                 NULL,
6293         },
6294 };
6295
6296 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6297         .f = cmd_link_flow_ctrl_set_parsed,
6298         .data = (void *)&cmd_link_flow_control_set_macfwd,
6299         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6300                 "Change mac ctrl fwd flow control parameter",
6301         .tokens = {
6302                 (void *)&cmd_lfc_set_set,
6303                 (void *)&cmd_lfc_set_flow_ctrl,
6304                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6305                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6306                 (void *)&cmd_lfc_set_portid,
6307                 NULL,
6308         },
6309 };
6310
6311 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6312         .f = cmd_link_flow_ctrl_set_parsed,
6313         .data = (void *)&cmd_link_flow_control_set_autoneg,
6314         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6315                 "Change autoneg flow control parameter",
6316         .tokens = {
6317                 (void *)&cmd_lfc_set_set,
6318                 (void *)&cmd_lfc_set_flow_ctrl,
6319                 (void *)&cmd_lfc_set_autoneg_str,
6320                 (void *)&cmd_lfc_set_autoneg,
6321                 (void *)&cmd_lfc_set_portid,
6322                 NULL,
6323         },
6324 };
6325
6326 static void
6327 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6328                               __attribute__((unused)) struct cmdline *cl,
6329                               void *data)
6330 {
6331         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6332         cmdline_parse_inst_t *cmd = data;
6333         struct rte_eth_fc_conf fc_conf;
6334         int rx_fc_en = 0;
6335         int tx_fc_en = 0;
6336         int ret;
6337
6338         /*
6339          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6340          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6341          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6342          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6343          */
6344         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6345                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6346         };
6347
6348         /* Partial command line, retrieve current configuration */
6349         if (cmd) {
6350                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6351                 if (ret != 0) {
6352                         printf("cannot get current flow ctrl parameters, return"
6353                                "code = %d\n", ret);
6354                         return;
6355                 }
6356
6357                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6358                     (fc_conf.mode == RTE_FC_FULL))
6359                         rx_fc_en = 1;
6360                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6361                     (fc_conf.mode == RTE_FC_FULL))
6362                         tx_fc_en = 1;
6363         }
6364
6365         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6366                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6367
6368         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6369                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6370
6371         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6372
6373         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6374                 fc_conf.high_water = res->high_water;
6375
6376         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6377                 fc_conf.low_water = res->low_water;
6378
6379         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6380                 fc_conf.pause_time = res->pause_time;
6381
6382         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6383                 fc_conf.send_xon = res->send_xon;
6384
6385         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6386                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6387                         fc_conf.mac_ctrl_frame_fwd = 1;
6388                 else
6389                         fc_conf.mac_ctrl_frame_fwd = 0;
6390         }
6391
6392         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6393                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6394
6395         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6396         if (ret != 0)
6397                 printf("bad flow contrl parameter, return code = %d \n", ret);
6398 }
6399
6400 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6401 struct cmd_priority_flow_ctrl_set_result {
6402         cmdline_fixed_string_t set;
6403         cmdline_fixed_string_t pfc_ctrl;
6404         cmdline_fixed_string_t rx;
6405         cmdline_fixed_string_t rx_pfc_mode;
6406         cmdline_fixed_string_t tx;
6407         cmdline_fixed_string_t tx_pfc_mode;
6408         uint32_t high_water;
6409         uint32_t low_water;
6410         uint16_t pause_time;
6411         uint8_t  priority;
6412         portid_t port_id;
6413 };
6414
6415 static void
6416 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6417                        __attribute__((unused)) struct cmdline *cl,
6418                        __attribute__((unused)) void *data)
6419 {
6420         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6421         struct rte_eth_pfc_conf pfc_conf;
6422         int rx_fc_enable, tx_fc_enable;
6423         int ret;
6424
6425         /*
6426          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6427          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6428          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6429          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6430          */
6431         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6432                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6433         };
6434
6435         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6436         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6437         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6438         pfc_conf.fc.high_water = res->high_water;
6439         pfc_conf.fc.low_water  = res->low_water;
6440         pfc_conf.fc.pause_time = res->pause_time;
6441         pfc_conf.priority      = res->priority;
6442
6443         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6444         if (ret != 0)
6445                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6446 }
6447
6448 cmdline_parse_token_string_t cmd_pfc_set_set =
6449         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6450                                 set, "set");
6451 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6452         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6453                                 pfc_ctrl, "pfc_ctrl");
6454 cmdline_parse_token_string_t cmd_pfc_set_rx =
6455         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6456                                 rx, "rx");
6457 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6458         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6459                                 rx_pfc_mode, "on#off");
6460 cmdline_parse_token_string_t cmd_pfc_set_tx =
6461         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6462                                 tx, "tx");
6463 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6464         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6465                                 tx_pfc_mode, "on#off");
6466 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6467         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6468                                 high_water, UINT32);
6469 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6470         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6471                                 low_water, UINT32);
6472 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6473         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6474                                 pause_time, UINT16);
6475 cmdline_parse_token_num_t cmd_pfc_set_priority =
6476         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6477                                 priority, UINT8);
6478 cmdline_parse_token_num_t cmd_pfc_set_portid =
6479         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6480                                 port_id, UINT16);
6481
6482 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6483         .f = cmd_priority_flow_ctrl_set_parsed,
6484         .data = NULL,
6485         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6486                 "<pause_time> <priority> <port_id>: "
6487                 "Configure the Ethernet priority flow control",
6488         .tokens = {
6489                 (void *)&cmd_pfc_set_set,
6490                 (void *)&cmd_pfc_set_flow_ctrl,
6491                 (void *)&cmd_pfc_set_rx,
6492                 (void *)&cmd_pfc_set_rx_mode,
6493                 (void *)&cmd_pfc_set_tx,
6494                 (void *)&cmd_pfc_set_tx_mode,
6495                 (void *)&cmd_pfc_set_high_water,
6496                 (void *)&cmd_pfc_set_low_water,
6497                 (void *)&cmd_pfc_set_pause_time,
6498                 (void *)&cmd_pfc_set_priority,
6499                 (void *)&cmd_pfc_set_portid,
6500                 NULL,
6501         },
6502 };
6503
6504 /* *** RESET CONFIGURATION *** */
6505 struct cmd_reset_result {
6506         cmdline_fixed_string_t reset;
6507         cmdline_fixed_string_t def;
6508 };
6509
6510 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6511                              struct cmdline *cl,
6512                              __attribute__((unused)) void *data)
6513 {
6514         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6515         set_def_fwd_config();
6516 }
6517
6518 cmdline_parse_token_string_t cmd_reset_set =
6519         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6520 cmdline_parse_token_string_t cmd_reset_def =
6521         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6522                                  "default");
6523
6524 cmdline_parse_inst_t cmd_reset = {
6525         .f = cmd_reset_parsed,
6526         .data = NULL,
6527         .help_str = "set default: Reset default forwarding configuration",
6528         .tokens = {
6529                 (void *)&cmd_reset_set,
6530                 (void *)&cmd_reset_def,
6531                 NULL,
6532         },
6533 };
6534
6535 /* *** START FORWARDING *** */
6536 struct cmd_start_result {
6537         cmdline_fixed_string_t start;
6538 };
6539
6540 cmdline_parse_token_string_t cmd_start_start =
6541         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6542
6543 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6544                              __attribute__((unused)) struct cmdline *cl,
6545                              __attribute__((unused)) void *data)
6546 {
6547         start_packet_forwarding(0);
6548 }
6549
6550 cmdline_parse_inst_t cmd_start = {
6551         .f = cmd_start_parsed,
6552         .data = NULL,
6553         .help_str = "start: Start packet forwarding",
6554         .tokens = {
6555                 (void *)&cmd_start_start,
6556                 NULL,
6557         },
6558 };
6559
6560 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6561 struct cmd_start_tx_first_result {
6562         cmdline_fixed_string_t start;
6563         cmdline_fixed_string_t tx_first;
6564 };
6565
6566 static void
6567 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6568                           __attribute__((unused)) struct cmdline *cl,
6569                           __attribute__((unused)) void *data)
6570 {
6571         start_packet_forwarding(1);
6572 }
6573
6574 cmdline_parse_token_string_t cmd_start_tx_first_start =
6575         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6576                                  "start");
6577 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6578         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6579                                  tx_first, "tx_first");
6580
6581 cmdline_parse_inst_t cmd_start_tx_first = {
6582         .f = cmd_start_tx_first_parsed,
6583         .data = NULL,
6584         .help_str = "start tx_first: Start packet forwarding, "
6585                 "after sending 1 burst of packets",
6586         .tokens = {
6587                 (void *)&cmd_start_tx_first_start,
6588                 (void *)&cmd_start_tx_first_tx_first,
6589                 NULL,
6590         },
6591 };
6592
6593 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6594 struct cmd_start_tx_first_n_result {
6595         cmdline_fixed_string_t start;
6596         cmdline_fixed_string_t tx_first;
6597         uint32_t tx_num;
6598 };
6599
6600 static void
6601 cmd_start_tx_first_n_parsed(void *parsed_result,
6602                           __attribute__((unused)) struct cmdline *cl,
6603                           __attribute__((unused)) void *data)
6604 {
6605         struct cmd_start_tx_first_n_result *res = parsed_result;
6606
6607         start_packet_forwarding(res->tx_num);
6608 }
6609
6610 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6611         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6612                         start, "start");
6613 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6614         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6615                         tx_first, "tx_first");
6616 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6617         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6618                         tx_num, UINT32);
6619
6620 cmdline_parse_inst_t cmd_start_tx_first_n = {
6621         .f = cmd_start_tx_first_n_parsed,
6622         .data = NULL,
6623         .help_str = "start tx_first <num>: "
6624                 "packet forwarding, after sending <num> bursts of packets",
6625         .tokens = {
6626                 (void *)&cmd_start_tx_first_n_start,
6627                 (void *)&cmd_start_tx_first_n_tx_first,
6628                 (void *)&cmd_start_tx_first_n_tx_num,
6629                 NULL,
6630         },
6631 };
6632
6633 /* *** SET LINK UP *** */
6634 struct cmd_set_link_up_result {
6635         cmdline_fixed_string_t set;
6636         cmdline_fixed_string_t link_up;
6637         cmdline_fixed_string_t port;
6638         portid_t port_id;
6639 };
6640
6641 cmdline_parse_token_string_t cmd_set_link_up_set =
6642         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6643 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6644         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6645                                 "link-up");
6646 cmdline_parse_token_string_t cmd_set_link_up_port =
6647         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6648 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6649         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6650
6651 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6652                              __attribute__((unused)) struct cmdline *cl,
6653                              __attribute__((unused)) void *data)
6654 {
6655         struct cmd_set_link_up_result *res = parsed_result;
6656         dev_set_link_up(res->port_id);
6657 }
6658
6659 cmdline_parse_inst_t cmd_set_link_up = {
6660         .f = cmd_set_link_up_parsed,
6661         .data = NULL,
6662         .help_str = "set link-up port <port id>",
6663         .tokens = {
6664                 (void *)&cmd_set_link_up_set,
6665                 (void *)&cmd_set_link_up_link_up,
6666                 (void *)&cmd_set_link_up_port,
6667                 (void *)&cmd_set_link_up_port_id,
6668                 NULL,
6669         },
6670 };
6671
6672 /* *** SET LINK DOWN *** */
6673 struct cmd_set_link_down_result {
6674         cmdline_fixed_string_t set;
6675         cmdline_fixed_string_t link_down;
6676         cmdline_fixed_string_t port;
6677         portid_t port_id;
6678 };
6679
6680 cmdline_parse_token_string_t cmd_set_link_down_set =
6681         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6682 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6683         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6684                                 "link-down");
6685 cmdline_parse_token_string_t cmd_set_link_down_port =
6686         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6687 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6688         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6689
6690 static void cmd_set_link_down_parsed(
6691                                 __attribute__((unused)) void *parsed_result,
6692                                 __attribute__((unused)) struct cmdline *cl,
6693                                 __attribute__((unused)) void *data)
6694 {
6695         struct cmd_set_link_down_result *res = parsed_result;
6696         dev_set_link_down(res->port_id);
6697 }
6698
6699 cmdline_parse_inst_t cmd_set_link_down = {
6700         .f = cmd_set_link_down_parsed,
6701         .data = NULL,
6702         .help_str = "set link-down port <port id>",
6703         .tokens = {
6704                 (void *)&cmd_set_link_down_set,
6705                 (void *)&cmd_set_link_down_link_down,
6706                 (void *)&cmd_set_link_down_port,
6707                 (void *)&cmd_set_link_down_port_id,
6708                 NULL,
6709         },
6710 };
6711
6712 /* *** SHOW CFG *** */
6713 struct cmd_showcfg_result {
6714         cmdline_fixed_string_t show;
6715         cmdline_fixed_string_t cfg;
6716         cmdline_fixed_string_t what;
6717 };
6718
6719 static void cmd_showcfg_parsed(void *parsed_result,
6720                                __attribute__((unused)) struct cmdline *cl,
6721                                __attribute__((unused)) void *data)
6722 {
6723         struct cmd_showcfg_result *res = parsed_result;
6724         if (!strcmp(res->what, "rxtx"))
6725                 rxtx_config_display();
6726         else if (!strcmp(res->what, "cores"))
6727                 fwd_lcores_config_display();
6728         else if (!strcmp(res->what, "fwd"))
6729                 pkt_fwd_config_display(&cur_fwd_config);
6730         else if (!strcmp(res->what, "txpkts"))
6731                 show_tx_pkt_segments();
6732 }
6733
6734 cmdline_parse_token_string_t cmd_showcfg_show =
6735         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6736 cmdline_parse_token_string_t cmd_showcfg_port =
6737         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6738 cmdline_parse_token_string_t cmd_showcfg_what =
6739         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6740                                  "rxtx#cores#fwd#txpkts");
6741
6742 cmdline_parse_inst_t cmd_showcfg = {
6743         .f = cmd_showcfg_parsed,
6744         .data = NULL,
6745         .help_str = "show config rxtx|cores|fwd|txpkts",
6746         .tokens = {
6747                 (void *)&cmd_showcfg_show,
6748                 (void *)&cmd_showcfg_port,
6749                 (void *)&cmd_showcfg_what,
6750                 NULL,
6751         },
6752 };
6753
6754 /* *** SHOW ALL PORT INFO *** */
6755 struct cmd_showportall_result {
6756         cmdline_fixed_string_t show;
6757         cmdline_fixed_string_t port;
6758         cmdline_fixed_string_t what;
6759         cmdline_fixed_string_t all;
6760 };
6761
6762 static void cmd_showportall_parsed(void *parsed_result,
6763                                 __attribute__((unused)) struct cmdline *cl,
6764                                 __attribute__((unused)) void *data)
6765 {
6766         portid_t i;
6767
6768         struct cmd_showportall_result *res = parsed_result;
6769         if (!strcmp(res->show, "clear")) {
6770                 if (!strcmp(res->what, "stats"))
6771                         RTE_ETH_FOREACH_DEV(i)
6772                                 nic_stats_clear(i);
6773                 else if (!strcmp(res->what, "xstats"))
6774                         RTE_ETH_FOREACH_DEV(i)
6775                                 nic_xstats_clear(i);
6776         } else if (!strcmp(res->what, "info"))
6777                 RTE_ETH_FOREACH_DEV(i)
6778                         port_infos_display(i);
6779         else if (!strcmp(res->what, "stats"))
6780                 RTE_ETH_FOREACH_DEV(i)
6781                         nic_stats_display(i);
6782         else if (!strcmp(res->what, "xstats"))
6783                 RTE_ETH_FOREACH_DEV(i)
6784                         nic_xstats_display(i);
6785         else if (!strcmp(res->what, "fdir"))
6786                 RTE_ETH_FOREACH_DEV(i)
6787                         fdir_get_infos(i);
6788         else if (!strcmp(res->what, "stat_qmap"))
6789                 RTE_ETH_FOREACH_DEV(i)
6790                         nic_stats_mapping_display(i);
6791         else if (!strcmp(res->what, "dcb_tc"))
6792                 RTE_ETH_FOREACH_DEV(i)
6793                         port_dcb_info_display(i);
6794         else if (!strcmp(res->what, "cap"))
6795                 RTE_ETH_FOREACH_DEV(i)
6796                         port_offload_cap_display(i);
6797 }
6798
6799 cmdline_parse_token_string_t cmd_showportall_show =
6800         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6801                                  "show#clear");
6802 cmdline_parse_token_string_t cmd_showportall_port =
6803         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6804 cmdline_parse_token_string_t cmd_showportall_what =
6805         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6806                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6807 cmdline_parse_token_string_t cmd_showportall_all =
6808         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6809 cmdline_parse_inst_t cmd_showportall = {
6810         .f = cmd_showportall_parsed,
6811         .data = NULL,
6812         .help_str = "show|clear port "
6813                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6814         .tokens = {
6815                 (void *)&cmd_showportall_show,
6816                 (void *)&cmd_showportall_port,
6817                 (void *)&cmd_showportall_what,
6818                 (void *)&cmd_showportall_all,
6819                 NULL,
6820         },
6821 };
6822
6823 /* *** SHOW PORT INFO *** */
6824 struct cmd_showport_result {
6825         cmdline_fixed_string_t show;
6826         cmdline_fixed_string_t port;
6827         cmdline_fixed_string_t what;
6828         uint16_t portnum;
6829 };
6830
6831 static void cmd_showport_parsed(void *parsed_result,
6832                                 __attribute__((unused)) struct cmdline *cl,
6833                                 __attribute__((unused)) void *data)
6834 {
6835         struct cmd_showport_result *res = parsed_result;
6836         if (!strcmp(res->show, "clear")) {
6837                 if (!strcmp(res->what, "stats"))
6838                         nic_stats_clear(res->portnum);
6839                 else if (!strcmp(res->what, "xstats"))
6840                         nic_xstats_clear(res->portnum);
6841         } else if (!strcmp(res->what, "info"))
6842                 port_infos_display(res->portnum);
6843         else if (!strcmp(res->what, "stats"))
6844                 nic_stats_display(res->portnum);
6845         else if (!strcmp(res->what, "xstats"))
6846                 nic_xstats_display(res->portnum);
6847         else if (!strcmp(res->what, "fdir"))
6848                  fdir_get_infos(res->portnum);
6849         else if (!strcmp(res->what, "stat_qmap"))
6850                 nic_stats_mapping_display(res->portnum);
6851         else if (!strcmp(res->what, "dcb_tc"))
6852                 port_dcb_info_display(res->portnum);
6853         else if (!strcmp(res->what, "cap"))
6854                 port_offload_cap_display(res->portnum);
6855 }
6856
6857 cmdline_parse_token_string_t cmd_showport_show =
6858         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6859                                  "show#clear");
6860 cmdline_parse_token_string_t cmd_showport_port =
6861         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6862 cmdline_parse_token_string_t cmd_showport_what =
6863         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6864                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6865 cmdline_parse_token_num_t cmd_showport_portnum =
6866         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6867
6868 cmdline_parse_inst_t cmd_showport = {
6869         .f = cmd_showport_parsed,
6870         .data = NULL,
6871         .help_str = "show|clear port "
6872                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6873                 "<port_id>",
6874         .tokens = {
6875                 (void *)&cmd_showport_show,
6876                 (void *)&cmd_showport_port,
6877                 (void *)&cmd_showport_what,
6878                 (void *)&cmd_showport_portnum,
6879                 NULL,
6880         },
6881 };
6882
6883 /* *** SHOW QUEUE INFO *** */
6884 struct cmd_showqueue_result {
6885         cmdline_fixed_string_t show;
6886         cmdline_fixed_string_t type;
6887         cmdline_fixed_string_t what;
6888         uint16_t portnum;
6889         uint16_t queuenum;
6890 };
6891
6892 static void
6893 cmd_showqueue_parsed(void *parsed_result,
6894         __attribute__((unused)) struct cmdline *cl,
6895         __attribute__((unused)) void *data)
6896 {
6897         struct cmd_showqueue_result *res = parsed_result;
6898
6899         if (!strcmp(res->type, "rxq"))
6900                 rx_queue_infos_display(res->portnum, res->queuenum);
6901         else if (!strcmp(res->type, "txq"))
6902                 tx_queue_infos_display(res->portnum, res->queuenum);
6903 }
6904
6905 cmdline_parse_token_string_t cmd_showqueue_show =
6906         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6907 cmdline_parse_token_string_t cmd_showqueue_type =
6908         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6909 cmdline_parse_token_string_t cmd_showqueue_what =
6910         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6911 cmdline_parse_token_num_t cmd_showqueue_portnum =
6912         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6913 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6914         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6915
6916 cmdline_parse_inst_t cmd_showqueue = {
6917         .f = cmd_showqueue_parsed,
6918         .data = NULL,
6919         .help_str = "show rxq|txq info <port_id> <queue_id>",
6920         .tokens = {
6921                 (void *)&cmd_showqueue_show,
6922                 (void *)&cmd_showqueue_type,
6923                 (void *)&cmd_showqueue_what,
6924                 (void *)&cmd_showqueue_portnum,
6925                 (void *)&cmd_showqueue_queuenum,
6926                 NULL,
6927         },
6928 };
6929
6930 /* *** READ PORT REGISTER *** */
6931 struct cmd_read_reg_result {
6932         cmdline_fixed_string_t read;
6933         cmdline_fixed_string_t reg;
6934         portid_t port_id;
6935         uint32_t reg_off;
6936 };
6937
6938 static void
6939 cmd_read_reg_parsed(void *parsed_result,
6940                     __attribute__((unused)) struct cmdline *cl,
6941                     __attribute__((unused)) void *data)
6942 {
6943         struct cmd_read_reg_result *res = parsed_result;
6944         port_reg_display(res->port_id, res->reg_off);
6945 }
6946
6947 cmdline_parse_token_string_t cmd_read_reg_read =
6948         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6949 cmdline_parse_token_string_t cmd_read_reg_reg =
6950         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6951 cmdline_parse_token_num_t cmd_read_reg_port_id =
6952         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6953 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6954         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6955
6956 cmdline_parse_inst_t cmd_read_reg = {
6957         .f = cmd_read_reg_parsed,
6958         .data = NULL,
6959         .help_str = "read reg <port_id> <reg_off>",
6960         .tokens = {
6961                 (void *)&cmd_read_reg_read,
6962                 (void *)&cmd_read_reg_reg,
6963                 (void *)&cmd_read_reg_port_id,
6964                 (void *)&cmd_read_reg_reg_off,
6965                 NULL,
6966         },
6967 };
6968
6969 /* *** READ PORT REGISTER BIT FIELD *** */
6970 struct cmd_read_reg_bit_field_result {
6971         cmdline_fixed_string_t read;
6972         cmdline_fixed_string_t regfield;
6973         portid_t port_id;
6974         uint32_t reg_off;
6975         uint8_t bit1_pos;
6976         uint8_t bit2_pos;
6977 };
6978
6979 static void
6980 cmd_read_reg_bit_field_parsed(void *parsed_result,
6981                               __attribute__((unused)) struct cmdline *cl,
6982                               __attribute__((unused)) void *data)
6983 {
6984         struct cmd_read_reg_bit_field_result *res = parsed_result;
6985         port_reg_bit_field_display(res->port_id, res->reg_off,
6986                                    res->bit1_pos, res->bit2_pos);
6987 }
6988
6989 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6990         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6991                                  "read");
6992 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6993         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6994                                  regfield, "regfield");
6995 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6996         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6997                               UINT16);
6998 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6999         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7000                               UINT32);
7001 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7002         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7003                               UINT8);
7004 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7005         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7006                               UINT8);
7007
7008 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7009         .f = cmd_read_reg_bit_field_parsed,
7010         .data = NULL,
7011         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7012         "Read register bit field between bit_x and bit_y included",
7013         .tokens = {
7014                 (void *)&cmd_read_reg_bit_field_read,
7015                 (void *)&cmd_read_reg_bit_field_regfield,
7016                 (void *)&cmd_read_reg_bit_field_port_id,
7017                 (void *)&cmd_read_reg_bit_field_reg_off,
7018                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7019                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7020                 NULL,
7021         },
7022 };
7023
7024 /* *** READ PORT REGISTER BIT *** */
7025 struct cmd_read_reg_bit_result {
7026         cmdline_fixed_string_t read;
7027         cmdline_fixed_string_t regbit;
7028         portid_t port_id;
7029         uint32_t reg_off;
7030         uint8_t bit_pos;
7031 };
7032
7033 static void
7034 cmd_read_reg_bit_parsed(void *parsed_result,
7035                         __attribute__((unused)) struct cmdline *cl,
7036                         __attribute__((unused)) void *data)
7037 {
7038         struct cmd_read_reg_bit_result *res = parsed_result;
7039         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7040 }
7041
7042 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7043         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7044 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7045         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7046                                  regbit, "regbit");
7047 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7048         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7049 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7050         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7051 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7052         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7053
7054 cmdline_parse_inst_t cmd_read_reg_bit = {
7055         .f = cmd_read_reg_bit_parsed,
7056         .data = NULL,
7057         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7058         .tokens = {
7059                 (void *)&cmd_read_reg_bit_read,
7060                 (void *)&cmd_read_reg_bit_regbit,
7061                 (void *)&cmd_read_reg_bit_port_id,
7062                 (void *)&cmd_read_reg_bit_reg_off,
7063                 (void *)&cmd_read_reg_bit_bit_pos,
7064                 NULL,
7065         },
7066 };
7067
7068 /* *** WRITE PORT REGISTER *** */
7069 struct cmd_write_reg_result {
7070         cmdline_fixed_string_t write;
7071         cmdline_fixed_string_t reg;
7072         portid_t port_id;
7073         uint32_t reg_off;
7074         uint32_t value;
7075 };
7076
7077 static void
7078 cmd_write_reg_parsed(void *parsed_result,
7079                      __attribute__((unused)) struct cmdline *cl,
7080                      __attribute__((unused)) void *data)
7081 {
7082         struct cmd_write_reg_result *res = parsed_result;
7083         port_reg_set(res->port_id, res->reg_off, res->value);
7084 }
7085
7086 cmdline_parse_token_string_t cmd_write_reg_write =
7087         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7088 cmdline_parse_token_string_t cmd_write_reg_reg =
7089         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7090 cmdline_parse_token_num_t cmd_write_reg_port_id =
7091         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7092 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7093         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7094 cmdline_parse_token_num_t cmd_write_reg_value =
7095         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7096
7097 cmdline_parse_inst_t cmd_write_reg = {
7098         .f = cmd_write_reg_parsed,
7099         .data = NULL,
7100         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7101         .tokens = {
7102                 (void *)&cmd_write_reg_write,
7103                 (void *)&cmd_write_reg_reg,
7104                 (void *)&cmd_write_reg_port_id,
7105                 (void *)&cmd_write_reg_reg_off,
7106                 (void *)&cmd_write_reg_value,
7107                 NULL,
7108         },
7109 };
7110
7111 /* *** WRITE PORT REGISTER BIT FIELD *** */
7112 struct cmd_write_reg_bit_field_result {
7113         cmdline_fixed_string_t write;
7114         cmdline_fixed_string_t regfield;
7115         portid_t port_id;
7116         uint32_t reg_off;
7117         uint8_t bit1_pos;
7118         uint8_t bit2_pos;
7119         uint32_t value;
7120 };
7121
7122 static void
7123 cmd_write_reg_bit_field_parsed(void *parsed_result,
7124                                __attribute__((unused)) struct cmdline *cl,
7125                                __attribute__((unused)) void *data)
7126 {
7127         struct cmd_write_reg_bit_field_result *res = parsed_result;
7128         port_reg_bit_field_set(res->port_id, res->reg_off,
7129                           res->bit1_pos, res->bit2_pos, res->value);
7130 }
7131
7132 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7133         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7134                                  "write");
7135 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7136         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7137                                  regfield, "regfield");
7138 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7139         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7140                               UINT16);
7141 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7142         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7143                               UINT32);
7144 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7145         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7146                               UINT8);
7147 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7148         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7149                               UINT8);
7150 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7151         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7152                               UINT32);
7153
7154 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7155         .f = cmd_write_reg_bit_field_parsed,
7156         .data = NULL,
7157         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7158                 "<reg_value>: "
7159                 "Set register bit field between bit_x and bit_y included",
7160         .tokens = {
7161                 (void *)&cmd_write_reg_bit_field_write,
7162                 (void *)&cmd_write_reg_bit_field_regfield,
7163                 (void *)&cmd_write_reg_bit_field_port_id,
7164                 (void *)&cmd_write_reg_bit_field_reg_off,
7165                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7166                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7167                 (void *)&cmd_write_reg_bit_field_value,
7168                 NULL,
7169         },
7170 };
7171
7172 /* *** WRITE PORT REGISTER BIT *** */
7173 struct cmd_write_reg_bit_result {
7174         cmdline_fixed_string_t write;
7175         cmdline_fixed_string_t regbit;
7176         portid_t port_id;
7177         uint32_t reg_off;
7178         uint8_t bit_pos;
7179         uint8_t value;
7180 };
7181
7182 static void
7183 cmd_write_reg_bit_parsed(void *parsed_result,
7184                          __attribute__((unused)) struct cmdline *cl,
7185                          __attribute__((unused)) void *data)
7186 {
7187         struct cmd_write_reg_bit_result *res = parsed_result;
7188         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7189 }
7190
7191 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7192         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7193                                  "write");
7194 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7195         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7196                                  regbit, "regbit");
7197 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7198         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7199 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7200         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7201 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7202         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7203 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7204         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7205
7206 cmdline_parse_inst_t cmd_write_reg_bit = {
7207         .f = cmd_write_reg_bit_parsed,
7208         .data = NULL,
7209         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7210                 "0 <= bit_x <= 31",
7211         .tokens = {
7212                 (void *)&cmd_write_reg_bit_write,
7213                 (void *)&cmd_write_reg_bit_regbit,
7214                 (void *)&cmd_write_reg_bit_port_id,
7215                 (void *)&cmd_write_reg_bit_reg_off,
7216                 (void *)&cmd_write_reg_bit_bit_pos,
7217                 (void *)&cmd_write_reg_bit_value,
7218                 NULL,
7219         },
7220 };
7221
7222 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7223 struct cmd_read_rxd_txd_result {
7224         cmdline_fixed_string_t read;
7225         cmdline_fixed_string_t rxd_txd;
7226         portid_t port_id;
7227         uint16_t queue_id;
7228         uint16_t desc_id;
7229 };
7230
7231 static void
7232 cmd_read_rxd_txd_parsed(void *parsed_result,
7233                         __attribute__((unused)) struct cmdline *cl,
7234                         __attribute__((unused)) void *data)
7235 {
7236         struct cmd_read_rxd_txd_result *res = parsed_result;
7237
7238         if (!strcmp(res->rxd_txd, "rxd"))
7239                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7240         else if (!strcmp(res->rxd_txd, "txd"))
7241                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7242 }
7243
7244 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7245         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7246 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7247         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7248                                  "rxd#txd");
7249 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7250         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7251 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7252         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7253 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7254         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7255
7256 cmdline_parse_inst_t cmd_read_rxd_txd = {
7257         .f = cmd_read_rxd_txd_parsed,
7258         .data = NULL,
7259         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7260         .tokens = {
7261                 (void *)&cmd_read_rxd_txd_read,
7262                 (void *)&cmd_read_rxd_txd_rxd_txd,
7263                 (void *)&cmd_read_rxd_txd_port_id,
7264                 (void *)&cmd_read_rxd_txd_queue_id,
7265                 (void *)&cmd_read_rxd_txd_desc_id,
7266                 NULL,
7267         },
7268 };
7269
7270 /* *** QUIT *** */
7271 struct cmd_quit_result {
7272         cmdline_fixed_string_t quit;
7273 };
7274
7275 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7276                             struct cmdline *cl,
7277                             __attribute__((unused)) void *data)
7278 {
7279         pmd_test_exit();
7280         cmdline_quit(cl);
7281 }
7282
7283 cmdline_parse_token_string_t cmd_quit_quit =
7284         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7285
7286 cmdline_parse_inst_t cmd_quit = {
7287         .f = cmd_quit_parsed,
7288         .data = NULL,
7289         .help_str = "quit: Exit application",
7290         .tokens = {
7291                 (void *)&cmd_quit_quit,
7292                 NULL,
7293         },
7294 };
7295
7296 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7297 struct cmd_mac_addr_result {
7298         cmdline_fixed_string_t mac_addr_cmd;
7299         cmdline_fixed_string_t what;
7300         uint16_t port_num;
7301         struct ether_addr address;
7302 };
7303
7304 static void cmd_mac_addr_parsed(void *parsed_result,
7305                 __attribute__((unused)) struct cmdline *cl,
7306                 __attribute__((unused)) void *data)
7307 {
7308         struct cmd_mac_addr_result *res = parsed_result;
7309         int ret;
7310
7311         if (strcmp(res->what, "add") == 0)
7312                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7313         else if (strcmp(res->what, "set") == 0)
7314                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7315                                                        &res->address);
7316         else
7317                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7318
7319         /* check the return value and print it if is < 0 */
7320         if(ret < 0)
7321                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7322
7323 }
7324
7325 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7326         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7327                                 "mac_addr");
7328 cmdline_parse_token_string_t cmd_mac_addr_what =
7329         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7330                                 "add#remove#set");
7331 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7332                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7333                                         UINT16);
7334 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7335                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7336
7337 cmdline_parse_inst_t cmd_mac_addr = {
7338         .f = cmd_mac_addr_parsed,
7339         .data = (void *)0,
7340         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7341                         "Add/Remove/Set MAC address on port_id",
7342         .tokens = {
7343                 (void *)&cmd_mac_addr_cmd,
7344                 (void *)&cmd_mac_addr_what,
7345                 (void *)&cmd_mac_addr_portnum,
7346                 (void *)&cmd_mac_addr_addr,
7347                 NULL,
7348         },
7349 };
7350
7351 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7352 struct cmd_eth_peer_result {
7353         cmdline_fixed_string_t set;
7354         cmdline_fixed_string_t eth_peer;
7355         portid_t port_id;
7356         cmdline_fixed_string_t peer_addr;
7357 };
7358
7359 static void cmd_set_eth_peer_parsed(void *parsed_result,
7360                         __attribute__((unused)) struct cmdline *cl,
7361                         __attribute__((unused)) void *data)
7362 {
7363                 struct cmd_eth_peer_result *res = parsed_result;
7364
7365                 if (test_done == 0) {
7366                         printf("Please stop forwarding first\n");
7367                         return;
7368                 }
7369                 if (!strcmp(res->eth_peer, "eth-peer")) {
7370                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7371                         fwd_config_setup();
7372                 }
7373 }
7374 cmdline_parse_token_string_t cmd_eth_peer_set =
7375         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7376 cmdline_parse_token_string_t cmd_eth_peer =
7377         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7378 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7379         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7380 cmdline_parse_token_string_t cmd_eth_peer_addr =
7381         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7382
7383 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7384         .f = cmd_set_eth_peer_parsed,
7385         .data = NULL,
7386         .help_str = "set eth-peer <port_id> <peer_mac>",
7387         .tokens = {
7388                 (void *)&cmd_eth_peer_set,
7389                 (void *)&cmd_eth_peer,
7390                 (void *)&cmd_eth_peer_port_id,
7391                 (void *)&cmd_eth_peer_addr,
7392                 NULL,
7393         },
7394 };
7395
7396 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7397 struct cmd_set_qmap_result {
7398         cmdline_fixed_string_t set;
7399         cmdline_fixed_string_t qmap;
7400         cmdline_fixed_string_t what;
7401         portid_t port_id;
7402         uint16_t queue_id;
7403         uint8_t map_value;
7404 };
7405
7406 static void
7407 cmd_set_qmap_parsed(void *parsed_result,
7408                        __attribute__((unused)) struct cmdline *cl,
7409                        __attribute__((unused)) void *data)
7410 {
7411         struct cmd_set_qmap_result *res = parsed_result;
7412         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7413
7414         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7415 }
7416
7417 cmdline_parse_token_string_t cmd_setqmap_set =
7418         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7419                                  set, "set");
7420 cmdline_parse_token_string_t cmd_setqmap_qmap =
7421         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7422                                  qmap, "stat_qmap");
7423 cmdline_parse_token_string_t cmd_setqmap_what =
7424         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7425                                  what, "tx#rx");
7426 cmdline_parse_token_num_t cmd_setqmap_portid =
7427         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7428                               port_id, UINT16);
7429 cmdline_parse_token_num_t cmd_setqmap_queueid =
7430         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7431                               queue_id, UINT16);
7432 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7433         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7434                               map_value, UINT8);
7435
7436 cmdline_parse_inst_t cmd_set_qmap = {
7437         .f = cmd_set_qmap_parsed,
7438         .data = NULL,
7439         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7440                 "Set statistics mapping value on tx|rx queue_id of port_id",
7441         .tokens = {
7442                 (void *)&cmd_setqmap_set,
7443                 (void *)&cmd_setqmap_qmap,
7444                 (void *)&cmd_setqmap_what,
7445                 (void *)&cmd_setqmap_portid,
7446                 (void *)&cmd_setqmap_queueid,
7447                 (void *)&cmd_setqmap_mapvalue,
7448                 NULL,
7449         },
7450 };
7451
7452 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7453 struct cmd_set_xstats_hide_zero_result {
7454         cmdline_fixed_string_t keyword;
7455         cmdline_fixed_string_t name;
7456         cmdline_fixed_string_t on_off;
7457 };
7458
7459 static void
7460 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7461                         __attribute__((unused)) struct cmdline *cl,
7462                         __attribute__((unused)) void *data)
7463 {
7464         struct cmd_set_xstats_hide_zero_result *res;
7465         uint16_t on_off = 0;
7466
7467         res = parsed_result;
7468         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7469         set_xstats_hide_zero(on_off);
7470 }
7471
7472 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7473         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7474                                  keyword, "set");
7475 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7476         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7477                                  name, "xstats-hide-zero");
7478 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7479         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7480                                  on_off, "on#off");
7481
7482 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7483         .f = cmd_set_xstats_hide_zero_parsed,
7484         .data = NULL,
7485         .help_str = "set xstats-hide-zero on|off",
7486         .tokens = {
7487                 (void *)&cmd_set_xstats_hide_zero_keyword,
7488                 (void *)&cmd_set_xstats_hide_zero_name,
7489                 (void *)&cmd_set_xstats_hide_zero_on_off,
7490                 NULL,
7491         },
7492 };
7493
7494 /* *** CONFIGURE UNICAST HASH TABLE *** */
7495 struct cmd_set_uc_hash_table {
7496         cmdline_fixed_string_t set;
7497         cmdline_fixed_string_t port;
7498         portid_t port_id;
7499         cmdline_fixed_string_t what;
7500         struct ether_addr address;
7501         cmdline_fixed_string_t mode;
7502 };
7503
7504 static void
7505 cmd_set_uc_hash_parsed(void *parsed_result,
7506                        __attribute__((unused)) struct cmdline *cl,
7507                        __attribute__((unused)) void *data)
7508 {
7509         int ret=0;
7510         struct cmd_set_uc_hash_table *res = parsed_result;
7511
7512         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7513
7514         if (strcmp(res->what, "uta") == 0)
7515                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7516                                                 &res->address,(uint8_t)is_on);
7517         if (ret < 0)
7518                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7519
7520 }
7521
7522 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7523         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7524                                  set, "set");
7525 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7526         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7527                                  port, "port");
7528 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7529         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7530                               port_id, UINT16);
7531 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7532         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7533                                  what, "uta");
7534 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7535         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7536                                 address);
7537 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7538         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7539                                  mode, "on#off");
7540
7541 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7542         .f = cmd_set_uc_hash_parsed,
7543         .data = NULL,
7544         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7545         .tokens = {
7546                 (void *)&cmd_set_uc_hash_set,
7547                 (void *)&cmd_set_uc_hash_port,
7548                 (void *)&cmd_set_uc_hash_portid,
7549                 (void *)&cmd_set_uc_hash_what,
7550                 (void *)&cmd_set_uc_hash_mac,
7551                 (void *)&cmd_set_uc_hash_mode,
7552                 NULL,
7553         },
7554 };
7555
7556 struct cmd_set_uc_all_hash_table {
7557         cmdline_fixed_string_t set;
7558         cmdline_fixed_string_t port;
7559         portid_t port_id;
7560         cmdline_fixed_string_t what;
7561         cmdline_fixed_string_t value;
7562         cmdline_fixed_string_t mode;
7563 };
7564
7565 static void
7566 cmd_set_uc_all_hash_parsed(void *parsed_result,
7567                        __attribute__((unused)) struct cmdline *cl,
7568                        __attribute__((unused)) void *data)
7569 {
7570         int ret=0;
7571         struct cmd_set_uc_all_hash_table *res = parsed_result;
7572
7573         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7574
7575         if ((strcmp(res->what, "uta") == 0) &&
7576                 (strcmp(res->value, "all") == 0))
7577                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7578         if (ret < 0)
7579                 printf("bad unicast hash table parameter,"
7580                         "return code = %d \n", ret);
7581 }
7582
7583 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7584         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7585                                  set, "set");
7586 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7587         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7588                                  port, "port");
7589 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7590         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7591                               port_id, UINT16);
7592 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7593         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7594                                  what, "uta");
7595 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7596         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7597                                 value,"all");
7598 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7599         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7600                                  mode, "on#off");
7601
7602 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7603         .f = cmd_set_uc_all_hash_parsed,
7604         .data = NULL,
7605         .help_str = "set port <port_id> uta all on|off",
7606         .tokens = {
7607                 (void *)&cmd_set_uc_all_hash_set,
7608                 (void *)&cmd_set_uc_all_hash_port,
7609                 (void *)&cmd_set_uc_all_hash_portid,
7610                 (void *)&cmd_set_uc_all_hash_what,
7611                 (void *)&cmd_set_uc_all_hash_value,
7612                 (void *)&cmd_set_uc_all_hash_mode,
7613                 NULL,
7614         },
7615 };
7616
7617 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7618 struct cmd_set_vf_macvlan_filter {
7619         cmdline_fixed_string_t set;
7620         cmdline_fixed_string_t port;
7621         portid_t port_id;
7622         cmdline_fixed_string_t vf;
7623         uint8_t vf_id;
7624         struct ether_addr address;
7625         cmdline_fixed_string_t filter_type;
7626         cmdline_fixed_string_t mode;
7627 };
7628
7629 static void
7630 cmd_set_vf_macvlan_parsed(void *parsed_result,
7631                        __attribute__((unused)) struct cmdline *cl,
7632                        __attribute__((unused)) void *data)
7633 {
7634         int is_on, ret = 0;
7635         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7636         struct rte_eth_mac_filter filter;
7637
7638         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7639
7640         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7641
7642         /* set VF MAC filter */
7643         filter.is_vf = 1;
7644
7645         /* set VF ID */
7646         filter.dst_id = res->vf_id;
7647
7648         if (!strcmp(res->filter_type, "exact-mac"))
7649                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7650         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7651                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7652         else if (!strcmp(res->filter_type, "hashmac"))
7653                 filter.filter_type = RTE_MAC_HASH_MATCH;
7654         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7655                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7656
7657         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7658
7659         if (is_on)
7660                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7661                                         RTE_ETH_FILTER_MACVLAN,
7662                                         RTE_ETH_FILTER_ADD,
7663                                          &filter);
7664         else
7665                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7666                                         RTE_ETH_FILTER_MACVLAN,
7667                                         RTE_ETH_FILTER_DELETE,
7668                                         &filter);
7669
7670         if (ret < 0)
7671                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7672
7673 }
7674
7675 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7676         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7677                                  set, "set");
7678 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7679         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7680                                  port, "port");
7681 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7682         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7683                               port_id, UINT16);
7684 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7685         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7686                                  vf, "vf");
7687 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7688         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7689                                 vf_id, UINT8);
7690 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7691         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7692                                 address);
7693 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7694         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7695                                 filter_type, "exact-mac#exact-mac-vlan"
7696                                 "#hashmac#hashmac-vlan");
7697 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7698         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7699                                  mode, "on#off");
7700
7701 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7702         .f = cmd_set_vf_macvlan_parsed,
7703         .data = NULL,
7704         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7705                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7706                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7707                 "hash match rule: hash match of MAC and exact match of VLAN",
7708         .tokens = {
7709                 (void *)&cmd_set_vf_macvlan_set,
7710                 (void *)&cmd_set_vf_macvlan_port,
7711                 (void *)&cmd_set_vf_macvlan_portid,
7712                 (void *)&cmd_set_vf_macvlan_vf,
7713                 (void *)&cmd_set_vf_macvlan_vf_id,
7714                 (void *)&cmd_set_vf_macvlan_mac,
7715                 (void *)&cmd_set_vf_macvlan_filter_type,
7716                 (void *)&cmd_set_vf_macvlan_mode,
7717                 NULL,
7718         },
7719 };
7720
7721 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7722 struct cmd_set_vf_traffic {
7723         cmdline_fixed_string_t set;
7724         cmdline_fixed_string_t port;
7725         portid_t port_id;
7726         cmdline_fixed_string_t vf;
7727         uint8_t vf_id;
7728         cmdline_fixed_string_t what;
7729         cmdline_fixed_string_t mode;
7730 };
7731
7732 static void
7733 cmd_set_vf_traffic_parsed(void *parsed_result,
7734                        __attribute__((unused)) struct cmdline *cl,
7735                        __attribute__((unused)) void *data)
7736 {
7737         struct cmd_set_vf_traffic *res = parsed_result;
7738         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7739         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7740
7741         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7742 }
7743
7744 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7745         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7746                                  set, "set");
7747 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7748         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7749                                  port, "port");
7750 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7751         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7752                               port_id, UINT16);
7753 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7754         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7755                                  vf, "vf");
7756 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7757         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7758                               vf_id, UINT8);
7759 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7760         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7761                                  what, "tx#rx");
7762 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7763         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7764                                  mode, "on#off");
7765
7766 cmdline_parse_inst_t cmd_set_vf_traffic = {
7767         .f = cmd_set_vf_traffic_parsed,
7768         .data = NULL,
7769         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7770         .tokens = {
7771                 (void *)&cmd_setvf_traffic_set,
7772                 (void *)&cmd_setvf_traffic_port,
7773                 (void *)&cmd_setvf_traffic_portid,
7774                 (void *)&cmd_setvf_traffic_vf,
7775                 (void *)&cmd_setvf_traffic_vfid,
7776                 (void *)&cmd_setvf_traffic_what,
7777                 (void *)&cmd_setvf_traffic_mode,
7778                 NULL,
7779         },
7780 };
7781
7782 /* *** CONFIGURE VF RECEIVE MODE *** */
7783 struct cmd_set_vf_rxmode {
7784         cmdline_fixed_string_t set;
7785         cmdline_fixed_string_t port;
7786         portid_t port_id;
7787         cmdline_fixed_string_t vf;
7788         uint8_t vf_id;
7789         cmdline_fixed_string_t what;
7790         cmdline_fixed_string_t mode;
7791         cmdline_fixed_string_t on;
7792 };
7793
7794 static void
7795 cmd_set_vf_rxmode_parsed(void *parsed_result,
7796                        __attribute__((unused)) struct cmdline *cl,
7797                        __attribute__((unused)) void *data)
7798 {
7799         int ret = -ENOTSUP;
7800         uint16_t rx_mode = 0;
7801         struct cmd_set_vf_rxmode *res = parsed_result;
7802
7803         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7804         if (!strcmp(res->what,"rxmode")) {
7805                 if (!strcmp(res->mode, "AUPE"))
7806                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7807                 else if (!strcmp(res->mode, "ROPE"))
7808                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7809                 else if (!strcmp(res->mode, "BAM"))
7810                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7811                 else if (!strncmp(res->mode, "MPE",3))
7812                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7813         }
7814
7815         RTE_SET_USED(is_on);
7816
7817 #ifdef RTE_LIBRTE_IXGBE_PMD
7818         if (ret == -ENOTSUP)
7819                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7820                                                   rx_mode, (uint8_t)is_on);
7821 #endif
7822 #ifdef RTE_LIBRTE_BNXT_PMD
7823         if (ret == -ENOTSUP)
7824                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7825                                                  rx_mode, (uint8_t)is_on);
7826 #endif
7827         if (ret < 0)
7828                 printf("bad VF receive mode parameter, return code = %d \n",
7829                 ret);
7830 }
7831
7832 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7833         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7834                                  set, "set");
7835 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7836         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7837                                  port, "port");
7838 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7839         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7840                               port_id, UINT16);
7841 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7842         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7843                                  vf, "vf");
7844 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7845         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7846                               vf_id, UINT8);
7847 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7848         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7849                                  what, "rxmode");
7850 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7851         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7852                                  mode, "AUPE#ROPE#BAM#MPE");
7853 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7854         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7855                                  on, "on#off");
7856
7857 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7858         .f = cmd_set_vf_rxmode_parsed,
7859         .data = NULL,
7860         .help_str = "set port <port_id> vf <vf_id> rxmode "
7861                 "AUPE|ROPE|BAM|MPE on|off",
7862         .tokens = {
7863                 (void *)&cmd_set_vf_rxmode_set,
7864                 (void *)&cmd_set_vf_rxmode_port,
7865                 (void *)&cmd_set_vf_rxmode_portid,
7866                 (void *)&cmd_set_vf_rxmode_vf,
7867                 (void *)&cmd_set_vf_rxmode_vfid,
7868                 (void *)&cmd_set_vf_rxmode_what,
7869                 (void *)&cmd_set_vf_rxmode_mode,
7870                 (void *)&cmd_set_vf_rxmode_on,
7871                 NULL,
7872         },
7873 };
7874
7875 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7876 struct cmd_vf_mac_addr_result {
7877         cmdline_fixed_string_t mac_addr_cmd;
7878         cmdline_fixed_string_t what;
7879         cmdline_fixed_string_t port;
7880         uint16_t port_num;
7881         cmdline_fixed_string_t vf;
7882         uint8_t vf_num;
7883         struct ether_addr address;
7884 };
7885
7886 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7887                 __attribute__((unused)) struct cmdline *cl,
7888                 __attribute__((unused)) void *data)
7889 {
7890         struct cmd_vf_mac_addr_result *res = parsed_result;
7891         int ret = -ENOTSUP;
7892
7893         if (strcmp(res->what, "add") != 0)
7894                 return;
7895
7896 #ifdef RTE_LIBRTE_I40E_PMD
7897         if (ret == -ENOTSUP)
7898                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7899                                                    &res->address);
7900 #endif
7901 #ifdef RTE_LIBRTE_BNXT_PMD
7902         if (ret == -ENOTSUP)
7903                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7904                                                 res->vf_num);
7905 #endif
7906
7907         if(ret < 0)
7908                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7909
7910 }
7911
7912 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7913         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7914                                 mac_addr_cmd,"mac_addr");
7915 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7916         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7917                                 what,"add");
7918 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7919         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7920                                 port,"port");
7921 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7922         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7923                                 port_num, UINT16);
7924 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7925         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7926                                 vf,"vf");
7927 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7928         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7929                                 vf_num, UINT8);
7930 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7931         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7932                                 address);
7933
7934 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7935         .f = cmd_vf_mac_addr_parsed,
7936         .data = (void *)0,
7937         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7938                 "Add MAC address filtering for a VF on port_id",
7939         .tokens = {
7940                 (void *)&cmd_vf_mac_addr_cmd,
7941                 (void *)&cmd_vf_mac_addr_what,
7942                 (void *)&cmd_vf_mac_addr_port,
7943                 (void *)&cmd_vf_mac_addr_portnum,
7944                 (void *)&cmd_vf_mac_addr_vf,
7945                 (void *)&cmd_vf_mac_addr_vfnum,
7946                 (void *)&cmd_vf_mac_addr_addr,
7947                 NULL,
7948         },
7949 };
7950
7951 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7952 struct cmd_vf_rx_vlan_filter {
7953         cmdline_fixed_string_t rx_vlan;
7954         cmdline_fixed_string_t what;
7955         uint16_t vlan_id;
7956         cmdline_fixed_string_t port;
7957         portid_t port_id;
7958         cmdline_fixed_string_t vf;
7959         uint64_t vf_mask;
7960 };
7961
7962 static void
7963 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7964                           __attribute__((unused)) struct cmdline *cl,
7965                           __attribute__((unused)) void *data)
7966 {
7967         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7968         int ret = -ENOTSUP;
7969
7970         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7971
7972 #ifdef RTE_LIBRTE_IXGBE_PMD
7973         if (ret == -ENOTSUP)
7974                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7975                                 res->vlan_id, res->vf_mask, is_add);
7976 #endif
7977 #ifdef RTE_LIBRTE_I40E_PMD
7978         if (ret == -ENOTSUP)
7979                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7980                                 res->vlan_id, res->vf_mask, is_add);
7981 #endif
7982 #ifdef RTE_LIBRTE_BNXT_PMD
7983         if (ret == -ENOTSUP)
7984                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7985                                 res->vlan_id, res->vf_mask, is_add);
7986 #endif
7987
7988         switch (ret) {
7989         case 0:
7990                 break;
7991         case -EINVAL:
7992                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7993                                 res->vlan_id, res->vf_mask);
7994                 break;
7995         case -ENODEV:
7996                 printf("invalid port_id %d\n", res->port_id);
7997                 break;
7998         case -ENOTSUP:
7999                 printf("function not implemented or supported\n");
8000                 break;
8001         default:
8002                 printf("programming error: (%s)\n", strerror(-ret));
8003         }
8004 }
8005
8006 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8007         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8008                                  rx_vlan, "rx_vlan");
8009 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8010         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8011                                  what, "add#rm");
8012 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8013         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8014                               vlan_id, UINT16);
8015 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8016         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8017                                  port, "port");
8018 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8019         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8020                               port_id, UINT16);
8021 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8022         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8023                                  vf, "vf");
8024 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8025         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8026                               vf_mask, UINT64);
8027
8028 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8029         .f = cmd_vf_rx_vlan_filter_parsed,
8030         .data = NULL,
8031         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8032                 "(vf_mask = hexadecimal VF mask)",
8033         .tokens = {
8034                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8035                 (void *)&cmd_vf_rx_vlan_filter_what,
8036                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8037                 (void *)&cmd_vf_rx_vlan_filter_port,
8038                 (void *)&cmd_vf_rx_vlan_filter_portid,
8039                 (void *)&cmd_vf_rx_vlan_filter_vf,
8040                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8041                 NULL,
8042         },
8043 };
8044
8045 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8046 struct cmd_queue_rate_limit_result {
8047         cmdline_fixed_string_t set;
8048         cmdline_fixed_string_t port;
8049         uint16_t port_num;
8050         cmdline_fixed_string_t queue;
8051         uint8_t queue_num;
8052         cmdline_fixed_string_t rate;
8053         uint16_t rate_num;
8054 };
8055
8056 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8057                 __attribute__((unused)) struct cmdline *cl,
8058                 __attribute__((unused)) void *data)
8059 {
8060         struct cmd_queue_rate_limit_result *res = parsed_result;
8061         int ret = 0;
8062
8063         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8064                 && (strcmp(res->queue, "queue") == 0)
8065                 && (strcmp(res->rate, "rate") == 0))
8066                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8067                                         res->rate_num);
8068         if (ret < 0)
8069                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8070
8071 }
8072
8073 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8074         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8075                                 set, "set");
8076 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8077         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8078                                 port, "port");
8079 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8080         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8081                                 port_num, UINT16);
8082 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8083         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8084                                 queue, "queue");
8085 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8086         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8087                                 queue_num, UINT8);
8088 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8089         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8090                                 rate, "rate");
8091 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8092         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8093                                 rate_num, UINT16);
8094
8095 cmdline_parse_inst_t cmd_queue_rate_limit = {
8096         .f = cmd_queue_rate_limit_parsed,
8097         .data = (void *)0,
8098         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8099                 "Set rate limit for a queue on port_id",
8100         .tokens = {
8101                 (void *)&cmd_queue_rate_limit_set,
8102                 (void *)&cmd_queue_rate_limit_port,
8103                 (void *)&cmd_queue_rate_limit_portnum,
8104                 (void *)&cmd_queue_rate_limit_queue,
8105                 (void *)&cmd_queue_rate_limit_queuenum,
8106                 (void *)&cmd_queue_rate_limit_rate,
8107                 (void *)&cmd_queue_rate_limit_ratenum,
8108                 NULL,
8109         },
8110 };
8111
8112 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8113 struct cmd_vf_rate_limit_result {
8114         cmdline_fixed_string_t set;
8115         cmdline_fixed_string_t port;
8116         uint16_t port_num;
8117         cmdline_fixed_string_t vf;
8118         uint8_t vf_num;
8119         cmdline_fixed_string_t rate;
8120         uint16_t rate_num;
8121         cmdline_fixed_string_t q_msk;
8122         uint64_t q_msk_val;
8123 };
8124
8125 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8126                 __attribute__((unused)) struct cmdline *cl,
8127                 __attribute__((unused)) void *data)
8128 {
8129         struct cmd_vf_rate_limit_result *res = parsed_result;
8130         int ret = 0;
8131
8132         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8133                 && (strcmp(res->vf, "vf") == 0)
8134                 && (strcmp(res->rate, "rate") == 0)
8135                 && (strcmp(res->q_msk, "queue_mask") == 0))
8136                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8137                                         res->rate_num, res->q_msk_val);
8138         if (ret < 0)
8139                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8140
8141 }
8142
8143 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8144         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8145                                 set, "set");
8146 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8147         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8148                                 port, "port");
8149 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8150         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8151                                 port_num, UINT16);
8152 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8153         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8154                                 vf, "vf");
8155 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8156         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8157                                 vf_num, UINT8);
8158 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8159         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8160                                 rate, "rate");
8161 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8162         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8163                                 rate_num, UINT16);
8164 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8165         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8166                                 q_msk, "queue_mask");
8167 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8168         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8169                                 q_msk_val, UINT64);
8170
8171 cmdline_parse_inst_t cmd_vf_rate_limit = {
8172         .f = cmd_vf_rate_limit_parsed,
8173         .data = (void *)0,
8174         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8175                 "queue_mask <queue_mask_value>: "
8176                 "Set rate limit for queues of VF on port_id",
8177         .tokens = {
8178                 (void *)&cmd_vf_rate_limit_set,
8179                 (void *)&cmd_vf_rate_limit_port,
8180                 (void *)&cmd_vf_rate_limit_portnum,
8181                 (void *)&cmd_vf_rate_limit_vf,
8182                 (void *)&cmd_vf_rate_limit_vfnum,
8183                 (void *)&cmd_vf_rate_limit_rate,
8184                 (void *)&cmd_vf_rate_limit_ratenum,
8185                 (void *)&cmd_vf_rate_limit_q_msk,
8186                 (void *)&cmd_vf_rate_limit_q_msk_val,
8187                 NULL,
8188         },
8189 };
8190
8191 /* *** ADD TUNNEL FILTER OF A PORT *** */
8192 struct cmd_tunnel_filter_result {
8193         cmdline_fixed_string_t cmd;
8194         cmdline_fixed_string_t what;
8195         portid_t port_id;
8196         struct ether_addr outer_mac;
8197         struct ether_addr inner_mac;
8198         cmdline_ipaddr_t ip_value;
8199         uint16_t inner_vlan;
8200         cmdline_fixed_string_t tunnel_type;
8201         cmdline_fixed_string_t filter_type;
8202         uint32_t tenant_id;
8203         uint16_t queue_num;
8204 };
8205
8206 static void
8207 cmd_tunnel_filter_parsed(void *parsed_result,
8208                           __attribute__((unused)) struct cmdline *cl,
8209                           __attribute__((unused)) void *data)
8210 {
8211         struct cmd_tunnel_filter_result *res = parsed_result;
8212         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8213         int ret = 0;
8214
8215         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8216
8217         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8218         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8219         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8220
8221         if (res->ip_value.family == AF_INET) {
8222                 tunnel_filter_conf.ip_addr.ipv4_addr =
8223                         res->ip_value.addr.ipv4.s_addr;
8224                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8225         } else {
8226                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8227                         &(res->ip_value.addr.ipv6),
8228                         sizeof(struct in6_addr));
8229                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8230         }
8231
8232         if (!strcmp(res->filter_type, "imac-ivlan"))
8233                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8234         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8235                 tunnel_filter_conf.filter_type =
8236                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8237         else if (!strcmp(res->filter_type, "imac-tenid"))
8238                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8239         else if (!strcmp(res->filter_type, "imac"))
8240                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8241         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8242                 tunnel_filter_conf.filter_type =
8243                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8244         else if (!strcmp(res->filter_type, "oip"))
8245                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8246         else if (!strcmp(res->filter_type, "iip"))
8247                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8248         else {
8249                 printf("The filter type is not supported");
8250                 return;
8251         }
8252
8253         if (!strcmp(res->tunnel_type, "vxlan"))
8254                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8255         else if (!strcmp(res->tunnel_type, "nvgre"))
8256                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8257         else if (!strcmp(res->tunnel_type, "ipingre"))
8258                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8259         else {
8260                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8261                 return;
8262         }
8263
8264         tunnel_filter_conf.tenant_id = res->tenant_id;
8265         tunnel_filter_conf.queue_id = res->queue_num;
8266         if (!strcmp(res->what, "add"))
8267                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8268                                         RTE_ETH_FILTER_TUNNEL,
8269                                         RTE_ETH_FILTER_ADD,
8270                                         &tunnel_filter_conf);
8271         else
8272                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8273                                         RTE_ETH_FILTER_TUNNEL,
8274                                         RTE_ETH_FILTER_DELETE,
8275                                         &tunnel_filter_conf);
8276         if (ret < 0)
8277                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8278                                 strerror(-ret));
8279
8280 }
8281 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8282         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8283         cmd, "tunnel_filter");
8284 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8285         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8286         what, "add#rm");
8287 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8288         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8289         port_id, UINT16);
8290 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8291         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8292         outer_mac);
8293 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8294         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8295         inner_mac);
8296 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8297         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8298         inner_vlan, UINT16);
8299 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8300         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8301         ip_value);
8302 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8303         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8304         tunnel_type, "vxlan#nvgre#ipingre");
8305
8306 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8307         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8308         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8309                 "imac#omac-imac-tenid");
8310 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8311         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8312         tenant_id, UINT32);
8313 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8314         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8315         queue_num, UINT16);
8316
8317 cmdline_parse_inst_t cmd_tunnel_filter = {
8318         .f = cmd_tunnel_filter_parsed,
8319         .data = (void *)0,
8320         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8321                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8322                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8323                 "<queue_id>: Add/Rm tunnel filter of a port",
8324         .tokens = {
8325                 (void *)&cmd_tunnel_filter_cmd,
8326                 (void *)&cmd_tunnel_filter_what,
8327                 (void *)&cmd_tunnel_filter_port_id,
8328                 (void *)&cmd_tunnel_filter_outer_mac,
8329                 (void *)&cmd_tunnel_filter_inner_mac,
8330                 (void *)&cmd_tunnel_filter_ip_value,
8331                 (void *)&cmd_tunnel_filter_innner_vlan,
8332                 (void *)&cmd_tunnel_filter_tunnel_type,
8333                 (void *)&cmd_tunnel_filter_filter_type,
8334                 (void *)&cmd_tunnel_filter_tenant_id,
8335                 (void *)&cmd_tunnel_filter_queue_num,
8336                 NULL,
8337         },
8338 };
8339
8340 /* *** CONFIGURE TUNNEL UDP PORT *** */
8341 struct cmd_tunnel_udp_config {
8342         cmdline_fixed_string_t cmd;
8343         cmdline_fixed_string_t what;
8344         uint16_t udp_port;
8345         portid_t port_id;
8346 };
8347
8348 static void
8349 cmd_tunnel_udp_config_parsed(void *parsed_result,
8350                           __attribute__((unused)) struct cmdline *cl,
8351                           __attribute__((unused)) void *data)
8352 {
8353         struct cmd_tunnel_udp_config *res = parsed_result;
8354         struct rte_eth_udp_tunnel tunnel_udp;
8355         int ret;
8356
8357         tunnel_udp.udp_port = res->udp_port;
8358
8359         if (!strcmp(res->cmd, "rx_vxlan_port"))
8360                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8361
8362         if (!strcmp(res->what, "add"))
8363                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8364                                                       &tunnel_udp);
8365         else
8366                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8367                                                          &tunnel_udp);
8368
8369         if (ret < 0)
8370                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8371 }
8372
8373 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8374         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8375                                 cmd, "rx_vxlan_port");
8376 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8377         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8378                                 what, "add#rm");
8379 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8380         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8381                                 udp_port, UINT16);
8382 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8383         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8384                                 port_id, UINT16);
8385
8386 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8387         .f = cmd_tunnel_udp_config_parsed,
8388         .data = (void *)0,
8389         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8390                 "Add/Remove a tunneling UDP port filter",
8391         .tokens = {
8392                 (void *)&cmd_tunnel_udp_config_cmd,
8393                 (void *)&cmd_tunnel_udp_config_what,
8394                 (void *)&cmd_tunnel_udp_config_udp_port,
8395                 (void *)&cmd_tunnel_udp_config_port_id,
8396                 NULL,
8397         },
8398 };
8399
8400 /* *** GLOBAL CONFIG *** */
8401 struct cmd_global_config_result {
8402         cmdline_fixed_string_t cmd;
8403         portid_t port_id;
8404         cmdline_fixed_string_t cfg_type;
8405         uint8_t len;
8406 };
8407
8408 static void
8409 cmd_global_config_parsed(void *parsed_result,
8410                          __attribute__((unused)) struct cmdline *cl,
8411                          __attribute__((unused)) void *data)
8412 {
8413         struct cmd_global_config_result *res = parsed_result;
8414         struct rte_eth_global_cfg conf;
8415         int ret;
8416
8417         memset(&conf, 0, sizeof(conf));
8418         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8419         conf.cfg.gre_key_len = res->len;
8420         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8421                                       RTE_ETH_FILTER_SET, &conf);
8422         if (ret != 0)
8423                 printf("Global config error\n");
8424 }
8425
8426 cmdline_parse_token_string_t cmd_global_config_cmd =
8427         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8428                 "global_config");
8429 cmdline_parse_token_num_t cmd_global_config_port_id =
8430         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8431                                UINT16);
8432 cmdline_parse_token_string_t cmd_global_config_type =
8433         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8434                 cfg_type, "gre-key-len");
8435 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8436         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8437                 len, UINT8);
8438
8439 cmdline_parse_inst_t cmd_global_config = {
8440         .f = cmd_global_config_parsed,
8441         .data = (void *)NULL,
8442         .help_str = "global_config <port_id> gre-key-len <key_len>",
8443         .tokens = {
8444                 (void *)&cmd_global_config_cmd,
8445                 (void *)&cmd_global_config_port_id,
8446                 (void *)&cmd_global_config_type,
8447                 (void *)&cmd_global_config_gre_key_len,
8448                 NULL,
8449         },
8450 };
8451
8452 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8453 struct cmd_set_mirror_mask_result {
8454         cmdline_fixed_string_t set;
8455         cmdline_fixed_string_t port;
8456         portid_t port_id;
8457         cmdline_fixed_string_t mirror;
8458         uint8_t rule_id;
8459         cmdline_fixed_string_t what;
8460         cmdline_fixed_string_t value;
8461         cmdline_fixed_string_t dstpool;
8462         uint8_t dstpool_id;
8463         cmdline_fixed_string_t on;
8464 };
8465
8466 cmdline_parse_token_string_t cmd_mirror_mask_set =
8467         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8468                                 set, "set");
8469 cmdline_parse_token_string_t cmd_mirror_mask_port =
8470         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8471                                 port, "port");
8472 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8473         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8474                                 port_id, UINT16);
8475 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8476         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8477                                 mirror, "mirror-rule");
8478 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8479         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8480                                 rule_id, UINT8);
8481 cmdline_parse_token_string_t cmd_mirror_mask_what =
8482         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8483                                 what, "pool-mirror-up#pool-mirror-down"
8484                                       "#vlan-mirror");
8485 cmdline_parse_token_string_t cmd_mirror_mask_value =
8486         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8487                                 value, NULL);
8488 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8489         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8490                                 dstpool, "dst-pool");
8491 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8492         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8493                                 dstpool_id, UINT8);
8494 cmdline_parse_token_string_t cmd_mirror_mask_on =
8495         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8496                                 on, "on#off");
8497
8498 static void
8499 cmd_set_mirror_mask_parsed(void *parsed_result,
8500                        __attribute__((unused)) struct cmdline *cl,
8501                        __attribute__((unused)) void *data)
8502 {
8503         int ret,nb_item,i;
8504         struct cmd_set_mirror_mask_result *res = parsed_result;
8505         struct rte_eth_mirror_conf mr_conf;
8506
8507         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8508
8509         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8510
8511         mr_conf.dst_pool = res->dstpool_id;
8512
8513         if (!strcmp(res->what, "pool-mirror-up")) {
8514                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8515                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8516         } else if (!strcmp(res->what, "pool-mirror-down")) {
8517                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8518                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8519         } else if (!strcmp(res->what, "vlan-mirror")) {
8520                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8521                 nb_item = parse_item_list(res->value, "vlan",
8522                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8523                 if (nb_item <= 0)
8524                         return;
8525
8526                 for (i = 0; i < nb_item; i++) {
8527                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8528                                 printf("Invalid vlan_id: must be < 4096\n");
8529                                 return;
8530                         }
8531
8532                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8533                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8534                 }
8535         }
8536
8537         if (!strcmp(res->on, "on"))
8538                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8539                                                 res->rule_id, 1);
8540         else
8541                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8542                                                 res->rule_id, 0);
8543         if (ret < 0)
8544                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8545 }
8546
8547 cmdline_parse_inst_t cmd_set_mirror_mask = {
8548                 .f = cmd_set_mirror_mask_parsed,
8549                 .data = NULL,
8550                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8551                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8552                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8553                 .tokens = {
8554                         (void *)&cmd_mirror_mask_set,
8555                         (void *)&cmd_mirror_mask_port,
8556                         (void *)&cmd_mirror_mask_portid,
8557                         (void *)&cmd_mirror_mask_mirror,
8558                         (void *)&cmd_mirror_mask_ruleid,
8559                         (void *)&cmd_mirror_mask_what,
8560                         (void *)&cmd_mirror_mask_value,
8561                         (void *)&cmd_mirror_mask_dstpool,
8562                         (void *)&cmd_mirror_mask_poolid,
8563                         (void *)&cmd_mirror_mask_on,
8564                         NULL,
8565                 },
8566 };
8567
8568 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8569 struct cmd_set_mirror_link_result {
8570         cmdline_fixed_string_t set;
8571         cmdline_fixed_string_t port;
8572         portid_t port_id;
8573         cmdline_fixed_string_t mirror;
8574         uint8_t rule_id;
8575         cmdline_fixed_string_t what;
8576         cmdline_fixed_string_t dstpool;
8577         uint8_t dstpool_id;
8578         cmdline_fixed_string_t on;
8579 };
8580
8581 cmdline_parse_token_string_t cmd_mirror_link_set =
8582         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8583                                  set, "set");
8584 cmdline_parse_token_string_t cmd_mirror_link_port =
8585         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8586                                 port, "port");
8587 cmdline_parse_token_num_t cmd_mirror_link_portid =
8588         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8589                                 port_id, UINT16);
8590 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8591         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8592                                 mirror, "mirror-rule");
8593 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8594         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8595                             rule_id, UINT8);
8596 cmdline_parse_token_string_t cmd_mirror_link_what =
8597         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8598                                 what, "uplink-mirror#downlink-mirror");
8599 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8600         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8601                                 dstpool, "dst-pool");
8602 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8603         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8604                                 dstpool_id, UINT8);
8605 cmdline_parse_token_string_t cmd_mirror_link_on =
8606         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8607                                 on, "on#off");
8608
8609 static void
8610 cmd_set_mirror_link_parsed(void *parsed_result,
8611                        __attribute__((unused)) struct cmdline *cl,
8612                        __attribute__((unused)) void *data)
8613 {
8614         int ret;
8615         struct cmd_set_mirror_link_result *res = parsed_result;
8616         struct rte_eth_mirror_conf mr_conf;
8617
8618         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8619         if (!strcmp(res->what, "uplink-mirror"))
8620                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8621         else
8622                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8623
8624         mr_conf.dst_pool = res->dstpool_id;
8625
8626         if (!strcmp(res->on, "on"))
8627                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8628                                                 res->rule_id, 1);
8629         else
8630                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8631                                                 res->rule_id, 0);
8632
8633         /* check the return value and print it if is < 0 */
8634         if (ret < 0)
8635                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8636
8637 }
8638
8639 cmdline_parse_inst_t cmd_set_mirror_link = {
8640                 .f = cmd_set_mirror_link_parsed,
8641                 .data = NULL,
8642                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8643                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8644                 .tokens = {
8645                         (void *)&cmd_mirror_link_set,
8646                         (void *)&cmd_mirror_link_port,
8647                         (void *)&cmd_mirror_link_portid,
8648                         (void *)&cmd_mirror_link_mirror,
8649                         (void *)&cmd_mirror_link_ruleid,
8650                         (void *)&cmd_mirror_link_what,
8651                         (void *)&cmd_mirror_link_dstpool,
8652                         (void *)&cmd_mirror_link_poolid,
8653                         (void *)&cmd_mirror_link_on,
8654                         NULL,
8655                 },
8656 };
8657
8658 /* *** RESET VM MIRROR RULE *** */
8659 struct cmd_rm_mirror_rule_result {
8660         cmdline_fixed_string_t reset;
8661         cmdline_fixed_string_t port;
8662         portid_t port_id;
8663         cmdline_fixed_string_t mirror;
8664         uint8_t rule_id;
8665 };
8666
8667 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8668         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8669                                  reset, "reset");
8670 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8671         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8672                                 port, "port");
8673 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8674         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8675                                 port_id, UINT16);
8676 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8677         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8678                                 mirror, "mirror-rule");
8679 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8680         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8681                                 rule_id, UINT8);
8682
8683 static void
8684 cmd_reset_mirror_rule_parsed(void *parsed_result,
8685                        __attribute__((unused)) struct cmdline *cl,
8686                        __attribute__((unused)) void *data)
8687 {
8688         int ret;
8689         struct cmd_set_mirror_link_result *res = parsed_result;
8690         /* check rule_id */
8691         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8692         if(ret < 0)
8693                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8694 }
8695
8696 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8697                 .f = cmd_reset_mirror_rule_parsed,
8698                 .data = NULL,
8699                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8700                 .tokens = {
8701                         (void *)&cmd_rm_mirror_rule_reset,
8702                         (void *)&cmd_rm_mirror_rule_port,
8703                         (void *)&cmd_rm_mirror_rule_portid,
8704                         (void *)&cmd_rm_mirror_rule_mirror,
8705                         (void *)&cmd_rm_mirror_rule_ruleid,
8706                         NULL,
8707                 },
8708 };
8709
8710 /* ******************************************************************************** */
8711
8712 struct cmd_dump_result {
8713         cmdline_fixed_string_t dump;
8714 };
8715
8716 static void
8717 dump_struct_sizes(void)
8718 {
8719 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8720         DUMP_SIZE(struct rte_mbuf);
8721         DUMP_SIZE(struct rte_mempool);
8722         DUMP_SIZE(struct rte_ring);
8723 #undef DUMP_SIZE
8724 }
8725
8726 static void cmd_dump_parsed(void *parsed_result,
8727                             __attribute__((unused)) struct cmdline *cl,
8728                             __attribute__((unused)) void *data)
8729 {
8730         struct cmd_dump_result *res = parsed_result;
8731
8732         if (!strcmp(res->dump, "dump_physmem"))
8733                 rte_dump_physmem_layout(stdout);
8734         else if (!strcmp(res->dump, "dump_memzone"))
8735                 rte_memzone_dump(stdout);
8736         else if (!strcmp(res->dump, "dump_struct_sizes"))
8737                 dump_struct_sizes();
8738         else if (!strcmp(res->dump, "dump_ring"))
8739                 rte_ring_list_dump(stdout);
8740         else if (!strcmp(res->dump, "dump_mempool"))
8741                 rte_mempool_list_dump(stdout);
8742         else if (!strcmp(res->dump, "dump_devargs"))
8743                 rte_eal_devargs_dump(stdout);
8744         else if (!strcmp(res->dump, "dump_log_types"))
8745                 rte_log_dump(stdout);
8746 }
8747
8748 cmdline_parse_token_string_t cmd_dump_dump =
8749         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8750                 "dump_physmem#"
8751                 "dump_memzone#"
8752                 "dump_struct_sizes#"
8753                 "dump_ring#"
8754                 "dump_mempool#"
8755                 "dump_devargs#"
8756                 "dump_log_types");
8757
8758 cmdline_parse_inst_t cmd_dump = {
8759         .f = cmd_dump_parsed,  /* function to call */
8760         .data = NULL,      /* 2nd arg of func */
8761         .help_str = "Dump status",
8762         .tokens = {        /* token list, NULL terminated */
8763                 (void *)&cmd_dump_dump,
8764                 NULL,
8765         },
8766 };
8767
8768 /* ******************************************************************************** */
8769
8770 struct cmd_dump_one_result {
8771         cmdline_fixed_string_t dump;
8772         cmdline_fixed_string_t name;
8773 };
8774
8775 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8776                                 __attribute__((unused)) void *data)
8777 {
8778         struct cmd_dump_one_result *res = parsed_result;
8779
8780         if (!strcmp(res->dump, "dump_ring")) {
8781                 struct rte_ring *r;
8782                 r = rte_ring_lookup(res->name);
8783                 if (r == NULL) {
8784                         cmdline_printf(cl, "Cannot find ring\n");
8785                         return;
8786                 }
8787                 rte_ring_dump(stdout, r);
8788         } else if (!strcmp(res->dump, "dump_mempool")) {
8789                 struct rte_mempool *mp;
8790                 mp = rte_mempool_lookup(res->name);
8791                 if (mp == NULL) {
8792                         cmdline_printf(cl, "Cannot find mempool\n");
8793                         return;
8794                 }
8795                 rte_mempool_dump(stdout, mp);
8796         }
8797 }
8798
8799 cmdline_parse_token_string_t cmd_dump_one_dump =
8800         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8801                                  "dump_ring#dump_mempool");
8802
8803 cmdline_parse_token_string_t cmd_dump_one_name =
8804         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8805
8806 cmdline_parse_inst_t cmd_dump_one = {
8807         .f = cmd_dump_one_parsed,  /* function to call */
8808         .data = NULL,      /* 2nd arg of func */
8809         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8810         .tokens = {        /* token list, NULL terminated */
8811                 (void *)&cmd_dump_one_dump,
8812                 (void *)&cmd_dump_one_name,
8813                 NULL,
8814         },
8815 };
8816
8817 /* *** Add/Del syn filter *** */
8818 struct cmd_syn_filter_result {
8819         cmdline_fixed_string_t filter;
8820         portid_t port_id;
8821         cmdline_fixed_string_t ops;
8822         cmdline_fixed_string_t priority;
8823         cmdline_fixed_string_t high;
8824         cmdline_fixed_string_t queue;
8825         uint16_t queue_id;
8826 };
8827
8828 static void
8829 cmd_syn_filter_parsed(void *parsed_result,
8830                         __attribute__((unused)) struct cmdline *cl,
8831                         __attribute__((unused)) void *data)
8832 {
8833         struct cmd_syn_filter_result *res = parsed_result;
8834         struct rte_eth_syn_filter syn_filter;
8835         int ret = 0;
8836
8837         ret = rte_eth_dev_filter_supported(res->port_id,
8838                                         RTE_ETH_FILTER_SYN);
8839         if (ret < 0) {
8840                 printf("syn filter is not supported on port %u.\n",
8841                                 res->port_id);
8842                 return;
8843         }
8844
8845         memset(&syn_filter, 0, sizeof(syn_filter));
8846
8847         if (!strcmp(res->ops, "add")) {
8848                 if (!strcmp(res->high, "high"))
8849                         syn_filter.hig_pri = 1;
8850                 else
8851                         syn_filter.hig_pri = 0;
8852
8853                 syn_filter.queue = res->queue_id;
8854                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8855                                                 RTE_ETH_FILTER_SYN,
8856                                                 RTE_ETH_FILTER_ADD,
8857                                                 &syn_filter);
8858         } else
8859                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8860                                                 RTE_ETH_FILTER_SYN,
8861                                                 RTE_ETH_FILTER_DELETE,
8862                                                 &syn_filter);
8863
8864         if (ret < 0)
8865                 printf("syn filter programming error: (%s)\n",
8866                                 strerror(-ret));
8867 }
8868
8869 cmdline_parse_token_string_t cmd_syn_filter_filter =
8870         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8871         filter, "syn_filter");
8872 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8873         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8874         port_id, UINT16);
8875 cmdline_parse_token_string_t cmd_syn_filter_ops =
8876         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8877         ops, "add#del");
8878 cmdline_parse_token_string_t cmd_syn_filter_priority =
8879         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8880                                 priority, "priority");
8881 cmdline_parse_token_string_t cmd_syn_filter_high =
8882         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8883                                 high, "high#low");
8884 cmdline_parse_token_string_t cmd_syn_filter_queue =
8885         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8886                                 queue, "queue");
8887 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8888         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8889                                 queue_id, UINT16);
8890
8891 cmdline_parse_inst_t cmd_syn_filter = {
8892         .f = cmd_syn_filter_parsed,
8893         .data = NULL,
8894         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8895                 "<queue_id>: Add/Delete syn filter",
8896         .tokens = {
8897                 (void *)&cmd_syn_filter_filter,
8898                 (void *)&cmd_syn_filter_port_id,
8899                 (void *)&cmd_syn_filter_ops,
8900                 (void *)&cmd_syn_filter_priority,
8901                 (void *)&cmd_syn_filter_high,
8902                 (void *)&cmd_syn_filter_queue,
8903                 (void *)&cmd_syn_filter_queue_id,
8904                 NULL,
8905         },
8906 };
8907
8908 /* *** queue region set *** */
8909 struct cmd_queue_region_result {
8910         cmdline_fixed_string_t set;
8911         cmdline_fixed_string_t port;
8912         portid_t port_id;
8913         cmdline_fixed_string_t cmd;
8914         cmdline_fixed_string_t region;
8915         uint8_t  region_id;
8916         cmdline_fixed_string_t queue_start_index;
8917         uint8_t  queue_id;
8918         cmdline_fixed_string_t queue_num;
8919         uint8_t  queue_num_value;
8920 };
8921
8922 static void
8923 cmd_queue_region_parsed(void *parsed_result,
8924                         __attribute__((unused)) struct cmdline *cl,
8925                         __attribute__((unused)) void *data)
8926 {
8927         struct cmd_queue_region_result *res = parsed_result;
8928         int ret = -ENOTSUP;
8929 #ifdef RTE_LIBRTE_I40E_PMD
8930         struct rte_pmd_i40e_queue_region_conf region_conf;
8931         enum rte_pmd_i40e_queue_region_op op_type;
8932 #endif
8933
8934         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8935                 return;
8936
8937 #ifdef RTE_LIBRTE_I40E_PMD
8938         memset(&region_conf, 0, sizeof(region_conf));
8939         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8940         region_conf.region_id = res->region_id;
8941         region_conf.queue_num = res->queue_num_value;
8942         region_conf.queue_start_index = res->queue_id;
8943
8944         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8945                                 op_type, &region_conf);
8946 #endif
8947
8948         switch (ret) {
8949         case 0:
8950                 break;
8951         case -ENOTSUP:
8952                 printf("function not implemented or supported\n");
8953                 break;
8954         default:
8955                 printf("queue region config error: (%s)\n", strerror(-ret));
8956         }
8957 }
8958
8959 cmdline_parse_token_string_t cmd_queue_region_set =
8960 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8961                 set, "set");
8962 cmdline_parse_token_string_t cmd_queue_region_port =
8963         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8964 cmdline_parse_token_num_t cmd_queue_region_port_id =
8965         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8966                                 port_id, UINT16);
8967 cmdline_parse_token_string_t cmd_queue_region_cmd =
8968         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8969                                  cmd, "queue-region");
8970 cmdline_parse_token_string_t cmd_queue_region_id =
8971         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8972                                 region, "region_id");
8973 cmdline_parse_token_num_t cmd_queue_region_index =
8974         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8975                                 region_id, UINT8);
8976 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8977         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8978                                 queue_start_index, "queue_start_index");
8979 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8980         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8981                                 queue_id, UINT8);
8982 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8983         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8984                                 queue_num, "queue_num");
8985 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8986         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8987                                 queue_num_value, UINT8);
8988
8989 cmdline_parse_inst_t cmd_queue_region = {
8990         .f = cmd_queue_region_parsed,
8991         .data = NULL,
8992         .help_str = "set port <port_id> queue-region region_id <value> "
8993                 "queue_start_index <value> queue_num <value>: Set a queue region",
8994         .tokens = {
8995                 (void *)&cmd_queue_region_set,
8996                 (void *)&cmd_queue_region_port,
8997                 (void *)&cmd_queue_region_port_id,
8998                 (void *)&cmd_queue_region_cmd,
8999                 (void *)&cmd_queue_region_id,
9000                 (void *)&cmd_queue_region_index,
9001                 (void *)&cmd_queue_region_queue_start_index,
9002                 (void *)&cmd_queue_region_queue_id,
9003                 (void *)&cmd_queue_region_queue_num,
9004                 (void *)&cmd_queue_region_queue_num_value,
9005                 NULL,
9006         },
9007 };
9008
9009 /* *** queue region and flowtype set *** */
9010 struct cmd_region_flowtype_result {
9011         cmdline_fixed_string_t set;
9012         cmdline_fixed_string_t port;
9013         portid_t port_id;
9014         cmdline_fixed_string_t cmd;
9015         cmdline_fixed_string_t region;
9016         uint8_t  region_id;
9017         cmdline_fixed_string_t flowtype;
9018         uint8_t  flowtype_id;
9019 };
9020
9021 static void
9022 cmd_region_flowtype_parsed(void *parsed_result,
9023                         __attribute__((unused)) struct cmdline *cl,
9024                         __attribute__((unused)) void *data)
9025 {
9026         struct cmd_region_flowtype_result *res = parsed_result;
9027         int ret = -ENOTSUP;
9028 #ifdef RTE_LIBRTE_I40E_PMD
9029         struct rte_pmd_i40e_queue_region_conf region_conf;
9030         enum rte_pmd_i40e_queue_region_op op_type;
9031 #endif
9032
9033         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9034                 return;
9035
9036 #ifdef RTE_LIBRTE_I40E_PMD
9037         memset(&region_conf, 0, sizeof(region_conf));
9038
9039         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9040         region_conf.region_id = res->region_id;
9041         region_conf.hw_flowtype = res->flowtype_id;
9042
9043         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9044                         op_type, &region_conf);
9045 #endif
9046
9047         switch (ret) {
9048         case 0:
9049                 break;
9050         case -ENOTSUP:
9051                 printf("function not implemented or supported\n");
9052                 break;
9053         default:
9054                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9055         }
9056 }
9057
9058 cmdline_parse_token_string_t cmd_region_flowtype_set =
9059 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9060                                 set, "set");
9061 cmdline_parse_token_string_t cmd_region_flowtype_port =
9062         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9063                                 port, "port");
9064 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9065         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9066                                 port_id, UINT16);
9067 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9068         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9069                                 cmd, "queue-region");
9070 cmdline_parse_token_string_t cmd_region_flowtype_index =
9071         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9072                                 region, "region_id");
9073 cmdline_parse_token_num_t cmd_region_flowtype_id =
9074         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9075                                 region_id, UINT8);
9076 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9077         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9078                                 flowtype, "flowtype");
9079 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9080         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9081                                 flowtype_id, UINT8);
9082 cmdline_parse_inst_t cmd_region_flowtype = {
9083         .f = cmd_region_flowtype_parsed,
9084         .data = NULL,
9085         .help_str = "set port <port_id> queue-region region_id <value> "
9086                 "flowtype <value>: Set a flowtype region index",
9087         .tokens = {
9088                 (void *)&cmd_region_flowtype_set,
9089                 (void *)&cmd_region_flowtype_port,
9090                 (void *)&cmd_region_flowtype_port_index,
9091                 (void *)&cmd_region_flowtype_cmd,
9092                 (void *)&cmd_region_flowtype_index,
9093                 (void *)&cmd_region_flowtype_id,
9094                 (void *)&cmd_region_flowtype_flow_index,
9095                 (void *)&cmd_region_flowtype_flow_id,
9096                 NULL,
9097         },
9098 };
9099
9100 /* *** User Priority (UP) to queue region (region_id) set *** */
9101 struct cmd_user_priority_region_result {
9102         cmdline_fixed_string_t set;
9103         cmdline_fixed_string_t port;
9104         portid_t port_id;
9105         cmdline_fixed_string_t cmd;
9106         cmdline_fixed_string_t user_priority;
9107         uint8_t  user_priority_id;
9108         cmdline_fixed_string_t region;
9109         uint8_t  region_id;
9110 };
9111
9112 static void
9113 cmd_user_priority_region_parsed(void *parsed_result,
9114                         __attribute__((unused)) struct cmdline *cl,
9115                         __attribute__((unused)) void *data)
9116 {
9117         struct cmd_user_priority_region_result *res = parsed_result;
9118         int ret = -ENOTSUP;
9119 #ifdef RTE_LIBRTE_I40E_PMD
9120         struct rte_pmd_i40e_queue_region_conf region_conf;
9121         enum rte_pmd_i40e_queue_region_op op_type;
9122 #endif
9123
9124         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9125                 return;
9126
9127 #ifdef RTE_LIBRTE_I40E_PMD
9128         memset(&region_conf, 0, sizeof(region_conf));
9129         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9130         region_conf.user_priority = res->user_priority_id;
9131         region_conf.region_id = res->region_id;
9132
9133         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9134                                 op_type, &region_conf);
9135 #endif
9136
9137         switch (ret) {
9138         case 0:
9139                 break;
9140         case -ENOTSUP:
9141                 printf("function not implemented or supported\n");
9142                 break;
9143         default:
9144                 printf("user_priority region config error: (%s)\n",
9145                                 strerror(-ret));
9146         }
9147 }
9148
9149 cmdline_parse_token_string_t cmd_user_priority_region_set =
9150         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9151                                 set, "set");
9152 cmdline_parse_token_string_t cmd_user_priority_region_port =
9153         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9154                                 port, "port");
9155 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9156         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9157                                 port_id, UINT16);
9158 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9159         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9160                                 cmd, "queue-region");
9161 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9162         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9163                                 user_priority, "UP");
9164 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9165         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9166                                 user_priority_id, UINT8);
9167 cmdline_parse_token_string_t cmd_user_priority_region_region =
9168         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9169                                 region, "region_id");
9170 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9171         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9172                                 region_id, UINT8);
9173
9174 cmdline_parse_inst_t cmd_user_priority_region = {
9175         .f = cmd_user_priority_region_parsed,
9176         .data = NULL,
9177         .help_str = "set port <port_id> queue-region UP <value> "
9178                 "region_id <value>: Set the mapping of User Priority (UP) "
9179                 "to queue region (region_id) ",
9180         .tokens = {
9181                 (void *)&cmd_user_priority_region_set,
9182                 (void *)&cmd_user_priority_region_port,
9183                 (void *)&cmd_user_priority_region_port_index,
9184                 (void *)&cmd_user_priority_region_cmd,
9185                 (void *)&cmd_user_priority_region_UP,
9186                 (void *)&cmd_user_priority_region_UP_id,
9187                 (void *)&cmd_user_priority_region_region,
9188                 (void *)&cmd_user_priority_region_region_id,
9189                 NULL,
9190         },
9191 };
9192
9193 /* *** flush all queue region related configuration *** */
9194 struct cmd_flush_queue_region_result {
9195         cmdline_fixed_string_t set;
9196         cmdline_fixed_string_t port;
9197         portid_t port_id;
9198         cmdline_fixed_string_t cmd;
9199         cmdline_fixed_string_t flush;
9200         cmdline_fixed_string_t what;
9201 };
9202
9203 static void
9204 cmd_flush_queue_region_parsed(void *parsed_result,
9205                         __attribute__((unused)) struct cmdline *cl,
9206                         __attribute__((unused)) void *data)
9207 {
9208         struct cmd_flush_queue_region_result *res = parsed_result;
9209         int ret = -ENOTSUP;
9210 #ifdef RTE_LIBRTE_I40E_PMD
9211         struct rte_pmd_i40e_queue_region_conf region_conf;
9212         enum rte_pmd_i40e_queue_region_op op_type;
9213 #endif
9214
9215         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9216                 return;
9217
9218 #ifdef RTE_LIBRTE_I40E_PMD
9219         memset(&region_conf, 0, sizeof(region_conf));
9220
9221         if (strcmp(res->what, "on") == 0)
9222                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9223         else
9224                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9225
9226         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9227                                 op_type, &region_conf);
9228 #endif
9229
9230         switch (ret) {
9231         case 0:
9232                 break;
9233         case -ENOTSUP:
9234                 printf("function not implemented or supported\n");
9235                 break;
9236         default:
9237                 printf("queue region config flush error: (%s)\n",
9238                                 strerror(-ret));
9239         }
9240 }
9241
9242 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9243         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9244                                 set, "set");
9245 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9246         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9247                                 port, "port");
9248 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9249         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9250                                 port_id, UINT16);
9251 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9252         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9253                                 cmd, "queue-region");
9254 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9255         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9256                                 flush, "flush");
9257 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9258         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9259                                 what, "on#off");
9260
9261 cmdline_parse_inst_t cmd_flush_queue_region = {
9262         .f = cmd_flush_queue_region_parsed,
9263         .data = NULL,
9264         .help_str = "set port <port_id> queue-region flush on|off"
9265                 ": flush all queue region related configuration",
9266         .tokens = {
9267                 (void *)&cmd_flush_queue_region_set,
9268                 (void *)&cmd_flush_queue_region_port,
9269                 (void *)&cmd_flush_queue_region_port_index,
9270                 (void *)&cmd_flush_queue_region_cmd,
9271                 (void *)&cmd_flush_queue_region_flush,
9272                 (void *)&cmd_flush_queue_region_what,
9273                 NULL,
9274         },
9275 };
9276
9277 /* *** get all queue region related configuration info *** */
9278 struct cmd_show_queue_region_info {
9279         cmdline_fixed_string_t show;
9280         cmdline_fixed_string_t port;
9281         portid_t port_id;
9282         cmdline_fixed_string_t cmd;
9283 };
9284
9285 static void
9286 cmd_show_queue_region_info_parsed(void *parsed_result,
9287                         __attribute__((unused)) struct cmdline *cl,
9288                         __attribute__((unused)) void *data)
9289 {
9290         struct cmd_show_queue_region_info *res = parsed_result;
9291         int ret = -ENOTSUP;
9292 #ifdef RTE_LIBRTE_I40E_PMD
9293         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9294         enum rte_pmd_i40e_queue_region_op op_type;
9295 #endif
9296
9297         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9298                 return;
9299
9300 #ifdef RTE_LIBRTE_I40E_PMD
9301         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9302
9303         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9304
9305         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9306                                         op_type, &rte_pmd_regions);
9307
9308         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9309 #endif
9310
9311         switch (ret) {
9312         case 0:
9313                 break;
9314         case -ENOTSUP:
9315                 printf("function not implemented or supported\n");
9316                 break;
9317         default:
9318                 printf("queue region config info show error: (%s)\n",
9319                                 strerror(-ret));
9320         }
9321 }
9322
9323 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9324 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9325                                 show, "show");
9326 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9327         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9328                                 port, "port");
9329 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9330         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9331                                 port_id, UINT16);
9332 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9333         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9334                                 cmd, "queue-region");
9335
9336 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9337         .f = cmd_show_queue_region_info_parsed,
9338         .data = NULL,
9339         .help_str = "show port <port_id> queue-region"
9340                 ": show all queue region related configuration info",
9341         .tokens = {
9342                 (void *)&cmd_show_queue_region_info_get,
9343                 (void *)&cmd_show_queue_region_info_port,
9344                 (void *)&cmd_show_queue_region_info_port_index,
9345                 (void *)&cmd_show_queue_region_info_cmd,
9346                 NULL,
9347         },
9348 };
9349
9350 /* *** ADD/REMOVE A 2tuple FILTER *** */
9351 struct cmd_2tuple_filter_result {
9352         cmdline_fixed_string_t filter;
9353         portid_t port_id;
9354         cmdline_fixed_string_t ops;
9355         cmdline_fixed_string_t dst_port;
9356         uint16_t dst_port_value;
9357         cmdline_fixed_string_t protocol;
9358         uint8_t protocol_value;
9359         cmdline_fixed_string_t mask;
9360         uint8_t  mask_value;
9361         cmdline_fixed_string_t tcp_flags;
9362         uint8_t tcp_flags_value;
9363         cmdline_fixed_string_t priority;
9364         uint8_t  priority_value;
9365         cmdline_fixed_string_t queue;
9366         uint16_t  queue_id;
9367 };
9368
9369 static void
9370 cmd_2tuple_filter_parsed(void *parsed_result,
9371                         __attribute__((unused)) struct cmdline *cl,
9372                         __attribute__((unused)) void *data)
9373 {
9374         struct rte_eth_ntuple_filter filter;
9375         struct cmd_2tuple_filter_result *res = parsed_result;
9376         int ret = 0;
9377
9378         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9379         if (ret < 0) {
9380                 printf("ntuple filter is not supported on port %u.\n",
9381                         res->port_id);
9382                 return;
9383         }
9384
9385         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9386
9387         filter.flags = RTE_2TUPLE_FLAGS;
9388         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9389         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9390         filter.proto = res->protocol_value;
9391         filter.priority = res->priority_value;
9392         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9393                 printf("nonzero tcp_flags is only meaningful"
9394                         " when protocol is TCP.\n");
9395                 return;
9396         }
9397         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9398                 printf("invalid TCP flags.\n");
9399                 return;
9400         }
9401
9402         if (res->tcp_flags_value != 0) {
9403                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9404                 filter.tcp_flags = res->tcp_flags_value;
9405         }
9406
9407         /* need convert to big endian. */
9408         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9409         filter.queue = res->queue_id;
9410
9411         if (!strcmp(res->ops, "add"))
9412                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9413                                 RTE_ETH_FILTER_NTUPLE,
9414                                 RTE_ETH_FILTER_ADD,
9415                                 &filter);
9416         else
9417                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9418                                 RTE_ETH_FILTER_NTUPLE,
9419                                 RTE_ETH_FILTER_DELETE,
9420                                 &filter);
9421         if (ret < 0)
9422                 printf("2tuple filter programming error: (%s)\n",
9423                         strerror(-ret));
9424
9425 }
9426
9427 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9428         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9429                                  filter, "2tuple_filter");
9430 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9431         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9432                                 port_id, UINT16);
9433 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9434         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9435                                  ops, "add#del");
9436 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9437         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9438                                 dst_port, "dst_port");
9439 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9440         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9441                                 dst_port_value, UINT16);
9442 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9443         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9444                                 protocol, "protocol");
9445 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9446         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9447                                 protocol_value, UINT8);
9448 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9449         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9450                                 mask, "mask");
9451 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9452         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9453                                 mask_value, INT8);
9454 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9455         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9456                                 tcp_flags, "tcp_flags");
9457 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9458         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9459                                 tcp_flags_value, UINT8);
9460 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9461         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9462                                 priority, "priority");
9463 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9464         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9465                                 priority_value, UINT8);
9466 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9467         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9468                                 queue, "queue");
9469 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9470         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9471                                 queue_id, UINT16);
9472
9473 cmdline_parse_inst_t cmd_2tuple_filter = {
9474         .f = cmd_2tuple_filter_parsed,
9475         .data = NULL,
9476         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9477                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9478                 "<queue_id>: Add a 2tuple filter",
9479         .tokens = {
9480                 (void *)&cmd_2tuple_filter_filter,
9481                 (void *)&cmd_2tuple_filter_port_id,
9482                 (void *)&cmd_2tuple_filter_ops,
9483                 (void *)&cmd_2tuple_filter_dst_port,
9484                 (void *)&cmd_2tuple_filter_dst_port_value,
9485                 (void *)&cmd_2tuple_filter_protocol,
9486                 (void *)&cmd_2tuple_filter_protocol_value,
9487                 (void *)&cmd_2tuple_filter_mask,
9488                 (void *)&cmd_2tuple_filter_mask_value,
9489                 (void *)&cmd_2tuple_filter_tcp_flags,
9490                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9491                 (void *)&cmd_2tuple_filter_priority,
9492                 (void *)&cmd_2tuple_filter_priority_value,
9493                 (void *)&cmd_2tuple_filter_queue,
9494                 (void *)&cmd_2tuple_filter_queue_id,
9495                 NULL,
9496         },
9497 };
9498
9499 /* *** ADD/REMOVE A 5tuple FILTER *** */
9500 struct cmd_5tuple_filter_result {
9501         cmdline_fixed_string_t filter;
9502         portid_t port_id;
9503         cmdline_fixed_string_t ops;
9504         cmdline_fixed_string_t dst_ip;
9505         cmdline_ipaddr_t dst_ip_value;
9506         cmdline_fixed_string_t src_ip;
9507         cmdline_ipaddr_t src_ip_value;
9508         cmdline_fixed_string_t dst_port;
9509         uint16_t dst_port_value;
9510         cmdline_fixed_string_t src_port;
9511         uint16_t src_port_value;
9512         cmdline_fixed_string_t protocol;
9513         uint8_t protocol_value;
9514         cmdline_fixed_string_t mask;
9515         uint8_t  mask_value;
9516         cmdline_fixed_string_t tcp_flags;
9517         uint8_t tcp_flags_value;
9518         cmdline_fixed_string_t priority;
9519         uint8_t  priority_value;
9520         cmdline_fixed_string_t queue;
9521         uint16_t  queue_id;
9522 };
9523
9524 static void
9525 cmd_5tuple_filter_parsed(void *parsed_result,
9526                         __attribute__((unused)) struct cmdline *cl,
9527                         __attribute__((unused)) void *data)
9528 {
9529         struct rte_eth_ntuple_filter filter;
9530         struct cmd_5tuple_filter_result *res = parsed_result;
9531         int ret = 0;
9532
9533         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9534         if (ret < 0) {
9535                 printf("ntuple filter is not supported on port %u.\n",
9536                         res->port_id);
9537                 return;
9538         }
9539
9540         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9541
9542         filter.flags = RTE_5TUPLE_FLAGS;
9543         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9544         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9545         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9546         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9547         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9548         filter.proto = res->protocol_value;
9549         filter.priority = res->priority_value;
9550         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9551                 printf("nonzero tcp_flags is only meaningful"
9552                         " when protocol is TCP.\n");
9553                 return;
9554         }
9555         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9556                 printf("invalid TCP flags.\n");
9557                 return;
9558         }
9559
9560         if (res->tcp_flags_value != 0) {
9561                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9562                 filter.tcp_flags = res->tcp_flags_value;
9563         }
9564
9565         if (res->dst_ip_value.family == AF_INET)
9566                 /* no need to convert, already big endian. */
9567                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9568         else {
9569                 if (filter.dst_ip_mask == 0) {
9570                         printf("can not support ipv6 involved compare.\n");
9571                         return;
9572                 }
9573                 filter.dst_ip = 0;
9574         }
9575
9576         if (res->src_ip_value.family == AF_INET)
9577                 /* no need to convert, already big endian. */
9578                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9579         else {
9580                 if (filter.src_ip_mask == 0) {
9581                         printf("can not support ipv6 involved compare.\n");
9582                         return;
9583                 }
9584                 filter.src_ip = 0;
9585         }
9586         /* need convert to big endian. */
9587         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9588         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9589         filter.queue = res->queue_id;
9590
9591         if (!strcmp(res->ops, "add"))
9592                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9593                                 RTE_ETH_FILTER_NTUPLE,
9594                                 RTE_ETH_FILTER_ADD,
9595                                 &filter);
9596         else
9597                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9598                                 RTE_ETH_FILTER_NTUPLE,
9599                                 RTE_ETH_FILTER_DELETE,
9600                                 &filter);
9601         if (ret < 0)
9602                 printf("5tuple filter programming error: (%s)\n",
9603                         strerror(-ret));
9604 }
9605
9606 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9607         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9608                                  filter, "5tuple_filter");
9609 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9610         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9611                                 port_id, UINT16);
9612 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9613         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9614                                  ops, "add#del");
9615 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9616         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9617                                 dst_ip, "dst_ip");
9618 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9619         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9620                                 dst_ip_value);
9621 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9622         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9623                                 src_ip, "src_ip");
9624 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9625         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9626                                 src_ip_value);
9627 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9628         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9629                                 dst_port, "dst_port");
9630 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9631         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9632                                 dst_port_value, UINT16);
9633 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9634         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9635                                 src_port, "src_port");
9636 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9637         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9638                                 src_port_value, UINT16);
9639 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9640         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9641                                 protocol, "protocol");
9642 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9643         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9644                                 protocol_value, UINT8);
9645 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9646         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9647                                 mask, "mask");
9648 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9649         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9650                                 mask_value, INT8);
9651 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9652         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9653                                 tcp_flags, "tcp_flags");
9654 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9655         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9656                                 tcp_flags_value, UINT8);
9657 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9658         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9659                                 priority, "priority");
9660 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9661         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9662                                 priority_value, UINT8);
9663 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9664         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9665                                 queue, "queue");
9666 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9667         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9668                                 queue_id, UINT16);
9669
9670 cmdline_parse_inst_t cmd_5tuple_filter = {
9671         .f = cmd_5tuple_filter_parsed,
9672         .data = NULL,
9673         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9674                 "src_ip <value> dst_port <value> src_port <value> "
9675                 "protocol <value>  mask <value> tcp_flags <value> "
9676                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9677         .tokens = {
9678                 (void *)&cmd_5tuple_filter_filter,
9679                 (void *)&cmd_5tuple_filter_port_id,
9680                 (void *)&cmd_5tuple_filter_ops,
9681                 (void *)&cmd_5tuple_filter_dst_ip,
9682                 (void *)&cmd_5tuple_filter_dst_ip_value,
9683                 (void *)&cmd_5tuple_filter_src_ip,
9684                 (void *)&cmd_5tuple_filter_src_ip_value,
9685                 (void *)&cmd_5tuple_filter_dst_port,
9686                 (void *)&cmd_5tuple_filter_dst_port_value,
9687                 (void *)&cmd_5tuple_filter_src_port,
9688                 (void *)&cmd_5tuple_filter_src_port_value,
9689                 (void *)&cmd_5tuple_filter_protocol,
9690                 (void *)&cmd_5tuple_filter_protocol_value,
9691                 (void *)&cmd_5tuple_filter_mask,
9692                 (void *)&cmd_5tuple_filter_mask_value,
9693                 (void *)&cmd_5tuple_filter_tcp_flags,
9694                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9695                 (void *)&cmd_5tuple_filter_priority,
9696                 (void *)&cmd_5tuple_filter_priority_value,
9697                 (void *)&cmd_5tuple_filter_queue,
9698                 (void *)&cmd_5tuple_filter_queue_id,
9699                 NULL,
9700         },
9701 };
9702
9703 /* *** ADD/REMOVE A flex FILTER *** */
9704 struct cmd_flex_filter_result {
9705         cmdline_fixed_string_t filter;
9706         cmdline_fixed_string_t ops;
9707         portid_t port_id;
9708         cmdline_fixed_string_t len;
9709         uint8_t len_value;
9710         cmdline_fixed_string_t bytes;
9711         cmdline_fixed_string_t bytes_value;
9712         cmdline_fixed_string_t mask;
9713         cmdline_fixed_string_t mask_value;
9714         cmdline_fixed_string_t priority;
9715         uint8_t priority_value;
9716         cmdline_fixed_string_t queue;
9717         uint16_t queue_id;
9718 };
9719
9720 static int xdigit2val(unsigned char c)
9721 {
9722         int val;
9723         if (isdigit(c))
9724                 val = c - '0';
9725         else if (isupper(c))
9726                 val = c - 'A' + 10;
9727         else
9728                 val = c - 'a' + 10;
9729         return val;
9730 }
9731
9732 static void
9733 cmd_flex_filter_parsed(void *parsed_result,
9734                           __attribute__((unused)) struct cmdline *cl,
9735                           __attribute__((unused)) void *data)
9736 {
9737         int ret = 0;
9738         struct rte_eth_flex_filter filter;
9739         struct cmd_flex_filter_result *res = parsed_result;
9740         char *bytes_ptr, *mask_ptr;
9741         uint16_t len, i, j = 0;
9742         char c;
9743         int val;
9744         uint8_t byte = 0;
9745
9746         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9747                 printf("the len exceed the max length 128\n");
9748                 return;
9749         }
9750         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9751         filter.len = res->len_value;
9752         filter.priority = res->priority_value;
9753         filter.queue = res->queue_id;
9754         bytes_ptr = res->bytes_value;
9755         mask_ptr = res->mask_value;
9756
9757          /* translate bytes string to array. */
9758         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9759                 (bytes_ptr[1] == 'X')))
9760                 bytes_ptr += 2;
9761         len = strnlen(bytes_ptr, res->len_value * 2);
9762         if (len == 0 || (len % 8 != 0)) {
9763                 printf("please check len and bytes input\n");
9764                 return;
9765         }
9766         for (i = 0; i < len; i++) {
9767                 c = bytes_ptr[i];
9768                 if (isxdigit(c) == 0) {
9769                         /* invalid characters. */
9770                         printf("invalid input\n");
9771                         return;
9772                 }
9773                 val = xdigit2val(c);
9774                 if (i % 2) {
9775                         byte |= val;
9776                         filter.bytes[j] = byte;
9777                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9778                         j++;
9779                         byte = 0;
9780                 } else
9781                         byte |= val << 4;
9782         }
9783         printf("\n");
9784          /* translate mask string to uint8_t array. */
9785         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9786                 (mask_ptr[1] == 'X')))
9787                 mask_ptr += 2;
9788         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9789         if (len == 0) {
9790                 printf("invalid input\n");
9791                 return;
9792         }
9793         j = 0;
9794         byte = 0;
9795         for (i = 0; i < len; i++) {
9796                 c = mask_ptr[i];
9797                 if (isxdigit(c) == 0) {
9798                         /* invalid characters. */
9799                         printf("invalid input\n");
9800                         return;
9801                 }
9802                 val = xdigit2val(c);
9803                 if (i % 2) {
9804                         byte |= val;
9805                         filter.mask[j] = byte;
9806                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9807                         j++;
9808                         byte = 0;
9809                 } else
9810                         byte |= val << 4;
9811         }
9812         printf("\n");
9813
9814         if (!strcmp(res->ops, "add"))
9815                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9816                                 RTE_ETH_FILTER_FLEXIBLE,
9817                                 RTE_ETH_FILTER_ADD,
9818                                 &filter);
9819         else
9820                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9821                                 RTE_ETH_FILTER_FLEXIBLE,
9822                                 RTE_ETH_FILTER_DELETE,
9823                                 &filter);
9824
9825         if (ret < 0)
9826                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9827 }
9828
9829 cmdline_parse_token_string_t cmd_flex_filter_filter =
9830         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9831                                 filter, "flex_filter");
9832 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9833         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9834                                 port_id, UINT16);
9835 cmdline_parse_token_string_t cmd_flex_filter_ops =
9836         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9837                                 ops, "add#del");
9838 cmdline_parse_token_string_t cmd_flex_filter_len =
9839         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9840                                 len, "len");
9841 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9842         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9843                                 len_value, UINT8);
9844 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9845         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9846                                 bytes, "bytes");
9847 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9848         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9849                                 bytes_value, NULL);
9850 cmdline_parse_token_string_t cmd_flex_filter_mask =
9851         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9852                                 mask, "mask");
9853 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9854         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9855                                 mask_value, NULL);
9856 cmdline_parse_token_string_t cmd_flex_filter_priority =
9857         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9858                                 priority, "priority");
9859 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9860         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9861                                 priority_value, UINT8);
9862 cmdline_parse_token_string_t cmd_flex_filter_queue =
9863         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9864                                 queue, "queue");
9865 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9866         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9867                                 queue_id, UINT16);
9868 cmdline_parse_inst_t cmd_flex_filter = {
9869         .f = cmd_flex_filter_parsed,
9870         .data = NULL,
9871         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9872                 "<value> mask <value> priority <value> queue <queue_id>: "
9873                 "Add/Del a flex filter",
9874         .tokens = {
9875                 (void *)&cmd_flex_filter_filter,
9876                 (void *)&cmd_flex_filter_port_id,
9877                 (void *)&cmd_flex_filter_ops,
9878                 (void *)&cmd_flex_filter_len,
9879                 (void *)&cmd_flex_filter_len_value,
9880                 (void *)&cmd_flex_filter_bytes,
9881                 (void *)&cmd_flex_filter_bytes_value,
9882                 (void *)&cmd_flex_filter_mask,
9883                 (void *)&cmd_flex_filter_mask_value,
9884                 (void *)&cmd_flex_filter_priority,
9885                 (void *)&cmd_flex_filter_priority_value,
9886                 (void *)&cmd_flex_filter_queue,
9887                 (void *)&cmd_flex_filter_queue_id,
9888                 NULL,
9889         },
9890 };
9891
9892 /* *** Filters Control *** */
9893
9894 /* *** deal with ethertype filter *** */
9895 struct cmd_ethertype_filter_result {
9896         cmdline_fixed_string_t filter;
9897         portid_t port_id;
9898         cmdline_fixed_string_t ops;
9899         cmdline_fixed_string_t mac;
9900         struct ether_addr mac_addr;
9901         cmdline_fixed_string_t ethertype;
9902         uint16_t ethertype_value;
9903         cmdline_fixed_string_t drop;
9904         cmdline_fixed_string_t queue;
9905         uint16_t  queue_id;
9906 };
9907
9908 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9909         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9910                                  filter, "ethertype_filter");
9911 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9912         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9913                               port_id, UINT16);
9914 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9915         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9916                                  ops, "add#del");
9917 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9918         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9919                                  mac, "mac_addr#mac_ignr");
9920 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9921         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9922                                      mac_addr);
9923 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9924         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9925                                  ethertype, "ethertype");
9926 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9927         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9928                               ethertype_value, UINT16);
9929 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9930         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9931                                  drop, "drop#fwd");
9932 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9933         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9934                                  queue, "queue");
9935 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9936         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9937                               queue_id, UINT16);
9938
9939 static void
9940 cmd_ethertype_filter_parsed(void *parsed_result,
9941                           __attribute__((unused)) struct cmdline *cl,
9942                           __attribute__((unused)) void *data)
9943 {
9944         struct cmd_ethertype_filter_result *res = parsed_result;
9945         struct rte_eth_ethertype_filter filter;
9946         int ret = 0;
9947
9948         ret = rte_eth_dev_filter_supported(res->port_id,
9949                         RTE_ETH_FILTER_ETHERTYPE);
9950         if (ret < 0) {
9951                 printf("ethertype filter is not supported on port %u.\n",
9952                         res->port_id);
9953                 return;
9954         }
9955
9956         memset(&filter, 0, sizeof(filter));
9957         if (!strcmp(res->mac, "mac_addr")) {
9958                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9959                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9960                         sizeof(struct ether_addr));
9961         }
9962         if (!strcmp(res->drop, "drop"))
9963                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9964         filter.ether_type = res->ethertype_value;
9965         filter.queue = res->queue_id;
9966
9967         if (!strcmp(res->ops, "add"))
9968                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9969                                 RTE_ETH_FILTER_ETHERTYPE,
9970                                 RTE_ETH_FILTER_ADD,
9971                                 &filter);
9972         else
9973                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9974                                 RTE_ETH_FILTER_ETHERTYPE,
9975                                 RTE_ETH_FILTER_DELETE,
9976                                 &filter);
9977         if (ret < 0)
9978                 printf("ethertype filter programming error: (%s)\n",
9979                         strerror(-ret));
9980 }
9981
9982 cmdline_parse_inst_t cmd_ethertype_filter = {
9983         .f = cmd_ethertype_filter_parsed,
9984         .data = NULL,
9985         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9986                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9987                 "Add or delete an ethertype filter entry",
9988         .tokens = {
9989                 (void *)&cmd_ethertype_filter_filter,
9990                 (void *)&cmd_ethertype_filter_port_id,
9991                 (void *)&cmd_ethertype_filter_ops,
9992                 (void *)&cmd_ethertype_filter_mac,
9993                 (void *)&cmd_ethertype_filter_mac_addr,
9994                 (void *)&cmd_ethertype_filter_ethertype,
9995                 (void *)&cmd_ethertype_filter_ethertype_value,
9996                 (void *)&cmd_ethertype_filter_drop,
9997                 (void *)&cmd_ethertype_filter_queue,
9998                 (void *)&cmd_ethertype_filter_queue_id,
9999                 NULL,
10000         },
10001 };
10002
10003 /* *** deal with flow director filter *** */
10004 struct cmd_flow_director_result {
10005         cmdline_fixed_string_t flow_director_filter;
10006         portid_t port_id;
10007         cmdline_fixed_string_t mode;
10008         cmdline_fixed_string_t mode_value;
10009         cmdline_fixed_string_t ops;
10010         cmdline_fixed_string_t flow;
10011         cmdline_fixed_string_t flow_type;
10012         cmdline_fixed_string_t ether;
10013         uint16_t ether_type;
10014         cmdline_fixed_string_t src;
10015         cmdline_ipaddr_t ip_src;
10016         uint16_t port_src;
10017         cmdline_fixed_string_t dst;
10018         cmdline_ipaddr_t ip_dst;
10019         uint16_t port_dst;
10020         cmdline_fixed_string_t verify_tag;
10021         uint32_t verify_tag_value;
10022         cmdline_fixed_string_t tos;
10023         uint8_t tos_value;
10024         cmdline_fixed_string_t proto;
10025         uint8_t proto_value;
10026         cmdline_fixed_string_t ttl;
10027         uint8_t ttl_value;
10028         cmdline_fixed_string_t vlan;
10029         uint16_t vlan_value;
10030         cmdline_fixed_string_t flexbytes;
10031         cmdline_fixed_string_t flexbytes_value;
10032         cmdline_fixed_string_t pf_vf;
10033         cmdline_fixed_string_t drop;
10034         cmdline_fixed_string_t queue;
10035         uint16_t  queue_id;
10036         cmdline_fixed_string_t fd_id;
10037         uint32_t  fd_id_value;
10038         cmdline_fixed_string_t mac;
10039         struct ether_addr mac_addr;
10040         cmdline_fixed_string_t tunnel;
10041         cmdline_fixed_string_t tunnel_type;
10042         cmdline_fixed_string_t tunnel_id;
10043         uint32_t tunnel_id_value;
10044         cmdline_fixed_string_t packet;
10045         char filepath[];
10046 };
10047
10048 static inline int
10049 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10050 {
10051         char s[256];
10052         const char *p, *p0 = q_arg;
10053         char *end;
10054         unsigned long int_fld;
10055         char *str_fld[max_num];
10056         int i;
10057         unsigned size;
10058         int ret = -1;
10059
10060         p = strchr(p0, '(');
10061         if (p == NULL)
10062                 return -1;
10063         ++p;
10064         p0 = strchr(p, ')');
10065         if (p0 == NULL)
10066                 return -1;
10067
10068         size = p0 - p;
10069         if (size >= sizeof(s))
10070                 return -1;
10071
10072         snprintf(s, sizeof(s), "%.*s", size, p);
10073         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10074         if (ret < 0 || ret > max_num)
10075                 return -1;
10076         for (i = 0; i < ret; i++) {
10077                 errno = 0;
10078                 int_fld = strtoul(str_fld[i], &end, 0);
10079                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10080                         return -1;
10081                 flexbytes[i] = (uint8_t)int_fld;
10082         }
10083         return ret;
10084 }
10085
10086 static uint16_t
10087 str2flowtype(char *string)
10088 {
10089         uint8_t i = 0;
10090         static const struct {
10091                 char str[32];
10092                 uint16_t type;
10093         } flowtype_str[] = {
10094                 {"raw", RTE_ETH_FLOW_RAW},
10095                 {"ipv4", RTE_ETH_FLOW_IPV4},
10096                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10097                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10098                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10099                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10100                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10101                 {"ipv6", RTE_ETH_FLOW_IPV6},
10102                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10103                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10104                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10105                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10106                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10107                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10108         };
10109
10110         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10111                 if (!strcmp(flowtype_str[i].str, string))
10112                         return flowtype_str[i].type;
10113         }
10114
10115         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10116                 return (uint16_t)atoi(string);
10117
10118         return RTE_ETH_FLOW_UNKNOWN;
10119 }
10120
10121 static enum rte_eth_fdir_tunnel_type
10122 str2fdir_tunneltype(char *string)
10123 {
10124         uint8_t i = 0;
10125
10126         static const struct {
10127                 char str[32];
10128                 enum rte_eth_fdir_tunnel_type type;
10129         } tunneltype_str[] = {
10130                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10131                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10132         };
10133
10134         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10135                 if (!strcmp(tunneltype_str[i].str, string))
10136                         return tunneltype_str[i].type;
10137         }
10138         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10139 }
10140
10141 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10142 do { \
10143         if ((ip_addr).family == AF_INET) \
10144                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10145         else { \
10146                 printf("invalid parameter.\n"); \
10147                 return; \
10148         } \
10149 } while (0)
10150
10151 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10152 do { \
10153         if ((ip_addr).family == AF_INET6) \
10154                 rte_memcpy(&(ip), \
10155                                  &((ip_addr).addr.ipv6), \
10156                                  sizeof(struct in6_addr)); \
10157         else { \
10158                 printf("invalid parameter.\n"); \
10159                 return; \
10160         } \
10161 } while (0)
10162
10163 static void
10164 cmd_flow_director_filter_parsed(void *parsed_result,
10165                           __attribute__((unused)) struct cmdline *cl,
10166                           __attribute__((unused)) void *data)
10167 {
10168         struct cmd_flow_director_result *res = parsed_result;
10169         struct rte_eth_fdir_filter entry;
10170         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10171         char *end;
10172         unsigned long vf_id;
10173         int ret = 0;
10174
10175         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10176         if (ret < 0) {
10177                 printf("flow director is not supported on port %u.\n",
10178                         res->port_id);
10179                 return;
10180         }
10181         memset(flexbytes, 0, sizeof(flexbytes));
10182         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10183
10184         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10185                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10186                         printf("Please set mode to MAC-VLAN.\n");
10187                         return;
10188                 }
10189         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10190                 if (strcmp(res->mode_value, "Tunnel")) {
10191                         printf("Please set mode to Tunnel.\n");
10192                         return;
10193                 }
10194         } else {
10195                 if (!strcmp(res->mode_value, "raw")) {
10196 #ifdef RTE_LIBRTE_I40E_PMD
10197                         struct rte_pmd_i40e_flow_type_mapping
10198                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10199                         struct rte_pmd_i40e_pkt_template_conf conf;
10200                         uint16_t flow_type = str2flowtype(res->flow_type);
10201                         uint16_t i, port = res->port_id;
10202                         uint8_t add;
10203
10204                         memset(&conf, 0, sizeof(conf));
10205
10206                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10207                                 printf("Invalid flow type specified.\n");
10208                                 return;
10209                         }
10210                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10211                                                                  mapping);
10212                         if (ret)
10213                                 return;
10214                         if (mapping[flow_type].pctype == 0ULL) {
10215                                 printf("Invalid flow type specified.\n");
10216                                 return;
10217                         }
10218                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10219                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10220                                         conf.input.pctype = i;
10221                                         break;
10222                                 }
10223                         }
10224
10225                         conf.input.packet = open_file(res->filepath,
10226                                                 &conf.input.length);
10227                         if (!conf.input.packet)
10228                                 return;
10229                         if (!strcmp(res->drop, "drop"))
10230                                 conf.action.behavior =
10231                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10232                         else
10233                                 conf.action.behavior =
10234                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10235                         conf.action.report_status =
10236                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10237                         conf.action.rx_queue = res->queue_id;
10238                         conf.soft_id = res->fd_id_value;
10239                         add  = strcmp(res->ops, "del") ? 1 : 0;
10240                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10241                                                                         &conf,
10242                                                                         add);
10243                         if (ret < 0)
10244                                 printf("flow director config error: (%s)\n",
10245                                        strerror(-ret));
10246                         close_file(conf.input.packet);
10247 #endif
10248                         return;
10249                 } else if (strcmp(res->mode_value, "IP")) {
10250                         printf("Please set mode to IP or raw.\n");
10251                         return;
10252                 }
10253                 entry.input.flow_type = str2flowtype(res->flow_type);
10254         }
10255
10256         ret = parse_flexbytes(res->flexbytes_value,
10257                                         flexbytes,
10258                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10259         if (ret < 0) {
10260                 printf("error: Cannot parse flexbytes input.\n");
10261                 return;
10262         }
10263
10264         switch (entry.input.flow_type) {
10265         case RTE_ETH_FLOW_FRAG_IPV4:
10266         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10267                 entry.input.flow.ip4_flow.proto = res->proto_value;
10268                 /* fall-through */
10269         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10270         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10271                 IPV4_ADDR_TO_UINT(res->ip_dst,
10272                         entry.input.flow.ip4_flow.dst_ip);
10273                 IPV4_ADDR_TO_UINT(res->ip_src,
10274                         entry.input.flow.ip4_flow.src_ip);
10275                 entry.input.flow.ip4_flow.tos = res->tos_value;
10276                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10277                 /* need convert to big endian. */
10278                 entry.input.flow.udp4_flow.dst_port =
10279                                 rte_cpu_to_be_16(res->port_dst);
10280                 entry.input.flow.udp4_flow.src_port =
10281                                 rte_cpu_to_be_16(res->port_src);
10282                 break;
10283         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10284                 IPV4_ADDR_TO_UINT(res->ip_dst,
10285                         entry.input.flow.sctp4_flow.ip.dst_ip);
10286                 IPV4_ADDR_TO_UINT(res->ip_src,
10287                         entry.input.flow.sctp4_flow.ip.src_ip);
10288                 entry.input.flow.ip4_flow.tos = res->tos_value;
10289                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10290                 /* need convert to big endian. */
10291                 entry.input.flow.sctp4_flow.dst_port =
10292                                 rte_cpu_to_be_16(res->port_dst);
10293                 entry.input.flow.sctp4_flow.src_port =
10294                                 rte_cpu_to_be_16(res->port_src);
10295                 entry.input.flow.sctp4_flow.verify_tag =
10296                                 rte_cpu_to_be_32(res->verify_tag_value);
10297                 break;
10298         case RTE_ETH_FLOW_FRAG_IPV6:
10299         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10300                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10301                 /* fall-through */
10302         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10303         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10304                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10305                         entry.input.flow.ipv6_flow.dst_ip);
10306                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10307                         entry.input.flow.ipv6_flow.src_ip);
10308                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10309                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10310                 /* need convert to big endian. */
10311                 entry.input.flow.udp6_flow.dst_port =
10312                                 rte_cpu_to_be_16(res->port_dst);
10313                 entry.input.flow.udp6_flow.src_port =
10314                                 rte_cpu_to_be_16(res->port_src);
10315                 break;
10316         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10317                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10318                         entry.input.flow.sctp6_flow.ip.dst_ip);
10319                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10320                         entry.input.flow.sctp6_flow.ip.src_ip);
10321                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10322                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10323                 /* need convert to big endian. */
10324                 entry.input.flow.sctp6_flow.dst_port =
10325                                 rte_cpu_to_be_16(res->port_dst);
10326                 entry.input.flow.sctp6_flow.src_port =
10327                                 rte_cpu_to_be_16(res->port_src);
10328                 entry.input.flow.sctp6_flow.verify_tag =
10329                                 rte_cpu_to_be_32(res->verify_tag_value);
10330                 break;
10331         case RTE_ETH_FLOW_L2_PAYLOAD:
10332                 entry.input.flow.l2_flow.ether_type =
10333                         rte_cpu_to_be_16(res->ether_type);
10334                 break;
10335         default:
10336                 break;
10337         }
10338
10339         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10340                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10341                                  &res->mac_addr,
10342                                  sizeof(struct ether_addr));
10343
10344         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10345                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10346                                  &res->mac_addr,
10347                                  sizeof(struct ether_addr));
10348                 entry.input.flow.tunnel_flow.tunnel_type =
10349                         str2fdir_tunneltype(res->tunnel_type);
10350                 entry.input.flow.tunnel_flow.tunnel_id =
10351                         rte_cpu_to_be_32(res->tunnel_id_value);
10352         }
10353
10354         rte_memcpy(entry.input.flow_ext.flexbytes,
10355                    flexbytes,
10356                    RTE_ETH_FDIR_MAX_FLEXLEN);
10357
10358         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10359
10360         entry.action.flex_off = 0;  /*use 0 by default */
10361         if (!strcmp(res->drop, "drop"))
10362                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10363         else
10364                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10365
10366         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10367             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10368                 if (!strcmp(res->pf_vf, "pf"))
10369                         entry.input.flow_ext.is_vf = 0;
10370                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10371                         struct rte_eth_dev_info dev_info;
10372
10373                         memset(&dev_info, 0, sizeof(dev_info));
10374                         rte_eth_dev_info_get(res->port_id, &dev_info);
10375                         errno = 0;
10376                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10377                         if (errno != 0 || *end != '\0' ||
10378                             vf_id >= dev_info.max_vfs) {
10379                                 printf("invalid parameter %s.\n", res->pf_vf);
10380                                 return;
10381                         }
10382                         entry.input.flow_ext.is_vf = 1;
10383                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10384                 } else {
10385                         printf("invalid parameter %s.\n", res->pf_vf);
10386                         return;
10387                 }
10388         }
10389
10390         /* set to report FD ID by default */
10391         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10392         entry.action.rx_queue = res->queue_id;
10393         entry.soft_id = res->fd_id_value;
10394         if (!strcmp(res->ops, "add"))
10395                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10396                                              RTE_ETH_FILTER_ADD, &entry);
10397         else if (!strcmp(res->ops, "del"))
10398                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10399                                              RTE_ETH_FILTER_DELETE, &entry);
10400         else
10401                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10402                                              RTE_ETH_FILTER_UPDATE, &entry);
10403         if (ret < 0)
10404                 printf("flow director programming error: (%s)\n",
10405                         strerror(-ret));
10406 }
10407
10408 cmdline_parse_token_string_t cmd_flow_director_filter =
10409         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10410                                  flow_director_filter, "flow_director_filter");
10411 cmdline_parse_token_num_t cmd_flow_director_port_id =
10412         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10413                               port_id, UINT16);
10414 cmdline_parse_token_string_t cmd_flow_director_ops =
10415         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10416                                  ops, "add#del#update");
10417 cmdline_parse_token_string_t cmd_flow_director_flow =
10418         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10419                                  flow, "flow");
10420 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10421         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10422                 flow_type, NULL);
10423 cmdline_parse_token_string_t cmd_flow_director_ether =
10424         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10425                                  ether, "ether");
10426 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10427         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10428                               ether_type, UINT16);
10429 cmdline_parse_token_string_t cmd_flow_director_src =
10430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10431                                  src, "src");
10432 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10433         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10434                                  ip_src);
10435 cmdline_parse_token_num_t cmd_flow_director_port_src =
10436         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10437                               port_src, UINT16);
10438 cmdline_parse_token_string_t cmd_flow_director_dst =
10439         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10440                                  dst, "dst");
10441 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10442         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10443                                  ip_dst);
10444 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10445         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10446                               port_dst, UINT16);
10447 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10448         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10449                                   verify_tag, "verify_tag");
10450 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10451         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10452                               verify_tag_value, UINT32);
10453 cmdline_parse_token_string_t cmd_flow_director_tos =
10454         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10455                                  tos, "tos");
10456 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10457         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10458                               tos_value, UINT8);
10459 cmdline_parse_token_string_t cmd_flow_director_proto =
10460         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10461                                  proto, "proto");
10462 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10463         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10464                               proto_value, UINT8);
10465 cmdline_parse_token_string_t cmd_flow_director_ttl =
10466         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10467                                  ttl, "ttl");
10468 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10469         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10470                               ttl_value, UINT8);
10471 cmdline_parse_token_string_t cmd_flow_director_vlan =
10472         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10473                                  vlan, "vlan");
10474 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10475         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10476                               vlan_value, UINT16);
10477 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10478         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10479                                  flexbytes, "flexbytes");
10480 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10481         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10482                               flexbytes_value, NULL);
10483 cmdline_parse_token_string_t cmd_flow_director_drop =
10484         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10485                                  drop, "drop#fwd");
10486 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10487         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10488                               pf_vf, NULL);
10489 cmdline_parse_token_string_t cmd_flow_director_queue =
10490         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10491                                  queue, "queue");
10492 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10493         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10494                               queue_id, UINT16);
10495 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10496         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10497                                  fd_id, "fd_id");
10498 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10499         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10500                               fd_id_value, UINT32);
10501
10502 cmdline_parse_token_string_t cmd_flow_director_mode =
10503         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10504                                  mode, "mode");
10505 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10506         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10507                                  mode_value, "IP");
10508 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10509         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10510                                  mode_value, "MAC-VLAN");
10511 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10512         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10513                                  mode_value, "Tunnel");
10514 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10515         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10516                                  mode_value, "raw");
10517 cmdline_parse_token_string_t cmd_flow_director_mac =
10518         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10519                                  mac, "mac");
10520 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10521         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10522                                     mac_addr);
10523 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10524         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10525                                  tunnel, "tunnel");
10526 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10527         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10528                                  tunnel_type, "NVGRE#VxLAN");
10529 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10530         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10531                                  tunnel_id, "tunnel-id");
10532 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10533         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10534                               tunnel_id_value, UINT32);
10535 cmdline_parse_token_string_t cmd_flow_director_packet =
10536         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10537                                  packet, "packet");
10538 cmdline_parse_token_string_t cmd_flow_director_filepath =
10539         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10540                                  filepath, NULL);
10541
10542 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10543         .f = cmd_flow_director_filter_parsed,
10544         .data = NULL,
10545         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10546                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10547                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10548                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10549                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10550                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10551                 "fd_id <fd_id_value>: "
10552                 "Add or delete an ip flow director entry on NIC",
10553         .tokens = {
10554                 (void *)&cmd_flow_director_filter,
10555                 (void *)&cmd_flow_director_port_id,
10556                 (void *)&cmd_flow_director_mode,
10557                 (void *)&cmd_flow_director_mode_ip,
10558                 (void *)&cmd_flow_director_ops,
10559                 (void *)&cmd_flow_director_flow,
10560                 (void *)&cmd_flow_director_flow_type,
10561                 (void *)&cmd_flow_director_src,
10562                 (void *)&cmd_flow_director_ip_src,
10563                 (void *)&cmd_flow_director_dst,
10564                 (void *)&cmd_flow_director_ip_dst,
10565                 (void *)&cmd_flow_director_tos,
10566                 (void *)&cmd_flow_director_tos_value,
10567                 (void *)&cmd_flow_director_proto,
10568                 (void *)&cmd_flow_director_proto_value,
10569                 (void *)&cmd_flow_director_ttl,
10570                 (void *)&cmd_flow_director_ttl_value,
10571                 (void *)&cmd_flow_director_vlan,
10572                 (void *)&cmd_flow_director_vlan_value,
10573                 (void *)&cmd_flow_director_flexbytes,
10574                 (void *)&cmd_flow_director_flexbytes_value,
10575                 (void *)&cmd_flow_director_drop,
10576                 (void *)&cmd_flow_director_pf_vf,
10577                 (void *)&cmd_flow_director_queue,
10578                 (void *)&cmd_flow_director_queue_id,
10579                 (void *)&cmd_flow_director_fd_id,
10580                 (void *)&cmd_flow_director_fd_id_value,
10581                 NULL,
10582         },
10583 };
10584
10585 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10586         .f = cmd_flow_director_filter_parsed,
10587         .data = NULL,
10588         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10589                 "director entry on NIC",
10590         .tokens = {
10591                 (void *)&cmd_flow_director_filter,
10592                 (void *)&cmd_flow_director_port_id,
10593                 (void *)&cmd_flow_director_mode,
10594                 (void *)&cmd_flow_director_mode_ip,
10595                 (void *)&cmd_flow_director_ops,
10596                 (void *)&cmd_flow_director_flow,
10597                 (void *)&cmd_flow_director_flow_type,
10598                 (void *)&cmd_flow_director_src,
10599                 (void *)&cmd_flow_director_ip_src,
10600                 (void *)&cmd_flow_director_port_src,
10601                 (void *)&cmd_flow_director_dst,
10602                 (void *)&cmd_flow_director_ip_dst,
10603                 (void *)&cmd_flow_director_port_dst,
10604                 (void *)&cmd_flow_director_tos,
10605                 (void *)&cmd_flow_director_tos_value,
10606                 (void *)&cmd_flow_director_ttl,
10607                 (void *)&cmd_flow_director_ttl_value,
10608                 (void *)&cmd_flow_director_vlan,
10609                 (void *)&cmd_flow_director_vlan_value,
10610                 (void *)&cmd_flow_director_flexbytes,
10611                 (void *)&cmd_flow_director_flexbytes_value,
10612                 (void *)&cmd_flow_director_drop,
10613                 (void *)&cmd_flow_director_pf_vf,
10614                 (void *)&cmd_flow_director_queue,
10615                 (void *)&cmd_flow_director_queue_id,
10616                 (void *)&cmd_flow_director_fd_id,
10617                 (void *)&cmd_flow_director_fd_id_value,
10618                 NULL,
10619         },
10620 };
10621
10622 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10623         .f = cmd_flow_director_filter_parsed,
10624         .data = NULL,
10625         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10626                 "director entry on NIC",
10627         .tokens = {
10628                 (void *)&cmd_flow_director_filter,
10629                 (void *)&cmd_flow_director_port_id,
10630                 (void *)&cmd_flow_director_mode,
10631                 (void *)&cmd_flow_director_mode_ip,
10632                 (void *)&cmd_flow_director_ops,
10633                 (void *)&cmd_flow_director_flow,
10634                 (void *)&cmd_flow_director_flow_type,
10635                 (void *)&cmd_flow_director_src,
10636                 (void *)&cmd_flow_director_ip_src,
10637                 (void *)&cmd_flow_director_port_src,
10638                 (void *)&cmd_flow_director_dst,
10639                 (void *)&cmd_flow_director_ip_dst,
10640                 (void *)&cmd_flow_director_port_dst,
10641                 (void *)&cmd_flow_director_verify_tag,
10642                 (void *)&cmd_flow_director_verify_tag_value,
10643                 (void *)&cmd_flow_director_tos,
10644                 (void *)&cmd_flow_director_tos_value,
10645                 (void *)&cmd_flow_director_ttl,
10646                 (void *)&cmd_flow_director_ttl_value,
10647                 (void *)&cmd_flow_director_vlan,
10648                 (void *)&cmd_flow_director_vlan_value,
10649                 (void *)&cmd_flow_director_flexbytes,
10650                 (void *)&cmd_flow_director_flexbytes_value,
10651                 (void *)&cmd_flow_director_drop,
10652                 (void *)&cmd_flow_director_pf_vf,
10653                 (void *)&cmd_flow_director_queue,
10654                 (void *)&cmd_flow_director_queue_id,
10655                 (void *)&cmd_flow_director_fd_id,
10656                 (void *)&cmd_flow_director_fd_id_value,
10657                 NULL,
10658         },
10659 };
10660
10661 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10662         .f = cmd_flow_director_filter_parsed,
10663         .data = NULL,
10664         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10665                 "director entry on NIC",
10666         .tokens = {
10667                 (void *)&cmd_flow_director_filter,
10668                 (void *)&cmd_flow_director_port_id,
10669                 (void *)&cmd_flow_director_mode,
10670                 (void *)&cmd_flow_director_mode_ip,
10671                 (void *)&cmd_flow_director_ops,
10672                 (void *)&cmd_flow_director_flow,
10673                 (void *)&cmd_flow_director_flow_type,
10674                 (void *)&cmd_flow_director_ether,
10675                 (void *)&cmd_flow_director_ether_type,
10676                 (void *)&cmd_flow_director_flexbytes,
10677                 (void *)&cmd_flow_director_flexbytes_value,
10678                 (void *)&cmd_flow_director_drop,
10679                 (void *)&cmd_flow_director_pf_vf,
10680                 (void *)&cmd_flow_director_queue,
10681                 (void *)&cmd_flow_director_queue_id,
10682                 (void *)&cmd_flow_director_fd_id,
10683                 (void *)&cmd_flow_director_fd_id_value,
10684                 NULL,
10685         },
10686 };
10687
10688 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10689         .f = cmd_flow_director_filter_parsed,
10690         .data = NULL,
10691         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10692                 "director entry on NIC",
10693         .tokens = {
10694                 (void *)&cmd_flow_director_filter,
10695                 (void *)&cmd_flow_director_port_id,
10696                 (void *)&cmd_flow_director_mode,
10697                 (void *)&cmd_flow_director_mode_mac_vlan,
10698                 (void *)&cmd_flow_director_ops,
10699                 (void *)&cmd_flow_director_mac,
10700                 (void *)&cmd_flow_director_mac_addr,
10701                 (void *)&cmd_flow_director_vlan,
10702                 (void *)&cmd_flow_director_vlan_value,
10703                 (void *)&cmd_flow_director_flexbytes,
10704                 (void *)&cmd_flow_director_flexbytes_value,
10705                 (void *)&cmd_flow_director_drop,
10706                 (void *)&cmd_flow_director_queue,
10707                 (void *)&cmd_flow_director_queue_id,
10708                 (void *)&cmd_flow_director_fd_id,
10709                 (void *)&cmd_flow_director_fd_id_value,
10710                 NULL,
10711         },
10712 };
10713
10714 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10715         .f = cmd_flow_director_filter_parsed,
10716         .data = NULL,
10717         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10718                 "director entry on NIC",
10719         .tokens = {
10720                 (void *)&cmd_flow_director_filter,
10721                 (void *)&cmd_flow_director_port_id,
10722                 (void *)&cmd_flow_director_mode,
10723                 (void *)&cmd_flow_director_mode_tunnel,
10724                 (void *)&cmd_flow_director_ops,
10725                 (void *)&cmd_flow_director_mac,
10726                 (void *)&cmd_flow_director_mac_addr,
10727                 (void *)&cmd_flow_director_vlan,
10728                 (void *)&cmd_flow_director_vlan_value,
10729                 (void *)&cmd_flow_director_tunnel,
10730                 (void *)&cmd_flow_director_tunnel_type,
10731                 (void *)&cmd_flow_director_tunnel_id,
10732                 (void *)&cmd_flow_director_tunnel_id_value,
10733                 (void *)&cmd_flow_director_flexbytes,
10734                 (void *)&cmd_flow_director_flexbytes_value,
10735                 (void *)&cmd_flow_director_drop,
10736                 (void *)&cmd_flow_director_queue,
10737                 (void *)&cmd_flow_director_queue_id,
10738                 (void *)&cmd_flow_director_fd_id,
10739                 (void *)&cmd_flow_director_fd_id_value,
10740                 NULL,
10741         },
10742 };
10743
10744 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10745         .f = cmd_flow_director_filter_parsed,
10746         .data = NULL,
10747         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10748                 "director entry on NIC",
10749         .tokens = {
10750                 (void *)&cmd_flow_director_filter,
10751                 (void *)&cmd_flow_director_port_id,
10752                 (void *)&cmd_flow_director_mode,
10753                 (void *)&cmd_flow_director_mode_raw,
10754                 (void *)&cmd_flow_director_ops,
10755                 (void *)&cmd_flow_director_flow,
10756                 (void *)&cmd_flow_director_flow_type,
10757                 (void *)&cmd_flow_director_drop,
10758                 (void *)&cmd_flow_director_queue,
10759                 (void *)&cmd_flow_director_queue_id,
10760                 (void *)&cmd_flow_director_fd_id,
10761                 (void *)&cmd_flow_director_fd_id_value,
10762                 (void *)&cmd_flow_director_packet,
10763                 (void *)&cmd_flow_director_filepath,
10764                 NULL,
10765         },
10766 };
10767
10768 struct cmd_flush_flow_director_result {
10769         cmdline_fixed_string_t flush_flow_director;
10770         portid_t port_id;
10771 };
10772
10773 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10774         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10775                                  flush_flow_director, "flush_flow_director");
10776 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10777         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10778                               port_id, UINT16);
10779
10780 static void
10781 cmd_flush_flow_director_parsed(void *parsed_result,
10782                           __attribute__((unused)) struct cmdline *cl,
10783                           __attribute__((unused)) void *data)
10784 {
10785         struct cmd_flow_director_result *res = parsed_result;
10786         int ret = 0;
10787
10788         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10789         if (ret < 0) {
10790                 printf("flow director is not supported on port %u.\n",
10791                         res->port_id);
10792                 return;
10793         }
10794
10795         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10796                         RTE_ETH_FILTER_FLUSH, NULL);
10797         if (ret < 0)
10798                 printf("flow director table flushing error: (%s)\n",
10799                         strerror(-ret));
10800 }
10801
10802 cmdline_parse_inst_t cmd_flush_flow_director = {
10803         .f = cmd_flush_flow_director_parsed,
10804         .data = NULL,
10805         .help_str = "flush_flow_director <port_id>: "
10806                 "Flush all flow director entries of a device on NIC",
10807         .tokens = {
10808                 (void *)&cmd_flush_flow_director_flush,
10809                 (void *)&cmd_flush_flow_director_port_id,
10810                 NULL,
10811         },
10812 };
10813
10814 /* *** deal with flow director mask *** */
10815 struct cmd_flow_director_mask_result {
10816         cmdline_fixed_string_t flow_director_mask;
10817         portid_t port_id;
10818         cmdline_fixed_string_t mode;
10819         cmdline_fixed_string_t mode_value;
10820         cmdline_fixed_string_t vlan;
10821         uint16_t vlan_mask;
10822         cmdline_fixed_string_t src_mask;
10823         cmdline_ipaddr_t ipv4_src;
10824         cmdline_ipaddr_t ipv6_src;
10825         uint16_t port_src;
10826         cmdline_fixed_string_t dst_mask;
10827         cmdline_ipaddr_t ipv4_dst;
10828         cmdline_ipaddr_t ipv6_dst;
10829         uint16_t port_dst;
10830         cmdline_fixed_string_t mac;
10831         uint8_t mac_addr_byte_mask;
10832         cmdline_fixed_string_t tunnel_id;
10833         uint32_t tunnel_id_mask;
10834         cmdline_fixed_string_t tunnel_type;
10835         uint8_t tunnel_type_mask;
10836 };
10837
10838 static void
10839 cmd_flow_director_mask_parsed(void *parsed_result,
10840                           __attribute__((unused)) struct cmdline *cl,
10841                           __attribute__((unused)) void *data)
10842 {
10843         struct cmd_flow_director_mask_result *res = parsed_result;
10844         struct rte_eth_fdir_masks *mask;
10845         struct rte_port *port;
10846
10847         if (res->port_id > nb_ports) {
10848                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10849                 return;
10850         }
10851
10852         port = &ports[res->port_id];
10853         /** Check if the port is not started **/
10854         if (port->port_status != RTE_PORT_STOPPED) {
10855                 printf("Please stop port %d first\n", res->port_id);
10856                 return;
10857         }
10858
10859         mask = &port->dev_conf.fdir_conf.mask;
10860
10861         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10862                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10863                         printf("Please set mode to MAC-VLAN.\n");
10864                         return;
10865                 }
10866
10867                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10868         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10869                 if (strcmp(res->mode_value, "Tunnel")) {
10870                         printf("Please set mode to Tunnel.\n");
10871                         return;
10872                 }
10873
10874                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10875                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10876                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10877                 mask->tunnel_type_mask = res->tunnel_type_mask;
10878         } else {
10879                 if (strcmp(res->mode_value, "IP")) {
10880                         printf("Please set mode to IP.\n");
10881                         return;
10882                 }
10883
10884                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10885                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10886                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10887                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10888                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10889                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10890                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10891         }
10892
10893         cmd_reconfig_device_queue(res->port_id, 1, 1);
10894 }
10895
10896 cmdline_parse_token_string_t cmd_flow_director_mask =
10897         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10898                                  flow_director_mask, "flow_director_mask");
10899 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10900         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10901                               port_id, UINT16);
10902 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10903         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10904                                  vlan, "vlan");
10905 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10906         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10907                               vlan_mask, UINT16);
10908 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10909         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10910                                  src_mask, "src_mask");
10911 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10912         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10913                                  ipv4_src);
10914 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10915         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10916                                  ipv6_src);
10917 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10918         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10919                               port_src, UINT16);
10920 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10921         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10922                                  dst_mask, "dst_mask");
10923 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10924         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10925                                  ipv4_dst);
10926 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10927         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10928                                  ipv6_dst);
10929 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10930         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10931                               port_dst, UINT16);
10932
10933 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10934         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10935                                  mode, "mode");
10936 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10937         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10938                                  mode_value, "IP");
10939 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10940         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10941                                  mode_value, "MAC-VLAN");
10942 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10943         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10944                                  mode_value, "Tunnel");
10945 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10946         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10947                                  mac, "mac");
10948 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10949         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10950                               mac_addr_byte_mask, UINT8);
10951 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10952         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10953                                  tunnel_type, "tunnel-type");
10954 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10955         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10956                               tunnel_type_mask, UINT8);
10957 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10958         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10959                                  tunnel_id, "tunnel-id");
10960 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10961         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10962                               tunnel_id_mask, UINT32);
10963
10964 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10965         .f = cmd_flow_director_mask_parsed,
10966         .data = NULL,
10967         .help_str = "flow_director_mask ... : "
10968                 "Set IP mode flow director's mask on NIC",
10969         .tokens = {
10970                 (void *)&cmd_flow_director_mask,
10971                 (void *)&cmd_flow_director_mask_port_id,
10972                 (void *)&cmd_flow_director_mask_mode,
10973                 (void *)&cmd_flow_director_mask_mode_ip,
10974                 (void *)&cmd_flow_director_mask_vlan,
10975                 (void *)&cmd_flow_director_mask_vlan_value,
10976                 (void *)&cmd_flow_director_mask_src,
10977                 (void *)&cmd_flow_director_mask_ipv4_src,
10978                 (void *)&cmd_flow_director_mask_ipv6_src,
10979                 (void *)&cmd_flow_director_mask_port_src,
10980                 (void *)&cmd_flow_director_mask_dst,
10981                 (void *)&cmd_flow_director_mask_ipv4_dst,
10982                 (void *)&cmd_flow_director_mask_ipv6_dst,
10983                 (void *)&cmd_flow_director_mask_port_dst,
10984                 NULL,
10985         },
10986 };
10987
10988 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10989         .f = cmd_flow_director_mask_parsed,
10990         .data = NULL,
10991         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10992                 "flow director's mask on NIC",
10993         .tokens = {
10994                 (void *)&cmd_flow_director_mask,
10995                 (void *)&cmd_flow_director_mask_port_id,
10996                 (void *)&cmd_flow_director_mask_mode,
10997                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10998                 (void *)&cmd_flow_director_mask_vlan,
10999                 (void *)&cmd_flow_director_mask_vlan_value,
11000                 NULL,
11001         },
11002 };
11003
11004 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11005         .f = cmd_flow_director_mask_parsed,
11006         .data = NULL,
11007         .help_str = "flow_director_mask ... : Set tunnel mode "
11008                 "flow director's mask on NIC",
11009         .tokens = {
11010                 (void *)&cmd_flow_director_mask,
11011                 (void *)&cmd_flow_director_mask_port_id,
11012                 (void *)&cmd_flow_director_mask_mode,
11013                 (void *)&cmd_flow_director_mask_mode_tunnel,
11014                 (void *)&cmd_flow_director_mask_vlan,
11015                 (void *)&cmd_flow_director_mask_vlan_value,
11016                 (void *)&cmd_flow_director_mask_mac,
11017                 (void *)&cmd_flow_director_mask_mac_value,
11018                 (void *)&cmd_flow_director_mask_tunnel_type,
11019                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11020                 (void *)&cmd_flow_director_mask_tunnel_id,
11021                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11022                 NULL,
11023         },
11024 };
11025
11026 /* *** deal with flow director mask on flexible payload *** */
11027 struct cmd_flow_director_flex_mask_result {
11028         cmdline_fixed_string_t flow_director_flexmask;
11029         portid_t port_id;
11030         cmdline_fixed_string_t flow;
11031         cmdline_fixed_string_t flow_type;
11032         cmdline_fixed_string_t mask;
11033 };
11034
11035 static void
11036 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11037                           __attribute__((unused)) struct cmdline *cl,
11038                           __attribute__((unused)) void *data)
11039 {
11040         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11041         struct rte_eth_fdir_info fdir_info;
11042         struct rte_eth_fdir_flex_mask flex_mask;
11043         struct rte_port *port;
11044         uint64_t flow_type_mask;
11045         uint16_t i;
11046         int ret;
11047
11048         if (res->port_id > nb_ports) {
11049                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
11050                 return;
11051         }
11052
11053         port = &ports[res->port_id];
11054         /** Check if the port is not started **/
11055         if (port->port_status != RTE_PORT_STOPPED) {
11056                 printf("Please stop port %d first\n", res->port_id);
11057                 return;
11058         }
11059
11060         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11061         ret = parse_flexbytes(res->mask,
11062                         flex_mask.mask,
11063                         RTE_ETH_FDIR_MAX_FLEXLEN);
11064         if (ret < 0) {
11065                 printf("error: Cannot parse mask input.\n");
11066                 return;
11067         }
11068
11069         memset(&fdir_info, 0, sizeof(fdir_info));
11070         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11071                                 RTE_ETH_FILTER_INFO, &fdir_info);
11072         if (ret < 0) {
11073                 printf("Cannot get FDir filter info\n");
11074                 return;
11075         }
11076
11077         if (!strcmp(res->flow_type, "none")) {
11078                 /* means don't specify the flow type */
11079                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11080                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11081                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11082                                0, sizeof(struct rte_eth_fdir_flex_mask));
11083                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11084                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11085                                  &flex_mask,
11086                                  sizeof(struct rte_eth_fdir_flex_mask));
11087                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11088                 return;
11089         }
11090         flow_type_mask = fdir_info.flow_types_mask[0];
11091         if (!strcmp(res->flow_type, "all")) {
11092                 if (!flow_type_mask) {
11093                         printf("No flow type supported\n");
11094                         return;
11095                 }
11096                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11097                         if (flow_type_mask & (1ULL << i)) {
11098                                 flex_mask.flow_type = i;
11099                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11100                         }
11101                 }
11102                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11103                 return;
11104         }
11105         flex_mask.flow_type = str2flowtype(res->flow_type);
11106         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11107                 printf("Flow type %s not supported on port %d\n",
11108                                 res->flow_type, res->port_id);
11109                 return;
11110         }
11111         fdir_set_flex_mask(res->port_id, &flex_mask);
11112         cmd_reconfig_device_queue(res->port_id, 1, 1);
11113 }
11114
11115 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11116         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11117                                  flow_director_flexmask,
11118                                  "flow_director_flex_mask");
11119 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11120         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11121                               port_id, UINT16);
11122 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11123         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11124                                  flow, "flow");
11125 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11126         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11127                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11128                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11129 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11130         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11131                                  mask, NULL);
11132
11133 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11134         .f = cmd_flow_director_flex_mask_parsed,
11135         .data = NULL,
11136         .help_str = "flow_director_flex_mask ... : "
11137                 "Set flow director's flex mask on NIC",
11138         .tokens = {
11139                 (void *)&cmd_flow_director_flexmask,
11140                 (void *)&cmd_flow_director_flexmask_port_id,
11141                 (void *)&cmd_flow_director_flexmask_flow,
11142                 (void *)&cmd_flow_director_flexmask_flow_type,
11143                 (void *)&cmd_flow_director_flexmask_mask,
11144                 NULL,
11145         },
11146 };
11147
11148 /* *** deal with flow director flexible payload configuration *** */
11149 struct cmd_flow_director_flexpayload_result {
11150         cmdline_fixed_string_t flow_director_flexpayload;
11151         portid_t port_id;
11152         cmdline_fixed_string_t payload_layer;
11153         cmdline_fixed_string_t payload_cfg;
11154 };
11155
11156 static inline int
11157 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11158 {
11159         char s[256];
11160         const char *p, *p0 = q_arg;
11161         char *end;
11162         unsigned long int_fld;
11163         char *str_fld[max_num];
11164         int i;
11165         unsigned size;
11166         int ret = -1;
11167
11168         p = strchr(p0, '(');
11169         if (p == NULL)
11170                 return -1;
11171         ++p;
11172         p0 = strchr(p, ')');
11173         if (p0 == NULL)
11174                 return -1;
11175
11176         size = p0 - p;
11177         if (size >= sizeof(s))
11178                 return -1;
11179
11180         snprintf(s, sizeof(s), "%.*s", size, p);
11181         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11182         if (ret < 0 || ret > max_num)
11183                 return -1;
11184         for (i = 0; i < ret; i++) {
11185                 errno = 0;
11186                 int_fld = strtoul(str_fld[i], &end, 0);
11187                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11188                         return -1;
11189                 offsets[i] = (uint16_t)int_fld;
11190         }
11191         return ret;
11192 }
11193
11194 static void
11195 cmd_flow_director_flxpld_parsed(void *parsed_result,
11196                           __attribute__((unused)) struct cmdline *cl,
11197                           __attribute__((unused)) void *data)
11198 {
11199         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11200         struct rte_eth_flex_payload_cfg flex_cfg;
11201         struct rte_port *port;
11202         int ret = 0;
11203
11204         if (res->port_id > nb_ports) {
11205                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
11206                 return;
11207         }
11208
11209         port = &ports[res->port_id];
11210         /** Check if the port is not started **/
11211         if (port->port_status != RTE_PORT_STOPPED) {
11212                 printf("Please stop port %d first\n", res->port_id);
11213                 return;
11214         }
11215
11216         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11217
11218         if (!strcmp(res->payload_layer, "raw"))
11219                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11220         else if (!strcmp(res->payload_layer, "l2"))
11221                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11222         else if (!strcmp(res->payload_layer, "l3"))
11223                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11224         else if (!strcmp(res->payload_layer, "l4"))
11225                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11226
11227         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11228                             RTE_ETH_FDIR_MAX_FLEXLEN);
11229         if (ret < 0) {
11230                 printf("error: Cannot parse flex payload input.\n");
11231                 return;
11232         }
11233
11234         fdir_set_flex_payload(res->port_id, &flex_cfg);
11235         cmd_reconfig_device_queue(res->port_id, 1, 1);
11236 }
11237
11238 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11239         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11240                                  flow_director_flexpayload,
11241                                  "flow_director_flex_payload");
11242 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11243         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11244                               port_id, UINT16);
11245 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11246         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11247                                  payload_layer, "raw#l2#l3#l4");
11248 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11249         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11250                                  payload_cfg, NULL);
11251
11252 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11253         .f = cmd_flow_director_flxpld_parsed,
11254         .data = NULL,
11255         .help_str = "flow_director_flexpayload ... : "
11256                 "Set flow director's flex payload on NIC",
11257         .tokens = {
11258                 (void *)&cmd_flow_director_flexpayload,
11259                 (void *)&cmd_flow_director_flexpayload_port_id,
11260                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11261                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11262                 NULL,
11263         },
11264 };
11265
11266 /* Generic flow interface command. */
11267 extern cmdline_parse_inst_t cmd_flow;
11268
11269 /* *** Classification Filters Control *** */
11270 /* *** Get symmetric hash enable per port *** */
11271 struct cmd_get_sym_hash_ena_per_port_result {
11272         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11273         portid_t port_id;
11274 };
11275
11276 static void
11277 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11278                                  __rte_unused struct cmdline *cl,
11279                                  __rte_unused void *data)
11280 {
11281         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11282         struct rte_eth_hash_filter_info info;
11283         int ret;
11284
11285         if (rte_eth_dev_filter_supported(res->port_id,
11286                                 RTE_ETH_FILTER_HASH) < 0) {
11287                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11288                                                         res->port_id);
11289                 return;
11290         }
11291
11292         memset(&info, 0, sizeof(info));
11293         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11294         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11295                                                 RTE_ETH_FILTER_GET, &info);
11296
11297         if (ret < 0) {
11298                 printf("Cannot get symmetric hash enable per port "
11299                                         "on port %u\n", res->port_id);
11300                 return;
11301         }
11302
11303         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11304                                 "enabled" : "disabled", res->port_id);
11305 }
11306
11307 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11308         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11309                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11310 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11311         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11312                 port_id, UINT16);
11313
11314 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11315         .f = cmd_get_sym_hash_per_port_parsed,
11316         .data = NULL,
11317         .help_str = "get_sym_hash_ena_per_port <port_id>",
11318         .tokens = {
11319                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11320                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11321                 NULL,
11322         },
11323 };
11324
11325 /* *** Set symmetric hash enable per port *** */
11326 struct cmd_set_sym_hash_ena_per_port_result {
11327         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11328         cmdline_fixed_string_t enable;
11329         portid_t port_id;
11330 };
11331
11332 static void
11333 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11334                                  __rte_unused struct cmdline *cl,
11335                                  __rte_unused void *data)
11336 {
11337         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11338         struct rte_eth_hash_filter_info info;
11339         int ret;
11340
11341         if (rte_eth_dev_filter_supported(res->port_id,
11342                                 RTE_ETH_FILTER_HASH) < 0) {
11343                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11344                                                         res->port_id);
11345                 return;
11346         }
11347
11348         memset(&info, 0, sizeof(info));
11349         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11350         if (!strcmp(res->enable, "enable"))
11351                 info.info.enable = 1;
11352         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11353                                         RTE_ETH_FILTER_SET, &info);
11354         if (ret < 0) {
11355                 printf("Cannot set symmetric hash enable per port on "
11356                                         "port %u\n", res->port_id);
11357                 return;
11358         }
11359         printf("Symmetric hash has been set to %s on port %u\n",
11360                                         res->enable, res->port_id);
11361 }
11362
11363 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11364         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11365                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11366 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11367         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11368                 port_id, UINT16);
11369 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11370         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11371                 enable, "enable#disable");
11372
11373 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11374         .f = cmd_set_sym_hash_per_port_parsed,
11375         .data = NULL,
11376         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11377         .tokens = {
11378                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11379                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11380                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11381                 NULL,
11382         },
11383 };
11384
11385 /* Get global config of hash function */
11386 struct cmd_get_hash_global_config_result {
11387         cmdline_fixed_string_t get_hash_global_config;
11388         portid_t port_id;
11389 };
11390
11391 static char *
11392 flowtype_to_str(uint16_t ftype)
11393 {
11394         uint16_t i;
11395         static struct {
11396                 char str[16];
11397                 uint16_t ftype;
11398         } ftype_table[] = {
11399                 {"ipv4", RTE_ETH_FLOW_IPV4},
11400                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11401                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11402                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11403                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11404                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11405                 {"ipv6", RTE_ETH_FLOW_IPV6},
11406                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11407                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11408                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11409                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11410                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11411                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11412                 {"port", RTE_ETH_FLOW_PORT},
11413                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11414                 {"geneve", RTE_ETH_FLOW_GENEVE},
11415                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11416         };
11417
11418         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11419                 if (ftype_table[i].ftype == ftype)
11420                         return ftype_table[i].str;
11421         }
11422
11423         return NULL;
11424 }
11425
11426 static void
11427 cmd_get_hash_global_config_parsed(void *parsed_result,
11428                                   __rte_unused struct cmdline *cl,
11429                                   __rte_unused void *data)
11430 {
11431         struct cmd_get_hash_global_config_result *res = parsed_result;
11432         struct rte_eth_hash_filter_info info;
11433         uint32_t idx, offset;
11434         uint16_t i;
11435         char *str;
11436         int ret;
11437
11438         if (rte_eth_dev_filter_supported(res->port_id,
11439                         RTE_ETH_FILTER_HASH) < 0) {
11440                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11441                                                         res->port_id);
11442                 return;
11443         }
11444
11445         memset(&info, 0, sizeof(info));
11446         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11447         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11448                                         RTE_ETH_FILTER_GET, &info);
11449         if (ret < 0) {
11450                 printf("Cannot get hash global configurations by port %d\n",
11451                                                         res->port_id);
11452                 return;
11453         }
11454
11455         switch (info.info.global_conf.hash_func) {
11456         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11457                 printf("Hash function is Toeplitz\n");
11458                 break;
11459         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11460                 printf("Hash function is Simple XOR\n");
11461                 break;
11462         default:
11463                 printf("Unknown hash function\n");
11464                 break;
11465         }
11466
11467         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11468                 idx = i / UINT64_BIT;
11469                 offset = i % UINT64_BIT;
11470                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11471                                                 (1ULL << offset)))
11472                         continue;
11473                 str = flowtype_to_str(i);
11474                 if (!str)
11475                         continue;
11476                 printf("Symmetric hash is %s globally for flow type %s "
11477                                                         "by port %d\n",
11478                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11479                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11480                                                         res->port_id);
11481         }
11482 }
11483
11484 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11485         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11486                 get_hash_global_config, "get_hash_global_config");
11487 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11488         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11489                 port_id, UINT16);
11490
11491 cmdline_parse_inst_t cmd_get_hash_global_config = {
11492         .f = cmd_get_hash_global_config_parsed,
11493         .data = NULL,
11494         .help_str = "get_hash_global_config <port_id>",
11495         .tokens = {
11496                 (void *)&cmd_get_hash_global_config_all,
11497                 (void *)&cmd_get_hash_global_config_port_id,
11498                 NULL,
11499         },
11500 };
11501
11502 /* Set global config of hash function */
11503 struct cmd_set_hash_global_config_result {
11504         cmdline_fixed_string_t set_hash_global_config;
11505         portid_t port_id;
11506         cmdline_fixed_string_t hash_func;
11507         cmdline_fixed_string_t flow_type;
11508         cmdline_fixed_string_t enable;
11509 };
11510
11511 static void
11512 cmd_set_hash_global_config_parsed(void *parsed_result,
11513                                   __rte_unused struct cmdline *cl,
11514                                   __rte_unused void *data)
11515 {
11516         struct cmd_set_hash_global_config_result *res = parsed_result;
11517         struct rte_eth_hash_filter_info info;
11518         uint32_t ftype, idx, offset;
11519         int ret;
11520
11521         if (rte_eth_dev_filter_supported(res->port_id,
11522                                 RTE_ETH_FILTER_HASH) < 0) {
11523                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11524                                                         res->port_id);
11525                 return;
11526         }
11527         memset(&info, 0, sizeof(info));
11528         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11529         if (!strcmp(res->hash_func, "toeplitz"))
11530                 info.info.global_conf.hash_func =
11531                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11532         else if (!strcmp(res->hash_func, "simple_xor"))
11533                 info.info.global_conf.hash_func =
11534                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11535         else if (!strcmp(res->hash_func, "default"))
11536                 info.info.global_conf.hash_func =
11537                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11538
11539         ftype = str2flowtype(res->flow_type);
11540         idx = ftype / UINT64_BIT;
11541         offset = ftype % UINT64_BIT;
11542         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11543         if (!strcmp(res->enable, "enable"))
11544                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11545                                                 (1ULL << offset);
11546         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11547                                         RTE_ETH_FILTER_SET, &info);
11548         if (ret < 0)
11549                 printf("Cannot set global hash configurations by port %d\n",
11550                                                         res->port_id);
11551         else
11552                 printf("Global hash configurations have been set "
11553                         "succcessfully by port %d\n", res->port_id);
11554 }
11555
11556 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11557         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11558                 set_hash_global_config, "set_hash_global_config");
11559 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11560         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11561                 port_id, UINT16);
11562 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11563         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11564                 hash_func, "toeplitz#simple_xor#default");
11565 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11566         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11567                 flow_type,
11568                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11569                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11570 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11571         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11572                 enable, "enable#disable");
11573
11574 cmdline_parse_inst_t cmd_set_hash_global_config = {
11575         .f = cmd_set_hash_global_config_parsed,
11576         .data = NULL,
11577         .help_str = "set_hash_global_config <port_id> "
11578                 "toeplitz|simple_xor|default "
11579                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11580                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11581                 "l2_payload enable|disable",
11582         .tokens = {
11583                 (void *)&cmd_set_hash_global_config_all,
11584                 (void *)&cmd_set_hash_global_config_port_id,
11585                 (void *)&cmd_set_hash_global_config_hash_func,
11586                 (void *)&cmd_set_hash_global_config_flow_type,
11587                 (void *)&cmd_set_hash_global_config_enable,
11588                 NULL,
11589         },
11590 };
11591
11592 /* Set hash input set */
11593 struct cmd_set_hash_input_set_result {
11594         cmdline_fixed_string_t set_hash_input_set;
11595         portid_t port_id;
11596         cmdline_fixed_string_t flow_type;
11597         cmdline_fixed_string_t inset_field;
11598         cmdline_fixed_string_t select;
11599 };
11600
11601 static enum rte_eth_input_set_field
11602 str2inset(char *string)
11603 {
11604         uint16_t i;
11605
11606         static const struct {
11607                 char str[32];
11608                 enum rte_eth_input_set_field inset;
11609         } inset_table[] = {
11610                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11611                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11612                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11613                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11614                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11615                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11616                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11617                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11618                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11619                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11620                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11621                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11622                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11623                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11624                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11625                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11626                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11627                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11628                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11629                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11630                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11631                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11632                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11633                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11634                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11635                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11636                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11637                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11638                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11639                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11640                 {"none", RTE_ETH_INPUT_SET_NONE},
11641         };
11642
11643         for (i = 0; i < RTE_DIM(inset_table); i++) {
11644                 if (!strcmp(string, inset_table[i].str))
11645                         return inset_table[i].inset;
11646         }
11647
11648         return RTE_ETH_INPUT_SET_UNKNOWN;
11649 }
11650
11651 static void
11652 cmd_set_hash_input_set_parsed(void *parsed_result,
11653                               __rte_unused struct cmdline *cl,
11654                               __rte_unused void *data)
11655 {
11656         struct cmd_set_hash_input_set_result *res = parsed_result;
11657         struct rte_eth_hash_filter_info info;
11658
11659         memset(&info, 0, sizeof(info));
11660         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11661         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11662         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11663         info.info.input_set_conf.inset_size = 1;
11664         if (!strcmp(res->select, "select"))
11665                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11666         else if (!strcmp(res->select, "add"))
11667                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11668         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11669                                 RTE_ETH_FILTER_SET, &info);
11670 }
11671
11672 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11673         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11674                 set_hash_input_set, "set_hash_input_set");
11675 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11676         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11677                 port_id, UINT16);
11678 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11679         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11680                 flow_type, NULL);
11681 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11682         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11683                 inset_field,
11684                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11685                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11686                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11687                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11688                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11689                 "fld-8th#none");
11690 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11691         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11692                 select, "select#add");
11693
11694 cmdline_parse_inst_t cmd_set_hash_input_set = {
11695         .f = cmd_set_hash_input_set_parsed,
11696         .data = NULL,
11697         .help_str = "set_hash_input_set <port_id> "
11698         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11699         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11700         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11701         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11702         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11703         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11704         "fld-7th|fld-8th|none select|add",
11705         .tokens = {
11706                 (void *)&cmd_set_hash_input_set_cmd,
11707                 (void *)&cmd_set_hash_input_set_port_id,
11708                 (void *)&cmd_set_hash_input_set_flow_type,
11709                 (void *)&cmd_set_hash_input_set_field,
11710                 (void *)&cmd_set_hash_input_set_select,
11711                 NULL,
11712         },
11713 };
11714
11715 /* Set flow director input set */
11716 struct cmd_set_fdir_input_set_result {
11717         cmdline_fixed_string_t set_fdir_input_set;
11718         portid_t port_id;
11719         cmdline_fixed_string_t flow_type;
11720         cmdline_fixed_string_t inset_field;
11721         cmdline_fixed_string_t select;
11722 };
11723
11724 static void
11725 cmd_set_fdir_input_set_parsed(void *parsed_result,
11726         __rte_unused struct cmdline *cl,
11727         __rte_unused void *data)
11728 {
11729         struct cmd_set_fdir_input_set_result *res = parsed_result;
11730         struct rte_eth_fdir_filter_info info;
11731
11732         memset(&info, 0, sizeof(info));
11733         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11734         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11735         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11736         info.info.input_set_conf.inset_size = 1;
11737         if (!strcmp(res->select, "select"))
11738                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11739         else if (!strcmp(res->select, "add"))
11740                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11741         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11742                 RTE_ETH_FILTER_SET, &info);
11743 }
11744
11745 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11746         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11747         set_fdir_input_set, "set_fdir_input_set");
11748 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11749         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11750         port_id, UINT16);
11751 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11752         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11753         flow_type,
11754         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11755         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11756 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11757         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11758         inset_field,
11759         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11760         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11761         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11762         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11763         "sctp-veri-tag#none");
11764 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11765         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11766         select, "select#add");
11767
11768 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11769         .f = cmd_set_fdir_input_set_parsed,
11770         .data = NULL,
11771         .help_str = "set_fdir_input_set <port_id> "
11772         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11773         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11774         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11775         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11776         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11777         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11778         "sctp-veri-tag|none select|add",
11779         .tokens = {
11780                 (void *)&cmd_set_fdir_input_set_cmd,
11781                 (void *)&cmd_set_fdir_input_set_port_id,
11782                 (void *)&cmd_set_fdir_input_set_flow_type,
11783                 (void *)&cmd_set_fdir_input_set_field,
11784                 (void *)&cmd_set_fdir_input_set_select,
11785                 NULL,
11786         },
11787 };
11788
11789 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11790 struct cmd_mcast_addr_result {
11791         cmdline_fixed_string_t mcast_addr_cmd;
11792         cmdline_fixed_string_t what;
11793         uint16_t port_num;
11794         struct ether_addr mc_addr;
11795 };
11796
11797 static void cmd_mcast_addr_parsed(void *parsed_result,
11798                 __attribute__((unused)) struct cmdline *cl,
11799                 __attribute__((unused)) void *data)
11800 {
11801         struct cmd_mcast_addr_result *res = parsed_result;
11802
11803         if (!is_multicast_ether_addr(&res->mc_addr)) {
11804                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11805                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11806                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11807                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11808                 return;
11809         }
11810         if (strcmp(res->what, "add") == 0)
11811                 mcast_addr_add(res->port_num, &res->mc_addr);
11812         else
11813                 mcast_addr_remove(res->port_num, &res->mc_addr);
11814 }
11815
11816 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11817         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11818                                  mcast_addr_cmd, "mcast_addr");
11819 cmdline_parse_token_string_t cmd_mcast_addr_what =
11820         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11821                                  "add#remove");
11822 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11823         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11824 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11825         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11826
11827 cmdline_parse_inst_t cmd_mcast_addr = {
11828         .f = cmd_mcast_addr_parsed,
11829         .data = (void *)0,
11830         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11831                 "Add/Remove multicast MAC address on port_id",
11832         .tokens = {
11833                 (void *)&cmd_mcast_addr_cmd,
11834                 (void *)&cmd_mcast_addr_what,
11835                 (void *)&cmd_mcast_addr_portnum,
11836                 (void *)&cmd_mcast_addr_addr,
11837                 NULL,
11838         },
11839 };
11840
11841 /* l2 tunnel config
11842  * only support E-tag now.
11843  */
11844
11845 /* Ether type config */
11846 struct cmd_config_l2_tunnel_eth_type_result {
11847         cmdline_fixed_string_t port;
11848         cmdline_fixed_string_t config;
11849         cmdline_fixed_string_t all;
11850         uint8_t id;
11851         cmdline_fixed_string_t l2_tunnel;
11852         cmdline_fixed_string_t l2_tunnel_type;
11853         cmdline_fixed_string_t eth_type;
11854         uint16_t eth_type_val;
11855 };
11856
11857 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11858         TOKEN_STRING_INITIALIZER
11859                 (struct cmd_config_l2_tunnel_eth_type_result,
11860                  port, "port");
11861 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11862         TOKEN_STRING_INITIALIZER
11863                 (struct cmd_config_l2_tunnel_eth_type_result,
11864                  config, "config");
11865 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11866         TOKEN_STRING_INITIALIZER
11867                 (struct cmd_config_l2_tunnel_eth_type_result,
11868                  all, "all");
11869 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11870         TOKEN_NUM_INITIALIZER
11871                 (struct cmd_config_l2_tunnel_eth_type_result,
11872                  id, UINT8);
11873 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11874         TOKEN_STRING_INITIALIZER
11875                 (struct cmd_config_l2_tunnel_eth_type_result,
11876                  l2_tunnel, "l2-tunnel");
11877 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11878         TOKEN_STRING_INITIALIZER
11879                 (struct cmd_config_l2_tunnel_eth_type_result,
11880                  l2_tunnel_type, "E-tag");
11881 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11882         TOKEN_STRING_INITIALIZER
11883                 (struct cmd_config_l2_tunnel_eth_type_result,
11884                  eth_type, "ether-type");
11885 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11886         TOKEN_NUM_INITIALIZER
11887                 (struct cmd_config_l2_tunnel_eth_type_result,
11888                  eth_type_val, UINT16);
11889
11890 static enum rte_eth_tunnel_type
11891 str2fdir_l2_tunnel_type(char *string)
11892 {
11893         uint32_t i = 0;
11894
11895         static const struct {
11896                 char str[32];
11897                 enum rte_eth_tunnel_type type;
11898         } l2_tunnel_type_str[] = {
11899                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11900         };
11901
11902         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11903                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11904                         return l2_tunnel_type_str[i].type;
11905         }
11906         return RTE_TUNNEL_TYPE_NONE;
11907 }
11908
11909 /* ether type config for all ports */
11910 static void
11911 cmd_config_l2_tunnel_eth_type_all_parsed
11912         (void *parsed_result,
11913          __attribute__((unused)) struct cmdline *cl,
11914          __attribute__((unused)) void *data)
11915 {
11916         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11917         struct rte_eth_l2_tunnel_conf entry;
11918         portid_t pid;
11919
11920         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11921         entry.ether_type = res->eth_type_val;
11922
11923         RTE_ETH_FOREACH_DEV(pid) {
11924                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11925         }
11926 }
11927
11928 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11929         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11930         .data = NULL,
11931         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11932         .tokens = {
11933                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11934                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11935                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11936                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11937                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11938                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11939                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11940                 NULL,
11941         },
11942 };
11943
11944 /* ether type config for a specific port */
11945 static void
11946 cmd_config_l2_tunnel_eth_type_specific_parsed(
11947         void *parsed_result,
11948         __attribute__((unused)) struct cmdline *cl,
11949         __attribute__((unused)) void *data)
11950 {
11951         struct cmd_config_l2_tunnel_eth_type_result *res =
11952                  parsed_result;
11953         struct rte_eth_l2_tunnel_conf entry;
11954
11955         if (port_id_is_invalid(res->id, ENABLED_WARN))
11956                 return;
11957
11958         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11959         entry.ether_type = res->eth_type_val;
11960
11961         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11962 }
11963
11964 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11965         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11966         .data = NULL,
11967         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11968         .tokens = {
11969                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11970                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11971                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11972                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11973                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11974                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11975                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11976                 NULL,
11977         },
11978 };
11979
11980 /* Enable/disable l2 tunnel */
11981 struct cmd_config_l2_tunnel_en_dis_result {
11982         cmdline_fixed_string_t port;
11983         cmdline_fixed_string_t config;
11984         cmdline_fixed_string_t all;
11985         uint8_t id;
11986         cmdline_fixed_string_t l2_tunnel;
11987         cmdline_fixed_string_t l2_tunnel_type;
11988         cmdline_fixed_string_t en_dis;
11989 };
11990
11991 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11992         TOKEN_STRING_INITIALIZER
11993                 (struct cmd_config_l2_tunnel_en_dis_result,
11994                  port, "port");
11995 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11996         TOKEN_STRING_INITIALIZER
11997                 (struct cmd_config_l2_tunnel_en_dis_result,
11998                  config, "config");
11999 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12000         TOKEN_STRING_INITIALIZER
12001                 (struct cmd_config_l2_tunnel_en_dis_result,
12002                  all, "all");
12003 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12004         TOKEN_NUM_INITIALIZER
12005                 (struct cmd_config_l2_tunnel_en_dis_result,
12006                  id, UINT8);
12007 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12008         TOKEN_STRING_INITIALIZER
12009                 (struct cmd_config_l2_tunnel_en_dis_result,
12010                  l2_tunnel, "l2-tunnel");
12011 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12012         TOKEN_STRING_INITIALIZER
12013                 (struct cmd_config_l2_tunnel_en_dis_result,
12014                  l2_tunnel_type, "E-tag");
12015 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12016         TOKEN_STRING_INITIALIZER
12017                 (struct cmd_config_l2_tunnel_en_dis_result,
12018                  en_dis, "enable#disable");
12019
12020 /* enable/disable l2 tunnel for all ports */
12021 static void
12022 cmd_config_l2_tunnel_en_dis_all_parsed(
12023         void *parsed_result,
12024         __attribute__((unused)) struct cmdline *cl,
12025         __attribute__((unused)) void *data)
12026 {
12027         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12028         struct rte_eth_l2_tunnel_conf entry;
12029         portid_t pid;
12030         uint8_t en;
12031
12032         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12033
12034         if (!strcmp("enable", res->en_dis))
12035                 en = 1;
12036         else
12037                 en = 0;
12038
12039         RTE_ETH_FOREACH_DEV(pid) {
12040                 rte_eth_dev_l2_tunnel_offload_set(pid,
12041                                                   &entry,
12042                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12043                                                   en);
12044         }
12045 }
12046
12047 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12048         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12049         .data = NULL,
12050         .help_str = "port config all l2-tunnel E-tag enable|disable",
12051         .tokens = {
12052                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12053                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12054                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12055                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12056                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12057                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12058                 NULL,
12059         },
12060 };
12061
12062 /* enable/disable l2 tunnel for a port */
12063 static void
12064 cmd_config_l2_tunnel_en_dis_specific_parsed(
12065         void *parsed_result,
12066         __attribute__((unused)) struct cmdline *cl,
12067         __attribute__((unused)) void *data)
12068 {
12069         struct cmd_config_l2_tunnel_en_dis_result *res =
12070                 parsed_result;
12071         struct rte_eth_l2_tunnel_conf entry;
12072
12073         if (port_id_is_invalid(res->id, ENABLED_WARN))
12074                 return;
12075
12076         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12077
12078         if (!strcmp("enable", res->en_dis))
12079                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12080                                                   &entry,
12081                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12082                                                   1);
12083         else
12084                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12085                                                   &entry,
12086                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12087                                                   0);
12088 }
12089
12090 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12091         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12092         .data = NULL,
12093         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12094         .tokens = {
12095                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12096                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12097                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12098                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12099                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12100                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12101                 NULL,
12102         },
12103 };
12104
12105 /* E-tag configuration */
12106
12107 /* Common result structure for all E-tag configuration */
12108 struct cmd_config_e_tag_result {
12109         cmdline_fixed_string_t e_tag;
12110         cmdline_fixed_string_t set;
12111         cmdline_fixed_string_t insertion;
12112         cmdline_fixed_string_t stripping;
12113         cmdline_fixed_string_t forwarding;
12114         cmdline_fixed_string_t filter;
12115         cmdline_fixed_string_t add;
12116         cmdline_fixed_string_t del;
12117         cmdline_fixed_string_t on;
12118         cmdline_fixed_string_t off;
12119         cmdline_fixed_string_t on_off;
12120         cmdline_fixed_string_t port_tag_id;
12121         uint32_t port_tag_id_val;
12122         cmdline_fixed_string_t e_tag_id;
12123         uint16_t e_tag_id_val;
12124         cmdline_fixed_string_t dst_pool;
12125         uint8_t dst_pool_val;
12126         cmdline_fixed_string_t port;
12127         portid_t port_id;
12128         cmdline_fixed_string_t vf;
12129         uint8_t vf_id;
12130 };
12131
12132 /* Common CLI fields for all E-tag configuration */
12133 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12134         TOKEN_STRING_INITIALIZER
12135                 (struct cmd_config_e_tag_result,
12136                  e_tag, "E-tag");
12137 cmdline_parse_token_string_t cmd_config_e_tag_set =
12138         TOKEN_STRING_INITIALIZER
12139                 (struct cmd_config_e_tag_result,
12140                  set, "set");
12141 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12142         TOKEN_STRING_INITIALIZER
12143                 (struct cmd_config_e_tag_result,
12144                  insertion, "insertion");
12145 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12146         TOKEN_STRING_INITIALIZER
12147                 (struct cmd_config_e_tag_result,
12148                  stripping, "stripping");
12149 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12150         TOKEN_STRING_INITIALIZER
12151                 (struct cmd_config_e_tag_result,
12152                  forwarding, "forwarding");
12153 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12154         TOKEN_STRING_INITIALIZER
12155                 (struct cmd_config_e_tag_result,
12156                  filter, "filter");
12157 cmdline_parse_token_string_t cmd_config_e_tag_add =
12158         TOKEN_STRING_INITIALIZER
12159                 (struct cmd_config_e_tag_result,
12160                  add, "add");
12161 cmdline_parse_token_string_t cmd_config_e_tag_del =
12162         TOKEN_STRING_INITIALIZER
12163                 (struct cmd_config_e_tag_result,
12164                  del, "del");
12165 cmdline_parse_token_string_t cmd_config_e_tag_on =
12166         TOKEN_STRING_INITIALIZER
12167                 (struct cmd_config_e_tag_result,
12168                  on, "on");
12169 cmdline_parse_token_string_t cmd_config_e_tag_off =
12170         TOKEN_STRING_INITIALIZER
12171                 (struct cmd_config_e_tag_result,
12172                  off, "off");
12173 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12174         TOKEN_STRING_INITIALIZER
12175                 (struct cmd_config_e_tag_result,
12176                  on_off, "on#off");
12177 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12178         TOKEN_STRING_INITIALIZER
12179                 (struct cmd_config_e_tag_result,
12180                  port_tag_id, "port-tag-id");
12181 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12182         TOKEN_NUM_INITIALIZER
12183                 (struct cmd_config_e_tag_result,
12184                  port_tag_id_val, UINT32);
12185 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12186         TOKEN_STRING_INITIALIZER
12187                 (struct cmd_config_e_tag_result,
12188                  e_tag_id, "e-tag-id");
12189 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12190         TOKEN_NUM_INITIALIZER
12191                 (struct cmd_config_e_tag_result,
12192                  e_tag_id_val, UINT16);
12193 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12194         TOKEN_STRING_INITIALIZER
12195                 (struct cmd_config_e_tag_result,
12196                  dst_pool, "dst-pool");
12197 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12198         TOKEN_NUM_INITIALIZER
12199                 (struct cmd_config_e_tag_result,
12200                  dst_pool_val, UINT8);
12201 cmdline_parse_token_string_t cmd_config_e_tag_port =
12202         TOKEN_STRING_INITIALIZER
12203                 (struct cmd_config_e_tag_result,
12204                  port, "port");
12205 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12206         TOKEN_NUM_INITIALIZER
12207                 (struct cmd_config_e_tag_result,
12208                  port_id, UINT16);
12209 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12210         TOKEN_STRING_INITIALIZER
12211                 (struct cmd_config_e_tag_result,
12212                  vf, "vf");
12213 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12214         TOKEN_NUM_INITIALIZER
12215                 (struct cmd_config_e_tag_result,
12216                  vf_id, UINT8);
12217
12218 /* E-tag insertion configuration */
12219 static void
12220 cmd_config_e_tag_insertion_en_parsed(
12221         void *parsed_result,
12222         __attribute__((unused)) struct cmdline *cl,
12223         __attribute__((unused)) void *data)
12224 {
12225         struct cmd_config_e_tag_result *res =
12226                 parsed_result;
12227         struct rte_eth_l2_tunnel_conf entry;
12228
12229         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12230                 return;
12231
12232         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12233         entry.tunnel_id = res->port_tag_id_val;
12234         entry.vf_id = res->vf_id;
12235         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12236                                           &entry,
12237                                           ETH_L2_TUNNEL_INSERTION_MASK,
12238                                           1);
12239 }
12240
12241 static void
12242 cmd_config_e_tag_insertion_dis_parsed(
12243         void *parsed_result,
12244         __attribute__((unused)) struct cmdline *cl,
12245         __attribute__((unused)) void *data)
12246 {
12247         struct cmd_config_e_tag_result *res =
12248                 parsed_result;
12249         struct rte_eth_l2_tunnel_conf entry;
12250
12251         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12252                 return;
12253
12254         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12255         entry.vf_id = res->vf_id;
12256
12257         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12258                                           &entry,
12259                                           ETH_L2_TUNNEL_INSERTION_MASK,
12260                                           0);
12261 }
12262
12263 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12264         .f = cmd_config_e_tag_insertion_en_parsed,
12265         .data = NULL,
12266         .help_str = "E-tag ... : E-tag insertion enable",
12267         .tokens = {
12268                 (void *)&cmd_config_e_tag_e_tag,
12269                 (void *)&cmd_config_e_tag_set,
12270                 (void *)&cmd_config_e_tag_insertion,
12271                 (void *)&cmd_config_e_tag_on,
12272                 (void *)&cmd_config_e_tag_port_tag_id,
12273                 (void *)&cmd_config_e_tag_port_tag_id_val,
12274                 (void *)&cmd_config_e_tag_port,
12275                 (void *)&cmd_config_e_tag_port_id,
12276                 (void *)&cmd_config_e_tag_vf,
12277                 (void *)&cmd_config_e_tag_vf_id,
12278                 NULL,
12279         },
12280 };
12281
12282 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12283         .f = cmd_config_e_tag_insertion_dis_parsed,
12284         .data = NULL,
12285         .help_str = "E-tag ... : E-tag insertion disable",
12286         .tokens = {
12287                 (void *)&cmd_config_e_tag_e_tag,
12288                 (void *)&cmd_config_e_tag_set,
12289                 (void *)&cmd_config_e_tag_insertion,
12290                 (void *)&cmd_config_e_tag_off,
12291                 (void *)&cmd_config_e_tag_port,
12292                 (void *)&cmd_config_e_tag_port_id,
12293                 (void *)&cmd_config_e_tag_vf,
12294                 (void *)&cmd_config_e_tag_vf_id,
12295                 NULL,
12296         },
12297 };
12298
12299 /* E-tag stripping configuration */
12300 static void
12301 cmd_config_e_tag_stripping_parsed(
12302         void *parsed_result,
12303         __attribute__((unused)) struct cmdline *cl,
12304         __attribute__((unused)) void *data)
12305 {
12306         struct cmd_config_e_tag_result *res =
12307                 parsed_result;
12308         struct rte_eth_l2_tunnel_conf entry;
12309
12310         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12311                 return;
12312
12313         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12314
12315         if (!strcmp(res->on_off, "on"))
12316                 rte_eth_dev_l2_tunnel_offload_set
12317                         (res->port_id,
12318                          &entry,
12319                          ETH_L2_TUNNEL_STRIPPING_MASK,
12320                          1);
12321         else
12322                 rte_eth_dev_l2_tunnel_offload_set
12323                         (res->port_id,
12324                          &entry,
12325                          ETH_L2_TUNNEL_STRIPPING_MASK,
12326                          0);
12327 }
12328
12329 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12330         .f = cmd_config_e_tag_stripping_parsed,
12331         .data = NULL,
12332         .help_str = "E-tag ... : E-tag stripping enable/disable",
12333         .tokens = {
12334                 (void *)&cmd_config_e_tag_e_tag,
12335                 (void *)&cmd_config_e_tag_set,
12336                 (void *)&cmd_config_e_tag_stripping,
12337                 (void *)&cmd_config_e_tag_on_off,
12338                 (void *)&cmd_config_e_tag_port,
12339                 (void *)&cmd_config_e_tag_port_id,
12340                 NULL,
12341         },
12342 };
12343
12344 /* E-tag forwarding configuration */
12345 static void
12346 cmd_config_e_tag_forwarding_parsed(
12347         void *parsed_result,
12348         __attribute__((unused)) struct cmdline *cl,
12349         __attribute__((unused)) void *data)
12350 {
12351         struct cmd_config_e_tag_result *res = parsed_result;
12352         struct rte_eth_l2_tunnel_conf entry;
12353
12354         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12355                 return;
12356
12357         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12358
12359         if (!strcmp(res->on_off, "on"))
12360                 rte_eth_dev_l2_tunnel_offload_set
12361                         (res->port_id,
12362                          &entry,
12363                          ETH_L2_TUNNEL_FORWARDING_MASK,
12364                          1);
12365         else
12366                 rte_eth_dev_l2_tunnel_offload_set
12367                         (res->port_id,
12368                          &entry,
12369                          ETH_L2_TUNNEL_FORWARDING_MASK,
12370                          0);
12371 }
12372
12373 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12374         .f = cmd_config_e_tag_forwarding_parsed,
12375         .data = NULL,
12376         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12377         .tokens = {
12378                 (void *)&cmd_config_e_tag_e_tag,
12379                 (void *)&cmd_config_e_tag_set,
12380                 (void *)&cmd_config_e_tag_forwarding,
12381                 (void *)&cmd_config_e_tag_on_off,
12382                 (void *)&cmd_config_e_tag_port,
12383                 (void *)&cmd_config_e_tag_port_id,
12384                 NULL,
12385         },
12386 };
12387
12388 /* E-tag filter configuration */
12389 static void
12390 cmd_config_e_tag_filter_add_parsed(
12391         void *parsed_result,
12392         __attribute__((unused)) struct cmdline *cl,
12393         __attribute__((unused)) void *data)
12394 {
12395         struct cmd_config_e_tag_result *res = parsed_result;
12396         struct rte_eth_l2_tunnel_conf entry;
12397         int ret = 0;
12398
12399         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12400                 return;
12401
12402         if (res->e_tag_id_val > 0x3fff) {
12403                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12404                 return;
12405         }
12406
12407         ret = rte_eth_dev_filter_supported(res->port_id,
12408                                            RTE_ETH_FILTER_L2_TUNNEL);
12409         if (ret < 0) {
12410                 printf("E-tag filter is not supported on port %u.\n",
12411                        res->port_id);
12412                 return;
12413         }
12414
12415         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12416         entry.tunnel_id = res->e_tag_id_val;
12417         entry.pool = res->dst_pool_val;
12418
12419         ret = rte_eth_dev_filter_ctrl(res->port_id,
12420                                       RTE_ETH_FILTER_L2_TUNNEL,
12421                                       RTE_ETH_FILTER_ADD,
12422                                       &entry);
12423         if (ret < 0)
12424                 printf("E-tag filter programming error: (%s)\n",
12425                        strerror(-ret));
12426 }
12427
12428 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12429         .f = cmd_config_e_tag_filter_add_parsed,
12430         .data = NULL,
12431         .help_str = "E-tag ... : E-tag filter add",
12432         .tokens = {
12433                 (void *)&cmd_config_e_tag_e_tag,
12434                 (void *)&cmd_config_e_tag_set,
12435                 (void *)&cmd_config_e_tag_filter,
12436                 (void *)&cmd_config_e_tag_add,
12437                 (void *)&cmd_config_e_tag_e_tag_id,
12438                 (void *)&cmd_config_e_tag_e_tag_id_val,
12439                 (void *)&cmd_config_e_tag_dst_pool,
12440                 (void *)&cmd_config_e_tag_dst_pool_val,
12441                 (void *)&cmd_config_e_tag_port,
12442                 (void *)&cmd_config_e_tag_port_id,
12443                 NULL,
12444         },
12445 };
12446
12447 static void
12448 cmd_config_e_tag_filter_del_parsed(
12449         void *parsed_result,
12450         __attribute__((unused)) struct cmdline *cl,
12451         __attribute__((unused)) void *data)
12452 {
12453         struct cmd_config_e_tag_result *res = parsed_result;
12454         struct rte_eth_l2_tunnel_conf entry;
12455         int ret = 0;
12456
12457         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12458                 return;
12459
12460         if (res->e_tag_id_val > 0x3fff) {
12461                 printf("e-tag-id must be less than 0x3fff.\n");
12462                 return;
12463         }
12464
12465         ret = rte_eth_dev_filter_supported(res->port_id,
12466                                            RTE_ETH_FILTER_L2_TUNNEL);
12467         if (ret < 0) {
12468                 printf("E-tag filter is not supported on port %u.\n",
12469                        res->port_id);
12470                 return;
12471         }
12472
12473         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12474         entry.tunnel_id = res->e_tag_id_val;
12475
12476         ret = rte_eth_dev_filter_ctrl(res->port_id,
12477                                       RTE_ETH_FILTER_L2_TUNNEL,
12478                                       RTE_ETH_FILTER_DELETE,
12479                                       &entry);
12480         if (ret < 0)
12481                 printf("E-tag filter programming error: (%s)\n",
12482                        strerror(-ret));
12483 }
12484
12485 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12486         .f = cmd_config_e_tag_filter_del_parsed,
12487         .data = NULL,
12488         .help_str = "E-tag ... : E-tag filter delete",
12489         .tokens = {
12490                 (void *)&cmd_config_e_tag_e_tag,
12491                 (void *)&cmd_config_e_tag_set,
12492                 (void *)&cmd_config_e_tag_filter,
12493                 (void *)&cmd_config_e_tag_del,
12494                 (void *)&cmd_config_e_tag_e_tag_id,
12495                 (void *)&cmd_config_e_tag_e_tag_id_val,
12496                 (void *)&cmd_config_e_tag_port,
12497                 (void *)&cmd_config_e_tag_port_id,
12498                 NULL,
12499         },
12500 };
12501
12502 /* vf vlan anti spoof configuration */
12503
12504 /* Common result structure for vf vlan anti spoof */
12505 struct cmd_vf_vlan_anti_spoof_result {
12506         cmdline_fixed_string_t set;
12507         cmdline_fixed_string_t vf;
12508         cmdline_fixed_string_t vlan;
12509         cmdline_fixed_string_t antispoof;
12510         portid_t port_id;
12511         uint32_t vf_id;
12512         cmdline_fixed_string_t on_off;
12513 };
12514
12515 /* Common CLI fields for vf vlan anti spoof enable disable */
12516 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12517         TOKEN_STRING_INITIALIZER
12518                 (struct cmd_vf_vlan_anti_spoof_result,
12519                  set, "set");
12520 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12521         TOKEN_STRING_INITIALIZER
12522                 (struct cmd_vf_vlan_anti_spoof_result,
12523                  vf, "vf");
12524 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12525         TOKEN_STRING_INITIALIZER
12526                 (struct cmd_vf_vlan_anti_spoof_result,
12527                  vlan, "vlan");
12528 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12529         TOKEN_STRING_INITIALIZER
12530                 (struct cmd_vf_vlan_anti_spoof_result,
12531                  antispoof, "antispoof");
12532 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12533         TOKEN_NUM_INITIALIZER
12534                 (struct cmd_vf_vlan_anti_spoof_result,
12535                  port_id, UINT16);
12536 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12537         TOKEN_NUM_INITIALIZER
12538                 (struct cmd_vf_vlan_anti_spoof_result,
12539                  vf_id, UINT32);
12540 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12541         TOKEN_STRING_INITIALIZER
12542                 (struct cmd_vf_vlan_anti_spoof_result,
12543                  on_off, "on#off");
12544
12545 static void
12546 cmd_set_vf_vlan_anti_spoof_parsed(
12547         void *parsed_result,
12548         __attribute__((unused)) struct cmdline *cl,
12549         __attribute__((unused)) void *data)
12550 {
12551         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12552         int ret = -ENOTSUP;
12553
12554         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12555
12556         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12557                 return;
12558
12559 #ifdef RTE_LIBRTE_IXGBE_PMD
12560         if (ret == -ENOTSUP)
12561                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12562                                 res->vf_id, is_on);
12563 #endif
12564 #ifdef RTE_LIBRTE_I40E_PMD
12565         if (ret == -ENOTSUP)
12566                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12567                                 res->vf_id, is_on);
12568 #endif
12569 #ifdef RTE_LIBRTE_BNXT_PMD
12570         if (ret == -ENOTSUP)
12571                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12572                                 res->vf_id, is_on);
12573 #endif
12574
12575         switch (ret) {
12576         case 0:
12577                 break;
12578         case -EINVAL:
12579                 printf("invalid vf_id %d\n", res->vf_id);
12580                 break;
12581         case -ENODEV:
12582                 printf("invalid port_id %d\n", res->port_id);
12583                 break;
12584         case -ENOTSUP:
12585                 printf("function not implemented\n");
12586                 break;
12587         default:
12588                 printf("programming error: (%s)\n", strerror(-ret));
12589         }
12590 }
12591
12592 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12593         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12594         .data = NULL,
12595         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12596         .tokens = {
12597                 (void *)&cmd_vf_vlan_anti_spoof_set,
12598                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12599                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12600                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12601                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12602                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12603                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12604                 NULL,
12605         },
12606 };
12607
12608 /* vf mac anti spoof configuration */
12609
12610 /* Common result structure for vf mac anti spoof */
12611 struct cmd_vf_mac_anti_spoof_result {
12612         cmdline_fixed_string_t set;
12613         cmdline_fixed_string_t vf;
12614         cmdline_fixed_string_t mac;
12615         cmdline_fixed_string_t antispoof;
12616         portid_t port_id;
12617         uint32_t vf_id;
12618         cmdline_fixed_string_t on_off;
12619 };
12620
12621 /* Common CLI fields for vf mac anti spoof enable disable */
12622 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12623         TOKEN_STRING_INITIALIZER
12624                 (struct cmd_vf_mac_anti_spoof_result,
12625                  set, "set");
12626 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12627         TOKEN_STRING_INITIALIZER
12628                 (struct cmd_vf_mac_anti_spoof_result,
12629                  vf, "vf");
12630 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12631         TOKEN_STRING_INITIALIZER
12632                 (struct cmd_vf_mac_anti_spoof_result,
12633                  mac, "mac");
12634 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12635         TOKEN_STRING_INITIALIZER
12636                 (struct cmd_vf_mac_anti_spoof_result,
12637                  antispoof, "antispoof");
12638 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12639         TOKEN_NUM_INITIALIZER
12640                 (struct cmd_vf_mac_anti_spoof_result,
12641                  port_id, UINT16);
12642 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12643         TOKEN_NUM_INITIALIZER
12644                 (struct cmd_vf_mac_anti_spoof_result,
12645                  vf_id, UINT32);
12646 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12647         TOKEN_STRING_INITIALIZER
12648                 (struct cmd_vf_mac_anti_spoof_result,
12649                  on_off, "on#off");
12650
12651 static void
12652 cmd_set_vf_mac_anti_spoof_parsed(
12653         void *parsed_result,
12654         __attribute__((unused)) struct cmdline *cl,
12655         __attribute__((unused)) void *data)
12656 {
12657         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12658         int ret = -ENOTSUP;
12659
12660         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12661
12662         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12663                 return;
12664
12665 #ifdef RTE_LIBRTE_IXGBE_PMD
12666         if (ret == -ENOTSUP)
12667                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12668                         res->vf_id, is_on);
12669 #endif
12670 #ifdef RTE_LIBRTE_I40E_PMD
12671         if (ret == -ENOTSUP)
12672                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12673                         res->vf_id, is_on);
12674 #endif
12675 #ifdef RTE_LIBRTE_BNXT_PMD
12676         if (ret == -ENOTSUP)
12677                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12678                         res->vf_id, is_on);
12679 #endif
12680
12681         switch (ret) {
12682         case 0:
12683                 break;
12684         case -EINVAL:
12685                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12686                 break;
12687         case -ENODEV:
12688                 printf("invalid port_id %d\n", res->port_id);
12689                 break;
12690         case -ENOTSUP:
12691                 printf("function not implemented\n");
12692                 break;
12693         default:
12694                 printf("programming error: (%s)\n", strerror(-ret));
12695         }
12696 }
12697
12698 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12699         .f = cmd_set_vf_mac_anti_spoof_parsed,
12700         .data = NULL,
12701         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12702         .tokens = {
12703                 (void *)&cmd_vf_mac_anti_spoof_set,
12704                 (void *)&cmd_vf_mac_anti_spoof_vf,
12705                 (void *)&cmd_vf_mac_anti_spoof_mac,
12706                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12707                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12708                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12709                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12710                 NULL,
12711         },
12712 };
12713
12714 /* vf vlan strip queue configuration */
12715
12716 /* Common result structure for vf mac anti spoof */
12717 struct cmd_vf_vlan_stripq_result {
12718         cmdline_fixed_string_t set;
12719         cmdline_fixed_string_t vf;
12720         cmdline_fixed_string_t vlan;
12721         cmdline_fixed_string_t stripq;
12722         portid_t port_id;
12723         uint16_t vf_id;
12724         cmdline_fixed_string_t on_off;
12725 };
12726
12727 /* Common CLI fields for vf vlan strip enable disable */
12728 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12729         TOKEN_STRING_INITIALIZER
12730                 (struct cmd_vf_vlan_stripq_result,
12731                  set, "set");
12732 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12733         TOKEN_STRING_INITIALIZER
12734                 (struct cmd_vf_vlan_stripq_result,
12735                  vf, "vf");
12736 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12737         TOKEN_STRING_INITIALIZER
12738                 (struct cmd_vf_vlan_stripq_result,
12739                  vlan, "vlan");
12740 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12741         TOKEN_STRING_INITIALIZER
12742                 (struct cmd_vf_vlan_stripq_result,
12743                  stripq, "stripq");
12744 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12745         TOKEN_NUM_INITIALIZER
12746                 (struct cmd_vf_vlan_stripq_result,
12747                  port_id, UINT16);
12748 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12749         TOKEN_NUM_INITIALIZER
12750                 (struct cmd_vf_vlan_stripq_result,
12751                  vf_id, UINT16);
12752 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12753         TOKEN_STRING_INITIALIZER
12754                 (struct cmd_vf_vlan_stripq_result,
12755                  on_off, "on#off");
12756
12757 static void
12758 cmd_set_vf_vlan_stripq_parsed(
12759         void *parsed_result,
12760         __attribute__((unused)) struct cmdline *cl,
12761         __attribute__((unused)) void *data)
12762 {
12763         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12764         int ret = -ENOTSUP;
12765
12766         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12767
12768         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12769                 return;
12770
12771 #ifdef RTE_LIBRTE_IXGBE_PMD
12772         if (ret == -ENOTSUP)
12773                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12774                         res->vf_id, is_on);
12775 #endif
12776 #ifdef RTE_LIBRTE_I40E_PMD
12777         if (ret == -ENOTSUP)
12778                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12779                         res->vf_id, is_on);
12780 #endif
12781 #ifdef RTE_LIBRTE_BNXT_PMD
12782         if (ret == -ENOTSUP)
12783                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12784                         res->vf_id, is_on);
12785 #endif
12786
12787         switch (ret) {
12788         case 0:
12789                 break;
12790         case -EINVAL:
12791                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12792                 break;
12793         case -ENODEV:
12794                 printf("invalid port_id %d\n", res->port_id);
12795                 break;
12796         case -ENOTSUP:
12797                 printf("function not implemented\n");
12798                 break;
12799         default:
12800                 printf("programming error: (%s)\n", strerror(-ret));
12801         }
12802 }
12803
12804 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12805         .f = cmd_set_vf_vlan_stripq_parsed,
12806         .data = NULL,
12807         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12808         .tokens = {
12809                 (void *)&cmd_vf_vlan_stripq_set,
12810                 (void *)&cmd_vf_vlan_stripq_vf,
12811                 (void *)&cmd_vf_vlan_stripq_vlan,
12812                 (void *)&cmd_vf_vlan_stripq_stripq,
12813                 (void *)&cmd_vf_vlan_stripq_port_id,
12814                 (void *)&cmd_vf_vlan_stripq_vf_id,
12815                 (void *)&cmd_vf_vlan_stripq_on_off,
12816                 NULL,
12817         },
12818 };
12819
12820 /* vf vlan insert configuration */
12821
12822 /* Common result structure for vf vlan insert */
12823 struct cmd_vf_vlan_insert_result {
12824         cmdline_fixed_string_t set;
12825         cmdline_fixed_string_t vf;
12826         cmdline_fixed_string_t vlan;
12827         cmdline_fixed_string_t insert;
12828         portid_t port_id;
12829         uint16_t vf_id;
12830         uint16_t vlan_id;
12831 };
12832
12833 /* Common CLI fields for vf vlan insert enable disable */
12834 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12835         TOKEN_STRING_INITIALIZER
12836                 (struct cmd_vf_vlan_insert_result,
12837                  set, "set");
12838 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12839         TOKEN_STRING_INITIALIZER
12840                 (struct cmd_vf_vlan_insert_result,
12841                  vf, "vf");
12842 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12843         TOKEN_STRING_INITIALIZER
12844                 (struct cmd_vf_vlan_insert_result,
12845                  vlan, "vlan");
12846 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12847         TOKEN_STRING_INITIALIZER
12848                 (struct cmd_vf_vlan_insert_result,
12849                  insert, "insert");
12850 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12851         TOKEN_NUM_INITIALIZER
12852                 (struct cmd_vf_vlan_insert_result,
12853                  port_id, UINT16);
12854 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12855         TOKEN_NUM_INITIALIZER
12856                 (struct cmd_vf_vlan_insert_result,
12857                  vf_id, UINT16);
12858 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12859         TOKEN_NUM_INITIALIZER
12860                 (struct cmd_vf_vlan_insert_result,
12861                  vlan_id, UINT16);
12862
12863 static void
12864 cmd_set_vf_vlan_insert_parsed(
12865         void *parsed_result,
12866         __attribute__((unused)) struct cmdline *cl,
12867         __attribute__((unused)) void *data)
12868 {
12869         struct cmd_vf_vlan_insert_result *res = parsed_result;
12870         int ret = -ENOTSUP;
12871
12872         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12873                 return;
12874
12875 #ifdef RTE_LIBRTE_IXGBE_PMD
12876         if (ret == -ENOTSUP)
12877                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12878                         res->vlan_id);
12879 #endif
12880 #ifdef RTE_LIBRTE_I40E_PMD
12881         if (ret == -ENOTSUP)
12882                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12883                         res->vlan_id);
12884 #endif
12885 #ifdef RTE_LIBRTE_BNXT_PMD
12886         if (ret == -ENOTSUP)
12887                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12888                         res->vlan_id);
12889 #endif
12890
12891         switch (ret) {
12892         case 0:
12893                 break;
12894         case -EINVAL:
12895                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12896                 break;
12897         case -ENODEV:
12898                 printf("invalid port_id %d\n", res->port_id);
12899                 break;
12900         case -ENOTSUP:
12901                 printf("function not implemented\n");
12902                 break;
12903         default:
12904                 printf("programming error: (%s)\n", strerror(-ret));
12905         }
12906 }
12907
12908 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12909         .f = cmd_set_vf_vlan_insert_parsed,
12910         .data = NULL,
12911         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12912         .tokens = {
12913                 (void *)&cmd_vf_vlan_insert_set,
12914                 (void *)&cmd_vf_vlan_insert_vf,
12915                 (void *)&cmd_vf_vlan_insert_vlan,
12916                 (void *)&cmd_vf_vlan_insert_insert,
12917                 (void *)&cmd_vf_vlan_insert_port_id,
12918                 (void *)&cmd_vf_vlan_insert_vf_id,
12919                 (void *)&cmd_vf_vlan_insert_vlan_id,
12920                 NULL,
12921         },
12922 };
12923
12924 /* tx loopback configuration */
12925
12926 /* Common result structure for tx loopback */
12927 struct cmd_tx_loopback_result {
12928         cmdline_fixed_string_t set;
12929         cmdline_fixed_string_t tx;
12930         cmdline_fixed_string_t loopback;
12931         portid_t port_id;
12932         cmdline_fixed_string_t on_off;
12933 };
12934
12935 /* Common CLI fields for tx loopback enable disable */
12936 cmdline_parse_token_string_t cmd_tx_loopback_set =
12937         TOKEN_STRING_INITIALIZER
12938                 (struct cmd_tx_loopback_result,
12939                  set, "set");
12940 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12941         TOKEN_STRING_INITIALIZER
12942                 (struct cmd_tx_loopback_result,
12943                  tx, "tx");
12944 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12945         TOKEN_STRING_INITIALIZER
12946                 (struct cmd_tx_loopback_result,
12947                  loopback, "loopback");
12948 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12949         TOKEN_NUM_INITIALIZER
12950                 (struct cmd_tx_loopback_result,
12951                  port_id, UINT16);
12952 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12953         TOKEN_STRING_INITIALIZER
12954                 (struct cmd_tx_loopback_result,
12955                  on_off, "on#off");
12956
12957 static void
12958 cmd_set_tx_loopback_parsed(
12959         void *parsed_result,
12960         __attribute__((unused)) struct cmdline *cl,
12961         __attribute__((unused)) void *data)
12962 {
12963         struct cmd_tx_loopback_result *res = parsed_result;
12964         int ret = -ENOTSUP;
12965
12966         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12967
12968         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12969                 return;
12970
12971 #ifdef RTE_LIBRTE_IXGBE_PMD
12972         if (ret == -ENOTSUP)
12973                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12974 #endif
12975 #ifdef RTE_LIBRTE_I40E_PMD
12976         if (ret == -ENOTSUP)
12977                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12978 #endif
12979 #ifdef RTE_LIBRTE_BNXT_PMD
12980         if (ret == -ENOTSUP)
12981                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12982 #endif
12983 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
12984         if (ret == -ENOTSUP)
12985                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12986 #endif
12987
12988         switch (ret) {
12989         case 0:
12990                 break;
12991         case -EINVAL:
12992                 printf("invalid is_on %d\n", is_on);
12993                 break;
12994         case -ENODEV:
12995                 printf("invalid port_id %d\n", res->port_id);
12996                 break;
12997         case -ENOTSUP:
12998                 printf("function not implemented\n");
12999                 break;
13000         default:
13001                 printf("programming error: (%s)\n", strerror(-ret));
13002         }
13003 }
13004
13005 cmdline_parse_inst_t cmd_set_tx_loopback = {
13006         .f = cmd_set_tx_loopback_parsed,
13007         .data = NULL,
13008         .help_str = "set tx loopback <port_id> on|off",
13009         .tokens = {
13010                 (void *)&cmd_tx_loopback_set,
13011                 (void *)&cmd_tx_loopback_tx,
13012                 (void *)&cmd_tx_loopback_loopback,
13013                 (void *)&cmd_tx_loopback_port_id,
13014                 (void *)&cmd_tx_loopback_on_off,
13015                 NULL,
13016         },
13017 };
13018
13019 /* all queues drop enable configuration */
13020
13021 /* Common result structure for all queues drop enable */
13022 struct cmd_all_queues_drop_en_result {
13023         cmdline_fixed_string_t set;
13024         cmdline_fixed_string_t all;
13025         cmdline_fixed_string_t queues;
13026         cmdline_fixed_string_t drop;
13027         portid_t port_id;
13028         cmdline_fixed_string_t on_off;
13029 };
13030
13031 /* Common CLI fields for tx loopback enable disable */
13032 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13033         TOKEN_STRING_INITIALIZER
13034                 (struct cmd_all_queues_drop_en_result,
13035                  set, "set");
13036 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13037         TOKEN_STRING_INITIALIZER
13038                 (struct cmd_all_queues_drop_en_result,
13039                  all, "all");
13040 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13041         TOKEN_STRING_INITIALIZER
13042                 (struct cmd_all_queues_drop_en_result,
13043                  queues, "queues");
13044 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13045         TOKEN_STRING_INITIALIZER
13046                 (struct cmd_all_queues_drop_en_result,
13047                  drop, "drop");
13048 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13049         TOKEN_NUM_INITIALIZER
13050                 (struct cmd_all_queues_drop_en_result,
13051                  port_id, UINT16);
13052 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13053         TOKEN_STRING_INITIALIZER
13054                 (struct cmd_all_queues_drop_en_result,
13055                  on_off, "on#off");
13056
13057 static void
13058 cmd_set_all_queues_drop_en_parsed(
13059         void *parsed_result,
13060         __attribute__((unused)) struct cmdline *cl,
13061         __attribute__((unused)) void *data)
13062 {
13063         struct cmd_all_queues_drop_en_result *res = parsed_result;
13064         int ret = -ENOTSUP;
13065         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13066
13067         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13068                 return;
13069
13070 #ifdef RTE_LIBRTE_IXGBE_PMD
13071         if (ret == -ENOTSUP)
13072                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13073 #endif
13074 #ifdef RTE_LIBRTE_BNXT_PMD
13075         if (ret == -ENOTSUP)
13076                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13077 #endif
13078         switch (ret) {
13079         case 0:
13080                 break;
13081         case -EINVAL:
13082                 printf("invalid is_on %d\n", is_on);
13083                 break;
13084         case -ENODEV:
13085                 printf("invalid port_id %d\n", res->port_id);
13086                 break;
13087         case -ENOTSUP:
13088                 printf("function not implemented\n");
13089                 break;
13090         default:
13091                 printf("programming error: (%s)\n", strerror(-ret));
13092         }
13093 }
13094
13095 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13096         .f = cmd_set_all_queues_drop_en_parsed,
13097         .data = NULL,
13098         .help_str = "set all queues drop <port_id> on|off",
13099         .tokens = {
13100                 (void *)&cmd_all_queues_drop_en_set,
13101                 (void *)&cmd_all_queues_drop_en_all,
13102                 (void *)&cmd_all_queues_drop_en_queues,
13103                 (void *)&cmd_all_queues_drop_en_drop,
13104                 (void *)&cmd_all_queues_drop_en_port_id,
13105                 (void *)&cmd_all_queues_drop_en_on_off,
13106                 NULL,
13107         },
13108 };
13109
13110 /* vf split drop enable configuration */
13111
13112 /* Common result structure for vf split drop enable */
13113 struct cmd_vf_split_drop_en_result {
13114         cmdline_fixed_string_t set;
13115         cmdline_fixed_string_t vf;
13116         cmdline_fixed_string_t split;
13117         cmdline_fixed_string_t drop;
13118         portid_t port_id;
13119         uint16_t vf_id;
13120         cmdline_fixed_string_t on_off;
13121 };
13122
13123 /* Common CLI fields for vf split drop enable disable */
13124 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13125         TOKEN_STRING_INITIALIZER
13126                 (struct cmd_vf_split_drop_en_result,
13127                  set, "set");
13128 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13129         TOKEN_STRING_INITIALIZER
13130                 (struct cmd_vf_split_drop_en_result,
13131                  vf, "vf");
13132 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13133         TOKEN_STRING_INITIALIZER
13134                 (struct cmd_vf_split_drop_en_result,
13135                  split, "split");
13136 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13137         TOKEN_STRING_INITIALIZER
13138                 (struct cmd_vf_split_drop_en_result,
13139                  drop, "drop");
13140 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13141         TOKEN_NUM_INITIALIZER
13142                 (struct cmd_vf_split_drop_en_result,
13143                  port_id, UINT16);
13144 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13145         TOKEN_NUM_INITIALIZER
13146                 (struct cmd_vf_split_drop_en_result,
13147                  vf_id, UINT16);
13148 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13149         TOKEN_STRING_INITIALIZER
13150                 (struct cmd_vf_split_drop_en_result,
13151                  on_off, "on#off");
13152
13153 static void
13154 cmd_set_vf_split_drop_en_parsed(
13155         void *parsed_result,
13156         __attribute__((unused)) struct cmdline *cl,
13157         __attribute__((unused)) void *data)
13158 {
13159         struct cmd_vf_split_drop_en_result *res = parsed_result;
13160         int ret = -ENOTSUP;
13161         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13162
13163         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13164                 return;
13165
13166 #ifdef RTE_LIBRTE_IXGBE_PMD
13167         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13168                         is_on);
13169 #endif
13170         switch (ret) {
13171         case 0:
13172                 break;
13173         case -EINVAL:
13174                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13175                 break;
13176         case -ENODEV:
13177                 printf("invalid port_id %d\n", res->port_id);
13178                 break;
13179         case -ENOTSUP:
13180                 printf("not supported on port %d\n", res->port_id);
13181                 break;
13182         default:
13183                 printf("programming error: (%s)\n", strerror(-ret));
13184         }
13185 }
13186
13187 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13188         .f = cmd_set_vf_split_drop_en_parsed,
13189         .data = NULL,
13190         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13191         .tokens = {
13192                 (void *)&cmd_vf_split_drop_en_set,
13193                 (void *)&cmd_vf_split_drop_en_vf,
13194                 (void *)&cmd_vf_split_drop_en_split,
13195                 (void *)&cmd_vf_split_drop_en_drop,
13196                 (void *)&cmd_vf_split_drop_en_port_id,
13197                 (void *)&cmd_vf_split_drop_en_vf_id,
13198                 (void *)&cmd_vf_split_drop_en_on_off,
13199                 NULL,
13200         },
13201 };
13202
13203 /* vf mac address configuration */
13204
13205 /* Common result structure for vf mac address */
13206 struct cmd_set_vf_mac_addr_result {
13207         cmdline_fixed_string_t set;
13208         cmdline_fixed_string_t vf;
13209         cmdline_fixed_string_t mac;
13210         cmdline_fixed_string_t addr;
13211         portid_t port_id;
13212         uint16_t vf_id;
13213         struct ether_addr mac_addr;
13214
13215 };
13216
13217 /* Common CLI fields for vf split drop enable disable */
13218 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13219         TOKEN_STRING_INITIALIZER
13220                 (struct cmd_set_vf_mac_addr_result,
13221                  set, "set");
13222 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13223         TOKEN_STRING_INITIALIZER
13224                 (struct cmd_set_vf_mac_addr_result,
13225                  vf, "vf");
13226 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13227         TOKEN_STRING_INITIALIZER
13228                 (struct cmd_set_vf_mac_addr_result,
13229                  mac, "mac");
13230 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13231         TOKEN_STRING_INITIALIZER
13232                 (struct cmd_set_vf_mac_addr_result,
13233                  addr, "addr");
13234 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13235         TOKEN_NUM_INITIALIZER
13236                 (struct cmd_set_vf_mac_addr_result,
13237                  port_id, UINT16);
13238 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13239         TOKEN_NUM_INITIALIZER
13240                 (struct cmd_set_vf_mac_addr_result,
13241                  vf_id, UINT16);
13242 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13243         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13244                  mac_addr);
13245
13246 static void
13247 cmd_set_vf_mac_addr_parsed(
13248         void *parsed_result,
13249         __attribute__((unused)) struct cmdline *cl,
13250         __attribute__((unused)) void *data)
13251 {
13252         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13253         int ret = -ENOTSUP;
13254
13255         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13256                 return;
13257
13258 #ifdef RTE_LIBRTE_IXGBE_PMD
13259         if (ret == -ENOTSUP)
13260                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13261                                 &res->mac_addr);
13262 #endif
13263 #ifdef RTE_LIBRTE_I40E_PMD
13264         if (ret == -ENOTSUP)
13265                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13266                                 &res->mac_addr);
13267 #endif
13268 #ifdef RTE_LIBRTE_BNXT_PMD
13269         if (ret == -ENOTSUP)
13270                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13271                                 &res->mac_addr);
13272 #endif
13273
13274         switch (ret) {
13275         case 0:
13276                 break;
13277         case -EINVAL:
13278                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13279                 break;
13280         case -ENODEV:
13281                 printf("invalid port_id %d\n", res->port_id);
13282                 break;
13283         case -ENOTSUP:
13284                 printf("function not implemented\n");
13285                 break;
13286         default:
13287                 printf("programming error: (%s)\n", strerror(-ret));
13288         }
13289 }
13290
13291 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13292         .f = cmd_set_vf_mac_addr_parsed,
13293         .data = NULL,
13294         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13295         .tokens = {
13296                 (void *)&cmd_set_vf_mac_addr_set,
13297                 (void *)&cmd_set_vf_mac_addr_vf,
13298                 (void *)&cmd_set_vf_mac_addr_mac,
13299                 (void *)&cmd_set_vf_mac_addr_addr,
13300                 (void *)&cmd_set_vf_mac_addr_port_id,
13301                 (void *)&cmd_set_vf_mac_addr_vf_id,
13302                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13303                 NULL,
13304         },
13305 };
13306
13307 /* MACsec configuration */
13308
13309 /* Common result structure for MACsec offload enable */
13310 struct cmd_macsec_offload_on_result {
13311         cmdline_fixed_string_t set;
13312         cmdline_fixed_string_t macsec;
13313         cmdline_fixed_string_t offload;
13314         portid_t port_id;
13315         cmdline_fixed_string_t on;
13316         cmdline_fixed_string_t encrypt;
13317         cmdline_fixed_string_t en_on_off;
13318         cmdline_fixed_string_t replay_protect;
13319         cmdline_fixed_string_t rp_on_off;
13320 };
13321
13322 /* Common CLI fields for MACsec offload disable */
13323 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13324         TOKEN_STRING_INITIALIZER
13325                 (struct cmd_macsec_offload_on_result,
13326                  set, "set");
13327 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13328         TOKEN_STRING_INITIALIZER
13329                 (struct cmd_macsec_offload_on_result,
13330                  macsec, "macsec");
13331 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13332         TOKEN_STRING_INITIALIZER
13333                 (struct cmd_macsec_offload_on_result,
13334                  offload, "offload");
13335 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13336         TOKEN_NUM_INITIALIZER
13337                 (struct cmd_macsec_offload_on_result,
13338                  port_id, UINT16);
13339 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13340         TOKEN_STRING_INITIALIZER
13341                 (struct cmd_macsec_offload_on_result,
13342                  on, "on");
13343 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13344         TOKEN_STRING_INITIALIZER
13345                 (struct cmd_macsec_offload_on_result,
13346                  encrypt, "encrypt");
13347 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13348         TOKEN_STRING_INITIALIZER
13349                 (struct cmd_macsec_offload_on_result,
13350                  en_on_off, "on#off");
13351 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13352         TOKEN_STRING_INITIALIZER
13353                 (struct cmd_macsec_offload_on_result,
13354                  replay_protect, "replay-protect");
13355 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13356         TOKEN_STRING_INITIALIZER
13357                 (struct cmd_macsec_offload_on_result,
13358                  rp_on_off, "on#off");
13359
13360 static void
13361 cmd_set_macsec_offload_on_parsed(
13362         void *parsed_result,
13363         __attribute__((unused)) struct cmdline *cl,
13364         __attribute__((unused)) void *data)
13365 {
13366         struct cmd_macsec_offload_on_result *res = parsed_result;
13367         int ret = -ENOTSUP;
13368         portid_t port_id = res->port_id;
13369         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13370         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13371         struct rte_eth_dev_info dev_info;
13372
13373         if (port_id_is_invalid(port_id, ENABLED_WARN))
13374                 return;
13375         if (!port_is_stopped(port_id)) {
13376                 printf("Please stop port %d first\n", port_id);
13377                 return;
13378         }
13379
13380         rte_eth_dev_info_get(port_id, &dev_info);
13381         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13382 #ifdef RTE_LIBRTE_IXGBE_PMD
13383                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13384 #endif
13385         }
13386         RTE_SET_USED(en);
13387         RTE_SET_USED(rp);
13388
13389         switch (ret) {
13390         case 0:
13391                 ports[port_id].dev_conf.txmode.offloads |=
13392                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13393                 cmd_reconfig_device_queue(port_id, 1, 1);
13394                 break;
13395         case -ENODEV:
13396                 printf("invalid port_id %d\n", port_id);
13397                 break;
13398         case -ENOTSUP:
13399                 printf("not supported on port %d\n", port_id);
13400                 break;
13401         default:
13402                 printf("programming error: (%s)\n", strerror(-ret));
13403         }
13404 }
13405
13406 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13407         .f = cmd_set_macsec_offload_on_parsed,
13408         .data = NULL,
13409         .help_str = "set macsec offload <port_id> on "
13410                 "encrypt on|off replay-protect on|off",
13411         .tokens = {
13412                 (void *)&cmd_macsec_offload_on_set,
13413                 (void *)&cmd_macsec_offload_on_macsec,
13414                 (void *)&cmd_macsec_offload_on_offload,
13415                 (void *)&cmd_macsec_offload_on_port_id,
13416                 (void *)&cmd_macsec_offload_on_on,
13417                 (void *)&cmd_macsec_offload_on_encrypt,
13418                 (void *)&cmd_macsec_offload_on_en_on_off,
13419                 (void *)&cmd_macsec_offload_on_replay_protect,
13420                 (void *)&cmd_macsec_offload_on_rp_on_off,
13421                 NULL,
13422         },
13423 };
13424
13425 /* Common result structure for MACsec offload disable */
13426 struct cmd_macsec_offload_off_result {
13427         cmdline_fixed_string_t set;
13428         cmdline_fixed_string_t macsec;
13429         cmdline_fixed_string_t offload;
13430         portid_t port_id;
13431         cmdline_fixed_string_t off;
13432 };
13433
13434 /* Common CLI fields for MACsec offload disable */
13435 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13436         TOKEN_STRING_INITIALIZER
13437                 (struct cmd_macsec_offload_off_result,
13438                  set, "set");
13439 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13440         TOKEN_STRING_INITIALIZER
13441                 (struct cmd_macsec_offload_off_result,
13442                  macsec, "macsec");
13443 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13444         TOKEN_STRING_INITIALIZER
13445                 (struct cmd_macsec_offload_off_result,
13446                  offload, "offload");
13447 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13448         TOKEN_NUM_INITIALIZER
13449                 (struct cmd_macsec_offload_off_result,
13450                  port_id, UINT16);
13451 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13452         TOKEN_STRING_INITIALIZER
13453                 (struct cmd_macsec_offload_off_result,
13454                  off, "off");
13455
13456 static void
13457 cmd_set_macsec_offload_off_parsed(
13458         void *parsed_result,
13459         __attribute__((unused)) struct cmdline *cl,
13460         __attribute__((unused)) void *data)
13461 {
13462         struct cmd_macsec_offload_off_result *res = parsed_result;
13463         int ret = -ENOTSUP;
13464         struct rte_eth_dev_info dev_info;
13465         portid_t port_id = res->port_id;
13466
13467         if (port_id_is_invalid(port_id, ENABLED_WARN))
13468                 return;
13469         if (!port_is_stopped(port_id)) {
13470                 printf("Please stop port %d first\n", port_id);
13471                 return;
13472         }
13473
13474         rte_eth_dev_info_get(port_id, &dev_info);
13475         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13476 #ifdef RTE_LIBRTE_IXGBE_PMD
13477                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13478 #endif
13479         }
13480         switch (ret) {
13481         case 0:
13482                 ports[port_id].dev_conf.txmode.offloads &=
13483                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13484                 cmd_reconfig_device_queue(port_id, 1, 1);
13485                 break;
13486         case -ENODEV:
13487                 printf("invalid port_id %d\n", port_id);
13488                 break;
13489         case -ENOTSUP:
13490                 printf("not supported on port %d\n", port_id);
13491                 break;
13492         default:
13493                 printf("programming error: (%s)\n", strerror(-ret));
13494         }
13495 }
13496
13497 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13498         .f = cmd_set_macsec_offload_off_parsed,
13499         .data = NULL,
13500         .help_str = "set macsec offload <port_id> off",
13501         .tokens = {
13502                 (void *)&cmd_macsec_offload_off_set,
13503                 (void *)&cmd_macsec_offload_off_macsec,
13504                 (void *)&cmd_macsec_offload_off_offload,
13505                 (void *)&cmd_macsec_offload_off_port_id,
13506                 (void *)&cmd_macsec_offload_off_off,
13507                 NULL,
13508         },
13509 };
13510
13511 /* Common result structure for MACsec secure connection configure */
13512 struct cmd_macsec_sc_result {
13513         cmdline_fixed_string_t set;
13514         cmdline_fixed_string_t macsec;
13515         cmdline_fixed_string_t sc;
13516         cmdline_fixed_string_t tx_rx;
13517         portid_t port_id;
13518         struct ether_addr mac;
13519         uint16_t pi;
13520 };
13521
13522 /* Common CLI fields for MACsec secure connection configure */
13523 cmdline_parse_token_string_t cmd_macsec_sc_set =
13524         TOKEN_STRING_INITIALIZER
13525                 (struct cmd_macsec_sc_result,
13526                  set, "set");
13527 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13528         TOKEN_STRING_INITIALIZER
13529                 (struct cmd_macsec_sc_result,
13530                  macsec, "macsec");
13531 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13532         TOKEN_STRING_INITIALIZER
13533                 (struct cmd_macsec_sc_result,
13534                  sc, "sc");
13535 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13536         TOKEN_STRING_INITIALIZER
13537                 (struct cmd_macsec_sc_result,
13538                  tx_rx, "tx#rx");
13539 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13540         TOKEN_NUM_INITIALIZER
13541                 (struct cmd_macsec_sc_result,
13542                  port_id, UINT16);
13543 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13544         TOKEN_ETHERADDR_INITIALIZER
13545                 (struct cmd_macsec_sc_result,
13546                  mac);
13547 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13548         TOKEN_NUM_INITIALIZER
13549                 (struct cmd_macsec_sc_result,
13550                  pi, UINT16);
13551
13552 static void
13553 cmd_set_macsec_sc_parsed(
13554         void *parsed_result,
13555         __attribute__((unused)) struct cmdline *cl,
13556         __attribute__((unused)) void *data)
13557 {
13558         struct cmd_macsec_sc_result *res = parsed_result;
13559         int ret = -ENOTSUP;
13560         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13561
13562 #ifdef RTE_LIBRTE_IXGBE_PMD
13563         ret = is_tx ?
13564                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13565                                 res->mac.addr_bytes) :
13566                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13567                                 res->mac.addr_bytes, res->pi);
13568 #endif
13569         RTE_SET_USED(is_tx);
13570
13571         switch (ret) {
13572         case 0:
13573                 break;
13574         case -ENODEV:
13575                 printf("invalid port_id %d\n", res->port_id);
13576                 break;
13577         case -ENOTSUP:
13578                 printf("not supported on port %d\n", res->port_id);
13579                 break;
13580         default:
13581                 printf("programming error: (%s)\n", strerror(-ret));
13582         }
13583 }
13584
13585 cmdline_parse_inst_t cmd_set_macsec_sc = {
13586         .f = cmd_set_macsec_sc_parsed,
13587         .data = NULL,
13588         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13589         .tokens = {
13590                 (void *)&cmd_macsec_sc_set,
13591                 (void *)&cmd_macsec_sc_macsec,
13592                 (void *)&cmd_macsec_sc_sc,
13593                 (void *)&cmd_macsec_sc_tx_rx,
13594                 (void *)&cmd_macsec_sc_port_id,
13595                 (void *)&cmd_macsec_sc_mac,
13596                 (void *)&cmd_macsec_sc_pi,
13597                 NULL,
13598         },
13599 };
13600
13601 /* Common result structure for MACsec secure connection configure */
13602 struct cmd_macsec_sa_result {
13603         cmdline_fixed_string_t set;
13604         cmdline_fixed_string_t macsec;
13605         cmdline_fixed_string_t sa;
13606         cmdline_fixed_string_t tx_rx;
13607         portid_t port_id;
13608         uint8_t idx;
13609         uint8_t an;
13610         uint32_t pn;
13611         cmdline_fixed_string_t key;
13612 };
13613
13614 /* Common CLI fields for MACsec secure connection configure */
13615 cmdline_parse_token_string_t cmd_macsec_sa_set =
13616         TOKEN_STRING_INITIALIZER
13617                 (struct cmd_macsec_sa_result,
13618                  set, "set");
13619 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13620         TOKEN_STRING_INITIALIZER
13621                 (struct cmd_macsec_sa_result,
13622                  macsec, "macsec");
13623 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13624         TOKEN_STRING_INITIALIZER
13625                 (struct cmd_macsec_sa_result,
13626                  sa, "sa");
13627 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13628         TOKEN_STRING_INITIALIZER
13629                 (struct cmd_macsec_sa_result,
13630                  tx_rx, "tx#rx");
13631 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13632         TOKEN_NUM_INITIALIZER
13633                 (struct cmd_macsec_sa_result,
13634                  port_id, UINT16);
13635 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13636         TOKEN_NUM_INITIALIZER
13637                 (struct cmd_macsec_sa_result,
13638                  idx, UINT8);
13639 cmdline_parse_token_num_t cmd_macsec_sa_an =
13640         TOKEN_NUM_INITIALIZER
13641                 (struct cmd_macsec_sa_result,
13642                  an, UINT8);
13643 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13644         TOKEN_NUM_INITIALIZER
13645                 (struct cmd_macsec_sa_result,
13646                  pn, UINT32);
13647 cmdline_parse_token_string_t cmd_macsec_sa_key =
13648         TOKEN_STRING_INITIALIZER
13649                 (struct cmd_macsec_sa_result,
13650                  key, NULL);
13651
13652 static void
13653 cmd_set_macsec_sa_parsed(
13654         void *parsed_result,
13655         __attribute__((unused)) struct cmdline *cl,
13656         __attribute__((unused)) void *data)
13657 {
13658         struct cmd_macsec_sa_result *res = parsed_result;
13659         int ret = -ENOTSUP;
13660         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13661         uint8_t key[16] = { 0 };
13662         uint8_t xdgt0;
13663         uint8_t xdgt1;
13664         int key_len;
13665         int i;
13666
13667         key_len = strlen(res->key) / 2;
13668         if (key_len > 16)
13669                 key_len = 16;
13670
13671         for (i = 0; i < key_len; i++) {
13672                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13673                 if (xdgt0 == 0xFF)
13674                         return;
13675                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13676                 if (xdgt1 == 0xFF)
13677                         return;
13678                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13679         }
13680
13681 #ifdef RTE_LIBRTE_IXGBE_PMD
13682         ret = is_tx ?
13683                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13684                         res->idx, res->an, res->pn, key) :
13685                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13686                         res->idx, res->an, res->pn, key);
13687 #endif
13688         RTE_SET_USED(is_tx);
13689         RTE_SET_USED(key);
13690
13691         switch (ret) {
13692         case 0:
13693                 break;
13694         case -EINVAL:
13695                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13696                 break;
13697         case -ENODEV:
13698                 printf("invalid port_id %d\n", res->port_id);
13699                 break;
13700         case -ENOTSUP:
13701                 printf("not supported on port %d\n", res->port_id);
13702                 break;
13703         default:
13704                 printf("programming error: (%s)\n", strerror(-ret));
13705         }
13706 }
13707
13708 cmdline_parse_inst_t cmd_set_macsec_sa = {
13709         .f = cmd_set_macsec_sa_parsed,
13710         .data = NULL,
13711         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13712         .tokens = {
13713                 (void *)&cmd_macsec_sa_set,
13714                 (void *)&cmd_macsec_sa_macsec,
13715                 (void *)&cmd_macsec_sa_sa,
13716                 (void *)&cmd_macsec_sa_tx_rx,
13717                 (void *)&cmd_macsec_sa_port_id,
13718                 (void *)&cmd_macsec_sa_idx,
13719                 (void *)&cmd_macsec_sa_an,
13720                 (void *)&cmd_macsec_sa_pn,
13721                 (void *)&cmd_macsec_sa_key,
13722                 NULL,
13723         },
13724 };
13725
13726 /* VF unicast promiscuous mode configuration */
13727
13728 /* Common result structure for VF unicast promiscuous mode */
13729 struct cmd_vf_promisc_result {
13730         cmdline_fixed_string_t set;
13731         cmdline_fixed_string_t vf;
13732         cmdline_fixed_string_t promisc;
13733         portid_t port_id;
13734         uint32_t vf_id;
13735         cmdline_fixed_string_t on_off;
13736 };
13737
13738 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13739 cmdline_parse_token_string_t cmd_vf_promisc_set =
13740         TOKEN_STRING_INITIALIZER
13741                 (struct cmd_vf_promisc_result,
13742                  set, "set");
13743 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13744         TOKEN_STRING_INITIALIZER
13745                 (struct cmd_vf_promisc_result,
13746                  vf, "vf");
13747 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13748         TOKEN_STRING_INITIALIZER
13749                 (struct cmd_vf_promisc_result,
13750                  promisc, "promisc");
13751 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13752         TOKEN_NUM_INITIALIZER
13753                 (struct cmd_vf_promisc_result,
13754                  port_id, UINT16);
13755 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13756         TOKEN_NUM_INITIALIZER
13757                 (struct cmd_vf_promisc_result,
13758                  vf_id, UINT32);
13759 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13760         TOKEN_STRING_INITIALIZER
13761                 (struct cmd_vf_promisc_result,
13762                  on_off, "on#off");
13763
13764 static void
13765 cmd_set_vf_promisc_parsed(
13766         void *parsed_result,
13767         __attribute__((unused)) struct cmdline *cl,
13768         __attribute__((unused)) void *data)
13769 {
13770         struct cmd_vf_promisc_result *res = parsed_result;
13771         int ret = -ENOTSUP;
13772
13773         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13774
13775         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13776                 return;
13777
13778 #ifdef RTE_LIBRTE_I40E_PMD
13779         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13780                                                   res->vf_id, is_on);
13781 #endif
13782
13783         switch (ret) {
13784         case 0:
13785                 break;
13786         case -EINVAL:
13787                 printf("invalid vf_id %d\n", res->vf_id);
13788                 break;
13789         case -ENODEV:
13790                 printf("invalid port_id %d\n", res->port_id);
13791                 break;
13792         case -ENOTSUP:
13793                 printf("function not implemented\n");
13794                 break;
13795         default:
13796                 printf("programming error: (%s)\n", strerror(-ret));
13797         }
13798 }
13799
13800 cmdline_parse_inst_t cmd_set_vf_promisc = {
13801         .f = cmd_set_vf_promisc_parsed,
13802         .data = NULL,
13803         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13804                 "Set unicast promiscuous mode for a VF from the PF",
13805         .tokens = {
13806                 (void *)&cmd_vf_promisc_set,
13807                 (void *)&cmd_vf_promisc_vf,
13808                 (void *)&cmd_vf_promisc_promisc,
13809                 (void *)&cmd_vf_promisc_port_id,
13810                 (void *)&cmd_vf_promisc_vf_id,
13811                 (void *)&cmd_vf_promisc_on_off,
13812                 NULL,
13813         },
13814 };
13815
13816 /* VF multicast promiscuous mode configuration */
13817
13818 /* Common result structure for VF multicast promiscuous mode */
13819 struct cmd_vf_allmulti_result {
13820         cmdline_fixed_string_t set;
13821         cmdline_fixed_string_t vf;
13822         cmdline_fixed_string_t allmulti;
13823         portid_t port_id;
13824         uint32_t vf_id;
13825         cmdline_fixed_string_t on_off;
13826 };
13827
13828 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13829 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13830         TOKEN_STRING_INITIALIZER
13831                 (struct cmd_vf_allmulti_result,
13832                  set, "set");
13833 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13834         TOKEN_STRING_INITIALIZER
13835                 (struct cmd_vf_allmulti_result,
13836                  vf, "vf");
13837 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13838         TOKEN_STRING_INITIALIZER
13839                 (struct cmd_vf_allmulti_result,
13840                  allmulti, "allmulti");
13841 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13842         TOKEN_NUM_INITIALIZER
13843                 (struct cmd_vf_allmulti_result,
13844                  port_id, UINT16);
13845 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13846         TOKEN_NUM_INITIALIZER
13847                 (struct cmd_vf_allmulti_result,
13848                  vf_id, UINT32);
13849 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13850         TOKEN_STRING_INITIALIZER
13851                 (struct cmd_vf_allmulti_result,
13852                  on_off, "on#off");
13853
13854 static void
13855 cmd_set_vf_allmulti_parsed(
13856         void *parsed_result,
13857         __attribute__((unused)) struct cmdline *cl,
13858         __attribute__((unused)) void *data)
13859 {
13860         struct cmd_vf_allmulti_result *res = parsed_result;
13861         int ret = -ENOTSUP;
13862
13863         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13864
13865         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13866                 return;
13867
13868 #ifdef RTE_LIBRTE_I40E_PMD
13869         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13870                                                     res->vf_id, is_on);
13871 #endif
13872
13873         switch (ret) {
13874         case 0:
13875                 break;
13876         case -EINVAL:
13877                 printf("invalid vf_id %d\n", res->vf_id);
13878                 break;
13879         case -ENODEV:
13880                 printf("invalid port_id %d\n", res->port_id);
13881                 break;
13882         case -ENOTSUP:
13883                 printf("function not implemented\n");
13884                 break;
13885         default:
13886                 printf("programming error: (%s)\n", strerror(-ret));
13887         }
13888 }
13889
13890 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13891         .f = cmd_set_vf_allmulti_parsed,
13892         .data = NULL,
13893         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13894                 "Set multicast promiscuous mode for a VF from the PF",
13895         .tokens = {
13896                 (void *)&cmd_vf_allmulti_set,
13897                 (void *)&cmd_vf_allmulti_vf,
13898                 (void *)&cmd_vf_allmulti_allmulti,
13899                 (void *)&cmd_vf_allmulti_port_id,
13900                 (void *)&cmd_vf_allmulti_vf_id,
13901                 (void *)&cmd_vf_allmulti_on_off,
13902                 NULL,
13903         },
13904 };
13905
13906 /* vf broadcast mode configuration */
13907
13908 /* Common result structure for vf broadcast */
13909 struct cmd_set_vf_broadcast_result {
13910         cmdline_fixed_string_t set;
13911         cmdline_fixed_string_t vf;
13912         cmdline_fixed_string_t broadcast;
13913         portid_t port_id;
13914         uint16_t vf_id;
13915         cmdline_fixed_string_t on_off;
13916 };
13917
13918 /* Common CLI fields for vf broadcast enable disable */
13919 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13920         TOKEN_STRING_INITIALIZER
13921                 (struct cmd_set_vf_broadcast_result,
13922                  set, "set");
13923 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13924         TOKEN_STRING_INITIALIZER
13925                 (struct cmd_set_vf_broadcast_result,
13926                  vf, "vf");
13927 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13928         TOKEN_STRING_INITIALIZER
13929                 (struct cmd_set_vf_broadcast_result,
13930                  broadcast, "broadcast");
13931 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13932         TOKEN_NUM_INITIALIZER
13933                 (struct cmd_set_vf_broadcast_result,
13934                  port_id, UINT16);
13935 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13936         TOKEN_NUM_INITIALIZER
13937                 (struct cmd_set_vf_broadcast_result,
13938                  vf_id, UINT16);
13939 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13940         TOKEN_STRING_INITIALIZER
13941                 (struct cmd_set_vf_broadcast_result,
13942                  on_off, "on#off");
13943
13944 static void
13945 cmd_set_vf_broadcast_parsed(
13946         void *parsed_result,
13947         __attribute__((unused)) struct cmdline *cl,
13948         __attribute__((unused)) void *data)
13949 {
13950         struct cmd_set_vf_broadcast_result *res = parsed_result;
13951         int ret = -ENOTSUP;
13952
13953         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13954
13955         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13956                 return;
13957
13958 #ifdef RTE_LIBRTE_I40E_PMD
13959         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13960                                             res->vf_id, is_on);
13961 #endif
13962
13963         switch (ret) {
13964         case 0:
13965                 break;
13966         case -EINVAL:
13967                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13968                 break;
13969         case -ENODEV:
13970                 printf("invalid port_id %d\n", res->port_id);
13971                 break;
13972         case -ENOTSUP:
13973                 printf("function not implemented\n");
13974                 break;
13975         default:
13976                 printf("programming error: (%s)\n", strerror(-ret));
13977         }
13978 }
13979
13980 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13981         .f = cmd_set_vf_broadcast_parsed,
13982         .data = NULL,
13983         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13984         .tokens = {
13985                 (void *)&cmd_set_vf_broadcast_set,
13986                 (void *)&cmd_set_vf_broadcast_vf,
13987                 (void *)&cmd_set_vf_broadcast_broadcast,
13988                 (void *)&cmd_set_vf_broadcast_port_id,
13989                 (void *)&cmd_set_vf_broadcast_vf_id,
13990                 (void *)&cmd_set_vf_broadcast_on_off,
13991                 NULL,
13992         },
13993 };
13994
13995 /* vf vlan tag configuration */
13996
13997 /* Common result structure for vf vlan tag */
13998 struct cmd_set_vf_vlan_tag_result {
13999         cmdline_fixed_string_t set;
14000         cmdline_fixed_string_t vf;
14001         cmdline_fixed_string_t vlan;
14002         cmdline_fixed_string_t tag;
14003         portid_t port_id;
14004         uint16_t vf_id;
14005         cmdline_fixed_string_t on_off;
14006 };
14007
14008 /* Common CLI fields for vf vlan tag enable disable */
14009 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14010         TOKEN_STRING_INITIALIZER
14011                 (struct cmd_set_vf_vlan_tag_result,
14012                  set, "set");
14013 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14014         TOKEN_STRING_INITIALIZER
14015                 (struct cmd_set_vf_vlan_tag_result,
14016                  vf, "vf");
14017 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14018         TOKEN_STRING_INITIALIZER
14019                 (struct cmd_set_vf_vlan_tag_result,
14020                  vlan, "vlan");
14021 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14022         TOKEN_STRING_INITIALIZER
14023                 (struct cmd_set_vf_vlan_tag_result,
14024                  tag, "tag");
14025 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14026         TOKEN_NUM_INITIALIZER
14027                 (struct cmd_set_vf_vlan_tag_result,
14028                  port_id, UINT16);
14029 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14030         TOKEN_NUM_INITIALIZER
14031                 (struct cmd_set_vf_vlan_tag_result,
14032                  vf_id, UINT16);
14033 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14034         TOKEN_STRING_INITIALIZER
14035                 (struct cmd_set_vf_vlan_tag_result,
14036                  on_off, "on#off");
14037
14038 static void
14039 cmd_set_vf_vlan_tag_parsed(
14040         void *parsed_result,
14041         __attribute__((unused)) struct cmdline *cl,
14042         __attribute__((unused)) void *data)
14043 {
14044         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14045         int ret = -ENOTSUP;
14046
14047         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14048
14049         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14050                 return;
14051
14052 #ifdef RTE_LIBRTE_I40E_PMD
14053         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14054                                            res->vf_id, is_on);
14055 #endif
14056
14057         switch (ret) {
14058         case 0:
14059                 break;
14060         case -EINVAL:
14061                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14062                 break;
14063         case -ENODEV:
14064                 printf("invalid port_id %d\n", res->port_id);
14065                 break;
14066         case -ENOTSUP:
14067                 printf("function not implemented\n");
14068                 break;
14069         default:
14070                 printf("programming error: (%s)\n", strerror(-ret));
14071         }
14072 }
14073
14074 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14075         .f = cmd_set_vf_vlan_tag_parsed,
14076         .data = NULL,
14077         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14078         .tokens = {
14079                 (void *)&cmd_set_vf_vlan_tag_set,
14080                 (void *)&cmd_set_vf_vlan_tag_vf,
14081                 (void *)&cmd_set_vf_vlan_tag_vlan,
14082                 (void *)&cmd_set_vf_vlan_tag_tag,
14083                 (void *)&cmd_set_vf_vlan_tag_port_id,
14084                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14085                 (void *)&cmd_set_vf_vlan_tag_on_off,
14086                 NULL,
14087         },
14088 };
14089
14090 /* Common definition of VF and TC TX bandwidth configuration */
14091 struct cmd_vf_tc_bw_result {
14092         cmdline_fixed_string_t set;
14093         cmdline_fixed_string_t vf;
14094         cmdline_fixed_string_t tc;
14095         cmdline_fixed_string_t tx;
14096         cmdline_fixed_string_t min_bw;
14097         cmdline_fixed_string_t max_bw;
14098         cmdline_fixed_string_t strict_link_prio;
14099         portid_t port_id;
14100         uint16_t vf_id;
14101         uint8_t tc_no;
14102         uint32_t bw;
14103         cmdline_fixed_string_t bw_list;
14104         uint8_t tc_map;
14105 };
14106
14107 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14108         TOKEN_STRING_INITIALIZER
14109                 (struct cmd_vf_tc_bw_result,
14110                  set, "set");
14111 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14112         TOKEN_STRING_INITIALIZER
14113                 (struct cmd_vf_tc_bw_result,
14114                  vf, "vf");
14115 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14116         TOKEN_STRING_INITIALIZER
14117                 (struct cmd_vf_tc_bw_result,
14118                  tc, "tc");
14119 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14120         TOKEN_STRING_INITIALIZER
14121                 (struct cmd_vf_tc_bw_result,
14122                  tx, "tx");
14123 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14124         TOKEN_STRING_INITIALIZER
14125                 (struct cmd_vf_tc_bw_result,
14126                  strict_link_prio, "strict-link-priority");
14127 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14128         TOKEN_STRING_INITIALIZER
14129                 (struct cmd_vf_tc_bw_result,
14130                  min_bw, "min-bandwidth");
14131 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14132         TOKEN_STRING_INITIALIZER
14133                 (struct cmd_vf_tc_bw_result,
14134                  max_bw, "max-bandwidth");
14135 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14136         TOKEN_NUM_INITIALIZER
14137                 (struct cmd_vf_tc_bw_result,
14138                  port_id, UINT16);
14139 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14140         TOKEN_NUM_INITIALIZER
14141                 (struct cmd_vf_tc_bw_result,
14142                  vf_id, UINT16);
14143 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14144         TOKEN_NUM_INITIALIZER
14145                 (struct cmd_vf_tc_bw_result,
14146                  tc_no, UINT8);
14147 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14148         TOKEN_NUM_INITIALIZER
14149                 (struct cmd_vf_tc_bw_result,
14150                  bw, UINT32);
14151 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14152         TOKEN_STRING_INITIALIZER
14153                 (struct cmd_vf_tc_bw_result,
14154                  bw_list, NULL);
14155 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14156         TOKEN_NUM_INITIALIZER
14157                 (struct cmd_vf_tc_bw_result,
14158                  tc_map, UINT8);
14159
14160 /* VF max bandwidth setting */
14161 static void
14162 cmd_vf_max_bw_parsed(
14163         void *parsed_result,
14164         __attribute__((unused)) struct cmdline *cl,
14165         __attribute__((unused)) void *data)
14166 {
14167         struct cmd_vf_tc_bw_result *res = parsed_result;
14168         int ret = -ENOTSUP;
14169
14170         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14171                 return;
14172
14173 #ifdef RTE_LIBRTE_I40E_PMD
14174         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14175                                          res->vf_id, res->bw);
14176 #endif
14177
14178         switch (ret) {
14179         case 0:
14180                 break;
14181         case -EINVAL:
14182                 printf("invalid vf_id %d or bandwidth %d\n",
14183                        res->vf_id, res->bw);
14184                 break;
14185         case -ENODEV:
14186                 printf("invalid port_id %d\n", res->port_id);
14187                 break;
14188         case -ENOTSUP:
14189                 printf("function not implemented\n");
14190                 break;
14191         default:
14192                 printf("programming error: (%s)\n", strerror(-ret));
14193         }
14194 }
14195
14196 cmdline_parse_inst_t cmd_vf_max_bw = {
14197         .f = cmd_vf_max_bw_parsed,
14198         .data = NULL,
14199         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14200         .tokens = {
14201                 (void *)&cmd_vf_tc_bw_set,
14202                 (void *)&cmd_vf_tc_bw_vf,
14203                 (void *)&cmd_vf_tc_bw_tx,
14204                 (void *)&cmd_vf_tc_bw_max_bw,
14205                 (void *)&cmd_vf_tc_bw_port_id,
14206                 (void *)&cmd_vf_tc_bw_vf_id,
14207                 (void *)&cmd_vf_tc_bw_bw,
14208                 NULL,
14209         },
14210 };
14211
14212 static int
14213 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14214                            uint8_t *tc_num,
14215                            char *str)
14216 {
14217         uint32_t size;
14218         const char *p, *p0 = str;
14219         char s[256];
14220         char *end;
14221         char *str_fld[16];
14222         uint16_t i;
14223         int ret;
14224
14225         p = strchr(p0, '(');
14226         if (p == NULL) {
14227                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14228                 return -1;
14229         }
14230         p++;
14231         p0 = strchr(p, ')');
14232         if (p0 == NULL) {
14233                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14234                 return -1;
14235         }
14236         size = p0 - p;
14237         if (size >= sizeof(s)) {
14238                 printf("The string size exceeds the internal buffer size\n");
14239                 return -1;
14240         }
14241         snprintf(s, sizeof(s), "%.*s", size, p);
14242         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14243         if (ret <= 0) {
14244                 printf("Failed to get the bandwidth list. ");
14245                 return -1;
14246         }
14247         *tc_num = ret;
14248         for (i = 0; i < ret; i++)
14249                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14250
14251         return 0;
14252 }
14253
14254 /* TC min bandwidth setting */
14255 static void
14256 cmd_vf_tc_min_bw_parsed(
14257         void *parsed_result,
14258         __attribute__((unused)) struct cmdline *cl,
14259         __attribute__((unused)) void *data)
14260 {
14261         struct cmd_vf_tc_bw_result *res = parsed_result;
14262         uint8_t tc_num;
14263         uint8_t bw[16];
14264         int ret = -ENOTSUP;
14265
14266         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14267                 return;
14268
14269         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14270         if (ret)
14271                 return;
14272
14273 #ifdef RTE_LIBRTE_I40E_PMD
14274         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14275                                               tc_num, bw);
14276 #endif
14277
14278         switch (ret) {
14279         case 0:
14280                 break;
14281         case -EINVAL:
14282                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14283                 break;
14284         case -ENODEV:
14285                 printf("invalid port_id %d\n", res->port_id);
14286                 break;
14287         case -ENOTSUP:
14288                 printf("function not implemented\n");
14289                 break;
14290         default:
14291                 printf("programming error: (%s)\n", strerror(-ret));
14292         }
14293 }
14294
14295 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14296         .f = cmd_vf_tc_min_bw_parsed,
14297         .data = NULL,
14298         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14299                     " <bw1, bw2, ...>",
14300         .tokens = {
14301                 (void *)&cmd_vf_tc_bw_set,
14302                 (void *)&cmd_vf_tc_bw_vf,
14303                 (void *)&cmd_vf_tc_bw_tc,
14304                 (void *)&cmd_vf_tc_bw_tx,
14305                 (void *)&cmd_vf_tc_bw_min_bw,
14306                 (void *)&cmd_vf_tc_bw_port_id,
14307                 (void *)&cmd_vf_tc_bw_vf_id,
14308                 (void *)&cmd_vf_tc_bw_bw_list,
14309                 NULL,
14310         },
14311 };
14312
14313 static void
14314 cmd_tc_min_bw_parsed(
14315         void *parsed_result,
14316         __attribute__((unused)) struct cmdline *cl,
14317         __attribute__((unused)) void *data)
14318 {
14319         struct cmd_vf_tc_bw_result *res = parsed_result;
14320         struct rte_port *port;
14321         uint8_t tc_num;
14322         uint8_t bw[16];
14323         int ret = -ENOTSUP;
14324
14325         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14326                 return;
14327
14328         port = &ports[res->port_id];
14329         /** Check if the port is not started **/
14330         if (port->port_status != RTE_PORT_STOPPED) {
14331                 printf("Please stop port %d first\n", res->port_id);
14332                 return;
14333         }
14334
14335         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14336         if (ret)
14337                 return;
14338
14339 #ifdef RTE_LIBRTE_IXGBE_PMD
14340         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14341 #endif
14342
14343         switch (ret) {
14344         case 0:
14345                 break;
14346         case -EINVAL:
14347                 printf("invalid bandwidth\n");
14348                 break;
14349         case -ENODEV:
14350                 printf("invalid port_id %d\n", res->port_id);
14351                 break;
14352         case -ENOTSUP:
14353                 printf("function not implemented\n");
14354                 break;
14355         default:
14356                 printf("programming error: (%s)\n", strerror(-ret));
14357         }
14358 }
14359
14360 cmdline_parse_inst_t cmd_tc_min_bw = {
14361         .f = cmd_tc_min_bw_parsed,
14362         .data = NULL,
14363         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14364         .tokens = {
14365                 (void *)&cmd_vf_tc_bw_set,
14366                 (void *)&cmd_vf_tc_bw_tc,
14367                 (void *)&cmd_vf_tc_bw_tx,
14368                 (void *)&cmd_vf_tc_bw_min_bw,
14369                 (void *)&cmd_vf_tc_bw_port_id,
14370                 (void *)&cmd_vf_tc_bw_bw_list,
14371                 NULL,
14372         },
14373 };
14374
14375 /* TC max bandwidth setting */
14376 static void
14377 cmd_vf_tc_max_bw_parsed(
14378         void *parsed_result,
14379         __attribute__((unused)) struct cmdline *cl,
14380         __attribute__((unused)) void *data)
14381 {
14382         struct cmd_vf_tc_bw_result *res = parsed_result;
14383         int ret = -ENOTSUP;
14384
14385         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14386                 return;
14387
14388 #ifdef RTE_LIBRTE_I40E_PMD
14389         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14390                                             res->tc_no, res->bw);
14391 #endif
14392
14393         switch (ret) {
14394         case 0:
14395                 break;
14396         case -EINVAL:
14397                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14398                        res->vf_id, res->tc_no, res->bw);
14399                 break;
14400         case -ENODEV:
14401                 printf("invalid port_id %d\n", res->port_id);
14402                 break;
14403         case -ENOTSUP:
14404                 printf("function not implemented\n");
14405                 break;
14406         default:
14407                 printf("programming error: (%s)\n", strerror(-ret));
14408         }
14409 }
14410
14411 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14412         .f = cmd_vf_tc_max_bw_parsed,
14413         .data = NULL,
14414         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14415                     " <bandwidth>",
14416         .tokens = {
14417                 (void *)&cmd_vf_tc_bw_set,
14418                 (void *)&cmd_vf_tc_bw_vf,
14419                 (void *)&cmd_vf_tc_bw_tc,
14420                 (void *)&cmd_vf_tc_bw_tx,
14421                 (void *)&cmd_vf_tc_bw_max_bw,
14422                 (void *)&cmd_vf_tc_bw_port_id,
14423                 (void *)&cmd_vf_tc_bw_vf_id,
14424                 (void *)&cmd_vf_tc_bw_tc_no,
14425                 (void *)&cmd_vf_tc_bw_bw,
14426                 NULL,
14427         },
14428 };
14429
14430
14431 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14432
14433 /* *** Set Port default Traffic Management Hierarchy *** */
14434 struct cmd_set_port_tm_hierarchy_default_result {
14435         cmdline_fixed_string_t set;
14436         cmdline_fixed_string_t port;
14437         cmdline_fixed_string_t tm;
14438         cmdline_fixed_string_t hierarchy;
14439         cmdline_fixed_string_t def;
14440         portid_t port_id;
14441 };
14442
14443 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14444         TOKEN_STRING_INITIALIZER(
14445                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14446 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14447         TOKEN_STRING_INITIALIZER(
14448                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14449 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14450         TOKEN_STRING_INITIALIZER(
14451                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14452 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14453         TOKEN_STRING_INITIALIZER(
14454                 struct cmd_set_port_tm_hierarchy_default_result,
14455                         hierarchy, "hierarchy");
14456 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14457         TOKEN_STRING_INITIALIZER(
14458                 struct cmd_set_port_tm_hierarchy_default_result,
14459                         def, "default");
14460 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14461         TOKEN_NUM_INITIALIZER(
14462                 struct cmd_set_port_tm_hierarchy_default_result,
14463                         port_id, UINT16);
14464
14465 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14466         __attribute__((unused)) struct cmdline *cl,
14467         __attribute__((unused)) void *data)
14468 {
14469         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14470         struct rte_port *p;
14471         portid_t port_id = res->port_id;
14472
14473         if (port_id_is_invalid(port_id, ENABLED_WARN))
14474                 return;
14475
14476         p = &ports[port_id];
14477
14478         /* Port tm flag */
14479         if (p->softport.tm_flag == 0) {
14480                 printf("  tm not enabled on port %u (error)\n", port_id);
14481                 return;
14482         }
14483
14484         /* Forward mode: tm */
14485         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14486                 printf("  tm mode not enabled(error)\n");
14487                 return;
14488         }
14489
14490         /* Set the default tm hierarchy */
14491         p->softport.tm.default_hierarchy_enable = 1;
14492 }
14493
14494 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14495         .f = cmd_set_port_tm_hierarchy_default_parsed,
14496         .data = NULL,
14497         .help_str = "set port tm hierarchy default <port_id>",
14498         .tokens = {
14499                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14500                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14501                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14502                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14503                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14504                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14505                 NULL,
14506         },
14507 };
14508 #endif
14509
14510 /* Strict link priority scheduling mode setting */
14511 static void
14512 cmd_strict_link_prio_parsed(
14513         void *parsed_result,
14514         __attribute__((unused)) struct cmdline *cl,
14515         __attribute__((unused)) void *data)
14516 {
14517         struct cmd_vf_tc_bw_result *res = parsed_result;
14518         int ret = -ENOTSUP;
14519
14520         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14521                 return;
14522
14523 #ifdef RTE_LIBRTE_I40E_PMD
14524         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14525 #endif
14526
14527         switch (ret) {
14528         case 0:
14529                 break;
14530         case -EINVAL:
14531                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14532                 break;
14533         case -ENODEV:
14534                 printf("invalid port_id %d\n", res->port_id);
14535                 break;
14536         case -ENOTSUP:
14537                 printf("function not implemented\n");
14538                 break;
14539         default:
14540                 printf("programming error: (%s)\n", strerror(-ret));
14541         }
14542 }
14543
14544 cmdline_parse_inst_t cmd_strict_link_prio = {
14545         .f = cmd_strict_link_prio_parsed,
14546         .data = NULL,
14547         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14548         .tokens = {
14549                 (void *)&cmd_vf_tc_bw_set,
14550                 (void *)&cmd_vf_tc_bw_tx,
14551                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14552                 (void *)&cmd_vf_tc_bw_port_id,
14553                 (void *)&cmd_vf_tc_bw_tc_map,
14554                 NULL,
14555         },
14556 };
14557
14558 /* Load dynamic device personalization*/
14559 struct cmd_ddp_add_result {
14560         cmdline_fixed_string_t ddp;
14561         cmdline_fixed_string_t add;
14562         portid_t port_id;
14563         char filepath[];
14564 };
14565
14566 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14567         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14568 cmdline_parse_token_string_t cmd_ddp_add_add =
14569         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14570 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14571         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14572 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14573         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14574
14575 static void
14576 cmd_ddp_add_parsed(
14577         void *parsed_result,
14578         __attribute__((unused)) struct cmdline *cl,
14579         __attribute__((unused)) void *data)
14580 {
14581         struct cmd_ddp_add_result *res = parsed_result;
14582         uint8_t *buff;
14583         uint32_t size;
14584         char *filepath;
14585         char *file_fld[2];
14586         int file_num;
14587         int ret = -ENOTSUP;
14588
14589         if (res->port_id > nb_ports) {
14590                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14591                 return;
14592         }
14593
14594         if (!all_ports_stopped()) {
14595                 printf("Please stop all ports first\n");
14596                 return;
14597         }
14598
14599         filepath = strdup(res->filepath);
14600         if (filepath == NULL) {
14601                 printf("Failed to allocate memory\n");
14602                 return;
14603         }
14604         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14605
14606         buff = open_file(file_fld[0], &size);
14607         if (!buff) {
14608                 free((void *)filepath);
14609                 return;
14610         }
14611
14612 #ifdef RTE_LIBRTE_I40E_PMD
14613         if (ret == -ENOTSUP)
14614                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14615                                                buff, size,
14616                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14617 #endif
14618
14619         if (ret == -EEXIST)
14620                 printf("Profile has already existed.\n");
14621         else if (ret < 0)
14622                 printf("Failed to load profile.\n");
14623         else if (file_num == 2)
14624                 save_file(file_fld[1], buff, size);
14625
14626         close_file(buff);
14627         free((void *)filepath);
14628 }
14629
14630 cmdline_parse_inst_t cmd_ddp_add = {
14631         .f = cmd_ddp_add_parsed,
14632         .data = NULL,
14633         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14634         .tokens = {
14635                 (void *)&cmd_ddp_add_ddp,
14636                 (void *)&cmd_ddp_add_add,
14637                 (void *)&cmd_ddp_add_port_id,
14638                 (void *)&cmd_ddp_add_filepath,
14639                 NULL,
14640         },
14641 };
14642
14643 /* Delete dynamic device personalization*/
14644 struct cmd_ddp_del_result {
14645         cmdline_fixed_string_t ddp;
14646         cmdline_fixed_string_t del;
14647         portid_t port_id;
14648         char filepath[];
14649 };
14650
14651 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14652         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14653 cmdline_parse_token_string_t cmd_ddp_del_del =
14654         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14655 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14656         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14657 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14658         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14659
14660 static void
14661 cmd_ddp_del_parsed(
14662         void *parsed_result,
14663         __attribute__((unused)) struct cmdline *cl,
14664         __attribute__((unused)) void *data)
14665 {
14666         struct cmd_ddp_del_result *res = parsed_result;
14667         uint8_t *buff;
14668         uint32_t size;
14669         int ret = -ENOTSUP;
14670
14671         if (res->port_id > nb_ports) {
14672                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14673                 return;
14674         }
14675
14676         if (!all_ports_stopped()) {
14677                 printf("Please stop all ports first\n");
14678                 return;
14679         }
14680
14681         buff = open_file(res->filepath, &size);
14682         if (!buff)
14683                 return;
14684
14685 #ifdef RTE_LIBRTE_I40E_PMD
14686         if (ret == -ENOTSUP)
14687                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14688                                                buff, size,
14689                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14690 #endif
14691
14692         if (ret == -EACCES)
14693                 printf("Profile does not exist.\n");
14694         else if (ret < 0)
14695                 printf("Failed to delete profile.\n");
14696
14697         close_file(buff);
14698 }
14699
14700 cmdline_parse_inst_t cmd_ddp_del = {
14701         .f = cmd_ddp_del_parsed,
14702         .data = NULL,
14703         .help_str = "ddp del <port_id> <backup_profile_path>",
14704         .tokens = {
14705                 (void *)&cmd_ddp_del_ddp,
14706                 (void *)&cmd_ddp_del_del,
14707                 (void *)&cmd_ddp_del_port_id,
14708                 (void *)&cmd_ddp_del_filepath,
14709                 NULL,
14710         },
14711 };
14712
14713 /* Get dynamic device personalization profile info */
14714 struct cmd_ddp_info_result {
14715         cmdline_fixed_string_t ddp;
14716         cmdline_fixed_string_t get;
14717         cmdline_fixed_string_t info;
14718         char filepath[];
14719 };
14720
14721 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14722         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14723 cmdline_parse_token_string_t cmd_ddp_info_get =
14724         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14725 cmdline_parse_token_string_t cmd_ddp_info_info =
14726         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14727 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14728         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14729
14730 static void
14731 cmd_ddp_info_parsed(
14732         void *parsed_result,
14733         __attribute__((unused)) struct cmdline *cl,
14734         __attribute__((unused)) void *data)
14735 {
14736         struct cmd_ddp_info_result *res = parsed_result;
14737         uint8_t *pkg;
14738         uint32_t pkg_size;
14739         int ret = -ENOTSUP;
14740 #ifdef RTE_LIBRTE_I40E_PMD
14741         uint32_t i, j, n;
14742         uint8_t *buff;
14743         uint32_t buff_size = 0;
14744         struct rte_pmd_i40e_profile_info info;
14745         uint32_t dev_num = 0;
14746         struct rte_pmd_i40e_ddp_device_id *devs;
14747         uint32_t proto_num = 0;
14748         struct rte_pmd_i40e_proto_info *proto = NULL;
14749         uint32_t pctype_num = 0;
14750         struct rte_pmd_i40e_ptype_info *pctype;
14751         uint32_t ptype_num = 0;
14752         struct rte_pmd_i40e_ptype_info *ptype;
14753         uint8_t proto_id;
14754
14755 #endif
14756
14757         pkg = open_file(res->filepath, &pkg_size);
14758         if (!pkg)
14759                 return;
14760
14761 #ifdef RTE_LIBRTE_I40E_PMD
14762         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14763                                 (uint8_t *)&info, sizeof(info),
14764                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14765         if (!ret) {
14766                 printf("Global Track id:       0x%x\n", info.track_id);
14767                 printf("Global Version:        %d.%d.%d.%d\n",
14768                         info.version.major,
14769                         info.version.minor,
14770                         info.version.update,
14771                         info.version.draft);
14772                 printf("Global Package name:   %s\n\n", info.name);
14773         }
14774
14775         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14776                                 (uint8_t *)&info, sizeof(info),
14777                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14778         if (!ret) {
14779                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14780                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14781                         info.version.major,
14782                         info.version.minor,
14783                         info.version.update,
14784                         info.version.draft);
14785                 printf("i40e Profile name:     %s\n\n", info.name);
14786         }
14787
14788         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14789                                 (uint8_t *)&buff_size, sizeof(buff_size),
14790                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14791         if (!ret && buff_size) {
14792                 buff = (uint8_t *)malloc(buff_size);
14793                 if (buff) {
14794                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14795                                                 buff, buff_size,
14796                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14797                         if (!ret)
14798                                 printf("Package Notes:\n%s\n\n", buff);
14799                         free(buff);
14800                 }
14801         }
14802
14803         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14804                                 (uint8_t *)&dev_num, sizeof(dev_num),
14805                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14806         if (!ret && dev_num) {
14807                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14808                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14809                 if (devs) {
14810                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14811                                                 (uint8_t *)devs, buff_size,
14812                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14813                         if (!ret) {
14814                                 printf("List of supported devices:\n");
14815                                 for (i = 0; i < dev_num; i++) {
14816                                         printf("  %04X:%04X %04X:%04X\n",
14817                                                 devs[i].vendor_dev_id >> 16,
14818                                                 devs[i].vendor_dev_id & 0xFFFF,
14819                                                 devs[i].sub_vendor_dev_id >> 16,
14820                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14821                                 }
14822                                 printf("\n");
14823                         }
14824                         free(devs);
14825                 }
14826         }
14827
14828         /* get information about protocols and packet types */
14829         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14830                 (uint8_t *)&proto_num, sizeof(proto_num),
14831                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14832         if (ret || !proto_num)
14833                 goto no_print_return;
14834
14835         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14836         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14837         if (!proto)
14838                 goto no_print_return;
14839
14840         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14841                                         buff_size,
14842                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14843         if (!ret) {
14844                 printf("List of used protocols:\n");
14845                 for (i = 0; i < proto_num; i++)
14846                         printf("  %2u: %s\n", proto[i].proto_id,
14847                                proto[i].name);
14848                 printf("\n");
14849         }
14850         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14851                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14852                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14853         if (ret || !pctype_num)
14854                 goto no_print_pctypes;
14855
14856         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14857         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14858         if (!pctype)
14859                 goto no_print_pctypes;
14860
14861         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14862                                         buff_size,
14863                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14864         if (ret) {
14865                 free(pctype);
14866                 goto no_print_pctypes;
14867         }
14868
14869         printf("List of defined packet classification types:\n");
14870         for (i = 0; i < pctype_num; i++) {
14871                 printf("  %2u:", pctype[i].ptype_id);
14872                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14873                         proto_id = pctype[i].protocols[j];
14874                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14875                                 for (n = 0; n < proto_num; n++) {
14876                                         if (proto[n].proto_id == proto_id) {
14877                                                 printf(" %s", proto[n].name);
14878                                                 break;
14879                                         }
14880                                 }
14881                         }
14882                 }
14883                 printf("\n");
14884         }
14885         printf("\n");
14886         free(pctype);
14887
14888 no_print_pctypes:
14889
14890         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14891                                         sizeof(ptype_num),
14892                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14893         if (ret || !ptype_num)
14894                 goto no_print_return;
14895
14896         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14897         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14898         if (!ptype)
14899                 goto no_print_return;
14900
14901         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14902                                         buff_size,
14903                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14904         if (ret) {
14905                 free(ptype);
14906                 goto no_print_return;
14907         }
14908         printf("List of defined packet types:\n");
14909         for (i = 0; i < ptype_num; i++) {
14910                 printf("  %2u:", ptype[i].ptype_id);
14911                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14912                         proto_id = ptype[i].protocols[j];
14913                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14914                                 for (n = 0; n < proto_num; n++) {
14915                                         if (proto[n].proto_id == proto_id) {
14916                                                 printf(" %s", proto[n].name);
14917                                                 break;
14918                                         }
14919                                 }
14920                         }
14921                 }
14922                 printf("\n");
14923         }
14924         free(ptype);
14925         printf("\n");
14926
14927         ret = 0;
14928 no_print_return:
14929         if (proto)
14930                 free(proto);
14931 #endif
14932         if (ret == -ENOTSUP)
14933                 printf("Function not supported in PMD driver\n");
14934         close_file(pkg);
14935 }
14936
14937 cmdline_parse_inst_t cmd_ddp_get_info = {
14938         .f = cmd_ddp_info_parsed,
14939         .data = NULL,
14940         .help_str = "ddp get info <profile_path>",
14941         .tokens = {
14942                 (void *)&cmd_ddp_info_ddp,
14943                 (void *)&cmd_ddp_info_get,
14944                 (void *)&cmd_ddp_info_info,
14945                 (void *)&cmd_ddp_info_filepath,
14946                 NULL,
14947         },
14948 };
14949
14950 /* Get dynamic device personalization profile info list*/
14951 #define PROFILE_INFO_SIZE 48
14952 #define MAX_PROFILE_NUM 16
14953
14954 struct cmd_ddp_get_list_result {
14955         cmdline_fixed_string_t ddp;
14956         cmdline_fixed_string_t get;
14957         cmdline_fixed_string_t list;
14958         portid_t port_id;
14959 };
14960
14961 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14962         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14963 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14964         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14965 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14966         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14967 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14968         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14969
14970 static void
14971 cmd_ddp_get_list_parsed(
14972         void *parsed_result,
14973         __attribute__((unused)) struct cmdline *cl,
14974         __attribute__((unused)) void *data)
14975 {
14976         struct cmd_ddp_get_list_result *res = parsed_result;
14977 #ifdef RTE_LIBRTE_I40E_PMD
14978         struct rte_pmd_i40e_profile_list *p_list;
14979         struct rte_pmd_i40e_profile_info *p_info;
14980         uint32_t p_num;
14981         uint32_t size;
14982         uint32_t i;
14983 #endif
14984         int ret = -ENOTSUP;
14985
14986         if (res->port_id > nb_ports) {
14987                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14988                 return;
14989         }
14990
14991 #ifdef RTE_LIBRTE_I40E_PMD
14992         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14993         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14994         if (!p_list)
14995                 printf("%s: Failed to malloc buffer\n", __func__);
14996
14997         if (ret == -ENOTSUP)
14998                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14999                                                 (uint8_t *)p_list, size);
15000
15001         if (!ret) {
15002                 p_num = p_list->p_count;
15003                 printf("Profile number is: %d\n\n", p_num);
15004
15005                 for (i = 0; i < p_num; i++) {
15006                         p_info = &p_list->p_info[i];
15007                         printf("Profile %d:\n", i);
15008                         printf("Track id:     0x%x\n", p_info->track_id);
15009                         printf("Version:      %d.%d.%d.%d\n",
15010                                p_info->version.major,
15011                                p_info->version.minor,
15012                                p_info->version.update,
15013                                p_info->version.draft);
15014                         printf("Profile name: %s\n\n", p_info->name);
15015                 }
15016         }
15017
15018         free(p_list);
15019 #endif
15020
15021         if (ret < 0)
15022                 printf("Failed to get ddp list\n");
15023 }
15024
15025 cmdline_parse_inst_t cmd_ddp_get_list = {
15026         .f = cmd_ddp_get_list_parsed,
15027         .data = NULL,
15028         .help_str = "ddp get list <port_id>",
15029         .tokens = {
15030                 (void *)&cmd_ddp_get_list_ddp,
15031                 (void *)&cmd_ddp_get_list_get,
15032                 (void *)&cmd_ddp_get_list_list,
15033                 (void *)&cmd_ddp_get_list_port_id,
15034                 NULL,
15035         },
15036 };
15037
15038 /* Configure input set */
15039 struct cmd_cfg_input_set_result {
15040         cmdline_fixed_string_t port;
15041         cmdline_fixed_string_t cfg;
15042         portid_t port_id;
15043         cmdline_fixed_string_t pctype;
15044         uint8_t pctype_id;
15045         cmdline_fixed_string_t inset_type;
15046         cmdline_fixed_string_t opt;
15047         cmdline_fixed_string_t field;
15048         uint8_t field_idx;
15049 };
15050
15051 static void
15052 cmd_cfg_input_set_parsed(
15053         void *parsed_result,
15054         __attribute__((unused)) struct cmdline *cl,
15055         __attribute__((unused)) void *data)
15056 {
15057         struct cmd_cfg_input_set_result *res = parsed_result;
15058 #ifdef RTE_LIBRTE_I40E_PMD
15059         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15060         struct rte_pmd_i40e_inset inset;
15061 #endif
15062         int ret = -ENOTSUP;
15063
15064         if (res->port_id > nb_ports) {
15065                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
15066                 return;
15067         }
15068
15069         if (!all_ports_stopped()) {
15070                 printf("Please stop all ports first\n");
15071                 return;
15072         }
15073
15074 #ifdef RTE_LIBRTE_I40E_PMD
15075         if (!strcmp(res->inset_type, "hash_inset"))
15076                 inset_type = INSET_HASH;
15077         else if (!strcmp(res->inset_type, "fdir_inset"))
15078                 inset_type = INSET_FDIR;
15079         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15080                 inset_type = INSET_FDIR_FLX;
15081         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15082                                      &inset, inset_type);
15083         if (ret) {
15084                 printf("Failed to get input set.\n");
15085                 return;
15086         }
15087
15088         if (!strcmp(res->opt, "get")) {
15089                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15090                                                    res->field_idx);
15091                 if (ret)
15092                         printf("Field index %d is enabled.\n", res->field_idx);
15093                 else
15094                         printf("Field index %d is disabled.\n", res->field_idx);
15095                 return;
15096         } else if (!strcmp(res->opt, "set"))
15097                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15098                                                    res->field_idx);
15099         else if (!strcmp(res->opt, "clear"))
15100                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15101                                                      res->field_idx);
15102         if (ret) {
15103                 printf("Failed to configure input set field.\n");
15104                 return;
15105         }
15106
15107         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15108                                      &inset, inset_type);
15109         if (ret) {
15110                 printf("Failed to set input set.\n");
15111                 return;
15112         }
15113 #endif
15114
15115         if (ret == -ENOTSUP)
15116                 printf("Function not supported\n");
15117 }
15118
15119 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15120         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15121                                  port, "port");
15122 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15123         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15124                                  cfg, "config");
15125 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15126         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15127                               port_id, UINT16);
15128 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15129         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15130                                  pctype, "pctype");
15131 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15132         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15133                               pctype_id, UINT8);
15134 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15135         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15136                                  inset_type,
15137                                  "hash_inset#fdir_inset#fdir_flx_inset");
15138 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15139         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15140                                  opt, "get#set#clear");
15141 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15142         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15143                                  field, "field");
15144 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15145         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15146                               field_idx, UINT8);
15147
15148 cmdline_parse_inst_t cmd_cfg_input_set = {
15149         .f = cmd_cfg_input_set_parsed,
15150         .data = NULL,
15151         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15152                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15153         .tokens = {
15154                 (void *)&cmd_cfg_input_set_port,
15155                 (void *)&cmd_cfg_input_set_cfg,
15156                 (void *)&cmd_cfg_input_set_port_id,
15157                 (void *)&cmd_cfg_input_set_pctype,
15158                 (void *)&cmd_cfg_input_set_pctype_id,
15159                 (void *)&cmd_cfg_input_set_inset_type,
15160                 (void *)&cmd_cfg_input_set_opt,
15161                 (void *)&cmd_cfg_input_set_field,
15162                 (void *)&cmd_cfg_input_set_field_idx,
15163                 NULL,
15164         },
15165 };
15166
15167 /* Clear input set */
15168 struct cmd_clear_input_set_result {
15169         cmdline_fixed_string_t port;
15170         cmdline_fixed_string_t cfg;
15171         portid_t port_id;
15172         cmdline_fixed_string_t pctype;
15173         uint8_t pctype_id;
15174         cmdline_fixed_string_t inset_type;
15175         cmdline_fixed_string_t clear;
15176         cmdline_fixed_string_t all;
15177 };
15178
15179 static void
15180 cmd_clear_input_set_parsed(
15181         void *parsed_result,
15182         __attribute__((unused)) struct cmdline *cl,
15183         __attribute__((unused)) void *data)
15184 {
15185         struct cmd_clear_input_set_result *res = parsed_result;
15186 #ifdef RTE_LIBRTE_I40E_PMD
15187         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15188         struct rte_pmd_i40e_inset inset;
15189 #endif
15190         int ret = -ENOTSUP;
15191
15192         if (res->port_id > nb_ports) {
15193                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
15194                 return;
15195         }
15196
15197         if (!all_ports_stopped()) {
15198                 printf("Please stop all ports first\n");
15199                 return;
15200         }
15201
15202 #ifdef RTE_LIBRTE_I40E_PMD
15203         if (!strcmp(res->inset_type, "hash_inset"))
15204                 inset_type = INSET_HASH;
15205         else if (!strcmp(res->inset_type, "fdir_inset"))
15206                 inset_type = INSET_FDIR;
15207         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15208                 inset_type = INSET_FDIR_FLX;
15209
15210         memset(&inset, 0, sizeof(inset));
15211
15212         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15213                                      &inset, inset_type);
15214         if (ret) {
15215                 printf("Failed to clear input set.\n");
15216                 return;
15217         }
15218
15219 #endif
15220
15221         if (ret == -ENOTSUP)
15222                 printf("Function not supported\n");
15223 }
15224
15225 cmdline_parse_token_string_t cmd_clear_input_set_port =
15226         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15227                                  port, "port");
15228 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15229         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15230                                  cfg, "config");
15231 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15232         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15233                               port_id, UINT16);
15234 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15235         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15236                                  pctype, "pctype");
15237 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15238         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15239                               pctype_id, UINT8);
15240 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15241         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15242                                  inset_type,
15243                                  "hash_inset#fdir_inset#fdir_flx_inset");
15244 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15245         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15246                                  clear, "clear");
15247 cmdline_parse_token_string_t cmd_clear_input_set_all =
15248         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15249                                  all, "all");
15250
15251 cmdline_parse_inst_t cmd_clear_input_set = {
15252         .f = cmd_clear_input_set_parsed,
15253         .data = NULL,
15254         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15255                     "fdir_inset|fdir_flx_inset clear all",
15256         .tokens = {
15257                 (void *)&cmd_clear_input_set_port,
15258                 (void *)&cmd_clear_input_set_cfg,
15259                 (void *)&cmd_clear_input_set_port_id,
15260                 (void *)&cmd_clear_input_set_pctype,
15261                 (void *)&cmd_clear_input_set_pctype_id,
15262                 (void *)&cmd_clear_input_set_inset_type,
15263                 (void *)&cmd_clear_input_set_clear,
15264                 (void *)&cmd_clear_input_set_all,
15265                 NULL,
15266         },
15267 };
15268
15269 /* show vf stats */
15270
15271 /* Common result structure for show vf stats */
15272 struct cmd_show_vf_stats_result {
15273         cmdline_fixed_string_t show;
15274         cmdline_fixed_string_t vf;
15275         cmdline_fixed_string_t stats;
15276         portid_t port_id;
15277         uint16_t vf_id;
15278 };
15279
15280 /* Common CLI fields show vf stats*/
15281 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15282         TOKEN_STRING_INITIALIZER
15283                 (struct cmd_show_vf_stats_result,
15284                  show, "show");
15285 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15286         TOKEN_STRING_INITIALIZER
15287                 (struct cmd_show_vf_stats_result,
15288                  vf, "vf");
15289 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15290         TOKEN_STRING_INITIALIZER
15291                 (struct cmd_show_vf_stats_result,
15292                  stats, "stats");
15293 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15294         TOKEN_NUM_INITIALIZER
15295                 (struct cmd_show_vf_stats_result,
15296                  port_id, UINT16);
15297 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15298         TOKEN_NUM_INITIALIZER
15299                 (struct cmd_show_vf_stats_result,
15300                  vf_id, UINT16);
15301
15302 static void
15303 cmd_show_vf_stats_parsed(
15304         void *parsed_result,
15305         __attribute__((unused)) struct cmdline *cl,
15306         __attribute__((unused)) void *data)
15307 {
15308         struct cmd_show_vf_stats_result *res = parsed_result;
15309         struct rte_eth_stats stats;
15310         int ret = -ENOTSUP;
15311         static const char *nic_stats_border = "########################";
15312
15313         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15314                 return;
15315
15316         memset(&stats, 0, sizeof(stats));
15317
15318 #ifdef RTE_LIBRTE_I40E_PMD
15319         if (ret == -ENOTSUP)
15320                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15321                                                 res->vf_id,
15322                                                 &stats);
15323 #endif
15324 #ifdef RTE_LIBRTE_BNXT_PMD
15325         if (ret == -ENOTSUP)
15326                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15327                                                 res->vf_id,
15328                                                 &stats);
15329 #endif
15330
15331         switch (ret) {
15332         case 0:
15333                 break;
15334         case -EINVAL:
15335                 printf("invalid vf_id %d\n", res->vf_id);
15336                 break;
15337         case -ENODEV:
15338                 printf("invalid port_id %d\n", res->port_id);
15339                 break;
15340         case -ENOTSUP:
15341                 printf("function not implemented\n");
15342                 break;
15343         default:
15344                 printf("programming error: (%s)\n", strerror(-ret));
15345         }
15346
15347         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15348                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15349
15350         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15351                "%-"PRIu64"\n",
15352                stats.ipackets, stats.imissed, stats.ibytes);
15353         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15354         printf("  RX-nombuf:  %-10"PRIu64"\n",
15355                stats.rx_nombuf);
15356         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15357                "%-"PRIu64"\n",
15358                stats.opackets, stats.oerrors, stats.obytes);
15359
15360         printf("  %s############################%s\n",
15361                                nic_stats_border, nic_stats_border);
15362 }
15363
15364 cmdline_parse_inst_t cmd_show_vf_stats = {
15365         .f = cmd_show_vf_stats_parsed,
15366         .data = NULL,
15367         .help_str = "show vf stats <port_id> <vf_id>",
15368         .tokens = {
15369                 (void *)&cmd_show_vf_stats_show,
15370                 (void *)&cmd_show_vf_stats_vf,
15371                 (void *)&cmd_show_vf_stats_stats,
15372                 (void *)&cmd_show_vf_stats_port_id,
15373                 (void *)&cmd_show_vf_stats_vf_id,
15374                 NULL,
15375         },
15376 };
15377
15378 /* clear vf stats */
15379
15380 /* Common result structure for clear vf stats */
15381 struct cmd_clear_vf_stats_result {
15382         cmdline_fixed_string_t clear;
15383         cmdline_fixed_string_t vf;
15384         cmdline_fixed_string_t stats;
15385         portid_t port_id;
15386         uint16_t vf_id;
15387 };
15388
15389 /* Common CLI fields clear vf stats*/
15390 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15391         TOKEN_STRING_INITIALIZER
15392                 (struct cmd_clear_vf_stats_result,
15393                  clear, "clear");
15394 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15395         TOKEN_STRING_INITIALIZER
15396                 (struct cmd_clear_vf_stats_result,
15397                  vf, "vf");
15398 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15399         TOKEN_STRING_INITIALIZER
15400                 (struct cmd_clear_vf_stats_result,
15401                  stats, "stats");
15402 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15403         TOKEN_NUM_INITIALIZER
15404                 (struct cmd_clear_vf_stats_result,
15405                  port_id, UINT16);
15406 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15407         TOKEN_NUM_INITIALIZER
15408                 (struct cmd_clear_vf_stats_result,
15409                  vf_id, UINT16);
15410
15411 static void
15412 cmd_clear_vf_stats_parsed(
15413         void *parsed_result,
15414         __attribute__((unused)) struct cmdline *cl,
15415         __attribute__((unused)) void *data)
15416 {
15417         struct cmd_clear_vf_stats_result *res = parsed_result;
15418         int ret = -ENOTSUP;
15419
15420         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15421                 return;
15422
15423 #ifdef RTE_LIBRTE_I40E_PMD
15424         if (ret == -ENOTSUP)
15425                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15426                                                   res->vf_id);
15427 #endif
15428 #ifdef RTE_LIBRTE_BNXT_PMD
15429         if (ret == -ENOTSUP)
15430                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15431                                                   res->vf_id);
15432 #endif
15433
15434         switch (ret) {
15435         case 0:
15436                 break;
15437         case -EINVAL:
15438                 printf("invalid vf_id %d\n", res->vf_id);
15439                 break;
15440         case -ENODEV:
15441                 printf("invalid port_id %d\n", res->port_id);
15442                 break;
15443         case -ENOTSUP:
15444                 printf("function not implemented\n");
15445                 break;
15446         default:
15447                 printf("programming error: (%s)\n", strerror(-ret));
15448         }
15449 }
15450
15451 cmdline_parse_inst_t cmd_clear_vf_stats = {
15452         .f = cmd_clear_vf_stats_parsed,
15453         .data = NULL,
15454         .help_str = "clear vf stats <port_id> <vf_id>",
15455         .tokens = {
15456                 (void *)&cmd_clear_vf_stats_clear,
15457                 (void *)&cmd_clear_vf_stats_vf,
15458                 (void *)&cmd_clear_vf_stats_stats,
15459                 (void *)&cmd_clear_vf_stats_port_id,
15460                 (void *)&cmd_clear_vf_stats_vf_id,
15461                 NULL,
15462         },
15463 };
15464
15465 /* port config pctype mapping reset */
15466
15467 /* Common result structure for port config pctype mapping reset */
15468 struct cmd_pctype_mapping_reset_result {
15469         cmdline_fixed_string_t port;
15470         cmdline_fixed_string_t config;
15471         portid_t port_id;
15472         cmdline_fixed_string_t pctype;
15473         cmdline_fixed_string_t mapping;
15474         cmdline_fixed_string_t reset;
15475 };
15476
15477 /* Common CLI fields for port config pctype mapping reset*/
15478 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15479         TOKEN_STRING_INITIALIZER
15480                 (struct cmd_pctype_mapping_reset_result,
15481                  port, "port");
15482 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15483         TOKEN_STRING_INITIALIZER
15484                 (struct cmd_pctype_mapping_reset_result,
15485                  config, "config");
15486 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15487         TOKEN_NUM_INITIALIZER
15488                 (struct cmd_pctype_mapping_reset_result,
15489                  port_id, UINT16);
15490 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15491         TOKEN_STRING_INITIALIZER
15492                 (struct cmd_pctype_mapping_reset_result,
15493                  pctype, "pctype");
15494 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15495         TOKEN_STRING_INITIALIZER
15496                 (struct cmd_pctype_mapping_reset_result,
15497                  mapping, "mapping");
15498 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15499         TOKEN_STRING_INITIALIZER
15500                 (struct cmd_pctype_mapping_reset_result,
15501                  reset, "reset");
15502
15503 static void
15504 cmd_pctype_mapping_reset_parsed(
15505         void *parsed_result,
15506         __attribute__((unused)) struct cmdline *cl,
15507         __attribute__((unused)) void *data)
15508 {
15509         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15510         int ret = -ENOTSUP;
15511
15512         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15513                 return;
15514
15515 #ifdef RTE_LIBRTE_I40E_PMD
15516         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15517 #endif
15518
15519         switch (ret) {
15520         case 0:
15521                 break;
15522         case -ENODEV:
15523                 printf("invalid port_id %d\n", res->port_id);
15524                 break;
15525         case -ENOTSUP:
15526                 printf("function not implemented\n");
15527                 break;
15528         default:
15529                 printf("programming error: (%s)\n", strerror(-ret));
15530         }
15531 }
15532
15533 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15534         .f = cmd_pctype_mapping_reset_parsed,
15535         .data = NULL,
15536         .help_str = "port config <port_id> pctype mapping reset",
15537         .tokens = {
15538                 (void *)&cmd_pctype_mapping_reset_port,
15539                 (void *)&cmd_pctype_mapping_reset_config,
15540                 (void *)&cmd_pctype_mapping_reset_port_id,
15541                 (void *)&cmd_pctype_mapping_reset_pctype,
15542                 (void *)&cmd_pctype_mapping_reset_mapping,
15543                 (void *)&cmd_pctype_mapping_reset_reset,
15544                 NULL,
15545         },
15546 };
15547
15548 /* show port pctype mapping */
15549
15550 /* Common result structure for show port pctype mapping */
15551 struct cmd_pctype_mapping_get_result {
15552         cmdline_fixed_string_t show;
15553         cmdline_fixed_string_t port;
15554         portid_t port_id;
15555         cmdline_fixed_string_t pctype;
15556         cmdline_fixed_string_t mapping;
15557 };
15558
15559 /* Common CLI fields for pctype mapping get */
15560 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15561         TOKEN_STRING_INITIALIZER
15562                 (struct cmd_pctype_mapping_get_result,
15563                  show, "show");
15564 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15565         TOKEN_STRING_INITIALIZER
15566                 (struct cmd_pctype_mapping_get_result,
15567                  port, "port");
15568 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15569         TOKEN_NUM_INITIALIZER
15570                 (struct cmd_pctype_mapping_get_result,
15571                  port_id, UINT16);
15572 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15573         TOKEN_STRING_INITIALIZER
15574                 (struct cmd_pctype_mapping_get_result,
15575                  pctype, "pctype");
15576 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15577         TOKEN_STRING_INITIALIZER
15578                 (struct cmd_pctype_mapping_get_result,
15579                  mapping, "mapping");
15580
15581 static void
15582 cmd_pctype_mapping_get_parsed(
15583         void *parsed_result,
15584         __attribute__((unused)) struct cmdline *cl,
15585         __attribute__((unused)) void *data)
15586 {
15587         struct cmd_pctype_mapping_get_result *res = parsed_result;
15588         int ret = -ENOTSUP;
15589 #ifdef RTE_LIBRTE_I40E_PMD
15590         struct rte_pmd_i40e_flow_type_mapping
15591                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15592         int i, j, first_pctype;
15593 #endif
15594
15595         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15596                 return;
15597
15598 #ifdef RTE_LIBRTE_I40E_PMD
15599         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15600 #endif
15601
15602         switch (ret) {
15603         case 0:
15604                 break;
15605         case -ENODEV:
15606                 printf("invalid port_id %d\n", res->port_id);
15607                 return;
15608         case -ENOTSUP:
15609                 printf("function not implemented\n");
15610                 return;
15611         default:
15612                 printf("programming error: (%s)\n", strerror(-ret));
15613                 return;
15614         }
15615
15616 #ifdef RTE_LIBRTE_I40E_PMD
15617         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15618                 if (mapping[i].pctype != 0ULL) {
15619                         first_pctype = 1;
15620
15621                         printf("pctype: ");
15622                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15623                                 if (mapping[i].pctype & (1ULL << j)) {
15624                                         printf(first_pctype ?
15625                                                "%02d" : ",%02d", j);
15626                                         first_pctype = 0;
15627                                 }
15628                         }
15629                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15630                 }
15631         }
15632 #endif
15633 }
15634
15635 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15636         .f = cmd_pctype_mapping_get_parsed,
15637         .data = NULL,
15638         .help_str = "show port <port_id> pctype mapping",
15639         .tokens = {
15640                 (void *)&cmd_pctype_mapping_get_show,
15641                 (void *)&cmd_pctype_mapping_get_port,
15642                 (void *)&cmd_pctype_mapping_get_port_id,
15643                 (void *)&cmd_pctype_mapping_get_pctype,
15644                 (void *)&cmd_pctype_mapping_get_mapping,
15645                 NULL,
15646         },
15647 };
15648
15649 /* port config pctype mapping update */
15650
15651 /* Common result structure for port config pctype mapping update */
15652 struct cmd_pctype_mapping_update_result {
15653         cmdline_fixed_string_t port;
15654         cmdline_fixed_string_t config;
15655         portid_t port_id;
15656         cmdline_fixed_string_t pctype;
15657         cmdline_fixed_string_t mapping;
15658         cmdline_fixed_string_t update;
15659         cmdline_fixed_string_t pctype_list;
15660         uint16_t flow_type;
15661 };
15662
15663 /* Common CLI fields for pctype mapping update*/
15664 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15665         TOKEN_STRING_INITIALIZER
15666                 (struct cmd_pctype_mapping_update_result,
15667                  port, "port");
15668 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15669         TOKEN_STRING_INITIALIZER
15670                 (struct cmd_pctype_mapping_update_result,
15671                  config, "config");
15672 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15673         TOKEN_NUM_INITIALIZER
15674                 (struct cmd_pctype_mapping_update_result,
15675                  port_id, UINT16);
15676 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15677         TOKEN_STRING_INITIALIZER
15678                 (struct cmd_pctype_mapping_update_result,
15679                  pctype, "pctype");
15680 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15681         TOKEN_STRING_INITIALIZER
15682                 (struct cmd_pctype_mapping_update_result,
15683                  mapping, "mapping");
15684 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15685         TOKEN_STRING_INITIALIZER
15686                 (struct cmd_pctype_mapping_update_result,
15687                  update, "update");
15688 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15689         TOKEN_STRING_INITIALIZER
15690                 (struct cmd_pctype_mapping_update_result,
15691                  pctype_list, NULL);
15692 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15693         TOKEN_NUM_INITIALIZER
15694                 (struct cmd_pctype_mapping_update_result,
15695                  flow_type, UINT16);
15696
15697 static void
15698 cmd_pctype_mapping_update_parsed(
15699         void *parsed_result,
15700         __attribute__((unused)) struct cmdline *cl,
15701         __attribute__((unused)) void *data)
15702 {
15703         struct cmd_pctype_mapping_update_result *res = parsed_result;
15704         int ret = -ENOTSUP;
15705 #ifdef RTE_LIBRTE_I40E_PMD
15706         struct rte_pmd_i40e_flow_type_mapping mapping;
15707         unsigned int i;
15708         unsigned int nb_item;
15709         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15710 #endif
15711
15712         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15713                 return;
15714
15715 #ifdef RTE_LIBRTE_I40E_PMD
15716         nb_item = parse_item_list(res->pctype_list, "pctypes",
15717                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15718         mapping.flow_type = res->flow_type;
15719         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15720                 mapping.pctype |= (1ULL << pctype_list[i]);
15721         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15722                                                 &mapping,
15723                                                 1,
15724                                                 0);
15725 #endif
15726
15727         switch (ret) {
15728         case 0:
15729                 break;
15730         case -EINVAL:
15731                 printf("invalid pctype or flow type\n");
15732                 break;
15733         case -ENODEV:
15734                 printf("invalid port_id %d\n", res->port_id);
15735                 break;
15736         case -ENOTSUP:
15737                 printf("function not implemented\n");
15738                 break;
15739         default:
15740                 printf("programming error: (%s)\n", strerror(-ret));
15741         }
15742 }
15743
15744 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15745         .f = cmd_pctype_mapping_update_parsed,
15746         .data = NULL,
15747         .help_str = "port config <port_id> pctype mapping update"
15748         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15749         .tokens = {
15750                 (void *)&cmd_pctype_mapping_update_port,
15751                 (void *)&cmd_pctype_mapping_update_config,
15752                 (void *)&cmd_pctype_mapping_update_port_id,
15753                 (void *)&cmd_pctype_mapping_update_pctype,
15754                 (void *)&cmd_pctype_mapping_update_mapping,
15755                 (void *)&cmd_pctype_mapping_update_update,
15756                 (void *)&cmd_pctype_mapping_update_pc_type,
15757                 (void *)&cmd_pctype_mapping_update_flow_type,
15758                 NULL,
15759         },
15760 };
15761
15762 /* ptype mapping get */
15763
15764 /* Common result structure for ptype mapping get */
15765 struct cmd_ptype_mapping_get_result {
15766         cmdline_fixed_string_t ptype;
15767         cmdline_fixed_string_t mapping;
15768         cmdline_fixed_string_t get;
15769         portid_t port_id;
15770         uint8_t valid_only;
15771 };
15772
15773 /* Common CLI fields for ptype mapping get */
15774 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15775         TOKEN_STRING_INITIALIZER
15776                 (struct cmd_ptype_mapping_get_result,
15777                  ptype, "ptype");
15778 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15779         TOKEN_STRING_INITIALIZER
15780                 (struct cmd_ptype_mapping_get_result,
15781                  mapping, "mapping");
15782 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15783         TOKEN_STRING_INITIALIZER
15784                 (struct cmd_ptype_mapping_get_result,
15785                  get, "get");
15786 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15787         TOKEN_NUM_INITIALIZER
15788                 (struct cmd_ptype_mapping_get_result,
15789                  port_id, UINT16);
15790 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15791         TOKEN_NUM_INITIALIZER
15792                 (struct cmd_ptype_mapping_get_result,
15793                  valid_only, UINT8);
15794
15795 static void
15796 cmd_ptype_mapping_get_parsed(
15797         void *parsed_result,
15798         __attribute__((unused)) struct cmdline *cl,
15799         __attribute__((unused)) void *data)
15800 {
15801         struct cmd_ptype_mapping_get_result *res = parsed_result;
15802         int ret = -ENOTSUP;
15803 #ifdef RTE_LIBRTE_I40E_PMD
15804         int max_ptype_num = 256;
15805         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15806         uint16_t count;
15807         int i;
15808 #endif
15809
15810         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15811                 return;
15812
15813 #ifdef RTE_LIBRTE_I40E_PMD
15814         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15815                                         mapping,
15816                                         max_ptype_num,
15817                                         &count,
15818                                         res->valid_only);
15819 #endif
15820
15821         switch (ret) {
15822         case 0:
15823                 break;
15824         case -ENODEV:
15825                 printf("invalid port_id %d\n", res->port_id);
15826                 break;
15827         case -ENOTSUP:
15828                 printf("function not implemented\n");
15829                 break;
15830         default:
15831                 printf("programming error: (%s)\n", strerror(-ret));
15832         }
15833
15834 #ifdef RTE_LIBRTE_I40E_PMD
15835         if (!ret) {
15836                 for (i = 0; i < count; i++)
15837                         printf("%3d\t0x%08x\n",
15838                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15839         }
15840 #endif
15841 }
15842
15843 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15844         .f = cmd_ptype_mapping_get_parsed,
15845         .data = NULL,
15846         .help_str = "ptype mapping get <port_id> <valid_only>",
15847         .tokens = {
15848                 (void *)&cmd_ptype_mapping_get_ptype,
15849                 (void *)&cmd_ptype_mapping_get_mapping,
15850                 (void *)&cmd_ptype_mapping_get_get,
15851                 (void *)&cmd_ptype_mapping_get_port_id,
15852                 (void *)&cmd_ptype_mapping_get_valid_only,
15853                 NULL,
15854         },
15855 };
15856
15857 /* ptype mapping replace */
15858
15859 /* Common result structure for ptype mapping replace */
15860 struct cmd_ptype_mapping_replace_result {
15861         cmdline_fixed_string_t ptype;
15862         cmdline_fixed_string_t mapping;
15863         cmdline_fixed_string_t replace;
15864         portid_t port_id;
15865         uint32_t target;
15866         uint8_t mask;
15867         uint32_t pkt_type;
15868 };
15869
15870 /* Common CLI fields for ptype mapping replace */
15871 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15872         TOKEN_STRING_INITIALIZER
15873                 (struct cmd_ptype_mapping_replace_result,
15874                  ptype, "ptype");
15875 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15876         TOKEN_STRING_INITIALIZER
15877                 (struct cmd_ptype_mapping_replace_result,
15878                  mapping, "mapping");
15879 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15880         TOKEN_STRING_INITIALIZER
15881                 (struct cmd_ptype_mapping_replace_result,
15882                  replace, "replace");
15883 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15884         TOKEN_NUM_INITIALIZER
15885                 (struct cmd_ptype_mapping_replace_result,
15886                  port_id, UINT16);
15887 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15888         TOKEN_NUM_INITIALIZER
15889                 (struct cmd_ptype_mapping_replace_result,
15890                  target, UINT32);
15891 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15892         TOKEN_NUM_INITIALIZER
15893                 (struct cmd_ptype_mapping_replace_result,
15894                  mask, UINT8);
15895 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15896         TOKEN_NUM_INITIALIZER
15897                 (struct cmd_ptype_mapping_replace_result,
15898                  pkt_type, UINT32);
15899
15900 static void
15901 cmd_ptype_mapping_replace_parsed(
15902         void *parsed_result,
15903         __attribute__((unused)) struct cmdline *cl,
15904         __attribute__((unused)) void *data)
15905 {
15906         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15907         int ret = -ENOTSUP;
15908
15909         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15910                 return;
15911
15912 #ifdef RTE_LIBRTE_I40E_PMD
15913         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15914                                         res->target,
15915                                         res->mask,
15916                                         res->pkt_type);
15917 #endif
15918
15919         switch (ret) {
15920         case 0:
15921                 break;
15922         case -EINVAL:
15923                 printf("invalid ptype 0x%8x or 0x%8x\n",
15924                                 res->target, res->pkt_type);
15925                 break;
15926         case -ENODEV:
15927                 printf("invalid port_id %d\n", res->port_id);
15928                 break;
15929         case -ENOTSUP:
15930                 printf("function not implemented\n");
15931                 break;
15932         default:
15933                 printf("programming error: (%s)\n", strerror(-ret));
15934         }
15935 }
15936
15937 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15938         .f = cmd_ptype_mapping_replace_parsed,
15939         .data = NULL,
15940         .help_str =
15941                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15942         .tokens = {
15943                 (void *)&cmd_ptype_mapping_replace_ptype,
15944                 (void *)&cmd_ptype_mapping_replace_mapping,
15945                 (void *)&cmd_ptype_mapping_replace_replace,
15946                 (void *)&cmd_ptype_mapping_replace_port_id,
15947                 (void *)&cmd_ptype_mapping_replace_target,
15948                 (void *)&cmd_ptype_mapping_replace_mask,
15949                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15950                 NULL,
15951         },
15952 };
15953
15954 /* ptype mapping reset */
15955
15956 /* Common result structure for ptype mapping reset */
15957 struct cmd_ptype_mapping_reset_result {
15958         cmdline_fixed_string_t ptype;
15959         cmdline_fixed_string_t mapping;
15960         cmdline_fixed_string_t reset;
15961         portid_t port_id;
15962 };
15963
15964 /* Common CLI fields for ptype mapping reset*/
15965 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15966         TOKEN_STRING_INITIALIZER
15967                 (struct cmd_ptype_mapping_reset_result,
15968                  ptype, "ptype");
15969 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15970         TOKEN_STRING_INITIALIZER
15971                 (struct cmd_ptype_mapping_reset_result,
15972                  mapping, "mapping");
15973 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15974         TOKEN_STRING_INITIALIZER
15975                 (struct cmd_ptype_mapping_reset_result,
15976                  reset, "reset");
15977 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15978         TOKEN_NUM_INITIALIZER
15979                 (struct cmd_ptype_mapping_reset_result,
15980                  port_id, UINT16);
15981
15982 static void
15983 cmd_ptype_mapping_reset_parsed(
15984         void *parsed_result,
15985         __attribute__((unused)) struct cmdline *cl,
15986         __attribute__((unused)) void *data)
15987 {
15988         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15989         int ret = -ENOTSUP;
15990
15991         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15992                 return;
15993
15994 #ifdef RTE_LIBRTE_I40E_PMD
15995         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15996 #endif
15997
15998         switch (ret) {
15999         case 0:
16000                 break;
16001         case -ENODEV:
16002                 printf("invalid port_id %d\n", res->port_id);
16003                 break;
16004         case -ENOTSUP:
16005                 printf("function not implemented\n");
16006                 break;
16007         default:
16008                 printf("programming error: (%s)\n", strerror(-ret));
16009         }
16010 }
16011
16012 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16013         .f = cmd_ptype_mapping_reset_parsed,
16014         .data = NULL,
16015         .help_str = "ptype mapping reset <port_id>",
16016         .tokens = {
16017                 (void *)&cmd_ptype_mapping_reset_ptype,
16018                 (void *)&cmd_ptype_mapping_reset_mapping,
16019                 (void *)&cmd_ptype_mapping_reset_reset,
16020                 (void *)&cmd_ptype_mapping_reset_port_id,
16021                 NULL,
16022         },
16023 };
16024
16025 /* ptype mapping update */
16026
16027 /* Common result structure for ptype mapping update */
16028 struct cmd_ptype_mapping_update_result {
16029         cmdline_fixed_string_t ptype;
16030         cmdline_fixed_string_t mapping;
16031         cmdline_fixed_string_t reset;
16032         portid_t port_id;
16033         uint8_t hw_ptype;
16034         uint32_t sw_ptype;
16035 };
16036
16037 /* Common CLI fields for ptype mapping update*/
16038 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16039         TOKEN_STRING_INITIALIZER
16040                 (struct cmd_ptype_mapping_update_result,
16041                  ptype, "ptype");
16042 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16043         TOKEN_STRING_INITIALIZER
16044                 (struct cmd_ptype_mapping_update_result,
16045                  mapping, "mapping");
16046 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16047         TOKEN_STRING_INITIALIZER
16048                 (struct cmd_ptype_mapping_update_result,
16049                  reset, "update");
16050 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16051         TOKEN_NUM_INITIALIZER
16052                 (struct cmd_ptype_mapping_update_result,
16053                  port_id, UINT16);
16054 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16055         TOKEN_NUM_INITIALIZER
16056                 (struct cmd_ptype_mapping_update_result,
16057                  hw_ptype, UINT8);
16058 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16059         TOKEN_NUM_INITIALIZER
16060                 (struct cmd_ptype_mapping_update_result,
16061                  sw_ptype, UINT32);
16062
16063 static void
16064 cmd_ptype_mapping_update_parsed(
16065         void *parsed_result,
16066         __attribute__((unused)) struct cmdline *cl,
16067         __attribute__((unused)) void *data)
16068 {
16069         struct cmd_ptype_mapping_update_result *res = parsed_result;
16070         int ret = -ENOTSUP;
16071 #ifdef RTE_LIBRTE_I40E_PMD
16072         struct rte_pmd_i40e_ptype_mapping mapping;
16073 #endif
16074         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16075                 return;
16076
16077 #ifdef RTE_LIBRTE_I40E_PMD
16078         mapping.hw_ptype = res->hw_ptype;
16079         mapping.sw_ptype = res->sw_ptype;
16080         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16081                                                 &mapping,
16082                                                 1,
16083                                                 0);
16084 #endif
16085
16086         switch (ret) {
16087         case 0:
16088                 break;
16089         case -EINVAL:
16090                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16091                 break;
16092         case -ENODEV:
16093                 printf("invalid port_id %d\n", res->port_id);
16094                 break;
16095         case -ENOTSUP:
16096                 printf("function not implemented\n");
16097                 break;
16098         default:
16099                 printf("programming error: (%s)\n", strerror(-ret));
16100         }
16101 }
16102
16103 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16104         .f = cmd_ptype_mapping_update_parsed,
16105         .data = NULL,
16106         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16107         .tokens = {
16108                 (void *)&cmd_ptype_mapping_update_ptype,
16109                 (void *)&cmd_ptype_mapping_update_mapping,
16110                 (void *)&cmd_ptype_mapping_update_update,
16111                 (void *)&cmd_ptype_mapping_update_port_id,
16112                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16113                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16114                 NULL,
16115         },
16116 };
16117
16118 /* Common result structure for file commands */
16119 struct cmd_cmdfile_result {
16120         cmdline_fixed_string_t load;
16121         cmdline_fixed_string_t filename;
16122 };
16123
16124 /* Common CLI fields for file commands */
16125 cmdline_parse_token_string_t cmd_load_cmdfile =
16126         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16127 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16128         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16129
16130 static void
16131 cmd_load_from_file_parsed(
16132         void *parsed_result,
16133         __attribute__((unused)) struct cmdline *cl,
16134         __attribute__((unused)) void *data)
16135 {
16136         struct cmd_cmdfile_result *res = parsed_result;
16137
16138         cmdline_read_from_file(res->filename);
16139 }
16140
16141 cmdline_parse_inst_t cmd_load_from_file = {
16142         .f = cmd_load_from_file_parsed,
16143         .data = NULL,
16144         .help_str = "load <filename>",
16145         .tokens = {
16146                 (void *)&cmd_load_cmdfile,
16147                 (void *)&cmd_load_cmdfile_filename,
16148                 NULL,
16149         },
16150 };
16151
16152 /* ******************************************************************************** */
16153
16154 /* list of instructions */
16155 cmdline_parse_ctx_t main_ctx[] = {
16156         (cmdline_parse_inst_t *)&cmd_help_brief,
16157         (cmdline_parse_inst_t *)&cmd_help_long,
16158         (cmdline_parse_inst_t *)&cmd_quit,
16159         (cmdline_parse_inst_t *)&cmd_load_from_file,
16160         (cmdline_parse_inst_t *)&cmd_showport,
16161         (cmdline_parse_inst_t *)&cmd_showqueue,
16162         (cmdline_parse_inst_t *)&cmd_showportall,
16163         (cmdline_parse_inst_t *)&cmd_showcfg,
16164         (cmdline_parse_inst_t *)&cmd_start,
16165         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16166         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16167         (cmdline_parse_inst_t *)&cmd_set_link_up,
16168         (cmdline_parse_inst_t *)&cmd_set_link_down,
16169         (cmdline_parse_inst_t *)&cmd_reset,
16170         (cmdline_parse_inst_t *)&cmd_set_numbers,
16171         (cmdline_parse_inst_t *)&cmd_set_log,
16172         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16173         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16174         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16175         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16176         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16177         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16178         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16179         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16180         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16181         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16182         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16183         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16184         (cmdline_parse_inst_t *)&cmd_set_link_check,
16185         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16186         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16187         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16188         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16189 #ifdef RTE_LIBRTE_PMD_BOND
16190         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16191         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16192         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16193         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16194         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16195         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16196         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16197         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16198         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16199         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16200         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16201 #endif
16202         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16203         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16204         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16205         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16206         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16207         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16208         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16209         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16210         (cmdline_parse_inst_t *)&cmd_csum_set,
16211         (cmdline_parse_inst_t *)&cmd_csum_show,
16212         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16213         (cmdline_parse_inst_t *)&cmd_tso_set,
16214         (cmdline_parse_inst_t *)&cmd_tso_show,
16215         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16216         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16217         (cmdline_parse_inst_t *)&cmd_gro_enable,
16218         (cmdline_parse_inst_t *)&cmd_gro_flush,
16219         (cmdline_parse_inst_t *)&cmd_gro_show,
16220         (cmdline_parse_inst_t *)&cmd_gso_enable,
16221         (cmdline_parse_inst_t *)&cmd_gso_size,
16222         (cmdline_parse_inst_t *)&cmd_gso_show,
16223         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16224         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16225         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16226         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16227         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16228         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16229         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16230         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16231         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16232         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16233         (cmdline_parse_inst_t *)&cmd_config_dcb,
16234         (cmdline_parse_inst_t *)&cmd_read_reg,
16235         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16236         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16237         (cmdline_parse_inst_t *)&cmd_write_reg,
16238         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16239         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16240         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16241         (cmdline_parse_inst_t *)&cmd_stop,
16242         (cmdline_parse_inst_t *)&cmd_mac_addr,
16243         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16244         (cmdline_parse_inst_t *)&cmd_set_qmap,
16245         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16246         (cmdline_parse_inst_t *)&cmd_operate_port,
16247         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16248         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16249         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16250         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16251         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16252         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16253         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16254         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16255         (cmdline_parse_inst_t *)&cmd_config_mtu,
16256         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16257         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16258         (cmdline_parse_inst_t *)&cmd_config_rss,
16259         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16260         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16261         (cmdline_parse_inst_t *)&cmd_showport_reta,
16262         (cmdline_parse_inst_t *)&cmd_config_burst,
16263         (cmdline_parse_inst_t *)&cmd_config_thresh,
16264         (cmdline_parse_inst_t *)&cmd_config_threshold,
16265         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16266         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16267         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16268         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16269         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16270         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16271         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16272         (cmdline_parse_inst_t *)&cmd_global_config,
16273         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16274         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16275         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16276         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16277         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16278         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16279         (cmdline_parse_inst_t *)&cmd_dump,
16280         (cmdline_parse_inst_t *)&cmd_dump_one,
16281         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16282         (cmdline_parse_inst_t *)&cmd_syn_filter,
16283         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16284         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16285         (cmdline_parse_inst_t *)&cmd_flex_filter,
16286         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16287         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16288         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16289         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16290         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16291         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16292         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16293         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16294         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16295         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16296         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16297         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16298         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16299         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16300         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16301         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16302         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16303         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16304         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16305         (cmdline_parse_inst_t *)&cmd_flow,
16306         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16307         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16308         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16309         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16310         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16311         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16312         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16313         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16314         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16315         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16316         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16317         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16318         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16319         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16320         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16321         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16322         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16323         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16324         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16325         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16326         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16327         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16328         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16329         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16330         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16331         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16332         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16333         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16334         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16335         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16336         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16337         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16338         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16339         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16340         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16341         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16342         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16343         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16344         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16345         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16346         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16347         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16348         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16349         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16350         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16351         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16352         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16353         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16354         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16355 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16356         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16357 #endif
16358         (cmdline_parse_inst_t *)&cmd_ddp_add,
16359         (cmdline_parse_inst_t *)&cmd_ddp_del,
16360         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16361         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16362         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16363         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16364         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16365         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16366         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16367         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16368         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16369         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16370
16371         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16372         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16373         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16374         (cmdline_parse_inst_t *)&cmd_queue_region,
16375         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16376         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16377         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16378         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16379         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16380         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16381         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16382         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16383         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16384         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16385         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16386         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16387         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16388         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16389         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16390         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16391         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16392         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16393         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16394         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16395         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16396         NULL,
16397 };
16398
16399 /* read cmdline commands from file */
16400 void
16401 cmdline_read_from_file(const char *filename)
16402 {
16403         struct cmdline *cl;
16404
16405         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16406         if (cl == NULL) {
16407                 printf("Failed to create file based cmdline context: %s\n",
16408                        filename);
16409                 return;
16410         }
16411
16412         cmdline_interact(cl);
16413         cmdline_quit(cl);
16414
16415         cmdline_free(cl);
16416
16417         printf("Read CLI commands from %s\n", filename);
16418 }
16419
16420 /* prompt function, called from main on MASTER lcore */
16421 void
16422 prompt(void)
16423 {
16424         /* initialize non-constant commands */
16425         cmd_set_fwd_mode_init();
16426         cmd_set_fwd_retry_mode_init();
16427
16428         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16429         if (testpmd_cl == NULL)
16430                 return;
16431         cmdline_interact(testpmd_cl);
16432         cmdline_stdin_exit(testpmd_cl);
16433 }
16434
16435 void
16436 prompt_exit(void)
16437 {
16438         if (testpmd_cl != NULL)
16439                 cmdline_quit(testpmd_cl);
16440 }
16441
16442 static void
16443 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16444 {
16445         if (id == (portid_t)RTE_PORT_ALL) {
16446                 portid_t pid;
16447
16448                 RTE_ETH_FOREACH_DEV(pid) {
16449                         /* check if need_reconfig has been set to 1 */
16450                         if (ports[pid].need_reconfig == 0)
16451                                 ports[pid].need_reconfig = dev;
16452                         /* check if need_reconfig_queues has been set to 1 */
16453                         if (ports[pid].need_reconfig_queues == 0)
16454                                 ports[pid].need_reconfig_queues = queue;
16455                 }
16456         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16457                 /* check if need_reconfig has been set to 1 */
16458                 if (ports[id].need_reconfig == 0)
16459                         ports[id].need_reconfig = dev;
16460                 /* check if need_reconfig_queues has been set to 1 */
16461                 if (ports[id].need_reconfig_queues == 0)
16462                         ports[id].need_reconfig_queues = queue;
16463         }
16464 }