app/testpmd: add option to configure UDP tunnel port
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22
23 #include <sys/queue.h>
24
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_eth_ctrl.h>
48 #include <rte_flow.h>
49 #include <rte_gro.h>
50
51 #include <cmdline_rdline.h>
52 #include <cmdline_parse.h>
53 #include <cmdline_parse_num.h>
54 #include <cmdline_parse_string.h>
55 #include <cmdline_parse_ipaddr.h>
56 #include <cmdline_parse_etheraddr.h>
57 #include <cmdline_socket.h>
58 #include <cmdline.h>
59 #ifdef RTE_LIBRTE_PMD_BOND
60 #include <rte_eth_bond.h>
61 #include <rte_eth_bond_8023ad.h>
62 #endif
63 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
64 #include <rte_pmd_dpaa.h>
65 #endif
66 #ifdef RTE_LIBRTE_IXGBE_PMD
67 #include <rte_pmd_ixgbe.h>
68 #endif
69 #ifdef RTE_LIBRTE_I40E_PMD
70 #include <rte_pmd_i40e.h>
71 #endif
72 #ifdef RTE_LIBRTE_BNXT_PMD
73 #include <rte_pmd_bnxt.h>
74 #endif
75 #include "testpmd.h"
76 #include "cmdline_mtr.h"
77 #include "cmdline_tm.h"
78
79 static struct cmdline *testpmd_cl;
80
81 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
82
83 /* *** Help command with introduction. *** */
84 struct cmd_help_brief_result {
85         cmdline_fixed_string_t help;
86 };
87
88 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
89                                   struct cmdline *cl,
90                                   __attribute__((unused)) void *data)
91 {
92         cmdline_printf(
93                 cl,
94                 "\n"
95                 "Help is available for the following sections:\n\n"
96                 "    help control    : Start and stop forwarding.\n"
97                 "    help display    : Displaying port, stats and config "
98                 "information.\n"
99                 "    help config     : Configuration information.\n"
100                 "    help ports      : Configuring ports.\n"
101                 "    help registers  : Reading and setting port registers.\n"
102                 "    help filters    : Filters configuration help.\n"
103                 "    help all        : All of the above sections.\n\n"
104         );
105
106 }
107
108 cmdline_parse_token_string_t cmd_help_brief_help =
109         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
110
111 cmdline_parse_inst_t cmd_help_brief = {
112         .f = cmd_help_brief_parsed,
113         .data = NULL,
114         .help_str = "help: Show help",
115         .tokens = {
116                 (void *)&cmd_help_brief_help,
117                 NULL,
118         },
119 };
120
121 /* *** Help command with help sections. *** */
122 struct cmd_help_long_result {
123         cmdline_fixed_string_t help;
124         cmdline_fixed_string_t section;
125 };
126
127 static void cmd_help_long_parsed(void *parsed_result,
128                                  struct cmdline *cl,
129                                  __attribute__((unused)) void *data)
130 {
131         int show_all = 0;
132         struct cmd_help_long_result *res = parsed_result;
133
134         if (!strcmp(res->section, "all"))
135                 show_all = 1;
136
137         if (show_all || !strcmp(res->section, "control")) {
138
139                 cmdline_printf(
140                         cl,
141                         "\n"
142                         "Control forwarding:\n"
143                         "-------------------\n\n"
144
145                         "start\n"
146                         "    Start packet forwarding with current configuration.\n\n"
147
148                         "start tx_first\n"
149                         "    Start packet forwarding with current config"
150                         " after sending one burst of packets.\n\n"
151
152                         "stop\n"
153                         "    Stop packet forwarding, and display accumulated"
154                         " statistics.\n\n"
155
156                         "quit\n"
157                         "    Quit to prompt.\n\n"
158                 );
159         }
160
161         if (show_all || !strcmp(res->section, "display")) {
162
163                 cmdline_printf(
164                         cl,
165                         "\n"
166                         "Display:\n"
167                         "--------\n\n"
168
169                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
170                         "    Display information for port_id, or all.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
178                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
179                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
180                         "    Display the RSS hash functions and RSS hash key"
181                         " of port X\n\n"
182
183                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
184                         "    Clear information for port_id, or all.\n\n"
185
186                         "show (rxq|txq) info (port_id) (queue_id)\n"
187                         "    Display information for configured RX/TX queue.\n\n"
188
189                         "show config (rxtx|cores|fwd|txpkts)\n"
190                         "    Display the given configuration.\n\n"
191
192                         "read rxd (port_id) (queue_id) (rxd_id)\n"
193                         "    Display an RX descriptor of a port RX queue.\n\n"
194
195                         "read txd (port_id) (queue_id) (txd_id)\n"
196                         "    Display a TX descriptor of a port TX queue.\n\n"
197
198                         "ddp get list (port_id)\n"
199                         "    Get ddp profile info list\n\n"
200
201                         "ddp get info (profile_path)\n"
202                         "    Get ddp profile information.\n\n"
203
204                         "show vf stats (port_id) (vf_id)\n"
205                         "    Display a VF's statistics.\n\n"
206
207                         "clear vf stats (port_id) (vf_id)\n"
208                         "    Reset a VF's statistics.\n\n"
209
210                         "show port (port_id) pctype mapping\n"
211                         "    Get flow ptype to pctype mapping on a port\n\n"
212
213                         "show port meter stats (port_id) (meter_id) (clear)\n"
214                         "    Get meter stats on a port\n\n"
215                         "show port tm cap (port_id)\n"
216                         "       Display the port TM capability.\n\n"
217
218                         "show port tm level cap (port_id) (level_id)\n"
219                         "       Display the port TM hierarchical level capability.\n\n"
220
221                         "show port tm node cap (port_id) (node_id)\n"
222                         "       Display the port TM node capability.\n\n"
223
224                         "show port tm node type (port_id) (node_id)\n"
225                         "       Display the port TM node type.\n\n"
226
227                         "show port tm node stats (port_id) (node_id) (clear)\n"
228                         "       Display the port TM node stats.\n\n"
229
230                 );
231         }
232
233         if (show_all || !strcmp(res->section, "config")) {
234                 cmdline_printf(
235                         cl,
236                         "\n"
237                         "Configuration:\n"
238                         "--------------\n"
239                         "Configuration changes only become active when"
240                         " forwarding is started/restarted.\n\n"
241
242                         "set default\n"
243                         "    Reset forwarding to the default configuration.\n\n"
244
245                         "set verbose (level)\n"
246                         "    Set the debug verbosity level X.\n\n"
247
248                         "set log global|(type) (level)\n"
249                         "    Set the log level.\n\n"
250
251                         "set nbport (num)\n"
252                         "    Set number of ports.\n\n"
253
254                         "set nbcore (num)\n"
255                         "    Set number of cores.\n\n"
256
257                         "set coremask (mask)\n"
258                         "    Set the forwarding cores hexadecimal mask.\n\n"
259
260                         "set portmask (mask)\n"
261                         "    Set the forwarding ports hexadecimal mask.\n\n"
262
263                         "set burst (num)\n"
264                         "    Set number of packets per burst.\n\n"
265
266                         "set burst tx delay (microseconds) retry (num)\n"
267                         "    Set the transmit delay time and number of retries,"
268                         " effective when retry is enabled.\n\n"
269
270                         "set txpkts (x[,y]*)\n"
271                         "    Set the length of each segment of TXONLY"
272                         " and optionally CSUM packets.\n\n"
273
274                         "set txsplit (off|on|rand)\n"
275                         "    Set the split policy for the TX packets."
276                         " Right now only applicable for CSUM and TXONLY"
277                         " modes\n\n"
278
279                         "set corelist (x[,y]*)\n"
280                         "    Set the list of forwarding cores.\n\n"
281
282                         "set portlist (x[,y]*)\n"
283                         "    Set the list of forwarding ports.\n\n"
284
285                         "set tx loopback (port_id) (on|off)\n"
286                         "    Enable or disable tx loopback.\n\n"
287
288                         "set all queues drop (port_id) (on|off)\n"
289                         "    Set drop enable bit for all queues.\n\n"
290
291                         "set vf split drop (port_id) (vf_id) (on|off)\n"
292                         "    Set split drop enable bit for a VF from the PF.\n\n"
293
294                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
295                         "    Set MAC antispoof for a VF from the PF.\n\n"
296
297                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
298                         "    Enable MACsec offload.\n\n"
299
300                         "set macsec offload (port_id) off\n"
301                         "    Disable MACsec offload.\n\n"
302
303                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
304                         "    Configure MACsec secure connection (SC).\n\n"
305
306                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
307                         "    Configure MACsec secure association (SA).\n\n"
308
309                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
310                         "    Set VF broadcast for a VF from the PF.\n\n"
311
312                         "vlan set strip (on|off) (port_id)\n"
313                         "    Set the VLAN strip on a port.\n\n"
314
315                         "vlan set stripq (on|off) (port_id,queue_id)\n"
316                         "    Set the VLAN strip for a queue on a port.\n\n"
317
318                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
319                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
320
321                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
322                         "    Set VLAN insert for a VF from the PF.\n\n"
323
324                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
325                         "    Set VLAN antispoof for a VF from the PF.\n\n"
326
327                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
328                         "    Set VLAN tag for a VF from the PF.\n\n"
329
330                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
331                         "    Set a VF's max bandwidth(Mbps).\n\n"
332
333                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
334                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
335
336                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
337                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
338
339                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
340                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
341
342                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
343                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
344
345                         "vlan set filter (on|off) (port_id)\n"
346                         "    Set the VLAN filter on a port.\n\n"
347
348                         "vlan set qinq (on|off) (port_id)\n"
349                         "    Set the VLAN QinQ (extended queue in queue)"
350                         " on a port.\n\n"
351
352                         "vlan set (inner|outer) tpid (value) (port_id)\n"
353                         "    Set the VLAN TPID for Packet Filtering on"
354                         " a port\n\n"
355
356                         "rx_vlan add (vlan_id|all) (port_id)\n"
357                         "    Add a vlan_id, or all identifiers, to the set"
358                         " of VLAN identifiers filtered by port_id.\n\n"
359
360                         "rx_vlan rm (vlan_id|all) (port_id)\n"
361                         "    Remove a vlan_id, or all identifiers, from the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
365                         "    Add a vlan_id, to the set of VLAN identifiers"
366                         "filtered for VF(s) from port_id.\n\n"
367
368                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Remove a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
373                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
374                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
375                         "   add a tunnel filter of a port.\n\n"
376
377                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
378                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
379                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
380                         "   remove a tunnel filter of a port.\n\n"
381
382                         "rx_vxlan_port add (udp_port) (port_id)\n"
383                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
384
385                         "rx_vxlan_port rm (udp_port) (port_id)\n"
386                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
387
388                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
389                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
390                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
391
392                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
393                         "    Set port based TX VLAN insertion.\n\n"
394
395                         "tx_vlan reset (port_id)\n"
396                         "    Disable hardware insertion of a VLAN header in"
397                         " packets sent on a port.\n\n"
398
399                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
400                         "    Select hardware or software calculation of the"
401                         " checksum when transmitting a packet using the"
402                         " csum forward engine.\n"
403                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
404                         "    outer-ip concerns the outer IP layer in"
405                         " case the packet is recognized as a tunnel packet by"
406                         " the forward engine (vxlan, gre and ipip are supported)\n"
407                         "    Please check the NIC datasheet for HW limits.\n\n"
408
409                         "csum parse-tunnel (on|off) (tx_port_id)\n"
410                         "    If disabled, treat tunnel packets as non-tunneled"
411                         " packets (treat inner headers as payload). The port\n"
412                         "    argument is the port used for TX in csum forward"
413                         " engine.\n\n"
414
415                         "csum show (port_id)\n"
416                         "    Display tx checksum offload configuration\n\n"
417
418                         "tso set (segsize) (portid)\n"
419                         "    Enable TCP Segmentation Offload in csum forward"
420                         " engine.\n"
421                         "    Please check the NIC datasheet for HW limits.\n\n"
422
423                         "tso show (portid)"
424                         "    Display the status of TCP Segmentation Offload.\n\n"
425
426                         "set port (port_id) gro on|off\n"
427                         "    Enable or disable Generic Receive Offload in"
428                         " csum forwarding engine.\n\n"
429
430                         "show port (port_id) gro\n"
431                         "    Display GRO configuration.\n\n"
432
433                         "set gro flush (cycles)\n"
434                         "    Set the cycle to flush GROed packets from"
435                         " reassembly tables.\n\n"
436
437                         "set port (port_id) gso (on|off)"
438                         "    Enable or disable Generic Segmentation Offload in"
439                         " csum forwarding engine.\n\n"
440
441                         "set gso segsz (length)\n"
442                         "    Set max packet length for output GSO segments,"
443                         " including packet header and payload.\n\n"
444
445                         "show port (port_id) gso\n"
446                         "    Show GSO configuration.\n\n"
447
448                         "set fwd (%s)\n"
449                         "    Set packet forwarding mode.\n\n"
450
451                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
452                         "    Add a MAC address on port_id.\n\n"
453
454                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
455                         "    Remove a MAC address from port_id.\n\n"
456
457                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
458                         "    Set the default MAC address for port_id.\n\n"
459
460                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
461                         "    Add a MAC address for a VF on the port.\n\n"
462
463                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
464                         "    Set the MAC address for a VF from the PF.\n\n"
465
466                         "set eth-peer (port_id) (peer_addr)\n"
467                         "    set the peer address for certain port.\n\n"
468
469                         "set port (port_id) uta (mac_address|all) (on|off)\n"
470                         "    Add/Remove a or all unicast hash filter(s)"
471                         "from port X.\n\n"
472
473                         "set promisc (port_id|all) (on|off)\n"
474                         "    Set the promiscuous mode on port_id, or all.\n\n"
475
476                         "set allmulti (port_id|all) (on|off)\n"
477                         "    Set the allmulti mode on port_id, or all.\n\n"
478
479                         "set vf promisc (port_id) (vf_id) (on|off)\n"
480                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
481
482                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
483                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
484
485                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
486                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
487                         " (on|off) autoneg (on|off) (port_id)\n"
488                         "set flow_ctrl rx (on|off) (portid)\n"
489                         "set flow_ctrl tx (on|off) (portid)\n"
490                         "set flow_ctrl high_water (high_water) (portid)\n"
491                         "set flow_ctrl low_water (low_water) (portid)\n"
492                         "set flow_ctrl pause_time (pause_time) (portid)\n"
493                         "set flow_ctrl send_xon (send_xon) (portid)\n"
494                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
495                         "set flow_ctrl autoneg (on|off) (port_id)\n"
496                         "    Set the link flow control parameter on a port.\n\n"
497
498                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
499                         " (low_water) (pause_time) (priority) (port_id)\n"
500                         "    Set the priority flow control parameter on a"
501                         " port.\n\n"
502
503                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
504                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
505                         " queue on port.\n"
506                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
507                         " on port 0 to mapping 5.\n\n"
508
509                         "set xstats-hide-zero on|off\n"
510                         "    Set the option to hide the zero values"
511                         " for xstats display.\n"
512
513                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
514                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
515
516                         "set port (port_id) vf (vf_id) (mac_addr)"
517                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
518                         "   Add/Remove unicast or multicast MAC addr filter"
519                         " for a VF.\n\n"
520
521                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
522                         "|MPE) (on|off)\n"
523                         "    AUPE:accepts untagged VLAN;"
524                         "ROPE:accept unicast hash\n\n"
525                         "    BAM:accepts broadcast packets;"
526                         "MPE:accepts all multicast packets\n\n"
527                         "    Enable/Disable a VF receive mode of a port\n\n"
528
529                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
530                         "    Set rate limit for a queue of a port\n\n"
531
532                         "set port (port_id) vf (vf_id) rate (rate_num) "
533                         "queue_mask (queue_mask_value)\n"
534                         "    Set rate limit for queues in VF of a port\n\n"
535
536                         "set port (port_id) mirror-rule (rule_id)"
537                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
538                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
539                         "   Set pool or vlan type mirror rule on a port.\n"
540                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
541                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
542                         " to pool 0.\n\n"
543
544                         "set port (port_id) mirror-rule (rule_id)"
545                         " (uplink-mirror|downlink-mirror) dst-pool"
546                         " (pool_id) (on|off)\n"
547                         "   Set uplink or downlink type mirror rule on a port.\n"
548                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
549                         " 0 on' enable mirror income traffic to pool 0.\n\n"
550
551                         "reset port (port_id) mirror-rule (rule_id)\n"
552                         "   Reset a mirror rule.\n\n"
553
554                         "set flush_rx (on|off)\n"
555                         "   Flush (default) or don't flush RX streams before"
556                         " forwarding. Mainly used with PCAP drivers.\n\n"
557
558                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
559                         "   Set the bypass mode for the lowest port on bypass enabled"
560                         " NIC.\n\n"
561
562                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
563                         "mode (normal|bypass|isolate) (port_id)\n"
564                         "   Set the event required to initiate specified bypass mode for"
565                         " the lowest port on a bypass enabled NIC where:\n"
566                         "       timeout   = enable bypass after watchdog timeout.\n"
567                         "       os_on     = enable bypass when OS/board is powered on.\n"
568                         "       os_off    = enable bypass when OS/board is powered off.\n"
569                         "       power_on  = enable bypass when power supply is turned on.\n"
570                         "       power_off = enable bypass when power supply is turned off."
571                         "\n\n"
572
573                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
574                         "   Set the bypass watchdog timeout to 'n' seconds"
575                         " where 0 = instant.\n\n"
576
577                         "show bypass config (port_id)\n"
578                         "   Show the bypass configuration for a bypass enabled NIC"
579                         " using the lowest port on the NIC.\n\n"
580
581 #ifdef RTE_LIBRTE_PMD_BOND
582                         "create bonded device (mode) (socket)\n"
583                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
584
585                         "add bonding slave (slave_id) (port_id)\n"
586                         "       Add a slave device to a bonded device.\n\n"
587
588                         "remove bonding slave (slave_id) (port_id)\n"
589                         "       Remove a slave device from a bonded device.\n\n"
590
591                         "set bonding mode (value) (port_id)\n"
592                         "       Set the bonding mode on a bonded device.\n\n"
593
594                         "set bonding primary (slave_id) (port_id)\n"
595                         "       Set the primary slave for a bonded device.\n\n"
596
597                         "show bonding config (port_id)\n"
598                         "       Show the bonding config for port_id.\n\n"
599
600                         "set bonding mac_addr (port_id) (address)\n"
601                         "       Set the MAC address of a bonded device.\n\n"
602
603                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
604                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
605
606                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
607                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
608
609                         "set bonding mon_period (port_id) (value)\n"
610                         "       Set the bonding link status monitoring polling period in ms.\n\n"
611
612                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
613                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
614
615 #endif
616                         "set link-up port (port_id)\n"
617                         "       Set link up for a port.\n\n"
618
619                         "set link-down port (port_id)\n"
620                         "       Set link down for a port.\n\n"
621
622                         "E-tag set insertion on port-tag-id (value)"
623                         " port (port_id) vf (vf_id)\n"
624                         "    Enable E-tag insertion for a VF on a port\n\n"
625
626                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
627                         "    Disable E-tag insertion for a VF on a port\n\n"
628
629                         "E-tag set stripping (on|off) port (port_id)\n"
630                         "    Enable/disable E-tag stripping on a port\n\n"
631
632                         "E-tag set forwarding (on|off) port (port_id)\n"
633                         "    Enable/disable E-tag based forwarding"
634                         " on a port\n\n"
635
636                         "E-tag set filter add e-tag-id (value) dst-pool"
637                         " (pool_id) port (port_id)\n"
638                         "    Add an E-tag forwarding filter on a port\n\n"
639
640                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
641                         "    Delete an E-tag forwarding filter on a port\n\n"
642
643 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
644                         "set port tm hierarchy default (port_id)\n"
645                         "       Set default traffic Management hierarchy on a port\n\n"
646
647 #endif
648                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
649                         "    Load a profile package on a port\n\n"
650
651                         "ddp del (port_id) (backup_profile_path)\n"
652                         "    Delete a profile package from a port\n\n"
653
654                         "ptype mapping get (port_id) (valid_only)\n"
655                         "    Get ptype mapping on a port\n\n"
656
657                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
658                         "    Replace target with the pkt_type in ptype mapping\n\n"
659
660                         "ptype mapping reset (port_id)\n"
661                         "    Reset ptype mapping on a port\n\n"
662
663                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
664                         "    Update a ptype mapping item on a port\n\n"
665
666                         "set port (port_id) queue-region region_id (value) "
667                         "queue_start_index (value) queue_num (value)\n"
668                         "    Set a queue region on a port\n\n"
669
670                         "set port (port_id) queue-region region_id (value) "
671                         "flowtype (value)\n"
672                         "    Set a flowtype region index on a port\n\n"
673
674                         "set port (port_id) queue-region UP (value) region_id (value)\n"
675                         "    Set the mapping of User Priority to "
676                         "queue region on a port\n\n"
677
678                         "set port (port_id) queue-region flush (on|off)\n"
679                         "    flush all queue region related configuration\n\n"
680
681                         "show port meter cap (port_id)\n"
682                         "    Show port meter capability information\n\n"
683
684                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
685                         "    meter profile add - srtcm rfc 2697\n\n"
686
687                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
688                         "    meter profile add - trtcm rfc 2698\n\n"
689
690                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
691                         "    meter profile add - trtcm rfc 4115\n\n"
692
693                         "del port meter profile (port_id) (profile_id)\n"
694                         "    meter profile delete\n\n"
695
696                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
697                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
698                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
699                         "(dscp_tbl_entry63)]\n"
700                         "    meter create\n\n"
701
702                         "enable port meter (port_id) (mtr_id)\n"
703                         "    meter enable\n\n"
704
705                         "disable port meter (port_id) (mtr_id)\n"
706                         "    meter disable\n\n"
707
708                         "del port meter (port_id) (mtr_id)\n"
709                         "    meter delete\n\n"
710
711                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
712                         "    meter update meter profile\n\n"
713
714                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
715                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
716                         "    update meter dscp table entries\n\n"
717
718                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
719                         "(action0) [(action1) (action2)]\n"
720                         "    meter update policer action\n\n"
721
722                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
723                         "    meter update stats\n\n"
724
725                         "show port (port_id) queue-region\n"
726                         "    show all queue region related configuration info\n\n"
727
728                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
729                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
730                         "       Add port tm node private shaper profile.\n\n"
731
732                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
733                         "       Delete port tm node private shaper profile.\n\n"
734
735                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
736                         " (shaper_profile_id)\n"
737                         "       Add/update port tm node shared shaper.\n\n"
738
739                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
740                         "       Delete port tm node shared shaper.\n\n"
741
742                         "set port tm node shaper profile (port_id) (node_id)"
743                         " (shaper_profile_id)\n"
744                         "       Set port tm node shaper profile.\n\n"
745
746                         "add port tm node wred profile (port_id) (wred_profile_id)"
747                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
748                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
749                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
750                         "       Add port tm node wred profile.\n\n"
751
752                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
753                         "       Delete port tm node wred profile.\n\n"
754
755                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
756                         " (priority) (weight) (level_id) (shaper_profile_id)"
757                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
758                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
759                         "       Add port tm nonleaf node.\n\n"
760
761                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
762                         " (priority) (weight) (level_id) (shaper_profile_id)"
763                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
764                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
765                         "       Add port tm leaf node.\n\n"
766
767                         "del port tm node (port_id) (node_id)\n"
768                         "       Delete port tm node.\n\n"
769
770                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
771                         " (priority) (weight)\n"
772                         "       Set port tm node parent.\n\n"
773
774                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
775                         "       Commit tm hierarchy.\n\n"
776
777                         , list_pkt_forwarding_modes()
778                 );
779         }
780
781         if (show_all || !strcmp(res->section, "ports")) {
782
783                 cmdline_printf(
784                         cl,
785                         "\n"
786                         "Port Operations:\n"
787                         "----------------\n\n"
788
789                         "port start (port_id|all)\n"
790                         "    Start all ports or port_id.\n\n"
791
792                         "port stop (port_id|all)\n"
793                         "    Stop all ports or port_id.\n\n"
794
795                         "port close (port_id|all)\n"
796                         "    Close all ports or port_id.\n\n"
797
798                         "port attach (ident)\n"
799                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
800
801                         "port detach (port_id)\n"
802                         "    Detach physical or virtual dev by port_id\n\n"
803
804                         "port config (port_id|all)"
805                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
806                         " duplex (half|full|auto)\n"
807                         "    Set speed and duplex for all ports or port_id\n\n"
808
809                         "port config (port_id|all) loopback (mode)\n"
810                         "    Set loopback mode for all ports or port_id\n\n"
811
812                         "port config all (rxq|txq|rxd|txd) (value)\n"
813                         "    Set number for rxq/txq/rxd/txd.\n\n"
814
815                         "port config all max-pkt-len (value)\n"
816                         "    Set the max packet length.\n\n"
817
818                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
819                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
820                         " (on|off)\n"
821                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
822                         " for ports.\n\n"
823
824                         "port config all rss (all|default|ip|tcp|udp|sctp|"
825                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
826                         "    Set the RSS mode.\n\n"
827
828                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
829                         "    Set the RSS redirection table.\n\n"
830
831                         "port config (port_id) dcb vt (on|off) (traffic_class)"
832                         " pfc (on|off)\n"
833                         "    Set the DCB mode.\n\n"
834
835                         "port config all burst (value)\n"
836                         "    Set the number of packets per burst.\n\n"
837
838                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
839                         " (value)\n"
840                         "    Set the ring prefetch/host/writeback threshold"
841                         " for tx/rx queue.\n\n"
842
843                         "port config all (txfreet|txrst|rxfreet) (value)\n"
844                         "    Set free threshold for rx/tx, or set"
845                         " tx rs bit threshold.\n\n"
846                         "port config mtu X value\n"
847                         "    Set the MTU of port X to a given value\n\n"
848
849                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
850                         "    Set a rx/tx queue's ring size configuration, the new"
851                         " value will take effect after command that (re-)start the port"
852                         " or command that setup the specific queue\n\n"
853
854                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
855                         "    Start/stop a rx/tx queue of port X. Only take effect"
856                         " when port X is started\n\n"
857
858                         "port (port_id) (rxq|txq) (queue_id) setup\n"
859                         "    Setup a rx/tx queue of port X.\n\n"
860
861                         "port config (port_id|all) l2-tunnel E-tag ether-type"
862                         " (value)\n"
863                         "    Set the value of E-tag ether-type.\n\n"
864
865                         "port config (port_id|all) l2-tunnel E-tag"
866                         " (enable|disable)\n"
867                         "    Enable/disable the E-tag support.\n\n"
868
869                         "port config (port_id) pctype mapping reset\n"
870                         "    Reset flow type to pctype mapping on a port\n\n"
871
872                         "port config (port_id) pctype mapping update"
873                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
874                         "    Update a flow type to pctype mapping item on a port\n\n"
875
876                         "port config (port_id) pctype (pctype_id) hash_inset|"
877                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
878                         " (field_idx)\n"
879                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
880
881                         "port config (port_id) pctype (pctype_id) hash_inset|"
882                         "fdir_inset|fdir_flx_inset clear all"
883                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
884
885                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
886                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
887                 );
888         }
889
890         if (show_all || !strcmp(res->section, "registers")) {
891
892                 cmdline_printf(
893                         cl,
894                         "\n"
895                         "Registers:\n"
896                         "----------\n\n"
897
898                         "read reg (port_id) (address)\n"
899                         "    Display value of a port register.\n\n"
900
901                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
902                         "    Display a port register bit field.\n\n"
903
904                         "read regbit (port_id) (address) (bit_x)\n"
905                         "    Display a single port register bit.\n\n"
906
907                         "write reg (port_id) (address) (value)\n"
908                         "    Set value of a port register.\n\n"
909
910                         "write regfield (port_id) (address) (bit_x) (bit_y)"
911                         " (value)\n"
912                         "    Set bit field of a port register.\n\n"
913
914                         "write regbit (port_id) (address) (bit_x) (value)\n"
915                         "    Set single bit value of a port register.\n\n"
916                 );
917         }
918         if (show_all || !strcmp(res->section, "filters")) {
919
920                 cmdline_printf(
921                         cl,
922                         "\n"
923                         "filters:\n"
924                         "--------\n\n"
925
926                         "ethertype_filter (port_id) (add|del)"
927                         " (mac_addr|mac_ignr) (mac_address) ethertype"
928                         " (ether_type) (drop|fwd) queue (queue_id)\n"
929                         "    Add/Del an ethertype filter.\n\n"
930
931                         "2tuple_filter (port_id) (add|del)"
932                         " dst_port (dst_port_value) protocol (protocol_value)"
933                         " mask (mask_value) tcp_flags (tcp_flags_value)"
934                         " priority (prio_value) queue (queue_id)\n"
935                         "    Add/Del a 2tuple filter.\n\n"
936
937                         "5tuple_filter (port_id) (add|del)"
938                         " dst_ip (dst_address) src_ip (src_address)"
939                         " dst_port (dst_port_value) src_port (src_port_value)"
940                         " protocol (protocol_value)"
941                         " mask (mask_value) tcp_flags (tcp_flags_value)"
942                         " priority (prio_value) queue (queue_id)\n"
943                         "    Add/Del a 5tuple filter.\n\n"
944
945                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
946                         "    Add/Del syn filter.\n\n"
947
948                         "flex_filter (port_id) (add|del) len (len_value)"
949                         " bytes (bytes_value) mask (mask_value)"
950                         " priority (prio_value) queue (queue_id)\n"
951                         "    Add/Del a flex filter.\n\n"
952
953                         "flow_director_filter (port_id) mode IP (add|del|update)"
954                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
955                         " src (src_ip_address) dst (dst_ip_address)"
956                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
957                         " vlan (vlan_value) flexbytes (flexbytes_value)"
958                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
959                         " fd_id (fd_id_value)\n"
960                         "    Add/Del an IP type flow director filter.\n\n"
961
962                         "flow_director_filter (port_id) mode IP (add|del|update)"
963                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
964                         " src (src_ip_address) (src_port)"
965                         " dst (dst_ip_address) (dst_port)"
966                         " tos (tos_value) ttl (ttl_value)"
967                         " vlan (vlan_value) flexbytes (flexbytes_value)"
968                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
969                         " fd_id (fd_id_value)\n"
970                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
971
972                         "flow_director_filter (port_id) mode IP (add|del|update)"
973                         " flow (ipv4-sctp|ipv6-sctp)"
974                         " src (src_ip_address) (src_port)"
975                         " dst (dst_ip_address) (dst_port)"
976                         " tag (verification_tag) "
977                         " tos (tos_value) ttl (ttl_value)"
978                         " vlan (vlan_value)"
979                         " flexbytes (flexbytes_value) (drop|fwd)"
980                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
981                         "    Add/Del a SCTP type flow director filter.\n\n"
982
983                         "flow_director_filter (port_id) mode IP (add|del|update)"
984                         " flow l2_payload ether (ethertype)"
985                         " flexbytes (flexbytes_value) (drop|fwd)"
986                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
987                         "    Add/Del a l2 payload type flow director filter.\n\n"
988
989                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
990                         " mac (mac_address) vlan (vlan_value)"
991                         " flexbytes (flexbytes_value) (drop|fwd)"
992                         " queue (queue_id) fd_id (fd_id_value)\n"
993                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
994
995                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
996                         " mac (mac_address) vlan (vlan_value)"
997                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
998                         " flexbytes (flexbytes_value) (drop|fwd)"
999                         " queue (queue_id) fd_id (fd_id_value)\n"
1000                         "    Add/Del a Tunnel flow director filter.\n\n"
1001
1002                         "flow_director_filter (port_id) mode raw (add|del|update)"
1003                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1004                         " fd_id (fd_id_value) packet (packet file name)\n"
1005                         "    Add/Del a raw type flow director filter.\n\n"
1006
1007                         "flush_flow_director (port_id)\n"
1008                         "    Flush all flow director entries of a device.\n\n"
1009
1010                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1011                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1012                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1013                         "    Set flow director IP mask.\n\n"
1014
1015                         "flow_director_mask (port_id) mode MAC-VLAN"
1016                         " vlan (vlan_value)\n"
1017                         "    Set flow director MAC-VLAN mask.\n\n"
1018
1019                         "flow_director_mask (port_id) mode Tunnel"
1020                         " vlan (vlan_value) mac (mac_value)"
1021                         " tunnel-type (tunnel_type_value)"
1022                         " tunnel-id (tunnel_id_value)\n"
1023                         "    Set flow director Tunnel mask.\n\n"
1024
1025                         "flow_director_flex_mask (port_id)"
1026                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1027                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1028                         " (mask)\n"
1029                         "    Configure mask of flex payload.\n\n"
1030
1031                         "flow_director_flex_payload (port_id)"
1032                         " (raw|l2|l3|l4) (config)\n"
1033                         "    Configure flex payload selection.\n\n"
1034
1035                         "get_sym_hash_ena_per_port (port_id)\n"
1036                         "    get symmetric hash enable configuration per port.\n\n"
1037
1038                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1039                         "    set symmetric hash enable configuration per port"
1040                         " to enable or disable.\n\n"
1041
1042                         "get_hash_global_config (port_id)\n"
1043                         "    Get the global configurations of hash filters.\n\n"
1044
1045                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1046                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1047                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1048                         " (enable|disable)\n"
1049                         "    Set the global configurations of hash filters.\n\n"
1050
1051                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1052                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1053                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1054                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1055                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1056                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1057                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1058                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1059                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1060                         "fld-8th|none) (select|add)\n"
1061                         "    Set the input set for hash.\n\n"
1062
1063                         "set_fdir_input_set (port_id) "
1064                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1065                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1066                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1067                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1068                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1069                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1070                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1071                         " (select|add)\n"
1072                         "    Set the input set for FDir.\n\n"
1073
1074                         "flow validate {port_id}"
1075                         " [group {group_id}] [priority {level}]"
1076                         " [ingress] [egress]"
1077                         " pattern {item} [/ {item} [...]] / end"
1078                         " actions {action} [/ {action} [...]] / end\n"
1079                         "    Check whether a flow rule can be created.\n\n"
1080
1081                         "flow create {port_id}"
1082                         " [group {group_id}] [priority {level}]"
1083                         " [ingress] [egress]"
1084                         " pattern {item} [/ {item} [...]] / end"
1085                         " actions {action} [/ {action} [...]] / end\n"
1086                         "    Create a flow rule.\n\n"
1087
1088                         "flow destroy {port_id} rule {rule_id} [...]\n"
1089                         "    Destroy specific flow rules.\n\n"
1090
1091                         "flow flush {port_id}\n"
1092                         "    Destroy all flow rules.\n\n"
1093
1094                         "flow query {port_id} {rule_id} {action}\n"
1095                         "    Query an existing flow rule.\n\n"
1096
1097                         "flow list {port_id} [group {group_id}] [...]\n"
1098                         "    List existing flow rules sorted by priority,"
1099                         " filtered by group identifiers.\n\n"
1100
1101                         "flow isolate {port_id} {boolean}\n"
1102                         "    Restrict ingress traffic to the defined"
1103                         " flow rules\n\n"
1104                 );
1105         }
1106 }
1107
1108 cmdline_parse_token_string_t cmd_help_long_help =
1109         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1110
1111 cmdline_parse_token_string_t cmd_help_long_section =
1112         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1113                         "all#control#display#config#"
1114                         "ports#registers#filters");
1115
1116 cmdline_parse_inst_t cmd_help_long = {
1117         .f = cmd_help_long_parsed,
1118         .data = NULL,
1119         .help_str = "help all|control|display|config|ports|register|filters: "
1120                 "Show help",
1121         .tokens = {
1122                 (void *)&cmd_help_long_help,
1123                 (void *)&cmd_help_long_section,
1124                 NULL,
1125         },
1126 };
1127
1128
1129 /* *** start/stop/close all ports *** */
1130 struct cmd_operate_port_result {
1131         cmdline_fixed_string_t keyword;
1132         cmdline_fixed_string_t name;
1133         cmdline_fixed_string_t value;
1134 };
1135
1136 static void cmd_operate_port_parsed(void *parsed_result,
1137                                 __attribute__((unused)) struct cmdline *cl,
1138                                 __attribute__((unused)) void *data)
1139 {
1140         struct cmd_operate_port_result *res = parsed_result;
1141
1142         if (!strcmp(res->name, "start"))
1143                 start_port(RTE_PORT_ALL);
1144         else if (!strcmp(res->name, "stop"))
1145                 stop_port(RTE_PORT_ALL);
1146         else if (!strcmp(res->name, "close"))
1147                 close_port(RTE_PORT_ALL);
1148         else if (!strcmp(res->name, "reset"))
1149                 reset_port(RTE_PORT_ALL);
1150         else
1151                 printf("Unknown parameter\n");
1152 }
1153
1154 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1155         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1156                                                                 "port");
1157 cmdline_parse_token_string_t cmd_operate_port_all_port =
1158         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1159                                                 "start#stop#close#reset");
1160 cmdline_parse_token_string_t cmd_operate_port_all_all =
1161         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1162
1163 cmdline_parse_inst_t cmd_operate_port = {
1164         .f = cmd_operate_port_parsed,
1165         .data = NULL,
1166         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1167         .tokens = {
1168                 (void *)&cmd_operate_port_all_cmd,
1169                 (void *)&cmd_operate_port_all_port,
1170                 (void *)&cmd_operate_port_all_all,
1171                 NULL,
1172         },
1173 };
1174
1175 /* *** start/stop/close specific port *** */
1176 struct cmd_operate_specific_port_result {
1177         cmdline_fixed_string_t keyword;
1178         cmdline_fixed_string_t name;
1179         uint8_t value;
1180 };
1181
1182 static void cmd_operate_specific_port_parsed(void *parsed_result,
1183                         __attribute__((unused)) struct cmdline *cl,
1184                                 __attribute__((unused)) void *data)
1185 {
1186         struct cmd_operate_specific_port_result *res = parsed_result;
1187
1188         if (!strcmp(res->name, "start"))
1189                 start_port(res->value);
1190         else if (!strcmp(res->name, "stop"))
1191                 stop_port(res->value);
1192         else if (!strcmp(res->name, "close"))
1193                 close_port(res->value);
1194         else if (!strcmp(res->name, "reset"))
1195                 reset_port(res->value);
1196         else
1197                 printf("Unknown parameter\n");
1198 }
1199
1200 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1201         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1202                                                         keyword, "port");
1203 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1204         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1205                                                 name, "start#stop#close#reset");
1206 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1207         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1208                                                         value, UINT8);
1209
1210 cmdline_parse_inst_t cmd_operate_specific_port = {
1211         .f = cmd_operate_specific_port_parsed,
1212         .data = NULL,
1213         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1214         .tokens = {
1215                 (void *)&cmd_operate_specific_port_cmd,
1216                 (void *)&cmd_operate_specific_port_port,
1217                 (void *)&cmd_operate_specific_port_id,
1218                 NULL,
1219         },
1220 };
1221
1222 /* *** attach a specified port *** */
1223 struct cmd_operate_attach_port_result {
1224         cmdline_fixed_string_t port;
1225         cmdline_fixed_string_t keyword;
1226         cmdline_fixed_string_t identifier;
1227 };
1228
1229 static void cmd_operate_attach_port_parsed(void *parsed_result,
1230                                 __attribute__((unused)) struct cmdline *cl,
1231                                 __attribute__((unused)) void *data)
1232 {
1233         struct cmd_operate_attach_port_result *res = parsed_result;
1234
1235         if (!strcmp(res->keyword, "attach"))
1236                 attach_port(res->identifier);
1237         else
1238                 printf("Unknown parameter\n");
1239 }
1240
1241 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1242         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1243                         port, "port");
1244 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1245         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1246                         keyword, "attach");
1247 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1248         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1249                         identifier, NULL);
1250
1251 cmdline_parse_inst_t cmd_operate_attach_port = {
1252         .f = cmd_operate_attach_port_parsed,
1253         .data = NULL,
1254         .help_str = "port attach <identifier>: "
1255                 "(identifier: pci address or virtual dev name)",
1256         .tokens = {
1257                 (void *)&cmd_operate_attach_port_port,
1258                 (void *)&cmd_operate_attach_port_keyword,
1259                 (void *)&cmd_operate_attach_port_identifier,
1260                 NULL,
1261         },
1262 };
1263
1264 /* *** detach a specified port *** */
1265 struct cmd_operate_detach_port_result {
1266         cmdline_fixed_string_t port;
1267         cmdline_fixed_string_t keyword;
1268         portid_t port_id;
1269 };
1270
1271 static void cmd_operate_detach_port_parsed(void *parsed_result,
1272                                 __attribute__((unused)) struct cmdline *cl,
1273                                 __attribute__((unused)) void *data)
1274 {
1275         struct cmd_operate_detach_port_result *res = parsed_result;
1276
1277         if (!strcmp(res->keyword, "detach"))
1278                 detach_port(res->port_id);
1279         else
1280                 printf("Unknown parameter\n");
1281 }
1282
1283 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1284         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1285                         port, "port");
1286 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1287         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1288                         keyword, "detach");
1289 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1290         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1291                         port_id, UINT16);
1292
1293 cmdline_parse_inst_t cmd_operate_detach_port = {
1294         .f = cmd_operate_detach_port_parsed,
1295         .data = NULL,
1296         .help_str = "port detach <port_id>",
1297         .tokens = {
1298                 (void *)&cmd_operate_detach_port_port,
1299                 (void *)&cmd_operate_detach_port_keyword,
1300                 (void *)&cmd_operate_detach_port_port_id,
1301                 NULL,
1302         },
1303 };
1304
1305 /* *** configure speed for all ports *** */
1306 struct cmd_config_speed_all {
1307         cmdline_fixed_string_t port;
1308         cmdline_fixed_string_t keyword;
1309         cmdline_fixed_string_t all;
1310         cmdline_fixed_string_t item1;
1311         cmdline_fixed_string_t item2;
1312         cmdline_fixed_string_t value1;
1313         cmdline_fixed_string_t value2;
1314 };
1315
1316 static int
1317 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1318 {
1319
1320         int duplex;
1321
1322         if (!strcmp(duplexstr, "half")) {
1323                 duplex = ETH_LINK_HALF_DUPLEX;
1324         } else if (!strcmp(duplexstr, "full")) {
1325                 duplex = ETH_LINK_FULL_DUPLEX;
1326         } else if (!strcmp(duplexstr, "auto")) {
1327                 duplex = ETH_LINK_FULL_DUPLEX;
1328         } else {
1329                 printf("Unknown duplex parameter\n");
1330                 return -1;
1331         }
1332
1333         if (!strcmp(speedstr, "10")) {
1334                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1335                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1336         } else if (!strcmp(speedstr, "100")) {
1337                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1338                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1339         } else {
1340                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1341                         printf("Invalid speed/duplex parameters\n");
1342                         return -1;
1343                 }
1344                 if (!strcmp(speedstr, "1000")) {
1345                         *speed = ETH_LINK_SPEED_1G;
1346                 } else if (!strcmp(speedstr, "10000")) {
1347                         *speed = ETH_LINK_SPEED_10G;
1348                 } else if (!strcmp(speedstr, "25000")) {
1349                         *speed = ETH_LINK_SPEED_25G;
1350                 } else if (!strcmp(speedstr, "40000")) {
1351                         *speed = ETH_LINK_SPEED_40G;
1352                 } else if (!strcmp(speedstr, "50000")) {
1353                         *speed = ETH_LINK_SPEED_50G;
1354                 } else if (!strcmp(speedstr, "100000")) {
1355                         *speed = ETH_LINK_SPEED_100G;
1356                 } else if (!strcmp(speedstr, "auto")) {
1357                         *speed = ETH_LINK_SPEED_AUTONEG;
1358                 } else {
1359                         printf("Unknown speed parameter\n");
1360                         return -1;
1361                 }
1362         }
1363
1364         return 0;
1365 }
1366
1367 static void
1368 cmd_config_speed_all_parsed(void *parsed_result,
1369                         __attribute__((unused)) struct cmdline *cl,
1370                         __attribute__((unused)) void *data)
1371 {
1372         struct cmd_config_speed_all *res = parsed_result;
1373         uint32_t link_speed;
1374         portid_t pid;
1375
1376         if (!all_ports_stopped()) {
1377                 printf("Please stop all ports first\n");
1378                 return;
1379         }
1380
1381         if (parse_and_check_speed_duplex(res->value1, res->value2,
1382                         &link_speed) < 0)
1383                 return;
1384
1385         RTE_ETH_FOREACH_DEV(pid) {
1386                 ports[pid].dev_conf.link_speeds = link_speed;
1387         }
1388
1389         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1390 }
1391
1392 cmdline_parse_token_string_t cmd_config_speed_all_port =
1393         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1394 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1395         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1396                                                         "config");
1397 cmdline_parse_token_string_t cmd_config_speed_all_all =
1398         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1399 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1400         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1401 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1402         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1403                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1404 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1405         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1406 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1407         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1408                                                 "half#full#auto");
1409
1410 cmdline_parse_inst_t cmd_config_speed_all = {
1411         .f = cmd_config_speed_all_parsed,
1412         .data = NULL,
1413         .help_str = "port config all speed "
1414                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1415                                                         "half|full|auto",
1416         .tokens = {
1417                 (void *)&cmd_config_speed_all_port,
1418                 (void *)&cmd_config_speed_all_keyword,
1419                 (void *)&cmd_config_speed_all_all,
1420                 (void *)&cmd_config_speed_all_item1,
1421                 (void *)&cmd_config_speed_all_value1,
1422                 (void *)&cmd_config_speed_all_item2,
1423                 (void *)&cmd_config_speed_all_value2,
1424                 NULL,
1425         },
1426 };
1427
1428 /* *** configure speed for specific port *** */
1429 struct cmd_config_speed_specific {
1430         cmdline_fixed_string_t port;
1431         cmdline_fixed_string_t keyword;
1432         portid_t id;
1433         cmdline_fixed_string_t item1;
1434         cmdline_fixed_string_t item2;
1435         cmdline_fixed_string_t value1;
1436         cmdline_fixed_string_t value2;
1437 };
1438
1439 static void
1440 cmd_config_speed_specific_parsed(void *parsed_result,
1441                                 __attribute__((unused)) struct cmdline *cl,
1442                                 __attribute__((unused)) void *data)
1443 {
1444         struct cmd_config_speed_specific *res = parsed_result;
1445         uint32_t link_speed;
1446
1447         if (!all_ports_stopped()) {
1448                 printf("Please stop all ports first\n");
1449                 return;
1450         }
1451
1452         if (port_id_is_invalid(res->id, ENABLED_WARN))
1453                 return;
1454
1455         if (parse_and_check_speed_duplex(res->value1, res->value2,
1456                         &link_speed) < 0)
1457                 return;
1458
1459         ports[res->id].dev_conf.link_speeds = link_speed;
1460
1461         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1462 }
1463
1464
1465 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1467                                                                 "port");
1468 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1470                                                                 "config");
1471 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1472         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1473 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1474         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1475                                                                 "speed");
1476 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1477         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1478                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1479 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1480         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1481                                                                 "duplex");
1482 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1483         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1484                                                         "half#full#auto");
1485
1486 cmdline_parse_inst_t cmd_config_speed_specific = {
1487         .f = cmd_config_speed_specific_parsed,
1488         .data = NULL,
1489         .help_str = "port config <port_id> speed "
1490                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1491                                                         "half|full|auto",
1492         .tokens = {
1493                 (void *)&cmd_config_speed_specific_port,
1494                 (void *)&cmd_config_speed_specific_keyword,
1495                 (void *)&cmd_config_speed_specific_id,
1496                 (void *)&cmd_config_speed_specific_item1,
1497                 (void *)&cmd_config_speed_specific_value1,
1498                 (void *)&cmd_config_speed_specific_item2,
1499                 (void *)&cmd_config_speed_specific_value2,
1500                 NULL,
1501         },
1502 };
1503
1504 /* *** configure loopback for all ports *** */
1505 struct cmd_config_loopback_all {
1506         cmdline_fixed_string_t port;
1507         cmdline_fixed_string_t keyword;
1508         cmdline_fixed_string_t all;
1509         cmdline_fixed_string_t item;
1510         uint32_t mode;
1511 };
1512
1513 static void
1514 cmd_config_loopback_all_parsed(void *parsed_result,
1515                         __attribute__((unused)) struct cmdline *cl,
1516                         __attribute__((unused)) void *data)
1517 {
1518         struct cmd_config_loopback_all *res = parsed_result;
1519         portid_t pid;
1520
1521         if (!all_ports_stopped()) {
1522                 printf("Please stop all ports first\n");
1523                 return;
1524         }
1525
1526         RTE_ETH_FOREACH_DEV(pid) {
1527                 ports[pid].dev_conf.lpbk_mode = res->mode;
1528         }
1529
1530         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1531 }
1532
1533 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1534         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1535 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1536         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1537                                                         "config");
1538 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1539         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1540 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1541         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1542                                                         "loopback");
1543 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1544         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1545
1546 cmdline_parse_inst_t cmd_config_loopback_all = {
1547         .f = cmd_config_loopback_all_parsed,
1548         .data = NULL,
1549         .help_str = "port config all loopback <mode>",
1550         .tokens = {
1551                 (void *)&cmd_config_loopback_all_port,
1552                 (void *)&cmd_config_loopback_all_keyword,
1553                 (void *)&cmd_config_loopback_all_all,
1554                 (void *)&cmd_config_loopback_all_item,
1555                 (void *)&cmd_config_loopback_all_mode,
1556                 NULL,
1557         },
1558 };
1559
1560 /* *** configure loopback for specific port *** */
1561 struct cmd_config_loopback_specific {
1562         cmdline_fixed_string_t port;
1563         cmdline_fixed_string_t keyword;
1564         uint16_t port_id;
1565         cmdline_fixed_string_t item;
1566         uint32_t mode;
1567 };
1568
1569 static void
1570 cmd_config_loopback_specific_parsed(void *parsed_result,
1571                                 __attribute__((unused)) struct cmdline *cl,
1572                                 __attribute__((unused)) void *data)
1573 {
1574         struct cmd_config_loopback_specific *res = parsed_result;
1575
1576         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1577                 return;
1578
1579         if (!port_is_stopped(res->port_id)) {
1580                 printf("Please stop port %u first\n", res->port_id);
1581                 return;
1582         }
1583
1584         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1585
1586         cmd_reconfig_device_queue(res->port_id, 1, 1);
1587 }
1588
1589
1590 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1591         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1592                                                                 "port");
1593 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1594         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1595                                                                 "config");
1596 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1597         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1598                                                                 UINT16);
1599 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1600         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1601                                                                 "loopback");
1602 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1603         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1604                               UINT32);
1605
1606 cmdline_parse_inst_t cmd_config_loopback_specific = {
1607         .f = cmd_config_loopback_specific_parsed,
1608         .data = NULL,
1609         .help_str = "port config <port_id> loopback <mode>",
1610         .tokens = {
1611                 (void *)&cmd_config_loopback_specific_port,
1612                 (void *)&cmd_config_loopback_specific_keyword,
1613                 (void *)&cmd_config_loopback_specific_id,
1614                 (void *)&cmd_config_loopback_specific_item,
1615                 (void *)&cmd_config_loopback_specific_mode,
1616                 NULL,
1617         },
1618 };
1619
1620 /* *** configure txq/rxq, txd/rxd *** */
1621 struct cmd_config_rx_tx {
1622         cmdline_fixed_string_t port;
1623         cmdline_fixed_string_t keyword;
1624         cmdline_fixed_string_t all;
1625         cmdline_fixed_string_t name;
1626         uint16_t value;
1627 };
1628
1629 static void
1630 cmd_config_rx_tx_parsed(void *parsed_result,
1631                         __attribute__((unused)) struct cmdline *cl,
1632                         __attribute__((unused)) void *data)
1633 {
1634         struct cmd_config_rx_tx *res = parsed_result;
1635
1636         if (!all_ports_stopped()) {
1637                 printf("Please stop all ports first\n");
1638                 return;
1639         }
1640         if (!strcmp(res->name, "rxq")) {
1641                 if (!res->value && !nb_txq) {
1642                         printf("Warning: Either rx or tx queues should be non zero\n");
1643                         return;
1644                 }
1645                 if (check_nb_rxq(res->value) != 0)
1646                         return;
1647                 nb_rxq = res->value;
1648         }
1649         else if (!strcmp(res->name, "txq")) {
1650                 if (!res->value && !nb_rxq) {
1651                         printf("Warning: Either rx or tx queues should be non zero\n");
1652                         return;
1653                 }
1654                 if (check_nb_txq(res->value) != 0)
1655                         return;
1656                 nb_txq = res->value;
1657         }
1658         else if (!strcmp(res->name, "rxd")) {
1659                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1660                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1661                                         res->value, RTE_TEST_RX_DESC_MAX);
1662                         return;
1663                 }
1664                 nb_rxd = res->value;
1665         } else if (!strcmp(res->name, "txd")) {
1666                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1667                         printf("txd %d invalid - must be > 0 && <= %d\n",
1668                                         res->value, RTE_TEST_TX_DESC_MAX);
1669                         return;
1670                 }
1671                 nb_txd = res->value;
1672         } else {
1673                 printf("Unknown parameter\n");
1674                 return;
1675         }
1676
1677         fwd_config_setup();
1678
1679         init_port_config();
1680
1681         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1682 }
1683
1684 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1685         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1686 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1687         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1688 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1689         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1690 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1691         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1692                                                 "rxq#txq#rxd#txd");
1693 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1694         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1695
1696 cmdline_parse_inst_t cmd_config_rx_tx = {
1697         .f = cmd_config_rx_tx_parsed,
1698         .data = NULL,
1699         .help_str = "port config all rxq|txq|rxd|txd <value>",
1700         .tokens = {
1701                 (void *)&cmd_config_rx_tx_port,
1702                 (void *)&cmd_config_rx_tx_keyword,
1703                 (void *)&cmd_config_rx_tx_all,
1704                 (void *)&cmd_config_rx_tx_name,
1705                 (void *)&cmd_config_rx_tx_value,
1706                 NULL,
1707         },
1708 };
1709
1710 /* *** config max packet length *** */
1711 struct cmd_config_max_pkt_len_result {
1712         cmdline_fixed_string_t port;
1713         cmdline_fixed_string_t keyword;
1714         cmdline_fixed_string_t all;
1715         cmdline_fixed_string_t name;
1716         uint32_t value;
1717 };
1718
1719 static void
1720 cmd_config_max_pkt_len_parsed(void *parsed_result,
1721                                 __attribute__((unused)) struct cmdline *cl,
1722                                 __attribute__((unused)) void *data)
1723 {
1724         struct cmd_config_max_pkt_len_result *res = parsed_result;
1725         portid_t pid;
1726
1727         if (!all_ports_stopped()) {
1728                 printf("Please stop all ports first\n");
1729                 return;
1730         }
1731
1732         RTE_ETH_FOREACH_DEV(pid) {
1733                 struct rte_port *port = &ports[pid];
1734                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1735
1736                 if (!strcmp(res->name, "max-pkt-len")) {
1737                         if (res->value < ETHER_MIN_LEN) {
1738                                 printf("max-pkt-len can not be less than %d\n",
1739                                                 ETHER_MIN_LEN);
1740                                 return;
1741                         }
1742                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1743                                 return;
1744
1745                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1746                         if (res->value > ETHER_MAX_LEN)
1747                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1748                         else
1749                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1750                         port->dev_conf.rxmode.offloads = rx_offloads;
1751                 } else {
1752                         printf("Unknown parameter\n");
1753                         return;
1754                 }
1755         }
1756
1757         init_port_config();
1758
1759         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1760 }
1761
1762 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1763         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1764                                                                 "port");
1765 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1766         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1767                                                                 "config");
1768 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1769         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1770                                                                 "all");
1771 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1772         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1773                                                                 "max-pkt-len");
1774 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1775         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1776                                                                 UINT32);
1777
1778 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1779         .f = cmd_config_max_pkt_len_parsed,
1780         .data = NULL,
1781         .help_str = "port config all max-pkt-len <value>",
1782         .tokens = {
1783                 (void *)&cmd_config_max_pkt_len_port,
1784                 (void *)&cmd_config_max_pkt_len_keyword,
1785                 (void *)&cmd_config_max_pkt_len_all,
1786                 (void *)&cmd_config_max_pkt_len_name,
1787                 (void *)&cmd_config_max_pkt_len_value,
1788                 NULL,
1789         },
1790 };
1791
1792 /* *** configure port MTU *** */
1793 struct cmd_config_mtu_result {
1794         cmdline_fixed_string_t port;
1795         cmdline_fixed_string_t keyword;
1796         cmdline_fixed_string_t mtu;
1797         portid_t port_id;
1798         uint16_t value;
1799 };
1800
1801 static void
1802 cmd_config_mtu_parsed(void *parsed_result,
1803                       __attribute__((unused)) struct cmdline *cl,
1804                       __attribute__((unused)) void *data)
1805 {
1806         struct cmd_config_mtu_result *res = parsed_result;
1807
1808         if (res->value < ETHER_MIN_LEN) {
1809                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1810                 return;
1811         }
1812         port_mtu_set(res->port_id, res->value);
1813 }
1814
1815 cmdline_parse_token_string_t cmd_config_mtu_port =
1816         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1817                                  "port");
1818 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1819         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1820                                  "config");
1821 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1822         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1823                                  "mtu");
1824 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1825         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1826 cmdline_parse_token_num_t cmd_config_mtu_value =
1827         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1828
1829 cmdline_parse_inst_t cmd_config_mtu = {
1830         .f = cmd_config_mtu_parsed,
1831         .data = NULL,
1832         .help_str = "port config mtu <port_id> <value>",
1833         .tokens = {
1834                 (void *)&cmd_config_mtu_port,
1835                 (void *)&cmd_config_mtu_keyword,
1836                 (void *)&cmd_config_mtu_mtu,
1837                 (void *)&cmd_config_mtu_port_id,
1838                 (void *)&cmd_config_mtu_value,
1839                 NULL,
1840         },
1841 };
1842
1843 /* *** configure rx mode *** */
1844 struct cmd_config_rx_mode_flag {
1845         cmdline_fixed_string_t port;
1846         cmdline_fixed_string_t keyword;
1847         cmdline_fixed_string_t all;
1848         cmdline_fixed_string_t name;
1849         cmdline_fixed_string_t value;
1850 };
1851
1852 static void
1853 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1854                                 __attribute__((unused)) struct cmdline *cl,
1855                                 __attribute__((unused)) void *data)
1856 {
1857         struct cmd_config_rx_mode_flag *res = parsed_result;
1858         portid_t pid;
1859
1860         if (!all_ports_stopped()) {
1861                 printf("Please stop all ports first\n");
1862                 return;
1863         }
1864
1865         RTE_ETH_FOREACH_DEV(pid) {
1866                 struct rte_port *port;
1867                 uint64_t rx_offloads;
1868
1869                 port = &ports[pid];
1870                 rx_offloads = port->dev_conf.rxmode.offloads;
1871                 if (!strcmp(res->name, "crc-strip")) {
1872                         if (!strcmp(res->value, "on"))
1873                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1874                         else if (!strcmp(res->value, "off"))
1875                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1876                         else {
1877                                 printf("Unknown parameter\n");
1878                                 return;
1879                         }
1880                 } else if (!strcmp(res->name, "scatter")) {
1881                         if (!strcmp(res->value, "on")) {
1882                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1883                         } else if (!strcmp(res->value, "off")) {
1884                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1885                         } else {
1886                                 printf("Unknown parameter\n");
1887                                 return;
1888                         }
1889                 } else if (!strcmp(res->name, "rx-cksum")) {
1890                         if (!strcmp(res->value, "on"))
1891                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1892                         else if (!strcmp(res->value, "off"))
1893                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1894                         else {
1895                                 printf("Unknown parameter\n");
1896                                 return;
1897                         }
1898                 } else if (!strcmp(res->name, "rx-timestamp")) {
1899                         if (!strcmp(res->value, "on"))
1900                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1901                         else if (!strcmp(res->value, "off"))
1902                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1903                         else {
1904                                 printf("Unknown parameter\n");
1905                                 return;
1906                         }
1907                 } else if (!strcmp(res->name, "hw-vlan")) {
1908                         if (!strcmp(res->value, "on")) {
1909                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1910                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1911                         } else if (!strcmp(res->value, "off")) {
1912                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1913                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1914                         } else {
1915                                 printf("Unknown parameter\n");
1916                                 return;
1917                         }
1918                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1919                         if (!strcmp(res->value, "on"))
1920                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1921                         else if (!strcmp(res->value, "off"))
1922                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1923                         else {
1924                                 printf("Unknown parameter\n");
1925                                 return;
1926                         }
1927                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1928                         if (!strcmp(res->value, "on"))
1929                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1930                         else if (!strcmp(res->value, "off"))
1931                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1932                         else {
1933                                 printf("Unknown parameter\n");
1934                                 return;
1935                         }
1936                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1937                         if (!strcmp(res->value, "on"))
1938                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1939                         else if (!strcmp(res->value, "off"))
1940                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1941                         else {
1942                                 printf("Unknown parameter\n");
1943                                 return;
1944                         }
1945                 } else if (!strcmp(res->name, "drop-en")) {
1946                         if (!strcmp(res->value, "on"))
1947                                 rx_drop_en = 1;
1948                         else if (!strcmp(res->value, "off"))
1949                                 rx_drop_en = 0;
1950                         else {
1951                                 printf("Unknown parameter\n");
1952                                 return;
1953                         }
1954                 } else {
1955                         printf("Unknown parameter\n");
1956                         return;
1957                 }
1958                 port->dev_conf.rxmode.offloads = rx_offloads;
1959         }
1960
1961         init_port_config();
1962
1963         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1964 }
1965
1966 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1967         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1968 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1969         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1970                                                                 "config");
1971 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1972         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1973 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1974         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1975                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1976                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1977 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1978         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1979                                                         "on#off");
1980
1981 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1982         .f = cmd_config_rx_mode_flag_parsed,
1983         .data = NULL,
1984         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1985                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1986         .tokens = {
1987                 (void *)&cmd_config_rx_mode_flag_port,
1988                 (void *)&cmd_config_rx_mode_flag_keyword,
1989                 (void *)&cmd_config_rx_mode_flag_all,
1990                 (void *)&cmd_config_rx_mode_flag_name,
1991                 (void *)&cmd_config_rx_mode_flag_value,
1992                 NULL,
1993         },
1994 };
1995
1996 /* *** configure rss *** */
1997 struct cmd_config_rss {
1998         cmdline_fixed_string_t port;
1999         cmdline_fixed_string_t keyword;
2000         cmdline_fixed_string_t all;
2001         cmdline_fixed_string_t name;
2002         cmdline_fixed_string_t value;
2003 };
2004
2005 static void
2006 cmd_config_rss_parsed(void *parsed_result,
2007                         __attribute__((unused)) struct cmdline *cl,
2008                         __attribute__((unused)) void *data)
2009 {
2010         struct cmd_config_rss *res = parsed_result;
2011         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2012         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2013         int diag;
2014         uint16_t i;
2015
2016         if (!strcmp(res->value, "all"))
2017                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2018                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2019                                         ETH_RSS_L2_PAYLOAD;
2020         else if (!strcmp(res->value, "ip"))
2021                 rss_conf.rss_hf = ETH_RSS_IP;
2022         else if (!strcmp(res->value, "udp"))
2023                 rss_conf.rss_hf = ETH_RSS_UDP;
2024         else if (!strcmp(res->value, "tcp"))
2025                 rss_conf.rss_hf = ETH_RSS_TCP;
2026         else if (!strcmp(res->value, "sctp"))
2027                 rss_conf.rss_hf = ETH_RSS_SCTP;
2028         else if (!strcmp(res->value, "ether"))
2029                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2030         else if (!strcmp(res->value, "port"))
2031                 rss_conf.rss_hf = ETH_RSS_PORT;
2032         else if (!strcmp(res->value, "vxlan"))
2033                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2034         else if (!strcmp(res->value, "geneve"))
2035                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2036         else if (!strcmp(res->value, "nvgre"))
2037                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2038         else if (!strcmp(res->value, "none") || !strcmp(res->value, "default"))
2039                 rss_conf.rss_hf = 0;
2040         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2041                                                 atoi(res->value) < 64)
2042                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2043         else {
2044                 printf("Unknown parameter\n");
2045                 return;
2046         }
2047         rss_conf.rss_key = NULL;
2048         /* Update global configuration for RSS types. */
2049         rss_hf = rss_conf.rss_hf;
2050         RTE_ETH_FOREACH_DEV(i) {
2051                 if (!strcmp(res->value, "default")) {
2052                         rte_eth_dev_info_get(i, &dev_info);
2053                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2054                 }
2055                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
2056                 if (diag < 0)
2057                         printf("Configuration of RSS hash at ethernet port %d "
2058                                 "failed with error (%d): %s.\n",
2059                                 i, -diag, strerror(-diag));
2060         }
2061 }
2062
2063 cmdline_parse_token_string_t cmd_config_rss_port =
2064         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2065 cmdline_parse_token_string_t cmd_config_rss_keyword =
2066         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2067 cmdline_parse_token_string_t cmd_config_rss_all =
2068         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2069 cmdline_parse_token_string_t cmd_config_rss_name =
2070         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2071 cmdline_parse_token_string_t cmd_config_rss_value =
2072         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2073
2074 cmdline_parse_inst_t cmd_config_rss = {
2075         .f = cmd_config_rss_parsed,
2076         .data = NULL,
2077         .help_str = "port config all rss "
2078                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2079         .tokens = {
2080                 (void *)&cmd_config_rss_port,
2081                 (void *)&cmd_config_rss_keyword,
2082                 (void *)&cmd_config_rss_all,
2083                 (void *)&cmd_config_rss_name,
2084                 (void *)&cmd_config_rss_value,
2085                 NULL,
2086         },
2087 };
2088
2089 /* *** configure rss hash key *** */
2090 struct cmd_config_rss_hash_key {
2091         cmdline_fixed_string_t port;
2092         cmdline_fixed_string_t config;
2093         portid_t port_id;
2094         cmdline_fixed_string_t rss_hash_key;
2095         cmdline_fixed_string_t rss_type;
2096         cmdline_fixed_string_t key;
2097 };
2098
2099 static uint8_t
2100 hexa_digit_to_value(char hexa_digit)
2101 {
2102         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2103                 return (uint8_t) (hexa_digit - '0');
2104         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2105                 return (uint8_t) ((hexa_digit - 'a') + 10);
2106         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2107                 return (uint8_t) ((hexa_digit - 'A') + 10);
2108         /* Invalid hexa digit */
2109         return 0xFF;
2110 }
2111
2112 static uint8_t
2113 parse_and_check_key_hexa_digit(char *key, int idx)
2114 {
2115         uint8_t hexa_v;
2116
2117         hexa_v = hexa_digit_to_value(key[idx]);
2118         if (hexa_v == 0xFF)
2119                 printf("invalid key: character %c at position %d is not a "
2120                        "valid hexa digit\n", key[idx], idx);
2121         return hexa_v;
2122 }
2123
2124 static void
2125 cmd_config_rss_hash_key_parsed(void *parsed_result,
2126                                __attribute__((unused)) struct cmdline *cl,
2127                                __attribute__((unused)) void *data)
2128 {
2129         struct cmd_config_rss_hash_key *res = parsed_result;
2130         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2131         uint8_t xdgt0;
2132         uint8_t xdgt1;
2133         int i;
2134         struct rte_eth_dev_info dev_info;
2135         uint8_t hash_key_size;
2136         uint32_t key_len;
2137
2138         memset(&dev_info, 0, sizeof(dev_info));
2139         rte_eth_dev_info_get(res->port_id, &dev_info);
2140         if (dev_info.hash_key_size > 0 &&
2141                         dev_info.hash_key_size <= sizeof(hash_key))
2142                 hash_key_size = dev_info.hash_key_size;
2143         else {
2144                 printf("dev_info did not provide a valid hash key size\n");
2145                 return;
2146         }
2147         /* Check the length of the RSS hash key */
2148         key_len = strlen(res->key);
2149         if (key_len != (hash_key_size * 2)) {
2150                 printf("key length: %d invalid - key must be a string of %d"
2151                            " hexa-decimal numbers\n",
2152                            (int) key_len, hash_key_size * 2);
2153                 return;
2154         }
2155         /* Translate RSS hash key into binary representation */
2156         for (i = 0; i < hash_key_size; i++) {
2157                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2158                 if (xdgt0 == 0xFF)
2159                         return;
2160                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2161                 if (xdgt1 == 0xFF)
2162                         return;
2163                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2164         }
2165         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2166                         hash_key_size);
2167 }
2168
2169 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2170         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2171 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2172         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2173                                  "config");
2174 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2175         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2176 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2177         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2178                                  rss_hash_key, "rss-hash-key");
2179 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2180         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2181                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2182                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2183                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2184                                  "ipv6-tcp-ex#ipv6-udp-ex");
2185 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2186         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2187
2188 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2189         .f = cmd_config_rss_hash_key_parsed,
2190         .data = NULL,
2191         .help_str = "port config <port_id> rss-hash-key "
2192                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2193                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2194                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2195                 "<string of hex digits (variable length, NIC dependent)>",
2196         .tokens = {
2197                 (void *)&cmd_config_rss_hash_key_port,
2198                 (void *)&cmd_config_rss_hash_key_config,
2199                 (void *)&cmd_config_rss_hash_key_port_id,
2200                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2201                 (void *)&cmd_config_rss_hash_key_rss_type,
2202                 (void *)&cmd_config_rss_hash_key_value,
2203                 NULL,
2204         },
2205 };
2206
2207 /* *** configure port rxq/txq ring size *** */
2208 struct cmd_config_rxtx_ring_size {
2209         cmdline_fixed_string_t port;
2210         cmdline_fixed_string_t config;
2211         portid_t portid;
2212         cmdline_fixed_string_t rxtxq;
2213         uint16_t qid;
2214         cmdline_fixed_string_t rsize;
2215         uint16_t size;
2216 };
2217
2218 static void
2219 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2220                                  __attribute__((unused)) struct cmdline *cl,
2221                                  __attribute__((unused)) void *data)
2222 {
2223         struct cmd_config_rxtx_ring_size *res = parsed_result;
2224         struct rte_port *port;
2225         uint8_t isrx;
2226
2227         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2228                 return;
2229
2230         if (res->portid == (portid_t)RTE_PORT_ALL) {
2231                 printf("Invalid port id\n");
2232                 return;
2233         }
2234
2235         port = &ports[res->portid];
2236
2237         if (!strcmp(res->rxtxq, "rxq"))
2238                 isrx = 1;
2239         else if (!strcmp(res->rxtxq, "txq"))
2240                 isrx = 0;
2241         else {
2242                 printf("Unknown parameter\n");
2243                 return;
2244         }
2245
2246         if (isrx && rx_queue_id_is_invalid(res->qid))
2247                 return;
2248         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2249                 return;
2250
2251         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2252                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2253                        rx_free_thresh);
2254                 return;
2255         }
2256
2257         if (isrx)
2258                 port->nb_rx_desc[res->qid] = res->size;
2259         else
2260                 port->nb_tx_desc[res->qid] = res->size;
2261
2262         cmd_reconfig_device_queue(res->portid, 0, 1);
2263 }
2264
2265 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2266         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2267                                  port, "port");
2268 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2269         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2270                                  config, "config");
2271 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2272         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2273                                  portid, UINT16);
2274 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2275         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2276                                  rxtxq, "rxq#txq");
2277 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2278         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2279                               qid, UINT16);
2280 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2281         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2282                                  rsize, "ring_size");
2283 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2284         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2285                               size, UINT16);
2286
2287 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2288         .f = cmd_config_rxtx_ring_size_parsed,
2289         .data = NULL,
2290         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2291         .tokens = {
2292                 (void *)&cmd_config_rxtx_ring_size_port,
2293                 (void *)&cmd_config_rxtx_ring_size_config,
2294                 (void *)&cmd_config_rxtx_ring_size_portid,
2295                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2296                 (void *)&cmd_config_rxtx_ring_size_qid,
2297                 (void *)&cmd_config_rxtx_ring_size_rsize,
2298                 (void *)&cmd_config_rxtx_ring_size_size,
2299                 NULL,
2300         },
2301 };
2302
2303 /* *** configure port rxq/txq start/stop *** */
2304 struct cmd_config_rxtx_queue {
2305         cmdline_fixed_string_t port;
2306         portid_t portid;
2307         cmdline_fixed_string_t rxtxq;
2308         uint16_t qid;
2309         cmdline_fixed_string_t opname;
2310 };
2311
2312 static void
2313 cmd_config_rxtx_queue_parsed(void *parsed_result,
2314                         __attribute__((unused)) struct cmdline *cl,
2315                         __attribute__((unused)) void *data)
2316 {
2317         struct cmd_config_rxtx_queue *res = parsed_result;
2318         uint8_t isrx;
2319         uint8_t isstart;
2320         int ret = 0;
2321
2322         if (test_done == 0) {
2323                 printf("Please stop forwarding first\n");
2324                 return;
2325         }
2326
2327         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2328                 return;
2329
2330         if (port_is_started(res->portid) != 1) {
2331                 printf("Please start port %u first\n", res->portid);
2332                 return;
2333         }
2334
2335         if (!strcmp(res->rxtxq, "rxq"))
2336                 isrx = 1;
2337         else if (!strcmp(res->rxtxq, "txq"))
2338                 isrx = 0;
2339         else {
2340                 printf("Unknown parameter\n");
2341                 return;
2342         }
2343
2344         if (isrx && rx_queue_id_is_invalid(res->qid))
2345                 return;
2346         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2347                 return;
2348
2349         if (!strcmp(res->opname, "start"))
2350                 isstart = 1;
2351         else if (!strcmp(res->opname, "stop"))
2352                 isstart = 0;
2353         else {
2354                 printf("Unknown parameter\n");
2355                 return;
2356         }
2357
2358         if (isstart && isrx)
2359                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2360         else if (!isstart && isrx)
2361                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2362         else if (isstart && !isrx)
2363                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2364         else
2365                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2366
2367         if (ret == -ENOTSUP)
2368                 printf("Function not supported in PMD driver\n");
2369 }
2370
2371 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2372         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2373 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2374         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2375 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2376         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2377 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2378         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2379 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2380         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2381                                                 "start#stop");
2382
2383 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2384         .f = cmd_config_rxtx_queue_parsed,
2385         .data = NULL,
2386         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2387         .tokens = {
2388                 (void *)&cmd_config_rxtx_queue_port,
2389                 (void *)&cmd_config_rxtx_queue_portid,
2390                 (void *)&cmd_config_rxtx_queue_rxtxq,
2391                 (void *)&cmd_config_rxtx_queue_qid,
2392                 (void *)&cmd_config_rxtx_queue_opname,
2393                 NULL,
2394         },
2395 };
2396
2397 /* *** configure port rxq/txq setup *** */
2398 struct cmd_setup_rxtx_queue {
2399         cmdline_fixed_string_t port;
2400         portid_t portid;
2401         cmdline_fixed_string_t rxtxq;
2402         uint16_t qid;
2403         cmdline_fixed_string_t setup;
2404 };
2405
2406 /* Common CLI fields for queue setup */
2407 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2408         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2409 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2410         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2411 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2412         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2413 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2414         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2415 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2416         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2417
2418 static void
2419 cmd_setup_rxtx_queue_parsed(
2420         void *parsed_result,
2421         __attribute__((unused)) struct cmdline *cl,
2422         __attribute__((unused)) void *data)
2423 {
2424         struct cmd_setup_rxtx_queue *res = parsed_result;
2425         struct rte_port *port;
2426         struct rte_mempool *mp;
2427         unsigned int socket_id;
2428         uint8_t isrx = 0;
2429         int ret;
2430
2431         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2432                 return;
2433
2434         if (res->portid == (portid_t)RTE_PORT_ALL) {
2435                 printf("Invalid port id\n");
2436                 return;
2437         }
2438
2439         if (!strcmp(res->rxtxq, "rxq"))
2440                 isrx = 1;
2441         else if (!strcmp(res->rxtxq, "txq"))
2442                 isrx = 0;
2443         else {
2444                 printf("Unknown parameter\n");
2445                 return;
2446         }
2447
2448         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2449                 printf("Invalid rx queue\n");
2450                 return;
2451         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2452                 printf("Invalid tx queue\n");
2453                 return;
2454         }
2455
2456         port = &ports[res->portid];
2457         if (isrx) {
2458                 socket_id = rxring_numa[res->portid];
2459                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2460                         socket_id = port->socket_id;
2461
2462                 mp = mbuf_pool_find(socket_id);
2463                 if (mp == NULL) {
2464                         printf("Failed to setup RX queue: "
2465                                 "No mempool allocation"
2466                                 " on the socket %d\n",
2467                                 rxring_numa[res->portid]);
2468                         return;
2469                 }
2470                 ret = rte_eth_rx_queue_setup(res->portid,
2471                                              res->qid,
2472                                              port->nb_rx_desc[res->qid],
2473                                              socket_id,
2474                                              &port->rx_conf[res->qid],
2475                                              mp);
2476                 if (ret)
2477                         printf("Failed to setup RX queue\n");
2478         } else {
2479                 socket_id = txring_numa[res->portid];
2480                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2481                         socket_id = port->socket_id;
2482
2483                 ret = rte_eth_tx_queue_setup(res->portid,
2484                                              res->qid,
2485                                              port->nb_tx_desc[res->qid],
2486                                              socket_id,
2487                                              &port->tx_conf[res->qid]);
2488                 if (ret)
2489                         printf("Failed to setup TX queue\n");
2490         }
2491 }
2492
2493 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2494         .f = cmd_setup_rxtx_queue_parsed,
2495         .data = NULL,
2496         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2497         .tokens = {
2498                 (void *)&cmd_setup_rxtx_queue_port,
2499                 (void *)&cmd_setup_rxtx_queue_portid,
2500                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2501                 (void *)&cmd_setup_rxtx_queue_qid,
2502                 (void *)&cmd_setup_rxtx_queue_setup,
2503                 NULL,
2504         },
2505 };
2506
2507
2508 /* *** Configure RSS RETA *** */
2509 struct cmd_config_rss_reta {
2510         cmdline_fixed_string_t port;
2511         cmdline_fixed_string_t keyword;
2512         portid_t port_id;
2513         cmdline_fixed_string_t name;
2514         cmdline_fixed_string_t list_name;
2515         cmdline_fixed_string_t list_of_items;
2516 };
2517
2518 static int
2519 parse_reta_config(const char *str,
2520                   struct rte_eth_rss_reta_entry64 *reta_conf,
2521                   uint16_t nb_entries)
2522 {
2523         int i;
2524         unsigned size;
2525         uint16_t hash_index, idx, shift;
2526         uint16_t nb_queue;
2527         char s[256];
2528         const char *p, *p0 = str;
2529         char *end;
2530         enum fieldnames {
2531                 FLD_HASH_INDEX = 0,
2532                 FLD_QUEUE,
2533                 _NUM_FLD
2534         };
2535         unsigned long int_fld[_NUM_FLD];
2536         char *str_fld[_NUM_FLD];
2537
2538         while ((p = strchr(p0,'(')) != NULL) {
2539                 ++p;
2540                 if((p0 = strchr(p,')')) == NULL)
2541                         return -1;
2542
2543                 size = p0 - p;
2544                 if(size >= sizeof(s))
2545                         return -1;
2546
2547                 snprintf(s, sizeof(s), "%.*s", size, p);
2548                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2549                         return -1;
2550                 for (i = 0; i < _NUM_FLD; i++) {
2551                         errno = 0;
2552                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2553                         if (errno != 0 || end == str_fld[i] ||
2554                                         int_fld[i] > 65535)
2555                                 return -1;
2556                 }
2557
2558                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2559                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2560
2561                 if (hash_index >= nb_entries) {
2562                         printf("Invalid RETA hash index=%d\n", hash_index);
2563                         return -1;
2564                 }
2565
2566                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2567                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2568                 reta_conf[idx].mask |= (1ULL << shift);
2569                 reta_conf[idx].reta[shift] = nb_queue;
2570         }
2571
2572         return 0;
2573 }
2574
2575 static void
2576 cmd_set_rss_reta_parsed(void *parsed_result,
2577                         __attribute__((unused)) struct cmdline *cl,
2578                         __attribute__((unused)) void *data)
2579 {
2580         int ret;
2581         struct rte_eth_dev_info dev_info;
2582         struct rte_eth_rss_reta_entry64 reta_conf[8];
2583         struct cmd_config_rss_reta *res = parsed_result;
2584
2585         memset(&dev_info, 0, sizeof(dev_info));
2586         rte_eth_dev_info_get(res->port_id, &dev_info);
2587         if (dev_info.reta_size == 0) {
2588                 printf("Redirection table size is 0 which is "
2589                                         "invalid for RSS\n");
2590                 return;
2591         } else
2592                 printf("The reta size of port %d is %u\n",
2593                         res->port_id, dev_info.reta_size);
2594         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2595                 printf("Currently do not support more than %u entries of "
2596                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2597                 return;
2598         }
2599
2600         memset(reta_conf, 0, sizeof(reta_conf));
2601         if (!strcmp(res->list_name, "reta")) {
2602                 if (parse_reta_config(res->list_of_items, reta_conf,
2603                                                 dev_info.reta_size)) {
2604                         printf("Invalid RSS Redirection Table "
2605                                         "config entered\n");
2606                         return;
2607                 }
2608                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2609                                 reta_conf, dev_info.reta_size);
2610                 if (ret != 0)
2611                         printf("Bad redirection table parameter, "
2612                                         "return code = %d \n", ret);
2613         }
2614 }
2615
2616 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2617         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2618 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2619         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2620 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2621         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2622 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2623         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2624 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2625         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2626 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2627         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2628                                  NULL);
2629 cmdline_parse_inst_t cmd_config_rss_reta = {
2630         .f = cmd_set_rss_reta_parsed,
2631         .data = NULL,
2632         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2633         .tokens = {
2634                 (void *)&cmd_config_rss_reta_port,
2635                 (void *)&cmd_config_rss_reta_keyword,
2636                 (void *)&cmd_config_rss_reta_port_id,
2637                 (void *)&cmd_config_rss_reta_name,
2638                 (void *)&cmd_config_rss_reta_list_name,
2639                 (void *)&cmd_config_rss_reta_list_of_items,
2640                 NULL,
2641         },
2642 };
2643
2644 /* *** SHOW PORT RETA INFO *** */
2645 struct cmd_showport_reta {
2646         cmdline_fixed_string_t show;
2647         cmdline_fixed_string_t port;
2648         portid_t port_id;
2649         cmdline_fixed_string_t rss;
2650         cmdline_fixed_string_t reta;
2651         uint16_t size;
2652         cmdline_fixed_string_t list_of_items;
2653 };
2654
2655 static int
2656 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2657                            uint16_t nb_entries,
2658                            char *str)
2659 {
2660         uint32_t size;
2661         const char *p, *p0 = str;
2662         char s[256];
2663         char *end;
2664         char *str_fld[8];
2665         uint16_t i;
2666         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2667                         RTE_RETA_GROUP_SIZE;
2668         int ret;
2669
2670         p = strchr(p0, '(');
2671         if (p == NULL)
2672                 return -1;
2673         p++;
2674         p0 = strchr(p, ')');
2675         if (p0 == NULL)
2676                 return -1;
2677         size = p0 - p;
2678         if (size >= sizeof(s)) {
2679                 printf("The string size exceeds the internal buffer size\n");
2680                 return -1;
2681         }
2682         snprintf(s, sizeof(s), "%.*s", size, p);
2683         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2684         if (ret <= 0 || ret != num) {
2685                 printf("The bits of masks do not match the number of "
2686                                         "reta entries: %u\n", num);
2687                 return -1;
2688         }
2689         for (i = 0; i < ret; i++)
2690                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2691
2692         return 0;
2693 }
2694
2695 static void
2696 cmd_showport_reta_parsed(void *parsed_result,
2697                          __attribute__((unused)) struct cmdline *cl,
2698                          __attribute__((unused)) void *data)
2699 {
2700         struct cmd_showport_reta *res = parsed_result;
2701         struct rte_eth_rss_reta_entry64 reta_conf[8];
2702         struct rte_eth_dev_info dev_info;
2703         uint16_t max_reta_size;
2704
2705         memset(&dev_info, 0, sizeof(dev_info));
2706         rte_eth_dev_info_get(res->port_id, &dev_info);
2707         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2708         if (res->size == 0 || res->size > max_reta_size) {
2709                 printf("Invalid redirection table size: %u (1-%u)\n",
2710                         res->size, max_reta_size);
2711                 return;
2712         }
2713
2714         memset(reta_conf, 0, sizeof(reta_conf));
2715         if (showport_parse_reta_config(reta_conf, res->size,
2716                                 res->list_of_items) < 0) {
2717                 printf("Invalid string: %s for reta masks\n",
2718                                         res->list_of_items);
2719                 return;
2720         }
2721         port_rss_reta_info(res->port_id, reta_conf, res->size);
2722 }
2723
2724 cmdline_parse_token_string_t cmd_showport_reta_show =
2725         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2726 cmdline_parse_token_string_t cmd_showport_reta_port =
2727         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2728 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2729         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2730 cmdline_parse_token_string_t cmd_showport_reta_rss =
2731         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2732 cmdline_parse_token_string_t cmd_showport_reta_reta =
2733         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2734 cmdline_parse_token_num_t cmd_showport_reta_size =
2735         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2736 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2737         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2738                                         list_of_items, NULL);
2739
2740 cmdline_parse_inst_t cmd_showport_reta = {
2741         .f = cmd_showport_reta_parsed,
2742         .data = NULL,
2743         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2744         .tokens = {
2745                 (void *)&cmd_showport_reta_show,
2746                 (void *)&cmd_showport_reta_port,
2747                 (void *)&cmd_showport_reta_port_id,
2748                 (void *)&cmd_showport_reta_rss,
2749                 (void *)&cmd_showport_reta_reta,
2750                 (void *)&cmd_showport_reta_size,
2751                 (void *)&cmd_showport_reta_list_of_items,
2752                 NULL,
2753         },
2754 };
2755
2756 /* *** Show RSS hash configuration *** */
2757 struct cmd_showport_rss_hash {
2758         cmdline_fixed_string_t show;
2759         cmdline_fixed_string_t port;
2760         portid_t port_id;
2761         cmdline_fixed_string_t rss_hash;
2762         cmdline_fixed_string_t rss_type;
2763         cmdline_fixed_string_t key; /* optional argument */
2764 };
2765
2766 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2767                                 __attribute__((unused)) struct cmdline *cl,
2768                                 void *show_rss_key)
2769 {
2770         struct cmd_showport_rss_hash *res = parsed_result;
2771
2772         port_rss_hash_conf_show(res->port_id, res->rss_type,
2773                                 show_rss_key != NULL);
2774 }
2775
2776 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2777         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2778 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2779         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2780 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2781         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2782 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2783         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2784                                  "rss-hash");
2785 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2786         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2787                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2788                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2789                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2790                                  "ipv6-tcp-ex#ipv6-udp-ex");
2791 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2792         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2793
2794 cmdline_parse_inst_t cmd_showport_rss_hash = {
2795         .f = cmd_showport_rss_hash_parsed,
2796         .data = NULL,
2797         .help_str = "show port <port_id> rss-hash "
2798                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2799                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2800                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2801         .tokens = {
2802                 (void *)&cmd_showport_rss_hash_show,
2803                 (void *)&cmd_showport_rss_hash_port,
2804                 (void *)&cmd_showport_rss_hash_port_id,
2805                 (void *)&cmd_showport_rss_hash_rss_hash,
2806                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2807                 NULL,
2808         },
2809 };
2810
2811 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2812         .f = cmd_showport_rss_hash_parsed,
2813         .data = (void *)1,
2814         .help_str = "show port <port_id> rss-hash "
2815                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2816                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2817                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2818         .tokens = {
2819                 (void *)&cmd_showport_rss_hash_show,
2820                 (void *)&cmd_showport_rss_hash_port,
2821                 (void *)&cmd_showport_rss_hash_port_id,
2822                 (void *)&cmd_showport_rss_hash_rss_hash,
2823                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2824                 (void *)&cmd_showport_rss_hash_rss_key,
2825                 NULL,
2826         },
2827 };
2828
2829 /* *** Configure DCB *** */
2830 struct cmd_config_dcb {
2831         cmdline_fixed_string_t port;
2832         cmdline_fixed_string_t config;
2833         portid_t port_id;
2834         cmdline_fixed_string_t dcb;
2835         cmdline_fixed_string_t vt;
2836         cmdline_fixed_string_t vt_en;
2837         uint8_t num_tcs;
2838         cmdline_fixed_string_t pfc;
2839         cmdline_fixed_string_t pfc_en;
2840 };
2841
2842 static void
2843 cmd_config_dcb_parsed(void *parsed_result,
2844                         __attribute__((unused)) struct cmdline *cl,
2845                         __attribute__((unused)) void *data)
2846 {
2847         struct cmd_config_dcb *res = parsed_result;
2848         portid_t port_id = res->port_id;
2849         struct rte_port *port;
2850         uint8_t pfc_en;
2851         int ret;
2852
2853         port = &ports[port_id];
2854         /** Check if the port is not started **/
2855         if (port->port_status != RTE_PORT_STOPPED) {
2856                 printf("Please stop port %d first\n", port_id);
2857                 return;
2858         }
2859
2860         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2861                 printf("The invalid number of traffic class,"
2862                         " only 4 or 8 allowed.\n");
2863                 return;
2864         }
2865
2866         if (nb_fwd_lcores < res->num_tcs) {
2867                 printf("nb_cores shouldn't be less than number of TCs.\n");
2868                 return;
2869         }
2870         if (!strncmp(res->pfc_en, "on", 2))
2871                 pfc_en = 1;
2872         else
2873                 pfc_en = 0;
2874
2875         /* DCB in VT mode */
2876         if (!strncmp(res->vt_en, "on", 2))
2877                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2878                                 (enum rte_eth_nb_tcs)res->num_tcs,
2879                                 pfc_en);
2880         else
2881                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2882                                 (enum rte_eth_nb_tcs)res->num_tcs,
2883                                 pfc_en);
2884
2885
2886         if (ret != 0) {
2887                 printf("Cannot initialize network ports.\n");
2888                 return;
2889         }
2890
2891         cmd_reconfig_device_queue(port_id, 1, 1);
2892 }
2893
2894 cmdline_parse_token_string_t cmd_config_dcb_port =
2895         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2896 cmdline_parse_token_string_t cmd_config_dcb_config =
2897         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2898 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2899         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2900 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2901         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2902 cmdline_parse_token_string_t cmd_config_dcb_vt =
2903         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2904 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2905         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2906 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2907         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2908 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2909         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2910 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2911         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2912
2913 cmdline_parse_inst_t cmd_config_dcb = {
2914         .f = cmd_config_dcb_parsed,
2915         .data = NULL,
2916         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2917         .tokens = {
2918                 (void *)&cmd_config_dcb_port,
2919                 (void *)&cmd_config_dcb_config,
2920                 (void *)&cmd_config_dcb_port_id,
2921                 (void *)&cmd_config_dcb_dcb,
2922                 (void *)&cmd_config_dcb_vt,
2923                 (void *)&cmd_config_dcb_vt_en,
2924                 (void *)&cmd_config_dcb_num_tcs,
2925                 (void *)&cmd_config_dcb_pfc,
2926                 (void *)&cmd_config_dcb_pfc_en,
2927                 NULL,
2928         },
2929 };
2930
2931 /* *** configure number of packets per burst *** */
2932 struct cmd_config_burst {
2933         cmdline_fixed_string_t port;
2934         cmdline_fixed_string_t keyword;
2935         cmdline_fixed_string_t all;
2936         cmdline_fixed_string_t name;
2937         uint16_t value;
2938 };
2939
2940 static void
2941 cmd_config_burst_parsed(void *parsed_result,
2942                         __attribute__((unused)) struct cmdline *cl,
2943                         __attribute__((unused)) void *data)
2944 {
2945         struct cmd_config_burst *res = parsed_result;
2946         struct rte_eth_dev_info dev_info;
2947         uint16_t rec_nb_pkts;
2948
2949         if (!all_ports_stopped()) {
2950                 printf("Please stop all ports first\n");
2951                 return;
2952         }
2953
2954         if (!strcmp(res->name, "burst")) {
2955                 if (res->value == 0) {
2956                         /* If user gives a value of zero, query the PMD for
2957                          * its recommended Rx burst size. Testpmd uses a single
2958                          * size for all ports, so assume all ports are the same
2959                          * NIC model and use the values from Port 0.
2960                          */
2961                         rte_eth_dev_info_get(0, &dev_info);
2962                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
2963
2964                         if (rec_nb_pkts == 0) {
2965                                 printf("PMD does not recommend a burst size.\n"
2966                                         "User provided value must be between"
2967                                         " 1 and %d\n", MAX_PKT_BURST);
2968                                 return;
2969                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
2970                                 printf("PMD recommended burst size of %d"
2971                                         " exceeds maximum value of %d\n",
2972                                         rec_nb_pkts, MAX_PKT_BURST);
2973                                 return;
2974                         }
2975                         printf("Using PMD-provided burst value of %d\n",
2976                                 rec_nb_pkts);
2977                         nb_pkt_per_burst = rec_nb_pkts;
2978                 } else if (res->value > MAX_PKT_BURST) {
2979                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2980                         return;
2981                 } else
2982                         nb_pkt_per_burst = res->value;
2983         } else {
2984                 printf("Unknown parameter\n");
2985                 return;
2986         }
2987
2988         init_port_config();
2989
2990         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2991 }
2992
2993 cmdline_parse_token_string_t cmd_config_burst_port =
2994         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2995 cmdline_parse_token_string_t cmd_config_burst_keyword =
2996         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2997 cmdline_parse_token_string_t cmd_config_burst_all =
2998         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2999 cmdline_parse_token_string_t cmd_config_burst_name =
3000         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3001 cmdline_parse_token_num_t cmd_config_burst_value =
3002         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3003
3004 cmdline_parse_inst_t cmd_config_burst = {
3005         .f = cmd_config_burst_parsed,
3006         .data = NULL,
3007         .help_str = "port config all burst <value>",
3008         .tokens = {
3009                 (void *)&cmd_config_burst_port,
3010                 (void *)&cmd_config_burst_keyword,
3011                 (void *)&cmd_config_burst_all,
3012                 (void *)&cmd_config_burst_name,
3013                 (void *)&cmd_config_burst_value,
3014                 NULL,
3015         },
3016 };
3017
3018 /* *** configure rx/tx queues *** */
3019 struct cmd_config_thresh {
3020         cmdline_fixed_string_t port;
3021         cmdline_fixed_string_t keyword;
3022         cmdline_fixed_string_t all;
3023         cmdline_fixed_string_t name;
3024         uint8_t value;
3025 };
3026
3027 static void
3028 cmd_config_thresh_parsed(void *parsed_result,
3029                         __attribute__((unused)) struct cmdline *cl,
3030                         __attribute__((unused)) void *data)
3031 {
3032         struct cmd_config_thresh *res = parsed_result;
3033
3034         if (!all_ports_stopped()) {
3035                 printf("Please stop all ports first\n");
3036                 return;
3037         }
3038
3039         if (!strcmp(res->name, "txpt"))
3040                 tx_pthresh = res->value;
3041         else if(!strcmp(res->name, "txht"))
3042                 tx_hthresh = res->value;
3043         else if(!strcmp(res->name, "txwt"))
3044                 tx_wthresh = res->value;
3045         else if(!strcmp(res->name, "rxpt"))
3046                 rx_pthresh = res->value;
3047         else if(!strcmp(res->name, "rxht"))
3048                 rx_hthresh = res->value;
3049         else if(!strcmp(res->name, "rxwt"))
3050                 rx_wthresh = res->value;
3051         else {
3052                 printf("Unknown parameter\n");
3053                 return;
3054         }
3055
3056         init_port_config();
3057
3058         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3059 }
3060
3061 cmdline_parse_token_string_t cmd_config_thresh_port =
3062         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3063 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3064         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3065 cmdline_parse_token_string_t cmd_config_thresh_all =
3066         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3067 cmdline_parse_token_string_t cmd_config_thresh_name =
3068         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3069                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3070 cmdline_parse_token_num_t cmd_config_thresh_value =
3071         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3072
3073 cmdline_parse_inst_t cmd_config_thresh = {
3074         .f = cmd_config_thresh_parsed,
3075         .data = NULL,
3076         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3077         .tokens = {
3078                 (void *)&cmd_config_thresh_port,
3079                 (void *)&cmd_config_thresh_keyword,
3080                 (void *)&cmd_config_thresh_all,
3081                 (void *)&cmd_config_thresh_name,
3082                 (void *)&cmd_config_thresh_value,
3083                 NULL,
3084         },
3085 };
3086
3087 /* *** configure free/rs threshold *** */
3088 struct cmd_config_threshold {
3089         cmdline_fixed_string_t port;
3090         cmdline_fixed_string_t keyword;
3091         cmdline_fixed_string_t all;
3092         cmdline_fixed_string_t name;
3093         uint16_t value;
3094 };
3095
3096 static void
3097 cmd_config_threshold_parsed(void *parsed_result,
3098                         __attribute__((unused)) struct cmdline *cl,
3099                         __attribute__((unused)) void *data)
3100 {
3101         struct cmd_config_threshold *res = parsed_result;
3102
3103         if (!all_ports_stopped()) {
3104                 printf("Please stop all ports first\n");
3105                 return;
3106         }
3107
3108         if (!strcmp(res->name, "txfreet"))
3109                 tx_free_thresh = res->value;
3110         else if (!strcmp(res->name, "txrst"))
3111                 tx_rs_thresh = res->value;
3112         else if (!strcmp(res->name, "rxfreet"))
3113                 rx_free_thresh = res->value;
3114         else {
3115                 printf("Unknown parameter\n");
3116                 return;
3117         }
3118
3119         init_port_config();
3120
3121         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3122 }
3123
3124 cmdline_parse_token_string_t cmd_config_threshold_port =
3125         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3126 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3127         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3128                                                                 "config");
3129 cmdline_parse_token_string_t cmd_config_threshold_all =
3130         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3131 cmdline_parse_token_string_t cmd_config_threshold_name =
3132         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3133                                                 "txfreet#txrst#rxfreet");
3134 cmdline_parse_token_num_t cmd_config_threshold_value =
3135         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3136
3137 cmdline_parse_inst_t cmd_config_threshold = {
3138         .f = cmd_config_threshold_parsed,
3139         .data = NULL,
3140         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3141         .tokens = {
3142                 (void *)&cmd_config_threshold_port,
3143                 (void *)&cmd_config_threshold_keyword,
3144                 (void *)&cmd_config_threshold_all,
3145                 (void *)&cmd_config_threshold_name,
3146                 (void *)&cmd_config_threshold_value,
3147                 NULL,
3148         },
3149 };
3150
3151 /* *** stop *** */
3152 struct cmd_stop_result {
3153         cmdline_fixed_string_t stop;
3154 };
3155
3156 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3157                             __attribute__((unused)) struct cmdline *cl,
3158                             __attribute__((unused)) void *data)
3159 {
3160         stop_packet_forwarding();
3161 }
3162
3163 cmdline_parse_token_string_t cmd_stop_stop =
3164         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3165
3166 cmdline_parse_inst_t cmd_stop = {
3167         .f = cmd_stop_parsed,
3168         .data = NULL,
3169         .help_str = "stop: Stop packet forwarding",
3170         .tokens = {
3171                 (void *)&cmd_stop_stop,
3172                 NULL,
3173         },
3174 };
3175
3176 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3177
3178 unsigned int
3179 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3180                 unsigned int *parsed_items, int check_unique_values)
3181 {
3182         unsigned int nb_item;
3183         unsigned int value;
3184         unsigned int i;
3185         unsigned int j;
3186         int value_ok;
3187         char c;
3188
3189         /*
3190          * First parse all items in the list and store their value.
3191          */
3192         value = 0;
3193         nb_item = 0;
3194         value_ok = 0;
3195         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3196                 c = str[i];
3197                 if ((c >= '0') && (c <= '9')) {
3198                         value = (unsigned int) (value * 10 + (c - '0'));
3199                         value_ok = 1;
3200                         continue;
3201                 }
3202                 if (c != ',') {
3203                         printf("character %c is not a decimal digit\n", c);
3204                         return 0;
3205                 }
3206                 if (! value_ok) {
3207                         printf("No valid value before comma\n");
3208                         return 0;
3209                 }
3210                 if (nb_item < max_items) {
3211                         parsed_items[nb_item] = value;
3212                         value_ok = 0;
3213                         value = 0;
3214                 }
3215                 nb_item++;
3216         }
3217         if (nb_item >= max_items) {
3218                 printf("Number of %s = %u > %u (maximum items)\n",
3219                        item_name, nb_item + 1, max_items);
3220                 return 0;
3221         }
3222         parsed_items[nb_item++] = value;
3223         if (! check_unique_values)
3224                 return nb_item;
3225
3226         /*
3227          * Then, check that all values in the list are differents.
3228          * No optimization here...
3229          */
3230         for (i = 0; i < nb_item; i++) {
3231                 for (j = i + 1; j < nb_item; j++) {
3232                         if (parsed_items[j] == parsed_items[i]) {
3233                                 printf("duplicated %s %u at index %u and %u\n",
3234                                        item_name, parsed_items[i], i, j);
3235                                 return 0;
3236                         }
3237                 }
3238         }
3239         return nb_item;
3240 }
3241
3242 struct cmd_set_list_result {
3243         cmdline_fixed_string_t cmd_keyword;
3244         cmdline_fixed_string_t list_name;
3245         cmdline_fixed_string_t list_of_items;
3246 };
3247
3248 static void cmd_set_list_parsed(void *parsed_result,
3249                                 __attribute__((unused)) struct cmdline *cl,
3250                                 __attribute__((unused)) void *data)
3251 {
3252         struct cmd_set_list_result *res;
3253         union {
3254                 unsigned int lcorelist[RTE_MAX_LCORE];
3255                 unsigned int portlist[RTE_MAX_ETHPORTS];
3256         } parsed_items;
3257         unsigned int nb_item;
3258
3259         if (test_done == 0) {
3260                 printf("Please stop forwarding first\n");
3261                 return;
3262         }
3263
3264         res = parsed_result;
3265         if (!strcmp(res->list_name, "corelist")) {
3266                 nb_item = parse_item_list(res->list_of_items, "core",
3267                                           RTE_MAX_LCORE,
3268                                           parsed_items.lcorelist, 1);
3269                 if (nb_item > 0) {
3270                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3271                         fwd_config_setup();
3272                 }
3273                 return;
3274         }
3275         if (!strcmp(res->list_name, "portlist")) {
3276                 nb_item = parse_item_list(res->list_of_items, "port",
3277                                           RTE_MAX_ETHPORTS,
3278                                           parsed_items.portlist, 1);
3279                 if (nb_item > 0) {
3280                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3281                         fwd_config_setup();
3282                 }
3283         }
3284 }
3285
3286 cmdline_parse_token_string_t cmd_set_list_keyword =
3287         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3288                                  "set");
3289 cmdline_parse_token_string_t cmd_set_list_name =
3290         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3291                                  "corelist#portlist");
3292 cmdline_parse_token_string_t cmd_set_list_of_items =
3293         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3294                                  NULL);
3295
3296 cmdline_parse_inst_t cmd_set_fwd_list = {
3297         .f = cmd_set_list_parsed,
3298         .data = NULL,
3299         .help_str = "set corelist|portlist <list0[,list1]*>",
3300         .tokens = {
3301                 (void *)&cmd_set_list_keyword,
3302                 (void *)&cmd_set_list_name,
3303                 (void *)&cmd_set_list_of_items,
3304                 NULL,
3305         },
3306 };
3307
3308 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3309
3310 struct cmd_setmask_result {
3311         cmdline_fixed_string_t set;
3312         cmdline_fixed_string_t mask;
3313         uint64_t hexavalue;
3314 };
3315
3316 static void cmd_set_mask_parsed(void *parsed_result,
3317                                 __attribute__((unused)) struct cmdline *cl,
3318                                 __attribute__((unused)) void *data)
3319 {
3320         struct cmd_setmask_result *res = parsed_result;
3321
3322         if (test_done == 0) {
3323                 printf("Please stop forwarding first\n");
3324                 return;
3325         }
3326         if (!strcmp(res->mask, "coremask")) {
3327                 set_fwd_lcores_mask(res->hexavalue);
3328                 fwd_config_setup();
3329         } else if (!strcmp(res->mask, "portmask")) {
3330                 set_fwd_ports_mask(res->hexavalue);
3331                 fwd_config_setup();
3332         }
3333 }
3334
3335 cmdline_parse_token_string_t cmd_setmask_set =
3336         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3337 cmdline_parse_token_string_t cmd_setmask_mask =
3338         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3339                                  "coremask#portmask");
3340 cmdline_parse_token_num_t cmd_setmask_value =
3341         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3342
3343 cmdline_parse_inst_t cmd_set_fwd_mask = {
3344         .f = cmd_set_mask_parsed,
3345         .data = NULL,
3346         .help_str = "set coremask|portmask <hexadecimal value>",
3347         .tokens = {
3348                 (void *)&cmd_setmask_set,
3349                 (void *)&cmd_setmask_mask,
3350                 (void *)&cmd_setmask_value,
3351                 NULL,
3352         },
3353 };
3354
3355 /*
3356  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3357  */
3358 struct cmd_set_result {
3359         cmdline_fixed_string_t set;
3360         cmdline_fixed_string_t what;
3361         uint16_t value;
3362 };
3363
3364 static void cmd_set_parsed(void *parsed_result,
3365                            __attribute__((unused)) struct cmdline *cl,
3366                            __attribute__((unused)) void *data)
3367 {
3368         struct cmd_set_result *res = parsed_result;
3369         if (!strcmp(res->what, "nbport")) {
3370                 set_fwd_ports_number(res->value);
3371                 fwd_config_setup();
3372         } else if (!strcmp(res->what, "nbcore")) {
3373                 set_fwd_lcores_number(res->value);
3374                 fwd_config_setup();
3375         } else if (!strcmp(res->what, "burst"))
3376                 set_nb_pkt_per_burst(res->value);
3377         else if (!strcmp(res->what, "verbose"))
3378                 set_verbose_level(res->value);
3379 }
3380
3381 cmdline_parse_token_string_t cmd_set_set =
3382         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3383 cmdline_parse_token_string_t cmd_set_what =
3384         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3385                                  "nbport#nbcore#burst#verbose");
3386 cmdline_parse_token_num_t cmd_set_value =
3387         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3388
3389 cmdline_parse_inst_t cmd_set_numbers = {
3390         .f = cmd_set_parsed,
3391         .data = NULL,
3392         .help_str = "set nbport|nbcore|burst|verbose <value>",
3393         .tokens = {
3394                 (void *)&cmd_set_set,
3395                 (void *)&cmd_set_what,
3396                 (void *)&cmd_set_value,
3397                 NULL,
3398         },
3399 };
3400
3401 /* *** SET LOG LEVEL CONFIGURATION *** */
3402
3403 struct cmd_set_log_result {
3404         cmdline_fixed_string_t set;
3405         cmdline_fixed_string_t log;
3406         cmdline_fixed_string_t type;
3407         uint32_t level;
3408 };
3409
3410 static void
3411 cmd_set_log_parsed(void *parsed_result,
3412                    __attribute__((unused)) struct cmdline *cl,
3413                    __attribute__((unused)) void *data)
3414 {
3415         struct cmd_set_log_result *res;
3416         int ret;
3417
3418         res = parsed_result;
3419         if (!strcmp(res->type, "global"))
3420                 rte_log_set_global_level(res->level);
3421         else {
3422                 ret = rte_log_set_level_regexp(res->type, res->level);
3423                 if (ret < 0)
3424                         printf("Unable to set log level\n");
3425         }
3426 }
3427
3428 cmdline_parse_token_string_t cmd_set_log_set =
3429         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3430 cmdline_parse_token_string_t cmd_set_log_log =
3431         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3432 cmdline_parse_token_string_t cmd_set_log_type =
3433         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3434 cmdline_parse_token_num_t cmd_set_log_level =
3435         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3436
3437 cmdline_parse_inst_t cmd_set_log = {
3438         .f = cmd_set_log_parsed,
3439         .data = NULL,
3440         .help_str = "set log global|<type> <level>",
3441         .tokens = {
3442                 (void *)&cmd_set_log_set,
3443                 (void *)&cmd_set_log_log,
3444                 (void *)&cmd_set_log_type,
3445                 (void *)&cmd_set_log_level,
3446                 NULL,
3447         },
3448 };
3449
3450 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3451
3452 struct cmd_set_txpkts_result {
3453         cmdline_fixed_string_t cmd_keyword;
3454         cmdline_fixed_string_t txpkts;
3455         cmdline_fixed_string_t seg_lengths;
3456 };
3457
3458 static void
3459 cmd_set_txpkts_parsed(void *parsed_result,
3460                       __attribute__((unused)) struct cmdline *cl,
3461                       __attribute__((unused)) void *data)
3462 {
3463         struct cmd_set_txpkts_result *res;
3464         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3465         unsigned int nb_segs;
3466
3467         res = parsed_result;
3468         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3469                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3470         if (nb_segs > 0)
3471                 set_tx_pkt_segments(seg_lengths, nb_segs);
3472 }
3473
3474 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3475         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3476                                  cmd_keyword, "set");
3477 cmdline_parse_token_string_t cmd_set_txpkts_name =
3478         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3479                                  txpkts, "txpkts");
3480 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3481         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3482                                  seg_lengths, NULL);
3483
3484 cmdline_parse_inst_t cmd_set_txpkts = {
3485         .f = cmd_set_txpkts_parsed,
3486         .data = NULL,
3487         .help_str = "set txpkts <len0[,len1]*>",
3488         .tokens = {
3489                 (void *)&cmd_set_txpkts_keyword,
3490                 (void *)&cmd_set_txpkts_name,
3491                 (void *)&cmd_set_txpkts_lengths,
3492                 NULL,
3493         },
3494 };
3495
3496 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3497
3498 struct cmd_set_txsplit_result {
3499         cmdline_fixed_string_t cmd_keyword;
3500         cmdline_fixed_string_t txsplit;
3501         cmdline_fixed_string_t mode;
3502 };
3503
3504 static void
3505 cmd_set_txsplit_parsed(void *parsed_result,
3506                       __attribute__((unused)) struct cmdline *cl,
3507                       __attribute__((unused)) void *data)
3508 {
3509         struct cmd_set_txsplit_result *res;
3510
3511         res = parsed_result;
3512         set_tx_pkt_split(res->mode);
3513 }
3514
3515 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3516         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3517                                  cmd_keyword, "set");
3518 cmdline_parse_token_string_t cmd_set_txsplit_name =
3519         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3520                                  txsplit, "txsplit");
3521 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3522         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3523                                  mode, NULL);
3524
3525 cmdline_parse_inst_t cmd_set_txsplit = {
3526         .f = cmd_set_txsplit_parsed,
3527         .data = NULL,
3528         .help_str = "set txsplit on|off|rand",
3529         .tokens = {
3530                 (void *)&cmd_set_txsplit_keyword,
3531                 (void *)&cmd_set_txsplit_name,
3532                 (void *)&cmd_set_txsplit_mode,
3533                 NULL,
3534         },
3535 };
3536
3537 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3538 struct cmd_rx_vlan_filter_all_result {
3539         cmdline_fixed_string_t rx_vlan;
3540         cmdline_fixed_string_t what;
3541         cmdline_fixed_string_t all;
3542         portid_t port_id;
3543 };
3544
3545 static void
3546 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3547                               __attribute__((unused)) struct cmdline *cl,
3548                               __attribute__((unused)) void *data)
3549 {
3550         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3551
3552         if (!strcmp(res->what, "add"))
3553                 rx_vlan_all_filter_set(res->port_id, 1);
3554         else
3555                 rx_vlan_all_filter_set(res->port_id, 0);
3556 }
3557
3558 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3559         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3560                                  rx_vlan, "rx_vlan");
3561 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3562         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3563                                  what, "add#rm");
3564 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3565         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3566                                  all, "all");
3567 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3568         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3569                               port_id, UINT16);
3570
3571 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3572         .f = cmd_rx_vlan_filter_all_parsed,
3573         .data = NULL,
3574         .help_str = "rx_vlan add|rm all <port_id>: "
3575                 "Add/Remove all identifiers to/from the set of VLAN "
3576                 "identifiers filtered by a port",
3577         .tokens = {
3578                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3579                 (void *)&cmd_rx_vlan_filter_all_what,
3580                 (void *)&cmd_rx_vlan_filter_all_all,
3581                 (void *)&cmd_rx_vlan_filter_all_portid,
3582                 NULL,
3583         },
3584 };
3585
3586 /* *** VLAN OFFLOAD SET ON A PORT *** */
3587 struct cmd_vlan_offload_result {
3588         cmdline_fixed_string_t vlan;
3589         cmdline_fixed_string_t set;
3590         cmdline_fixed_string_t vlan_type;
3591         cmdline_fixed_string_t what;
3592         cmdline_fixed_string_t on;
3593         cmdline_fixed_string_t port_id;
3594 };
3595
3596 static void
3597 cmd_vlan_offload_parsed(void *parsed_result,
3598                           __attribute__((unused)) struct cmdline *cl,
3599                           __attribute__((unused)) void *data)
3600 {
3601         int on;
3602         struct cmd_vlan_offload_result *res = parsed_result;
3603         char *str;
3604         int i, len = 0;
3605         portid_t port_id = 0;
3606         unsigned int tmp;
3607
3608         str = res->port_id;
3609         len = strnlen(str, STR_TOKEN_SIZE);
3610         i = 0;
3611         /* Get port_id first */
3612         while(i < len){
3613                 if(str[i] == ',')
3614                         break;
3615
3616                 i++;
3617         }
3618         str[i]='\0';
3619         tmp = strtoul(str, NULL, 0);
3620         /* If port_id greater that what portid_t can represent, return */
3621         if(tmp >= RTE_MAX_ETHPORTS)
3622                 return;
3623         port_id = (portid_t)tmp;
3624
3625         if (!strcmp(res->on, "on"))
3626                 on = 1;
3627         else
3628                 on = 0;
3629
3630         if (!strcmp(res->what, "strip"))
3631                 rx_vlan_strip_set(port_id,  on);
3632         else if(!strcmp(res->what, "stripq")){
3633                 uint16_t queue_id = 0;
3634
3635                 /* No queue_id, return */
3636                 if(i + 1 >= len) {
3637                         printf("must specify (port,queue_id)\n");
3638                         return;
3639                 }
3640                 tmp = strtoul(str + i + 1, NULL, 0);
3641                 /* If queue_id greater that what 16-bits can represent, return */
3642                 if(tmp > 0xffff)
3643                         return;
3644
3645                 queue_id = (uint16_t)tmp;
3646                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3647         }
3648         else if (!strcmp(res->what, "filter"))
3649                 rx_vlan_filter_set(port_id, on);
3650         else
3651                 vlan_extend_set(port_id, on);
3652
3653         return;
3654 }
3655
3656 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3657         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3658                                  vlan, "vlan");
3659 cmdline_parse_token_string_t cmd_vlan_offload_set =
3660         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3661                                  set, "set");
3662 cmdline_parse_token_string_t cmd_vlan_offload_what =
3663         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3664                                  what, "strip#filter#qinq#stripq");
3665 cmdline_parse_token_string_t cmd_vlan_offload_on =
3666         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3667                               on, "on#off");
3668 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3669         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3670                               port_id, NULL);
3671
3672 cmdline_parse_inst_t cmd_vlan_offload = {
3673         .f = cmd_vlan_offload_parsed,
3674         .data = NULL,
3675         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3676                 "<port_id[,queue_id]>: "
3677                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3678         .tokens = {
3679                 (void *)&cmd_vlan_offload_vlan,
3680                 (void *)&cmd_vlan_offload_set,
3681                 (void *)&cmd_vlan_offload_what,
3682                 (void *)&cmd_vlan_offload_on,
3683                 (void *)&cmd_vlan_offload_portid,
3684                 NULL,
3685         },
3686 };
3687
3688 /* *** VLAN TPID SET ON A PORT *** */
3689 struct cmd_vlan_tpid_result {
3690         cmdline_fixed_string_t vlan;
3691         cmdline_fixed_string_t set;
3692         cmdline_fixed_string_t vlan_type;
3693         cmdline_fixed_string_t what;
3694         uint16_t tp_id;
3695         portid_t port_id;
3696 };
3697
3698 static void
3699 cmd_vlan_tpid_parsed(void *parsed_result,
3700                           __attribute__((unused)) struct cmdline *cl,
3701                           __attribute__((unused)) void *data)
3702 {
3703         struct cmd_vlan_tpid_result *res = parsed_result;
3704         enum rte_vlan_type vlan_type;
3705
3706         if (!strcmp(res->vlan_type, "inner"))
3707                 vlan_type = ETH_VLAN_TYPE_INNER;
3708         else if (!strcmp(res->vlan_type, "outer"))
3709                 vlan_type = ETH_VLAN_TYPE_OUTER;
3710         else {
3711                 printf("Unknown vlan type\n");
3712                 return;
3713         }
3714         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3715 }
3716
3717 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3718         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3719                                  vlan, "vlan");
3720 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3721         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3722                                  set, "set");
3723 cmdline_parse_token_string_t cmd_vlan_type =
3724         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3725                                  vlan_type, "inner#outer");
3726 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3727         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3728                                  what, "tpid");
3729 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3730         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3731                               tp_id, UINT16);
3732 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3733         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3734                               port_id, UINT16);
3735
3736 cmdline_parse_inst_t cmd_vlan_tpid = {
3737         .f = cmd_vlan_tpid_parsed,
3738         .data = NULL,
3739         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3740                 "Set the VLAN Ether type",
3741         .tokens = {
3742                 (void *)&cmd_vlan_tpid_vlan,
3743                 (void *)&cmd_vlan_tpid_set,
3744                 (void *)&cmd_vlan_type,
3745                 (void *)&cmd_vlan_tpid_what,
3746                 (void *)&cmd_vlan_tpid_tpid,
3747                 (void *)&cmd_vlan_tpid_portid,
3748                 NULL,
3749         },
3750 };
3751
3752 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3753 struct cmd_rx_vlan_filter_result {
3754         cmdline_fixed_string_t rx_vlan;
3755         cmdline_fixed_string_t what;
3756         uint16_t vlan_id;
3757         portid_t port_id;
3758 };
3759
3760 static void
3761 cmd_rx_vlan_filter_parsed(void *parsed_result,
3762                           __attribute__((unused)) struct cmdline *cl,
3763                           __attribute__((unused)) void *data)
3764 {
3765         struct cmd_rx_vlan_filter_result *res = parsed_result;
3766
3767         if (!strcmp(res->what, "add"))
3768                 rx_vft_set(res->port_id, res->vlan_id, 1);
3769         else
3770                 rx_vft_set(res->port_id, res->vlan_id, 0);
3771 }
3772
3773 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3774         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3775                                  rx_vlan, "rx_vlan");
3776 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3777         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3778                                  what, "add#rm");
3779 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3780         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3781                               vlan_id, UINT16);
3782 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3783         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3784                               port_id, UINT16);
3785
3786 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3787         .f = cmd_rx_vlan_filter_parsed,
3788         .data = NULL,
3789         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3790                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3791                 "identifiers filtered by a port",
3792         .tokens = {
3793                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3794                 (void *)&cmd_rx_vlan_filter_what,
3795                 (void *)&cmd_rx_vlan_filter_vlanid,
3796                 (void *)&cmd_rx_vlan_filter_portid,
3797                 NULL,
3798         },
3799 };
3800
3801 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3802 struct cmd_tx_vlan_set_result {
3803         cmdline_fixed_string_t tx_vlan;
3804         cmdline_fixed_string_t set;
3805         portid_t port_id;
3806         uint16_t vlan_id;
3807 };
3808
3809 static void
3810 cmd_tx_vlan_set_parsed(void *parsed_result,
3811                        __attribute__((unused)) struct cmdline *cl,
3812                        __attribute__((unused)) void *data)
3813 {
3814         struct cmd_tx_vlan_set_result *res = parsed_result;
3815
3816         if (!port_is_stopped(res->port_id)) {
3817                 printf("Please stop port %d first\n", res->port_id);
3818                 return;
3819         }
3820
3821         tx_vlan_set(res->port_id, res->vlan_id);
3822
3823         cmd_reconfig_device_queue(res->port_id, 1, 1);
3824 }
3825
3826 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3827         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3828                                  tx_vlan, "tx_vlan");
3829 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3830         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3831                                  set, "set");
3832 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3833         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3834                               port_id, UINT16);
3835 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3836         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3837                               vlan_id, UINT16);
3838
3839 cmdline_parse_inst_t cmd_tx_vlan_set = {
3840         .f = cmd_tx_vlan_set_parsed,
3841         .data = NULL,
3842         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3843                 "Enable hardware insertion of a single VLAN header "
3844                 "with a given TAG Identifier in packets sent on a port",
3845         .tokens = {
3846                 (void *)&cmd_tx_vlan_set_tx_vlan,
3847                 (void *)&cmd_tx_vlan_set_set,
3848                 (void *)&cmd_tx_vlan_set_portid,
3849                 (void *)&cmd_tx_vlan_set_vlanid,
3850                 NULL,
3851         },
3852 };
3853
3854 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3855 struct cmd_tx_vlan_set_qinq_result {
3856         cmdline_fixed_string_t tx_vlan;
3857         cmdline_fixed_string_t set;
3858         portid_t port_id;
3859         uint16_t vlan_id;
3860         uint16_t vlan_id_outer;
3861 };
3862
3863 static void
3864 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3865                             __attribute__((unused)) struct cmdline *cl,
3866                             __attribute__((unused)) void *data)
3867 {
3868         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3869
3870         if (!port_is_stopped(res->port_id)) {
3871                 printf("Please stop port %d first\n", res->port_id);
3872                 return;
3873         }
3874
3875         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3876
3877         cmd_reconfig_device_queue(res->port_id, 1, 1);
3878 }
3879
3880 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3881         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3882                 tx_vlan, "tx_vlan");
3883 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3884         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3885                 set, "set");
3886 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3887         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3888                 port_id, UINT16);
3889 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3890         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3891                 vlan_id, UINT16);
3892 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3893         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3894                 vlan_id_outer, UINT16);
3895
3896 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3897         .f = cmd_tx_vlan_set_qinq_parsed,
3898         .data = NULL,
3899         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3900                 "Enable hardware insertion of double VLAN header "
3901                 "with given TAG Identifiers in packets sent on a port",
3902         .tokens = {
3903                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3904                 (void *)&cmd_tx_vlan_set_qinq_set,
3905                 (void *)&cmd_tx_vlan_set_qinq_portid,
3906                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3907                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3908                 NULL,
3909         },
3910 };
3911
3912 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3913 struct cmd_tx_vlan_set_pvid_result {
3914         cmdline_fixed_string_t tx_vlan;
3915         cmdline_fixed_string_t set;
3916         cmdline_fixed_string_t pvid;
3917         portid_t port_id;
3918         uint16_t vlan_id;
3919         cmdline_fixed_string_t mode;
3920 };
3921
3922 static void
3923 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3924                             __attribute__((unused)) struct cmdline *cl,
3925                             __attribute__((unused)) void *data)
3926 {
3927         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3928
3929         if (strcmp(res->mode, "on") == 0)
3930                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3931         else
3932                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3933 }
3934
3935 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3936         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3937                                  tx_vlan, "tx_vlan");
3938 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3939         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3940                                  set, "set");
3941 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3942         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3943                                  pvid, "pvid");
3944 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3945         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3946                              port_id, UINT16);
3947 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3948         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3949                               vlan_id, UINT16);
3950 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3951         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3952                                  mode, "on#off");
3953
3954 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3955         .f = cmd_tx_vlan_set_pvid_parsed,
3956         .data = NULL,
3957         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3958         .tokens = {
3959                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3960                 (void *)&cmd_tx_vlan_set_pvid_set,
3961                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3962                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3963                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3964                 (void *)&cmd_tx_vlan_set_pvid_mode,
3965                 NULL,
3966         },
3967 };
3968
3969 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3970 struct cmd_tx_vlan_reset_result {
3971         cmdline_fixed_string_t tx_vlan;
3972         cmdline_fixed_string_t reset;
3973         portid_t port_id;
3974 };
3975
3976 static void
3977 cmd_tx_vlan_reset_parsed(void *parsed_result,
3978                          __attribute__((unused)) struct cmdline *cl,
3979                          __attribute__((unused)) void *data)
3980 {
3981         struct cmd_tx_vlan_reset_result *res = parsed_result;
3982
3983         if (!port_is_stopped(res->port_id)) {
3984                 printf("Please stop port %d first\n", res->port_id);
3985                 return;
3986         }
3987
3988         tx_vlan_reset(res->port_id);
3989
3990         cmd_reconfig_device_queue(res->port_id, 1, 1);
3991 }
3992
3993 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3994         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3995                                  tx_vlan, "tx_vlan");
3996 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3997         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3998                                  reset, "reset");
3999 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4000         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4001                               port_id, UINT16);
4002
4003 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4004         .f = cmd_tx_vlan_reset_parsed,
4005         .data = NULL,
4006         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4007                 "VLAN header in packets sent on a port",
4008         .tokens = {
4009                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4010                 (void *)&cmd_tx_vlan_reset_reset,
4011                 (void *)&cmd_tx_vlan_reset_portid,
4012                 NULL,
4013         },
4014 };
4015
4016
4017 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4018 struct cmd_csum_result {
4019         cmdline_fixed_string_t csum;
4020         cmdline_fixed_string_t mode;
4021         cmdline_fixed_string_t proto;
4022         cmdline_fixed_string_t hwsw;
4023         portid_t port_id;
4024 };
4025
4026 static void
4027 csum_show(int port_id)
4028 {
4029         struct rte_eth_dev_info dev_info;
4030         uint64_t tx_offloads;
4031
4032         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4033         printf("Parse tunnel is %s\n",
4034                 (ports[port_id].parse_tunnel) ? "on" : "off");
4035         printf("IP checksum offload is %s\n",
4036                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4037         printf("UDP checksum offload is %s\n",
4038                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4039         printf("TCP checksum offload is %s\n",
4040                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4041         printf("SCTP checksum offload is %s\n",
4042                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4043         printf("Outer-Ip checksum offload is %s\n",
4044                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4045
4046         /* display warnings if configuration is not supported by the NIC */
4047         rte_eth_dev_info_get(port_id, &dev_info);
4048         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4049                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4050                 printf("Warning: hardware IP checksum enabled but not "
4051                         "supported by port %d\n", port_id);
4052         }
4053         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4054                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4055                 printf("Warning: hardware UDP checksum enabled but not "
4056                         "supported by port %d\n", port_id);
4057         }
4058         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4059                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4060                 printf("Warning: hardware TCP checksum enabled but not "
4061                         "supported by port %d\n", port_id);
4062         }
4063         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4064                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4065                 printf("Warning: hardware SCTP checksum enabled but not "
4066                         "supported by port %d\n", port_id);
4067         }
4068         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4069                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4070                 printf("Warning: hardware outer IP checksum enabled but not "
4071                         "supported by port %d\n", port_id);
4072         }
4073 }
4074
4075 static void
4076 cmd_csum_parsed(void *parsed_result,
4077                        __attribute__((unused)) struct cmdline *cl,
4078                        __attribute__((unused)) void *data)
4079 {
4080         struct cmd_csum_result *res = parsed_result;
4081         int hw = 0;
4082         uint64_t csum_offloads = 0;
4083         struct rte_eth_dev_info dev_info;
4084
4085         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4086                 printf("invalid port %d\n", res->port_id);
4087                 return;
4088         }
4089         if (!port_is_stopped(res->port_id)) {
4090                 printf("Please stop port %d first\n", res->port_id);
4091                 return;
4092         }
4093
4094         rte_eth_dev_info_get(res->port_id, &dev_info);
4095         if (!strcmp(res->mode, "set")) {
4096
4097                 if (!strcmp(res->hwsw, "hw"))
4098                         hw = 1;
4099
4100                 if (!strcmp(res->proto, "ip")) {
4101                         if (hw == 0 || (dev_info.tx_offload_capa &
4102                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4103                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4104                         } else {
4105                                 printf("IP checksum offload is not supported "
4106                                        "by port %u\n", res->port_id);
4107                         }
4108                 } else if (!strcmp(res->proto, "udp")) {
4109                         if (hw == 0 || (dev_info.tx_offload_capa &
4110                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4111                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4112                         } else {
4113                                 printf("UDP checksum offload is not supported "
4114                                        "by port %u\n", res->port_id);
4115                         }
4116                 } else if (!strcmp(res->proto, "tcp")) {
4117                         if (hw == 0 || (dev_info.tx_offload_capa &
4118                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4119                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4120                         } else {
4121                                 printf("TCP checksum offload is not supported "
4122                                        "by port %u\n", res->port_id);
4123                         }
4124                 } else if (!strcmp(res->proto, "sctp")) {
4125                         if (hw == 0 || (dev_info.tx_offload_capa &
4126                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4127                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4128                         } else {
4129                                 printf("SCTP checksum offload is not supported "
4130                                        "by port %u\n", res->port_id);
4131                         }
4132                 } else if (!strcmp(res->proto, "outer-ip")) {
4133                         if (hw == 0 || (dev_info.tx_offload_capa &
4134                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4135                                 csum_offloads |=
4136                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4137                         } else {
4138                                 printf("Outer IP checksum offload is not "
4139                                        "supported by port %u\n", res->port_id);
4140                         }
4141                 }
4142
4143                 if (hw) {
4144                         ports[res->port_id].dev_conf.txmode.offloads |=
4145                                                         csum_offloads;
4146                 } else {
4147                         ports[res->port_id].dev_conf.txmode.offloads &=
4148                                                         (~csum_offloads);
4149                 }
4150         }
4151         csum_show(res->port_id);
4152
4153         cmd_reconfig_device_queue(res->port_id, 1, 1);
4154 }
4155
4156 cmdline_parse_token_string_t cmd_csum_csum =
4157         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4158                                 csum, "csum");
4159 cmdline_parse_token_string_t cmd_csum_mode =
4160         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4161                                 mode, "set");
4162 cmdline_parse_token_string_t cmd_csum_proto =
4163         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4164                                 proto, "ip#tcp#udp#sctp#outer-ip");
4165 cmdline_parse_token_string_t cmd_csum_hwsw =
4166         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4167                                 hwsw, "hw#sw");
4168 cmdline_parse_token_num_t cmd_csum_portid =
4169         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4170                                 port_id, UINT16);
4171
4172 cmdline_parse_inst_t cmd_csum_set = {
4173         .f = cmd_csum_parsed,
4174         .data = NULL,
4175         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4176                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4177                 "using csum forward engine",
4178         .tokens = {
4179                 (void *)&cmd_csum_csum,
4180                 (void *)&cmd_csum_mode,
4181                 (void *)&cmd_csum_proto,
4182                 (void *)&cmd_csum_hwsw,
4183                 (void *)&cmd_csum_portid,
4184                 NULL,
4185         },
4186 };
4187
4188 cmdline_parse_token_string_t cmd_csum_mode_show =
4189         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4190                                 mode, "show");
4191
4192 cmdline_parse_inst_t cmd_csum_show = {
4193         .f = cmd_csum_parsed,
4194         .data = NULL,
4195         .help_str = "csum show <port_id>: Show checksum offload configuration",
4196         .tokens = {
4197                 (void *)&cmd_csum_csum,
4198                 (void *)&cmd_csum_mode_show,
4199                 (void *)&cmd_csum_portid,
4200                 NULL,
4201         },
4202 };
4203
4204 /* Enable/disable tunnel parsing */
4205 struct cmd_csum_tunnel_result {
4206         cmdline_fixed_string_t csum;
4207         cmdline_fixed_string_t parse;
4208         cmdline_fixed_string_t onoff;
4209         portid_t port_id;
4210 };
4211
4212 static void
4213 cmd_csum_tunnel_parsed(void *parsed_result,
4214                        __attribute__((unused)) struct cmdline *cl,
4215                        __attribute__((unused)) void *data)
4216 {
4217         struct cmd_csum_tunnel_result *res = parsed_result;
4218
4219         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4220                 return;
4221
4222         if (!strcmp(res->onoff, "on"))
4223                 ports[res->port_id].parse_tunnel = 1;
4224         else
4225                 ports[res->port_id].parse_tunnel = 0;
4226
4227         csum_show(res->port_id);
4228 }
4229
4230 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4231         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4232                                 csum, "csum");
4233 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4234         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4235                                 parse, "parse_tunnel");
4236 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4237         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4238                                 onoff, "on#off");
4239 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4240         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4241                                 port_id, UINT16);
4242
4243 cmdline_parse_inst_t cmd_csum_tunnel = {
4244         .f = cmd_csum_tunnel_parsed,
4245         .data = NULL,
4246         .help_str = "csum parse_tunnel on|off <port_id>: "
4247                 "Enable/Disable parsing of tunnels for csum engine",
4248         .tokens = {
4249                 (void *)&cmd_csum_tunnel_csum,
4250                 (void *)&cmd_csum_tunnel_parse,
4251                 (void *)&cmd_csum_tunnel_onoff,
4252                 (void *)&cmd_csum_tunnel_portid,
4253                 NULL,
4254         },
4255 };
4256
4257 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4258 struct cmd_tso_set_result {
4259         cmdline_fixed_string_t tso;
4260         cmdline_fixed_string_t mode;
4261         uint16_t tso_segsz;
4262         portid_t port_id;
4263 };
4264
4265 static void
4266 cmd_tso_set_parsed(void *parsed_result,
4267                        __attribute__((unused)) struct cmdline *cl,
4268                        __attribute__((unused)) void *data)
4269 {
4270         struct cmd_tso_set_result *res = parsed_result;
4271         struct rte_eth_dev_info dev_info;
4272
4273         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4274                 return;
4275         if (!port_is_stopped(res->port_id)) {
4276                 printf("Please stop port %d first\n", res->port_id);
4277                 return;
4278         }
4279
4280         if (!strcmp(res->mode, "set"))
4281                 ports[res->port_id].tso_segsz = res->tso_segsz;
4282
4283         rte_eth_dev_info_get(res->port_id, &dev_info);
4284         if ((ports[res->port_id].tso_segsz != 0) &&
4285                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4286                 printf("Error: TSO is not supported by port %d\n",
4287                        res->port_id);
4288                 return;
4289         }
4290
4291         if (ports[res->port_id].tso_segsz == 0) {
4292                 ports[res->port_id].dev_conf.txmode.offloads &=
4293                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4294                 printf("TSO for non-tunneled packets is disabled\n");
4295         } else {
4296                 ports[res->port_id].dev_conf.txmode.offloads |=
4297                                                 DEV_TX_OFFLOAD_TCP_TSO;
4298                 printf("TSO segment size for non-tunneled packets is %d\n",
4299                         ports[res->port_id].tso_segsz);
4300         }
4301
4302         /* display warnings if configuration is not supported by the NIC */
4303         rte_eth_dev_info_get(res->port_id, &dev_info);
4304         if ((ports[res->port_id].tso_segsz != 0) &&
4305                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4306                 printf("Warning: TSO enabled but not "
4307                         "supported by port %d\n", res->port_id);
4308         }
4309
4310         cmd_reconfig_device_queue(res->port_id, 1, 1);
4311 }
4312
4313 cmdline_parse_token_string_t cmd_tso_set_tso =
4314         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4315                                 tso, "tso");
4316 cmdline_parse_token_string_t cmd_tso_set_mode =
4317         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4318                                 mode, "set");
4319 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4320         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4321                                 tso_segsz, UINT16);
4322 cmdline_parse_token_num_t cmd_tso_set_portid =
4323         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4324                                 port_id, UINT16);
4325
4326 cmdline_parse_inst_t cmd_tso_set = {
4327         .f = cmd_tso_set_parsed,
4328         .data = NULL,
4329         .help_str = "tso set <tso_segsz> <port_id>: "
4330                 "Set TSO segment size of non-tunneled packets for csum engine "
4331                 "(0 to disable)",
4332         .tokens = {
4333                 (void *)&cmd_tso_set_tso,
4334                 (void *)&cmd_tso_set_mode,
4335                 (void *)&cmd_tso_set_tso_segsz,
4336                 (void *)&cmd_tso_set_portid,
4337                 NULL,
4338         },
4339 };
4340
4341 cmdline_parse_token_string_t cmd_tso_show_mode =
4342         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4343                                 mode, "show");
4344
4345
4346 cmdline_parse_inst_t cmd_tso_show = {
4347         .f = cmd_tso_set_parsed,
4348         .data = NULL,
4349         .help_str = "tso show <port_id>: "
4350                 "Show TSO segment size of non-tunneled packets for csum engine",
4351         .tokens = {
4352                 (void *)&cmd_tso_set_tso,
4353                 (void *)&cmd_tso_show_mode,
4354                 (void *)&cmd_tso_set_portid,
4355                 NULL,
4356         },
4357 };
4358
4359 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4360 struct cmd_tunnel_tso_set_result {
4361         cmdline_fixed_string_t tso;
4362         cmdline_fixed_string_t mode;
4363         uint16_t tso_segsz;
4364         portid_t port_id;
4365 };
4366
4367 static struct rte_eth_dev_info
4368 check_tunnel_tso_nic_support(portid_t port_id)
4369 {
4370         struct rte_eth_dev_info dev_info;
4371
4372         rte_eth_dev_info_get(port_id, &dev_info);
4373         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4374                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4375                        "not enabled for port %d\n", port_id);
4376         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4377                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4378                        "not enabled for port %d\n", port_id);
4379         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4380                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4381                        "not enabled for port %d\n", port_id);
4382         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4383                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4384                        "not enabled for port %d\n", port_id);
4385         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4386                 printf("Warning: IP TUNNEL TSO not supported therefore "
4387                        "not enabled for port %d\n", port_id);
4388         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4389                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4390                        "not enabled for port %d\n", port_id);
4391         return dev_info;
4392 }
4393
4394 static void
4395 cmd_tunnel_tso_set_parsed(void *parsed_result,
4396                           __attribute__((unused)) struct cmdline *cl,
4397                           __attribute__((unused)) void *data)
4398 {
4399         struct cmd_tunnel_tso_set_result *res = parsed_result;
4400         struct rte_eth_dev_info dev_info;
4401
4402         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4403                 return;
4404         if (!port_is_stopped(res->port_id)) {
4405                 printf("Please stop port %d first\n", res->port_id);
4406                 return;
4407         }
4408
4409         if (!strcmp(res->mode, "set"))
4410                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4411
4412         dev_info = check_tunnel_tso_nic_support(res->port_id);
4413         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4414                 ports[res->port_id].dev_conf.txmode.offloads &=
4415                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4416                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4417                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4418                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4419                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4420                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4421                 printf("TSO for tunneled packets is disabled\n");
4422         } else {
4423                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4424                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4425                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4426                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4427                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4428                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4429
4430                 ports[res->port_id].dev_conf.txmode.offloads |=
4431                         (tso_offloads & dev_info.tx_offload_capa);
4432                 printf("TSO segment size for tunneled packets is %d\n",
4433                         ports[res->port_id].tunnel_tso_segsz);
4434
4435                 /* Below conditions are needed to make it work:
4436                  * (1) tunnel TSO is supported by the NIC;
4437                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4438                  * are recognized;
4439                  * (3) for tunneled pkts with outer L3 of IPv4,
4440                  * "csum set outer-ip" must be set to hw, because after tso,
4441                  * total_len of outer IP header is changed, and the checksum
4442                  * of outer IP header calculated by sw should be wrong; that
4443                  * is not necessary for IPv6 tunneled pkts because there's no
4444                  * checksum in IP header anymore.
4445                  */
4446
4447                 if (!ports[res->port_id].parse_tunnel)
4448                         printf("Warning: csum parse_tunnel must be set "
4449                                 "so that tunneled packets are recognized\n");
4450                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4451                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4452                         printf("Warning: csum set outer-ip must be set to hw "
4453                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4454         }
4455
4456         cmd_reconfig_device_queue(res->port_id, 1, 1);
4457 }
4458
4459 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4460         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4461                                 tso, "tunnel_tso");
4462 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4463         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4464                                 mode, "set");
4465 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4466         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4467                                 tso_segsz, UINT16);
4468 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4469         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4470                                 port_id, UINT16);
4471
4472 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4473         .f = cmd_tunnel_tso_set_parsed,
4474         .data = NULL,
4475         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4476                 "Set TSO segment size of tunneled packets for csum engine "
4477                 "(0 to disable)",
4478         .tokens = {
4479                 (void *)&cmd_tunnel_tso_set_tso,
4480                 (void *)&cmd_tunnel_tso_set_mode,
4481                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4482                 (void *)&cmd_tunnel_tso_set_portid,
4483                 NULL,
4484         },
4485 };
4486
4487 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4488         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4489                                 mode, "show");
4490
4491
4492 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4493         .f = cmd_tunnel_tso_set_parsed,
4494         .data = NULL,
4495         .help_str = "tunnel_tso show <port_id> "
4496                 "Show TSO segment size of tunneled packets for csum engine",
4497         .tokens = {
4498                 (void *)&cmd_tunnel_tso_set_tso,
4499                 (void *)&cmd_tunnel_tso_show_mode,
4500                 (void *)&cmd_tunnel_tso_set_portid,
4501                 NULL,
4502         },
4503 };
4504
4505 /* *** SET GRO FOR A PORT *** */
4506 struct cmd_gro_enable_result {
4507         cmdline_fixed_string_t cmd_set;
4508         cmdline_fixed_string_t cmd_port;
4509         cmdline_fixed_string_t cmd_keyword;
4510         cmdline_fixed_string_t cmd_onoff;
4511         portid_t cmd_pid;
4512 };
4513
4514 static void
4515 cmd_gro_enable_parsed(void *parsed_result,
4516                 __attribute__((unused)) struct cmdline *cl,
4517                 __attribute__((unused)) void *data)
4518 {
4519         struct cmd_gro_enable_result *res;
4520
4521         res = parsed_result;
4522         if (!strcmp(res->cmd_keyword, "gro"))
4523                 setup_gro(res->cmd_onoff, res->cmd_pid);
4524 }
4525
4526 cmdline_parse_token_string_t cmd_gro_enable_set =
4527         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4528                         cmd_set, "set");
4529 cmdline_parse_token_string_t cmd_gro_enable_port =
4530         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4531                         cmd_keyword, "port");
4532 cmdline_parse_token_num_t cmd_gro_enable_pid =
4533         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4534                         cmd_pid, UINT16);
4535 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4536         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4537                         cmd_keyword, "gro");
4538 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4539         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4540                         cmd_onoff, "on#off");
4541
4542 cmdline_parse_inst_t cmd_gro_enable = {
4543         .f = cmd_gro_enable_parsed,
4544         .data = NULL,
4545         .help_str = "set port <port_id> gro on|off",
4546         .tokens = {
4547                 (void *)&cmd_gro_enable_set,
4548                 (void *)&cmd_gro_enable_port,
4549                 (void *)&cmd_gro_enable_pid,
4550                 (void *)&cmd_gro_enable_keyword,
4551                 (void *)&cmd_gro_enable_onoff,
4552                 NULL,
4553         },
4554 };
4555
4556 /* *** DISPLAY GRO CONFIGURATION *** */
4557 struct cmd_gro_show_result {
4558         cmdline_fixed_string_t cmd_show;
4559         cmdline_fixed_string_t cmd_port;
4560         cmdline_fixed_string_t cmd_keyword;
4561         portid_t cmd_pid;
4562 };
4563
4564 static void
4565 cmd_gro_show_parsed(void *parsed_result,
4566                 __attribute__((unused)) struct cmdline *cl,
4567                 __attribute__((unused)) void *data)
4568 {
4569         struct cmd_gro_show_result *res;
4570
4571         res = parsed_result;
4572         if (!strcmp(res->cmd_keyword, "gro"))
4573                 show_gro(res->cmd_pid);
4574 }
4575
4576 cmdline_parse_token_string_t cmd_gro_show_show =
4577         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4578                         cmd_show, "show");
4579 cmdline_parse_token_string_t cmd_gro_show_port =
4580         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4581                         cmd_port, "port");
4582 cmdline_parse_token_num_t cmd_gro_show_pid =
4583         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4584                         cmd_pid, UINT16);
4585 cmdline_parse_token_string_t cmd_gro_show_keyword =
4586         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4587                         cmd_keyword, "gro");
4588
4589 cmdline_parse_inst_t cmd_gro_show = {
4590         .f = cmd_gro_show_parsed,
4591         .data = NULL,
4592         .help_str = "show port <port_id> gro",
4593         .tokens = {
4594                 (void *)&cmd_gro_show_show,
4595                 (void *)&cmd_gro_show_port,
4596                 (void *)&cmd_gro_show_pid,
4597                 (void *)&cmd_gro_show_keyword,
4598                 NULL,
4599         },
4600 };
4601
4602 /* *** SET FLUSH CYCLES FOR GRO *** */
4603 struct cmd_gro_flush_result {
4604         cmdline_fixed_string_t cmd_set;
4605         cmdline_fixed_string_t cmd_keyword;
4606         cmdline_fixed_string_t cmd_flush;
4607         uint8_t cmd_cycles;
4608 };
4609
4610 static void
4611 cmd_gro_flush_parsed(void *parsed_result,
4612                 __attribute__((unused)) struct cmdline *cl,
4613                 __attribute__((unused)) void *data)
4614 {
4615         struct cmd_gro_flush_result *res;
4616
4617         res = parsed_result;
4618         if ((!strcmp(res->cmd_keyword, "gro")) &&
4619                         (!strcmp(res->cmd_flush, "flush")))
4620                 setup_gro_flush_cycles(res->cmd_cycles);
4621 }
4622
4623 cmdline_parse_token_string_t cmd_gro_flush_set =
4624         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4625                         cmd_set, "set");
4626 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4627         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4628                         cmd_keyword, "gro");
4629 cmdline_parse_token_string_t cmd_gro_flush_flush =
4630         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4631                         cmd_flush, "flush");
4632 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4633         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4634                         cmd_cycles, UINT8);
4635
4636 cmdline_parse_inst_t cmd_gro_flush = {
4637         .f = cmd_gro_flush_parsed,
4638         .data = NULL,
4639         .help_str = "set gro flush <cycles>",
4640         .tokens = {
4641                 (void *)&cmd_gro_flush_set,
4642                 (void *)&cmd_gro_flush_keyword,
4643                 (void *)&cmd_gro_flush_flush,
4644                 (void *)&cmd_gro_flush_cycles,
4645                 NULL,
4646         },
4647 };
4648
4649 /* *** ENABLE/DISABLE GSO *** */
4650 struct cmd_gso_enable_result {
4651         cmdline_fixed_string_t cmd_set;
4652         cmdline_fixed_string_t cmd_port;
4653         cmdline_fixed_string_t cmd_keyword;
4654         cmdline_fixed_string_t cmd_mode;
4655         portid_t cmd_pid;
4656 };
4657
4658 static void
4659 cmd_gso_enable_parsed(void *parsed_result,
4660                 __attribute__((unused)) struct cmdline *cl,
4661                 __attribute__((unused)) void *data)
4662 {
4663         struct cmd_gso_enable_result *res;
4664
4665         res = parsed_result;
4666         if (!strcmp(res->cmd_keyword, "gso"))
4667                 setup_gso(res->cmd_mode, res->cmd_pid);
4668 }
4669
4670 cmdline_parse_token_string_t cmd_gso_enable_set =
4671         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4672                         cmd_set, "set");
4673 cmdline_parse_token_string_t cmd_gso_enable_port =
4674         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4675                         cmd_port, "port");
4676 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4677         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4678                         cmd_keyword, "gso");
4679 cmdline_parse_token_string_t cmd_gso_enable_mode =
4680         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4681                         cmd_mode, "on#off");
4682 cmdline_parse_token_num_t cmd_gso_enable_pid =
4683         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4684                         cmd_pid, UINT16);
4685
4686 cmdline_parse_inst_t cmd_gso_enable = {
4687         .f = cmd_gso_enable_parsed,
4688         .data = NULL,
4689         .help_str = "set port <port_id> gso on|off",
4690         .tokens = {
4691                 (void *)&cmd_gso_enable_set,
4692                 (void *)&cmd_gso_enable_port,
4693                 (void *)&cmd_gso_enable_pid,
4694                 (void *)&cmd_gso_enable_keyword,
4695                 (void *)&cmd_gso_enable_mode,
4696                 NULL,
4697         },
4698 };
4699
4700 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4701 struct cmd_gso_size_result {
4702         cmdline_fixed_string_t cmd_set;
4703         cmdline_fixed_string_t cmd_keyword;
4704         cmdline_fixed_string_t cmd_segsz;
4705         uint16_t cmd_size;
4706 };
4707
4708 static void
4709 cmd_gso_size_parsed(void *parsed_result,
4710                        __attribute__((unused)) struct cmdline *cl,
4711                        __attribute__((unused)) void *data)
4712 {
4713         struct cmd_gso_size_result *res = parsed_result;
4714
4715         if (test_done == 0) {
4716                 printf("Before setting GSO segsz, please first"
4717                                 " stop fowarding\n");
4718                 return;
4719         }
4720
4721         if (!strcmp(res->cmd_keyword, "gso") &&
4722                         !strcmp(res->cmd_segsz, "segsz")) {
4723                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4724                         printf("gso_size should be larger than %zu."
4725                                         " Please input a legal value\n",
4726                                         RTE_GSO_SEG_SIZE_MIN);
4727                 else
4728                         gso_max_segment_size = res->cmd_size;
4729         }
4730 }
4731
4732 cmdline_parse_token_string_t cmd_gso_size_set =
4733         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4734                                 cmd_set, "set");
4735 cmdline_parse_token_string_t cmd_gso_size_keyword =
4736         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4737                                 cmd_keyword, "gso");
4738 cmdline_parse_token_string_t cmd_gso_size_segsz =
4739         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4740                                 cmd_segsz, "segsz");
4741 cmdline_parse_token_num_t cmd_gso_size_size =
4742         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4743                                 cmd_size, UINT16);
4744
4745 cmdline_parse_inst_t cmd_gso_size = {
4746         .f = cmd_gso_size_parsed,
4747         .data = NULL,
4748         .help_str = "set gso segsz <length>",
4749         .tokens = {
4750                 (void *)&cmd_gso_size_set,
4751                 (void *)&cmd_gso_size_keyword,
4752                 (void *)&cmd_gso_size_segsz,
4753                 (void *)&cmd_gso_size_size,
4754                 NULL,
4755         },
4756 };
4757
4758 /* *** SHOW GSO CONFIGURATION *** */
4759 struct cmd_gso_show_result {
4760         cmdline_fixed_string_t cmd_show;
4761         cmdline_fixed_string_t cmd_port;
4762         cmdline_fixed_string_t cmd_keyword;
4763         portid_t cmd_pid;
4764 };
4765
4766 static void
4767 cmd_gso_show_parsed(void *parsed_result,
4768                        __attribute__((unused)) struct cmdline *cl,
4769                        __attribute__((unused)) void *data)
4770 {
4771         struct cmd_gso_show_result *res = parsed_result;
4772
4773         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4774                 printf("invalid port id %u\n", res->cmd_pid);
4775                 return;
4776         }
4777         if (!strcmp(res->cmd_keyword, "gso")) {
4778                 if (gso_ports[res->cmd_pid].enable) {
4779                         printf("Max GSO'd packet size: %uB\n"
4780                                         "Supported GSO types: TCP/IPv4, "
4781                                         "VxLAN with inner TCP/IPv4 packet, "
4782                                         "GRE with inner TCP/IPv4  packet\n",
4783                                         gso_max_segment_size);
4784                 } else
4785                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4786         }
4787 }
4788
4789 cmdline_parse_token_string_t cmd_gso_show_show =
4790 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4791                 cmd_show, "show");
4792 cmdline_parse_token_string_t cmd_gso_show_port =
4793 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4794                 cmd_port, "port");
4795 cmdline_parse_token_string_t cmd_gso_show_keyword =
4796         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4797                                 cmd_keyword, "gso");
4798 cmdline_parse_token_num_t cmd_gso_show_pid =
4799         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4800                                 cmd_pid, UINT16);
4801
4802 cmdline_parse_inst_t cmd_gso_show = {
4803         .f = cmd_gso_show_parsed,
4804         .data = NULL,
4805         .help_str = "show port <port_id> gso",
4806         .tokens = {
4807                 (void *)&cmd_gso_show_show,
4808                 (void *)&cmd_gso_show_port,
4809                 (void *)&cmd_gso_show_pid,
4810                 (void *)&cmd_gso_show_keyword,
4811                 NULL,
4812         },
4813 };
4814
4815 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4816 struct cmd_set_flush_rx {
4817         cmdline_fixed_string_t set;
4818         cmdline_fixed_string_t flush_rx;
4819         cmdline_fixed_string_t mode;
4820 };
4821
4822 static void
4823 cmd_set_flush_rx_parsed(void *parsed_result,
4824                 __attribute__((unused)) struct cmdline *cl,
4825                 __attribute__((unused)) void *data)
4826 {
4827         struct cmd_set_flush_rx *res = parsed_result;
4828         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4829 }
4830
4831 cmdline_parse_token_string_t cmd_setflushrx_set =
4832         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4833                         set, "set");
4834 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4835         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4836                         flush_rx, "flush_rx");
4837 cmdline_parse_token_string_t cmd_setflushrx_mode =
4838         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4839                         mode, "on#off");
4840
4841
4842 cmdline_parse_inst_t cmd_set_flush_rx = {
4843         .f = cmd_set_flush_rx_parsed,
4844         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4845         .data = NULL,
4846         .tokens = {
4847                 (void *)&cmd_setflushrx_set,
4848                 (void *)&cmd_setflushrx_flush_rx,
4849                 (void *)&cmd_setflushrx_mode,
4850                 NULL,
4851         },
4852 };
4853
4854 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4855 struct cmd_set_link_check {
4856         cmdline_fixed_string_t set;
4857         cmdline_fixed_string_t link_check;
4858         cmdline_fixed_string_t mode;
4859 };
4860
4861 static void
4862 cmd_set_link_check_parsed(void *parsed_result,
4863                 __attribute__((unused)) struct cmdline *cl,
4864                 __attribute__((unused)) void *data)
4865 {
4866         struct cmd_set_link_check *res = parsed_result;
4867         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4868 }
4869
4870 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4871         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4872                         set, "set");
4873 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4874         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4875                         link_check, "link_check");
4876 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4877         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4878                         mode, "on#off");
4879
4880
4881 cmdline_parse_inst_t cmd_set_link_check = {
4882         .f = cmd_set_link_check_parsed,
4883         .help_str = "set link_check on|off: Enable/Disable link status check "
4884                     "when starting/stopping a port",
4885         .data = NULL,
4886         .tokens = {
4887                 (void *)&cmd_setlinkcheck_set,
4888                 (void *)&cmd_setlinkcheck_link_check,
4889                 (void *)&cmd_setlinkcheck_mode,
4890                 NULL,
4891         },
4892 };
4893
4894 /* *** SET NIC BYPASS MODE *** */
4895 struct cmd_set_bypass_mode_result {
4896         cmdline_fixed_string_t set;
4897         cmdline_fixed_string_t bypass;
4898         cmdline_fixed_string_t mode;
4899         cmdline_fixed_string_t value;
4900         portid_t port_id;
4901 };
4902
4903 static void
4904 cmd_set_bypass_mode_parsed(void *parsed_result,
4905                 __attribute__((unused)) struct cmdline *cl,
4906                 __attribute__((unused)) void *data)
4907 {
4908         struct cmd_set_bypass_mode_result *res = parsed_result;
4909         portid_t port_id = res->port_id;
4910         int32_t rc = -EINVAL;
4911
4912 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4913         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4914
4915         if (!strcmp(res->value, "bypass"))
4916                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4917         else if (!strcmp(res->value, "isolate"))
4918                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4919         else
4920                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4921
4922         /* Set the bypass mode for the relevant port. */
4923         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4924 #endif
4925         if (rc != 0)
4926                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4927 }
4928
4929 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4930         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4931                         set, "set");
4932 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4933         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4934                         bypass, "bypass");
4935 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4936         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4937                         mode, "mode");
4938 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4939         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4940                         value, "normal#bypass#isolate");
4941 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4942         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4943                                 port_id, UINT16);
4944
4945 cmdline_parse_inst_t cmd_set_bypass_mode = {
4946         .f = cmd_set_bypass_mode_parsed,
4947         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4948                     "Set the NIC bypass mode for port_id",
4949         .data = NULL,
4950         .tokens = {
4951                 (void *)&cmd_setbypass_mode_set,
4952                 (void *)&cmd_setbypass_mode_bypass,
4953                 (void *)&cmd_setbypass_mode_mode,
4954                 (void *)&cmd_setbypass_mode_value,
4955                 (void *)&cmd_setbypass_mode_port,
4956                 NULL,
4957         },
4958 };
4959
4960 /* *** SET NIC BYPASS EVENT *** */
4961 struct cmd_set_bypass_event_result {
4962         cmdline_fixed_string_t set;
4963         cmdline_fixed_string_t bypass;
4964         cmdline_fixed_string_t event;
4965         cmdline_fixed_string_t event_value;
4966         cmdline_fixed_string_t mode;
4967         cmdline_fixed_string_t mode_value;
4968         portid_t port_id;
4969 };
4970
4971 static void
4972 cmd_set_bypass_event_parsed(void *parsed_result,
4973                 __attribute__((unused)) struct cmdline *cl,
4974                 __attribute__((unused)) void *data)
4975 {
4976         int32_t rc = -EINVAL;
4977         struct cmd_set_bypass_event_result *res = parsed_result;
4978         portid_t port_id = res->port_id;
4979
4980 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4981         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4982         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4983
4984         if (!strcmp(res->event_value, "timeout"))
4985                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4986         else if (!strcmp(res->event_value, "os_on"))
4987                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4988         else if (!strcmp(res->event_value, "os_off"))
4989                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4990         else if (!strcmp(res->event_value, "power_on"))
4991                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4992         else if (!strcmp(res->event_value, "power_off"))
4993                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4994         else
4995                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4996
4997         if (!strcmp(res->mode_value, "bypass"))
4998                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4999         else if (!strcmp(res->mode_value, "isolate"))
5000                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5001         else
5002                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5003
5004         /* Set the watchdog timeout. */
5005         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5006
5007                 rc = -EINVAL;
5008                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5009                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5010                                                            bypass_timeout);
5011                 }
5012                 if (rc != 0) {
5013                         printf("Failed to set timeout value %u "
5014                         "for port %d, errto code: %d.\n",
5015                         bypass_timeout, port_id, rc);
5016                 }
5017         }
5018
5019         /* Set the bypass event to transition to bypass mode. */
5020         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5021                                               bypass_mode);
5022 #endif
5023
5024         if (rc != 0)
5025                 printf("\t Failed to set bypass event for port = %d.\n",
5026                        port_id);
5027 }
5028
5029 cmdline_parse_token_string_t cmd_setbypass_event_set =
5030         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5031                         set, "set");
5032 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5033         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5034                         bypass, "bypass");
5035 cmdline_parse_token_string_t cmd_setbypass_event_event =
5036         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5037                         event, "event");
5038 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5039         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5040                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5041 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5042         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5043                         mode, "mode");
5044 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5045         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5046                         mode_value, "normal#bypass#isolate");
5047 cmdline_parse_token_num_t cmd_setbypass_event_port =
5048         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5049                                 port_id, UINT16);
5050
5051 cmdline_parse_inst_t cmd_set_bypass_event = {
5052         .f = cmd_set_bypass_event_parsed,
5053         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5054                 "power_off mode normal|bypass|isolate <port_id>: "
5055                 "Set the NIC bypass event mode for port_id",
5056         .data = NULL,
5057         .tokens = {
5058                 (void *)&cmd_setbypass_event_set,
5059                 (void *)&cmd_setbypass_event_bypass,
5060                 (void *)&cmd_setbypass_event_event,
5061                 (void *)&cmd_setbypass_event_event_value,
5062                 (void *)&cmd_setbypass_event_mode,
5063                 (void *)&cmd_setbypass_event_mode_value,
5064                 (void *)&cmd_setbypass_event_port,
5065                 NULL,
5066         },
5067 };
5068
5069
5070 /* *** SET NIC BYPASS TIMEOUT *** */
5071 struct cmd_set_bypass_timeout_result {
5072         cmdline_fixed_string_t set;
5073         cmdline_fixed_string_t bypass;
5074         cmdline_fixed_string_t timeout;
5075         cmdline_fixed_string_t value;
5076 };
5077
5078 static void
5079 cmd_set_bypass_timeout_parsed(void *parsed_result,
5080                 __attribute__((unused)) struct cmdline *cl,
5081                 __attribute__((unused)) void *data)
5082 {
5083         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5084
5085 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5086         if (!strcmp(res->value, "1.5"))
5087                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5088         else if (!strcmp(res->value, "2"))
5089                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5090         else if (!strcmp(res->value, "3"))
5091                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5092         else if (!strcmp(res->value, "4"))
5093                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5094         else if (!strcmp(res->value, "8"))
5095                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5096         else if (!strcmp(res->value, "16"))
5097                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5098         else if (!strcmp(res->value, "32"))
5099                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5100         else
5101                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5102 #endif
5103 }
5104
5105 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5106         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5107                         set, "set");
5108 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5109         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5110                         bypass, "bypass");
5111 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5112         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5113                         timeout, "timeout");
5114 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5115         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5116                         value, "0#1.5#2#3#4#8#16#32");
5117
5118 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5119         .f = cmd_set_bypass_timeout_parsed,
5120         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5121                 "Set the NIC bypass watchdog timeout in seconds",
5122         .data = NULL,
5123         .tokens = {
5124                 (void *)&cmd_setbypass_timeout_set,
5125                 (void *)&cmd_setbypass_timeout_bypass,
5126                 (void *)&cmd_setbypass_timeout_timeout,
5127                 (void *)&cmd_setbypass_timeout_value,
5128                 NULL,
5129         },
5130 };
5131
5132 /* *** SHOW NIC BYPASS MODE *** */
5133 struct cmd_show_bypass_config_result {
5134         cmdline_fixed_string_t show;
5135         cmdline_fixed_string_t bypass;
5136         cmdline_fixed_string_t config;
5137         portid_t port_id;
5138 };
5139
5140 static void
5141 cmd_show_bypass_config_parsed(void *parsed_result,
5142                 __attribute__((unused)) struct cmdline *cl,
5143                 __attribute__((unused)) void *data)
5144 {
5145         struct cmd_show_bypass_config_result *res = parsed_result;
5146         portid_t port_id = res->port_id;
5147         int rc = -EINVAL;
5148 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5149         uint32_t event_mode;
5150         uint32_t bypass_mode;
5151         uint32_t timeout = bypass_timeout;
5152         int i;
5153
5154         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5155                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5156         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5157                 {"UNKNOWN", "normal", "bypass", "isolate"};
5158         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5159                 "NONE",
5160                 "OS/board on",
5161                 "power supply on",
5162                 "OS/board off",
5163                 "power supply off",
5164                 "timeout"};
5165         int num_events = (sizeof events) / (sizeof events[0]);
5166
5167         /* Display the bypass mode.*/
5168         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5169                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5170                 return;
5171         }
5172         else {
5173                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5174                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5175
5176                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5177         }
5178
5179         /* Display the bypass timeout.*/
5180         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5181                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5182
5183         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5184
5185         /* Display the bypass events and associated modes. */
5186         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5187
5188                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5189                         printf("\tFailed to get bypass mode for event = %s\n",
5190                                 events[i]);
5191                 } else {
5192                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5193                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5194
5195                         printf("\tbypass event: %-16s = %s\n", events[i],
5196                                 modes[event_mode]);
5197                 }
5198         }
5199 #endif
5200         if (rc != 0)
5201                 printf("\tFailed to get bypass configuration for port = %d\n",
5202                        port_id);
5203 }
5204
5205 cmdline_parse_token_string_t cmd_showbypass_config_show =
5206         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5207                         show, "show");
5208 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5209         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5210                         bypass, "bypass");
5211 cmdline_parse_token_string_t cmd_showbypass_config_config =
5212         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5213                         config, "config");
5214 cmdline_parse_token_num_t cmd_showbypass_config_port =
5215         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5216                                 port_id, UINT16);
5217
5218 cmdline_parse_inst_t cmd_show_bypass_config = {
5219         .f = cmd_show_bypass_config_parsed,
5220         .help_str = "show bypass config <port_id>: "
5221                     "Show the NIC bypass config for port_id",
5222         .data = NULL,
5223         .tokens = {
5224                 (void *)&cmd_showbypass_config_show,
5225                 (void *)&cmd_showbypass_config_bypass,
5226                 (void *)&cmd_showbypass_config_config,
5227                 (void *)&cmd_showbypass_config_port,
5228                 NULL,
5229         },
5230 };
5231
5232 #ifdef RTE_LIBRTE_PMD_BOND
5233 /* *** SET BONDING MODE *** */
5234 struct cmd_set_bonding_mode_result {
5235         cmdline_fixed_string_t set;
5236         cmdline_fixed_string_t bonding;
5237         cmdline_fixed_string_t mode;
5238         uint8_t value;
5239         portid_t port_id;
5240 };
5241
5242 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5243                 __attribute__((unused))  struct cmdline *cl,
5244                 __attribute__((unused)) void *data)
5245 {
5246         struct cmd_set_bonding_mode_result *res = parsed_result;
5247         portid_t port_id = res->port_id;
5248
5249         /* Set the bonding mode for the relevant port. */
5250         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5251                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5252 }
5253
5254 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5255 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5256                 set, "set");
5257 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5258 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5259                 bonding, "bonding");
5260 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5261 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5262                 mode, "mode");
5263 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5264 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5265                 value, UINT8);
5266 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5267 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5268                 port_id, UINT16);
5269
5270 cmdline_parse_inst_t cmd_set_bonding_mode = {
5271                 .f = cmd_set_bonding_mode_parsed,
5272                 .help_str = "set bonding mode <mode_value> <port_id>: "
5273                         "Set the bonding mode for port_id",
5274                 .data = NULL,
5275                 .tokens = {
5276                                 (void *) &cmd_setbonding_mode_set,
5277                                 (void *) &cmd_setbonding_mode_bonding,
5278                                 (void *) &cmd_setbonding_mode_mode,
5279                                 (void *) &cmd_setbonding_mode_value,
5280                                 (void *) &cmd_setbonding_mode_port,
5281                                 NULL
5282                 }
5283 };
5284
5285 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5286 struct cmd_set_bonding_lacp_dedicated_queues_result {
5287         cmdline_fixed_string_t set;
5288         cmdline_fixed_string_t bonding;
5289         cmdline_fixed_string_t lacp;
5290         cmdline_fixed_string_t dedicated_queues;
5291         portid_t port_id;
5292         cmdline_fixed_string_t mode;
5293 };
5294
5295 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5296                 __attribute__((unused))  struct cmdline *cl,
5297                 __attribute__((unused)) void *data)
5298 {
5299         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5300         portid_t port_id = res->port_id;
5301         struct rte_port *port;
5302
5303         port = &ports[port_id];
5304
5305         /** Check if the port is not started **/
5306         if (port->port_status != RTE_PORT_STOPPED) {
5307                 printf("Please stop port %d first\n", port_id);
5308                 return;
5309         }
5310
5311         if (!strcmp(res->mode, "enable")) {
5312                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5313                         printf("Dedicate queues for LACP control packets"
5314                                         " enabled\n");
5315                 else
5316                         printf("Enabling dedicate queues for LACP control "
5317                                         "packets on port %d failed\n", port_id);
5318         } else if (!strcmp(res->mode, "disable")) {
5319                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5320                         printf("Dedicated queues for LACP control packets "
5321                                         "disabled\n");
5322                 else
5323                         printf("Disabling dedicated queues for LACP control "
5324                                         "traffic on port %d failed\n", port_id);
5325         }
5326 }
5327
5328 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5329 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5330                 set, "set");
5331 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5332 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5333                 bonding, "bonding");
5334 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5335 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5336                 lacp, "lacp");
5337 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5338 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5339                 dedicated_queues, "dedicated_queues");
5340 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5341 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5342                 port_id, UINT16);
5343 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5344 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5345                 mode, "enable#disable");
5346
5347 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5348                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5349                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5350                         "enable|disable: "
5351                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5352                 .data = NULL,
5353                 .tokens = {
5354                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5355                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5356                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5357                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5358                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5359                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5360                         NULL
5361                 }
5362 };
5363
5364 /* *** SET BALANCE XMIT POLICY *** */
5365 struct cmd_set_bonding_balance_xmit_policy_result {
5366         cmdline_fixed_string_t set;
5367         cmdline_fixed_string_t bonding;
5368         cmdline_fixed_string_t balance_xmit_policy;
5369         portid_t port_id;
5370         cmdline_fixed_string_t policy;
5371 };
5372
5373 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5374                 __attribute__((unused))  struct cmdline *cl,
5375                 __attribute__((unused)) void *data)
5376 {
5377         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5378         portid_t port_id = res->port_id;
5379         uint8_t policy;
5380
5381         if (!strcmp(res->policy, "l2")) {
5382                 policy = BALANCE_XMIT_POLICY_LAYER2;
5383         } else if (!strcmp(res->policy, "l23")) {
5384                 policy = BALANCE_XMIT_POLICY_LAYER23;
5385         } else if (!strcmp(res->policy, "l34")) {
5386                 policy = BALANCE_XMIT_POLICY_LAYER34;
5387         } else {
5388                 printf("\t Invalid xmit policy selection");
5389                 return;
5390         }
5391
5392         /* Set the bonding mode for the relevant port. */
5393         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5394                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5395                                 port_id);
5396         }
5397 }
5398
5399 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5400 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5401                 set, "set");
5402 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5403 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5404                 bonding, "bonding");
5405 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5406 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5407                 balance_xmit_policy, "balance_xmit_policy");
5408 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5409 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5410                 port_id, UINT16);
5411 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5412 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5413                 policy, "l2#l23#l34");
5414
5415 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5416                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5417                 .help_str = "set bonding balance_xmit_policy <port_id> "
5418                         "l2|l23|l34: "
5419                         "Set the bonding balance_xmit_policy for port_id",
5420                 .data = NULL,
5421                 .tokens = {
5422                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5423                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5424                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5425                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5426                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5427                                 NULL
5428                 }
5429 };
5430
5431 /* *** SHOW NIC BONDING CONFIGURATION *** */
5432 struct cmd_show_bonding_config_result {
5433         cmdline_fixed_string_t show;
5434         cmdline_fixed_string_t bonding;
5435         cmdline_fixed_string_t config;
5436         portid_t port_id;
5437 };
5438
5439 static void cmd_show_bonding_config_parsed(void *parsed_result,
5440                 __attribute__((unused))  struct cmdline *cl,
5441                 __attribute__((unused)) void *data)
5442 {
5443         struct cmd_show_bonding_config_result *res = parsed_result;
5444         int bonding_mode, agg_mode;
5445         portid_t slaves[RTE_MAX_ETHPORTS];
5446         int num_slaves, num_active_slaves;
5447         int primary_id;
5448         int i;
5449         portid_t port_id = res->port_id;
5450
5451         /* Display the bonding mode.*/
5452         bonding_mode = rte_eth_bond_mode_get(port_id);
5453         if (bonding_mode < 0) {
5454                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5455                 return;
5456         } else
5457                 printf("\tBonding mode: %d\n", bonding_mode);
5458
5459         if (bonding_mode == BONDING_MODE_BALANCE) {
5460                 int balance_xmit_policy;
5461
5462                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5463                 if (balance_xmit_policy < 0) {
5464                         printf("\tFailed to get balance xmit policy for port = %d\n",
5465                                         port_id);
5466                         return;
5467                 } else {
5468                         printf("\tBalance Xmit Policy: ");
5469
5470                         switch (balance_xmit_policy) {
5471                         case BALANCE_XMIT_POLICY_LAYER2:
5472                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5473                                 break;
5474                         case BALANCE_XMIT_POLICY_LAYER23:
5475                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5476                                 break;
5477                         case BALANCE_XMIT_POLICY_LAYER34:
5478                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5479                                 break;
5480                         }
5481                         printf("\n");
5482                 }
5483         }
5484
5485         if (bonding_mode == BONDING_MODE_8023AD) {
5486                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5487                 printf("\tIEEE802.3AD Aggregator Mode: ");
5488                 switch (agg_mode) {
5489                 case AGG_BANDWIDTH:
5490                         printf("bandwidth");
5491                         break;
5492                 case AGG_STABLE:
5493                         printf("stable");
5494                         break;
5495                 case AGG_COUNT:
5496                         printf("count");
5497                         break;
5498                 }
5499                 printf("\n");
5500         }
5501
5502         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5503
5504         if (num_slaves < 0) {
5505                 printf("\tFailed to get slave list for port = %d\n", port_id);
5506                 return;
5507         }
5508         if (num_slaves > 0) {
5509                 printf("\tSlaves (%d): [", num_slaves);
5510                 for (i = 0; i < num_slaves - 1; i++)
5511                         printf("%d ", slaves[i]);
5512
5513                 printf("%d]\n", slaves[num_slaves - 1]);
5514         } else {
5515                 printf("\tSlaves: []\n");
5516
5517         }
5518
5519         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5520                         RTE_MAX_ETHPORTS);
5521
5522         if (num_active_slaves < 0) {
5523                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5524                 return;
5525         }
5526         if (num_active_slaves > 0) {
5527                 printf("\tActive Slaves (%d): [", num_active_slaves);
5528                 for (i = 0; i < num_active_slaves - 1; i++)
5529                         printf("%d ", slaves[i]);
5530
5531                 printf("%d]\n", slaves[num_active_slaves - 1]);
5532
5533         } else {
5534                 printf("\tActive Slaves: []\n");
5535
5536         }
5537
5538         primary_id = rte_eth_bond_primary_get(port_id);
5539         if (primary_id < 0) {
5540                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5541                 return;
5542         } else
5543                 printf("\tPrimary: [%d]\n", primary_id);
5544
5545 }
5546
5547 cmdline_parse_token_string_t cmd_showbonding_config_show =
5548 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5549                 show, "show");
5550 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5551 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5552                 bonding, "bonding");
5553 cmdline_parse_token_string_t cmd_showbonding_config_config =
5554 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5555                 config, "config");
5556 cmdline_parse_token_num_t cmd_showbonding_config_port =
5557 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5558                 port_id, UINT16);
5559
5560 cmdline_parse_inst_t cmd_show_bonding_config = {
5561                 .f = cmd_show_bonding_config_parsed,
5562                 .help_str = "show bonding config <port_id>: "
5563                         "Show the bonding config for port_id",
5564                 .data = NULL,
5565                 .tokens = {
5566                                 (void *)&cmd_showbonding_config_show,
5567                                 (void *)&cmd_showbonding_config_bonding,
5568                                 (void *)&cmd_showbonding_config_config,
5569                                 (void *)&cmd_showbonding_config_port,
5570                                 NULL
5571                 }
5572 };
5573
5574 /* *** SET BONDING PRIMARY *** */
5575 struct cmd_set_bonding_primary_result {
5576         cmdline_fixed_string_t set;
5577         cmdline_fixed_string_t bonding;
5578         cmdline_fixed_string_t primary;
5579         portid_t slave_id;
5580         portid_t port_id;
5581 };
5582
5583 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5584                 __attribute__((unused))  struct cmdline *cl,
5585                 __attribute__((unused)) void *data)
5586 {
5587         struct cmd_set_bonding_primary_result *res = parsed_result;
5588         portid_t master_port_id = res->port_id;
5589         portid_t slave_port_id = res->slave_id;
5590
5591         /* Set the primary slave for a bonded device. */
5592         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5593                 printf("\t Failed to set primary slave for port = %d.\n",
5594                                 master_port_id);
5595                 return;
5596         }
5597         init_port_config();
5598 }
5599
5600 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5601 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5602                 set, "set");
5603 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5604 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5605                 bonding, "bonding");
5606 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5607 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5608                 primary, "primary");
5609 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5610 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5611                 slave_id, UINT16);
5612 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5613 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5614                 port_id, UINT16);
5615
5616 cmdline_parse_inst_t cmd_set_bonding_primary = {
5617                 .f = cmd_set_bonding_primary_parsed,
5618                 .help_str = "set bonding primary <slave_id> <port_id>: "
5619                         "Set the primary slave for port_id",
5620                 .data = NULL,
5621                 .tokens = {
5622                                 (void *)&cmd_setbonding_primary_set,
5623                                 (void *)&cmd_setbonding_primary_bonding,
5624                                 (void *)&cmd_setbonding_primary_primary,
5625                                 (void *)&cmd_setbonding_primary_slave,
5626                                 (void *)&cmd_setbonding_primary_port,
5627                                 NULL
5628                 }
5629 };
5630
5631 /* *** ADD SLAVE *** */
5632 struct cmd_add_bonding_slave_result {
5633         cmdline_fixed_string_t add;
5634         cmdline_fixed_string_t bonding;
5635         cmdline_fixed_string_t slave;
5636         portid_t slave_id;
5637         portid_t port_id;
5638 };
5639
5640 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5641                 __attribute__((unused))  struct cmdline *cl,
5642                 __attribute__((unused)) void *data)
5643 {
5644         struct cmd_add_bonding_slave_result *res = parsed_result;
5645         portid_t master_port_id = res->port_id;
5646         portid_t slave_port_id = res->slave_id;
5647
5648         /* add the slave for a bonded device. */
5649         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5650                 printf("\t Failed to add slave %d to master port = %d.\n",
5651                                 slave_port_id, master_port_id);
5652                 return;
5653         }
5654         init_port_config();
5655         set_port_slave_flag(slave_port_id);
5656 }
5657
5658 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5659 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5660                 add, "add");
5661 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5662 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5663                 bonding, "bonding");
5664 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5665 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5666                 slave, "slave");
5667 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5668 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5669                 slave_id, UINT16);
5670 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5671 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5672                 port_id, UINT16);
5673
5674 cmdline_parse_inst_t cmd_add_bonding_slave = {
5675                 .f = cmd_add_bonding_slave_parsed,
5676                 .help_str = "add bonding slave <slave_id> <port_id>: "
5677                         "Add a slave device to a bonded device",
5678                 .data = NULL,
5679                 .tokens = {
5680                                 (void *)&cmd_addbonding_slave_add,
5681                                 (void *)&cmd_addbonding_slave_bonding,
5682                                 (void *)&cmd_addbonding_slave_slave,
5683                                 (void *)&cmd_addbonding_slave_slaveid,
5684                                 (void *)&cmd_addbonding_slave_port,
5685                                 NULL
5686                 }
5687 };
5688
5689 /* *** REMOVE SLAVE *** */
5690 struct cmd_remove_bonding_slave_result {
5691         cmdline_fixed_string_t remove;
5692         cmdline_fixed_string_t bonding;
5693         cmdline_fixed_string_t slave;
5694         portid_t slave_id;
5695         portid_t port_id;
5696 };
5697
5698 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5699                 __attribute__((unused))  struct cmdline *cl,
5700                 __attribute__((unused)) void *data)
5701 {
5702         struct cmd_remove_bonding_slave_result *res = parsed_result;
5703         portid_t master_port_id = res->port_id;
5704         portid_t slave_port_id = res->slave_id;
5705
5706         /* remove the slave from a bonded device. */
5707         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5708                 printf("\t Failed to remove slave %d from master port = %d.\n",
5709                                 slave_port_id, master_port_id);
5710                 return;
5711         }
5712         init_port_config();
5713         clear_port_slave_flag(slave_port_id);
5714 }
5715
5716 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5717                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5718                                 remove, "remove");
5719 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5720                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5721                                 bonding, "bonding");
5722 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5723                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5724                                 slave, "slave");
5725 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5726                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5727                                 slave_id, UINT16);
5728 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5729                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5730                                 port_id, UINT16);
5731
5732 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5733                 .f = cmd_remove_bonding_slave_parsed,
5734                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5735                         "Remove a slave device from a bonded device",
5736                 .data = NULL,
5737                 .tokens = {
5738                                 (void *)&cmd_removebonding_slave_remove,
5739                                 (void *)&cmd_removebonding_slave_bonding,
5740                                 (void *)&cmd_removebonding_slave_slave,
5741                                 (void *)&cmd_removebonding_slave_slaveid,
5742                                 (void *)&cmd_removebonding_slave_port,
5743                                 NULL
5744                 }
5745 };
5746
5747 /* *** CREATE BONDED DEVICE *** */
5748 struct cmd_create_bonded_device_result {
5749         cmdline_fixed_string_t create;
5750         cmdline_fixed_string_t bonded;
5751         cmdline_fixed_string_t device;
5752         uint8_t mode;
5753         uint8_t socket;
5754 };
5755
5756 static int bond_dev_num = 0;
5757
5758 static void cmd_create_bonded_device_parsed(void *parsed_result,
5759                 __attribute__((unused))  struct cmdline *cl,
5760                 __attribute__((unused)) void *data)
5761 {
5762         struct cmd_create_bonded_device_result *res = parsed_result;
5763         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5764         int port_id;
5765
5766         if (test_done == 0) {
5767                 printf("Please stop forwarding first\n");
5768                 return;
5769         }
5770
5771         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5772                         bond_dev_num++);
5773
5774         /* Create a new bonded device. */
5775         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5776         if (port_id < 0) {
5777                 printf("\t Failed to create bonded device.\n");
5778                 return;
5779         } else {
5780                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5781                                 port_id);
5782
5783                 /* Update number of ports */
5784                 nb_ports = rte_eth_dev_count_avail();
5785                 reconfig(port_id, res->socket);
5786                 rte_eth_promiscuous_enable(port_id);
5787         }
5788
5789 }
5790
5791 cmdline_parse_token_string_t cmd_createbonded_device_create =
5792                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5793                                 create, "create");
5794 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5795                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5796                                 bonded, "bonded");
5797 cmdline_parse_token_string_t cmd_createbonded_device_device =
5798                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5799                                 device, "device");
5800 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5801                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5802                                 mode, UINT8);
5803 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5804                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5805                                 socket, UINT8);
5806
5807 cmdline_parse_inst_t cmd_create_bonded_device = {
5808                 .f = cmd_create_bonded_device_parsed,
5809                 .help_str = "create bonded device <mode> <socket>: "
5810                         "Create a new bonded device with specific bonding mode and socket",
5811                 .data = NULL,
5812                 .tokens = {
5813                                 (void *)&cmd_createbonded_device_create,
5814                                 (void *)&cmd_createbonded_device_bonded,
5815                                 (void *)&cmd_createbonded_device_device,
5816                                 (void *)&cmd_createbonded_device_mode,
5817                                 (void *)&cmd_createbonded_device_socket,
5818                                 NULL
5819                 }
5820 };
5821
5822 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5823 struct cmd_set_bond_mac_addr_result {
5824         cmdline_fixed_string_t set;
5825         cmdline_fixed_string_t bonding;
5826         cmdline_fixed_string_t mac_addr;
5827         uint16_t port_num;
5828         struct ether_addr address;
5829 };
5830
5831 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5832                 __attribute__((unused))  struct cmdline *cl,
5833                 __attribute__((unused)) void *data)
5834 {
5835         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5836         int ret;
5837
5838         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5839                 return;
5840
5841         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5842
5843         /* check the return value and print it if is < 0 */
5844         if (ret < 0)
5845                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5846 }
5847
5848 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5849                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5850 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5851                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5852                                 "bonding");
5853 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5854                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5855                                 "mac_addr");
5856 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5857                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5858                                 port_num, UINT16);
5859 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5860                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5861
5862 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5863                 .f = cmd_set_bond_mac_addr_parsed,
5864                 .data = (void *) 0,
5865                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5866                 .tokens = {
5867                                 (void *)&cmd_set_bond_mac_addr_set,
5868                                 (void *)&cmd_set_bond_mac_addr_bonding,
5869                                 (void *)&cmd_set_bond_mac_addr_mac,
5870                                 (void *)&cmd_set_bond_mac_addr_portnum,
5871                                 (void *)&cmd_set_bond_mac_addr_addr,
5872                                 NULL
5873                 }
5874 };
5875
5876
5877 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5878 struct cmd_set_bond_mon_period_result {
5879         cmdline_fixed_string_t set;
5880         cmdline_fixed_string_t bonding;
5881         cmdline_fixed_string_t mon_period;
5882         uint16_t port_num;
5883         uint32_t period_ms;
5884 };
5885
5886 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5887                 __attribute__((unused))  struct cmdline *cl,
5888                 __attribute__((unused)) void *data)
5889 {
5890         struct cmd_set_bond_mon_period_result *res = parsed_result;
5891         int ret;
5892
5893         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5894
5895         /* check the return value and print it if is < 0 */
5896         if (ret < 0)
5897                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5898 }
5899
5900 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5901                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5902                                 set, "set");
5903 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5904                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5905                                 bonding, "bonding");
5906 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5907                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5908                                 mon_period,     "mon_period");
5909 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5910                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5911                                 port_num, UINT16);
5912 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5913                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5914                                 period_ms, UINT32);
5915
5916 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5917                 .f = cmd_set_bond_mon_period_parsed,
5918                 .data = (void *) 0,
5919                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5920                 .tokens = {
5921                                 (void *)&cmd_set_bond_mon_period_set,
5922                                 (void *)&cmd_set_bond_mon_period_bonding,
5923                                 (void *)&cmd_set_bond_mon_period_mon_period,
5924                                 (void *)&cmd_set_bond_mon_period_portnum,
5925                                 (void *)&cmd_set_bond_mon_period_period_ms,
5926                                 NULL
5927                 }
5928 };
5929
5930
5931
5932 struct cmd_set_bonding_agg_mode_policy_result {
5933         cmdline_fixed_string_t set;
5934         cmdline_fixed_string_t bonding;
5935         cmdline_fixed_string_t agg_mode;
5936         uint16_t port_num;
5937         cmdline_fixed_string_t policy;
5938 };
5939
5940
5941 static void
5942 cmd_set_bonding_agg_mode(void *parsed_result,
5943                 __attribute__((unused)) struct cmdline *cl,
5944                 __attribute__((unused)) void *data)
5945 {
5946         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5947         uint8_t policy = AGG_BANDWIDTH;
5948
5949         if (!strcmp(res->policy, "bandwidth"))
5950                 policy = AGG_BANDWIDTH;
5951         else if (!strcmp(res->policy, "stable"))
5952                 policy = AGG_STABLE;
5953         else if (!strcmp(res->policy, "count"))
5954                 policy = AGG_COUNT;
5955
5956         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5957 }
5958
5959
5960 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5961         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5962                                 set, "set");
5963 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5964         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5965                                 bonding, "bonding");
5966
5967 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5968         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5969                                 agg_mode, "agg_mode");
5970
5971 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5972         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5973                                 port_num, UINT16);
5974
5975 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5976         TOKEN_STRING_INITIALIZER(
5977                         struct cmd_set_bonding_balance_xmit_policy_result,
5978                 policy, "stable#bandwidth#count");
5979
5980 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5981         .f = cmd_set_bonding_agg_mode,
5982         .data = (void *) 0,
5983         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5984         .tokens = {
5985                         (void *)&cmd_set_bonding_agg_mode_set,
5986                         (void *)&cmd_set_bonding_agg_mode_bonding,
5987                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5988                         (void *)&cmd_set_bonding_agg_mode_portnum,
5989                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5990                         NULL
5991                 }
5992 };
5993
5994
5995 #endif /* RTE_LIBRTE_PMD_BOND */
5996
5997 /* *** SET FORWARDING MODE *** */
5998 struct cmd_set_fwd_mode_result {
5999         cmdline_fixed_string_t set;
6000         cmdline_fixed_string_t fwd;
6001         cmdline_fixed_string_t mode;
6002 };
6003
6004 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6005                                     __attribute__((unused)) struct cmdline *cl,
6006                                     __attribute__((unused)) void *data)
6007 {
6008         struct cmd_set_fwd_mode_result *res = parsed_result;
6009
6010         retry_enabled = 0;
6011         set_pkt_forwarding_mode(res->mode);
6012 }
6013
6014 cmdline_parse_token_string_t cmd_setfwd_set =
6015         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6016 cmdline_parse_token_string_t cmd_setfwd_fwd =
6017         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6018 cmdline_parse_token_string_t cmd_setfwd_mode =
6019         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6020                 "" /* defined at init */);
6021
6022 cmdline_parse_inst_t cmd_set_fwd_mode = {
6023         .f = cmd_set_fwd_mode_parsed,
6024         .data = NULL,
6025         .help_str = NULL, /* defined at init */
6026         .tokens = {
6027                 (void *)&cmd_setfwd_set,
6028                 (void *)&cmd_setfwd_fwd,
6029                 (void *)&cmd_setfwd_mode,
6030                 NULL,
6031         },
6032 };
6033
6034 static void cmd_set_fwd_mode_init(void)
6035 {
6036         char *modes, *c;
6037         static char token[128];
6038         static char help[256];
6039         cmdline_parse_token_string_t *token_struct;
6040
6041         modes = list_pkt_forwarding_modes();
6042         snprintf(help, sizeof(help), "set fwd %s: "
6043                 "Set packet forwarding mode", modes);
6044         cmd_set_fwd_mode.help_str = help;
6045
6046         /* string token separator is # */
6047         for (c = token; *modes != '\0'; modes++)
6048                 if (*modes == '|')
6049                         *c++ = '#';
6050                 else
6051                         *c++ = *modes;
6052         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6053         token_struct->string_data.str = token;
6054 }
6055
6056 /* *** SET RETRY FORWARDING MODE *** */
6057 struct cmd_set_fwd_retry_mode_result {
6058         cmdline_fixed_string_t set;
6059         cmdline_fixed_string_t fwd;
6060         cmdline_fixed_string_t mode;
6061         cmdline_fixed_string_t retry;
6062 };
6063
6064 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6065                             __attribute__((unused)) struct cmdline *cl,
6066                             __attribute__((unused)) void *data)
6067 {
6068         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6069
6070         retry_enabled = 1;
6071         set_pkt_forwarding_mode(res->mode);
6072 }
6073
6074 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6075         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6076                         set, "set");
6077 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6078         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6079                         fwd, "fwd");
6080 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6081         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6082                         mode,
6083                 "" /* defined at init */);
6084 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6085         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6086                         retry, "retry");
6087
6088 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6089         .f = cmd_set_fwd_retry_mode_parsed,
6090         .data = NULL,
6091         .help_str = NULL, /* defined at init */
6092         .tokens = {
6093                 (void *)&cmd_setfwd_retry_set,
6094                 (void *)&cmd_setfwd_retry_fwd,
6095                 (void *)&cmd_setfwd_retry_mode,
6096                 (void *)&cmd_setfwd_retry_retry,
6097                 NULL,
6098         },
6099 };
6100
6101 static void cmd_set_fwd_retry_mode_init(void)
6102 {
6103         char *modes, *c;
6104         static char token[128];
6105         static char help[256];
6106         cmdline_parse_token_string_t *token_struct;
6107
6108         modes = list_pkt_forwarding_retry_modes();
6109         snprintf(help, sizeof(help), "set fwd %s retry: "
6110                 "Set packet forwarding mode with retry", modes);
6111         cmd_set_fwd_retry_mode.help_str = help;
6112
6113         /* string token separator is # */
6114         for (c = token; *modes != '\0'; modes++)
6115                 if (*modes == '|')
6116                         *c++ = '#';
6117                 else
6118                         *c++ = *modes;
6119         token_struct = (cmdline_parse_token_string_t *)
6120                 cmd_set_fwd_retry_mode.tokens[2];
6121         token_struct->string_data.str = token;
6122 }
6123
6124 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6125 struct cmd_set_burst_tx_retry_result {
6126         cmdline_fixed_string_t set;
6127         cmdline_fixed_string_t burst;
6128         cmdline_fixed_string_t tx;
6129         cmdline_fixed_string_t delay;
6130         uint32_t time;
6131         cmdline_fixed_string_t retry;
6132         uint32_t retry_num;
6133 };
6134
6135 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6136                                         __attribute__((unused)) struct cmdline *cl,
6137                                         __attribute__((unused)) void *data)
6138 {
6139         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6140
6141         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6142                 && !strcmp(res->tx, "tx")) {
6143                 if (!strcmp(res->delay, "delay"))
6144                         burst_tx_delay_time = res->time;
6145                 if (!strcmp(res->retry, "retry"))
6146                         burst_tx_retry_num = res->retry_num;
6147         }
6148
6149 }
6150
6151 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6152         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6153 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6154         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6155                                  "burst");
6156 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6157         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6158 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6159         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6160 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6161         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6162 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6163         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6164 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6165         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6166
6167 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6168         .f = cmd_set_burst_tx_retry_parsed,
6169         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6170         .tokens = {
6171                 (void *)&cmd_set_burst_tx_retry_set,
6172                 (void *)&cmd_set_burst_tx_retry_burst,
6173                 (void *)&cmd_set_burst_tx_retry_tx,
6174                 (void *)&cmd_set_burst_tx_retry_delay,
6175                 (void *)&cmd_set_burst_tx_retry_time,
6176                 (void *)&cmd_set_burst_tx_retry_retry,
6177                 (void *)&cmd_set_burst_tx_retry_retry_num,
6178                 NULL,
6179         },
6180 };
6181
6182 /* *** SET PROMISC MODE *** */
6183 struct cmd_set_promisc_mode_result {
6184         cmdline_fixed_string_t set;
6185         cmdline_fixed_string_t promisc;
6186         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6187         uint16_t port_num;               /* valid if "allports" argument == 0 */
6188         cmdline_fixed_string_t mode;
6189 };
6190
6191 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6192                                         __attribute__((unused)) struct cmdline *cl,
6193                                         void *allports)
6194 {
6195         struct cmd_set_promisc_mode_result *res = parsed_result;
6196         int enable;
6197         portid_t i;
6198
6199         if (!strcmp(res->mode, "on"))
6200                 enable = 1;
6201         else
6202                 enable = 0;
6203
6204         /* all ports */
6205         if (allports) {
6206                 RTE_ETH_FOREACH_DEV(i) {
6207                         if (enable)
6208                                 rte_eth_promiscuous_enable(i);
6209                         else
6210                                 rte_eth_promiscuous_disable(i);
6211                 }
6212         }
6213         else {
6214                 if (enable)
6215                         rte_eth_promiscuous_enable(res->port_num);
6216                 else
6217                         rte_eth_promiscuous_disable(res->port_num);
6218         }
6219 }
6220
6221 cmdline_parse_token_string_t cmd_setpromisc_set =
6222         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6223 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6224         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6225                                  "promisc");
6226 cmdline_parse_token_string_t cmd_setpromisc_portall =
6227         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6228                                  "all");
6229 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6230         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6231                               UINT16);
6232 cmdline_parse_token_string_t cmd_setpromisc_mode =
6233         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6234                                  "on#off");
6235
6236 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6237         .f = cmd_set_promisc_mode_parsed,
6238         .data = (void *)1,
6239         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6240         .tokens = {
6241                 (void *)&cmd_setpromisc_set,
6242                 (void *)&cmd_setpromisc_promisc,
6243                 (void *)&cmd_setpromisc_portall,
6244                 (void *)&cmd_setpromisc_mode,
6245                 NULL,
6246         },
6247 };
6248
6249 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6250         .f = cmd_set_promisc_mode_parsed,
6251         .data = (void *)0,
6252         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6253         .tokens = {
6254                 (void *)&cmd_setpromisc_set,
6255                 (void *)&cmd_setpromisc_promisc,
6256                 (void *)&cmd_setpromisc_portnum,
6257                 (void *)&cmd_setpromisc_mode,
6258                 NULL,
6259         },
6260 };
6261
6262 /* *** SET ALLMULTI MODE *** */
6263 struct cmd_set_allmulti_mode_result {
6264         cmdline_fixed_string_t set;
6265         cmdline_fixed_string_t allmulti;
6266         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6267         uint16_t port_num;               /* valid if "allports" argument == 0 */
6268         cmdline_fixed_string_t mode;
6269 };
6270
6271 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6272                                         __attribute__((unused)) struct cmdline *cl,
6273                                         void *allports)
6274 {
6275         struct cmd_set_allmulti_mode_result *res = parsed_result;
6276         int enable;
6277         portid_t i;
6278
6279         if (!strcmp(res->mode, "on"))
6280                 enable = 1;
6281         else
6282                 enable = 0;
6283
6284         /* all ports */
6285         if (allports) {
6286                 RTE_ETH_FOREACH_DEV(i) {
6287                         if (enable)
6288                                 rte_eth_allmulticast_enable(i);
6289                         else
6290                                 rte_eth_allmulticast_disable(i);
6291                 }
6292         }
6293         else {
6294                 if (enable)
6295                         rte_eth_allmulticast_enable(res->port_num);
6296                 else
6297                         rte_eth_allmulticast_disable(res->port_num);
6298         }
6299 }
6300
6301 cmdline_parse_token_string_t cmd_setallmulti_set =
6302         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6303 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6304         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6305                                  "allmulti");
6306 cmdline_parse_token_string_t cmd_setallmulti_portall =
6307         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6308                                  "all");
6309 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6310         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6311                               UINT16);
6312 cmdline_parse_token_string_t cmd_setallmulti_mode =
6313         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6314                                  "on#off");
6315
6316 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6317         .f = cmd_set_allmulti_mode_parsed,
6318         .data = (void *)1,
6319         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6320         .tokens = {
6321                 (void *)&cmd_setallmulti_set,
6322                 (void *)&cmd_setallmulti_allmulti,
6323                 (void *)&cmd_setallmulti_portall,
6324                 (void *)&cmd_setallmulti_mode,
6325                 NULL,
6326         },
6327 };
6328
6329 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6330         .f = cmd_set_allmulti_mode_parsed,
6331         .data = (void *)0,
6332         .help_str = "set allmulti <port_id> on|off: "
6333                 "Set allmulti mode on port_id",
6334         .tokens = {
6335                 (void *)&cmd_setallmulti_set,
6336                 (void *)&cmd_setallmulti_allmulti,
6337                 (void *)&cmd_setallmulti_portnum,
6338                 (void *)&cmd_setallmulti_mode,
6339                 NULL,
6340         },
6341 };
6342
6343 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6344 struct cmd_link_flow_ctrl_set_result {
6345         cmdline_fixed_string_t set;
6346         cmdline_fixed_string_t flow_ctrl;
6347         cmdline_fixed_string_t rx;
6348         cmdline_fixed_string_t rx_lfc_mode;
6349         cmdline_fixed_string_t tx;
6350         cmdline_fixed_string_t tx_lfc_mode;
6351         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6352         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6353         cmdline_fixed_string_t autoneg_str;
6354         cmdline_fixed_string_t autoneg;
6355         cmdline_fixed_string_t hw_str;
6356         uint32_t high_water;
6357         cmdline_fixed_string_t lw_str;
6358         uint32_t low_water;
6359         cmdline_fixed_string_t pt_str;
6360         uint16_t pause_time;
6361         cmdline_fixed_string_t xon_str;
6362         uint16_t send_xon;
6363         portid_t port_id;
6364 };
6365
6366 cmdline_parse_token_string_t cmd_lfc_set_set =
6367         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6368                                 set, "set");
6369 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6370         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6371                                 flow_ctrl, "flow_ctrl");
6372 cmdline_parse_token_string_t cmd_lfc_set_rx =
6373         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6374                                 rx, "rx");
6375 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6376         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6377                                 rx_lfc_mode, "on#off");
6378 cmdline_parse_token_string_t cmd_lfc_set_tx =
6379         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6380                                 tx, "tx");
6381 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6382         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6383                                 tx_lfc_mode, "on#off");
6384 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6385         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6386                                 hw_str, "high_water");
6387 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6388         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6389                                 high_water, UINT32);
6390 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6391         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6392                                 lw_str, "low_water");
6393 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6394         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6395                                 low_water, UINT32);
6396 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6397         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6398                                 pt_str, "pause_time");
6399 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6400         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6401                                 pause_time, UINT16);
6402 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6403         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6404                                 xon_str, "send_xon");
6405 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6406         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6407                                 send_xon, UINT16);
6408 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6409         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6410                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6411 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6412         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6413                                 mac_ctrl_frame_fwd_mode, "on#off");
6414 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6415         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6416                                 autoneg_str, "autoneg");
6417 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6418         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6419                                 autoneg, "on#off");
6420 cmdline_parse_token_num_t cmd_lfc_set_portid =
6421         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6422                                 port_id, UINT16);
6423
6424 /* forward declaration */
6425 static void
6426 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6427                               void *data);
6428
6429 cmdline_parse_inst_t cmd_link_flow_control_set = {
6430         .f = cmd_link_flow_ctrl_set_parsed,
6431         .data = NULL,
6432         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6433                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6434                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6435         .tokens = {
6436                 (void *)&cmd_lfc_set_set,
6437                 (void *)&cmd_lfc_set_flow_ctrl,
6438                 (void *)&cmd_lfc_set_rx,
6439                 (void *)&cmd_lfc_set_rx_mode,
6440                 (void *)&cmd_lfc_set_tx,
6441                 (void *)&cmd_lfc_set_tx_mode,
6442                 (void *)&cmd_lfc_set_high_water,
6443                 (void *)&cmd_lfc_set_low_water,
6444                 (void *)&cmd_lfc_set_pause_time,
6445                 (void *)&cmd_lfc_set_send_xon,
6446                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6447                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6448                 (void *)&cmd_lfc_set_autoneg_str,
6449                 (void *)&cmd_lfc_set_autoneg,
6450                 (void *)&cmd_lfc_set_portid,
6451                 NULL,
6452         },
6453 };
6454
6455 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6456         .f = cmd_link_flow_ctrl_set_parsed,
6457         .data = (void *)&cmd_link_flow_control_set_rx,
6458         .help_str = "set flow_ctrl rx on|off <port_id>: "
6459                 "Change rx flow control parameter",
6460         .tokens = {
6461                 (void *)&cmd_lfc_set_set,
6462                 (void *)&cmd_lfc_set_flow_ctrl,
6463                 (void *)&cmd_lfc_set_rx,
6464                 (void *)&cmd_lfc_set_rx_mode,
6465                 (void *)&cmd_lfc_set_portid,
6466                 NULL,
6467         },
6468 };
6469
6470 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6471         .f = cmd_link_flow_ctrl_set_parsed,
6472         .data = (void *)&cmd_link_flow_control_set_tx,
6473         .help_str = "set flow_ctrl tx on|off <port_id>: "
6474                 "Change tx flow control parameter",
6475         .tokens = {
6476                 (void *)&cmd_lfc_set_set,
6477                 (void *)&cmd_lfc_set_flow_ctrl,
6478                 (void *)&cmd_lfc_set_tx,
6479                 (void *)&cmd_lfc_set_tx_mode,
6480                 (void *)&cmd_lfc_set_portid,
6481                 NULL,
6482         },
6483 };
6484
6485 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6486         .f = cmd_link_flow_ctrl_set_parsed,
6487         .data = (void *)&cmd_link_flow_control_set_hw,
6488         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6489                 "Change high water flow control parameter",
6490         .tokens = {
6491                 (void *)&cmd_lfc_set_set,
6492                 (void *)&cmd_lfc_set_flow_ctrl,
6493                 (void *)&cmd_lfc_set_high_water_str,
6494                 (void *)&cmd_lfc_set_high_water,
6495                 (void *)&cmd_lfc_set_portid,
6496                 NULL,
6497         },
6498 };
6499
6500 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6501         .f = cmd_link_flow_ctrl_set_parsed,
6502         .data = (void *)&cmd_link_flow_control_set_lw,
6503         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6504                 "Change low water flow control parameter",
6505         .tokens = {
6506                 (void *)&cmd_lfc_set_set,
6507                 (void *)&cmd_lfc_set_flow_ctrl,
6508                 (void *)&cmd_lfc_set_low_water_str,
6509                 (void *)&cmd_lfc_set_low_water,
6510                 (void *)&cmd_lfc_set_portid,
6511                 NULL,
6512         },
6513 };
6514
6515 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6516         .f = cmd_link_flow_ctrl_set_parsed,
6517         .data = (void *)&cmd_link_flow_control_set_pt,
6518         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6519                 "Change pause time flow control parameter",
6520         .tokens = {
6521                 (void *)&cmd_lfc_set_set,
6522                 (void *)&cmd_lfc_set_flow_ctrl,
6523                 (void *)&cmd_lfc_set_pause_time_str,
6524                 (void *)&cmd_lfc_set_pause_time,
6525                 (void *)&cmd_lfc_set_portid,
6526                 NULL,
6527         },
6528 };
6529
6530 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6531         .f = cmd_link_flow_ctrl_set_parsed,
6532         .data = (void *)&cmd_link_flow_control_set_xon,
6533         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6534                 "Change send_xon flow control parameter",
6535         .tokens = {
6536                 (void *)&cmd_lfc_set_set,
6537                 (void *)&cmd_lfc_set_flow_ctrl,
6538                 (void *)&cmd_lfc_set_send_xon_str,
6539                 (void *)&cmd_lfc_set_send_xon,
6540                 (void *)&cmd_lfc_set_portid,
6541                 NULL,
6542         },
6543 };
6544
6545 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6546         .f = cmd_link_flow_ctrl_set_parsed,
6547         .data = (void *)&cmd_link_flow_control_set_macfwd,
6548         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6549                 "Change mac ctrl fwd flow control parameter",
6550         .tokens = {
6551                 (void *)&cmd_lfc_set_set,
6552                 (void *)&cmd_lfc_set_flow_ctrl,
6553                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6554                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6555                 (void *)&cmd_lfc_set_portid,
6556                 NULL,
6557         },
6558 };
6559
6560 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6561         .f = cmd_link_flow_ctrl_set_parsed,
6562         .data = (void *)&cmd_link_flow_control_set_autoneg,
6563         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6564                 "Change autoneg flow control parameter",
6565         .tokens = {
6566                 (void *)&cmd_lfc_set_set,
6567                 (void *)&cmd_lfc_set_flow_ctrl,
6568                 (void *)&cmd_lfc_set_autoneg_str,
6569                 (void *)&cmd_lfc_set_autoneg,
6570                 (void *)&cmd_lfc_set_portid,
6571                 NULL,
6572         },
6573 };
6574
6575 static void
6576 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6577                               __attribute__((unused)) struct cmdline *cl,
6578                               void *data)
6579 {
6580         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6581         cmdline_parse_inst_t *cmd = data;
6582         struct rte_eth_fc_conf fc_conf;
6583         int rx_fc_en = 0;
6584         int tx_fc_en = 0;
6585         int ret;
6586
6587         /*
6588          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6589          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6590          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6591          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6592          */
6593         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6594                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6595         };
6596
6597         /* Partial command line, retrieve current configuration */
6598         if (cmd) {
6599                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6600                 if (ret != 0) {
6601                         printf("cannot get current flow ctrl parameters, return"
6602                                "code = %d\n", ret);
6603                         return;
6604                 }
6605
6606                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6607                     (fc_conf.mode == RTE_FC_FULL))
6608                         rx_fc_en = 1;
6609                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6610                     (fc_conf.mode == RTE_FC_FULL))
6611                         tx_fc_en = 1;
6612         }
6613
6614         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6615                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6616
6617         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6618                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6619
6620         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6621
6622         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6623                 fc_conf.high_water = res->high_water;
6624
6625         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6626                 fc_conf.low_water = res->low_water;
6627
6628         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6629                 fc_conf.pause_time = res->pause_time;
6630
6631         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6632                 fc_conf.send_xon = res->send_xon;
6633
6634         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6635                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6636                         fc_conf.mac_ctrl_frame_fwd = 1;
6637                 else
6638                         fc_conf.mac_ctrl_frame_fwd = 0;
6639         }
6640
6641         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6642                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6643
6644         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6645         if (ret != 0)
6646                 printf("bad flow contrl parameter, return code = %d \n", ret);
6647 }
6648
6649 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6650 struct cmd_priority_flow_ctrl_set_result {
6651         cmdline_fixed_string_t set;
6652         cmdline_fixed_string_t pfc_ctrl;
6653         cmdline_fixed_string_t rx;
6654         cmdline_fixed_string_t rx_pfc_mode;
6655         cmdline_fixed_string_t tx;
6656         cmdline_fixed_string_t tx_pfc_mode;
6657         uint32_t high_water;
6658         uint32_t low_water;
6659         uint16_t pause_time;
6660         uint8_t  priority;
6661         portid_t port_id;
6662 };
6663
6664 static void
6665 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6666                        __attribute__((unused)) struct cmdline *cl,
6667                        __attribute__((unused)) void *data)
6668 {
6669         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6670         struct rte_eth_pfc_conf pfc_conf;
6671         int rx_fc_enable, tx_fc_enable;
6672         int ret;
6673
6674         /*
6675          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6676          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6677          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6678          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6679          */
6680         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6681                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6682         };
6683
6684         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6685         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6686         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6687         pfc_conf.fc.high_water = res->high_water;
6688         pfc_conf.fc.low_water  = res->low_water;
6689         pfc_conf.fc.pause_time = res->pause_time;
6690         pfc_conf.priority      = res->priority;
6691
6692         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6693         if (ret != 0)
6694                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6695 }
6696
6697 cmdline_parse_token_string_t cmd_pfc_set_set =
6698         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6699                                 set, "set");
6700 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6701         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6702                                 pfc_ctrl, "pfc_ctrl");
6703 cmdline_parse_token_string_t cmd_pfc_set_rx =
6704         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6705                                 rx, "rx");
6706 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6707         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6708                                 rx_pfc_mode, "on#off");
6709 cmdline_parse_token_string_t cmd_pfc_set_tx =
6710         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6711                                 tx, "tx");
6712 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6713         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6714                                 tx_pfc_mode, "on#off");
6715 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6716         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6717                                 high_water, UINT32);
6718 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6719         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6720                                 low_water, UINT32);
6721 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6722         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6723                                 pause_time, UINT16);
6724 cmdline_parse_token_num_t cmd_pfc_set_priority =
6725         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6726                                 priority, UINT8);
6727 cmdline_parse_token_num_t cmd_pfc_set_portid =
6728         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6729                                 port_id, UINT16);
6730
6731 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6732         .f = cmd_priority_flow_ctrl_set_parsed,
6733         .data = NULL,
6734         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6735                 "<pause_time> <priority> <port_id>: "
6736                 "Configure the Ethernet priority flow control",
6737         .tokens = {
6738                 (void *)&cmd_pfc_set_set,
6739                 (void *)&cmd_pfc_set_flow_ctrl,
6740                 (void *)&cmd_pfc_set_rx,
6741                 (void *)&cmd_pfc_set_rx_mode,
6742                 (void *)&cmd_pfc_set_tx,
6743                 (void *)&cmd_pfc_set_tx_mode,
6744                 (void *)&cmd_pfc_set_high_water,
6745                 (void *)&cmd_pfc_set_low_water,
6746                 (void *)&cmd_pfc_set_pause_time,
6747                 (void *)&cmd_pfc_set_priority,
6748                 (void *)&cmd_pfc_set_portid,
6749                 NULL,
6750         },
6751 };
6752
6753 /* *** RESET CONFIGURATION *** */
6754 struct cmd_reset_result {
6755         cmdline_fixed_string_t reset;
6756         cmdline_fixed_string_t def;
6757 };
6758
6759 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6760                              struct cmdline *cl,
6761                              __attribute__((unused)) void *data)
6762 {
6763         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6764         set_def_fwd_config();
6765 }
6766
6767 cmdline_parse_token_string_t cmd_reset_set =
6768         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6769 cmdline_parse_token_string_t cmd_reset_def =
6770         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6771                                  "default");
6772
6773 cmdline_parse_inst_t cmd_reset = {
6774         .f = cmd_reset_parsed,
6775         .data = NULL,
6776         .help_str = "set default: Reset default forwarding configuration",
6777         .tokens = {
6778                 (void *)&cmd_reset_set,
6779                 (void *)&cmd_reset_def,
6780                 NULL,
6781         },
6782 };
6783
6784 /* *** START FORWARDING *** */
6785 struct cmd_start_result {
6786         cmdline_fixed_string_t start;
6787 };
6788
6789 cmdline_parse_token_string_t cmd_start_start =
6790         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6791
6792 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6793                              __attribute__((unused)) struct cmdline *cl,
6794                              __attribute__((unused)) void *data)
6795 {
6796         start_packet_forwarding(0);
6797 }
6798
6799 cmdline_parse_inst_t cmd_start = {
6800         .f = cmd_start_parsed,
6801         .data = NULL,
6802         .help_str = "start: Start packet forwarding",
6803         .tokens = {
6804                 (void *)&cmd_start_start,
6805                 NULL,
6806         },
6807 };
6808
6809 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6810 struct cmd_start_tx_first_result {
6811         cmdline_fixed_string_t start;
6812         cmdline_fixed_string_t tx_first;
6813 };
6814
6815 static void
6816 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6817                           __attribute__((unused)) struct cmdline *cl,
6818                           __attribute__((unused)) void *data)
6819 {
6820         start_packet_forwarding(1);
6821 }
6822
6823 cmdline_parse_token_string_t cmd_start_tx_first_start =
6824         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6825                                  "start");
6826 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6827         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6828                                  tx_first, "tx_first");
6829
6830 cmdline_parse_inst_t cmd_start_tx_first = {
6831         .f = cmd_start_tx_first_parsed,
6832         .data = NULL,
6833         .help_str = "start tx_first: Start packet forwarding, "
6834                 "after sending 1 burst of packets",
6835         .tokens = {
6836                 (void *)&cmd_start_tx_first_start,
6837                 (void *)&cmd_start_tx_first_tx_first,
6838                 NULL,
6839         },
6840 };
6841
6842 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6843 struct cmd_start_tx_first_n_result {
6844         cmdline_fixed_string_t start;
6845         cmdline_fixed_string_t tx_first;
6846         uint32_t tx_num;
6847 };
6848
6849 static void
6850 cmd_start_tx_first_n_parsed(void *parsed_result,
6851                           __attribute__((unused)) struct cmdline *cl,
6852                           __attribute__((unused)) void *data)
6853 {
6854         struct cmd_start_tx_first_n_result *res = parsed_result;
6855
6856         start_packet_forwarding(res->tx_num);
6857 }
6858
6859 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6860         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6861                         start, "start");
6862 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6863         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6864                         tx_first, "tx_first");
6865 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6866         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6867                         tx_num, UINT32);
6868
6869 cmdline_parse_inst_t cmd_start_tx_first_n = {
6870         .f = cmd_start_tx_first_n_parsed,
6871         .data = NULL,
6872         .help_str = "start tx_first <num>: "
6873                 "packet forwarding, after sending <num> bursts of packets",
6874         .tokens = {
6875                 (void *)&cmd_start_tx_first_n_start,
6876                 (void *)&cmd_start_tx_first_n_tx_first,
6877                 (void *)&cmd_start_tx_first_n_tx_num,
6878                 NULL,
6879         },
6880 };
6881
6882 /* *** SET LINK UP *** */
6883 struct cmd_set_link_up_result {
6884         cmdline_fixed_string_t set;
6885         cmdline_fixed_string_t link_up;
6886         cmdline_fixed_string_t port;
6887         portid_t port_id;
6888 };
6889
6890 cmdline_parse_token_string_t cmd_set_link_up_set =
6891         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6892 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6893         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6894                                 "link-up");
6895 cmdline_parse_token_string_t cmd_set_link_up_port =
6896         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6897 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6898         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6899
6900 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6901                              __attribute__((unused)) struct cmdline *cl,
6902                              __attribute__((unused)) void *data)
6903 {
6904         struct cmd_set_link_up_result *res = parsed_result;
6905         dev_set_link_up(res->port_id);
6906 }
6907
6908 cmdline_parse_inst_t cmd_set_link_up = {
6909         .f = cmd_set_link_up_parsed,
6910         .data = NULL,
6911         .help_str = "set link-up port <port id>",
6912         .tokens = {
6913                 (void *)&cmd_set_link_up_set,
6914                 (void *)&cmd_set_link_up_link_up,
6915                 (void *)&cmd_set_link_up_port,
6916                 (void *)&cmd_set_link_up_port_id,
6917                 NULL,
6918         },
6919 };
6920
6921 /* *** SET LINK DOWN *** */
6922 struct cmd_set_link_down_result {
6923         cmdline_fixed_string_t set;
6924         cmdline_fixed_string_t link_down;
6925         cmdline_fixed_string_t port;
6926         portid_t port_id;
6927 };
6928
6929 cmdline_parse_token_string_t cmd_set_link_down_set =
6930         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6931 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6932         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6933                                 "link-down");
6934 cmdline_parse_token_string_t cmd_set_link_down_port =
6935         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6936 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6937         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6938
6939 static void cmd_set_link_down_parsed(
6940                                 __attribute__((unused)) void *parsed_result,
6941                                 __attribute__((unused)) struct cmdline *cl,
6942                                 __attribute__((unused)) void *data)
6943 {
6944         struct cmd_set_link_down_result *res = parsed_result;
6945         dev_set_link_down(res->port_id);
6946 }
6947
6948 cmdline_parse_inst_t cmd_set_link_down = {
6949         .f = cmd_set_link_down_parsed,
6950         .data = NULL,
6951         .help_str = "set link-down port <port id>",
6952         .tokens = {
6953                 (void *)&cmd_set_link_down_set,
6954                 (void *)&cmd_set_link_down_link_down,
6955                 (void *)&cmd_set_link_down_port,
6956                 (void *)&cmd_set_link_down_port_id,
6957                 NULL,
6958         },
6959 };
6960
6961 /* *** SHOW CFG *** */
6962 struct cmd_showcfg_result {
6963         cmdline_fixed_string_t show;
6964         cmdline_fixed_string_t cfg;
6965         cmdline_fixed_string_t what;
6966 };
6967
6968 static void cmd_showcfg_parsed(void *parsed_result,
6969                                __attribute__((unused)) struct cmdline *cl,
6970                                __attribute__((unused)) void *data)
6971 {
6972         struct cmd_showcfg_result *res = parsed_result;
6973         if (!strcmp(res->what, "rxtx"))
6974                 rxtx_config_display();
6975         else if (!strcmp(res->what, "cores"))
6976                 fwd_lcores_config_display();
6977         else if (!strcmp(res->what, "fwd"))
6978                 pkt_fwd_config_display(&cur_fwd_config);
6979         else if (!strcmp(res->what, "txpkts"))
6980                 show_tx_pkt_segments();
6981 }
6982
6983 cmdline_parse_token_string_t cmd_showcfg_show =
6984         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6985 cmdline_parse_token_string_t cmd_showcfg_port =
6986         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6987 cmdline_parse_token_string_t cmd_showcfg_what =
6988         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6989                                  "rxtx#cores#fwd#txpkts");
6990
6991 cmdline_parse_inst_t cmd_showcfg = {
6992         .f = cmd_showcfg_parsed,
6993         .data = NULL,
6994         .help_str = "show config rxtx|cores|fwd|txpkts",
6995         .tokens = {
6996                 (void *)&cmd_showcfg_show,
6997                 (void *)&cmd_showcfg_port,
6998                 (void *)&cmd_showcfg_what,
6999                 NULL,
7000         },
7001 };
7002
7003 /* *** SHOW ALL PORT INFO *** */
7004 struct cmd_showportall_result {
7005         cmdline_fixed_string_t show;
7006         cmdline_fixed_string_t port;
7007         cmdline_fixed_string_t what;
7008         cmdline_fixed_string_t all;
7009 };
7010
7011 static void cmd_showportall_parsed(void *parsed_result,
7012                                 __attribute__((unused)) struct cmdline *cl,
7013                                 __attribute__((unused)) void *data)
7014 {
7015         portid_t i;
7016
7017         struct cmd_showportall_result *res = parsed_result;
7018         if (!strcmp(res->show, "clear")) {
7019                 if (!strcmp(res->what, "stats"))
7020                         RTE_ETH_FOREACH_DEV(i)
7021                                 nic_stats_clear(i);
7022                 else if (!strcmp(res->what, "xstats"))
7023                         RTE_ETH_FOREACH_DEV(i)
7024                                 nic_xstats_clear(i);
7025         } else if (!strcmp(res->what, "info"))
7026                 RTE_ETH_FOREACH_DEV(i)
7027                         port_infos_display(i);
7028         else if (!strcmp(res->what, "stats"))
7029                 RTE_ETH_FOREACH_DEV(i)
7030                         nic_stats_display(i);
7031         else if (!strcmp(res->what, "xstats"))
7032                 RTE_ETH_FOREACH_DEV(i)
7033                         nic_xstats_display(i);
7034         else if (!strcmp(res->what, "fdir"))
7035                 RTE_ETH_FOREACH_DEV(i)
7036                         fdir_get_infos(i);
7037         else if (!strcmp(res->what, "stat_qmap"))
7038                 RTE_ETH_FOREACH_DEV(i)
7039                         nic_stats_mapping_display(i);
7040         else if (!strcmp(res->what, "dcb_tc"))
7041                 RTE_ETH_FOREACH_DEV(i)
7042                         port_dcb_info_display(i);
7043         else if (!strcmp(res->what, "cap"))
7044                 RTE_ETH_FOREACH_DEV(i)
7045                         port_offload_cap_display(i);
7046 }
7047
7048 cmdline_parse_token_string_t cmd_showportall_show =
7049         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7050                                  "show#clear");
7051 cmdline_parse_token_string_t cmd_showportall_port =
7052         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7053 cmdline_parse_token_string_t cmd_showportall_what =
7054         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7055                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7056 cmdline_parse_token_string_t cmd_showportall_all =
7057         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7058 cmdline_parse_inst_t cmd_showportall = {
7059         .f = cmd_showportall_parsed,
7060         .data = NULL,
7061         .help_str = "show|clear port "
7062                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7063         .tokens = {
7064                 (void *)&cmd_showportall_show,
7065                 (void *)&cmd_showportall_port,
7066                 (void *)&cmd_showportall_what,
7067                 (void *)&cmd_showportall_all,
7068                 NULL,
7069         },
7070 };
7071
7072 /* *** SHOW PORT INFO *** */
7073 struct cmd_showport_result {
7074         cmdline_fixed_string_t show;
7075         cmdline_fixed_string_t port;
7076         cmdline_fixed_string_t what;
7077         uint16_t portnum;
7078 };
7079
7080 static void cmd_showport_parsed(void *parsed_result,
7081                                 __attribute__((unused)) struct cmdline *cl,
7082                                 __attribute__((unused)) void *data)
7083 {
7084         struct cmd_showport_result *res = parsed_result;
7085         if (!strcmp(res->show, "clear")) {
7086                 if (!strcmp(res->what, "stats"))
7087                         nic_stats_clear(res->portnum);
7088                 else if (!strcmp(res->what, "xstats"))
7089                         nic_xstats_clear(res->portnum);
7090         } else if (!strcmp(res->what, "info"))
7091                 port_infos_display(res->portnum);
7092         else if (!strcmp(res->what, "stats"))
7093                 nic_stats_display(res->portnum);
7094         else if (!strcmp(res->what, "xstats"))
7095                 nic_xstats_display(res->portnum);
7096         else if (!strcmp(res->what, "fdir"))
7097                  fdir_get_infos(res->portnum);
7098         else if (!strcmp(res->what, "stat_qmap"))
7099                 nic_stats_mapping_display(res->portnum);
7100         else if (!strcmp(res->what, "dcb_tc"))
7101                 port_dcb_info_display(res->portnum);
7102         else if (!strcmp(res->what, "cap"))
7103                 port_offload_cap_display(res->portnum);
7104 }
7105
7106 cmdline_parse_token_string_t cmd_showport_show =
7107         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7108                                  "show#clear");
7109 cmdline_parse_token_string_t cmd_showport_port =
7110         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7111 cmdline_parse_token_string_t cmd_showport_what =
7112         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7113                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7114 cmdline_parse_token_num_t cmd_showport_portnum =
7115         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7116
7117 cmdline_parse_inst_t cmd_showport = {
7118         .f = cmd_showport_parsed,
7119         .data = NULL,
7120         .help_str = "show|clear port "
7121                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7122                 "<port_id>",
7123         .tokens = {
7124                 (void *)&cmd_showport_show,
7125                 (void *)&cmd_showport_port,
7126                 (void *)&cmd_showport_what,
7127                 (void *)&cmd_showport_portnum,
7128                 NULL,
7129         },
7130 };
7131
7132 /* *** SHOW QUEUE INFO *** */
7133 struct cmd_showqueue_result {
7134         cmdline_fixed_string_t show;
7135         cmdline_fixed_string_t type;
7136         cmdline_fixed_string_t what;
7137         uint16_t portnum;
7138         uint16_t queuenum;
7139 };
7140
7141 static void
7142 cmd_showqueue_parsed(void *parsed_result,
7143         __attribute__((unused)) struct cmdline *cl,
7144         __attribute__((unused)) void *data)
7145 {
7146         struct cmd_showqueue_result *res = parsed_result;
7147
7148         if (!strcmp(res->type, "rxq"))
7149                 rx_queue_infos_display(res->portnum, res->queuenum);
7150         else if (!strcmp(res->type, "txq"))
7151                 tx_queue_infos_display(res->portnum, res->queuenum);
7152 }
7153
7154 cmdline_parse_token_string_t cmd_showqueue_show =
7155         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7156 cmdline_parse_token_string_t cmd_showqueue_type =
7157         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7158 cmdline_parse_token_string_t cmd_showqueue_what =
7159         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7160 cmdline_parse_token_num_t cmd_showqueue_portnum =
7161         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7162 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7163         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7164
7165 cmdline_parse_inst_t cmd_showqueue = {
7166         .f = cmd_showqueue_parsed,
7167         .data = NULL,
7168         .help_str = "show rxq|txq info <port_id> <queue_id>",
7169         .tokens = {
7170                 (void *)&cmd_showqueue_show,
7171                 (void *)&cmd_showqueue_type,
7172                 (void *)&cmd_showqueue_what,
7173                 (void *)&cmd_showqueue_portnum,
7174                 (void *)&cmd_showqueue_queuenum,
7175                 NULL,
7176         },
7177 };
7178
7179 /* *** READ PORT REGISTER *** */
7180 struct cmd_read_reg_result {
7181         cmdline_fixed_string_t read;
7182         cmdline_fixed_string_t reg;
7183         portid_t port_id;
7184         uint32_t reg_off;
7185 };
7186
7187 static void
7188 cmd_read_reg_parsed(void *parsed_result,
7189                     __attribute__((unused)) struct cmdline *cl,
7190                     __attribute__((unused)) void *data)
7191 {
7192         struct cmd_read_reg_result *res = parsed_result;
7193         port_reg_display(res->port_id, res->reg_off);
7194 }
7195
7196 cmdline_parse_token_string_t cmd_read_reg_read =
7197         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7198 cmdline_parse_token_string_t cmd_read_reg_reg =
7199         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7200 cmdline_parse_token_num_t cmd_read_reg_port_id =
7201         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7202 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7203         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7204
7205 cmdline_parse_inst_t cmd_read_reg = {
7206         .f = cmd_read_reg_parsed,
7207         .data = NULL,
7208         .help_str = "read reg <port_id> <reg_off>",
7209         .tokens = {
7210                 (void *)&cmd_read_reg_read,
7211                 (void *)&cmd_read_reg_reg,
7212                 (void *)&cmd_read_reg_port_id,
7213                 (void *)&cmd_read_reg_reg_off,
7214                 NULL,
7215         },
7216 };
7217
7218 /* *** READ PORT REGISTER BIT FIELD *** */
7219 struct cmd_read_reg_bit_field_result {
7220         cmdline_fixed_string_t read;
7221         cmdline_fixed_string_t regfield;
7222         portid_t port_id;
7223         uint32_t reg_off;
7224         uint8_t bit1_pos;
7225         uint8_t bit2_pos;
7226 };
7227
7228 static void
7229 cmd_read_reg_bit_field_parsed(void *parsed_result,
7230                               __attribute__((unused)) struct cmdline *cl,
7231                               __attribute__((unused)) void *data)
7232 {
7233         struct cmd_read_reg_bit_field_result *res = parsed_result;
7234         port_reg_bit_field_display(res->port_id, res->reg_off,
7235                                    res->bit1_pos, res->bit2_pos);
7236 }
7237
7238 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7239         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7240                                  "read");
7241 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7242         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7243                                  regfield, "regfield");
7244 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7245         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7246                               UINT16);
7247 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7248         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7249                               UINT32);
7250 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7251         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7252                               UINT8);
7253 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7254         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7255                               UINT8);
7256
7257 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7258         .f = cmd_read_reg_bit_field_parsed,
7259         .data = NULL,
7260         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7261         "Read register bit field between bit_x and bit_y included",
7262         .tokens = {
7263                 (void *)&cmd_read_reg_bit_field_read,
7264                 (void *)&cmd_read_reg_bit_field_regfield,
7265                 (void *)&cmd_read_reg_bit_field_port_id,
7266                 (void *)&cmd_read_reg_bit_field_reg_off,
7267                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7268                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7269                 NULL,
7270         },
7271 };
7272
7273 /* *** READ PORT REGISTER BIT *** */
7274 struct cmd_read_reg_bit_result {
7275         cmdline_fixed_string_t read;
7276         cmdline_fixed_string_t regbit;
7277         portid_t port_id;
7278         uint32_t reg_off;
7279         uint8_t bit_pos;
7280 };
7281
7282 static void
7283 cmd_read_reg_bit_parsed(void *parsed_result,
7284                         __attribute__((unused)) struct cmdline *cl,
7285                         __attribute__((unused)) void *data)
7286 {
7287         struct cmd_read_reg_bit_result *res = parsed_result;
7288         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7289 }
7290
7291 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7292         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7293 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7294         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7295                                  regbit, "regbit");
7296 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7297         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7298 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7299         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7300 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7301         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7302
7303 cmdline_parse_inst_t cmd_read_reg_bit = {
7304         .f = cmd_read_reg_bit_parsed,
7305         .data = NULL,
7306         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7307         .tokens = {
7308                 (void *)&cmd_read_reg_bit_read,
7309                 (void *)&cmd_read_reg_bit_regbit,
7310                 (void *)&cmd_read_reg_bit_port_id,
7311                 (void *)&cmd_read_reg_bit_reg_off,
7312                 (void *)&cmd_read_reg_bit_bit_pos,
7313                 NULL,
7314         },
7315 };
7316
7317 /* *** WRITE PORT REGISTER *** */
7318 struct cmd_write_reg_result {
7319         cmdline_fixed_string_t write;
7320         cmdline_fixed_string_t reg;
7321         portid_t port_id;
7322         uint32_t reg_off;
7323         uint32_t value;
7324 };
7325
7326 static void
7327 cmd_write_reg_parsed(void *parsed_result,
7328                      __attribute__((unused)) struct cmdline *cl,
7329                      __attribute__((unused)) void *data)
7330 {
7331         struct cmd_write_reg_result *res = parsed_result;
7332         port_reg_set(res->port_id, res->reg_off, res->value);
7333 }
7334
7335 cmdline_parse_token_string_t cmd_write_reg_write =
7336         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7337 cmdline_parse_token_string_t cmd_write_reg_reg =
7338         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7339 cmdline_parse_token_num_t cmd_write_reg_port_id =
7340         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7341 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7342         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7343 cmdline_parse_token_num_t cmd_write_reg_value =
7344         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7345
7346 cmdline_parse_inst_t cmd_write_reg = {
7347         .f = cmd_write_reg_parsed,
7348         .data = NULL,
7349         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7350         .tokens = {
7351                 (void *)&cmd_write_reg_write,
7352                 (void *)&cmd_write_reg_reg,
7353                 (void *)&cmd_write_reg_port_id,
7354                 (void *)&cmd_write_reg_reg_off,
7355                 (void *)&cmd_write_reg_value,
7356                 NULL,
7357         },
7358 };
7359
7360 /* *** WRITE PORT REGISTER BIT FIELD *** */
7361 struct cmd_write_reg_bit_field_result {
7362         cmdline_fixed_string_t write;
7363         cmdline_fixed_string_t regfield;
7364         portid_t port_id;
7365         uint32_t reg_off;
7366         uint8_t bit1_pos;
7367         uint8_t bit2_pos;
7368         uint32_t value;
7369 };
7370
7371 static void
7372 cmd_write_reg_bit_field_parsed(void *parsed_result,
7373                                __attribute__((unused)) struct cmdline *cl,
7374                                __attribute__((unused)) void *data)
7375 {
7376         struct cmd_write_reg_bit_field_result *res = parsed_result;
7377         port_reg_bit_field_set(res->port_id, res->reg_off,
7378                           res->bit1_pos, res->bit2_pos, res->value);
7379 }
7380
7381 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7382         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7383                                  "write");
7384 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7385         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7386                                  regfield, "regfield");
7387 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7388         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7389                               UINT16);
7390 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7391         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7392                               UINT32);
7393 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7394         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7395                               UINT8);
7396 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7397         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7398                               UINT8);
7399 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7400         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7401                               UINT32);
7402
7403 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7404         .f = cmd_write_reg_bit_field_parsed,
7405         .data = NULL,
7406         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7407                 "<reg_value>: "
7408                 "Set register bit field between bit_x and bit_y included",
7409         .tokens = {
7410                 (void *)&cmd_write_reg_bit_field_write,
7411                 (void *)&cmd_write_reg_bit_field_regfield,
7412                 (void *)&cmd_write_reg_bit_field_port_id,
7413                 (void *)&cmd_write_reg_bit_field_reg_off,
7414                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7415                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7416                 (void *)&cmd_write_reg_bit_field_value,
7417                 NULL,
7418         },
7419 };
7420
7421 /* *** WRITE PORT REGISTER BIT *** */
7422 struct cmd_write_reg_bit_result {
7423         cmdline_fixed_string_t write;
7424         cmdline_fixed_string_t regbit;
7425         portid_t port_id;
7426         uint32_t reg_off;
7427         uint8_t bit_pos;
7428         uint8_t value;
7429 };
7430
7431 static void
7432 cmd_write_reg_bit_parsed(void *parsed_result,
7433                          __attribute__((unused)) struct cmdline *cl,
7434                          __attribute__((unused)) void *data)
7435 {
7436         struct cmd_write_reg_bit_result *res = parsed_result;
7437         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7438 }
7439
7440 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7441         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7442                                  "write");
7443 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7444         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7445                                  regbit, "regbit");
7446 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7447         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7448 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7449         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7450 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7451         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7452 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7453         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7454
7455 cmdline_parse_inst_t cmd_write_reg_bit = {
7456         .f = cmd_write_reg_bit_parsed,
7457         .data = NULL,
7458         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7459                 "0 <= bit_x <= 31",
7460         .tokens = {
7461                 (void *)&cmd_write_reg_bit_write,
7462                 (void *)&cmd_write_reg_bit_regbit,
7463                 (void *)&cmd_write_reg_bit_port_id,
7464                 (void *)&cmd_write_reg_bit_reg_off,
7465                 (void *)&cmd_write_reg_bit_bit_pos,
7466                 (void *)&cmd_write_reg_bit_value,
7467                 NULL,
7468         },
7469 };
7470
7471 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7472 struct cmd_read_rxd_txd_result {
7473         cmdline_fixed_string_t read;
7474         cmdline_fixed_string_t rxd_txd;
7475         portid_t port_id;
7476         uint16_t queue_id;
7477         uint16_t desc_id;
7478 };
7479
7480 static void
7481 cmd_read_rxd_txd_parsed(void *parsed_result,
7482                         __attribute__((unused)) struct cmdline *cl,
7483                         __attribute__((unused)) void *data)
7484 {
7485         struct cmd_read_rxd_txd_result *res = parsed_result;
7486
7487         if (!strcmp(res->rxd_txd, "rxd"))
7488                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7489         else if (!strcmp(res->rxd_txd, "txd"))
7490                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7491 }
7492
7493 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7494         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7495 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7496         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7497                                  "rxd#txd");
7498 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7499         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7500 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7501         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7502 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7503         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7504
7505 cmdline_parse_inst_t cmd_read_rxd_txd = {
7506         .f = cmd_read_rxd_txd_parsed,
7507         .data = NULL,
7508         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7509         .tokens = {
7510                 (void *)&cmd_read_rxd_txd_read,
7511                 (void *)&cmd_read_rxd_txd_rxd_txd,
7512                 (void *)&cmd_read_rxd_txd_port_id,
7513                 (void *)&cmd_read_rxd_txd_queue_id,
7514                 (void *)&cmd_read_rxd_txd_desc_id,
7515                 NULL,
7516         },
7517 };
7518
7519 /* *** QUIT *** */
7520 struct cmd_quit_result {
7521         cmdline_fixed_string_t quit;
7522 };
7523
7524 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7525                             struct cmdline *cl,
7526                             __attribute__((unused)) void *data)
7527 {
7528         pmd_test_exit();
7529         cmdline_quit(cl);
7530 }
7531
7532 cmdline_parse_token_string_t cmd_quit_quit =
7533         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7534
7535 cmdline_parse_inst_t cmd_quit = {
7536         .f = cmd_quit_parsed,
7537         .data = NULL,
7538         .help_str = "quit: Exit application",
7539         .tokens = {
7540                 (void *)&cmd_quit_quit,
7541                 NULL,
7542         },
7543 };
7544
7545 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7546 struct cmd_mac_addr_result {
7547         cmdline_fixed_string_t mac_addr_cmd;
7548         cmdline_fixed_string_t what;
7549         uint16_t port_num;
7550         struct ether_addr address;
7551 };
7552
7553 static void cmd_mac_addr_parsed(void *parsed_result,
7554                 __attribute__((unused)) struct cmdline *cl,
7555                 __attribute__((unused)) void *data)
7556 {
7557         struct cmd_mac_addr_result *res = parsed_result;
7558         int ret;
7559
7560         if (strcmp(res->what, "add") == 0)
7561                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7562         else if (strcmp(res->what, "set") == 0)
7563                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7564                                                        &res->address);
7565         else
7566                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7567
7568         /* check the return value and print it if is < 0 */
7569         if(ret < 0)
7570                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7571
7572 }
7573
7574 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7575         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7576                                 "mac_addr");
7577 cmdline_parse_token_string_t cmd_mac_addr_what =
7578         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7579                                 "add#remove#set");
7580 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7581                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7582                                         UINT16);
7583 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7584                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7585
7586 cmdline_parse_inst_t cmd_mac_addr = {
7587         .f = cmd_mac_addr_parsed,
7588         .data = (void *)0,
7589         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7590                         "Add/Remove/Set MAC address on port_id",
7591         .tokens = {
7592                 (void *)&cmd_mac_addr_cmd,
7593                 (void *)&cmd_mac_addr_what,
7594                 (void *)&cmd_mac_addr_portnum,
7595                 (void *)&cmd_mac_addr_addr,
7596                 NULL,
7597         },
7598 };
7599
7600 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7601 struct cmd_eth_peer_result {
7602         cmdline_fixed_string_t set;
7603         cmdline_fixed_string_t eth_peer;
7604         portid_t port_id;
7605         cmdline_fixed_string_t peer_addr;
7606 };
7607
7608 static void cmd_set_eth_peer_parsed(void *parsed_result,
7609                         __attribute__((unused)) struct cmdline *cl,
7610                         __attribute__((unused)) void *data)
7611 {
7612                 struct cmd_eth_peer_result *res = parsed_result;
7613
7614                 if (test_done == 0) {
7615                         printf("Please stop forwarding first\n");
7616                         return;
7617                 }
7618                 if (!strcmp(res->eth_peer, "eth-peer")) {
7619                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7620                         fwd_config_setup();
7621                 }
7622 }
7623 cmdline_parse_token_string_t cmd_eth_peer_set =
7624         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7625 cmdline_parse_token_string_t cmd_eth_peer =
7626         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7627 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7628         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7629 cmdline_parse_token_string_t cmd_eth_peer_addr =
7630         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7631
7632 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7633         .f = cmd_set_eth_peer_parsed,
7634         .data = NULL,
7635         .help_str = "set eth-peer <port_id> <peer_mac>",
7636         .tokens = {
7637                 (void *)&cmd_eth_peer_set,
7638                 (void *)&cmd_eth_peer,
7639                 (void *)&cmd_eth_peer_port_id,
7640                 (void *)&cmd_eth_peer_addr,
7641                 NULL,
7642         },
7643 };
7644
7645 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7646 struct cmd_set_qmap_result {
7647         cmdline_fixed_string_t set;
7648         cmdline_fixed_string_t qmap;
7649         cmdline_fixed_string_t what;
7650         portid_t port_id;
7651         uint16_t queue_id;
7652         uint8_t map_value;
7653 };
7654
7655 static void
7656 cmd_set_qmap_parsed(void *parsed_result,
7657                        __attribute__((unused)) struct cmdline *cl,
7658                        __attribute__((unused)) void *data)
7659 {
7660         struct cmd_set_qmap_result *res = parsed_result;
7661         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7662
7663         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7664 }
7665
7666 cmdline_parse_token_string_t cmd_setqmap_set =
7667         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7668                                  set, "set");
7669 cmdline_parse_token_string_t cmd_setqmap_qmap =
7670         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7671                                  qmap, "stat_qmap");
7672 cmdline_parse_token_string_t cmd_setqmap_what =
7673         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7674                                  what, "tx#rx");
7675 cmdline_parse_token_num_t cmd_setqmap_portid =
7676         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7677                               port_id, UINT16);
7678 cmdline_parse_token_num_t cmd_setqmap_queueid =
7679         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7680                               queue_id, UINT16);
7681 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7682         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7683                               map_value, UINT8);
7684
7685 cmdline_parse_inst_t cmd_set_qmap = {
7686         .f = cmd_set_qmap_parsed,
7687         .data = NULL,
7688         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7689                 "Set statistics mapping value on tx|rx queue_id of port_id",
7690         .tokens = {
7691                 (void *)&cmd_setqmap_set,
7692                 (void *)&cmd_setqmap_qmap,
7693                 (void *)&cmd_setqmap_what,
7694                 (void *)&cmd_setqmap_portid,
7695                 (void *)&cmd_setqmap_queueid,
7696                 (void *)&cmd_setqmap_mapvalue,
7697                 NULL,
7698         },
7699 };
7700
7701 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7702 struct cmd_set_xstats_hide_zero_result {
7703         cmdline_fixed_string_t keyword;
7704         cmdline_fixed_string_t name;
7705         cmdline_fixed_string_t on_off;
7706 };
7707
7708 static void
7709 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7710                         __attribute__((unused)) struct cmdline *cl,
7711                         __attribute__((unused)) void *data)
7712 {
7713         struct cmd_set_xstats_hide_zero_result *res;
7714         uint16_t on_off = 0;
7715
7716         res = parsed_result;
7717         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7718         set_xstats_hide_zero(on_off);
7719 }
7720
7721 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7722         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7723                                  keyword, "set");
7724 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7725         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7726                                  name, "xstats-hide-zero");
7727 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7728         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7729                                  on_off, "on#off");
7730
7731 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7732         .f = cmd_set_xstats_hide_zero_parsed,
7733         .data = NULL,
7734         .help_str = "set xstats-hide-zero on|off",
7735         .tokens = {
7736                 (void *)&cmd_set_xstats_hide_zero_keyword,
7737                 (void *)&cmd_set_xstats_hide_zero_name,
7738                 (void *)&cmd_set_xstats_hide_zero_on_off,
7739                 NULL,
7740         },
7741 };
7742
7743 /* *** CONFIGURE UNICAST HASH TABLE *** */
7744 struct cmd_set_uc_hash_table {
7745         cmdline_fixed_string_t set;
7746         cmdline_fixed_string_t port;
7747         portid_t port_id;
7748         cmdline_fixed_string_t what;
7749         struct ether_addr address;
7750         cmdline_fixed_string_t mode;
7751 };
7752
7753 static void
7754 cmd_set_uc_hash_parsed(void *parsed_result,
7755                        __attribute__((unused)) struct cmdline *cl,
7756                        __attribute__((unused)) void *data)
7757 {
7758         int ret=0;
7759         struct cmd_set_uc_hash_table *res = parsed_result;
7760
7761         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7762
7763         if (strcmp(res->what, "uta") == 0)
7764                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7765                                                 &res->address,(uint8_t)is_on);
7766         if (ret < 0)
7767                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7768
7769 }
7770
7771 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7772         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7773                                  set, "set");
7774 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7775         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7776                                  port, "port");
7777 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7778         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7779                               port_id, UINT16);
7780 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7781         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7782                                  what, "uta");
7783 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7784         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7785                                 address);
7786 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7787         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7788                                  mode, "on#off");
7789
7790 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7791         .f = cmd_set_uc_hash_parsed,
7792         .data = NULL,
7793         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7794         .tokens = {
7795                 (void *)&cmd_set_uc_hash_set,
7796                 (void *)&cmd_set_uc_hash_port,
7797                 (void *)&cmd_set_uc_hash_portid,
7798                 (void *)&cmd_set_uc_hash_what,
7799                 (void *)&cmd_set_uc_hash_mac,
7800                 (void *)&cmd_set_uc_hash_mode,
7801                 NULL,
7802         },
7803 };
7804
7805 struct cmd_set_uc_all_hash_table {
7806         cmdline_fixed_string_t set;
7807         cmdline_fixed_string_t port;
7808         portid_t port_id;
7809         cmdline_fixed_string_t what;
7810         cmdline_fixed_string_t value;
7811         cmdline_fixed_string_t mode;
7812 };
7813
7814 static void
7815 cmd_set_uc_all_hash_parsed(void *parsed_result,
7816                        __attribute__((unused)) struct cmdline *cl,
7817                        __attribute__((unused)) void *data)
7818 {
7819         int ret=0;
7820         struct cmd_set_uc_all_hash_table *res = parsed_result;
7821
7822         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7823
7824         if ((strcmp(res->what, "uta") == 0) &&
7825                 (strcmp(res->value, "all") == 0))
7826                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7827         if (ret < 0)
7828                 printf("bad unicast hash table parameter,"
7829                         "return code = %d \n", ret);
7830 }
7831
7832 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7833         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7834                                  set, "set");
7835 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7836         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7837                                  port, "port");
7838 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7839         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7840                               port_id, UINT16);
7841 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7842         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7843                                  what, "uta");
7844 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7845         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7846                                 value,"all");
7847 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7848         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7849                                  mode, "on#off");
7850
7851 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7852         .f = cmd_set_uc_all_hash_parsed,
7853         .data = NULL,
7854         .help_str = "set port <port_id> uta all on|off",
7855         .tokens = {
7856                 (void *)&cmd_set_uc_all_hash_set,
7857                 (void *)&cmd_set_uc_all_hash_port,
7858                 (void *)&cmd_set_uc_all_hash_portid,
7859                 (void *)&cmd_set_uc_all_hash_what,
7860                 (void *)&cmd_set_uc_all_hash_value,
7861                 (void *)&cmd_set_uc_all_hash_mode,
7862                 NULL,
7863         },
7864 };
7865
7866 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7867 struct cmd_set_vf_macvlan_filter {
7868         cmdline_fixed_string_t set;
7869         cmdline_fixed_string_t port;
7870         portid_t port_id;
7871         cmdline_fixed_string_t vf;
7872         uint8_t vf_id;
7873         struct ether_addr address;
7874         cmdline_fixed_string_t filter_type;
7875         cmdline_fixed_string_t mode;
7876 };
7877
7878 static void
7879 cmd_set_vf_macvlan_parsed(void *parsed_result,
7880                        __attribute__((unused)) struct cmdline *cl,
7881                        __attribute__((unused)) void *data)
7882 {
7883         int is_on, ret = 0;
7884         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7885         struct rte_eth_mac_filter filter;
7886
7887         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7888
7889         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7890
7891         /* set VF MAC filter */
7892         filter.is_vf = 1;
7893
7894         /* set VF ID */
7895         filter.dst_id = res->vf_id;
7896
7897         if (!strcmp(res->filter_type, "exact-mac"))
7898                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7899         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7900                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7901         else if (!strcmp(res->filter_type, "hashmac"))
7902                 filter.filter_type = RTE_MAC_HASH_MATCH;
7903         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7904                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7905
7906         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7907
7908         if (is_on)
7909                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7910                                         RTE_ETH_FILTER_MACVLAN,
7911                                         RTE_ETH_FILTER_ADD,
7912                                          &filter);
7913         else
7914                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7915                                         RTE_ETH_FILTER_MACVLAN,
7916                                         RTE_ETH_FILTER_DELETE,
7917                                         &filter);
7918
7919         if (ret < 0)
7920                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7921
7922 }
7923
7924 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7925         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7926                                  set, "set");
7927 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7928         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7929                                  port, "port");
7930 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7931         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7932                               port_id, UINT16);
7933 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7934         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7935                                  vf, "vf");
7936 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7937         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7938                                 vf_id, UINT8);
7939 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7940         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7941                                 address);
7942 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7943         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7944                                 filter_type, "exact-mac#exact-mac-vlan"
7945                                 "#hashmac#hashmac-vlan");
7946 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7947         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7948                                  mode, "on#off");
7949
7950 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7951         .f = cmd_set_vf_macvlan_parsed,
7952         .data = NULL,
7953         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7954                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7955                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7956                 "hash match rule: hash match of MAC and exact match of VLAN",
7957         .tokens = {
7958                 (void *)&cmd_set_vf_macvlan_set,
7959                 (void *)&cmd_set_vf_macvlan_port,
7960                 (void *)&cmd_set_vf_macvlan_portid,
7961                 (void *)&cmd_set_vf_macvlan_vf,
7962                 (void *)&cmd_set_vf_macvlan_vf_id,
7963                 (void *)&cmd_set_vf_macvlan_mac,
7964                 (void *)&cmd_set_vf_macvlan_filter_type,
7965                 (void *)&cmd_set_vf_macvlan_mode,
7966                 NULL,
7967         },
7968 };
7969
7970 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7971 struct cmd_set_vf_traffic {
7972         cmdline_fixed_string_t set;
7973         cmdline_fixed_string_t port;
7974         portid_t port_id;
7975         cmdline_fixed_string_t vf;
7976         uint8_t vf_id;
7977         cmdline_fixed_string_t what;
7978         cmdline_fixed_string_t mode;
7979 };
7980
7981 static void
7982 cmd_set_vf_traffic_parsed(void *parsed_result,
7983                        __attribute__((unused)) struct cmdline *cl,
7984                        __attribute__((unused)) void *data)
7985 {
7986         struct cmd_set_vf_traffic *res = parsed_result;
7987         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7988         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7989
7990         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7991 }
7992
7993 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7994         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7995                                  set, "set");
7996 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7997         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7998                                  port, "port");
7999 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8000         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8001                               port_id, UINT16);
8002 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8003         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8004                                  vf, "vf");
8005 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8006         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8007                               vf_id, UINT8);
8008 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8009         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8010                                  what, "tx#rx");
8011 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8012         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8013                                  mode, "on#off");
8014
8015 cmdline_parse_inst_t cmd_set_vf_traffic = {
8016         .f = cmd_set_vf_traffic_parsed,
8017         .data = NULL,
8018         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8019         .tokens = {
8020                 (void *)&cmd_setvf_traffic_set,
8021                 (void *)&cmd_setvf_traffic_port,
8022                 (void *)&cmd_setvf_traffic_portid,
8023                 (void *)&cmd_setvf_traffic_vf,
8024                 (void *)&cmd_setvf_traffic_vfid,
8025                 (void *)&cmd_setvf_traffic_what,
8026                 (void *)&cmd_setvf_traffic_mode,
8027                 NULL,
8028         },
8029 };
8030
8031 /* *** CONFIGURE VF RECEIVE MODE *** */
8032 struct cmd_set_vf_rxmode {
8033         cmdline_fixed_string_t set;
8034         cmdline_fixed_string_t port;
8035         portid_t port_id;
8036         cmdline_fixed_string_t vf;
8037         uint8_t vf_id;
8038         cmdline_fixed_string_t what;
8039         cmdline_fixed_string_t mode;
8040         cmdline_fixed_string_t on;
8041 };
8042
8043 static void
8044 cmd_set_vf_rxmode_parsed(void *parsed_result,
8045                        __attribute__((unused)) struct cmdline *cl,
8046                        __attribute__((unused)) void *data)
8047 {
8048         int ret = -ENOTSUP;
8049         uint16_t rx_mode = 0;
8050         struct cmd_set_vf_rxmode *res = parsed_result;
8051
8052         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8053         if (!strcmp(res->what,"rxmode")) {
8054                 if (!strcmp(res->mode, "AUPE"))
8055                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8056                 else if (!strcmp(res->mode, "ROPE"))
8057                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8058                 else if (!strcmp(res->mode, "BAM"))
8059                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8060                 else if (!strncmp(res->mode, "MPE",3))
8061                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8062         }
8063
8064         RTE_SET_USED(is_on);
8065
8066 #ifdef RTE_LIBRTE_IXGBE_PMD
8067         if (ret == -ENOTSUP)
8068                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8069                                                   rx_mode, (uint8_t)is_on);
8070 #endif
8071 #ifdef RTE_LIBRTE_BNXT_PMD
8072         if (ret == -ENOTSUP)
8073                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8074                                                  rx_mode, (uint8_t)is_on);
8075 #endif
8076         if (ret < 0)
8077                 printf("bad VF receive mode parameter, return code = %d \n",
8078                 ret);
8079 }
8080
8081 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8082         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8083                                  set, "set");
8084 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8085         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8086                                  port, "port");
8087 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8088         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8089                               port_id, UINT16);
8090 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8091         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8092                                  vf, "vf");
8093 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8094         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8095                               vf_id, UINT8);
8096 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8097         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8098                                  what, "rxmode");
8099 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8100         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8101                                  mode, "AUPE#ROPE#BAM#MPE");
8102 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8103         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8104                                  on, "on#off");
8105
8106 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8107         .f = cmd_set_vf_rxmode_parsed,
8108         .data = NULL,
8109         .help_str = "set port <port_id> vf <vf_id> rxmode "
8110                 "AUPE|ROPE|BAM|MPE on|off",
8111         .tokens = {
8112                 (void *)&cmd_set_vf_rxmode_set,
8113                 (void *)&cmd_set_vf_rxmode_port,
8114                 (void *)&cmd_set_vf_rxmode_portid,
8115                 (void *)&cmd_set_vf_rxmode_vf,
8116                 (void *)&cmd_set_vf_rxmode_vfid,
8117                 (void *)&cmd_set_vf_rxmode_what,
8118                 (void *)&cmd_set_vf_rxmode_mode,
8119                 (void *)&cmd_set_vf_rxmode_on,
8120                 NULL,
8121         },
8122 };
8123
8124 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8125 struct cmd_vf_mac_addr_result {
8126         cmdline_fixed_string_t mac_addr_cmd;
8127         cmdline_fixed_string_t what;
8128         cmdline_fixed_string_t port;
8129         uint16_t port_num;
8130         cmdline_fixed_string_t vf;
8131         uint8_t vf_num;
8132         struct ether_addr address;
8133 };
8134
8135 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8136                 __attribute__((unused)) struct cmdline *cl,
8137                 __attribute__((unused)) void *data)
8138 {
8139         struct cmd_vf_mac_addr_result *res = parsed_result;
8140         int ret = -ENOTSUP;
8141
8142         if (strcmp(res->what, "add") != 0)
8143                 return;
8144
8145 #ifdef RTE_LIBRTE_I40E_PMD
8146         if (ret == -ENOTSUP)
8147                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8148                                                    &res->address);
8149 #endif
8150 #ifdef RTE_LIBRTE_BNXT_PMD
8151         if (ret == -ENOTSUP)
8152                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8153                                                 res->vf_num);
8154 #endif
8155
8156         if(ret < 0)
8157                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8158
8159 }
8160
8161 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8162         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8163                                 mac_addr_cmd,"mac_addr");
8164 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8165         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8166                                 what,"add");
8167 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8168         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8169                                 port,"port");
8170 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8171         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8172                                 port_num, UINT16);
8173 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8174         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8175                                 vf,"vf");
8176 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8177         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8178                                 vf_num, UINT8);
8179 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8180         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8181                                 address);
8182
8183 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8184         .f = cmd_vf_mac_addr_parsed,
8185         .data = (void *)0,
8186         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8187                 "Add MAC address filtering for a VF on port_id",
8188         .tokens = {
8189                 (void *)&cmd_vf_mac_addr_cmd,
8190                 (void *)&cmd_vf_mac_addr_what,
8191                 (void *)&cmd_vf_mac_addr_port,
8192                 (void *)&cmd_vf_mac_addr_portnum,
8193                 (void *)&cmd_vf_mac_addr_vf,
8194                 (void *)&cmd_vf_mac_addr_vfnum,
8195                 (void *)&cmd_vf_mac_addr_addr,
8196                 NULL,
8197         },
8198 };
8199
8200 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8201 struct cmd_vf_rx_vlan_filter {
8202         cmdline_fixed_string_t rx_vlan;
8203         cmdline_fixed_string_t what;
8204         uint16_t vlan_id;
8205         cmdline_fixed_string_t port;
8206         portid_t port_id;
8207         cmdline_fixed_string_t vf;
8208         uint64_t vf_mask;
8209 };
8210
8211 static void
8212 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8213                           __attribute__((unused)) struct cmdline *cl,
8214                           __attribute__((unused)) void *data)
8215 {
8216         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8217         int ret = -ENOTSUP;
8218
8219         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8220
8221 #ifdef RTE_LIBRTE_IXGBE_PMD
8222         if (ret == -ENOTSUP)
8223                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8224                                 res->vlan_id, res->vf_mask, is_add);
8225 #endif
8226 #ifdef RTE_LIBRTE_I40E_PMD
8227         if (ret == -ENOTSUP)
8228                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8229                                 res->vlan_id, res->vf_mask, is_add);
8230 #endif
8231 #ifdef RTE_LIBRTE_BNXT_PMD
8232         if (ret == -ENOTSUP)
8233                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8234                                 res->vlan_id, res->vf_mask, is_add);
8235 #endif
8236
8237         switch (ret) {
8238         case 0:
8239                 break;
8240         case -EINVAL:
8241                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8242                                 res->vlan_id, res->vf_mask);
8243                 break;
8244         case -ENODEV:
8245                 printf("invalid port_id %d\n", res->port_id);
8246                 break;
8247         case -ENOTSUP:
8248                 printf("function not implemented or supported\n");
8249                 break;
8250         default:
8251                 printf("programming error: (%s)\n", strerror(-ret));
8252         }
8253 }
8254
8255 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8256         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8257                                  rx_vlan, "rx_vlan");
8258 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8259         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8260                                  what, "add#rm");
8261 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8262         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8263                               vlan_id, UINT16);
8264 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8265         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8266                                  port, "port");
8267 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8268         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8269                               port_id, UINT16);
8270 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8271         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8272                                  vf, "vf");
8273 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8274         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8275                               vf_mask, UINT64);
8276
8277 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8278         .f = cmd_vf_rx_vlan_filter_parsed,
8279         .data = NULL,
8280         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8281                 "(vf_mask = hexadecimal VF mask)",
8282         .tokens = {
8283                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8284                 (void *)&cmd_vf_rx_vlan_filter_what,
8285                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8286                 (void *)&cmd_vf_rx_vlan_filter_port,
8287                 (void *)&cmd_vf_rx_vlan_filter_portid,
8288                 (void *)&cmd_vf_rx_vlan_filter_vf,
8289                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8290                 NULL,
8291         },
8292 };
8293
8294 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8295 struct cmd_queue_rate_limit_result {
8296         cmdline_fixed_string_t set;
8297         cmdline_fixed_string_t port;
8298         uint16_t port_num;
8299         cmdline_fixed_string_t queue;
8300         uint8_t queue_num;
8301         cmdline_fixed_string_t rate;
8302         uint16_t rate_num;
8303 };
8304
8305 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8306                 __attribute__((unused)) struct cmdline *cl,
8307                 __attribute__((unused)) void *data)
8308 {
8309         struct cmd_queue_rate_limit_result *res = parsed_result;
8310         int ret = 0;
8311
8312         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8313                 && (strcmp(res->queue, "queue") == 0)
8314                 && (strcmp(res->rate, "rate") == 0))
8315                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8316                                         res->rate_num);
8317         if (ret < 0)
8318                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8319
8320 }
8321
8322 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8323         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8324                                 set, "set");
8325 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8326         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8327                                 port, "port");
8328 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8329         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8330                                 port_num, UINT16);
8331 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8332         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8333                                 queue, "queue");
8334 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8335         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8336                                 queue_num, UINT8);
8337 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8338         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8339                                 rate, "rate");
8340 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8341         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8342                                 rate_num, UINT16);
8343
8344 cmdline_parse_inst_t cmd_queue_rate_limit = {
8345         .f = cmd_queue_rate_limit_parsed,
8346         .data = (void *)0,
8347         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8348                 "Set rate limit for a queue on port_id",
8349         .tokens = {
8350                 (void *)&cmd_queue_rate_limit_set,
8351                 (void *)&cmd_queue_rate_limit_port,
8352                 (void *)&cmd_queue_rate_limit_portnum,
8353                 (void *)&cmd_queue_rate_limit_queue,
8354                 (void *)&cmd_queue_rate_limit_queuenum,
8355                 (void *)&cmd_queue_rate_limit_rate,
8356                 (void *)&cmd_queue_rate_limit_ratenum,
8357                 NULL,
8358         },
8359 };
8360
8361 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8362 struct cmd_vf_rate_limit_result {
8363         cmdline_fixed_string_t set;
8364         cmdline_fixed_string_t port;
8365         uint16_t port_num;
8366         cmdline_fixed_string_t vf;
8367         uint8_t vf_num;
8368         cmdline_fixed_string_t rate;
8369         uint16_t rate_num;
8370         cmdline_fixed_string_t q_msk;
8371         uint64_t q_msk_val;
8372 };
8373
8374 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8375                 __attribute__((unused)) struct cmdline *cl,
8376                 __attribute__((unused)) void *data)
8377 {
8378         struct cmd_vf_rate_limit_result *res = parsed_result;
8379         int ret = 0;
8380
8381         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8382                 && (strcmp(res->vf, "vf") == 0)
8383                 && (strcmp(res->rate, "rate") == 0)
8384                 && (strcmp(res->q_msk, "queue_mask") == 0))
8385                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8386                                         res->rate_num, res->q_msk_val);
8387         if (ret < 0)
8388                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8389
8390 }
8391
8392 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8393         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8394                                 set, "set");
8395 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8396         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8397                                 port, "port");
8398 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8399         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8400                                 port_num, UINT16);
8401 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8402         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8403                                 vf, "vf");
8404 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8405         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8406                                 vf_num, UINT8);
8407 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8408         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8409                                 rate, "rate");
8410 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8411         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8412                                 rate_num, UINT16);
8413 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8414         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8415                                 q_msk, "queue_mask");
8416 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8417         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8418                                 q_msk_val, UINT64);
8419
8420 cmdline_parse_inst_t cmd_vf_rate_limit = {
8421         .f = cmd_vf_rate_limit_parsed,
8422         .data = (void *)0,
8423         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8424                 "queue_mask <queue_mask_value>: "
8425                 "Set rate limit for queues of VF on port_id",
8426         .tokens = {
8427                 (void *)&cmd_vf_rate_limit_set,
8428                 (void *)&cmd_vf_rate_limit_port,
8429                 (void *)&cmd_vf_rate_limit_portnum,
8430                 (void *)&cmd_vf_rate_limit_vf,
8431                 (void *)&cmd_vf_rate_limit_vfnum,
8432                 (void *)&cmd_vf_rate_limit_rate,
8433                 (void *)&cmd_vf_rate_limit_ratenum,
8434                 (void *)&cmd_vf_rate_limit_q_msk,
8435                 (void *)&cmd_vf_rate_limit_q_msk_val,
8436                 NULL,
8437         },
8438 };
8439
8440 /* *** ADD TUNNEL FILTER OF A PORT *** */
8441 struct cmd_tunnel_filter_result {
8442         cmdline_fixed_string_t cmd;
8443         cmdline_fixed_string_t what;
8444         portid_t port_id;
8445         struct ether_addr outer_mac;
8446         struct ether_addr inner_mac;
8447         cmdline_ipaddr_t ip_value;
8448         uint16_t inner_vlan;
8449         cmdline_fixed_string_t tunnel_type;
8450         cmdline_fixed_string_t filter_type;
8451         uint32_t tenant_id;
8452         uint16_t queue_num;
8453 };
8454
8455 static void
8456 cmd_tunnel_filter_parsed(void *parsed_result,
8457                           __attribute__((unused)) struct cmdline *cl,
8458                           __attribute__((unused)) void *data)
8459 {
8460         struct cmd_tunnel_filter_result *res = parsed_result;
8461         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8462         int ret = 0;
8463
8464         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8465
8466         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8467         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8468         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8469
8470         if (res->ip_value.family == AF_INET) {
8471                 tunnel_filter_conf.ip_addr.ipv4_addr =
8472                         res->ip_value.addr.ipv4.s_addr;
8473                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8474         } else {
8475                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8476                         &(res->ip_value.addr.ipv6),
8477                         sizeof(struct in6_addr));
8478                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8479         }
8480
8481         if (!strcmp(res->filter_type, "imac-ivlan"))
8482                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8483         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8484                 tunnel_filter_conf.filter_type =
8485                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8486         else if (!strcmp(res->filter_type, "imac-tenid"))
8487                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8488         else if (!strcmp(res->filter_type, "imac"))
8489                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8490         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8491                 tunnel_filter_conf.filter_type =
8492                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8493         else if (!strcmp(res->filter_type, "oip"))
8494                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8495         else if (!strcmp(res->filter_type, "iip"))
8496                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8497         else {
8498                 printf("The filter type is not supported");
8499                 return;
8500         }
8501
8502         if (!strcmp(res->tunnel_type, "vxlan"))
8503                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8504         else if (!strcmp(res->tunnel_type, "nvgre"))
8505                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8506         else if (!strcmp(res->tunnel_type, "ipingre"))
8507                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8508         else {
8509                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8510                 return;
8511         }
8512
8513         tunnel_filter_conf.tenant_id = res->tenant_id;
8514         tunnel_filter_conf.queue_id = res->queue_num;
8515         if (!strcmp(res->what, "add"))
8516                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8517                                         RTE_ETH_FILTER_TUNNEL,
8518                                         RTE_ETH_FILTER_ADD,
8519                                         &tunnel_filter_conf);
8520         else
8521                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8522                                         RTE_ETH_FILTER_TUNNEL,
8523                                         RTE_ETH_FILTER_DELETE,
8524                                         &tunnel_filter_conf);
8525         if (ret < 0)
8526                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8527                                 strerror(-ret));
8528
8529 }
8530 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8531         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8532         cmd, "tunnel_filter");
8533 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8534         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8535         what, "add#rm");
8536 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8537         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8538         port_id, UINT16);
8539 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8540         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8541         outer_mac);
8542 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8543         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8544         inner_mac);
8545 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8546         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8547         inner_vlan, UINT16);
8548 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8549         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8550         ip_value);
8551 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8552         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8553         tunnel_type, "vxlan#nvgre#ipingre");
8554
8555 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8556         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8557         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8558                 "imac#omac-imac-tenid");
8559 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8560         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8561         tenant_id, UINT32);
8562 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8563         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8564         queue_num, UINT16);
8565
8566 cmdline_parse_inst_t cmd_tunnel_filter = {
8567         .f = cmd_tunnel_filter_parsed,
8568         .data = (void *)0,
8569         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8570                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8571                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8572                 "<queue_id>: Add/Rm tunnel filter of a port",
8573         .tokens = {
8574                 (void *)&cmd_tunnel_filter_cmd,
8575                 (void *)&cmd_tunnel_filter_what,
8576                 (void *)&cmd_tunnel_filter_port_id,
8577                 (void *)&cmd_tunnel_filter_outer_mac,
8578                 (void *)&cmd_tunnel_filter_inner_mac,
8579                 (void *)&cmd_tunnel_filter_ip_value,
8580                 (void *)&cmd_tunnel_filter_innner_vlan,
8581                 (void *)&cmd_tunnel_filter_tunnel_type,
8582                 (void *)&cmd_tunnel_filter_filter_type,
8583                 (void *)&cmd_tunnel_filter_tenant_id,
8584                 (void *)&cmd_tunnel_filter_queue_num,
8585                 NULL,
8586         },
8587 };
8588
8589 /* *** CONFIGURE TUNNEL UDP PORT *** */
8590 struct cmd_tunnel_udp_config {
8591         cmdline_fixed_string_t cmd;
8592         cmdline_fixed_string_t what;
8593         uint16_t udp_port;
8594         portid_t port_id;
8595 };
8596
8597 static void
8598 cmd_tunnel_udp_config_parsed(void *parsed_result,
8599                           __attribute__((unused)) struct cmdline *cl,
8600                           __attribute__((unused)) void *data)
8601 {
8602         struct cmd_tunnel_udp_config *res = parsed_result;
8603         struct rte_eth_udp_tunnel tunnel_udp;
8604         int ret;
8605
8606         tunnel_udp.udp_port = res->udp_port;
8607
8608         if (!strcmp(res->cmd, "rx_vxlan_port"))
8609                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8610
8611         if (!strcmp(res->what, "add"))
8612                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8613                                                       &tunnel_udp);
8614         else
8615                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8616                                                          &tunnel_udp);
8617
8618         if (ret < 0)
8619                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8620 }
8621
8622 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8623         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8624                                 cmd, "rx_vxlan_port");
8625 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8626         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8627                                 what, "add#rm");
8628 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8629         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8630                                 udp_port, UINT16);
8631 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8632         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8633                                 port_id, UINT16);
8634
8635 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8636         .f = cmd_tunnel_udp_config_parsed,
8637         .data = (void *)0,
8638         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8639                 "Add/Remove a tunneling UDP port filter",
8640         .tokens = {
8641                 (void *)&cmd_tunnel_udp_config_cmd,
8642                 (void *)&cmd_tunnel_udp_config_what,
8643                 (void *)&cmd_tunnel_udp_config_udp_port,
8644                 (void *)&cmd_tunnel_udp_config_port_id,
8645                 NULL,
8646         },
8647 };
8648
8649 struct cmd_config_tunnel_udp_port {
8650         cmdline_fixed_string_t port;
8651         cmdline_fixed_string_t config;
8652         portid_t port_id;
8653         cmdline_fixed_string_t udp_tunnel_port;
8654         cmdline_fixed_string_t action;
8655         cmdline_fixed_string_t tunnel_type;
8656         uint16_t udp_port;
8657 };
8658
8659 static void
8660 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8661                                __attribute__((unused)) struct cmdline *cl,
8662                                __attribute__((unused)) void *data)
8663 {
8664         struct cmd_config_tunnel_udp_port *res = parsed_result;
8665         struct rte_eth_udp_tunnel tunnel_udp;
8666         int ret = 0;
8667
8668         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8669                 return;
8670
8671         tunnel_udp.udp_port = res->udp_port;
8672
8673         if (!strcmp(res->tunnel_type, "vxlan")) {
8674                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8675         } else if (!strcmp(res->tunnel_type, "geneve")) {
8676                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8677         } else {
8678                 printf("Invalid tunnel type\n");
8679                 return;
8680         }
8681
8682         if (!strcmp(res->action, "add"))
8683                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8684                                                       &tunnel_udp);
8685         else
8686                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8687                                                          &tunnel_udp);
8688
8689         if (ret < 0)
8690                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8691 }
8692
8693 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8694         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8695                                  "port");
8696 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8697         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8698                                  "config");
8699 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8700         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8701                               UINT16);
8702 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8703         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8704                                  udp_tunnel_port,
8705                                  "udp_tunnel_port");
8706 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8707         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8708                                  "add#rm");
8709 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8710         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8711                                  "vxlan#geneve");
8712 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8713         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8714                               UINT16);
8715
8716 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8717         .f = cmd_cfg_tunnel_udp_port_parsed,
8718         .data = NULL,
8719         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8720         .tokens = {
8721                 (void *)&cmd_config_tunnel_udp_port_port,
8722                 (void *)&cmd_config_tunnel_udp_port_config,
8723                 (void *)&cmd_config_tunnel_udp_port_port_id,
8724                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8725                 (void *)&cmd_config_tunnel_udp_port_action,
8726                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8727                 (void *)&cmd_config_tunnel_udp_port_value,
8728                 NULL,
8729         },
8730 };
8731
8732 /* *** GLOBAL CONFIG *** */
8733 struct cmd_global_config_result {
8734         cmdline_fixed_string_t cmd;
8735         portid_t port_id;
8736         cmdline_fixed_string_t cfg_type;
8737         uint8_t len;
8738 };
8739
8740 static void
8741 cmd_global_config_parsed(void *parsed_result,
8742                          __attribute__((unused)) struct cmdline *cl,
8743                          __attribute__((unused)) void *data)
8744 {
8745         struct cmd_global_config_result *res = parsed_result;
8746         struct rte_eth_global_cfg conf;
8747         int ret;
8748
8749         memset(&conf, 0, sizeof(conf));
8750         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8751         conf.cfg.gre_key_len = res->len;
8752         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8753                                       RTE_ETH_FILTER_SET, &conf);
8754         if (ret != 0)
8755                 printf("Global config error\n");
8756 }
8757
8758 cmdline_parse_token_string_t cmd_global_config_cmd =
8759         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8760                 "global_config");
8761 cmdline_parse_token_num_t cmd_global_config_port_id =
8762         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8763                                UINT16);
8764 cmdline_parse_token_string_t cmd_global_config_type =
8765         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8766                 cfg_type, "gre-key-len");
8767 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8768         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8769                 len, UINT8);
8770
8771 cmdline_parse_inst_t cmd_global_config = {
8772         .f = cmd_global_config_parsed,
8773         .data = (void *)NULL,
8774         .help_str = "global_config <port_id> gre-key-len <key_len>",
8775         .tokens = {
8776                 (void *)&cmd_global_config_cmd,
8777                 (void *)&cmd_global_config_port_id,
8778                 (void *)&cmd_global_config_type,
8779                 (void *)&cmd_global_config_gre_key_len,
8780                 NULL,
8781         },
8782 };
8783
8784 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8785 struct cmd_set_mirror_mask_result {
8786         cmdline_fixed_string_t set;
8787         cmdline_fixed_string_t port;
8788         portid_t port_id;
8789         cmdline_fixed_string_t mirror;
8790         uint8_t rule_id;
8791         cmdline_fixed_string_t what;
8792         cmdline_fixed_string_t value;
8793         cmdline_fixed_string_t dstpool;
8794         uint8_t dstpool_id;
8795         cmdline_fixed_string_t on;
8796 };
8797
8798 cmdline_parse_token_string_t cmd_mirror_mask_set =
8799         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8800                                 set, "set");
8801 cmdline_parse_token_string_t cmd_mirror_mask_port =
8802         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8803                                 port, "port");
8804 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8805         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8806                                 port_id, UINT16);
8807 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8808         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8809                                 mirror, "mirror-rule");
8810 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8811         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8812                                 rule_id, UINT8);
8813 cmdline_parse_token_string_t cmd_mirror_mask_what =
8814         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8815                                 what, "pool-mirror-up#pool-mirror-down"
8816                                       "#vlan-mirror");
8817 cmdline_parse_token_string_t cmd_mirror_mask_value =
8818         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8819                                 value, NULL);
8820 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8821         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8822                                 dstpool, "dst-pool");
8823 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8824         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8825                                 dstpool_id, UINT8);
8826 cmdline_parse_token_string_t cmd_mirror_mask_on =
8827         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8828                                 on, "on#off");
8829
8830 static void
8831 cmd_set_mirror_mask_parsed(void *parsed_result,
8832                        __attribute__((unused)) struct cmdline *cl,
8833                        __attribute__((unused)) void *data)
8834 {
8835         int ret,nb_item,i;
8836         struct cmd_set_mirror_mask_result *res = parsed_result;
8837         struct rte_eth_mirror_conf mr_conf;
8838
8839         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8840
8841         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8842
8843         mr_conf.dst_pool = res->dstpool_id;
8844
8845         if (!strcmp(res->what, "pool-mirror-up")) {
8846                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8847                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8848         } else if (!strcmp(res->what, "pool-mirror-down")) {
8849                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8850                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8851         } else if (!strcmp(res->what, "vlan-mirror")) {
8852                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8853                 nb_item = parse_item_list(res->value, "vlan",
8854                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8855                 if (nb_item <= 0)
8856                         return;
8857
8858                 for (i = 0; i < nb_item; i++) {
8859                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8860                                 printf("Invalid vlan_id: must be < 4096\n");
8861                                 return;
8862                         }
8863
8864                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8865                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8866                 }
8867         }
8868
8869         if (!strcmp(res->on, "on"))
8870                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8871                                                 res->rule_id, 1);
8872         else
8873                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8874                                                 res->rule_id, 0);
8875         if (ret < 0)
8876                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8877 }
8878
8879 cmdline_parse_inst_t cmd_set_mirror_mask = {
8880                 .f = cmd_set_mirror_mask_parsed,
8881                 .data = NULL,
8882                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8883                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8884                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8885                 .tokens = {
8886                         (void *)&cmd_mirror_mask_set,
8887                         (void *)&cmd_mirror_mask_port,
8888                         (void *)&cmd_mirror_mask_portid,
8889                         (void *)&cmd_mirror_mask_mirror,
8890                         (void *)&cmd_mirror_mask_ruleid,
8891                         (void *)&cmd_mirror_mask_what,
8892                         (void *)&cmd_mirror_mask_value,
8893                         (void *)&cmd_mirror_mask_dstpool,
8894                         (void *)&cmd_mirror_mask_poolid,
8895                         (void *)&cmd_mirror_mask_on,
8896                         NULL,
8897                 },
8898 };
8899
8900 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8901 struct cmd_set_mirror_link_result {
8902         cmdline_fixed_string_t set;
8903         cmdline_fixed_string_t port;
8904         portid_t port_id;
8905         cmdline_fixed_string_t mirror;
8906         uint8_t rule_id;
8907         cmdline_fixed_string_t what;
8908         cmdline_fixed_string_t dstpool;
8909         uint8_t dstpool_id;
8910         cmdline_fixed_string_t on;
8911 };
8912
8913 cmdline_parse_token_string_t cmd_mirror_link_set =
8914         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8915                                  set, "set");
8916 cmdline_parse_token_string_t cmd_mirror_link_port =
8917         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8918                                 port, "port");
8919 cmdline_parse_token_num_t cmd_mirror_link_portid =
8920         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8921                                 port_id, UINT16);
8922 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8923         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8924                                 mirror, "mirror-rule");
8925 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8926         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8927                             rule_id, UINT8);
8928 cmdline_parse_token_string_t cmd_mirror_link_what =
8929         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8930                                 what, "uplink-mirror#downlink-mirror");
8931 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8932         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8933                                 dstpool, "dst-pool");
8934 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8935         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8936                                 dstpool_id, UINT8);
8937 cmdline_parse_token_string_t cmd_mirror_link_on =
8938         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8939                                 on, "on#off");
8940
8941 static void
8942 cmd_set_mirror_link_parsed(void *parsed_result,
8943                        __attribute__((unused)) struct cmdline *cl,
8944                        __attribute__((unused)) void *data)
8945 {
8946         int ret;
8947         struct cmd_set_mirror_link_result *res = parsed_result;
8948         struct rte_eth_mirror_conf mr_conf;
8949
8950         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8951         if (!strcmp(res->what, "uplink-mirror"))
8952                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8953         else
8954                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8955
8956         mr_conf.dst_pool = res->dstpool_id;
8957
8958         if (!strcmp(res->on, "on"))
8959                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8960                                                 res->rule_id, 1);
8961         else
8962                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8963                                                 res->rule_id, 0);
8964
8965         /* check the return value and print it if is < 0 */
8966         if (ret < 0)
8967                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8968
8969 }
8970
8971 cmdline_parse_inst_t cmd_set_mirror_link = {
8972                 .f = cmd_set_mirror_link_parsed,
8973                 .data = NULL,
8974                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8975                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8976                 .tokens = {
8977                         (void *)&cmd_mirror_link_set,
8978                         (void *)&cmd_mirror_link_port,
8979                         (void *)&cmd_mirror_link_portid,
8980                         (void *)&cmd_mirror_link_mirror,
8981                         (void *)&cmd_mirror_link_ruleid,
8982                         (void *)&cmd_mirror_link_what,
8983                         (void *)&cmd_mirror_link_dstpool,
8984                         (void *)&cmd_mirror_link_poolid,
8985                         (void *)&cmd_mirror_link_on,
8986                         NULL,
8987                 },
8988 };
8989
8990 /* *** RESET VM MIRROR RULE *** */
8991 struct cmd_rm_mirror_rule_result {
8992         cmdline_fixed_string_t reset;
8993         cmdline_fixed_string_t port;
8994         portid_t port_id;
8995         cmdline_fixed_string_t mirror;
8996         uint8_t rule_id;
8997 };
8998
8999 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9000         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9001                                  reset, "reset");
9002 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9003         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9004                                 port, "port");
9005 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9006         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9007                                 port_id, UINT16);
9008 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9009         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9010                                 mirror, "mirror-rule");
9011 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9012         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9013                                 rule_id, UINT8);
9014
9015 static void
9016 cmd_reset_mirror_rule_parsed(void *parsed_result,
9017                        __attribute__((unused)) struct cmdline *cl,
9018                        __attribute__((unused)) void *data)
9019 {
9020         int ret;
9021         struct cmd_set_mirror_link_result *res = parsed_result;
9022         /* check rule_id */
9023         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9024         if(ret < 0)
9025                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9026 }
9027
9028 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9029                 .f = cmd_reset_mirror_rule_parsed,
9030                 .data = NULL,
9031                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9032                 .tokens = {
9033                         (void *)&cmd_rm_mirror_rule_reset,
9034                         (void *)&cmd_rm_mirror_rule_port,
9035                         (void *)&cmd_rm_mirror_rule_portid,
9036                         (void *)&cmd_rm_mirror_rule_mirror,
9037                         (void *)&cmd_rm_mirror_rule_ruleid,
9038                         NULL,
9039                 },
9040 };
9041
9042 /* ******************************************************************************** */
9043
9044 struct cmd_dump_result {
9045         cmdline_fixed_string_t dump;
9046 };
9047
9048 static void
9049 dump_struct_sizes(void)
9050 {
9051 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9052         DUMP_SIZE(struct rte_mbuf);
9053         DUMP_SIZE(struct rte_mempool);
9054         DUMP_SIZE(struct rte_ring);
9055 #undef DUMP_SIZE
9056 }
9057
9058 static void cmd_dump_parsed(void *parsed_result,
9059                             __attribute__((unused)) struct cmdline *cl,
9060                             __attribute__((unused)) void *data)
9061 {
9062         struct cmd_dump_result *res = parsed_result;
9063
9064         if (!strcmp(res->dump, "dump_physmem"))
9065                 rte_dump_physmem_layout(stdout);
9066         else if (!strcmp(res->dump, "dump_memzone"))
9067                 rte_memzone_dump(stdout);
9068         else if (!strcmp(res->dump, "dump_struct_sizes"))
9069                 dump_struct_sizes();
9070         else if (!strcmp(res->dump, "dump_ring"))
9071                 rte_ring_list_dump(stdout);
9072         else if (!strcmp(res->dump, "dump_mempool"))
9073                 rte_mempool_list_dump(stdout);
9074         else if (!strcmp(res->dump, "dump_devargs"))
9075                 rte_devargs_dump(stdout);
9076         else if (!strcmp(res->dump, "dump_log_types"))
9077                 rte_log_dump(stdout);
9078 }
9079
9080 cmdline_parse_token_string_t cmd_dump_dump =
9081         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9082                 "dump_physmem#"
9083                 "dump_memzone#"
9084                 "dump_struct_sizes#"
9085                 "dump_ring#"
9086                 "dump_mempool#"
9087                 "dump_devargs#"
9088                 "dump_log_types");
9089
9090 cmdline_parse_inst_t cmd_dump = {
9091         .f = cmd_dump_parsed,  /* function to call */
9092         .data = NULL,      /* 2nd arg of func */
9093         .help_str = "Dump status",
9094         .tokens = {        /* token list, NULL terminated */
9095                 (void *)&cmd_dump_dump,
9096                 NULL,
9097         },
9098 };
9099
9100 /* ******************************************************************************** */
9101
9102 struct cmd_dump_one_result {
9103         cmdline_fixed_string_t dump;
9104         cmdline_fixed_string_t name;
9105 };
9106
9107 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9108                                 __attribute__((unused)) void *data)
9109 {
9110         struct cmd_dump_one_result *res = parsed_result;
9111
9112         if (!strcmp(res->dump, "dump_ring")) {
9113                 struct rte_ring *r;
9114                 r = rte_ring_lookup(res->name);
9115                 if (r == NULL) {
9116                         cmdline_printf(cl, "Cannot find ring\n");
9117                         return;
9118                 }
9119                 rte_ring_dump(stdout, r);
9120         } else if (!strcmp(res->dump, "dump_mempool")) {
9121                 struct rte_mempool *mp;
9122                 mp = rte_mempool_lookup(res->name);
9123                 if (mp == NULL) {
9124                         cmdline_printf(cl, "Cannot find mempool\n");
9125                         return;
9126                 }
9127                 rte_mempool_dump(stdout, mp);
9128         }
9129 }
9130
9131 cmdline_parse_token_string_t cmd_dump_one_dump =
9132         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9133                                  "dump_ring#dump_mempool");
9134
9135 cmdline_parse_token_string_t cmd_dump_one_name =
9136         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9137
9138 cmdline_parse_inst_t cmd_dump_one = {
9139         .f = cmd_dump_one_parsed,  /* function to call */
9140         .data = NULL,      /* 2nd arg of func */
9141         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9142         .tokens = {        /* token list, NULL terminated */
9143                 (void *)&cmd_dump_one_dump,
9144                 (void *)&cmd_dump_one_name,
9145                 NULL,
9146         },
9147 };
9148
9149 /* *** Add/Del syn filter *** */
9150 struct cmd_syn_filter_result {
9151         cmdline_fixed_string_t filter;
9152         portid_t port_id;
9153         cmdline_fixed_string_t ops;
9154         cmdline_fixed_string_t priority;
9155         cmdline_fixed_string_t high;
9156         cmdline_fixed_string_t queue;
9157         uint16_t queue_id;
9158 };
9159
9160 static void
9161 cmd_syn_filter_parsed(void *parsed_result,
9162                         __attribute__((unused)) struct cmdline *cl,
9163                         __attribute__((unused)) void *data)
9164 {
9165         struct cmd_syn_filter_result *res = parsed_result;
9166         struct rte_eth_syn_filter syn_filter;
9167         int ret = 0;
9168
9169         ret = rte_eth_dev_filter_supported(res->port_id,
9170                                         RTE_ETH_FILTER_SYN);
9171         if (ret < 0) {
9172                 printf("syn filter is not supported on port %u.\n",
9173                                 res->port_id);
9174                 return;
9175         }
9176
9177         memset(&syn_filter, 0, sizeof(syn_filter));
9178
9179         if (!strcmp(res->ops, "add")) {
9180                 if (!strcmp(res->high, "high"))
9181                         syn_filter.hig_pri = 1;
9182                 else
9183                         syn_filter.hig_pri = 0;
9184
9185                 syn_filter.queue = res->queue_id;
9186                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9187                                                 RTE_ETH_FILTER_SYN,
9188                                                 RTE_ETH_FILTER_ADD,
9189                                                 &syn_filter);
9190         } else
9191                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9192                                                 RTE_ETH_FILTER_SYN,
9193                                                 RTE_ETH_FILTER_DELETE,
9194                                                 &syn_filter);
9195
9196         if (ret < 0)
9197                 printf("syn filter programming error: (%s)\n",
9198                                 strerror(-ret));
9199 }
9200
9201 cmdline_parse_token_string_t cmd_syn_filter_filter =
9202         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9203         filter, "syn_filter");
9204 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9205         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9206         port_id, UINT16);
9207 cmdline_parse_token_string_t cmd_syn_filter_ops =
9208         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9209         ops, "add#del");
9210 cmdline_parse_token_string_t cmd_syn_filter_priority =
9211         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9212                                 priority, "priority");
9213 cmdline_parse_token_string_t cmd_syn_filter_high =
9214         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9215                                 high, "high#low");
9216 cmdline_parse_token_string_t cmd_syn_filter_queue =
9217         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9218                                 queue, "queue");
9219 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9220         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9221                                 queue_id, UINT16);
9222
9223 cmdline_parse_inst_t cmd_syn_filter = {
9224         .f = cmd_syn_filter_parsed,
9225         .data = NULL,
9226         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9227                 "<queue_id>: Add/Delete syn filter",
9228         .tokens = {
9229                 (void *)&cmd_syn_filter_filter,
9230                 (void *)&cmd_syn_filter_port_id,
9231                 (void *)&cmd_syn_filter_ops,
9232                 (void *)&cmd_syn_filter_priority,
9233                 (void *)&cmd_syn_filter_high,
9234                 (void *)&cmd_syn_filter_queue,
9235                 (void *)&cmd_syn_filter_queue_id,
9236                 NULL,
9237         },
9238 };
9239
9240 /* *** queue region set *** */
9241 struct cmd_queue_region_result {
9242         cmdline_fixed_string_t set;
9243         cmdline_fixed_string_t port;
9244         portid_t port_id;
9245         cmdline_fixed_string_t cmd;
9246         cmdline_fixed_string_t region;
9247         uint8_t  region_id;
9248         cmdline_fixed_string_t queue_start_index;
9249         uint8_t  queue_id;
9250         cmdline_fixed_string_t queue_num;
9251         uint8_t  queue_num_value;
9252 };
9253
9254 static void
9255 cmd_queue_region_parsed(void *parsed_result,
9256                         __attribute__((unused)) struct cmdline *cl,
9257                         __attribute__((unused)) void *data)
9258 {
9259         struct cmd_queue_region_result *res = parsed_result;
9260         int ret = -ENOTSUP;
9261 #ifdef RTE_LIBRTE_I40E_PMD
9262         struct rte_pmd_i40e_queue_region_conf region_conf;
9263         enum rte_pmd_i40e_queue_region_op op_type;
9264 #endif
9265
9266         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9267                 return;
9268
9269 #ifdef RTE_LIBRTE_I40E_PMD
9270         memset(&region_conf, 0, sizeof(region_conf));
9271         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9272         region_conf.region_id = res->region_id;
9273         region_conf.queue_num = res->queue_num_value;
9274         region_conf.queue_start_index = res->queue_id;
9275
9276         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9277                                 op_type, &region_conf);
9278 #endif
9279
9280         switch (ret) {
9281         case 0:
9282                 break;
9283         case -ENOTSUP:
9284                 printf("function not implemented or supported\n");
9285                 break;
9286         default:
9287                 printf("queue region config error: (%s)\n", strerror(-ret));
9288         }
9289 }
9290
9291 cmdline_parse_token_string_t cmd_queue_region_set =
9292 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9293                 set, "set");
9294 cmdline_parse_token_string_t cmd_queue_region_port =
9295         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9296 cmdline_parse_token_num_t cmd_queue_region_port_id =
9297         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9298                                 port_id, UINT16);
9299 cmdline_parse_token_string_t cmd_queue_region_cmd =
9300         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9301                                  cmd, "queue-region");
9302 cmdline_parse_token_string_t cmd_queue_region_id =
9303         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9304                                 region, "region_id");
9305 cmdline_parse_token_num_t cmd_queue_region_index =
9306         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9307                                 region_id, UINT8);
9308 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9309         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9310                                 queue_start_index, "queue_start_index");
9311 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9312         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9313                                 queue_id, UINT8);
9314 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9315         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9316                                 queue_num, "queue_num");
9317 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9318         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9319                                 queue_num_value, UINT8);
9320
9321 cmdline_parse_inst_t cmd_queue_region = {
9322         .f = cmd_queue_region_parsed,
9323         .data = NULL,
9324         .help_str = "set port <port_id> queue-region region_id <value> "
9325                 "queue_start_index <value> queue_num <value>: Set a queue region",
9326         .tokens = {
9327                 (void *)&cmd_queue_region_set,
9328                 (void *)&cmd_queue_region_port,
9329                 (void *)&cmd_queue_region_port_id,
9330                 (void *)&cmd_queue_region_cmd,
9331                 (void *)&cmd_queue_region_id,
9332                 (void *)&cmd_queue_region_index,
9333                 (void *)&cmd_queue_region_queue_start_index,
9334                 (void *)&cmd_queue_region_queue_id,
9335                 (void *)&cmd_queue_region_queue_num,
9336                 (void *)&cmd_queue_region_queue_num_value,
9337                 NULL,
9338         },
9339 };
9340
9341 /* *** queue region and flowtype set *** */
9342 struct cmd_region_flowtype_result {
9343         cmdline_fixed_string_t set;
9344         cmdline_fixed_string_t port;
9345         portid_t port_id;
9346         cmdline_fixed_string_t cmd;
9347         cmdline_fixed_string_t region;
9348         uint8_t  region_id;
9349         cmdline_fixed_string_t flowtype;
9350         uint8_t  flowtype_id;
9351 };
9352
9353 static void
9354 cmd_region_flowtype_parsed(void *parsed_result,
9355                         __attribute__((unused)) struct cmdline *cl,
9356                         __attribute__((unused)) void *data)
9357 {
9358         struct cmd_region_flowtype_result *res = parsed_result;
9359         int ret = -ENOTSUP;
9360 #ifdef RTE_LIBRTE_I40E_PMD
9361         struct rte_pmd_i40e_queue_region_conf region_conf;
9362         enum rte_pmd_i40e_queue_region_op op_type;
9363 #endif
9364
9365         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9366                 return;
9367
9368 #ifdef RTE_LIBRTE_I40E_PMD
9369         memset(&region_conf, 0, sizeof(region_conf));
9370
9371         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9372         region_conf.region_id = res->region_id;
9373         region_conf.hw_flowtype = res->flowtype_id;
9374
9375         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9376                         op_type, &region_conf);
9377 #endif
9378
9379         switch (ret) {
9380         case 0:
9381                 break;
9382         case -ENOTSUP:
9383                 printf("function not implemented or supported\n");
9384                 break;
9385         default:
9386                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9387         }
9388 }
9389
9390 cmdline_parse_token_string_t cmd_region_flowtype_set =
9391 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9392                                 set, "set");
9393 cmdline_parse_token_string_t cmd_region_flowtype_port =
9394         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9395                                 port, "port");
9396 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9397         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9398                                 port_id, UINT16);
9399 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9400         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9401                                 cmd, "queue-region");
9402 cmdline_parse_token_string_t cmd_region_flowtype_index =
9403         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9404                                 region, "region_id");
9405 cmdline_parse_token_num_t cmd_region_flowtype_id =
9406         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9407                                 region_id, UINT8);
9408 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9409         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9410                                 flowtype, "flowtype");
9411 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9412         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9413                                 flowtype_id, UINT8);
9414 cmdline_parse_inst_t cmd_region_flowtype = {
9415         .f = cmd_region_flowtype_parsed,
9416         .data = NULL,
9417         .help_str = "set port <port_id> queue-region region_id <value> "
9418                 "flowtype <value>: Set a flowtype region index",
9419         .tokens = {
9420                 (void *)&cmd_region_flowtype_set,
9421                 (void *)&cmd_region_flowtype_port,
9422                 (void *)&cmd_region_flowtype_port_index,
9423                 (void *)&cmd_region_flowtype_cmd,
9424                 (void *)&cmd_region_flowtype_index,
9425                 (void *)&cmd_region_flowtype_id,
9426                 (void *)&cmd_region_flowtype_flow_index,
9427                 (void *)&cmd_region_flowtype_flow_id,
9428                 NULL,
9429         },
9430 };
9431
9432 /* *** User Priority (UP) to queue region (region_id) set *** */
9433 struct cmd_user_priority_region_result {
9434         cmdline_fixed_string_t set;
9435         cmdline_fixed_string_t port;
9436         portid_t port_id;
9437         cmdline_fixed_string_t cmd;
9438         cmdline_fixed_string_t user_priority;
9439         uint8_t  user_priority_id;
9440         cmdline_fixed_string_t region;
9441         uint8_t  region_id;
9442 };
9443
9444 static void
9445 cmd_user_priority_region_parsed(void *parsed_result,
9446                         __attribute__((unused)) struct cmdline *cl,
9447                         __attribute__((unused)) void *data)
9448 {
9449         struct cmd_user_priority_region_result *res = parsed_result;
9450         int ret = -ENOTSUP;
9451 #ifdef RTE_LIBRTE_I40E_PMD
9452         struct rte_pmd_i40e_queue_region_conf region_conf;
9453         enum rte_pmd_i40e_queue_region_op op_type;
9454 #endif
9455
9456         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9457                 return;
9458
9459 #ifdef RTE_LIBRTE_I40E_PMD
9460         memset(&region_conf, 0, sizeof(region_conf));
9461         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9462         region_conf.user_priority = res->user_priority_id;
9463         region_conf.region_id = res->region_id;
9464
9465         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9466                                 op_type, &region_conf);
9467 #endif
9468
9469         switch (ret) {
9470         case 0:
9471                 break;
9472         case -ENOTSUP:
9473                 printf("function not implemented or supported\n");
9474                 break;
9475         default:
9476                 printf("user_priority region config error: (%s)\n",
9477                                 strerror(-ret));
9478         }
9479 }
9480
9481 cmdline_parse_token_string_t cmd_user_priority_region_set =
9482         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9483                                 set, "set");
9484 cmdline_parse_token_string_t cmd_user_priority_region_port =
9485         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9486                                 port, "port");
9487 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9488         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9489                                 port_id, UINT16);
9490 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9491         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9492                                 cmd, "queue-region");
9493 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9494         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9495                                 user_priority, "UP");
9496 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9497         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9498                                 user_priority_id, UINT8);
9499 cmdline_parse_token_string_t cmd_user_priority_region_region =
9500         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9501                                 region, "region_id");
9502 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9503         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9504                                 region_id, UINT8);
9505
9506 cmdline_parse_inst_t cmd_user_priority_region = {
9507         .f = cmd_user_priority_region_parsed,
9508         .data = NULL,
9509         .help_str = "set port <port_id> queue-region UP <value> "
9510                 "region_id <value>: Set the mapping of User Priority (UP) "
9511                 "to queue region (region_id) ",
9512         .tokens = {
9513                 (void *)&cmd_user_priority_region_set,
9514                 (void *)&cmd_user_priority_region_port,
9515                 (void *)&cmd_user_priority_region_port_index,
9516                 (void *)&cmd_user_priority_region_cmd,
9517                 (void *)&cmd_user_priority_region_UP,
9518                 (void *)&cmd_user_priority_region_UP_id,
9519                 (void *)&cmd_user_priority_region_region,
9520                 (void *)&cmd_user_priority_region_region_id,
9521                 NULL,
9522         },
9523 };
9524
9525 /* *** flush all queue region related configuration *** */
9526 struct cmd_flush_queue_region_result {
9527         cmdline_fixed_string_t set;
9528         cmdline_fixed_string_t port;
9529         portid_t port_id;
9530         cmdline_fixed_string_t cmd;
9531         cmdline_fixed_string_t flush;
9532         cmdline_fixed_string_t what;
9533 };
9534
9535 static void
9536 cmd_flush_queue_region_parsed(void *parsed_result,
9537                         __attribute__((unused)) struct cmdline *cl,
9538                         __attribute__((unused)) void *data)
9539 {
9540         struct cmd_flush_queue_region_result *res = parsed_result;
9541         int ret = -ENOTSUP;
9542 #ifdef RTE_LIBRTE_I40E_PMD
9543         struct rte_pmd_i40e_queue_region_conf region_conf;
9544         enum rte_pmd_i40e_queue_region_op op_type;
9545 #endif
9546
9547         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9548                 return;
9549
9550 #ifdef RTE_LIBRTE_I40E_PMD
9551         memset(&region_conf, 0, sizeof(region_conf));
9552
9553         if (strcmp(res->what, "on") == 0)
9554                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9555         else
9556                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9557
9558         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9559                                 op_type, &region_conf);
9560 #endif
9561
9562         switch (ret) {
9563         case 0:
9564                 break;
9565         case -ENOTSUP:
9566                 printf("function not implemented or supported\n");
9567                 break;
9568         default:
9569                 printf("queue region config flush error: (%s)\n",
9570                                 strerror(-ret));
9571         }
9572 }
9573
9574 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9575         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9576                                 set, "set");
9577 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9578         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9579                                 port, "port");
9580 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9581         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9582                                 port_id, UINT16);
9583 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9584         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9585                                 cmd, "queue-region");
9586 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9587         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9588                                 flush, "flush");
9589 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9590         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9591                                 what, "on#off");
9592
9593 cmdline_parse_inst_t cmd_flush_queue_region = {
9594         .f = cmd_flush_queue_region_parsed,
9595         .data = NULL,
9596         .help_str = "set port <port_id> queue-region flush on|off"
9597                 ": flush all queue region related configuration",
9598         .tokens = {
9599                 (void *)&cmd_flush_queue_region_set,
9600                 (void *)&cmd_flush_queue_region_port,
9601                 (void *)&cmd_flush_queue_region_port_index,
9602                 (void *)&cmd_flush_queue_region_cmd,
9603                 (void *)&cmd_flush_queue_region_flush,
9604                 (void *)&cmd_flush_queue_region_what,
9605                 NULL,
9606         },
9607 };
9608
9609 /* *** get all queue region related configuration info *** */
9610 struct cmd_show_queue_region_info {
9611         cmdline_fixed_string_t show;
9612         cmdline_fixed_string_t port;
9613         portid_t port_id;
9614         cmdline_fixed_string_t cmd;
9615 };
9616
9617 static void
9618 cmd_show_queue_region_info_parsed(void *parsed_result,
9619                         __attribute__((unused)) struct cmdline *cl,
9620                         __attribute__((unused)) void *data)
9621 {
9622         struct cmd_show_queue_region_info *res = parsed_result;
9623         int ret = -ENOTSUP;
9624 #ifdef RTE_LIBRTE_I40E_PMD
9625         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9626         enum rte_pmd_i40e_queue_region_op op_type;
9627 #endif
9628
9629         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9630                 return;
9631
9632 #ifdef RTE_LIBRTE_I40E_PMD
9633         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9634
9635         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9636
9637         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9638                                         op_type, &rte_pmd_regions);
9639
9640         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9641 #endif
9642
9643         switch (ret) {
9644         case 0:
9645                 break;
9646         case -ENOTSUP:
9647                 printf("function not implemented or supported\n");
9648                 break;
9649         default:
9650                 printf("queue region config info show error: (%s)\n",
9651                                 strerror(-ret));
9652         }
9653 }
9654
9655 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9656 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9657                                 show, "show");
9658 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9659         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9660                                 port, "port");
9661 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9662         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9663                                 port_id, UINT16);
9664 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9665         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9666                                 cmd, "queue-region");
9667
9668 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9669         .f = cmd_show_queue_region_info_parsed,
9670         .data = NULL,
9671         .help_str = "show port <port_id> queue-region"
9672                 ": show all queue region related configuration info",
9673         .tokens = {
9674                 (void *)&cmd_show_queue_region_info_get,
9675                 (void *)&cmd_show_queue_region_info_port,
9676                 (void *)&cmd_show_queue_region_info_port_index,
9677                 (void *)&cmd_show_queue_region_info_cmd,
9678                 NULL,
9679         },
9680 };
9681
9682 /* *** ADD/REMOVE A 2tuple FILTER *** */
9683 struct cmd_2tuple_filter_result {
9684         cmdline_fixed_string_t filter;
9685         portid_t port_id;
9686         cmdline_fixed_string_t ops;
9687         cmdline_fixed_string_t dst_port;
9688         uint16_t dst_port_value;
9689         cmdline_fixed_string_t protocol;
9690         uint8_t protocol_value;
9691         cmdline_fixed_string_t mask;
9692         uint8_t  mask_value;
9693         cmdline_fixed_string_t tcp_flags;
9694         uint8_t tcp_flags_value;
9695         cmdline_fixed_string_t priority;
9696         uint8_t  priority_value;
9697         cmdline_fixed_string_t queue;
9698         uint16_t  queue_id;
9699 };
9700
9701 static void
9702 cmd_2tuple_filter_parsed(void *parsed_result,
9703                         __attribute__((unused)) struct cmdline *cl,
9704                         __attribute__((unused)) void *data)
9705 {
9706         struct rte_eth_ntuple_filter filter;
9707         struct cmd_2tuple_filter_result *res = parsed_result;
9708         int ret = 0;
9709
9710         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9711         if (ret < 0) {
9712                 printf("ntuple filter is not supported on port %u.\n",
9713                         res->port_id);
9714                 return;
9715         }
9716
9717         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9718
9719         filter.flags = RTE_2TUPLE_FLAGS;
9720         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9721         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9722         filter.proto = res->protocol_value;
9723         filter.priority = res->priority_value;
9724         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9725                 printf("nonzero tcp_flags is only meaningful"
9726                         " when protocol is TCP.\n");
9727                 return;
9728         }
9729         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9730                 printf("invalid TCP flags.\n");
9731                 return;
9732         }
9733
9734         if (res->tcp_flags_value != 0) {
9735                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9736                 filter.tcp_flags = res->tcp_flags_value;
9737         }
9738
9739         /* need convert to big endian. */
9740         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9741         filter.queue = res->queue_id;
9742
9743         if (!strcmp(res->ops, "add"))
9744                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9745                                 RTE_ETH_FILTER_NTUPLE,
9746                                 RTE_ETH_FILTER_ADD,
9747                                 &filter);
9748         else
9749                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9750                                 RTE_ETH_FILTER_NTUPLE,
9751                                 RTE_ETH_FILTER_DELETE,
9752                                 &filter);
9753         if (ret < 0)
9754                 printf("2tuple filter programming error: (%s)\n",
9755                         strerror(-ret));
9756
9757 }
9758
9759 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9760         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9761                                  filter, "2tuple_filter");
9762 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9763         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9764                                 port_id, UINT16);
9765 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9766         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9767                                  ops, "add#del");
9768 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9769         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9770                                 dst_port, "dst_port");
9771 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9772         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9773                                 dst_port_value, UINT16);
9774 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9775         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9776                                 protocol, "protocol");
9777 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9778         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9779                                 protocol_value, UINT8);
9780 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9781         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9782                                 mask, "mask");
9783 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9784         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9785                                 mask_value, INT8);
9786 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9787         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9788                                 tcp_flags, "tcp_flags");
9789 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9790         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9791                                 tcp_flags_value, UINT8);
9792 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9793         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9794                                 priority, "priority");
9795 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9796         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9797                                 priority_value, UINT8);
9798 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9799         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9800                                 queue, "queue");
9801 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9802         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9803                                 queue_id, UINT16);
9804
9805 cmdline_parse_inst_t cmd_2tuple_filter = {
9806         .f = cmd_2tuple_filter_parsed,
9807         .data = NULL,
9808         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9809                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9810                 "<queue_id>: Add a 2tuple filter",
9811         .tokens = {
9812                 (void *)&cmd_2tuple_filter_filter,
9813                 (void *)&cmd_2tuple_filter_port_id,
9814                 (void *)&cmd_2tuple_filter_ops,
9815                 (void *)&cmd_2tuple_filter_dst_port,
9816                 (void *)&cmd_2tuple_filter_dst_port_value,
9817                 (void *)&cmd_2tuple_filter_protocol,
9818                 (void *)&cmd_2tuple_filter_protocol_value,
9819                 (void *)&cmd_2tuple_filter_mask,
9820                 (void *)&cmd_2tuple_filter_mask_value,
9821                 (void *)&cmd_2tuple_filter_tcp_flags,
9822                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9823                 (void *)&cmd_2tuple_filter_priority,
9824                 (void *)&cmd_2tuple_filter_priority_value,
9825                 (void *)&cmd_2tuple_filter_queue,
9826                 (void *)&cmd_2tuple_filter_queue_id,
9827                 NULL,
9828         },
9829 };
9830
9831 /* *** ADD/REMOVE A 5tuple FILTER *** */
9832 struct cmd_5tuple_filter_result {
9833         cmdline_fixed_string_t filter;
9834         portid_t port_id;
9835         cmdline_fixed_string_t ops;
9836         cmdline_fixed_string_t dst_ip;
9837         cmdline_ipaddr_t dst_ip_value;
9838         cmdline_fixed_string_t src_ip;
9839         cmdline_ipaddr_t src_ip_value;
9840         cmdline_fixed_string_t dst_port;
9841         uint16_t dst_port_value;
9842         cmdline_fixed_string_t src_port;
9843         uint16_t src_port_value;
9844         cmdline_fixed_string_t protocol;
9845         uint8_t protocol_value;
9846         cmdline_fixed_string_t mask;
9847         uint8_t  mask_value;
9848         cmdline_fixed_string_t tcp_flags;
9849         uint8_t tcp_flags_value;
9850         cmdline_fixed_string_t priority;
9851         uint8_t  priority_value;
9852         cmdline_fixed_string_t queue;
9853         uint16_t  queue_id;
9854 };
9855
9856 static void
9857 cmd_5tuple_filter_parsed(void *parsed_result,
9858                         __attribute__((unused)) struct cmdline *cl,
9859                         __attribute__((unused)) void *data)
9860 {
9861         struct rte_eth_ntuple_filter filter;
9862         struct cmd_5tuple_filter_result *res = parsed_result;
9863         int ret = 0;
9864
9865         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9866         if (ret < 0) {
9867                 printf("ntuple filter is not supported on port %u.\n",
9868                         res->port_id);
9869                 return;
9870         }
9871
9872         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9873
9874         filter.flags = RTE_5TUPLE_FLAGS;
9875         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9876         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9877         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9878         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9879         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9880         filter.proto = res->protocol_value;
9881         filter.priority = res->priority_value;
9882         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9883                 printf("nonzero tcp_flags is only meaningful"
9884                         " when protocol is TCP.\n");
9885                 return;
9886         }
9887         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9888                 printf("invalid TCP flags.\n");
9889                 return;
9890         }
9891
9892         if (res->tcp_flags_value != 0) {
9893                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9894                 filter.tcp_flags = res->tcp_flags_value;
9895         }
9896
9897         if (res->dst_ip_value.family == AF_INET)
9898                 /* no need to convert, already big endian. */
9899                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9900         else {
9901                 if (filter.dst_ip_mask == 0) {
9902                         printf("can not support ipv6 involved compare.\n");
9903                         return;
9904                 }
9905                 filter.dst_ip = 0;
9906         }
9907
9908         if (res->src_ip_value.family == AF_INET)
9909                 /* no need to convert, already big endian. */
9910                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9911         else {
9912                 if (filter.src_ip_mask == 0) {
9913                         printf("can not support ipv6 involved compare.\n");
9914                         return;
9915                 }
9916                 filter.src_ip = 0;
9917         }
9918         /* need convert to big endian. */
9919         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9920         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9921         filter.queue = res->queue_id;
9922
9923         if (!strcmp(res->ops, "add"))
9924                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9925                                 RTE_ETH_FILTER_NTUPLE,
9926                                 RTE_ETH_FILTER_ADD,
9927                                 &filter);
9928         else
9929                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9930                                 RTE_ETH_FILTER_NTUPLE,
9931                                 RTE_ETH_FILTER_DELETE,
9932                                 &filter);
9933         if (ret < 0)
9934                 printf("5tuple filter programming error: (%s)\n",
9935                         strerror(-ret));
9936 }
9937
9938 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9939         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9940                                  filter, "5tuple_filter");
9941 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9942         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9943                                 port_id, UINT16);
9944 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9945         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9946                                  ops, "add#del");
9947 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9948         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9949                                 dst_ip, "dst_ip");
9950 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9951         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9952                                 dst_ip_value);
9953 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9954         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9955                                 src_ip, "src_ip");
9956 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9957         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9958                                 src_ip_value);
9959 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9960         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9961                                 dst_port, "dst_port");
9962 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9963         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9964                                 dst_port_value, UINT16);
9965 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9966         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9967                                 src_port, "src_port");
9968 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9969         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9970                                 src_port_value, UINT16);
9971 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9972         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9973                                 protocol, "protocol");
9974 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9975         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9976                                 protocol_value, UINT8);
9977 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9978         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9979                                 mask, "mask");
9980 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9981         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9982                                 mask_value, INT8);
9983 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9984         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9985                                 tcp_flags, "tcp_flags");
9986 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9987         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9988                                 tcp_flags_value, UINT8);
9989 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9990         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9991                                 priority, "priority");
9992 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9993         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9994                                 priority_value, UINT8);
9995 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9996         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9997                                 queue, "queue");
9998 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9999         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10000                                 queue_id, UINT16);
10001
10002 cmdline_parse_inst_t cmd_5tuple_filter = {
10003         .f = cmd_5tuple_filter_parsed,
10004         .data = NULL,
10005         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10006                 "src_ip <value> dst_port <value> src_port <value> "
10007                 "protocol <value>  mask <value> tcp_flags <value> "
10008                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10009         .tokens = {
10010                 (void *)&cmd_5tuple_filter_filter,
10011                 (void *)&cmd_5tuple_filter_port_id,
10012                 (void *)&cmd_5tuple_filter_ops,
10013                 (void *)&cmd_5tuple_filter_dst_ip,
10014                 (void *)&cmd_5tuple_filter_dst_ip_value,
10015                 (void *)&cmd_5tuple_filter_src_ip,
10016                 (void *)&cmd_5tuple_filter_src_ip_value,
10017                 (void *)&cmd_5tuple_filter_dst_port,
10018                 (void *)&cmd_5tuple_filter_dst_port_value,
10019                 (void *)&cmd_5tuple_filter_src_port,
10020                 (void *)&cmd_5tuple_filter_src_port_value,
10021                 (void *)&cmd_5tuple_filter_protocol,
10022                 (void *)&cmd_5tuple_filter_protocol_value,
10023                 (void *)&cmd_5tuple_filter_mask,
10024                 (void *)&cmd_5tuple_filter_mask_value,
10025                 (void *)&cmd_5tuple_filter_tcp_flags,
10026                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10027                 (void *)&cmd_5tuple_filter_priority,
10028                 (void *)&cmd_5tuple_filter_priority_value,
10029                 (void *)&cmd_5tuple_filter_queue,
10030                 (void *)&cmd_5tuple_filter_queue_id,
10031                 NULL,
10032         },
10033 };
10034
10035 /* *** ADD/REMOVE A flex FILTER *** */
10036 struct cmd_flex_filter_result {
10037         cmdline_fixed_string_t filter;
10038         cmdline_fixed_string_t ops;
10039         portid_t port_id;
10040         cmdline_fixed_string_t len;
10041         uint8_t len_value;
10042         cmdline_fixed_string_t bytes;
10043         cmdline_fixed_string_t bytes_value;
10044         cmdline_fixed_string_t mask;
10045         cmdline_fixed_string_t mask_value;
10046         cmdline_fixed_string_t priority;
10047         uint8_t priority_value;
10048         cmdline_fixed_string_t queue;
10049         uint16_t queue_id;
10050 };
10051
10052 static int xdigit2val(unsigned char c)
10053 {
10054         int val;
10055         if (isdigit(c))
10056                 val = c - '0';
10057         else if (isupper(c))
10058                 val = c - 'A' + 10;
10059         else
10060                 val = c - 'a' + 10;
10061         return val;
10062 }
10063
10064 static void
10065 cmd_flex_filter_parsed(void *parsed_result,
10066                           __attribute__((unused)) struct cmdline *cl,
10067                           __attribute__((unused)) void *data)
10068 {
10069         int ret = 0;
10070         struct rte_eth_flex_filter filter;
10071         struct cmd_flex_filter_result *res = parsed_result;
10072         char *bytes_ptr, *mask_ptr;
10073         uint16_t len, i, j = 0;
10074         char c;
10075         int val;
10076         uint8_t byte = 0;
10077
10078         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10079                 printf("the len exceed the max length 128\n");
10080                 return;
10081         }
10082         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10083         filter.len = res->len_value;
10084         filter.priority = res->priority_value;
10085         filter.queue = res->queue_id;
10086         bytes_ptr = res->bytes_value;
10087         mask_ptr = res->mask_value;
10088
10089          /* translate bytes string to array. */
10090         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10091                 (bytes_ptr[1] == 'X')))
10092                 bytes_ptr += 2;
10093         len = strnlen(bytes_ptr, res->len_value * 2);
10094         if (len == 0 || (len % 8 != 0)) {
10095                 printf("please check len and bytes input\n");
10096                 return;
10097         }
10098         for (i = 0; i < len; i++) {
10099                 c = bytes_ptr[i];
10100                 if (isxdigit(c) == 0) {
10101                         /* invalid characters. */
10102                         printf("invalid input\n");
10103                         return;
10104                 }
10105                 val = xdigit2val(c);
10106                 if (i % 2) {
10107                         byte |= val;
10108                         filter.bytes[j] = byte;
10109                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10110                         j++;
10111                         byte = 0;
10112                 } else
10113                         byte |= val << 4;
10114         }
10115         printf("\n");
10116          /* translate mask string to uint8_t array. */
10117         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10118                 (mask_ptr[1] == 'X')))
10119                 mask_ptr += 2;
10120         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10121         if (len == 0) {
10122                 printf("invalid input\n");
10123                 return;
10124         }
10125         j = 0;
10126         byte = 0;
10127         for (i = 0; i < len; i++) {
10128                 c = mask_ptr[i];
10129                 if (isxdigit(c) == 0) {
10130                         /* invalid characters. */
10131                         printf("invalid input\n");
10132                         return;
10133                 }
10134                 val = xdigit2val(c);
10135                 if (i % 2) {
10136                         byte |= val;
10137                         filter.mask[j] = byte;
10138                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10139                         j++;
10140                         byte = 0;
10141                 } else
10142                         byte |= val << 4;
10143         }
10144         printf("\n");
10145
10146         if (!strcmp(res->ops, "add"))
10147                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10148                                 RTE_ETH_FILTER_FLEXIBLE,
10149                                 RTE_ETH_FILTER_ADD,
10150                                 &filter);
10151         else
10152                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10153                                 RTE_ETH_FILTER_FLEXIBLE,
10154                                 RTE_ETH_FILTER_DELETE,
10155                                 &filter);
10156
10157         if (ret < 0)
10158                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10159 }
10160
10161 cmdline_parse_token_string_t cmd_flex_filter_filter =
10162         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10163                                 filter, "flex_filter");
10164 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10165         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10166                                 port_id, UINT16);
10167 cmdline_parse_token_string_t cmd_flex_filter_ops =
10168         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10169                                 ops, "add#del");
10170 cmdline_parse_token_string_t cmd_flex_filter_len =
10171         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10172                                 len, "len");
10173 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10174         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10175                                 len_value, UINT8);
10176 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10177         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10178                                 bytes, "bytes");
10179 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10180         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10181                                 bytes_value, NULL);
10182 cmdline_parse_token_string_t cmd_flex_filter_mask =
10183         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10184                                 mask, "mask");
10185 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10186         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10187                                 mask_value, NULL);
10188 cmdline_parse_token_string_t cmd_flex_filter_priority =
10189         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10190                                 priority, "priority");
10191 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10192         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10193                                 priority_value, UINT8);
10194 cmdline_parse_token_string_t cmd_flex_filter_queue =
10195         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10196                                 queue, "queue");
10197 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10198         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10199                                 queue_id, UINT16);
10200 cmdline_parse_inst_t cmd_flex_filter = {
10201         .f = cmd_flex_filter_parsed,
10202         .data = NULL,
10203         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10204                 "<value> mask <value> priority <value> queue <queue_id>: "
10205                 "Add/Del a flex filter",
10206         .tokens = {
10207                 (void *)&cmd_flex_filter_filter,
10208                 (void *)&cmd_flex_filter_port_id,
10209                 (void *)&cmd_flex_filter_ops,
10210                 (void *)&cmd_flex_filter_len,
10211                 (void *)&cmd_flex_filter_len_value,
10212                 (void *)&cmd_flex_filter_bytes,
10213                 (void *)&cmd_flex_filter_bytes_value,
10214                 (void *)&cmd_flex_filter_mask,
10215                 (void *)&cmd_flex_filter_mask_value,
10216                 (void *)&cmd_flex_filter_priority,
10217                 (void *)&cmd_flex_filter_priority_value,
10218                 (void *)&cmd_flex_filter_queue,
10219                 (void *)&cmd_flex_filter_queue_id,
10220                 NULL,
10221         },
10222 };
10223
10224 /* *** Filters Control *** */
10225
10226 /* *** deal with ethertype filter *** */
10227 struct cmd_ethertype_filter_result {
10228         cmdline_fixed_string_t filter;
10229         portid_t port_id;
10230         cmdline_fixed_string_t ops;
10231         cmdline_fixed_string_t mac;
10232         struct ether_addr mac_addr;
10233         cmdline_fixed_string_t ethertype;
10234         uint16_t ethertype_value;
10235         cmdline_fixed_string_t drop;
10236         cmdline_fixed_string_t queue;
10237         uint16_t  queue_id;
10238 };
10239
10240 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10241         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10242                                  filter, "ethertype_filter");
10243 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10244         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10245                               port_id, UINT16);
10246 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10247         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10248                                  ops, "add#del");
10249 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10250         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10251                                  mac, "mac_addr#mac_ignr");
10252 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10253         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10254                                      mac_addr);
10255 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10256         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10257                                  ethertype, "ethertype");
10258 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10259         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10260                               ethertype_value, UINT16);
10261 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10262         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10263                                  drop, "drop#fwd");
10264 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10265         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10266                                  queue, "queue");
10267 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10268         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10269                               queue_id, UINT16);
10270
10271 static void
10272 cmd_ethertype_filter_parsed(void *parsed_result,
10273                           __attribute__((unused)) struct cmdline *cl,
10274                           __attribute__((unused)) void *data)
10275 {
10276         struct cmd_ethertype_filter_result *res = parsed_result;
10277         struct rte_eth_ethertype_filter filter;
10278         int ret = 0;
10279
10280         ret = rte_eth_dev_filter_supported(res->port_id,
10281                         RTE_ETH_FILTER_ETHERTYPE);
10282         if (ret < 0) {
10283                 printf("ethertype filter is not supported on port %u.\n",
10284                         res->port_id);
10285                 return;
10286         }
10287
10288         memset(&filter, 0, sizeof(filter));
10289         if (!strcmp(res->mac, "mac_addr")) {
10290                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10291                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10292                         sizeof(struct ether_addr));
10293         }
10294         if (!strcmp(res->drop, "drop"))
10295                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10296         filter.ether_type = res->ethertype_value;
10297         filter.queue = res->queue_id;
10298
10299         if (!strcmp(res->ops, "add"))
10300                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10301                                 RTE_ETH_FILTER_ETHERTYPE,
10302                                 RTE_ETH_FILTER_ADD,
10303                                 &filter);
10304         else
10305                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10306                                 RTE_ETH_FILTER_ETHERTYPE,
10307                                 RTE_ETH_FILTER_DELETE,
10308                                 &filter);
10309         if (ret < 0)
10310                 printf("ethertype filter programming error: (%s)\n",
10311                         strerror(-ret));
10312 }
10313
10314 cmdline_parse_inst_t cmd_ethertype_filter = {
10315         .f = cmd_ethertype_filter_parsed,
10316         .data = NULL,
10317         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10318                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10319                 "Add or delete an ethertype filter entry",
10320         .tokens = {
10321                 (void *)&cmd_ethertype_filter_filter,
10322                 (void *)&cmd_ethertype_filter_port_id,
10323                 (void *)&cmd_ethertype_filter_ops,
10324                 (void *)&cmd_ethertype_filter_mac,
10325                 (void *)&cmd_ethertype_filter_mac_addr,
10326                 (void *)&cmd_ethertype_filter_ethertype,
10327                 (void *)&cmd_ethertype_filter_ethertype_value,
10328                 (void *)&cmd_ethertype_filter_drop,
10329                 (void *)&cmd_ethertype_filter_queue,
10330                 (void *)&cmd_ethertype_filter_queue_id,
10331                 NULL,
10332         },
10333 };
10334
10335 /* *** deal with flow director filter *** */
10336 struct cmd_flow_director_result {
10337         cmdline_fixed_string_t flow_director_filter;
10338         portid_t port_id;
10339         cmdline_fixed_string_t mode;
10340         cmdline_fixed_string_t mode_value;
10341         cmdline_fixed_string_t ops;
10342         cmdline_fixed_string_t flow;
10343         cmdline_fixed_string_t flow_type;
10344         cmdline_fixed_string_t ether;
10345         uint16_t ether_type;
10346         cmdline_fixed_string_t src;
10347         cmdline_ipaddr_t ip_src;
10348         uint16_t port_src;
10349         cmdline_fixed_string_t dst;
10350         cmdline_ipaddr_t ip_dst;
10351         uint16_t port_dst;
10352         cmdline_fixed_string_t verify_tag;
10353         uint32_t verify_tag_value;
10354         cmdline_fixed_string_t tos;
10355         uint8_t tos_value;
10356         cmdline_fixed_string_t proto;
10357         uint8_t proto_value;
10358         cmdline_fixed_string_t ttl;
10359         uint8_t ttl_value;
10360         cmdline_fixed_string_t vlan;
10361         uint16_t vlan_value;
10362         cmdline_fixed_string_t flexbytes;
10363         cmdline_fixed_string_t flexbytes_value;
10364         cmdline_fixed_string_t pf_vf;
10365         cmdline_fixed_string_t drop;
10366         cmdline_fixed_string_t queue;
10367         uint16_t  queue_id;
10368         cmdline_fixed_string_t fd_id;
10369         uint32_t  fd_id_value;
10370         cmdline_fixed_string_t mac;
10371         struct ether_addr mac_addr;
10372         cmdline_fixed_string_t tunnel;
10373         cmdline_fixed_string_t tunnel_type;
10374         cmdline_fixed_string_t tunnel_id;
10375         uint32_t tunnel_id_value;
10376         cmdline_fixed_string_t packet;
10377         char filepath[];
10378 };
10379
10380 static inline int
10381 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10382 {
10383         char s[256];
10384         const char *p, *p0 = q_arg;
10385         char *end;
10386         unsigned long int_fld;
10387         char *str_fld[max_num];
10388         int i;
10389         unsigned size;
10390         int ret = -1;
10391
10392         p = strchr(p0, '(');
10393         if (p == NULL)
10394                 return -1;
10395         ++p;
10396         p0 = strchr(p, ')');
10397         if (p0 == NULL)
10398                 return -1;
10399
10400         size = p0 - p;
10401         if (size >= sizeof(s))
10402                 return -1;
10403
10404         snprintf(s, sizeof(s), "%.*s", size, p);
10405         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10406         if (ret < 0 || ret > max_num)
10407                 return -1;
10408         for (i = 0; i < ret; i++) {
10409                 errno = 0;
10410                 int_fld = strtoul(str_fld[i], &end, 0);
10411                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10412                         return -1;
10413                 flexbytes[i] = (uint8_t)int_fld;
10414         }
10415         return ret;
10416 }
10417
10418 static uint16_t
10419 str2flowtype(char *string)
10420 {
10421         uint8_t i = 0;
10422         static const struct {
10423                 char str[32];
10424                 uint16_t type;
10425         } flowtype_str[] = {
10426                 {"raw", RTE_ETH_FLOW_RAW},
10427                 {"ipv4", RTE_ETH_FLOW_IPV4},
10428                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10429                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10430                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10431                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10432                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10433                 {"ipv6", RTE_ETH_FLOW_IPV6},
10434                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10435                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10436                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10437                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10438                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10439                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10440         };
10441
10442         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10443                 if (!strcmp(flowtype_str[i].str, string))
10444                         return flowtype_str[i].type;
10445         }
10446
10447         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10448                 return (uint16_t)atoi(string);
10449
10450         return RTE_ETH_FLOW_UNKNOWN;
10451 }
10452
10453 static enum rte_eth_fdir_tunnel_type
10454 str2fdir_tunneltype(char *string)
10455 {
10456         uint8_t i = 0;
10457
10458         static const struct {
10459                 char str[32];
10460                 enum rte_eth_fdir_tunnel_type type;
10461         } tunneltype_str[] = {
10462                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10463                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10464         };
10465
10466         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10467                 if (!strcmp(tunneltype_str[i].str, string))
10468                         return tunneltype_str[i].type;
10469         }
10470         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10471 }
10472
10473 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10474 do { \
10475         if ((ip_addr).family == AF_INET) \
10476                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10477         else { \
10478                 printf("invalid parameter.\n"); \
10479                 return; \
10480         } \
10481 } while (0)
10482
10483 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10484 do { \
10485         if ((ip_addr).family == AF_INET6) \
10486                 rte_memcpy(&(ip), \
10487                                  &((ip_addr).addr.ipv6), \
10488                                  sizeof(struct in6_addr)); \
10489         else { \
10490                 printf("invalid parameter.\n"); \
10491                 return; \
10492         } \
10493 } while (0)
10494
10495 static void
10496 cmd_flow_director_filter_parsed(void *parsed_result,
10497                           __attribute__((unused)) struct cmdline *cl,
10498                           __attribute__((unused)) void *data)
10499 {
10500         struct cmd_flow_director_result *res = parsed_result;
10501         struct rte_eth_fdir_filter entry;
10502         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10503         char *end;
10504         unsigned long vf_id;
10505         int ret = 0;
10506
10507         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10508         if (ret < 0) {
10509                 printf("flow director is not supported on port %u.\n",
10510                         res->port_id);
10511                 return;
10512         }
10513         memset(flexbytes, 0, sizeof(flexbytes));
10514         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10515
10516         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10517                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10518                         printf("Please set mode to MAC-VLAN.\n");
10519                         return;
10520                 }
10521         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10522                 if (strcmp(res->mode_value, "Tunnel")) {
10523                         printf("Please set mode to Tunnel.\n");
10524                         return;
10525                 }
10526         } else {
10527                 if (!strcmp(res->mode_value, "raw")) {
10528 #ifdef RTE_LIBRTE_I40E_PMD
10529                         struct rte_pmd_i40e_flow_type_mapping
10530                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10531                         struct rte_pmd_i40e_pkt_template_conf conf;
10532                         uint16_t flow_type = str2flowtype(res->flow_type);
10533                         uint16_t i, port = res->port_id;
10534                         uint8_t add;
10535
10536                         memset(&conf, 0, sizeof(conf));
10537
10538                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10539                                 printf("Invalid flow type specified.\n");
10540                                 return;
10541                         }
10542                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10543                                                                  mapping);
10544                         if (ret)
10545                                 return;
10546                         if (mapping[flow_type].pctype == 0ULL) {
10547                                 printf("Invalid flow type specified.\n");
10548                                 return;
10549                         }
10550                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10551                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10552                                         conf.input.pctype = i;
10553                                         break;
10554                                 }
10555                         }
10556
10557                         conf.input.packet = open_file(res->filepath,
10558                                                 &conf.input.length);
10559                         if (!conf.input.packet)
10560                                 return;
10561                         if (!strcmp(res->drop, "drop"))
10562                                 conf.action.behavior =
10563                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10564                         else
10565                                 conf.action.behavior =
10566                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10567                         conf.action.report_status =
10568                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10569                         conf.action.rx_queue = res->queue_id;
10570                         conf.soft_id = res->fd_id_value;
10571                         add  = strcmp(res->ops, "del") ? 1 : 0;
10572                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10573                                                                         &conf,
10574                                                                         add);
10575                         if (ret < 0)
10576                                 printf("flow director config error: (%s)\n",
10577                                        strerror(-ret));
10578                         close_file(conf.input.packet);
10579 #endif
10580                         return;
10581                 } else if (strcmp(res->mode_value, "IP")) {
10582                         printf("Please set mode to IP or raw.\n");
10583                         return;
10584                 }
10585                 entry.input.flow_type = str2flowtype(res->flow_type);
10586         }
10587
10588         ret = parse_flexbytes(res->flexbytes_value,
10589                                         flexbytes,
10590                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10591         if (ret < 0) {
10592                 printf("error: Cannot parse flexbytes input.\n");
10593                 return;
10594         }
10595
10596         switch (entry.input.flow_type) {
10597         case RTE_ETH_FLOW_FRAG_IPV4:
10598         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10599                 entry.input.flow.ip4_flow.proto = res->proto_value;
10600                 /* fall-through */
10601         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10602         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10603                 IPV4_ADDR_TO_UINT(res->ip_dst,
10604                         entry.input.flow.ip4_flow.dst_ip);
10605                 IPV4_ADDR_TO_UINT(res->ip_src,
10606                         entry.input.flow.ip4_flow.src_ip);
10607                 entry.input.flow.ip4_flow.tos = res->tos_value;
10608                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10609                 /* need convert to big endian. */
10610                 entry.input.flow.udp4_flow.dst_port =
10611                                 rte_cpu_to_be_16(res->port_dst);
10612                 entry.input.flow.udp4_flow.src_port =
10613                                 rte_cpu_to_be_16(res->port_src);
10614                 break;
10615         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10616                 IPV4_ADDR_TO_UINT(res->ip_dst,
10617                         entry.input.flow.sctp4_flow.ip.dst_ip);
10618                 IPV4_ADDR_TO_UINT(res->ip_src,
10619                         entry.input.flow.sctp4_flow.ip.src_ip);
10620                 entry.input.flow.ip4_flow.tos = res->tos_value;
10621                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10622                 /* need convert to big endian. */
10623                 entry.input.flow.sctp4_flow.dst_port =
10624                                 rte_cpu_to_be_16(res->port_dst);
10625                 entry.input.flow.sctp4_flow.src_port =
10626                                 rte_cpu_to_be_16(res->port_src);
10627                 entry.input.flow.sctp4_flow.verify_tag =
10628                                 rte_cpu_to_be_32(res->verify_tag_value);
10629                 break;
10630         case RTE_ETH_FLOW_FRAG_IPV6:
10631         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10632                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10633                 /* fall-through */
10634         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10635         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10636                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10637                         entry.input.flow.ipv6_flow.dst_ip);
10638                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10639                         entry.input.flow.ipv6_flow.src_ip);
10640                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10641                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10642                 /* need convert to big endian. */
10643                 entry.input.flow.udp6_flow.dst_port =
10644                                 rte_cpu_to_be_16(res->port_dst);
10645                 entry.input.flow.udp6_flow.src_port =
10646                                 rte_cpu_to_be_16(res->port_src);
10647                 break;
10648         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10649                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10650                         entry.input.flow.sctp6_flow.ip.dst_ip);
10651                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10652                         entry.input.flow.sctp6_flow.ip.src_ip);
10653                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10654                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10655                 /* need convert to big endian. */
10656                 entry.input.flow.sctp6_flow.dst_port =
10657                                 rte_cpu_to_be_16(res->port_dst);
10658                 entry.input.flow.sctp6_flow.src_port =
10659                                 rte_cpu_to_be_16(res->port_src);
10660                 entry.input.flow.sctp6_flow.verify_tag =
10661                                 rte_cpu_to_be_32(res->verify_tag_value);
10662                 break;
10663         case RTE_ETH_FLOW_L2_PAYLOAD:
10664                 entry.input.flow.l2_flow.ether_type =
10665                         rte_cpu_to_be_16(res->ether_type);
10666                 break;
10667         default:
10668                 break;
10669         }
10670
10671         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10672                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10673                                  &res->mac_addr,
10674                                  sizeof(struct ether_addr));
10675
10676         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10677                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10678                                  &res->mac_addr,
10679                                  sizeof(struct ether_addr));
10680                 entry.input.flow.tunnel_flow.tunnel_type =
10681                         str2fdir_tunneltype(res->tunnel_type);
10682                 entry.input.flow.tunnel_flow.tunnel_id =
10683                         rte_cpu_to_be_32(res->tunnel_id_value);
10684         }
10685
10686         rte_memcpy(entry.input.flow_ext.flexbytes,
10687                    flexbytes,
10688                    RTE_ETH_FDIR_MAX_FLEXLEN);
10689
10690         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10691
10692         entry.action.flex_off = 0;  /*use 0 by default */
10693         if (!strcmp(res->drop, "drop"))
10694                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10695         else
10696                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10697
10698         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10699             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10700                 if (!strcmp(res->pf_vf, "pf"))
10701                         entry.input.flow_ext.is_vf = 0;
10702                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10703                         struct rte_eth_dev_info dev_info;
10704
10705                         memset(&dev_info, 0, sizeof(dev_info));
10706                         rte_eth_dev_info_get(res->port_id, &dev_info);
10707                         errno = 0;
10708                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10709                         if (errno != 0 || *end != '\0' ||
10710                             vf_id >= dev_info.max_vfs) {
10711                                 printf("invalid parameter %s.\n", res->pf_vf);
10712                                 return;
10713                         }
10714                         entry.input.flow_ext.is_vf = 1;
10715                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10716                 } else {
10717                         printf("invalid parameter %s.\n", res->pf_vf);
10718                         return;
10719                 }
10720         }
10721
10722         /* set to report FD ID by default */
10723         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10724         entry.action.rx_queue = res->queue_id;
10725         entry.soft_id = res->fd_id_value;
10726         if (!strcmp(res->ops, "add"))
10727                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10728                                              RTE_ETH_FILTER_ADD, &entry);
10729         else if (!strcmp(res->ops, "del"))
10730                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10731                                              RTE_ETH_FILTER_DELETE, &entry);
10732         else
10733                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10734                                              RTE_ETH_FILTER_UPDATE, &entry);
10735         if (ret < 0)
10736                 printf("flow director programming error: (%s)\n",
10737                         strerror(-ret));
10738 }
10739
10740 cmdline_parse_token_string_t cmd_flow_director_filter =
10741         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10742                                  flow_director_filter, "flow_director_filter");
10743 cmdline_parse_token_num_t cmd_flow_director_port_id =
10744         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10745                               port_id, UINT16);
10746 cmdline_parse_token_string_t cmd_flow_director_ops =
10747         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10748                                  ops, "add#del#update");
10749 cmdline_parse_token_string_t cmd_flow_director_flow =
10750         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10751                                  flow, "flow");
10752 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10753         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10754                 flow_type, NULL);
10755 cmdline_parse_token_string_t cmd_flow_director_ether =
10756         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10757                                  ether, "ether");
10758 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10759         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10760                               ether_type, UINT16);
10761 cmdline_parse_token_string_t cmd_flow_director_src =
10762         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10763                                  src, "src");
10764 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10765         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10766                                  ip_src);
10767 cmdline_parse_token_num_t cmd_flow_director_port_src =
10768         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10769                               port_src, UINT16);
10770 cmdline_parse_token_string_t cmd_flow_director_dst =
10771         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10772                                  dst, "dst");
10773 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10774         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10775                                  ip_dst);
10776 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10777         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10778                               port_dst, UINT16);
10779 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10780         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10781                                   verify_tag, "verify_tag");
10782 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10783         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10784                               verify_tag_value, UINT32);
10785 cmdline_parse_token_string_t cmd_flow_director_tos =
10786         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10787                                  tos, "tos");
10788 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10789         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10790                               tos_value, UINT8);
10791 cmdline_parse_token_string_t cmd_flow_director_proto =
10792         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10793                                  proto, "proto");
10794 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10795         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10796                               proto_value, UINT8);
10797 cmdline_parse_token_string_t cmd_flow_director_ttl =
10798         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10799                                  ttl, "ttl");
10800 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10801         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10802                               ttl_value, UINT8);
10803 cmdline_parse_token_string_t cmd_flow_director_vlan =
10804         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10805                                  vlan, "vlan");
10806 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10807         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10808                               vlan_value, UINT16);
10809 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10810         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10811                                  flexbytes, "flexbytes");
10812 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10813         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10814                               flexbytes_value, NULL);
10815 cmdline_parse_token_string_t cmd_flow_director_drop =
10816         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10817                                  drop, "drop#fwd");
10818 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10819         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10820                               pf_vf, NULL);
10821 cmdline_parse_token_string_t cmd_flow_director_queue =
10822         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10823                                  queue, "queue");
10824 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10825         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10826                               queue_id, UINT16);
10827 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10828         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10829                                  fd_id, "fd_id");
10830 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10831         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10832                               fd_id_value, UINT32);
10833
10834 cmdline_parse_token_string_t cmd_flow_director_mode =
10835         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10836                                  mode, "mode");
10837 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10838         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10839                                  mode_value, "IP");
10840 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10841         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10842                                  mode_value, "MAC-VLAN");
10843 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10844         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10845                                  mode_value, "Tunnel");
10846 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10847         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10848                                  mode_value, "raw");
10849 cmdline_parse_token_string_t cmd_flow_director_mac =
10850         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10851                                  mac, "mac");
10852 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10853         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10854                                     mac_addr);
10855 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10856         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10857                                  tunnel, "tunnel");
10858 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10859         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10860                                  tunnel_type, "NVGRE#VxLAN");
10861 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10862         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10863                                  tunnel_id, "tunnel-id");
10864 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10865         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10866                               tunnel_id_value, UINT32);
10867 cmdline_parse_token_string_t cmd_flow_director_packet =
10868         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10869                                  packet, "packet");
10870 cmdline_parse_token_string_t cmd_flow_director_filepath =
10871         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10872                                  filepath, NULL);
10873
10874 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10875         .f = cmd_flow_director_filter_parsed,
10876         .data = NULL,
10877         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10878                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10879                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10880                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10881                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10882                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10883                 "fd_id <fd_id_value>: "
10884                 "Add or delete an ip flow director entry on NIC",
10885         .tokens = {
10886                 (void *)&cmd_flow_director_filter,
10887                 (void *)&cmd_flow_director_port_id,
10888                 (void *)&cmd_flow_director_mode,
10889                 (void *)&cmd_flow_director_mode_ip,
10890                 (void *)&cmd_flow_director_ops,
10891                 (void *)&cmd_flow_director_flow,
10892                 (void *)&cmd_flow_director_flow_type,
10893                 (void *)&cmd_flow_director_src,
10894                 (void *)&cmd_flow_director_ip_src,
10895                 (void *)&cmd_flow_director_dst,
10896                 (void *)&cmd_flow_director_ip_dst,
10897                 (void *)&cmd_flow_director_tos,
10898                 (void *)&cmd_flow_director_tos_value,
10899                 (void *)&cmd_flow_director_proto,
10900                 (void *)&cmd_flow_director_proto_value,
10901                 (void *)&cmd_flow_director_ttl,
10902                 (void *)&cmd_flow_director_ttl_value,
10903                 (void *)&cmd_flow_director_vlan,
10904                 (void *)&cmd_flow_director_vlan_value,
10905                 (void *)&cmd_flow_director_flexbytes,
10906                 (void *)&cmd_flow_director_flexbytes_value,
10907                 (void *)&cmd_flow_director_drop,
10908                 (void *)&cmd_flow_director_pf_vf,
10909                 (void *)&cmd_flow_director_queue,
10910                 (void *)&cmd_flow_director_queue_id,
10911                 (void *)&cmd_flow_director_fd_id,
10912                 (void *)&cmd_flow_director_fd_id_value,
10913                 NULL,
10914         },
10915 };
10916
10917 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10918         .f = cmd_flow_director_filter_parsed,
10919         .data = NULL,
10920         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10921                 "director entry on NIC",
10922         .tokens = {
10923                 (void *)&cmd_flow_director_filter,
10924                 (void *)&cmd_flow_director_port_id,
10925                 (void *)&cmd_flow_director_mode,
10926                 (void *)&cmd_flow_director_mode_ip,
10927                 (void *)&cmd_flow_director_ops,
10928                 (void *)&cmd_flow_director_flow,
10929                 (void *)&cmd_flow_director_flow_type,
10930                 (void *)&cmd_flow_director_src,
10931                 (void *)&cmd_flow_director_ip_src,
10932                 (void *)&cmd_flow_director_port_src,
10933                 (void *)&cmd_flow_director_dst,
10934                 (void *)&cmd_flow_director_ip_dst,
10935                 (void *)&cmd_flow_director_port_dst,
10936                 (void *)&cmd_flow_director_tos,
10937                 (void *)&cmd_flow_director_tos_value,
10938                 (void *)&cmd_flow_director_ttl,
10939                 (void *)&cmd_flow_director_ttl_value,
10940                 (void *)&cmd_flow_director_vlan,
10941                 (void *)&cmd_flow_director_vlan_value,
10942                 (void *)&cmd_flow_director_flexbytes,
10943                 (void *)&cmd_flow_director_flexbytes_value,
10944                 (void *)&cmd_flow_director_drop,
10945                 (void *)&cmd_flow_director_pf_vf,
10946                 (void *)&cmd_flow_director_queue,
10947                 (void *)&cmd_flow_director_queue_id,
10948                 (void *)&cmd_flow_director_fd_id,
10949                 (void *)&cmd_flow_director_fd_id_value,
10950                 NULL,
10951         },
10952 };
10953
10954 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10955         .f = cmd_flow_director_filter_parsed,
10956         .data = NULL,
10957         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10958                 "director entry on NIC",
10959         .tokens = {
10960                 (void *)&cmd_flow_director_filter,
10961                 (void *)&cmd_flow_director_port_id,
10962                 (void *)&cmd_flow_director_mode,
10963                 (void *)&cmd_flow_director_mode_ip,
10964                 (void *)&cmd_flow_director_ops,
10965                 (void *)&cmd_flow_director_flow,
10966                 (void *)&cmd_flow_director_flow_type,
10967                 (void *)&cmd_flow_director_src,
10968                 (void *)&cmd_flow_director_ip_src,
10969                 (void *)&cmd_flow_director_port_src,
10970                 (void *)&cmd_flow_director_dst,
10971                 (void *)&cmd_flow_director_ip_dst,
10972                 (void *)&cmd_flow_director_port_dst,
10973                 (void *)&cmd_flow_director_verify_tag,
10974                 (void *)&cmd_flow_director_verify_tag_value,
10975                 (void *)&cmd_flow_director_tos,
10976                 (void *)&cmd_flow_director_tos_value,
10977                 (void *)&cmd_flow_director_ttl,
10978                 (void *)&cmd_flow_director_ttl_value,
10979                 (void *)&cmd_flow_director_vlan,
10980                 (void *)&cmd_flow_director_vlan_value,
10981                 (void *)&cmd_flow_director_flexbytes,
10982                 (void *)&cmd_flow_director_flexbytes_value,
10983                 (void *)&cmd_flow_director_drop,
10984                 (void *)&cmd_flow_director_pf_vf,
10985                 (void *)&cmd_flow_director_queue,
10986                 (void *)&cmd_flow_director_queue_id,
10987                 (void *)&cmd_flow_director_fd_id,
10988                 (void *)&cmd_flow_director_fd_id_value,
10989                 NULL,
10990         },
10991 };
10992
10993 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10994         .f = cmd_flow_director_filter_parsed,
10995         .data = NULL,
10996         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10997                 "director entry on NIC",
10998         .tokens = {
10999                 (void *)&cmd_flow_director_filter,
11000                 (void *)&cmd_flow_director_port_id,
11001                 (void *)&cmd_flow_director_mode,
11002                 (void *)&cmd_flow_director_mode_ip,
11003                 (void *)&cmd_flow_director_ops,
11004                 (void *)&cmd_flow_director_flow,
11005                 (void *)&cmd_flow_director_flow_type,
11006                 (void *)&cmd_flow_director_ether,
11007                 (void *)&cmd_flow_director_ether_type,
11008                 (void *)&cmd_flow_director_flexbytes,
11009                 (void *)&cmd_flow_director_flexbytes_value,
11010                 (void *)&cmd_flow_director_drop,
11011                 (void *)&cmd_flow_director_pf_vf,
11012                 (void *)&cmd_flow_director_queue,
11013                 (void *)&cmd_flow_director_queue_id,
11014                 (void *)&cmd_flow_director_fd_id,
11015                 (void *)&cmd_flow_director_fd_id_value,
11016                 NULL,
11017         },
11018 };
11019
11020 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11021         .f = cmd_flow_director_filter_parsed,
11022         .data = NULL,
11023         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11024                 "director entry on NIC",
11025         .tokens = {
11026                 (void *)&cmd_flow_director_filter,
11027                 (void *)&cmd_flow_director_port_id,
11028                 (void *)&cmd_flow_director_mode,
11029                 (void *)&cmd_flow_director_mode_mac_vlan,
11030                 (void *)&cmd_flow_director_ops,
11031                 (void *)&cmd_flow_director_mac,
11032                 (void *)&cmd_flow_director_mac_addr,
11033                 (void *)&cmd_flow_director_vlan,
11034                 (void *)&cmd_flow_director_vlan_value,
11035                 (void *)&cmd_flow_director_flexbytes,
11036                 (void *)&cmd_flow_director_flexbytes_value,
11037                 (void *)&cmd_flow_director_drop,
11038                 (void *)&cmd_flow_director_queue,
11039                 (void *)&cmd_flow_director_queue_id,
11040                 (void *)&cmd_flow_director_fd_id,
11041                 (void *)&cmd_flow_director_fd_id_value,
11042                 NULL,
11043         },
11044 };
11045
11046 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11047         .f = cmd_flow_director_filter_parsed,
11048         .data = NULL,
11049         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11050                 "director entry on NIC",
11051         .tokens = {
11052                 (void *)&cmd_flow_director_filter,
11053                 (void *)&cmd_flow_director_port_id,
11054                 (void *)&cmd_flow_director_mode,
11055                 (void *)&cmd_flow_director_mode_tunnel,
11056                 (void *)&cmd_flow_director_ops,
11057                 (void *)&cmd_flow_director_mac,
11058                 (void *)&cmd_flow_director_mac_addr,
11059                 (void *)&cmd_flow_director_vlan,
11060                 (void *)&cmd_flow_director_vlan_value,
11061                 (void *)&cmd_flow_director_tunnel,
11062                 (void *)&cmd_flow_director_tunnel_type,
11063                 (void *)&cmd_flow_director_tunnel_id,
11064                 (void *)&cmd_flow_director_tunnel_id_value,
11065                 (void *)&cmd_flow_director_flexbytes,
11066                 (void *)&cmd_flow_director_flexbytes_value,
11067                 (void *)&cmd_flow_director_drop,
11068                 (void *)&cmd_flow_director_queue,
11069                 (void *)&cmd_flow_director_queue_id,
11070                 (void *)&cmd_flow_director_fd_id,
11071                 (void *)&cmd_flow_director_fd_id_value,
11072                 NULL,
11073         },
11074 };
11075
11076 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11077         .f = cmd_flow_director_filter_parsed,
11078         .data = NULL,
11079         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11080                 "director entry on NIC",
11081         .tokens = {
11082                 (void *)&cmd_flow_director_filter,
11083                 (void *)&cmd_flow_director_port_id,
11084                 (void *)&cmd_flow_director_mode,
11085                 (void *)&cmd_flow_director_mode_raw,
11086                 (void *)&cmd_flow_director_ops,
11087                 (void *)&cmd_flow_director_flow,
11088                 (void *)&cmd_flow_director_flow_type,
11089                 (void *)&cmd_flow_director_drop,
11090                 (void *)&cmd_flow_director_queue,
11091                 (void *)&cmd_flow_director_queue_id,
11092                 (void *)&cmd_flow_director_fd_id,
11093                 (void *)&cmd_flow_director_fd_id_value,
11094                 (void *)&cmd_flow_director_packet,
11095                 (void *)&cmd_flow_director_filepath,
11096                 NULL,
11097         },
11098 };
11099
11100 struct cmd_flush_flow_director_result {
11101         cmdline_fixed_string_t flush_flow_director;
11102         portid_t port_id;
11103 };
11104
11105 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11106         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11107                                  flush_flow_director, "flush_flow_director");
11108 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11109         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11110                               port_id, UINT16);
11111
11112 static void
11113 cmd_flush_flow_director_parsed(void *parsed_result,
11114                           __attribute__((unused)) struct cmdline *cl,
11115                           __attribute__((unused)) void *data)
11116 {
11117         struct cmd_flow_director_result *res = parsed_result;
11118         int ret = 0;
11119
11120         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11121         if (ret < 0) {
11122                 printf("flow director is not supported on port %u.\n",
11123                         res->port_id);
11124                 return;
11125         }
11126
11127         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11128                         RTE_ETH_FILTER_FLUSH, NULL);
11129         if (ret < 0)
11130                 printf("flow director table flushing error: (%s)\n",
11131                         strerror(-ret));
11132 }
11133
11134 cmdline_parse_inst_t cmd_flush_flow_director = {
11135         .f = cmd_flush_flow_director_parsed,
11136         .data = NULL,
11137         .help_str = "flush_flow_director <port_id>: "
11138                 "Flush all flow director entries of a device on NIC",
11139         .tokens = {
11140                 (void *)&cmd_flush_flow_director_flush,
11141                 (void *)&cmd_flush_flow_director_port_id,
11142                 NULL,
11143         },
11144 };
11145
11146 /* *** deal with flow director mask *** */
11147 struct cmd_flow_director_mask_result {
11148         cmdline_fixed_string_t flow_director_mask;
11149         portid_t port_id;
11150         cmdline_fixed_string_t mode;
11151         cmdline_fixed_string_t mode_value;
11152         cmdline_fixed_string_t vlan;
11153         uint16_t vlan_mask;
11154         cmdline_fixed_string_t src_mask;
11155         cmdline_ipaddr_t ipv4_src;
11156         cmdline_ipaddr_t ipv6_src;
11157         uint16_t port_src;
11158         cmdline_fixed_string_t dst_mask;
11159         cmdline_ipaddr_t ipv4_dst;
11160         cmdline_ipaddr_t ipv6_dst;
11161         uint16_t port_dst;
11162         cmdline_fixed_string_t mac;
11163         uint8_t mac_addr_byte_mask;
11164         cmdline_fixed_string_t tunnel_id;
11165         uint32_t tunnel_id_mask;
11166         cmdline_fixed_string_t tunnel_type;
11167         uint8_t tunnel_type_mask;
11168 };
11169
11170 static void
11171 cmd_flow_director_mask_parsed(void *parsed_result,
11172                           __attribute__((unused)) struct cmdline *cl,
11173                           __attribute__((unused)) void *data)
11174 {
11175         struct cmd_flow_director_mask_result *res = parsed_result;
11176         struct rte_eth_fdir_masks *mask;
11177         struct rte_port *port;
11178
11179         port = &ports[res->port_id];
11180         /** Check if the port is not started **/
11181         if (port->port_status != RTE_PORT_STOPPED) {
11182                 printf("Please stop port %d first\n", res->port_id);
11183                 return;
11184         }
11185
11186         mask = &port->dev_conf.fdir_conf.mask;
11187
11188         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11189                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11190                         printf("Please set mode to MAC-VLAN.\n");
11191                         return;
11192                 }
11193
11194                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11195         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11196                 if (strcmp(res->mode_value, "Tunnel")) {
11197                         printf("Please set mode to Tunnel.\n");
11198                         return;
11199                 }
11200
11201                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11202                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11203                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11204                 mask->tunnel_type_mask = res->tunnel_type_mask;
11205         } else {
11206                 if (strcmp(res->mode_value, "IP")) {
11207                         printf("Please set mode to IP.\n");
11208                         return;
11209                 }
11210
11211                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11212                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11213                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11214                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11215                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11216                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11217                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11218         }
11219
11220         cmd_reconfig_device_queue(res->port_id, 1, 1);
11221 }
11222
11223 cmdline_parse_token_string_t cmd_flow_director_mask =
11224         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11225                                  flow_director_mask, "flow_director_mask");
11226 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11227         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11228                               port_id, UINT16);
11229 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11230         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11231                                  vlan, "vlan");
11232 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11233         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11234                               vlan_mask, UINT16);
11235 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11236         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11237                                  src_mask, "src_mask");
11238 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11239         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11240                                  ipv4_src);
11241 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11242         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11243                                  ipv6_src);
11244 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11245         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11246                               port_src, UINT16);
11247 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11248         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11249                                  dst_mask, "dst_mask");
11250 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11251         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11252                                  ipv4_dst);
11253 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11254         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11255                                  ipv6_dst);
11256 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11257         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11258                               port_dst, UINT16);
11259
11260 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11261         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11262                                  mode, "mode");
11263 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11264         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11265                                  mode_value, "IP");
11266 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11267         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11268                                  mode_value, "MAC-VLAN");
11269 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11270         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11271                                  mode_value, "Tunnel");
11272 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11273         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11274                                  mac, "mac");
11275 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11276         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11277                               mac_addr_byte_mask, UINT8);
11278 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11279         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11280                                  tunnel_type, "tunnel-type");
11281 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11282         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11283                               tunnel_type_mask, UINT8);
11284 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11285         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11286                                  tunnel_id, "tunnel-id");
11287 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11288         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11289                               tunnel_id_mask, UINT32);
11290
11291 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11292         .f = cmd_flow_director_mask_parsed,
11293         .data = NULL,
11294         .help_str = "flow_director_mask ... : "
11295                 "Set IP mode flow director's mask on NIC",
11296         .tokens = {
11297                 (void *)&cmd_flow_director_mask,
11298                 (void *)&cmd_flow_director_mask_port_id,
11299                 (void *)&cmd_flow_director_mask_mode,
11300                 (void *)&cmd_flow_director_mask_mode_ip,
11301                 (void *)&cmd_flow_director_mask_vlan,
11302                 (void *)&cmd_flow_director_mask_vlan_value,
11303                 (void *)&cmd_flow_director_mask_src,
11304                 (void *)&cmd_flow_director_mask_ipv4_src,
11305                 (void *)&cmd_flow_director_mask_ipv6_src,
11306                 (void *)&cmd_flow_director_mask_port_src,
11307                 (void *)&cmd_flow_director_mask_dst,
11308                 (void *)&cmd_flow_director_mask_ipv4_dst,
11309                 (void *)&cmd_flow_director_mask_ipv6_dst,
11310                 (void *)&cmd_flow_director_mask_port_dst,
11311                 NULL,
11312         },
11313 };
11314
11315 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11316         .f = cmd_flow_director_mask_parsed,
11317         .data = NULL,
11318         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11319                 "flow director's mask on NIC",
11320         .tokens = {
11321                 (void *)&cmd_flow_director_mask,
11322                 (void *)&cmd_flow_director_mask_port_id,
11323                 (void *)&cmd_flow_director_mask_mode,
11324                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11325                 (void *)&cmd_flow_director_mask_vlan,
11326                 (void *)&cmd_flow_director_mask_vlan_value,
11327                 NULL,
11328         },
11329 };
11330
11331 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11332         .f = cmd_flow_director_mask_parsed,
11333         .data = NULL,
11334         .help_str = "flow_director_mask ... : Set tunnel mode "
11335                 "flow director's mask on NIC",
11336         .tokens = {
11337                 (void *)&cmd_flow_director_mask,
11338                 (void *)&cmd_flow_director_mask_port_id,
11339                 (void *)&cmd_flow_director_mask_mode,
11340                 (void *)&cmd_flow_director_mask_mode_tunnel,
11341                 (void *)&cmd_flow_director_mask_vlan,
11342                 (void *)&cmd_flow_director_mask_vlan_value,
11343                 (void *)&cmd_flow_director_mask_mac,
11344                 (void *)&cmd_flow_director_mask_mac_value,
11345                 (void *)&cmd_flow_director_mask_tunnel_type,
11346                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11347                 (void *)&cmd_flow_director_mask_tunnel_id,
11348                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11349                 NULL,
11350         },
11351 };
11352
11353 /* *** deal with flow director mask on flexible payload *** */
11354 struct cmd_flow_director_flex_mask_result {
11355         cmdline_fixed_string_t flow_director_flexmask;
11356         portid_t port_id;
11357         cmdline_fixed_string_t flow;
11358         cmdline_fixed_string_t flow_type;
11359         cmdline_fixed_string_t mask;
11360 };
11361
11362 static void
11363 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11364                           __attribute__((unused)) struct cmdline *cl,
11365                           __attribute__((unused)) void *data)
11366 {
11367         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11368         struct rte_eth_fdir_info fdir_info;
11369         struct rte_eth_fdir_flex_mask flex_mask;
11370         struct rte_port *port;
11371         uint64_t flow_type_mask;
11372         uint16_t i;
11373         int ret;
11374
11375         port = &ports[res->port_id];
11376         /** Check if the port is not started **/
11377         if (port->port_status != RTE_PORT_STOPPED) {
11378                 printf("Please stop port %d first\n", res->port_id);
11379                 return;
11380         }
11381
11382         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11383         ret = parse_flexbytes(res->mask,
11384                         flex_mask.mask,
11385                         RTE_ETH_FDIR_MAX_FLEXLEN);
11386         if (ret < 0) {
11387                 printf("error: Cannot parse mask input.\n");
11388                 return;
11389         }
11390
11391         memset(&fdir_info, 0, sizeof(fdir_info));
11392         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11393                                 RTE_ETH_FILTER_INFO, &fdir_info);
11394         if (ret < 0) {
11395                 printf("Cannot get FDir filter info\n");
11396                 return;
11397         }
11398
11399         if (!strcmp(res->flow_type, "none")) {
11400                 /* means don't specify the flow type */
11401                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11402                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11403                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11404                                0, sizeof(struct rte_eth_fdir_flex_mask));
11405                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11406                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11407                                  &flex_mask,
11408                                  sizeof(struct rte_eth_fdir_flex_mask));
11409                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11410                 return;
11411         }
11412         flow_type_mask = fdir_info.flow_types_mask[0];
11413         if (!strcmp(res->flow_type, "all")) {
11414                 if (!flow_type_mask) {
11415                         printf("No flow type supported\n");
11416                         return;
11417                 }
11418                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11419                         if (flow_type_mask & (1ULL << i)) {
11420                                 flex_mask.flow_type = i;
11421                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11422                         }
11423                 }
11424                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11425                 return;
11426         }
11427         flex_mask.flow_type = str2flowtype(res->flow_type);
11428         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11429                 printf("Flow type %s not supported on port %d\n",
11430                                 res->flow_type, res->port_id);
11431                 return;
11432         }
11433         fdir_set_flex_mask(res->port_id, &flex_mask);
11434         cmd_reconfig_device_queue(res->port_id, 1, 1);
11435 }
11436
11437 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11438         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11439                                  flow_director_flexmask,
11440                                  "flow_director_flex_mask");
11441 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11442         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11443                               port_id, UINT16);
11444 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11445         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11446                                  flow, "flow");
11447 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11448         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11449                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11450                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11451 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11452         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11453                                  mask, NULL);
11454
11455 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11456         .f = cmd_flow_director_flex_mask_parsed,
11457         .data = NULL,
11458         .help_str = "flow_director_flex_mask ... : "
11459                 "Set flow director's flex mask on NIC",
11460         .tokens = {
11461                 (void *)&cmd_flow_director_flexmask,
11462                 (void *)&cmd_flow_director_flexmask_port_id,
11463                 (void *)&cmd_flow_director_flexmask_flow,
11464                 (void *)&cmd_flow_director_flexmask_flow_type,
11465                 (void *)&cmd_flow_director_flexmask_mask,
11466                 NULL,
11467         },
11468 };
11469
11470 /* *** deal with flow director flexible payload configuration *** */
11471 struct cmd_flow_director_flexpayload_result {
11472         cmdline_fixed_string_t flow_director_flexpayload;
11473         portid_t port_id;
11474         cmdline_fixed_string_t payload_layer;
11475         cmdline_fixed_string_t payload_cfg;
11476 };
11477
11478 static inline int
11479 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11480 {
11481         char s[256];
11482         const char *p, *p0 = q_arg;
11483         char *end;
11484         unsigned long int_fld;
11485         char *str_fld[max_num];
11486         int i;
11487         unsigned size;
11488         int ret = -1;
11489
11490         p = strchr(p0, '(');
11491         if (p == NULL)
11492                 return -1;
11493         ++p;
11494         p0 = strchr(p, ')');
11495         if (p0 == NULL)
11496                 return -1;
11497
11498         size = p0 - p;
11499         if (size >= sizeof(s))
11500                 return -1;
11501
11502         snprintf(s, sizeof(s), "%.*s", size, p);
11503         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11504         if (ret < 0 || ret > max_num)
11505                 return -1;
11506         for (i = 0; i < ret; i++) {
11507                 errno = 0;
11508                 int_fld = strtoul(str_fld[i], &end, 0);
11509                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11510                         return -1;
11511                 offsets[i] = (uint16_t)int_fld;
11512         }
11513         return ret;
11514 }
11515
11516 static void
11517 cmd_flow_director_flxpld_parsed(void *parsed_result,
11518                           __attribute__((unused)) struct cmdline *cl,
11519                           __attribute__((unused)) void *data)
11520 {
11521         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11522         struct rte_eth_flex_payload_cfg flex_cfg;
11523         struct rte_port *port;
11524         int ret = 0;
11525
11526         port = &ports[res->port_id];
11527         /** Check if the port is not started **/
11528         if (port->port_status != RTE_PORT_STOPPED) {
11529                 printf("Please stop port %d first\n", res->port_id);
11530                 return;
11531         }
11532
11533         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11534
11535         if (!strcmp(res->payload_layer, "raw"))
11536                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11537         else if (!strcmp(res->payload_layer, "l2"))
11538                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11539         else if (!strcmp(res->payload_layer, "l3"))
11540                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11541         else if (!strcmp(res->payload_layer, "l4"))
11542                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11543
11544         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11545                             RTE_ETH_FDIR_MAX_FLEXLEN);
11546         if (ret < 0) {
11547                 printf("error: Cannot parse flex payload input.\n");
11548                 return;
11549         }
11550
11551         fdir_set_flex_payload(res->port_id, &flex_cfg);
11552         cmd_reconfig_device_queue(res->port_id, 1, 1);
11553 }
11554
11555 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11556         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11557                                  flow_director_flexpayload,
11558                                  "flow_director_flex_payload");
11559 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11560         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11561                               port_id, UINT16);
11562 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11563         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11564                                  payload_layer, "raw#l2#l3#l4");
11565 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11566         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11567                                  payload_cfg, NULL);
11568
11569 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11570         .f = cmd_flow_director_flxpld_parsed,
11571         .data = NULL,
11572         .help_str = "flow_director_flexpayload ... : "
11573                 "Set flow director's flex payload on NIC",
11574         .tokens = {
11575                 (void *)&cmd_flow_director_flexpayload,
11576                 (void *)&cmd_flow_director_flexpayload_port_id,
11577                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11578                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11579                 NULL,
11580         },
11581 };
11582
11583 /* Generic flow interface command. */
11584 extern cmdline_parse_inst_t cmd_flow;
11585
11586 /* *** Classification Filters Control *** */
11587 /* *** Get symmetric hash enable per port *** */
11588 struct cmd_get_sym_hash_ena_per_port_result {
11589         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11590         portid_t port_id;
11591 };
11592
11593 static void
11594 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11595                                  __rte_unused struct cmdline *cl,
11596                                  __rte_unused void *data)
11597 {
11598         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11599         struct rte_eth_hash_filter_info info;
11600         int ret;
11601
11602         if (rte_eth_dev_filter_supported(res->port_id,
11603                                 RTE_ETH_FILTER_HASH) < 0) {
11604                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11605                                                         res->port_id);
11606                 return;
11607         }
11608
11609         memset(&info, 0, sizeof(info));
11610         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11611         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11612                                                 RTE_ETH_FILTER_GET, &info);
11613
11614         if (ret < 0) {
11615                 printf("Cannot get symmetric hash enable per port "
11616                                         "on port %u\n", res->port_id);
11617                 return;
11618         }
11619
11620         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11621                                 "enabled" : "disabled", res->port_id);
11622 }
11623
11624 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11625         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11626                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11627 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11628         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11629                 port_id, UINT16);
11630
11631 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11632         .f = cmd_get_sym_hash_per_port_parsed,
11633         .data = NULL,
11634         .help_str = "get_sym_hash_ena_per_port <port_id>",
11635         .tokens = {
11636                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11637                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11638                 NULL,
11639         },
11640 };
11641
11642 /* *** Set symmetric hash enable per port *** */
11643 struct cmd_set_sym_hash_ena_per_port_result {
11644         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11645         cmdline_fixed_string_t enable;
11646         portid_t port_id;
11647 };
11648
11649 static void
11650 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11651                                  __rte_unused struct cmdline *cl,
11652                                  __rte_unused void *data)
11653 {
11654         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11655         struct rte_eth_hash_filter_info info;
11656         int ret;
11657
11658         if (rte_eth_dev_filter_supported(res->port_id,
11659                                 RTE_ETH_FILTER_HASH) < 0) {
11660                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11661                                                         res->port_id);
11662                 return;
11663         }
11664
11665         memset(&info, 0, sizeof(info));
11666         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11667         if (!strcmp(res->enable, "enable"))
11668                 info.info.enable = 1;
11669         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11670                                         RTE_ETH_FILTER_SET, &info);
11671         if (ret < 0) {
11672                 printf("Cannot set symmetric hash enable per port on "
11673                                         "port %u\n", res->port_id);
11674                 return;
11675         }
11676         printf("Symmetric hash has been set to %s on port %u\n",
11677                                         res->enable, res->port_id);
11678 }
11679
11680 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11681         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11682                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11683 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11684         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11685                 port_id, UINT16);
11686 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11687         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11688                 enable, "enable#disable");
11689
11690 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11691         .f = cmd_set_sym_hash_per_port_parsed,
11692         .data = NULL,
11693         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11694         .tokens = {
11695                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11696                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11697                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11698                 NULL,
11699         },
11700 };
11701
11702 /* Get global config of hash function */
11703 struct cmd_get_hash_global_config_result {
11704         cmdline_fixed_string_t get_hash_global_config;
11705         portid_t port_id;
11706 };
11707
11708 static char *
11709 flowtype_to_str(uint16_t ftype)
11710 {
11711         uint16_t i;
11712         static struct {
11713                 char str[16];
11714                 uint16_t ftype;
11715         } ftype_table[] = {
11716                 {"ipv4", RTE_ETH_FLOW_IPV4},
11717                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11718                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11719                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11720                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11721                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11722                 {"ipv6", RTE_ETH_FLOW_IPV6},
11723                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11724                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11725                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11726                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11727                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11728                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11729                 {"port", RTE_ETH_FLOW_PORT},
11730                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11731                 {"geneve", RTE_ETH_FLOW_GENEVE},
11732                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11733         };
11734
11735         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11736                 if (ftype_table[i].ftype == ftype)
11737                         return ftype_table[i].str;
11738         }
11739
11740         return NULL;
11741 }
11742
11743 static void
11744 cmd_get_hash_global_config_parsed(void *parsed_result,
11745                                   __rte_unused struct cmdline *cl,
11746                                   __rte_unused void *data)
11747 {
11748         struct cmd_get_hash_global_config_result *res = parsed_result;
11749         struct rte_eth_hash_filter_info info;
11750         uint32_t idx, offset;
11751         uint16_t i;
11752         char *str;
11753         int ret;
11754
11755         if (rte_eth_dev_filter_supported(res->port_id,
11756                         RTE_ETH_FILTER_HASH) < 0) {
11757                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11758                                                         res->port_id);
11759                 return;
11760         }
11761
11762         memset(&info, 0, sizeof(info));
11763         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11764         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11765                                         RTE_ETH_FILTER_GET, &info);
11766         if (ret < 0) {
11767                 printf("Cannot get hash global configurations by port %d\n",
11768                                                         res->port_id);
11769                 return;
11770         }
11771
11772         switch (info.info.global_conf.hash_func) {
11773         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11774                 printf("Hash function is Toeplitz\n");
11775                 break;
11776         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11777                 printf("Hash function is Simple XOR\n");
11778                 break;
11779         default:
11780                 printf("Unknown hash function\n");
11781                 break;
11782         }
11783
11784         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11785                 idx = i / UINT64_BIT;
11786                 offset = i % UINT64_BIT;
11787                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11788                                                 (1ULL << offset)))
11789                         continue;
11790                 str = flowtype_to_str(i);
11791                 if (!str)
11792                         continue;
11793                 printf("Symmetric hash is %s globally for flow type %s "
11794                                                         "by port %d\n",
11795                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11796                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11797                                                         res->port_id);
11798         }
11799 }
11800
11801 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11802         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11803                 get_hash_global_config, "get_hash_global_config");
11804 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11805         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11806                 port_id, UINT16);
11807
11808 cmdline_parse_inst_t cmd_get_hash_global_config = {
11809         .f = cmd_get_hash_global_config_parsed,
11810         .data = NULL,
11811         .help_str = "get_hash_global_config <port_id>",
11812         .tokens = {
11813                 (void *)&cmd_get_hash_global_config_all,
11814                 (void *)&cmd_get_hash_global_config_port_id,
11815                 NULL,
11816         },
11817 };
11818
11819 /* Set global config of hash function */
11820 struct cmd_set_hash_global_config_result {
11821         cmdline_fixed_string_t set_hash_global_config;
11822         portid_t port_id;
11823         cmdline_fixed_string_t hash_func;
11824         cmdline_fixed_string_t flow_type;
11825         cmdline_fixed_string_t enable;
11826 };
11827
11828 static void
11829 cmd_set_hash_global_config_parsed(void *parsed_result,
11830                                   __rte_unused struct cmdline *cl,
11831                                   __rte_unused void *data)
11832 {
11833         struct cmd_set_hash_global_config_result *res = parsed_result;
11834         struct rte_eth_hash_filter_info info;
11835         uint32_t ftype, idx, offset;
11836         int ret;
11837
11838         if (rte_eth_dev_filter_supported(res->port_id,
11839                                 RTE_ETH_FILTER_HASH) < 0) {
11840                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11841                                                         res->port_id);
11842                 return;
11843         }
11844         memset(&info, 0, sizeof(info));
11845         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11846         if (!strcmp(res->hash_func, "toeplitz"))
11847                 info.info.global_conf.hash_func =
11848                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11849         else if (!strcmp(res->hash_func, "simple_xor"))
11850                 info.info.global_conf.hash_func =
11851                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11852         else if (!strcmp(res->hash_func, "default"))
11853                 info.info.global_conf.hash_func =
11854                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11855
11856         ftype = str2flowtype(res->flow_type);
11857         idx = ftype / UINT64_BIT;
11858         offset = ftype % UINT64_BIT;
11859         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11860         if (!strcmp(res->enable, "enable"))
11861                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11862                                                 (1ULL << offset);
11863         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11864                                         RTE_ETH_FILTER_SET, &info);
11865         if (ret < 0)
11866                 printf("Cannot set global hash configurations by port %d\n",
11867                                                         res->port_id);
11868         else
11869                 printf("Global hash configurations have been set "
11870                         "succcessfully by port %d\n", res->port_id);
11871 }
11872
11873 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11874         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11875                 set_hash_global_config, "set_hash_global_config");
11876 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11877         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11878                 port_id, UINT16);
11879 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11880         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11881                 hash_func, "toeplitz#simple_xor#default");
11882 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11883         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11884                 flow_type,
11885                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11886                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11887 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11888         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11889                 enable, "enable#disable");
11890
11891 cmdline_parse_inst_t cmd_set_hash_global_config = {
11892         .f = cmd_set_hash_global_config_parsed,
11893         .data = NULL,
11894         .help_str = "set_hash_global_config <port_id> "
11895                 "toeplitz|simple_xor|default "
11896                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11897                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11898                 "l2_payload enable|disable",
11899         .tokens = {
11900                 (void *)&cmd_set_hash_global_config_all,
11901                 (void *)&cmd_set_hash_global_config_port_id,
11902                 (void *)&cmd_set_hash_global_config_hash_func,
11903                 (void *)&cmd_set_hash_global_config_flow_type,
11904                 (void *)&cmd_set_hash_global_config_enable,
11905                 NULL,
11906         },
11907 };
11908
11909 /* Set hash input set */
11910 struct cmd_set_hash_input_set_result {
11911         cmdline_fixed_string_t set_hash_input_set;
11912         portid_t port_id;
11913         cmdline_fixed_string_t flow_type;
11914         cmdline_fixed_string_t inset_field;
11915         cmdline_fixed_string_t select;
11916 };
11917
11918 static enum rte_eth_input_set_field
11919 str2inset(char *string)
11920 {
11921         uint16_t i;
11922
11923         static const struct {
11924                 char str[32];
11925                 enum rte_eth_input_set_field inset;
11926         } inset_table[] = {
11927                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11928                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11929                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11930                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11931                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11932                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11933                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11934                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11935                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11936                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11937                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11938                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11939                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11940                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11941                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11942                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11943                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11944                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11945                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11946                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11947                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11948                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11949                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11950                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11951                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11952                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11953                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11954                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11955                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11956                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11957                 {"none", RTE_ETH_INPUT_SET_NONE},
11958         };
11959
11960         for (i = 0; i < RTE_DIM(inset_table); i++) {
11961                 if (!strcmp(string, inset_table[i].str))
11962                         return inset_table[i].inset;
11963         }
11964
11965         return RTE_ETH_INPUT_SET_UNKNOWN;
11966 }
11967
11968 static void
11969 cmd_set_hash_input_set_parsed(void *parsed_result,
11970                               __rte_unused struct cmdline *cl,
11971                               __rte_unused void *data)
11972 {
11973         struct cmd_set_hash_input_set_result *res = parsed_result;
11974         struct rte_eth_hash_filter_info info;
11975
11976         memset(&info, 0, sizeof(info));
11977         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11978         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11979         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11980         info.info.input_set_conf.inset_size = 1;
11981         if (!strcmp(res->select, "select"))
11982                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11983         else if (!strcmp(res->select, "add"))
11984                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11985         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11986                                 RTE_ETH_FILTER_SET, &info);
11987 }
11988
11989 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11990         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11991                 set_hash_input_set, "set_hash_input_set");
11992 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11993         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11994                 port_id, UINT16);
11995 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11996         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11997                 flow_type, NULL);
11998 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11999         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12000                 inset_field,
12001                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12002                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12003                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12004                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12005                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12006                 "fld-8th#none");
12007 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12008         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12009                 select, "select#add");
12010
12011 cmdline_parse_inst_t cmd_set_hash_input_set = {
12012         .f = cmd_set_hash_input_set_parsed,
12013         .data = NULL,
12014         .help_str = "set_hash_input_set <port_id> "
12015         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12016         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12017         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12018         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12019         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12020         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12021         "fld-7th|fld-8th|none select|add",
12022         .tokens = {
12023                 (void *)&cmd_set_hash_input_set_cmd,
12024                 (void *)&cmd_set_hash_input_set_port_id,
12025                 (void *)&cmd_set_hash_input_set_flow_type,
12026                 (void *)&cmd_set_hash_input_set_field,
12027                 (void *)&cmd_set_hash_input_set_select,
12028                 NULL,
12029         },
12030 };
12031
12032 /* Set flow director input set */
12033 struct cmd_set_fdir_input_set_result {
12034         cmdline_fixed_string_t set_fdir_input_set;
12035         portid_t port_id;
12036         cmdline_fixed_string_t flow_type;
12037         cmdline_fixed_string_t inset_field;
12038         cmdline_fixed_string_t select;
12039 };
12040
12041 static void
12042 cmd_set_fdir_input_set_parsed(void *parsed_result,
12043         __rte_unused struct cmdline *cl,
12044         __rte_unused void *data)
12045 {
12046         struct cmd_set_fdir_input_set_result *res = parsed_result;
12047         struct rte_eth_fdir_filter_info info;
12048
12049         memset(&info, 0, sizeof(info));
12050         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12051         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12052         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12053         info.info.input_set_conf.inset_size = 1;
12054         if (!strcmp(res->select, "select"))
12055                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12056         else if (!strcmp(res->select, "add"))
12057                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12058         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12059                 RTE_ETH_FILTER_SET, &info);
12060 }
12061
12062 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12063         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12064         set_fdir_input_set, "set_fdir_input_set");
12065 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12066         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12067         port_id, UINT16);
12068 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12069         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12070         flow_type,
12071         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12072         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12073 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12074         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12075         inset_field,
12076         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12077         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12078         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12079         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12080         "sctp-veri-tag#none");
12081 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12082         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12083         select, "select#add");
12084
12085 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12086         .f = cmd_set_fdir_input_set_parsed,
12087         .data = NULL,
12088         .help_str = "set_fdir_input_set <port_id> "
12089         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12090         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12091         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12092         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12093         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12094         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12095         "sctp-veri-tag|none select|add",
12096         .tokens = {
12097                 (void *)&cmd_set_fdir_input_set_cmd,
12098                 (void *)&cmd_set_fdir_input_set_port_id,
12099                 (void *)&cmd_set_fdir_input_set_flow_type,
12100                 (void *)&cmd_set_fdir_input_set_field,
12101                 (void *)&cmd_set_fdir_input_set_select,
12102                 NULL,
12103         },
12104 };
12105
12106 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12107 struct cmd_mcast_addr_result {
12108         cmdline_fixed_string_t mcast_addr_cmd;
12109         cmdline_fixed_string_t what;
12110         uint16_t port_num;
12111         struct ether_addr mc_addr;
12112 };
12113
12114 static void cmd_mcast_addr_parsed(void *parsed_result,
12115                 __attribute__((unused)) struct cmdline *cl,
12116                 __attribute__((unused)) void *data)
12117 {
12118         struct cmd_mcast_addr_result *res = parsed_result;
12119
12120         if (!is_multicast_ether_addr(&res->mc_addr)) {
12121                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12122                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12123                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12124                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12125                 return;
12126         }
12127         if (strcmp(res->what, "add") == 0)
12128                 mcast_addr_add(res->port_num, &res->mc_addr);
12129         else
12130                 mcast_addr_remove(res->port_num, &res->mc_addr);
12131 }
12132
12133 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12134         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12135                                  mcast_addr_cmd, "mcast_addr");
12136 cmdline_parse_token_string_t cmd_mcast_addr_what =
12137         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12138                                  "add#remove");
12139 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12140         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12141 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12142         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12143
12144 cmdline_parse_inst_t cmd_mcast_addr = {
12145         .f = cmd_mcast_addr_parsed,
12146         .data = (void *)0,
12147         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12148                 "Add/Remove multicast MAC address on port_id",
12149         .tokens = {
12150                 (void *)&cmd_mcast_addr_cmd,
12151                 (void *)&cmd_mcast_addr_what,
12152                 (void *)&cmd_mcast_addr_portnum,
12153                 (void *)&cmd_mcast_addr_addr,
12154                 NULL,
12155         },
12156 };
12157
12158 /* l2 tunnel config
12159  * only support E-tag now.
12160  */
12161
12162 /* Ether type config */
12163 struct cmd_config_l2_tunnel_eth_type_result {
12164         cmdline_fixed_string_t port;
12165         cmdline_fixed_string_t config;
12166         cmdline_fixed_string_t all;
12167         portid_t id;
12168         cmdline_fixed_string_t l2_tunnel;
12169         cmdline_fixed_string_t l2_tunnel_type;
12170         cmdline_fixed_string_t eth_type;
12171         uint16_t eth_type_val;
12172 };
12173
12174 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12175         TOKEN_STRING_INITIALIZER
12176                 (struct cmd_config_l2_tunnel_eth_type_result,
12177                  port, "port");
12178 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12179         TOKEN_STRING_INITIALIZER
12180                 (struct cmd_config_l2_tunnel_eth_type_result,
12181                  config, "config");
12182 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12183         TOKEN_STRING_INITIALIZER
12184                 (struct cmd_config_l2_tunnel_eth_type_result,
12185                  all, "all");
12186 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12187         TOKEN_NUM_INITIALIZER
12188                 (struct cmd_config_l2_tunnel_eth_type_result,
12189                  id, UINT16);
12190 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12191         TOKEN_STRING_INITIALIZER
12192                 (struct cmd_config_l2_tunnel_eth_type_result,
12193                  l2_tunnel, "l2-tunnel");
12194 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12195         TOKEN_STRING_INITIALIZER
12196                 (struct cmd_config_l2_tunnel_eth_type_result,
12197                  l2_tunnel_type, "E-tag");
12198 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12199         TOKEN_STRING_INITIALIZER
12200                 (struct cmd_config_l2_tunnel_eth_type_result,
12201                  eth_type, "ether-type");
12202 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12203         TOKEN_NUM_INITIALIZER
12204                 (struct cmd_config_l2_tunnel_eth_type_result,
12205                  eth_type_val, UINT16);
12206
12207 static enum rte_eth_tunnel_type
12208 str2fdir_l2_tunnel_type(char *string)
12209 {
12210         uint32_t i = 0;
12211
12212         static const struct {
12213                 char str[32];
12214                 enum rte_eth_tunnel_type type;
12215         } l2_tunnel_type_str[] = {
12216                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12217         };
12218
12219         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12220                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12221                         return l2_tunnel_type_str[i].type;
12222         }
12223         return RTE_TUNNEL_TYPE_NONE;
12224 }
12225
12226 /* ether type config for all ports */
12227 static void
12228 cmd_config_l2_tunnel_eth_type_all_parsed
12229         (void *parsed_result,
12230          __attribute__((unused)) struct cmdline *cl,
12231          __attribute__((unused)) void *data)
12232 {
12233         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12234         struct rte_eth_l2_tunnel_conf entry;
12235         portid_t pid;
12236
12237         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12238         entry.ether_type = res->eth_type_val;
12239
12240         RTE_ETH_FOREACH_DEV(pid) {
12241                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12242         }
12243 }
12244
12245 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12246         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12247         .data = NULL,
12248         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12249         .tokens = {
12250                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12251                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12252                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12253                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12254                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12255                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12256                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12257                 NULL,
12258         },
12259 };
12260
12261 /* ether type config for a specific port */
12262 static void
12263 cmd_config_l2_tunnel_eth_type_specific_parsed(
12264         void *parsed_result,
12265         __attribute__((unused)) struct cmdline *cl,
12266         __attribute__((unused)) void *data)
12267 {
12268         struct cmd_config_l2_tunnel_eth_type_result *res =
12269                  parsed_result;
12270         struct rte_eth_l2_tunnel_conf entry;
12271
12272         if (port_id_is_invalid(res->id, ENABLED_WARN))
12273                 return;
12274
12275         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12276         entry.ether_type = res->eth_type_val;
12277
12278         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12279 }
12280
12281 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12282         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12283         .data = NULL,
12284         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12285         .tokens = {
12286                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12287                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12288                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12289                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12290                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12291                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12292                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12293                 NULL,
12294         },
12295 };
12296
12297 /* Enable/disable l2 tunnel */
12298 struct cmd_config_l2_tunnel_en_dis_result {
12299         cmdline_fixed_string_t port;
12300         cmdline_fixed_string_t config;
12301         cmdline_fixed_string_t all;
12302         portid_t id;
12303         cmdline_fixed_string_t l2_tunnel;
12304         cmdline_fixed_string_t l2_tunnel_type;
12305         cmdline_fixed_string_t en_dis;
12306 };
12307
12308 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12309         TOKEN_STRING_INITIALIZER
12310                 (struct cmd_config_l2_tunnel_en_dis_result,
12311                  port, "port");
12312 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12313         TOKEN_STRING_INITIALIZER
12314                 (struct cmd_config_l2_tunnel_en_dis_result,
12315                  config, "config");
12316 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12317         TOKEN_STRING_INITIALIZER
12318                 (struct cmd_config_l2_tunnel_en_dis_result,
12319                  all, "all");
12320 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12321         TOKEN_NUM_INITIALIZER
12322                 (struct cmd_config_l2_tunnel_en_dis_result,
12323                  id, UINT16);
12324 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12325         TOKEN_STRING_INITIALIZER
12326                 (struct cmd_config_l2_tunnel_en_dis_result,
12327                  l2_tunnel, "l2-tunnel");
12328 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12329         TOKEN_STRING_INITIALIZER
12330                 (struct cmd_config_l2_tunnel_en_dis_result,
12331                  l2_tunnel_type, "E-tag");
12332 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12333         TOKEN_STRING_INITIALIZER
12334                 (struct cmd_config_l2_tunnel_en_dis_result,
12335                  en_dis, "enable#disable");
12336
12337 /* enable/disable l2 tunnel for all ports */
12338 static void
12339 cmd_config_l2_tunnel_en_dis_all_parsed(
12340         void *parsed_result,
12341         __attribute__((unused)) struct cmdline *cl,
12342         __attribute__((unused)) void *data)
12343 {
12344         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12345         struct rte_eth_l2_tunnel_conf entry;
12346         portid_t pid;
12347         uint8_t en;
12348
12349         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12350
12351         if (!strcmp("enable", res->en_dis))
12352                 en = 1;
12353         else
12354                 en = 0;
12355
12356         RTE_ETH_FOREACH_DEV(pid) {
12357                 rte_eth_dev_l2_tunnel_offload_set(pid,
12358                                                   &entry,
12359                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12360                                                   en);
12361         }
12362 }
12363
12364 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12365         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12366         .data = NULL,
12367         .help_str = "port config all l2-tunnel E-tag enable|disable",
12368         .tokens = {
12369                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12370                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12371                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12372                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12373                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12374                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12375                 NULL,
12376         },
12377 };
12378
12379 /* enable/disable l2 tunnel for a port */
12380 static void
12381 cmd_config_l2_tunnel_en_dis_specific_parsed(
12382         void *parsed_result,
12383         __attribute__((unused)) struct cmdline *cl,
12384         __attribute__((unused)) void *data)
12385 {
12386         struct cmd_config_l2_tunnel_en_dis_result *res =
12387                 parsed_result;
12388         struct rte_eth_l2_tunnel_conf entry;
12389
12390         if (port_id_is_invalid(res->id, ENABLED_WARN))
12391                 return;
12392
12393         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12394
12395         if (!strcmp("enable", res->en_dis))
12396                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12397                                                   &entry,
12398                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12399                                                   1);
12400         else
12401                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12402                                                   &entry,
12403                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12404                                                   0);
12405 }
12406
12407 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12408         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12409         .data = NULL,
12410         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12411         .tokens = {
12412                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12413                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12414                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12415                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12416                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12417                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12418                 NULL,
12419         },
12420 };
12421
12422 /* E-tag configuration */
12423
12424 /* Common result structure for all E-tag configuration */
12425 struct cmd_config_e_tag_result {
12426         cmdline_fixed_string_t e_tag;
12427         cmdline_fixed_string_t set;
12428         cmdline_fixed_string_t insertion;
12429         cmdline_fixed_string_t stripping;
12430         cmdline_fixed_string_t forwarding;
12431         cmdline_fixed_string_t filter;
12432         cmdline_fixed_string_t add;
12433         cmdline_fixed_string_t del;
12434         cmdline_fixed_string_t on;
12435         cmdline_fixed_string_t off;
12436         cmdline_fixed_string_t on_off;
12437         cmdline_fixed_string_t port_tag_id;
12438         uint32_t port_tag_id_val;
12439         cmdline_fixed_string_t e_tag_id;
12440         uint16_t e_tag_id_val;
12441         cmdline_fixed_string_t dst_pool;
12442         uint8_t dst_pool_val;
12443         cmdline_fixed_string_t port;
12444         portid_t port_id;
12445         cmdline_fixed_string_t vf;
12446         uint8_t vf_id;
12447 };
12448
12449 /* Common CLI fields for all E-tag configuration */
12450 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12451         TOKEN_STRING_INITIALIZER
12452                 (struct cmd_config_e_tag_result,
12453                  e_tag, "E-tag");
12454 cmdline_parse_token_string_t cmd_config_e_tag_set =
12455         TOKEN_STRING_INITIALIZER
12456                 (struct cmd_config_e_tag_result,
12457                  set, "set");
12458 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12459         TOKEN_STRING_INITIALIZER
12460                 (struct cmd_config_e_tag_result,
12461                  insertion, "insertion");
12462 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12463         TOKEN_STRING_INITIALIZER
12464                 (struct cmd_config_e_tag_result,
12465                  stripping, "stripping");
12466 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12467         TOKEN_STRING_INITIALIZER
12468                 (struct cmd_config_e_tag_result,
12469                  forwarding, "forwarding");
12470 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12471         TOKEN_STRING_INITIALIZER
12472                 (struct cmd_config_e_tag_result,
12473                  filter, "filter");
12474 cmdline_parse_token_string_t cmd_config_e_tag_add =
12475         TOKEN_STRING_INITIALIZER
12476                 (struct cmd_config_e_tag_result,
12477                  add, "add");
12478 cmdline_parse_token_string_t cmd_config_e_tag_del =
12479         TOKEN_STRING_INITIALIZER
12480                 (struct cmd_config_e_tag_result,
12481                  del, "del");
12482 cmdline_parse_token_string_t cmd_config_e_tag_on =
12483         TOKEN_STRING_INITIALIZER
12484                 (struct cmd_config_e_tag_result,
12485                  on, "on");
12486 cmdline_parse_token_string_t cmd_config_e_tag_off =
12487         TOKEN_STRING_INITIALIZER
12488                 (struct cmd_config_e_tag_result,
12489                  off, "off");
12490 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12491         TOKEN_STRING_INITIALIZER
12492                 (struct cmd_config_e_tag_result,
12493                  on_off, "on#off");
12494 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12495         TOKEN_STRING_INITIALIZER
12496                 (struct cmd_config_e_tag_result,
12497                  port_tag_id, "port-tag-id");
12498 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12499         TOKEN_NUM_INITIALIZER
12500                 (struct cmd_config_e_tag_result,
12501                  port_tag_id_val, UINT32);
12502 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12503         TOKEN_STRING_INITIALIZER
12504                 (struct cmd_config_e_tag_result,
12505                  e_tag_id, "e-tag-id");
12506 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12507         TOKEN_NUM_INITIALIZER
12508                 (struct cmd_config_e_tag_result,
12509                  e_tag_id_val, UINT16);
12510 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12511         TOKEN_STRING_INITIALIZER
12512                 (struct cmd_config_e_tag_result,
12513                  dst_pool, "dst-pool");
12514 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12515         TOKEN_NUM_INITIALIZER
12516                 (struct cmd_config_e_tag_result,
12517                  dst_pool_val, UINT8);
12518 cmdline_parse_token_string_t cmd_config_e_tag_port =
12519         TOKEN_STRING_INITIALIZER
12520                 (struct cmd_config_e_tag_result,
12521                  port, "port");
12522 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12523         TOKEN_NUM_INITIALIZER
12524                 (struct cmd_config_e_tag_result,
12525                  port_id, UINT16);
12526 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12527         TOKEN_STRING_INITIALIZER
12528                 (struct cmd_config_e_tag_result,
12529                  vf, "vf");
12530 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12531         TOKEN_NUM_INITIALIZER
12532                 (struct cmd_config_e_tag_result,
12533                  vf_id, UINT8);
12534
12535 /* E-tag insertion configuration */
12536 static void
12537 cmd_config_e_tag_insertion_en_parsed(
12538         void *parsed_result,
12539         __attribute__((unused)) struct cmdline *cl,
12540         __attribute__((unused)) void *data)
12541 {
12542         struct cmd_config_e_tag_result *res =
12543                 parsed_result;
12544         struct rte_eth_l2_tunnel_conf entry;
12545
12546         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12547                 return;
12548
12549         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12550         entry.tunnel_id = res->port_tag_id_val;
12551         entry.vf_id = res->vf_id;
12552         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12553                                           &entry,
12554                                           ETH_L2_TUNNEL_INSERTION_MASK,
12555                                           1);
12556 }
12557
12558 static void
12559 cmd_config_e_tag_insertion_dis_parsed(
12560         void *parsed_result,
12561         __attribute__((unused)) struct cmdline *cl,
12562         __attribute__((unused)) void *data)
12563 {
12564         struct cmd_config_e_tag_result *res =
12565                 parsed_result;
12566         struct rte_eth_l2_tunnel_conf entry;
12567
12568         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12569                 return;
12570
12571         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12572         entry.vf_id = res->vf_id;
12573
12574         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12575                                           &entry,
12576                                           ETH_L2_TUNNEL_INSERTION_MASK,
12577                                           0);
12578 }
12579
12580 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12581         .f = cmd_config_e_tag_insertion_en_parsed,
12582         .data = NULL,
12583         .help_str = "E-tag ... : E-tag insertion enable",
12584         .tokens = {
12585                 (void *)&cmd_config_e_tag_e_tag,
12586                 (void *)&cmd_config_e_tag_set,
12587                 (void *)&cmd_config_e_tag_insertion,
12588                 (void *)&cmd_config_e_tag_on,
12589                 (void *)&cmd_config_e_tag_port_tag_id,
12590                 (void *)&cmd_config_e_tag_port_tag_id_val,
12591                 (void *)&cmd_config_e_tag_port,
12592                 (void *)&cmd_config_e_tag_port_id,
12593                 (void *)&cmd_config_e_tag_vf,
12594                 (void *)&cmd_config_e_tag_vf_id,
12595                 NULL,
12596         },
12597 };
12598
12599 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12600         .f = cmd_config_e_tag_insertion_dis_parsed,
12601         .data = NULL,
12602         .help_str = "E-tag ... : E-tag insertion disable",
12603         .tokens = {
12604                 (void *)&cmd_config_e_tag_e_tag,
12605                 (void *)&cmd_config_e_tag_set,
12606                 (void *)&cmd_config_e_tag_insertion,
12607                 (void *)&cmd_config_e_tag_off,
12608                 (void *)&cmd_config_e_tag_port,
12609                 (void *)&cmd_config_e_tag_port_id,
12610                 (void *)&cmd_config_e_tag_vf,
12611                 (void *)&cmd_config_e_tag_vf_id,
12612                 NULL,
12613         },
12614 };
12615
12616 /* E-tag stripping configuration */
12617 static void
12618 cmd_config_e_tag_stripping_parsed(
12619         void *parsed_result,
12620         __attribute__((unused)) struct cmdline *cl,
12621         __attribute__((unused)) void *data)
12622 {
12623         struct cmd_config_e_tag_result *res =
12624                 parsed_result;
12625         struct rte_eth_l2_tunnel_conf entry;
12626
12627         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12628                 return;
12629
12630         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12631
12632         if (!strcmp(res->on_off, "on"))
12633                 rte_eth_dev_l2_tunnel_offload_set
12634                         (res->port_id,
12635                          &entry,
12636                          ETH_L2_TUNNEL_STRIPPING_MASK,
12637                          1);
12638         else
12639                 rte_eth_dev_l2_tunnel_offload_set
12640                         (res->port_id,
12641                          &entry,
12642                          ETH_L2_TUNNEL_STRIPPING_MASK,
12643                          0);
12644 }
12645
12646 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12647         .f = cmd_config_e_tag_stripping_parsed,
12648         .data = NULL,
12649         .help_str = "E-tag ... : E-tag stripping enable/disable",
12650         .tokens = {
12651                 (void *)&cmd_config_e_tag_e_tag,
12652                 (void *)&cmd_config_e_tag_set,
12653                 (void *)&cmd_config_e_tag_stripping,
12654                 (void *)&cmd_config_e_tag_on_off,
12655                 (void *)&cmd_config_e_tag_port,
12656                 (void *)&cmd_config_e_tag_port_id,
12657                 NULL,
12658         },
12659 };
12660
12661 /* E-tag forwarding configuration */
12662 static void
12663 cmd_config_e_tag_forwarding_parsed(
12664         void *parsed_result,
12665         __attribute__((unused)) struct cmdline *cl,
12666         __attribute__((unused)) void *data)
12667 {
12668         struct cmd_config_e_tag_result *res = parsed_result;
12669         struct rte_eth_l2_tunnel_conf entry;
12670
12671         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12672                 return;
12673
12674         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12675
12676         if (!strcmp(res->on_off, "on"))
12677                 rte_eth_dev_l2_tunnel_offload_set
12678                         (res->port_id,
12679                          &entry,
12680                          ETH_L2_TUNNEL_FORWARDING_MASK,
12681                          1);
12682         else
12683                 rte_eth_dev_l2_tunnel_offload_set
12684                         (res->port_id,
12685                          &entry,
12686                          ETH_L2_TUNNEL_FORWARDING_MASK,
12687                          0);
12688 }
12689
12690 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12691         .f = cmd_config_e_tag_forwarding_parsed,
12692         .data = NULL,
12693         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12694         .tokens = {
12695                 (void *)&cmd_config_e_tag_e_tag,
12696                 (void *)&cmd_config_e_tag_set,
12697                 (void *)&cmd_config_e_tag_forwarding,
12698                 (void *)&cmd_config_e_tag_on_off,
12699                 (void *)&cmd_config_e_tag_port,
12700                 (void *)&cmd_config_e_tag_port_id,
12701                 NULL,
12702         },
12703 };
12704
12705 /* E-tag filter configuration */
12706 static void
12707 cmd_config_e_tag_filter_add_parsed(
12708         void *parsed_result,
12709         __attribute__((unused)) struct cmdline *cl,
12710         __attribute__((unused)) void *data)
12711 {
12712         struct cmd_config_e_tag_result *res = parsed_result;
12713         struct rte_eth_l2_tunnel_conf entry;
12714         int ret = 0;
12715
12716         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12717                 return;
12718
12719         if (res->e_tag_id_val > 0x3fff) {
12720                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12721                 return;
12722         }
12723
12724         ret = rte_eth_dev_filter_supported(res->port_id,
12725                                            RTE_ETH_FILTER_L2_TUNNEL);
12726         if (ret < 0) {
12727                 printf("E-tag filter is not supported on port %u.\n",
12728                        res->port_id);
12729                 return;
12730         }
12731
12732         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12733         entry.tunnel_id = res->e_tag_id_val;
12734         entry.pool = res->dst_pool_val;
12735
12736         ret = rte_eth_dev_filter_ctrl(res->port_id,
12737                                       RTE_ETH_FILTER_L2_TUNNEL,
12738                                       RTE_ETH_FILTER_ADD,
12739                                       &entry);
12740         if (ret < 0)
12741                 printf("E-tag filter programming error: (%s)\n",
12742                        strerror(-ret));
12743 }
12744
12745 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12746         .f = cmd_config_e_tag_filter_add_parsed,
12747         .data = NULL,
12748         .help_str = "E-tag ... : E-tag filter add",
12749         .tokens = {
12750                 (void *)&cmd_config_e_tag_e_tag,
12751                 (void *)&cmd_config_e_tag_set,
12752                 (void *)&cmd_config_e_tag_filter,
12753                 (void *)&cmd_config_e_tag_add,
12754                 (void *)&cmd_config_e_tag_e_tag_id,
12755                 (void *)&cmd_config_e_tag_e_tag_id_val,
12756                 (void *)&cmd_config_e_tag_dst_pool,
12757                 (void *)&cmd_config_e_tag_dst_pool_val,
12758                 (void *)&cmd_config_e_tag_port,
12759                 (void *)&cmd_config_e_tag_port_id,
12760                 NULL,
12761         },
12762 };
12763
12764 static void
12765 cmd_config_e_tag_filter_del_parsed(
12766         void *parsed_result,
12767         __attribute__((unused)) struct cmdline *cl,
12768         __attribute__((unused)) void *data)
12769 {
12770         struct cmd_config_e_tag_result *res = parsed_result;
12771         struct rte_eth_l2_tunnel_conf entry;
12772         int ret = 0;
12773
12774         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12775                 return;
12776
12777         if (res->e_tag_id_val > 0x3fff) {
12778                 printf("e-tag-id must be less than 0x3fff.\n");
12779                 return;
12780         }
12781
12782         ret = rte_eth_dev_filter_supported(res->port_id,
12783                                            RTE_ETH_FILTER_L2_TUNNEL);
12784         if (ret < 0) {
12785                 printf("E-tag filter is not supported on port %u.\n",
12786                        res->port_id);
12787                 return;
12788         }
12789
12790         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12791         entry.tunnel_id = res->e_tag_id_val;
12792
12793         ret = rte_eth_dev_filter_ctrl(res->port_id,
12794                                       RTE_ETH_FILTER_L2_TUNNEL,
12795                                       RTE_ETH_FILTER_DELETE,
12796                                       &entry);
12797         if (ret < 0)
12798                 printf("E-tag filter programming error: (%s)\n",
12799                        strerror(-ret));
12800 }
12801
12802 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12803         .f = cmd_config_e_tag_filter_del_parsed,
12804         .data = NULL,
12805         .help_str = "E-tag ... : E-tag filter delete",
12806         .tokens = {
12807                 (void *)&cmd_config_e_tag_e_tag,
12808                 (void *)&cmd_config_e_tag_set,
12809                 (void *)&cmd_config_e_tag_filter,
12810                 (void *)&cmd_config_e_tag_del,
12811                 (void *)&cmd_config_e_tag_e_tag_id,
12812                 (void *)&cmd_config_e_tag_e_tag_id_val,
12813                 (void *)&cmd_config_e_tag_port,
12814                 (void *)&cmd_config_e_tag_port_id,
12815                 NULL,
12816         },
12817 };
12818
12819 /* vf vlan anti spoof configuration */
12820
12821 /* Common result structure for vf vlan anti spoof */
12822 struct cmd_vf_vlan_anti_spoof_result {
12823         cmdline_fixed_string_t set;
12824         cmdline_fixed_string_t vf;
12825         cmdline_fixed_string_t vlan;
12826         cmdline_fixed_string_t antispoof;
12827         portid_t port_id;
12828         uint32_t vf_id;
12829         cmdline_fixed_string_t on_off;
12830 };
12831
12832 /* Common CLI fields for vf vlan anti spoof enable disable */
12833 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12834         TOKEN_STRING_INITIALIZER
12835                 (struct cmd_vf_vlan_anti_spoof_result,
12836                  set, "set");
12837 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12838         TOKEN_STRING_INITIALIZER
12839                 (struct cmd_vf_vlan_anti_spoof_result,
12840                  vf, "vf");
12841 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12842         TOKEN_STRING_INITIALIZER
12843                 (struct cmd_vf_vlan_anti_spoof_result,
12844                  vlan, "vlan");
12845 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12846         TOKEN_STRING_INITIALIZER
12847                 (struct cmd_vf_vlan_anti_spoof_result,
12848                  antispoof, "antispoof");
12849 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12850         TOKEN_NUM_INITIALIZER
12851                 (struct cmd_vf_vlan_anti_spoof_result,
12852                  port_id, UINT16);
12853 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12854         TOKEN_NUM_INITIALIZER
12855                 (struct cmd_vf_vlan_anti_spoof_result,
12856                  vf_id, UINT32);
12857 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12858         TOKEN_STRING_INITIALIZER
12859                 (struct cmd_vf_vlan_anti_spoof_result,
12860                  on_off, "on#off");
12861
12862 static void
12863 cmd_set_vf_vlan_anti_spoof_parsed(
12864         void *parsed_result,
12865         __attribute__((unused)) struct cmdline *cl,
12866         __attribute__((unused)) void *data)
12867 {
12868         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12869         int ret = -ENOTSUP;
12870
12871         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12872
12873         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12874                 return;
12875
12876 #ifdef RTE_LIBRTE_IXGBE_PMD
12877         if (ret == -ENOTSUP)
12878                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12879                                 res->vf_id, is_on);
12880 #endif
12881 #ifdef RTE_LIBRTE_I40E_PMD
12882         if (ret == -ENOTSUP)
12883                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12884                                 res->vf_id, is_on);
12885 #endif
12886 #ifdef RTE_LIBRTE_BNXT_PMD
12887         if (ret == -ENOTSUP)
12888                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12889                                 res->vf_id, is_on);
12890 #endif
12891
12892         switch (ret) {
12893         case 0:
12894                 break;
12895         case -EINVAL:
12896                 printf("invalid vf_id %d\n", res->vf_id);
12897                 break;
12898         case -ENODEV:
12899                 printf("invalid port_id %d\n", res->port_id);
12900                 break;
12901         case -ENOTSUP:
12902                 printf("function not implemented\n");
12903                 break;
12904         default:
12905                 printf("programming error: (%s)\n", strerror(-ret));
12906         }
12907 }
12908
12909 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12910         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12911         .data = NULL,
12912         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12913         .tokens = {
12914                 (void *)&cmd_vf_vlan_anti_spoof_set,
12915                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12916                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12917                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12918                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12919                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12920                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12921                 NULL,
12922         },
12923 };
12924
12925 /* vf mac anti spoof configuration */
12926
12927 /* Common result structure for vf mac anti spoof */
12928 struct cmd_vf_mac_anti_spoof_result {
12929         cmdline_fixed_string_t set;
12930         cmdline_fixed_string_t vf;
12931         cmdline_fixed_string_t mac;
12932         cmdline_fixed_string_t antispoof;
12933         portid_t port_id;
12934         uint32_t vf_id;
12935         cmdline_fixed_string_t on_off;
12936 };
12937
12938 /* Common CLI fields for vf mac anti spoof enable disable */
12939 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12940         TOKEN_STRING_INITIALIZER
12941                 (struct cmd_vf_mac_anti_spoof_result,
12942                  set, "set");
12943 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12944         TOKEN_STRING_INITIALIZER
12945                 (struct cmd_vf_mac_anti_spoof_result,
12946                  vf, "vf");
12947 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12948         TOKEN_STRING_INITIALIZER
12949                 (struct cmd_vf_mac_anti_spoof_result,
12950                  mac, "mac");
12951 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12952         TOKEN_STRING_INITIALIZER
12953                 (struct cmd_vf_mac_anti_spoof_result,
12954                  antispoof, "antispoof");
12955 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12956         TOKEN_NUM_INITIALIZER
12957                 (struct cmd_vf_mac_anti_spoof_result,
12958                  port_id, UINT16);
12959 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12960         TOKEN_NUM_INITIALIZER
12961                 (struct cmd_vf_mac_anti_spoof_result,
12962                  vf_id, UINT32);
12963 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12964         TOKEN_STRING_INITIALIZER
12965                 (struct cmd_vf_mac_anti_spoof_result,
12966                  on_off, "on#off");
12967
12968 static void
12969 cmd_set_vf_mac_anti_spoof_parsed(
12970         void *parsed_result,
12971         __attribute__((unused)) struct cmdline *cl,
12972         __attribute__((unused)) void *data)
12973 {
12974         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12975         int ret = -ENOTSUP;
12976
12977         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12978
12979         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12980                 return;
12981
12982 #ifdef RTE_LIBRTE_IXGBE_PMD
12983         if (ret == -ENOTSUP)
12984                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12985                         res->vf_id, is_on);
12986 #endif
12987 #ifdef RTE_LIBRTE_I40E_PMD
12988         if (ret == -ENOTSUP)
12989                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12990                         res->vf_id, is_on);
12991 #endif
12992 #ifdef RTE_LIBRTE_BNXT_PMD
12993         if (ret == -ENOTSUP)
12994                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12995                         res->vf_id, is_on);
12996 #endif
12997
12998         switch (ret) {
12999         case 0:
13000                 break;
13001         case -EINVAL:
13002                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13003                 break;
13004         case -ENODEV:
13005                 printf("invalid port_id %d\n", res->port_id);
13006                 break;
13007         case -ENOTSUP:
13008                 printf("function not implemented\n");
13009                 break;
13010         default:
13011                 printf("programming error: (%s)\n", strerror(-ret));
13012         }
13013 }
13014
13015 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13016         .f = cmd_set_vf_mac_anti_spoof_parsed,
13017         .data = NULL,
13018         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13019         .tokens = {
13020                 (void *)&cmd_vf_mac_anti_spoof_set,
13021                 (void *)&cmd_vf_mac_anti_spoof_vf,
13022                 (void *)&cmd_vf_mac_anti_spoof_mac,
13023                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13024                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13025                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13026                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13027                 NULL,
13028         },
13029 };
13030
13031 /* vf vlan strip queue configuration */
13032
13033 /* Common result structure for vf mac anti spoof */
13034 struct cmd_vf_vlan_stripq_result {
13035         cmdline_fixed_string_t set;
13036         cmdline_fixed_string_t vf;
13037         cmdline_fixed_string_t vlan;
13038         cmdline_fixed_string_t stripq;
13039         portid_t port_id;
13040         uint16_t vf_id;
13041         cmdline_fixed_string_t on_off;
13042 };
13043
13044 /* Common CLI fields for vf vlan strip enable disable */
13045 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13046         TOKEN_STRING_INITIALIZER
13047                 (struct cmd_vf_vlan_stripq_result,
13048                  set, "set");
13049 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13050         TOKEN_STRING_INITIALIZER
13051                 (struct cmd_vf_vlan_stripq_result,
13052                  vf, "vf");
13053 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13054         TOKEN_STRING_INITIALIZER
13055                 (struct cmd_vf_vlan_stripq_result,
13056                  vlan, "vlan");
13057 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13058         TOKEN_STRING_INITIALIZER
13059                 (struct cmd_vf_vlan_stripq_result,
13060                  stripq, "stripq");
13061 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13062         TOKEN_NUM_INITIALIZER
13063                 (struct cmd_vf_vlan_stripq_result,
13064                  port_id, UINT16);
13065 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13066         TOKEN_NUM_INITIALIZER
13067                 (struct cmd_vf_vlan_stripq_result,
13068                  vf_id, UINT16);
13069 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13070         TOKEN_STRING_INITIALIZER
13071                 (struct cmd_vf_vlan_stripq_result,
13072                  on_off, "on#off");
13073
13074 static void
13075 cmd_set_vf_vlan_stripq_parsed(
13076         void *parsed_result,
13077         __attribute__((unused)) struct cmdline *cl,
13078         __attribute__((unused)) void *data)
13079 {
13080         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13081         int ret = -ENOTSUP;
13082
13083         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13084
13085         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13086                 return;
13087
13088 #ifdef RTE_LIBRTE_IXGBE_PMD
13089         if (ret == -ENOTSUP)
13090                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13091                         res->vf_id, is_on);
13092 #endif
13093 #ifdef RTE_LIBRTE_I40E_PMD
13094         if (ret == -ENOTSUP)
13095                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13096                         res->vf_id, is_on);
13097 #endif
13098 #ifdef RTE_LIBRTE_BNXT_PMD
13099         if (ret == -ENOTSUP)
13100                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13101                         res->vf_id, is_on);
13102 #endif
13103
13104         switch (ret) {
13105         case 0:
13106                 break;
13107         case -EINVAL:
13108                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13109                 break;
13110         case -ENODEV:
13111                 printf("invalid port_id %d\n", res->port_id);
13112                 break;
13113         case -ENOTSUP:
13114                 printf("function not implemented\n");
13115                 break;
13116         default:
13117                 printf("programming error: (%s)\n", strerror(-ret));
13118         }
13119 }
13120
13121 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13122         .f = cmd_set_vf_vlan_stripq_parsed,
13123         .data = NULL,
13124         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13125         .tokens = {
13126                 (void *)&cmd_vf_vlan_stripq_set,
13127                 (void *)&cmd_vf_vlan_stripq_vf,
13128                 (void *)&cmd_vf_vlan_stripq_vlan,
13129                 (void *)&cmd_vf_vlan_stripq_stripq,
13130                 (void *)&cmd_vf_vlan_stripq_port_id,
13131                 (void *)&cmd_vf_vlan_stripq_vf_id,
13132                 (void *)&cmd_vf_vlan_stripq_on_off,
13133                 NULL,
13134         },
13135 };
13136
13137 /* vf vlan insert configuration */
13138
13139 /* Common result structure for vf vlan insert */
13140 struct cmd_vf_vlan_insert_result {
13141         cmdline_fixed_string_t set;
13142         cmdline_fixed_string_t vf;
13143         cmdline_fixed_string_t vlan;
13144         cmdline_fixed_string_t insert;
13145         portid_t port_id;
13146         uint16_t vf_id;
13147         uint16_t vlan_id;
13148 };
13149
13150 /* Common CLI fields for vf vlan insert enable disable */
13151 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13152         TOKEN_STRING_INITIALIZER
13153                 (struct cmd_vf_vlan_insert_result,
13154                  set, "set");
13155 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13156         TOKEN_STRING_INITIALIZER
13157                 (struct cmd_vf_vlan_insert_result,
13158                  vf, "vf");
13159 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13160         TOKEN_STRING_INITIALIZER
13161                 (struct cmd_vf_vlan_insert_result,
13162                  vlan, "vlan");
13163 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13164         TOKEN_STRING_INITIALIZER
13165                 (struct cmd_vf_vlan_insert_result,
13166                  insert, "insert");
13167 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13168         TOKEN_NUM_INITIALIZER
13169                 (struct cmd_vf_vlan_insert_result,
13170                  port_id, UINT16);
13171 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13172         TOKEN_NUM_INITIALIZER
13173                 (struct cmd_vf_vlan_insert_result,
13174                  vf_id, UINT16);
13175 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13176         TOKEN_NUM_INITIALIZER
13177                 (struct cmd_vf_vlan_insert_result,
13178                  vlan_id, UINT16);
13179
13180 static void
13181 cmd_set_vf_vlan_insert_parsed(
13182         void *parsed_result,
13183         __attribute__((unused)) struct cmdline *cl,
13184         __attribute__((unused)) void *data)
13185 {
13186         struct cmd_vf_vlan_insert_result *res = parsed_result;
13187         int ret = -ENOTSUP;
13188
13189         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13190                 return;
13191
13192 #ifdef RTE_LIBRTE_IXGBE_PMD
13193         if (ret == -ENOTSUP)
13194                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13195                         res->vlan_id);
13196 #endif
13197 #ifdef RTE_LIBRTE_I40E_PMD
13198         if (ret == -ENOTSUP)
13199                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13200                         res->vlan_id);
13201 #endif
13202 #ifdef RTE_LIBRTE_BNXT_PMD
13203         if (ret == -ENOTSUP)
13204                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13205                         res->vlan_id);
13206 #endif
13207
13208         switch (ret) {
13209         case 0:
13210                 break;
13211         case -EINVAL:
13212                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13213                 break;
13214         case -ENODEV:
13215                 printf("invalid port_id %d\n", res->port_id);
13216                 break;
13217         case -ENOTSUP:
13218                 printf("function not implemented\n");
13219                 break;
13220         default:
13221                 printf("programming error: (%s)\n", strerror(-ret));
13222         }
13223 }
13224
13225 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13226         .f = cmd_set_vf_vlan_insert_parsed,
13227         .data = NULL,
13228         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13229         .tokens = {
13230                 (void *)&cmd_vf_vlan_insert_set,
13231                 (void *)&cmd_vf_vlan_insert_vf,
13232                 (void *)&cmd_vf_vlan_insert_vlan,
13233                 (void *)&cmd_vf_vlan_insert_insert,
13234                 (void *)&cmd_vf_vlan_insert_port_id,
13235                 (void *)&cmd_vf_vlan_insert_vf_id,
13236                 (void *)&cmd_vf_vlan_insert_vlan_id,
13237                 NULL,
13238         },
13239 };
13240
13241 /* tx loopback configuration */
13242
13243 /* Common result structure for tx loopback */
13244 struct cmd_tx_loopback_result {
13245         cmdline_fixed_string_t set;
13246         cmdline_fixed_string_t tx;
13247         cmdline_fixed_string_t loopback;
13248         portid_t port_id;
13249         cmdline_fixed_string_t on_off;
13250 };
13251
13252 /* Common CLI fields for tx loopback enable disable */
13253 cmdline_parse_token_string_t cmd_tx_loopback_set =
13254         TOKEN_STRING_INITIALIZER
13255                 (struct cmd_tx_loopback_result,
13256                  set, "set");
13257 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13258         TOKEN_STRING_INITIALIZER
13259                 (struct cmd_tx_loopback_result,
13260                  tx, "tx");
13261 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13262         TOKEN_STRING_INITIALIZER
13263                 (struct cmd_tx_loopback_result,
13264                  loopback, "loopback");
13265 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13266         TOKEN_NUM_INITIALIZER
13267                 (struct cmd_tx_loopback_result,
13268                  port_id, UINT16);
13269 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13270         TOKEN_STRING_INITIALIZER
13271                 (struct cmd_tx_loopback_result,
13272                  on_off, "on#off");
13273
13274 static void
13275 cmd_set_tx_loopback_parsed(
13276         void *parsed_result,
13277         __attribute__((unused)) struct cmdline *cl,
13278         __attribute__((unused)) void *data)
13279 {
13280         struct cmd_tx_loopback_result *res = parsed_result;
13281         int ret = -ENOTSUP;
13282
13283         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13284
13285         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13286                 return;
13287
13288 #ifdef RTE_LIBRTE_IXGBE_PMD
13289         if (ret == -ENOTSUP)
13290                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13291 #endif
13292 #ifdef RTE_LIBRTE_I40E_PMD
13293         if (ret == -ENOTSUP)
13294                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13295 #endif
13296 #ifdef RTE_LIBRTE_BNXT_PMD
13297         if (ret == -ENOTSUP)
13298                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13299 #endif
13300 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13301         if (ret == -ENOTSUP)
13302                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13303 #endif
13304
13305         switch (ret) {
13306         case 0:
13307                 break;
13308         case -EINVAL:
13309                 printf("invalid is_on %d\n", is_on);
13310                 break;
13311         case -ENODEV:
13312                 printf("invalid port_id %d\n", res->port_id);
13313                 break;
13314         case -ENOTSUP:
13315                 printf("function not implemented\n");
13316                 break;
13317         default:
13318                 printf("programming error: (%s)\n", strerror(-ret));
13319         }
13320 }
13321
13322 cmdline_parse_inst_t cmd_set_tx_loopback = {
13323         .f = cmd_set_tx_loopback_parsed,
13324         .data = NULL,
13325         .help_str = "set tx loopback <port_id> on|off",
13326         .tokens = {
13327                 (void *)&cmd_tx_loopback_set,
13328                 (void *)&cmd_tx_loopback_tx,
13329                 (void *)&cmd_tx_loopback_loopback,
13330                 (void *)&cmd_tx_loopback_port_id,
13331                 (void *)&cmd_tx_loopback_on_off,
13332                 NULL,
13333         },
13334 };
13335
13336 /* all queues drop enable configuration */
13337
13338 /* Common result structure for all queues drop enable */
13339 struct cmd_all_queues_drop_en_result {
13340         cmdline_fixed_string_t set;
13341         cmdline_fixed_string_t all;
13342         cmdline_fixed_string_t queues;
13343         cmdline_fixed_string_t drop;
13344         portid_t port_id;
13345         cmdline_fixed_string_t on_off;
13346 };
13347
13348 /* Common CLI fields for tx loopback enable disable */
13349 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13350         TOKEN_STRING_INITIALIZER
13351                 (struct cmd_all_queues_drop_en_result,
13352                  set, "set");
13353 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13354         TOKEN_STRING_INITIALIZER
13355                 (struct cmd_all_queues_drop_en_result,
13356                  all, "all");
13357 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13358         TOKEN_STRING_INITIALIZER
13359                 (struct cmd_all_queues_drop_en_result,
13360                  queues, "queues");
13361 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13362         TOKEN_STRING_INITIALIZER
13363                 (struct cmd_all_queues_drop_en_result,
13364                  drop, "drop");
13365 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13366         TOKEN_NUM_INITIALIZER
13367                 (struct cmd_all_queues_drop_en_result,
13368                  port_id, UINT16);
13369 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13370         TOKEN_STRING_INITIALIZER
13371                 (struct cmd_all_queues_drop_en_result,
13372                  on_off, "on#off");
13373
13374 static void
13375 cmd_set_all_queues_drop_en_parsed(
13376         void *parsed_result,
13377         __attribute__((unused)) struct cmdline *cl,
13378         __attribute__((unused)) void *data)
13379 {
13380         struct cmd_all_queues_drop_en_result *res = parsed_result;
13381         int ret = -ENOTSUP;
13382         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13383
13384         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13385                 return;
13386
13387 #ifdef RTE_LIBRTE_IXGBE_PMD
13388         if (ret == -ENOTSUP)
13389                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13390 #endif
13391 #ifdef RTE_LIBRTE_BNXT_PMD
13392         if (ret == -ENOTSUP)
13393                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13394 #endif
13395         switch (ret) {
13396         case 0:
13397                 break;
13398         case -EINVAL:
13399                 printf("invalid is_on %d\n", is_on);
13400                 break;
13401         case -ENODEV:
13402                 printf("invalid port_id %d\n", res->port_id);
13403                 break;
13404         case -ENOTSUP:
13405                 printf("function not implemented\n");
13406                 break;
13407         default:
13408                 printf("programming error: (%s)\n", strerror(-ret));
13409         }
13410 }
13411
13412 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13413         .f = cmd_set_all_queues_drop_en_parsed,
13414         .data = NULL,
13415         .help_str = "set all queues drop <port_id> on|off",
13416         .tokens = {
13417                 (void *)&cmd_all_queues_drop_en_set,
13418                 (void *)&cmd_all_queues_drop_en_all,
13419                 (void *)&cmd_all_queues_drop_en_queues,
13420                 (void *)&cmd_all_queues_drop_en_drop,
13421                 (void *)&cmd_all_queues_drop_en_port_id,
13422                 (void *)&cmd_all_queues_drop_en_on_off,
13423                 NULL,
13424         },
13425 };
13426
13427 /* vf split drop enable configuration */
13428
13429 /* Common result structure for vf split drop enable */
13430 struct cmd_vf_split_drop_en_result {
13431         cmdline_fixed_string_t set;
13432         cmdline_fixed_string_t vf;
13433         cmdline_fixed_string_t split;
13434         cmdline_fixed_string_t drop;
13435         portid_t port_id;
13436         uint16_t vf_id;
13437         cmdline_fixed_string_t on_off;
13438 };
13439
13440 /* Common CLI fields for vf split drop enable disable */
13441 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13442         TOKEN_STRING_INITIALIZER
13443                 (struct cmd_vf_split_drop_en_result,
13444                  set, "set");
13445 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13446         TOKEN_STRING_INITIALIZER
13447                 (struct cmd_vf_split_drop_en_result,
13448                  vf, "vf");
13449 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13450         TOKEN_STRING_INITIALIZER
13451                 (struct cmd_vf_split_drop_en_result,
13452                  split, "split");
13453 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13454         TOKEN_STRING_INITIALIZER
13455                 (struct cmd_vf_split_drop_en_result,
13456                  drop, "drop");
13457 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13458         TOKEN_NUM_INITIALIZER
13459                 (struct cmd_vf_split_drop_en_result,
13460                  port_id, UINT16);
13461 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13462         TOKEN_NUM_INITIALIZER
13463                 (struct cmd_vf_split_drop_en_result,
13464                  vf_id, UINT16);
13465 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13466         TOKEN_STRING_INITIALIZER
13467                 (struct cmd_vf_split_drop_en_result,
13468                  on_off, "on#off");
13469
13470 static void
13471 cmd_set_vf_split_drop_en_parsed(
13472         void *parsed_result,
13473         __attribute__((unused)) struct cmdline *cl,
13474         __attribute__((unused)) void *data)
13475 {
13476         struct cmd_vf_split_drop_en_result *res = parsed_result;
13477         int ret = -ENOTSUP;
13478         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13479
13480         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13481                 return;
13482
13483 #ifdef RTE_LIBRTE_IXGBE_PMD
13484         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13485                         is_on);
13486 #endif
13487         switch (ret) {
13488         case 0:
13489                 break;
13490         case -EINVAL:
13491                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13492                 break;
13493         case -ENODEV:
13494                 printf("invalid port_id %d\n", res->port_id);
13495                 break;
13496         case -ENOTSUP:
13497                 printf("not supported on port %d\n", res->port_id);
13498                 break;
13499         default:
13500                 printf("programming error: (%s)\n", strerror(-ret));
13501         }
13502 }
13503
13504 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13505         .f = cmd_set_vf_split_drop_en_parsed,
13506         .data = NULL,
13507         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13508         .tokens = {
13509                 (void *)&cmd_vf_split_drop_en_set,
13510                 (void *)&cmd_vf_split_drop_en_vf,
13511                 (void *)&cmd_vf_split_drop_en_split,
13512                 (void *)&cmd_vf_split_drop_en_drop,
13513                 (void *)&cmd_vf_split_drop_en_port_id,
13514                 (void *)&cmd_vf_split_drop_en_vf_id,
13515                 (void *)&cmd_vf_split_drop_en_on_off,
13516                 NULL,
13517         },
13518 };
13519
13520 /* vf mac address configuration */
13521
13522 /* Common result structure for vf mac address */
13523 struct cmd_set_vf_mac_addr_result {
13524         cmdline_fixed_string_t set;
13525         cmdline_fixed_string_t vf;
13526         cmdline_fixed_string_t mac;
13527         cmdline_fixed_string_t addr;
13528         portid_t port_id;
13529         uint16_t vf_id;
13530         struct ether_addr mac_addr;
13531
13532 };
13533
13534 /* Common CLI fields for vf split drop enable disable */
13535 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13536         TOKEN_STRING_INITIALIZER
13537                 (struct cmd_set_vf_mac_addr_result,
13538                  set, "set");
13539 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13540         TOKEN_STRING_INITIALIZER
13541                 (struct cmd_set_vf_mac_addr_result,
13542                  vf, "vf");
13543 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13544         TOKEN_STRING_INITIALIZER
13545                 (struct cmd_set_vf_mac_addr_result,
13546                  mac, "mac");
13547 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13548         TOKEN_STRING_INITIALIZER
13549                 (struct cmd_set_vf_mac_addr_result,
13550                  addr, "addr");
13551 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13552         TOKEN_NUM_INITIALIZER
13553                 (struct cmd_set_vf_mac_addr_result,
13554                  port_id, UINT16);
13555 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13556         TOKEN_NUM_INITIALIZER
13557                 (struct cmd_set_vf_mac_addr_result,
13558                  vf_id, UINT16);
13559 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13560         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13561                  mac_addr);
13562
13563 static void
13564 cmd_set_vf_mac_addr_parsed(
13565         void *parsed_result,
13566         __attribute__((unused)) struct cmdline *cl,
13567         __attribute__((unused)) void *data)
13568 {
13569         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13570         int ret = -ENOTSUP;
13571
13572         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13573                 return;
13574
13575 #ifdef RTE_LIBRTE_IXGBE_PMD
13576         if (ret == -ENOTSUP)
13577                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13578                                 &res->mac_addr);
13579 #endif
13580 #ifdef RTE_LIBRTE_I40E_PMD
13581         if (ret == -ENOTSUP)
13582                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13583                                 &res->mac_addr);
13584 #endif
13585 #ifdef RTE_LIBRTE_BNXT_PMD
13586         if (ret == -ENOTSUP)
13587                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13588                                 &res->mac_addr);
13589 #endif
13590
13591         switch (ret) {
13592         case 0:
13593                 break;
13594         case -EINVAL:
13595                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13596                 break;
13597         case -ENODEV:
13598                 printf("invalid port_id %d\n", res->port_id);
13599                 break;
13600         case -ENOTSUP:
13601                 printf("function not implemented\n");
13602                 break;
13603         default:
13604                 printf("programming error: (%s)\n", strerror(-ret));
13605         }
13606 }
13607
13608 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13609         .f = cmd_set_vf_mac_addr_parsed,
13610         .data = NULL,
13611         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13612         .tokens = {
13613                 (void *)&cmd_set_vf_mac_addr_set,
13614                 (void *)&cmd_set_vf_mac_addr_vf,
13615                 (void *)&cmd_set_vf_mac_addr_mac,
13616                 (void *)&cmd_set_vf_mac_addr_addr,
13617                 (void *)&cmd_set_vf_mac_addr_port_id,
13618                 (void *)&cmd_set_vf_mac_addr_vf_id,
13619                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13620                 NULL,
13621         },
13622 };
13623
13624 /* MACsec configuration */
13625
13626 /* Common result structure for MACsec offload enable */
13627 struct cmd_macsec_offload_on_result {
13628         cmdline_fixed_string_t set;
13629         cmdline_fixed_string_t macsec;
13630         cmdline_fixed_string_t offload;
13631         portid_t port_id;
13632         cmdline_fixed_string_t on;
13633         cmdline_fixed_string_t encrypt;
13634         cmdline_fixed_string_t en_on_off;
13635         cmdline_fixed_string_t replay_protect;
13636         cmdline_fixed_string_t rp_on_off;
13637 };
13638
13639 /* Common CLI fields for MACsec offload disable */
13640 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13641         TOKEN_STRING_INITIALIZER
13642                 (struct cmd_macsec_offload_on_result,
13643                  set, "set");
13644 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13645         TOKEN_STRING_INITIALIZER
13646                 (struct cmd_macsec_offload_on_result,
13647                  macsec, "macsec");
13648 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13649         TOKEN_STRING_INITIALIZER
13650                 (struct cmd_macsec_offload_on_result,
13651                  offload, "offload");
13652 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13653         TOKEN_NUM_INITIALIZER
13654                 (struct cmd_macsec_offload_on_result,
13655                  port_id, UINT16);
13656 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13657         TOKEN_STRING_INITIALIZER
13658                 (struct cmd_macsec_offload_on_result,
13659                  on, "on");
13660 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13661         TOKEN_STRING_INITIALIZER
13662                 (struct cmd_macsec_offload_on_result,
13663                  encrypt, "encrypt");
13664 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13665         TOKEN_STRING_INITIALIZER
13666                 (struct cmd_macsec_offload_on_result,
13667                  en_on_off, "on#off");
13668 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13669         TOKEN_STRING_INITIALIZER
13670                 (struct cmd_macsec_offload_on_result,
13671                  replay_protect, "replay-protect");
13672 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13673         TOKEN_STRING_INITIALIZER
13674                 (struct cmd_macsec_offload_on_result,
13675                  rp_on_off, "on#off");
13676
13677 static void
13678 cmd_set_macsec_offload_on_parsed(
13679         void *parsed_result,
13680         __attribute__((unused)) struct cmdline *cl,
13681         __attribute__((unused)) void *data)
13682 {
13683         struct cmd_macsec_offload_on_result *res = parsed_result;
13684         int ret = -ENOTSUP;
13685         portid_t port_id = res->port_id;
13686         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13687         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13688         struct rte_eth_dev_info dev_info;
13689
13690         if (port_id_is_invalid(port_id, ENABLED_WARN))
13691                 return;
13692         if (!port_is_stopped(port_id)) {
13693                 printf("Please stop port %d first\n", port_id);
13694                 return;
13695         }
13696
13697         rte_eth_dev_info_get(port_id, &dev_info);
13698         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13699 #ifdef RTE_LIBRTE_IXGBE_PMD
13700                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13701 #endif
13702         }
13703         RTE_SET_USED(en);
13704         RTE_SET_USED(rp);
13705
13706         switch (ret) {
13707         case 0:
13708                 ports[port_id].dev_conf.txmode.offloads |=
13709                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13710                 cmd_reconfig_device_queue(port_id, 1, 1);
13711                 break;
13712         case -ENODEV:
13713                 printf("invalid port_id %d\n", port_id);
13714                 break;
13715         case -ENOTSUP:
13716                 printf("not supported on port %d\n", port_id);
13717                 break;
13718         default:
13719                 printf("programming error: (%s)\n", strerror(-ret));
13720         }
13721 }
13722
13723 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13724         .f = cmd_set_macsec_offload_on_parsed,
13725         .data = NULL,
13726         .help_str = "set macsec offload <port_id> on "
13727                 "encrypt on|off replay-protect on|off",
13728         .tokens = {
13729                 (void *)&cmd_macsec_offload_on_set,
13730                 (void *)&cmd_macsec_offload_on_macsec,
13731                 (void *)&cmd_macsec_offload_on_offload,
13732                 (void *)&cmd_macsec_offload_on_port_id,
13733                 (void *)&cmd_macsec_offload_on_on,
13734                 (void *)&cmd_macsec_offload_on_encrypt,
13735                 (void *)&cmd_macsec_offload_on_en_on_off,
13736                 (void *)&cmd_macsec_offload_on_replay_protect,
13737                 (void *)&cmd_macsec_offload_on_rp_on_off,
13738                 NULL,
13739         },
13740 };
13741
13742 /* Common result structure for MACsec offload disable */
13743 struct cmd_macsec_offload_off_result {
13744         cmdline_fixed_string_t set;
13745         cmdline_fixed_string_t macsec;
13746         cmdline_fixed_string_t offload;
13747         portid_t port_id;
13748         cmdline_fixed_string_t off;
13749 };
13750
13751 /* Common CLI fields for MACsec offload disable */
13752 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13753         TOKEN_STRING_INITIALIZER
13754                 (struct cmd_macsec_offload_off_result,
13755                  set, "set");
13756 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13757         TOKEN_STRING_INITIALIZER
13758                 (struct cmd_macsec_offload_off_result,
13759                  macsec, "macsec");
13760 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13761         TOKEN_STRING_INITIALIZER
13762                 (struct cmd_macsec_offload_off_result,
13763                  offload, "offload");
13764 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13765         TOKEN_NUM_INITIALIZER
13766                 (struct cmd_macsec_offload_off_result,
13767                  port_id, UINT16);
13768 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13769         TOKEN_STRING_INITIALIZER
13770                 (struct cmd_macsec_offload_off_result,
13771                  off, "off");
13772
13773 static void
13774 cmd_set_macsec_offload_off_parsed(
13775         void *parsed_result,
13776         __attribute__((unused)) struct cmdline *cl,
13777         __attribute__((unused)) void *data)
13778 {
13779         struct cmd_macsec_offload_off_result *res = parsed_result;
13780         int ret = -ENOTSUP;
13781         struct rte_eth_dev_info dev_info;
13782         portid_t port_id = res->port_id;
13783
13784         if (port_id_is_invalid(port_id, ENABLED_WARN))
13785                 return;
13786         if (!port_is_stopped(port_id)) {
13787                 printf("Please stop port %d first\n", port_id);
13788                 return;
13789         }
13790
13791         rte_eth_dev_info_get(port_id, &dev_info);
13792         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13793 #ifdef RTE_LIBRTE_IXGBE_PMD
13794                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13795 #endif
13796         }
13797         switch (ret) {
13798         case 0:
13799                 ports[port_id].dev_conf.txmode.offloads &=
13800                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13801                 cmd_reconfig_device_queue(port_id, 1, 1);
13802                 break;
13803         case -ENODEV:
13804                 printf("invalid port_id %d\n", port_id);
13805                 break;
13806         case -ENOTSUP:
13807                 printf("not supported on port %d\n", port_id);
13808                 break;
13809         default:
13810                 printf("programming error: (%s)\n", strerror(-ret));
13811         }
13812 }
13813
13814 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13815         .f = cmd_set_macsec_offload_off_parsed,
13816         .data = NULL,
13817         .help_str = "set macsec offload <port_id> off",
13818         .tokens = {
13819                 (void *)&cmd_macsec_offload_off_set,
13820                 (void *)&cmd_macsec_offload_off_macsec,
13821                 (void *)&cmd_macsec_offload_off_offload,
13822                 (void *)&cmd_macsec_offload_off_port_id,
13823                 (void *)&cmd_macsec_offload_off_off,
13824                 NULL,
13825         },
13826 };
13827
13828 /* Common result structure for MACsec secure connection configure */
13829 struct cmd_macsec_sc_result {
13830         cmdline_fixed_string_t set;
13831         cmdline_fixed_string_t macsec;
13832         cmdline_fixed_string_t sc;
13833         cmdline_fixed_string_t tx_rx;
13834         portid_t port_id;
13835         struct ether_addr mac;
13836         uint16_t pi;
13837 };
13838
13839 /* Common CLI fields for MACsec secure connection configure */
13840 cmdline_parse_token_string_t cmd_macsec_sc_set =
13841         TOKEN_STRING_INITIALIZER
13842                 (struct cmd_macsec_sc_result,
13843                  set, "set");
13844 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13845         TOKEN_STRING_INITIALIZER
13846                 (struct cmd_macsec_sc_result,
13847                  macsec, "macsec");
13848 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13849         TOKEN_STRING_INITIALIZER
13850                 (struct cmd_macsec_sc_result,
13851                  sc, "sc");
13852 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13853         TOKEN_STRING_INITIALIZER
13854                 (struct cmd_macsec_sc_result,
13855                  tx_rx, "tx#rx");
13856 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13857         TOKEN_NUM_INITIALIZER
13858                 (struct cmd_macsec_sc_result,
13859                  port_id, UINT16);
13860 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13861         TOKEN_ETHERADDR_INITIALIZER
13862                 (struct cmd_macsec_sc_result,
13863                  mac);
13864 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13865         TOKEN_NUM_INITIALIZER
13866                 (struct cmd_macsec_sc_result,
13867                  pi, UINT16);
13868
13869 static void
13870 cmd_set_macsec_sc_parsed(
13871         void *parsed_result,
13872         __attribute__((unused)) struct cmdline *cl,
13873         __attribute__((unused)) void *data)
13874 {
13875         struct cmd_macsec_sc_result *res = parsed_result;
13876         int ret = -ENOTSUP;
13877         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13878
13879 #ifdef RTE_LIBRTE_IXGBE_PMD
13880         ret = is_tx ?
13881                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13882                                 res->mac.addr_bytes) :
13883                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13884                                 res->mac.addr_bytes, res->pi);
13885 #endif
13886         RTE_SET_USED(is_tx);
13887
13888         switch (ret) {
13889         case 0:
13890                 break;
13891         case -ENODEV:
13892                 printf("invalid port_id %d\n", res->port_id);
13893                 break;
13894         case -ENOTSUP:
13895                 printf("not supported on port %d\n", res->port_id);
13896                 break;
13897         default:
13898                 printf("programming error: (%s)\n", strerror(-ret));
13899         }
13900 }
13901
13902 cmdline_parse_inst_t cmd_set_macsec_sc = {
13903         .f = cmd_set_macsec_sc_parsed,
13904         .data = NULL,
13905         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13906         .tokens = {
13907                 (void *)&cmd_macsec_sc_set,
13908                 (void *)&cmd_macsec_sc_macsec,
13909                 (void *)&cmd_macsec_sc_sc,
13910                 (void *)&cmd_macsec_sc_tx_rx,
13911                 (void *)&cmd_macsec_sc_port_id,
13912                 (void *)&cmd_macsec_sc_mac,
13913                 (void *)&cmd_macsec_sc_pi,
13914                 NULL,
13915         },
13916 };
13917
13918 /* Common result structure for MACsec secure connection configure */
13919 struct cmd_macsec_sa_result {
13920         cmdline_fixed_string_t set;
13921         cmdline_fixed_string_t macsec;
13922         cmdline_fixed_string_t sa;
13923         cmdline_fixed_string_t tx_rx;
13924         portid_t port_id;
13925         uint8_t idx;
13926         uint8_t an;
13927         uint32_t pn;
13928         cmdline_fixed_string_t key;
13929 };
13930
13931 /* Common CLI fields for MACsec secure connection configure */
13932 cmdline_parse_token_string_t cmd_macsec_sa_set =
13933         TOKEN_STRING_INITIALIZER
13934                 (struct cmd_macsec_sa_result,
13935                  set, "set");
13936 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13937         TOKEN_STRING_INITIALIZER
13938                 (struct cmd_macsec_sa_result,
13939                  macsec, "macsec");
13940 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13941         TOKEN_STRING_INITIALIZER
13942                 (struct cmd_macsec_sa_result,
13943                  sa, "sa");
13944 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13945         TOKEN_STRING_INITIALIZER
13946                 (struct cmd_macsec_sa_result,
13947                  tx_rx, "tx#rx");
13948 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13949         TOKEN_NUM_INITIALIZER
13950                 (struct cmd_macsec_sa_result,
13951                  port_id, UINT16);
13952 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13953         TOKEN_NUM_INITIALIZER
13954                 (struct cmd_macsec_sa_result,
13955                  idx, UINT8);
13956 cmdline_parse_token_num_t cmd_macsec_sa_an =
13957         TOKEN_NUM_INITIALIZER
13958                 (struct cmd_macsec_sa_result,
13959                  an, UINT8);
13960 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13961         TOKEN_NUM_INITIALIZER
13962                 (struct cmd_macsec_sa_result,
13963                  pn, UINT32);
13964 cmdline_parse_token_string_t cmd_macsec_sa_key =
13965         TOKEN_STRING_INITIALIZER
13966                 (struct cmd_macsec_sa_result,
13967                  key, NULL);
13968
13969 static void
13970 cmd_set_macsec_sa_parsed(
13971         void *parsed_result,
13972         __attribute__((unused)) struct cmdline *cl,
13973         __attribute__((unused)) void *data)
13974 {
13975         struct cmd_macsec_sa_result *res = parsed_result;
13976         int ret = -ENOTSUP;
13977         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13978         uint8_t key[16] = { 0 };
13979         uint8_t xdgt0;
13980         uint8_t xdgt1;
13981         int key_len;
13982         int i;
13983
13984         key_len = strlen(res->key) / 2;
13985         if (key_len > 16)
13986                 key_len = 16;
13987
13988         for (i = 0; i < key_len; i++) {
13989                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13990                 if (xdgt0 == 0xFF)
13991                         return;
13992                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13993                 if (xdgt1 == 0xFF)
13994                         return;
13995                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13996         }
13997
13998 #ifdef RTE_LIBRTE_IXGBE_PMD
13999         ret = is_tx ?
14000                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14001                         res->idx, res->an, res->pn, key) :
14002                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14003                         res->idx, res->an, res->pn, key);
14004 #endif
14005         RTE_SET_USED(is_tx);
14006         RTE_SET_USED(key);
14007
14008         switch (ret) {
14009         case 0:
14010                 break;
14011         case -EINVAL:
14012                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14013                 break;
14014         case -ENODEV:
14015                 printf("invalid port_id %d\n", res->port_id);
14016                 break;
14017         case -ENOTSUP:
14018                 printf("not supported on port %d\n", res->port_id);
14019                 break;
14020         default:
14021                 printf("programming error: (%s)\n", strerror(-ret));
14022         }
14023 }
14024
14025 cmdline_parse_inst_t cmd_set_macsec_sa = {
14026         .f = cmd_set_macsec_sa_parsed,
14027         .data = NULL,
14028         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14029         .tokens = {
14030                 (void *)&cmd_macsec_sa_set,
14031                 (void *)&cmd_macsec_sa_macsec,
14032                 (void *)&cmd_macsec_sa_sa,
14033                 (void *)&cmd_macsec_sa_tx_rx,
14034                 (void *)&cmd_macsec_sa_port_id,
14035                 (void *)&cmd_macsec_sa_idx,
14036                 (void *)&cmd_macsec_sa_an,
14037                 (void *)&cmd_macsec_sa_pn,
14038                 (void *)&cmd_macsec_sa_key,
14039                 NULL,
14040         },
14041 };
14042
14043 /* VF unicast promiscuous mode configuration */
14044
14045 /* Common result structure for VF unicast promiscuous mode */
14046 struct cmd_vf_promisc_result {
14047         cmdline_fixed_string_t set;
14048         cmdline_fixed_string_t vf;
14049         cmdline_fixed_string_t promisc;
14050         portid_t port_id;
14051         uint32_t vf_id;
14052         cmdline_fixed_string_t on_off;
14053 };
14054
14055 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14056 cmdline_parse_token_string_t cmd_vf_promisc_set =
14057         TOKEN_STRING_INITIALIZER
14058                 (struct cmd_vf_promisc_result,
14059                  set, "set");
14060 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14061         TOKEN_STRING_INITIALIZER
14062                 (struct cmd_vf_promisc_result,
14063                  vf, "vf");
14064 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14065         TOKEN_STRING_INITIALIZER
14066                 (struct cmd_vf_promisc_result,
14067                  promisc, "promisc");
14068 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14069         TOKEN_NUM_INITIALIZER
14070                 (struct cmd_vf_promisc_result,
14071                  port_id, UINT16);
14072 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14073         TOKEN_NUM_INITIALIZER
14074                 (struct cmd_vf_promisc_result,
14075                  vf_id, UINT32);
14076 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14077         TOKEN_STRING_INITIALIZER
14078                 (struct cmd_vf_promisc_result,
14079                  on_off, "on#off");
14080
14081 static void
14082 cmd_set_vf_promisc_parsed(
14083         void *parsed_result,
14084         __attribute__((unused)) struct cmdline *cl,
14085         __attribute__((unused)) void *data)
14086 {
14087         struct cmd_vf_promisc_result *res = parsed_result;
14088         int ret = -ENOTSUP;
14089
14090         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14091
14092         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14093                 return;
14094
14095 #ifdef RTE_LIBRTE_I40E_PMD
14096         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14097                                                   res->vf_id, is_on);
14098 #endif
14099
14100         switch (ret) {
14101         case 0:
14102                 break;
14103         case -EINVAL:
14104                 printf("invalid vf_id %d\n", res->vf_id);
14105                 break;
14106         case -ENODEV:
14107                 printf("invalid port_id %d\n", res->port_id);
14108                 break;
14109         case -ENOTSUP:
14110                 printf("function not implemented\n");
14111                 break;
14112         default:
14113                 printf("programming error: (%s)\n", strerror(-ret));
14114         }
14115 }
14116
14117 cmdline_parse_inst_t cmd_set_vf_promisc = {
14118         .f = cmd_set_vf_promisc_parsed,
14119         .data = NULL,
14120         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14121                 "Set unicast promiscuous mode for a VF from the PF",
14122         .tokens = {
14123                 (void *)&cmd_vf_promisc_set,
14124                 (void *)&cmd_vf_promisc_vf,
14125                 (void *)&cmd_vf_promisc_promisc,
14126                 (void *)&cmd_vf_promisc_port_id,
14127                 (void *)&cmd_vf_promisc_vf_id,
14128                 (void *)&cmd_vf_promisc_on_off,
14129                 NULL,
14130         },
14131 };
14132
14133 /* VF multicast promiscuous mode configuration */
14134
14135 /* Common result structure for VF multicast promiscuous mode */
14136 struct cmd_vf_allmulti_result {
14137         cmdline_fixed_string_t set;
14138         cmdline_fixed_string_t vf;
14139         cmdline_fixed_string_t allmulti;
14140         portid_t port_id;
14141         uint32_t vf_id;
14142         cmdline_fixed_string_t on_off;
14143 };
14144
14145 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14146 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14147         TOKEN_STRING_INITIALIZER
14148                 (struct cmd_vf_allmulti_result,
14149                  set, "set");
14150 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14151         TOKEN_STRING_INITIALIZER
14152                 (struct cmd_vf_allmulti_result,
14153                  vf, "vf");
14154 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14155         TOKEN_STRING_INITIALIZER
14156                 (struct cmd_vf_allmulti_result,
14157                  allmulti, "allmulti");
14158 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14159         TOKEN_NUM_INITIALIZER
14160                 (struct cmd_vf_allmulti_result,
14161                  port_id, UINT16);
14162 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14163         TOKEN_NUM_INITIALIZER
14164                 (struct cmd_vf_allmulti_result,
14165                  vf_id, UINT32);
14166 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14167         TOKEN_STRING_INITIALIZER
14168                 (struct cmd_vf_allmulti_result,
14169                  on_off, "on#off");
14170
14171 static void
14172 cmd_set_vf_allmulti_parsed(
14173         void *parsed_result,
14174         __attribute__((unused)) struct cmdline *cl,
14175         __attribute__((unused)) void *data)
14176 {
14177         struct cmd_vf_allmulti_result *res = parsed_result;
14178         int ret = -ENOTSUP;
14179
14180         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14181
14182         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14183                 return;
14184
14185 #ifdef RTE_LIBRTE_I40E_PMD
14186         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14187                                                     res->vf_id, is_on);
14188 #endif
14189
14190         switch (ret) {
14191         case 0:
14192                 break;
14193         case -EINVAL:
14194                 printf("invalid vf_id %d\n", res->vf_id);
14195                 break;
14196         case -ENODEV:
14197                 printf("invalid port_id %d\n", res->port_id);
14198                 break;
14199         case -ENOTSUP:
14200                 printf("function not implemented\n");
14201                 break;
14202         default:
14203                 printf("programming error: (%s)\n", strerror(-ret));
14204         }
14205 }
14206
14207 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14208         .f = cmd_set_vf_allmulti_parsed,
14209         .data = NULL,
14210         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14211                 "Set multicast promiscuous mode for a VF from the PF",
14212         .tokens = {
14213                 (void *)&cmd_vf_allmulti_set,
14214                 (void *)&cmd_vf_allmulti_vf,
14215                 (void *)&cmd_vf_allmulti_allmulti,
14216                 (void *)&cmd_vf_allmulti_port_id,
14217                 (void *)&cmd_vf_allmulti_vf_id,
14218                 (void *)&cmd_vf_allmulti_on_off,
14219                 NULL,
14220         },
14221 };
14222
14223 /* vf broadcast mode configuration */
14224
14225 /* Common result structure for vf broadcast */
14226 struct cmd_set_vf_broadcast_result {
14227         cmdline_fixed_string_t set;
14228         cmdline_fixed_string_t vf;
14229         cmdline_fixed_string_t broadcast;
14230         portid_t port_id;
14231         uint16_t vf_id;
14232         cmdline_fixed_string_t on_off;
14233 };
14234
14235 /* Common CLI fields for vf broadcast enable disable */
14236 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14237         TOKEN_STRING_INITIALIZER
14238                 (struct cmd_set_vf_broadcast_result,
14239                  set, "set");
14240 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14241         TOKEN_STRING_INITIALIZER
14242                 (struct cmd_set_vf_broadcast_result,
14243                  vf, "vf");
14244 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14245         TOKEN_STRING_INITIALIZER
14246                 (struct cmd_set_vf_broadcast_result,
14247                  broadcast, "broadcast");
14248 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14249         TOKEN_NUM_INITIALIZER
14250                 (struct cmd_set_vf_broadcast_result,
14251                  port_id, UINT16);
14252 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14253         TOKEN_NUM_INITIALIZER
14254                 (struct cmd_set_vf_broadcast_result,
14255                  vf_id, UINT16);
14256 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14257         TOKEN_STRING_INITIALIZER
14258                 (struct cmd_set_vf_broadcast_result,
14259                  on_off, "on#off");
14260
14261 static void
14262 cmd_set_vf_broadcast_parsed(
14263         void *parsed_result,
14264         __attribute__((unused)) struct cmdline *cl,
14265         __attribute__((unused)) void *data)
14266 {
14267         struct cmd_set_vf_broadcast_result *res = parsed_result;
14268         int ret = -ENOTSUP;
14269
14270         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14271
14272         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14273                 return;
14274
14275 #ifdef RTE_LIBRTE_I40E_PMD
14276         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14277                                             res->vf_id, is_on);
14278 #endif
14279
14280         switch (ret) {
14281         case 0:
14282                 break;
14283         case -EINVAL:
14284                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14285                 break;
14286         case -ENODEV:
14287                 printf("invalid port_id %d\n", res->port_id);
14288                 break;
14289         case -ENOTSUP:
14290                 printf("function not implemented\n");
14291                 break;
14292         default:
14293                 printf("programming error: (%s)\n", strerror(-ret));
14294         }
14295 }
14296
14297 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14298         .f = cmd_set_vf_broadcast_parsed,
14299         .data = NULL,
14300         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14301         .tokens = {
14302                 (void *)&cmd_set_vf_broadcast_set,
14303                 (void *)&cmd_set_vf_broadcast_vf,
14304                 (void *)&cmd_set_vf_broadcast_broadcast,
14305                 (void *)&cmd_set_vf_broadcast_port_id,
14306                 (void *)&cmd_set_vf_broadcast_vf_id,
14307                 (void *)&cmd_set_vf_broadcast_on_off,
14308                 NULL,
14309         },
14310 };
14311
14312 /* vf vlan tag configuration */
14313
14314 /* Common result structure for vf vlan tag */
14315 struct cmd_set_vf_vlan_tag_result {
14316         cmdline_fixed_string_t set;
14317         cmdline_fixed_string_t vf;
14318         cmdline_fixed_string_t vlan;
14319         cmdline_fixed_string_t tag;
14320         portid_t port_id;
14321         uint16_t vf_id;
14322         cmdline_fixed_string_t on_off;
14323 };
14324
14325 /* Common CLI fields for vf vlan tag enable disable */
14326 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14327         TOKEN_STRING_INITIALIZER
14328                 (struct cmd_set_vf_vlan_tag_result,
14329                  set, "set");
14330 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14331         TOKEN_STRING_INITIALIZER
14332                 (struct cmd_set_vf_vlan_tag_result,
14333                  vf, "vf");
14334 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14335         TOKEN_STRING_INITIALIZER
14336                 (struct cmd_set_vf_vlan_tag_result,
14337                  vlan, "vlan");
14338 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14339         TOKEN_STRING_INITIALIZER
14340                 (struct cmd_set_vf_vlan_tag_result,
14341                  tag, "tag");
14342 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14343         TOKEN_NUM_INITIALIZER
14344                 (struct cmd_set_vf_vlan_tag_result,
14345                  port_id, UINT16);
14346 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14347         TOKEN_NUM_INITIALIZER
14348                 (struct cmd_set_vf_vlan_tag_result,
14349                  vf_id, UINT16);
14350 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14351         TOKEN_STRING_INITIALIZER
14352                 (struct cmd_set_vf_vlan_tag_result,
14353                  on_off, "on#off");
14354
14355 static void
14356 cmd_set_vf_vlan_tag_parsed(
14357         void *parsed_result,
14358         __attribute__((unused)) struct cmdline *cl,
14359         __attribute__((unused)) void *data)
14360 {
14361         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14362         int ret = -ENOTSUP;
14363
14364         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14365
14366         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14367                 return;
14368
14369 #ifdef RTE_LIBRTE_I40E_PMD
14370         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14371                                            res->vf_id, is_on);
14372 #endif
14373
14374         switch (ret) {
14375         case 0:
14376                 break;
14377         case -EINVAL:
14378                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14379                 break;
14380         case -ENODEV:
14381                 printf("invalid port_id %d\n", res->port_id);
14382                 break;
14383         case -ENOTSUP:
14384                 printf("function not implemented\n");
14385                 break;
14386         default:
14387                 printf("programming error: (%s)\n", strerror(-ret));
14388         }
14389 }
14390
14391 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14392         .f = cmd_set_vf_vlan_tag_parsed,
14393         .data = NULL,
14394         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14395         .tokens = {
14396                 (void *)&cmd_set_vf_vlan_tag_set,
14397                 (void *)&cmd_set_vf_vlan_tag_vf,
14398                 (void *)&cmd_set_vf_vlan_tag_vlan,
14399                 (void *)&cmd_set_vf_vlan_tag_tag,
14400                 (void *)&cmd_set_vf_vlan_tag_port_id,
14401                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14402                 (void *)&cmd_set_vf_vlan_tag_on_off,
14403                 NULL,
14404         },
14405 };
14406
14407 /* Common definition of VF and TC TX bandwidth configuration */
14408 struct cmd_vf_tc_bw_result {
14409         cmdline_fixed_string_t set;
14410         cmdline_fixed_string_t vf;
14411         cmdline_fixed_string_t tc;
14412         cmdline_fixed_string_t tx;
14413         cmdline_fixed_string_t min_bw;
14414         cmdline_fixed_string_t max_bw;
14415         cmdline_fixed_string_t strict_link_prio;
14416         portid_t port_id;
14417         uint16_t vf_id;
14418         uint8_t tc_no;
14419         uint32_t bw;
14420         cmdline_fixed_string_t bw_list;
14421         uint8_t tc_map;
14422 };
14423
14424 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14425         TOKEN_STRING_INITIALIZER
14426                 (struct cmd_vf_tc_bw_result,
14427                  set, "set");
14428 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14429         TOKEN_STRING_INITIALIZER
14430                 (struct cmd_vf_tc_bw_result,
14431                  vf, "vf");
14432 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14433         TOKEN_STRING_INITIALIZER
14434                 (struct cmd_vf_tc_bw_result,
14435                  tc, "tc");
14436 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14437         TOKEN_STRING_INITIALIZER
14438                 (struct cmd_vf_tc_bw_result,
14439                  tx, "tx");
14440 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14441         TOKEN_STRING_INITIALIZER
14442                 (struct cmd_vf_tc_bw_result,
14443                  strict_link_prio, "strict-link-priority");
14444 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14445         TOKEN_STRING_INITIALIZER
14446                 (struct cmd_vf_tc_bw_result,
14447                  min_bw, "min-bandwidth");
14448 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14449         TOKEN_STRING_INITIALIZER
14450                 (struct cmd_vf_tc_bw_result,
14451                  max_bw, "max-bandwidth");
14452 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14453         TOKEN_NUM_INITIALIZER
14454                 (struct cmd_vf_tc_bw_result,
14455                  port_id, UINT16);
14456 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14457         TOKEN_NUM_INITIALIZER
14458                 (struct cmd_vf_tc_bw_result,
14459                  vf_id, UINT16);
14460 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14461         TOKEN_NUM_INITIALIZER
14462                 (struct cmd_vf_tc_bw_result,
14463                  tc_no, UINT8);
14464 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14465         TOKEN_NUM_INITIALIZER
14466                 (struct cmd_vf_tc_bw_result,
14467                  bw, UINT32);
14468 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14469         TOKEN_STRING_INITIALIZER
14470                 (struct cmd_vf_tc_bw_result,
14471                  bw_list, NULL);
14472 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14473         TOKEN_NUM_INITIALIZER
14474                 (struct cmd_vf_tc_bw_result,
14475                  tc_map, UINT8);
14476
14477 /* VF max bandwidth setting */
14478 static void
14479 cmd_vf_max_bw_parsed(
14480         void *parsed_result,
14481         __attribute__((unused)) struct cmdline *cl,
14482         __attribute__((unused)) void *data)
14483 {
14484         struct cmd_vf_tc_bw_result *res = parsed_result;
14485         int ret = -ENOTSUP;
14486
14487         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14488                 return;
14489
14490 #ifdef RTE_LIBRTE_I40E_PMD
14491         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14492                                          res->vf_id, res->bw);
14493 #endif
14494
14495         switch (ret) {
14496         case 0:
14497                 break;
14498         case -EINVAL:
14499                 printf("invalid vf_id %d or bandwidth %d\n",
14500                        res->vf_id, res->bw);
14501                 break;
14502         case -ENODEV:
14503                 printf("invalid port_id %d\n", res->port_id);
14504                 break;
14505         case -ENOTSUP:
14506                 printf("function not implemented\n");
14507                 break;
14508         default:
14509                 printf("programming error: (%s)\n", strerror(-ret));
14510         }
14511 }
14512
14513 cmdline_parse_inst_t cmd_vf_max_bw = {
14514         .f = cmd_vf_max_bw_parsed,
14515         .data = NULL,
14516         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14517         .tokens = {
14518                 (void *)&cmd_vf_tc_bw_set,
14519                 (void *)&cmd_vf_tc_bw_vf,
14520                 (void *)&cmd_vf_tc_bw_tx,
14521                 (void *)&cmd_vf_tc_bw_max_bw,
14522                 (void *)&cmd_vf_tc_bw_port_id,
14523                 (void *)&cmd_vf_tc_bw_vf_id,
14524                 (void *)&cmd_vf_tc_bw_bw,
14525                 NULL,
14526         },
14527 };
14528
14529 static int
14530 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14531                            uint8_t *tc_num,
14532                            char *str)
14533 {
14534         uint32_t size;
14535         const char *p, *p0 = str;
14536         char s[256];
14537         char *end;
14538         char *str_fld[16];
14539         uint16_t i;
14540         int ret;
14541
14542         p = strchr(p0, '(');
14543         if (p == NULL) {
14544                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14545                 return -1;
14546         }
14547         p++;
14548         p0 = strchr(p, ')');
14549         if (p0 == NULL) {
14550                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14551                 return -1;
14552         }
14553         size = p0 - p;
14554         if (size >= sizeof(s)) {
14555                 printf("The string size exceeds the internal buffer size\n");
14556                 return -1;
14557         }
14558         snprintf(s, sizeof(s), "%.*s", size, p);
14559         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14560         if (ret <= 0) {
14561                 printf("Failed to get the bandwidth list. ");
14562                 return -1;
14563         }
14564         *tc_num = ret;
14565         for (i = 0; i < ret; i++)
14566                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14567
14568         return 0;
14569 }
14570
14571 /* TC min bandwidth setting */
14572 static void
14573 cmd_vf_tc_min_bw_parsed(
14574         void *parsed_result,
14575         __attribute__((unused)) struct cmdline *cl,
14576         __attribute__((unused)) void *data)
14577 {
14578         struct cmd_vf_tc_bw_result *res = parsed_result;
14579         uint8_t tc_num;
14580         uint8_t bw[16];
14581         int ret = -ENOTSUP;
14582
14583         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14584                 return;
14585
14586         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14587         if (ret)
14588                 return;
14589
14590 #ifdef RTE_LIBRTE_I40E_PMD
14591         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14592                                               tc_num, bw);
14593 #endif
14594
14595         switch (ret) {
14596         case 0:
14597                 break;
14598         case -EINVAL:
14599                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14600                 break;
14601         case -ENODEV:
14602                 printf("invalid port_id %d\n", res->port_id);
14603                 break;
14604         case -ENOTSUP:
14605                 printf("function not implemented\n");
14606                 break;
14607         default:
14608                 printf("programming error: (%s)\n", strerror(-ret));
14609         }
14610 }
14611
14612 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14613         .f = cmd_vf_tc_min_bw_parsed,
14614         .data = NULL,
14615         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14616                     " <bw1, bw2, ...>",
14617         .tokens = {
14618                 (void *)&cmd_vf_tc_bw_set,
14619                 (void *)&cmd_vf_tc_bw_vf,
14620                 (void *)&cmd_vf_tc_bw_tc,
14621                 (void *)&cmd_vf_tc_bw_tx,
14622                 (void *)&cmd_vf_tc_bw_min_bw,
14623                 (void *)&cmd_vf_tc_bw_port_id,
14624                 (void *)&cmd_vf_tc_bw_vf_id,
14625                 (void *)&cmd_vf_tc_bw_bw_list,
14626                 NULL,
14627         },
14628 };
14629
14630 static void
14631 cmd_tc_min_bw_parsed(
14632         void *parsed_result,
14633         __attribute__((unused)) struct cmdline *cl,
14634         __attribute__((unused)) void *data)
14635 {
14636         struct cmd_vf_tc_bw_result *res = parsed_result;
14637         struct rte_port *port;
14638         uint8_t tc_num;
14639         uint8_t bw[16];
14640         int ret = -ENOTSUP;
14641
14642         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14643                 return;
14644
14645         port = &ports[res->port_id];
14646         /** Check if the port is not started **/
14647         if (port->port_status != RTE_PORT_STOPPED) {
14648                 printf("Please stop port %d first\n", res->port_id);
14649                 return;
14650         }
14651
14652         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14653         if (ret)
14654                 return;
14655
14656 #ifdef RTE_LIBRTE_IXGBE_PMD
14657         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14658 #endif
14659
14660         switch (ret) {
14661         case 0:
14662                 break;
14663         case -EINVAL:
14664                 printf("invalid bandwidth\n");
14665                 break;
14666         case -ENODEV:
14667                 printf("invalid port_id %d\n", res->port_id);
14668                 break;
14669         case -ENOTSUP:
14670                 printf("function not implemented\n");
14671                 break;
14672         default:
14673                 printf("programming error: (%s)\n", strerror(-ret));
14674         }
14675 }
14676
14677 cmdline_parse_inst_t cmd_tc_min_bw = {
14678         .f = cmd_tc_min_bw_parsed,
14679         .data = NULL,
14680         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14681         .tokens = {
14682                 (void *)&cmd_vf_tc_bw_set,
14683                 (void *)&cmd_vf_tc_bw_tc,
14684                 (void *)&cmd_vf_tc_bw_tx,
14685                 (void *)&cmd_vf_tc_bw_min_bw,
14686                 (void *)&cmd_vf_tc_bw_port_id,
14687                 (void *)&cmd_vf_tc_bw_bw_list,
14688                 NULL,
14689         },
14690 };
14691
14692 /* TC max bandwidth setting */
14693 static void
14694 cmd_vf_tc_max_bw_parsed(
14695         void *parsed_result,
14696         __attribute__((unused)) struct cmdline *cl,
14697         __attribute__((unused)) void *data)
14698 {
14699         struct cmd_vf_tc_bw_result *res = parsed_result;
14700         int ret = -ENOTSUP;
14701
14702         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14703                 return;
14704
14705 #ifdef RTE_LIBRTE_I40E_PMD
14706         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14707                                             res->tc_no, res->bw);
14708 #endif
14709
14710         switch (ret) {
14711         case 0:
14712                 break;
14713         case -EINVAL:
14714                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14715                        res->vf_id, res->tc_no, res->bw);
14716                 break;
14717         case -ENODEV:
14718                 printf("invalid port_id %d\n", res->port_id);
14719                 break;
14720         case -ENOTSUP:
14721                 printf("function not implemented\n");
14722                 break;
14723         default:
14724                 printf("programming error: (%s)\n", strerror(-ret));
14725         }
14726 }
14727
14728 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14729         .f = cmd_vf_tc_max_bw_parsed,
14730         .data = NULL,
14731         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14732                     " <bandwidth>",
14733         .tokens = {
14734                 (void *)&cmd_vf_tc_bw_set,
14735                 (void *)&cmd_vf_tc_bw_vf,
14736                 (void *)&cmd_vf_tc_bw_tc,
14737                 (void *)&cmd_vf_tc_bw_tx,
14738                 (void *)&cmd_vf_tc_bw_max_bw,
14739                 (void *)&cmd_vf_tc_bw_port_id,
14740                 (void *)&cmd_vf_tc_bw_vf_id,
14741                 (void *)&cmd_vf_tc_bw_tc_no,
14742                 (void *)&cmd_vf_tc_bw_bw,
14743                 NULL,
14744         },
14745 };
14746
14747
14748 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14749
14750 /* *** Set Port default Traffic Management Hierarchy *** */
14751 struct cmd_set_port_tm_hierarchy_default_result {
14752         cmdline_fixed_string_t set;
14753         cmdline_fixed_string_t port;
14754         cmdline_fixed_string_t tm;
14755         cmdline_fixed_string_t hierarchy;
14756         cmdline_fixed_string_t def;
14757         portid_t port_id;
14758 };
14759
14760 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14761         TOKEN_STRING_INITIALIZER(
14762                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14763 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14764         TOKEN_STRING_INITIALIZER(
14765                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14766 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14767         TOKEN_STRING_INITIALIZER(
14768                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14769 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14770         TOKEN_STRING_INITIALIZER(
14771                 struct cmd_set_port_tm_hierarchy_default_result,
14772                         hierarchy, "hierarchy");
14773 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14774         TOKEN_STRING_INITIALIZER(
14775                 struct cmd_set_port_tm_hierarchy_default_result,
14776                         def, "default");
14777 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14778         TOKEN_NUM_INITIALIZER(
14779                 struct cmd_set_port_tm_hierarchy_default_result,
14780                         port_id, UINT16);
14781
14782 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14783         __attribute__((unused)) struct cmdline *cl,
14784         __attribute__((unused)) void *data)
14785 {
14786         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14787         struct rte_port *p;
14788         portid_t port_id = res->port_id;
14789
14790         if (port_id_is_invalid(port_id, ENABLED_WARN))
14791                 return;
14792
14793         p = &ports[port_id];
14794
14795         /* Port tm flag */
14796         if (p->softport.tm_flag == 0) {
14797                 printf("  tm not enabled on port %u (error)\n", port_id);
14798                 return;
14799         }
14800
14801         /* Forward mode: tm */
14802         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14803                 printf("  tm mode not enabled(error)\n");
14804                 return;
14805         }
14806
14807         /* Set the default tm hierarchy */
14808         p->softport.tm.default_hierarchy_enable = 1;
14809 }
14810
14811 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14812         .f = cmd_set_port_tm_hierarchy_default_parsed,
14813         .data = NULL,
14814         .help_str = "set port tm hierarchy default <port_id>",
14815         .tokens = {
14816                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14817                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14818                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14819                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14820                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14821                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14822                 NULL,
14823         },
14824 };
14825 #endif
14826
14827 /* Strict link priority scheduling mode setting */
14828 static void
14829 cmd_strict_link_prio_parsed(
14830         void *parsed_result,
14831         __attribute__((unused)) struct cmdline *cl,
14832         __attribute__((unused)) void *data)
14833 {
14834         struct cmd_vf_tc_bw_result *res = parsed_result;
14835         int ret = -ENOTSUP;
14836
14837         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14838                 return;
14839
14840 #ifdef RTE_LIBRTE_I40E_PMD
14841         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14842 #endif
14843
14844         switch (ret) {
14845         case 0:
14846                 break;
14847         case -EINVAL:
14848                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14849                 break;
14850         case -ENODEV:
14851                 printf("invalid port_id %d\n", res->port_id);
14852                 break;
14853         case -ENOTSUP:
14854                 printf("function not implemented\n");
14855                 break;
14856         default:
14857                 printf("programming error: (%s)\n", strerror(-ret));
14858         }
14859 }
14860
14861 cmdline_parse_inst_t cmd_strict_link_prio = {
14862         .f = cmd_strict_link_prio_parsed,
14863         .data = NULL,
14864         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14865         .tokens = {
14866                 (void *)&cmd_vf_tc_bw_set,
14867                 (void *)&cmd_vf_tc_bw_tx,
14868                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14869                 (void *)&cmd_vf_tc_bw_port_id,
14870                 (void *)&cmd_vf_tc_bw_tc_map,
14871                 NULL,
14872         },
14873 };
14874
14875 /* Load dynamic device personalization*/
14876 struct cmd_ddp_add_result {
14877         cmdline_fixed_string_t ddp;
14878         cmdline_fixed_string_t add;
14879         portid_t port_id;
14880         char filepath[];
14881 };
14882
14883 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14884         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14885 cmdline_parse_token_string_t cmd_ddp_add_add =
14886         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14887 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14888         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14889 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14890         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14891
14892 static void
14893 cmd_ddp_add_parsed(
14894         void *parsed_result,
14895         __attribute__((unused)) struct cmdline *cl,
14896         __attribute__((unused)) void *data)
14897 {
14898         struct cmd_ddp_add_result *res = parsed_result;
14899         uint8_t *buff;
14900         uint32_t size;
14901         char *filepath;
14902         char *file_fld[2];
14903         int file_num;
14904         int ret = -ENOTSUP;
14905
14906         if (!all_ports_stopped()) {
14907                 printf("Please stop all ports first\n");
14908                 return;
14909         }
14910
14911         filepath = strdup(res->filepath);
14912         if (filepath == NULL) {
14913                 printf("Failed to allocate memory\n");
14914                 return;
14915         }
14916         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14917
14918         buff = open_file(file_fld[0], &size);
14919         if (!buff) {
14920                 free((void *)filepath);
14921                 return;
14922         }
14923
14924 #ifdef RTE_LIBRTE_I40E_PMD
14925         if (ret == -ENOTSUP)
14926                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14927                                                buff, size,
14928                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14929 #endif
14930
14931         if (ret == -EEXIST)
14932                 printf("Profile has already existed.\n");
14933         else if (ret < 0)
14934                 printf("Failed to load profile.\n");
14935         else if (file_num == 2)
14936                 save_file(file_fld[1], buff, size);
14937
14938         close_file(buff);
14939         free((void *)filepath);
14940 }
14941
14942 cmdline_parse_inst_t cmd_ddp_add = {
14943         .f = cmd_ddp_add_parsed,
14944         .data = NULL,
14945         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14946         .tokens = {
14947                 (void *)&cmd_ddp_add_ddp,
14948                 (void *)&cmd_ddp_add_add,
14949                 (void *)&cmd_ddp_add_port_id,
14950                 (void *)&cmd_ddp_add_filepath,
14951                 NULL,
14952         },
14953 };
14954
14955 /* Delete dynamic device personalization*/
14956 struct cmd_ddp_del_result {
14957         cmdline_fixed_string_t ddp;
14958         cmdline_fixed_string_t del;
14959         portid_t port_id;
14960         char filepath[];
14961 };
14962
14963 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14964         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14965 cmdline_parse_token_string_t cmd_ddp_del_del =
14966         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14967 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14968         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14969 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14970         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14971
14972 static void
14973 cmd_ddp_del_parsed(
14974         void *parsed_result,
14975         __attribute__((unused)) struct cmdline *cl,
14976         __attribute__((unused)) void *data)
14977 {
14978         struct cmd_ddp_del_result *res = parsed_result;
14979         uint8_t *buff;
14980         uint32_t size;
14981         int ret = -ENOTSUP;
14982
14983         if (!all_ports_stopped()) {
14984                 printf("Please stop all ports first\n");
14985                 return;
14986         }
14987
14988         buff = open_file(res->filepath, &size);
14989         if (!buff)
14990                 return;
14991
14992 #ifdef RTE_LIBRTE_I40E_PMD
14993         if (ret == -ENOTSUP)
14994                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14995                                                buff, size,
14996                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14997 #endif
14998
14999         if (ret == -EACCES)
15000                 printf("Profile does not exist.\n");
15001         else if (ret < 0)
15002                 printf("Failed to delete profile.\n");
15003
15004         close_file(buff);
15005 }
15006
15007 cmdline_parse_inst_t cmd_ddp_del = {
15008         .f = cmd_ddp_del_parsed,
15009         .data = NULL,
15010         .help_str = "ddp del <port_id> <backup_profile_path>",
15011         .tokens = {
15012                 (void *)&cmd_ddp_del_ddp,
15013                 (void *)&cmd_ddp_del_del,
15014                 (void *)&cmd_ddp_del_port_id,
15015                 (void *)&cmd_ddp_del_filepath,
15016                 NULL,
15017         },
15018 };
15019
15020 /* Get dynamic device personalization profile info */
15021 struct cmd_ddp_info_result {
15022         cmdline_fixed_string_t ddp;
15023         cmdline_fixed_string_t get;
15024         cmdline_fixed_string_t info;
15025         char filepath[];
15026 };
15027
15028 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15029         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15030 cmdline_parse_token_string_t cmd_ddp_info_get =
15031         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15032 cmdline_parse_token_string_t cmd_ddp_info_info =
15033         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15034 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15035         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15036
15037 static void
15038 cmd_ddp_info_parsed(
15039         void *parsed_result,
15040         __attribute__((unused)) struct cmdline *cl,
15041         __attribute__((unused)) void *data)
15042 {
15043         struct cmd_ddp_info_result *res = parsed_result;
15044         uint8_t *pkg;
15045         uint32_t pkg_size;
15046         int ret = -ENOTSUP;
15047 #ifdef RTE_LIBRTE_I40E_PMD
15048         uint32_t i, j, n;
15049         uint8_t *buff;
15050         uint32_t buff_size = 0;
15051         struct rte_pmd_i40e_profile_info info;
15052         uint32_t dev_num = 0;
15053         struct rte_pmd_i40e_ddp_device_id *devs;
15054         uint32_t proto_num = 0;
15055         struct rte_pmd_i40e_proto_info *proto = NULL;
15056         uint32_t pctype_num = 0;
15057         struct rte_pmd_i40e_ptype_info *pctype;
15058         uint32_t ptype_num = 0;
15059         struct rte_pmd_i40e_ptype_info *ptype;
15060         uint8_t proto_id;
15061
15062 #endif
15063
15064         pkg = open_file(res->filepath, &pkg_size);
15065         if (!pkg)
15066                 return;
15067
15068 #ifdef RTE_LIBRTE_I40E_PMD
15069         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15070                                 (uint8_t *)&info, sizeof(info),
15071                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15072         if (!ret) {
15073                 printf("Global Track id:       0x%x\n", info.track_id);
15074                 printf("Global Version:        %d.%d.%d.%d\n",
15075                         info.version.major,
15076                         info.version.minor,
15077                         info.version.update,
15078                         info.version.draft);
15079                 printf("Global Package name:   %s\n\n", info.name);
15080         }
15081
15082         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15083                                 (uint8_t *)&info, sizeof(info),
15084                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15085         if (!ret) {
15086                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15087                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15088                         info.version.major,
15089                         info.version.minor,
15090                         info.version.update,
15091                         info.version.draft);
15092                 printf("i40e Profile name:     %s\n\n", info.name);
15093         }
15094
15095         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15096                                 (uint8_t *)&buff_size, sizeof(buff_size),
15097                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15098         if (!ret && buff_size) {
15099                 buff = (uint8_t *)malloc(buff_size);
15100                 if (buff) {
15101                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15102                                                 buff, buff_size,
15103                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15104                         if (!ret)
15105                                 printf("Package Notes:\n%s\n\n", buff);
15106                         free(buff);
15107                 }
15108         }
15109
15110         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15111                                 (uint8_t *)&dev_num, sizeof(dev_num),
15112                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15113         if (!ret && dev_num) {
15114                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15115                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15116                 if (devs) {
15117                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15118                                                 (uint8_t *)devs, buff_size,
15119                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15120                         if (!ret) {
15121                                 printf("List of supported devices:\n");
15122                                 for (i = 0; i < dev_num; i++) {
15123                                         printf("  %04X:%04X %04X:%04X\n",
15124                                                 devs[i].vendor_dev_id >> 16,
15125                                                 devs[i].vendor_dev_id & 0xFFFF,
15126                                                 devs[i].sub_vendor_dev_id >> 16,
15127                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15128                                 }
15129                                 printf("\n");
15130                         }
15131                         free(devs);
15132                 }
15133         }
15134
15135         /* get information about protocols and packet types */
15136         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15137                 (uint8_t *)&proto_num, sizeof(proto_num),
15138                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15139         if (ret || !proto_num)
15140                 goto no_print_return;
15141
15142         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15143         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15144         if (!proto)
15145                 goto no_print_return;
15146
15147         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15148                                         buff_size,
15149                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15150         if (!ret) {
15151                 printf("List of used protocols:\n");
15152                 for (i = 0; i < proto_num; i++)
15153                         printf("  %2u: %s\n", proto[i].proto_id,
15154                                proto[i].name);
15155                 printf("\n");
15156         }
15157         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15158                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15159                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15160         if (ret || !pctype_num)
15161                 goto no_print_pctypes;
15162
15163         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15164         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15165         if (!pctype)
15166                 goto no_print_pctypes;
15167
15168         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15169                                         buff_size,
15170                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15171         if (ret) {
15172                 free(pctype);
15173                 goto no_print_pctypes;
15174         }
15175
15176         printf("List of defined packet classification types:\n");
15177         for (i = 0; i < pctype_num; i++) {
15178                 printf("  %2u:", pctype[i].ptype_id);
15179                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15180                         proto_id = pctype[i].protocols[j];
15181                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15182                                 for (n = 0; n < proto_num; n++) {
15183                                         if (proto[n].proto_id == proto_id) {
15184                                                 printf(" %s", proto[n].name);
15185                                                 break;
15186                                         }
15187                                 }
15188                         }
15189                 }
15190                 printf("\n");
15191         }
15192         printf("\n");
15193         free(pctype);
15194
15195 no_print_pctypes:
15196
15197         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15198                                         sizeof(ptype_num),
15199                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15200         if (ret || !ptype_num)
15201                 goto no_print_return;
15202
15203         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15204         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15205         if (!ptype)
15206                 goto no_print_return;
15207
15208         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15209                                         buff_size,
15210                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15211         if (ret) {
15212                 free(ptype);
15213                 goto no_print_return;
15214         }
15215         printf("List of defined packet types:\n");
15216         for (i = 0; i < ptype_num; i++) {
15217                 printf("  %2u:", ptype[i].ptype_id);
15218                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15219                         proto_id = ptype[i].protocols[j];
15220                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15221                                 for (n = 0; n < proto_num; n++) {
15222                                         if (proto[n].proto_id == proto_id) {
15223                                                 printf(" %s", proto[n].name);
15224                                                 break;
15225                                         }
15226                                 }
15227                         }
15228                 }
15229                 printf("\n");
15230         }
15231         free(ptype);
15232         printf("\n");
15233
15234         ret = 0;
15235 no_print_return:
15236         if (proto)
15237                 free(proto);
15238 #endif
15239         if (ret == -ENOTSUP)
15240                 printf("Function not supported in PMD driver\n");
15241         close_file(pkg);
15242 }
15243
15244 cmdline_parse_inst_t cmd_ddp_get_info = {
15245         .f = cmd_ddp_info_parsed,
15246         .data = NULL,
15247         .help_str = "ddp get info <profile_path>",
15248         .tokens = {
15249                 (void *)&cmd_ddp_info_ddp,
15250                 (void *)&cmd_ddp_info_get,
15251                 (void *)&cmd_ddp_info_info,
15252                 (void *)&cmd_ddp_info_filepath,
15253                 NULL,
15254         },
15255 };
15256
15257 /* Get dynamic device personalization profile info list*/
15258 #define PROFILE_INFO_SIZE 48
15259 #define MAX_PROFILE_NUM 16
15260
15261 struct cmd_ddp_get_list_result {
15262         cmdline_fixed_string_t ddp;
15263         cmdline_fixed_string_t get;
15264         cmdline_fixed_string_t list;
15265         portid_t port_id;
15266 };
15267
15268 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15269         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15270 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15271         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15272 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15273         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15274 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15275         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15276
15277 static void
15278 cmd_ddp_get_list_parsed(
15279         __attribute__((unused)) void *parsed_result,
15280         __attribute__((unused)) struct cmdline *cl,
15281         __attribute__((unused)) void *data)
15282 {
15283 #ifdef RTE_LIBRTE_I40E_PMD
15284         struct cmd_ddp_get_list_result *res = parsed_result;
15285         struct rte_pmd_i40e_profile_list *p_list;
15286         struct rte_pmd_i40e_profile_info *p_info;
15287         uint32_t p_num;
15288         uint32_t size;
15289         uint32_t i;
15290 #endif
15291         int ret = -ENOTSUP;
15292
15293 #ifdef RTE_LIBRTE_I40E_PMD
15294         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15295         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15296         if (!p_list)
15297                 printf("%s: Failed to malloc buffer\n", __func__);
15298
15299         if (ret == -ENOTSUP)
15300                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15301                                                 (uint8_t *)p_list, size);
15302
15303         if (!ret) {
15304                 p_num = p_list->p_count;
15305                 printf("Profile number is: %d\n\n", p_num);
15306
15307                 for (i = 0; i < p_num; i++) {
15308                         p_info = &p_list->p_info[i];
15309                         printf("Profile %d:\n", i);
15310                         printf("Track id:     0x%x\n", p_info->track_id);
15311                         printf("Version:      %d.%d.%d.%d\n",
15312                                p_info->version.major,
15313                                p_info->version.minor,
15314                                p_info->version.update,
15315                                p_info->version.draft);
15316                         printf("Profile name: %s\n\n", p_info->name);
15317                 }
15318         }
15319
15320         free(p_list);
15321 #endif
15322
15323         if (ret < 0)
15324                 printf("Failed to get ddp list\n");
15325 }
15326
15327 cmdline_parse_inst_t cmd_ddp_get_list = {
15328         .f = cmd_ddp_get_list_parsed,
15329         .data = NULL,
15330         .help_str = "ddp get list <port_id>",
15331         .tokens = {
15332                 (void *)&cmd_ddp_get_list_ddp,
15333                 (void *)&cmd_ddp_get_list_get,
15334                 (void *)&cmd_ddp_get_list_list,
15335                 (void *)&cmd_ddp_get_list_port_id,
15336                 NULL,
15337         },
15338 };
15339
15340 /* Configure input set */
15341 struct cmd_cfg_input_set_result {
15342         cmdline_fixed_string_t port;
15343         cmdline_fixed_string_t cfg;
15344         portid_t port_id;
15345         cmdline_fixed_string_t pctype;
15346         uint8_t pctype_id;
15347         cmdline_fixed_string_t inset_type;
15348         cmdline_fixed_string_t opt;
15349         cmdline_fixed_string_t field;
15350         uint8_t field_idx;
15351 };
15352
15353 static void
15354 cmd_cfg_input_set_parsed(
15355         __attribute__((unused)) void *parsed_result,
15356         __attribute__((unused)) struct cmdline *cl,
15357         __attribute__((unused)) void *data)
15358 {
15359 #ifdef RTE_LIBRTE_I40E_PMD
15360         struct cmd_cfg_input_set_result *res = parsed_result;
15361         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15362         struct rte_pmd_i40e_inset inset;
15363 #endif
15364         int ret = -ENOTSUP;
15365
15366         if (!all_ports_stopped()) {
15367                 printf("Please stop all ports first\n");
15368                 return;
15369         }
15370
15371 #ifdef RTE_LIBRTE_I40E_PMD
15372         if (!strcmp(res->inset_type, "hash_inset"))
15373                 inset_type = INSET_HASH;
15374         else if (!strcmp(res->inset_type, "fdir_inset"))
15375                 inset_type = INSET_FDIR;
15376         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15377                 inset_type = INSET_FDIR_FLX;
15378         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15379                                      &inset, inset_type);
15380         if (ret) {
15381                 printf("Failed to get input set.\n");
15382                 return;
15383         }
15384
15385         if (!strcmp(res->opt, "get")) {
15386                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15387                                                    res->field_idx);
15388                 if (ret)
15389                         printf("Field index %d is enabled.\n", res->field_idx);
15390                 else
15391                         printf("Field index %d is disabled.\n", res->field_idx);
15392                 return;
15393         } else if (!strcmp(res->opt, "set"))
15394                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15395                                                    res->field_idx);
15396         else if (!strcmp(res->opt, "clear"))
15397                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15398                                                      res->field_idx);
15399         if (ret) {
15400                 printf("Failed to configure input set field.\n");
15401                 return;
15402         }
15403
15404         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15405                                      &inset, inset_type);
15406         if (ret) {
15407                 printf("Failed to set input set.\n");
15408                 return;
15409         }
15410 #endif
15411
15412         if (ret == -ENOTSUP)
15413                 printf("Function not supported\n");
15414 }
15415
15416 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15417         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15418                                  port, "port");
15419 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15420         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15421                                  cfg, "config");
15422 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15423         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15424                               port_id, UINT16);
15425 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15426         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15427                                  pctype, "pctype");
15428 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15429         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15430                               pctype_id, UINT8);
15431 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15432         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15433                                  inset_type,
15434                                  "hash_inset#fdir_inset#fdir_flx_inset");
15435 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15436         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15437                                  opt, "get#set#clear");
15438 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15439         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15440                                  field, "field");
15441 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15442         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15443                               field_idx, UINT8);
15444
15445 cmdline_parse_inst_t cmd_cfg_input_set = {
15446         .f = cmd_cfg_input_set_parsed,
15447         .data = NULL,
15448         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15449                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15450         .tokens = {
15451                 (void *)&cmd_cfg_input_set_port,
15452                 (void *)&cmd_cfg_input_set_cfg,
15453                 (void *)&cmd_cfg_input_set_port_id,
15454                 (void *)&cmd_cfg_input_set_pctype,
15455                 (void *)&cmd_cfg_input_set_pctype_id,
15456                 (void *)&cmd_cfg_input_set_inset_type,
15457                 (void *)&cmd_cfg_input_set_opt,
15458                 (void *)&cmd_cfg_input_set_field,
15459                 (void *)&cmd_cfg_input_set_field_idx,
15460                 NULL,
15461         },
15462 };
15463
15464 /* Clear input set */
15465 struct cmd_clear_input_set_result {
15466         cmdline_fixed_string_t port;
15467         cmdline_fixed_string_t cfg;
15468         portid_t port_id;
15469         cmdline_fixed_string_t pctype;
15470         uint8_t pctype_id;
15471         cmdline_fixed_string_t inset_type;
15472         cmdline_fixed_string_t clear;
15473         cmdline_fixed_string_t all;
15474 };
15475
15476 static void
15477 cmd_clear_input_set_parsed(
15478         __attribute__((unused)) void *parsed_result,
15479         __attribute__((unused)) struct cmdline *cl,
15480         __attribute__((unused)) void *data)
15481 {
15482 #ifdef RTE_LIBRTE_I40E_PMD
15483         struct cmd_clear_input_set_result *res = parsed_result;
15484         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15485         struct rte_pmd_i40e_inset inset;
15486 #endif
15487         int ret = -ENOTSUP;
15488
15489         if (!all_ports_stopped()) {
15490                 printf("Please stop all ports first\n");
15491                 return;
15492         }
15493
15494 #ifdef RTE_LIBRTE_I40E_PMD
15495         if (!strcmp(res->inset_type, "hash_inset"))
15496                 inset_type = INSET_HASH;
15497         else if (!strcmp(res->inset_type, "fdir_inset"))
15498                 inset_type = INSET_FDIR;
15499         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15500                 inset_type = INSET_FDIR_FLX;
15501
15502         memset(&inset, 0, sizeof(inset));
15503
15504         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15505                                      &inset, inset_type);
15506         if (ret) {
15507                 printf("Failed to clear input set.\n");
15508                 return;
15509         }
15510
15511 #endif
15512
15513         if (ret == -ENOTSUP)
15514                 printf("Function not supported\n");
15515 }
15516
15517 cmdline_parse_token_string_t cmd_clear_input_set_port =
15518         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15519                                  port, "port");
15520 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15521         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15522                                  cfg, "config");
15523 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15524         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15525                               port_id, UINT16);
15526 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15527         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15528                                  pctype, "pctype");
15529 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15530         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15531                               pctype_id, UINT8);
15532 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15533         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15534                                  inset_type,
15535                                  "hash_inset#fdir_inset#fdir_flx_inset");
15536 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15537         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15538                                  clear, "clear");
15539 cmdline_parse_token_string_t cmd_clear_input_set_all =
15540         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15541                                  all, "all");
15542
15543 cmdline_parse_inst_t cmd_clear_input_set = {
15544         .f = cmd_clear_input_set_parsed,
15545         .data = NULL,
15546         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15547                     "fdir_inset|fdir_flx_inset clear all",
15548         .tokens = {
15549                 (void *)&cmd_clear_input_set_port,
15550                 (void *)&cmd_clear_input_set_cfg,
15551                 (void *)&cmd_clear_input_set_port_id,
15552                 (void *)&cmd_clear_input_set_pctype,
15553                 (void *)&cmd_clear_input_set_pctype_id,
15554                 (void *)&cmd_clear_input_set_inset_type,
15555                 (void *)&cmd_clear_input_set_clear,
15556                 (void *)&cmd_clear_input_set_all,
15557                 NULL,
15558         },
15559 };
15560
15561 /* show vf stats */
15562
15563 /* Common result structure for show vf stats */
15564 struct cmd_show_vf_stats_result {
15565         cmdline_fixed_string_t show;
15566         cmdline_fixed_string_t vf;
15567         cmdline_fixed_string_t stats;
15568         portid_t port_id;
15569         uint16_t vf_id;
15570 };
15571
15572 /* Common CLI fields show vf stats*/
15573 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15574         TOKEN_STRING_INITIALIZER
15575                 (struct cmd_show_vf_stats_result,
15576                  show, "show");
15577 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15578         TOKEN_STRING_INITIALIZER
15579                 (struct cmd_show_vf_stats_result,
15580                  vf, "vf");
15581 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15582         TOKEN_STRING_INITIALIZER
15583                 (struct cmd_show_vf_stats_result,
15584                  stats, "stats");
15585 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15586         TOKEN_NUM_INITIALIZER
15587                 (struct cmd_show_vf_stats_result,
15588                  port_id, UINT16);
15589 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15590         TOKEN_NUM_INITIALIZER
15591                 (struct cmd_show_vf_stats_result,
15592                  vf_id, UINT16);
15593
15594 static void
15595 cmd_show_vf_stats_parsed(
15596         void *parsed_result,
15597         __attribute__((unused)) struct cmdline *cl,
15598         __attribute__((unused)) void *data)
15599 {
15600         struct cmd_show_vf_stats_result *res = parsed_result;
15601         struct rte_eth_stats stats;
15602         int ret = -ENOTSUP;
15603         static const char *nic_stats_border = "########################";
15604
15605         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15606                 return;
15607
15608         memset(&stats, 0, sizeof(stats));
15609
15610 #ifdef RTE_LIBRTE_I40E_PMD
15611         if (ret == -ENOTSUP)
15612                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15613                                                 res->vf_id,
15614                                                 &stats);
15615 #endif
15616 #ifdef RTE_LIBRTE_BNXT_PMD
15617         if (ret == -ENOTSUP)
15618                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15619                                                 res->vf_id,
15620                                                 &stats);
15621 #endif
15622
15623         switch (ret) {
15624         case 0:
15625                 break;
15626         case -EINVAL:
15627                 printf("invalid vf_id %d\n", res->vf_id);
15628                 break;
15629         case -ENODEV:
15630                 printf("invalid port_id %d\n", res->port_id);
15631                 break;
15632         case -ENOTSUP:
15633                 printf("function not implemented\n");
15634                 break;
15635         default:
15636                 printf("programming error: (%s)\n", strerror(-ret));
15637         }
15638
15639         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15640                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15641
15642         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15643                "%-"PRIu64"\n",
15644                stats.ipackets, stats.imissed, stats.ibytes);
15645         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15646         printf("  RX-nombuf:  %-10"PRIu64"\n",
15647                stats.rx_nombuf);
15648         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15649                "%-"PRIu64"\n",
15650                stats.opackets, stats.oerrors, stats.obytes);
15651
15652         printf("  %s############################%s\n",
15653                                nic_stats_border, nic_stats_border);
15654 }
15655
15656 cmdline_parse_inst_t cmd_show_vf_stats = {
15657         .f = cmd_show_vf_stats_parsed,
15658         .data = NULL,
15659         .help_str = "show vf stats <port_id> <vf_id>",
15660         .tokens = {
15661                 (void *)&cmd_show_vf_stats_show,
15662                 (void *)&cmd_show_vf_stats_vf,
15663                 (void *)&cmd_show_vf_stats_stats,
15664                 (void *)&cmd_show_vf_stats_port_id,
15665                 (void *)&cmd_show_vf_stats_vf_id,
15666                 NULL,
15667         },
15668 };
15669
15670 /* clear vf stats */
15671
15672 /* Common result structure for clear vf stats */
15673 struct cmd_clear_vf_stats_result {
15674         cmdline_fixed_string_t clear;
15675         cmdline_fixed_string_t vf;
15676         cmdline_fixed_string_t stats;
15677         portid_t port_id;
15678         uint16_t vf_id;
15679 };
15680
15681 /* Common CLI fields clear vf stats*/
15682 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15683         TOKEN_STRING_INITIALIZER
15684                 (struct cmd_clear_vf_stats_result,
15685                  clear, "clear");
15686 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15687         TOKEN_STRING_INITIALIZER
15688                 (struct cmd_clear_vf_stats_result,
15689                  vf, "vf");
15690 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15691         TOKEN_STRING_INITIALIZER
15692                 (struct cmd_clear_vf_stats_result,
15693                  stats, "stats");
15694 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15695         TOKEN_NUM_INITIALIZER
15696                 (struct cmd_clear_vf_stats_result,
15697                  port_id, UINT16);
15698 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15699         TOKEN_NUM_INITIALIZER
15700                 (struct cmd_clear_vf_stats_result,
15701                  vf_id, UINT16);
15702
15703 static void
15704 cmd_clear_vf_stats_parsed(
15705         void *parsed_result,
15706         __attribute__((unused)) struct cmdline *cl,
15707         __attribute__((unused)) void *data)
15708 {
15709         struct cmd_clear_vf_stats_result *res = parsed_result;
15710         int ret = -ENOTSUP;
15711
15712         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15713                 return;
15714
15715 #ifdef RTE_LIBRTE_I40E_PMD
15716         if (ret == -ENOTSUP)
15717                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15718                                                   res->vf_id);
15719 #endif
15720 #ifdef RTE_LIBRTE_BNXT_PMD
15721         if (ret == -ENOTSUP)
15722                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15723                                                   res->vf_id);
15724 #endif
15725
15726         switch (ret) {
15727         case 0:
15728                 break;
15729         case -EINVAL:
15730                 printf("invalid vf_id %d\n", res->vf_id);
15731                 break;
15732         case -ENODEV:
15733                 printf("invalid port_id %d\n", res->port_id);
15734                 break;
15735         case -ENOTSUP:
15736                 printf("function not implemented\n");
15737                 break;
15738         default:
15739                 printf("programming error: (%s)\n", strerror(-ret));
15740         }
15741 }
15742
15743 cmdline_parse_inst_t cmd_clear_vf_stats = {
15744         .f = cmd_clear_vf_stats_parsed,
15745         .data = NULL,
15746         .help_str = "clear vf stats <port_id> <vf_id>",
15747         .tokens = {
15748                 (void *)&cmd_clear_vf_stats_clear,
15749                 (void *)&cmd_clear_vf_stats_vf,
15750                 (void *)&cmd_clear_vf_stats_stats,
15751                 (void *)&cmd_clear_vf_stats_port_id,
15752                 (void *)&cmd_clear_vf_stats_vf_id,
15753                 NULL,
15754         },
15755 };
15756
15757 /* port config pctype mapping reset */
15758
15759 /* Common result structure for port config pctype mapping reset */
15760 struct cmd_pctype_mapping_reset_result {
15761         cmdline_fixed_string_t port;
15762         cmdline_fixed_string_t config;
15763         portid_t port_id;
15764         cmdline_fixed_string_t pctype;
15765         cmdline_fixed_string_t mapping;
15766         cmdline_fixed_string_t reset;
15767 };
15768
15769 /* Common CLI fields for port config pctype mapping reset*/
15770 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15771         TOKEN_STRING_INITIALIZER
15772                 (struct cmd_pctype_mapping_reset_result,
15773                  port, "port");
15774 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15775         TOKEN_STRING_INITIALIZER
15776                 (struct cmd_pctype_mapping_reset_result,
15777                  config, "config");
15778 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15779         TOKEN_NUM_INITIALIZER
15780                 (struct cmd_pctype_mapping_reset_result,
15781                  port_id, UINT16);
15782 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15783         TOKEN_STRING_INITIALIZER
15784                 (struct cmd_pctype_mapping_reset_result,
15785                  pctype, "pctype");
15786 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15787         TOKEN_STRING_INITIALIZER
15788                 (struct cmd_pctype_mapping_reset_result,
15789                  mapping, "mapping");
15790 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15791         TOKEN_STRING_INITIALIZER
15792                 (struct cmd_pctype_mapping_reset_result,
15793                  reset, "reset");
15794
15795 static void
15796 cmd_pctype_mapping_reset_parsed(
15797         void *parsed_result,
15798         __attribute__((unused)) struct cmdline *cl,
15799         __attribute__((unused)) void *data)
15800 {
15801         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15802         int ret = -ENOTSUP;
15803
15804         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15805                 return;
15806
15807 #ifdef RTE_LIBRTE_I40E_PMD
15808         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15809 #endif
15810
15811         switch (ret) {
15812         case 0:
15813                 break;
15814         case -ENODEV:
15815                 printf("invalid port_id %d\n", res->port_id);
15816                 break;
15817         case -ENOTSUP:
15818                 printf("function not implemented\n");
15819                 break;
15820         default:
15821                 printf("programming error: (%s)\n", strerror(-ret));
15822         }
15823 }
15824
15825 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15826         .f = cmd_pctype_mapping_reset_parsed,
15827         .data = NULL,
15828         .help_str = "port config <port_id> pctype mapping reset",
15829         .tokens = {
15830                 (void *)&cmd_pctype_mapping_reset_port,
15831                 (void *)&cmd_pctype_mapping_reset_config,
15832                 (void *)&cmd_pctype_mapping_reset_port_id,
15833                 (void *)&cmd_pctype_mapping_reset_pctype,
15834                 (void *)&cmd_pctype_mapping_reset_mapping,
15835                 (void *)&cmd_pctype_mapping_reset_reset,
15836                 NULL,
15837         },
15838 };
15839
15840 /* show port pctype mapping */
15841
15842 /* Common result structure for show port pctype mapping */
15843 struct cmd_pctype_mapping_get_result {
15844         cmdline_fixed_string_t show;
15845         cmdline_fixed_string_t port;
15846         portid_t port_id;
15847         cmdline_fixed_string_t pctype;
15848         cmdline_fixed_string_t mapping;
15849 };
15850
15851 /* Common CLI fields for pctype mapping get */
15852 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15853         TOKEN_STRING_INITIALIZER
15854                 (struct cmd_pctype_mapping_get_result,
15855                  show, "show");
15856 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15857         TOKEN_STRING_INITIALIZER
15858                 (struct cmd_pctype_mapping_get_result,
15859                  port, "port");
15860 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15861         TOKEN_NUM_INITIALIZER
15862                 (struct cmd_pctype_mapping_get_result,
15863                  port_id, UINT16);
15864 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15865         TOKEN_STRING_INITIALIZER
15866                 (struct cmd_pctype_mapping_get_result,
15867                  pctype, "pctype");
15868 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15869         TOKEN_STRING_INITIALIZER
15870                 (struct cmd_pctype_mapping_get_result,
15871                  mapping, "mapping");
15872
15873 static void
15874 cmd_pctype_mapping_get_parsed(
15875         void *parsed_result,
15876         __attribute__((unused)) struct cmdline *cl,
15877         __attribute__((unused)) void *data)
15878 {
15879         struct cmd_pctype_mapping_get_result *res = parsed_result;
15880         int ret = -ENOTSUP;
15881 #ifdef RTE_LIBRTE_I40E_PMD
15882         struct rte_pmd_i40e_flow_type_mapping
15883                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15884         int i, j, first_pctype;
15885 #endif
15886
15887         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15888                 return;
15889
15890 #ifdef RTE_LIBRTE_I40E_PMD
15891         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15892 #endif
15893
15894         switch (ret) {
15895         case 0:
15896                 break;
15897         case -ENODEV:
15898                 printf("invalid port_id %d\n", res->port_id);
15899                 return;
15900         case -ENOTSUP:
15901                 printf("function not implemented\n");
15902                 return;
15903         default:
15904                 printf("programming error: (%s)\n", strerror(-ret));
15905                 return;
15906         }
15907
15908 #ifdef RTE_LIBRTE_I40E_PMD
15909         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15910                 if (mapping[i].pctype != 0ULL) {
15911                         first_pctype = 1;
15912
15913                         printf("pctype: ");
15914                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15915                                 if (mapping[i].pctype & (1ULL << j)) {
15916                                         printf(first_pctype ?
15917                                                "%02d" : ",%02d", j);
15918                                         first_pctype = 0;
15919                                 }
15920                         }
15921                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15922                 }
15923         }
15924 #endif
15925 }
15926
15927 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15928         .f = cmd_pctype_mapping_get_parsed,
15929         .data = NULL,
15930         .help_str = "show port <port_id> pctype mapping",
15931         .tokens = {
15932                 (void *)&cmd_pctype_mapping_get_show,
15933                 (void *)&cmd_pctype_mapping_get_port,
15934                 (void *)&cmd_pctype_mapping_get_port_id,
15935                 (void *)&cmd_pctype_mapping_get_pctype,
15936                 (void *)&cmd_pctype_mapping_get_mapping,
15937                 NULL,
15938         },
15939 };
15940
15941 /* port config pctype mapping update */
15942
15943 /* Common result structure for port config pctype mapping update */
15944 struct cmd_pctype_mapping_update_result {
15945         cmdline_fixed_string_t port;
15946         cmdline_fixed_string_t config;
15947         portid_t port_id;
15948         cmdline_fixed_string_t pctype;
15949         cmdline_fixed_string_t mapping;
15950         cmdline_fixed_string_t update;
15951         cmdline_fixed_string_t pctype_list;
15952         uint16_t flow_type;
15953 };
15954
15955 /* Common CLI fields for pctype mapping update*/
15956 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15957         TOKEN_STRING_INITIALIZER
15958                 (struct cmd_pctype_mapping_update_result,
15959                  port, "port");
15960 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15961         TOKEN_STRING_INITIALIZER
15962                 (struct cmd_pctype_mapping_update_result,
15963                  config, "config");
15964 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15965         TOKEN_NUM_INITIALIZER
15966                 (struct cmd_pctype_mapping_update_result,
15967                  port_id, UINT16);
15968 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15969         TOKEN_STRING_INITIALIZER
15970                 (struct cmd_pctype_mapping_update_result,
15971                  pctype, "pctype");
15972 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15973         TOKEN_STRING_INITIALIZER
15974                 (struct cmd_pctype_mapping_update_result,
15975                  mapping, "mapping");
15976 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15977         TOKEN_STRING_INITIALIZER
15978                 (struct cmd_pctype_mapping_update_result,
15979                  update, "update");
15980 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15981         TOKEN_STRING_INITIALIZER
15982                 (struct cmd_pctype_mapping_update_result,
15983                  pctype_list, NULL);
15984 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15985         TOKEN_NUM_INITIALIZER
15986                 (struct cmd_pctype_mapping_update_result,
15987                  flow_type, UINT16);
15988
15989 static void
15990 cmd_pctype_mapping_update_parsed(
15991         void *parsed_result,
15992         __attribute__((unused)) struct cmdline *cl,
15993         __attribute__((unused)) void *data)
15994 {
15995         struct cmd_pctype_mapping_update_result *res = parsed_result;
15996         int ret = -ENOTSUP;
15997 #ifdef RTE_LIBRTE_I40E_PMD
15998         struct rte_pmd_i40e_flow_type_mapping mapping;
15999         unsigned int i;
16000         unsigned int nb_item;
16001         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16002 #endif
16003
16004         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16005                 return;
16006
16007 #ifdef RTE_LIBRTE_I40E_PMD
16008         nb_item = parse_item_list(res->pctype_list, "pctypes",
16009                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16010         mapping.flow_type = res->flow_type;
16011         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16012                 mapping.pctype |= (1ULL << pctype_list[i]);
16013         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16014                                                 &mapping,
16015                                                 1,
16016                                                 0);
16017 #endif
16018
16019         switch (ret) {
16020         case 0:
16021                 break;
16022         case -EINVAL:
16023                 printf("invalid pctype or flow type\n");
16024                 break;
16025         case -ENODEV:
16026                 printf("invalid port_id %d\n", res->port_id);
16027                 break;
16028         case -ENOTSUP:
16029                 printf("function not implemented\n");
16030                 break;
16031         default:
16032                 printf("programming error: (%s)\n", strerror(-ret));
16033         }
16034 }
16035
16036 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16037         .f = cmd_pctype_mapping_update_parsed,
16038         .data = NULL,
16039         .help_str = "port config <port_id> pctype mapping update"
16040         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16041         .tokens = {
16042                 (void *)&cmd_pctype_mapping_update_port,
16043                 (void *)&cmd_pctype_mapping_update_config,
16044                 (void *)&cmd_pctype_mapping_update_port_id,
16045                 (void *)&cmd_pctype_mapping_update_pctype,
16046                 (void *)&cmd_pctype_mapping_update_mapping,
16047                 (void *)&cmd_pctype_mapping_update_update,
16048                 (void *)&cmd_pctype_mapping_update_pc_type,
16049                 (void *)&cmd_pctype_mapping_update_flow_type,
16050                 NULL,
16051         },
16052 };
16053
16054 /* ptype mapping get */
16055
16056 /* Common result structure for ptype mapping get */
16057 struct cmd_ptype_mapping_get_result {
16058         cmdline_fixed_string_t ptype;
16059         cmdline_fixed_string_t mapping;
16060         cmdline_fixed_string_t get;
16061         portid_t port_id;
16062         uint8_t valid_only;
16063 };
16064
16065 /* Common CLI fields for ptype mapping get */
16066 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16067         TOKEN_STRING_INITIALIZER
16068                 (struct cmd_ptype_mapping_get_result,
16069                  ptype, "ptype");
16070 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16071         TOKEN_STRING_INITIALIZER
16072                 (struct cmd_ptype_mapping_get_result,
16073                  mapping, "mapping");
16074 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16075         TOKEN_STRING_INITIALIZER
16076                 (struct cmd_ptype_mapping_get_result,
16077                  get, "get");
16078 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16079         TOKEN_NUM_INITIALIZER
16080                 (struct cmd_ptype_mapping_get_result,
16081                  port_id, UINT16);
16082 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16083         TOKEN_NUM_INITIALIZER
16084                 (struct cmd_ptype_mapping_get_result,
16085                  valid_only, UINT8);
16086
16087 static void
16088 cmd_ptype_mapping_get_parsed(
16089         void *parsed_result,
16090         __attribute__((unused)) struct cmdline *cl,
16091         __attribute__((unused)) void *data)
16092 {
16093         struct cmd_ptype_mapping_get_result *res = parsed_result;
16094         int ret = -ENOTSUP;
16095 #ifdef RTE_LIBRTE_I40E_PMD
16096         int max_ptype_num = 256;
16097         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16098         uint16_t count;
16099         int i;
16100 #endif
16101
16102         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16103                 return;
16104
16105 #ifdef RTE_LIBRTE_I40E_PMD
16106         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16107                                         mapping,
16108                                         max_ptype_num,
16109                                         &count,
16110                                         res->valid_only);
16111 #endif
16112
16113         switch (ret) {
16114         case 0:
16115                 break;
16116         case -ENODEV:
16117                 printf("invalid port_id %d\n", res->port_id);
16118                 break;
16119         case -ENOTSUP:
16120                 printf("function not implemented\n");
16121                 break;
16122         default:
16123                 printf("programming error: (%s)\n", strerror(-ret));
16124         }
16125
16126 #ifdef RTE_LIBRTE_I40E_PMD
16127         if (!ret) {
16128                 for (i = 0; i < count; i++)
16129                         printf("%3d\t0x%08x\n",
16130                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16131         }
16132 #endif
16133 }
16134
16135 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16136         .f = cmd_ptype_mapping_get_parsed,
16137         .data = NULL,
16138         .help_str = "ptype mapping get <port_id> <valid_only>",
16139         .tokens = {
16140                 (void *)&cmd_ptype_mapping_get_ptype,
16141                 (void *)&cmd_ptype_mapping_get_mapping,
16142                 (void *)&cmd_ptype_mapping_get_get,
16143                 (void *)&cmd_ptype_mapping_get_port_id,
16144                 (void *)&cmd_ptype_mapping_get_valid_only,
16145                 NULL,
16146         },
16147 };
16148
16149 /* ptype mapping replace */
16150
16151 /* Common result structure for ptype mapping replace */
16152 struct cmd_ptype_mapping_replace_result {
16153         cmdline_fixed_string_t ptype;
16154         cmdline_fixed_string_t mapping;
16155         cmdline_fixed_string_t replace;
16156         portid_t port_id;
16157         uint32_t target;
16158         uint8_t mask;
16159         uint32_t pkt_type;
16160 };
16161
16162 /* Common CLI fields for ptype mapping replace */
16163 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16164         TOKEN_STRING_INITIALIZER
16165                 (struct cmd_ptype_mapping_replace_result,
16166                  ptype, "ptype");
16167 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16168         TOKEN_STRING_INITIALIZER
16169                 (struct cmd_ptype_mapping_replace_result,
16170                  mapping, "mapping");
16171 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16172         TOKEN_STRING_INITIALIZER
16173                 (struct cmd_ptype_mapping_replace_result,
16174                  replace, "replace");
16175 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16176         TOKEN_NUM_INITIALIZER
16177                 (struct cmd_ptype_mapping_replace_result,
16178                  port_id, UINT16);
16179 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16180         TOKEN_NUM_INITIALIZER
16181                 (struct cmd_ptype_mapping_replace_result,
16182                  target, UINT32);
16183 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16184         TOKEN_NUM_INITIALIZER
16185                 (struct cmd_ptype_mapping_replace_result,
16186                  mask, UINT8);
16187 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16188         TOKEN_NUM_INITIALIZER
16189                 (struct cmd_ptype_mapping_replace_result,
16190                  pkt_type, UINT32);
16191
16192 static void
16193 cmd_ptype_mapping_replace_parsed(
16194         void *parsed_result,
16195         __attribute__((unused)) struct cmdline *cl,
16196         __attribute__((unused)) void *data)
16197 {
16198         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16199         int ret = -ENOTSUP;
16200
16201         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16202                 return;
16203
16204 #ifdef RTE_LIBRTE_I40E_PMD
16205         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16206                                         res->target,
16207                                         res->mask,
16208                                         res->pkt_type);
16209 #endif
16210
16211         switch (ret) {
16212         case 0:
16213                 break;
16214         case -EINVAL:
16215                 printf("invalid ptype 0x%8x or 0x%8x\n",
16216                                 res->target, res->pkt_type);
16217                 break;
16218         case -ENODEV:
16219                 printf("invalid port_id %d\n", res->port_id);
16220                 break;
16221         case -ENOTSUP:
16222                 printf("function not implemented\n");
16223                 break;
16224         default:
16225                 printf("programming error: (%s)\n", strerror(-ret));
16226         }
16227 }
16228
16229 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16230         .f = cmd_ptype_mapping_replace_parsed,
16231         .data = NULL,
16232         .help_str =
16233                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16234         .tokens = {
16235                 (void *)&cmd_ptype_mapping_replace_ptype,
16236                 (void *)&cmd_ptype_mapping_replace_mapping,
16237                 (void *)&cmd_ptype_mapping_replace_replace,
16238                 (void *)&cmd_ptype_mapping_replace_port_id,
16239                 (void *)&cmd_ptype_mapping_replace_target,
16240                 (void *)&cmd_ptype_mapping_replace_mask,
16241                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16242                 NULL,
16243         },
16244 };
16245
16246 /* ptype mapping reset */
16247
16248 /* Common result structure for ptype mapping reset */
16249 struct cmd_ptype_mapping_reset_result {
16250         cmdline_fixed_string_t ptype;
16251         cmdline_fixed_string_t mapping;
16252         cmdline_fixed_string_t reset;
16253         portid_t port_id;
16254 };
16255
16256 /* Common CLI fields for ptype mapping reset*/
16257 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16258         TOKEN_STRING_INITIALIZER
16259                 (struct cmd_ptype_mapping_reset_result,
16260                  ptype, "ptype");
16261 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16262         TOKEN_STRING_INITIALIZER
16263                 (struct cmd_ptype_mapping_reset_result,
16264                  mapping, "mapping");
16265 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16266         TOKEN_STRING_INITIALIZER
16267                 (struct cmd_ptype_mapping_reset_result,
16268                  reset, "reset");
16269 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16270         TOKEN_NUM_INITIALIZER
16271                 (struct cmd_ptype_mapping_reset_result,
16272                  port_id, UINT16);
16273
16274 static void
16275 cmd_ptype_mapping_reset_parsed(
16276         void *parsed_result,
16277         __attribute__((unused)) struct cmdline *cl,
16278         __attribute__((unused)) void *data)
16279 {
16280         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16281         int ret = -ENOTSUP;
16282
16283         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16284                 return;
16285
16286 #ifdef RTE_LIBRTE_I40E_PMD
16287         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16288 #endif
16289
16290         switch (ret) {
16291         case 0:
16292                 break;
16293         case -ENODEV:
16294                 printf("invalid port_id %d\n", res->port_id);
16295                 break;
16296         case -ENOTSUP:
16297                 printf("function not implemented\n");
16298                 break;
16299         default:
16300                 printf("programming error: (%s)\n", strerror(-ret));
16301         }
16302 }
16303
16304 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16305         .f = cmd_ptype_mapping_reset_parsed,
16306         .data = NULL,
16307         .help_str = "ptype mapping reset <port_id>",
16308         .tokens = {
16309                 (void *)&cmd_ptype_mapping_reset_ptype,
16310                 (void *)&cmd_ptype_mapping_reset_mapping,
16311                 (void *)&cmd_ptype_mapping_reset_reset,
16312                 (void *)&cmd_ptype_mapping_reset_port_id,
16313                 NULL,
16314         },
16315 };
16316
16317 /* ptype mapping update */
16318
16319 /* Common result structure for ptype mapping update */
16320 struct cmd_ptype_mapping_update_result {
16321         cmdline_fixed_string_t ptype;
16322         cmdline_fixed_string_t mapping;
16323         cmdline_fixed_string_t reset;
16324         portid_t port_id;
16325         uint8_t hw_ptype;
16326         uint32_t sw_ptype;
16327 };
16328
16329 /* Common CLI fields for ptype mapping update*/
16330 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16331         TOKEN_STRING_INITIALIZER
16332                 (struct cmd_ptype_mapping_update_result,
16333                  ptype, "ptype");
16334 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16335         TOKEN_STRING_INITIALIZER
16336                 (struct cmd_ptype_mapping_update_result,
16337                  mapping, "mapping");
16338 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16339         TOKEN_STRING_INITIALIZER
16340                 (struct cmd_ptype_mapping_update_result,
16341                  reset, "update");
16342 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16343         TOKEN_NUM_INITIALIZER
16344                 (struct cmd_ptype_mapping_update_result,
16345                  port_id, UINT16);
16346 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16347         TOKEN_NUM_INITIALIZER
16348                 (struct cmd_ptype_mapping_update_result,
16349                  hw_ptype, UINT8);
16350 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16351         TOKEN_NUM_INITIALIZER
16352                 (struct cmd_ptype_mapping_update_result,
16353                  sw_ptype, UINT32);
16354
16355 static void
16356 cmd_ptype_mapping_update_parsed(
16357         void *parsed_result,
16358         __attribute__((unused)) struct cmdline *cl,
16359         __attribute__((unused)) void *data)
16360 {
16361         struct cmd_ptype_mapping_update_result *res = parsed_result;
16362         int ret = -ENOTSUP;
16363 #ifdef RTE_LIBRTE_I40E_PMD
16364         struct rte_pmd_i40e_ptype_mapping mapping;
16365 #endif
16366         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16367                 return;
16368
16369 #ifdef RTE_LIBRTE_I40E_PMD
16370         mapping.hw_ptype = res->hw_ptype;
16371         mapping.sw_ptype = res->sw_ptype;
16372         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16373                                                 &mapping,
16374                                                 1,
16375                                                 0);
16376 #endif
16377
16378         switch (ret) {
16379         case 0:
16380                 break;
16381         case -EINVAL:
16382                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16383                 break;
16384         case -ENODEV:
16385                 printf("invalid port_id %d\n", res->port_id);
16386                 break;
16387         case -ENOTSUP:
16388                 printf("function not implemented\n");
16389                 break;
16390         default:
16391                 printf("programming error: (%s)\n", strerror(-ret));
16392         }
16393 }
16394
16395 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16396         .f = cmd_ptype_mapping_update_parsed,
16397         .data = NULL,
16398         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16399         .tokens = {
16400                 (void *)&cmd_ptype_mapping_update_ptype,
16401                 (void *)&cmd_ptype_mapping_update_mapping,
16402                 (void *)&cmd_ptype_mapping_update_update,
16403                 (void *)&cmd_ptype_mapping_update_port_id,
16404                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16405                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16406                 NULL,
16407         },
16408 };
16409
16410 /* Common result structure for file commands */
16411 struct cmd_cmdfile_result {
16412         cmdline_fixed_string_t load;
16413         cmdline_fixed_string_t filename;
16414 };
16415
16416 /* Common CLI fields for file commands */
16417 cmdline_parse_token_string_t cmd_load_cmdfile =
16418         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16419 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16420         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16421
16422 static void
16423 cmd_load_from_file_parsed(
16424         void *parsed_result,
16425         __attribute__((unused)) struct cmdline *cl,
16426         __attribute__((unused)) void *data)
16427 {
16428         struct cmd_cmdfile_result *res = parsed_result;
16429
16430         cmdline_read_from_file(res->filename);
16431 }
16432
16433 cmdline_parse_inst_t cmd_load_from_file = {
16434         .f = cmd_load_from_file_parsed,
16435         .data = NULL,
16436         .help_str = "load <filename>",
16437         .tokens = {
16438                 (void *)&cmd_load_cmdfile,
16439                 (void *)&cmd_load_cmdfile_filename,
16440                 NULL,
16441         },
16442 };
16443
16444 /* ******************************************************************************** */
16445
16446 /* list of instructions */
16447 cmdline_parse_ctx_t main_ctx[] = {
16448         (cmdline_parse_inst_t *)&cmd_help_brief,
16449         (cmdline_parse_inst_t *)&cmd_help_long,
16450         (cmdline_parse_inst_t *)&cmd_quit,
16451         (cmdline_parse_inst_t *)&cmd_load_from_file,
16452         (cmdline_parse_inst_t *)&cmd_showport,
16453         (cmdline_parse_inst_t *)&cmd_showqueue,
16454         (cmdline_parse_inst_t *)&cmd_showportall,
16455         (cmdline_parse_inst_t *)&cmd_showcfg,
16456         (cmdline_parse_inst_t *)&cmd_start,
16457         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16458         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16459         (cmdline_parse_inst_t *)&cmd_set_link_up,
16460         (cmdline_parse_inst_t *)&cmd_set_link_down,
16461         (cmdline_parse_inst_t *)&cmd_reset,
16462         (cmdline_parse_inst_t *)&cmd_set_numbers,
16463         (cmdline_parse_inst_t *)&cmd_set_log,
16464         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16465         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16466         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16467         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16468         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16469         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16470         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16471         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16472         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16473         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16474         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16475         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16476         (cmdline_parse_inst_t *)&cmd_set_link_check,
16477         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16478         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16479         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16480         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16481 #ifdef RTE_LIBRTE_PMD_BOND
16482         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16483         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16484         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16485         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16486         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16487         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16488         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16489         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16490         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16491         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16492         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16493 #endif
16494         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16495         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16496         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16497         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16498         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16499         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16500         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16501         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16502         (cmdline_parse_inst_t *)&cmd_csum_set,
16503         (cmdline_parse_inst_t *)&cmd_csum_show,
16504         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16505         (cmdline_parse_inst_t *)&cmd_tso_set,
16506         (cmdline_parse_inst_t *)&cmd_tso_show,
16507         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16508         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16509         (cmdline_parse_inst_t *)&cmd_gro_enable,
16510         (cmdline_parse_inst_t *)&cmd_gro_flush,
16511         (cmdline_parse_inst_t *)&cmd_gro_show,
16512         (cmdline_parse_inst_t *)&cmd_gso_enable,
16513         (cmdline_parse_inst_t *)&cmd_gso_size,
16514         (cmdline_parse_inst_t *)&cmd_gso_show,
16515         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16516         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16517         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16518         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16519         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16520         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16521         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16522         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16523         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16524         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16525         (cmdline_parse_inst_t *)&cmd_config_dcb,
16526         (cmdline_parse_inst_t *)&cmd_read_reg,
16527         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16528         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16529         (cmdline_parse_inst_t *)&cmd_write_reg,
16530         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16531         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16532         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16533         (cmdline_parse_inst_t *)&cmd_stop,
16534         (cmdline_parse_inst_t *)&cmd_mac_addr,
16535         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16536         (cmdline_parse_inst_t *)&cmd_set_qmap,
16537         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16538         (cmdline_parse_inst_t *)&cmd_operate_port,
16539         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16540         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16541         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16542         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16543         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16544         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16545         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16546         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16547         (cmdline_parse_inst_t *)&cmd_config_mtu,
16548         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16549         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16550         (cmdline_parse_inst_t *)&cmd_config_rss,
16551         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
16552         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16553         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
16554         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16555         (cmdline_parse_inst_t *)&cmd_showport_reta,
16556         (cmdline_parse_inst_t *)&cmd_config_burst,
16557         (cmdline_parse_inst_t *)&cmd_config_thresh,
16558         (cmdline_parse_inst_t *)&cmd_config_threshold,
16559         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16560         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16561         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16562         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16563         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16564         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16565         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16566         (cmdline_parse_inst_t *)&cmd_global_config,
16567         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16568         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16569         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16570         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16571         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16572         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16573         (cmdline_parse_inst_t *)&cmd_dump,
16574         (cmdline_parse_inst_t *)&cmd_dump_one,
16575         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16576         (cmdline_parse_inst_t *)&cmd_syn_filter,
16577         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16578         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16579         (cmdline_parse_inst_t *)&cmd_flex_filter,
16580         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16581         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16582         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16583         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16584         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16585         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16586         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16587         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16588         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16589         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16590         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16591         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16592         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16593         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16594         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16595         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16596         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16597         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16598         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16599         (cmdline_parse_inst_t *)&cmd_flow,
16600         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16601         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16602         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16603         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16604         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16605         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16606         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16607         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16608         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16609         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16610         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16611         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16612         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16613         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16614         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16615         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16616         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16617         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16618         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16619         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16620         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16621         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16622         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16623         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16624         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16625         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16626         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16627         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16628         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16629         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16630         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16631         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16632         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16633         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16634         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16635         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16636         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16637         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16638         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16639         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16640         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16641         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16642         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16643         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16644         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16645         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16646         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16647         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16648         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16649 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16650         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16651 #endif
16652         (cmdline_parse_inst_t *)&cmd_ddp_add,
16653         (cmdline_parse_inst_t *)&cmd_ddp_del,
16654         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16655         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16656         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16657         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16658         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16659         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16660         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16661         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16662         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16663         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16664
16665         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16666         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16667         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16668         (cmdline_parse_inst_t *)&cmd_queue_region,
16669         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16670         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16671         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16672         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16673         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16674         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16675         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16676         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16677         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16678         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16679         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16680         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16681         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16682         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16683         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16684         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16685         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16686         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16687         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16688         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16689         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16690         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
16691         NULL,
16692 };
16693
16694 /* read cmdline commands from file */
16695 void
16696 cmdline_read_from_file(const char *filename)
16697 {
16698         struct cmdline *cl;
16699
16700         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16701         if (cl == NULL) {
16702                 printf("Failed to create file based cmdline context: %s\n",
16703                        filename);
16704                 return;
16705         }
16706
16707         cmdline_interact(cl);
16708         cmdline_quit(cl);
16709
16710         cmdline_free(cl);
16711
16712         printf("Read CLI commands from %s\n", filename);
16713 }
16714
16715 /* prompt function, called from main on MASTER lcore */
16716 void
16717 prompt(void)
16718 {
16719         /* initialize non-constant commands */
16720         cmd_set_fwd_mode_init();
16721         cmd_set_fwd_retry_mode_init();
16722
16723         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16724         if (testpmd_cl == NULL)
16725                 return;
16726         cmdline_interact(testpmd_cl);
16727         cmdline_stdin_exit(testpmd_cl);
16728 }
16729
16730 void
16731 prompt_exit(void)
16732 {
16733         if (testpmd_cl != NULL)
16734                 cmdline_quit(testpmd_cl);
16735 }
16736
16737 static void
16738 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16739 {
16740         if (id == (portid_t)RTE_PORT_ALL) {
16741                 portid_t pid;
16742
16743                 RTE_ETH_FOREACH_DEV(pid) {
16744                         /* check if need_reconfig has been set to 1 */
16745                         if (ports[pid].need_reconfig == 0)
16746                                 ports[pid].need_reconfig = dev;
16747                         /* check if need_reconfig_queues has been set to 1 */
16748                         if (ports[pid].need_reconfig_queues == 0)
16749                                 ports[pid].need_reconfig_queues = queue;
16750                 }
16751         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16752                 /* check if need_reconfig has been set to 1 */
16753                 if (ports[id].need_reconfig == 0)
16754                         ports[id].need_reconfig = dev;
16755                 /* check if need_reconfig_queues has been set to 1 */
16756                 if (ports[id].need_reconfig_queues == 0)
16757                         ports[id].need_reconfig_queues = queue;
16758         }
16759 }