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