app/testpmd: add command to suspend a TM node
[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                         "suspend port tm node (port_id) (node_id)"
775                         "       Suspend tm node.\n\n"
776
777                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
778                         "       Commit tm hierarchy.\n\n"
779
780                         , list_pkt_forwarding_modes()
781                 );
782         }
783
784         if (show_all || !strcmp(res->section, "ports")) {
785
786                 cmdline_printf(
787                         cl,
788                         "\n"
789                         "Port Operations:\n"
790                         "----------------\n\n"
791
792                         "port start (port_id|all)\n"
793                         "    Start all ports or port_id.\n\n"
794
795                         "port stop (port_id|all)\n"
796                         "    Stop all ports or port_id.\n\n"
797
798                         "port close (port_id|all)\n"
799                         "    Close all ports or port_id.\n\n"
800
801                         "port attach (ident)\n"
802                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
803
804                         "port detach (port_id)\n"
805                         "    Detach physical or virtual dev by port_id\n\n"
806
807                         "port config (port_id|all)"
808                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
809                         " duplex (half|full|auto)\n"
810                         "    Set speed and duplex for all ports or port_id\n\n"
811
812                         "port config (port_id|all) loopback (mode)\n"
813                         "    Set loopback mode for all ports or port_id\n\n"
814
815                         "port config all (rxq|txq|rxd|txd) (value)\n"
816                         "    Set number for rxq/txq/rxd/txd.\n\n"
817
818                         "port config all max-pkt-len (value)\n"
819                         "    Set the max packet length.\n\n"
820
821                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
822                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
823                         " (on|off)\n"
824                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
825                         " for ports.\n\n"
826
827                         "port config all rss (all|default|ip|tcp|udp|sctp|"
828                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
829                         "    Set the RSS mode.\n\n"
830
831                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
832                         "    Set the RSS redirection table.\n\n"
833
834                         "port config (port_id) dcb vt (on|off) (traffic_class)"
835                         " pfc (on|off)\n"
836                         "    Set the DCB mode.\n\n"
837
838                         "port config all burst (value)\n"
839                         "    Set the number of packets per burst.\n\n"
840
841                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
842                         " (value)\n"
843                         "    Set the ring prefetch/host/writeback threshold"
844                         " for tx/rx queue.\n\n"
845
846                         "port config all (txfreet|txrst|rxfreet) (value)\n"
847                         "    Set free threshold for rx/tx, or set"
848                         " tx rs bit threshold.\n\n"
849                         "port config mtu X value\n"
850                         "    Set the MTU of port X to a given value\n\n"
851
852                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
853                         "    Set a rx/tx queue's ring size configuration, the new"
854                         " value will take effect after command that (re-)start the port"
855                         " or command that setup the specific queue\n\n"
856
857                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
858                         "    Start/stop a rx/tx queue of port X. Only take effect"
859                         " when port X is started\n\n"
860
861                         "port (port_id) (rxq|txq) (queue_id) setup\n"
862                         "    Setup a rx/tx queue of port X.\n\n"
863
864                         "port config (port_id|all) l2-tunnel E-tag ether-type"
865                         " (value)\n"
866                         "    Set the value of E-tag ether-type.\n\n"
867
868                         "port config (port_id|all) l2-tunnel E-tag"
869                         " (enable|disable)\n"
870                         "    Enable/disable the E-tag support.\n\n"
871
872                         "port config (port_id) pctype mapping reset\n"
873                         "    Reset flow type to pctype mapping on a port\n\n"
874
875                         "port config (port_id) pctype mapping update"
876                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
877                         "    Update a flow type to pctype mapping item on a port\n\n"
878
879                         "port config (port_id) pctype (pctype_id) hash_inset|"
880                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
881                         " (field_idx)\n"
882                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
883
884                         "port config (port_id) pctype (pctype_id) hash_inset|"
885                         "fdir_inset|fdir_flx_inset clear all"
886                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
887
888                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
889                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
890                 );
891         }
892
893         if (show_all || !strcmp(res->section, "registers")) {
894
895                 cmdline_printf(
896                         cl,
897                         "\n"
898                         "Registers:\n"
899                         "----------\n\n"
900
901                         "read reg (port_id) (address)\n"
902                         "    Display value of a port register.\n\n"
903
904                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
905                         "    Display a port register bit field.\n\n"
906
907                         "read regbit (port_id) (address) (bit_x)\n"
908                         "    Display a single port register bit.\n\n"
909
910                         "write reg (port_id) (address) (value)\n"
911                         "    Set value of a port register.\n\n"
912
913                         "write regfield (port_id) (address) (bit_x) (bit_y)"
914                         " (value)\n"
915                         "    Set bit field of a port register.\n\n"
916
917                         "write regbit (port_id) (address) (bit_x) (value)\n"
918                         "    Set single bit value of a port register.\n\n"
919                 );
920         }
921         if (show_all || !strcmp(res->section, "filters")) {
922
923                 cmdline_printf(
924                         cl,
925                         "\n"
926                         "filters:\n"
927                         "--------\n\n"
928
929                         "ethertype_filter (port_id) (add|del)"
930                         " (mac_addr|mac_ignr) (mac_address) ethertype"
931                         " (ether_type) (drop|fwd) queue (queue_id)\n"
932                         "    Add/Del an ethertype filter.\n\n"
933
934                         "2tuple_filter (port_id) (add|del)"
935                         " dst_port (dst_port_value) protocol (protocol_value)"
936                         " mask (mask_value) tcp_flags (tcp_flags_value)"
937                         " priority (prio_value) queue (queue_id)\n"
938                         "    Add/Del a 2tuple filter.\n\n"
939
940                         "5tuple_filter (port_id) (add|del)"
941                         " dst_ip (dst_address) src_ip (src_address)"
942                         " dst_port (dst_port_value) src_port (src_port_value)"
943                         " protocol (protocol_value)"
944                         " mask (mask_value) tcp_flags (tcp_flags_value)"
945                         " priority (prio_value) queue (queue_id)\n"
946                         "    Add/Del a 5tuple filter.\n\n"
947
948                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
949                         "    Add/Del syn filter.\n\n"
950
951                         "flex_filter (port_id) (add|del) len (len_value)"
952                         " bytes (bytes_value) mask (mask_value)"
953                         " priority (prio_value) queue (queue_id)\n"
954                         "    Add/Del a flex filter.\n\n"
955
956                         "flow_director_filter (port_id) mode IP (add|del|update)"
957                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
958                         " src (src_ip_address) dst (dst_ip_address)"
959                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
960                         " vlan (vlan_value) flexbytes (flexbytes_value)"
961                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
962                         " fd_id (fd_id_value)\n"
963                         "    Add/Del an IP type flow director filter.\n\n"
964
965                         "flow_director_filter (port_id) mode IP (add|del|update)"
966                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
967                         " src (src_ip_address) (src_port)"
968                         " dst (dst_ip_address) (dst_port)"
969                         " tos (tos_value) ttl (ttl_value)"
970                         " vlan (vlan_value) flexbytes (flexbytes_value)"
971                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
972                         " fd_id (fd_id_value)\n"
973                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
974
975                         "flow_director_filter (port_id) mode IP (add|del|update)"
976                         " flow (ipv4-sctp|ipv6-sctp)"
977                         " src (src_ip_address) (src_port)"
978                         " dst (dst_ip_address) (dst_port)"
979                         " tag (verification_tag) "
980                         " tos (tos_value) ttl (ttl_value)"
981                         " vlan (vlan_value)"
982                         " flexbytes (flexbytes_value) (drop|fwd)"
983                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
984                         "    Add/Del a SCTP type flow director filter.\n\n"
985
986                         "flow_director_filter (port_id) mode IP (add|del|update)"
987                         " flow l2_payload ether (ethertype)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a l2 payload type flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
993                         " mac (mac_address) vlan (vlan_value)"
994                         " flexbytes (flexbytes_value) (drop|fwd)"
995                         " queue (queue_id) fd_id (fd_id_value)\n"
996                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
997
998                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
999                         " mac (mac_address) vlan (vlan_value)"
1000                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1001                         " flexbytes (flexbytes_value) (drop|fwd)"
1002                         " queue (queue_id) fd_id (fd_id_value)\n"
1003                         "    Add/Del a Tunnel flow director filter.\n\n"
1004
1005                         "flow_director_filter (port_id) mode raw (add|del|update)"
1006                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1007                         " fd_id (fd_id_value) packet (packet file name)\n"
1008                         "    Add/Del a raw type flow director filter.\n\n"
1009
1010                         "flush_flow_director (port_id)\n"
1011                         "    Flush all flow director entries of a device.\n\n"
1012
1013                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1014                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1015                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1016                         "    Set flow director IP mask.\n\n"
1017
1018                         "flow_director_mask (port_id) mode MAC-VLAN"
1019                         " vlan (vlan_value)\n"
1020                         "    Set flow director MAC-VLAN mask.\n\n"
1021
1022                         "flow_director_mask (port_id) mode Tunnel"
1023                         " vlan (vlan_value) mac (mac_value)"
1024                         " tunnel-type (tunnel_type_value)"
1025                         " tunnel-id (tunnel_id_value)\n"
1026                         "    Set flow director Tunnel mask.\n\n"
1027
1028                         "flow_director_flex_mask (port_id)"
1029                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1030                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1031                         " (mask)\n"
1032                         "    Configure mask of flex payload.\n\n"
1033
1034                         "flow_director_flex_payload (port_id)"
1035                         " (raw|l2|l3|l4) (config)\n"
1036                         "    Configure flex payload selection.\n\n"
1037
1038                         "get_sym_hash_ena_per_port (port_id)\n"
1039                         "    get symmetric hash enable configuration per port.\n\n"
1040
1041                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1042                         "    set symmetric hash enable configuration per port"
1043                         " to enable or disable.\n\n"
1044
1045                         "get_hash_global_config (port_id)\n"
1046                         "    Get the global configurations of hash filters.\n\n"
1047
1048                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1049                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1050                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1051                         " (enable|disable)\n"
1052                         "    Set the global configurations of hash filters.\n\n"
1053
1054                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1055                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1056                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1057                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1058                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1059                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1060                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1061                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1062                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1063                         "fld-8th|none) (select|add)\n"
1064                         "    Set the input set for hash.\n\n"
1065
1066                         "set_fdir_input_set (port_id) "
1067                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1068                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1069                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1070                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1071                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1072                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1073                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1074                         " (select|add)\n"
1075                         "    Set the input set for FDir.\n\n"
1076
1077                         "flow validate {port_id}"
1078                         " [group {group_id}] [priority {level}]"
1079                         " [ingress] [egress]"
1080                         " pattern {item} [/ {item} [...]] / end"
1081                         " actions {action} [/ {action} [...]] / end\n"
1082                         "    Check whether a flow rule can be created.\n\n"
1083
1084                         "flow create {port_id}"
1085                         " [group {group_id}] [priority {level}]"
1086                         " [ingress] [egress]"
1087                         " pattern {item} [/ {item} [...]] / end"
1088                         " actions {action} [/ {action} [...]] / end\n"
1089                         "    Create a flow rule.\n\n"
1090
1091                         "flow destroy {port_id} rule {rule_id} [...]\n"
1092                         "    Destroy specific flow rules.\n\n"
1093
1094                         "flow flush {port_id}\n"
1095                         "    Destroy all flow rules.\n\n"
1096
1097                         "flow query {port_id} {rule_id} {action}\n"
1098                         "    Query an existing flow rule.\n\n"
1099
1100                         "flow list {port_id} [group {group_id}] [...]\n"
1101                         "    List existing flow rules sorted by priority,"
1102                         " filtered by group identifiers.\n\n"
1103
1104                         "flow isolate {port_id} {boolean}\n"
1105                         "    Restrict ingress traffic to the defined"
1106                         " flow rules\n\n"
1107                 );
1108         }
1109 }
1110
1111 cmdline_parse_token_string_t cmd_help_long_help =
1112         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1113
1114 cmdline_parse_token_string_t cmd_help_long_section =
1115         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1116                         "all#control#display#config#"
1117                         "ports#registers#filters");
1118
1119 cmdline_parse_inst_t cmd_help_long = {
1120         .f = cmd_help_long_parsed,
1121         .data = NULL,
1122         .help_str = "help all|control|display|config|ports|register|filters: "
1123                 "Show help",
1124         .tokens = {
1125                 (void *)&cmd_help_long_help,
1126                 (void *)&cmd_help_long_section,
1127                 NULL,
1128         },
1129 };
1130
1131
1132 /* *** start/stop/close all ports *** */
1133 struct cmd_operate_port_result {
1134         cmdline_fixed_string_t keyword;
1135         cmdline_fixed_string_t name;
1136         cmdline_fixed_string_t value;
1137 };
1138
1139 static void cmd_operate_port_parsed(void *parsed_result,
1140                                 __attribute__((unused)) struct cmdline *cl,
1141                                 __attribute__((unused)) void *data)
1142 {
1143         struct cmd_operate_port_result *res = parsed_result;
1144
1145         if (!strcmp(res->name, "start"))
1146                 start_port(RTE_PORT_ALL);
1147         else if (!strcmp(res->name, "stop"))
1148                 stop_port(RTE_PORT_ALL);
1149         else if (!strcmp(res->name, "close"))
1150                 close_port(RTE_PORT_ALL);
1151         else if (!strcmp(res->name, "reset"))
1152                 reset_port(RTE_PORT_ALL);
1153         else
1154                 printf("Unknown parameter\n");
1155 }
1156
1157 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1158         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1159                                                                 "port");
1160 cmdline_parse_token_string_t cmd_operate_port_all_port =
1161         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1162                                                 "start#stop#close#reset");
1163 cmdline_parse_token_string_t cmd_operate_port_all_all =
1164         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1165
1166 cmdline_parse_inst_t cmd_operate_port = {
1167         .f = cmd_operate_port_parsed,
1168         .data = NULL,
1169         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1170         .tokens = {
1171                 (void *)&cmd_operate_port_all_cmd,
1172                 (void *)&cmd_operate_port_all_port,
1173                 (void *)&cmd_operate_port_all_all,
1174                 NULL,
1175         },
1176 };
1177
1178 /* *** start/stop/close specific port *** */
1179 struct cmd_operate_specific_port_result {
1180         cmdline_fixed_string_t keyword;
1181         cmdline_fixed_string_t name;
1182         uint8_t value;
1183 };
1184
1185 static void cmd_operate_specific_port_parsed(void *parsed_result,
1186                         __attribute__((unused)) struct cmdline *cl,
1187                                 __attribute__((unused)) void *data)
1188 {
1189         struct cmd_operate_specific_port_result *res = parsed_result;
1190
1191         if (!strcmp(res->name, "start"))
1192                 start_port(res->value);
1193         else if (!strcmp(res->name, "stop"))
1194                 stop_port(res->value);
1195         else if (!strcmp(res->name, "close"))
1196                 close_port(res->value);
1197         else if (!strcmp(res->name, "reset"))
1198                 reset_port(res->value);
1199         else
1200                 printf("Unknown parameter\n");
1201 }
1202
1203 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1204         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1205                                                         keyword, "port");
1206 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1207         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1208                                                 name, "start#stop#close#reset");
1209 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1210         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1211                                                         value, UINT8);
1212
1213 cmdline_parse_inst_t cmd_operate_specific_port = {
1214         .f = cmd_operate_specific_port_parsed,
1215         .data = NULL,
1216         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1217         .tokens = {
1218                 (void *)&cmd_operate_specific_port_cmd,
1219                 (void *)&cmd_operate_specific_port_port,
1220                 (void *)&cmd_operate_specific_port_id,
1221                 NULL,
1222         },
1223 };
1224
1225 /* *** attach a specified port *** */
1226 struct cmd_operate_attach_port_result {
1227         cmdline_fixed_string_t port;
1228         cmdline_fixed_string_t keyword;
1229         cmdline_fixed_string_t identifier;
1230 };
1231
1232 static void cmd_operate_attach_port_parsed(void *parsed_result,
1233                                 __attribute__((unused)) struct cmdline *cl,
1234                                 __attribute__((unused)) void *data)
1235 {
1236         struct cmd_operate_attach_port_result *res = parsed_result;
1237
1238         if (!strcmp(res->keyword, "attach"))
1239                 attach_port(res->identifier);
1240         else
1241                 printf("Unknown parameter\n");
1242 }
1243
1244 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1245         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1246                         port, "port");
1247 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1248         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1249                         keyword, "attach");
1250 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1251         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1252                         identifier, NULL);
1253
1254 cmdline_parse_inst_t cmd_operate_attach_port = {
1255         .f = cmd_operate_attach_port_parsed,
1256         .data = NULL,
1257         .help_str = "port attach <identifier>: "
1258                 "(identifier: pci address or virtual dev name)",
1259         .tokens = {
1260                 (void *)&cmd_operate_attach_port_port,
1261                 (void *)&cmd_operate_attach_port_keyword,
1262                 (void *)&cmd_operate_attach_port_identifier,
1263                 NULL,
1264         },
1265 };
1266
1267 /* *** detach a specified port *** */
1268 struct cmd_operate_detach_port_result {
1269         cmdline_fixed_string_t port;
1270         cmdline_fixed_string_t keyword;
1271         portid_t port_id;
1272 };
1273
1274 static void cmd_operate_detach_port_parsed(void *parsed_result,
1275                                 __attribute__((unused)) struct cmdline *cl,
1276                                 __attribute__((unused)) void *data)
1277 {
1278         struct cmd_operate_detach_port_result *res = parsed_result;
1279
1280         if (!strcmp(res->keyword, "detach"))
1281                 detach_port(res->port_id);
1282         else
1283                 printf("Unknown parameter\n");
1284 }
1285
1286 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1287         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1288                         port, "port");
1289 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1290         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1291                         keyword, "detach");
1292 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1293         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1294                         port_id, UINT16);
1295
1296 cmdline_parse_inst_t cmd_operate_detach_port = {
1297         .f = cmd_operate_detach_port_parsed,
1298         .data = NULL,
1299         .help_str = "port detach <port_id>",
1300         .tokens = {
1301                 (void *)&cmd_operate_detach_port_port,
1302                 (void *)&cmd_operate_detach_port_keyword,
1303                 (void *)&cmd_operate_detach_port_port_id,
1304                 NULL,
1305         },
1306 };
1307
1308 /* *** configure speed for all ports *** */
1309 struct cmd_config_speed_all {
1310         cmdline_fixed_string_t port;
1311         cmdline_fixed_string_t keyword;
1312         cmdline_fixed_string_t all;
1313         cmdline_fixed_string_t item1;
1314         cmdline_fixed_string_t item2;
1315         cmdline_fixed_string_t value1;
1316         cmdline_fixed_string_t value2;
1317 };
1318
1319 static int
1320 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1321 {
1322
1323         int duplex;
1324
1325         if (!strcmp(duplexstr, "half")) {
1326                 duplex = ETH_LINK_HALF_DUPLEX;
1327         } else if (!strcmp(duplexstr, "full")) {
1328                 duplex = ETH_LINK_FULL_DUPLEX;
1329         } else if (!strcmp(duplexstr, "auto")) {
1330                 duplex = ETH_LINK_FULL_DUPLEX;
1331         } else {
1332                 printf("Unknown duplex parameter\n");
1333                 return -1;
1334         }
1335
1336         if (!strcmp(speedstr, "10")) {
1337                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1338                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1339         } else if (!strcmp(speedstr, "100")) {
1340                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1341                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1342         } else {
1343                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1344                         printf("Invalid speed/duplex parameters\n");
1345                         return -1;
1346                 }
1347                 if (!strcmp(speedstr, "1000")) {
1348                         *speed = ETH_LINK_SPEED_1G;
1349                 } else if (!strcmp(speedstr, "10000")) {
1350                         *speed = ETH_LINK_SPEED_10G;
1351                 } else if (!strcmp(speedstr, "25000")) {
1352                         *speed = ETH_LINK_SPEED_25G;
1353                 } else if (!strcmp(speedstr, "40000")) {
1354                         *speed = ETH_LINK_SPEED_40G;
1355                 } else if (!strcmp(speedstr, "50000")) {
1356                         *speed = ETH_LINK_SPEED_50G;
1357                 } else if (!strcmp(speedstr, "100000")) {
1358                         *speed = ETH_LINK_SPEED_100G;
1359                 } else if (!strcmp(speedstr, "auto")) {
1360                         *speed = ETH_LINK_SPEED_AUTONEG;
1361                 } else {
1362                         printf("Unknown speed parameter\n");
1363                         return -1;
1364                 }
1365         }
1366
1367         return 0;
1368 }
1369
1370 static void
1371 cmd_config_speed_all_parsed(void *parsed_result,
1372                         __attribute__((unused)) struct cmdline *cl,
1373                         __attribute__((unused)) void *data)
1374 {
1375         struct cmd_config_speed_all *res = parsed_result;
1376         uint32_t link_speed;
1377         portid_t pid;
1378
1379         if (!all_ports_stopped()) {
1380                 printf("Please stop all ports first\n");
1381                 return;
1382         }
1383
1384         if (parse_and_check_speed_duplex(res->value1, res->value2,
1385                         &link_speed) < 0)
1386                 return;
1387
1388         RTE_ETH_FOREACH_DEV(pid) {
1389                 ports[pid].dev_conf.link_speeds = link_speed;
1390         }
1391
1392         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1393 }
1394
1395 cmdline_parse_token_string_t cmd_config_speed_all_port =
1396         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1397 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1398         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1399                                                         "config");
1400 cmdline_parse_token_string_t cmd_config_speed_all_all =
1401         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1402 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1403         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1404 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1405         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1406                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1407 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1408         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1409 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1410         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1411                                                 "half#full#auto");
1412
1413 cmdline_parse_inst_t cmd_config_speed_all = {
1414         .f = cmd_config_speed_all_parsed,
1415         .data = NULL,
1416         .help_str = "port config all speed "
1417                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1418                                                         "half|full|auto",
1419         .tokens = {
1420                 (void *)&cmd_config_speed_all_port,
1421                 (void *)&cmd_config_speed_all_keyword,
1422                 (void *)&cmd_config_speed_all_all,
1423                 (void *)&cmd_config_speed_all_item1,
1424                 (void *)&cmd_config_speed_all_value1,
1425                 (void *)&cmd_config_speed_all_item2,
1426                 (void *)&cmd_config_speed_all_value2,
1427                 NULL,
1428         },
1429 };
1430
1431 /* *** configure speed for specific port *** */
1432 struct cmd_config_speed_specific {
1433         cmdline_fixed_string_t port;
1434         cmdline_fixed_string_t keyword;
1435         portid_t id;
1436         cmdline_fixed_string_t item1;
1437         cmdline_fixed_string_t item2;
1438         cmdline_fixed_string_t value1;
1439         cmdline_fixed_string_t value2;
1440 };
1441
1442 static void
1443 cmd_config_speed_specific_parsed(void *parsed_result,
1444                                 __attribute__((unused)) struct cmdline *cl,
1445                                 __attribute__((unused)) void *data)
1446 {
1447         struct cmd_config_speed_specific *res = parsed_result;
1448         uint32_t link_speed;
1449
1450         if (!all_ports_stopped()) {
1451                 printf("Please stop all ports first\n");
1452                 return;
1453         }
1454
1455         if (port_id_is_invalid(res->id, ENABLED_WARN))
1456                 return;
1457
1458         if (parse_and_check_speed_duplex(res->value1, res->value2,
1459                         &link_speed) < 0)
1460                 return;
1461
1462         ports[res->id].dev_conf.link_speeds = link_speed;
1463
1464         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1465 }
1466
1467
1468 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1470                                                                 "port");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1473                                                                 "config");
1474 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1475         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1476 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1477         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1478                                                                 "speed");
1479 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1480         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1481                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1482 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1483         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1484                                                                 "duplex");
1485 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1486         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1487                                                         "half#full#auto");
1488
1489 cmdline_parse_inst_t cmd_config_speed_specific = {
1490         .f = cmd_config_speed_specific_parsed,
1491         .data = NULL,
1492         .help_str = "port config <port_id> speed "
1493                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1494                                                         "half|full|auto",
1495         .tokens = {
1496                 (void *)&cmd_config_speed_specific_port,
1497                 (void *)&cmd_config_speed_specific_keyword,
1498                 (void *)&cmd_config_speed_specific_id,
1499                 (void *)&cmd_config_speed_specific_item1,
1500                 (void *)&cmd_config_speed_specific_value1,
1501                 (void *)&cmd_config_speed_specific_item2,
1502                 (void *)&cmd_config_speed_specific_value2,
1503                 NULL,
1504         },
1505 };
1506
1507 /* *** configure loopback for all ports *** */
1508 struct cmd_config_loopback_all {
1509         cmdline_fixed_string_t port;
1510         cmdline_fixed_string_t keyword;
1511         cmdline_fixed_string_t all;
1512         cmdline_fixed_string_t item;
1513         uint32_t mode;
1514 };
1515
1516 static void
1517 cmd_config_loopback_all_parsed(void *parsed_result,
1518                         __attribute__((unused)) struct cmdline *cl,
1519                         __attribute__((unused)) void *data)
1520 {
1521         struct cmd_config_loopback_all *res = parsed_result;
1522         portid_t pid;
1523
1524         if (!all_ports_stopped()) {
1525                 printf("Please stop all ports first\n");
1526                 return;
1527         }
1528
1529         RTE_ETH_FOREACH_DEV(pid) {
1530                 ports[pid].dev_conf.lpbk_mode = res->mode;
1531         }
1532
1533         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1534 }
1535
1536 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1537         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1538 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1539         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1540                                                         "config");
1541 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1542         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1543 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1544         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1545                                                         "loopback");
1546 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1547         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1548
1549 cmdline_parse_inst_t cmd_config_loopback_all = {
1550         .f = cmd_config_loopback_all_parsed,
1551         .data = NULL,
1552         .help_str = "port config all loopback <mode>",
1553         .tokens = {
1554                 (void *)&cmd_config_loopback_all_port,
1555                 (void *)&cmd_config_loopback_all_keyword,
1556                 (void *)&cmd_config_loopback_all_all,
1557                 (void *)&cmd_config_loopback_all_item,
1558                 (void *)&cmd_config_loopback_all_mode,
1559                 NULL,
1560         },
1561 };
1562
1563 /* *** configure loopback for specific port *** */
1564 struct cmd_config_loopback_specific {
1565         cmdline_fixed_string_t port;
1566         cmdline_fixed_string_t keyword;
1567         uint16_t port_id;
1568         cmdline_fixed_string_t item;
1569         uint32_t mode;
1570 };
1571
1572 static void
1573 cmd_config_loopback_specific_parsed(void *parsed_result,
1574                                 __attribute__((unused)) struct cmdline *cl,
1575                                 __attribute__((unused)) void *data)
1576 {
1577         struct cmd_config_loopback_specific *res = parsed_result;
1578
1579         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1580                 return;
1581
1582         if (!port_is_stopped(res->port_id)) {
1583                 printf("Please stop port %u first\n", res->port_id);
1584                 return;
1585         }
1586
1587         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1588
1589         cmd_reconfig_device_queue(res->port_id, 1, 1);
1590 }
1591
1592
1593 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1594         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1595                                                                 "port");
1596 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1597         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1598                                                                 "config");
1599 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1600         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1601                                                                 UINT16);
1602 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1603         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1604                                                                 "loopback");
1605 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1606         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1607                               UINT32);
1608
1609 cmdline_parse_inst_t cmd_config_loopback_specific = {
1610         .f = cmd_config_loopback_specific_parsed,
1611         .data = NULL,
1612         .help_str = "port config <port_id> loopback <mode>",
1613         .tokens = {
1614                 (void *)&cmd_config_loopback_specific_port,
1615                 (void *)&cmd_config_loopback_specific_keyword,
1616                 (void *)&cmd_config_loopback_specific_id,
1617                 (void *)&cmd_config_loopback_specific_item,
1618                 (void *)&cmd_config_loopback_specific_mode,
1619                 NULL,
1620         },
1621 };
1622
1623 /* *** configure txq/rxq, txd/rxd *** */
1624 struct cmd_config_rx_tx {
1625         cmdline_fixed_string_t port;
1626         cmdline_fixed_string_t keyword;
1627         cmdline_fixed_string_t all;
1628         cmdline_fixed_string_t name;
1629         uint16_t value;
1630 };
1631
1632 static void
1633 cmd_config_rx_tx_parsed(void *parsed_result,
1634                         __attribute__((unused)) struct cmdline *cl,
1635                         __attribute__((unused)) void *data)
1636 {
1637         struct cmd_config_rx_tx *res = parsed_result;
1638
1639         if (!all_ports_stopped()) {
1640                 printf("Please stop all ports first\n");
1641                 return;
1642         }
1643         if (!strcmp(res->name, "rxq")) {
1644                 if (!res->value && !nb_txq) {
1645                         printf("Warning: Either rx or tx queues should be non zero\n");
1646                         return;
1647                 }
1648                 if (check_nb_rxq(res->value) != 0)
1649                         return;
1650                 nb_rxq = res->value;
1651         }
1652         else if (!strcmp(res->name, "txq")) {
1653                 if (!res->value && !nb_rxq) {
1654                         printf("Warning: Either rx or tx queues should be non zero\n");
1655                         return;
1656                 }
1657                 if (check_nb_txq(res->value) != 0)
1658                         return;
1659                 nb_txq = res->value;
1660         }
1661         else if (!strcmp(res->name, "rxd")) {
1662                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1663                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1664                                         res->value, RTE_TEST_RX_DESC_MAX);
1665                         return;
1666                 }
1667                 nb_rxd = res->value;
1668         } else if (!strcmp(res->name, "txd")) {
1669                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1670                         printf("txd %d invalid - must be > 0 && <= %d\n",
1671                                         res->value, RTE_TEST_TX_DESC_MAX);
1672                         return;
1673                 }
1674                 nb_txd = res->value;
1675         } else {
1676                 printf("Unknown parameter\n");
1677                 return;
1678         }
1679
1680         fwd_config_setup();
1681
1682         init_port_config();
1683
1684         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1685 }
1686
1687 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1688         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1689 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1690         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1691 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1692         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1693 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1694         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1695                                                 "rxq#txq#rxd#txd");
1696 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1697         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1698
1699 cmdline_parse_inst_t cmd_config_rx_tx = {
1700         .f = cmd_config_rx_tx_parsed,
1701         .data = NULL,
1702         .help_str = "port config all rxq|txq|rxd|txd <value>",
1703         .tokens = {
1704                 (void *)&cmd_config_rx_tx_port,
1705                 (void *)&cmd_config_rx_tx_keyword,
1706                 (void *)&cmd_config_rx_tx_all,
1707                 (void *)&cmd_config_rx_tx_name,
1708                 (void *)&cmd_config_rx_tx_value,
1709                 NULL,
1710         },
1711 };
1712
1713 /* *** config max packet length *** */
1714 struct cmd_config_max_pkt_len_result {
1715         cmdline_fixed_string_t port;
1716         cmdline_fixed_string_t keyword;
1717         cmdline_fixed_string_t all;
1718         cmdline_fixed_string_t name;
1719         uint32_t value;
1720 };
1721
1722 static void
1723 cmd_config_max_pkt_len_parsed(void *parsed_result,
1724                                 __attribute__((unused)) struct cmdline *cl,
1725                                 __attribute__((unused)) void *data)
1726 {
1727         struct cmd_config_max_pkt_len_result *res = parsed_result;
1728         portid_t pid;
1729
1730         if (!all_ports_stopped()) {
1731                 printf("Please stop all ports first\n");
1732                 return;
1733         }
1734
1735         RTE_ETH_FOREACH_DEV(pid) {
1736                 struct rte_port *port = &ports[pid];
1737                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1738
1739                 if (!strcmp(res->name, "max-pkt-len")) {
1740                         if (res->value < ETHER_MIN_LEN) {
1741                                 printf("max-pkt-len can not be less than %d\n",
1742                                                 ETHER_MIN_LEN);
1743                                 return;
1744                         }
1745                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1746                                 return;
1747
1748                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1749                         if (res->value > ETHER_MAX_LEN)
1750                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1751                         else
1752                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1753                         port->dev_conf.rxmode.offloads = rx_offloads;
1754                 } else {
1755                         printf("Unknown parameter\n");
1756                         return;
1757                 }
1758         }
1759
1760         init_port_config();
1761
1762         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1763 }
1764
1765 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1766         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1767                                                                 "port");
1768 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1769         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1770                                                                 "config");
1771 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1772         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1773                                                                 "all");
1774 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1775         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1776                                                                 "max-pkt-len");
1777 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1778         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1779                                                                 UINT32);
1780
1781 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1782         .f = cmd_config_max_pkt_len_parsed,
1783         .data = NULL,
1784         .help_str = "port config all max-pkt-len <value>",
1785         .tokens = {
1786                 (void *)&cmd_config_max_pkt_len_port,
1787                 (void *)&cmd_config_max_pkt_len_keyword,
1788                 (void *)&cmd_config_max_pkt_len_all,
1789                 (void *)&cmd_config_max_pkt_len_name,
1790                 (void *)&cmd_config_max_pkt_len_value,
1791                 NULL,
1792         },
1793 };
1794
1795 /* *** configure port MTU *** */
1796 struct cmd_config_mtu_result {
1797         cmdline_fixed_string_t port;
1798         cmdline_fixed_string_t keyword;
1799         cmdline_fixed_string_t mtu;
1800         portid_t port_id;
1801         uint16_t value;
1802 };
1803
1804 static void
1805 cmd_config_mtu_parsed(void *parsed_result,
1806                       __attribute__((unused)) struct cmdline *cl,
1807                       __attribute__((unused)) void *data)
1808 {
1809         struct cmd_config_mtu_result *res = parsed_result;
1810
1811         if (res->value < ETHER_MIN_LEN) {
1812                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1813                 return;
1814         }
1815         port_mtu_set(res->port_id, res->value);
1816 }
1817
1818 cmdline_parse_token_string_t cmd_config_mtu_port =
1819         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1820                                  "port");
1821 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1822         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1823                                  "config");
1824 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1825         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1826                                  "mtu");
1827 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1828         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1829 cmdline_parse_token_num_t cmd_config_mtu_value =
1830         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1831
1832 cmdline_parse_inst_t cmd_config_mtu = {
1833         .f = cmd_config_mtu_parsed,
1834         .data = NULL,
1835         .help_str = "port config mtu <port_id> <value>",
1836         .tokens = {
1837                 (void *)&cmd_config_mtu_port,
1838                 (void *)&cmd_config_mtu_keyword,
1839                 (void *)&cmd_config_mtu_mtu,
1840                 (void *)&cmd_config_mtu_port_id,
1841                 (void *)&cmd_config_mtu_value,
1842                 NULL,
1843         },
1844 };
1845
1846 /* *** configure rx mode *** */
1847 struct cmd_config_rx_mode_flag {
1848         cmdline_fixed_string_t port;
1849         cmdline_fixed_string_t keyword;
1850         cmdline_fixed_string_t all;
1851         cmdline_fixed_string_t name;
1852         cmdline_fixed_string_t value;
1853 };
1854
1855 static void
1856 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1857                                 __attribute__((unused)) struct cmdline *cl,
1858                                 __attribute__((unused)) void *data)
1859 {
1860         struct cmd_config_rx_mode_flag *res = parsed_result;
1861         portid_t pid;
1862
1863         if (!all_ports_stopped()) {
1864                 printf("Please stop all ports first\n");
1865                 return;
1866         }
1867
1868         RTE_ETH_FOREACH_DEV(pid) {
1869                 struct rte_port *port;
1870                 uint64_t rx_offloads;
1871
1872                 port = &ports[pid];
1873                 rx_offloads = port->dev_conf.rxmode.offloads;
1874                 if (!strcmp(res->name, "crc-strip")) {
1875                         if (!strcmp(res->value, "on"))
1876                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1877                         else if (!strcmp(res->value, "off"))
1878                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1879                         else {
1880                                 printf("Unknown parameter\n");
1881                                 return;
1882                         }
1883                 } else if (!strcmp(res->name, "scatter")) {
1884                         if (!strcmp(res->value, "on")) {
1885                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1886                         } else if (!strcmp(res->value, "off")) {
1887                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1888                         } else {
1889                                 printf("Unknown parameter\n");
1890                                 return;
1891                         }
1892                 } else if (!strcmp(res->name, "rx-cksum")) {
1893                         if (!strcmp(res->value, "on"))
1894                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1895                         else if (!strcmp(res->value, "off"))
1896                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1897                         else {
1898                                 printf("Unknown parameter\n");
1899                                 return;
1900                         }
1901                 } else if (!strcmp(res->name, "rx-timestamp")) {
1902                         if (!strcmp(res->value, "on"))
1903                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1904                         else if (!strcmp(res->value, "off"))
1905                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1906                         else {
1907                                 printf("Unknown parameter\n");
1908                                 return;
1909                         }
1910                 } else if (!strcmp(res->name, "hw-vlan")) {
1911                         if (!strcmp(res->value, "on")) {
1912                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1913                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1914                         } else if (!strcmp(res->value, "off")) {
1915                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1916                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1917                         } else {
1918                                 printf("Unknown parameter\n");
1919                                 return;
1920                         }
1921                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1922                         if (!strcmp(res->value, "on"))
1923                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1924                         else if (!strcmp(res->value, "off"))
1925                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1926                         else {
1927                                 printf("Unknown parameter\n");
1928                                 return;
1929                         }
1930                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1931                         if (!strcmp(res->value, "on"))
1932                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1933                         else if (!strcmp(res->value, "off"))
1934                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1935                         else {
1936                                 printf("Unknown parameter\n");
1937                                 return;
1938                         }
1939                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1940                         if (!strcmp(res->value, "on"))
1941                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1942                         else if (!strcmp(res->value, "off"))
1943                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1944                         else {
1945                                 printf("Unknown parameter\n");
1946                                 return;
1947                         }
1948                 } else if (!strcmp(res->name, "drop-en")) {
1949                         if (!strcmp(res->value, "on"))
1950                                 rx_drop_en = 1;
1951                         else if (!strcmp(res->value, "off"))
1952                                 rx_drop_en = 0;
1953                         else {
1954                                 printf("Unknown parameter\n");
1955                                 return;
1956                         }
1957                 } else {
1958                         printf("Unknown parameter\n");
1959                         return;
1960                 }
1961                 port->dev_conf.rxmode.offloads = rx_offloads;
1962         }
1963
1964         init_port_config();
1965
1966         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1967 }
1968
1969 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1970         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1971 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1972         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1973                                                                 "config");
1974 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1975         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1976 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1977         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1978                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1979                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1980 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1981         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1982                                                         "on#off");
1983
1984 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1985         .f = cmd_config_rx_mode_flag_parsed,
1986         .data = NULL,
1987         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1988                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1989         .tokens = {
1990                 (void *)&cmd_config_rx_mode_flag_port,
1991                 (void *)&cmd_config_rx_mode_flag_keyword,
1992                 (void *)&cmd_config_rx_mode_flag_all,
1993                 (void *)&cmd_config_rx_mode_flag_name,
1994                 (void *)&cmd_config_rx_mode_flag_value,
1995                 NULL,
1996         },
1997 };
1998
1999 /* *** configure rss *** */
2000 struct cmd_config_rss {
2001         cmdline_fixed_string_t port;
2002         cmdline_fixed_string_t keyword;
2003         cmdline_fixed_string_t all;
2004         cmdline_fixed_string_t name;
2005         cmdline_fixed_string_t value;
2006 };
2007
2008 static void
2009 cmd_config_rss_parsed(void *parsed_result,
2010                         __attribute__((unused)) struct cmdline *cl,
2011                         __attribute__((unused)) void *data)
2012 {
2013         struct cmd_config_rss *res = parsed_result;
2014         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2015         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2016         int use_default = 0;
2017         int all_updated = 1;
2018         int diag;
2019         uint16_t i;
2020
2021         if (!strcmp(res->value, "all"))
2022                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2023                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2024                                         ETH_RSS_L2_PAYLOAD;
2025         else if (!strcmp(res->value, "ip"))
2026                 rss_conf.rss_hf = ETH_RSS_IP;
2027         else if (!strcmp(res->value, "udp"))
2028                 rss_conf.rss_hf = ETH_RSS_UDP;
2029         else if (!strcmp(res->value, "tcp"))
2030                 rss_conf.rss_hf = ETH_RSS_TCP;
2031         else if (!strcmp(res->value, "sctp"))
2032                 rss_conf.rss_hf = ETH_RSS_SCTP;
2033         else if (!strcmp(res->value, "ether"))
2034                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2035         else if (!strcmp(res->value, "port"))
2036                 rss_conf.rss_hf = ETH_RSS_PORT;
2037         else if (!strcmp(res->value, "vxlan"))
2038                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2039         else if (!strcmp(res->value, "geneve"))
2040                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2041         else if (!strcmp(res->value, "nvgre"))
2042                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2043         else if (!strcmp(res->value, "none"))
2044                 rss_conf.rss_hf = 0;
2045         else if (!strcmp(res->value, "default"))
2046                 use_default = 1;
2047         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2048                                                 atoi(res->value) < 64)
2049                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2050         else {
2051                 printf("Unknown parameter\n");
2052                 return;
2053         }
2054         rss_conf.rss_key = NULL;
2055         /* Update global configuration for RSS types. */
2056         RTE_ETH_FOREACH_DEV(i) {
2057                 if (use_default) {
2058                         rte_eth_dev_info_get(i, &dev_info);
2059                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2060                 }
2061                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
2062                 if (diag < 0) {
2063                         all_updated = 0;
2064                         printf("Configuration of RSS hash at ethernet port %d "
2065                                 "failed with error (%d): %s.\n",
2066                                 i, -diag, strerror(-diag));
2067                 }
2068         }
2069         if (all_updated && !use_default)
2070                 rss_hf = rss_conf.rss_hf;
2071 }
2072
2073 cmdline_parse_token_string_t cmd_config_rss_port =
2074         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2075 cmdline_parse_token_string_t cmd_config_rss_keyword =
2076         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2077 cmdline_parse_token_string_t cmd_config_rss_all =
2078         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2079 cmdline_parse_token_string_t cmd_config_rss_name =
2080         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2081 cmdline_parse_token_string_t cmd_config_rss_value =
2082         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2083
2084 cmdline_parse_inst_t cmd_config_rss = {
2085         .f = cmd_config_rss_parsed,
2086         .data = NULL,
2087         .help_str = "port config all rss "
2088                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2089         .tokens = {
2090                 (void *)&cmd_config_rss_port,
2091                 (void *)&cmd_config_rss_keyword,
2092                 (void *)&cmd_config_rss_all,
2093                 (void *)&cmd_config_rss_name,
2094                 (void *)&cmd_config_rss_value,
2095                 NULL,
2096         },
2097 };
2098
2099 /* *** configure rss hash key *** */
2100 struct cmd_config_rss_hash_key {
2101         cmdline_fixed_string_t port;
2102         cmdline_fixed_string_t config;
2103         portid_t port_id;
2104         cmdline_fixed_string_t rss_hash_key;
2105         cmdline_fixed_string_t rss_type;
2106         cmdline_fixed_string_t key;
2107 };
2108
2109 static uint8_t
2110 hexa_digit_to_value(char hexa_digit)
2111 {
2112         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2113                 return (uint8_t) (hexa_digit - '0');
2114         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2115                 return (uint8_t) ((hexa_digit - 'a') + 10);
2116         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2117                 return (uint8_t) ((hexa_digit - 'A') + 10);
2118         /* Invalid hexa digit */
2119         return 0xFF;
2120 }
2121
2122 static uint8_t
2123 parse_and_check_key_hexa_digit(char *key, int idx)
2124 {
2125         uint8_t hexa_v;
2126
2127         hexa_v = hexa_digit_to_value(key[idx]);
2128         if (hexa_v == 0xFF)
2129                 printf("invalid key: character %c at position %d is not a "
2130                        "valid hexa digit\n", key[idx], idx);
2131         return hexa_v;
2132 }
2133
2134 static void
2135 cmd_config_rss_hash_key_parsed(void *parsed_result,
2136                                __attribute__((unused)) struct cmdline *cl,
2137                                __attribute__((unused)) void *data)
2138 {
2139         struct cmd_config_rss_hash_key *res = parsed_result;
2140         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2141         uint8_t xdgt0;
2142         uint8_t xdgt1;
2143         int i;
2144         struct rte_eth_dev_info dev_info;
2145         uint8_t hash_key_size;
2146         uint32_t key_len;
2147
2148         memset(&dev_info, 0, sizeof(dev_info));
2149         rte_eth_dev_info_get(res->port_id, &dev_info);
2150         if (dev_info.hash_key_size > 0 &&
2151                         dev_info.hash_key_size <= sizeof(hash_key))
2152                 hash_key_size = dev_info.hash_key_size;
2153         else {
2154                 printf("dev_info did not provide a valid hash key size\n");
2155                 return;
2156         }
2157         /* Check the length of the RSS hash key */
2158         key_len = strlen(res->key);
2159         if (key_len != (hash_key_size * 2)) {
2160                 printf("key length: %d invalid - key must be a string of %d"
2161                            " hexa-decimal numbers\n",
2162                            (int) key_len, hash_key_size * 2);
2163                 return;
2164         }
2165         /* Translate RSS hash key into binary representation */
2166         for (i = 0; i < hash_key_size; i++) {
2167                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2168                 if (xdgt0 == 0xFF)
2169                         return;
2170                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2171                 if (xdgt1 == 0xFF)
2172                         return;
2173                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2174         }
2175         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2176                         hash_key_size);
2177 }
2178
2179 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2180         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2181 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2182         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2183                                  "config");
2184 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2185         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2186 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2187         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2188                                  rss_hash_key, "rss-hash-key");
2189 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2190         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2191                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2192                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2193                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2194                                  "ipv6-tcp-ex#ipv6-udp-ex");
2195 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2196         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2197
2198 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2199         .f = cmd_config_rss_hash_key_parsed,
2200         .data = NULL,
2201         .help_str = "port config <port_id> rss-hash-key "
2202                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2203                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2204                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2205                 "<string of hex digits (variable length, NIC dependent)>",
2206         .tokens = {
2207                 (void *)&cmd_config_rss_hash_key_port,
2208                 (void *)&cmd_config_rss_hash_key_config,
2209                 (void *)&cmd_config_rss_hash_key_port_id,
2210                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2211                 (void *)&cmd_config_rss_hash_key_rss_type,
2212                 (void *)&cmd_config_rss_hash_key_value,
2213                 NULL,
2214         },
2215 };
2216
2217 /* *** configure port rxq/txq ring size *** */
2218 struct cmd_config_rxtx_ring_size {
2219         cmdline_fixed_string_t port;
2220         cmdline_fixed_string_t config;
2221         portid_t portid;
2222         cmdline_fixed_string_t rxtxq;
2223         uint16_t qid;
2224         cmdline_fixed_string_t rsize;
2225         uint16_t size;
2226 };
2227
2228 static void
2229 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2230                                  __attribute__((unused)) struct cmdline *cl,
2231                                  __attribute__((unused)) void *data)
2232 {
2233         struct cmd_config_rxtx_ring_size *res = parsed_result;
2234         struct rte_port *port;
2235         uint8_t isrx;
2236
2237         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2238                 return;
2239
2240         if (res->portid == (portid_t)RTE_PORT_ALL) {
2241                 printf("Invalid port id\n");
2242                 return;
2243         }
2244
2245         port = &ports[res->portid];
2246
2247         if (!strcmp(res->rxtxq, "rxq"))
2248                 isrx = 1;
2249         else if (!strcmp(res->rxtxq, "txq"))
2250                 isrx = 0;
2251         else {
2252                 printf("Unknown parameter\n");
2253                 return;
2254         }
2255
2256         if (isrx && rx_queue_id_is_invalid(res->qid))
2257                 return;
2258         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2259                 return;
2260
2261         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2262                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2263                        rx_free_thresh);
2264                 return;
2265         }
2266
2267         if (isrx)
2268                 port->nb_rx_desc[res->qid] = res->size;
2269         else
2270                 port->nb_tx_desc[res->qid] = res->size;
2271
2272         cmd_reconfig_device_queue(res->portid, 0, 1);
2273 }
2274
2275 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2276         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2277                                  port, "port");
2278 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2279         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2280                                  config, "config");
2281 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2282         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2283                                  portid, UINT16);
2284 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2285         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2286                                  rxtxq, "rxq#txq");
2287 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2288         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2289                               qid, UINT16);
2290 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2291         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2292                                  rsize, "ring_size");
2293 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2294         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2295                               size, UINT16);
2296
2297 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2298         .f = cmd_config_rxtx_ring_size_parsed,
2299         .data = NULL,
2300         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2301         .tokens = {
2302                 (void *)&cmd_config_rxtx_ring_size_port,
2303                 (void *)&cmd_config_rxtx_ring_size_config,
2304                 (void *)&cmd_config_rxtx_ring_size_portid,
2305                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2306                 (void *)&cmd_config_rxtx_ring_size_qid,
2307                 (void *)&cmd_config_rxtx_ring_size_rsize,
2308                 (void *)&cmd_config_rxtx_ring_size_size,
2309                 NULL,
2310         },
2311 };
2312
2313 /* *** configure port rxq/txq start/stop *** */
2314 struct cmd_config_rxtx_queue {
2315         cmdline_fixed_string_t port;
2316         portid_t portid;
2317         cmdline_fixed_string_t rxtxq;
2318         uint16_t qid;
2319         cmdline_fixed_string_t opname;
2320 };
2321
2322 static void
2323 cmd_config_rxtx_queue_parsed(void *parsed_result,
2324                         __attribute__((unused)) struct cmdline *cl,
2325                         __attribute__((unused)) void *data)
2326 {
2327         struct cmd_config_rxtx_queue *res = parsed_result;
2328         uint8_t isrx;
2329         uint8_t isstart;
2330         int ret = 0;
2331
2332         if (test_done == 0) {
2333                 printf("Please stop forwarding first\n");
2334                 return;
2335         }
2336
2337         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2338                 return;
2339
2340         if (port_is_started(res->portid) != 1) {
2341                 printf("Please start port %u first\n", res->portid);
2342                 return;
2343         }
2344
2345         if (!strcmp(res->rxtxq, "rxq"))
2346                 isrx = 1;
2347         else if (!strcmp(res->rxtxq, "txq"))
2348                 isrx = 0;
2349         else {
2350                 printf("Unknown parameter\n");
2351                 return;
2352         }
2353
2354         if (isrx && rx_queue_id_is_invalid(res->qid))
2355                 return;
2356         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2357                 return;
2358
2359         if (!strcmp(res->opname, "start"))
2360                 isstart = 1;
2361         else if (!strcmp(res->opname, "stop"))
2362                 isstart = 0;
2363         else {
2364                 printf("Unknown parameter\n");
2365                 return;
2366         }
2367
2368         if (isstart && isrx)
2369                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2370         else if (!isstart && isrx)
2371                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2372         else if (isstart && !isrx)
2373                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2374         else
2375                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2376
2377         if (ret == -ENOTSUP)
2378                 printf("Function not supported in PMD driver\n");
2379 }
2380
2381 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2382         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2383 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2384         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2385 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2386         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2387 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2388         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2389 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2390         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2391                                                 "start#stop");
2392
2393 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2394         .f = cmd_config_rxtx_queue_parsed,
2395         .data = NULL,
2396         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2397         .tokens = {
2398                 (void *)&cmd_config_rxtx_queue_port,
2399                 (void *)&cmd_config_rxtx_queue_portid,
2400                 (void *)&cmd_config_rxtx_queue_rxtxq,
2401                 (void *)&cmd_config_rxtx_queue_qid,
2402                 (void *)&cmd_config_rxtx_queue_opname,
2403                 NULL,
2404         },
2405 };
2406
2407 /* *** configure port rxq/txq setup *** */
2408 struct cmd_setup_rxtx_queue {
2409         cmdline_fixed_string_t port;
2410         portid_t portid;
2411         cmdline_fixed_string_t rxtxq;
2412         uint16_t qid;
2413         cmdline_fixed_string_t setup;
2414 };
2415
2416 /* Common CLI fields for queue setup */
2417 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2418         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2419 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2420         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2421 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2422         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2423 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2424         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2425 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2426         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2427
2428 static void
2429 cmd_setup_rxtx_queue_parsed(
2430         void *parsed_result,
2431         __attribute__((unused)) struct cmdline *cl,
2432         __attribute__((unused)) void *data)
2433 {
2434         struct cmd_setup_rxtx_queue *res = parsed_result;
2435         struct rte_port *port;
2436         struct rte_mempool *mp;
2437         unsigned int socket_id;
2438         uint8_t isrx = 0;
2439         int ret;
2440
2441         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2442                 return;
2443
2444         if (res->portid == (portid_t)RTE_PORT_ALL) {
2445                 printf("Invalid port id\n");
2446                 return;
2447         }
2448
2449         if (!strcmp(res->rxtxq, "rxq"))
2450                 isrx = 1;
2451         else if (!strcmp(res->rxtxq, "txq"))
2452                 isrx = 0;
2453         else {
2454                 printf("Unknown parameter\n");
2455                 return;
2456         }
2457
2458         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2459                 printf("Invalid rx queue\n");
2460                 return;
2461         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2462                 printf("Invalid tx queue\n");
2463                 return;
2464         }
2465
2466         port = &ports[res->portid];
2467         if (isrx) {
2468                 socket_id = rxring_numa[res->portid];
2469                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2470                         socket_id = port->socket_id;
2471
2472                 mp = mbuf_pool_find(socket_id);
2473                 if (mp == NULL) {
2474                         printf("Failed to setup RX queue: "
2475                                 "No mempool allocation"
2476                                 " on the socket %d\n",
2477                                 rxring_numa[res->portid]);
2478                         return;
2479                 }
2480                 ret = rte_eth_rx_queue_setup(res->portid,
2481                                              res->qid,
2482                                              port->nb_rx_desc[res->qid],
2483                                              socket_id,
2484                                              &port->rx_conf[res->qid],
2485                                              mp);
2486                 if (ret)
2487                         printf("Failed to setup RX queue\n");
2488         } else {
2489                 socket_id = txring_numa[res->portid];
2490                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2491                         socket_id = port->socket_id;
2492
2493                 ret = rte_eth_tx_queue_setup(res->portid,
2494                                              res->qid,
2495                                              port->nb_tx_desc[res->qid],
2496                                              socket_id,
2497                                              &port->tx_conf[res->qid]);
2498                 if (ret)
2499                         printf("Failed to setup TX queue\n");
2500         }
2501 }
2502
2503 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2504         .f = cmd_setup_rxtx_queue_parsed,
2505         .data = NULL,
2506         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2507         .tokens = {
2508                 (void *)&cmd_setup_rxtx_queue_port,
2509                 (void *)&cmd_setup_rxtx_queue_portid,
2510                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2511                 (void *)&cmd_setup_rxtx_queue_qid,
2512                 (void *)&cmd_setup_rxtx_queue_setup,
2513                 NULL,
2514         },
2515 };
2516
2517
2518 /* *** Configure RSS RETA *** */
2519 struct cmd_config_rss_reta {
2520         cmdline_fixed_string_t port;
2521         cmdline_fixed_string_t keyword;
2522         portid_t port_id;
2523         cmdline_fixed_string_t name;
2524         cmdline_fixed_string_t list_name;
2525         cmdline_fixed_string_t list_of_items;
2526 };
2527
2528 static int
2529 parse_reta_config(const char *str,
2530                   struct rte_eth_rss_reta_entry64 *reta_conf,
2531                   uint16_t nb_entries)
2532 {
2533         int i;
2534         unsigned size;
2535         uint16_t hash_index, idx, shift;
2536         uint16_t nb_queue;
2537         char s[256];
2538         const char *p, *p0 = str;
2539         char *end;
2540         enum fieldnames {
2541                 FLD_HASH_INDEX = 0,
2542                 FLD_QUEUE,
2543                 _NUM_FLD
2544         };
2545         unsigned long int_fld[_NUM_FLD];
2546         char *str_fld[_NUM_FLD];
2547
2548         while ((p = strchr(p0,'(')) != NULL) {
2549                 ++p;
2550                 if((p0 = strchr(p,')')) == NULL)
2551                         return -1;
2552
2553                 size = p0 - p;
2554                 if(size >= sizeof(s))
2555                         return -1;
2556
2557                 snprintf(s, sizeof(s), "%.*s", size, p);
2558                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2559                         return -1;
2560                 for (i = 0; i < _NUM_FLD; i++) {
2561                         errno = 0;
2562                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2563                         if (errno != 0 || end == str_fld[i] ||
2564                                         int_fld[i] > 65535)
2565                                 return -1;
2566                 }
2567
2568                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2569                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2570
2571                 if (hash_index >= nb_entries) {
2572                         printf("Invalid RETA hash index=%d\n", hash_index);
2573                         return -1;
2574                 }
2575
2576                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2577                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2578                 reta_conf[idx].mask |= (1ULL << shift);
2579                 reta_conf[idx].reta[shift] = nb_queue;
2580         }
2581
2582         return 0;
2583 }
2584
2585 static void
2586 cmd_set_rss_reta_parsed(void *parsed_result,
2587                         __attribute__((unused)) struct cmdline *cl,
2588                         __attribute__((unused)) void *data)
2589 {
2590         int ret;
2591         struct rte_eth_dev_info dev_info;
2592         struct rte_eth_rss_reta_entry64 reta_conf[8];
2593         struct cmd_config_rss_reta *res = parsed_result;
2594
2595         memset(&dev_info, 0, sizeof(dev_info));
2596         rte_eth_dev_info_get(res->port_id, &dev_info);
2597         if (dev_info.reta_size == 0) {
2598                 printf("Redirection table size is 0 which is "
2599                                         "invalid for RSS\n");
2600                 return;
2601         } else
2602                 printf("The reta size of port %d is %u\n",
2603                         res->port_id, dev_info.reta_size);
2604         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2605                 printf("Currently do not support more than %u entries of "
2606                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2607                 return;
2608         }
2609
2610         memset(reta_conf, 0, sizeof(reta_conf));
2611         if (!strcmp(res->list_name, "reta")) {
2612                 if (parse_reta_config(res->list_of_items, reta_conf,
2613                                                 dev_info.reta_size)) {
2614                         printf("Invalid RSS Redirection Table "
2615                                         "config entered\n");
2616                         return;
2617                 }
2618                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2619                                 reta_conf, dev_info.reta_size);
2620                 if (ret != 0)
2621                         printf("Bad redirection table parameter, "
2622                                         "return code = %d \n", ret);
2623         }
2624 }
2625
2626 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2627         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2628 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2629         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2630 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2631         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2632 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2633         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2634 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2635         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2636 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2637         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2638                                  NULL);
2639 cmdline_parse_inst_t cmd_config_rss_reta = {
2640         .f = cmd_set_rss_reta_parsed,
2641         .data = NULL,
2642         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2643         .tokens = {
2644                 (void *)&cmd_config_rss_reta_port,
2645                 (void *)&cmd_config_rss_reta_keyword,
2646                 (void *)&cmd_config_rss_reta_port_id,
2647                 (void *)&cmd_config_rss_reta_name,
2648                 (void *)&cmd_config_rss_reta_list_name,
2649                 (void *)&cmd_config_rss_reta_list_of_items,
2650                 NULL,
2651         },
2652 };
2653
2654 /* *** SHOW PORT RETA INFO *** */
2655 struct cmd_showport_reta {
2656         cmdline_fixed_string_t show;
2657         cmdline_fixed_string_t port;
2658         portid_t port_id;
2659         cmdline_fixed_string_t rss;
2660         cmdline_fixed_string_t reta;
2661         uint16_t size;
2662         cmdline_fixed_string_t list_of_items;
2663 };
2664
2665 static int
2666 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2667                            uint16_t nb_entries,
2668                            char *str)
2669 {
2670         uint32_t size;
2671         const char *p, *p0 = str;
2672         char s[256];
2673         char *end;
2674         char *str_fld[8];
2675         uint16_t i;
2676         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2677                         RTE_RETA_GROUP_SIZE;
2678         int ret;
2679
2680         p = strchr(p0, '(');
2681         if (p == NULL)
2682                 return -1;
2683         p++;
2684         p0 = strchr(p, ')');
2685         if (p0 == NULL)
2686                 return -1;
2687         size = p0 - p;
2688         if (size >= sizeof(s)) {
2689                 printf("The string size exceeds the internal buffer size\n");
2690                 return -1;
2691         }
2692         snprintf(s, sizeof(s), "%.*s", size, p);
2693         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2694         if (ret <= 0 || ret != num) {
2695                 printf("The bits of masks do not match the number of "
2696                                         "reta entries: %u\n", num);
2697                 return -1;
2698         }
2699         for (i = 0; i < ret; i++)
2700                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2701
2702         return 0;
2703 }
2704
2705 static void
2706 cmd_showport_reta_parsed(void *parsed_result,
2707                          __attribute__((unused)) struct cmdline *cl,
2708                          __attribute__((unused)) void *data)
2709 {
2710         struct cmd_showport_reta *res = parsed_result;
2711         struct rte_eth_rss_reta_entry64 reta_conf[8];
2712         struct rte_eth_dev_info dev_info;
2713         uint16_t max_reta_size;
2714
2715         memset(&dev_info, 0, sizeof(dev_info));
2716         rte_eth_dev_info_get(res->port_id, &dev_info);
2717         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2718         if (res->size == 0 || res->size > max_reta_size) {
2719                 printf("Invalid redirection table size: %u (1-%u)\n",
2720                         res->size, max_reta_size);
2721                 return;
2722         }
2723
2724         memset(reta_conf, 0, sizeof(reta_conf));
2725         if (showport_parse_reta_config(reta_conf, res->size,
2726                                 res->list_of_items) < 0) {
2727                 printf("Invalid string: %s for reta masks\n",
2728                                         res->list_of_items);
2729                 return;
2730         }
2731         port_rss_reta_info(res->port_id, reta_conf, res->size);
2732 }
2733
2734 cmdline_parse_token_string_t cmd_showport_reta_show =
2735         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2736 cmdline_parse_token_string_t cmd_showport_reta_port =
2737         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2738 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2739         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2740 cmdline_parse_token_string_t cmd_showport_reta_rss =
2741         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2742 cmdline_parse_token_string_t cmd_showport_reta_reta =
2743         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2744 cmdline_parse_token_num_t cmd_showport_reta_size =
2745         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2746 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2747         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2748                                         list_of_items, NULL);
2749
2750 cmdline_parse_inst_t cmd_showport_reta = {
2751         .f = cmd_showport_reta_parsed,
2752         .data = NULL,
2753         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2754         .tokens = {
2755                 (void *)&cmd_showport_reta_show,
2756                 (void *)&cmd_showport_reta_port,
2757                 (void *)&cmd_showport_reta_port_id,
2758                 (void *)&cmd_showport_reta_rss,
2759                 (void *)&cmd_showport_reta_reta,
2760                 (void *)&cmd_showport_reta_size,
2761                 (void *)&cmd_showport_reta_list_of_items,
2762                 NULL,
2763         },
2764 };
2765
2766 /* *** Show RSS hash configuration *** */
2767 struct cmd_showport_rss_hash {
2768         cmdline_fixed_string_t show;
2769         cmdline_fixed_string_t port;
2770         portid_t port_id;
2771         cmdline_fixed_string_t rss_hash;
2772         cmdline_fixed_string_t rss_type;
2773         cmdline_fixed_string_t key; /* optional argument */
2774 };
2775
2776 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2777                                 __attribute__((unused)) struct cmdline *cl,
2778                                 void *show_rss_key)
2779 {
2780         struct cmd_showport_rss_hash *res = parsed_result;
2781
2782         port_rss_hash_conf_show(res->port_id, res->rss_type,
2783                                 show_rss_key != NULL);
2784 }
2785
2786 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2787         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2788 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2789         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2790 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2791         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2792 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2793         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2794                                  "rss-hash");
2795 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2796         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2797                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2798                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2799                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2800                                  "ipv6-tcp-ex#ipv6-udp-ex");
2801 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2802         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2803
2804 cmdline_parse_inst_t cmd_showport_rss_hash = {
2805         .f = cmd_showport_rss_hash_parsed,
2806         .data = NULL,
2807         .help_str = "show port <port_id> rss-hash "
2808                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2809                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2810                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2811         .tokens = {
2812                 (void *)&cmd_showport_rss_hash_show,
2813                 (void *)&cmd_showport_rss_hash_port,
2814                 (void *)&cmd_showport_rss_hash_port_id,
2815                 (void *)&cmd_showport_rss_hash_rss_hash,
2816                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2817                 NULL,
2818         },
2819 };
2820
2821 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2822         .f = cmd_showport_rss_hash_parsed,
2823         .data = (void *)1,
2824         .help_str = "show port <port_id> rss-hash "
2825                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2826                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2827                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2828         .tokens = {
2829                 (void *)&cmd_showport_rss_hash_show,
2830                 (void *)&cmd_showport_rss_hash_port,
2831                 (void *)&cmd_showport_rss_hash_port_id,
2832                 (void *)&cmd_showport_rss_hash_rss_hash,
2833                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2834                 (void *)&cmd_showport_rss_hash_rss_key,
2835                 NULL,
2836         },
2837 };
2838
2839 /* *** Configure DCB *** */
2840 struct cmd_config_dcb {
2841         cmdline_fixed_string_t port;
2842         cmdline_fixed_string_t config;
2843         portid_t port_id;
2844         cmdline_fixed_string_t dcb;
2845         cmdline_fixed_string_t vt;
2846         cmdline_fixed_string_t vt_en;
2847         uint8_t num_tcs;
2848         cmdline_fixed_string_t pfc;
2849         cmdline_fixed_string_t pfc_en;
2850 };
2851
2852 static void
2853 cmd_config_dcb_parsed(void *parsed_result,
2854                         __attribute__((unused)) struct cmdline *cl,
2855                         __attribute__((unused)) void *data)
2856 {
2857         struct cmd_config_dcb *res = parsed_result;
2858         portid_t port_id = res->port_id;
2859         struct rte_port *port;
2860         uint8_t pfc_en;
2861         int ret;
2862
2863         port = &ports[port_id];
2864         /** Check if the port is not started **/
2865         if (port->port_status != RTE_PORT_STOPPED) {
2866                 printf("Please stop port %d first\n", port_id);
2867                 return;
2868         }
2869
2870         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2871                 printf("The invalid number of traffic class,"
2872                         " only 4 or 8 allowed.\n");
2873                 return;
2874         }
2875
2876         if (nb_fwd_lcores < res->num_tcs) {
2877                 printf("nb_cores shouldn't be less than number of TCs.\n");
2878                 return;
2879         }
2880         if (!strncmp(res->pfc_en, "on", 2))
2881                 pfc_en = 1;
2882         else
2883                 pfc_en = 0;
2884
2885         /* DCB in VT mode */
2886         if (!strncmp(res->vt_en, "on", 2))
2887                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2888                                 (enum rte_eth_nb_tcs)res->num_tcs,
2889                                 pfc_en);
2890         else
2891                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2892                                 (enum rte_eth_nb_tcs)res->num_tcs,
2893                                 pfc_en);
2894
2895
2896         if (ret != 0) {
2897                 printf("Cannot initialize network ports.\n");
2898                 return;
2899         }
2900
2901         cmd_reconfig_device_queue(port_id, 1, 1);
2902 }
2903
2904 cmdline_parse_token_string_t cmd_config_dcb_port =
2905         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2906 cmdline_parse_token_string_t cmd_config_dcb_config =
2907         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2908 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2909         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2910 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2911         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2912 cmdline_parse_token_string_t cmd_config_dcb_vt =
2913         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2914 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2915         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2916 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2917         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2918 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2919         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2920 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2921         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2922
2923 cmdline_parse_inst_t cmd_config_dcb = {
2924         .f = cmd_config_dcb_parsed,
2925         .data = NULL,
2926         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2927         .tokens = {
2928                 (void *)&cmd_config_dcb_port,
2929                 (void *)&cmd_config_dcb_config,
2930                 (void *)&cmd_config_dcb_port_id,
2931                 (void *)&cmd_config_dcb_dcb,
2932                 (void *)&cmd_config_dcb_vt,
2933                 (void *)&cmd_config_dcb_vt_en,
2934                 (void *)&cmd_config_dcb_num_tcs,
2935                 (void *)&cmd_config_dcb_pfc,
2936                 (void *)&cmd_config_dcb_pfc_en,
2937                 NULL,
2938         },
2939 };
2940
2941 /* *** configure number of packets per burst *** */
2942 struct cmd_config_burst {
2943         cmdline_fixed_string_t port;
2944         cmdline_fixed_string_t keyword;
2945         cmdline_fixed_string_t all;
2946         cmdline_fixed_string_t name;
2947         uint16_t value;
2948 };
2949
2950 static void
2951 cmd_config_burst_parsed(void *parsed_result,
2952                         __attribute__((unused)) struct cmdline *cl,
2953                         __attribute__((unused)) void *data)
2954 {
2955         struct cmd_config_burst *res = parsed_result;
2956         struct rte_eth_dev_info dev_info;
2957         uint16_t rec_nb_pkts;
2958
2959         if (!all_ports_stopped()) {
2960                 printf("Please stop all ports first\n");
2961                 return;
2962         }
2963
2964         if (!strcmp(res->name, "burst")) {
2965                 if (res->value == 0) {
2966                         /* If user gives a value of zero, query the PMD for
2967                          * its recommended Rx burst size. Testpmd uses a single
2968                          * size for all ports, so assume all ports are the same
2969                          * NIC model and use the values from Port 0.
2970                          */
2971                         rte_eth_dev_info_get(0, &dev_info);
2972                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
2973
2974                         if (rec_nb_pkts == 0) {
2975                                 printf("PMD does not recommend a burst size.\n"
2976                                         "User provided value must be between"
2977                                         " 1 and %d\n", MAX_PKT_BURST);
2978                                 return;
2979                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
2980                                 printf("PMD recommended burst size of %d"
2981                                         " exceeds maximum value of %d\n",
2982                                         rec_nb_pkts, MAX_PKT_BURST);
2983                                 return;
2984                         }
2985                         printf("Using PMD-provided burst value of %d\n",
2986                                 rec_nb_pkts);
2987                         nb_pkt_per_burst = rec_nb_pkts;
2988                 } else if (res->value > MAX_PKT_BURST) {
2989                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2990                         return;
2991                 } else
2992                         nb_pkt_per_burst = res->value;
2993         } else {
2994                 printf("Unknown parameter\n");
2995                 return;
2996         }
2997
2998         init_port_config();
2999
3000         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3001 }
3002
3003 cmdline_parse_token_string_t cmd_config_burst_port =
3004         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3005 cmdline_parse_token_string_t cmd_config_burst_keyword =
3006         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3007 cmdline_parse_token_string_t cmd_config_burst_all =
3008         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3009 cmdline_parse_token_string_t cmd_config_burst_name =
3010         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3011 cmdline_parse_token_num_t cmd_config_burst_value =
3012         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3013
3014 cmdline_parse_inst_t cmd_config_burst = {
3015         .f = cmd_config_burst_parsed,
3016         .data = NULL,
3017         .help_str = "port config all burst <value>",
3018         .tokens = {
3019                 (void *)&cmd_config_burst_port,
3020                 (void *)&cmd_config_burst_keyword,
3021                 (void *)&cmd_config_burst_all,
3022                 (void *)&cmd_config_burst_name,
3023                 (void *)&cmd_config_burst_value,
3024                 NULL,
3025         },
3026 };
3027
3028 /* *** configure rx/tx queues *** */
3029 struct cmd_config_thresh {
3030         cmdline_fixed_string_t port;
3031         cmdline_fixed_string_t keyword;
3032         cmdline_fixed_string_t all;
3033         cmdline_fixed_string_t name;
3034         uint8_t value;
3035 };
3036
3037 static void
3038 cmd_config_thresh_parsed(void *parsed_result,
3039                         __attribute__((unused)) struct cmdline *cl,
3040                         __attribute__((unused)) void *data)
3041 {
3042         struct cmd_config_thresh *res = parsed_result;
3043
3044         if (!all_ports_stopped()) {
3045                 printf("Please stop all ports first\n");
3046                 return;
3047         }
3048
3049         if (!strcmp(res->name, "txpt"))
3050                 tx_pthresh = res->value;
3051         else if(!strcmp(res->name, "txht"))
3052                 tx_hthresh = res->value;
3053         else if(!strcmp(res->name, "txwt"))
3054                 tx_wthresh = res->value;
3055         else if(!strcmp(res->name, "rxpt"))
3056                 rx_pthresh = res->value;
3057         else if(!strcmp(res->name, "rxht"))
3058                 rx_hthresh = res->value;
3059         else if(!strcmp(res->name, "rxwt"))
3060                 rx_wthresh = res->value;
3061         else {
3062                 printf("Unknown parameter\n");
3063                 return;
3064         }
3065
3066         init_port_config();
3067
3068         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3069 }
3070
3071 cmdline_parse_token_string_t cmd_config_thresh_port =
3072         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3073 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3074         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3075 cmdline_parse_token_string_t cmd_config_thresh_all =
3076         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3077 cmdline_parse_token_string_t cmd_config_thresh_name =
3078         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3079                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3080 cmdline_parse_token_num_t cmd_config_thresh_value =
3081         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3082
3083 cmdline_parse_inst_t cmd_config_thresh = {
3084         .f = cmd_config_thresh_parsed,
3085         .data = NULL,
3086         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3087         .tokens = {
3088                 (void *)&cmd_config_thresh_port,
3089                 (void *)&cmd_config_thresh_keyword,
3090                 (void *)&cmd_config_thresh_all,
3091                 (void *)&cmd_config_thresh_name,
3092                 (void *)&cmd_config_thresh_value,
3093                 NULL,
3094         },
3095 };
3096
3097 /* *** configure free/rs threshold *** */
3098 struct cmd_config_threshold {
3099         cmdline_fixed_string_t port;
3100         cmdline_fixed_string_t keyword;
3101         cmdline_fixed_string_t all;
3102         cmdline_fixed_string_t name;
3103         uint16_t value;
3104 };
3105
3106 static void
3107 cmd_config_threshold_parsed(void *parsed_result,
3108                         __attribute__((unused)) struct cmdline *cl,
3109                         __attribute__((unused)) void *data)
3110 {
3111         struct cmd_config_threshold *res = parsed_result;
3112
3113         if (!all_ports_stopped()) {
3114                 printf("Please stop all ports first\n");
3115                 return;
3116         }
3117
3118         if (!strcmp(res->name, "txfreet"))
3119                 tx_free_thresh = res->value;
3120         else if (!strcmp(res->name, "txrst"))
3121                 tx_rs_thresh = res->value;
3122         else if (!strcmp(res->name, "rxfreet"))
3123                 rx_free_thresh = res->value;
3124         else {
3125                 printf("Unknown parameter\n");
3126                 return;
3127         }
3128
3129         init_port_config();
3130
3131         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3132 }
3133
3134 cmdline_parse_token_string_t cmd_config_threshold_port =
3135         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3136 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3137         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3138                                                                 "config");
3139 cmdline_parse_token_string_t cmd_config_threshold_all =
3140         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3141 cmdline_parse_token_string_t cmd_config_threshold_name =
3142         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3143                                                 "txfreet#txrst#rxfreet");
3144 cmdline_parse_token_num_t cmd_config_threshold_value =
3145         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3146
3147 cmdline_parse_inst_t cmd_config_threshold = {
3148         .f = cmd_config_threshold_parsed,
3149         .data = NULL,
3150         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3151         .tokens = {
3152                 (void *)&cmd_config_threshold_port,
3153                 (void *)&cmd_config_threshold_keyword,
3154                 (void *)&cmd_config_threshold_all,
3155                 (void *)&cmd_config_threshold_name,
3156                 (void *)&cmd_config_threshold_value,
3157                 NULL,
3158         },
3159 };
3160
3161 /* *** stop *** */
3162 struct cmd_stop_result {
3163         cmdline_fixed_string_t stop;
3164 };
3165
3166 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3167                             __attribute__((unused)) struct cmdline *cl,
3168                             __attribute__((unused)) void *data)
3169 {
3170         stop_packet_forwarding();
3171 }
3172
3173 cmdline_parse_token_string_t cmd_stop_stop =
3174         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3175
3176 cmdline_parse_inst_t cmd_stop = {
3177         .f = cmd_stop_parsed,
3178         .data = NULL,
3179         .help_str = "stop: Stop packet forwarding",
3180         .tokens = {
3181                 (void *)&cmd_stop_stop,
3182                 NULL,
3183         },
3184 };
3185
3186 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3187
3188 unsigned int
3189 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3190                 unsigned int *parsed_items, int check_unique_values)
3191 {
3192         unsigned int nb_item;
3193         unsigned int value;
3194         unsigned int i;
3195         unsigned int j;
3196         int value_ok;
3197         char c;
3198
3199         /*
3200          * First parse all items in the list and store their value.
3201          */
3202         value = 0;
3203         nb_item = 0;
3204         value_ok = 0;
3205         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3206                 c = str[i];
3207                 if ((c >= '0') && (c <= '9')) {
3208                         value = (unsigned int) (value * 10 + (c - '0'));
3209                         value_ok = 1;
3210                         continue;
3211                 }
3212                 if (c != ',') {
3213                         printf("character %c is not a decimal digit\n", c);
3214                         return 0;
3215                 }
3216                 if (! value_ok) {
3217                         printf("No valid value before comma\n");
3218                         return 0;
3219                 }
3220                 if (nb_item < max_items) {
3221                         parsed_items[nb_item] = value;
3222                         value_ok = 0;
3223                         value = 0;
3224                 }
3225                 nb_item++;
3226         }
3227         if (nb_item >= max_items) {
3228                 printf("Number of %s = %u > %u (maximum items)\n",
3229                        item_name, nb_item + 1, max_items);
3230                 return 0;
3231         }
3232         parsed_items[nb_item++] = value;
3233         if (! check_unique_values)
3234                 return nb_item;
3235
3236         /*
3237          * Then, check that all values in the list are differents.
3238          * No optimization here...
3239          */
3240         for (i = 0; i < nb_item; i++) {
3241                 for (j = i + 1; j < nb_item; j++) {
3242                         if (parsed_items[j] == parsed_items[i]) {
3243                                 printf("duplicated %s %u at index %u and %u\n",
3244                                        item_name, parsed_items[i], i, j);
3245                                 return 0;
3246                         }
3247                 }
3248         }
3249         return nb_item;
3250 }
3251
3252 struct cmd_set_list_result {
3253         cmdline_fixed_string_t cmd_keyword;
3254         cmdline_fixed_string_t list_name;
3255         cmdline_fixed_string_t list_of_items;
3256 };
3257
3258 static void cmd_set_list_parsed(void *parsed_result,
3259                                 __attribute__((unused)) struct cmdline *cl,
3260                                 __attribute__((unused)) void *data)
3261 {
3262         struct cmd_set_list_result *res;
3263         union {
3264                 unsigned int lcorelist[RTE_MAX_LCORE];
3265                 unsigned int portlist[RTE_MAX_ETHPORTS];
3266         } parsed_items;
3267         unsigned int nb_item;
3268
3269         if (test_done == 0) {
3270                 printf("Please stop forwarding first\n");
3271                 return;
3272         }
3273
3274         res = parsed_result;
3275         if (!strcmp(res->list_name, "corelist")) {
3276                 nb_item = parse_item_list(res->list_of_items, "core",
3277                                           RTE_MAX_LCORE,
3278                                           parsed_items.lcorelist, 1);
3279                 if (nb_item > 0) {
3280                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3281                         fwd_config_setup();
3282                 }
3283                 return;
3284         }
3285         if (!strcmp(res->list_name, "portlist")) {
3286                 nb_item = parse_item_list(res->list_of_items, "port",
3287                                           RTE_MAX_ETHPORTS,
3288                                           parsed_items.portlist, 1);
3289                 if (nb_item > 0) {
3290                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3291                         fwd_config_setup();
3292                 }
3293         }
3294 }
3295
3296 cmdline_parse_token_string_t cmd_set_list_keyword =
3297         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3298                                  "set");
3299 cmdline_parse_token_string_t cmd_set_list_name =
3300         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3301                                  "corelist#portlist");
3302 cmdline_parse_token_string_t cmd_set_list_of_items =
3303         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3304                                  NULL);
3305
3306 cmdline_parse_inst_t cmd_set_fwd_list = {
3307         .f = cmd_set_list_parsed,
3308         .data = NULL,
3309         .help_str = "set corelist|portlist <list0[,list1]*>",
3310         .tokens = {
3311                 (void *)&cmd_set_list_keyword,
3312                 (void *)&cmd_set_list_name,
3313                 (void *)&cmd_set_list_of_items,
3314                 NULL,
3315         },
3316 };
3317
3318 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3319
3320 struct cmd_setmask_result {
3321         cmdline_fixed_string_t set;
3322         cmdline_fixed_string_t mask;
3323         uint64_t hexavalue;
3324 };
3325
3326 static void cmd_set_mask_parsed(void *parsed_result,
3327                                 __attribute__((unused)) struct cmdline *cl,
3328                                 __attribute__((unused)) void *data)
3329 {
3330         struct cmd_setmask_result *res = parsed_result;
3331
3332         if (test_done == 0) {
3333                 printf("Please stop forwarding first\n");
3334                 return;
3335         }
3336         if (!strcmp(res->mask, "coremask")) {
3337                 set_fwd_lcores_mask(res->hexavalue);
3338                 fwd_config_setup();
3339         } else if (!strcmp(res->mask, "portmask")) {
3340                 set_fwd_ports_mask(res->hexavalue);
3341                 fwd_config_setup();
3342         }
3343 }
3344
3345 cmdline_parse_token_string_t cmd_setmask_set =
3346         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3347 cmdline_parse_token_string_t cmd_setmask_mask =
3348         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3349                                  "coremask#portmask");
3350 cmdline_parse_token_num_t cmd_setmask_value =
3351         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3352
3353 cmdline_parse_inst_t cmd_set_fwd_mask = {
3354         .f = cmd_set_mask_parsed,
3355         .data = NULL,
3356         .help_str = "set coremask|portmask <hexadecimal value>",
3357         .tokens = {
3358                 (void *)&cmd_setmask_set,
3359                 (void *)&cmd_setmask_mask,
3360                 (void *)&cmd_setmask_value,
3361                 NULL,
3362         },
3363 };
3364
3365 /*
3366  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3367  */
3368 struct cmd_set_result {
3369         cmdline_fixed_string_t set;
3370         cmdline_fixed_string_t what;
3371         uint16_t value;
3372 };
3373
3374 static void cmd_set_parsed(void *parsed_result,
3375                            __attribute__((unused)) struct cmdline *cl,
3376                            __attribute__((unused)) void *data)
3377 {
3378         struct cmd_set_result *res = parsed_result;
3379         if (!strcmp(res->what, "nbport")) {
3380                 set_fwd_ports_number(res->value);
3381                 fwd_config_setup();
3382         } else if (!strcmp(res->what, "nbcore")) {
3383                 set_fwd_lcores_number(res->value);
3384                 fwd_config_setup();
3385         } else if (!strcmp(res->what, "burst"))
3386                 set_nb_pkt_per_burst(res->value);
3387         else if (!strcmp(res->what, "verbose"))
3388                 set_verbose_level(res->value);
3389 }
3390
3391 cmdline_parse_token_string_t cmd_set_set =
3392         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3393 cmdline_parse_token_string_t cmd_set_what =
3394         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3395                                  "nbport#nbcore#burst#verbose");
3396 cmdline_parse_token_num_t cmd_set_value =
3397         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3398
3399 cmdline_parse_inst_t cmd_set_numbers = {
3400         .f = cmd_set_parsed,
3401         .data = NULL,
3402         .help_str = "set nbport|nbcore|burst|verbose <value>",
3403         .tokens = {
3404                 (void *)&cmd_set_set,
3405                 (void *)&cmd_set_what,
3406                 (void *)&cmd_set_value,
3407                 NULL,
3408         },
3409 };
3410
3411 /* *** SET LOG LEVEL CONFIGURATION *** */
3412
3413 struct cmd_set_log_result {
3414         cmdline_fixed_string_t set;
3415         cmdline_fixed_string_t log;
3416         cmdline_fixed_string_t type;
3417         uint32_t level;
3418 };
3419
3420 static void
3421 cmd_set_log_parsed(void *parsed_result,
3422                    __attribute__((unused)) struct cmdline *cl,
3423                    __attribute__((unused)) void *data)
3424 {
3425         struct cmd_set_log_result *res;
3426         int ret;
3427
3428         res = parsed_result;
3429         if (!strcmp(res->type, "global"))
3430                 rte_log_set_global_level(res->level);
3431         else {
3432                 ret = rte_log_set_level_regexp(res->type, res->level);
3433                 if (ret < 0)
3434                         printf("Unable to set log level\n");
3435         }
3436 }
3437
3438 cmdline_parse_token_string_t cmd_set_log_set =
3439         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3440 cmdline_parse_token_string_t cmd_set_log_log =
3441         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3442 cmdline_parse_token_string_t cmd_set_log_type =
3443         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3444 cmdline_parse_token_num_t cmd_set_log_level =
3445         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3446
3447 cmdline_parse_inst_t cmd_set_log = {
3448         .f = cmd_set_log_parsed,
3449         .data = NULL,
3450         .help_str = "set log global|<type> <level>",
3451         .tokens = {
3452                 (void *)&cmd_set_log_set,
3453                 (void *)&cmd_set_log_log,
3454                 (void *)&cmd_set_log_type,
3455                 (void *)&cmd_set_log_level,
3456                 NULL,
3457         },
3458 };
3459
3460 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3461
3462 struct cmd_set_txpkts_result {
3463         cmdline_fixed_string_t cmd_keyword;
3464         cmdline_fixed_string_t txpkts;
3465         cmdline_fixed_string_t seg_lengths;
3466 };
3467
3468 static void
3469 cmd_set_txpkts_parsed(void *parsed_result,
3470                       __attribute__((unused)) struct cmdline *cl,
3471                       __attribute__((unused)) void *data)
3472 {
3473         struct cmd_set_txpkts_result *res;
3474         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3475         unsigned int nb_segs;
3476
3477         res = parsed_result;
3478         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3479                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3480         if (nb_segs > 0)
3481                 set_tx_pkt_segments(seg_lengths, nb_segs);
3482 }
3483
3484 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3485         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3486                                  cmd_keyword, "set");
3487 cmdline_parse_token_string_t cmd_set_txpkts_name =
3488         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3489                                  txpkts, "txpkts");
3490 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3491         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3492                                  seg_lengths, NULL);
3493
3494 cmdline_parse_inst_t cmd_set_txpkts = {
3495         .f = cmd_set_txpkts_parsed,
3496         .data = NULL,
3497         .help_str = "set txpkts <len0[,len1]*>",
3498         .tokens = {
3499                 (void *)&cmd_set_txpkts_keyword,
3500                 (void *)&cmd_set_txpkts_name,
3501                 (void *)&cmd_set_txpkts_lengths,
3502                 NULL,
3503         },
3504 };
3505
3506 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3507
3508 struct cmd_set_txsplit_result {
3509         cmdline_fixed_string_t cmd_keyword;
3510         cmdline_fixed_string_t txsplit;
3511         cmdline_fixed_string_t mode;
3512 };
3513
3514 static void
3515 cmd_set_txsplit_parsed(void *parsed_result,
3516                       __attribute__((unused)) struct cmdline *cl,
3517                       __attribute__((unused)) void *data)
3518 {
3519         struct cmd_set_txsplit_result *res;
3520
3521         res = parsed_result;
3522         set_tx_pkt_split(res->mode);
3523 }
3524
3525 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3526         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3527                                  cmd_keyword, "set");
3528 cmdline_parse_token_string_t cmd_set_txsplit_name =
3529         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3530                                  txsplit, "txsplit");
3531 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3532         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3533                                  mode, NULL);
3534
3535 cmdline_parse_inst_t cmd_set_txsplit = {
3536         .f = cmd_set_txsplit_parsed,
3537         .data = NULL,
3538         .help_str = "set txsplit on|off|rand",
3539         .tokens = {
3540                 (void *)&cmd_set_txsplit_keyword,
3541                 (void *)&cmd_set_txsplit_name,
3542                 (void *)&cmd_set_txsplit_mode,
3543                 NULL,
3544         },
3545 };
3546
3547 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3548 struct cmd_rx_vlan_filter_all_result {
3549         cmdline_fixed_string_t rx_vlan;
3550         cmdline_fixed_string_t what;
3551         cmdline_fixed_string_t all;
3552         portid_t port_id;
3553 };
3554
3555 static void
3556 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3557                               __attribute__((unused)) struct cmdline *cl,
3558                               __attribute__((unused)) void *data)
3559 {
3560         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3561
3562         if (!strcmp(res->what, "add"))
3563                 rx_vlan_all_filter_set(res->port_id, 1);
3564         else
3565                 rx_vlan_all_filter_set(res->port_id, 0);
3566 }
3567
3568 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3569         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3570                                  rx_vlan, "rx_vlan");
3571 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3572         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3573                                  what, "add#rm");
3574 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3575         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3576                                  all, "all");
3577 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3578         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3579                               port_id, UINT16);
3580
3581 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3582         .f = cmd_rx_vlan_filter_all_parsed,
3583         .data = NULL,
3584         .help_str = "rx_vlan add|rm all <port_id>: "
3585                 "Add/Remove all identifiers to/from the set of VLAN "
3586                 "identifiers filtered by a port",
3587         .tokens = {
3588                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3589                 (void *)&cmd_rx_vlan_filter_all_what,
3590                 (void *)&cmd_rx_vlan_filter_all_all,
3591                 (void *)&cmd_rx_vlan_filter_all_portid,
3592                 NULL,
3593         },
3594 };
3595
3596 /* *** VLAN OFFLOAD SET ON A PORT *** */
3597 struct cmd_vlan_offload_result {
3598         cmdline_fixed_string_t vlan;
3599         cmdline_fixed_string_t set;
3600         cmdline_fixed_string_t vlan_type;
3601         cmdline_fixed_string_t what;
3602         cmdline_fixed_string_t on;
3603         cmdline_fixed_string_t port_id;
3604 };
3605
3606 static void
3607 cmd_vlan_offload_parsed(void *parsed_result,
3608                           __attribute__((unused)) struct cmdline *cl,
3609                           __attribute__((unused)) void *data)
3610 {
3611         int on;
3612         struct cmd_vlan_offload_result *res = parsed_result;
3613         char *str;
3614         int i, len = 0;
3615         portid_t port_id = 0;
3616         unsigned int tmp;
3617
3618         str = res->port_id;
3619         len = strnlen(str, STR_TOKEN_SIZE);
3620         i = 0;
3621         /* Get port_id first */
3622         while(i < len){
3623                 if(str[i] == ',')
3624                         break;
3625
3626                 i++;
3627         }
3628         str[i]='\0';
3629         tmp = strtoul(str, NULL, 0);
3630         /* If port_id greater that what portid_t can represent, return */
3631         if(tmp >= RTE_MAX_ETHPORTS)
3632                 return;
3633         port_id = (portid_t)tmp;
3634
3635         if (!strcmp(res->on, "on"))
3636                 on = 1;
3637         else
3638                 on = 0;
3639
3640         if (!strcmp(res->what, "strip"))
3641                 rx_vlan_strip_set(port_id,  on);
3642         else if(!strcmp(res->what, "stripq")){
3643                 uint16_t queue_id = 0;
3644
3645                 /* No queue_id, return */
3646                 if(i + 1 >= len) {
3647                         printf("must specify (port,queue_id)\n");
3648                         return;
3649                 }
3650                 tmp = strtoul(str + i + 1, NULL, 0);
3651                 /* If queue_id greater that what 16-bits can represent, return */
3652                 if(tmp > 0xffff)
3653                         return;
3654
3655                 queue_id = (uint16_t)tmp;
3656                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3657         }
3658         else if (!strcmp(res->what, "filter"))
3659                 rx_vlan_filter_set(port_id, on);
3660         else
3661                 vlan_extend_set(port_id, on);
3662
3663         return;
3664 }
3665
3666 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3667         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3668                                  vlan, "vlan");
3669 cmdline_parse_token_string_t cmd_vlan_offload_set =
3670         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3671                                  set, "set");
3672 cmdline_parse_token_string_t cmd_vlan_offload_what =
3673         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3674                                  what, "strip#filter#qinq#stripq");
3675 cmdline_parse_token_string_t cmd_vlan_offload_on =
3676         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3677                               on, "on#off");
3678 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3679         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3680                               port_id, NULL);
3681
3682 cmdline_parse_inst_t cmd_vlan_offload = {
3683         .f = cmd_vlan_offload_parsed,
3684         .data = NULL,
3685         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3686                 "<port_id[,queue_id]>: "
3687                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3688         .tokens = {
3689                 (void *)&cmd_vlan_offload_vlan,
3690                 (void *)&cmd_vlan_offload_set,
3691                 (void *)&cmd_vlan_offload_what,
3692                 (void *)&cmd_vlan_offload_on,
3693                 (void *)&cmd_vlan_offload_portid,
3694                 NULL,
3695         },
3696 };
3697
3698 /* *** VLAN TPID SET ON A PORT *** */
3699 struct cmd_vlan_tpid_result {
3700         cmdline_fixed_string_t vlan;
3701         cmdline_fixed_string_t set;
3702         cmdline_fixed_string_t vlan_type;
3703         cmdline_fixed_string_t what;
3704         uint16_t tp_id;
3705         portid_t port_id;
3706 };
3707
3708 static void
3709 cmd_vlan_tpid_parsed(void *parsed_result,
3710                           __attribute__((unused)) struct cmdline *cl,
3711                           __attribute__((unused)) void *data)
3712 {
3713         struct cmd_vlan_tpid_result *res = parsed_result;
3714         enum rte_vlan_type vlan_type;
3715
3716         if (!strcmp(res->vlan_type, "inner"))
3717                 vlan_type = ETH_VLAN_TYPE_INNER;
3718         else if (!strcmp(res->vlan_type, "outer"))
3719                 vlan_type = ETH_VLAN_TYPE_OUTER;
3720         else {
3721                 printf("Unknown vlan type\n");
3722                 return;
3723         }
3724         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3725 }
3726
3727 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3728         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3729                                  vlan, "vlan");
3730 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3731         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3732                                  set, "set");
3733 cmdline_parse_token_string_t cmd_vlan_type =
3734         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3735                                  vlan_type, "inner#outer");
3736 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3737         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3738                                  what, "tpid");
3739 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3740         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3741                               tp_id, UINT16);
3742 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3743         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3744                               port_id, UINT16);
3745
3746 cmdline_parse_inst_t cmd_vlan_tpid = {
3747         .f = cmd_vlan_tpid_parsed,
3748         .data = NULL,
3749         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3750                 "Set the VLAN Ether type",
3751         .tokens = {
3752                 (void *)&cmd_vlan_tpid_vlan,
3753                 (void *)&cmd_vlan_tpid_set,
3754                 (void *)&cmd_vlan_type,
3755                 (void *)&cmd_vlan_tpid_what,
3756                 (void *)&cmd_vlan_tpid_tpid,
3757                 (void *)&cmd_vlan_tpid_portid,
3758                 NULL,
3759         },
3760 };
3761
3762 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3763 struct cmd_rx_vlan_filter_result {
3764         cmdline_fixed_string_t rx_vlan;
3765         cmdline_fixed_string_t what;
3766         uint16_t vlan_id;
3767         portid_t port_id;
3768 };
3769
3770 static void
3771 cmd_rx_vlan_filter_parsed(void *parsed_result,
3772                           __attribute__((unused)) struct cmdline *cl,
3773                           __attribute__((unused)) void *data)
3774 {
3775         struct cmd_rx_vlan_filter_result *res = parsed_result;
3776
3777         if (!strcmp(res->what, "add"))
3778                 rx_vft_set(res->port_id, res->vlan_id, 1);
3779         else
3780                 rx_vft_set(res->port_id, res->vlan_id, 0);
3781 }
3782
3783 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3784         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3785                                  rx_vlan, "rx_vlan");
3786 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3787         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3788                                  what, "add#rm");
3789 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3790         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3791                               vlan_id, UINT16);
3792 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3793         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3794                               port_id, UINT16);
3795
3796 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3797         .f = cmd_rx_vlan_filter_parsed,
3798         .data = NULL,
3799         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3800                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3801                 "identifiers filtered by a port",
3802         .tokens = {
3803                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3804                 (void *)&cmd_rx_vlan_filter_what,
3805                 (void *)&cmd_rx_vlan_filter_vlanid,
3806                 (void *)&cmd_rx_vlan_filter_portid,
3807                 NULL,
3808         },
3809 };
3810
3811 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3812 struct cmd_tx_vlan_set_result {
3813         cmdline_fixed_string_t tx_vlan;
3814         cmdline_fixed_string_t set;
3815         portid_t port_id;
3816         uint16_t vlan_id;
3817 };
3818
3819 static void
3820 cmd_tx_vlan_set_parsed(void *parsed_result,
3821                        __attribute__((unused)) struct cmdline *cl,
3822                        __attribute__((unused)) void *data)
3823 {
3824         struct cmd_tx_vlan_set_result *res = parsed_result;
3825
3826         if (!port_is_stopped(res->port_id)) {
3827                 printf("Please stop port %d first\n", res->port_id);
3828                 return;
3829         }
3830
3831         tx_vlan_set(res->port_id, res->vlan_id);
3832
3833         cmd_reconfig_device_queue(res->port_id, 1, 1);
3834 }
3835
3836 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3837         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3838                                  tx_vlan, "tx_vlan");
3839 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3840         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3841                                  set, "set");
3842 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3843         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3844                               port_id, UINT16);
3845 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3846         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3847                               vlan_id, UINT16);
3848
3849 cmdline_parse_inst_t cmd_tx_vlan_set = {
3850         .f = cmd_tx_vlan_set_parsed,
3851         .data = NULL,
3852         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3853                 "Enable hardware insertion of a single VLAN header "
3854                 "with a given TAG Identifier in packets sent on a port",
3855         .tokens = {
3856                 (void *)&cmd_tx_vlan_set_tx_vlan,
3857                 (void *)&cmd_tx_vlan_set_set,
3858                 (void *)&cmd_tx_vlan_set_portid,
3859                 (void *)&cmd_tx_vlan_set_vlanid,
3860                 NULL,
3861         },
3862 };
3863
3864 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3865 struct cmd_tx_vlan_set_qinq_result {
3866         cmdline_fixed_string_t tx_vlan;
3867         cmdline_fixed_string_t set;
3868         portid_t port_id;
3869         uint16_t vlan_id;
3870         uint16_t vlan_id_outer;
3871 };
3872
3873 static void
3874 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3875                             __attribute__((unused)) struct cmdline *cl,
3876                             __attribute__((unused)) void *data)
3877 {
3878         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3879
3880         if (!port_is_stopped(res->port_id)) {
3881                 printf("Please stop port %d first\n", res->port_id);
3882                 return;
3883         }
3884
3885         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3886
3887         cmd_reconfig_device_queue(res->port_id, 1, 1);
3888 }
3889
3890 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3891         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3892                 tx_vlan, "tx_vlan");
3893 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3894         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3895                 set, "set");
3896 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3897         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3898                 port_id, UINT16);
3899 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3900         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3901                 vlan_id, UINT16);
3902 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3903         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3904                 vlan_id_outer, UINT16);
3905
3906 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3907         .f = cmd_tx_vlan_set_qinq_parsed,
3908         .data = NULL,
3909         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3910                 "Enable hardware insertion of double VLAN header "
3911                 "with given TAG Identifiers in packets sent on a port",
3912         .tokens = {
3913                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3914                 (void *)&cmd_tx_vlan_set_qinq_set,
3915                 (void *)&cmd_tx_vlan_set_qinq_portid,
3916                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3917                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3918                 NULL,
3919         },
3920 };
3921
3922 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3923 struct cmd_tx_vlan_set_pvid_result {
3924         cmdline_fixed_string_t tx_vlan;
3925         cmdline_fixed_string_t set;
3926         cmdline_fixed_string_t pvid;
3927         portid_t port_id;
3928         uint16_t vlan_id;
3929         cmdline_fixed_string_t mode;
3930 };
3931
3932 static void
3933 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3934                             __attribute__((unused)) struct cmdline *cl,
3935                             __attribute__((unused)) void *data)
3936 {
3937         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3938
3939         if (strcmp(res->mode, "on") == 0)
3940                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3941         else
3942                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3943 }
3944
3945 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3946         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3947                                  tx_vlan, "tx_vlan");
3948 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3949         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3950                                  set, "set");
3951 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3952         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3953                                  pvid, "pvid");
3954 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3955         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3956                              port_id, UINT16);
3957 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3958         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3959                               vlan_id, UINT16);
3960 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3961         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3962                                  mode, "on#off");
3963
3964 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3965         .f = cmd_tx_vlan_set_pvid_parsed,
3966         .data = NULL,
3967         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3968         .tokens = {
3969                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3970                 (void *)&cmd_tx_vlan_set_pvid_set,
3971                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3972                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3973                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3974                 (void *)&cmd_tx_vlan_set_pvid_mode,
3975                 NULL,
3976         },
3977 };
3978
3979 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3980 struct cmd_tx_vlan_reset_result {
3981         cmdline_fixed_string_t tx_vlan;
3982         cmdline_fixed_string_t reset;
3983         portid_t port_id;
3984 };
3985
3986 static void
3987 cmd_tx_vlan_reset_parsed(void *parsed_result,
3988                          __attribute__((unused)) struct cmdline *cl,
3989                          __attribute__((unused)) void *data)
3990 {
3991         struct cmd_tx_vlan_reset_result *res = parsed_result;
3992
3993         if (!port_is_stopped(res->port_id)) {
3994                 printf("Please stop port %d first\n", res->port_id);
3995                 return;
3996         }
3997
3998         tx_vlan_reset(res->port_id);
3999
4000         cmd_reconfig_device_queue(res->port_id, 1, 1);
4001 }
4002
4003 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4004         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4005                                  tx_vlan, "tx_vlan");
4006 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4007         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4008                                  reset, "reset");
4009 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4010         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4011                               port_id, UINT16);
4012
4013 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4014         .f = cmd_tx_vlan_reset_parsed,
4015         .data = NULL,
4016         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4017                 "VLAN header in packets sent on a port",
4018         .tokens = {
4019                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4020                 (void *)&cmd_tx_vlan_reset_reset,
4021                 (void *)&cmd_tx_vlan_reset_portid,
4022                 NULL,
4023         },
4024 };
4025
4026
4027 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4028 struct cmd_csum_result {
4029         cmdline_fixed_string_t csum;
4030         cmdline_fixed_string_t mode;
4031         cmdline_fixed_string_t proto;
4032         cmdline_fixed_string_t hwsw;
4033         portid_t port_id;
4034 };
4035
4036 static void
4037 csum_show(int port_id)
4038 {
4039         struct rte_eth_dev_info dev_info;
4040         uint64_t tx_offloads;
4041
4042         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4043         printf("Parse tunnel is %s\n",
4044                 (ports[port_id].parse_tunnel) ? "on" : "off");
4045         printf("IP checksum offload is %s\n",
4046                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4047         printf("UDP checksum offload is %s\n",
4048                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4049         printf("TCP checksum offload is %s\n",
4050                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4051         printf("SCTP checksum offload is %s\n",
4052                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4053         printf("Outer-Ip checksum offload is %s\n",
4054                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4055
4056         /* display warnings if configuration is not supported by the NIC */
4057         rte_eth_dev_info_get(port_id, &dev_info);
4058         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4059                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4060                 printf("Warning: hardware IP checksum enabled but not "
4061                         "supported by port %d\n", port_id);
4062         }
4063         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4064                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4065                 printf("Warning: hardware UDP checksum enabled but not "
4066                         "supported by port %d\n", port_id);
4067         }
4068         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4069                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4070                 printf("Warning: hardware TCP checksum enabled but not "
4071                         "supported by port %d\n", port_id);
4072         }
4073         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4074                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4075                 printf("Warning: hardware SCTP checksum enabled but not "
4076                         "supported by port %d\n", port_id);
4077         }
4078         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4079                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4080                 printf("Warning: hardware outer IP checksum enabled but not "
4081                         "supported by port %d\n", port_id);
4082         }
4083 }
4084
4085 static void
4086 cmd_csum_parsed(void *parsed_result,
4087                        __attribute__((unused)) struct cmdline *cl,
4088                        __attribute__((unused)) void *data)
4089 {
4090         struct cmd_csum_result *res = parsed_result;
4091         int hw = 0;
4092         uint64_t csum_offloads = 0;
4093         struct rte_eth_dev_info dev_info;
4094
4095         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4096                 printf("invalid port %d\n", res->port_id);
4097                 return;
4098         }
4099         if (!port_is_stopped(res->port_id)) {
4100                 printf("Please stop port %d first\n", res->port_id);
4101                 return;
4102         }
4103
4104         rte_eth_dev_info_get(res->port_id, &dev_info);
4105         if (!strcmp(res->mode, "set")) {
4106
4107                 if (!strcmp(res->hwsw, "hw"))
4108                         hw = 1;
4109
4110                 if (!strcmp(res->proto, "ip")) {
4111                         if (hw == 0 || (dev_info.tx_offload_capa &
4112                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4113                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4114                         } else {
4115                                 printf("IP checksum offload is not supported "
4116                                        "by port %u\n", res->port_id);
4117                         }
4118                 } else if (!strcmp(res->proto, "udp")) {
4119                         if (hw == 0 || (dev_info.tx_offload_capa &
4120                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4121                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4122                         } else {
4123                                 printf("UDP checksum offload is not supported "
4124                                        "by port %u\n", res->port_id);
4125                         }
4126                 } else if (!strcmp(res->proto, "tcp")) {
4127                         if (hw == 0 || (dev_info.tx_offload_capa &
4128                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4129                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4130                         } else {
4131                                 printf("TCP checksum offload is not supported "
4132                                        "by port %u\n", res->port_id);
4133                         }
4134                 } else if (!strcmp(res->proto, "sctp")) {
4135                         if (hw == 0 || (dev_info.tx_offload_capa &
4136                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4137                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4138                         } else {
4139                                 printf("SCTP checksum offload is not supported "
4140                                        "by port %u\n", res->port_id);
4141                         }
4142                 } else if (!strcmp(res->proto, "outer-ip")) {
4143                         if (hw == 0 || (dev_info.tx_offload_capa &
4144                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4145                                 csum_offloads |=
4146                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4147                         } else {
4148                                 printf("Outer IP checksum offload is not "
4149                                        "supported by port %u\n", res->port_id);
4150                         }
4151                 }
4152
4153                 if (hw) {
4154                         ports[res->port_id].dev_conf.txmode.offloads |=
4155                                                         csum_offloads;
4156                 } else {
4157                         ports[res->port_id].dev_conf.txmode.offloads &=
4158                                                         (~csum_offloads);
4159                 }
4160         }
4161         csum_show(res->port_id);
4162
4163         cmd_reconfig_device_queue(res->port_id, 1, 1);
4164 }
4165
4166 cmdline_parse_token_string_t cmd_csum_csum =
4167         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4168                                 csum, "csum");
4169 cmdline_parse_token_string_t cmd_csum_mode =
4170         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4171                                 mode, "set");
4172 cmdline_parse_token_string_t cmd_csum_proto =
4173         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4174                                 proto, "ip#tcp#udp#sctp#outer-ip");
4175 cmdline_parse_token_string_t cmd_csum_hwsw =
4176         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4177                                 hwsw, "hw#sw");
4178 cmdline_parse_token_num_t cmd_csum_portid =
4179         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4180                                 port_id, UINT16);
4181
4182 cmdline_parse_inst_t cmd_csum_set = {
4183         .f = cmd_csum_parsed,
4184         .data = NULL,
4185         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4186                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4187                 "using csum forward engine",
4188         .tokens = {
4189                 (void *)&cmd_csum_csum,
4190                 (void *)&cmd_csum_mode,
4191                 (void *)&cmd_csum_proto,
4192                 (void *)&cmd_csum_hwsw,
4193                 (void *)&cmd_csum_portid,
4194                 NULL,
4195         },
4196 };
4197
4198 cmdline_parse_token_string_t cmd_csum_mode_show =
4199         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4200                                 mode, "show");
4201
4202 cmdline_parse_inst_t cmd_csum_show = {
4203         .f = cmd_csum_parsed,
4204         .data = NULL,
4205         .help_str = "csum show <port_id>: Show checksum offload configuration",
4206         .tokens = {
4207                 (void *)&cmd_csum_csum,
4208                 (void *)&cmd_csum_mode_show,
4209                 (void *)&cmd_csum_portid,
4210                 NULL,
4211         },
4212 };
4213
4214 /* Enable/disable tunnel parsing */
4215 struct cmd_csum_tunnel_result {
4216         cmdline_fixed_string_t csum;
4217         cmdline_fixed_string_t parse;
4218         cmdline_fixed_string_t onoff;
4219         portid_t port_id;
4220 };
4221
4222 static void
4223 cmd_csum_tunnel_parsed(void *parsed_result,
4224                        __attribute__((unused)) struct cmdline *cl,
4225                        __attribute__((unused)) void *data)
4226 {
4227         struct cmd_csum_tunnel_result *res = parsed_result;
4228
4229         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4230                 return;
4231
4232         if (!strcmp(res->onoff, "on"))
4233                 ports[res->port_id].parse_tunnel = 1;
4234         else
4235                 ports[res->port_id].parse_tunnel = 0;
4236
4237         csum_show(res->port_id);
4238 }
4239
4240 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4241         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4242                                 csum, "csum");
4243 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4244         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4245                                 parse, "parse_tunnel");
4246 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4247         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4248                                 onoff, "on#off");
4249 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4250         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4251                                 port_id, UINT16);
4252
4253 cmdline_parse_inst_t cmd_csum_tunnel = {
4254         .f = cmd_csum_tunnel_parsed,
4255         .data = NULL,
4256         .help_str = "csum parse_tunnel on|off <port_id>: "
4257                 "Enable/Disable parsing of tunnels for csum engine",
4258         .tokens = {
4259                 (void *)&cmd_csum_tunnel_csum,
4260                 (void *)&cmd_csum_tunnel_parse,
4261                 (void *)&cmd_csum_tunnel_onoff,
4262                 (void *)&cmd_csum_tunnel_portid,
4263                 NULL,
4264         },
4265 };
4266
4267 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4268 struct cmd_tso_set_result {
4269         cmdline_fixed_string_t tso;
4270         cmdline_fixed_string_t mode;
4271         uint16_t tso_segsz;
4272         portid_t port_id;
4273 };
4274
4275 static void
4276 cmd_tso_set_parsed(void *parsed_result,
4277                        __attribute__((unused)) struct cmdline *cl,
4278                        __attribute__((unused)) void *data)
4279 {
4280         struct cmd_tso_set_result *res = parsed_result;
4281         struct rte_eth_dev_info dev_info;
4282
4283         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4284                 return;
4285         if (!port_is_stopped(res->port_id)) {
4286                 printf("Please stop port %d first\n", res->port_id);
4287                 return;
4288         }
4289
4290         if (!strcmp(res->mode, "set"))
4291                 ports[res->port_id].tso_segsz = res->tso_segsz;
4292
4293         rte_eth_dev_info_get(res->port_id, &dev_info);
4294         if ((ports[res->port_id].tso_segsz != 0) &&
4295                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4296                 printf("Error: TSO is not supported by port %d\n",
4297                        res->port_id);
4298                 return;
4299         }
4300
4301         if (ports[res->port_id].tso_segsz == 0) {
4302                 ports[res->port_id].dev_conf.txmode.offloads &=
4303                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4304                 printf("TSO for non-tunneled packets is disabled\n");
4305         } else {
4306                 ports[res->port_id].dev_conf.txmode.offloads |=
4307                                                 DEV_TX_OFFLOAD_TCP_TSO;
4308                 printf("TSO segment size for non-tunneled packets is %d\n",
4309                         ports[res->port_id].tso_segsz);
4310         }
4311
4312         /* display warnings if configuration is not supported by the NIC */
4313         rte_eth_dev_info_get(res->port_id, &dev_info);
4314         if ((ports[res->port_id].tso_segsz != 0) &&
4315                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4316                 printf("Warning: TSO enabled but not "
4317                         "supported by port %d\n", res->port_id);
4318         }
4319
4320         cmd_reconfig_device_queue(res->port_id, 1, 1);
4321 }
4322
4323 cmdline_parse_token_string_t cmd_tso_set_tso =
4324         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4325                                 tso, "tso");
4326 cmdline_parse_token_string_t cmd_tso_set_mode =
4327         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4328                                 mode, "set");
4329 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4330         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4331                                 tso_segsz, UINT16);
4332 cmdline_parse_token_num_t cmd_tso_set_portid =
4333         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4334                                 port_id, UINT16);
4335
4336 cmdline_parse_inst_t cmd_tso_set = {
4337         .f = cmd_tso_set_parsed,
4338         .data = NULL,
4339         .help_str = "tso set <tso_segsz> <port_id>: "
4340                 "Set TSO segment size of non-tunneled packets for csum engine "
4341                 "(0 to disable)",
4342         .tokens = {
4343                 (void *)&cmd_tso_set_tso,
4344                 (void *)&cmd_tso_set_mode,
4345                 (void *)&cmd_tso_set_tso_segsz,
4346                 (void *)&cmd_tso_set_portid,
4347                 NULL,
4348         },
4349 };
4350
4351 cmdline_parse_token_string_t cmd_tso_show_mode =
4352         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4353                                 mode, "show");
4354
4355
4356 cmdline_parse_inst_t cmd_tso_show = {
4357         .f = cmd_tso_set_parsed,
4358         .data = NULL,
4359         .help_str = "tso show <port_id>: "
4360                 "Show TSO segment size of non-tunneled packets for csum engine",
4361         .tokens = {
4362                 (void *)&cmd_tso_set_tso,
4363                 (void *)&cmd_tso_show_mode,
4364                 (void *)&cmd_tso_set_portid,
4365                 NULL,
4366         },
4367 };
4368
4369 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4370 struct cmd_tunnel_tso_set_result {
4371         cmdline_fixed_string_t tso;
4372         cmdline_fixed_string_t mode;
4373         uint16_t tso_segsz;
4374         portid_t port_id;
4375 };
4376
4377 static struct rte_eth_dev_info
4378 check_tunnel_tso_nic_support(portid_t port_id)
4379 {
4380         struct rte_eth_dev_info dev_info;
4381
4382         rte_eth_dev_info_get(port_id, &dev_info);
4383         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4384                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4385                        "not enabled for port %d\n", port_id);
4386         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4387                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4388                        "not enabled for port %d\n", port_id);
4389         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4390                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4391                        "not enabled for port %d\n", port_id);
4392         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4393                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4394                        "not enabled for port %d\n", port_id);
4395         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4396                 printf("Warning: IP TUNNEL TSO not supported therefore "
4397                        "not enabled for port %d\n", port_id);
4398         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4399                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4400                        "not enabled for port %d\n", port_id);
4401         return dev_info;
4402 }
4403
4404 static void
4405 cmd_tunnel_tso_set_parsed(void *parsed_result,
4406                           __attribute__((unused)) struct cmdline *cl,
4407                           __attribute__((unused)) void *data)
4408 {
4409         struct cmd_tunnel_tso_set_result *res = parsed_result;
4410         struct rte_eth_dev_info dev_info;
4411
4412         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4413                 return;
4414         if (!port_is_stopped(res->port_id)) {
4415                 printf("Please stop port %d first\n", res->port_id);
4416                 return;
4417         }
4418
4419         if (!strcmp(res->mode, "set"))
4420                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4421
4422         dev_info = check_tunnel_tso_nic_support(res->port_id);
4423         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4424                 ports[res->port_id].dev_conf.txmode.offloads &=
4425                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4426                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4427                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4428                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4429                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4430                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4431                 printf("TSO for tunneled packets is disabled\n");
4432         } else {
4433                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4434                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4435                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4436                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4437                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4438                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4439
4440                 ports[res->port_id].dev_conf.txmode.offloads |=
4441                         (tso_offloads & dev_info.tx_offload_capa);
4442                 printf("TSO segment size for tunneled packets is %d\n",
4443                         ports[res->port_id].tunnel_tso_segsz);
4444
4445                 /* Below conditions are needed to make it work:
4446                  * (1) tunnel TSO is supported by the NIC;
4447                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4448                  * are recognized;
4449                  * (3) for tunneled pkts with outer L3 of IPv4,
4450                  * "csum set outer-ip" must be set to hw, because after tso,
4451                  * total_len of outer IP header is changed, and the checksum
4452                  * of outer IP header calculated by sw should be wrong; that
4453                  * is not necessary for IPv6 tunneled pkts because there's no
4454                  * checksum in IP header anymore.
4455                  */
4456
4457                 if (!ports[res->port_id].parse_tunnel)
4458                         printf("Warning: csum parse_tunnel must be set "
4459                                 "so that tunneled packets are recognized\n");
4460                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4461                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4462                         printf("Warning: csum set outer-ip must be set to hw "
4463                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4464         }
4465
4466         cmd_reconfig_device_queue(res->port_id, 1, 1);
4467 }
4468
4469 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4470         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4471                                 tso, "tunnel_tso");
4472 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4473         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4474                                 mode, "set");
4475 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4476         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4477                                 tso_segsz, UINT16);
4478 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4479         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4480                                 port_id, UINT16);
4481
4482 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4483         .f = cmd_tunnel_tso_set_parsed,
4484         .data = NULL,
4485         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4486                 "Set TSO segment size of tunneled packets for csum engine "
4487                 "(0 to disable)",
4488         .tokens = {
4489                 (void *)&cmd_tunnel_tso_set_tso,
4490                 (void *)&cmd_tunnel_tso_set_mode,
4491                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4492                 (void *)&cmd_tunnel_tso_set_portid,
4493                 NULL,
4494         },
4495 };
4496
4497 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4498         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4499                                 mode, "show");
4500
4501
4502 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4503         .f = cmd_tunnel_tso_set_parsed,
4504         .data = NULL,
4505         .help_str = "tunnel_tso show <port_id> "
4506                 "Show TSO segment size of tunneled packets for csum engine",
4507         .tokens = {
4508                 (void *)&cmd_tunnel_tso_set_tso,
4509                 (void *)&cmd_tunnel_tso_show_mode,
4510                 (void *)&cmd_tunnel_tso_set_portid,
4511                 NULL,
4512         },
4513 };
4514
4515 /* *** SET GRO FOR A PORT *** */
4516 struct cmd_gro_enable_result {
4517         cmdline_fixed_string_t cmd_set;
4518         cmdline_fixed_string_t cmd_port;
4519         cmdline_fixed_string_t cmd_keyword;
4520         cmdline_fixed_string_t cmd_onoff;
4521         portid_t cmd_pid;
4522 };
4523
4524 static void
4525 cmd_gro_enable_parsed(void *parsed_result,
4526                 __attribute__((unused)) struct cmdline *cl,
4527                 __attribute__((unused)) void *data)
4528 {
4529         struct cmd_gro_enable_result *res;
4530
4531         res = parsed_result;
4532         if (!strcmp(res->cmd_keyword, "gro"))
4533                 setup_gro(res->cmd_onoff, res->cmd_pid);
4534 }
4535
4536 cmdline_parse_token_string_t cmd_gro_enable_set =
4537         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4538                         cmd_set, "set");
4539 cmdline_parse_token_string_t cmd_gro_enable_port =
4540         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4541                         cmd_keyword, "port");
4542 cmdline_parse_token_num_t cmd_gro_enable_pid =
4543         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4544                         cmd_pid, UINT16);
4545 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4546         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4547                         cmd_keyword, "gro");
4548 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4549         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4550                         cmd_onoff, "on#off");
4551
4552 cmdline_parse_inst_t cmd_gro_enable = {
4553         .f = cmd_gro_enable_parsed,
4554         .data = NULL,
4555         .help_str = "set port <port_id> gro on|off",
4556         .tokens = {
4557                 (void *)&cmd_gro_enable_set,
4558                 (void *)&cmd_gro_enable_port,
4559                 (void *)&cmd_gro_enable_pid,
4560                 (void *)&cmd_gro_enable_keyword,
4561                 (void *)&cmd_gro_enable_onoff,
4562                 NULL,
4563         },
4564 };
4565
4566 /* *** DISPLAY GRO CONFIGURATION *** */
4567 struct cmd_gro_show_result {
4568         cmdline_fixed_string_t cmd_show;
4569         cmdline_fixed_string_t cmd_port;
4570         cmdline_fixed_string_t cmd_keyword;
4571         portid_t cmd_pid;
4572 };
4573
4574 static void
4575 cmd_gro_show_parsed(void *parsed_result,
4576                 __attribute__((unused)) struct cmdline *cl,
4577                 __attribute__((unused)) void *data)
4578 {
4579         struct cmd_gro_show_result *res;
4580
4581         res = parsed_result;
4582         if (!strcmp(res->cmd_keyword, "gro"))
4583                 show_gro(res->cmd_pid);
4584 }
4585
4586 cmdline_parse_token_string_t cmd_gro_show_show =
4587         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4588                         cmd_show, "show");
4589 cmdline_parse_token_string_t cmd_gro_show_port =
4590         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4591                         cmd_port, "port");
4592 cmdline_parse_token_num_t cmd_gro_show_pid =
4593         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4594                         cmd_pid, UINT16);
4595 cmdline_parse_token_string_t cmd_gro_show_keyword =
4596         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4597                         cmd_keyword, "gro");
4598
4599 cmdline_parse_inst_t cmd_gro_show = {
4600         .f = cmd_gro_show_parsed,
4601         .data = NULL,
4602         .help_str = "show port <port_id> gro",
4603         .tokens = {
4604                 (void *)&cmd_gro_show_show,
4605                 (void *)&cmd_gro_show_port,
4606                 (void *)&cmd_gro_show_pid,
4607                 (void *)&cmd_gro_show_keyword,
4608                 NULL,
4609         },
4610 };
4611
4612 /* *** SET FLUSH CYCLES FOR GRO *** */
4613 struct cmd_gro_flush_result {
4614         cmdline_fixed_string_t cmd_set;
4615         cmdline_fixed_string_t cmd_keyword;
4616         cmdline_fixed_string_t cmd_flush;
4617         uint8_t cmd_cycles;
4618 };
4619
4620 static void
4621 cmd_gro_flush_parsed(void *parsed_result,
4622                 __attribute__((unused)) struct cmdline *cl,
4623                 __attribute__((unused)) void *data)
4624 {
4625         struct cmd_gro_flush_result *res;
4626
4627         res = parsed_result;
4628         if ((!strcmp(res->cmd_keyword, "gro")) &&
4629                         (!strcmp(res->cmd_flush, "flush")))
4630                 setup_gro_flush_cycles(res->cmd_cycles);
4631 }
4632
4633 cmdline_parse_token_string_t cmd_gro_flush_set =
4634         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4635                         cmd_set, "set");
4636 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4637         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4638                         cmd_keyword, "gro");
4639 cmdline_parse_token_string_t cmd_gro_flush_flush =
4640         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4641                         cmd_flush, "flush");
4642 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4643         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4644                         cmd_cycles, UINT8);
4645
4646 cmdline_parse_inst_t cmd_gro_flush = {
4647         .f = cmd_gro_flush_parsed,
4648         .data = NULL,
4649         .help_str = "set gro flush <cycles>",
4650         .tokens = {
4651                 (void *)&cmd_gro_flush_set,
4652                 (void *)&cmd_gro_flush_keyword,
4653                 (void *)&cmd_gro_flush_flush,
4654                 (void *)&cmd_gro_flush_cycles,
4655                 NULL,
4656         },
4657 };
4658
4659 /* *** ENABLE/DISABLE GSO *** */
4660 struct cmd_gso_enable_result {
4661         cmdline_fixed_string_t cmd_set;
4662         cmdline_fixed_string_t cmd_port;
4663         cmdline_fixed_string_t cmd_keyword;
4664         cmdline_fixed_string_t cmd_mode;
4665         portid_t cmd_pid;
4666 };
4667
4668 static void
4669 cmd_gso_enable_parsed(void *parsed_result,
4670                 __attribute__((unused)) struct cmdline *cl,
4671                 __attribute__((unused)) void *data)
4672 {
4673         struct cmd_gso_enable_result *res;
4674
4675         res = parsed_result;
4676         if (!strcmp(res->cmd_keyword, "gso"))
4677                 setup_gso(res->cmd_mode, res->cmd_pid);
4678 }
4679
4680 cmdline_parse_token_string_t cmd_gso_enable_set =
4681         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4682                         cmd_set, "set");
4683 cmdline_parse_token_string_t cmd_gso_enable_port =
4684         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4685                         cmd_port, "port");
4686 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4687         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4688                         cmd_keyword, "gso");
4689 cmdline_parse_token_string_t cmd_gso_enable_mode =
4690         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4691                         cmd_mode, "on#off");
4692 cmdline_parse_token_num_t cmd_gso_enable_pid =
4693         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4694                         cmd_pid, UINT16);
4695
4696 cmdline_parse_inst_t cmd_gso_enable = {
4697         .f = cmd_gso_enable_parsed,
4698         .data = NULL,
4699         .help_str = "set port <port_id> gso on|off",
4700         .tokens = {
4701                 (void *)&cmd_gso_enable_set,
4702                 (void *)&cmd_gso_enable_port,
4703                 (void *)&cmd_gso_enable_pid,
4704                 (void *)&cmd_gso_enable_keyword,
4705                 (void *)&cmd_gso_enable_mode,
4706                 NULL,
4707         },
4708 };
4709
4710 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4711 struct cmd_gso_size_result {
4712         cmdline_fixed_string_t cmd_set;
4713         cmdline_fixed_string_t cmd_keyword;
4714         cmdline_fixed_string_t cmd_segsz;
4715         uint16_t cmd_size;
4716 };
4717
4718 static void
4719 cmd_gso_size_parsed(void *parsed_result,
4720                        __attribute__((unused)) struct cmdline *cl,
4721                        __attribute__((unused)) void *data)
4722 {
4723         struct cmd_gso_size_result *res = parsed_result;
4724
4725         if (test_done == 0) {
4726                 printf("Before setting GSO segsz, please first"
4727                                 " stop fowarding\n");
4728                 return;
4729         }
4730
4731         if (!strcmp(res->cmd_keyword, "gso") &&
4732                         !strcmp(res->cmd_segsz, "segsz")) {
4733                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4734                         printf("gso_size should be larger than %zu."
4735                                         " Please input a legal value\n",
4736                                         RTE_GSO_SEG_SIZE_MIN);
4737                 else
4738                         gso_max_segment_size = res->cmd_size;
4739         }
4740 }
4741
4742 cmdline_parse_token_string_t cmd_gso_size_set =
4743         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4744                                 cmd_set, "set");
4745 cmdline_parse_token_string_t cmd_gso_size_keyword =
4746         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4747                                 cmd_keyword, "gso");
4748 cmdline_parse_token_string_t cmd_gso_size_segsz =
4749         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4750                                 cmd_segsz, "segsz");
4751 cmdline_parse_token_num_t cmd_gso_size_size =
4752         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4753                                 cmd_size, UINT16);
4754
4755 cmdline_parse_inst_t cmd_gso_size = {
4756         .f = cmd_gso_size_parsed,
4757         .data = NULL,
4758         .help_str = "set gso segsz <length>",
4759         .tokens = {
4760                 (void *)&cmd_gso_size_set,
4761                 (void *)&cmd_gso_size_keyword,
4762                 (void *)&cmd_gso_size_segsz,
4763                 (void *)&cmd_gso_size_size,
4764                 NULL,
4765         },
4766 };
4767
4768 /* *** SHOW GSO CONFIGURATION *** */
4769 struct cmd_gso_show_result {
4770         cmdline_fixed_string_t cmd_show;
4771         cmdline_fixed_string_t cmd_port;
4772         cmdline_fixed_string_t cmd_keyword;
4773         portid_t cmd_pid;
4774 };
4775
4776 static void
4777 cmd_gso_show_parsed(void *parsed_result,
4778                        __attribute__((unused)) struct cmdline *cl,
4779                        __attribute__((unused)) void *data)
4780 {
4781         struct cmd_gso_show_result *res = parsed_result;
4782
4783         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4784                 printf("invalid port id %u\n", res->cmd_pid);
4785                 return;
4786         }
4787         if (!strcmp(res->cmd_keyword, "gso")) {
4788                 if (gso_ports[res->cmd_pid].enable) {
4789                         printf("Max GSO'd packet size: %uB\n"
4790                                         "Supported GSO types: TCP/IPv4, "
4791                                         "VxLAN with inner TCP/IPv4 packet, "
4792                                         "GRE with inner TCP/IPv4  packet\n",
4793                                         gso_max_segment_size);
4794                 } else
4795                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4796         }
4797 }
4798
4799 cmdline_parse_token_string_t cmd_gso_show_show =
4800 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4801                 cmd_show, "show");
4802 cmdline_parse_token_string_t cmd_gso_show_port =
4803 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4804                 cmd_port, "port");
4805 cmdline_parse_token_string_t cmd_gso_show_keyword =
4806         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4807                                 cmd_keyword, "gso");
4808 cmdline_parse_token_num_t cmd_gso_show_pid =
4809         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4810                                 cmd_pid, UINT16);
4811
4812 cmdline_parse_inst_t cmd_gso_show = {
4813         .f = cmd_gso_show_parsed,
4814         .data = NULL,
4815         .help_str = "show port <port_id> gso",
4816         .tokens = {
4817                 (void *)&cmd_gso_show_show,
4818                 (void *)&cmd_gso_show_port,
4819                 (void *)&cmd_gso_show_pid,
4820                 (void *)&cmd_gso_show_keyword,
4821                 NULL,
4822         },
4823 };
4824
4825 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4826 struct cmd_set_flush_rx {
4827         cmdline_fixed_string_t set;
4828         cmdline_fixed_string_t flush_rx;
4829         cmdline_fixed_string_t mode;
4830 };
4831
4832 static void
4833 cmd_set_flush_rx_parsed(void *parsed_result,
4834                 __attribute__((unused)) struct cmdline *cl,
4835                 __attribute__((unused)) void *data)
4836 {
4837         struct cmd_set_flush_rx *res = parsed_result;
4838         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4839 }
4840
4841 cmdline_parse_token_string_t cmd_setflushrx_set =
4842         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4843                         set, "set");
4844 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4845         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4846                         flush_rx, "flush_rx");
4847 cmdline_parse_token_string_t cmd_setflushrx_mode =
4848         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4849                         mode, "on#off");
4850
4851
4852 cmdline_parse_inst_t cmd_set_flush_rx = {
4853         .f = cmd_set_flush_rx_parsed,
4854         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4855         .data = NULL,
4856         .tokens = {
4857                 (void *)&cmd_setflushrx_set,
4858                 (void *)&cmd_setflushrx_flush_rx,
4859                 (void *)&cmd_setflushrx_mode,
4860                 NULL,
4861         },
4862 };
4863
4864 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4865 struct cmd_set_link_check {
4866         cmdline_fixed_string_t set;
4867         cmdline_fixed_string_t link_check;
4868         cmdline_fixed_string_t mode;
4869 };
4870
4871 static void
4872 cmd_set_link_check_parsed(void *parsed_result,
4873                 __attribute__((unused)) struct cmdline *cl,
4874                 __attribute__((unused)) void *data)
4875 {
4876         struct cmd_set_link_check *res = parsed_result;
4877         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4878 }
4879
4880 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4881         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4882                         set, "set");
4883 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4884         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4885                         link_check, "link_check");
4886 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4887         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4888                         mode, "on#off");
4889
4890
4891 cmdline_parse_inst_t cmd_set_link_check = {
4892         .f = cmd_set_link_check_parsed,
4893         .help_str = "set link_check on|off: Enable/Disable link status check "
4894                     "when starting/stopping a port",
4895         .data = NULL,
4896         .tokens = {
4897                 (void *)&cmd_setlinkcheck_set,
4898                 (void *)&cmd_setlinkcheck_link_check,
4899                 (void *)&cmd_setlinkcheck_mode,
4900                 NULL,
4901         },
4902 };
4903
4904 /* *** SET NIC BYPASS MODE *** */
4905 struct cmd_set_bypass_mode_result {
4906         cmdline_fixed_string_t set;
4907         cmdline_fixed_string_t bypass;
4908         cmdline_fixed_string_t mode;
4909         cmdline_fixed_string_t value;
4910         portid_t port_id;
4911 };
4912
4913 static void
4914 cmd_set_bypass_mode_parsed(void *parsed_result,
4915                 __attribute__((unused)) struct cmdline *cl,
4916                 __attribute__((unused)) void *data)
4917 {
4918         struct cmd_set_bypass_mode_result *res = parsed_result;
4919         portid_t port_id = res->port_id;
4920         int32_t rc = -EINVAL;
4921
4922 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4923         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4924
4925         if (!strcmp(res->value, "bypass"))
4926                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4927         else if (!strcmp(res->value, "isolate"))
4928                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4929         else
4930                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4931
4932         /* Set the bypass mode for the relevant port. */
4933         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4934 #endif
4935         if (rc != 0)
4936                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4937 }
4938
4939 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4940         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4941                         set, "set");
4942 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4943         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4944                         bypass, "bypass");
4945 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4946         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4947                         mode, "mode");
4948 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4949         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4950                         value, "normal#bypass#isolate");
4951 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4952         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4953                                 port_id, UINT16);
4954
4955 cmdline_parse_inst_t cmd_set_bypass_mode = {
4956         .f = cmd_set_bypass_mode_parsed,
4957         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4958                     "Set the NIC bypass mode for port_id",
4959         .data = NULL,
4960         .tokens = {
4961                 (void *)&cmd_setbypass_mode_set,
4962                 (void *)&cmd_setbypass_mode_bypass,
4963                 (void *)&cmd_setbypass_mode_mode,
4964                 (void *)&cmd_setbypass_mode_value,
4965                 (void *)&cmd_setbypass_mode_port,
4966                 NULL,
4967         },
4968 };
4969
4970 /* *** SET NIC BYPASS EVENT *** */
4971 struct cmd_set_bypass_event_result {
4972         cmdline_fixed_string_t set;
4973         cmdline_fixed_string_t bypass;
4974         cmdline_fixed_string_t event;
4975         cmdline_fixed_string_t event_value;
4976         cmdline_fixed_string_t mode;
4977         cmdline_fixed_string_t mode_value;
4978         portid_t port_id;
4979 };
4980
4981 static void
4982 cmd_set_bypass_event_parsed(void *parsed_result,
4983                 __attribute__((unused)) struct cmdline *cl,
4984                 __attribute__((unused)) void *data)
4985 {
4986         int32_t rc = -EINVAL;
4987         struct cmd_set_bypass_event_result *res = parsed_result;
4988         portid_t port_id = res->port_id;
4989
4990 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4991         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4992         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4993
4994         if (!strcmp(res->event_value, "timeout"))
4995                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4996         else if (!strcmp(res->event_value, "os_on"))
4997                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4998         else if (!strcmp(res->event_value, "os_off"))
4999                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5000         else if (!strcmp(res->event_value, "power_on"))
5001                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5002         else if (!strcmp(res->event_value, "power_off"))
5003                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5004         else
5005                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5006
5007         if (!strcmp(res->mode_value, "bypass"))
5008                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5009         else if (!strcmp(res->mode_value, "isolate"))
5010                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5011         else
5012                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5013
5014         /* Set the watchdog timeout. */
5015         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5016
5017                 rc = -EINVAL;
5018                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5019                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5020                                                            bypass_timeout);
5021                 }
5022                 if (rc != 0) {
5023                         printf("Failed to set timeout value %u "
5024                         "for port %d, errto code: %d.\n",
5025                         bypass_timeout, port_id, rc);
5026                 }
5027         }
5028
5029         /* Set the bypass event to transition to bypass mode. */
5030         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5031                                               bypass_mode);
5032 #endif
5033
5034         if (rc != 0)
5035                 printf("\t Failed to set bypass event for port = %d.\n",
5036                        port_id);
5037 }
5038
5039 cmdline_parse_token_string_t cmd_setbypass_event_set =
5040         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5041                         set, "set");
5042 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5043         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5044                         bypass, "bypass");
5045 cmdline_parse_token_string_t cmd_setbypass_event_event =
5046         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5047                         event, "event");
5048 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5049         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5050                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5051 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5052         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5053                         mode, "mode");
5054 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5055         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5056                         mode_value, "normal#bypass#isolate");
5057 cmdline_parse_token_num_t cmd_setbypass_event_port =
5058         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5059                                 port_id, UINT16);
5060
5061 cmdline_parse_inst_t cmd_set_bypass_event = {
5062         .f = cmd_set_bypass_event_parsed,
5063         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5064                 "power_off mode normal|bypass|isolate <port_id>: "
5065                 "Set the NIC bypass event mode for port_id",
5066         .data = NULL,
5067         .tokens = {
5068                 (void *)&cmd_setbypass_event_set,
5069                 (void *)&cmd_setbypass_event_bypass,
5070                 (void *)&cmd_setbypass_event_event,
5071                 (void *)&cmd_setbypass_event_event_value,
5072                 (void *)&cmd_setbypass_event_mode,
5073                 (void *)&cmd_setbypass_event_mode_value,
5074                 (void *)&cmd_setbypass_event_port,
5075                 NULL,
5076         },
5077 };
5078
5079
5080 /* *** SET NIC BYPASS TIMEOUT *** */
5081 struct cmd_set_bypass_timeout_result {
5082         cmdline_fixed_string_t set;
5083         cmdline_fixed_string_t bypass;
5084         cmdline_fixed_string_t timeout;
5085         cmdline_fixed_string_t value;
5086 };
5087
5088 static void
5089 cmd_set_bypass_timeout_parsed(void *parsed_result,
5090                 __attribute__((unused)) struct cmdline *cl,
5091                 __attribute__((unused)) void *data)
5092 {
5093         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5094
5095 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5096         if (!strcmp(res->value, "1.5"))
5097                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5098         else if (!strcmp(res->value, "2"))
5099                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5100         else if (!strcmp(res->value, "3"))
5101                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5102         else if (!strcmp(res->value, "4"))
5103                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5104         else if (!strcmp(res->value, "8"))
5105                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5106         else if (!strcmp(res->value, "16"))
5107                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5108         else if (!strcmp(res->value, "32"))
5109                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5110         else
5111                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5112 #endif
5113 }
5114
5115 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5116         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5117                         set, "set");
5118 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5119         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5120                         bypass, "bypass");
5121 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5122         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5123                         timeout, "timeout");
5124 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5125         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5126                         value, "0#1.5#2#3#4#8#16#32");
5127
5128 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5129         .f = cmd_set_bypass_timeout_parsed,
5130         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5131                 "Set the NIC bypass watchdog timeout in seconds",
5132         .data = NULL,
5133         .tokens = {
5134                 (void *)&cmd_setbypass_timeout_set,
5135                 (void *)&cmd_setbypass_timeout_bypass,
5136                 (void *)&cmd_setbypass_timeout_timeout,
5137                 (void *)&cmd_setbypass_timeout_value,
5138                 NULL,
5139         },
5140 };
5141
5142 /* *** SHOW NIC BYPASS MODE *** */
5143 struct cmd_show_bypass_config_result {
5144         cmdline_fixed_string_t show;
5145         cmdline_fixed_string_t bypass;
5146         cmdline_fixed_string_t config;
5147         portid_t port_id;
5148 };
5149
5150 static void
5151 cmd_show_bypass_config_parsed(void *parsed_result,
5152                 __attribute__((unused)) struct cmdline *cl,
5153                 __attribute__((unused)) void *data)
5154 {
5155         struct cmd_show_bypass_config_result *res = parsed_result;
5156         portid_t port_id = res->port_id;
5157         int rc = -EINVAL;
5158 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5159         uint32_t event_mode;
5160         uint32_t bypass_mode;
5161         uint32_t timeout = bypass_timeout;
5162         int i;
5163
5164         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5165                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5166         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5167                 {"UNKNOWN", "normal", "bypass", "isolate"};
5168         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5169                 "NONE",
5170                 "OS/board on",
5171                 "power supply on",
5172                 "OS/board off",
5173                 "power supply off",
5174                 "timeout"};
5175         int num_events = (sizeof events) / (sizeof events[0]);
5176
5177         /* Display the bypass mode.*/
5178         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5179                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5180                 return;
5181         }
5182         else {
5183                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5184                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5185
5186                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5187         }
5188
5189         /* Display the bypass timeout.*/
5190         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5191                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5192
5193         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5194
5195         /* Display the bypass events and associated modes. */
5196         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5197
5198                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5199                         printf("\tFailed to get bypass mode for event = %s\n",
5200                                 events[i]);
5201                 } else {
5202                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5203                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5204
5205                         printf("\tbypass event: %-16s = %s\n", events[i],
5206                                 modes[event_mode]);
5207                 }
5208         }
5209 #endif
5210         if (rc != 0)
5211                 printf("\tFailed to get bypass configuration for port = %d\n",
5212                        port_id);
5213 }
5214
5215 cmdline_parse_token_string_t cmd_showbypass_config_show =
5216         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5217                         show, "show");
5218 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5219         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5220                         bypass, "bypass");
5221 cmdline_parse_token_string_t cmd_showbypass_config_config =
5222         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5223                         config, "config");
5224 cmdline_parse_token_num_t cmd_showbypass_config_port =
5225         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5226                                 port_id, UINT16);
5227
5228 cmdline_parse_inst_t cmd_show_bypass_config = {
5229         .f = cmd_show_bypass_config_parsed,
5230         .help_str = "show bypass config <port_id>: "
5231                     "Show the NIC bypass config for port_id",
5232         .data = NULL,
5233         .tokens = {
5234                 (void *)&cmd_showbypass_config_show,
5235                 (void *)&cmd_showbypass_config_bypass,
5236                 (void *)&cmd_showbypass_config_config,
5237                 (void *)&cmd_showbypass_config_port,
5238                 NULL,
5239         },
5240 };
5241
5242 #ifdef RTE_LIBRTE_PMD_BOND
5243 /* *** SET BONDING MODE *** */
5244 struct cmd_set_bonding_mode_result {
5245         cmdline_fixed_string_t set;
5246         cmdline_fixed_string_t bonding;
5247         cmdline_fixed_string_t mode;
5248         uint8_t value;
5249         portid_t port_id;
5250 };
5251
5252 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5253                 __attribute__((unused))  struct cmdline *cl,
5254                 __attribute__((unused)) void *data)
5255 {
5256         struct cmd_set_bonding_mode_result *res = parsed_result;
5257         portid_t port_id = res->port_id;
5258
5259         /* Set the bonding mode for the relevant port. */
5260         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5261                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5262 }
5263
5264 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5265 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5266                 set, "set");
5267 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5268 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5269                 bonding, "bonding");
5270 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5271 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5272                 mode, "mode");
5273 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5274 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5275                 value, UINT8);
5276 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5277 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5278                 port_id, UINT16);
5279
5280 cmdline_parse_inst_t cmd_set_bonding_mode = {
5281                 .f = cmd_set_bonding_mode_parsed,
5282                 .help_str = "set bonding mode <mode_value> <port_id>: "
5283                         "Set the bonding mode for port_id",
5284                 .data = NULL,
5285                 .tokens = {
5286                                 (void *) &cmd_setbonding_mode_set,
5287                                 (void *) &cmd_setbonding_mode_bonding,
5288                                 (void *) &cmd_setbonding_mode_mode,
5289                                 (void *) &cmd_setbonding_mode_value,
5290                                 (void *) &cmd_setbonding_mode_port,
5291                                 NULL
5292                 }
5293 };
5294
5295 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5296 struct cmd_set_bonding_lacp_dedicated_queues_result {
5297         cmdline_fixed_string_t set;
5298         cmdline_fixed_string_t bonding;
5299         cmdline_fixed_string_t lacp;
5300         cmdline_fixed_string_t dedicated_queues;
5301         portid_t port_id;
5302         cmdline_fixed_string_t mode;
5303 };
5304
5305 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5306                 __attribute__((unused))  struct cmdline *cl,
5307                 __attribute__((unused)) void *data)
5308 {
5309         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5310         portid_t port_id = res->port_id;
5311         struct rte_port *port;
5312
5313         port = &ports[port_id];
5314
5315         /** Check if the port is not started **/
5316         if (port->port_status != RTE_PORT_STOPPED) {
5317                 printf("Please stop port %d first\n", port_id);
5318                 return;
5319         }
5320
5321         if (!strcmp(res->mode, "enable")) {
5322                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5323                         printf("Dedicate queues for LACP control packets"
5324                                         " enabled\n");
5325                 else
5326                         printf("Enabling dedicate queues for LACP control "
5327                                         "packets on port %d failed\n", port_id);
5328         } else if (!strcmp(res->mode, "disable")) {
5329                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5330                         printf("Dedicated queues for LACP control packets "
5331                                         "disabled\n");
5332                 else
5333                         printf("Disabling dedicated queues for LACP control "
5334                                         "traffic on port %d failed\n", port_id);
5335         }
5336 }
5337
5338 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5339 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5340                 set, "set");
5341 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5342 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5343                 bonding, "bonding");
5344 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5345 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5346                 lacp, "lacp");
5347 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5348 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5349                 dedicated_queues, "dedicated_queues");
5350 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5351 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5352                 port_id, UINT16);
5353 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5354 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5355                 mode, "enable#disable");
5356
5357 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5358                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5359                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5360                         "enable|disable: "
5361                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5362                 .data = NULL,
5363                 .tokens = {
5364                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5365                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5366                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5367                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5368                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5369                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5370                         NULL
5371                 }
5372 };
5373
5374 /* *** SET BALANCE XMIT POLICY *** */
5375 struct cmd_set_bonding_balance_xmit_policy_result {
5376         cmdline_fixed_string_t set;
5377         cmdline_fixed_string_t bonding;
5378         cmdline_fixed_string_t balance_xmit_policy;
5379         portid_t port_id;
5380         cmdline_fixed_string_t policy;
5381 };
5382
5383 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5384                 __attribute__((unused))  struct cmdline *cl,
5385                 __attribute__((unused)) void *data)
5386 {
5387         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5388         portid_t port_id = res->port_id;
5389         uint8_t policy;
5390
5391         if (!strcmp(res->policy, "l2")) {
5392                 policy = BALANCE_XMIT_POLICY_LAYER2;
5393         } else if (!strcmp(res->policy, "l23")) {
5394                 policy = BALANCE_XMIT_POLICY_LAYER23;
5395         } else if (!strcmp(res->policy, "l34")) {
5396                 policy = BALANCE_XMIT_POLICY_LAYER34;
5397         } else {
5398                 printf("\t Invalid xmit policy selection");
5399                 return;
5400         }
5401
5402         /* Set the bonding mode for the relevant port. */
5403         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5404                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5405                                 port_id);
5406         }
5407 }
5408
5409 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5410 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5411                 set, "set");
5412 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5413 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5414                 bonding, "bonding");
5415 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5416 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5417                 balance_xmit_policy, "balance_xmit_policy");
5418 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5419 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5420                 port_id, UINT16);
5421 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5422 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5423                 policy, "l2#l23#l34");
5424
5425 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5426                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5427                 .help_str = "set bonding balance_xmit_policy <port_id> "
5428                         "l2|l23|l34: "
5429                         "Set the bonding balance_xmit_policy for port_id",
5430                 .data = NULL,
5431                 .tokens = {
5432                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5433                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5434                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5435                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5436                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5437                                 NULL
5438                 }
5439 };
5440
5441 /* *** SHOW NIC BONDING CONFIGURATION *** */
5442 struct cmd_show_bonding_config_result {
5443         cmdline_fixed_string_t show;
5444         cmdline_fixed_string_t bonding;
5445         cmdline_fixed_string_t config;
5446         portid_t port_id;
5447 };
5448
5449 static void cmd_show_bonding_config_parsed(void *parsed_result,
5450                 __attribute__((unused))  struct cmdline *cl,
5451                 __attribute__((unused)) void *data)
5452 {
5453         struct cmd_show_bonding_config_result *res = parsed_result;
5454         int bonding_mode, agg_mode;
5455         portid_t slaves[RTE_MAX_ETHPORTS];
5456         int num_slaves, num_active_slaves;
5457         int primary_id;
5458         int i;
5459         portid_t port_id = res->port_id;
5460
5461         /* Display the bonding mode.*/
5462         bonding_mode = rte_eth_bond_mode_get(port_id);
5463         if (bonding_mode < 0) {
5464                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5465                 return;
5466         } else
5467                 printf("\tBonding mode: %d\n", bonding_mode);
5468
5469         if (bonding_mode == BONDING_MODE_BALANCE) {
5470                 int balance_xmit_policy;
5471
5472                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5473                 if (balance_xmit_policy < 0) {
5474                         printf("\tFailed to get balance xmit policy for port = %d\n",
5475                                         port_id);
5476                         return;
5477                 } else {
5478                         printf("\tBalance Xmit Policy: ");
5479
5480                         switch (balance_xmit_policy) {
5481                         case BALANCE_XMIT_POLICY_LAYER2:
5482                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5483                                 break;
5484                         case BALANCE_XMIT_POLICY_LAYER23:
5485                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5486                                 break;
5487                         case BALANCE_XMIT_POLICY_LAYER34:
5488                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5489                                 break;
5490                         }
5491                         printf("\n");
5492                 }
5493         }
5494
5495         if (bonding_mode == BONDING_MODE_8023AD) {
5496                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5497                 printf("\tIEEE802.3AD Aggregator Mode: ");
5498                 switch (agg_mode) {
5499                 case AGG_BANDWIDTH:
5500                         printf("bandwidth");
5501                         break;
5502                 case AGG_STABLE:
5503                         printf("stable");
5504                         break;
5505                 case AGG_COUNT:
5506                         printf("count");
5507                         break;
5508                 }
5509                 printf("\n");
5510         }
5511
5512         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5513
5514         if (num_slaves < 0) {
5515                 printf("\tFailed to get slave list for port = %d\n", port_id);
5516                 return;
5517         }
5518         if (num_slaves > 0) {
5519                 printf("\tSlaves (%d): [", num_slaves);
5520                 for (i = 0; i < num_slaves - 1; i++)
5521                         printf("%d ", slaves[i]);
5522
5523                 printf("%d]\n", slaves[num_slaves - 1]);
5524         } else {
5525                 printf("\tSlaves: []\n");
5526
5527         }
5528
5529         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5530                         RTE_MAX_ETHPORTS);
5531
5532         if (num_active_slaves < 0) {
5533                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5534                 return;
5535         }
5536         if (num_active_slaves > 0) {
5537                 printf("\tActive Slaves (%d): [", num_active_slaves);
5538                 for (i = 0; i < num_active_slaves - 1; i++)
5539                         printf("%d ", slaves[i]);
5540
5541                 printf("%d]\n", slaves[num_active_slaves - 1]);
5542
5543         } else {
5544                 printf("\tActive Slaves: []\n");
5545
5546         }
5547
5548         primary_id = rte_eth_bond_primary_get(port_id);
5549         if (primary_id < 0) {
5550                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5551                 return;
5552         } else
5553                 printf("\tPrimary: [%d]\n", primary_id);
5554
5555 }
5556
5557 cmdline_parse_token_string_t cmd_showbonding_config_show =
5558 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5559                 show, "show");
5560 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5561 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5562                 bonding, "bonding");
5563 cmdline_parse_token_string_t cmd_showbonding_config_config =
5564 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5565                 config, "config");
5566 cmdline_parse_token_num_t cmd_showbonding_config_port =
5567 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5568                 port_id, UINT16);
5569
5570 cmdline_parse_inst_t cmd_show_bonding_config = {
5571                 .f = cmd_show_bonding_config_parsed,
5572                 .help_str = "show bonding config <port_id>: "
5573                         "Show the bonding config for port_id",
5574                 .data = NULL,
5575                 .tokens = {
5576                                 (void *)&cmd_showbonding_config_show,
5577                                 (void *)&cmd_showbonding_config_bonding,
5578                                 (void *)&cmd_showbonding_config_config,
5579                                 (void *)&cmd_showbonding_config_port,
5580                                 NULL
5581                 }
5582 };
5583
5584 /* *** SET BONDING PRIMARY *** */
5585 struct cmd_set_bonding_primary_result {
5586         cmdline_fixed_string_t set;
5587         cmdline_fixed_string_t bonding;
5588         cmdline_fixed_string_t primary;
5589         portid_t slave_id;
5590         portid_t port_id;
5591 };
5592
5593 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5594                 __attribute__((unused))  struct cmdline *cl,
5595                 __attribute__((unused)) void *data)
5596 {
5597         struct cmd_set_bonding_primary_result *res = parsed_result;
5598         portid_t master_port_id = res->port_id;
5599         portid_t slave_port_id = res->slave_id;
5600
5601         /* Set the primary slave for a bonded device. */
5602         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5603                 printf("\t Failed to set primary slave for port = %d.\n",
5604                                 master_port_id);
5605                 return;
5606         }
5607         init_port_config();
5608 }
5609
5610 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5611 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5612                 set, "set");
5613 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5614 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5615                 bonding, "bonding");
5616 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5617 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5618                 primary, "primary");
5619 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5620 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5621                 slave_id, UINT16);
5622 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5623 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5624                 port_id, UINT16);
5625
5626 cmdline_parse_inst_t cmd_set_bonding_primary = {
5627                 .f = cmd_set_bonding_primary_parsed,
5628                 .help_str = "set bonding primary <slave_id> <port_id>: "
5629                         "Set the primary slave for port_id",
5630                 .data = NULL,
5631                 .tokens = {
5632                                 (void *)&cmd_setbonding_primary_set,
5633                                 (void *)&cmd_setbonding_primary_bonding,
5634                                 (void *)&cmd_setbonding_primary_primary,
5635                                 (void *)&cmd_setbonding_primary_slave,
5636                                 (void *)&cmd_setbonding_primary_port,
5637                                 NULL
5638                 }
5639 };
5640
5641 /* *** ADD SLAVE *** */
5642 struct cmd_add_bonding_slave_result {
5643         cmdline_fixed_string_t add;
5644         cmdline_fixed_string_t bonding;
5645         cmdline_fixed_string_t slave;
5646         portid_t slave_id;
5647         portid_t port_id;
5648 };
5649
5650 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5651                 __attribute__((unused))  struct cmdline *cl,
5652                 __attribute__((unused)) void *data)
5653 {
5654         struct cmd_add_bonding_slave_result *res = parsed_result;
5655         portid_t master_port_id = res->port_id;
5656         portid_t slave_port_id = res->slave_id;
5657
5658         /* add the slave for a bonded device. */
5659         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5660                 printf("\t Failed to add slave %d to master port = %d.\n",
5661                                 slave_port_id, master_port_id);
5662                 return;
5663         }
5664         init_port_config();
5665         set_port_slave_flag(slave_port_id);
5666 }
5667
5668 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5669 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5670                 add, "add");
5671 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5672 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5673                 bonding, "bonding");
5674 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5675 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5676                 slave, "slave");
5677 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5678 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5679                 slave_id, UINT16);
5680 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5681 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5682                 port_id, UINT16);
5683
5684 cmdline_parse_inst_t cmd_add_bonding_slave = {
5685                 .f = cmd_add_bonding_slave_parsed,
5686                 .help_str = "add bonding slave <slave_id> <port_id>: "
5687                         "Add a slave device to a bonded device",
5688                 .data = NULL,
5689                 .tokens = {
5690                                 (void *)&cmd_addbonding_slave_add,
5691                                 (void *)&cmd_addbonding_slave_bonding,
5692                                 (void *)&cmd_addbonding_slave_slave,
5693                                 (void *)&cmd_addbonding_slave_slaveid,
5694                                 (void *)&cmd_addbonding_slave_port,
5695                                 NULL
5696                 }
5697 };
5698
5699 /* *** REMOVE SLAVE *** */
5700 struct cmd_remove_bonding_slave_result {
5701         cmdline_fixed_string_t remove;
5702         cmdline_fixed_string_t bonding;
5703         cmdline_fixed_string_t slave;
5704         portid_t slave_id;
5705         portid_t port_id;
5706 };
5707
5708 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5709                 __attribute__((unused))  struct cmdline *cl,
5710                 __attribute__((unused)) void *data)
5711 {
5712         struct cmd_remove_bonding_slave_result *res = parsed_result;
5713         portid_t master_port_id = res->port_id;
5714         portid_t slave_port_id = res->slave_id;
5715
5716         /* remove the slave from a bonded device. */
5717         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5718                 printf("\t Failed to remove slave %d from master port = %d.\n",
5719                                 slave_port_id, master_port_id);
5720                 return;
5721         }
5722         init_port_config();
5723         clear_port_slave_flag(slave_port_id);
5724 }
5725
5726 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5727                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5728                                 remove, "remove");
5729 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5730                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5731                                 bonding, "bonding");
5732 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5733                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5734                                 slave, "slave");
5735 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5736                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5737                                 slave_id, UINT16);
5738 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5739                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5740                                 port_id, UINT16);
5741
5742 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5743                 .f = cmd_remove_bonding_slave_parsed,
5744                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5745                         "Remove a slave device from a bonded device",
5746                 .data = NULL,
5747                 .tokens = {
5748                                 (void *)&cmd_removebonding_slave_remove,
5749                                 (void *)&cmd_removebonding_slave_bonding,
5750                                 (void *)&cmd_removebonding_slave_slave,
5751                                 (void *)&cmd_removebonding_slave_slaveid,
5752                                 (void *)&cmd_removebonding_slave_port,
5753                                 NULL
5754                 }
5755 };
5756
5757 /* *** CREATE BONDED DEVICE *** */
5758 struct cmd_create_bonded_device_result {
5759         cmdline_fixed_string_t create;
5760         cmdline_fixed_string_t bonded;
5761         cmdline_fixed_string_t device;
5762         uint8_t mode;
5763         uint8_t socket;
5764 };
5765
5766 static int bond_dev_num = 0;
5767
5768 static void cmd_create_bonded_device_parsed(void *parsed_result,
5769                 __attribute__((unused))  struct cmdline *cl,
5770                 __attribute__((unused)) void *data)
5771 {
5772         struct cmd_create_bonded_device_result *res = parsed_result;
5773         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5774         int port_id;
5775
5776         if (test_done == 0) {
5777                 printf("Please stop forwarding first\n");
5778                 return;
5779         }
5780
5781         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5782                         bond_dev_num++);
5783
5784         /* Create a new bonded device. */
5785         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5786         if (port_id < 0) {
5787                 printf("\t Failed to create bonded device.\n");
5788                 return;
5789         } else {
5790                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5791                                 port_id);
5792
5793                 /* Update number of ports */
5794                 nb_ports = rte_eth_dev_count_avail();
5795                 reconfig(port_id, res->socket);
5796                 rte_eth_promiscuous_enable(port_id);
5797         }
5798
5799 }
5800
5801 cmdline_parse_token_string_t cmd_createbonded_device_create =
5802                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5803                                 create, "create");
5804 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5805                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5806                                 bonded, "bonded");
5807 cmdline_parse_token_string_t cmd_createbonded_device_device =
5808                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5809                                 device, "device");
5810 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5811                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5812                                 mode, UINT8);
5813 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5814                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5815                                 socket, UINT8);
5816
5817 cmdline_parse_inst_t cmd_create_bonded_device = {
5818                 .f = cmd_create_bonded_device_parsed,
5819                 .help_str = "create bonded device <mode> <socket>: "
5820                         "Create a new bonded device with specific bonding mode and socket",
5821                 .data = NULL,
5822                 .tokens = {
5823                                 (void *)&cmd_createbonded_device_create,
5824                                 (void *)&cmd_createbonded_device_bonded,
5825                                 (void *)&cmd_createbonded_device_device,
5826                                 (void *)&cmd_createbonded_device_mode,
5827                                 (void *)&cmd_createbonded_device_socket,
5828                                 NULL
5829                 }
5830 };
5831
5832 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5833 struct cmd_set_bond_mac_addr_result {
5834         cmdline_fixed_string_t set;
5835         cmdline_fixed_string_t bonding;
5836         cmdline_fixed_string_t mac_addr;
5837         uint16_t port_num;
5838         struct ether_addr address;
5839 };
5840
5841 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5842                 __attribute__((unused))  struct cmdline *cl,
5843                 __attribute__((unused)) void *data)
5844 {
5845         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5846         int ret;
5847
5848         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5849                 return;
5850
5851         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5852
5853         /* check the return value and print it if is < 0 */
5854         if (ret < 0)
5855                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5856 }
5857
5858 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5859                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5860 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5861                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5862                                 "bonding");
5863 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5864                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5865                                 "mac_addr");
5866 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5867                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5868                                 port_num, UINT16);
5869 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5870                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5871
5872 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5873                 .f = cmd_set_bond_mac_addr_parsed,
5874                 .data = (void *) 0,
5875                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5876                 .tokens = {
5877                                 (void *)&cmd_set_bond_mac_addr_set,
5878                                 (void *)&cmd_set_bond_mac_addr_bonding,
5879                                 (void *)&cmd_set_bond_mac_addr_mac,
5880                                 (void *)&cmd_set_bond_mac_addr_portnum,
5881                                 (void *)&cmd_set_bond_mac_addr_addr,
5882                                 NULL
5883                 }
5884 };
5885
5886
5887 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5888 struct cmd_set_bond_mon_period_result {
5889         cmdline_fixed_string_t set;
5890         cmdline_fixed_string_t bonding;
5891         cmdline_fixed_string_t mon_period;
5892         uint16_t port_num;
5893         uint32_t period_ms;
5894 };
5895
5896 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5897                 __attribute__((unused))  struct cmdline *cl,
5898                 __attribute__((unused)) void *data)
5899 {
5900         struct cmd_set_bond_mon_period_result *res = parsed_result;
5901         int ret;
5902
5903         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5904
5905         /* check the return value and print it if is < 0 */
5906         if (ret < 0)
5907                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5908 }
5909
5910 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5911                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5912                                 set, "set");
5913 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5914                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5915                                 bonding, "bonding");
5916 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5917                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5918                                 mon_period,     "mon_period");
5919 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5920                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5921                                 port_num, UINT16);
5922 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5923                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5924                                 period_ms, UINT32);
5925
5926 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5927                 .f = cmd_set_bond_mon_period_parsed,
5928                 .data = (void *) 0,
5929                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5930                 .tokens = {
5931                                 (void *)&cmd_set_bond_mon_period_set,
5932                                 (void *)&cmd_set_bond_mon_period_bonding,
5933                                 (void *)&cmd_set_bond_mon_period_mon_period,
5934                                 (void *)&cmd_set_bond_mon_period_portnum,
5935                                 (void *)&cmd_set_bond_mon_period_period_ms,
5936                                 NULL
5937                 }
5938 };
5939
5940
5941
5942 struct cmd_set_bonding_agg_mode_policy_result {
5943         cmdline_fixed_string_t set;
5944         cmdline_fixed_string_t bonding;
5945         cmdline_fixed_string_t agg_mode;
5946         uint16_t port_num;
5947         cmdline_fixed_string_t policy;
5948 };
5949
5950
5951 static void
5952 cmd_set_bonding_agg_mode(void *parsed_result,
5953                 __attribute__((unused)) struct cmdline *cl,
5954                 __attribute__((unused)) void *data)
5955 {
5956         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5957         uint8_t policy = AGG_BANDWIDTH;
5958
5959         if (!strcmp(res->policy, "bandwidth"))
5960                 policy = AGG_BANDWIDTH;
5961         else if (!strcmp(res->policy, "stable"))
5962                 policy = AGG_STABLE;
5963         else if (!strcmp(res->policy, "count"))
5964                 policy = AGG_COUNT;
5965
5966         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5967 }
5968
5969
5970 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5971         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5972                                 set, "set");
5973 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5974         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5975                                 bonding, "bonding");
5976
5977 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5978         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5979                                 agg_mode, "agg_mode");
5980
5981 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5982         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5983                                 port_num, UINT16);
5984
5985 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5986         TOKEN_STRING_INITIALIZER(
5987                         struct cmd_set_bonding_balance_xmit_policy_result,
5988                 policy, "stable#bandwidth#count");
5989
5990 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5991         .f = cmd_set_bonding_agg_mode,
5992         .data = (void *) 0,
5993         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5994         .tokens = {
5995                         (void *)&cmd_set_bonding_agg_mode_set,
5996                         (void *)&cmd_set_bonding_agg_mode_bonding,
5997                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5998                         (void *)&cmd_set_bonding_agg_mode_portnum,
5999                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6000                         NULL
6001                 }
6002 };
6003
6004
6005 #endif /* RTE_LIBRTE_PMD_BOND */
6006
6007 /* *** SET FORWARDING MODE *** */
6008 struct cmd_set_fwd_mode_result {
6009         cmdline_fixed_string_t set;
6010         cmdline_fixed_string_t fwd;
6011         cmdline_fixed_string_t mode;
6012 };
6013
6014 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6015                                     __attribute__((unused)) struct cmdline *cl,
6016                                     __attribute__((unused)) void *data)
6017 {
6018         struct cmd_set_fwd_mode_result *res = parsed_result;
6019
6020         retry_enabled = 0;
6021         set_pkt_forwarding_mode(res->mode);
6022 }
6023
6024 cmdline_parse_token_string_t cmd_setfwd_set =
6025         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6026 cmdline_parse_token_string_t cmd_setfwd_fwd =
6027         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6028 cmdline_parse_token_string_t cmd_setfwd_mode =
6029         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6030                 "" /* defined at init */);
6031
6032 cmdline_parse_inst_t cmd_set_fwd_mode = {
6033         .f = cmd_set_fwd_mode_parsed,
6034         .data = NULL,
6035         .help_str = NULL, /* defined at init */
6036         .tokens = {
6037                 (void *)&cmd_setfwd_set,
6038                 (void *)&cmd_setfwd_fwd,
6039                 (void *)&cmd_setfwd_mode,
6040                 NULL,
6041         },
6042 };
6043
6044 static void cmd_set_fwd_mode_init(void)
6045 {
6046         char *modes, *c;
6047         static char token[128];
6048         static char help[256];
6049         cmdline_parse_token_string_t *token_struct;
6050
6051         modes = list_pkt_forwarding_modes();
6052         snprintf(help, sizeof(help), "set fwd %s: "
6053                 "Set packet forwarding mode", modes);
6054         cmd_set_fwd_mode.help_str = help;
6055
6056         /* string token separator is # */
6057         for (c = token; *modes != '\0'; modes++)
6058                 if (*modes == '|')
6059                         *c++ = '#';
6060                 else
6061                         *c++ = *modes;
6062         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6063         token_struct->string_data.str = token;
6064 }
6065
6066 /* *** SET RETRY FORWARDING MODE *** */
6067 struct cmd_set_fwd_retry_mode_result {
6068         cmdline_fixed_string_t set;
6069         cmdline_fixed_string_t fwd;
6070         cmdline_fixed_string_t mode;
6071         cmdline_fixed_string_t retry;
6072 };
6073
6074 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6075                             __attribute__((unused)) struct cmdline *cl,
6076                             __attribute__((unused)) void *data)
6077 {
6078         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6079
6080         retry_enabled = 1;
6081         set_pkt_forwarding_mode(res->mode);
6082 }
6083
6084 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6085         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6086                         set, "set");
6087 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6088         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6089                         fwd, "fwd");
6090 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6091         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6092                         mode,
6093                 "" /* defined at init */);
6094 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6095         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6096                         retry, "retry");
6097
6098 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6099         .f = cmd_set_fwd_retry_mode_parsed,
6100         .data = NULL,
6101         .help_str = NULL, /* defined at init */
6102         .tokens = {
6103                 (void *)&cmd_setfwd_retry_set,
6104                 (void *)&cmd_setfwd_retry_fwd,
6105                 (void *)&cmd_setfwd_retry_mode,
6106                 (void *)&cmd_setfwd_retry_retry,
6107                 NULL,
6108         },
6109 };
6110
6111 static void cmd_set_fwd_retry_mode_init(void)
6112 {
6113         char *modes, *c;
6114         static char token[128];
6115         static char help[256];
6116         cmdline_parse_token_string_t *token_struct;
6117
6118         modes = list_pkt_forwarding_retry_modes();
6119         snprintf(help, sizeof(help), "set fwd %s retry: "
6120                 "Set packet forwarding mode with retry", modes);
6121         cmd_set_fwd_retry_mode.help_str = help;
6122
6123         /* string token separator is # */
6124         for (c = token; *modes != '\0'; modes++)
6125                 if (*modes == '|')
6126                         *c++ = '#';
6127                 else
6128                         *c++ = *modes;
6129         token_struct = (cmdline_parse_token_string_t *)
6130                 cmd_set_fwd_retry_mode.tokens[2];
6131         token_struct->string_data.str = token;
6132 }
6133
6134 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6135 struct cmd_set_burst_tx_retry_result {
6136         cmdline_fixed_string_t set;
6137         cmdline_fixed_string_t burst;
6138         cmdline_fixed_string_t tx;
6139         cmdline_fixed_string_t delay;
6140         uint32_t time;
6141         cmdline_fixed_string_t retry;
6142         uint32_t retry_num;
6143 };
6144
6145 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6146                                         __attribute__((unused)) struct cmdline *cl,
6147                                         __attribute__((unused)) void *data)
6148 {
6149         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6150
6151         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6152                 && !strcmp(res->tx, "tx")) {
6153                 if (!strcmp(res->delay, "delay"))
6154                         burst_tx_delay_time = res->time;
6155                 if (!strcmp(res->retry, "retry"))
6156                         burst_tx_retry_num = res->retry_num;
6157         }
6158
6159 }
6160
6161 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6162         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6163 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6164         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6165                                  "burst");
6166 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6167         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6168 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6169         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6170 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6171         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6172 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6173         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6174 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6175         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6176
6177 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6178         .f = cmd_set_burst_tx_retry_parsed,
6179         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6180         .tokens = {
6181                 (void *)&cmd_set_burst_tx_retry_set,
6182                 (void *)&cmd_set_burst_tx_retry_burst,
6183                 (void *)&cmd_set_burst_tx_retry_tx,
6184                 (void *)&cmd_set_burst_tx_retry_delay,
6185                 (void *)&cmd_set_burst_tx_retry_time,
6186                 (void *)&cmd_set_burst_tx_retry_retry,
6187                 (void *)&cmd_set_burst_tx_retry_retry_num,
6188                 NULL,
6189         },
6190 };
6191
6192 /* *** SET PROMISC MODE *** */
6193 struct cmd_set_promisc_mode_result {
6194         cmdline_fixed_string_t set;
6195         cmdline_fixed_string_t promisc;
6196         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6197         uint16_t port_num;               /* valid if "allports" argument == 0 */
6198         cmdline_fixed_string_t mode;
6199 };
6200
6201 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6202                                         __attribute__((unused)) struct cmdline *cl,
6203                                         void *allports)
6204 {
6205         struct cmd_set_promisc_mode_result *res = parsed_result;
6206         int enable;
6207         portid_t i;
6208
6209         if (!strcmp(res->mode, "on"))
6210                 enable = 1;
6211         else
6212                 enable = 0;
6213
6214         /* all ports */
6215         if (allports) {
6216                 RTE_ETH_FOREACH_DEV(i) {
6217                         if (enable)
6218                                 rte_eth_promiscuous_enable(i);
6219                         else
6220                                 rte_eth_promiscuous_disable(i);
6221                 }
6222         }
6223         else {
6224                 if (enable)
6225                         rte_eth_promiscuous_enable(res->port_num);
6226                 else
6227                         rte_eth_promiscuous_disable(res->port_num);
6228         }
6229 }
6230
6231 cmdline_parse_token_string_t cmd_setpromisc_set =
6232         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6233 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6234         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6235                                  "promisc");
6236 cmdline_parse_token_string_t cmd_setpromisc_portall =
6237         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6238                                  "all");
6239 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6240         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6241                               UINT16);
6242 cmdline_parse_token_string_t cmd_setpromisc_mode =
6243         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6244                                  "on#off");
6245
6246 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6247         .f = cmd_set_promisc_mode_parsed,
6248         .data = (void *)1,
6249         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6250         .tokens = {
6251                 (void *)&cmd_setpromisc_set,
6252                 (void *)&cmd_setpromisc_promisc,
6253                 (void *)&cmd_setpromisc_portall,
6254                 (void *)&cmd_setpromisc_mode,
6255                 NULL,
6256         },
6257 };
6258
6259 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6260         .f = cmd_set_promisc_mode_parsed,
6261         .data = (void *)0,
6262         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6263         .tokens = {
6264                 (void *)&cmd_setpromisc_set,
6265                 (void *)&cmd_setpromisc_promisc,
6266                 (void *)&cmd_setpromisc_portnum,
6267                 (void *)&cmd_setpromisc_mode,
6268                 NULL,
6269         },
6270 };
6271
6272 /* *** SET ALLMULTI MODE *** */
6273 struct cmd_set_allmulti_mode_result {
6274         cmdline_fixed_string_t set;
6275         cmdline_fixed_string_t allmulti;
6276         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6277         uint16_t port_num;               /* valid if "allports" argument == 0 */
6278         cmdline_fixed_string_t mode;
6279 };
6280
6281 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6282                                         __attribute__((unused)) struct cmdline *cl,
6283                                         void *allports)
6284 {
6285         struct cmd_set_allmulti_mode_result *res = parsed_result;
6286         int enable;
6287         portid_t i;
6288
6289         if (!strcmp(res->mode, "on"))
6290                 enable = 1;
6291         else
6292                 enable = 0;
6293
6294         /* all ports */
6295         if (allports) {
6296                 RTE_ETH_FOREACH_DEV(i) {
6297                         if (enable)
6298                                 rte_eth_allmulticast_enable(i);
6299                         else
6300                                 rte_eth_allmulticast_disable(i);
6301                 }
6302         }
6303         else {
6304                 if (enable)
6305                         rte_eth_allmulticast_enable(res->port_num);
6306                 else
6307                         rte_eth_allmulticast_disable(res->port_num);
6308         }
6309 }
6310
6311 cmdline_parse_token_string_t cmd_setallmulti_set =
6312         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6313 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6314         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6315                                  "allmulti");
6316 cmdline_parse_token_string_t cmd_setallmulti_portall =
6317         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6318                                  "all");
6319 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6320         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6321                               UINT16);
6322 cmdline_parse_token_string_t cmd_setallmulti_mode =
6323         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6324                                  "on#off");
6325
6326 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6327         .f = cmd_set_allmulti_mode_parsed,
6328         .data = (void *)1,
6329         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6330         .tokens = {
6331                 (void *)&cmd_setallmulti_set,
6332                 (void *)&cmd_setallmulti_allmulti,
6333                 (void *)&cmd_setallmulti_portall,
6334                 (void *)&cmd_setallmulti_mode,
6335                 NULL,
6336         },
6337 };
6338
6339 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6340         .f = cmd_set_allmulti_mode_parsed,
6341         .data = (void *)0,
6342         .help_str = "set allmulti <port_id> on|off: "
6343                 "Set allmulti mode on port_id",
6344         .tokens = {
6345                 (void *)&cmd_setallmulti_set,
6346                 (void *)&cmd_setallmulti_allmulti,
6347                 (void *)&cmd_setallmulti_portnum,
6348                 (void *)&cmd_setallmulti_mode,
6349                 NULL,
6350         },
6351 };
6352
6353 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6354 struct cmd_link_flow_ctrl_set_result {
6355         cmdline_fixed_string_t set;
6356         cmdline_fixed_string_t flow_ctrl;
6357         cmdline_fixed_string_t rx;
6358         cmdline_fixed_string_t rx_lfc_mode;
6359         cmdline_fixed_string_t tx;
6360         cmdline_fixed_string_t tx_lfc_mode;
6361         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6362         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6363         cmdline_fixed_string_t autoneg_str;
6364         cmdline_fixed_string_t autoneg;
6365         cmdline_fixed_string_t hw_str;
6366         uint32_t high_water;
6367         cmdline_fixed_string_t lw_str;
6368         uint32_t low_water;
6369         cmdline_fixed_string_t pt_str;
6370         uint16_t pause_time;
6371         cmdline_fixed_string_t xon_str;
6372         uint16_t send_xon;
6373         portid_t port_id;
6374 };
6375
6376 cmdline_parse_token_string_t cmd_lfc_set_set =
6377         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6378                                 set, "set");
6379 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6380         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6381                                 flow_ctrl, "flow_ctrl");
6382 cmdline_parse_token_string_t cmd_lfc_set_rx =
6383         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6384                                 rx, "rx");
6385 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6386         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6387                                 rx_lfc_mode, "on#off");
6388 cmdline_parse_token_string_t cmd_lfc_set_tx =
6389         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6390                                 tx, "tx");
6391 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6392         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6393                                 tx_lfc_mode, "on#off");
6394 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6395         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6396                                 hw_str, "high_water");
6397 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6398         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6399                                 high_water, UINT32);
6400 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6401         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6402                                 lw_str, "low_water");
6403 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6404         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6405                                 low_water, UINT32);
6406 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6407         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6408                                 pt_str, "pause_time");
6409 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6410         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6411                                 pause_time, UINT16);
6412 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6413         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6414                                 xon_str, "send_xon");
6415 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6416         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6417                                 send_xon, UINT16);
6418 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6419         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6420                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6421 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6422         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6423                                 mac_ctrl_frame_fwd_mode, "on#off");
6424 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6425         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6426                                 autoneg_str, "autoneg");
6427 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6428         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6429                                 autoneg, "on#off");
6430 cmdline_parse_token_num_t cmd_lfc_set_portid =
6431         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6432                                 port_id, UINT16);
6433
6434 /* forward declaration */
6435 static void
6436 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6437                               void *data);
6438
6439 cmdline_parse_inst_t cmd_link_flow_control_set = {
6440         .f = cmd_link_flow_ctrl_set_parsed,
6441         .data = NULL,
6442         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6443                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6444                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6445         .tokens = {
6446                 (void *)&cmd_lfc_set_set,
6447                 (void *)&cmd_lfc_set_flow_ctrl,
6448                 (void *)&cmd_lfc_set_rx,
6449                 (void *)&cmd_lfc_set_rx_mode,
6450                 (void *)&cmd_lfc_set_tx,
6451                 (void *)&cmd_lfc_set_tx_mode,
6452                 (void *)&cmd_lfc_set_high_water,
6453                 (void *)&cmd_lfc_set_low_water,
6454                 (void *)&cmd_lfc_set_pause_time,
6455                 (void *)&cmd_lfc_set_send_xon,
6456                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6457                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6458                 (void *)&cmd_lfc_set_autoneg_str,
6459                 (void *)&cmd_lfc_set_autoneg,
6460                 (void *)&cmd_lfc_set_portid,
6461                 NULL,
6462         },
6463 };
6464
6465 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6466         .f = cmd_link_flow_ctrl_set_parsed,
6467         .data = (void *)&cmd_link_flow_control_set_rx,
6468         .help_str = "set flow_ctrl rx on|off <port_id>: "
6469                 "Change rx flow control parameter",
6470         .tokens = {
6471                 (void *)&cmd_lfc_set_set,
6472                 (void *)&cmd_lfc_set_flow_ctrl,
6473                 (void *)&cmd_lfc_set_rx,
6474                 (void *)&cmd_lfc_set_rx_mode,
6475                 (void *)&cmd_lfc_set_portid,
6476                 NULL,
6477         },
6478 };
6479
6480 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6481         .f = cmd_link_flow_ctrl_set_parsed,
6482         .data = (void *)&cmd_link_flow_control_set_tx,
6483         .help_str = "set flow_ctrl tx on|off <port_id>: "
6484                 "Change tx flow control parameter",
6485         .tokens = {
6486                 (void *)&cmd_lfc_set_set,
6487                 (void *)&cmd_lfc_set_flow_ctrl,
6488                 (void *)&cmd_lfc_set_tx,
6489                 (void *)&cmd_lfc_set_tx_mode,
6490                 (void *)&cmd_lfc_set_portid,
6491                 NULL,
6492         },
6493 };
6494
6495 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6496         .f = cmd_link_flow_ctrl_set_parsed,
6497         .data = (void *)&cmd_link_flow_control_set_hw,
6498         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6499                 "Change high water flow control parameter",
6500         .tokens = {
6501                 (void *)&cmd_lfc_set_set,
6502                 (void *)&cmd_lfc_set_flow_ctrl,
6503                 (void *)&cmd_lfc_set_high_water_str,
6504                 (void *)&cmd_lfc_set_high_water,
6505                 (void *)&cmd_lfc_set_portid,
6506                 NULL,
6507         },
6508 };
6509
6510 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6511         .f = cmd_link_flow_ctrl_set_parsed,
6512         .data = (void *)&cmd_link_flow_control_set_lw,
6513         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6514                 "Change low water flow control parameter",
6515         .tokens = {
6516                 (void *)&cmd_lfc_set_set,
6517                 (void *)&cmd_lfc_set_flow_ctrl,
6518                 (void *)&cmd_lfc_set_low_water_str,
6519                 (void *)&cmd_lfc_set_low_water,
6520                 (void *)&cmd_lfc_set_portid,
6521                 NULL,
6522         },
6523 };
6524
6525 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6526         .f = cmd_link_flow_ctrl_set_parsed,
6527         .data = (void *)&cmd_link_flow_control_set_pt,
6528         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6529                 "Change pause time flow control parameter",
6530         .tokens = {
6531                 (void *)&cmd_lfc_set_set,
6532                 (void *)&cmd_lfc_set_flow_ctrl,
6533                 (void *)&cmd_lfc_set_pause_time_str,
6534                 (void *)&cmd_lfc_set_pause_time,
6535                 (void *)&cmd_lfc_set_portid,
6536                 NULL,
6537         },
6538 };
6539
6540 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6541         .f = cmd_link_flow_ctrl_set_parsed,
6542         .data = (void *)&cmd_link_flow_control_set_xon,
6543         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6544                 "Change send_xon flow control parameter",
6545         .tokens = {
6546                 (void *)&cmd_lfc_set_set,
6547                 (void *)&cmd_lfc_set_flow_ctrl,
6548                 (void *)&cmd_lfc_set_send_xon_str,
6549                 (void *)&cmd_lfc_set_send_xon,
6550                 (void *)&cmd_lfc_set_portid,
6551                 NULL,
6552         },
6553 };
6554
6555 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6556         .f = cmd_link_flow_ctrl_set_parsed,
6557         .data = (void *)&cmd_link_flow_control_set_macfwd,
6558         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6559                 "Change mac ctrl fwd flow control parameter",
6560         .tokens = {
6561                 (void *)&cmd_lfc_set_set,
6562                 (void *)&cmd_lfc_set_flow_ctrl,
6563                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6564                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6565                 (void *)&cmd_lfc_set_portid,
6566                 NULL,
6567         },
6568 };
6569
6570 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6571         .f = cmd_link_flow_ctrl_set_parsed,
6572         .data = (void *)&cmd_link_flow_control_set_autoneg,
6573         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6574                 "Change autoneg flow control parameter",
6575         .tokens = {
6576                 (void *)&cmd_lfc_set_set,
6577                 (void *)&cmd_lfc_set_flow_ctrl,
6578                 (void *)&cmd_lfc_set_autoneg_str,
6579                 (void *)&cmd_lfc_set_autoneg,
6580                 (void *)&cmd_lfc_set_portid,
6581                 NULL,
6582         },
6583 };
6584
6585 static void
6586 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6587                               __attribute__((unused)) struct cmdline *cl,
6588                               void *data)
6589 {
6590         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6591         cmdline_parse_inst_t *cmd = data;
6592         struct rte_eth_fc_conf fc_conf;
6593         int rx_fc_en = 0;
6594         int tx_fc_en = 0;
6595         int ret;
6596
6597         /*
6598          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6599          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6600          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6601          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6602          */
6603         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6604                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6605         };
6606
6607         /* Partial command line, retrieve current configuration */
6608         if (cmd) {
6609                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6610                 if (ret != 0) {
6611                         printf("cannot get current flow ctrl parameters, return"
6612                                "code = %d\n", ret);
6613                         return;
6614                 }
6615
6616                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6617                     (fc_conf.mode == RTE_FC_FULL))
6618                         rx_fc_en = 1;
6619                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6620                     (fc_conf.mode == RTE_FC_FULL))
6621                         tx_fc_en = 1;
6622         }
6623
6624         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6625                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6626
6627         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6628                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6629
6630         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6631
6632         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6633                 fc_conf.high_water = res->high_water;
6634
6635         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6636                 fc_conf.low_water = res->low_water;
6637
6638         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6639                 fc_conf.pause_time = res->pause_time;
6640
6641         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6642                 fc_conf.send_xon = res->send_xon;
6643
6644         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6645                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6646                         fc_conf.mac_ctrl_frame_fwd = 1;
6647                 else
6648                         fc_conf.mac_ctrl_frame_fwd = 0;
6649         }
6650
6651         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6652                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6653
6654         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6655         if (ret != 0)
6656                 printf("bad flow contrl parameter, return code = %d \n", ret);
6657 }
6658
6659 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6660 struct cmd_priority_flow_ctrl_set_result {
6661         cmdline_fixed_string_t set;
6662         cmdline_fixed_string_t pfc_ctrl;
6663         cmdline_fixed_string_t rx;
6664         cmdline_fixed_string_t rx_pfc_mode;
6665         cmdline_fixed_string_t tx;
6666         cmdline_fixed_string_t tx_pfc_mode;
6667         uint32_t high_water;
6668         uint32_t low_water;
6669         uint16_t pause_time;
6670         uint8_t  priority;
6671         portid_t port_id;
6672 };
6673
6674 static void
6675 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6676                        __attribute__((unused)) struct cmdline *cl,
6677                        __attribute__((unused)) void *data)
6678 {
6679         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6680         struct rte_eth_pfc_conf pfc_conf;
6681         int rx_fc_enable, tx_fc_enable;
6682         int ret;
6683
6684         /*
6685          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6686          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6687          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6688          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6689          */
6690         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6691                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6692         };
6693
6694         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6695         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6696         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6697         pfc_conf.fc.high_water = res->high_water;
6698         pfc_conf.fc.low_water  = res->low_water;
6699         pfc_conf.fc.pause_time = res->pause_time;
6700         pfc_conf.priority      = res->priority;
6701
6702         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6703         if (ret != 0)
6704                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6705 }
6706
6707 cmdline_parse_token_string_t cmd_pfc_set_set =
6708         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6709                                 set, "set");
6710 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6711         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6712                                 pfc_ctrl, "pfc_ctrl");
6713 cmdline_parse_token_string_t cmd_pfc_set_rx =
6714         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6715                                 rx, "rx");
6716 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6717         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6718                                 rx_pfc_mode, "on#off");
6719 cmdline_parse_token_string_t cmd_pfc_set_tx =
6720         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6721                                 tx, "tx");
6722 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6723         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6724                                 tx_pfc_mode, "on#off");
6725 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6726         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6727                                 high_water, UINT32);
6728 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6729         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6730                                 low_water, UINT32);
6731 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6732         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6733                                 pause_time, UINT16);
6734 cmdline_parse_token_num_t cmd_pfc_set_priority =
6735         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6736                                 priority, UINT8);
6737 cmdline_parse_token_num_t cmd_pfc_set_portid =
6738         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6739                                 port_id, UINT16);
6740
6741 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6742         .f = cmd_priority_flow_ctrl_set_parsed,
6743         .data = NULL,
6744         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6745                 "<pause_time> <priority> <port_id>: "
6746                 "Configure the Ethernet priority flow control",
6747         .tokens = {
6748                 (void *)&cmd_pfc_set_set,
6749                 (void *)&cmd_pfc_set_flow_ctrl,
6750                 (void *)&cmd_pfc_set_rx,
6751                 (void *)&cmd_pfc_set_rx_mode,
6752                 (void *)&cmd_pfc_set_tx,
6753                 (void *)&cmd_pfc_set_tx_mode,
6754                 (void *)&cmd_pfc_set_high_water,
6755                 (void *)&cmd_pfc_set_low_water,
6756                 (void *)&cmd_pfc_set_pause_time,
6757                 (void *)&cmd_pfc_set_priority,
6758                 (void *)&cmd_pfc_set_portid,
6759                 NULL,
6760         },
6761 };
6762
6763 /* *** RESET CONFIGURATION *** */
6764 struct cmd_reset_result {
6765         cmdline_fixed_string_t reset;
6766         cmdline_fixed_string_t def;
6767 };
6768
6769 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6770                              struct cmdline *cl,
6771                              __attribute__((unused)) void *data)
6772 {
6773         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6774         set_def_fwd_config();
6775 }
6776
6777 cmdline_parse_token_string_t cmd_reset_set =
6778         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6779 cmdline_parse_token_string_t cmd_reset_def =
6780         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6781                                  "default");
6782
6783 cmdline_parse_inst_t cmd_reset = {
6784         .f = cmd_reset_parsed,
6785         .data = NULL,
6786         .help_str = "set default: Reset default forwarding configuration",
6787         .tokens = {
6788                 (void *)&cmd_reset_set,
6789                 (void *)&cmd_reset_def,
6790                 NULL,
6791         },
6792 };
6793
6794 /* *** START FORWARDING *** */
6795 struct cmd_start_result {
6796         cmdline_fixed_string_t start;
6797 };
6798
6799 cmdline_parse_token_string_t cmd_start_start =
6800         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6801
6802 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6803                              __attribute__((unused)) struct cmdline *cl,
6804                              __attribute__((unused)) void *data)
6805 {
6806         start_packet_forwarding(0);
6807 }
6808
6809 cmdline_parse_inst_t cmd_start = {
6810         .f = cmd_start_parsed,
6811         .data = NULL,
6812         .help_str = "start: Start packet forwarding",
6813         .tokens = {
6814                 (void *)&cmd_start_start,
6815                 NULL,
6816         },
6817 };
6818
6819 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6820 struct cmd_start_tx_first_result {
6821         cmdline_fixed_string_t start;
6822         cmdline_fixed_string_t tx_first;
6823 };
6824
6825 static void
6826 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6827                           __attribute__((unused)) struct cmdline *cl,
6828                           __attribute__((unused)) void *data)
6829 {
6830         start_packet_forwarding(1);
6831 }
6832
6833 cmdline_parse_token_string_t cmd_start_tx_first_start =
6834         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6835                                  "start");
6836 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6837         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6838                                  tx_first, "tx_first");
6839
6840 cmdline_parse_inst_t cmd_start_tx_first = {
6841         .f = cmd_start_tx_first_parsed,
6842         .data = NULL,
6843         .help_str = "start tx_first: Start packet forwarding, "
6844                 "after sending 1 burst of packets",
6845         .tokens = {
6846                 (void *)&cmd_start_tx_first_start,
6847                 (void *)&cmd_start_tx_first_tx_first,
6848                 NULL,
6849         },
6850 };
6851
6852 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6853 struct cmd_start_tx_first_n_result {
6854         cmdline_fixed_string_t start;
6855         cmdline_fixed_string_t tx_first;
6856         uint32_t tx_num;
6857 };
6858
6859 static void
6860 cmd_start_tx_first_n_parsed(void *parsed_result,
6861                           __attribute__((unused)) struct cmdline *cl,
6862                           __attribute__((unused)) void *data)
6863 {
6864         struct cmd_start_tx_first_n_result *res = parsed_result;
6865
6866         start_packet_forwarding(res->tx_num);
6867 }
6868
6869 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6870         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6871                         start, "start");
6872 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6873         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6874                         tx_first, "tx_first");
6875 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6876         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6877                         tx_num, UINT32);
6878
6879 cmdline_parse_inst_t cmd_start_tx_first_n = {
6880         .f = cmd_start_tx_first_n_parsed,
6881         .data = NULL,
6882         .help_str = "start tx_first <num>: "
6883                 "packet forwarding, after sending <num> bursts of packets",
6884         .tokens = {
6885                 (void *)&cmd_start_tx_first_n_start,
6886                 (void *)&cmd_start_tx_first_n_tx_first,
6887                 (void *)&cmd_start_tx_first_n_tx_num,
6888                 NULL,
6889         },
6890 };
6891
6892 /* *** SET LINK UP *** */
6893 struct cmd_set_link_up_result {
6894         cmdline_fixed_string_t set;
6895         cmdline_fixed_string_t link_up;
6896         cmdline_fixed_string_t port;
6897         portid_t port_id;
6898 };
6899
6900 cmdline_parse_token_string_t cmd_set_link_up_set =
6901         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6902 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6903         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6904                                 "link-up");
6905 cmdline_parse_token_string_t cmd_set_link_up_port =
6906         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6907 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6908         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6909
6910 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6911                              __attribute__((unused)) struct cmdline *cl,
6912                              __attribute__((unused)) void *data)
6913 {
6914         struct cmd_set_link_up_result *res = parsed_result;
6915         dev_set_link_up(res->port_id);
6916 }
6917
6918 cmdline_parse_inst_t cmd_set_link_up = {
6919         .f = cmd_set_link_up_parsed,
6920         .data = NULL,
6921         .help_str = "set link-up port <port id>",
6922         .tokens = {
6923                 (void *)&cmd_set_link_up_set,
6924                 (void *)&cmd_set_link_up_link_up,
6925                 (void *)&cmd_set_link_up_port,
6926                 (void *)&cmd_set_link_up_port_id,
6927                 NULL,
6928         },
6929 };
6930
6931 /* *** SET LINK DOWN *** */
6932 struct cmd_set_link_down_result {
6933         cmdline_fixed_string_t set;
6934         cmdline_fixed_string_t link_down;
6935         cmdline_fixed_string_t port;
6936         portid_t port_id;
6937 };
6938
6939 cmdline_parse_token_string_t cmd_set_link_down_set =
6940         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6941 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6942         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6943                                 "link-down");
6944 cmdline_parse_token_string_t cmd_set_link_down_port =
6945         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6946 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6947         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6948
6949 static void cmd_set_link_down_parsed(
6950                                 __attribute__((unused)) void *parsed_result,
6951                                 __attribute__((unused)) struct cmdline *cl,
6952                                 __attribute__((unused)) void *data)
6953 {
6954         struct cmd_set_link_down_result *res = parsed_result;
6955         dev_set_link_down(res->port_id);
6956 }
6957
6958 cmdline_parse_inst_t cmd_set_link_down = {
6959         .f = cmd_set_link_down_parsed,
6960         .data = NULL,
6961         .help_str = "set link-down port <port id>",
6962         .tokens = {
6963                 (void *)&cmd_set_link_down_set,
6964                 (void *)&cmd_set_link_down_link_down,
6965                 (void *)&cmd_set_link_down_port,
6966                 (void *)&cmd_set_link_down_port_id,
6967                 NULL,
6968         },
6969 };
6970
6971 /* *** SHOW CFG *** */
6972 struct cmd_showcfg_result {
6973         cmdline_fixed_string_t show;
6974         cmdline_fixed_string_t cfg;
6975         cmdline_fixed_string_t what;
6976 };
6977
6978 static void cmd_showcfg_parsed(void *parsed_result,
6979                                __attribute__((unused)) struct cmdline *cl,
6980                                __attribute__((unused)) void *data)
6981 {
6982         struct cmd_showcfg_result *res = parsed_result;
6983         if (!strcmp(res->what, "rxtx"))
6984                 rxtx_config_display();
6985         else if (!strcmp(res->what, "cores"))
6986                 fwd_lcores_config_display();
6987         else if (!strcmp(res->what, "fwd"))
6988                 pkt_fwd_config_display(&cur_fwd_config);
6989         else if (!strcmp(res->what, "txpkts"))
6990                 show_tx_pkt_segments();
6991 }
6992
6993 cmdline_parse_token_string_t cmd_showcfg_show =
6994         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6995 cmdline_parse_token_string_t cmd_showcfg_port =
6996         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6997 cmdline_parse_token_string_t cmd_showcfg_what =
6998         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6999                                  "rxtx#cores#fwd#txpkts");
7000
7001 cmdline_parse_inst_t cmd_showcfg = {
7002         .f = cmd_showcfg_parsed,
7003         .data = NULL,
7004         .help_str = "show config rxtx|cores|fwd|txpkts",
7005         .tokens = {
7006                 (void *)&cmd_showcfg_show,
7007                 (void *)&cmd_showcfg_port,
7008                 (void *)&cmd_showcfg_what,
7009                 NULL,
7010         },
7011 };
7012
7013 /* *** SHOW ALL PORT INFO *** */
7014 struct cmd_showportall_result {
7015         cmdline_fixed_string_t show;
7016         cmdline_fixed_string_t port;
7017         cmdline_fixed_string_t what;
7018         cmdline_fixed_string_t all;
7019 };
7020
7021 static void cmd_showportall_parsed(void *parsed_result,
7022                                 __attribute__((unused)) struct cmdline *cl,
7023                                 __attribute__((unused)) void *data)
7024 {
7025         portid_t i;
7026
7027         struct cmd_showportall_result *res = parsed_result;
7028         if (!strcmp(res->show, "clear")) {
7029                 if (!strcmp(res->what, "stats"))
7030                         RTE_ETH_FOREACH_DEV(i)
7031                                 nic_stats_clear(i);
7032                 else if (!strcmp(res->what, "xstats"))
7033                         RTE_ETH_FOREACH_DEV(i)
7034                                 nic_xstats_clear(i);
7035         } else if (!strcmp(res->what, "info"))
7036                 RTE_ETH_FOREACH_DEV(i)
7037                         port_infos_display(i);
7038         else if (!strcmp(res->what, "stats"))
7039                 RTE_ETH_FOREACH_DEV(i)
7040                         nic_stats_display(i);
7041         else if (!strcmp(res->what, "xstats"))
7042                 RTE_ETH_FOREACH_DEV(i)
7043                         nic_xstats_display(i);
7044         else if (!strcmp(res->what, "fdir"))
7045                 RTE_ETH_FOREACH_DEV(i)
7046                         fdir_get_infos(i);
7047         else if (!strcmp(res->what, "stat_qmap"))
7048                 RTE_ETH_FOREACH_DEV(i)
7049                         nic_stats_mapping_display(i);
7050         else if (!strcmp(res->what, "dcb_tc"))
7051                 RTE_ETH_FOREACH_DEV(i)
7052                         port_dcb_info_display(i);
7053         else if (!strcmp(res->what, "cap"))
7054                 RTE_ETH_FOREACH_DEV(i)
7055                         port_offload_cap_display(i);
7056 }
7057
7058 cmdline_parse_token_string_t cmd_showportall_show =
7059         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7060                                  "show#clear");
7061 cmdline_parse_token_string_t cmd_showportall_port =
7062         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7063 cmdline_parse_token_string_t cmd_showportall_what =
7064         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7065                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7066 cmdline_parse_token_string_t cmd_showportall_all =
7067         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7068 cmdline_parse_inst_t cmd_showportall = {
7069         .f = cmd_showportall_parsed,
7070         .data = NULL,
7071         .help_str = "show|clear port "
7072                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7073         .tokens = {
7074                 (void *)&cmd_showportall_show,
7075                 (void *)&cmd_showportall_port,
7076                 (void *)&cmd_showportall_what,
7077                 (void *)&cmd_showportall_all,
7078                 NULL,
7079         },
7080 };
7081
7082 /* *** SHOW PORT INFO *** */
7083 struct cmd_showport_result {
7084         cmdline_fixed_string_t show;
7085         cmdline_fixed_string_t port;
7086         cmdline_fixed_string_t what;
7087         uint16_t portnum;
7088 };
7089
7090 static void cmd_showport_parsed(void *parsed_result,
7091                                 __attribute__((unused)) struct cmdline *cl,
7092                                 __attribute__((unused)) void *data)
7093 {
7094         struct cmd_showport_result *res = parsed_result;
7095         if (!strcmp(res->show, "clear")) {
7096                 if (!strcmp(res->what, "stats"))
7097                         nic_stats_clear(res->portnum);
7098                 else if (!strcmp(res->what, "xstats"))
7099                         nic_xstats_clear(res->portnum);
7100         } else if (!strcmp(res->what, "info"))
7101                 port_infos_display(res->portnum);
7102         else if (!strcmp(res->what, "stats"))
7103                 nic_stats_display(res->portnum);
7104         else if (!strcmp(res->what, "xstats"))
7105                 nic_xstats_display(res->portnum);
7106         else if (!strcmp(res->what, "fdir"))
7107                  fdir_get_infos(res->portnum);
7108         else if (!strcmp(res->what, "stat_qmap"))
7109                 nic_stats_mapping_display(res->portnum);
7110         else if (!strcmp(res->what, "dcb_tc"))
7111                 port_dcb_info_display(res->portnum);
7112         else if (!strcmp(res->what, "cap"))
7113                 port_offload_cap_display(res->portnum);
7114 }
7115
7116 cmdline_parse_token_string_t cmd_showport_show =
7117         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7118                                  "show#clear");
7119 cmdline_parse_token_string_t cmd_showport_port =
7120         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7121 cmdline_parse_token_string_t cmd_showport_what =
7122         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7123                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7124 cmdline_parse_token_num_t cmd_showport_portnum =
7125         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7126
7127 cmdline_parse_inst_t cmd_showport = {
7128         .f = cmd_showport_parsed,
7129         .data = NULL,
7130         .help_str = "show|clear port "
7131                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7132                 "<port_id>",
7133         .tokens = {
7134                 (void *)&cmd_showport_show,
7135                 (void *)&cmd_showport_port,
7136                 (void *)&cmd_showport_what,
7137                 (void *)&cmd_showport_portnum,
7138                 NULL,
7139         },
7140 };
7141
7142 /* *** SHOW QUEUE INFO *** */
7143 struct cmd_showqueue_result {
7144         cmdline_fixed_string_t show;
7145         cmdline_fixed_string_t type;
7146         cmdline_fixed_string_t what;
7147         uint16_t portnum;
7148         uint16_t queuenum;
7149 };
7150
7151 static void
7152 cmd_showqueue_parsed(void *parsed_result,
7153         __attribute__((unused)) struct cmdline *cl,
7154         __attribute__((unused)) void *data)
7155 {
7156         struct cmd_showqueue_result *res = parsed_result;
7157
7158         if (!strcmp(res->type, "rxq"))
7159                 rx_queue_infos_display(res->portnum, res->queuenum);
7160         else if (!strcmp(res->type, "txq"))
7161                 tx_queue_infos_display(res->portnum, res->queuenum);
7162 }
7163
7164 cmdline_parse_token_string_t cmd_showqueue_show =
7165         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7166 cmdline_parse_token_string_t cmd_showqueue_type =
7167         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7168 cmdline_parse_token_string_t cmd_showqueue_what =
7169         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7170 cmdline_parse_token_num_t cmd_showqueue_portnum =
7171         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7172 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7173         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7174
7175 cmdline_parse_inst_t cmd_showqueue = {
7176         .f = cmd_showqueue_parsed,
7177         .data = NULL,
7178         .help_str = "show rxq|txq info <port_id> <queue_id>",
7179         .tokens = {
7180                 (void *)&cmd_showqueue_show,
7181                 (void *)&cmd_showqueue_type,
7182                 (void *)&cmd_showqueue_what,
7183                 (void *)&cmd_showqueue_portnum,
7184                 (void *)&cmd_showqueue_queuenum,
7185                 NULL,
7186         },
7187 };
7188
7189 /* *** READ PORT REGISTER *** */
7190 struct cmd_read_reg_result {
7191         cmdline_fixed_string_t read;
7192         cmdline_fixed_string_t reg;
7193         portid_t port_id;
7194         uint32_t reg_off;
7195 };
7196
7197 static void
7198 cmd_read_reg_parsed(void *parsed_result,
7199                     __attribute__((unused)) struct cmdline *cl,
7200                     __attribute__((unused)) void *data)
7201 {
7202         struct cmd_read_reg_result *res = parsed_result;
7203         port_reg_display(res->port_id, res->reg_off);
7204 }
7205
7206 cmdline_parse_token_string_t cmd_read_reg_read =
7207         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7208 cmdline_parse_token_string_t cmd_read_reg_reg =
7209         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7210 cmdline_parse_token_num_t cmd_read_reg_port_id =
7211         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7212 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7213         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7214
7215 cmdline_parse_inst_t cmd_read_reg = {
7216         .f = cmd_read_reg_parsed,
7217         .data = NULL,
7218         .help_str = "read reg <port_id> <reg_off>",
7219         .tokens = {
7220                 (void *)&cmd_read_reg_read,
7221                 (void *)&cmd_read_reg_reg,
7222                 (void *)&cmd_read_reg_port_id,
7223                 (void *)&cmd_read_reg_reg_off,
7224                 NULL,
7225         },
7226 };
7227
7228 /* *** READ PORT REGISTER BIT FIELD *** */
7229 struct cmd_read_reg_bit_field_result {
7230         cmdline_fixed_string_t read;
7231         cmdline_fixed_string_t regfield;
7232         portid_t port_id;
7233         uint32_t reg_off;
7234         uint8_t bit1_pos;
7235         uint8_t bit2_pos;
7236 };
7237
7238 static void
7239 cmd_read_reg_bit_field_parsed(void *parsed_result,
7240                               __attribute__((unused)) struct cmdline *cl,
7241                               __attribute__((unused)) void *data)
7242 {
7243         struct cmd_read_reg_bit_field_result *res = parsed_result;
7244         port_reg_bit_field_display(res->port_id, res->reg_off,
7245                                    res->bit1_pos, res->bit2_pos);
7246 }
7247
7248 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7249         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7250                                  "read");
7251 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7252         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7253                                  regfield, "regfield");
7254 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7255         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7256                               UINT16);
7257 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7258         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7259                               UINT32);
7260 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7261         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7262                               UINT8);
7263 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7264         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7265                               UINT8);
7266
7267 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7268         .f = cmd_read_reg_bit_field_parsed,
7269         .data = NULL,
7270         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7271         "Read register bit field between bit_x and bit_y included",
7272         .tokens = {
7273                 (void *)&cmd_read_reg_bit_field_read,
7274                 (void *)&cmd_read_reg_bit_field_regfield,
7275                 (void *)&cmd_read_reg_bit_field_port_id,
7276                 (void *)&cmd_read_reg_bit_field_reg_off,
7277                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7278                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7279                 NULL,
7280         },
7281 };
7282
7283 /* *** READ PORT REGISTER BIT *** */
7284 struct cmd_read_reg_bit_result {
7285         cmdline_fixed_string_t read;
7286         cmdline_fixed_string_t regbit;
7287         portid_t port_id;
7288         uint32_t reg_off;
7289         uint8_t bit_pos;
7290 };
7291
7292 static void
7293 cmd_read_reg_bit_parsed(void *parsed_result,
7294                         __attribute__((unused)) struct cmdline *cl,
7295                         __attribute__((unused)) void *data)
7296 {
7297         struct cmd_read_reg_bit_result *res = parsed_result;
7298         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7299 }
7300
7301 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7302         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7303 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7304         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7305                                  regbit, "regbit");
7306 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7307         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7308 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7309         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7310 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7311         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7312
7313 cmdline_parse_inst_t cmd_read_reg_bit = {
7314         .f = cmd_read_reg_bit_parsed,
7315         .data = NULL,
7316         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7317         .tokens = {
7318                 (void *)&cmd_read_reg_bit_read,
7319                 (void *)&cmd_read_reg_bit_regbit,
7320                 (void *)&cmd_read_reg_bit_port_id,
7321                 (void *)&cmd_read_reg_bit_reg_off,
7322                 (void *)&cmd_read_reg_bit_bit_pos,
7323                 NULL,
7324         },
7325 };
7326
7327 /* *** WRITE PORT REGISTER *** */
7328 struct cmd_write_reg_result {
7329         cmdline_fixed_string_t write;
7330         cmdline_fixed_string_t reg;
7331         portid_t port_id;
7332         uint32_t reg_off;
7333         uint32_t value;
7334 };
7335
7336 static void
7337 cmd_write_reg_parsed(void *parsed_result,
7338                      __attribute__((unused)) struct cmdline *cl,
7339                      __attribute__((unused)) void *data)
7340 {
7341         struct cmd_write_reg_result *res = parsed_result;
7342         port_reg_set(res->port_id, res->reg_off, res->value);
7343 }
7344
7345 cmdline_parse_token_string_t cmd_write_reg_write =
7346         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7347 cmdline_parse_token_string_t cmd_write_reg_reg =
7348         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7349 cmdline_parse_token_num_t cmd_write_reg_port_id =
7350         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7351 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7352         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7353 cmdline_parse_token_num_t cmd_write_reg_value =
7354         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7355
7356 cmdline_parse_inst_t cmd_write_reg = {
7357         .f = cmd_write_reg_parsed,
7358         .data = NULL,
7359         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7360         .tokens = {
7361                 (void *)&cmd_write_reg_write,
7362                 (void *)&cmd_write_reg_reg,
7363                 (void *)&cmd_write_reg_port_id,
7364                 (void *)&cmd_write_reg_reg_off,
7365                 (void *)&cmd_write_reg_value,
7366                 NULL,
7367         },
7368 };
7369
7370 /* *** WRITE PORT REGISTER BIT FIELD *** */
7371 struct cmd_write_reg_bit_field_result {
7372         cmdline_fixed_string_t write;
7373         cmdline_fixed_string_t regfield;
7374         portid_t port_id;
7375         uint32_t reg_off;
7376         uint8_t bit1_pos;
7377         uint8_t bit2_pos;
7378         uint32_t value;
7379 };
7380
7381 static void
7382 cmd_write_reg_bit_field_parsed(void *parsed_result,
7383                                __attribute__((unused)) struct cmdline *cl,
7384                                __attribute__((unused)) void *data)
7385 {
7386         struct cmd_write_reg_bit_field_result *res = parsed_result;
7387         port_reg_bit_field_set(res->port_id, res->reg_off,
7388                           res->bit1_pos, res->bit2_pos, res->value);
7389 }
7390
7391 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7392         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7393                                  "write");
7394 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7395         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7396                                  regfield, "regfield");
7397 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7398         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7399                               UINT16);
7400 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7401         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7402                               UINT32);
7403 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7404         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7405                               UINT8);
7406 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7407         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7408                               UINT8);
7409 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7410         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7411                               UINT32);
7412
7413 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7414         .f = cmd_write_reg_bit_field_parsed,
7415         .data = NULL,
7416         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7417                 "<reg_value>: "
7418                 "Set register bit field between bit_x and bit_y included",
7419         .tokens = {
7420                 (void *)&cmd_write_reg_bit_field_write,
7421                 (void *)&cmd_write_reg_bit_field_regfield,
7422                 (void *)&cmd_write_reg_bit_field_port_id,
7423                 (void *)&cmd_write_reg_bit_field_reg_off,
7424                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7425                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7426                 (void *)&cmd_write_reg_bit_field_value,
7427                 NULL,
7428         },
7429 };
7430
7431 /* *** WRITE PORT REGISTER BIT *** */
7432 struct cmd_write_reg_bit_result {
7433         cmdline_fixed_string_t write;
7434         cmdline_fixed_string_t regbit;
7435         portid_t port_id;
7436         uint32_t reg_off;
7437         uint8_t bit_pos;
7438         uint8_t value;
7439 };
7440
7441 static void
7442 cmd_write_reg_bit_parsed(void *parsed_result,
7443                          __attribute__((unused)) struct cmdline *cl,
7444                          __attribute__((unused)) void *data)
7445 {
7446         struct cmd_write_reg_bit_result *res = parsed_result;
7447         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7448 }
7449
7450 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7451         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7452                                  "write");
7453 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7454         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7455                                  regbit, "regbit");
7456 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7457         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7458 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7459         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7460 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7461         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7462 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7463         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7464
7465 cmdline_parse_inst_t cmd_write_reg_bit = {
7466         .f = cmd_write_reg_bit_parsed,
7467         .data = NULL,
7468         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7469                 "0 <= bit_x <= 31",
7470         .tokens = {
7471                 (void *)&cmd_write_reg_bit_write,
7472                 (void *)&cmd_write_reg_bit_regbit,
7473                 (void *)&cmd_write_reg_bit_port_id,
7474                 (void *)&cmd_write_reg_bit_reg_off,
7475                 (void *)&cmd_write_reg_bit_bit_pos,
7476                 (void *)&cmd_write_reg_bit_value,
7477                 NULL,
7478         },
7479 };
7480
7481 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7482 struct cmd_read_rxd_txd_result {
7483         cmdline_fixed_string_t read;
7484         cmdline_fixed_string_t rxd_txd;
7485         portid_t port_id;
7486         uint16_t queue_id;
7487         uint16_t desc_id;
7488 };
7489
7490 static void
7491 cmd_read_rxd_txd_parsed(void *parsed_result,
7492                         __attribute__((unused)) struct cmdline *cl,
7493                         __attribute__((unused)) void *data)
7494 {
7495         struct cmd_read_rxd_txd_result *res = parsed_result;
7496
7497         if (!strcmp(res->rxd_txd, "rxd"))
7498                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7499         else if (!strcmp(res->rxd_txd, "txd"))
7500                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7501 }
7502
7503 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7504         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7505 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7506         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7507                                  "rxd#txd");
7508 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7509         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7510 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7511         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7512 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7513         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7514
7515 cmdline_parse_inst_t cmd_read_rxd_txd = {
7516         .f = cmd_read_rxd_txd_parsed,
7517         .data = NULL,
7518         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7519         .tokens = {
7520                 (void *)&cmd_read_rxd_txd_read,
7521                 (void *)&cmd_read_rxd_txd_rxd_txd,
7522                 (void *)&cmd_read_rxd_txd_port_id,
7523                 (void *)&cmd_read_rxd_txd_queue_id,
7524                 (void *)&cmd_read_rxd_txd_desc_id,
7525                 NULL,
7526         },
7527 };
7528
7529 /* *** QUIT *** */
7530 struct cmd_quit_result {
7531         cmdline_fixed_string_t quit;
7532 };
7533
7534 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7535                             struct cmdline *cl,
7536                             __attribute__((unused)) void *data)
7537 {
7538         pmd_test_exit();
7539         cmdline_quit(cl);
7540 }
7541
7542 cmdline_parse_token_string_t cmd_quit_quit =
7543         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7544
7545 cmdline_parse_inst_t cmd_quit = {
7546         .f = cmd_quit_parsed,
7547         .data = NULL,
7548         .help_str = "quit: Exit application",
7549         .tokens = {
7550                 (void *)&cmd_quit_quit,
7551                 NULL,
7552         },
7553 };
7554
7555 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7556 struct cmd_mac_addr_result {
7557         cmdline_fixed_string_t mac_addr_cmd;
7558         cmdline_fixed_string_t what;
7559         uint16_t port_num;
7560         struct ether_addr address;
7561 };
7562
7563 static void cmd_mac_addr_parsed(void *parsed_result,
7564                 __attribute__((unused)) struct cmdline *cl,
7565                 __attribute__((unused)) void *data)
7566 {
7567         struct cmd_mac_addr_result *res = parsed_result;
7568         int ret;
7569
7570         if (strcmp(res->what, "add") == 0)
7571                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7572         else if (strcmp(res->what, "set") == 0)
7573                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7574                                                        &res->address);
7575         else
7576                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7577
7578         /* check the return value and print it if is < 0 */
7579         if(ret < 0)
7580                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7581
7582 }
7583
7584 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7585         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7586                                 "mac_addr");
7587 cmdline_parse_token_string_t cmd_mac_addr_what =
7588         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7589                                 "add#remove#set");
7590 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7591                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7592                                         UINT16);
7593 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7594                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7595
7596 cmdline_parse_inst_t cmd_mac_addr = {
7597         .f = cmd_mac_addr_parsed,
7598         .data = (void *)0,
7599         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7600                         "Add/Remove/Set MAC address on port_id",
7601         .tokens = {
7602                 (void *)&cmd_mac_addr_cmd,
7603                 (void *)&cmd_mac_addr_what,
7604                 (void *)&cmd_mac_addr_portnum,
7605                 (void *)&cmd_mac_addr_addr,
7606                 NULL,
7607         },
7608 };
7609
7610 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7611 struct cmd_eth_peer_result {
7612         cmdline_fixed_string_t set;
7613         cmdline_fixed_string_t eth_peer;
7614         portid_t port_id;
7615         cmdline_fixed_string_t peer_addr;
7616 };
7617
7618 static void cmd_set_eth_peer_parsed(void *parsed_result,
7619                         __attribute__((unused)) struct cmdline *cl,
7620                         __attribute__((unused)) void *data)
7621 {
7622                 struct cmd_eth_peer_result *res = parsed_result;
7623
7624                 if (test_done == 0) {
7625                         printf("Please stop forwarding first\n");
7626                         return;
7627                 }
7628                 if (!strcmp(res->eth_peer, "eth-peer")) {
7629                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7630                         fwd_config_setup();
7631                 }
7632 }
7633 cmdline_parse_token_string_t cmd_eth_peer_set =
7634         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7635 cmdline_parse_token_string_t cmd_eth_peer =
7636         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7637 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7638         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7639 cmdline_parse_token_string_t cmd_eth_peer_addr =
7640         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7641
7642 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7643         .f = cmd_set_eth_peer_parsed,
7644         .data = NULL,
7645         .help_str = "set eth-peer <port_id> <peer_mac>",
7646         .tokens = {
7647                 (void *)&cmd_eth_peer_set,
7648                 (void *)&cmd_eth_peer,
7649                 (void *)&cmd_eth_peer_port_id,
7650                 (void *)&cmd_eth_peer_addr,
7651                 NULL,
7652         },
7653 };
7654
7655 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7656 struct cmd_set_qmap_result {
7657         cmdline_fixed_string_t set;
7658         cmdline_fixed_string_t qmap;
7659         cmdline_fixed_string_t what;
7660         portid_t port_id;
7661         uint16_t queue_id;
7662         uint8_t map_value;
7663 };
7664
7665 static void
7666 cmd_set_qmap_parsed(void *parsed_result,
7667                        __attribute__((unused)) struct cmdline *cl,
7668                        __attribute__((unused)) void *data)
7669 {
7670         struct cmd_set_qmap_result *res = parsed_result;
7671         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7672
7673         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7674 }
7675
7676 cmdline_parse_token_string_t cmd_setqmap_set =
7677         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7678                                  set, "set");
7679 cmdline_parse_token_string_t cmd_setqmap_qmap =
7680         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7681                                  qmap, "stat_qmap");
7682 cmdline_parse_token_string_t cmd_setqmap_what =
7683         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7684                                  what, "tx#rx");
7685 cmdline_parse_token_num_t cmd_setqmap_portid =
7686         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7687                               port_id, UINT16);
7688 cmdline_parse_token_num_t cmd_setqmap_queueid =
7689         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7690                               queue_id, UINT16);
7691 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7692         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7693                               map_value, UINT8);
7694
7695 cmdline_parse_inst_t cmd_set_qmap = {
7696         .f = cmd_set_qmap_parsed,
7697         .data = NULL,
7698         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7699                 "Set statistics mapping value on tx|rx queue_id of port_id",
7700         .tokens = {
7701                 (void *)&cmd_setqmap_set,
7702                 (void *)&cmd_setqmap_qmap,
7703                 (void *)&cmd_setqmap_what,
7704                 (void *)&cmd_setqmap_portid,
7705                 (void *)&cmd_setqmap_queueid,
7706                 (void *)&cmd_setqmap_mapvalue,
7707                 NULL,
7708         },
7709 };
7710
7711 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7712 struct cmd_set_xstats_hide_zero_result {
7713         cmdline_fixed_string_t keyword;
7714         cmdline_fixed_string_t name;
7715         cmdline_fixed_string_t on_off;
7716 };
7717
7718 static void
7719 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7720                         __attribute__((unused)) struct cmdline *cl,
7721                         __attribute__((unused)) void *data)
7722 {
7723         struct cmd_set_xstats_hide_zero_result *res;
7724         uint16_t on_off = 0;
7725
7726         res = parsed_result;
7727         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7728         set_xstats_hide_zero(on_off);
7729 }
7730
7731 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7732         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7733                                  keyword, "set");
7734 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7735         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7736                                  name, "xstats-hide-zero");
7737 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7738         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7739                                  on_off, "on#off");
7740
7741 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7742         .f = cmd_set_xstats_hide_zero_parsed,
7743         .data = NULL,
7744         .help_str = "set xstats-hide-zero on|off",
7745         .tokens = {
7746                 (void *)&cmd_set_xstats_hide_zero_keyword,
7747                 (void *)&cmd_set_xstats_hide_zero_name,
7748                 (void *)&cmd_set_xstats_hide_zero_on_off,
7749                 NULL,
7750         },
7751 };
7752
7753 /* *** CONFIGURE UNICAST HASH TABLE *** */
7754 struct cmd_set_uc_hash_table {
7755         cmdline_fixed_string_t set;
7756         cmdline_fixed_string_t port;
7757         portid_t port_id;
7758         cmdline_fixed_string_t what;
7759         struct ether_addr address;
7760         cmdline_fixed_string_t mode;
7761 };
7762
7763 static void
7764 cmd_set_uc_hash_parsed(void *parsed_result,
7765                        __attribute__((unused)) struct cmdline *cl,
7766                        __attribute__((unused)) void *data)
7767 {
7768         int ret=0;
7769         struct cmd_set_uc_hash_table *res = parsed_result;
7770
7771         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7772
7773         if (strcmp(res->what, "uta") == 0)
7774                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7775                                                 &res->address,(uint8_t)is_on);
7776         if (ret < 0)
7777                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7778
7779 }
7780
7781 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7782         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7783                                  set, "set");
7784 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7785         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7786                                  port, "port");
7787 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7788         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7789                               port_id, UINT16);
7790 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7791         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7792                                  what, "uta");
7793 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7794         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7795                                 address);
7796 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7797         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7798                                  mode, "on#off");
7799
7800 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7801         .f = cmd_set_uc_hash_parsed,
7802         .data = NULL,
7803         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7804         .tokens = {
7805                 (void *)&cmd_set_uc_hash_set,
7806                 (void *)&cmd_set_uc_hash_port,
7807                 (void *)&cmd_set_uc_hash_portid,
7808                 (void *)&cmd_set_uc_hash_what,
7809                 (void *)&cmd_set_uc_hash_mac,
7810                 (void *)&cmd_set_uc_hash_mode,
7811                 NULL,
7812         },
7813 };
7814
7815 struct cmd_set_uc_all_hash_table {
7816         cmdline_fixed_string_t set;
7817         cmdline_fixed_string_t port;
7818         portid_t port_id;
7819         cmdline_fixed_string_t what;
7820         cmdline_fixed_string_t value;
7821         cmdline_fixed_string_t mode;
7822 };
7823
7824 static void
7825 cmd_set_uc_all_hash_parsed(void *parsed_result,
7826                        __attribute__((unused)) struct cmdline *cl,
7827                        __attribute__((unused)) void *data)
7828 {
7829         int ret=0;
7830         struct cmd_set_uc_all_hash_table *res = parsed_result;
7831
7832         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7833
7834         if ((strcmp(res->what, "uta") == 0) &&
7835                 (strcmp(res->value, "all") == 0))
7836                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7837         if (ret < 0)
7838                 printf("bad unicast hash table parameter,"
7839                         "return code = %d \n", ret);
7840 }
7841
7842 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7843         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7844                                  set, "set");
7845 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7846         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7847                                  port, "port");
7848 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7849         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7850                               port_id, UINT16);
7851 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7852         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7853                                  what, "uta");
7854 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7855         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7856                                 value,"all");
7857 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7858         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7859                                  mode, "on#off");
7860
7861 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7862         .f = cmd_set_uc_all_hash_parsed,
7863         .data = NULL,
7864         .help_str = "set port <port_id> uta all on|off",
7865         .tokens = {
7866                 (void *)&cmd_set_uc_all_hash_set,
7867                 (void *)&cmd_set_uc_all_hash_port,
7868                 (void *)&cmd_set_uc_all_hash_portid,
7869                 (void *)&cmd_set_uc_all_hash_what,
7870                 (void *)&cmd_set_uc_all_hash_value,
7871                 (void *)&cmd_set_uc_all_hash_mode,
7872                 NULL,
7873         },
7874 };
7875
7876 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7877 struct cmd_set_vf_macvlan_filter {
7878         cmdline_fixed_string_t set;
7879         cmdline_fixed_string_t port;
7880         portid_t port_id;
7881         cmdline_fixed_string_t vf;
7882         uint8_t vf_id;
7883         struct ether_addr address;
7884         cmdline_fixed_string_t filter_type;
7885         cmdline_fixed_string_t mode;
7886 };
7887
7888 static void
7889 cmd_set_vf_macvlan_parsed(void *parsed_result,
7890                        __attribute__((unused)) struct cmdline *cl,
7891                        __attribute__((unused)) void *data)
7892 {
7893         int is_on, ret = 0;
7894         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7895         struct rte_eth_mac_filter filter;
7896
7897         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7898
7899         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7900
7901         /* set VF MAC filter */
7902         filter.is_vf = 1;
7903
7904         /* set VF ID */
7905         filter.dst_id = res->vf_id;
7906
7907         if (!strcmp(res->filter_type, "exact-mac"))
7908                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7909         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7910                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7911         else if (!strcmp(res->filter_type, "hashmac"))
7912                 filter.filter_type = RTE_MAC_HASH_MATCH;
7913         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7914                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7915
7916         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7917
7918         if (is_on)
7919                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7920                                         RTE_ETH_FILTER_MACVLAN,
7921                                         RTE_ETH_FILTER_ADD,
7922                                          &filter);
7923         else
7924                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7925                                         RTE_ETH_FILTER_MACVLAN,
7926                                         RTE_ETH_FILTER_DELETE,
7927                                         &filter);
7928
7929         if (ret < 0)
7930                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7931
7932 }
7933
7934 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7935         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7936                                  set, "set");
7937 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7938         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7939                                  port, "port");
7940 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7941         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7942                               port_id, UINT16);
7943 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7944         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7945                                  vf, "vf");
7946 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7947         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7948                                 vf_id, UINT8);
7949 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7950         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7951                                 address);
7952 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7953         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7954                                 filter_type, "exact-mac#exact-mac-vlan"
7955                                 "#hashmac#hashmac-vlan");
7956 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7957         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7958                                  mode, "on#off");
7959
7960 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7961         .f = cmd_set_vf_macvlan_parsed,
7962         .data = NULL,
7963         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7964                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7965                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7966                 "hash match rule: hash match of MAC and exact match of VLAN",
7967         .tokens = {
7968                 (void *)&cmd_set_vf_macvlan_set,
7969                 (void *)&cmd_set_vf_macvlan_port,
7970                 (void *)&cmd_set_vf_macvlan_portid,
7971                 (void *)&cmd_set_vf_macvlan_vf,
7972                 (void *)&cmd_set_vf_macvlan_vf_id,
7973                 (void *)&cmd_set_vf_macvlan_mac,
7974                 (void *)&cmd_set_vf_macvlan_filter_type,
7975                 (void *)&cmd_set_vf_macvlan_mode,
7976                 NULL,
7977         },
7978 };
7979
7980 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7981 struct cmd_set_vf_traffic {
7982         cmdline_fixed_string_t set;
7983         cmdline_fixed_string_t port;
7984         portid_t port_id;
7985         cmdline_fixed_string_t vf;
7986         uint8_t vf_id;
7987         cmdline_fixed_string_t what;
7988         cmdline_fixed_string_t mode;
7989 };
7990
7991 static void
7992 cmd_set_vf_traffic_parsed(void *parsed_result,
7993                        __attribute__((unused)) struct cmdline *cl,
7994                        __attribute__((unused)) void *data)
7995 {
7996         struct cmd_set_vf_traffic *res = parsed_result;
7997         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7998         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7999
8000         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8001 }
8002
8003 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8004         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8005                                  set, "set");
8006 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8007         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8008                                  port, "port");
8009 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8010         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8011                               port_id, UINT16);
8012 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8013         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8014                                  vf, "vf");
8015 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8016         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8017                               vf_id, UINT8);
8018 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8019         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8020                                  what, "tx#rx");
8021 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8022         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8023                                  mode, "on#off");
8024
8025 cmdline_parse_inst_t cmd_set_vf_traffic = {
8026         .f = cmd_set_vf_traffic_parsed,
8027         .data = NULL,
8028         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8029         .tokens = {
8030                 (void *)&cmd_setvf_traffic_set,
8031                 (void *)&cmd_setvf_traffic_port,
8032                 (void *)&cmd_setvf_traffic_portid,
8033                 (void *)&cmd_setvf_traffic_vf,
8034                 (void *)&cmd_setvf_traffic_vfid,
8035                 (void *)&cmd_setvf_traffic_what,
8036                 (void *)&cmd_setvf_traffic_mode,
8037                 NULL,
8038         },
8039 };
8040
8041 /* *** CONFIGURE VF RECEIVE MODE *** */
8042 struct cmd_set_vf_rxmode {
8043         cmdline_fixed_string_t set;
8044         cmdline_fixed_string_t port;
8045         portid_t port_id;
8046         cmdline_fixed_string_t vf;
8047         uint8_t vf_id;
8048         cmdline_fixed_string_t what;
8049         cmdline_fixed_string_t mode;
8050         cmdline_fixed_string_t on;
8051 };
8052
8053 static void
8054 cmd_set_vf_rxmode_parsed(void *parsed_result,
8055                        __attribute__((unused)) struct cmdline *cl,
8056                        __attribute__((unused)) void *data)
8057 {
8058         int ret = -ENOTSUP;
8059         uint16_t rx_mode = 0;
8060         struct cmd_set_vf_rxmode *res = parsed_result;
8061
8062         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8063         if (!strcmp(res->what,"rxmode")) {
8064                 if (!strcmp(res->mode, "AUPE"))
8065                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8066                 else if (!strcmp(res->mode, "ROPE"))
8067                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8068                 else if (!strcmp(res->mode, "BAM"))
8069                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8070                 else if (!strncmp(res->mode, "MPE",3))
8071                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8072         }
8073
8074         RTE_SET_USED(is_on);
8075
8076 #ifdef RTE_LIBRTE_IXGBE_PMD
8077         if (ret == -ENOTSUP)
8078                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8079                                                   rx_mode, (uint8_t)is_on);
8080 #endif
8081 #ifdef RTE_LIBRTE_BNXT_PMD
8082         if (ret == -ENOTSUP)
8083                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8084                                                  rx_mode, (uint8_t)is_on);
8085 #endif
8086         if (ret < 0)
8087                 printf("bad VF receive mode parameter, return code = %d \n",
8088                 ret);
8089 }
8090
8091 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8092         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8093                                  set, "set");
8094 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8095         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8096                                  port, "port");
8097 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8098         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8099                               port_id, UINT16);
8100 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8101         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8102                                  vf, "vf");
8103 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8104         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8105                               vf_id, UINT8);
8106 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8107         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8108                                  what, "rxmode");
8109 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8110         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8111                                  mode, "AUPE#ROPE#BAM#MPE");
8112 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8113         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8114                                  on, "on#off");
8115
8116 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8117         .f = cmd_set_vf_rxmode_parsed,
8118         .data = NULL,
8119         .help_str = "set port <port_id> vf <vf_id> rxmode "
8120                 "AUPE|ROPE|BAM|MPE on|off",
8121         .tokens = {
8122                 (void *)&cmd_set_vf_rxmode_set,
8123                 (void *)&cmd_set_vf_rxmode_port,
8124                 (void *)&cmd_set_vf_rxmode_portid,
8125                 (void *)&cmd_set_vf_rxmode_vf,
8126                 (void *)&cmd_set_vf_rxmode_vfid,
8127                 (void *)&cmd_set_vf_rxmode_what,
8128                 (void *)&cmd_set_vf_rxmode_mode,
8129                 (void *)&cmd_set_vf_rxmode_on,
8130                 NULL,
8131         },
8132 };
8133
8134 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8135 struct cmd_vf_mac_addr_result {
8136         cmdline_fixed_string_t mac_addr_cmd;
8137         cmdline_fixed_string_t what;
8138         cmdline_fixed_string_t port;
8139         uint16_t port_num;
8140         cmdline_fixed_string_t vf;
8141         uint8_t vf_num;
8142         struct ether_addr address;
8143 };
8144
8145 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8146                 __attribute__((unused)) struct cmdline *cl,
8147                 __attribute__((unused)) void *data)
8148 {
8149         struct cmd_vf_mac_addr_result *res = parsed_result;
8150         int ret = -ENOTSUP;
8151
8152         if (strcmp(res->what, "add") != 0)
8153                 return;
8154
8155 #ifdef RTE_LIBRTE_I40E_PMD
8156         if (ret == -ENOTSUP)
8157                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8158                                                    &res->address);
8159 #endif
8160 #ifdef RTE_LIBRTE_BNXT_PMD
8161         if (ret == -ENOTSUP)
8162                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8163                                                 res->vf_num);
8164 #endif
8165
8166         if(ret < 0)
8167                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8168
8169 }
8170
8171 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8172         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8173                                 mac_addr_cmd,"mac_addr");
8174 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8175         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8176                                 what,"add");
8177 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8178         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8179                                 port,"port");
8180 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8181         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8182                                 port_num, UINT16);
8183 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8184         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8185                                 vf,"vf");
8186 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8187         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8188                                 vf_num, UINT8);
8189 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8190         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8191                                 address);
8192
8193 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8194         .f = cmd_vf_mac_addr_parsed,
8195         .data = (void *)0,
8196         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8197                 "Add MAC address filtering for a VF on port_id",
8198         .tokens = {
8199                 (void *)&cmd_vf_mac_addr_cmd,
8200                 (void *)&cmd_vf_mac_addr_what,
8201                 (void *)&cmd_vf_mac_addr_port,
8202                 (void *)&cmd_vf_mac_addr_portnum,
8203                 (void *)&cmd_vf_mac_addr_vf,
8204                 (void *)&cmd_vf_mac_addr_vfnum,
8205                 (void *)&cmd_vf_mac_addr_addr,
8206                 NULL,
8207         },
8208 };
8209
8210 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8211 struct cmd_vf_rx_vlan_filter {
8212         cmdline_fixed_string_t rx_vlan;
8213         cmdline_fixed_string_t what;
8214         uint16_t vlan_id;
8215         cmdline_fixed_string_t port;
8216         portid_t port_id;
8217         cmdline_fixed_string_t vf;
8218         uint64_t vf_mask;
8219 };
8220
8221 static void
8222 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8223                           __attribute__((unused)) struct cmdline *cl,
8224                           __attribute__((unused)) void *data)
8225 {
8226         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8227         int ret = -ENOTSUP;
8228
8229         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8230
8231 #ifdef RTE_LIBRTE_IXGBE_PMD
8232         if (ret == -ENOTSUP)
8233                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8234                                 res->vlan_id, res->vf_mask, is_add);
8235 #endif
8236 #ifdef RTE_LIBRTE_I40E_PMD
8237         if (ret == -ENOTSUP)
8238                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8239                                 res->vlan_id, res->vf_mask, is_add);
8240 #endif
8241 #ifdef RTE_LIBRTE_BNXT_PMD
8242         if (ret == -ENOTSUP)
8243                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8244                                 res->vlan_id, res->vf_mask, is_add);
8245 #endif
8246
8247         switch (ret) {
8248         case 0:
8249                 break;
8250         case -EINVAL:
8251                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8252                                 res->vlan_id, res->vf_mask);
8253                 break;
8254         case -ENODEV:
8255                 printf("invalid port_id %d\n", res->port_id);
8256                 break;
8257         case -ENOTSUP:
8258                 printf("function not implemented or supported\n");
8259                 break;
8260         default:
8261                 printf("programming error: (%s)\n", strerror(-ret));
8262         }
8263 }
8264
8265 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8266         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8267                                  rx_vlan, "rx_vlan");
8268 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8269         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8270                                  what, "add#rm");
8271 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8272         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8273                               vlan_id, UINT16);
8274 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8275         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8276                                  port, "port");
8277 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8278         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8279                               port_id, UINT16);
8280 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8281         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8282                                  vf, "vf");
8283 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8284         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8285                               vf_mask, UINT64);
8286
8287 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8288         .f = cmd_vf_rx_vlan_filter_parsed,
8289         .data = NULL,
8290         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8291                 "(vf_mask = hexadecimal VF mask)",
8292         .tokens = {
8293                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8294                 (void *)&cmd_vf_rx_vlan_filter_what,
8295                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8296                 (void *)&cmd_vf_rx_vlan_filter_port,
8297                 (void *)&cmd_vf_rx_vlan_filter_portid,
8298                 (void *)&cmd_vf_rx_vlan_filter_vf,
8299                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8300                 NULL,
8301         },
8302 };
8303
8304 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8305 struct cmd_queue_rate_limit_result {
8306         cmdline_fixed_string_t set;
8307         cmdline_fixed_string_t port;
8308         uint16_t port_num;
8309         cmdline_fixed_string_t queue;
8310         uint8_t queue_num;
8311         cmdline_fixed_string_t rate;
8312         uint16_t rate_num;
8313 };
8314
8315 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8316                 __attribute__((unused)) struct cmdline *cl,
8317                 __attribute__((unused)) void *data)
8318 {
8319         struct cmd_queue_rate_limit_result *res = parsed_result;
8320         int ret = 0;
8321
8322         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8323                 && (strcmp(res->queue, "queue") == 0)
8324                 && (strcmp(res->rate, "rate") == 0))
8325                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8326                                         res->rate_num);
8327         if (ret < 0)
8328                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8329
8330 }
8331
8332 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8333         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8334                                 set, "set");
8335 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8336         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8337                                 port, "port");
8338 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8339         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8340                                 port_num, UINT16);
8341 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8342         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8343                                 queue, "queue");
8344 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8345         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8346                                 queue_num, UINT8);
8347 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8348         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8349                                 rate, "rate");
8350 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8351         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8352                                 rate_num, UINT16);
8353
8354 cmdline_parse_inst_t cmd_queue_rate_limit = {
8355         .f = cmd_queue_rate_limit_parsed,
8356         .data = (void *)0,
8357         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8358                 "Set rate limit for a queue on port_id",
8359         .tokens = {
8360                 (void *)&cmd_queue_rate_limit_set,
8361                 (void *)&cmd_queue_rate_limit_port,
8362                 (void *)&cmd_queue_rate_limit_portnum,
8363                 (void *)&cmd_queue_rate_limit_queue,
8364                 (void *)&cmd_queue_rate_limit_queuenum,
8365                 (void *)&cmd_queue_rate_limit_rate,
8366                 (void *)&cmd_queue_rate_limit_ratenum,
8367                 NULL,
8368         },
8369 };
8370
8371 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8372 struct cmd_vf_rate_limit_result {
8373         cmdline_fixed_string_t set;
8374         cmdline_fixed_string_t port;
8375         uint16_t port_num;
8376         cmdline_fixed_string_t vf;
8377         uint8_t vf_num;
8378         cmdline_fixed_string_t rate;
8379         uint16_t rate_num;
8380         cmdline_fixed_string_t q_msk;
8381         uint64_t q_msk_val;
8382 };
8383
8384 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8385                 __attribute__((unused)) struct cmdline *cl,
8386                 __attribute__((unused)) void *data)
8387 {
8388         struct cmd_vf_rate_limit_result *res = parsed_result;
8389         int ret = 0;
8390
8391         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8392                 && (strcmp(res->vf, "vf") == 0)
8393                 && (strcmp(res->rate, "rate") == 0)
8394                 && (strcmp(res->q_msk, "queue_mask") == 0))
8395                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8396                                         res->rate_num, res->q_msk_val);
8397         if (ret < 0)
8398                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8399
8400 }
8401
8402 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8403         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8404                                 set, "set");
8405 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8406         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8407                                 port, "port");
8408 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8409         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8410                                 port_num, UINT16);
8411 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8412         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8413                                 vf, "vf");
8414 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8415         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8416                                 vf_num, UINT8);
8417 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8418         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8419                                 rate, "rate");
8420 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8421         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8422                                 rate_num, UINT16);
8423 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8424         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8425                                 q_msk, "queue_mask");
8426 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8427         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8428                                 q_msk_val, UINT64);
8429
8430 cmdline_parse_inst_t cmd_vf_rate_limit = {
8431         .f = cmd_vf_rate_limit_parsed,
8432         .data = (void *)0,
8433         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8434                 "queue_mask <queue_mask_value>: "
8435                 "Set rate limit for queues of VF on port_id",
8436         .tokens = {
8437                 (void *)&cmd_vf_rate_limit_set,
8438                 (void *)&cmd_vf_rate_limit_port,
8439                 (void *)&cmd_vf_rate_limit_portnum,
8440                 (void *)&cmd_vf_rate_limit_vf,
8441                 (void *)&cmd_vf_rate_limit_vfnum,
8442                 (void *)&cmd_vf_rate_limit_rate,
8443                 (void *)&cmd_vf_rate_limit_ratenum,
8444                 (void *)&cmd_vf_rate_limit_q_msk,
8445                 (void *)&cmd_vf_rate_limit_q_msk_val,
8446                 NULL,
8447         },
8448 };
8449
8450 /* *** ADD TUNNEL FILTER OF A PORT *** */
8451 struct cmd_tunnel_filter_result {
8452         cmdline_fixed_string_t cmd;
8453         cmdline_fixed_string_t what;
8454         portid_t port_id;
8455         struct ether_addr outer_mac;
8456         struct ether_addr inner_mac;
8457         cmdline_ipaddr_t ip_value;
8458         uint16_t inner_vlan;
8459         cmdline_fixed_string_t tunnel_type;
8460         cmdline_fixed_string_t filter_type;
8461         uint32_t tenant_id;
8462         uint16_t queue_num;
8463 };
8464
8465 static void
8466 cmd_tunnel_filter_parsed(void *parsed_result,
8467                           __attribute__((unused)) struct cmdline *cl,
8468                           __attribute__((unused)) void *data)
8469 {
8470         struct cmd_tunnel_filter_result *res = parsed_result;
8471         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8472         int ret = 0;
8473
8474         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8475
8476         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8477         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8478         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8479
8480         if (res->ip_value.family == AF_INET) {
8481                 tunnel_filter_conf.ip_addr.ipv4_addr =
8482                         res->ip_value.addr.ipv4.s_addr;
8483                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8484         } else {
8485                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8486                         &(res->ip_value.addr.ipv6),
8487                         sizeof(struct in6_addr));
8488                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8489         }
8490
8491         if (!strcmp(res->filter_type, "imac-ivlan"))
8492                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8493         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8494                 tunnel_filter_conf.filter_type =
8495                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8496         else if (!strcmp(res->filter_type, "imac-tenid"))
8497                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8498         else if (!strcmp(res->filter_type, "imac"))
8499                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8500         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8501                 tunnel_filter_conf.filter_type =
8502                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8503         else if (!strcmp(res->filter_type, "oip"))
8504                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8505         else if (!strcmp(res->filter_type, "iip"))
8506                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8507         else {
8508                 printf("The filter type is not supported");
8509                 return;
8510         }
8511
8512         if (!strcmp(res->tunnel_type, "vxlan"))
8513                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8514         else if (!strcmp(res->tunnel_type, "nvgre"))
8515                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8516         else if (!strcmp(res->tunnel_type, "ipingre"))
8517                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8518         else {
8519                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8520                 return;
8521         }
8522
8523         tunnel_filter_conf.tenant_id = res->tenant_id;
8524         tunnel_filter_conf.queue_id = res->queue_num;
8525         if (!strcmp(res->what, "add"))
8526                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8527                                         RTE_ETH_FILTER_TUNNEL,
8528                                         RTE_ETH_FILTER_ADD,
8529                                         &tunnel_filter_conf);
8530         else
8531                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8532                                         RTE_ETH_FILTER_TUNNEL,
8533                                         RTE_ETH_FILTER_DELETE,
8534                                         &tunnel_filter_conf);
8535         if (ret < 0)
8536                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8537                                 strerror(-ret));
8538
8539 }
8540 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8541         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8542         cmd, "tunnel_filter");
8543 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8544         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8545         what, "add#rm");
8546 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8547         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8548         port_id, UINT16);
8549 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8550         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8551         outer_mac);
8552 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8553         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8554         inner_mac);
8555 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8556         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8557         inner_vlan, UINT16);
8558 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8559         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8560         ip_value);
8561 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8562         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8563         tunnel_type, "vxlan#nvgre#ipingre");
8564
8565 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8566         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8567         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8568                 "imac#omac-imac-tenid");
8569 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8570         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8571         tenant_id, UINT32);
8572 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8573         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8574         queue_num, UINT16);
8575
8576 cmdline_parse_inst_t cmd_tunnel_filter = {
8577         .f = cmd_tunnel_filter_parsed,
8578         .data = (void *)0,
8579         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8580                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8581                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8582                 "<queue_id>: Add/Rm tunnel filter of a port",
8583         .tokens = {
8584                 (void *)&cmd_tunnel_filter_cmd,
8585                 (void *)&cmd_tunnel_filter_what,
8586                 (void *)&cmd_tunnel_filter_port_id,
8587                 (void *)&cmd_tunnel_filter_outer_mac,
8588                 (void *)&cmd_tunnel_filter_inner_mac,
8589                 (void *)&cmd_tunnel_filter_ip_value,
8590                 (void *)&cmd_tunnel_filter_innner_vlan,
8591                 (void *)&cmd_tunnel_filter_tunnel_type,
8592                 (void *)&cmd_tunnel_filter_filter_type,
8593                 (void *)&cmd_tunnel_filter_tenant_id,
8594                 (void *)&cmd_tunnel_filter_queue_num,
8595                 NULL,
8596         },
8597 };
8598
8599 /* *** CONFIGURE TUNNEL UDP PORT *** */
8600 struct cmd_tunnel_udp_config {
8601         cmdline_fixed_string_t cmd;
8602         cmdline_fixed_string_t what;
8603         uint16_t udp_port;
8604         portid_t port_id;
8605 };
8606
8607 static void
8608 cmd_tunnel_udp_config_parsed(void *parsed_result,
8609                           __attribute__((unused)) struct cmdline *cl,
8610                           __attribute__((unused)) void *data)
8611 {
8612         struct cmd_tunnel_udp_config *res = parsed_result;
8613         struct rte_eth_udp_tunnel tunnel_udp;
8614         int ret;
8615
8616         tunnel_udp.udp_port = res->udp_port;
8617
8618         if (!strcmp(res->cmd, "rx_vxlan_port"))
8619                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8620
8621         if (!strcmp(res->what, "add"))
8622                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8623                                                       &tunnel_udp);
8624         else
8625                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8626                                                          &tunnel_udp);
8627
8628         if (ret < 0)
8629                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8630 }
8631
8632 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8633         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8634                                 cmd, "rx_vxlan_port");
8635 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8636         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8637                                 what, "add#rm");
8638 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8639         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8640                                 udp_port, UINT16);
8641 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8642         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8643                                 port_id, UINT16);
8644
8645 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8646         .f = cmd_tunnel_udp_config_parsed,
8647         .data = (void *)0,
8648         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8649                 "Add/Remove a tunneling UDP port filter",
8650         .tokens = {
8651                 (void *)&cmd_tunnel_udp_config_cmd,
8652                 (void *)&cmd_tunnel_udp_config_what,
8653                 (void *)&cmd_tunnel_udp_config_udp_port,
8654                 (void *)&cmd_tunnel_udp_config_port_id,
8655                 NULL,
8656         },
8657 };
8658
8659 struct cmd_config_tunnel_udp_port {
8660         cmdline_fixed_string_t port;
8661         cmdline_fixed_string_t config;
8662         portid_t port_id;
8663         cmdline_fixed_string_t udp_tunnel_port;
8664         cmdline_fixed_string_t action;
8665         cmdline_fixed_string_t tunnel_type;
8666         uint16_t udp_port;
8667 };
8668
8669 static void
8670 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8671                                __attribute__((unused)) struct cmdline *cl,
8672                                __attribute__((unused)) void *data)
8673 {
8674         struct cmd_config_tunnel_udp_port *res = parsed_result;
8675         struct rte_eth_udp_tunnel tunnel_udp;
8676         int ret = 0;
8677
8678         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8679                 return;
8680
8681         tunnel_udp.udp_port = res->udp_port;
8682
8683         if (!strcmp(res->tunnel_type, "vxlan")) {
8684                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8685         } else if (!strcmp(res->tunnel_type, "geneve")) {
8686                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8687         } else {
8688                 printf("Invalid tunnel type\n");
8689                 return;
8690         }
8691
8692         if (!strcmp(res->action, "add"))
8693                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8694                                                       &tunnel_udp);
8695         else
8696                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8697                                                          &tunnel_udp);
8698
8699         if (ret < 0)
8700                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8701 }
8702
8703 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8704         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8705                                  "port");
8706 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8707         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8708                                  "config");
8709 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8710         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8711                               UINT16);
8712 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8713         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8714                                  udp_tunnel_port,
8715                                  "udp_tunnel_port");
8716 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8717         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8718                                  "add#rm");
8719 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8720         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8721                                  "vxlan#geneve");
8722 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8723         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8724                               UINT16);
8725
8726 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8727         .f = cmd_cfg_tunnel_udp_port_parsed,
8728         .data = NULL,
8729         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8730         .tokens = {
8731                 (void *)&cmd_config_tunnel_udp_port_port,
8732                 (void *)&cmd_config_tunnel_udp_port_config,
8733                 (void *)&cmd_config_tunnel_udp_port_port_id,
8734                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8735                 (void *)&cmd_config_tunnel_udp_port_action,
8736                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8737                 (void *)&cmd_config_tunnel_udp_port_value,
8738                 NULL,
8739         },
8740 };
8741
8742 /* *** GLOBAL CONFIG *** */
8743 struct cmd_global_config_result {
8744         cmdline_fixed_string_t cmd;
8745         portid_t port_id;
8746         cmdline_fixed_string_t cfg_type;
8747         uint8_t len;
8748 };
8749
8750 static void
8751 cmd_global_config_parsed(void *parsed_result,
8752                          __attribute__((unused)) struct cmdline *cl,
8753                          __attribute__((unused)) void *data)
8754 {
8755         struct cmd_global_config_result *res = parsed_result;
8756         struct rte_eth_global_cfg conf;
8757         int ret;
8758
8759         memset(&conf, 0, sizeof(conf));
8760         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8761         conf.cfg.gre_key_len = res->len;
8762         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8763                                       RTE_ETH_FILTER_SET, &conf);
8764         if (ret != 0)
8765                 printf("Global config error\n");
8766 }
8767
8768 cmdline_parse_token_string_t cmd_global_config_cmd =
8769         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8770                 "global_config");
8771 cmdline_parse_token_num_t cmd_global_config_port_id =
8772         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8773                                UINT16);
8774 cmdline_parse_token_string_t cmd_global_config_type =
8775         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8776                 cfg_type, "gre-key-len");
8777 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8778         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8779                 len, UINT8);
8780
8781 cmdline_parse_inst_t cmd_global_config = {
8782         .f = cmd_global_config_parsed,
8783         .data = (void *)NULL,
8784         .help_str = "global_config <port_id> gre-key-len <key_len>",
8785         .tokens = {
8786                 (void *)&cmd_global_config_cmd,
8787                 (void *)&cmd_global_config_port_id,
8788                 (void *)&cmd_global_config_type,
8789                 (void *)&cmd_global_config_gre_key_len,
8790                 NULL,
8791         },
8792 };
8793
8794 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8795 struct cmd_set_mirror_mask_result {
8796         cmdline_fixed_string_t set;
8797         cmdline_fixed_string_t port;
8798         portid_t port_id;
8799         cmdline_fixed_string_t mirror;
8800         uint8_t rule_id;
8801         cmdline_fixed_string_t what;
8802         cmdline_fixed_string_t value;
8803         cmdline_fixed_string_t dstpool;
8804         uint8_t dstpool_id;
8805         cmdline_fixed_string_t on;
8806 };
8807
8808 cmdline_parse_token_string_t cmd_mirror_mask_set =
8809         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8810                                 set, "set");
8811 cmdline_parse_token_string_t cmd_mirror_mask_port =
8812         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8813                                 port, "port");
8814 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8815         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8816                                 port_id, UINT16);
8817 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8818         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8819                                 mirror, "mirror-rule");
8820 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8821         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8822                                 rule_id, UINT8);
8823 cmdline_parse_token_string_t cmd_mirror_mask_what =
8824         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8825                                 what, "pool-mirror-up#pool-mirror-down"
8826                                       "#vlan-mirror");
8827 cmdline_parse_token_string_t cmd_mirror_mask_value =
8828         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8829                                 value, NULL);
8830 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8831         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8832                                 dstpool, "dst-pool");
8833 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8834         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8835                                 dstpool_id, UINT8);
8836 cmdline_parse_token_string_t cmd_mirror_mask_on =
8837         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8838                                 on, "on#off");
8839
8840 static void
8841 cmd_set_mirror_mask_parsed(void *parsed_result,
8842                        __attribute__((unused)) struct cmdline *cl,
8843                        __attribute__((unused)) void *data)
8844 {
8845         int ret,nb_item,i;
8846         struct cmd_set_mirror_mask_result *res = parsed_result;
8847         struct rte_eth_mirror_conf mr_conf;
8848
8849         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8850
8851         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8852
8853         mr_conf.dst_pool = res->dstpool_id;
8854
8855         if (!strcmp(res->what, "pool-mirror-up")) {
8856                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8857                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8858         } else if (!strcmp(res->what, "pool-mirror-down")) {
8859                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8860                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8861         } else if (!strcmp(res->what, "vlan-mirror")) {
8862                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8863                 nb_item = parse_item_list(res->value, "vlan",
8864                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8865                 if (nb_item <= 0)
8866                         return;
8867
8868                 for (i = 0; i < nb_item; i++) {
8869                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8870                                 printf("Invalid vlan_id: must be < 4096\n");
8871                                 return;
8872                         }
8873
8874                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8875                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8876                 }
8877         }
8878
8879         if (!strcmp(res->on, "on"))
8880                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8881                                                 res->rule_id, 1);
8882         else
8883                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8884                                                 res->rule_id, 0);
8885         if (ret < 0)
8886                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8887 }
8888
8889 cmdline_parse_inst_t cmd_set_mirror_mask = {
8890                 .f = cmd_set_mirror_mask_parsed,
8891                 .data = NULL,
8892                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8893                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8894                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8895                 .tokens = {
8896                         (void *)&cmd_mirror_mask_set,
8897                         (void *)&cmd_mirror_mask_port,
8898                         (void *)&cmd_mirror_mask_portid,
8899                         (void *)&cmd_mirror_mask_mirror,
8900                         (void *)&cmd_mirror_mask_ruleid,
8901                         (void *)&cmd_mirror_mask_what,
8902                         (void *)&cmd_mirror_mask_value,
8903                         (void *)&cmd_mirror_mask_dstpool,
8904                         (void *)&cmd_mirror_mask_poolid,
8905                         (void *)&cmd_mirror_mask_on,
8906                         NULL,
8907                 },
8908 };
8909
8910 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8911 struct cmd_set_mirror_link_result {
8912         cmdline_fixed_string_t set;
8913         cmdline_fixed_string_t port;
8914         portid_t port_id;
8915         cmdline_fixed_string_t mirror;
8916         uint8_t rule_id;
8917         cmdline_fixed_string_t what;
8918         cmdline_fixed_string_t dstpool;
8919         uint8_t dstpool_id;
8920         cmdline_fixed_string_t on;
8921 };
8922
8923 cmdline_parse_token_string_t cmd_mirror_link_set =
8924         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8925                                  set, "set");
8926 cmdline_parse_token_string_t cmd_mirror_link_port =
8927         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8928                                 port, "port");
8929 cmdline_parse_token_num_t cmd_mirror_link_portid =
8930         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8931                                 port_id, UINT16);
8932 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8933         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8934                                 mirror, "mirror-rule");
8935 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8936         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8937                             rule_id, UINT8);
8938 cmdline_parse_token_string_t cmd_mirror_link_what =
8939         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8940                                 what, "uplink-mirror#downlink-mirror");
8941 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8942         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8943                                 dstpool, "dst-pool");
8944 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8945         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8946                                 dstpool_id, UINT8);
8947 cmdline_parse_token_string_t cmd_mirror_link_on =
8948         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8949                                 on, "on#off");
8950
8951 static void
8952 cmd_set_mirror_link_parsed(void *parsed_result,
8953                        __attribute__((unused)) struct cmdline *cl,
8954                        __attribute__((unused)) void *data)
8955 {
8956         int ret;
8957         struct cmd_set_mirror_link_result *res = parsed_result;
8958         struct rte_eth_mirror_conf mr_conf;
8959
8960         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8961         if (!strcmp(res->what, "uplink-mirror"))
8962                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8963         else
8964                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8965
8966         mr_conf.dst_pool = res->dstpool_id;
8967
8968         if (!strcmp(res->on, "on"))
8969                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8970                                                 res->rule_id, 1);
8971         else
8972                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8973                                                 res->rule_id, 0);
8974
8975         /* check the return value and print it if is < 0 */
8976         if (ret < 0)
8977                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8978
8979 }
8980
8981 cmdline_parse_inst_t cmd_set_mirror_link = {
8982                 .f = cmd_set_mirror_link_parsed,
8983                 .data = NULL,
8984                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8985                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8986                 .tokens = {
8987                         (void *)&cmd_mirror_link_set,
8988                         (void *)&cmd_mirror_link_port,
8989                         (void *)&cmd_mirror_link_portid,
8990                         (void *)&cmd_mirror_link_mirror,
8991                         (void *)&cmd_mirror_link_ruleid,
8992                         (void *)&cmd_mirror_link_what,
8993                         (void *)&cmd_mirror_link_dstpool,
8994                         (void *)&cmd_mirror_link_poolid,
8995                         (void *)&cmd_mirror_link_on,
8996                         NULL,
8997                 },
8998 };
8999
9000 /* *** RESET VM MIRROR RULE *** */
9001 struct cmd_rm_mirror_rule_result {
9002         cmdline_fixed_string_t reset;
9003         cmdline_fixed_string_t port;
9004         portid_t port_id;
9005         cmdline_fixed_string_t mirror;
9006         uint8_t rule_id;
9007 };
9008
9009 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9010         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9011                                  reset, "reset");
9012 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9013         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9014                                 port, "port");
9015 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9016         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9017                                 port_id, UINT16);
9018 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9019         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9020                                 mirror, "mirror-rule");
9021 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9022         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9023                                 rule_id, UINT8);
9024
9025 static void
9026 cmd_reset_mirror_rule_parsed(void *parsed_result,
9027                        __attribute__((unused)) struct cmdline *cl,
9028                        __attribute__((unused)) void *data)
9029 {
9030         int ret;
9031         struct cmd_set_mirror_link_result *res = parsed_result;
9032         /* check rule_id */
9033         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9034         if(ret < 0)
9035                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9036 }
9037
9038 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9039                 .f = cmd_reset_mirror_rule_parsed,
9040                 .data = NULL,
9041                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9042                 .tokens = {
9043                         (void *)&cmd_rm_mirror_rule_reset,
9044                         (void *)&cmd_rm_mirror_rule_port,
9045                         (void *)&cmd_rm_mirror_rule_portid,
9046                         (void *)&cmd_rm_mirror_rule_mirror,
9047                         (void *)&cmd_rm_mirror_rule_ruleid,
9048                         NULL,
9049                 },
9050 };
9051
9052 /* ******************************************************************************** */
9053
9054 struct cmd_dump_result {
9055         cmdline_fixed_string_t dump;
9056 };
9057
9058 static void
9059 dump_struct_sizes(void)
9060 {
9061 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9062         DUMP_SIZE(struct rte_mbuf);
9063         DUMP_SIZE(struct rte_mempool);
9064         DUMP_SIZE(struct rte_ring);
9065 #undef DUMP_SIZE
9066 }
9067
9068 static void cmd_dump_parsed(void *parsed_result,
9069                             __attribute__((unused)) struct cmdline *cl,
9070                             __attribute__((unused)) void *data)
9071 {
9072         struct cmd_dump_result *res = parsed_result;
9073
9074         if (!strcmp(res->dump, "dump_physmem"))
9075                 rte_dump_physmem_layout(stdout);
9076         else if (!strcmp(res->dump, "dump_memzone"))
9077                 rte_memzone_dump(stdout);
9078         else if (!strcmp(res->dump, "dump_struct_sizes"))
9079                 dump_struct_sizes();
9080         else if (!strcmp(res->dump, "dump_ring"))
9081                 rte_ring_list_dump(stdout);
9082         else if (!strcmp(res->dump, "dump_mempool"))
9083                 rte_mempool_list_dump(stdout);
9084         else if (!strcmp(res->dump, "dump_devargs"))
9085                 rte_devargs_dump(stdout);
9086         else if (!strcmp(res->dump, "dump_log_types"))
9087                 rte_log_dump(stdout);
9088 }
9089
9090 cmdline_parse_token_string_t cmd_dump_dump =
9091         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9092                 "dump_physmem#"
9093                 "dump_memzone#"
9094                 "dump_struct_sizes#"
9095                 "dump_ring#"
9096                 "dump_mempool#"
9097                 "dump_devargs#"
9098                 "dump_log_types");
9099
9100 cmdline_parse_inst_t cmd_dump = {
9101         .f = cmd_dump_parsed,  /* function to call */
9102         .data = NULL,      /* 2nd arg of func */
9103         .help_str = "Dump status",
9104         .tokens = {        /* token list, NULL terminated */
9105                 (void *)&cmd_dump_dump,
9106                 NULL,
9107         },
9108 };
9109
9110 /* ******************************************************************************** */
9111
9112 struct cmd_dump_one_result {
9113         cmdline_fixed_string_t dump;
9114         cmdline_fixed_string_t name;
9115 };
9116
9117 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9118                                 __attribute__((unused)) void *data)
9119 {
9120         struct cmd_dump_one_result *res = parsed_result;
9121
9122         if (!strcmp(res->dump, "dump_ring")) {
9123                 struct rte_ring *r;
9124                 r = rte_ring_lookup(res->name);
9125                 if (r == NULL) {
9126                         cmdline_printf(cl, "Cannot find ring\n");
9127                         return;
9128                 }
9129                 rte_ring_dump(stdout, r);
9130         } else if (!strcmp(res->dump, "dump_mempool")) {
9131                 struct rte_mempool *mp;
9132                 mp = rte_mempool_lookup(res->name);
9133                 if (mp == NULL) {
9134                         cmdline_printf(cl, "Cannot find mempool\n");
9135                         return;
9136                 }
9137                 rte_mempool_dump(stdout, mp);
9138         }
9139 }
9140
9141 cmdline_parse_token_string_t cmd_dump_one_dump =
9142         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9143                                  "dump_ring#dump_mempool");
9144
9145 cmdline_parse_token_string_t cmd_dump_one_name =
9146         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9147
9148 cmdline_parse_inst_t cmd_dump_one = {
9149         .f = cmd_dump_one_parsed,  /* function to call */
9150         .data = NULL,      /* 2nd arg of func */
9151         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9152         .tokens = {        /* token list, NULL terminated */
9153                 (void *)&cmd_dump_one_dump,
9154                 (void *)&cmd_dump_one_name,
9155                 NULL,
9156         },
9157 };
9158
9159 /* *** Add/Del syn filter *** */
9160 struct cmd_syn_filter_result {
9161         cmdline_fixed_string_t filter;
9162         portid_t port_id;
9163         cmdline_fixed_string_t ops;
9164         cmdline_fixed_string_t priority;
9165         cmdline_fixed_string_t high;
9166         cmdline_fixed_string_t queue;
9167         uint16_t queue_id;
9168 };
9169
9170 static void
9171 cmd_syn_filter_parsed(void *parsed_result,
9172                         __attribute__((unused)) struct cmdline *cl,
9173                         __attribute__((unused)) void *data)
9174 {
9175         struct cmd_syn_filter_result *res = parsed_result;
9176         struct rte_eth_syn_filter syn_filter;
9177         int ret = 0;
9178
9179         ret = rte_eth_dev_filter_supported(res->port_id,
9180                                         RTE_ETH_FILTER_SYN);
9181         if (ret < 0) {
9182                 printf("syn filter is not supported on port %u.\n",
9183                                 res->port_id);
9184                 return;
9185         }
9186
9187         memset(&syn_filter, 0, sizeof(syn_filter));
9188
9189         if (!strcmp(res->ops, "add")) {
9190                 if (!strcmp(res->high, "high"))
9191                         syn_filter.hig_pri = 1;
9192                 else
9193                         syn_filter.hig_pri = 0;
9194
9195                 syn_filter.queue = res->queue_id;
9196                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9197                                                 RTE_ETH_FILTER_SYN,
9198                                                 RTE_ETH_FILTER_ADD,
9199                                                 &syn_filter);
9200         } else
9201                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9202                                                 RTE_ETH_FILTER_SYN,
9203                                                 RTE_ETH_FILTER_DELETE,
9204                                                 &syn_filter);
9205
9206         if (ret < 0)
9207                 printf("syn filter programming error: (%s)\n",
9208                                 strerror(-ret));
9209 }
9210
9211 cmdline_parse_token_string_t cmd_syn_filter_filter =
9212         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9213         filter, "syn_filter");
9214 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9215         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9216         port_id, UINT16);
9217 cmdline_parse_token_string_t cmd_syn_filter_ops =
9218         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9219         ops, "add#del");
9220 cmdline_parse_token_string_t cmd_syn_filter_priority =
9221         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9222                                 priority, "priority");
9223 cmdline_parse_token_string_t cmd_syn_filter_high =
9224         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9225                                 high, "high#low");
9226 cmdline_parse_token_string_t cmd_syn_filter_queue =
9227         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9228                                 queue, "queue");
9229 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9230         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9231                                 queue_id, UINT16);
9232
9233 cmdline_parse_inst_t cmd_syn_filter = {
9234         .f = cmd_syn_filter_parsed,
9235         .data = NULL,
9236         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9237                 "<queue_id>: Add/Delete syn filter",
9238         .tokens = {
9239                 (void *)&cmd_syn_filter_filter,
9240                 (void *)&cmd_syn_filter_port_id,
9241                 (void *)&cmd_syn_filter_ops,
9242                 (void *)&cmd_syn_filter_priority,
9243                 (void *)&cmd_syn_filter_high,
9244                 (void *)&cmd_syn_filter_queue,
9245                 (void *)&cmd_syn_filter_queue_id,
9246                 NULL,
9247         },
9248 };
9249
9250 /* *** queue region set *** */
9251 struct cmd_queue_region_result {
9252         cmdline_fixed_string_t set;
9253         cmdline_fixed_string_t port;
9254         portid_t port_id;
9255         cmdline_fixed_string_t cmd;
9256         cmdline_fixed_string_t region;
9257         uint8_t  region_id;
9258         cmdline_fixed_string_t queue_start_index;
9259         uint8_t  queue_id;
9260         cmdline_fixed_string_t queue_num;
9261         uint8_t  queue_num_value;
9262 };
9263
9264 static void
9265 cmd_queue_region_parsed(void *parsed_result,
9266                         __attribute__((unused)) struct cmdline *cl,
9267                         __attribute__((unused)) void *data)
9268 {
9269         struct cmd_queue_region_result *res = parsed_result;
9270         int ret = -ENOTSUP;
9271 #ifdef RTE_LIBRTE_I40E_PMD
9272         struct rte_pmd_i40e_queue_region_conf region_conf;
9273         enum rte_pmd_i40e_queue_region_op op_type;
9274 #endif
9275
9276         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9277                 return;
9278
9279 #ifdef RTE_LIBRTE_I40E_PMD
9280         memset(&region_conf, 0, sizeof(region_conf));
9281         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9282         region_conf.region_id = res->region_id;
9283         region_conf.queue_num = res->queue_num_value;
9284         region_conf.queue_start_index = res->queue_id;
9285
9286         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9287                                 op_type, &region_conf);
9288 #endif
9289
9290         switch (ret) {
9291         case 0:
9292                 break;
9293         case -ENOTSUP:
9294                 printf("function not implemented or supported\n");
9295                 break;
9296         default:
9297                 printf("queue region config error: (%s)\n", strerror(-ret));
9298         }
9299 }
9300
9301 cmdline_parse_token_string_t cmd_queue_region_set =
9302 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9303                 set, "set");
9304 cmdline_parse_token_string_t cmd_queue_region_port =
9305         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9306 cmdline_parse_token_num_t cmd_queue_region_port_id =
9307         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9308                                 port_id, UINT16);
9309 cmdline_parse_token_string_t cmd_queue_region_cmd =
9310         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9311                                  cmd, "queue-region");
9312 cmdline_parse_token_string_t cmd_queue_region_id =
9313         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9314                                 region, "region_id");
9315 cmdline_parse_token_num_t cmd_queue_region_index =
9316         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9317                                 region_id, UINT8);
9318 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9319         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9320                                 queue_start_index, "queue_start_index");
9321 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9322         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9323                                 queue_id, UINT8);
9324 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9325         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9326                                 queue_num, "queue_num");
9327 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9328         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9329                                 queue_num_value, UINT8);
9330
9331 cmdline_parse_inst_t cmd_queue_region = {
9332         .f = cmd_queue_region_parsed,
9333         .data = NULL,
9334         .help_str = "set port <port_id> queue-region region_id <value> "
9335                 "queue_start_index <value> queue_num <value>: Set a queue region",
9336         .tokens = {
9337                 (void *)&cmd_queue_region_set,
9338                 (void *)&cmd_queue_region_port,
9339                 (void *)&cmd_queue_region_port_id,
9340                 (void *)&cmd_queue_region_cmd,
9341                 (void *)&cmd_queue_region_id,
9342                 (void *)&cmd_queue_region_index,
9343                 (void *)&cmd_queue_region_queue_start_index,
9344                 (void *)&cmd_queue_region_queue_id,
9345                 (void *)&cmd_queue_region_queue_num,
9346                 (void *)&cmd_queue_region_queue_num_value,
9347                 NULL,
9348         },
9349 };
9350
9351 /* *** queue region and flowtype set *** */
9352 struct cmd_region_flowtype_result {
9353         cmdline_fixed_string_t set;
9354         cmdline_fixed_string_t port;
9355         portid_t port_id;
9356         cmdline_fixed_string_t cmd;
9357         cmdline_fixed_string_t region;
9358         uint8_t  region_id;
9359         cmdline_fixed_string_t flowtype;
9360         uint8_t  flowtype_id;
9361 };
9362
9363 static void
9364 cmd_region_flowtype_parsed(void *parsed_result,
9365                         __attribute__((unused)) struct cmdline *cl,
9366                         __attribute__((unused)) void *data)
9367 {
9368         struct cmd_region_flowtype_result *res = parsed_result;
9369         int ret = -ENOTSUP;
9370 #ifdef RTE_LIBRTE_I40E_PMD
9371         struct rte_pmd_i40e_queue_region_conf region_conf;
9372         enum rte_pmd_i40e_queue_region_op op_type;
9373 #endif
9374
9375         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9376                 return;
9377
9378 #ifdef RTE_LIBRTE_I40E_PMD
9379         memset(&region_conf, 0, sizeof(region_conf));
9380
9381         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9382         region_conf.region_id = res->region_id;
9383         region_conf.hw_flowtype = res->flowtype_id;
9384
9385         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9386                         op_type, &region_conf);
9387 #endif
9388
9389         switch (ret) {
9390         case 0:
9391                 break;
9392         case -ENOTSUP:
9393                 printf("function not implemented or supported\n");
9394                 break;
9395         default:
9396                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9397         }
9398 }
9399
9400 cmdline_parse_token_string_t cmd_region_flowtype_set =
9401 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9402                                 set, "set");
9403 cmdline_parse_token_string_t cmd_region_flowtype_port =
9404         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9405                                 port, "port");
9406 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9407         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9408                                 port_id, UINT16);
9409 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9410         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9411                                 cmd, "queue-region");
9412 cmdline_parse_token_string_t cmd_region_flowtype_index =
9413         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9414                                 region, "region_id");
9415 cmdline_parse_token_num_t cmd_region_flowtype_id =
9416         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9417                                 region_id, UINT8);
9418 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9419         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9420                                 flowtype, "flowtype");
9421 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9422         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9423                                 flowtype_id, UINT8);
9424 cmdline_parse_inst_t cmd_region_flowtype = {
9425         .f = cmd_region_flowtype_parsed,
9426         .data = NULL,
9427         .help_str = "set port <port_id> queue-region region_id <value> "
9428                 "flowtype <value>: Set a flowtype region index",
9429         .tokens = {
9430                 (void *)&cmd_region_flowtype_set,
9431                 (void *)&cmd_region_flowtype_port,
9432                 (void *)&cmd_region_flowtype_port_index,
9433                 (void *)&cmd_region_flowtype_cmd,
9434                 (void *)&cmd_region_flowtype_index,
9435                 (void *)&cmd_region_flowtype_id,
9436                 (void *)&cmd_region_flowtype_flow_index,
9437                 (void *)&cmd_region_flowtype_flow_id,
9438                 NULL,
9439         },
9440 };
9441
9442 /* *** User Priority (UP) to queue region (region_id) set *** */
9443 struct cmd_user_priority_region_result {
9444         cmdline_fixed_string_t set;
9445         cmdline_fixed_string_t port;
9446         portid_t port_id;
9447         cmdline_fixed_string_t cmd;
9448         cmdline_fixed_string_t user_priority;
9449         uint8_t  user_priority_id;
9450         cmdline_fixed_string_t region;
9451         uint8_t  region_id;
9452 };
9453
9454 static void
9455 cmd_user_priority_region_parsed(void *parsed_result,
9456                         __attribute__((unused)) struct cmdline *cl,
9457                         __attribute__((unused)) void *data)
9458 {
9459         struct cmd_user_priority_region_result *res = parsed_result;
9460         int ret = -ENOTSUP;
9461 #ifdef RTE_LIBRTE_I40E_PMD
9462         struct rte_pmd_i40e_queue_region_conf region_conf;
9463         enum rte_pmd_i40e_queue_region_op op_type;
9464 #endif
9465
9466         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9467                 return;
9468
9469 #ifdef RTE_LIBRTE_I40E_PMD
9470         memset(&region_conf, 0, sizeof(region_conf));
9471         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9472         region_conf.user_priority = res->user_priority_id;
9473         region_conf.region_id = res->region_id;
9474
9475         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9476                                 op_type, &region_conf);
9477 #endif
9478
9479         switch (ret) {
9480         case 0:
9481                 break;
9482         case -ENOTSUP:
9483                 printf("function not implemented or supported\n");
9484                 break;
9485         default:
9486                 printf("user_priority region config error: (%s)\n",
9487                                 strerror(-ret));
9488         }
9489 }
9490
9491 cmdline_parse_token_string_t cmd_user_priority_region_set =
9492         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9493                                 set, "set");
9494 cmdline_parse_token_string_t cmd_user_priority_region_port =
9495         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9496                                 port, "port");
9497 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9498         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9499                                 port_id, UINT16);
9500 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9501         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9502                                 cmd, "queue-region");
9503 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9504         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9505                                 user_priority, "UP");
9506 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9507         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9508                                 user_priority_id, UINT8);
9509 cmdline_parse_token_string_t cmd_user_priority_region_region =
9510         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9511                                 region, "region_id");
9512 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9513         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9514                                 region_id, UINT8);
9515
9516 cmdline_parse_inst_t cmd_user_priority_region = {
9517         .f = cmd_user_priority_region_parsed,
9518         .data = NULL,
9519         .help_str = "set port <port_id> queue-region UP <value> "
9520                 "region_id <value>: Set the mapping of User Priority (UP) "
9521                 "to queue region (region_id) ",
9522         .tokens = {
9523                 (void *)&cmd_user_priority_region_set,
9524                 (void *)&cmd_user_priority_region_port,
9525                 (void *)&cmd_user_priority_region_port_index,
9526                 (void *)&cmd_user_priority_region_cmd,
9527                 (void *)&cmd_user_priority_region_UP,
9528                 (void *)&cmd_user_priority_region_UP_id,
9529                 (void *)&cmd_user_priority_region_region,
9530                 (void *)&cmd_user_priority_region_region_id,
9531                 NULL,
9532         },
9533 };
9534
9535 /* *** flush all queue region related configuration *** */
9536 struct cmd_flush_queue_region_result {
9537         cmdline_fixed_string_t set;
9538         cmdline_fixed_string_t port;
9539         portid_t port_id;
9540         cmdline_fixed_string_t cmd;
9541         cmdline_fixed_string_t flush;
9542         cmdline_fixed_string_t what;
9543 };
9544
9545 static void
9546 cmd_flush_queue_region_parsed(void *parsed_result,
9547                         __attribute__((unused)) struct cmdline *cl,
9548                         __attribute__((unused)) void *data)
9549 {
9550         struct cmd_flush_queue_region_result *res = parsed_result;
9551         int ret = -ENOTSUP;
9552 #ifdef RTE_LIBRTE_I40E_PMD
9553         struct rte_pmd_i40e_queue_region_conf region_conf;
9554         enum rte_pmd_i40e_queue_region_op op_type;
9555 #endif
9556
9557         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9558                 return;
9559
9560 #ifdef RTE_LIBRTE_I40E_PMD
9561         memset(&region_conf, 0, sizeof(region_conf));
9562
9563         if (strcmp(res->what, "on") == 0)
9564                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9565         else
9566                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9567
9568         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9569                                 op_type, &region_conf);
9570 #endif
9571
9572         switch (ret) {
9573         case 0:
9574                 break;
9575         case -ENOTSUP:
9576                 printf("function not implemented or supported\n");
9577                 break;
9578         default:
9579                 printf("queue region config flush error: (%s)\n",
9580                                 strerror(-ret));
9581         }
9582 }
9583
9584 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9585         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9586                                 set, "set");
9587 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9588         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9589                                 port, "port");
9590 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9591         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9592                                 port_id, UINT16);
9593 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9594         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9595                                 cmd, "queue-region");
9596 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9597         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9598                                 flush, "flush");
9599 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9600         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9601                                 what, "on#off");
9602
9603 cmdline_parse_inst_t cmd_flush_queue_region = {
9604         .f = cmd_flush_queue_region_parsed,
9605         .data = NULL,
9606         .help_str = "set port <port_id> queue-region flush on|off"
9607                 ": flush all queue region related configuration",
9608         .tokens = {
9609                 (void *)&cmd_flush_queue_region_set,
9610                 (void *)&cmd_flush_queue_region_port,
9611                 (void *)&cmd_flush_queue_region_port_index,
9612                 (void *)&cmd_flush_queue_region_cmd,
9613                 (void *)&cmd_flush_queue_region_flush,
9614                 (void *)&cmd_flush_queue_region_what,
9615                 NULL,
9616         },
9617 };
9618
9619 /* *** get all queue region related configuration info *** */
9620 struct cmd_show_queue_region_info {
9621         cmdline_fixed_string_t show;
9622         cmdline_fixed_string_t port;
9623         portid_t port_id;
9624         cmdline_fixed_string_t cmd;
9625 };
9626
9627 static void
9628 cmd_show_queue_region_info_parsed(void *parsed_result,
9629                         __attribute__((unused)) struct cmdline *cl,
9630                         __attribute__((unused)) void *data)
9631 {
9632         struct cmd_show_queue_region_info *res = parsed_result;
9633         int ret = -ENOTSUP;
9634 #ifdef RTE_LIBRTE_I40E_PMD
9635         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9636         enum rte_pmd_i40e_queue_region_op op_type;
9637 #endif
9638
9639         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9640                 return;
9641
9642 #ifdef RTE_LIBRTE_I40E_PMD
9643         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9644
9645         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9646
9647         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9648                                         op_type, &rte_pmd_regions);
9649
9650         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9651 #endif
9652
9653         switch (ret) {
9654         case 0:
9655                 break;
9656         case -ENOTSUP:
9657                 printf("function not implemented or supported\n");
9658                 break;
9659         default:
9660                 printf("queue region config info show error: (%s)\n",
9661                                 strerror(-ret));
9662         }
9663 }
9664
9665 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9666 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9667                                 show, "show");
9668 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9669         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9670                                 port, "port");
9671 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9672         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9673                                 port_id, UINT16);
9674 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9675         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9676                                 cmd, "queue-region");
9677
9678 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9679         .f = cmd_show_queue_region_info_parsed,
9680         .data = NULL,
9681         .help_str = "show port <port_id> queue-region"
9682                 ": show all queue region related configuration info",
9683         .tokens = {
9684                 (void *)&cmd_show_queue_region_info_get,
9685                 (void *)&cmd_show_queue_region_info_port,
9686                 (void *)&cmd_show_queue_region_info_port_index,
9687                 (void *)&cmd_show_queue_region_info_cmd,
9688                 NULL,
9689         },
9690 };
9691
9692 /* *** ADD/REMOVE A 2tuple FILTER *** */
9693 struct cmd_2tuple_filter_result {
9694         cmdline_fixed_string_t filter;
9695         portid_t port_id;
9696         cmdline_fixed_string_t ops;
9697         cmdline_fixed_string_t dst_port;
9698         uint16_t dst_port_value;
9699         cmdline_fixed_string_t protocol;
9700         uint8_t protocol_value;
9701         cmdline_fixed_string_t mask;
9702         uint8_t  mask_value;
9703         cmdline_fixed_string_t tcp_flags;
9704         uint8_t tcp_flags_value;
9705         cmdline_fixed_string_t priority;
9706         uint8_t  priority_value;
9707         cmdline_fixed_string_t queue;
9708         uint16_t  queue_id;
9709 };
9710
9711 static void
9712 cmd_2tuple_filter_parsed(void *parsed_result,
9713                         __attribute__((unused)) struct cmdline *cl,
9714                         __attribute__((unused)) void *data)
9715 {
9716         struct rte_eth_ntuple_filter filter;
9717         struct cmd_2tuple_filter_result *res = parsed_result;
9718         int ret = 0;
9719
9720         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9721         if (ret < 0) {
9722                 printf("ntuple filter is not supported on port %u.\n",
9723                         res->port_id);
9724                 return;
9725         }
9726
9727         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9728
9729         filter.flags = RTE_2TUPLE_FLAGS;
9730         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9731         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9732         filter.proto = res->protocol_value;
9733         filter.priority = res->priority_value;
9734         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9735                 printf("nonzero tcp_flags is only meaningful"
9736                         " when protocol is TCP.\n");
9737                 return;
9738         }
9739         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9740                 printf("invalid TCP flags.\n");
9741                 return;
9742         }
9743
9744         if (res->tcp_flags_value != 0) {
9745                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9746                 filter.tcp_flags = res->tcp_flags_value;
9747         }
9748
9749         /* need convert to big endian. */
9750         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9751         filter.queue = res->queue_id;
9752
9753         if (!strcmp(res->ops, "add"))
9754                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9755                                 RTE_ETH_FILTER_NTUPLE,
9756                                 RTE_ETH_FILTER_ADD,
9757                                 &filter);
9758         else
9759                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9760                                 RTE_ETH_FILTER_NTUPLE,
9761                                 RTE_ETH_FILTER_DELETE,
9762                                 &filter);
9763         if (ret < 0)
9764                 printf("2tuple filter programming error: (%s)\n",
9765                         strerror(-ret));
9766
9767 }
9768
9769 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9770         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9771                                  filter, "2tuple_filter");
9772 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9773         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9774                                 port_id, UINT16);
9775 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9776         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9777                                  ops, "add#del");
9778 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9779         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9780                                 dst_port, "dst_port");
9781 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9782         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9783                                 dst_port_value, UINT16);
9784 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9785         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9786                                 protocol, "protocol");
9787 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9788         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9789                                 protocol_value, UINT8);
9790 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9791         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9792                                 mask, "mask");
9793 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9794         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9795                                 mask_value, INT8);
9796 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9797         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9798                                 tcp_flags, "tcp_flags");
9799 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9800         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9801                                 tcp_flags_value, UINT8);
9802 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9803         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9804                                 priority, "priority");
9805 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9806         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9807                                 priority_value, UINT8);
9808 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9809         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9810                                 queue, "queue");
9811 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9812         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9813                                 queue_id, UINT16);
9814
9815 cmdline_parse_inst_t cmd_2tuple_filter = {
9816         .f = cmd_2tuple_filter_parsed,
9817         .data = NULL,
9818         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9819                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9820                 "<queue_id>: Add a 2tuple filter",
9821         .tokens = {
9822                 (void *)&cmd_2tuple_filter_filter,
9823                 (void *)&cmd_2tuple_filter_port_id,
9824                 (void *)&cmd_2tuple_filter_ops,
9825                 (void *)&cmd_2tuple_filter_dst_port,
9826                 (void *)&cmd_2tuple_filter_dst_port_value,
9827                 (void *)&cmd_2tuple_filter_protocol,
9828                 (void *)&cmd_2tuple_filter_protocol_value,
9829                 (void *)&cmd_2tuple_filter_mask,
9830                 (void *)&cmd_2tuple_filter_mask_value,
9831                 (void *)&cmd_2tuple_filter_tcp_flags,
9832                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9833                 (void *)&cmd_2tuple_filter_priority,
9834                 (void *)&cmd_2tuple_filter_priority_value,
9835                 (void *)&cmd_2tuple_filter_queue,
9836                 (void *)&cmd_2tuple_filter_queue_id,
9837                 NULL,
9838         },
9839 };
9840
9841 /* *** ADD/REMOVE A 5tuple FILTER *** */
9842 struct cmd_5tuple_filter_result {
9843         cmdline_fixed_string_t filter;
9844         portid_t port_id;
9845         cmdline_fixed_string_t ops;
9846         cmdline_fixed_string_t dst_ip;
9847         cmdline_ipaddr_t dst_ip_value;
9848         cmdline_fixed_string_t src_ip;
9849         cmdline_ipaddr_t src_ip_value;
9850         cmdline_fixed_string_t dst_port;
9851         uint16_t dst_port_value;
9852         cmdline_fixed_string_t src_port;
9853         uint16_t src_port_value;
9854         cmdline_fixed_string_t protocol;
9855         uint8_t protocol_value;
9856         cmdline_fixed_string_t mask;
9857         uint8_t  mask_value;
9858         cmdline_fixed_string_t tcp_flags;
9859         uint8_t tcp_flags_value;
9860         cmdline_fixed_string_t priority;
9861         uint8_t  priority_value;
9862         cmdline_fixed_string_t queue;
9863         uint16_t  queue_id;
9864 };
9865
9866 static void
9867 cmd_5tuple_filter_parsed(void *parsed_result,
9868                         __attribute__((unused)) struct cmdline *cl,
9869                         __attribute__((unused)) void *data)
9870 {
9871         struct rte_eth_ntuple_filter filter;
9872         struct cmd_5tuple_filter_result *res = parsed_result;
9873         int ret = 0;
9874
9875         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9876         if (ret < 0) {
9877                 printf("ntuple filter is not supported on port %u.\n",
9878                         res->port_id);
9879                 return;
9880         }
9881
9882         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9883
9884         filter.flags = RTE_5TUPLE_FLAGS;
9885         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9886         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9887         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9888         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9889         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9890         filter.proto = res->protocol_value;
9891         filter.priority = res->priority_value;
9892         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9893                 printf("nonzero tcp_flags is only meaningful"
9894                         " when protocol is TCP.\n");
9895                 return;
9896         }
9897         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9898                 printf("invalid TCP flags.\n");
9899                 return;
9900         }
9901
9902         if (res->tcp_flags_value != 0) {
9903                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9904                 filter.tcp_flags = res->tcp_flags_value;
9905         }
9906
9907         if (res->dst_ip_value.family == AF_INET)
9908                 /* no need to convert, already big endian. */
9909                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9910         else {
9911                 if (filter.dst_ip_mask == 0) {
9912                         printf("can not support ipv6 involved compare.\n");
9913                         return;
9914                 }
9915                 filter.dst_ip = 0;
9916         }
9917
9918         if (res->src_ip_value.family == AF_INET)
9919                 /* no need to convert, already big endian. */
9920                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9921         else {
9922                 if (filter.src_ip_mask == 0) {
9923                         printf("can not support ipv6 involved compare.\n");
9924                         return;
9925                 }
9926                 filter.src_ip = 0;
9927         }
9928         /* need convert to big endian. */
9929         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9930         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9931         filter.queue = res->queue_id;
9932
9933         if (!strcmp(res->ops, "add"))
9934                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9935                                 RTE_ETH_FILTER_NTUPLE,
9936                                 RTE_ETH_FILTER_ADD,
9937                                 &filter);
9938         else
9939                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9940                                 RTE_ETH_FILTER_NTUPLE,
9941                                 RTE_ETH_FILTER_DELETE,
9942                                 &filter);
9943         if (ret < 0)
9944                 printf("5tuple filter programming error: (%s)\n",
9945                         strerror(-ret));
9946 }
9947
9948 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9949         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9950                                  filter, "5tuple_filter");
9951 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9952         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9953                                 port_id, UINT16);
9954 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9955         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9956                                  ops, "add#del");
9957 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9958         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9959                                 dst_ip, "dst_ip");
9960 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9961         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9962                                 dst_ip_value);
9963 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9964         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9965                                 src_ip, "src_ip");
9966 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9967         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9968                                 src_ip_value);
9969 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9970         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9971                                 dst_port, "dst_port");
9972 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9973         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9974                                 dst_port_value, UINT16);
9975 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9976         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9977                                 src_port, "src_port");
9978 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9979         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9980                                 src_port_value, UINT16);
9981 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9982         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9983                                 protocol, "protocol");
9984 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9985         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9986                                 protocol_value, UINT8);
9987 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9988         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9989                                 mask, "mask");
9990 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9991         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9992                                 mask_value, INT8);
9993 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9994         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9995                                 tcp_flags, "tcp_flags");
9996 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9997         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9998                                 tcp_flags_value, UINT8);
9999 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10000         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10001                                 priority, "priority");
10002 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10003         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10004                                 priority_value, UINT8);
10005 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10006         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10007                                 queue, "queue");
10008 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10009         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10010                                 queue_id, UINT16);
10011
10012 cmdline_parse_inst_t cmd_5tuple_filter = {
10013         .f = cmd_5tuple_filter_parsed,
10014         .data = NULL,
10015         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10016                 "src_ip <value> dst_port <value> src_port <value> "
10017                 "protocol <value>  mask <value> tcp_flags <value> "
10018                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10019         .tokens = {
10020                 (void *)&cmd_5tuple_filter_filter,
10021                 (void *)&cmd_5tuple_filter_port_id,
10022                 (void *)&cmd_5tuple_filter_ops,
10023                 (void *)&cmd_5tuple_filter_dst_ip,
10024                 (void *)&cmd_5tuple_filter_dst_ip_value,
10025                 (void *)&cmd_5tuple_filter_src_ip,
10026                 (void *)&cmd_5tuple_filter_src_ip_value,
10027                 (void *)&cmd_5tuple_filter_dst_port,
10028                 (void *)&cmd_5tuple_filter_dst_port_value,
10029                 (void *)&cmd_5tuple_filter_src_port,
10030                 (void *)&cmd_5tuple_filter_src_port_value,
10031                 (void *)&cmd_5tuple_filter_protocol,
10032                 (void *)&cmd_5tuple_filter_protocol_value,
10033                 (void *)&cmd_5tuple_filter_mask,
10034                 (void *)&cmd_5tuple_filter_mask_value,
10035                 (void *)&cmd_5tuple_filter_tcp_flags,
10036                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10037                 (void *)&cmd_5tuple_filter_priority,
10038                 (void *)&cmd_5tuple_filter_priority_value,
10039                 (void *)&cmd_5tuple_filter_queue,
10040                 (void *)&cmd_5tuple_filter_queue_id,
10041                 NULL,
10042         },
10043 };
10044
10045 /* *** ADD/REMOVE A flex FILTER *** */
10046 struct cmd_flex_filter_result {
10047         cmdline_fixed_string_t filter;
10048         cmdline_fixed_string_t ops;
10049         portid_t port_id;
10050         cmdline_fixed_string_t len;
10051         uint8_t len_value;
10052         cmdline_fixed_string_t bytes;
10053         cmdline_fixed_string_t bytes_value;
10054         cmdline_fixed_string_t mask;
10055         cmdline_fixed_string_t mask_value;
10056         cmdline_fixed_string_t priority;
10057         uint8_t priority_value;
10058         cmdline_fixed_string_t queue;
10059         uint16_t queue_id;
10060 };
10061
10062 static int xdigit2val(unsigned char c)
10063 {
10064         int val;
10065         if (isdigit(c))
10066                 val = c - '0';
10067         else if (isupper(c))
10068                 val = c - 'A' + 10;
10069         else
10070                 val = c - 'a' + 10;
10071         return val;
10072 }
10073
10074 static void
10075 cmd_flex_filter_parsed(void *parsed_result,
10076                           __attribute__((unused)) struct cmdline *cl,
10077                           __attribute__((unused)) void *data)
10078 {
10079         int ret = 0;
10080         struct rte_eth_flex_filter filter;
10081         struct cmd_flex_filter_result *res = parsed_result;
10082         char *bytes_ptr, *mask_ptr;
10083         uint16_t len, i, j = 0;
10084         char c;
10085         int val;
10086         uint8_t byte = 0;
10087
10088         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10089                 printf("the len exceed the max length 128\n");
10090                 return;
10091         }
10092         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10093         filter.len = res->len_value;
10094         filter.priority = res->priority_value;
10095         filter.queue = res->queue_id;
10096         bytes_ptr = res->bytes_value;
10097         mask_ptr = res->mask_value;
10098
10099          /* translate bytes string to array. */
10100         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10101                 (bytes_ptr[1] == 'X')))
10102                 bytes_ptr += 2;
10103         len = strnlen(bytes_ptr, res->len_value * 2);
10104         if (len == 0 || (len % 8 != 0)) {
10105                 printf("please check len and bytes input\n");
10106                 return;
10107         }
10108         for (i = 0; i < len; i++) {
10109                 c = bytes_ptr[i];
10110                 if (isxdigit(c) == 0) {
10111                         /* invalid characters. */
10112                         printf("invalid input\n");
10113                         return;
10114                 }
10115                 val = xdigit2val(c);
10116                 if (i % 2) {
10117                         byte |= val;
10118                         filter.bytes[j] = byte;
10119                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10120                         j++;
10121                         byte = 0;
10122                 } else
10123                         byte |= val << 4;
10124         }
10125         printf("\n");
10126          /* translate mask string to uint8_t array. */
10127         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10128                 (mask_ptr[1] == 'X')))
10129                 mask_ptr += 2;
10130         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10131         if (len == 0) {
10132                 printf("invalid input\n");
10133                 return;
10134         }
10135         j = 0;
10136         byte = 0;
10137         for (i = 0; i < len; i++) {
10138                 c = mask_ptr[i];
10139                 if (isxdigit(c) == 0) {
10140                         /* invalid characters. */
10141                         printf("invalid input\n");
10142                         return;
10143                 }
10144                 val = xdigit2val(c);
10145                 if (i % 2) {
10146                         byte |= val;
10147                         filter.mask[j] = byte;
10148                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10149                         j++;
10150                         byte = 0;
10151                 } else
10152                         byte |= val << 4;
10153         }
10154         printf("\n");
10155
10156         if (!strcmp(res->ops, "add"))
10157                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10158                                 RTE_ETH_FILTER_FLEXIBLE,
10159                                 RTE_ETH_FILTER_ADD,
10160                                 &filter);
10161         else
10162                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10163                                 RTE_ETH_FILTER_FLEXIBLE,
10164                                 RTE_ETH_FILTER_DELETE,
10165                                 &filter);
10166
10167         if (ret < 0)
10168                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10169 }
10170
10171 cmdline_parse_token_string_t cmd_flex_filter_filter =
10172         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10173                                 filter, "flex_filter");
10174 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10175         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10176                                 port_id, UINT16);
10177 cmdline_parse_token_string_t cmd_flex_filter_ops =
10178         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10179                                 ops, "add#del");
10180 cmdline_parse_token_string_t cmd_flex_filter_len =
10181         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10182                                 len, "len");
10183 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10184         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10185                                 len_value, UINT8);
10186 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10187         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10188                                 bytes, "bytes");
10189 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10190         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10191                                 bytes_value, NULL);
10192 cmdline_parse_token_string_t cmd_flex_filter_mask =
10193         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10194                                 mask, "mask");
10195 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10196         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10197                                 mask_value, NULL);
10198 cmdline_parse_token_string_t cmd_flex_filter_priority =
10199         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10200                                 priority, "priority");
10201 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10202         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10203                                 priority_value, UINT8);
10204 cmdline_parse_token_string_t cmd_flex_filter_queue =
10205         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10206                                 queue, "queue");
10207 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10208         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10209                                 queue_id, UINT16);
10210 cmdline_parse_inst_t cmd_flex_filter = {
10211         .f = cmd_flex_filter_parsed,
10212         .data = NULL,
10213         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10214                 "<value> mask <value> priority <value> queue <queue_id>: "
10215                 "Add/Del a flex filter",
10216         .tokens = {
10217                 (void *)&cmd_flex_filter_filter,
10218                 (void *)&cmd_flex_filter_port_id,
10219                 (void *)&cmd_flex_filter_ops,
10220                 (void *)&cmd_flex_filter_len,
10221                 (void *)&cmd_flex_filter_len_value,
10222                 (void *)&cmd_flex_filter_bytes,
10223                 (void *)&cmd_flex_filter_bytes_value,
10224                 (void *)&cmd_flex_filter_mask,
10225                 (void *)&cmd_flex_filter_mask_value,
10226                 (void *)&cmd_flex_filter_priority,
10227                 (void *)&cmd_flex_filter_priority_value,
10228                 (void *)&cmd_flex_filter_queue,
10229                 (void *)&cmd_flex_filter_queue_id,
10230                 NULL,
10231         },
10232 };
10233
10234 /* *** Filters Control *** */
10235
10236 /* *** deal with ethertype filter *** */
10237 struct cmd_ethertype_filter_result {
10238         cmdline_fixed_string_t filter;
10239         portid_t port_id;
10240         cmdline_fixed_string_t ops;
10241         cmdline_fixed_string_t mac;
10242         struct ether_addr mac_addr;
10243         cmdline_fixed_string_t ethertype;
10244         uint16_t ethertype_value;
10245         cmdline_fixed_string_t drop;
10246         cmdline_fixed_string_t queue;
10247         uint16_t  queue_id;
10248 };
10249
10250 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10251         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10252                                  filter, "ethertype_filter");
10253 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10254         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10255                               port_id, UINT16);
10256 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10257         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10258                                  ops, "add#del");
10259 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10260         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10261                                  mac, "mac_addr#mac_ignr");
10262 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10263         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10264                                      mac_addr);
10265 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10266         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10267                                  ethertype, "ethertype");
10268 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10269         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10270                               ethertype_value, UINT16);
10271 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10272         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10273                                  drop, "drop#fwd");
10274 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10275         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10276                                  queue, "queue");
10277 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10278         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10279                               queue_id, UINT16);
10280
10281 static void
10282 cmd_ethertype_filter_parsed(void *parsed_result,
10283                           __attribute__((unused)) struct cmdline *cl,
10284                           __attribute__((unused)) void *data)
10285 {
10286         struct cmd_ethertype_filter_result *res = parsed_result;
10287         struct rte_eth_ethertype_filter filter;
10288         int ret = 0;
10289
10290         ret = rte_eth_dev_filter_supported(res->port_id,
10291                         RTE_ETH_FILTER_ETHERTYPE);
10292         if (ret < 0) {
10293                 printf("ethertype filter is not supported on port %u.\n",
10294                         res->port_id);
10295                 return;
10296         }
10297
10298         memset(&filter, 0, sizeof(filter));
10299         if (!strcmp(res->mac, "mac_addr")) {
10300                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10301                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10302                         sizeof(struct ether_addr));
10303         }
10304         if (!strcmp(res->drop, "drop"))
10305                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10306         filter.ether_type = res->ethertype_value;
10307         filter.queue = res->queue_id;
10308
10309         if (!strcmp(res->ops, "add"))
10310                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10311                                 RTE_ETH_FILTER_ETHERTYPE,
10312                                 RTE_ETH_FILTER_ADD,
10313                                 &filter);
10314         else
10315                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10316                                 RTE_ETH_FILTER_ETHERTYPE,
10317                                 RTE_ETH_FILTER_DELETE,
10318                                 &filter);
10319         if (ret < 0)
10320                 printf("ethertype filter programming error: (%s)\n",
10321                         strerror(-ret));
10322 }
10323
10324 cmdline_parse_inst_t cmd_ethertype_filter = {
10325         .f = cmd_ethertype_filter_parsed,
10326         .data = NULL,
10327         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10328                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10329                 "Add or delete an ethertype filter entry",
10330         .tokens = {
10331                 (void *)&cmd_ethertype_filter_filter,
10332                 (void *)&cmd_ethertype_filter_port_id,
10333                 (void *)&cmd_ethertype_filter_ops,
10334                 (void *)&cmd_ethertype_filter_mac,
10335                 (void *)&cmd_ethertype_filter_mac_addr,
10336                 (void *)&cmd_ethertype_filter_ethertype,
10337                 (void *)&cmd_ethertype_filter_ethertype_value,
10338                 (void *)&cmd_ethertype_filter_drop,
10339                 (void *)&cmd_ethertype_filter_queue,
10340                 (void *)&cmd_ethertype_filter_queue_id,
10341                 NULL,
10342         },
10343 };
10344
10345 /* *** deal with flow director filter *** */
10346 struct cmd_flow_director_result {
10347         cmdline_fixed_string_t flow_director_filter;
10348         portid_t port_id;
10349         cmdline_fixed_string_t mode;
10350         cmdline_fixed_string_t mode_value;
10351         cmdline_fixed_string_t ops;
10352         cmdline_fixed_string_t flow;
10353         cmdline_fixed_string_t flow_type;
10354         cmdline_fixed_string_t ether;
10355         uint16_t ether_type;
10356         cmdline_fixed_string_t src;
10357         cmdline_ipaddr_t ip_src;
10358         uint16_t port_src;
10359         cmdline_fixed_string_t dst;
10360         cmdline_ipaddr_t ip_dst;
10361         uint16_t port_dst;
10362         cmdline_fixed_string_t verify_tag;
10363         uint32_t verify_tag_value;
10364         cmdline_fixed_string_t tos;
10365         uint8_t tos_value;
10366         cmdline_fixed_string_t proto;
10367         uint8_t proto_value;
10368         cmdline_fixed_string_t ttl;
10369         uint8_t ttl_value;
10370         cmdline_fixed_string_t vlan;
10371         uint16_t vlan_value;
10372         cmdline_fixed_string_t flexbytes;
10373         cmdline_fixed_string_t flexbytes_value;
10374         cmdline_fixed_string_t pf_vf;
10375         cmdline_fixed_string_t drop;
10376         cmdline_fixed_string_t queue;
10377         uint16_t  queue_id;
10378         cmdline_fixed_string_t fd_id;
10379         uint32_t  fd_id_value;
10380         cmdline_fixed_string_t mac;
10381         struct ether_addr mac_addr;
10382         cmdline_fixed_string_t tunnel;
10383         cmdline_fixed_string_t tunnel_type;
10384         cmdline_fixed_string_t tunnel_id;
10385         uint32_t tunnel_id_value;
10386         cmdline_fixed_string_t packet;
10387         char filepath[];
10388 };
10389
10390 static inline int
10391 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10392 {
10393         char s[256];
10394         const char *p, *p0 = q_arg;
10395         char *end;
10396         unsigned long int_fld;
10397         char *str_fld[max_num];
10398         int i;
10399         unsigned size;
10400         int ret = -1;
10401
10402         p = strchr(p0, '(');
10403         if (p == NULL)
10404                 return -1;
10405         ++p;
10406         p0 = strchr(p, ')');
10407         if (p0 == NULL)
10408                 return -1;
10409
10410         size = p0 - p;
10411         if (size >= sizeof(s))
10412                 return -1;
10413
10414         snprintf(s, sizeof(s), "%.*s", size, p);
10415         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10416         if (ret < 0 || ret > max_num)
10417                 return -1;
10418         for (i = 0; i < ret; i++) {
10419                 errno = 0;
10420                 int_fld = strtoul(str_fld[i], &end, 0);
10421                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10422                         return -1;
10423                 flexbytes[i] = (uint8_t)int_fld;
10424         }
10425         return ret;
10426 }
10427
10428 static uint16_t
10429 str2flowtype(char *string)
10430 {
10431         uint8_t i = 0;
10432         static const struct {
10433                 char str[32];
10434                 uint16_t type;
10435         } flowtype_str[] = {
10436                 {"raw", RTE_ETH_FLOW_RAW},
10437                 {"ipv4", RTE_ETH_FLOW_IPV4},
10438                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10439                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10440                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10441                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10442                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10443                 {"ipv6", RTE_ETH_FLOW_IPV6},
10444                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10445                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10446                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10447                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10448                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10449                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10450         };
10451
10452         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10453                 if (!strcmp(flowtype_str[i].str, string))
10454                         return flowtype_str[i].type;
10455         }
10456
10457         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10458                 return (uint16_t)atoi(string);
10459
10460         return RTE_ETH_FLOW_UNKNOWN;
10461 }
10462
10463 static enum rte_eth_fdir_tunnel_type
10464 str2fdir_tunneltype(char *string)
10465 {
10466         uint8_t i = 0;
10467
10468         static const struct {
10469                 char str[32];
10470                 enum rte_eth_fdir_tunnel_type type;
10471         } tunneltype_str[] = {
10472                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10473                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10474         };
10475
10476         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10477                 if (!strcmp(tunneltype_str[i].str, string))
10478                         return tunneltype_str[i].type;
10479         }
10480         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10481 }
10482
10483 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10484 do { \
10485         if ((ip_addr).family == AF_INET) \
10486                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10487         else { \
10488                 printf("invalid parameter.\n"); \
10489                 return; \
10490         } \
10491 } while (0)
10492
10493 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10494 do { \
10495         if ((ip_addr).family == AF_INET6) \
10496                 rte_memcpy(&(ip), \
10497                                  &((ip_addr).addr.ipv6), \
10498                                  sizeof(struct in6_addr)); \
10499         else { \
10500                 printf("invalid parameter.\n"); \
10501                 return; \
10502         } \
10503 } while (0)
10504
10505 static void
10506 cmd_flow_director_filter_parsed(void *parsed_result,
10507                           __attribute__((unused)) struct cmdline *cl,
10508                           __attribute__((unused)) void *data)
10509 {
10510         struct cmd_flow_director_result *res = parsed_result;
10511         struct rte_eth_fdir_filter entry;
10512         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10513         char *end;
10514         unsigned long vf_id;
10515         int ret = 0;
10516
10517         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10518         if (ret < 0) {
10519                 printf("flow director is not supported on port %u.\n",
10520                         res->port_id);
10521                 return;
10522         }
10523         memset(flexbytes, 0, sizeof(flexbytes));
10524         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10525
10526         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10527                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10528                         printf("Please set mode to MAC-VLAN.\n");
10529                         return;
10530                 }
10531         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10532                 if (strcmp(res->mode_value, "Tunnel")) {
10533                         printf("Please set mode to Tunnel.\n");
10534                         return;
10535                 }
10536         } else {
10537                 if (!strcmp(res->mode_value, "raw")) {
10538 #ifdef RTE_LIBRTE_I40E_PMD
10539                         struct rte_pmd_i40e_flow_type_mapping
10540                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10541                         struct rte_pmd_i40e_pkt_template_conf conf;
10542                         uint16_t flow_type = str2flowtype(res->flow_type);
10543                         uint16_t i, port = res->port_id;
10544                         uint8_t add;
10545
10546                         memset(&conf, 0, sizeof(conf));
10547
10548                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10549                                 printf("Invalid flow type specified.\n");
10550                                 return;
10551                         }
10552                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10553                                                                  mapping);
10554                         if (ret)
10555                                 return;
10556                         if (mapping[flow_type].pctype == 0ULL) {
10557                                 printf("Invalid flow type specified.\n");
10558                                 return;
10559                         }
10560                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10561                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10562                                         conf.input.pctype = i;
10563                                         break;
10564                                 }
10565                         }
10566
10567                         conf.input.packet = open_file(res->filepath,
10568                                                 &conf.input.length);
10569                         if (!conf.input.packet)
10570                                 return;
10571                         if (!strcmp(res->drop, "drop"))
10572                                 conf.action.behavior =
10573                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10574                         else
10575                                 conf.action.behavior =
10576                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10577                         conf.action.report_status =
10578                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10579                         conf.action.rx_queue = res->queue_id;
10580                         conf.soft_id = res->fd_id_value;
10581                         add  = strcmp(res->ops, "del") ? 1 : 0;
10582                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10583                                                                         &conf,
10584                                                                         add);
10585                         if (ret < 0)
10586                                 printf("flow director config error: (%s)\n",
10587                                        strerror(-ret));
10588                         close_file(conf.input.packet);
10589 #endif
10590                         return;
10591                 } else if (strcmp(res->mode_value, "IP")) {
10592                         printf("Please set mode to IP or raw.\n");
10593                         return;
10594                 }
10595                 entry.input.flow_type = str2flowtype(res->flow_type);
10596         }
10597
10598         ret = parse_flexbytes(res->flexbytes_value,
10599                                         flexbytes,
10600                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10601         if (ret < 0) {
10602                 printf("error: Cannot parse flexbytes input.\n");
10603                 return;
10604         }
10605
10606         switch (entry.input.flow_type) {
10607         case RTE_ETH_FLOW_FRAG_IPV4:
10608         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10609                 entry.input.flow.ip4_flow.proto = res->proto_value;
10610                 /* fall-through */
10611         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10612         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10613                 IPV4_ADDR_TO_UINT(res->ip_dst,
10614                         entry.input.flow.ip4_flow.dst_ip);
10615                 IPV4_ADDR_TO_UINT(res->ip_src,
10616                         entry.input.flow.ip4_flow.src_ip);
10617                 entry.input.flow.ip4_flow.tos = res->tos_value;
10618                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10619                 /* need convert to big endian. */
10620                 entry.input.flow.udp4_flow.dst_port =
10621                                 rte_cpu_to_be_16(res->port_dst);
10622                 entry.input.flow.udp4_flow.src_port =
10623                                 rte_cpu_to_be_16(res->port_src);
10624                 break;
10625         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10626                 IPV4_ADDR_TO_UINT(res->ip_dst,
10627                         entry.input.flow.sctp4_flow.ip.dst_ip);
10628                 IPV4_ADDR_TO_UINT(res->ip_src,
10629                         entry.input.flow.sctp4_flow.ip.src_ip);
10630                 entry.input.flow.ip4_flow.tos = res->tos_value;
10631                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10632                 /* need convert to big endian. */
10633                 entry.input.flow.sctp4_flow.dst_port =
10634                                 rte_cpu_to_be_16(res->port_dst);
10635                 entry.input.flow.sctp4_flow.src_port =
10636                                 rte_cpu_to_be_16(res->port_src);
10637                 entry.input.flow.sctp4_flow.verify_tag =
10638                                 rte_cpu_to_be_32(res->verify_tag_value);
10639                 break;
10640         case RTE_ETH_FLOW_FRAG_IPV6:
10641         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10642                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10643                 /* fall-through */
10644         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10645         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10646                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10647                         entry.input.flow.ipv6_flow.dst_ip);
10648                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10649                         entry.input.flow.ipv6_flow.src_ip);
10650                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10651                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10652                 /* need convert to big endian. */
10653                 entry.input.flow.udp6_flow.dst_port =
10654                                 rte_cpu_to_be_16(res->port_dst);
10655                 entry.input.flow.udp6_flow.src_port =
10656                                 rte_cpu_to_be_16(res->port_src);
10657                 break;
10658         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10659                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10660                         entry.input.flow.sctp6_flow.ip.dst_ip);
10661                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10662                         entry.input.flow.sctp6_flow.ip.src_ip);
10663                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10664                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10665                 /* need convert to big endian. */
10666                 entry.input.flow.sctp6_flow.dst_port =
10667                                 rte_cpu_to_be_16(res->port_dst);
10668                 entry.input.flow.sctp6_flow.src_port =
10669                                 rte_cpu_to_be_16(res->port_src);
10670                 entry.input.flow.sctp6_flow.verify_tag =
10671                                 rte_cpu_to_be_32(res->verify_tag_value);
10672                 break;
10673         case RTE_ETH_FLOW_L2_PAYLOAD:
10674                 entry.input.flow.l2_flow.ether_type =
10675                         rte_cpu_to_be_16(res->ether_type);
10676                 break;
10677         default:
10678                 break;
10679         }
10680
10681         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10682                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10683                                  &res->mac_addr,
10684                                  sizeof(struct ether_addr));
10685
10686         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10687                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10688                                  &res->mac_addr,
10689                                  sizeof(struct ether_addr));
10690                 entry.input.flow.tunnel_flow.tunnel_type =
10691                         str2fdir_tunneltype(res->tunnel_type);
10692                 entry.input.flow.tunnel_flow.tunnel_id =
10693                         rte_cpu_to_be_32(res->tunnel_id_value);
10694         }
10695
10696         rte_memcpy(entry.input.flow_ext.flexbytes,
10697                    flexbytes,
10698                    RTE_ETH_FDIR_MAX_FLEXLEN);
10699
10700         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10701
10702         entry.action.flex_off = 0;  /*use 0 by default */
10703         if (!strcmp(res->drop, "drop"))
10704                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10705         else
10706                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10707
10708         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10709             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10710                 if (!strcmp(res->pf_vf, "pf"))
10711                         entry.input.flow_ext.is_vf = 0;
10712                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10713                         struct rte_eth_dev_info dev_info;
10714
10715                         memset(&dev_info, 0, sizeof(dev_info));
10716                         rte_eth_dev_info_get(res->port_id, &dev_info);
10717                         errno = 0;
10718                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10719                         if (errno != 0 || *end != '\0' ||
10720                             vf_id >= dev_info.max_vfs) {
10721                                 printf("invalid parameter %s.\n", res->pf_vf);
10722                                 return;
10723                         }
10724                         entry.input.flow_ext.is_vf = 1;
10725                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10726                 } else {
10727                         printf("invalid parameter %s.\n", res->pf_vf);
10728                         return;
10729                 }
10730         }
10731
10732         /* set to report FD ID by default */
10733         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10734         entry.action.rx_queue = res->queue_id;
10735         entry.soft_id = res->fd_id_value;
10736         if (!strcmp(res->ops, "add"))
10737                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10738                                              RTE_ETH_FILTER_ADD, &entry);
10739         else if (!strcmp(res->ops, "del"))
10740                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10741                                              RTE_ETH_FILTER_DELETE, &entry);
10742         else
10743                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10744                                              RTE_ETH_FILTER_UPDATE, &entry);
10745         if (ret < 0)
10746                 printf("flow director programming error: (%s)\n",
10747                         strerror(-ret));
10748 }
10749
10750 cmdline_parse_token_string_t cmd_flow_director_filter =
10751         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10752                                  flow_director_filter, "flow_director_filter");
10753 cmdline_parse_token_num_t cmd_flow_director_port_id =
10754         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10755                               port_id, UINT16);
10756 cmdline_parse_token_string_t cmd_flow_director_ops =
10757         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10758                                  ops, "add#del#update");
10759 cmdline_parse_token_string_t cmd_flow_director_flow =
10760         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10761                                  flow, "flow");
10762 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10763         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10764                 flow_type, NULL);
10765 cmdline_parse_token_string_t cmd_flow_director_ether =
10766         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10767                                  ether, "ether");
10768 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10769         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10770                               ether_type, UINT16);
10771 cmdline_parse_token_string_t cmd_flow_director_src =
10772         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10773                                  src, "src");
10774 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10775         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10776                                  ip_src);
10777 cmdline_parse_token_num_t cmd_flow_director_port_src =
10778         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10779                               port_src, UINT16);
10780 cmdline_parse_token_string_t cmd_flow_director_dst =
10781         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10782                                  dst, "dst");
10783 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10784         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10785                                  ip_dst);
10786 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10787         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10788                               port_dst, UINT16);
10789 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10790         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10791                                   verify_tag, "verify_tag");
10792 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10793         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10794                               verify_tag_value, UINT32);
10795 cmdline_parse_token_string_t cmd_flow_director_tos =
10796         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10797                                  tos, "tos");
10798 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10799         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10800                               tos_value, UINT8);
10801 cmdline_parse_token_string_t cmd_flow_director_proto =
10802         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10803                                  proto, "proto");
10804 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10805         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10806                               proto_value, UINT8);
10807 cmdline_parse_token_string_t cmd_flow_director_ttl =
10808         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10809                                  ttl, "ttl");
10810 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10811         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10812                               ttl_value, UINT8);
10813 cmdline_parse_token_string_t cmd_flow_director_vlan =
10814         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10815                                  vlan, "vlan");
10816 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10817         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10818                               vlan_value, UINT16);
10819 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10820         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10821                                  flexbytes, "flexbytes");
10822 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10823         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10824                               flexbytes_value, NULL);
10825 cmdline_parse_token_string_t cmd_flow_director_drop =
10826         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10827                                  drop, "drop#fwd");
10828 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10829         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10830                               pf_vf, NULL);
10831 cmdline_parse_token_string_t cmd_flow_director_queue =
10832         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10833                                  queue, "queue");
10834 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10835         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10836                               queue_id, UINT16);
10837 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10838         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10839                                  fd_id, "fd_id");
10840 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10841         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10842                               fd_id_value, UINT32);
10843
10844 cmdline_parse_token_string_t cmd_flow_director_mode =
10845         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10846                                  mode, "mode");
10847 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10848         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10849                                  mode_value, "IP");
10850 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10851         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10852                                  mode_value, "MAC-VLAN");
10853 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10854         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10855                                  mode_value, "Tunnel");
10856 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10857         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10858                                  mode_value, "raw");
10859 cmdline_parse_token_string_t cmd_flow_director_mac =
10860         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10861                                  mac, "mac");
10862 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10863         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10864                                     mac_addr);
10865 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10866         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10867                                  tunnel, "tunnel");
10868 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10869         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10870                                  tunnel_type, "NVGRE#VxLAN");
10871 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10872         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10873                                  tunnel_id, "tunnel-id");
10874 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10875         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10876                               tunnel_id_value, UINT32);
10877 cmdline_parse_token_string_t cmd_flow_director_packet =
10878         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10879                                  packet, "packet");
10880 cmdline_parse_token_string_t cmd_flow_director_filepath =
10881         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10882                                  filepath, NULL);
10883
10884 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10885         .f = cmd_flow_director_filter_parsed,
10886         .data = NULL,
10887         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10888                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10889                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10890                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10891                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10892                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10893                 "fd_id <fd_id_value>: "
10894                 "Add or delete an ip flow director entry on NIC",
10895         .tokens = {
10896                 (void *)&cmd_flow_director_filter,
10897                 (void *)&cmd_flow_director_port_id,
10898                 (void *)&cmd_flow_director_mode,
10899                 (void *)&cmd_flow_director_mode_ip,
10900                 (void *)&cmd_flow_director_ops,
10901                 (void *)&cmd_flow_director_flow,
10902                 (void *)&cmd_flow_director_flow_type,
10903                 (void *)&cmd_flow_director_src,
10904                 (void *)&cmd_flow_director_ip_src,
10905                 (void *)&cmd_flow_director_dst,
10906                 (void *)&cmd_flow_director_ip_dst,
10907                 (void *)&cmd_flow_director_tos,
10908                 (void *)&cmd_flow_director_tos_value,
10909                 (void *)&cmd_flow_director_proto,
10910                 (void *)&cmd_flow_director_proto_value,
10911                 (void *)&cmd_flow_director_ttl,
10912                 (void *)&cmd_flow_director_ttl_value,
10913                 (void *)&cmd_flow_director_vlan,
10914                 (void *)&cmd_flow_director_vlan_value,
10915                 (void *)&cmd_flow_director_flexbytes,
10916                 (void *)&cmd_flow_director_flexbytes_value,
10917                 (void *)&cmd_flow_director_drop,
10918                 (void *)&cmd_flow_director_pf_vf,
10919                 (void *)&cmd_flow_director_queue,
10920                 (void *)&cmd_flow_director_queue_id,
10921                 (void *)&cmd_flow_director_fd_id,
10922                 (void *)&cmd_flow_director_fd_id_value,
10923                 NULL,
10924         },
10925 };
10926
10927 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10928         .f = cmd_flow_director_filter_parsed,
10929         .data = NULL,
10930         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10931                 "director entry on NIC",
10932         .tokens = {
10933                 (void *)&cmd_flow_director_filter,
10934                 (void *)&cmd_flow_director_port_id,
10935                 (void *)&cmd_flow_director_mode,
10936                 (void *)&cmd_flow_director_mode_ip,
10937                 (void *)&cmd_flow_director_ops,
10938                 (void *)&cmd_flow_director_flow,
10939                 (void *)&cmd_flow_director_flow_type,
10940                 (void *)&cmd_flow_director_src,
10941                 (void *)&cmd_flow_director_ip_src,
10942                 (void *)&cmd_flow_director_port_src,
10943                 (void *)&cmd_flow_director_dst,
10944                 (void *)&cmd_flow_director_ip_dst,
10945                 (void *)&cmd_flow_director_port_dst,
10946                 (void *)&cmd_flow_director_tos,
10947                 (void *)&cmd_flow_director_tos_value,
10948                 (void *)&cmd_flow_director_ttl,
10949                 (void *)&cmd_flow_director_ttl_value,
10950                 (void *)&cmd_flow_director_vlan,
10951                 (void *)&cmd_flow_director_vlan_value,
10952                 (void *)&cmd_flow_director_flexbytes,
10953                 (void *)&cmd_flow_director_flexbytes_value,
10954                 (void *)&cmd_flow_director_drop,
10955                 (void *)&cmd_flow_director_pf_vf,
10956                 (void *)&cmd_flow_director_queue,
10957                 (void *)&cmd_flow_director_queue_id,
10958                 (void *)&cmd_flow_director_fd_id,
10959                 (void *)&cmd_flow_director_fd_id_value,
10960                 NULL,
10961         },
10962 };
10963
10964 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10965         .f = cmd_flow_director_filter_parsed,
10966         .data = NULL,
10967         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10968                 "director entry on NIC",
10969         .tokens = {
10970                 (void *)&cmd_flow_director_filter,
10971                 (void *)&cmd_flow_director_port_id,
10972                 (void *)&cmd_flow_director_mode,
10973                 (void *)&cmd_flow_director_mode_ip,
10974                 (void *)&cmd_flow_director_ops,
10975                 (void *)&cmd_flow_director_flow,
10976                 (void *)&cmd_flow_director_flow_type,
10977                 (void *)&cmd_flow_director_src,
10978                 (void *)&cmd_flow_director_ip_src,
10979                 (void *)&cmd_flow_director_port_src,
10980                 (void *)&cmd_flow_director_dst,
10981                 (void *)&cmd_flow_director_ip_dst,
10982                 (void *)&cmd_flow_director_port_dst,
10983                 (void *)&cmd_flow_director_verify_tag,
10984                 (void *)&cmd_flow_director_verify_tag_value,
10985                 (void *)&cmd_flow_director_tos,
10986                 (void *)&cmd_flow_director_tos_value,
10987                 (void *)&cmd_flow_director_ttl,
10988                 (void *)&cmd_flow_director_ttl_value,
10989                 (void *)&cmd_flow_director_vlan,
10990                 (void *)&cmd_flow_director_vlan_value,
10991                 (void *)&cmd_flow_director_flexbytes,
10992                 (void *)&cmd_flow_director_flexbytes_value,
10993                 (void *)&cmd_flow_director_drop,
10994                 (void *)&cmd_flow_director_pf_vf,
10995                 (void *)&cmd_flow_director_queue,
10996                 (void *)&cmd_flow_director_queue_id,
10997                 (void *)&cmd_flow_director_fd_id,
10998                 (void *)&cmd_flow_director_fd_id_value,
10999                 NULL,
11000         },
11001 };
11002
11003 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11004         .f = cmd_flow_director_filter_parsed,
11005         .data = NULL,
11006         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11007                 "director entry on NIC",
11008         .tokens = {
11009                 (void *)&cmd_flow_director_filter,
11010                 (void *)&cmd_flow_director_port_id,
11011                 (void *)&cmd_flow_director_mode,
11012                 (void *)&cmd_flow_director_mode_ip,
11013                 (void *)&cmd_flow_director_ops,
11014                 (void *)&cmd_flow_director_flow,
11015                 (void *)&cmd_flow_director_flow_type,
11016                 (void *)&cmd_flow_director_ether,
11017                 (void *)&cmd_flow_director_ether_type,
11018                 (void *)&cmd_flow_director_flexbytes,
11019                 (void *)&cmd_flow_director_flexbytes_value,
11020                 (void *)&cmd_flow_director_drop,
11021                 (void *)&cmd_flow_director_pf_vf,
11022                 (void *)&cmd_flow_director_queue,
11023                 (void *)&cmd_flow_director_queue_id,
11024                 (void *)&cmd_flow_director_fd_id,
11025                 (void *)&cmd_flow_director_fd_id_value,
11026                 NULL,
11027         },
11028 };
11029
11030 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11031         .f = cmd_flow_director_filter_parsed,
11032         .data = NULL,
11033         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11034                 "director entry on NIC",
11035         .tokens = {
11036                 (void *)&cmd_flow_director_filter,
11037                 (void *)&cmd_flow_director_port_id,
11038                 (void *)&cmd_flow_director_mode,
11039                 (void *)&cmd_flow_director_mode_mac_vlan,
11040                 (void *)&cmd_flow_director_ops,
11041                 (void *)&cmd_flow_director_mac,
11042                 (void *)&cmd_flow_director_mac_addr,
11043                 (void *)&cmd_flow_director_vlan,
11044                 (void *)&cmd_flow_director_vlan_value,
11045                 (void *)&cmd_flow_director_flexbytes,
11046                 (void *)&cmd_flow_director_flexbytes_value,
11047                 (void *)&cmd_flow_director_drop,
11048                 (void *)&cmd_flow_director_queue,
11049                 (void *)&cmd_flow_director_queue_id,
11050                 (void *)&cmd_flow_director_fd_id,
11051                 (void *)&cmd_flow_director_fd_id_value,
11052                 NULL,
11053         },
11054 };
11055
11056 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11057         .f = cmd_flow_director_filter_parsed,
11058         .data = NULL,
11059         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11060                 "director entry on NIC",
11061         .tokens = {
11062                 (void *)&cmd_flow_director_filter,
11063                 (void *)&cmd_flow_director_port_id,
11064                 (void *)&cmd_flow_director_mode,
11065                 (void *)&cmd_flow_director_mode_tunnel,
11066                 (void *)&cmd_flow_director_ops,
11067                 (void *)&cmd_flow_director_mac,
11068                 (void *)&cmd_flow_director_mac_addr,
11069                 (void *)&cmd_flow_director_vlan,
11070                 (void *)&cmd_flow_director_vlan_value,
11071                 (void *)&cmd_flow_director_tunnel,
11072                 (void *)&cmd_flow_director_tunnel_type,
11073                 (void *)&cmd_flow_director_tunnel_id,
11074                 (void *)&cmd_flow_director_tunnel_id_value,
11075                 (void *)&cmd_flow_director_flexbytes,
11076                 (void *)&cmd_flow_director_flexbytes_value,
11077                 (void *)&cmd_flow_director_drop,
11078                 (void *)&cmd_flow_director_queue,
11079                 (void *)&cmd_flow_director_queue_id,
11080                 (void *)&cmd_flow_director_fd_id,
11081                 (void *)&cmd_flow_director_fd_id_value,
11082                 NULL,
11083         },
11084 };
11085
11086 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11087         .f = cmd_flow_director_filter_parsed,
11088         .data = NULL,
11089         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11090                 "director entry on NIC",
11091         .tokens = {
11092                 (void *)&cmd_flow_director_filter,
11093                 (void *)&cmd_flow_director_port_id,
11094                 (void *)&cmd_flow_director_mode,
11095                 (void *)&cmd_flow_director_mode_raw,
11096                 (void *)&cmd_flow_director_ops,
11097                 (void *)&cmd_flow_director_flow,
11098                 (void *)&cmd_flow_director_flow_type,
11099                 (void *)&cmd_flow_director_drop,
11100                 (void *)&cmd_flow_director_queue,
11101                 (void *)&cmd_flow_director_queue_id,
11102                 (void *)&cmd_flow_director_fd_id,
11103                 (void *)&cmd_flow_director_fd_id_value,
11104                 (void *)&cmd_flow_director_packet,
11105                 (void *)&cmd_flow_director_filepath,
11106                 NULL,
11107         },
11108 };
11109
11110 struct cmd_flush_flow_director_result {
11111         cmdline_fixed_string_t flush_flow_director;
11112         portid_t port_id;
11113 };
11114
11115 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11116         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11117                                  flush_flow_director, "flush_flow_director");
11118 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11119         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11120                               port_id, UINT16);
11121
11122 static void
11123 cmd_flush_flow_director_parsed(void *parsed_result,
11124                           __attribute__((unused)) struct cmdline *cl,
11125                           __attribute__((unused)) void *data)
11126 {
11127         struct cmd_flow_director_result *res = parsed_result;
11128         int ret = 0;
11129
11130         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11131         if (ret < 0) {
11132                 printf("flow director is not supported on port %u.\n",
11133                         res->port_id);
11134                 return;
11135         }
11136
11137         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11138                         RTE_ETH_FILTER_FLUSH, NULL);
11139         if (ret < 0)
11140                 printf("flow director table flushing error: (%s)\n",
11141                         strerror(-ret));
11142 }
11143
11144 cmdline_parse_inst_t cmd_flush_flow_director = {
11145         .f = cmd_flush_flow_director_parsed,
11146         .data = NULL,
11147         .help_str = "flush_flow_director <port_id>: "
11148                 "Flush all flow director entries of a device on NIC",
11149         .tokens = {
11150                 (void *)&cmd_flush_flow_director_flush,
11151                 (void *)&cmd_flush_flow_director_port_id,
11152                 NULL,
11153         },
11154 };
11155
11156 /* *** deal with flow director mask *** */
11157 struct cmd_flow_director_mask_result {
11158         cmdline_fixed_string_t flow_director_mask;
11159         portid_t port_id;
11160         cmdline_fixed_string_t mode;
11161         cmdline_fixed_string_t mode_value;
11162         cmdline_fixed_string_t vlan;
11163         uint16_t vlan_mask;
11164         cmdline_fixed_string_t src_mask;
11165         cmdline_ipaddr_t ipv4_src;
11166         cmdline_ipaddr_t ipv6_src;
11167         uint16_t port_src;
11168         cmdline_fixed_string_t dst_mask;
11169         cmdline_ipaddr_t ipv4_dst;
11170         cmdline_ipaddr_t ipv6_dst;
11171         uint16_t port_dst;
11172         cmdline_fixed_string_t mac;
11173         uint8_t mac_addr_byte_mask;
11174         cmdline_fixed_string_t tunnel_id;
11175         uint32_t tunnel_id_mask;
11176         cmdline_fixed_string_t tunnel_type;
11177         uint8_t tunnel_type_mask;
11178 };
11179
11180 static void
11181 cmd_flow_director_mask_parsed(void *parsed_result,
11182                           __attribute__((unused)) struct cmdline *cl,
11183                           __attribute__((unused)) void *data)
11184 {
11185         struct cmd_flow_director_mask_result *res = parsed_result;
11186         struct rte_eth_fdir_masks *mask;
11187         struct rte_port *port;
11188
11189         port = &ports[res->port_id];
11190         /** Check if the port is not started **/
11191         if (port->port_status != RTE_PORT_STOPPED) {
11192                 printf("Please stop port %d first\n", res->port_id);
11193                 return;
11194         }
11195
11196         mask = &port->dev_conf.fdir_conf.mask;
11197
11198         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11199                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11200                         printf("Please set mode to MAC-VLAN.\n");
11201                         return;
11202                 }
11203
11204                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11205         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11206                 if (strcmp(res->mode_value, "Tunnel")) {
11207                         printf("Please set mode to Tunnel.\n");
11208                         return;
11209                 }
11210
11211                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11212                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11213                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11214                 mask->tunnel_type_mask = res->tunnel_type_mask;
11215         } else {
11216                 if (strcmp(res->mode_value, "IP")) {
11217                         printf("Please set mode to IP.\n");
11218                         return;
11219                 }
11220
11221                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11222                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11223                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11224                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11225                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11226                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11227                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11228         }
11229
11230         cmd_reconfig_device_queue(res->port_id, 1, 1);
11231 }
11232
11233 cmdline_parse_token_string_t cmd_flow_director_mask =
11234         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11235                                  flow_director_mask, "flow_director_mask");
11236 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11237         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11238                               port_id, UINT16);
11239 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11240         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11241                                  vlan, "vlan");
11242 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11243         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11244                               vlan_mask, UINT16);
11245 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11246         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11247                                  src_mask, "src_mask");
11248 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11249         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11250                                  ipv4_src);
11251 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11252         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11253                                  ipv6_src);
11254 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11255         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11256                               port_src, UINT16);
11257 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11258         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11259                                  dst_mask, "dst_mask");
11260 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11261         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11262                                  ipv4_dst);
11263 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11264         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11265                                  ipv6_dst);
11266 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11267         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11268                               port_dst, UINT16);
11269
11270 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11272                                  mode, "mode");
11273 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11274         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11275                                  mode_value, "IP");
11276 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11277         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11278                                  mode_value, "MAC-VLAN");
11279 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11280         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11281                                  mode_value, "Tunnel");
11282 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11283         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11284                                  mac, "mac");
11285 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11286         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11287                               mac_addr_byte_mask, UINT8);
11288 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11289         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11290                                  tunnel_type, "tunnel-type");
11291 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11292         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11293                               tunnel_type_mask, UINT8);
11294 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11295         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11296                                  tunnel_id, "tunnel-id");
11297 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11298         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11299                               tunnel_id_mask, UINT32);
11300
11301 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11302         .f = cmd_flow_director_mask_parsed,
11303         .data = NULL,
11304         .help_str = "flow_director_mask ... : "
11305                 "Set IP mode flow director's mask on NIC",
11306         .tokens = {
11307                 (void *)&cmd_flow_director_mask,
11308                 (void *)&cmd_flow_director_mask_port_id,
11309                 (void *)&cmd_flow_director_mask_mode,
11310                 (void *)&cmd_flow_director_mask_mode_ip,
11311                 (void *)&cmd_flow_director_mask_vlan,
11312                 (void *)&cmd_flow_director_mask_vlan_value,
11313                 (void *)&cmd_flow_director_mask_src,
11314                 (void *)&cmd_flow_director_mask_ipv4_src,
11315                 (void *)&cmd_flow_director_mask_ipv6_src,
11316                 (void *)&cmd_flow_director_mask_port_src,
11317                 (void *)&cmd_flow_director_mask_dst,
11318                 (void *)&cmd_flow_director_mask_ipv4_dst,
11319                 (void *)&cmd_flow_director_mask_ipv6_dst,
11320                 (void *)&cmd_flow_director_mask_port_dst,
11321                 NULL,
11322         },
11323 };
11324
11325 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11326         .f = cmd_flow_director_mask_parsed,
11327         .data = NULL,
11328         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11329                 "flow director's mask on NIC",
11330         .tokens = {
11331                 (void *)&cmd_flow_director_mask,
11332                 (void *)&cmd_flow_director_mask_port_id,
11333                 (void *)&cmd_flow_director_mask_mode,
11334                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11335                 (void *)&cmd_flow_director_mask_vlan,
11336                 (void *)&cmd_flow_director_mask_vlan_value,
11337                 NULL,
11338         },
11339 };
11340
11341 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11342         .f = cmd_flow_director_mask_parsed,
11343         .data = NULL,
11344         .help_str = "flow_director_mask ... : Set tunnel mode "
11345                 "flow director's mask on NIC",
11346         .tokens = {
11347                 (void *)&cmd_flow_director_mask,
11348                 (void *)&cmd_flow_director_mask_port_id,
11349                 (void *)&cmd_flow_director_mask_mode,
11350                 (void *)&cmd_flow_director_mask_mode_tunnel,
11351                 (void *)&cmd_flow_director_mask_vlan,
11352                 (void *)&cmd_flow_director_mask_vlan_value,
11353                 (void *)&cmd_flow_director_mask_mac,
11354                 (void *)&cmd_flow_director_mask_mac_value,
11355                 (void *)&cmd_flow_director_mask_tunnel_type,
11356                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11357                 (void *)&cmd_flow_director_mask_tunnel_id,
11358                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11359                 NULL,
11360         },
11361 };
11362
11363 /* *** deal with flow director mask on flexible payload *** */
11364 struct cmd_flow_director_flex_mask_result {
11365         cmdline_fixed_string_t flow_director_flexmask;
11366         portid_t port_id;
11367         cmdline_fixed_string_t flow;
11368         cmdline_fixed_string_t flow_type;
11369         cmdline_fixed_string_t mask;
11370 };
11371
11372 static void
11373 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11374                           __attribute__((unused)) struct cmdline *cl,
11375                           __attribute__((unused)) void *data)
11376 {
11377         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11378         struct rte_eth_fdir_info fdir_info;
11379         struct rte_eth_fdir_flex_mask flex_mask;
11380         struct rte_port *port;
11381         uint64_t flow_type_mask;
11382         uint16_t i;
11383         int ret;
11384
11385         port = &ports[res->port_id];
11386         /** Check if the port is not started **/
11387         if (port->port_status != RTE_PORT_STOPPED) {
11388                 printf("Please stop port %d first\n", res->port_id);
11389                 return;
11390         }
11391
11392         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11393         ret = parse_flexbytes(res->mask,
11394                         flex_mask.mask,
11395                         RTE_ETH_FDIR_MAX_FLEXLEN);
11396         if (ret < 0) {
11397                 printf("error: Cannot parse mask input.\n");
11398                 return;
11399         }
11400
11401         memset(&fdir_info, 0, sizeof(fdir_info));
11402         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11403                                 RTE_ETH_FILTER_INFO, &fdir_info);
11404         if (ret < 0) {
11405                 printf("Cannot get FDir filter info\n");
11406                 return;
11407         }
11408
11409         if (!strcmp(res->flow_type, "none")) {
11410                 /* means don't specify the flow type */
11411                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11412                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11413                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11414                                0, sizeof(struct rte_eth_fdir_flex_mask));
11415                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11416                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11417                                  &flex_mask,
11418                                  sizeof(struct rte_eth_fdir_flex_mask));
11419                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11420                 return;
11421         }
11422         flow_type_mask = fdir_info.flow_types_mask[0];
11423         if (!strcmp(res->flow_type, "all")) {
11424                 if (!flow_type_mask) {
11425                         printf("No flow type supported\n");
11426                         return;
11427                 }
11428                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11429                         if (flow_type_mask & (1ULL << i)) {
11430                                 flex_mask.flow_type = i;
11431                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11432                         }
11433                 }
11434                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11435                 return;
11436         }
11437         flex_mask.flow_type = str2flowtype(res->flow_type);
11438         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11439                 printf("Flow type %s not supported on port %d\n",
11440                                 res->flow_type, res->port_id);
11441                 return;
11442         }
11443         fdir_set_flex_mask(res->port_id, &flex_mask);
11444         cmd_reconfig_device_queue(res->port_id, 1, 1);
11445 }
11446
11447 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11448         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11449                                  flow_director_flexmask,
11450                                  "flow_director_flex_mask");
11451 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11452         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11453                               port_id, UINT16);
11454 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11455         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11456                                  flow, "flow");
11457 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11458         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11459                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11460                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11461 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11462         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11463                                  mask, NULL);
11464
11465 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11466         .f = cmd_flow_director_flex_mask_parsed,
11467         .data = NULL,
11468         .help_str = "flow_director_flex_mask ... : "
11469                 "Set flow director's flex mask on NIC",
11470         .tokens = {
11471                 (void *)&cmd_flow_director_flexmask,
11472                 (void *)&cmd_flow_director_flexmask_port_id,
11473                 (void *)&cmd_flow_director_flexmask_flow,
11474                 (void *)&cmd_flow_director_flexmask_flow_type,
11475                 (void *)&cmd_flow_director_flexmask_mask,
11476                 NULL,
11477         },
11478 };
11479
11480 /* *** deal with flow director flexible payload configuration *** */
11481 struct cmd_flow_director_flexpayload_result {
11482         cmdline_fixed_string_t flow_director_flexpayload;
11483         portid_t port_id;
11484         cmdline_fixed_string_t payload_layer;
11485         cmdline_fixed_string_t payload_cfg;
11486 };
11487
11488 static inline int
11489 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11490 {
11491         char s[256];
11492         const char *p, *p0 = q_arg;
11493         char *end;
11494         unsigned long int_fld;
11495         char *str_fld[max_num];
11496         int i;
11497         unsigned size;
11498         int ret = -1;
11499
11500         p = strchr(p0, '(');
11501         if (p == NULL)
11502                 return -1;
11503         ++p;
11504         p0 = strchr(p, ')');
11505         if (p0 == NULL)
11506                 return -1;
11507
11508         size = p0 - p;
11509         if (size >= sizeof(s))
11510                 return -1;
11511
11512         snprintf(s, sizeof(s), "%.*s", size, p);
11513         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11514         if (ret < 0 || ret > max_num)
11515                 return -1;
11516         for (i = 0; i < ret; i++) {
11517                 errno = 0;
11518                 int_fld = strtoul(str_fld[i], &end, 0);
11519                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11520                         return -1;
11521                 offsets[i] = (uint16_t)int_fld;
11522         }
11523         return ret;
11524 }
11525
11526 static void
11527 cmd_flow_director_flxpld_parsed(void *parsed_result,
11528                           __attribute__((unused)) struct cmdline *cl,
11529                           __attribute__((unused)) void *data)
11530 {
11531         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11532         struct rte_eth_flex_payload_cfg flex_cfg;
11533         struct rte_port *port;
11534         int ret = 0;
11535
11536         port = &ports[res->port_id];
11537         /** Check if the port is not started **/
11538         if (port->port_status != RTE_PORT_STOPPED) {
11539                 printf("Please stop port %d first\n", res->port_id);
11540                 return;
11541         }
11542
11543         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11544
11545         if (!strcmp(res->payload_layer, "raw"))
11546                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11547         else if (!strcmp(res->payload_layer, "l2"))
11548                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11549         else if (!strcmp(res->payload_layer, "l3"))
11550                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11551         else if (!strcmp(res->payload_layer, "l4"))
11552                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11553
11554         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11555                             RTE_ETH_FDIR_MAX_FLEXLEN);
11556         if (ret < 0) {
11557                 printf("error: Cannot parse flex payload input.\n");
11558                 return;
11559         }
11560
11561         fdir_set_flex_payload(res->port_id, &flex_cfg);
11562         cmd_reconfig_device_queue(res->port_id, 1, 1);
11563 }
11564
11565 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11566         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11567                                  flow_director_flexpayload,
11568                                  "flow_director_flex_payload");
11569 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11570         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11571                               port_id, UINT16);
11572 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11573         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11574                                  payload_layer, "raw#l2#l3#l4");
11575 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11576         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11577                                  payload_cfg, NULL);
11578
11579 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11580         .f = cmd_flow_director_flxpld_parsed,
11581         .data = NULL,
11582         .help_str = "flow_director_flexpayload ... : "
11583                 "Set flow director's flex payload on NIC",
11584         .tokens = {
11585                 (void *)&cmd_flow_director_flexpayload,
11586                 (void *)&cmd_flow_director_flexpayload_port_id,
11587                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11588                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11589                 NULL,
11590         },
11591 };
11592
11593 /* Generic flow interface command. */
11594 extern cmdline_parse_inst_t cmd_flow;
11595
11596 /* *** Classification Filters Control *** */
11597 /* *** Get symmetric hash enable per port *** */
11598 struct cmd_get_sym_hash_ena_per_port_result {
11599         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11600         portid_t port_id;
11601 };
11602
11603 static void
11604 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11605                                  __rte_unused struct cmdline *cl,
11606                                  __rte_unused void *data)
11607 {
11608         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11609         struct rte_eth_hash_filter_info info;
11610         int ret;
11611
11612         if (rte_eth_dev_filter_supported(res->port_id,
11613                                 RTE_ETH_FILTER_HASH) < 0) {
11614                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11615                                                         res->port_id);
11616                 return;
11617         }
11618
11619         memset(&info, 0, sizeof(info));
11620         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11621         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11622                                                 RTE_ETH_FILTER_GET, &info);
11623
11624         if (ret < 0) {
11625                 printf("Cannot get symmetric hash enable per port "
11626                                         "on port %u\n", res->port_id);
11627                 return;
11628         }
11629
11630         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11631                                 "enabled" : "disabled", res->port_id);
11632 }
11633
11634 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11635         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11636                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11637 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11638         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11639                 port_id, UINT16);
11640
11641 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11642         .f = cmd_get_sym_hash_per_port_parsed,
11643         .data = NULL,
11644         .help_str = "get_sym_hash_ena_per_port <port_id>",
11645         .tokens = {
11646                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11647                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11648                 NULL,
11649         },
11650 };
11651
11652 /* *** Set symmetric hash enable per port *** */
11653 struct cmd_set_sym_hash_ena_per_port_result {
11654         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11655         cmdline_fixed_string_t enable;
11656         portid_t port_id;
11657 };
11658
11659 static void
11660 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11661                                  __rte_unused struct cmdline *cl,
11662                                  __rte_unused void *data)
11663 {
11664         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11665         struct rte_eth_hash_filter_info info;
11666         int ret;
11667
11668         if (rte_eth_dev_filter_supported(res->port_id,
11669                                 RTE_ETH_FILTER_HASH) < 0) {
11670                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11671                                                         res->port_id);
11672                 return;
11673         }
11674
11675         memset(&info, 0, sizeof(info));
11676         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11677         if (!strcmp(res->enable, "enable"))
11678                 info.info.enable = 1;
11679         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11680                                         RTE_ETH_FILTER_SET, &info);
11681         if (ret < 0) {
11682                 printf("Cannot set symmetric hash enable per port on "
11683                                         "port %u\n", res->port_id);
11684                 return;
11685         }
11686         printf("Symmetric hash has been set to %s on port %u\n",
11687                                         res->enable, res->port_id);
11688 }
11689
11690 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11691         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11692                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11693 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11694         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11695                 port_id, UINT16);
11696 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11697         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11698                 enable, "enable#disable");
11699
11700 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11701         .f = cmd_set_sym_hash_per_port_parsed,
11702         .data = NULL,
11703         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11704         .tokens = {
11705                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11706                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11707                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11708                 NULL,
11709         },
11710 };
11711
11712 /* Get global config of hash function */
11713 struct cmd_get_hash_global_config_result {
11714         cmdline_fixed_string_t get_hash_global_config;
11715         portid_t port_id;
11716 };
11717
11718 static char *
11719 flowtype_to_str(uint16_t ftype)
11720 {
11721         uint16_t i;
11722         static struct {
11723                 char str[16];
11724                 uint16_t ftype;
11725         } ftype_table[] = {
11726                 {"ipv4", RTE_ETH_FLOW_IPV4},
11727                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11728                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11729                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11730                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11731                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11732                 {"ipv6", RTE_ETH_FLOW_IPV6},
11733                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11734                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11735                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11736                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11737                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11738                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11739                 {"port", RTE_ETH_FLOW_PORT},
11740                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11741                 {"geneve", RTE_ETH_FLOW_GENEVE},
11742                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11743         };
11744
11745         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11746                 if (ftype_table[i].ftype == ftype)
11747                         return ftype_table[i].str;
11748         }
11749
11750         return NULL;
11751 }
11752
11753 static void
11754 cmd_get_hash_global_config_parsed(void *parsed_result,
11755                                   __rte_unused struct cmdline *cl,
11756                                   __rte_unused void *data)
11757 {
11758         struct cmd_get_hash_global_config_result *res = parsed_result;
11759         struct rte_eth_hash_filter_info info;
11760         uint32_t idx, offset;
11761         uint16_t i;
11762         char *str;
11763         int ret;
11764
11765         if (rte_eth_dev_filter_supported(res->port_id,
11766                         RTE_ETH_FILTER_HASH) < 0) {
11767                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11768                                                         res->port_id);
11769                 return;
11770         }
11771
11772         memset(&info, 0, sizeof(info));
11773         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11774         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11775                                         RTE_ETH_FILTER_GET, &info);
11776         if (ret < 0) {
11777                 printf("Cannot get hash global configurations by port %d\n",
11778                                                         res->port_id);
11779                 return;
11780         }
11781
11782         switch (info.info.global_conf.hash_func) {
11783         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11784                 printf("Hash function is Toeplitz\n");
11785                 break;
11786         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11787                 printf("Hash function is Simple XOR\n");
11788                 break;
11789         default:
11790                 printf("Unknown hash function\n");
11791                 break;
11792         }
11793
11794         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11795                 idx = i / UINT64_BIT;
11796                 offset = i % UINT64_BIT;
11797                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11798                                                 (1ULL << offset)))
11799                         continue;
11800                 str = flowtype_to_str(i);
11801                 if (!str)
11802                         continue;
11803                 printf("Symmetric hash is %s globally for flow type %s "
11804                                                         "by port %d\n",
11805                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11806                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11807                                                         res->port_id);
11808         }
11809 }
11810
11811 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11812         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11813                 get_hash_global_config, "get_hash_global_config");
11814 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11815         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11816                 port_id, UINT16);
11817
11818 cmdline_parse_inst_t cmd_get_hash_global_config = {
11819         .f = cmd_get_hash_global_config_parsed,
11820         .data = NULL,
11821         .help_str = "get_hash_global_config <port_id>",
11822         .tokens = {
11823                 (void *)&cmd_get_hash_global_config_all,
11824                 (void *)&cmd_get_hash_global_config_port_id,
11825                 NULL,
11826         },
11827 };
11828
11829 /* Set global config of hash function */
11830 struct cmd_set_hash_global_config_result {
11831         cmdline_fixed_string_t set_hash_global_config;
11832         portid_t port_id;
11833         cmdline_fixed_string_t hash_func;
11834         cmdline_fixed_string_t flow_type;
11835         cmdline_fixed_string_t enable;
11836 };
11837
11838 static void
11839 cmd_set_hash_global_config_parsed(void *parsed_result,
11840                                   __rte_unused struct cmdline *cl,
11841                                   __rte_unused void *data)
11842 {
11843         struct cmd_set_hash_global_config_result *res = parsed_result;
11844         struct rte_eth_hash_filter_info info;
11845         uint32_t ftype, idx, offset;
11846         int ret;
11847
11848         if (rte_eth_dev_filter_supported(res->port_id,
11849                                 RTE_ETH_FILTER_HASH) < 0) {
11850                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11851                                                         res->port_id);
11852                 return;
11853         }
11854         memset(&info, 0, sizeof(info));
11855         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11856         if (!strcmp(res->hash_func, "toeplitz"))
11857                 info.info.global_conf.hash_func =
11858                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11859         else if (!strcmp(res->hash_func, "simple_xor"))
11860                 info.info.global_conf.hash_func =
11861                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11862         else if (!strcmp(res->hash_func, "default"))
11863                 info.info.global_conf.hash_func =
11864                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11865
11866         ftype = str2flowtype(res->flow_type);
11867         idx = ftype / UINT64_BIT;
11868         offset = ftype % UINT64_BIT;
11869         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11870         if (!strcmp(res->enable, "enable"))
11871                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11872                                                 (1ULL << offset);
11873         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11874                                         RTE_ETH_FILTER_SET, &info);
11875         if (ret < 0)
11876                 printf("Cannot set global hash configurations by port %d\n",
11877                                                         res->port_id);
11878         else
11879                 printf("Global hash configurations have been set "
11880                         "succcessfully by port %d\n", res->port_id);
11881 }
11882
11883 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11884         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11885                 set_hash_global_config, "set_hash_global_config");
11886 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11887         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11888                 port_id, UINT16);
11889 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11890         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11891                 hash_func, "toeplitz#simple_xor#default");
11892 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11893         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11894                 flow_type,
11895                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11896                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11897 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11898         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11899                 enable, "enable#disable");
11900
11901 cmdline_parse_inst_t cmd_set_hash_global_config = {
11902         .f = cmd_set_hash_global_config_parsed,
11903         .data = NULL,
11904         .help_str = "set_hash_global_config <port_id> "
11905                 "toeplitz|simple_xor|default "
11906                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11907                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11908                 "l2_payload enable|disable",
11909         .tokens = {
11910                 (void *)&cmd_set_hash_global_config_all,
11911                 (void *)&cmd_set_hash_global_config_port_id,
11912                 (void *)&cmd_set_hash_global_config_hash_func,
11913                 (void *)&cmd_set_hash_global_config_flow_type,
11914                 (void *)&cmd_set_hash_global_config_enable,
11915                 NULL,
11916         },
11917 };
11918
11919 /* Set hash input set */
11920 struct cmd_set_hash_input_set_result {
11921         cmdline_fixed_string_t set_hash_input_set;
11922         portid_t port_id;
11923         cmdline_fixed_string_t flow_type;
11924         cmdline_fixed_string_t inset_field;
11925         cmdline_fixed_string_t select;
11926 };
11927
11928 static enum rte_eth_input_set_field
11929 str2inset(char *string)
11930 {
11931         uint16_t i;
11932
11933         static const struct {
11934                 char str[32];
11935                 enum rte_eth_input_set_field inset;
11936         } inset_table[] = {
11937                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11938                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11939                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11940                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11941                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11942                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11943                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11944                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11945                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11946                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11947                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11948                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11949                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11950                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11951                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11952                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11953                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11954                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11955                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11956                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11957                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11958                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11959                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11960                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11961                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11962                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11963                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11964                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11965                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11966                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11967                 {"none", RTE_ETH_INPUT_SET_NONE},
11968         };
11969
11970         for (i = 0; i < RTE_DIM(inset_table); i++) {
11971                 if (!strcmp(string, inset_table[i].str))
11972                         return inset_table[i].inset;
11973         }
11974
11975         return RTE_ETH_INPUT_SET_UNKNOWN;
11976 }
11977
11978 static void
11979 cmd_set_hash_input_set_parsed(void *parsed_result,
11980                               __rte_unused struct cmdline *cl,
11981                               __rte_unused void *data)
11982 {
11983         struct cmd_set_hash_input_set_result *res = parsed_result;
11984         struct rte_eth_hash_filter_info info;
11985
11986         memset(&info, 0, sizeof(info));
11987         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11988         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11989         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11990         info.info.input_set_conf.inset_size = 1;
11991         if (!strcmp(res->select, "select"))
11992                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11993         else if (!strcmp(res->select, "add"))
11994                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11995         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11996                                 RTE_ETH_FILTER_SET, &info);
11997 }
11998
11999 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12000         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12001                 set_hash_input_set, "set_hash_input_set");
12002 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12003         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12004                 port_id, UINT16);
12005 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12006         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12007                 flow_type, NULL);
12008 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12009         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12010                 inset_field,
12011                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12012                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12013                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12014                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12015                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12016                 "fld-8th#none");
12017 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12018         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12019                 select, "select#add");
12020
12021 cmdline_parse_inst_t cmd_set_hash_input_set = {
12022         .f = cmd_set_hash_input_set_parsed,
12023         .data = NULL,
12024         .help_str = "set_hash_input_set <port_id> "
12025         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12026         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12027         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12028         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12029         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12030         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12031         "fld-7th|fld-8th|none select|add",
12032         .tokens = {
12033                 (void *)&cmd_set_hash_input_set_cmd,
12034                 (void *)&cmd_set_hash_input_set_port_id,
12035                 (void *)&cmd_set_hash_input_set_flow_type,
12036                 (void *)&cmd_set_hash_input_set_field,
12037                 (void *)&cmd_set_hash_input_set_select,
12038                 NULL,
12039         },
12040 };
12041
12042 /* Set flow director input set */
12043 struct cmd_set_fdir_input_set_result {
12044         cmdline_fixed_string_t set_fdir_input_set;
12045         portid_t port_id;
12046         cmdline_fixed_string_t flow_type;
12047         cmdline_fixed_string_t inset_field;
12048         cmdline_fixed_string_t select;
12049 };
12050
12051 static void
12052 cmd_set_fdir_input_set_parsed(void *parsed_result,
12053         __rte_unused struct cmdline *cl,
12054         __rte_unused void *data)
12055 {
12056         struct cmd_set_fdir_input_set_result *res = parsed_result;
12057         struct rte_eth_fdir_filter_info info;
12058
12059         memset(&info, 0, sizeof(info));
12060         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12061         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12062         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12063         info.info.input_set_conf.inset_size = 1;
12064         if (!strcmp(res->select, "select"))
12065                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12066         else if (!strcmp(res->select, "add"))
12067                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12068         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12069                 RTE_ETH_FILTER_SET, &info);
12070 }
12071
12072 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12073         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12074         set_fdir_input_set, "set_fdir_input_set");
12075 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12076         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12077         port_id, UINT16);
12078 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12079         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12080         flow_type,
12081         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12082         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12083 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12084         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12085         inset_field,
12086         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12087         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12088         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12089         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12090         "sctp-veri-tag#none");
12091 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12092         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12093         select, "select#add");
12094
12095 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12096         .f = cmd_set_fdir_input_set_parsed,
12097         .data = NULL,
12098         .help_str = "set_fdir_input_set <port_id> "
12099         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12100         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12101         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12102         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12103         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12104         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12105         "sctp-veri-tag|none select|add",
12106         .tokens = {
12107                 (void *)&cmd_set_fdir_input_set_cmd,
12108                 (void *)&cmd_set_fdir_input_set_port_id,
12109                 (void *)&cmd_set_fdir_input_set_flow_type,
12110                 (void *)&cmd_set_fdir_input_set_field,
12111                 (void *)&cmd_set_fdir_input_set_select,
12112                 NULL,
12113         },
12114 };
12115
12116 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12117 struct cmd_mcast_addr_result {
12118         cmdline_fixed_string_t mcast_addr_cmd;
12119         cmdline_fixed_string_t what;
12120         uint16_t port_num;
12121         struct ether_addr mc_addr;
12122 };
12123
12124 static void cmd_mcast_addr_parsed(void *parsed_result,
12125                 __attribute__((unused)) struct cmdline *cl,
12126                 __attribute__((unused)) void *data)
12127 {
12128         struct cmd_mcast_addr_result *res = parsed_result;
12129
12130         if (!is_multicast_ether_addr(&res->mc_addr)) {
12131                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12132                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12133                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12134                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12135                 return;
12136         }
12137         if (strcmp(res->what, "add") == 0)
12138                 mcast_addr_add(res->port_num, &res->mc_addr);
12139         else
12140                 mcast_addr_remove(res->port_num, &res->mc_addr);
12141 }
12142
12143 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12144         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12145                                  mcast_addr_cmd, "mcast_addr");
12146 cmdline_parse_token_string_t cmd_mcast_addr_what =
12147         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12148                                  "add#remove");
12149 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12150         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12151 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12152         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12153
12154 cmdline_parse_inst_t cmd_mcast_addr = {
12155         .f = cmd_mcast_addr_parsed,
12156         .data = (void *)0,
12157         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12158                 "Add/Remove multicast MAC address on port_id",
12159         .tokens = {
12160                 (void *)&cmd_mcast_addr_cmd,
12161                 (void *)&cmd_mcast_addr_what,
12162                 (void *)&cmd_mcast_addr_portnum,
12163                 (void *)&cmd_mcast_addr_addr,
12164                 NULL,
12165         },
12166 };
12167
12168 /* l2 tunnel config
12169  * only support E-tag now.
12170  */
12171
12172 /* Ether type config */
12173 struct cmd_config_l2_tunnel_eth_type_result {
12174         cmdline_fixed_string_t port;
12175         cmdline_fixed_string_t config;
12176         cmdline_fixed_string_t all;
12177         portid_t id;
12178         cmdline_fixed_string_t l2_tunnel;
12179         cmdline_fixed_string_t l2_tunnel_type;
12180         cmdline_fixed_string_t eth_type;
12181         uint16_t eth_type_val;
12182 };
12183
12184 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12185         TOKEN_STRING_INITIALIZER
12186                 (struct cmd_config_l2_tunnel_eth_type_result,
12187                  port, "port");
12188 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12189         TOKEN_STRING_INITIALIZER
12190                 (struct cmd_config_l2_tunnel_eth_type_result,
12191                  config, "config");
12192 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12193         TOKEN_STRING_INITIALIZER
12194                 (struct cmd_config_l2_tunnel_eth_type_result,
12195                  all, "all");
12196 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12197         TOKEN_NUM_INITIALIZER
12198                 (struct cmd_config_l2_tunnel_eth_type_result,
12199                  id, UINT16);
12200 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12201         TOKEN_STRING_INITIALIZER
12202                 (struct cmd_config_l2_tunnel_eth_type_result,
12203                  l2_tunnel, "l2-tunnel");
12204 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12205         TOKEN_STRING_INITIALIZER
12206                 (struct cmd_config_l2_tunnel_eth_type_result,
12207                  l2_tunnel_type, "E-tag");
12208 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12209         TOKEN_STRING_INITIALIZER
12210                 (struct cmd_config_l2_tunnel_eth_type_result,
12211                  eth_type, "ether-type");
12212 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12213         TOKEN_NUM_INITIALIZER
12214                 (struct cmd_config_l2_tunnel_eth_type_result,
12215                  eth_type_val, UINT16);
12216
12217 static enum rte_eth_tunnel_type
12218 str2fdir_l2_tunnel_type(char *string)
12219 {
12220         uint32_t i = 0;
12221
12222         static const struct {
12223                 char str[32];
12224                 enum rte_eth_tunnel_type type;
12225         } l2_tunnel_type_str[] = {
12226                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12227         };
12228
12229         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12230                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12231                         return l2_tunnel_type_str[i].type;
12232         }
12233         return RTE_TUNNEL_TYPE_NONE;
12234 }
12235
12236 /* ether type config for all ports */
12237 static void
12238 cmd_config_l2_tunnel_eth_type_all_parsed
12239         (void *parsed_result,
12240          __attribute__((unused)) struct cmdline *cl,
12241          __attribute__((unused)) void *data)
12242 {
12243         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12244         struct rte_eth_l2_tunnel_conf entry;
12245         portid_t pid;
12246
12247         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12248         entry.ether_type = res->eth_type_val;
12249
12250         RTE_ETH_FOREACH_DEV(pid) {
12251                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12252         }
12253 }
12254
12255 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12256         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12257         .data = NULL,
12258         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12259         .tokens = {
12260                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12261                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12262                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12263                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12264                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12265                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12266                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12267                 NULL,
12268         },
12269 };
12270
12271 /* ether type config for a specific port */
12272 static void
12273 cmd_config_l2_tunnel_eth_type_specific_parsed(
12274         void *parsed_result,
12275         __attribute__((unused)) struct cmdline *cl,
12276         __attribute__((unused)) void *data)
12277 {
12278         struct cmd_config_l2_tunnel_eth_type_result *res =
12279                  parsed_result;
12280         struct rte_eth_l2_tunnel_conf entry;
12281
12282         if (port_id_is_invalid(res->id, ENABLED_WARN))
12283                 return;
12284
12285         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12286         entry.ether_type = res->eth_type_val;
12287
12288         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12289 }
12290
12291 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12292         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12293         .data = NULL,
12294         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12295         .tokens = {
12296                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12297                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12298                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12299                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12300                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12301                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12302                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12303                 NULL,
12304         },
12305 };
12306
12307 /* Enable/disable l2 tunnel */
12308 struct cmd_config_l2_tunnel_en_dis_result {
12309         cmdline_fixed_string_t port;
12310         cmdline_fixed_string_t config;
12311         cmdline_fixed_string_t all;
12312         portid_t id;
12313         cmdline_fixed_string_t l2_tunnel;
12314         cmdline_fixed_string_t l2_tunnel_type;
12315         cmdline_fixed_string_t en_dis;
12316 };
12317
12318 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12319         TOKEN_STRING_INITIALIZER
12320                 (struct cmd_config_l2_tunnel_en_dis_result,
12321                  port, "port");
12322 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12323         TOKEN_STRING_INITIALIZER
12324                 (struct cmd_config_l2_tunnel_en_dis_result,
12325                  config, "config");
12326 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12327         TOKEN_STRING_INITIALIZER
12328                 (struct cmd_config_l2_tunnel_en_dis_result,
12329                  all, "all");
12330 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12331         TOKEN_NUM_INITIALIZER
12332                 (struct cmd_config_l2_tunnel_en_dis_result,
12333                  id, UINT16);
12334 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12335         TOKEN_STRING_INITIALIZER
12336                 (struct cmd_config_l2_tunnel_en_dis_result,
12337                  l2_tunnel, "l2-tunnel");
12338 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12339         TOKEN_STRING_INITIALIZER
12340                 (struct cmd_config_l2_tunnel_en_dis_result,
12341                  l2_tunnel_type, "E-tag");
12342 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12343         TOKEN_STRING_INITIALIZER
12344                 (struct cmd_config_l2_tunnel_en_dis_result,
12345                  en_dis, "enable#disable");
12346
12347 /* enable/disable l2 tunnel for all ports */
12348 static void
12349 cmd_config_l2_tunnel_en_dis_all_parsed(
12350         void *parsed_result,
12351         __attribute__((unused)) struct cmdline *cl,
12352         __attribute__((unused)) void *data)
12353 {
12354         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12355         struct rte_eth_l2_tunnel_conf entry;
12356         portid_t pid;
12357         uint8_t en;
12358
12359         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12360
12361         if (!strcmp("enable", res->en_dis))
12362                 en = 1;
12363         else
12364                 en = 0;
12365
12366         RTE_ETH_FOREACH_DEV(pid) {
12367                 rte_eth_dev_l2_tunnel_offload_set(pid,
12368                                                   &entry,
12369                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12370                                                   en);
12371         }
12372 }
12373
12374 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12375         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12376         .data = NULL,
12377         .help_str = "port config all l2-tunnel E-tag enable|disable",
12378         .tokens = {
12379                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12380                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12381                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12382                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12383                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12384                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12385                 NULL,
12386         },
12387 };
12388
12389 /* enable/disable l2 tunnel for a port */
12390 static void
12391 cmd_config_l2_tunnel_en_dis_specific_parsed(
12392         void *parsed_result,
12393         __attribute__((unused)) struct cmdline *cl,
12394         __attribute__((unused)) void *data)
12395 {
12396         struct cmd_config_l2_tunnel_en_dis_result *res =
12397                 parsed_result;
12398         struct rte_eth_l2_tunnel_conf entry;
12399
12400         if (port_id_is_invalid(res->id, ENABLED_WARN))
12401                 return;
12402
12403         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12404
12405         if (!strcmp("enable", res->en_dis))
12406                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12407                                                   &entry,
12408                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12409                                                   1);
12410         else
12411                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12412                                                   &entry,
12413                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12414                                                   0);
12415 }
12416
12417 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12418         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12419         .data = NULL,
12420         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12421         .tokens = {
12422                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12423                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12424                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12425                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12426                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12427                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12428                 NULL,
12429         },
12430 };
12431
12432 /* E-tag configuration */
12433
12434 /* Common result structure for all E-tag configuration */
12435 struct cmd_config_e_tag_result {
12436         cmdline_fixed_string_t e_tag;
12437         cmdline_fixed_string_t set;
12438         cmdline_fixed_string_t insertion;
12439         cmdline_fixed_string_t stripping;
12440         cmdline_fixed_string_t forwarding;
12441         cmdline_fixed_string_t filter;
12442         cmdline_fixed_string_t add;
12443         cmdline_fixed_string_t del;
12444         cmdline_fixed_string_t on;
12445         cmdline_fixed_string_t off;
12446         cmdline_fixed_string_t on_off;
12447         cmdline_fixed_string_t port_tag_id;
12448         uint32_t port_tag_id_val;
12449         cmdline_fixed_string_t e_tag_id;
12450         uint16_t e_tag_id_val;
12451         cmdline_fixed_string_t dst_pool;
12452         uint8_t dst_pool_val;
12453         cmdline_fixed_string_t port;
12454         portid_t port_id;
12455         cmdline_fixed_string_t vf;
12456         uint8_t vf_id;
12457 };
12458
12459 /* Common CLI fields for all E-tag configuration */
12460 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12461         TOKEN_STRING_INITIALIZER
12462                 (struct cmd_config_e_tag_result,
12463                  e_tag, "E-tag");
12464 cmdline_parse_token_string_t cmd_config_e_tag_set =
12465         TOKEN_STRING_INITIALIZER
12466                 (struct cmd_config_e_tag_result,
12467                  set, "set");
12468 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12469         TOKEN_STRING_INITIALIZER
12470                 (struct cmd_config_e_tag_result,
12471                  insertion, "insertion");
12472 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12473         TOKEN_STRING_INITIALIZER
12474                 (struct cmd_config_e_tag_result,
12475                  stripping, "stripping");
12476 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12477         TOKEN_STRING_INITIALIZER
12478                 (struct cmd_config_e_tag_result,
12479                  forwarding, "forwarding");
12480 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12481         TOKEN_STRING_INITIALIZER
12482                 (struct cmd_config_e_tag_result,
12483                  filter, "filter");
12484 cmdline_parse_token_string_t cmd_config_e_tag_add =
12485         TOKEN_STRING_INITIALIZER
12486                 (struct cmd_config_e_tag_result,
12487                  add, "add");
12488 cmdline_parse_token_string_t cmd_config_e_tag_del =
12489         TOKEN_STRING_INITIALIZER
12490                 (struct cmd_config_e_tag_result,
12491                  del, "del");
12492 cmdline_parse_token_string_t cmd_config_e_tag_on =
12493         TOKEN_STRING_INITIALIZER
12494                 (struct cmd_config_e_tag_result,
12495                  on, "on");
12496 cmdline_parse_token_string_t cmd_config_e_tag_off =
12497         TOKEN_STRING_INITIALIZER
12498                 (struct cmd_config_e_tag_result,
12499                  off, "off");
12500 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12501         TOKEN_STRING_INITIALIZER
12502                 (struct cmd_config_e_tag_result,
12503                  on_off, "on#off");
12504 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12505         TOKEN_STRING_INITIALIZER
12506                 (struct cmd_config_e_tag_result,
12507                  port_tag_id, "port-tag-id");
12508 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12509         TOKEN_NUM_INITIALIZER
12510                 (struct cmd_config_e_tag_result,
12511                  port_tag_id_val, UINT32);
12512 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12513         TOKEN_STRING_INITIALIZER
12514                 (struct cmd_config_e_tag_result,
12515                  e_tag_id, "e-tag-id");
12516 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12517         TOKEN_NUM_INITIALIZER
12518                 (struct cmd_config_e_tag_result,
12519                  e_tag_id_val, UINT16);
12520 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12521         TOKEN_STRING_INITIALIZER
12522                 (struct cmd_config_e_tag_result,
12523                  dst_pool, "dst-pool");
12524 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12525         TOKEN_NUM_INITIALIZER
12526                 (struct cmd_config_e_tag_result,
12527                  dst_pool_val, UINT8);
12528 cmdline_parse_token_string_t cmd_config_e_tag_port =
12529         TOKEN_STRING_INITIALIZER
12530                 (struct cmd_config_e_tag_result,
12531                  port, "port");
12532 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12533         TOKEN_NUM_INITIALIZER
12534                 (struct cmd_config_e_tag_result,
12535                  port_id, UINT16);
12536 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12537         TOKEN_STRING_INITIALIZER
12538                 (struct cmd_config_e_tag_result,
12539                  vf, "vf");
12540 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12541         TOKEN_NUM_INITIALIZER
12542                 (struct cmd_config_e_tag_result,
12543                  vf_id, UINT8);
12544
12545 /* E-tag insertion configuration */
12546 static void
12547 cmd_config_e_tag_insertion_en_parsed(
12548         void *parsed_result,
12549         __attribute__((unused)) struct cmdline *cl,
12550         __attribute__((unused)) void *data)
12551 {
12552         struct cmd_config_e_tag_result *res =
12553                 parsed_result;
12554         struct rte_eth_l2_tunnel_conf entry;
12555
12556         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12557                 return;
12558
12559         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12560         entry.tunnel_id = res->port_tag_id_val;
12561         entry.vf_id = res->vf_id;
12562         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12563                                           &entry,
12564                                           ETH_L2_TUNNEL_INSERTION_MASK,
12565                                           1);
12566 }
12567
12568 static void
12569 cmd_config_e_tag_insertion_dis_parsed(
12570         void *parsed_result,
12571         __attribute__((unused)) struct cmdline *cl,
12572         __attribute__((unused)) void *data)
12573 {
12574         struct cmd_config_e_tag_result *res =
12575                 parsed_result;
12576         struct rte_eth_l2_tunnel_conf entry;
12577
12578         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12579                 return;
12580
12581         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12582         entry.vf_id = res->vf_id;
12583
12584         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12585                                           &entry,
12586                                           ETH_L2_TUNNEL_INSERTION_MASK,
12587                                           0);
12588 }
12589
12590 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12591         .f = cmd_config_e_tag_insertion_en_parsed,
12592         .data = NULL,
12593         .help_str = "E-tag ... : E-tag insertion enable",
12594         .tokens = {
12595                 (void *)&cmd_config_e_tag_e_tag,
12596                 (void *)&cmd_config_e_tag_set,
12597                 (void *)&cmd_config_e_tag_insertion,
12598                 (void *)&cmd_config_e_tag_on,
12599                 (void *)&cmd_config_e_tag_port_tag_id,
12600                 (void *)&cmd_config_e_tag_port_tag_id_val,
12601                 (void *)&cmd_config_e_tag_port,
12602                 (void *)&cmd_config_e_tag_port_id,
12603                 (void *)&cmd_config_e_tag_vf,
12604                 (void *)&cmd_config_e_tag_vf_id,
12605                 NULL,
12606         },
12607 };
12608
12609 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12610         .f = cmd_config_e_tag_insertion_dis_parsed,
12611         .data = NULL,
12612         .help_str = "E-tag ... : E-tag insertion disable",
12613         .tokens = {
12614                 (void *)&cmd_config_e_tag_e_tag,
12615                 (void *)&cmd_config_e_tag_set,
12616                 (void *)&cmd_config_e_tag_insertion,
12617                 (void *)&cmd_config_e_tag_off,
12618                 (void *)&cmd_config_e_tag_port,
12619                 (void *)&cmd_config_e_tag_port_id,
12620                 (void *)&cmd_config_e_tag_vf,
12621                 (void *)&cmd_config_e_tag_vf_id,
12622                 NULL,
12623         },
12624 };
12625
12626 /* E-tag stripping configuration */
12627 static void
12628 cmd_config_e_tag_stripping_parsed(
12629         void *parsed_result,
12630         __attribute__((unused)) struct cmdline *cl,
12631         __attribute__((unused)) void *data)
12632 {
12633         struct cmd_config_e_tag_result *res =
12634                 parsed_result;
12635         struct rte_eth_l2_tunnel_conf entry;
12636
12637         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12638                 return;
12639
12640         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12641
12642         if (!strcmp(res->on_off, "on"))
12643                 rte_eth_dev_l2_tunnel_offload_set
12644                         (res->port_id,
12645                          &entry,
12646                          ETH_L2_TUNNEL_STRIPPING_MASK,
12647                          1);
12648         else
12649                 rte_eth_dev_l2_tunnel_offload_set
12650                         (res->port_id,
12651                          &entry,
12652                          ETH_L2_TUNNEL_STRIPPING_MASK,
12653                          0);
12654 }
12655
12656 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12657         .f = cmd_config_e_tag_stripping_parsed,
12658         .data = NULL,
12659         .help_str = "E-tag ... : E-tag stripping enable/disable",
12660         .tokens = {
12661                 (void *)&cmd_config_e_tag_e_tag,
12662                 (void *)&cmd_config_e_tag_set,
12663                 (void *)&cmd_config_e_tag_stripping,
12664                 (void *)&cmd_config_e_tag_on_off,
12665                 (void *)&cmd_config_e_tag_port,
12666                 (void *)&cmd_config_e_tag_port_id,
12667                 NULL,
12668         },
12669 };
12670
12671 /* E-tag forwarding configuration */
12672 static void
12673 cmd_config_e_tag_forwarding_parsed(
12674         void *parsed_result,
12675         __attribute__((unused)) struct cmdline *cl,
12676         __attribute__((unused)) void *data)
12677 {
12678         struct cmd_config_e_tag_result *res = parsed_result;
12679         struct rte_eth_l2_tunnel_conf entry;
12680
12681         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12682                 return;
12683
12684         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12685
12686         if (!strcmp(res->on_off, "on"))
12687                 rte_eth_dev_l2_tunnel_offload_set
12688                         (res->port_id,
12689                          &entry,
12690                          ETH_L2_TUNNEL_FORWARDING_MASK,
12691                          1);
12692         else
12693                 rte_eth_dev_l2_tunnel_offload_set
12694                         (res->port_id,
12695                          &entry,
12696                          ETH_L2_TUNNEL_FORWARDING_MASK,
12697                          0);
12698 }
12699
12700 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12701         .f = cmd_config_e_tag_forwarding_parsed,
12702         .data = NULL,
12703         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12704         .tokens = {
12705                 (void *)&cmd_config_e_tag_e_tag,
12706                 (void *)&cmd_config_e_tag_set,
12707                 (void *)&cmd_config_e_tag_forwarding,
12708                 (void *)&cmd_config_e_tag_on_off,
12709                 (void *)&cmd_config_e_tag_port,
12710                 (void *)&cmd_config_e_tag_port_id,
12711                 NULL,
12712         },
12713 };
12714
12715 /* E-tag filter configuration */
12716 static void
12717 cmd_config_e_tag_filter_add_parsed(
12718         void *parsed_result,
12719         __attribute__((unused)) struct cmdline *cl,
12720         __attribute__((unused)) void *data)
12721 {
12722         struct cmd_config_e_tag_result *res = parsed_result;
12723         struct rte_eth_l2_tunnel_conf entry;
12724         int ret = 0;
12725
12726         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12727                 return;
12728
12729         if (res->e_tag_id_val > 0x3fff) {
12730                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12731                 return;
12732         }
12733
12734         ret = rte_eth_dev_filter_supported(res->port_id,
12735                                            RTE_ETH_FILTER_L2_TUNNEL);
12736         if (ret < 0) {
12737                 printf("E-tag filter is not supported on port %u.\n",
12738                        res->port_id);
12739                 return;
12740         }
12741
12742         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12743         entry.tunnel_id = res->e_tag_id_val;
12744         entry.pool = res->dst_pool_val;
12745
12746         ret = rte_eth_dev_filter_ctrl(res->port_id,
12747                                       RTE_ETH_FILTER_L2_TUNNEL,
12748                                       RTE_ETH_FILTER_ADD,
12749                                       &entry);
12750         if (ret < 0)
12751                 printf("E-tag filter programming error: (%s)\n",
12752                        strerror(-ret));
12753 }
12754
12755 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12756         .f = cmd_config_e_tag_filter_add_parsed,
12757         .data = NULL,
12758         .help_str = "E-tag ... : E-tag filter add",
12759         .tokens = {
12760                 (void *)&cmd_config_e_tag_e_tag,
12761                 (void *)&cmd_config_e_tag_set,
12762                 (void *)&cmd_config_e_tag_filter,
12763                 (void *)&cmd_config_e_tag_add,
12764                 (void *)&cmd_config_e_tag_e_tag_id,
12765                 (void *)&cmd_config_e_tag_e_tag_id_val,
12766                 (void *)&cmd_config_e_tag_dst_pool,
12767                 (void *)&cmd_config_e_tag_dst_pool_val,
12768                 (void *)&cmd_config_e_tag_port,
12769                 (void *)&cmd_config_e_tag_port_id,
12770                 NULL,
12771         },
12772 };
12773
12774 static void
12775 cmd_config_e_tag_filter_del_parsed(
12776         void *parsed_result,
12777         __attribute__((unused)) struct cmdline *cl,
12778         __attribute__((unused)) void *data)
12779 {
12780         struct cmd_config_e_tag_result *res = parsed_result;
12781         struct rte_eth_l2_tunnel_conf entry;
12782         int ret = 0;
12783
12784         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12785                 return;
12786
12787         if (res->e_tag_id_val > 0x3fff) {
12788                 printf("e-tag-id must be less than 0x3fff.\n");
12789                 return;
12790         }
12791
12792         ret = rte_eth_dev_filter_supported(res->port_id,
12793                                            RTE_ETH_FILTER_L2_TUNNEL);
12794         if (ret < 0) {
12795                 printf("E-tag filter is not supported on port %u.\n",
12796                        res->port_id);
12797                 return;
12798         }
12799
12800         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12801         entry.tunnel_id = res->e_tag_id_val;
12802
12803         ret = rte_eth_dev_filter_ctrl(res->port_id,
12804                                       RTE_ETH_FILTER_L2_TUNNEL,
12805                                       RTE_ETH_FILTER_DELETE,
12806                                       &entry);
12807         if (ret < 0)
12808                 printf("E-tag filter programming error: (%s)\n",
12809                        strerror(-ret));
12810 }
12811
12812 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12813         .f = cmd_config_e_tag_filter_del_parsed,
12814         .data = NULL,
12815         .help_str = "E-tag ... : E-tag filter delete",
12816         .tokens = {
12817                 (void *)&cmd_config_e_tag_e_tag,
12818                 (void *)&cmd_config_e_tag_set,
12819                 (void *)&cmd_config_e_tag_filter,
12820                 (void *)&cmd_config_e_tag_del,
12821                 (void *)&cmd_config_e_tag_e_tag_id,
12822                 (void *)&cmd_config_e_tag_e_tag_id_val,
12823                 (void *)&cmd_config_e_tag_port,
12824                 (void *)&cmd_config_e_tag_port_id,
12825                 NULL,
12826         },
12827 };
12828
12829 /* vf vlan anti spoof configuration */
12830
12831 /* Common result structure for vf vlan anti spoof */
12832 struct cmd_vf_vlan_anti_spoof_result {
12833         cmdline_fixed_string_t set;
12834         cmdline_fixed_string_t vf;
12835         cmdline_fixed_string_t vlan;
12836         cmdline_fixed_string_t antispoof;
12837         portid_t port_id;
12838         uint32_t vf_id;
12839         cmdline_fixed_string_t on_off;
12840 };
12841
12842 /* Common CLI fields for vf vlan anti spoof enable disable */
12843 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12844         TOKEN_STRING_INITIALIZER
12845                 (struct cmd_vf_vlan_anti_spoof_result,
12846                  set, "set");
12847 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12848         TOKEN_STRING_INITIALIZER
12849                 (struct cmd_vf_vlan_anti_spoof_result,
12850                  vf, "vf");
12851 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12852         TOKEN_STRING_INITIALIZER
12853                 (struct cmd_vf_vlan_anti_spoof_result,
12854                  vlan, "vlan");
12855 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12856         TOKEN_STRING_INITIALIZER
12857                 (struct cmd_vf_vlan_anti_spoof_result,
12858                  antispoof, "antispoof");
12859 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12860         TOKEN_NUM_INITIALIZER
12861                 (struct cmd_vf_vlan_anti_spoof_result,
12862                  port_id, UINT16);
12863 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12864         TOKEN_NUM_INITIALIZER
12865                 (struct cmd_vf_vlan_anti_spoof_result,
12866                  vf_id, UINT32);
12867 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12868         TOKEN_STRING_INITIALIZER
12869                 (struct cmd_vf_vlan_anti_spoof_result,
12870                  on_off, "on#off");
12871
12872 static void
12873 cmd_set_vf_vlan_anti_spoof_parsed(
12874         void *parsed_result,
12875         __attribute__((unused)) struct cmdline *cl,
12876         __attribute__((unused)) void *data)
12877 {
12878         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12879         int ret = -ENOTSUP;
12880
12881         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12882
12883         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12884                 return;
12885
12886 #ifdef RTE_LIBRTE_IXGBE_PMD
12887         if (ret == -ENOTSUP)
12888                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12889                                 res->vf_id, is_on);
12890 #endif
12891 #ifdef RTE_LIBRTE_I40E_PMD
12892         if (ret == -ENOTSUP)
12893                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12894                                 res->vf_id, is_on);
12895 #endif
12896 #ifdef RTE_LIBRTE_BNXT_PMD
12897         if (ret == -ENOTSUP)
12898                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12899                                 res->vf_id, is_on);
12900 #endif
12901
12902         switch (ret) {
12903         case 0:
12904                 break;
12905         case -EINVAL:
12906                 printf("invalid vf_id %d\n", res->vf_id);
12907                 break;
12908         case -ENODEV:
12909                 printf("invalid port_id %d\n", res->port_id);
12910                 break;
12911         case -ENOTSUP:
12912                 printf("function not implemented\n");
12913                 break;
12914         default:
12915                 printf("programming error: (%s)\n", strerror(-ret));
12916         }
12917 }
12918
12919 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12920         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12921         .data = NULL,
12922         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12923         .tokens = {
12924                 (void *)&cmd_vf_vlan_anti_spoof_set,
12925                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12926                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12927                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12928                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12929                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12930                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12931                 NULL,
12932         },
12933 };
12934
12935 /* vf mac anti spoof configuration */
12936
12937 /* Common result structure for vf mac anti spoof */
12938 struct cmd_vf_mac_anti_spoof_result {
12939         cmdline_fixed_string_t set;
12940         cmdline_fixed_string_t vf;
12941         cmdline_fixed_string_t mac;
12942         cmdline_fixed_string_t antispoof;
12943         portid_t port_id;
12944         uint32_t vf_id;
12945         cmdline_fixed_string_t on_off;
12946 };
12947
12948 /* Common CLI fields for vf mac anti spoof enable disable */
12949 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12950         TOKEN_STRING_INITIALIZER
12951                 (struct cmd_vf_mac_anti_spoof_result,
12952                  set, "set");
12953 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12954         TOKEN_STRING_INITIALIZER
12955                 (struct cmd_vf_mac_anti_spoof_result,
12956                  vf, "vf");
12957 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12958         TOKEN_STRING_INITIALIZER
12959                 (struct cmd_vf_mac_anti_spoof_result,
12960                  mac, "mac");
12961 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12962         TOKEN_STRING_INITIALIZER
12963                 (struct cmd_vf_mac_anti_spoof_result,
12964                  antispoof, "antispoof");
12965 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12966         TOKEN_NUM_INITIALIZER
12967                 (struct cmd_vf_mac_anti_spoof_result,
12968                  port_id, UINT16);
12969 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12970         TOKEN_NUM_INITIALIZER
12971                 (struct cmd_vf_mac_anti_spoof_result,
12972                  vf_id, UINT32);
12973 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12974         TOKEN_STRING_INITIALIZER
12975                 (struct cmd_vf_mac_anti_spoof_result,
12976                  on_off, "on#off");
12977
12978 static void
12979 cmd_set_vf_mac_anti_spoof_parsed(
12980         void *parsed_result,
12981         __attribute__((unused)) struct cmdline *cl,
12982         __attribute__((unused)) void *data)
12983 {
12984         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12985         int ret = -ENOTSUP;
12986
12987         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12988
12989         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12990                 return;
12991
12992 #ifdef RTE_LIBRTE_IXGBE_PMD
12993         if (ret == -ENOTSUP)
12994                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12995                         res->vf_id, is_on);
12996 #endif
12997 #ifdef RTE_LIBRTE_I40E_PMD
12998         if (ret == -ENOTSUP)
12999                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13000                         res->vf_id, is_on);
13001 #endif
13002 #ifdef RTE_LIBRTE_BNXT_PMD
13003         if (ret == -ENOTSUP)
13004                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13005                         res->vf_id, is_on);
13006 #endif
13007
13008         switch (ret) {
13009         case 0:
13010                 break;
13011         case -EINVAL:
13012                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13013                 break;
13014         case -ENODEV:
13015                 printf("invalid port_id %d\n", res->port_id);
13016                 break;
13017         case -ENOTSUP:
13018                 printf("function not implemented\n");
13019                 break;
13020         default:
13021                 printf("programming error: (%s)\n", strerror(-ret));
13022         }
13023 }
13024
13025 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13026         .f = cmd_set_vf_mac_anti_spoof_parsed,
13027         .data = NULL,
13028         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13029         .tokens = {
13030                 (void *)&cmd_vf_mac_anti_spoof_set,
13031                 (void *)&cmd_vf_mac_anti_spoof_vf,
13032                 (void *)&cmd_vf_mac_anti_spoof_mac,
13033                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13034                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13035                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13036                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13037                 NULL,
13038         },
13039 };
13040
13041 /* vf vlan strip queue configuration */
13042
13043 /* Common result structure for vf mac anti spoof */
13044 struct cmd_vf_vlan_stripq_result {
13045         cmdline_fixed_string_t set;
13046         cmdline_fixed_string_t vf;
13047         cmdline_fixed_string_t vlan;
13048         cmdline_fixed_string_t stripq;
13049         portid_t port_id;
13050         uint16_t vf_id;
13051         cmdline_fixed_string_t on_off;
13052 };
13053
13054 /* Common CLI fields for vf vlan strip enable disable */
13055 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13056         TOKEN_STRING_INITIALIZER
13057                 (struct cmd_vf_vlan_stripq_result,
13058                  set, "set");
13059 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13060         TOKEN_STRING_INITIALIZER
13061                 (struct cmd_vf_vlan_stripq_result,
13062                  vf, "vf");
13063 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13064         TOKEN_STRING_INITIALIZER
13065                 (struct cmd_vf_vlan_stripq_result,
13066                  vlan, "vlan");
13067 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13068         TOKEN_STRING_INITIALIZER
13069                 (struct cmd_vf_vlan_stripq_result,
13070                  stripq, "stripq");
13071 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13072         TOKEN_NUM_INITIALIZER
13073                 (struct cmd_vf_vlan_stripq_result,
13074                  port_id, UINT16);
13075 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13076         TOKEN_NUM_INITIALIZER
13077                 (struct cmd_vf_vlan_stripq_result,
13078                  vf_id, UINT16);
13079 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13080         TOKEN_STRING_INITIALIZER
13081                 (struct cmd_vf_vlan_stripq_result,
13082                  on_off, "on#off");
13083
13084 static void
13085 cmd_set_vf_vlan_stripq_parsed(
13086         void *parsed_result,
13087         __attribute__((unused)) struct cmdline *cl,
13088         __attribute__((unused)) void *data)
13089 {
13090         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13091         int ret = -ENOTSUP;
13092
13093         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13094
13095         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13096                 return;
13097
13098 #ifdef RTE_LIBRTE_IXGBE_PMD
13099         if (ret == -ENOTSUP)
13100                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13101                         res->vf_id, is_on);
13102 #endif
13103 #ifdef RTE_LIBRTE_I40E_PMD
13104         if (ret == -ENOTSUP)
13105                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13106                         res->vf_id, is_on);
13107 #endif
13108 #ifdef RTE_LIBRTE_BNXT_PMD
13109         if (ret == -ENOTSUP)
13110                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13111                         res->vf_id, is_on);
13112 #endif
13113
13114         switch (ret) {
13115         case 0:
13116                 break;
13117         case -EINVAL:
13118                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13119                 break;
13120         case -ENODEV:
13121                 printf("invalid port_id %d\n", res->port_id);
13122                 break;
13123         case -ENOTSUP:
13124                 printf("function not implemented\n");
13125                 break;
13126         default:
13127                 printf("programming error: (%s)\n", strerror(-ret));
13128         }
13129 }
13130
13131 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13132         .f = cmd_set_vf_vlan_stripq_parsed,
13133         .data = NULL,
13134         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13135         .tokens = {
13136                 (void *)&cmd_vf_vlan_stripq_set,
13137                 (void *)&cmd_vf_vlan_stripq_vf,
13138                 (void *)&cmd_vf_vlan_stripq_vlan,
13139                 (void *)&cmd_vf_vlan_stripq_stripq,
13140                 (void *)&cmd_vf_vlan_stripq_port_id,
13141                 (void *)&cmd_vf_vlan_stripq_vf_id,
13142                 (void *)&cmd_vf_vlan_stripq_on_off,
13143                 NULL,
13144         },
13145 };
13146
13147 /* vf vlan insert configuration */
13148
13149 /* Common result structure for vf vlan insert */
13150 struct cmd_vf_vlan_insert_result {
13151         cmdline_fixed_string_t set;
13152         cmdline_fixed_string_t vf;
13153         cmdline_fixed_string_t vlan;
13154         cmdline_fixed_string_t insert;
13155         portid_t port_id;
13156         uint16_t vf_id;
13157         uint16_t vlan_id;
13158 };
13159
13160 /* Common CLI fields for vf vlan insert enable disable */
13161 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13162         TOKEN_STRING_INITIALIZER
13163                 (struct cmd_vf_vlan_insert_result,
13164                  set, "set");
13165 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13166         TOKEN_STRING_INITIALIZER
13167                 (struct cmd_vf_vlan_insert_result,
13168                  vf, "vf");
13169 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13170         TOKEN_STRING_INITIALIZER
13171                 (struct cmd_vf_vlan_insert_result,
13172                  vlan, "vlan");
13173 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13174         TOKEN_STRING_INITIALIZER
13175                 (struct cmd_vf_vlan_insert_result,
13176                  insert, "insert");
13177 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13178         TOKEN_NUM_INITIALIZER
13179                 (struct cmd_vf_vlan_insert_result,
13180                  port_id, UINT16);
13181 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13182         TOKEN_NUM_INITIALIZER
13183                 (struct cmd_vf_vlan_insert_result,
13184                  vf_id, UINT16);
13185 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13186         TOKEN_NUM_INITIALIZER
13187                 (struct cmd_vf_vlan_insert_result,
13188                  vlan_id, UINT16);
13189
13190 static void
13191 cmd_set_vf_vlan_insert_parsed(
13192         void *parsed_result,
13193         __attribute__((unused)) struct cmdline *cl,
13194         __attribute__((unused)) void *data)
13195 {
13196         struct cmd_vf_vlan_insert_result *res = parsed_result;
13197         int ret = -ENOTSUP;
13198
13199         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13200                 return;
13201
13202 #ifdef RTE_LIBRTE_IXGBE_PMD
13203         if (ret == -ENOTSUP)
13204                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13205                         res->vlan_id);
13206 #endif
13207 #ifdef RTE_LIBRTE_I40E_PMD
13208         if (ret == -ENOTSUP)
13209                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13210                         res->vlan_id);
13211 #endif
13212 #ifdef RTE_LIBRTE_BNXT_PMD
13213         if (ret == -ENOTSUP)
13214                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13215                         res->vlan_id);
13216 #endif
13217
13218         switch (ret) {
13219         case 0:
13220                 break;
13221         case -EINVAL:
13222                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13223                 break;
13224         case -ENODEV:
13225                 printf("invalid port_id %d\n", res->port_id);
13226                 break;
13227         case -ENOTSUP:
13228                 printf("function not implemented\n");
13229                 break;
13230         default:
13231                 printf("programming error: (%s)\n", strerror(-ret));
13232         }
13233 }
13234
13235 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13236         .f = cmd_set_vf_vlan_insert_parsed,
13237         .data = NULL,
13238         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13239         .tokens = {
13240                 (void *)&cmd_vf_vlan_insert_set,
13241                 (void *)&cmd_vf_vlan_insert_vf,
13242                 (void *)&cmd_vf_vlan_insert_vlan,
13243                 (void *)&cmd_vf_vlan_insert_insert,
13244                 (void *)&cmd_vf_vlan_insert_port_id,
13245                 (void *)&cmd_vf_vlan_insert_vf_id,
13246                 (void *)&cmd_vf_vlan_insert_vlan_id,
13247                 NULL,
13248         },
13249 };
13250
13251 /* tx loopback configuration */
13252
13253 /* Common result structure for tx loopback */
13254 struct cmd_tx_loopback_result {
13255         cmdline_fixed_string_t set;
13256         cmdline_fixed_string_t tx;
13257         cmdline_fixed_string_t loopback;
13258         portid_t port_id;
13259         cmdline_fixed_string_t on_off;
13260 };
13261
13262 /* Common CLI fields for tx loopback enable disable */
13263 cmdline_parse_token_string_t cmd_tx_loopback_set =
13264         TOKEN_STRING_INITIALIZER
13265                 (struct cmd_tx_loopback_result,
13266                  set, "set");
13267 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13268         TOKEN_STRING_INITIALIZER
13269                 (struct cmd_tx_loopback_result,
13270                  tx, "tx");
13271 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13272         TOKEN_STRING_INITIALIZER
13273                 (struct cmd_tx_loopback_result,
13274                  loopback, "loopback");
13275 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13276         TOKEN_NUM_INITIALIZER
13277                 (struct cmd_tx_loopback_result,
13278                  port_id, UINT16);
13279 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13280         TOKEN_STRING_INITIALIZER
13281                 (struct cmd_tx_loopback_result,
13282                  on_off, "on#off");
13283
13284 static void
13285 cmd_set_tx_loopback_parsed(
13286         void *parsed_result,
13287         __attribute__((unused)) struct cmdline *cl,
13288         __attribute__((unused)) void *data)
13289 {
13290         struct cmd_tx_loopback_result *res = parsed_result;
13291         int ret = -ENOTSUP;
13292
13293         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13294
13295         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13296                 return;
13297
13298 #ifdef RTE_LIBRTE_IXGBE_PMD
13299         if (ret == -ENOTSUP)
13300                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13301 #endif
13302 #ifdef RTE_LIBRTE_I40E_PMD
13303         if (ret == -ENOTSUP)
13304                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13305 #endif
13306 #ifdef RTE_LIBRTE_BNXT_PMD
13307         if (ret == -ENOTSUP)
13308                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13309 #endif
13310 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13311         if (ret == -ENOTSUP)
13312                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13313 #endif
13314
13315         switch (ret) {
13316         case 0:
13317                 break;
13318         case -EINVAL:
13319                 printf("invalid is_on %d\n", is_on);
13320                 break;
13321         case -ENODEV:
13322                 printf("invalid port_id %d\n", res->port_id);
13323                 break;
13324         case -ENOTSUP:
13325                 printf("function not implemented\n");
13326                 break;
13327         default:
13328                 printf("programming error: (%s)\n", strerror(-ret));
13329         }
13330 }
13331
13332 cmdline_parse_inst_t cmd_set_tx_loopback = {
13333         .f = cmd_set_tx_loopback_parsed,
13334         .data = NULL,
13335         .help_str = "set tx loopback <port_id> on|off",
13336         .tokens = {
13337                 (void *)&cmd_tx_loopback_set,
13338                 (void *)&cmd_tx_loopback_tx,
13339                 (void *)&cmd_tx_loopback_loopback,
13340                 (void *)&cmd_tx_loopback_port_id,
13341                 (void *)&cmd_tx_loopback_on_off,
13342                 NULL,
13343         },
13344 };
13345
13346 /* all queues drop enable configuration */
13347
13348 /* Common result structure for all queues drop enable */
13349 struct cmd_all_queues_drop_en_result {
13350         cmdline_fixed_string_t set;
13351         cmdline_fixed_string_t all;
13352         cmdline_fixed_string_t queues;
13353         cmdline_fixed_string_t drop;
13354         portid_t port_id;
13355         cmdline_fixed_string_t on_off;
13356 };
13357
13358 /* Common CLI fields for tx loopback enable disable */
13359 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13360         TOKEN_STRING_INITIALIZER
13361                 (struct cmd_all_queues_drop_en_result,
13362                  set, "set");
13363 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13364         TOKEN_STRING_INITIALIZER
13365                 (struct cmd_all_queues_drop_en_result,
13366                  all, "all");
13367 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13368         TOKEN_STRING_INITIALIZER
13369                 (struct cmd_all_queues_drop_en_result,
13370                  queues, "queues");
13371 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13372         TOKEN_STRING_INITIALIZER
13373                 (struct cmd_all_queues_drop_en_result,
13374                  drop, "drop");
13375 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13376         TOKEN_NUM_INITIALIZER
13377                 (struct cmd_all_queues_drop_en_result,
13378                  port_id, UINT16);
13379 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13380         TOKEN_STRING_INITIALIZER
13381                 (struct cmd_all_queues_drop_en_result,
13382                  on_off, "on#off");
13383
13384 static void
13385 cmd_set_all_queues_drop_en_parsed(
13386         void *parsed_result,
13387         __attribute__((unused)) struct cmdline *cl,
13388         __attribute__((unused)) void *data)
13389 {
13390         struct cmd_all_queues_drop_en_result *res = parsed_result;
13391         int ret = -ENOTSUP;
13392         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13393
13394         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13395                 return;
13396
13397 #ifdef RTE_LIBRTE_IXGBE_PMD
13398         if (ret == -ENOTSUP)
13399                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13400 #endif
13401 #ifdef RTE_LIBRTE_BNXT_PMD
13402         if (ret == -ENOTSUP)
13403                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13404 #endif
13405         switch (ret) {
13406         case 0:
13407                 break;
13408         case -EINVAL:
13409                 printf("invalid is_on %d\n", is_on);
13410                 break;
13411         case -ENODEV:
13412                 printf("invalid port_id %d\n", res->port_id);
13413                 break;
13414         case -ENOTSUP:
13415                 printf("function not implemented\n");
13416                 break;
13417         default:
13418                 printf("programming error: (%s)\n", strerror(-ret));
13419         }
13420 }
13421
13422 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13423         .f = cmd_set_all_queues_drop_en_parsed,
13424         .data = NULL,
13425         .help_str = "set all queues drop <port_id> on|off",
13426         .tokens = {
13427                 (void *)&cmd_all_queues_drop_en_set,
13428                 (void *)&cmd_all_queues_drop_en_all,
13429                 (void *)&cmd_all_queues_drop_en_queues,
13430                 (void *)&cmd_all_queues_drop_en_drop,
13431                 (void *)&cmd_all_queues_drop_en_port_id,
13432                 (void *)&cmd_all_queues_drop_en_on_off,
13433                 NULL,
13434         },
13435 };
13436
13437 /* vf split drop enable configuration */
13438
13439 /* Common result structure for vf split drop enable */
13440 struct cmd_vf_split_drop_en_result {
13441         cmdline_fixed_string_t set;
13442         cmdline_fixed_string_t vf;
13443         cmdline_fixed_string_t split;
13444         cmdline_fixed_string_t drop;
13445         portid_t port_id;
13446         uint16_t vf_id;
13447         cmdline_fixed_string_t on_off;
13448 };
13449
13450 /* Common CLI fields for vf split drop enable disable */
13451 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13452         TOKEN_STRING_INITIALIZER
13453                 (struct cmd_vf_split_drop_en_result,
13454                  set, "set");
13455 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13456         TOKEN_STRING_INITIALIZER
13457                 (struct cmd_vf_split_drop_en_result,
13458                  vf, "vf");
13459 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13460         TOKEN_STRING_INITIALIZER
13461                 (struct cmd_vf_split_drop_en_result,
13462                  split, "split");
13463 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13464         TOKEN_STRING_INITIALIZER
13465                 (struct cmd_vf_split_drop_en_result,
13466                  drop, "drop");
13467 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13468         TOKEN_NUM_INITIALIZER
13469                 (struct cmd_vf_split_drop_en_result,
13470                  port_id, UINT16);
13471 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13472         TOKEN_NUM_INITIALIZER
13473                 (struct cmd_vf_split_drop_en_result,
13474                  vf_id, UINT16);
13475 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13476         TOKEN_STRING_INITIALIZER
13477                 (struct cmd_vf_split_drop_en_result,
13478                  on_off, "on#off");
13479
13480 static void
13481 cmd_set_vf_split_drop_en_parsed(
13482         void *parsed_result,
13483         __attribute__((unused)) struct cmdline *cl,
13484         __attribute__((unused)) void *data)
13485 {
13486         struct cmd_vf_split_drop_en_result *res = parsed_result;
13487         int ret = -ENOTSUP;
13488         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13489
13490         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13491                 return;
13492
13493 #ifdef RTE_LIBRTE_IXGBE_PMD
13494         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13495                         is_on);
13496 #endif
13497         switch (ret) {
13498         case 0:
13499                 break;
13500         case -EINVAL:
13501                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13502                 break;
13503         case -ENODEV:
13504                 printf("invalid port_id %d\n", res->port_id);
13505                 break;
13506         case -ENOTSUP:
13507                 printf("not supported on port %d\n", res->port_id);
13508                 break;
13509         default:
13510                 printf("programming error: (%s)\n", strerror(-ret));
13511         }
13512 }
13513
13514 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13515         .f = cmd_set_vf_split_drop_en_parsed,
13516         .data = NULL,
13517         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13518         .tokens = {
13519                 (void *)&cmd_vf_split_drop_en_set,
13520                 (void *)&cmd_vf_split_drop_en_vf,
13521                 (void *)&cmd_vf_split_drop_en_split,
13522                 (void *)&cmd_vf_split_drop_en_drop,
13523                 (void *)&cmd_vf_split_drop_en_port_id,
13524                 (void *)&cmd_vf_split_drop_en_vf_id,
13525                 (void *)&cmd_vf_split_drop_en_on_off,
13526                 NULL,
13527         },
13528 };
13529
13530 /* vf mac address configuration */
13531
13532 /* Common result structure for vf mac address */
13533 struct cmd_set_vf_mac_addr_result {
13534         cmdline_fixed_string_t set;
13535         cmdline_fixed_string_t vf;
13536         cmdline_fixed_string_t mac;
13537         cmdline_fixed_string_t addr;
13538         portid_t port_id;
13539         uint16_t vf_id;
13540         struct ether_addr mac_addr;
13541
13542 };
13543
13544 /* Common CLI fields for vf split drop enable disable */
13545 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13546         TOKEN_STRING_INITIALIZER
13547                 (struct cmd_set_vf_mac_addr_result,
13548                  set, "set");
13549 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13550         TOKEN_STRING_INITIALIZER
13551                 (struct cmd_set_vf_mac_addr_result,
13552                  vf, "vf");
13553 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13554         TOKEN_STRING_INITIALIZER
13555                 (struct cmd_set_vf_mac_addr_result,
13556                  mac, "mac");
13557 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13558         TOKEN_STRING_INITIALIZER
13559                 (struct cmd_set_vf_mac_addr_result,
13560                  addr, "addr");
13561 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13562         TOKEN_NUM_INITIALIZER
13563                 (struct cmd_set_vf_mac_addr_result,
13564                  port_id, UINT16);
13565 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13566         TOKEN_NUM_INITIALIZER
13567                 (struct cmd_set_vf_mac_addr_result,
13568                  vf_id, UINT16);
13569 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13570         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13571                  mac_addr);
13572
13573 static void
13574 cmd_set_vf_mac_addr_parsed(
13575         void *parsed_result,
13576         __attribute__((unused)) struct cmdline *cl,
13577         __attribute__((unused)) void *data)
13578 {
13579         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13580         int ret = -ENOTSUP;
13581
13582         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13583                 return;
13584
13585 #ifdef RTE_LIBRTE_IXGBE_PMD
13586         if (ret == -ENOTSUP)
13587                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13588                                 &res->mac_addr);
13589 #endif
13590 #ifdef RTE_LIBRTE_I40E_PMD
13591         if (ret == -ENOTSUP)
13592                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13593                                 &res->mac_addr);
13594 #endif
13595 #ifdef RTE_LIBRTE_BNXT_PMD
13596         if (ret == -ENOTSUP)
13597                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13598                                 &res->mac_addr);
13599 #endif
13600
13601         switch (ret) {
13602         case 0:
13603                 break;
13604         case -EINVAL:
13605                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13606                 break;
13607         case -ENODEV:
13608                 printf("invalid port_id %d\n", res->port_id);
13609                 break;
13610         case -ENOTSUP:
13611                 printf("function not implemented\n");
13612                 break;
13613         default:
13614                 printf("programming error: (%s)\n", strerror(-ret));
13615         }
13616 }
13617
13618 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13619         .f = cmd_set_vf_mac_addr_parsed,
13620         .data = NULL,
13621         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13622         .tokens = {
13623                 (void *)&cmd_set_vf_mac_addr_set,
13624                 (void *)&cmd_set_vf_mac_addr_vf,
13625                 (void *)&cmd_set_vf_mac_addr_mac,
13626                 (void *)&cmd_set_vf_mac_addr_addr,
13627                 (void *)&cmd_set_vf_mac_addr_port_id,
13628                 (void *)&cmd_set_vf_mac_addr_vf_id,
13629                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13630                 NULL,
13631         },
13632 };
13633
13634 /* MACsec configuration */
13635
13636 /* Common result structure for MACsec offload enable */
13637 struct cmd_macsec_offload_on_result {
13638         cmdline_fixed_string_t set;
13639         cmdline_fixed_string_t macsec;
13640         cmdline_fixed_string_t offload;
13641         portid_t port_id;
13642         cmdline_fixed_string_t on;
13643         cmdline_fixed_string_t encrypt;
13644         cmdline_fixed_string_t en_on_off;
13645         cmdline_fixed_string_t replay_protect;
13646         cmdline_fixed_string_t rp_on_off;
13647 };
13648
13649 /* Common CLI fields for MACsec offload disable */
13650 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13651         TOKEN_STRING_INITIALIZER
13652                 (struct cmd_macsec_offload_on_result,
13653                  set, "set");
13654 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13655         TOKEN_STRING_INITIALIZER
13656                 (struct cmd_macsec_offload_on_result,
13657                  macsec, "macsec");
13658 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13659         TOKEN_STRING_INITIALIZER
13660                 (struct cmd_macsec_offload_on_result,
13661                  offload, "offload");
13662 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13663         TOKEN_NUM_INITIALIZER
13664                 (struct cmd_macsec_offload_on_result,
13665                  port_id, UINT16);
13666 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13667         TOKEN_STRING_INITIALIZER
13668                 (struct cmd_macsec_offload_on_result,
13669                  on, "on");
13670 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13671         TOKEN_STRING_INITIALIZER
13672                 (struct cmd_macsec_offload_on_result,
13673                  encrypt, "encrypt");
13674 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13675         TOKEN_STRING_INITIALIZER
13676                 (struct cmd_macsec_offload_on_result,
13677                  en_on_off, "on#off");
13678 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13679         TOKEN_STRING_INITIALIZER
13680                 (struct cmd_macsec_offload_on_result,
13681                  replay_protect, "replay-protect");
13682 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13683         TOKEN_STRING_INITIALIZER
13684                 (struct cmd_macsec_offload_on_result,
13685                  rp_on_off, "on#off");
13686
13687 static void
13688 cmd_set_macsec_offload_on_parsed(
13689         void *parsed_result,
13690         __attribute__((unused)) struct cmdline *cl,
13691         __attribute__((unused)) void *data)
13692 {
13693         struct cmd_macsec_offload_on_result *res = parsed_result;
13694         int ret = -ENOTSUP;
13695         portid_t port_id = res->port_id;
13696         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13697         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13698         struct rte_eth_dev_info dev_info;
13699
13700         if (port_id_is_invalid(port_id, ENABLED_WARN))
13701                 return;
13702         if (!port_is_stopped(port_id)) {
13703                 printf("Please stop port %d first\n", port_id);
13704                 return;
13705         }
13706
13707         rte_eth_dev_info_get(port_id, &dev_info);
13708         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13709 #ifdef RTE_LIBRTE_IXGBE_PMD
13710                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13711 #endif
13712         }
13713         RTE_SET_USED(en);
13714         RTE_SET_USED(rp);
13715
13716         switch (ret) {
13717         case 0:
13718                 ports[port_id].dev_conf.txmode.offloads |=
13719                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13720                 cmd_reconfig_device_queue(port_id, 1, 1);
13721                 break;
13722         case -ENODEV:
13723                 printf("invalid port_id %d\n", port_id);
13724                 break;
13725         case -ENOTSUP:
13726                 printf("not supported on port %d\n", port_id);
13727                 break;
13728         default:
13729                 printf("programming error: (%s)\n", strerror(-ret));
13730         }
13731 }
13732
13733 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13734         .f = cmd_set_macsec_offload_on_parsed,
13735         .data = NULL,
13736         .help_str = "set macsec offload <port_id> on "
13737                 "encrypt on|off replay-protect on|off",
13738         .tokens = {
13739                 (void *)&cmd_macsec_offload_on_set,
13740                 (void *)&cmd_macsec_offload_on_macsec,
13741                 (void *)&cmd_macsec_offload_on_offload,
13742                 (void *)&cmd_macsec_offload_on_port_id,
13743                 (void *)&cmd_macsec_offload_on_on,
13744                 (void *)&cmd_macsec_offload_on_encrypt,
13745                 (void *)&cmd_macsec_offload_on_en_on_off,
13746                 (void *)&cmd_macsec_offload_on_replay_protect,
13747                 (void *)&cmd_macsec_offload_on_rp_on_off,
13748                 NULL,
13749         },
13750 };
13751
13752 /* Common result structure for MACsec offload disable */
13753 struct cmd_macsec_offload_off_result {
13754         cmdline_fixed_string_t set;
13755         cmdline_fixed_string_t macsec;
13756         cmdline_fixed_string_t offload;
13757         portid_t port_id;
13758         cmdline_fixed_string_t off;
13759 };
13760
13761 /* Common CLI fields for MACsec offload disable */
13762 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13763         TOKEN_STRING_INITIALIZER
13764                 (struct cmd_macsec_offload_off_result,
13765                  set, "set");
13766 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13767         TOKEN_STRING_INITIALIZER
13768                 (struct cmd_macsec_offload_off_result,
13769                  macsec, "macsec");
13770 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13771         TOKEN_STRING_INITIALIZER
13772                 (struct cmd_macsec_offload_off_result,
13773                  offload, "offload");
13774 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13775         TOKEN_NUM_INITIALIZER
13776                 (struct cmd_macsec_offload_off_result,
13777                  port_id, UINT16);
13778 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13779         TOKEN_STRING_INITIALIZER
13780                 (struct cmd_macsec_offload_off_result,
13781                  off, "off");
13782
13783 static void
13784 cmd_set_macsec_offload_off_parsed(
13785         void *parsed_result,
13786         __attribute__((unused)) struct cmdline *cl,
13787         __attribute__((unused)) void *data)
13788 {
13789         struct cmd_macsec_offload_off_result *res = parsed_result;
13790         int ret = -ENOTSUP;
13791         struct rte_eth_dev_info dev_info;
13792         portid_t port_id = res->port_id;
13793
13794         if (port_id_is_invalid(port_id, ENABLED_WARN))
13795                 return;
13796         if (!port_is_stopped(port_id)) {
13797                 printf("Please stop port %d first\n", port_id);
13798                 return;
13799         }
13800
13801         rte_eth_dev_info_get(port_id, &dev_info);
13802         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13803 #ifdef RTE_LIBRTE_IXGBE_PMD
13804                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13805 #endif
13806         }
13807         switch (ret) {
13808         case 0:
13809                 ports[port_id].dev_conf.txmode.offloads &=
13810                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13811                 cmd_reconfig_device_queue(port_id, 1, 1);
13812                 break;
13813         case -ENODEV:
13814                 printf("invalid port_id %d\n", port_id);
13815                 break;
13816         case -ENOTSUP:
13817                 printf("not supported on port %d\n", port_id);
13818                 break;
13819         default:
13820                 printf("programming error: (%s)\n", strerror(-ret));
13821         }
13822 }
13823
13824 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13825         .f = cmd_set_macsec_offload_off_parsed,
13826         .data = NULL,
13827         .help_str = "set macsec offload <port_id> off",
13828         .tokens = {
13829                 (void *)&cmd_macsec_offload_off_set,
13830                 (void *)&cmd_macsec_offload_off_macsec,
13831                 (void *)&cmd_macsec_offload_off_offload,
13832                 (void *)&cmd_macsec_offload_off_port_id,
13833                 (void *)&cmd_macsec_offload_off_off,
13834                 NULL,
13835         },
13836 };
13837
13838 /* Common result structure for MACsec secure connection configure */
13839 struct cmd_macsec_sc_result {
13840         cmdline_fixed_string_t set;
13841         cmdline_fixed_string_t macsec;
13842         cmdline_fixed_string_t sc;
13843         cmdline_fixed_string_t tx_rx;
13844         portid_t port_id;
13845         struct ether_addr mac;
13846         uint16_t pi;
13847 };
13848
13849 /* Common CLI fields for MACsec secure connection configure */
13850 cmdline_parse_token_string_t cmd_macsec_sc_set =
13851         TOKEN_STRING_INITIALIZER
13852                 (struct cmd_macsec_sc_result,
13853                  set, "set");
13854 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13855         TOKEN_STRING_INITIALIZER
13856                 (struct cmd_macsec_sc_result,
13857                  macsec, "macsec");
13858 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13859         TOKEN_STRING_INITIALIZER
13860                 (struct cmd_macsec_sc_result,
13861                  sc, "sc");
13862 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13863         TOKEN_STRING_INITIALIZER
13864                 (struct cmd_macsec_sc_result,
13865                  tx_rx, "tx#rx");
13866 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13867         TOKEN_NUM_INITIALIZER
13868                 (struct cmd_macsec_sc_result,
13869                  port_id, UINT16);
13870 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13871         TOKEN_ETHERADDR_INITIALIZER
13872                 (struct cmd_macsec_sc_result,
13873                  mac);
13874 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13875         TOKEN_NUM_INITIALIZER
13876                 (struct cmd_macsec_sc_result,
13877                  pi, UINT16);
13878
13879 static void
13880 cmd_set_macsec_sc_parsed(
13881         void *parsed_result,
13882         __attribute__((unused)) struct cmdline *cl,
13883         __attribute__((unused)) void *data)
13884 {
13885         struct cmd_macsec_sc_result *res = parsed_result;
13886         int ret = -ENOTSUP;
13887         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13888
13889 #ifdef RTE_LIBRTE_IXGBE_PMD
13890         ret = is_tx ?
13891                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13892                                 res->mac.addr_bytes) :
13893                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13894                                 res->mac.addr_bytes, res->pi);
13895 #endif
13896         RTE_SET_USED(is_tx);
13897
13898         switch (ret) {
13899         case 0:
13900                 break;
13901         case -ENODEV:
13902                 printf("invalid port_id %d\n", res->port_id);
13903                 break;
13904         case -ENOTSUP:
13905                 printf("not supported on port %d\n", res->port_id);
13906                 break;
13907         default:
13908                 printf("programming error: (%s)\n", strerror(-ret));
13909         }
13910 }
13911
13912 cmdline_parse_inst_t cmd_set_macsec_sc = {
13913         .f = cmd_set_macsec_sc_parsed,
13914         .data = NULL,
13915         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13916         .tokens = {
13917                 (void *)&cmd_macsec_sc_set,
13918                 (void *)&cmd_macsec_sc_macsec,
13919                 (void *)&cmd_macsec_sc_sc,
13920                 (void *)&cmd_macsec_sc_tx_rx,
13921                 (void *)&cmd_macsec_sc_port_id,
13922                 (void *)&cmd_macsec_sc_mac,
13923                 (void *)&cmd_macsec_sc_pi,
13924                 NULL,
13925         },
13926 };
13927
13928 /* Common result structure for MACsec secure connection configure */
13929 struct cmd_macsec_sa_result {
13930         cmdline_fixed_string_t set;
13931         cmdline_fixed_string_t macsec;
13932         cmdline_fixed_string_t sa;
13933         cmdline_fixed_string_t tx_rx;
13934         portid_t port_id;
13935         uint8_t idx;
13936         uint8_t an;
13937         uint32_t pn;
13938         cmdline_fixed_string_t key;
13939 };
13940
13941 /* Common CLI fields for MACsec secure connection configure */
13942 cmdline_parse_token_string_t cmd_macsec_sa_set =
13943         TOKEN_STRING_INITIALIZER
13944                 (struct cmd_macsec_sa_result,
13945                  set, "set");
13946 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13947         TOKEN_STRING_INITIALIZER
13948                 (struct cmd_macsec_sa_result,
13949                  macsec, "macsec");
13950 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13951         TOKEN_STRING_INITIALIZER
13952                 (struct cmd_macsec_sa_result,
13953                  sa, "sa");
13954 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13955         TOKEN_STRING_INITIALIZER
13956                 (struct cmd_macsec_sa_result,
13957                  tx_rx, "tx#rx");
13958 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13959         TOKEN_NUM_INITIALIZER
13960                 (struct cmd_macsec_sa_result,
13961                  port_id, UINT16);
13962 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13963         TOKEN_NUM_INITIALIZER
13964                 (struct cmd_macsec_sa_result,
13965                  idx, UINT8);
13966 cmdline_parse_token_num_t cmd_macsec_sa_an =
13967         TOKEN_NUM_INITIALIZER
13968                 (struct cmd_macsec_sa_result,
13969                  an, UINT8);
13970 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13971         TOKEN_NUM_INITIALIZER
13972                 (struct cmd_macsec_sa_result,
13973                  pn, UINT32);
13974 cmdline_parse_token_string_t cmd_macsec_sa_key =
13975         TOKEN_STRING_INITIALIZER
13976                 (struct cmd_macsec_sa_result,
13977                  key, NULL);
13978
13979 static void
13980 cmd_set_macsec_sa_parsed(
13981         void *parsed_result,
13982         __attribute__((unused)) struct cmdline *cl,
13983         __attribute__((unused)) void *data)
13984 {
13985         struct cmd_macsec_sa_result *res = parsed_result;
13986         int ret = -ENOTSUP;
13987         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13988         uint8_t key[16] = { 0 };
13989         uint8_t xdgt0;
13990         uint8_t xdgt1;
13991         int key_len;
13992         int i;
13993
13994         key_len = strlen(res->key) / 2;
13995         if (key_len > 16)
13996                 key_len = 16;
13997
13998         for (i = 0; i < key_len; i++) {
13999                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14000                 if (xdgt0 == 0xFF)
14001                         return;
14002                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14003                 if (xdgt1 == 0xFF)
14004                         return;
14005                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14006         }
14007
14008 #ifdef RTE_LIBRTE_IXGBE_PMD
14009         ret = is_tx ?
14010                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14011                         res->idx, res->an, res->pn, key) :
14012                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14013                         res->idx, res->an, res->pn, key);
14014 #endif
14015         RTE_SET_USED(is_tx);
14016         RTE_SET_USED(key);
14017
14018         switch (ret) {
14019         case 0:
14020                 break;
14021         case -EINVAL:
14022                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14023                 break;
14024         case -ENODEV:
14025                 printf("invalid port_id %d\n", res->port_id);
14026                 break;
14027         case -ENOTSUP:
14028                 printf("not supported on port %d\n", res->port_id);
14029                 break;
14030         default:
14031                 printf("programming error: (%s)\n", strerror(-ret));
14032         }
14033 }
14034
14035 cmdline_parse_inst_t cmd_set_macsec_sa = {
14036         .f = cmd_set_macsec_sa_parsed,
14037         .data = NULL,
14038         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14039         .tokens = {
14040                 (void *)&cmd_macsec_sa_set,
14041                 (void *)&cmd_macsec_sa_macsec,
14042                 (void *)&cmd_macsec_sa_sa,
14043                 (void *)&cmd_macsec_sa_tx_rx,
14044                 (void *)&cmd_macsec_sa_port_id,
14045                 (void *)&cmd_macsec_sa_idx,
14046                 (void *)&cmd_macsec_sa_an,
14047                 (void *)&cmd_macsec_sa_pn,
14048                 (void *)&cmd_macsec_sa_key,
14049                 NULL,
14050         },
14051 };
14052
14053 /* VF unicast promiscuous mode configuration */
14054
14055 /* Common result structure for VF unicast promiscuous mode */
14056 struct cmd_vf_promisc_result {
14057         cmdline_fixed_string_t set;
14058         cmdline_fixed_string_t vf;
14059         cmdline_fixed_string_t promisc;
14060         portid_t port_id;
14061         uint32_t vf_id;
14062         cmdline_fixed_string_t on_off;
14063 };
14064
14065 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14066 cmdline_parse_token_string_t cmd_vf_promisc_set =
14067         TOKEN_STRING_INITIALIZER
14068                 (struct cmd_vf_promisc_result,
14069                  set, "set");
14070 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14071         TOKEN_STRING_INITIALIZER
14072                 (struct cmd_vf_promisc_result,
14073                  vf, "vf");
14074 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14075         TOKEN_STRING_INITIALIZER
14076                 (struct cmd_vf_promisc_result,
14077                  promisc, "promisc");
14078 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14079         TOKEN_NUM_INITIALIZER
14080                 (struct cmd_vf_promisc_result,
14081                  port_id, UINT16);
14082 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14083         TOKEN_NUM_INITIALIZER
14084                 (struct cmd_vf_promisc_result,
14085                  vf_id, UINT32);
14086 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14087         TOKEN_STRING_INITIALIZER
14088                 (struct cmd_vf_promisc_result,
14089                  on_off, "on#off");
14090
14091 static void
14092 cmd_set_vf_promisc_parsed(
14093         void *parsed_result,
14094         __attribute__((unused)) struct cmdline *cl,
14095         __attribute__((unused)) void *data)
14096 {
14097         struct cmd_vf_promisc_result *res = parsed_result;
14098         int ret = -ENOTSUP;
14099
14100         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14101
14102         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14103                 return;
14104
14105 #ifdef RTE_LIBRTE_I40E_PMD
14106         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14107                                                   res->vf_id, is_on);
14108 #endif
14109
14110         switch (ret) {
14111         case 0:
14112                 break;
14113         case -EINVAL:
14114                 printf("invalid vf_id %d\n", res->vf_id);
14115                 break;
14116         case -ENODEV:
14117                 printf("invalid port_id %d\n", res->port_id);
14118                 break;
14119         case -ENOTSUP:
14120                 printf("function not implemented\n");
14121                 break;
14122         default:
14123                 printf("programming error: (%s)\n", strerror(-ret));
14124         }
14125 }
14126
14127 cmdline_parse_inst_t cmd_set_vf_promisc = {
14128         .f = cmd_set_vf_promisc_parsed,
14129         .data = NULL,
14130         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14131                 "Set unicast promiscuous mode for a VF from the PF",
14132         .tokens = {
14133                 (void *)&cmd_vf_promisc_set,
14134                 (void *)&cmd_vf_promisc_vf,
14135                 (void *)&cmd_vf_promisc_promisc,
14136                 (void *)&cmd_vf_promisc_port_id,
14137                 (void *)&cmd_vf_promisc_vf_id,
14138                 (void *)&cmd_vf_promisc_on_off,
14139                 NULL,
14140         },
14141 };
14142
14143 /* VF multicast promiscuous mode configuration */
14144
14145 /* Common result structure for VF multicast promiscuous mode */
14146 struct cmd_vf_allmulti_result {
14147         cmdline_fixed_string_t set;
14148         cmdline_fixed_string_t vf;
14149         cmdline_fixed_string_t allmulti;
14150         portid_t port_id;
14151         uint32_t vf_id;
14152         cmdline_fixed_string_t on_off;
14153 };
14154
14155 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14156 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14157         TOKEN_STRING_INITIALIZER
14158                 (struct cmd_vf_allmulti_result,
14159                  set, "set");
14160 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14161         TOKEN_STRING_INITIALIZER
14162                 (struct cmd_vf_allmulti_result,
14163                  vf, "vf");
14164 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14165         TOKEN_STRING_INITIALIZER
14166                 (struct cmd_vf_allmulti_result,
14167                  allmulti, "allmulti");
14168 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14169         TOKEN_NUM_INITIALIZER
14170                 (struct cmd_vf_allmulti_result,
14171                  port_id, UINT16);
14172 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14173         TOKEN_NUM_INITIALIZER
14174                 (struct cmd_vf_allmulti_result,
14175                  vf_id, UINT32);
14176 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14177         TOKEN_STRING_INITIALIZER
14178                 (struct cmd_vf_allmulti_result,
14179                  on_off, "on#off");
14180
14181 static void
14182 cmd_set_vf_allmulti_parsed(
14183         void *parsed_result,
14184         __attribute__((unused)) struct cmdline *cl,
14185         __attribute__((unused)) void *data)
14186 {
14187         struct cmd_vf_allmulti_result *res = parsed_result;
14188         int ret = -ENOTSUP;
14189
14190         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14191
14192         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14193                 return;
14194
14195 #ifdef RTE_LIBRTE_I40E_PMD
14196         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14197                                                     res->vf_id, is_on);
14198 #endif
14199
14200         switch (ret) {
14201         case 0:
14202                 break;
14203         case -EINVAL:
14204                 printf("invalid vf_id %d\n", res->vf_id);
14205                 break;
14206         case -ENODEV:
14207                 printf("invalid port_id %d\n", res->port_id);
14208                 break;
14209         case -ENOTSUP:
14210                 printf("function not implemented\n");
14211                 break;
14212         default:
14213                 printf("programming error: (%s)\n", strerror(-ret));
14214         }
14215 }
14216
14217 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14218         .f = cmd_set_vf_allmulti_parsed,
14219         .data = NULL,
14220         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14221                 "Set multicast promiscuous mode for a VF from the PF",
14222         .tokens = {
14223                 (void *)&cmd_vf_allmulti_set,
14224                 (void *)&cmd_vf_allmulti_vf,
14225                 (void *)&cmd_vf_allmulti_allmulti,
14226                 (void *)&cmd_vf_allmulti_port_id,
14227                 (void *)&cmd_vf_allmulti_vf_id,
14228                 (void *)&cmd_vf_allmulti_on_off,
14229                 NULL,
14230         },
14231 };
14232
14233 /* vf broadcast mode configuration */
14234
14235 /* Common result structure for vf broadcast */
14236 struct cmd_set_vf_broadcast_result {
14237         cmdline_fixed_string_t set;
14238         cmdline_fixed_string_t vf;
14239         cmdline_fixed_string_t broadcast;
14240         portid_t port_id;
14241         uint16_t vf_id;
14242         cmdline_fixed_string_t on_off;
14243 };
14244
14245 /* Common CLI fields for vf broadcast enable disable */
14246 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14247         TOKEN_STRING_INITIALIZER
14248                 (struct cmd_set_vf_broadcast_result,
14249                  set, "set");
14250 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14251         TOKEN_STRING_INITIALIZER
14252                 (struct cmd_set_vf_broadcast_result,
14253                  vf, "vf");
14254 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14255         TOKEN_STRING_INITIALIZER
14256                 (struct cmd_set_vf_broadcast_result,
14257                  broadcast, "broadcast");
14258 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14259         TOKEN_NUM_INITIALIZER
14260                 (struct cmd_set_vf_broadcast_result,
14261                  port_id, UINT16);
14262 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14263         TOKEN_NUM_INITIALIZER
14264                 (struct cmd_set_vf_broadcast_result,
14265                  vf_id, UINT16);
14266 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14267         TOKEN_STRING_INITIALIZER
14268                 (struct cmd_set_vf_broadcast_result,
14269                  on_off, "on#off");
14270
14271 static void
14272 cmd_set_vf_broadcast_parsed(
14273         void *parsed_result,
14274         __attribute__((unused)) struct cmdline *cl,
14275         __attribute__((unused)) void *data)
14276 {
14277         struct cmd_set_vf_broadcast_result *res = parsed_result;
14278         int ret = -ENOTSUP;
14279
14280         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14281
14282         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14283                 return;
14284
14285 #ifdef RTE_LIBRTE_I40E_PMD
14286         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14287                                             res->vf_id, is_on);
14288 #endif
14289
14290         switch (ret) {
14291         case 0:
14292                 break;
14293         case -EINVAL:
14294                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14295                 break;
14296         case -ENODEV:
14297                 printf("invalid port_id %d\n", res->port_id);
14298                 break;
14299         case -ENOTSUP:
14300                 printf("function not implemented\n");
14301                 break;
14302         default:
14303                 printf("programming error: (%s)\n", strerror(-ret));
14304         }
14305 }
14306
14307 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14308         .f = cmd_set_vf_broadcast_parsed,
14309         .data = NULL,
14310         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14311         .tokens = {
14312                 (void *)&cmd_set_vf_broadcast_set,
14313                 (void *)&cmd_set_vf_broadcast_vf,
14314                 (void *)&cmd_set_vf_broadcast_broadcast,
14315                 (void *)&cmd_set_vf_broadcast_port_id,
14316                 (void *)&cmd_set_vf_broadcast_vf_id,
14317                 (void *)&cmd_set_vf_broadcast_on_off,
14318                 NULL,
14319         },
14320 };
14321
14322 /* vf vlan tag configuration */
14323
14324 /* Common result structure for vf vlan tag */
14325 struct cmd_set_vf_vlan_tag_result {
14326         cmdline_fixed_string_t set;
14327         cmdline_fixed_string_t vf;
14328         cmdline_fixed_string_t vlan;
14329         cmdline_fixed_string_t tag;
14330         portid_t port_id;
14331         uint16_t vf_id;
14332         cmdline_fixed_string_t on_off;
14333 };
14334
14335 /* Common CLI fields for vf vlan tag enable disable */
14336 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14337         TOKEN_STRING_INITIALIZER
14338                 (struct cmd_set_vf_vlan_tag_result,
14339                  set, "set");
14340 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14341         TOKEN_STRING_INITIALIZER
14342                 (struct cmd_set_vf_vlan_tag_result,
14343                  vf, "vf");
14344 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14345         TOKEN_STRING_INITIALIZER
14346                 (struct cmd_set_vf_vlan_tag_result,
14347                  vlan, "vlan");
14348 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14349         TOKEN_STRING_INITIALIZER
14350                 (struct cmd_set_vf_vlan_tag_result,
14351                  tag, "tag");
14352 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14353         TOKEN_NUM_INITIALIZER
14354                 (struct cmd_set_vf_vlan_tag_result,
14355                  port_id, UINT16);
14356 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14357         TOKEN_NUM_INITIALIZER
14358                 (struct cmd_set_vf_vlan_tag_result,
14359                  vf_id, UINT16);
14360 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14361         TOKEN_STRING_INITIALIZER
14362                 (struct cmd_set_vf_vlan_tag_result,
14363                  on_off, "on#off");
14364
14365 static void
14366 cmd_set_vf_vlan_tag_parsed(
14367         void *parsed_result,
14368         __attribute__((unused)) struct cmdline *cl,
14369         __attribute__((unused)) void *data)
14370 {
14371         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14372         int ret = -ENOTSUP;
14373
14374         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14375
14376         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14377                 return;
14378
14379 #ifdef RTE_LIBRTE_I40E_PMD
14380         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14381                                            res->vf_id, is_on);
14382 #endif
14383
14384         switch (ret) {
14385         case 0:
14386                 break;
14387         case -EINVAL:
14388                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14389                 break;
14390         case -ENODEV:
14391                 printf("invalid port_id %d\n", res->port_id);
14392                 break;
14393         case -ENOTSUP:
14394                 printf("function not implemented\n");
14395                 break;
14396         default:
14397                 printf("programming error: (%s)\n", strerror(-ret));
14398         }
14399 }
14400
14401 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14402         .f = cmd_set_vf_vlan_tag_parsed,
14403         .data = NULL,
14404         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14405         .tokens = {
14406                 (void *)&cmd_set_vf_vlan_tag_set,
14407                 (void *)&cmd_set_vf_vlan_tag_vf,
14408                 (void *)&cmd_set_vf_vlan_tag_vlan,
14409                 (void *)&cmd_set_vf_vlan_tag_tag,
14410                 (void *)&cmd_set_vf_vlan_tag_port_id,
14411                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14412                 (void *)&cmd_set_vf_vlan_tag_on_off,
14413                 NULL,
14414         },
14415 };
14416
14417 /* Common definition of VF and TC TX bandwidth configuration */
14418 struct cmd_vf_tc_bw_result {
14419         cmdline_fixed_string_t set;
14420         cmdline_fixed_string_t vf;
14421         cmdline_fixed_string_t tc;
14422         cmdline_fixed_string_t tx;
14423         cmdline_fixed_string_t min_bw;
14424         cmdline_fixed_string_t max_bw;
14425         cmdline_fixed_string_t strict_link_prio;
14426         portid_t port_id;
14427         uint16_t vf_id;
14428         uint8_t tc_no;
14429         uint32_t bw;
14430         cmdline_fixed_string_t bw_list;
14431         uint8_t tc_map;
14432 };
14433
14434 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14435         TOKEN_STRING_INITIALIZER
14436                 (struct cmd_vf_tc_bw_result,
14437                  set, "set");
14438 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14439         TOKEN_STRING_INITIALIZER
14440                 (struct cmd_vf_tc_bw_result,
14441                  vf, "vf");
14442 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14443         TOKEN_STRING_INITIALIZER
14444                 (struct cmd_vf_tc_bw_result,
14445                  tc, "tc");
14446 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14447         TOKEN_STRING_INITIALIZER
14448                 (struct cmd_vf_tc_bw_result,
14449                  tx, "tx");
14450 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14451         TOKEN_STRING_INITIALIZER
14452                 (struct cmd_vf_tc_bw_result,
14453                  strict_link_prio, "strict-link-priority");
14454 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14455         TOKEN_STRING_INITIALIZER
14456                 (struct cmd_vf_tc_bw_result,
14457                  min_bw, "min-bandwidth");
14458 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14459         TOKEN_STRING_INITIALIZER
14460                 (struct cmd_vf_tc_bw_result,
14461                  max_bw, "max-bandwidth");
14462 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14463         TOKEN_NUM_INITIALIZER
14464                 (struct cmd_vf_tc_bw_result,
14465                  port_id, UINT16);
14466 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14467         TOKEN_NUM_INITIALIZER
14468                 (struct cmd_vf_tc_bw_result,
14469                  vf_id, UINT16);
14470 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14471         TOKEN_NUM_INITIALIZER
14472                 (struct cmd_vf_tc_bw_result,
14473                  tc_no, UINT8);
14474 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14475         TOKEN_NUM_INITIALIZER
14476                 (struct cmd_vf_tc_bw_result,
14477                  bw, UINT32);
14478 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14479         TOKEN_STRING_INITIALIZER
14480                 (struct cmd_vf_tc_bw_result,
14481                  bw_list, NULL);
14482 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14483         TOKEN_NUM_INITIALIZER
14484                 (struct cmd_vf_tc_bw_result,
14485                  tc_map, UINT8);
14486
14487 /* VF max bandwidth setting */
14488 static void
14489 cmd_vf_max_bw_parsed(
14490         void *parsed_result,
14491         __attribute__((unused)) struct cmdline *cl,
14492         __attribute__((unused)) void *data)
14493 {
14494         struct cmd_vf_tc_bw_result *res = parsed_result;
14495         int ret = -ENOTSUP;
14496
14497         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14498                 return;
14499
14500 #ifdef RTE_LIBRTE_I40E_PMD
14501         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14502                                          res->vf_id, res->bw);
14503 #endif
14504
14505         switch (ret) {
14506         case 0:
14507                 break;
14508         case -EINVAL:
14509                 printf("invalid vf_id %d or bandwidth %d\n",
14510                        res->vf_id, res->bw);
14511                 break;
14512         case -ENODEV:
14513                 printf("invalid port_id %d\n", res->port_id);
14514                 break;
14515         case -ENOTSUP:
14516                 printf("function not implemented\n");
14517                 break;
14518         default:
14519                 printf("programming error: (%s)\n", strerror(-ret));
14520         }
14521 }
14522
14523 cmdline_parse_inst_t cmd_vf_max_bw = {
14524         .f = cmd_vf_max_bw_parsed,
14525         .data = NULL,
14526         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14527         .tokens = {
14528                 (void *)&cmd_vf_tc_bw_set,
14529                 (void *)&cmd_vf_tc_bw_vf,
14530                 (void *)&cmd_vf_tc_bw_tx,
14531                 (void *)&cmd_vf_tc_bw_max_bw,
14532                 (void *)&cmd_vf_tc_bw_port_id,
14533                 (void *)&cmd_vf_tc_bw_vf_id,
14534                 (void *)&cmd_vf_tc_bw_bw,
14535                 NULL,
14536         },
14537 };
14538
14539 static int
14540 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14541                            uint8_t *tc_num,
14542                            char *str)
14543 {
14544         uint32_t size;
14545         const char *p, *p0 = str;
14546         char s[256];
14547         char *end;
14548         char *str_fld[16];
14549         uint16_t i;
14550         int ret;
14551
14552         p = strchr(p0, '(');
14553         if (p == NULL) {
14554                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14555                 return -1;
14556         }
14557         p++;
14558         p0 = strchr(p, ')');
14559         if (p0 == NULL) {
14560                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14561                 return -1;
14562         }
14563         size = p0 - p;
14564         if (size >= sizeof(s)) {
14565                 printf("The string size exceeds the internal buffer size\n");
14566                 return -1;
14567         }
14568         snprintf(s, sizeof(s), "%.*s", size, p);
14569         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14570         if (ret <= 0) {
14571                 printf("Failed to get the bandwidth list. ");
14572                 return -1;
14573         }
14574         *tc_num = ret;
14575         for (i = 0; i < ret; i++)
14576                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14577
14578         return 0;
14579 }
14580
14581 /* TC min bandwidth setting */
14582 static void
14583 cmd_vf_tc_min_bw_parsed(
14584         void *parsed_result,
14585         __attribute__((unused)) struct cmdline *cl,
14586         __attribute__((unused)) void *data)
14587 {
14588         struct cmd_vf_tc_bw_result *res = parsed_result;
14589         uint8_t tc_num;
14590         uint8_t bw[16];
14591         int ret = -ENOTSUP;
14592
14593         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14594                 return;
14595
14596         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14597         if (ret)
14598                 return;
14599
14600 #ifdef RTE_LIBRTE_I40E_PMD
14601         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14602                                               tc_num, bw);
14603 #endif
14604
14605         switch (ret) {
14606         case 0:
14607                 break;
14608         case -EINVAL:
14609                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14610                 break;
14611         case -ENODEV:
14612                 printf("invalid port_id %d\n", res->port_id);
14613                 break;
14614         case -ENOTSUP:
14615                 printf("function not implemented\n");
14616                 break;
14617         default:
14618                 printf("programming error: (%s)\n", strerror(-ret));
14619         }
14620 }
14621
14622 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14623         .f = cmd_vf_tc_min_bw_parsed,
14624         .data = NULL,
14625         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14626                     " <bw1, bw2, ...>",
14627         .tokens = {
14628                 (void *)&cmd_vf_tc_bw_set,
14629                 (void *)&cmd_vf_tc_bw_vf,
14630                 (void *)&cmd_vf_tc_bw_tc,
14631                 (void *)&cmd_vf_tc_bw_tx,
14632                 (void *)&cmd_vf_tc_bw_min_bw,
14633                 (void *)&cmd_vf_tc_bw_port_id,
14634                 (void *)&cmd_vf_tc_bw_vf_id,
14635                 (void *)&cmd_vf_tc_bw_bw_list,
14636                 NULL,
14637         },
14638 };
14639
14640 static void
14641 cmd_tc_min_bw_parsed(
14642         void *parsed_result,
14643         __attribute__((unused)) struct cmdline *cl,
14644         __attribute__((unused)) void *data)
14645 {
14646         struct cmd_vf_tc_bw_result *res = parsed_result;
14647         struct rte_port *port;
14648         uint8_t tc_num;
14649         uint8_t bw[16];
14650         int ret = -ENOTSUP;
14651
14652         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14653                 return;
14654
14655         port = &ports[res->port_id];
14656         /** Check if the port is not started **/
14657         if (port->port_status != RTE_PORT_STOPPED) {
14658                 printf("Please stop port %d first\n", res->port_id);
14659                 return;
14660         }
14661
14662         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14663         if (ret)
14664                 return;
14665
14666 #ifdef RTE_LIBRTE_IXGBE_PMD
14667         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14668 #endif
14669
14670         switch (ret) {
14671         case 0:
14672                 break;
14673         case -EINVAL:
14674                 printf("invalid bandwidth\n");
14675                 break;
14676         case -ENODEV:
14677                 printf("invalid port_id %d\n", res->port_id);
14678                 break;
14679         case -ENOTSUP:
14680                 printf("function not implemented\n");
14681                 break;
14682         default:
14683                 printf("programming error: (%s)\n", strerror(-ret));
14684         }
14685 }
14686
14687 cmdline_parse_inst_t cmd_tc_min_bw = {
14688         .f = cmd_tc_min_bw_parsed,
14689         .data = NULL,
14690         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14691         .tokens = {
14692                 (void *)&cmd_vf_tc_bw_set,
14693                 (void *)&cmd_vf_tc_bw_tc,
14694                 (void *)&cmd_vf_tc_bw_tx,
14695                 (void *)&cmd_vf_tc_bw_min_bw,
14696                 (void *)&cmd_vf_tc_bw_port_id,
14697                 (void *)&cmd_vf_tc_bw_bw_list,
14698                 NULL,
14699         },
14700 };
14701
14702 /* TC max bandwidth setting */
14703 static void
14704 cmd_vf_tc_max_bw_parsed(
14705         void *parsed_result,
14706         __attribute__((unused)) struct cmdline *cl,
14707         __attribute__((unused)) void *data)
14708 {
14709         struct cmd_vf_tc_bw_result *res = parsed_result;
14710         int ret = -ENOTSUP;
14711
14712         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14713                 return;
14714
14715 #ifdef RTE_LIBRTE_I40E_PMD
14716         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14717                                             res->tc_no, res->bw);
14718 #endif
14719
14720         switch (ret) {
14721         case 0:
14722                 break;
14723         case -EINVAL:
14724                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14725                        res->vf_id, res->tc_no, res->bw);
14726                 break;
14727         case -ENODEV:
14728                 printf("invalid port_id %d\n", res->port_id);
14729                 break;
14730         case -ENOTSUP:
14731                 printf("function not implemented\n");
14732                 break;
14733         default:
14734                 printf("programming error: (%s)\n", strerror(-ret));
14735         }
14736 }
14737
14738 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14739         .f = cmd_vf_tc_max_bw_parsed,
14740         .data = NULL,
14741         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14742                     " <bandwidth>",
14743         .tokens = {
14744                 (void *)&cmd_vf_tc_bw_set,
14745                 (void *)&cmd_vf_tc_bw_vf,
14746                 (void *)&cmd_vf_tc_bw_tc,
14747                 (void *)&cmd_vf_tc_bw_tx,
14748                 (void *)&cmd_vf_tc_bw_max_bw,
14749                 (void *)&cmd_vf_tc_bw_port_id,
14750                 (void *)&cmd_vf_tc_bw_vf_id,
14751                 (void *)&cmd_vf_tc_bw_tc_no,
14752                 (void *)&cmd_vf_tc_bw_bw,
14753                 NULL,
14754         },
14755 };
14756
14757
14758 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14759
14760 /* *** Set Port default Traffic Management Hierarchy *** */
14761 struct cmd_set_port_tm_hierarchy_default_result {
14762         cmdline_fixed_string_t set;
14763         cmdline_fixed_string_t port;
14764         cmdline_fixed_string_t tm;
14765         cmdline_fixed_string_t hierarchy;
14766         cmdline_fixed_string_t def;
14767         portid_t port_id;
14768 };
14769
14770 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14771         TOKEN_STRING_INITIALIZER(
14772                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14773 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14774         TOKEN_STRING_INITIALIZER(
14775                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14776 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14777         TOKEN_STRING_INITIALIZER(
14778                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14779 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14780         TOKEN_STRING_INITIALIZER(
14781                 struct cmd_set_port_tm_hierarchy_default_result,
14782                         hierarchy, "hierarchy");
14783 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14784         TOKEN_STRING_INITIALIZER(
14785                 struct cmd_set_port_tm_hierarchy_default_result,
14786                         def, "default");
14787 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14788         TOKEN_NUM_INITIALIZER(
14789                 struct cmd_set_port_tm_hierarchy_default_result,
14790                         port_id, UINT16);
14791
14792 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14793         __attribute__((unused)) struct cmdline *cl,
14794         __attribute__((unused)) void *data)
14795 {
14796         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14797         struct rte_port *p;
14798         portid_t port_id = res->port_id;
14799
14800         if (port_id_is_invalid(port_id, ENABLED_WARN))
14801                 return;
14802
14803         p = &ports[port_id];
14804
14805         /* Port tm flag */
14806         if (p->softport.tm_flag == 0) {
14807                 printf("  tm not enabled on port %u (error)\n", port_id);
14808                 return;
14809         }
14810
14811         /* Forward mode: tm */
14812         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14813                 printf("  tm mode not enabled(error)\n");
14814                 return;
14815         }
14816
14817         /* Set the default tm hierarchy */
14818         p->softport.tm.default_hierarchy_enable = 1;
14819 }
14820
14821 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14822         .f = cmd_set_port_tm_hierarchy_default_parsed,
14823         .data = NULL,
14824         .help_str = "set port tm hierarchy default <port_id>",
14825         .tokens = {
14826                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14827                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14828                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14829                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14830                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14831                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14832                 NULL,
14833         },
14834 };
14835 #endif
14836
14837 /* Strict link priority scheduling mode setting */
14838 static void
14839 cmd_strict_link_prio_parsed(
14840         void *parsed_result,
14841         __attribute__((unused)) struct cmdline *cl,
14842         __attribute__((unused)) void *data)
14843 {
14844         struct cmd_vf_tc_bw_result *res = parsed_result;
14845         int ret = -ENOTSUP;
14846
14847         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14848                 return;
14849
14850 #ifdef RTE_LIBRTE_I40E_PMD
14851         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14852 #endif
14853
14854         switch (ret) {
14855         case 0:
14856                 break;
14857         case -EINVAL:
14858                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14859                 break;
14860         case -ENODEV:
14861                 printf("invalid port_id %d\n", res->port_id);
14862                 break;
14863         case -ENOTSUP:
14864                 printf("function not implemented\n");
14865                 break;
14866         default:
14867                 printf("programming error: (%s)\n", strerror(-ret));
14868         }
14869 }
14870
14871 cmdline_parse_inst_t cmd_strict_link_prio = {
14872         .f = cmd_strict_link_prio_parsed,
14873         .data = NULL,
14874         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14875         .tokens = {
14876                 (void *)&cmd_vf_tc_bw_set,
14877                 (void *)&cmd_vf_tc_bw_tx,
14878                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14879                 (void *)&cmd_vf_tc_bw_port_id,
14880                 (void *)&cmd_vf_tc_bw_tc_map,
14881                 NULL,
14882         },
14883 };
14884
14885 /* Load dynamic device personalization*/
14886 struct cmd_ddp_add_result {
14887         cmdline_fixed_string_t ddp;
14888         cmdline_fixed_string_t add;
14889         portid_t port_id;
14890         char filepath[];
14891 };
14892
14893 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14894         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14895 cmdline_parse_token_string_t cmd_ddp_add_add =
14896         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14897 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14898         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14899 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14900         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14901
14902 static void
14903 cmd_ddp_add_parsed(
14904         void *parsed_result,
14905         __attribute__((unused)) struct cmdline *cl,
14906         __attribute__((unused)) void *data)
14907 {
14908         struct cmd_ddp_add_result *res = parsed_result;
14909         uint8_t *buff;
14910         uint32_t size;
14911         char *filepath;
14912         char *file_fld[2];
14913         int file_num;
14914         int ret = -ENOTSUP;
14915
14916         if (!all_ports_stopped()) {
14917                 printf("Please stop all ports first\n");
14918                 return;
14919         }
14920
14921         filepath = strdup(res->filepath);
14922         if (filepath == NULL) {
14923                 printf("Failed to allocate memory\n");
14924                 return;
14925         }
14926         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14927
14928         buff = open_file(file_fld[0], &size);
14929         if (!buff) {
14930                 free((void *)filepath);
14931                 return;
14932         }
14933
14934 #ifdef RTE_LIBRTE_I40E_PMD
14935         if (ret == -ENOTSUP)
14936                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14937                                                buff, size,
14938                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14939 #endif
14940
14941         if (ret == -EEXIST)
14942                 printf("Profile has already existed.\n");
14943         else if (ret < 0)
14944                 printf("Failed to load profile.\n");
14945         else if (file_num == 2)
14946                 save_file(file_fld[1], buff, size);
14947
14948         close_file(buff);
14949         free((void *)filepath);
14950 }
14951
14952 cmdline_parse_inst_t cmd_ddp_add = {
14953         .f = cmd_ddp_add_parsed,
14954         .data = NULL,
14955         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14956         .tokens = {
14957                 (void *)&cmd_ddp_add_ddp,
14958                 (void *)&cmd_ddp_add_add,
14959                 (void *)&cmd_ddp_add_port_id,
14960                 (void *)&cmd_ddp_add_filepath,
14961                 NULL,
14962         },
14963 };
14964
14965 /* Delete dynamic device personalization*/
14966 struct cmd_ddp_del_result {
14967         cmdline_fixed_string_t ddp;
14968         cmdline_fixed_string_t del;
14969         portid_t port_id;
14970         char filepath[];
14971 };
14972
14973 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14974         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14975 cmdline_parse_token_string_t cmd_ddp_del_del =
14976         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14977 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14978         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14979 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14980         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14981
14982 static void
14983 cmd_ddp_del_parsed(
14984         void *parsed_result,
14985         __attribute__((unused)) struct cmdline *cl,
14986         __attribute__((unused)) void *data)
14987 {
14988         struct cmd_ddp_del_result *res = parsed_result;
14989         uint8_t *buff;
14990         uint32_t size;
14991         int ret = -ENOTSUP;
14992
14993         if (!all_ports_stopped()) {
14994                 printf("Please stop all ports first\n");
14995                 return;
14996         }
14997
14998         buff = open_file(res->filepath, &size);
14999         if (!buff)
15000                 return;
15001
15002 #ifdef RTE_LIBRTE_I40E_PMD
15003         if (ret == -ENOTSUP)
15004                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15005                                                buff, size,
15006                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15007 #endif
15008
15009         if (ret == -EACCES)
15010                 printf("Profile does not exist.\n");
15011         else if (ret < 0)
15012                 printf("Failed to delete profile.\n");
15013
15014         close_file(buff);
15015 }
15016
15017 cmdline_parse_inst_t cmd_ddp_del = {
15018         .f = cmd_ddp_del_parsed,
15019         .data = NULL,
15020         .help_str = "ddp del <port_id> <backup_profile_path>",
15021         .tokens = {
15022                 (void *)&cmd_ddp_del_ddp,
15023                 (void *)&cmd_ddp_del_del,
15024                 (void *)&cmd_ddp_del_port_id,
15025                 (void *)&cmd_ddp_del_filepath,
15026                 NULL,
15027         },
15028 };
15029
15030 /* Get dynamic device personalization profile info */
15031 struct cmd_ddp_info_result {
15032         cmdline_fixed_string_t ddp;
15033         cmdline_fixed_string_t get;
15034         cmdline_fixed_string_t info;
15035         char filepath[];
15036 };
15037
15038 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15039         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15040 cmdline_parse_token_string_t cmd_ddp_info_get =
15041         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15042 cmdline_parse_token_string_t cmd_ddp_info_info =
15043         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15044 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15045         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15046
15047 static void
15048 cmd_ddp_info_parsed(
15049         void *parsed_result,
15050         __attribute__((unused)) struct cmdline *cl,
15051         __attribute__((unused)) void *data)
15052 {
15053         struct cmd_ddp_info_result *res = parsed_result;
15054         uint8_t *pkg;
15055         uint32_t pkg_size;
15056         int ret = -ENOTSUP;
15057 #ifdef RTE_LIBRTE_I40E_PMD
15058         uint32_t i, j, n;
15059         uint8_t *buff;
15060         uint32_t buff_size = 0;
15061         struct rte_pmd_i40e_profile_info info;
15062         uint32_t dev_num = 0;
15063         struct rte_pmd_i40e_ddp_device_id *devs;
15064         uint32_t proto_num = 0;
15065         struct rte_pmd_i40e_proto_info *proto = NULL;
15066         uint32_t pctype_num = 0;
15067         struct rte_pmd_i40e_ptype_info *pctype;
15068         uint32_t ptype_num = 0;
15069         struct rte_pmd_i40e_ptype_info *ptype;
15070         uint8_t proto_id;
15071
15072 #endif
15073
15074         pkg = open_file(res->filepath, &pkg_size);
15075         if (!pkg)
15076                 return;
15077
15078 #ifdef RTE_LIBRTE_I40E_PMD
15079         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15080                                 (uint8_t *)&info, sizeof(info),
15081                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15082         if (!ret) {
15083                 printf("Global Track id:       0x%x\n", info.track_id);
15084                 printf("Global Version:        %d.%d.%d.%d\n",
15085                         info.version.major,
15086                         info.version.minor,
15087                         info.version.update,
15088                         info.version.draft);
15089                 printf("Global Package name:   %s\n\n", info.name);
15090         }
15091
15092         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15093                                 (uint8_t *)&info, sizeof(info),
15094                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15095         if (!ret) {
15096                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15097                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15098                         info.version.major,
15099                         info.version.minor,
15100                         info.version.update,
15101                         info.version.draft);
15102                 printf("i40e Profile name:     %s\n\n", info.name);
15103         }
15104
15105         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15106                                 (uint8_t *)&buff_size, sizeof(buff_size),
15107                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15108         if (!ret && buff_size) {
15109                 buff = (uint8_t *)malloc(buff_size);
15110                 if (buff) {
15111                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15112                                                 buff, buff_size,
15113                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15114                         if (!ret)
15115                                 printf("Package Notes:\n%s\n\n", buff);
15116                         free(buff);
15117                 }
15118         }
15119
15120         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15121                                 (uint8_t *)&dev_num, sizeof(dev_num),
15122                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15123         if (!ret && dev_num) {
15124                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15125                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15126                 if (devs) {
15127                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15128                                                 (uint8_t *)devs, buff_size,
15129                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15130                         if (!ret) {
15131                                 printf("List of supported devices:\n");
15132                                 for (i = 0; i < dev_num; i++) {
15133                                         printf("  %04X:%04X %04X:%04X\n",
15134                                                 devs[i].vendor_dev_id >> 16,
15135                                                 devs[i].vendor_dev_id & 0xFFFF,
15136                                                 devs[i].sub_vendor_dev_id >> 16,
15137                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15138                                 }
15139                                 printf("\n");
15140                         }
15141                         free(devs);
15142                 }
15143         }
15144
15145         /* get information about protocols and packet types */
15146         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15147                 (uint8_t *)&proto_num, sizeof(proto_num),
15148                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15149         if (ret || !proto_num)
15150                 goto no_print_return;
15151
15152         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15153         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15154         if (!proto)
15155                 goto no_print_return;
15156
15157         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15158                                         buff_size,
15159                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15160         if (!ret) {
15161                 printf("List of used protocols:\n");
15162                 for (i = 0; i < proto_num; i++)
15163                         printf("  %2u: %s\n", proto[i].proto_id,
15164                                proto[i].name);
15165                 printf("\n");
15166         }
15167         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15168                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15169                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15170         if (ret || !pctype_num)
15171                 goto no_print_pctypes;
15172
15173         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15174         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15175         if (!pctype)
15176                 goto no_print_pctypes;
15177
15178         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15179                                         buff_size,
15180                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15181         if (ret) {
15182                 free(pctype);
15183                 goto no_print_pctypes;
15184         }
15185
15186         printf("List of defined packet classification types:\n");
15187         for (i = 0; i < pctype_num; i++) {
15188                 printf("  %2u:", pctype[i].ptype_id);
15189                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15190                         proto_id = pctype[i].protocols[j];
15191                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15192                                 for (n = 0; n < proto_num; n++) {
15193                                         if (proto[n].proto_id == proto_id) {
15194                                                 printf(" %s", proto[n].name);
15195                                                 break;
15196                                         }
15197                                 }
15198                         }
15199                 }
15200                 printf("\n");
15201         }
15202         printf("\n");
15203         free(pctype);
15204
15205 no_print_pctypes:
15206
15207         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15208                                         sizeof(ptype_num),
15209                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15210         if (ret || !ptype_num)
15211                 goto no_print_return;
15212
15213         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15214         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15215         if (!ptype)
15216                 goto no_print_return;
15217
15218         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15219                                         buff_size,
15220                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15221         if (ret) {
15222                 free(ptype);
15223                 goto no_print_return;
15224         }
15225         printf("List of defined packet types:\n");
15226         for (i = 0; i < ptype_num; i++) {
15227                 printf("  %2u:", ptype[i].ptype_id);
15228                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15229                         proto_id = ptype[i].protocols[j];
15230                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15231                                 for (n = 0; n < proto_num; n++) {
15232                                         if (proto[n].proto_id == proto_id) {
15233                                                 printf(" %s", proto[n].name);
15234                                                 break;
15235                                         }
15236                                 }
15237                         }
15238                 }
15239                 printf("\n");
15240         }
15241         free(ptype);
15242         printf("\n");
15243
15244         ret = 0;
15245 no_print_return:
15246         if (proto)
15247                 free(proto);
15248 #endif
15249         if (ret == -ENOTSUP)
15250                 printf("Function not supported in PMD driver\n");
15251         close_file(pkg);
15252 }
15253
15254 cmdline_parse_inst_t cmd_ddp_get_info = {
15255         .f = cmd_ddp_info_parsed,
15256         .data = NULL,
15257         .help_str = "ddp get info <profile_path>",
15258         .tokens = {
15259                 (void *)&cmd_ddp_info_ddp,
15260                 (void *)&cmd_ddp_info_get,
15261                 (void *)&cmd_ddp_info_info,
15262                 (void *)&cmd_ddp_info_filepath,
15263                 NULL,
15264         },
15265 };
15266
15267 /* Get dynamic device personalization profile info list*/
15268 #define PROFILE_INFO_SIZE 48
15269 #define MAX_PROFILE_NUM 16
15270
15271 struct cmd_ddp_get_list_result {
15272         cmdline_fixed_string_t ddp;
15273         cmdline_fixed_string_t get;
15274         cmdline_fixed_string_t list;
15275         portid_t port_id;
15276 };
15277
15278 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15279         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15280 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15281         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15282 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15283         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15284 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15285         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15286
15287 static void
15288 cmd_ddp_get_list_parsed(
15289         __attribute__((unused)) void *parsed_result,
15290         __attribute__((unused)) struct cmdline *cl,
15291         __attribute__((unused)) void *data)
15292 {
15293 #ifdef RTE_LIBRTE_I40E_PMD
15294         struct cmd_ddp_get_list_result *res = parsed_result;
15295         struct rte_pmd_i40e_profile_list *p_list;
15296         struct rte_pmd_i40e_profile_info *p_info;
15297         uint32_t p_num;
15298         uint32_t size;
15299         uint32_t i;
15300 #endif
15301         int ret = -ENOTSUP;
15302
15303 #ifdef RTE_LIBRTE_I40E_PMD
15304         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15305         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15306         if (!p_list)
15307                 printf("%s: Failed to malloc buffer\n", __func__);
15308
15309         if (ret == -ENOTSUP)
15310                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15311                                                 (uint8_t *)p_list, size);
15312
15313         if (!ret) {
15314                 p_num = p_list->p_count;
15315                 printf("Profile number is: %d\n\n", p_num);
15316
15317                 for (i = 0; i < p_num; i++) {
15318                         p_info = &p_list->p_info[i];
15319                         printf("Profile %d:\n", i);
15320                         printf("Track id:     0x%x\n", p_info->track_id);
15321                         printf("Version:      %d.%d.%d.%d\n",
15322                                p_info->version.major,
15323                                p_info->version.minor,
15324                                p_info->version.update,
15325                                p_info->version.draft);
15326                         printf("Profile name: %s\n\n", p_info->name);
15327                 }
15328         }
15329
15330         free(p_list);
15331 #endif
15332
15333         if (ret < 0)
15334                 printf("Failed to get ddp list\n");
15335 }
15336
15337 cmdline_parse_inst_t cmd_ddp_get_list = {
15338         .f = cmd_ddp_get_list_parsed,
15339         .data = NULL,
15340         .help_str = "ddp get list <port_id>",
15341         .tokens = {
15342                 (void *)&cmd_ddp_get_list_ddp,
15343                 (void *)&cmd_ddp_get_list_get,
15344                 (void *)&cmd_ddp_get_list_list,
15345                 (void *)&cmd_ddp_get_list_port_id,
15346                 NULL,
15347         },
15348 };
15349
15350 /* Configure input set */
15351 struct cmd_cfg_input_set_result {
15352         cmdline_fixed_string_t port;
15353         cmdline_fixed_string_t cfg;
15354         portid_t port_id;
15355         cmdline_fixed_string_t pctype;
15356         uint8_t pctype_id;
15357         cmdline_fixed_string_t inset_type;
15358         cmdline_fixed_string_t opt;
15359         cmdline_fixed_string_t field;
15360         uint8_t field_idx;
15361 };
15362
15363 static void
15364 cmd_cfg_input_set_parsed(
15365         __attribute__((unused)) void *parsed_result,
15366         __attribute__((unused)) struct cmdline *cl,
15367         __attribute__((unused)) void *data)
15368 {
15369 #ifdef RTE_LIBRTE_I40E_PMD
15370         struct cmd_cfg_input_set_result *res = parsed_result;
15371         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15372         struct rte_pmd_i40e_inset inset;
15373 #endif
15374         int ret = -ENOTSUP;
15375
15376         if (!all_ports_stopped()) {
15377                 printf("Please stop all ports first\n");
15378                 return;
15379         }
15380
15381 #ifdef RTE_LIBRTE_I40E_PMD
15382         if (!strcmp(res->inset_type, "hash_inset"))
15383                 inset_type = INSET_HASH;
15384         else if (!strcmp(res->inset_type, "fdir_inset"))
15385                 inset_type = INSET_FDIR;
15386         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15387                 inset_type = INSET_FDIR_FLX;
15388         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15389                                      &inset, inset_type);
15390         if (ret) {
15391                 printf("Failed to get input set.\n");
15392                 return;
15393         }
15394
15395         if (!strcmp(res->opt, "get")) {
15396                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15397                                                    res->field_idx);
15398                 if (ret)
15399                         printf("Field index %d is enabled.\n", res->field_idx);
15400                 else
15401                         printf("Field index %d is disabled.\n", res->field_idx);
15402                 return;
15403         } else if (!strcmp(res->opt, "set"))
15404                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15405                                                    res->field_idx);
15406         else if (!strcmp(res->opt, "clear"))
15407                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15408                                                      res->field_idx);
15409         if (ret) {
15410                 printf("Failed to configure input set field.\n");
15411                 return;
15412         }
15413
15414         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15415                                      &inset, inset_type);
15416         if (ret) {
15417                 printf("Failed to set input set.\n");
15418                 return;
15419         }
15420 #endif
15421
15422         if (ret == -ENOTSUP)
15423                 printf("Function not supported\n");
15424 }
15425
15426 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15427         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15428                                  port, "port");
15429 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15430         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15431                                  cfg, "config");
15432 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15433         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15434                               port_id, UINT16);
15435 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15436         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15437                                  pctype, "pctype");
15438 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15439         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15440                               pctype_id, UINT8);
15441 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15442         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15443                                  inset_type,
15444                                  "hash_inset#fdir_inset#fdir_flx_inset");
15445 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15446         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15447                                  opt, "get#set#clear");
15448 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15449         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15450                                  field, "field");
15451 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15452         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15453                               field_idx, UINT8);
15454
15455 cmdline_parse_inst_t cmd_cfg_input_set = {
15456         .f = cmd_cfg_input_set_parsed,
15457         .data = NULL,
15458         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15459                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15460         .tokens = {
15461                 (void *)&cmd_cfg_input_set_port,
15462                 (void *)&cmd_cfg_input_set_cfg,
15463                 (void *)&cmd_cfg_input_set_port_id,
15464                 (void *)&cmd_cfg_input_set_pctype,
15465                 (void *)&cmd_cfg_input_set_pctype_id,
15466                 (void *)&cmd_cfg_input_set_inset_type,
15467                 (void *)&cmd_cfg_input_set_opt,
15468                 (void *)&cmd_cfg_input_set_field,
15469                 (void *)&cmd_cfg_input_set_field_idx,
15470                 NULL,
15471         },
15472 };
15473
15474 /* Clear input set */
15475 struct cmd_clear_input_set_result {
15476         cmdline_fixed_string_t port;
15477         cmdline_fixed_string_t cfg;
15478         portid_t port_id;
15479         cmdline_fixed_string_t pctype;
15480         uint8_t pctype_id;
15481         cmdline_fixed_string_t inset_type;
15482         cmdline_fixed_string_t clear;
15483         cmdline_fixed_string_t all;
15484 };
15485
15486 static void
15487 cmd_clear_input_set_parsed(
15488         __attribute__((unused)) void *parsed_result,
15489         __attribute__((unused)) struct cmdline *cl,
15490         __attribute__((unused)) void *data)
15491 {
15492 #ifdef RTE_LIBRTE_I40E_PMD
15493         struct cmd_clear_input_set_result *res = parsed_result;
15494         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15495         struct rte_pmd_i40e_inset inset;
15496 #endif
15497         int ret = -ENOTSUP;
15498
15499         if (!all_ports_stopped()) {
15500                 printf("Please stop all ports first\n");
15501                 return;
15502         }
15503
15504 #ifdef RTE_LIBRTE_I40E_PMD
15505         if (!strcmp(res->inset_type, "hash_inset"))
15506                 inset_type = INSET_HASH;
15507         else if (!strcmp(res->inset_type, "fdir_inset"))
15508                 inset_type = INSET_FDIR;
15509         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15510                 inset_type = INSET_FDIR_FLX;
15511
15512         memset(&inset, 0, sizeof(inset));
15513
15514         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15515                                      &inset, inset_type);
15516         if (ret) {
15517                 printf("Failed to clear input set.\n");
15518                 return;
15519         }
15520
15521 #endif
15522
15523         if (ret == -ENOTSUP)
15524                 printf("Function not supported\n");
15525 }
15526
15527 cmdline_parse_token_string_t cmd_clear_input_set_port =
15528         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15529                                  port, "port");
15530 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15531         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15532                                  cfg, "config");
15533 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15534         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15535                               port_id, UINT16);
15536 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15537         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15538                                  pctype, "pctype");
15539 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15540         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15541                               pctype_id, UINT8);
15542 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15543         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15544                                  inset_type,
15545                                  "hash_inset#fdir_inset#fdir_flx_inset");
15546 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15547         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15548                                  clear, "clear");
15549 cmdline_parse_token_string_t cmd_clear_input_set_all =
15550         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15551                                  all, "all");
15552
15553 cmdline_parse_inst_t cmd_clear_input_set = {
15554         .f = cmd_clear_input_set_parsed,
15555         .data = NULL,
15556         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15557                     "fdir_inset|fdir_flx_inset clear all",
15558         .tokens = {
15559                 (void *)&cmd_clear_input_set_port,
15560                 (void *)&cmd_clear_input_set_cfg,
15561                 (void *)&cmd_clear_input_set_port_id,
15562                 (void *)&cmd_clear_input_set_pctype,
15563                 (void *)&cmd_clear_input_set_pctype_id,
15564                 (void *)&cmd_clear_input_set_inset_type,
15565                 (void *)&cmd_clear_input_set_clear,
15566                 (void *)&cmd_clear_input_set_all,
15567                 NULL,
15568         },
15569 };
15570
15571 /* show vf stats */
15572
15573 /* Common result structure for show vf stats */
15574 struct cmd_show_vf_stats_result {
15575         cmdline_fixed_string_t show;
15576         cmdline_fixed_string_t vf;
15577         cmdline_fixed_string_t stats;
15578         portid_t port_id;
15579         uint16_t vf_id;
15580 };
15581
15582 /* Common CLI fields show vf stats*/
15583 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15584         TOKEN_STRING_INITIALIZER
15585                 (struct cmd_show_vf_stats_result,
15586                  show, "show");
15587 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15588         TOKEN_STRING_INITIALIZER
15589                 (struct cmd_show_vf_stats_result,
15590                  vf, "vf");
15591 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15592         TOKEN_STRING_INITIALIZER
15593                 (struct cmd_show_vf_stats_result,
15594                  stats, "stats");
15595 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15596         TOKEN_NUM_INITIALIZER
15597                 (struct cmd_show_vf_stats_result,
15598                  port_id, UINT16);
15599 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15600         TOKEN_NUM_INITIALIZER
15601                 (struct cmd_show_vf_stats_result,
15602                  vf_id, UINT16);
15603
15604 static void
15605 cmd_show_vf_stats_parsed(
15606         void *parsed_result,
15607         __attribute__((unused)) struct cmdline *cl,
15608         __attribute__((unused)) void *data)
15609 {
15610         struct cmd_show_vf_stats_result *res = parsed_result;
15611         struct rte_eth_stats stats;
15612         int ret = -ENOTSUP;
15613         static const char *nic_stats_border = "########################";
15614
15615         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15616                 return;
15617
15618         memset(&stats, 0, sizeof(stats));
15619
15620 #ifdef RTE_LIBRTE_I40E_PMD
15621         if (ret == -ENOTSUP)
15622                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15623                                                 res->vf_id,
15624                                                 &stats);
15625 #endif
15626 #ifdef RTE_LIBRTE_BNXT_PMD
15627         if (ret == -ENOTSUP)
15628                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15629                                                 res->vf_id,
15630                                                 &stats);
15631 #endif
15632
15633         switch (ret) {
15634         case 0:
15635                 break;
15636         case -EINVAL:
15637                 printf("invalid vf_id %d\n", res->vf_id);
15638                 break;
15639         case -ENODEV:
15640                 printf("invalid port_id %d\n", res->port_id);
15641                 break;
15642         case -ENOTSUP:
15643                 printf("function not implemented\n");
15644                 break;
15645         default:
15646                 printf("programming error: (%s)\n", strerror(-ret));
15647         }
15648
15649         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15650                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15651
15652         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15653                "%-"PRIu64"\n",
15654                stats.ipackets, stats.imissed, stats.ibytes);
15655         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15656         printf("  RX-nombuf:  %-10"PRIu64"\n",
15657                stats.rx_nombuf);
15658         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15659                "%-"PRIu64"\n",
15660                stats.opackets, stats.oerrors, stats.obytes);
15661
15662         printf("  %s############################%s\n",
15663                                nic_stats_border, nic_stats_border);
15664 }
15665
15666 cmdline_parse_inst_t cmd_show_vf_stats = {
15667         .f = cmd_show_vf_stats_parsed,
15668         .data = NULL,
15669         .help_str = "show vf stats <port_id> <vf_id>",
15670         .tokens = {
15671                 (void *)&cmd_show_vf_stats_show,
15672                 (void *)&cmd_show_vf_stats_vf,
15673                 (void *)&cmd_show_vf_stats_stats,
15674                 (void *)&cmd_show_vf_stats_port_id,
15675                 (void *)&cmd_show_vf_stats_vf_id,
15676                 NULL,
15677         },
15678 };
15679
15680 /* clear vf stats */
15681
15682 /* Common result structure for clear vf stats */
15683 struct cmd_clear_vf_stats_result {
15684         cmdline_fixed_string_t clear;
15685         cmdline_fixed_string_t vf;
15686         cmdline_fixed_string_t stats;
15687         portid_t port_id;
15688         uint16_t vf_id;
15689 };
15690
15691 /* Common CLI fields clear vf stats*/
15692 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15693         TOKEN_STRING_INITIALIZER
15694                 (struct cmd_clear_vf_stats_result,
15695                  clear, "clear");
15696 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15697         TOKEN_STRING_INITIALIZER
15698                 (struct cmd_clear_vf_stats_result,
15699                  vf, "vf");
15700 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15701         TOKEN_STRING_INITIALIZER
15702                 (struct cmd_clear_vf_stats_result,
15703                  stats, "stats");
15704 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15705         TOKEN_NUM_INITIALIZER
15706                 (struct cmd_clear_vf_stats_result,
15707                  port_id, UINT16);
15708 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15709         TOKEN_NUM_INITIALIZER
15710                 (struct cmd_clear_vf_stats_result,
15711                  vf_id, UINT16);
15712
15713 static void
15714 cmd_clear_vf_stats_parsed(
15715         void *parsed_result,
15716         __attribute__((unused)) struct cmdline *cl,
15717         __attribute__((unused)) void *data)
15718 {
15719         struct cmd_clear_vf_stats_result *res = parsed_result;
15720         int ret = -ENOTSUP;
15721
15722         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15723                 return;
15724
15725 #ifdef RTE_LIBRTE_I40E_PMD
15726         if (ret == -ENOTSUP)
15727                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15728                                                   res->vf_id);
15729 #endif
15730 #ifdef RTE_LIBRTE_BNXT_PMD
15731         if (ret == -ENOTSUP)
15732                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15733                                                   res->vf_id);
15734 #endif
15735
15736         switch (ret) {
15737         case 0:
15738                 break;
15739         case -EINVAL:
15740                 printf("invalid vf_id %d\n", res->vf_id);
15741                 break;
15742         case -ENODEV:
15743                 printf("invalid port_id %d\n", res->port_id);
15744                 break;
15745         case -ENOTSUP:
15746                 printf("function not implemented\n");
15747                 break;
15748         default:
15749                 printf("programming error: (%s)\n", strerror(-ret));
15750         }
15751 }
15752
15753 cmdline_parse_inst_t cmd_clear_vf_stats = {
15754         .f = cmd_clear_vf_stats_parsed,
15755         .data = NULL,
15756         .help_str = "clear vf stats <port_id> <vf_id>",
15757         .tokens = {
15758                 (void *)&cmd_clear_vf_stats_clear,
15759                 (void *)&cmd_clear_vf_stats_vf,
15760                 (void *)&cmd_clear_vf_stats_stats,
15761                 (void *)&cmd_clear_vf_stats_port_id,
15762                 (void *)&cmd_clear_vf_stats_vf_id,
15763                 NULL,
15764         },
15765 };
15766
15767 /* port config pctype mapping reset */
15768
15769 /* Common result structure for port config pctype mapping reset */
15770 struct cmd_pctype_mapping_reset_result {
15771         cmdline_fixed_string_t port;
15772         cmdline_fixed_string_t config;
15773         portid_t port_id;
15774         cmdline_fixed_string_t pctype;
15775         cmdline_fixed_string_t mapping;
15776         cmdline_fixed_string_t reset;
15777 };
15778
15779 /* Common CLI fields for port config pctype mapping reset*/
15780 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15781         TOKEN_STRING_INITIALIZER
15782                 (struct cmd_pctype_mapping_reset_result,
15783                  port, "port");
15784 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15785         TOKEN_STRING_INITIALIZER
15786                 (struct cmd_pctype_mapping_reset_result,
15787                  config, "config");
15788 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15789         TOKEN_NUM_INITIALIZER
15790                 (struct cmd_pctype_mapping_reset_result,
15791                  port_id, UINT16);
15792 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15793         TOKEN_STRING_INITIALIZER
15794                 (struct cmd_pctype_mapping_reset_result,
15795                  pctype, "pctype");
15796 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15797         TOKEN_STRING_INITIALIZER
15798                 (struct cmd_pctype_mapping_reset_result,
15799                  mapping, "mapping");
15800 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15801         TOKEN_STRING_INITIALIZER
15802                 (struct cmd_pctype_mapping_reset_result,
15803                  reset, "reset");
15804
15805 static void
15806 cmd_pctype_mapping_reset_parsed(
15807         void *parsed_result,
15808         __attribute__((unused)) struct cmdline *cl,
15809         __attribute__((unused)) void *data)
15810 {
15811         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15812         int ret = -ENOTSUP;
15813
15814         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15815                 return;
15816
15817 #ifdef RTE_LIBRTE_I40E_PMD
15818         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15819 #endif
15820
15821         switch (ret) {
15822         case 0:
15823                 break;
15824         case -ENODEV:
15825                 printf("invalid port_id %d\n", res->port_id);
15826                 break;
15827         case -ENOTSUP:
15828                 printf("function not implemented\n");
15829                 break;
15830         default:
15831                 printf("programming error: (%s)\n", strerror(-ret));
15832         }
15833 }
15834
15835 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15836         .f = cmd_pctype_mapping_reset_parsed,
15837         .data = NULL,
15838         .help_str = "port config <port_id> pctype mapping reset",
15839         .tokens = {
15840                 (void *)&cmd_pctype_mapping_reset_port,
15841                 (void *)&cmd_pctype_mapping_reset_config,
15842                 (void *)&cmd_pctype_mapping_reset_port_id,
15843                 (void *)&cmd_pctype_mapping_reset_pctype,
15844                 (void *)&cmd_pctype_mapping_reset_mapping,
15845                 (void *)&cmd_pctype_mapping_reset_reset,
15846                 NULL,
15847         },
15848 };
15849
15850 /* show port pctype mapping */
15851
15852 /* Common result structure for show port pctype mapping */
15853 struct cmd_pctype_mapping_get_result {
15854         cmdline_fixed_string_t show;
15855         cmdline_fixed_string_t port;
15856         portid_t port_id;
15857         cmdline_fixed_string_t pctype;
15858         cmdline_fixed_string_t mapping;
15859 };
15860
15861 /* Common CLI fields for pctype mapping get */
15862 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15863         TOKEN_STRING_INITIALIZER
15864                 (struct cmd_pctype_mapping_get_result,
15865                  show, "show");
15866 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15867         TOKEN_STRING_INITIALIZER
15868                 (struct cmd_pctype_mapping_get_result,
15869                  port, "port");
15870 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15871         TOKEN_NUM_INITIALIZER
15872                 (struct cmd_pctype_mapping_get_result,
15873                  port_id, UINT16);
15874 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15875         TOKEN_STRING_INITIALIZER
15876                 (struct cmd_pctype_mapping_get_result,
15877                  pctype, "pctype");
15878 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15879         TOKEN_STRING_INITIALIZER
15880                 (struct cmd_pctype_mapping_get_result,
15881                  mapping, "mapping");
15882
15883 static void
15884 cmd_pctype_mapping_get_parsed(
15885         void *parsed_result,
15886         __attribute__((unused)) struct cmdline *cl,
15887         __attribute__((unused)) void *data)
15888 {
15889         struct cmd_pctype_mapping_get_result *res = parsed_result;
15890         int ret = -ENOTSUP;
15891 #ifdef RTE_LIBRTE_I40E_PMD
15892         struct rte_pmd_i40e_flow_type_mapping
15893                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15894         int i, j, first_pctype;
15895 #endif
15896
15897         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15898                 return;
15899
15900 #ifdef RTE_LIBRTE_I40E_PMD
15901         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15902 #endif
15903
15904         switch (ret) {
15905         case 0:
15906                 break;
15907         case -ENODEV:
15908                 printf("invalid port_id %d\n", res->port_id);
15909                 return;
15910         case -ENOTSUP:
15911                 printf("function not implemented\n");
15912                 return;
15913         default:
15914                 printf("programming error: (%s)\n", strerror(-ret));
15915                 return;
15916         }
15917
15918 #ifdef RTE_LIBRTE_I40E_PMD
15919         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15920                 if (mapping[i].pctype != 0ULL) {
15921                         first_pctype = 1;
15922
15923                         printf("pctype: ");
15924                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15925                                 if (mapping[i].pctype & (1ULL << j)) {
15926                                         printf(first_pctype ?
15927                                                "%02d" : ",%02d", j);
15928                                         first_pctype = 0;
15929                                 }
15930                         }
15931                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15932                 }
15933         }
15934 #endif
15935 }
15936
15937 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15938         .f = cmd_pctype_mapping_get_parsed,
15939         .data = NULL,
15940         .help_str = "show port <port_id> pctype mapping",
15941         .tokens = {
15942                 (void *)&cmd_pctype_mapping_get_show,
15943                 (void *)&cmd_pctype_mapping_get_port,
15944                 (void *)&cmd_pctype_mapping_get_port_id,
15945                 (void *)&cmd_pctype_mapping_get_pctype,
15946                 (void *)&cmd_pctype_mapping_get_mapping,
15947                 NULL,
15948         },
15949 };
15950
15951 /* port config pctype mapping update */
15952
15953 /* Common result structure for port config pctype mapping update */
15954 struct cmd_pctype_mapping_update_result {
15955         cmdline_fixed_string_t port;
15956         cmdline_fixed_string_t config;
15957         portid_t port_id;
15958         cmdline_fixed_string_t pctype;
15959         cmdline_fixed_string_t mapping;
15960         cmdline_fixed_string_t update;
15961         cmdline_fixed_string_t pctype_list;
15962         uint16_t flow_type;
15963 };
15964
15965 /* Common CLI fields for pctype mapping update*/
15966 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15967         TOKEN_STRING_INITIALIZER
15968                 (struct cmd_pctype_mapping_update_result,
15969                  port, "port");
15970 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15971         TOKEN_STRING_INITIALIZER
15972                 (struct cmd_pctype_mapping_update_result,
15973                  config, "config");
15974 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15975         TOKEN_NUM_INITIALIZER
15976                 (struct cmd_pctype_mapping_update_result,
15977                  port_id, UINT16);
15978 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15979         TOKEN_STRING_INITIALIZER
15980                 (struct cmd_pctype_mapping_update_result,
15981                  pctype, "pctype");
15982 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15983         TOKEN_STRING_INITIALIZER
15984                 (struct cmd_pctype_mapping_update_result,
15985                  mapping, "mapping");
15986 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15987         TOKEN_STRING_INITIALIZER
15988                 (struct cmd_pctype_mapping_update_result,
15989                  update, "update");
15990 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15991         TOKEN_STRING_INITIALIZER
15992                 (struct cmd_pctype_mapping_update_result,
15993                  pctype_list, NULL);
15994 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15995         TOKEN_NUM_INITIALIZER
15996                 (struct cmd_pctype_mapping_update_result,
15997                  flow_type, UINT16);
15998
15999 static void
16000 cmd_pctype_mapping_update_parsed(
16001         void *parsed_result,
16002         __attribute__((unused)) struct cmdline *cl,
16003         __attribute__((unused)) void *data)
16004 {
16005         struct cmd_pctype_mapping_update_result *res = parsed_result;
16006         int ret = -ENOTSUP;
16007 #ifdef RTE_LIBRTE_I40E_PMD
16008         struct rte_pmd_i40e_flow_type_mapping mapping;
16009         unsigned int i;
16010         unsigned int nb_item;
16011         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16012 #endif
16013
16014         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16015                 return;
16016
16017 #ifdef RTE_LIBRTE_I40E_PMD
16018         nb_item = parse_item_list(res->pctype_list, "pctypes",
16019                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16020         mapping.flow_type = res->flow_type;
16021         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16022                 mapping.pctype |= (1ULL << pctype_list[i]);
16023         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16024                                                 &mapping,
16025                                                 1,
16026                                                 0);
16027 #endif
16028
16029         switch (ret) {
16030         case 0:
16031                 break;
16032         case -EINVAL:
16033                 printf("invalid pctype or flow type\n");
16034                 break;
16035         case -ENODEV:
16036                 printf("invalid port_id %d\n", res->port_id);
16037                 break;
16038         case -ENOTSUP:
16039                 printf("function not implemented\n");
16040                 break;
16041         default:
16042                 printf("programming error: (%s)\n", strerror(-ret));
16043         }
16044 }
16045
16046 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16047         .f = cmd_pctype_mapping_update_parsed,
16048         .data = NULL,
16049         .help_str = "port config <port_id> pctype mapping update"
16050         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16051         .tokens = {
16052                 (void *)&cmd_pctype_mapping_update_port,
16053                 (void *)&cmd_pctype_mapping_update_config,
16054                 (void *)&cmd_pctype_mapping_update_port_id,
16055                 (void *)&cmd_pctype_mapping_update_pctype,
16056                 (void *)&cmd_pctype_mapping_update_mapping,
16057                 (void *)&cmd_pctype_mapping_update_update,
16058                 (void *)&cmd_pctype_mapping_update_pc_type,
16059                 (void *)&cmd_pctype_mapping_update_flow_type,
16060                 NULL,
16061         },
16062 };
16063
16064 /* ptype mapping get */
16065
16066 /* Common result structure for ptype mapping get */
16067 struct cmd_ptype_mapping_get_result {
16068         cmdline_fixed_string_t ptype;
16069         cmdline_fixed_string_t mapping;
16070         cmdline_fixed_string_t get;
16071         portid_t port_id;
16072         uint8_t valid_only;
16073 };
16074
16075 /* Common CLI fields for ptype mapping get */
16076 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16077         TOKEN_STRING_INITIALIZER
16078                 (struct cmd_ptype_mapping_get_result,
16079                  ptype, "ptype");
16080 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16081         TOKEN_STRING_INITIALIZER
16082                 (struct cmd_ptype_mapping_get_result,
16083                  mapping, "mapping");
16084 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16085         TOKEN_STRING_INITIALIZER
16086                 (struct cmd_ptype_mapping_get_result,
16087                  get, "get");
16088 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16089         TOKEN_NUM_INITIALIZER
16090                 (struct cmd_ptype_mapping_get_result,
16091                  port_id, UINT16);
16092 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16093         TOKEN_NUM_INITIALIZER
16094                 (struct cmd_ptype_mapping_get_result,
16095                  valid_only, UINT8);
16096
16097 static void
16098 cmd_ptype_mapping_get_parsed(
16099         void *parsed_result,
16100         __attribute__((unused)) struct cmdline *cl,
16101         __attribute__((unused)) void *data)
16102 {
16103         struct cmd_ptype_mapping_get_result *res = parsed_result;
16104         int ret = -ENOTSUP;
16105 #ifdef RTE_LIBRTE_I40E_PMD
16106         int max_ptype_num = 256;
16107         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16108         uint16_t count;
16109         int i;
16110 #endif
16111
16112         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16113                 return;
16114
16115 #ifdef RTE_LIBRTE_I40E_PMD
16116         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16117                                         mapping,
16118                                         max_ptype_num,
16119                                         &count,
16120                                         res->valid_only);
16121 #endif
16122
16123         switch (ret) {
16124         case 0:
16125                 break;
16126         case -ENODEV:
16127                 printf("invalid port_id %d\n", res->port_id);
16128                 break;
16129         case -ENOTSUP:
16130                 printf("function not implemented\n");
16131                 break;
16132         default:
16133                 printf("programming error: (%s)\n", strerror(-ret));
16134         }
16135
16136 #ifdef RTE_LIBRTE_I40E_PMD
16137         if (!ret) {
16138                 for (i = 0; i < count; i++)
16139                         printf("%3d\t0x%08x\n",
16140                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16141         }
16142 #endif
16143 }
16144
16145 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16146         .f = cmd_ptype_mapping_get_parsed,
16147         .data = NULL,
16148         .help_str = "ptype mapping get <port_id> <valid_only>",
16149         .tokens = {
16150                 (void *)&cmd_ptype_mapping_get_ptype,
16151                 (void *)&cmd_ptype_mapping_get_mapping,
16152                 (void *)&cmd_ptype_mapping_get_get,
16153                 (void *)&cmd_ptype_mapping_get_port_id,
16154                 (void *)&cmd_ptype_mapping_get_valid_only,
16155                 NULL,
16156         },
16157 };
16158
16159 /* ptype mapping replace */
16160
16161 /* Common result structure for ptype mapping replace */
16162 struct cmd_ptype_mapping_replace_result {
16163         cmdline_fixed_string_t ptype;
16164         cmdline_fixed_string_t mapping;
16165         cmdline_fixed_string_t replace;
16166         portid_t port_id;
16167         uint32_t target;
16168         uint8_t mask;
16169         uint32_t pkt_type;
16170 };
16171
16172 /* Common CLI fields for ptype mapping replace */
16173 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16174         TOKEN_STRING_INITIALIZER
16175                 (struct cmd_ptype_mapping_replace_result,
16176                  ptype, "ptype");
16177 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16178         TOKEN_STRING_INITIALIZER
16179                 (struct cmd_ptype_mapping_replace_result,
16180                  mapping, "mapping");
16181 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16182         TOKEN_STRING_INITIALIZER
16183                 (struct cmd_ptype_mapping_replace_result,
16184                  replace, "replace");
16185 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16186         TOKEN_NUM_INITIALIZER
16187                 (struct cmd_ptype_mapping_replace_result,
16188                  port_id, UINT16);
16189 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16190         TOKEN_NUM_INITIALIZER
16191                 (struct cmd_ptype_mapping_replace_result,
16192                  target, UINT32);
16193 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16194         TOKEN_NUM_INITIALIZER
16195                 (struct cmd_ptype_mapping_replace_result,
16196                  mask, UINT8);
16197 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16198         TOKEN_NUM_INITIALIZER
16199                 (struct cmd_ptype_mapping_replace_result,
16200                  pkt_type, UINT32);
16201
16202 static void
16203 cmd_ptype_mapping_replace_parsed(
16204         void *parsed_result,
16205         __attribute__((unused)) struct cmdline *cl,
16206         __attribute__((unused)) void *data)
16207 {
16208         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16209         int ret = -ENOTSUP;
16210
16211         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16212                 return;
16213
16214 #ifdef RTE_LIBRTE_I40E_PMD
16215         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16216                                         res->target,
16217                                         res->mask,
16218                                         res->pkt_type);
16219 #endif
16220
16221         switch (ret) {
16222         case 0:
16223                 break;
16224         case -EINVAL:
16225                 printf("invalid ptype 0x%8x or 0x%8x\n",
16226                                 res->target, res->pkt_type);
16227                 break;
16228         case -ENODEV:
16229                 printf("invalid port_id %d\n", res->port_id);
16230                 break;
16231         case -ENOTSUP:
16232                 printf("function not implemented\n");
16233                 break;
16234         default:
16235                 printf("programming error: (%s)\n", strerror(-ret));
16236         }
16237 }
16238
16239 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16240         .f = cmd_ptype_mapping_replace_parsed,
16241         .data = NULL,
16242         .help_str =
16243                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16244         .tokens = {
16245                 (void *)&cmd_ptype_mapping_replace_ptype,
16246                 (void *)&cmd_ptype_mapping_replace_mapping,
16247                 (void *)&cmd_ptype_mapping_replace_replace,
16248                 (void *)&cmd_ptype_mapping_replace_port_id,
16249                 (void *)&cmd_ptype_mapping_replace_target,
16250                 (void *)&cmd_ptype_mapping_replace_mask,
16251                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16252                 NULL,
16253         },
16254 };
16255
16256 /* ptype mapping reset */
16257
16258 /* Common result structure for ptype mapping reset */
16259 struct cmd_ptype_mapping_reset_result {
16260         cmdline_fixed_string_t ptype;
16261         cmdline_fixed_string_t mapping;
16262         cmdline_fixed_string_t reset;
16263         portid_t port_id;
16264 };
16265
16266 /* Common CLI fields for ptype mapping reset*/
16267 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16268         TOKEN_STRING_INITIALIZER
16269                 (struct cmd_ptype_mapping_reset_result,
16270                  ptype, "ptype");
16271 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16272         TOKEN_STRING_INITIALIZER
16273                 (struct cmd_ptype_mapping_reset_result,
16274                  mapping, "mapping");
16275 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16276         TOKEN_STRING_INITIALIZER
16277                 (struct cmd_ptype_mapping_reset_result,
16278                  reset, "reset");
16279 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16280         TOKEN_NUM_INITIALIZER
16281                 (struct cmd_ptype_mapping_reset_result,
16282                  port_id, UINT16);
16283
16284 static void
16285 cmd_ptype_mapping_reset_parsed(
16286         void *parsed_result,
16287         __attribute__((unused)) struct cmdline *cl,
16288         __attribute__((unused)) void *data)
16289 {
16290         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16291         int ret = -ENOTSUP;
16292
16293         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16294                 return;
16295
16296 #ifdef RTE_LIBRTE_I40E_PMD
16297         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16298 #endif
16299
16300         switch (ret) {
16301         case 0:
16302                 break;
16303         case -ENODEV:
16304                 printf("invalid port_id %d\n", res->port_id);
16305                 break;
16306         case -ENOTSUP:
16307                 printf("function not implemented\n");
16308                 break;
16309         default:
16310                 printf("programming error: (%s)\n", strerror(-ret));
16311         }
16312 }
16313
16314 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16315         .f = cmd_ptype_mapping_reset_parsed,
16316         .data = NULL,
16317         .help_str = "ptype mapping reset <port_id>",
16318         .tokens = {
16319                 (void *)&cmd_ptype_mapping_reset_ptype,
16320                 (void *)&cmd_ptype_mapping_reset_mapping,
16321                 (void *)&cmd_ptype_mapping_reset_reset,
16322                 (void *)&cmd_ptype_mapping_reset_port_id,
16323                 NULL,
16324         },
16325 };
16326
16327 /* ptype mapping update */
16328
16329 /* Common result structure for ptype mapping update */
16330 struct cmd_ptype_mapping_update_result {
16331         cmdline_fixed_string_t ptype;
16332         cmdline_fixed_string_t mapping;
16333         cmdline_fixed_string_t reset;
16334         portid_t port_id;
16335         uint8_t hw_ptype;
16336         uint32_t sw_ptype;
16337 };
16338
16339 /* Common CLI fields for ptype mapping update*/
16340 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16341         TOKEN_STRING_INITIALIZER
16342                 (struct cmd_ptype_mapping_update_result,
16343                  ptype, "ptype");
16344 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16345         TOKEN_STRING_INITIALIZER
16346                 (struct cmd_ptype_mapping_update_result,
16347                  mapping, "mapping");
16348 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16349         TOKEN_STRING_INITIALIZER
16350                 (struct cmd_ptype_mapping_update_result,
16351                  reset, "update");
16352 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16353         TOKEN_NUM_INITIALIZER
16354                 (struct cmd_ptype_mapping_update_result,
16355                  port_id, UINT16);
16356 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16357         TOKEN_NUM_INITIALIZER
16358                 (struct cmd_ptype_mapping_update_result,
16359                  hw_ptype, UINT8);
16360 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16361         TOKEN_NUM_INITIALIZER
16362                 (struct cmd_ptype_mapping_update_result,
16363                  sw_ptype, UINT32);
16364
16365 static void
16366 cmd_ptype_mapping_update_parsed(
16367         void *parsed_result,
16368         __attribute__((unused)) struct cmdline *cl,
16369         __attribute__((unused)) void *data)
16370 {
16371         struct cmd_ptype_mapping_update_result *res = parsed_result;
16372         int ret = -ENOTSUP;
16373 #ifdef RTE_LIBRTE_I40E_PMD
16374         struct rte_pmd_i40e_ptype_mapping mapping;
16375 #endif
16376         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16377                 return;
16378
16379 #ifdef RTE_LIBRTE_I40E_PMD
16380         mapping.hw_ptype = res->hw_ptype;
16381         mapping.sw_ptype = res->sw_ptype;
16382         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16383                                                 &mapping,
16384                                                 1,
16385                                                 0);
16386 #endif
16387
16388         switch (ret) {
16389         case 0:
16390                 break;
16391         case -EINVAL:
16392                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16393                 break;
16394         case -ENODEV:
16395                 printf("invalid port_id %d\n", res->port_id);
16396                 break;
16397         case -ENOTSUP:
16398                 printf("function not implemented\n");
16399                 break;
16400         default:
16401                 printf("programming error: (%s)\n", strerror(-ret));
16402         }
16403 }
16404
16405 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16406         .f = cmd_ptype_mapping_update_parsed,
16407         .data = NULL,
16408         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16409         .tokens = {
16410                 (void *)&cmd_ptype_mapping_update_ptype,
16411                 (void *)&cmd_ptype_mapping_update_mapping,
16412                 (void *)&cmd_ptype_mapping_update_update,
16413                 (void *)&cmd_ptype_mapping_update_port_id,
16414                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16415                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16416                 NULL,
16417         },
16418 };
16419
16420 /* Common result structure for file commands */
16421 struct cmd_cmdfile_result {
16422         cmdline_fixed_string_t load;
16423         cmdline_fixed_string_t filename;
16424 };
16425
16426 /* Common CLI fields for file commands */
16427 cmdline_parse_token_string_t cmd_load_cmdfile =
16428         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16429 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16430         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16431
16432 static void
16433 cmd_load_from_file_parsed(
16434         void *parsed_result,
16435         __attribute__((unused)) struct cmdline *cl,
16436         __attribute__((unused)) void *data)
16437 {
16438         struct cmd_cmdfile_result *res = parsed_result;
16439
16440         cmdline_read_from_file(res->filename);
16441 }
16442
16443 cmdline_parse_inst_t cmd_load_from_file = {
16444         .f = cmd_load_from_file_parsed,
16445         .data = NULL,
16446         .help_str = "load <filename>",
16447         .tokens = {
16448                 (void *)&cmd_load_cmdfile,
16449                 (void *)&cmd_load_cmdfile_filename,
16450                 NULL,
16451         },
16452 };
16453
16454 /* ******************************************************************************** */
16455
16456 /* list of instructions */
16457 cmdline_parse_ctx_t main_ctx[] = {
16458         (cmdline_parse_inst_t *)&cmd_help_brief,
16459         (cmdline_parse_inst_t *)&cmd_help_long,
16460         (cmdline_parse_inst_t *)&cmd_quit,
16461         (cmdline_parse_inst_t *)&cmd_load_from_file,
16462         (cmdline_parse_inst_t *)&cmd_showport,
16463         (cmdline_parse_inst_t *)&cmd_showqueue,
16464         (cmdline_parse_inst_t *)&cmd_showportall,
16465         (cmdline_parse_inst_t *)&cmd_showcfg,
16466         (cmdline_parse_inst_t *)&cmd_start,
16467         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16468         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16469         (cmdline_parse_inst_t *)&cmd_set_link_up,
16470         (cmdline_parse_inst_t *)&cmd_set_link_down,
16471         (cmdline_parse_inst_t *)&cmd_reset,
16472         (cmdline_parse_inst_t *)&cmd_set_numbers,
16473         (cmdline_parse_inst_t *)&cmd_set_log,
16474         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16475         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16476         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16477         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16478         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16479         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16480         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16481         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16482         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16483         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16484         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16485         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16486         (cmdline_parse_inst_t *)&cmd_set_link_check,
16487         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16488         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16489         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16490         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16491 #ifdef RTE_LIBRTE_PMD_BOND
16492         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16493         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16494         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16495         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16496         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16497         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16498         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16499         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16500         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16501         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16502         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16503 #endif
16504         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16505         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16506         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16507         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16508         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16509         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16510         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16511         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16512         (cmdline_parse_inst_t *)&cmd_csum_set,
16513         (cmdline_parse_inst_t *)&cmd_csum_show,
16514         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16515         (cmdline_parse_inst_t *)&cmd_tso_set,
16516         (cmdline_parse_inst_t *)&cmd_tso_show,
16517         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16518         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16519         (cmdline_parse_inst_t *)&cmd_gro_enable,
16520         (cmdline_parse_inst_t *)&cmd_gro_flush,
16521         (cmdline_parse_inst_t *)&cmd_gro_show,
16522         (cmdline_parse_inst_t *)&cmd_gso_enable,
16523         (cmdline_parse_inst_t *)&cmd_gso_size,
16524         (cmdline_parse_inst_t *)&cmd_gso_show,
16525         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16526         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16527         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16528         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16529         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16530         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16531         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16532         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16533         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16534         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16535         (cmdline_parse_inst_t *)&cmd_config_dcb,
16536         (cmdline_parse_inst_t *)&cmd_read_reg,
16537         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16538         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16539         (cmdline_parse_inst_t *)&cmd_write_reg,
16540         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16541         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16542         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16543         (cmdline_parse_inst_t *)&cmd_stop,
16544         (cmdline_parse_inst_t *)&cmd_mac_addr,
16545         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16546         (cmdline_parse_inst_t *)&cmd_set_qmap,
16547         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16548         (cmdline_parse_inst_t *)&cmd_operate_port,
16549         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16550         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16551         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16552         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16553         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16554         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16555         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16556         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16557         (cmdline_parse_inst_t *)&cmd_config_mtu,
16558         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16559         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16560         (cmdline_parse_inst_t *)&cmd_config_rss,
16561         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
16562         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16563         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
16564         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16565         (cmdline_parse_inst_t *)&cmd_showport_reta,
16566         (cmdline_parse_inst_t *)&cmd_config_burst,
16567         (cmdline_parse_inst_t *)&cmd_config_thresh,
16568         (cmdline_parse_inst_t *)&cmd_config_threshold,
16569         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16570         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16571         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16572         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16573         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16574         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16575         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16576         (cmdline_parse_inst_t *)&cmd_global_config,
16577         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16578         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16579         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16580         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16581         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16582         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16583         (cmdline_parse_inst_t *)&cmd_dump,
16584         (cmdline_parse_inst_t *)&cmd_dump_one,
16585         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16586         (cmdline_parse_inst_t *)&cmd_syn_filter,
16587         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16588         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16589         (cmdline_parse_inst_t *)&cmd_flex_filter,
16590         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16591         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16592         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16593         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16594         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16595         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16596         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16597         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16598         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16599         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16600         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16601         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16602         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16603         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16604         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16605         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16606         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16607         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16608         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16609         (cmdline_parse_inst_t *)&cmd_flow,
16610         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16611         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16612         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16613         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16614         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16615         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16616         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16617         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16618         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16619         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16620         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16621         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16622         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16623         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16624         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16625         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16626         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16627         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16628         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16629         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16630         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16631         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16632         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16633         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16634         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16635         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16636         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16637         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16638         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16639         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16640         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16641         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16642         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16643         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16644         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16645         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16646         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16647         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16648         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16649         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16650         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16651         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16652         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16653         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16654         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16655         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16656         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16657         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16658         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16659 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16660         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16661 #endif
16662         (cmdline_parse_inst_t *)&cmd_ddp_add,
16663         (cmdline_parse_inst_t *)&cmd_ddp_del,
16664         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16665         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16666         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16667         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16668         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16669         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16670         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16671         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16672         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16673         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16674
16675         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16676         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16677         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16678         (cmdline_parse_inst_t *)&cmd_queue_region,
16679         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16680         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16681         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16682         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16683         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16684         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16685         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16686         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16687         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16688         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16689         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16690         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16691         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16692         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16693         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16694         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16695         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16696         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16697         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16698         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16699         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
16700         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16701         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
16702         NULL,
16703 };
16704
16705 /* read cmdline commands from file */
16706 void
16707 cmdline_read_from_file(const char *filename)
16708 {
16709         struct cmdline *cl;
16710
16711         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16712         if (cl == NULL) {
16713                 printf("Failed to create file based cmdline context: %s\n",
16714                        filename);
16715                 return;
16716         }
16717
16718         cmdline_interact(cl);
16719         cmdline_quit(cl);
16720
16721         cmdline_free(cl);
16722
16723         printf("Read CLI commands from %s\n", filename);
16724 }
16725
16726 /* prompt function, called from main on MASTER lcore */
16727 void
16728 prompt(void)
16729 {
16730         /* initialize non-constant commands */
16731         cmd_set_fwd_mode_init();
16732         cmd_set_fwd_retry_mode_init();
16733
16734         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16735         if (testpmd_cl == NULL)
16736                 return;
16737         cmdline_interact(testpmd_cl);
16738         cmdline_stdin_exit(testpmd_cl);
16739 }
16740
16741 void
16742 prompt_exit(void)
16743 {
16744         if (testpmd_cl != NULL)
16745                 cmdline_quit(testpmd_cl);
16746 }
16747
16748 static void
16749 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16750 {
16751         if (id == (portid_t)RTE_PORT_ALL) {
16752                 portid_t pid;
16753
16754                 RTE_ETH_FOREACH_DEV(pid) {
16755                         /* check if need_reconfig has been set to 1 */
16756                         if (ports[pid].need_reconfig == 0)
16757                                 ports[pid].need_reconfig = dev;
16758                         /* check if need_reconfig_queues has been set to 1 */
16759                         if (ports[pid].need_reconfig_queues == 0)
16760                                 ports[pid].need_reconfig_queues = queue;
16761                 }
16762         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16763                 /* check if need_reconfig has been set to 1 */
16764                 if (ports[id].need_reconfig == 0)
16765                         ports[id].need_reconfig = dev;
16766                 /* check if need_reconfig_queues has been set to 1 */
16767                 if (ports[id].need_reconfig_queues == 0)
16768                         ports[id].need_reconfig_queues = queue;
16769         }
16770 }